cssstyle 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/lib/CSSStyleDeclaration.js +18 -18
  3. package/lib/CSSStyleDeclaration.test.js +12 -6
  4. package/lib/allProperties.js +76 -9
  5. package/lib/allWebkitProperties.js +1 -1
  6. package/lib/implementedProperties.js +1 -1
  7. package/lib/parsers.js +32 -20
  8. package/lib/parsers.test.js +7 -0
  9. package/lib/properties/azimuth.js +3 -6
  10. package/lib/properties/backgroundAttachment.js +2 -2
  11. package/lib/properties/backgroundColor.js +2 -2
  12. package/lib/properties/backgroundImage.js +2 -2
  13. package/lib/properties/backgroundPosition.js +3 -3
  14. package/lib/properties/backgroundRepeat.js +2 -2
  15. package/lib/properties/border.js +1 -1
  16. package/lib/properties/borderBottomColor.js +2 -2
  17. package/lib/properties/borderBottomStyle.js +2 -2
  18. package/lib/properties/borderBottomWidth.js +2 -2
  19. package/lib/properties/borderCollapse.js +2 -2
  20. package/lib/properties/borderColor.js +2 -2
  21. package/lib/properties/borderLeftColor.js +2 -2
  22. package/lib/properties/borderLeftStyle.js +2 -2
  23. package/lib/properties/borderLeftWidth.js +2 -2
  24. package/lib/properties/borderRightColor.js +2 -2
  25. package/lib/properties/borderRightStyle.js +2 -2
  26. package/lib/properties/borderRightWidth.js +2 -2
  27. package/lib/properties/borderSpacing.js +3 -3
  28. package/lib/properties/borderStyle.js +2 -2
  29. package/lib/properties/borderTopColor.js +2 -2
  30. package/lib/properties/borderTopStyle.js +2 -2
  31. package/lib/properties/borderTopWidth.js +2 -2
  32. package/lib/properties/borderWidth.js +2 -2
  33. package/lib/properties/bottom.js +2 -2
  34. package/lib/properties/clear.js +2 -2
  35. package/lib/properties/clip.js +4 -4
  36. package/lib/properties/color.js +2 -2
  37. package/lib/properties/cssFloat.js +2 -2
  38. package/lib/properties/flex.js +2 -4
  39. package/lib/properties/flexBasis.js +2 -2
  40. package/lib/properties/flexGrow.js +2 -2
  41. package/lib/properties/flexShrink.js +2 -2
  42. package/lib/properties/float.js +2 -2
  43. package/lib/properties/floodColor.js +2 -2
  44. package/lib/properties/font.js +1 -1
  45. package/lib/properties/fontFamily.js +2 -2
  46. package/lib/properties/fontSize.js +4 -4
  47. package/lib/properties/fontStyle.js +3 -3
  48. package/lib/properties/fontVariant.js +2 -2
  49. package/lib/properties/fontWeight.js +2 -2
  50. package/lib/properties/height.js +2 -2
  51. package/lib/properties/left.js +2 -2
  52. package/lib/properties/lightingColor.js +2 -2
  53. package/lib/properties/lineHeight.js +2 -2
  54. package/lib/properties/margin.js +6 -6
  55. package/lib/properties/marginBottom.js +1 -1
  56. package/lib/properties/marginLeft.js +1 -1
  57. package/lib/properties/marginRight.js +1 -1
  58. package/lib/properties/marginTop.js +1 -1
  59. package/lib/properties/opacity.js +2 -2
  60. package/lib/properties/outlineColor.js +2 -2
  61. package/lib/properties/padding.js +6 -6
  62. package/lib/properties/paddingBottom.js +1 -1
  63. package/lib/properties/paddingLeft.js +1 -1
  64. package/lib/properties/paddingRight.js +1 -1
  65. package/lib/properties/paddingTop.js +1 -1
  66. package/lib/properties/right.js +2 -2
  67. package/lib/properties/stopColor.js +2 -2
  68. package/lib/properties/textLineThroughColor.js +2 -2
  69. package/lib/properties/textOverlineColor.js +2 -2
  70. package/lib/properties/textUnderlineColor.js +2 -2
  71. package/lib/properties/top.js +2 -2
  72. package/lib/properties/webkitBorderAfterColor.js +2 -2
  73. package/lib/properties/webkitBorderBeforeColor.js +2 -2
  74. package/lib/properties/webkitBorderEndColor.js +2 -2
  75. package/lib/properties/webkitBorderStartColor.js +2 -2
  76. package/lib/properties/webkitColumnRuleColor.js +2 -2
  77. package/lib/properties/webkitMatchNearestMailBlockquoteColor.js +2 -2
  78. package/lib/properties/webkitTapHighlightColor.js +2 -2
  79. package/lib/properties/webkitTextEmphasisColor.js +2 -2
  80. package/lib/properties/webkitTextFillColor.js +2 -2
  81. package/lib/properties/webkitTextStrokeColor.js +2 -2
  82. package/lib/properties/width.js +2 -2
  83. package/lib/properties.js +1 -1
  84. package/lib/utils/getBasicPropertyDescriptor.js +2 -2
  85. package/package.json +15 -15
package/README.md CHANGED
@@ -10,6 +10,6 @@ A Node JS implementation of the CSS Object Model [CSSStyleDeclaration interface]
10
10
 
11
11
  This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's [CSSOM](https://github.com/NV/CSSOM) with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.
12
12
 
13
- It was originally created by Chad Walker, it is now maintaind by Jon Sakas and other open source contributors.
13
+ It was originally created by Chad Walker, it is now maintained by the jsdom community.
14
14
 
15
15
  Bug reports and pull requests are welcome.
@@ -3,7 +3,7 @@
3
3
  * https://github.com/NV/CSSOM
4
4
  ********************************************************************/
5
5
  'use strict';
6
- var CSSOM = require('cssom');
6
+ var CSSOM = require('rrweb-cssom');
7
7
  var allProperties = require('./allProperties');
8
8
  var allExtraProperties = require('./allExtraProperties');
9
9
  var implementedProperties = require('./implementedProperties');
@@ -20,7 +20,7 @@ var CSSStyleDeclaration = function CSSStyleDeclaration(onChangeCallback) {
20
20
  this._length = 0;
21
21
  this._onChange =
22
22
  onChangeCallback ||
23
- function() {
23
+ function () {
24
24
  return;
25
25
  };
26
26
  };
@@ -34,7 +34,7 @@ CSSStyleDeclaration.prototype = {
34
34
  * @return {string} the value of the property if it has been explicitly set for this declaration block.
35
35
  * Returns the empty string if the property has not been set.
36
36
  */
37
- getPropertyValue: function(name) {
37
+ getPropertyValue: function (name) {
38
38
  if (!this._values.hasOwnProperty(name)) {
39
39
  return '';
40
40
  }
@@ -48,7 +48,7 @@ CSSStyleDeclaration.prototype = {
48
48
  * @param {string} [priority=null] "important" or null
49
49
  * @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-setProperty
50
50
  */
51
- setProperty: function(name, value, priority) {
51
+ setProperty: function (name, value, priority) {
52
52
  if (value === undefined) {
53
53
  return;
54
54
  }
@@ -69,7 +69,7 @@ CSSStyleDeclaration.prototype = {
69
69
  this[lowercaseName] = value;
70
70
  this._importants[lowercaseName] = priority;
71
71
  },
72
- _setProperty: function(name, value, priority) {
72
+ _setProperty: function (name, value, priority) {
73
73
  if (value === undefined) {
74
74
  return;
75
75
  }
@@ -101,7 +101,7 @@ CSSStyleDeclaration.prototype = {
101
101
  * @return {string} the value of the property if it has been explicitly set for this declaration block.
102
102
  * Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property.
103
103
  */
104
- removeProperty: function(name) {
104
+ removeProperty: function (name) {
105
105
  if (!this._values.hasOwnProperty(name)) {
106
106
  return '';
107
107
  }
@@ -129,11 +129,11 @@ CSSStyleDeclaration.prototype = {
129
129
  *
130
130
  * @param {String} name
131
131
  */
132
- getPropertyPriority: function(name) {
132
+ getPropertyPriority: function (name) {
133
133
  return this._importants[name] || '';
134
134
  },
135
135
 
136
- getPropertyCSSValue: function() {
136
+ getPropertyCSSValue: function () {
137
137
  //FIXME
138
138
  return;
139
139
  },
@@ -143,12 +143,12 @@ CSSStyleDeclaration.prototype = {
143
143
  * element.style.getPropertyShorthand("overflow-x")
144
144
  * -> "overflow"
145
145
  */
146
- getPropertyShorthand: function() {
146
+ getPropertyShorthand: function () {
147
147
  //FIXME
148
148
  return;
149
149
  },
150
150
 
151
- isPropertyImplicit: function() {
151
+ isPropertyImplicit: function () {
152
152
  //FIXME
153
153
  return;
154
154
  },
@@ -156,7 +156,7 @@ CSSStyleDeclaration.prototype = {
156
156
  /**
157
157
  * http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-item
158
158
  */
159
- item: function(index) {
159
+ item: function (index) {
160
160
  index = parseInt(index, 10);
161
161
  if (index < 0 || index >= this._length) {
162
162
  return '';
@@ -167,7 +167,7 @@ CSSStyleDeclaration.prototype = {
167
167
 
168
168
  Object.defineProperties(CSSStyleDeclaration.prototype, {
169
169
  cssText: {
170
- get: function() {
170
+ get: function () {
171
171
  var properties = [];
172
172
  var i;
173
173
  var name;
@@ -184,7 +184,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
184
184
  }
185
185
  return properties.join(' ');
186
186
  },
187
- set: function(value) {
187
+ set: function (value) {
188
188
  var i;
189
189
  this._values = {};
190
190
  Array.prototype.splice.call(this, 0, this._length);
@@ -212,14 +212,14 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
212
212
  configurable: true,
213
213
  },
214
214
  parentRule: {
215
- get: function() {
215
+ get: function () {
216
216
  return null;
217
217
  },
218
218
  enumerable: true,
219
219
  configurable: true,
220
220
  },
221
221
  length: {
222
- get: function() {
222
+ get: function () {
223
223
  return this._length;
224
224
  },
225
225
  /**
@@ -227,7 +227,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
227
227
  * length. If the new length is more, it does nothing, the new indices
228
228
  * will be undefined until set.
229
229
  **/
230
- set: function(value) {
230
+ set: function (value) {
231
231
  var i;
232
232
  for (i = value; i < this._length; i++) {
233
233
  delete this[i];
@@ -241,7 +241,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
241
241
 
242
242
  require('./properties')(CSSStyleDeclaration.prototype);
243
243
 
244
- allProperties.forEach(function(property) {
244
+ allProperties.forEach(function (property) {
245
245
  if (!implementedProperties.has(property)) {
246
246
  var declaration = getBasicPropertyDescriptor(property);
247
247
  Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
@@ -249,7 +249,7 @@ allProperties.forEach(function(property) {
249
249
  }
250
250
  });
251
251
 
252
- allExtraProperties.forEach(function(property) {
252
+ allExtraProperties.forEach(function (property) {
253
253
  if (!implementedProperties.has(property)) {
254
254
  var declaration = getBasicPropertyDescriptor(property);
255
255
  Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
@@ -10,7 +10,7 @@ var parsers = require('./parsers');
10
10
  var dashedProperties = [...allProperties, ...allExtraProperties];
11
11
  var allowedProperties = dashedProperties.map(parsers.dashedToCamelCase);
12
12
  implementedProperties = Array.from(implementedProperties).map(parsers.dashedToCamelCase);
13
- var invalidProperties = implementedProperties.filter(prop => !allowedProperties.includes(prop));
13
+ var invalidProperties = implementedProperties.filter((prop) => !allowedProperties.includes(prop));
14
14
 
15
15
  describe('CSSStyleDeclaration', () => {
16
16
  test('has only valid properties implemented', () => {
@@ -19,7 +19,7 @@ describe('CSSStyleDeclaration', () => {
19
19
 
20
20
  test('has all properties', () => {
21
21
  var style = new CSSStyleDeclaration();
22
- allProperties.forEach(property => {
22
+ allProperties.forEach((property) => {
23
23
  expect(style.__lookupGetter__(property)).toBeTruthy();
24
24
  expect(style.__lookupSetter__(property)).toBeTruthy();
25
25
  });
@@ -27,7 +27,7 @@ describe('CSSStyleDeclaration', () => {
27
27
 
28
28
  test('has dashed properties', () => {
29
29
  var style = new CSSStyleDeclaration();
30
- dashedProperties.forEach(property => {
30
+ dashedProperties.forEach((property) => {
31
31
  expect(style.__lookupGetter__(property)).toBeTruthy();
32
32
  expect(style.__lookupSetter__(property)).toBeTruthy();
33
33
  });
@@ -302,7 +302,7 @@ describe('CSSStyleDeclaration', () => {
302
302
  test('padding and margin should set/clear shorthand properties', () => {
303
303
  var style = new CSSStyleDeclaration();
304
304
  var parts = ['Top', 'Right', 'Bottom', 'Left'];
305
- var testParts = function(name, v, V) {
305
+ var testParts = function (name, v, V) {
306
306
  style[name] = v;
307
307
  for (var i = 0; i < 4; i++) {
308
308
  var part = name + parts[i];
@@ -329,7 +329,7 @@ describe('CSSStyleDeclaration', () => {
329
329
  test('padding and margin shorthands should set main properties', () => {
330
330
  var style = new CSSStyleDeclaration();
331
331
  var parts = ['Top', 'Right', 'Bottom', 'Left'];
332
- var testParts = function(name, v, V) {
332
+ var testParts = function (name, v, V) {
333
333
  var expected;
334
334
  for (var i = 0; i < 4; i++) {
335
335
  style[name] = v;
@@ -353,7 +353,7 @@ describe('CSSStyleDeclaration', () => {
353
353
  });
354
354
 
355
355
  test('onchange callback should be called when the csstext changes', () => {
356
- var style = new CSSStyleDeclaration(function(cssText) {
356
+ var style = new CSSStyleDeclaration(function (cssText) {
357
357
  expect(cssText).toEqual('opacity: 0;');
358
358
  });
359
359
  style.setProperty('opacity', 0);
@@ -547,4 +547,10 @@ describe('CSSStyleDeclaration', () => {
547
547
  expect(style.getPropertyValue('--foo')).toEqual('');
548
548
  expect(style.getPropertyValue('--fOo')).toEqual('purple');
549
549
  });
550
+
551
+ test('supports calc', () => {
552
+ const style = new CSSStyleDeclaration();
553
+ style.setProperty('width', 'calc(100% - 100px)');
554
+ expect(style.getPropertyValue('width')).toEqual('calc(100% - 100px)');
555
+ });
550
556
  });
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // autogenerated - 1/20/2020
3
+ // autogenerated - 1/22/2023
4
4
 
5
5
  /*
6
6
  *
@@ -8,6 +8,8 @@
8
8
  */
9
9
 
10
10
  module.exports = new Set([
11
+ '-webkit-line-clamp',
12
+ 'accent-color',
11
13
  'align-content',
12
14
  'align-items',
13
15
  'align-self',
@@ -15,15 +17,20 @@ module.exports = new Set([
15
17
  'all',
16
18
  'animation',
17
19
  'animation-delay',
20
+ 'animation-delay-end',
21
+ 'animation-delay-start',
18
22
  'animation-direction',
19
23
  'animation-duration',
20
24
  'animation-fill-mode',
21
25
  'animation-iteration-count',
22
26
  'animation-name',
23
27
  'animation-play-state',
28
+ 'animation-range',
24
29
  'animation-timing-function',
25
30
  'appearance',
31
+ 'aspect-ratio',
26
32
  'azimuth',
33
+ 'backface-visibility',
27
34
  'background',
28
35
  'background-attachment',
29
36
  'background-blend-mode',
@@ -35,7 +42,8 @@ module.exports = new Set([
35
42
  'background-repeat',
36
43
  'background-size',
37
44
  'baseline-shift',
38
- 'block-overflow',
45
+ 'baseline-source',
46
+ 'block-ellipsis',
39
47
  'block-size',
40
48
  'bookmark-label',
41
49
  'bookmark-level',
@@ -134,7 +142,16 @@ module.exports = new Set([
134
142
  'column-width',
135
143
  'columns',
136
144
  'contain',
145
+ 'contain-intrinsic-block-size',
146
+ 'contain-intrinsic-height',
147
+ 'contain-intrinsic-inline-size',
148
+ 'contain-intrinsic-size',
149
+ 'contain-intrinsic-width',
150
+ 'container',
151
+ 'container-name',
152
+ 'container-type',
137
153
  'content',
154
+ 'content-visibility',
138
155
  'continue',
139
156
  'counter-increment',
140
157
  'counter-reset',
@@ -218,9 +235,9 @@ module.exports = new Set([
218
235
  'image-orientation',
219
236
  'image-rendering',
220
237
  'image-resolution',
221
- 'initial-letters',
222
- 'initial-letters-align',
223
- 'initial-letters-wrap',
238
+ 'initial-letter',
239
+ 'initial-letter-align',
240
+ 'initial-letter-wrap',
224
241
  'inline-size',
225
242
  'inline-sizing',
226
243
  'inset',
@@ -234,6 +251,7 @@ module.exports = new Set([
234
251
  'justify-content',
235
252
  'justify-items',
236
253
  'justify-self',
254
+ 'leading-trim',
237
255
  'left',
238
256
  'letter-spacing',
239
257
  'lighting-color',
@@ -285,6 +303,7 @@ module.exports = new Set([
285
303
  'min-block-size',
286
304
  'min-height',
287
305
  'min-inline-size',
306
+ 'min-intrinsic-sizing',
288
307
  'min-width',
289
308
  'mix-blend-mode',
290
309
  'nav-down',
@@ -294,15 +313,11 @@ module.exports = new Set([
294
313
  'object-fit',
295
314
  'object-position',
296
315
  'offset',
297
- 'offset-after',
298
316
  'offset-anchor',
299
- 'offset-before',
300
317
  'offset-distance',
301
- 'offset-end',
302
318
  'offset-path',
303
319
  'offset-position',
304
320
  'offset-rotate',
305
- 'offset-start',
306
321
  'opacity',
307
322
  'order',
308
323
  'orphans',
@@ -312,7 +327,19 @@ module.exports = new Set([
312
327
  'outline-style',
313
328
  'outline-width',
314
329
  'overflow',
330
+ 'overflow-anchor',
315
331
  'overflow-block',
332
+ 'overflow-clip-margin',
333
+ 'overflow-clip-margin-block',
334
+ 'overflow-clip-margin-block-end',
335
+ 'overflow-clip-margin-block-start',
336
+ 'overflow-clip-margin-bottom',
337
+ 'overflow-clip-margin-inline',
338
+ 'overflow-clip-margin-inline-end',
339
+ 'overflow-clip-margin-inline-start',
340
+ 'overflow-clip-margin-left',
341
+ 'overflow-clip-margin-right',
342
+ 'overflow-clip-margin-top',
316
343
  'overflow-inline',
317
344
  'overflow-wrap',
318
345
  'overflow-x',
@@ -335,6 +362,8 @@ module.exports = new Set([
335
362
  'pause',
336
363
  'pause-after',
337
364
  'pause-before',
365
+ 'perspective',
366
+ 'perspective-origin',
338
367
  'pitch',
339
368
  'pitch-range',
340
369
  'place-content',
@@ -342,16 +371,23 @@ module.exports = new Set([
342
371
  'place-self',
343
372
  'play-during',
344
373
  'position',
374
+ 'print-color-adjust',
345
375
  'quotes',
346
376
  'region-fragment',
347
377
  'resize',
378
+ 'rest',
379
+ 'rest-after',
380
+ 'rest-before',
348
381
  'richness',
349
382
  'right',
383
+ 'rotate',
350
384
  'row-gap',
351
385
  'ruby-align',
352
386
  'ruby-merge',
387
+ 'ruby-overhang',
353
388
  'ruby-position',
354
389
  'running',
390
+ 'scale',
355
391
  'scroll-behavior',
356
392
  'scroll-margin',
357
393
  'scroll-margin-block',
@@ -378,6 +414,12 @@ module.exports = new Set([
378
414
  'scroll-snap-align',
379
415
  'scroll-snap-stop',
380
416
  'scroll-snap-type',
417
+ 'scroll-timeline',
418
+ 'scroll-timeline-axis',
419
+ 'scroll-timeline-name',
420
+ 'scrollbar-color',
421
+ 'scrollbar-gutter',
422
+ 'scrollbar-width',
381
423
  'shape-image-threshold',
382
424
  'shape-inside',
383
425
  'shape-margin',
@@ -386,6 +428,7 @@ module.exports = new Set([
386
428
  'spatial-navigation-contain',
387
429
  'spatial-navigation-function',
388
430
  'speak',
431
+ 'speak-as',
389
432
  'speak-header',
390
433
  'speak-numeral',
391
434
  'speak-punctuation',
@@ -401,10 +444,19 @@ module.exports = new Set([
401
444
  'text-decoration',
402
445
  'text-decoration-color',
403
446
  'text-decoration-line',
447
+ 'text-decoration-skip',
448
+ 'text-decoration-skip-box',
449
+ 'text-decoration-skip-ink',
450
+ 'text-decoration-skip-inset',
451
+ 'text-decoration-skip-self',
452
+ 'text-decoration-skip-spaces',
404
453
  'text-decoration-style',
454
+ 'text-decoration-thickness',
455
+ 'text-edge',
405
456
  'text-emphasis',
406
457
  'text-emphasis-color',
407
458
  'text-emphasis-position',
459
+ 'text-emphasis-skip',
408
460
  'text-emphasis-style',
409
461
  'text-group-align',
410
462
  'text-indent',
@@ -416,22 +468,37 @@ module.exports = new Set([
416
468
  'text-space-trim',
417
469
  'text-spacing',
418
470
  'text-transform',
471
+ 'text-underline-offset',
419
472
  'text-underline-position',
420
473
  'text-wrap',
421
474
  'top',
422
475
  'transform',
423
476
  'transform-box',
424
477
  'transform-origin',
478
+ 'transform-style',
425
479
  'transition',
426
480
  'transition-delay',
427
481
  'transition-duration',
428
482
  'transition-property',
429
483
  'transition-timing-function',
484
+ 'translate',
430
485
  'unicode-bidi',
431
486
  'user-select',
432
487
  'vertical-align',
488
+ 'view-timeline',
489
+ 'view-timeline-axis',
490
+ 'view-timeline-inset',
491
+ 'view-timeline-name',
492
+ 'view-transition-name',
433
493
  'visibility',
494
+ 'voice-balance',
495
+ 'voice-duration',
434
496
  'voice-family',
497
+ 'voice-pitch',
498
+ 'voice-range',
499
+ 'voice-rate',
500
+ 'voice-stress',
501
+ 'voice-volume',
435
502
  'volume',
436
503
  'white-space',
437
504
  'widows',
@@ -191,4 +191,4 @@ module.exports = [
191
191
  'wrap-through',
192
192
  'writing-mode',
193
193
  'zoom',
194
- ].map(prop => 'webkit-' + prop);
194
+ ].map((prop) => 'webkit-' + prop);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // autogenerated - 1/23/2020
3
+ // autogenerated - 2/12/2023
4
4
 
5
5
  /*
6
6
  *
package/lib/parsers.js CHANGED
@@ -18,6 +18,7 @@ exports.TYPES = {
18
18
  ANGLE: 8,
19
19
  KEYWORD: 9,
20
20
  NULL_OR_EMPTY_STR: 10,
21
+ CALC: 11,
21
22
  };
22
23
 
23
24
  // rough regular expressions
@@ -30,7 +31,9 @@ var stringRegEx = /^("[^"]*"|'[^']*')$/;
30
31
  var colorRegEx1 = /^#([0-9a-fA-F]{3,4}){1,2}$/;
31
32
  var colorRegEx2 = /^rgb\(([^)]*)\)$/;
32
33
  var colorRegEx3 = /^rgba\(([^)]*)\)$/;
33
- var colorRegEx4 = /^hsla?\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*(,\s*(-?\d+|-?\d*.\d+)\s*)?\)/;
34
+ var calcRegEx = /^calc\(([^)]*)\)$/;
35
+ var colorRegEx4 =
36
+ /^hsla?\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*(,\s*(-?\d+|-?\d*.\d+)\s*)?\)/;
34
37
  var angleRegEx = /^([-+]?[0-9]*\.?[0-9]+)(deg|grad|rad)$/;
35
38
 
36
39
  // This will return one of the above types based on the passed in string
@@ -61,6 +64,9 @@ exports.valueType = function valueType(val) {
61
64
  if (urlRegEx.test(val)) {
62
65
  return exports.TYPES.URL;
63
66
  }
67
+ if (calcRegEx.test(val)) {
68
+ return exports.TYPES.CALC;
69
+ }
64
70
  if (stringRegEx.test(val)) {
65
71
  return exports.TYPES.STRING;
66
72
  }
@@ -70,6 +76,7 @@ exports.valueType = function valueType(val) {
70
76
  if (colorRegEx1.test(val)) {
71
77
  return exports.TYPES.COLOR;
72
78
  }
79
+
73
80
  var res = colorRegEx2.exec(val);
74
81
  var parts;
75
82
  if (res !== null) {
@@ -201,6 +208,11 @@ exports.parsePercent = function parsePercent(val) {
201
208
 
202
209
  // either a length or a percent
203
210
  exports.parseMeasurement = function parseMeasurement(val) {
211
+ var type = exports.valueType(val);
212
+ if (type === exports.TYPES.CALC) {
213
+ return val;
214
+ }
215
+
204
216
  var length = exports.parseLength(val);
205
217
  if (length !== undefined) {
206
218
  return length;
@@ -437,7 +449,7 @@ exports.parseKeyword = function parseKeyword(val, valid_keywords) {
437
449
  };
438
450
 
439
451
  // utility to translate from border-width to borderWidth
440
- var dashedToCamelCase = function(dashed) {
452
+ var dashedToCamelCase = function (dashed) {
441
453
  var i;
442
454
  var camel = '';
443
455
  var nextCap = false;
@@ -457,7 +469,7 @@ var is_space = /\s/;
457
469
  var opening_deliminators = ['"', "'", '('];
458
470
  var closing_deliminators = ['"', "'", ')'];
459
471
  // this splits on whitespace, but keeps quoted and parened parts together
460
- var getParts = function(str) {
472
+ var getParts = function (str) {
461
473
  var deliminator_stack = [];
462
474
  var length = str.length;
463
475
  var i;
@@ -510,7 +522,7 @@ exports.shorthandParser = function parse(v, shorthand_for) {
510
522
  var obj = {};
511
523
  var type = exports.valueType(v);
512
524
  if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
513
- Object.keys(shorthand_for).forEach(function(property) {
525
+ Object.keys(shorthand_for).forEach(function (property) {
514
526
  obj[property] = '';
515
527
  });
516
528
  return obj;
@@ -529,9 +541,9 @@ exports.shorthandParser = function parse(v, shorthand_for) {
529
541
  }
530
542
  var parts = getParts(v);
531
543
  var valid = true;
532
- parts.forEach(function(part, i) {
544
+ parts.forEach(function (part, i) {
533
545
  var part_valid = false;
534
- Object.keys(shorthand_for).forEach(function(property) {
546
+ Object.keys(shorthand_for).forEach(function (property) {
535
547
  if (shorthand_for[property].isValid(part, i)) {
536
548
  part_valid = true;
537
549
  obj[property] = part;
@@ -545,14 +557,14 @@ exports.shorthandParser = function parse(v, shorthand_for) {
545
557
  return obj;
546
558
  };
547
559
 
548
- exports.shorthandSetter = function(property, shorthand_for) {
549
- return function(v) {
560
+ exports.shorthandSetter = function (property, shorthand_for) {
561
+ return function (v) {
550
562
  var obj = exports.shorthandParser(v, shorthand_for);
551
563
  if (obj === undefined) {
552
564
  return;
553
565
  }
554
566
  //console.log('shorthandSetter for:', property, 'obj:', obj);
555
- Object.keys(obj).forEach(function(subprop) {
567
+ Object.keys(obj).forEach(function (subprop) {
556
568
  // in case subprop is an implicit property, this will clear
557
569
  // *its* subpropertiesX
558
570
  var camel = dashedToCamelCase(subprop);
@@ -565,7 +577,7 @@ exports.shorthandSetter = function(property, shorthand_for) {
565
577
  this._values[subprop] = obj[subprop];
566
578
  }
567
579
  }, this);
568
- Object.keys(shorthand_for).forEach(function(subprop) {
580
+ Object.keys(shorthand_for).forEach(function (subprop) {
569
581
  if (!obj.hasOwnProperty(subprop)) {
570
582
  this.removeProperty(subprop);
571
583
  delete this._values[subprop];
@@ -583,16 +595,16 @@ exports.shorthandSetter = function(property, shorthand_for) {
583
595
  };
584
596
  };
585
597
 
586
- exports.shorthandGetter = function(property, shorthand_for) {
587
- return function() {
598
+ exports.shorthandGetter = function (property, shorthand_for) {
599
+ return function () {
588
600
  if (this._values[property] !== undefined) {
589
601
  return this.getPropertyValue(property);
590
602
  }
591
603
  return Object.keys(shorthand_for)
592
- .map(function(subprop) {
604
+ .map(function (subprop) {
593
605
  return this.getPropertyValue(subprop);
594
606
  }, this)
595
- .filter(function(value) {
607
+ .filter(function (value) {
596
608
  return value !== '';
597
609
  })
598
610
  .join(' ');
@@ -604,14 +616,14 @@ exports.shorthandGetter = function(property, shorthand_for) {
604
616
  // if two, the first applies to the top and bottom, and the second to left and right
605
617
  // if three, the first applies to the top, the second to left and right, the third bottom
606
618
  // if four, top, right, bottom, left
607
- exports.implicitSetter = function(property_before, property_after, isValid, parser) {
619
+ exports.implicitSetter = function (property_before, property_after, isValid, parser) {
608
620
  property_after = property_after || '';
609
621
  if (property_after !== '') {
610
622
  property_after = '-' + property_after;
611
623
  }
612
624
  var part_names = ['top', 'right', 'bottom', 'left'];
613
625
 
614
- return function(v) {
626
+ return function (v) {
615
627
  if (typeof v === 'number') {
616
628
  v = v.toString();
617
629
  }
@@ -632,7 +644,7 @@ exports.implicitSetter = function(property_before, property_after, isValid, pars
632
644
  return undefined;
633
645
  }
634
646
 
635
- parts = parts.map(function(part) {
647
+ parts = parts.map(function (part) {
636
648
  return parser(part);
637
649
  });
638
650
  this._setProperty(property_before + property_after, parts.join(' '));
@@ -663,11 +675,11 @@ exports.implicitSetter = function(property_before, property_after, isValid, pars
663
675
  // sub-parts are set. If so, it sets the shorthand version and removes
664
676
  // the individual parts from the cssText.
665
677
  //
666
- exports.subImplicitSetter = function(prefix, part, isValid, parser) {
678
+ exports.subImplicitSetter = function (prefix, part, isValid, parser) {
667
679
  var property = prefix + '-' + part;
668
680
  var subparts = [prefix + '-top', prefix + '-right', prefix + '-bottom', prefix + '-left'];
669
681
 
670
- return function(v) {
682
+ return function (v) {
671
683
  if (typeof v === 'number') {
672
684
  v = v.toString();
673
685
  }
@@ -700,7 +712,7 @@ exports.subImplicitSetter = function(prefix, part, isValid, parser) {
700
712
  var camel_to_dashed = /[A-Z]/g;
701
713
  var first_segment = /^\([^-]\)-/;
702
714
  var vendor_prefixes = ['o', 'moz', 'ms', 'webkit'];
703
- exports.camelToDashed = function(camel_case) {
715
+ exports.camelToDashed = function (camel_case) {
704
716
  var match;
705
717
  var dashed = camel_case.replace(camel_to_dashed, '-$&').toLowerCase();
706
718
  match = dashed.match(first_segment);
@@ -65,6 +65,13 @@ describe('valueType', () => {
65
65
 
66
66
  expect(output).toEqual(parsers.TYPES.LENGTH);
67
67
  });
68
+
69
+ it('returns calc from calc(100px * 2)', () => {
70
+ let input = 'calc(100px * 2)';
71
+ let output = parsers.valueType(input);
72
+
73
+ expect(output).toEqual(parsers.TYPES.CALC);
74
+ });
68
75
  });
69
76
  describe('parseInteger', () => {
70
77
  it.todo('test');