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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
(function(root){
/*
* General Value Types definition
* they return an object of arrays of type { <name>: [<start-value>, <end-value>], ... }
*/
var values = {
'length' : function() {
// http://www.w3.org/TR/css3-values/#lengths
return {
// CSS Values and Module Level 3
// ch: ['1ch', '10ch'],
// rem: ['1rem', '10rem'],
// vw: ['1vw', '10vw'],
// vh: ['1vh', '10vh'],
// vmin: ['1vmin', '10vmin'],
// vmax: ['1vmax', '10vmax'],
// CSS Values and Module Level 2
pt: ['1pt', '10pt'],
pc: ['1pc', '10pc'],
px: ['1px', '10px'],
// CSS Values and Module Level 1
em: ['1em', '10em'],
ex: ['1ex', '10ex'],
mm: ['1mm', '10mm'],
cm: ['1cm', '10cm'],
'in': ['1in', '10in']
};
},
'length-em': function() {
return {
em: ['1.1em', '1.5em']
};
},
'percentage': function() {
// http://www.w3.org/TR/css3-values/#percentages
return {
'%': ['33%', '80%']
};
},
'color': function() {
// http://www.w3.org/TR/css3-values/#colors
// http://www.w3.org/TR/css3-color/
return {
rgba: ['rgba(100,100,100,1)', 'rgba(10,10,10,0.4)']
};
},
'rectangle': function() {
// http://www.w3.org/TR/CSS2/visufx.html#value-def-shape
return {
rectangle: ['rect(10px,10px,10px,10px)', 'rect(15px,15px,5px,5px)']
};
},
'font-weight': function() {
// http://www.w3.org/TR/css3-fonts/#font-weight-prop
return {
keyword: ["normal", "bold"],
numeric: ["100", "900"]
};
},
'number': function() {
// http://www.w3.org/TR/css3-values/#number
return {
integer: ["1", "10"],
decimal: ["1.1", "9.55"]
};
},
'number[0,1]': function() {
// http://www.w3.org/TR/css3-values/#number
// applies to [0,1]-ranged properties like opacity
return {
"zero-to-one": ["0.2", "0.9"]
};
},
'integer': function() {
// http://www.w3.org/TR/css3-values/#integer
return {
integer: ["1", "10"]
};
},
'shadow': function() {
// http://www.w3.org/TR/css-text-decor-3/#text-shadow-property
return {
shadow: ['rgba(0,0,0,0.1) 5px 6px 7px', 'rgba(10,10,10,0.9) 5px 6px 7px']
};
},
'visibility': function() {
// http://www.w3.org/TR/CSS2/visufx.html#visibility
return {
keyword: ['visible', 'hidden', {discrete: true}]
};
},
// types reqired for non-specified properties
'border-radius': function() {
return {
px: ['1px', '10px'],
"px-px": ['1px 3px', '10px 13px']
};
},
'image' : function() {
var prefix = getValueVendorPrefix('background-image', 'linear-gradient(top, hsl(0, 80%, 70%), #bada55)');
return {
// Chrome implements this
url: ['url(support/one.gif)', 'url(support/two.gif)'],
data: ['url(data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=)', 'url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==)'],
// A hunch, as from the spec:
// http://www.w3.org/TR/css3-transitions/#animatable-types
// gradient: interpolated via the positions and colors of each stop. They must have the same type (radial or linear) and same number of stops in order to be animated. Note: [CSS3-IMAGES] may extend this definition.
gradient: [prefix + 'linear-gradient(top, hsl(0, 80%, 70%), #bada55)', prefix + 'linear-gradient(top, #bada55, hsl(0, 80%, 70%))']
};
},
'background-size': function() {
return {
keyword: ['cover', 'contain']
};
},
'box-shadow': function() {
// http://www.w3.org/TR/css3-background/#ltshadowgt
return {
shadow: ['60px -16px teal', '60px -16px red']
};
},
'vertical': function() {
return {
keyword: ['top', 'bottom']
};
},
'horizontal': function() {
return {
keyword: ['left', 'right']
};
},
'font-stretch': function() {
return {
keyword: ['condensed', 'expanded']
};
},
'transform': function() {
return {
rotate: ['rotate(10deg)', 'rotate(20deg)']
};
},
'position': function() {
return {
'static to absolute': ['static', 'absolute', {discrete: true}],
'relative to absolute': ['relative', 'absolute', {discrete: true}],
'absolute to fixed': ['absolute', 'fixed', {discrete: true}]
};
},
'display': function() {
return {
'static to absolute': ['none', 'block', {discrete: true}],
'block to inline-block': ['block', 'inline-block', {discrete: true}]
};
},
'object-view-box': function() {
return {
inset: ['inset(10% 10% 20% 20%)', 'inset(20% 20% 30% 30%)'],
rect: ['rect(10px 20px 30px 40px)', 'rect(20px 30px 40px 50px)'],
xywh: ['xywh(10px 20px 30px 40px)', 'xywh(20px 30px 40px 50px)'],
};
}
};
/*
* Property to Type table
* (as stated in specification)
*/
var properties = {
'background-color': ['color'],
'background-position': ['length', 'percentage'],
'border-top-width': ['length'],
'border-right-width': ['length'],
'border-bottom-width': ['length'],
'border-left-width': ['length'],
'border-top-color': ['color'],
'border-right-color': ['color'],
'border-bottom-color': ['color'],
'border-left-color': ['color'],
'padding-bottom': ['length'],
'padding-left': ['length'],
'padding-right': ['length'],
'padding-top': ['length'],
'margin-bottom': ['length'],
'margin-left': ['length'],
'margin-right': ['length'],
'margin-top': ['length'],
'height': ['length', 'percentage'],
'width': ['length', 'percentage'],
'min-height': ['length', 'percentage'],
'min-width': ['length', 'percentage'],
'max-height': ['length', 'percentage'],
'max-width': ['length', 'percentage'],
'top': ['length', 'percentage'],
'right': ['length', 'percentage'],
'bottom': ['length', 'percentage'],
'left': ['length', 'percentage'],
'color': ['color'],
'font-size': ['length', 'percentage'],
'font-weight': ['font-weight'],
'line-height': ['number', 'length', 'percentage'],
'letter-spacing': ['length'],
// Note: percentage is Level3 and not implemented anywhere yet
// https://drafts.csswg.org/css3-text/#word-spacing
'word-spacing': ['length', 'percentage'],
'text-indent': ['length', 'percentage'],
'text-shadow': ['shadow'],
'outline-color': ['color'],
// outline-offset <integer> used to be an error in the spec
'outline-offset': ['length'],
'outline-width': ['length'],
'clip': ['rectangle'],
'vertical-align': ['length', 'percentage'],
'opacity': ['number[0,1]'],
'visibility': ['visibility'],
'z-index': ['integer']
};
/*
* Property to Type table
* (missing value-types of specified properties)
*/
var missing_properties = {
'margin-bottom': ['percentage'],
'margin-left': ['percentage'],
'margin-right': ['percentage'],
'margin-top': ['percentage'],
'padding-bottom': ['percentage'],
'padding-left': ['percentage'],
'padding-right': ['percentage'],
'padding-top': ['percentage'],
'vertical-align': ['vertical']
};
/*
* Property to Type table
* (properties that haven't been specified but implemented)
*/
var unspecified_properties = {
// http://oli.jp/2010/css-animatable-properties/
'border-top-left-radius': ['border-radius'],
'border-top-right-radius': ['border-radius'],
'border-bottom-left-radius': ['border-radius'],
'border-bottom-right-radius': ['border-radius'],
'background-image': ['image'],
'background-size': ['background-size'],
// https://drafts.csswg.org/css3-background/#the-box-shadow
// Animatable: yes, except between inner and outer shadows (Transition to/from an absent shadow is a transition to/from ‘0 0 transparent’ or ‘0 0 transparent inset’, as appropriate.)
'box-shadow': ['box-shadow'],
'font-size-adjust': ['number'],
'font-stretch': ['font-stretch'],
'text-decoration-color': ['color'],
'column-count': ['integer'],
'column-gap': ['length'],
'column-rule-color': ['color'],
'column-rule-width': ['length'],
'column-width': ['length'],
'transform': ['transform'],
'transform-origin': ['horizontal'],
'display': ['display'],
'position': ['position'],
'object-view-box': ['object-view-box']
};
/*
* additional styles required to actually render
* (different browsers expect different environment)
*/
var additional_styles = {
// all browsers
'border-top-width': {'border-top-style' : 'solid'},
'border-right-width': {'border-right-style' : 'solid'},
'border-bottom-width': {'border-bottom-style' : 'solid'},
'border-left-width': {'border-left-style' : 'solid'},
'top': {'position': 'absolute'},
'right': {'position': 'absolute'},
'bottom': {'position': 'absolute'},
'left': {'position': 'absolute'},
'z-index': {'position': 'absolute'},
'outline-offset': {'outline-style': 'solid'},
'outline-width': {'outline-style': 'solid'},
'word-spacing': {'width': '100px', 'height': '100px'},
// unspecified properties
'column-rule-width': {'column-rule-style': 'solid'},
'position': {'width': '50px', 'height': '50px', top: '10px', left: '50px'}
};
/*
* additional styles required *on the parent* to actually render
* (different browsers expect different environment)
*/
var parent_styles = {
'border-top-width': {'border-top-style' : 'solid'},
'border-right-width': {'border-right-style' : 'solid'},
'border-bottom-width': {'border-bottom-style' : 'solid'},
'border-left-width': {'border-left-style' : 'solid'},
'height': {'width': '100px', 'height': '100px'},
'min-height': {'width': '100px', 'height': '100px'},
'max-height': {'width': '100px', 'height': '100px'},
'width': {'width': '100px', 'height': '100px'},
'min-width': {'width': '100px', 'height': '100px'},
'max-width': {'width': '100px', 'height': '100px'},
// unspecified properties
'position': {'position': 'relative', 'width': '100px', 'height': '100px'},
// inheritance tests
'top': {'width': '100px', 'height': '100px', 'position': 'relative'},
'right': {'width': '100px', 'height': '100px', 'position': 'relative'},
'bottom': {'width': '100px', 'height': '100px', 'position': 'relative'},
'left': {'width': '100px', 'height': '100px', 'position': 'relative'}
};
function assemble(props) {
var tests = [];
// assemble tests
for (var property in props) {
props[property].forEach(function(type) {
var _values = values[type](property);
Object.keys(_values).forEach(function(unit) {
var data = {
name: property + ' ' + type + '(' + unit + ')',
property: property,
valueType : type,
unit : unit,
parentStyle: extend({}, parent_styles[property] || {}),
from: extend({}, additional_styles[property] || {}),
to: {}
};
data.from[property] = _values[unit][0];
data.to[property] = _values[unit][1];
data.flags = _values[unit][2] || {};
tests.push(data);
});
});
}
return tests;
}
root.getPropertyTests = function() {
return assemble(properties);
};
root.getMissingPropertyTests = function() {
return assemble(missing_properties);
};
root.getUnspecifiedPropertyTests = function() {
return assemble(unspecified_properties);
};
root.getFontSizeRelativePropertyTests = function() {
var accepted = {};
for (var key in properties) {
if (!Object.prototype.hasOwnProperty.call(properties, key) || key === "font-size") {
continue;
}
if (properties[key].indexOf('length') > -1) {
accepted[key] = ['length-em'];
}
}
return assemble(accepted);
};
root.filterPropertyTests = function(tests, names) {
var allowed = {};
var accepted = [];
if (typeof names === "string") {
names = [names];
}
if (!(names instanceof RegExp)) {
names.forEach(function(name) {
allowed[name] = true;
});
}
tests.forEach(function(test) {
if (names instanceof RegExp) {
if (!test.name.match(names)) {
return;
}
} else if (!allowed[test.name]) {
return;
}
accepted.push(test);
});
return accepted;
};
})(window);
|