-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcssobj-plugin-default-unit.js
63 lines (49 loc) · 1.12 KB
/
cssobj-plugin-default-unit.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
47
48
49
50
51
52
53
54
55
56
57
58
59
// cssobj value plugin
import {dashify, isNumeric} from '../../cssobj-helper/lib/cssobj-helper.js'
var unitless = [
"animation-iteration-count",
"box-flex",
"box-flex-group",
"box-ordinal-group",
"columns",
"column-count",
"fill-opacity",
"flex",
"flex-grow",
"flex-positive",
"flex-negative",
"flex-order",
"flex-shrink",
"font-weight",
"line-height", /* 1.5 or 22px? so don't add unit here */
"line-clamp",
"opacity",
"order",
"orphans",
"stop-opacity",
"stroke-dash-offset",
"stroke-opacity",
"stroke-width",
"tab-size",
"widows",
"z-index",
"zoom"
]
export default function cssobj_plugin_default_unit (unit) {
unit = unit || 'px'
return {
value: function(value, key, node, result) {
var base = dashify(key).replace(
/^[^a-zA-Z]*(?:ms-|o-|webkit-|moz-|khtml-)?|[^a-zA-Z]+$/g,
'')
// here **ignored** value===''||value===null,
// which is false for isNaN.
// cssobj never have this value
return (!isNumeric(value)
|| unitless.indexOf(base)>-1
)
? value
: value + unit
}
}
}