1 | var understandable = require('./properties/understandable');
|
---|
2 |
|
---|
3 | function animationIterationCount(validator, value1, value2) {
|
---|
4 | if (!understandable(validator, value1, value2, 0, true)
|
---|
5 | && !(validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2))) {
|
---|
6 | return false;
|
---|
7 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
8 | return true;
|
---|
9 | }
|
---|
10 |
|
---|
11 | return validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2);
|
---|
12 | }
|
---|
13 |
|
---|
14 | function animationName(validator, value1, value2) {
|
---|
15 | if (!understandable(validator, value1, value2, 0, true)
|
---|
16 | && !(validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2))) {
|
---|
17 | return false;
|
---|
18 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
19 | return true;
|
---|
20 | }
|
---|
21 |
|
---|
22 | return validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2);
|
---|
23 | }
|
---|
24 |
|
---|
25 | function areSameFunction(validator, value1, value2) {
|
---|
26 | if (!validator.isFunction(value1) || !validator.isFunction(value2)) {
|
---|
27 | return false;
|
---|
28 | }
|
---|
29 |
|
---|
30 | var function1Name = value1.substring(0, value1.indexOf('('));
|
---|
31 | var function2Name = value2.substring(0, value2.indexOf('('));
|
---|
32 |
|
---|
33 | var function1Value = value1.substring(function1Name.length + 1, value1.length - 1);
|
---|
34 | var function2Value = value2.substring(function2Name.length + 1, value2.length - 1);
|
---|
35 |
|
---|
36 | if (validator.isFunction(function1Value) || validator.isFunction(function2Value)) {
|
---|
37 | return function1Name === function2Name && areSameFunction(validator, function1Value, function2Value);
|
---|
38 | }
|
---|
39 | return function1Name === function2Name;
|
---|
40 | }
|
---|
41 |
|
---|
42 | function backgroundPosition(validator, value1, value2) {
|
---|
43 | if (!understandable(validator, value1, value2, 0, true)
|
---|
44 | && !(validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2))) {
|
---|
45 | return false;
|
---|
46 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
47 | return true;
|
---|
48 | } if (validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2)) {
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 |
|
---|
52 | return unit(validator, value1, value2);
|
---|
53 | }
|
---|
54 |
|
---|
55 | function backgroundSize(validator, value1, value2) {
|
---|
56 | if (!understandable(validator, value1, value2, 0, true)
|
---|
57 | && !(validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2))) {
|
---|
58 | return false;
|
---|
59 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
60 | return true;
|
---|
61 | } if (validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2)) {
|
---|
62 | return true;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return unit(validator, value1, value2);
|
---|
66 | }
|
---|
67 |
|
---|
68 | function color(validator, value1, value2) {
|
---|
69 | if (!understandable(validator, value1, value2, 0, true) && !validator.isColor(value2)) {
|
---|
70 | return false;
|
---|
71 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
72 | return true;
|
---|
73 | } if (!validator.colorOpacity && (validator.isRgbColor(value1) || validator.isHslColor(value1))) {
|
---|
74 | return false;
|
---|
75 | } if (!validator.colorOpacity && (validator.isRgbColor(value2) || validator.isHslColor(value2))) {
|
---|
76 | return false;
|
---|
77 | } if (!validator.colorHexAlpha && (validator.isHexAlphaColor(value1) || validator.isHexAlphaColor(value2))) {
|
---|
78 | return false;
|
---|
79 | } if (validator.isColor(value1) && validator.isColor(value2)) {
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | return sameFunctionOrValue(validator, value1, value2);
|
---|
84 | }
|
---|
85 |
|
---|
86 | function components(overrideCheckers) {
|
---|
87 | return function(validator, value1, value2, position) {
|
---|
88 | return overrideCheckers[position](validator, value1, value2);
|
---|
89 | };
|
---|
90 | }
|
---|
91 |
|
---|
92 | function fontFamily(validator, value1, value2) {
|
---|
93 | return understandable(validator, value1, value2, 0, true);
|
---|
94 | }
|
---|
95 |
|
---|
96 | function image(validator, value1, value2) {
|
---|
97 | if (!understandable(validator, value1, value2, 0, true) && !validator.isImage(value2)) {
|
---|
98 | return false;
|
---|
99 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
100 | return true;
|
---|
101 | } if (validator.isImage(value2)) {
|
---|
102 | return true;
|
---|
103 | } if (validator.isImage(value1)) {
|
---|
104 | return false;
|
---|
105 | }
|
---|
106 |
|
---|
107 | return sameFunctionOrValue(validator, value1, value2);
|
---|
108 | }
|
---|
109 |
|
---|
110 | function keyword(propertyName) {
|
---|
111 | return function(validator, value1, value2) {
|
---|
112 | if (!understandable(validator, value1, value2, 0, true) && !validator.isKeyword(propertyName)(value2)) {
|
---|
113 | return false;
|
---|
114 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 |
|
---|
118 | return validator.isKeyword(propertyName)(value2);
|
---|
119 | };
|
---|
120 | }
|
---|
121 |
|
---|
122 | function keywordWithGlobal(propertyName) {
|
---|
123 | return function(validator, value1, value2) {
|
---|
124 | if (!understandable(validator, value1, value2, 0, true)
|
---|
125 | && !(validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2))) {
|
---|
126 | return false;
|
---|
127 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
128 | return true;
|
---|
129 | }
|
---|
130 |
|
---|
131 | return validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2);
|
---|
132 | };
|
---|
133 | }
|
---|
134 |
|
---|
135 | function propertyName(validator, value1, value2) {
|
---|
136 | if (!understandable(validator, value1, value2, 0, true) && !validator.isIdentifier(value2)) {
|
---|
137 | return false;
|
---|
138 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
139 | return true;
|
---|
140 | }
|
---|
141 |
|
---|
142 | return validator.isIdentifier(value2);
|
---|
143 | }
|
---|
144 |
|
---|
145 | function sameFunctionOrValue(validator, value1, value2) {
|
---|
146 | return areSameFunction(validator, value1, value2)
|
---|
147 | ? true
|
---|
148 | : value1 === value2;
|
---|
149 | }
|
---|
150 |
|
---|
151 | function textShadow(validator, value1, value2) {
|
---|
152 | if (!understandable(validator, value1, value2, 0, true)
|
---|
153 | && !(validator.isUnit(value2)
|
---|
154 | || validator.isColor(value2)
|
---|
155 | || validator.isGlobal(value2))) {
|
---|
156 | return false;
|
---|
157 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
158 | return true;
|
---|
159 | }
|
---|
160 |
|
---|
161 | return validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2);
|
---|
162 | }
|
---|
163 |
|
---|
164 | function time(validator, value1, value2) {
|
---|
165 | if (!understandable(validator, value1, value2, 0, true) && !validator.isTime(value2)) {
|
---|
166 | return false;
|
---|
167 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
168 | return true;
|
---|
169 | } if (validator.isTime(value1) && !validator.isTime(value2)) {
|
---|
170 | return false;
|
---|
171 | } if (validator.isTime(value2)) {
|
---|
172 | return true;
|
---|
173 | } if (validator.isTime(value1)) {
|
---|
174 | return false;
|
---|
175 | } if (validator.isFunction(value1)
|
---|
176 | && !validator.isPrefixed(value1)
|
---|
177 | && validator.isFunction(value2)
|
---|
178 | && !validator.isPrefixed(value2)) {
|
---|
179 | return true;
|
---|
180 | }
|
---|
181 |
|
---|
182 | return sameFunctionOrValue(validator, value1, value2);
|
---|
183 | }
|
---|
184 |
|
---|
185 | function timingFunction(validator, value1, value2) {
|
---|
186 | if (!understandable(validator, value1, value2, 0, true)
|
---|
187 | && !(validator.isTimingFunction(value2) || validator.isGlobal(value2))) {
|
---|
188 | return false;
|
---|
189 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
190 | return true;
|
---|
191 | }
|
---|
192 |
|
---|
193 | return validator.isTimingFunction(value2) || validator.isGlobal(value2);
|
---|
194 | }
|
---|
195 |
|
---|
196 | function unit(validator, value1, value2) {
|
---|
197 | if (!understandable(validator, value1, value2, 0, true) && !validator.isUnit(value2)) {
|
---|
198 | return false;
|
---|
199 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
200 | return true;
|
---|
201 | } if (validator.isUnit(value1) && !validator.isUnit(value2)) {
|
---|
202 | return false;
|
---|
203 | } if (validator.isUnit(value2)) {
|
---|
204 | return true;
|
---|
205 | } if (validator.isUnit(value1)) {
|
---|
206 | return false;
|
---|
207 | } if (validator.isFunction(value1)
|
---|
208 | && !validator.isPrefixed(value1)
|
---|
209 | && validator.isFunction(value2)
|
---|
210 | && !validator.isPrefixed(value2)) {
|
---|
211 | return true;
|
---|
212 | }
|
---|
213 |
|
---|
214 | return sameFunctionOrValue(validator, value1, value2);
|
---|
215 | }
|
---|
216 |
|
---|
217 | function unitOrKeywordWithGlobal(propertyName) {
|
---|
218 | var byKeyword = keywordWithGlobal(propertyName);
|
---|
219 |
|
---|
220 | return function(validator, value1, value2) {
|
---|
221 | return unit(validator, value1, value2) || byKeyword(validator, value1, value2);
|
---|
222 | };
|
---|
223 | }
|
---|
224 |
|
---|
225 | function unitOrNumber(validator, value1, value2) {
|
---|
226 | if (!understandable(validator, value1, value2, 0, true)
|
---|
227 | && !(validator.isUnit(value2)
|
---|
228 | || validator.isNumber(value2))) {
|
---|
229 | return false;
|
---|
230 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
231 | return true;
|
---|
232 | } if ((validator.isUnit(value1)
|
---|
233 | || validator.isNumber(value1))
|
---|
234 | && !(validator.isUnit(value2)
|
---|
235 | || validator.isNumber(value2))) {
|
---|
236 | return false;
|
---|
237 | } if (validator.isUnit(value2) || validator.isNumber(value2)) {
|
---|
238 | return true;
|
---|
239 | } if (validator.isUnit(value1) || validator.isNumber(value1)) {
|
---|
240 | return false;
|
---|
241 | } if (validator.isFunction(value1)
|
---|
242 | && !validator.isPrefixed(value1)
|
---|
243 | && validator.isFunction(value2)
|
---|
244 | && !validator.isPrefixed(value2)) {
|
---|
245 | return true;
|
---|
246 | }
|
---|
247 |
|
---|
248 | return sameFunctionOrValue(validator, value1, value2);
|
---|
249 | }
|
---|
250 |
|
---|
251 | function zIndex(validator, value1, value2) {
|
---|
252 | if (!understandable(validator, value1, value2, 0, true) && !validator.isZIndex(value2)) {
|
---|
253 | return false;
|
---|
254 | } if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
---|
255 | return true;
|
---|
256 | }
|
---|
257 |
|
---|
258 | return validator.isZIndex(value2);
|
---|
259 | }
|
---|
260 |
|
---|
261 | module.exports = {
|
---|
262 | generic: {
|
---|
263 | color: color,
|
---|
264 | components: components,
|
---|
265 | image: image,
|
---|
266 | propertyName: propertyName,
|
---|
267 | time: time,
|
---|
268 | timingFunction: timingFunction,
|
---|
269 | unit: unit,
|
---|
270 | unitOrNumber: unitOrNumber
|
---|
271 | },
|
---|
272 | property: {
|
---|
273 | animationDirection: keywordWithGlobal('animation-direction'),
|
---|
274 | animationFillMode: keyword('animation-fill-mode'),
|
---|
275 | animationIterationCount: animationIterationCount,
|
---|
276 | animationName: animationName,
|
---|
277 | animationPlayState: keywordWithGlobal('animation-play-state'),
|
---|
278 | backgroundAttachment: keyword('background-attachment'),
|
---|
279 | backgroundClip: keywordWithGlobal('background-clip'),
|
---|
280 | backgroundOrigin: keyword('background-origin'),
|
---|
281 | backgroundPosition: backgroundPosition,
|
---|
282 | backgroundRepeat: keyword('background-repeat'),
|
---|
283 | backgroundSize: backgroundSize,
|
---|
284 | bottom: unitOrKeywordWithGlobal('bottom'),
|
---|
285 | borderCollapse: keyword('border-collapse'),
|
---|
286 | borderStyle: keywordWithGlobal('*-style'),
|
---|
287 | clear: keywordWithGlobal('clear'),
|
---|
288 | cursor: keywordWithGlobal('cursor'),
|
---|
289 | display: keywordWithGlobal('display'),
|
---|
290 | float: keywordWithGlobal('float'),
|
---|
291 | left: unitOrKeywordWithGlobal('left'),
|
---|
292 | fontFamily: fontFamily,
|
---|
293 | fontStretch: keywordWithGlobal('font-stretch'),
|
---|
294 | fontStyle: keywordWithGlobal('font-style'),
|
---|
295 | fontVariant: keywordWithGlobal('font-variant'),
|
---|
296 | fontWeight: keywordWithGlobal('font-weight'),
|
---|
297 | listStyleType: keywordWithGlobal('list-style-type'),
|
---|
298 | listStylePosition: keywordWithGlobal('list-style-position'),
|
---|
299 | outlineStyle: keywordWithGlobal('*-style'),
|
---|
300 | overflow: keywordWithGlobal('overflow'),
|
---|
301 | position: keywordWithGlobal('position'),
|
---|
302 | right: unitOrKeywordWithGlobal('right'),
|
---|
303 | textAlign: keywordWithGlobal('text-align'),
|
---|
304 | textDecoration: keywordWithGlobal('text-decoration'),
|
---|
305 | textOverflow: keywordWithGlobal('text-overflow'),
|
---|
306 | textShadow: textShadow,
|
---|
307 | top: unitOrKeywordWithGlobal('top'),
|
---|
308 | transform: sameFunctionOrValue,
|
---|
309 | verticalAlign: unitOrKeywordWithGlobal('vertical-align'),
|
---|
310 | visibility: keywordWithGlobal('visibility'),
|
---|
311 | whiteSpace: keywordWithGlobal('white-space'),
|
---|
312 | zIndex: zIndex
|
---|
313 | }
|
---|
314 | };
|
---|