+11
-11
| /* eslint-disable no-useless-return,no-useless-escape,camelcase,semi,no-cond-assign,no-unused-vars */ | ||
| const env = process.env.NODE_ENV | ||
| const handleVars = (varItem, addPrefix) => { | ||
| const handleVars = (varItem) => { | ||
| varItem = varItem.map(e => e + '') | ||
| if (addPrefix) { | ||
| varItem[0] = '--' + varItem[0].replace('--', '') | ||
| } | ||
| return { | ||
| varsName: varItem[0], | ||
| varsName: '--' + varItem[0].replace('--', ''), | ||
| varsValue: varItem[1] | ||
| } | ||
| } | ||
| const changeVars = (el, binding, prefix) => { | ||
| const changeVars = (el, binding) => { | ||
| const vars = Object.entries(binding.value) | ||
@@ -20,3 +17,3 @@ const dom = binding.modifiers.root ? document.documentElement : el | ||
| varsValue | ||
| } = handleVars(k, prefix) | ||
| } = handleVars(k) | ||
| dom.style.setProperty(varsName, varsValue) | ||
@@ -43,3 +40,3 @@ } | ||
| } | ||
| changeVars(el, binding, options.prefix) | ||
| changeVars(el, binding) | ||
| }, | ||
@@ -53,3 +50,6 @@ update: function (el, binding) { | ||
| // get all cssVars in the dom | ||
| const styleList = dom.style.cssText.split(';').map(e => e.split(':')).filter(e => e[0] !== '') | ||
| const styleList = dom.style.cssText | ||
| .split(';') | ||
| .map(e => e.split(':')) | ||
| .filter(e => e[0] !== '' && e[0].startsWith('--')) | ||
| const vars = Object.entries(binding.value) | ||
@@ -62,3 +62,3 @@ // 更新当前变量 | ||
| varsValue | ||
| } = handleVars(k, options.prefix) | ||
| } = handleVars(k) | ||
| const oldValue = document.body.style.getPropertyValue(varsName) | ||
@@ -71,3 +71,3 @@ if (oldValue !== varsValue) { | ||
| for (const k of styleList) { | ||
| const key = options.prefix ? k[0].replace('--', '') : k[0] | ||
| const key = k[0].replace('--', '') | ||
| if (!vars.find(e => e[0] === key)) { | ||
@@ -74,0 +74,0 @@ dom.style.removeProperty(k[0]) |
+1
-1
| { | ||
| "name": "v-css-var", | ||
| "version": "1.0.1", | ||
| "version": "1.0.3", | ||
| "description": "use CSS Variables by vue directive", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+2
-4
@@ -9,5 +9,3 @@ # v-css-var | ||
| import cssVar from 'v-css-var' | ||
| Vue.use(cssVar,{ | ||
| prefix: true // auto add the prefix like -- | ||
| }) | ||
| Vue.use(cssVar) | ||
| ``` | ||
@@ -24,3 +22,3 @@ #### basic use | ||
| var:{ | ||
| a:'1px' | ||
| a:'1px' // not suggest start with --,like '--a':'1px',but supported | ||
| } | ||
@@ -27,0 +25,0 @@ } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3825
-1.49%56
-3.45%