-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (44 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const config = {
name : 'css',
isPx : true,
toLine : false
}
function toLowerLine(str) {
var temp = str.replace(/[A-Z]/g, function (match) {
return "-" + match.toLowerCase();
});
if(temp.slice(0,1) === '-'){
temp = temp.slice(1);
}
return temp;
}
export default function(app,options=config) {
let {name,isPx,toLine} = {...config , ...options}
function change(el,binding){
for(let [key,value] of Object.entries(binding.value)){
if(value == null) continue;
if(toLine){
key = toLowerLine(key)
}
if(isPx){
if ( typeof value === "number") value += 'px'
}
el.style.setProperty('--'+key, value);
}
}
app.directive(name, {
mounted(el,binding){
change(el,binding)
},
inserted(el,binding){
change(el,binding)
},
updated(el, binding) {
change(el,binding)
},
update(el,binding){
change(el,binding)
}
})
return app;
}