优化滚动组件
parent
17ce8fe6fa
commit
7f420b0caa
10
build.dev.js
10
build.dev.js
|
@ -37,10 +37,10 @@ function fixImport(str) {
|
|||
}
|
||||
|
||||
function compileJs(entry, output) {
|
||||
log('编译JS: %s', chalk.green(entry))
|
||||
let buf = fs.cat(entry).toString()
|
||||
let code = fixImport(buf)
|
||||
var buf = fs.cat(entry).toString()
|
||||
var code = fixImport(buf)
|
||||
|
||||
log('编译JS: %s', chalk.green(entry))
|
||||
fs.echo(code, output)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ function mkWCFile({ style, html, js }) {
|
|||
|
||||
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
|
||||
.split(/\n+/)
|
||||
.slice(1, -1)
|
||||
|
@ -77,7 +77,7 @@ function mkWCFile({ style, html, 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
|
||||
return `${s} extends HTMLElement `
|
||||
})
|
||||
|
|
|
@ -36,10 +36,12 @@ function fixImport(str) {
|
|||
)
|
||||
}
|
||||
|
||||
const compileJs = (entry, output) => {
|
||||
let t1 = Date.now()
|
||||
let buf = fs.cat(entry).toString()
|
||||
function compileJs(entry, output) {
|
||||
var t1 = Date.now()
|
||||
var buf = fs.cat(entry).toString()
|
||||
|
||||
buf = fixImport(buf)
|
||||
|
||||
minify(buf, { sourceMap: false }).then(res => {
|
||||
log(
|
||||
'编译JS: %s, 耗时 %s ms',
|
||||
|
@ -65,19 +67,17 @@ function compileScss(code = '') {
|
|||
}
|
||||
|
||||
function mkWCFile({ style, html, js }) {
|
||||
let name = ''
|
||||
style = compileScss(style)
|
||||
|
||||
html = html.replace(/[\n\r]+/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
|
||||
.split(/\n+/)
|
||||
.slice(1, -1)
|
||||
.map(it => {
|
||||
var tmp = it.split(':')
|
||||
let tmp = it.split(':')
|
||||
return tmp[0].trim().replace(/^['"]|['"]$/g, '')
|
||||
})
|
||||
return `
|
||||
|
@ -91,7 +91,7 @@ function mkWCFile({ style, html, 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
|
||||
return `${s} extends HTMLElement `
|
||||
})
|
||||
|
@ -137,7 +137,7 @@ if(!customElements.get('wc-${parseName(name)}')){
|
|||
}
|
||||
|
||||
const compileWC = (entry, output) => {
|
||||
log('编译wc: %s', chalk.green(entry))
|
||||
let t1 = Date.now()
|
||||
let code = fs.cat(entry).toString()
|
||||
let style = code.match(/<style[^>]*?>([\w\W]*?)<\/style>/)
|
||||
let html = code.match(/<template>([\w\W]*?)<\/template>/)
|
||||
|
@ -148,6 +148,11 @@ const compileWC = (entry, output) => {
|
|||
js = js ? js[1] : ''
|
||||
|
||||
mkWCFile({ style, html, js }).then(txt => {
|
||||
log(
|
||||
'编译WC: %s, 耗时 %s ms',
|
||||
chalk.green(entry),
|
||||
chalk.yellow(Date.now() - t1)
|
||||
)
|
||||
fs.echo(txt, output)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ export default class Scroll {
|
|||
|
||||
fixedY = fixedY >> 0
|
||||
|
||||
if ((fixedY === 0 || height - yBar === fixedY) && fixedY === thumbY) {
|
||||
if (fixedY === thumbY) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ export default class Scroll {
|
|||
|
||||
fixedX = fixedX >> 0
|
||||
|
||||
if ((fixedX === 0 || width - xBar === fixedX) && fixedX === thumbX) {
|
||||
if (fixedX === thumbX) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue