UNPKG

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