Comparing version 1.0.0 to 1.0.1
30
index.js
@@ -1,2 +0,2 @@ | ||
/* eslint-disable no-useless-return,no-useless-escape,camelcase,semi,no-cond-assign */ | ||
/* eslint-disable no-useless-return,no-useless-escape,camelcase,semi,no-cond-assign,no-unused-vars */ | ||
const env = process.env.NODE_ENV | ||
@@ -6,3 +6,3 @@ const handleVars = (varItem, addPrefix) => { | ||
if (addPrefix) { | ||
varItem[0] = '--' + varItem[0] | ||
varItem[0] = '--' + varItem[0].replace('--', '') | ||
} | ||
@@ -52,13 +52,23 @@ return { | ||
// get all cssVars in the dom | ||
const styleList = dom.style.cssText.split(';').map(e => e.split(':')).filter(e => e[0] !== '') | ||
const vars = Object.entries(binding.value) | ||
for (const k of vars) { | ||
const { | ||
varsName, | ||
varsValue | ||
} = handleVars(k, options.prefix) | ||
const oldValue = dom.style.getPropertyValue(varsName) | ||
if (oldValue !== varsValue) { | ||
dom.style.setProperty(varsName, varsValue) | ||
// 更新当前变量 | ||
if (vars.length > 0) { | ||
for (const k of vars) { | ||
const { | ||
varsName, | ||
varsValue | ||
} = handleVars(k, options.prefix) | ||
const oldValue = document.body.style.getPropertyValue(varsName) | ||
if (oldValue !== varsValue) { | ||
dom.style.setProperty(varsName, varsValue) | ||
} | ||
} | ||
} | ||
for (const k of styleList) { | ||
const key = options.prefix ? k[0].replace('--', '') : k[0] | ||
if (!vars.find(e => e[0] === key)) { | ||
dom.style.removeProperty(k[0]) | ||
} | ||
} | ||
} | ||
@@ -65,0 +75,0 @@ }) |
{ | ||
"name": "v-css-var", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "use CSS Variables by vue directive", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,2 +56,3 @@ # v-css-var | ||
#### TO DO | ||
- [ ] remove the css Variables | ||
- [x] remove the css Variables | ||
- [ ] write the test |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78
58
3883
3