This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化滚动组件

old
宇天 2021-05-07 22:46:20 +08:00
parent 17ce8fe6fa
commit 7f420b0caa
3 changed files with 22 additions and 17 deletions

View File

@ -37,10 +37,10 @@ function fixImport(str) {
} }
function compileJs(entry, output) { function compileJs(entry, output) {
log('编译JS: %s', chalk.green(entry)) var buf = fs.cat(entry).toString()
let buf = fs.cat(entry).toString() var code = fixImport(buf)
let code = fixImport(buf)
log('编译JS: %s', chalk.green(entry))
fs.echo(code, output) fs.echo(code, output)
} }
@ -58,7 +58,7 @@ function mkWCFile({ style, html, js }) {
let name = '' let name = ''
js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function(str) { js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function (str) {
var attr = str var attr = str
.split(/\n+/) .split(/\n+/)
.slice(1, -1) .slice(1, -1)
@ -77,7 +77,7 @@ function mkWCFile({ style, html, js }) {
}) })
js = fixImport(js) js = fixImport(js)
.replace(/export default class ([a-zA-Z0-9]+)/, function(s, m) { .replace(/export default class ([a-zA-Z0-9]+)/, function (s, m) {
name = m name = m
return `${s} extends HTMLElement ` return `${s} extends HTMLElement `
}) })

View File

@ -36,10 +36,12 @@ function fixImport(str) {
) )
} }
const compileJs = (entry, output) => { function compileJs(entry, output) {
let t1 = Date.now() var t1 = Date.now()
let buf = fs.cat(entry).toString() var buf = fs.cat(entry).toString()
buf = fixImport(buf) buf = fixImport(buf)
minify(buf, { sourceMap: false }).then(res => { minify(buf, { sourceMap: false }).then(res => {
log( log(
'编译JS: %s, 耗时 %s ms', '编译JS: %s, 耗时 %s ms',
@ -65,19 +67,17 @@ function compileScss(code = '') {
} }
function mkWCFile({ style, html, js }) { function mkWCFile({ style, html, js }) {
let name = ''
style = compileScss(style) style = compileScss(style)
html = html.replace(/[\n\r]+/g, ' ') html = html.replace(/[\n\r]+/g, ' ')
html = html.replace(/\s+/g, ' ') html = html.replace(/\s+/g, ' ')
let name = '' js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function (str) {
js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function(str) {
var attr = str var attr = str
.split(/\n+/) .split(/\n+/)
.slice(1, -1) .slice(1, -1)
.map(it => { .map(it => {
var tmp = it.split(':') let tmp = it.split(':')
return tmp[0].trim().replace(/^['"]|['"]$/g, '') return tmp[0].trim().replace(/^['"]|['"]$/g, '')
}) })
return ` return `
@ -91,7 +91,7 @@ function mkWCFile({ style, html, js }) {
}) })
js = fixImport(js) js = fixImport(js)
.replace(/export default class ([a-zA-Z0-9]+)/, function(s, m) { .replace(/export default class ([a-zA-Z0-9]+)/, function (s, m) {
name = m name = m
return `${s} extends HTMLElement ` return `${s} extends HTMLElement `
}) })
@ -137,7 +137,7 @@ if(!customElements.get('wc-${parseName(name)}')){
} }
const compileWC = (entry, output) => { const compileWC = (entry, output) => {
log('编译wc: %s', chalk.green(entry)) let t1 = Date.now()
let code = fs.cat(entry).toString() let code = fs.cat(entry).toString()
let style = code.match(/<style[^>]*?>([\w\W]*?)<\/style>/) let style = code.match(/<style[^>]*?>([\w\W]*?)<\/style>/)
let html = code.match(/<template>([\w\W]*?)<\/template>/) let html = code.match(/<template>([\w\W]*?)<\/template>/)
@ -148,6 +148,11 @@ const compileWC = (entry, output) => {
js = js ? js[1] : '' js = js ? js[1] : ''
mkWCFile({ style, html, js }).then(txt => { mkWCFile({ style, html, js }).then(txt => {
log(
'编译WC: %s, 耗时 %s ms',
chalk.green(entry),
chalk.yellow(Date.now() - t1)
)
fs.echo(txt, output) fs.echo(txt, output)
}) })
} }

View File

@ -308,7 +308,7 @@ export default class Scroll {
fixedY = fixedY >> 0 fixedY = fixedY >> 0
if ((fixedY === 0 || height - yBar === fixedY) && fixedY === thumbY) { if (fixedY === thumbY) {
return return
} }
@ -329,7 +329,7 @@ export default class Scroll {
fixedX = fixedX >> 0 fixedX = fixedX >> 0
if ((fixedX === 0 || width - xBar === fixedX) && fixedX === thumbX) { if (fixedX === thumbX) {
return return
} }