theme replacing should cut tons of irrelevant css
风格替换既然是颜色,那么应该削减大量无关的代码. 可以通过regexp 捕捉相关的,以上代码经过测试
This commit is contained in:
parent
ae41459cb1
commit
51fb0994ed
|
@ -66,11 +66,17 @@ export default {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
updateStyle(style, oldCluster, newCluster) {
|
updateStyle(style, oldCluster, newCluster) {
|
||||||
let newStyle = style
|
let colorOverrides = [] // only capture color overides
|
||||||
oldCluster.forEach((color, index) => {
|
oldCluster.forEach((color, index) => {
|
||||||
newStyle = newStyle.replace(new RegExp(color, 'ig'), newCluster[index])
|
let value = newCluster[index]
|
||||||
|
let repl = new RegExp(`(^|})([^{]+{[^{}]+)${color}\\b([^}]*)(?=})`, 'gi')
|
||||||
|
let nestRepl = new RegExp(color, 'ig') // for greed matching before the 'color'
|
||||||
|
let v
|
||||||
|
while ((v = repl.exec(data))) {
|
||||||
|
colorOverrides.push(v[2].replace(nestRepl, value) + value + v[3] + '}') // '}' not captured in the regexp repl to reserve it as locator-boundary
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return newStyle
|
return colorOverrides.join('')
|
||||||
},
|
},
|
||||||
|
|
||||||
getCSSString(url, callback, variable) {
|
getCSSString(url, callback, variable) {
|
||||||
|
|
Loading…
Reference in New Issue