parent
574dd7e693
commit
d5dcd44fec
|
@ -38,6 +38,16 @@ function md5(str = '') {
|
||||||
return sum.digest('hex').slice(0, 8)
|
return sum.digest('hex').slice(0, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseVDeep(curr, val, scoped) {
|
||||||
|
let res = V_DEEP.exec(curr)
|
||||||
|
if (res) {
|
||||||
|
scoped && (val = val.replace(/\[data\-[^\]]+\]/g, ''))
|
||||||
|
return `${res[1] + res[2]} ${val}`
|
||||||
|
} else {
|
||||||
|
return `${curr} ${val}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function scopeCss(css = '', hash) {
|
function scopeCss(css = '', hash) {
|
||||||
return css.replace(CSS_SHEET_EXP, (m, selector) => {
|
return css.replace(CSS_SHEET_EXP, (m, selector) => {
|
||||||
if (!selector.startsWith('@')) {
|
if (!selector.startsWith('@')) {
|
||||||
|
@ -50,29 +60,28 @@ function scopeCss(css = '', hash) {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
let tmp = s.split(' ')
|
let tmp = s.split(' ')
|
||||||
let last = tmp.pop()
|
let output = ''
|
||||||
if (last.includes(':')) {
|
let last
|
||||||
let res = V_DEEP.exec(last)
|
let scoped = false
|
||||||
if (res) {
|
|
||||||
if (tmp.length) {
|
while ((last = tmp.pop())) {
|
||||||
last = tmp.pop()
|
if (scoped) {
|
||||||
last += `[data-${hash}] `
|
if (last.startsWith(':')) {
|
||||||
|
output = parseVDeep(last, output, true)
|
||||||
} else {
|
} else {
|
||||||
last = res[1]
|
output = `${last} ${output}`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (last.startsWith(':')) {
|
if (last.startsWith(':')) {
|
||||||
let _prev = tmp.pop()
|
output = parseVDeep(last, output)
|
||||||
last = `${_prev}[data-${hash}] ` + last
|
|
||||||
} else {
|
} else {
|
||||||
last = last.replace(':', `[data-${hash}]:`)
|
scoped = true
|
||||||
|
output = `${last}[data-${hash}] ${output}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
last += `[data-${hash}]`
|
|
||||||
}
|
}
|
||||||
tmp.push(last)
|
|
||||||
return tmp.join(' ')
|
return output
|
||||||
})
|
})
|
||||||
.join(', ')
|
.join(', ')
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
|
export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
|
||||||
export const STYLE_EXP = /<style([^>]*?)>([\w\W]*?)<\/style>/g
|
export const STYLE_EXP = /<style([^>]*?)>([\w\W]*?)<\/style>/g
|
||||||
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)\n<\/template>/
|
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)\n<\/template>/
|
||||||
export const V_DEEP = /:deep\(([^)]*?)\)/
|
export const V_DEEP = /:deep\(([^)]*?)\)(.*)/
|
||||||
|
|
||||||
export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g
|
export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g
|
||||||
export const PERCENT_EXP = /^\d+%$/
|
export const PERCENT_EXP = /^\d+%$/
|
||||||
|
|
Loading…
Reference in New Issue