UNPKG

3.69 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11/**
12 * CSS properties which accept numbers but are not in units of "px".
13 */
14
15var isUnitlessNumber = {
16 animationIterationCount: true,
17 borderImageOutset: true,
18 borderImageSlice: true,
19 borderImageWidth: true,
20 boxFlex: true,
21 boxFlexGroup: true,
22 boxOrdinalGroup: true,
23 columnCount: true,
24 columns: true,
25 flex: true,
26 flexGrow: true,
27 flexPositive: true,
28 flexShrink: true,
29 flexNegative: true,
30 flexOrder: true,
31 gridRow: true,
32 gridRowEnd: true,
33 gridRowSpan: true,
34 gridRowStart: true,
35 gridColumn: true,
36 gridColumnEnd: true,
37 gridColumnSpan: true,
38 gridColumnStart: true,
39 fontWeight: true,
40 lineClamp: true,
41 lineHeight: true,
42 opacity: true,
43 order: true,
44 orphans: true,
45 tabSize: true,
46 widows: true,
47 zIndex: true,
48 zoom: true,
49
50 // SVG-related properties
51 fillOpacity: true,
52 floodOpacity: true,
53 stopOpacity: true,
54 strokeDasharray: true,
55 strokeDashoffset: true,
56 strokeMiterlimit: true,
57 strokeOpacity: true,
58 strokeWidth: true
59};
60
61/**
62 * @param {string} prefix vendor-specific prefix, eg: Webkit
63 * @param {string} key style name, eg: transitionDuration
64 * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
65 * WebkitTransitionDuration
66 */
67function prefixKey(prefix, key) {
68 return prefix + key.charAt(0).toUpperCase() + key.substring(1);
69}
70
71/**
72 * Support style names that may come passed in prefixed by adding permutations
73 * of vendor prefixes.
74 */
75var prefixes = ['Webkit', 'ms', 'Moz', 'O'];
76
77// Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
78// infinite loop, because it iterates over the newly added props too.
79Object.keys(isUnitlessNumber).forEach(function (prop) {
80 prefixes.forEach(function (prefix) {
81 isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
82 });
83});
84
85/**
86 * Most style properties can be unset by doing .style[prop] = '' but IE8
87 * doesn't like doing that with shorthand properties so for the properties that
88 * IE8 breaks on, which are listed here, we instead unset each of the
89 * individual properties. See http://bugs.jquery.com/ticket/12385.
90 * The 4-value 'clock' properties like margin, padding, border-width seem to
91 * behave without any problems. Curiously, list-style works too without any
92 * special prodding.
93 */
94var shorthandPropertyExpansions = {
95 background: {
96 backgroundAttachment: true,
97 backgroundColor: true,
98 backgroundImage: true,
99 backgroundPositionX: true,
100 backgroundPositionY: true,
101 backgroundRepeat: true
102 },
103 backgroundPosition: {
104 backgroundPositionX: true,
105 backgroundPositionY: true
106 },
107 border: {
108 borderWidth: true,
109 borderStyle: true,
110 borderColor: true
111 },
112 borderBottom: {
113 borderBottomWidth: true,
114 borderBottomStyle: true,
115 borderBottomColor: true
116 },
117 borderLeft: {
118 borderLeftWidth: true,
119 borderLeftStyle: true,
120 borderLeftColor: true
121 },
122 borderRight: {
123 borderRightWidth: true,
124 borderRightStyle: true,
125 borderRightColor: true
126 },
127 borderTop: {
128 borderTopWidth: true,
129 borderTopStyle: true,
130 borderTopColor: true
131 },
132 font: {
133 fontStyle: true,
134 fontVariant: true,
135 fontWeight: true,
136 fontSize: true,
137 lineHeight: true,
138 fontFamily: true
139 },
140 outline: {
141 outlineWidth: true,
142 outlineStyle: true,
143 outlineColor: true
144 }
145};
146
147var CSSProperty = {
148 isUnitlessNumber: isUnitlessNumber,
149 shorthandPropertyExpansions: shorthandPropertyExpansions
150};
151
152module.exports = CSSProperty;
\No newline at end of file