@antv/g 5.0.22-alpha.6 → 5.0.23-alpha.2

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 (156) hide show
  1. package/dist/index.umd.min.js +3 -3
  2. package/es/AbstractRenderer.js +5 -0
  3. package/es/camera/Camera.js +2 -2
  4. package/es/css/cssom/CSSKeywordValue.d.ts +1 -1
  5. package/es/css/cssom/CSSNumericSumValue.d.ts +1 -1
  6. package/es/css/cssom/CSSNumericValue.d.ts +108 -4
  7. package/es/css/cssom/CSSNumericValue.js +908 -5
  8. package/es/css/cssom/CSSNumericValueType.d.ts +1 -1
  9. package/es/css/cssom/CSSNumericValueType.js +1 -1
  10. package/es/css/cssom/CSSTransformValue.d.ts +1 -1
  11. package/es/css/cssom/index.d.ts +0 -9
  12. package/es/css/cssom/index.js +1 -10
  13. package/es/css/parser/color.js +1 -1
  14. package/es/css/parser/dimension.js +1 -2
  15. package/es/css/parser/numeric.js +1 -1
  16. package/es/css/parser/path.d.ts +2 -2
  17. package/es/css/parser/path.js +1 -1
  18. package/es/css/parser/points.js +1 -1
  19. package/es/css/parser/transform-origin.js +1 -1
  20. package/es/css/properties/CSSPropertyPath.d.ts +14 -2
  21. package/es/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  22. package/es/css/properties/CSSPropertyTransform.js +1 -2
  23. package/es/display-objects/DisplayObject.js +4 -5
  24. package/es/display-objects/Path.d.ts +15 -15
  25. package/es/display-objects/Path.js +1 -1
  26. package/es/display-objects/Polygon.d.ts +8 -1
  27. package/es/display-objects/Polyline.d.ts +7 -5
  28. package/es/dom/Document.js +2 -2
  29. package/es/dom/Element.js +1 -2
  30. package/es/dom/EventTarget.js +1 -1
  31. package/es/dom/FederatedTouchEvent.d.ts +5 -3
  32. package/es/plugins/CullingPlugin.d.ts +0 -1
  33. package/es/plugins/CullingPlugin.js +3 -8
  34. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  35. package/es/plugins/DirtyCheckPlugin.js +9 -8
  36. package/es/plugins/EventPlugin.d.ts +1 -1
  37. package/es/plugins/EventPlugin.js +163 -148
  38. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  39. package/es/plugins/PrepareRendererPlugin.js +15 -16
  40. package/es/services/EventService.d.ts +8 -0
  41. package/es/services/EventService.js +274 -20
  42. package/es/services/RenderingService.d.ts +17 -16
  43. package/es/services/RenderingService.js +18 -17
  44. package/es/services/SceneGraphService.js +1 -1
  45. package/es/services/aabb/PathUpdater.d.ts +3 -3
  46. package/es/services/aabb/PolylineUpdater.d.ts +3 -3
  47. package/es/services/aabb/RectUpdater.js +1 -1
  48. package/es/types.d.ts +5 -3
  49. package/es/utils/assert.d.ts +6 -0
  50. package/es/utils/assert.js +18 -0
  51. package/es/utils/event.d.ts +18 -16
  52. package/es/utils/hooks.d.ts +280 -0
  53. package/es/utils/hooks.js +753 -0
  54. package/es/utils/index.d.ts +1 -0
  55. package/es/utils/index.js +2 -1
  56. package/es/utils/math.d.ts +1 -0
  57. package/es/utils/math.js +13 -2
  58. package/es/utils/string.d.ts +1 -0
  59. package/es/utils/string.js +8 -0
  60. package/es/utils/text.js +2 -1
  61. package/lib/AbstractRenderer.js +5 -0
  62. package/lib/camera/Camera.js +4 -4
  63. package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
  64. package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
  65. package/lib/css/cssom/CSSNumericValue.d.ts +108 -4
  66. package/lib/css/cssom/CSSNumericValue.js +965 -52
  67. package/lib/css/cssom/CSSNumericValueType.d.ts +1 -1
  68. package/lib/css/cssom/CSSNumericValueType.js +59 -59
  69. package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
  70. package/lib/css/cssom/index.d.ts +0 -9
  71. package/lib/css/cssom/index.js +0 -117
  72. package/lib/css/parser/color.js +5 -5
  73. package/lib/css/parser/dimension.js +1 -3
  74. package/lib/css/parser/numeric.js +3 -3
  75. package/lib/css/parser/path.d.ts +2 -2
  76. package/lib/css/parser/path.js +4 -4
  77. package/lib/css/parser/points.js +2 -2
  78. package/lib/css/parser/transform-origin.js +2 -2
  79. package/lib/css/properties/CSSPropertyPath.d.ts +14 -2
  80. package/lib/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  81. package/lib/css/properties/CSSPropertyTransform.js +0 -2
  82. package/lib/display-objects/DisplayObject.js +7 -9
  83. package/lib/display-objects/Path.d.ts +15 -15
  84. package/lib/display-objects/Path.js +3 -3
  85. package/lib/display-objects/Polygon.d.ts +8 -1
  86. package/lib/display-objects/Polyline.d.ts +7 -5
  87. package/lib/dom/Document.js +2 -2
  88. package/lib/dom/Element.js +1 -3
  89. package/lib/dom/EventTarget.js +9 -9
  90. package/lib/dom/FederatedTouchEvent.d.ts +5 -3
  91. package/lib/plugins/CullingPlugin.d.ts +0 -1
  92. package/lib/plugins/CullingPlugin.js +3 -7
  93. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  94. package/lib/plugins/DirtyCheckPlugin.js +10 -8
  95. package/lib/plugins/EventPlugin.d.ts +1 -1
  96. package/lib/plugins/EventPlugin.js +172 -156
  97. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  98. package/lib/plugins/PrepareRendererPlugin.js +14 -14
  99. package/lib/services/EventService.d.ts +8 -0
  100. package/lib/services/EventService.js +274 -19
  101. package/lib/services/RenderingService.d.ts +17 -16
  102. package/lib/services/RenderingService.js +19 -18
  103. package/lib/services/SceneGraphService.js +3 -3
  104. package/lib/services/aabb/PathUpdater.d.ts +3 -3
  105. package/lib/services/aabb/PolylineUpdater.d.ts +3 -3
  106. package/lib/services/aabb/RectUpdater.js +3 -3
  107. package/lib/types.d.ts +5 -3
  108. package/lib/utils/assert.d.ts +6 -0
  109. package/lib/utils/assert.js +30 -0
  110. package/lib/utils/event.d.ts +18 -16
  111. package/lib/utils/hooks.d.ts +280 -0
  112. package/lib/utils/hooks.js +759 -0
  113. package/lib/utils/index.d.ts +1 -0
  114. package/lib/utils/index.js +13 -0
  115. package/lib/utils/math.d.ts +1 -0
  116. package/lib/utils/math.js +17 -4
  117. package/lib/utils/string.d.ts +1 -0
  118. package/lib/utils/string.js +11 -0
  119. package/lib/utils/text.js +5 -3
  120. package/package.json +4 -7
  121. package/es/css/cssom/CSSMathInvert.d.ts +0 -14
  122. package/es/css/cssom/CSSMathInvert.js +0 -84
  123. package/es/css/cssom/CSSMathMax.d.ts +0 -17
  124. package/es/css/cssom/CSSMathMax.js +0 -118
  125. package/es/css/cssom/CSSMathMin.d.ts +0 -17
  126. package/es/css/cssom/CSSMathMin.js +0 -119
  127. package/es/css/cssom/CSSMathNegate.d.ts +0 -14
  128. package/es/css/cssom/CSSMathNegate.js +0 -80
  129. package/es/css/cssom/CSSMathProduct.d.ts +0 -16
  130. package/es/css/cssom/CSSMathProduct.js +0 -109
  131. package/es/css/cssom/CSSMathSum.d.ts +0 -17
  132. package/es/css/cssom/CSSMathSum.js +0 -117
  133. package/es/css/cssom/CSSMathValue.d.ts +0 -11
  134. package/es/css/cssom/CSSMathValue.js +0 -27
  135. package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
  136. package/es/css/cssom/CSSMathVariadic.js +0 -44
  137. package/es/css/cssom/CSSUnitValue.d.ts +0 -33
  138. package/es/css/cssom/CSSUnitValue.js +0 -252
  139. package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
  140. package/lib/css/cssom/CSSMathInvert.js +0 -94
  141. package/lib/css/cssom/CSSMathMax.d.ts +0 -17
  142. package/lib/css/cssom/CSSMathMax.js +0 -128
  143. package/lib/css/cssom/CSSMathMin.d.ts +0 -17
  144. package/lib/css/cssom/CSSMathMin.js +0 -128
  145. package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
  146. package/lib/css/cssom/CSSMathNegate.js +0 -89
  147. package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
  148. package/lib/css/cssom/CSSMathProduct.js +0 -119
  149. package/lib/css/cssom/CSSMathSum.d.ts +0 -17
  150. package/lib/css/cssom/CSSMathSum.js +0 -129
  151. package/lib/css/cssom/CSSMathValue.d.ts +0 -11
  152. package/lib/css/cssom/CSSMathValue.js +0 -35
  153. package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
  154. package/lib/css/cssom/CSSMathVariadic.js +0 -55
  155. package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
  156. package/lib/css/cssom/CSSUnitValue.js +0 -267
@@ -3,15 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CSSNumericValue = void 0;
6
+ exports.CSSUnitValue = exports.CSSNumericValue = exports.CSSMathVariadic = exports.CSSMathValue = exports.CSSMathSum = exports.CSSMathProduct = exports.CSSMathNegate = exports.CSSMathMin = exports.CSSMathMax = exports.CSSMathInvert = void 0;
7
+ exports.typeCheck = typeCheck;
7
8
 
8
9
  var _tslib = require("tslib");
9
10
 
10
11
  var _utils = require("../../utils");
11
12
 
13
+ var _CSSMathOperator = require("./CSSMathOperator");
14
+
15
+ var _CSSNumericValueType = require("./CSSNumericValueType");
16
+
12
17
  var _CSSStyleValue = require("./CSSStyleValue");
13
18
 
14
- var _ = require(".");
19
+ var _types = require("./types");
15
20
 
16
21
  /**
17
22
  * CSSNumericValue is the base class for numeric and length typed CSS Values.
@@ -37,7 +42,7 @@ function (_super) {
37
42
 
38
43
  CSSNumericValue.fromNumberish = function (value) {
39
44
  if (typeof value === 'number') {
40
- return new _.CSSUnitValue(value, _.UnitType.kNumber);
45
+ return new CSSUnitValue(value, _types.UnitType.kNumber);
41
46
  }
42
47
 
43
48
  return value;
@@ -45,14 +50,14 @@ function (_super) {
45
50
 
46
51
  CSSNumericValue.fromPercentish = function (value) {
47
52
  if (typeof value === 'number') {
48
- return new _.CSSUnitValue(value * 100, _.UnitType.kPercentage);
53
+ return new CSSUnitValue(value * 100, _types.UnitType.kPercentage);
49
54
  }
50
55
 
51
56
  return value;
52
57
  };
53
58
 
54
59
  CSSNumericValue.prototype.getType = function () {
55
- return _.CSSStyleValueType.kUnknownType;
60
+ return _CSSStyleValue.CSSStyleValueType.kUnknownType;
56
61
  }; // toCSSValue() {
57
62
  // return null;
58
63
  // }
@@ -89,15 +94,15 @@ function (_super) {
89
94
  }
90
95
 
91
96
  var values = cssNumberishesToNumericValues(numberishes);
92
- prependValueForArithmetic(_.CSSStyleValueType.kSumType, values, this); // eg. 1px + 2px = 3px
97
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kSumType, values, this); // eg. 1px + 2px = 3px
93
98
 
94
- var unitValue = maybeSimplifyAsUnitValue(values, _.CSSMathOperator.kAdd);
99
+ var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kAdd);
95
100
 
96
101
  if (unitValue) {
97
102
  return unitValue;
98
103
  }
99
104
 
100
- return _.CSSMathSum.create(values);
105
+ return CSSMathSum.create(values);
101
106
  };
102
107
  /**
103
108
  * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#452
@@ -115,15 +120,15 @@ function (_super) {
115
120
  values = values.map(function (value) {
116
121
  return value.negate();
117
122
  });
118
- prependValueForArithmetic(_.CSSStyleValueType.kSumType, values, this); // eg. 3px - 2px = 1px
123
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kSumType, values, this); // eg. 3px - 2px = 1px
119
124
 
120
- var unitValue = maybeSimplifyAsUnitValue(values, _.CSSMathOperator.kAdd);
125
+ var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kAdd);
121
126
 
122
127
  if (unitValue) {
123
128
  return unitValue;
124
129
  }
125
130
 
126
- return _.CSSMathSum.create(values);
131
+ return CSSMathSum.create(values);
127
132
  };
128
133
  /**
129
134
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/mul
@@ -138,14 +143,14 @@ function (_super) {
138
143
  }
139
144
 
140
145
  var values = cssNumberishesToNumericValues(numberishes);
141
- prependValueForArithmetic(_.CSSStyleValueType.kProductType, values, this);
146
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kProductType, values, this);
142
147
  var unitValue = maybeMultiplyAsUnitValue(values);
143
148
 
144
149
  if (unitValue) {
145
150
  return unitValue;
146
151
  }
147
152
 
148
- return _.CSSMathProduct.create(values);
153
+ return CSSMathProduct.create(values);
149
154
  };
150
155
  /**
151
156
  * eg. calc(24px / 4%)
@@ -164,14 +169,14 @@ function (_super) {
164
169
  values = values.map(function (value) {
165
170
  return value.invert();
166
171
  });
167
- prependValueForArithmetic(_.CSSStyleValueType.kProductType, values, this);
172
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kProductType, values, this);
168
173
  var unitValue = maybeMultiplyAsUnitValue(values);
169
174
 
170
175
  if (unitValue) {
171
176
  return unitValue;
172
177
  }
173
178
 
174
- return _.CSSMathProduct.create(values);
179
+ return CSSMathProduct.create(values);
175
180
  };
176
181
 
177
182
  CSSNumericValue.prototype.min = function () {
@@ -182,14 +187,14 @@ function (_super) {
182
187
  }
183
188
 
184
189
  var values = cssNumberishesToNumericValues(numberishes);
185
- prependValueForArithmetic(_.CSSStyleValueType.kMinType, values, this);
186
- var unitValue = maybeSimplifyAsUnitValue(values, _.CSSMathOperator.kMin);
190
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kMinType, values, this);
191
+ var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kMin);
187
192
 
188
193
  if (unitValue) {
189
194
  return unitValue;
190
195
  }
191
196
 
192
- return _.CSSMathMin.create(values);
197
+ return CSSMathMin.create(values);
193
198
  };
194
199
 
195
200
  CSSNumericValue.prototype.max = function () {
@@ -200,14 +205,14 @@ function (_super) {
200
205
  }
201
206
 
202
207
  var values = cssNumberishesToNumericValues(numberishes);
203
- prependValueForArithmetic(_.CSSStyleValueType.kMaxType, values, this);
204
- var unitValue = maybeSimplifyAsUnitValue(values, _.CSSMathOperator.kMax);
208
+ prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kMaxType, values, this);
209
+ var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kMax);
205
210
 
206
211
  if (unitValue) {
207
212
  return unitValue;
208
213
  }
209
214
 
210
- return _.CSSMathMax.create(values);
215
+ return CSSMathMax.create(values);
211
216
  };
212
217
  /**
213
218
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/to
@@ -223,7 +228,7 @@ function (_super) {
223
228
  var unit;
224
229
 
225
230
  if (typeof unitOrName === 'string') {
226
- unit = _.CSSUnitValue.unitFromName(unitOrName);
231
+ unit = CSSUnitValue.unitFromName(unitOrName);
227
232
  } else {
228
233
  unit = unitOrName;
229
234
  }
@@ -301,8 +306,7 @@ function (_super) {
301
306
  return a.unit - b.unit;
302
307
  }); // We got 'values' from a sum value, so it must be a valid CSSMathSum.
303
308
 
304
- var result_1 = _.CSSMathSum.create(values);
305
-
309
+ var result_1 = CSSMathSum.create(values);
306
310
  (0, _utils.DCHECK)(!!result_1);
307
311
  return result_1;
308
312
  }
@@ -327,7 +331,7 @@ function (_super) {
327
331
 
328
332
  return cur_sum;
329
333
  }, 0);
330
- result.push(new _.CSSUnitValue(total_value, target_unit));
334
+ result.push(new CSSUnitValue(total_value, target_unit));
331
335
  };
332
336
 
333
337
  try {
@@ -354,7 +358,7 @@ function (_super) {
354
358
  throw new Error('There were leftover terms that were not converted');
355
359
  }
356
360
 
357
- return _.CSSMathSum.create(result);
361
+ return CSSMathSum.create(result);
358
362
  };
359
363
  /**
360
364
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/type
@@ -373,67 +377,67 @@ function (_super) {
373
377
  percent: 0,
374
378
  percentHint: 'length'
375
379
  };
376
- var exponent = this.type_.exponent(_.BaseType.kLength);
380
+ var exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kLength);
377
381
 
378
382
  if (exponent) {
379
383
  type.length = exponent;
380
384
  }
381
385
 
382
- exponent = this.type_.exponent(_.BaseType.kAngle);
386
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kAngle);
383
387
 
384
388
  if (exponent) {
385
389
  type.angle = exponent;
386
390
  }
387
391
 
388
- exponent = this.type_.exponent(_.BaseType.kTime);
392
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kTime);
389
393
 
390
394
  if (exponent) {
391
395
  type.time = exponent;
392
396
  }
393
397
 
394
- exponent = this.type_.exponent(_.BaseType.kFrequency);
398
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kFrequency);
395
399
 
396
400
  if (exponent) {
397
401
  type.frequency = exponent;
398
402
  }
399
403
 
400
- exponent = this.type_.exponent(_.BaseType.kResolution);
404
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kResolution);
401
405
 
402
406
  if (exponent) {
403
407
  type.resolution = exponent;
404
408
  }
405
409
 
406
- exponent = this.type_.exponent(_.BaseType.kFlex);
410
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kFlex);
407
411
 
408
412
  if (exponent) {
409
413
  type.flex = exponent;
410
414
  }
411
415
 
412
- exponent = this.type_.exponent(_.BaseType.kPercent);
416
+ exponent = this.type_.exponent(_CSSNumericValueType.BaseType.kPercent);
413
417
 
414
418
  if (exponent) {
415
419
  type.percent = exponent;
416
420
  }
417
421
 
418
422
  if (this.type_.hasPercentHint) {
419
- type.percentHint = (0, _.baseTypeToString)(this.type_.percentHint);
423
+ type.percentHint = (0, _CSSNumericValueType.baseTypeToString)(this.type_.percentHint);
420
424
  }
421
425
 
422
426
  return type;
423
427
  };
424
428
 
425
429
  CSSNumericValue.isValidUnit = function (unit) {
426
- if (unit === _.UnitType.kUserUnits) return false;
427
- if (unit === _.UnitType.kNumber || unit == _.UnitType.kPercentage || this.isLength(unit) || this.isAngle(unit) || this.isTime(unit) || this.isFrequency(unit) || this.isResolution(unit) || this.isFlex(unit)) return true;
430
+ if (unit === _types.UnitType.kUserUnits) return false;
431
+ if (unit === _types.UnitType.kNumber || unit == _types.UnitType.kPercentage || this.isLength(unit) || this.isAngle(unit) || this.isTime(unit) || this.isFrequency(unit) || this.isResolution(unit) || this.isFlex(unit)) return true;
428
432
  return false;
429
433
  };
430
434
 
431
435
  CSSNumericValue.prototype.negate = function () {
432
- return _.CSSMathNegate.create(this);
436
+ return CSSMathNegate.create(this);
433
437
  };
434
438
 
435
439
  CSSNumericValue.prototype.invert = function () {
436
- return _.CSSMathInvert.create(this);
440
+ return CSSMathInvert.create(this);
437
441
  };
438
442
 
439
443
  return CSSNumericValue;
@@ -457,11 +461,11 @@ function prependValueForArithmetic(type, values, value) {
457
461
 
458
462
  function cssNumericSumValueEntryToUnitValue(term) {
459
463
  if (Object.keys(term.units).length === 0) {
460
- return new _.CSSUnitValue(term.value);
464
+ return new CSSUnitValue(term.value);
461
465
  }
462
466
 
463
467
  if (Object.keys(term.units).length === 1 && term.units[Object.keys(term.units)[0]] === 1) {
464
- return new _.CSSUnitValue(term.value, Number(Object.keys(term.units)[0]));
468
+ return new CSSUnitValue(term.value, Number(Object.keys(term.units)[0]));
465
469
  }
466
470
 
467
471
  return null;
@@ -469,43 +473,952 @@ function cssNumericSumValueEntryToUnitValue(term) {
469
473
 
470
474
  function maybeSimplifyAsUnitValue(values, operator) {
471
475
  (0, _utils.DCHECK)(!!values.length);
472
- var first_unit_value = values[0] instanceof _.CSSUnitValue ? values[0] : null;
476
+ var first_unit_value = values[0] instanceof CSSUnitValue ? values[0] : null;
473
477
  if (!first_unit_value) return null;
474
478
  var final_value = first_unit_value.value;
475
479
 
476
480
  for (var i = 1; i < values.length; i++) {
477
- var unit_value = values[i] instanceof _.CSSUnitValue ? values[i] : null;
481
+ var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
478
482
  if (!unit_value || unit_value.unit !== first_unit_value.unit) return null;
479
483
 
480
- if (operator === _.CSSMathOperator.kAdd) {
484
+ if (operator === _CSSMathOperator.CSSMathOperator.kAdd) {
481
485
  final_value += unit_value.value;
482
- } else if (operator === _.CSSMathOperator.kMax) {
486
+ } else if (operator === _CSSMathOperator.CSSMathOperator.kMax) {
483
487
  final_value = Math.max(final_value, unit_value.value);
484
- } else if (operator === _.CSSMathOperator.kMin) {
488
+ } else if (operator === _CSSMathOperator.CSSMathOperator.kMin) {
485
489
  final_value = Math.min(final_value, unit_value.value);
486
490
  }
487
491
  }
488
492
 
489
- return new _.CSSUnitValue(final_value, first_unit_value.unit);
493
+ return new CSSUnitValue(final_value, first_unit_value.unit);
490
494
  }
491
495
 
492
496
  function maybeMultiplyAsUnitValue(values) {
493
497
  (0, _utils.DCHECK)(!!values.length); // We are allowed one unit value with type other than kNumber.
494
498
 
495
- var unit_other_than_number = _.UnitType.kNumber;
499
+ var unit_other_than_number = _types.UnitType.kNumber;
496
500
  var final_value = 1.0;
497
501
 
498
502
  for (var i = 0; i < values.length; i++) {
499
- var unit_value = values[i] instanceof _.CSSUnitValue ? values[i] : null;
503
+ var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
500
504
  if (!unit_value) return null;
501
505
 
502
- if (unit_value.unit !== _.UnitType.kNumber) {
503
- if (unit_other_than_number !== _.UnitType.kNumber) return null;
506
+ if (unit_value.unit !== _types.UnitType.kNumber) {
507
+ if (unit_other_than_number !== _types.UnitType.kNumber) return null;
504
508
  unit_other_than_number = unit_value.unit;
505
509
  }
506
510
 
507
511
  final_value *= unit_value.value;
508
512
  }
509
513
 
510
- return new _.CSSUnitValue(final_value, unit_other_than_number);
511
- }
514
+ return new CSSUnitValue(final_value, unit_other_than_number);
515
+ }
516
+ /**
517
+ * Represents numeric values that can be expressed as a single number plus a
518
+ * unit (or a naked number or percentage).
519
+ * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
520
+ */
521
+
522
+
523
+ var CSSUnitValue =
524
+ /** @class */
525
+ function (_super) {
526
+ (0, _tslib.__extends)(CSSUnitValue, _super);
527
+
528
+ function CSSUnitValue(value, unitOrName) {
529
+ if (unitOrName === void 0) {
530
+ unitOrName = _types.UnitType.kNumber;
531
+ }
532
+
533
+ var _this = this;
534
+
535
+ var unit;
536
+
537
+ if (typeof unitOrName === 'string') {
538
+ unit = CSSUnitValue.unitFromName(unitOrName);
539
+ } else {
540
+ unit = unitOrName;
541
+ }
542
+
543
+ (0, _utils.DCHECK)(CSSUnitValue.isValidUnit(unit));
544
+ _this = _super.call(this, new _CSSNumericValueType.CSSNumericValueType(unit)) || this;
545
+ _this.unit = unit;
546
+ _this.value = value;
547
+ return _this;
548
+ } // static fromCSSValue(value: CSSNumericLiteralValue) {
549
+ // let unit = value.type;
550
+ // if (unit === UnitType.kInteger) unit = UnitType.kNumber;
551
+ // if (!this.isValidUnit(unit)) return null;
552
+ // return new CSSUnitValue(value.getDoubleValue(), unit);
553
+ // }
554
+
555
+
556
+ CSSUnitValue.toCanonicalUnit = function (unit) {
557
+ return this.canonicalUnitTypeForCategory(this.unitTypeToUnitCategory(unit));
558
+ };
559
+
560
+ CSSUnitValue.toCanonicalUnitIfPossible = function (unit) {
561
+ var canonical_unit = this.toCanonicalUnit(unit);
562
+ if (canonical_unit === _types.UnitType.kUnknown) return unit;
563
+ return canonical_unit;
564
+ };
565
+
566
+ CSSUnitValue.formatInfinityOrNaN = function (number, suffix) {
567
+ if (suffix === void 0) {
568
+ suffix = '';
569
+ }
570
+
571
+ var result = '';
572
+
573
+ if (!Number.isFinite(number)) {
574
+ if (number > 0) result = 'infinity';else result = '-infinity';
575
+ } else {
576
+ (0, _utils.DCHECK)(Number.isNaN(number));
577
+ result = 'NaN';
578
+ }
579
+
580
+ return result += suffix;
581
+ };
582
+
583
+ CSSUnitValue.formatNumber = function (number, suffix) {
584
+ if (suffix === void 0) {
585
+ suffix = '';
586
+ }
587
+
588
+ return number + suffix;
589
+ };
590
+
591
+ CSSUnitValue.prototype.clone = function () {
592
+ return new CSSUnitValue(this.value, this.unit);
593
+ };
594
+
595
+ CSSUnitValue.prototype.convertTo = function (target_unit) {
596
+ if (this.unit === target_unit) {
597
+ return new CSSUnitValue(this.value, this.unit);
598
+ } // Instead of defining the scale factors for every unit to every other unit,
599
+ // we simply convert to the canonical unit and back since we already have
600
+ // the scale factors for canonical units.
601
+
602
+
603
+ var canonical_unit = CSSUnitValue.toCanonicalUnit(this.unit);
604
+
605
+ if (canonical_unit !== CSSUnitValue.toCanonicalUnit(target_unit) || canonical_unit === _types.UnitType.kUnknown) {
606
+ return null;
607
+ }
608
+
609
+ var scale_factor = _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit) / _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(target_unit);
610
+
611
+ return new CSSUnitValue(this.value * scale_factor, target_unit);
612
+ };
613
+
614
+ CSSUnitValue.prototype.equals = function (other) {
615
+ var other_unit_value = other;
616
+ return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
617
+ };
618
+
619
+ CSSUnitValue.prototype.getType = function () {
620
+ return _CSSStyleValue.CSSStyleValueType.kUnitType;
621
+ }; // toCSSValue() {
622
+ // return new CSSNumericLiteralValue(this.value, this.unit);
623
+ // }
624
+ // // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
625
+ // toCalcExpressionNode() {
626
+ // return CSSMathExpressionNumericLiteral.create(
627
+ // new CSSNumericLiteralValue(this.value, this.unit),
628
+ // );
629
+ // }
630
+
631
+
632
+ CSSUnitValue.prototype.sumValue = function () {
633
+ var sum = [];
634
+ var unit_map = {};
635
+
636
+ if (this.unit !== _types.UnitType.kNumber) {
637
+ unit_map[CSSUnitValue.toCanonicalUnitIfPossible(this.unit)] = 1;
638
+ }
639
+
640
+ sum.push({
641
+ value: this.value * _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit),
642
+ units: unit_map
643
+ });
644
+ return sum;
645
+ };
646
+
647
+ CSSUnitValue.prototype.negate = function () {
648
+ return new CSSUnitValue(-this.value, this.unit);
649
+ };
650
+
651
+ CSSUnitValue.prototype.invert = function () {
652
+ if (this.unit === _types.UnitType.kNumber) {
653
+ if (this.value === 0) return null;
654
+ return new CSSUnitValue(1.0 / this.value, this.unit);
655
+ }
656
+
657
+ return CSSMathInvert.create(this);
658
+ };
659
+
660
+ CSSUnitValue.prototype.buildCSSText = function (n, p, result) {
661
+ var text;
662
+
663
+ switch (this.unit) {
664
+ case _types.UnitType.kUnknown:
665
+ // FIXME
666
+ break;
667
+
668
+ case _types.UnitType.kInteger:
669
+ text = Number(this.value).toFixed(0);
670
+ break;
671
+
672
+ case _types.UnitType.kNumber:
673
+ case _types.UnitType.kPercentage:
674
+ case _types.UnitType.kEms:
675
+ case _types.UnitType.kQuirkyEms:
676
+ case _types.UnitType.kExs:
677
+ case _types.UnitType.kRems:
678
+ case _types.UnitType.kChs:
679
+ case _types.UnitType.kPixels:
680
+ case _types.UnitType.kCentimeters:
681
+ case _types.UnitType.kDotsPerPixel:
682
+ case _types.UnitType.kDotsPerInch:
683
+ case _types.UnitType.kDotsPerCentimeter:
684
+ case _types.UnitType.kMillimeters:
685
+ case _types.UnitType.kQuarterMillimeters:
686
+ case _types.UnitType.kInches:
687
+ case _types.UnitType.kPoints:
688
+ case _types.UnitType.kPicas:
689
+ case _types.UnitType.kUserUnits:
690
+ case _types.UnitType.kDegrees:
691
+ case _types.UnitType.kRadians:
692
+ case _types.UnitType.kGradians:
693
+ case _types.UnitType.kMilliseconds:
694
+ case _types.UnitType.kSeconds:
695
+ case _types.UnitType.kHertz:
696
+ case _types.UnitType.kKilohertz:
697
+ case _types.UnitType.kTurns:
698
+ case _types.UnitType.kFraction:
699
+ case _types.UnitType.kViewportWidth:
700
+ case _types.UnitType.kViewportHeight:
701
+ case _types.UnitType.kViewportInlineSize:
702
+ case _types.UnitType.kViewportBlockSize:
703
+ case _types.UnitType.kViewportMin:
704
+ case _types.UnitType.kViewportMax:
705
+ case _types.UnitType.kSmallViewportWidth:
706
+ case _types.UnitType.kSmallViewportHeight:
707
+ case _types.UnitType.kSmallViewportInlineSize:
708
+ case _types.UnitType.kSmallViewportBlockSize:
709
+ case _types.UnitType.kSmallViewportMin:
710
+ case _types.UnitType.kSmallViewportMax:
711
+ case _types.UnitType.kLargeViewportWidth:
712
+ case _types.UnitType.kLargeViewportHeight:
713
+ case _types.UnitType.kLargeViewportInlineSize:
714
+ case _types.UnitType.kLargeViewportBlockSize:
715
+ case _types.UnitType.kLargeViewportMin:
716
+ case _types.UnitType.kLargeViewportMax:
717
+ case _types.UnitType.kDynamicViewportWidth:
718
+ case _types.UnitType.kDynamicViewportHeight:
719
+ case _types.UnitType.kDynamicViewportInlineSize:
720
+ case _types.UnitType.kDynamicViewportBlockSize:
721
+ case _types.UnitType.kDynamicViewportMin:
722
+ case _types.UnitType.kDynamicViewportMax:
723
+ case _types.UnitType.kContainerWidth:
724
+ case _types.UnitType.kContainerHeight:
725
+ case _types.UnitType.kContainerInlineSize:
726
+ case _types.UnitType.kContainerBlockSize:
727
+ case _types.UnitType.kContainerMin:
728
+ case _types.UnitType.kContainerMax:
729
+ {
730
+ var kMinInteger = -999999;
731
+ var kMaxInteger = 999999;
732
+ var value = this.value;
733
+ var unit = CSSUnitValue.unitTypeToString(this.unit);
734
+
735
+ if (value < kMinInteger || value > kMaxInteger) {
736
+ var unit_1 = CSSUnitValue.unitTypeToString(this.unit);
737
+
738
+ if (!Number.isFinite(value) || Number.isNaN(value)) {
739
+ text = CSSUnitValue.formatInfinityOrNaN(value, unit_1);
740
+ } else {
741
+ text = CSSUnitValue.formatNumber(value, unit_1);
742
+ }
743
+ } else {
744
+ text = "".concat(value).concat(unit);
745
+ }
746
+ }
747
+ }
748
+
749
+ result += text;
750
+ return result;
751
+ };
752
+
753
+ return CSSUnitValue;
754
+ }(CSSNumericValue);
755
+
756
+ exports.CSSUnitValue = CSSUnitValue;
757
+
758
+ /**
759
+ * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
760
+ *
761
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
762
+ * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
763
+ */
764
+ var CSSMathValue =
765
+ /** @class */
766
+ function (_super) {
767
+ (0, _tslib.__extends)(CSSMathValue, _super);
768
+
769
+ function CSSMathValue() {
770
+ return _super !== null && _super.apply(this, arguments) || this;
771
+ } // From CSSNumericValue
772
+
773
+
774
+ CSSMathValue.prototype.isUnitValue = function () {
775
+ return false;
776
+ };
777
+
778
+ return CSSMathValue;
779
+ }(CSSNumericValue);
780
+
781
+ exports.CSSMathValue = CSSMathValue;
782
+
783
+ var CSSMathInvert =
784
+ /** @class */
785
+ function (_super) {
786
+ (0, _tslib.__extends)(CSSMathInvert, _super);
787
+
788
+ function CSSMathInvert(value, type) {
789
+ var _this = _super.call(this, type) || this;
790
+
791
+ _this.value = value;
792
+ _this.operator = 'invert';
793
+ return _this;
794
+ }
795
+
796
+ CSSMathInvert.create = function (value) {
797
+ var type = _CSSNumericValueType.CSSNumericValueType.negateExponents(value.type_);
798
+
799
+ return new CSSMathInvert(value, type);
800
+ };
801
+
802
+ CSSMathInvert.prototype.clone = function () {
803
+ return new CSSMathInvert(this.value, this.type_);
804
+ };
805
+
806
+ CSSMathInvert.prototype.getType = function () {
807
+ return _CSSStyleValue.CSSStyleValueType.kInvertType;
808
+ };
809
+
810
+ CSSMathInvert.prototype.equals = function (other) {
811
+ if (other.getType() !== _CSSStyleValue.CSSStyleValueType.kInvertType) {
812
+ return false;
813
+ } // We can safely cast here as we know 'other' has the same type as us.
814
+
815
+
816
+ var other_invert = other;
817
+ return this.value.equals(other_invert.value);
818
+ };
819
+
820
+ CSSMathInvert.prototype.sumValue = function () {
821
+ var sum = this.value.sumValue();
822
+
823
+ if (sum.length === 0 || sum.length !== 1 || sum[0].value === 0) {
824
+ return null;
825
+ }
826
+
827
+ Object.keys(sum[0].units).forEach(function (key) {
828
+ sum[0].units[key] *= -1;
829
+ });
830
+ sum[0].value = 1.0 / sum[0].value;
831
+ return sum;
832
+ }; // toCalcExpressionNode(): CSSMathExpressionNode {
833
+ // const right_side = this.value.toCalcExpressionNode();
834
+ // if (!right_side) {
835
+ // return null;
836
+ // }
837
+ // // return CSSMathExpressionOperation::CreateArithmeticOperation(
838
+ // // CSSMathExpressionNumericLiteral::Create(
839
+ // // 1, UnitType.kNumber),
840
+ // // right_side, CSSMathOperator.kDivide);
841
+ // return null;
842
+ // }
843
+
844
+
845
+ CSSMathInvert.prototype.buildCSSText = function (nested, paren_less, result) {
846
+ if (paren_less == _types.ParenLess.kNo) {
847
+ result += nested === _types.Nested.kYes ? '(' : 'calc(';
848
+ }
849
+
850
+ result += '1 / ';
851
+ result = this.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
852
+
853
+ if (paren_less === _types.ParenLess.kNo) {
854
+ result += ')';
855
+ }
856
+
857
+ return result;
858
+ };
859
+
860
+ return CSSMathInvert;
861
+ }(CSSMathValue);
862
+
863
+ exports.CSSMathInvert = CSSMathInvert;
864
+
865
+ var CSSMathNegate =
866
+ /** @class */
867
+ function (_super) {
868
+ (0, _tslib.__extends)(CSSMathNegate, _super);
869
+
870
+ function CSSMathNegate(value, type) {
871
+ var _this = _super.call(this, type) || this;
872
+
873
+ _this.value = value;
874
+ _this.operator = 'negate';
875
+ return _this;
876
+ }
877
+
878
+ CSSMathNegate.create = function (value) {
879
+ return new CSSMathNegate(value, value.type_);
880
+ };
881
+
882
+ CSSMathNegate.prototype.clone = function () {
883
+ return new CSSMathNegate(this.value, this.type_);
884
+ };
885
+
886
+ CSSMathNegate.prototype.getType = function () {
887
+ return _CSSStyleValue.CSSStyleValueType.kNegateType;
888
+ };
889
+
890
+ CSSMathNegate.prototype.equals = function (other) {
891
+ if (other.getType() !== _CSSStyleValue.CSSStyleValueType.kNegateType) {
892
+ return false;
893
+ }
894
+
895
+ var other_invert = other;
896
+ return this.value.equals(other_invert.value);
897
+ };
898
+
899
+ CSSMathNegate.prototype.sumValue = function () {
900
+ var sum = this.value.sumValue();
901
+
902
+ if (sum.length === 0) {
903
+ return null;
904
+ }
905
+
906
+ sum.forEach(function (term) {
907
+ term.value *= -1;
908
+ });
909
+ return sum;
910
+ }; // toCalcExpressionNode(): CSSMathExpressionNode {
911
+ // const right_side = this.value.toCalcExpressionNode();
912
+ // if (!right_side) {
913
+ // return null;
914
+ // }
915
+ // // return CSSMathExpressionOperation::CreateArithmeticOperationSimplified(
916
+ // // CSSMathExpressionNumericLiteral::Create(
917
+ // // -1, CSSPrimitiveValue::UnitType::kNumber),
918
+ // // right_side, CSSMathOperator::kMultiply);
919
+ // }
920
+
921
+
922
+ CSSMathNegate.prototype.buildCSSText = function (nested, paren_less, result) {
923
+ if (paren_less == _types.ParenLess.kNo) {
924
+ result += nested === _types.Nested.kYes ? '(' : 'calc(';
925
+ }
926
+
927
+ result += '-';
928
+ result = this.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
929
+
930
+ if (paren_less === _types.ParenLess.kNo) {
931
+ result += ')';
932
+ }
933
+
934
+ return result;
935
+ };
936
+
937
+ return CSSMathNegate;
938
+ }(CSSMathValue);
939
+
940
+ exports.CSSMathNegate = CSSMathNegate;
941
+
942
+ function typeCheck(values, op, error) {
943
+ error = false;
944
+ var final_type = values[0].type_;
945
+
946
+ for (var i = 1; i < values.length; i++) {
947
+ final_type = op(final_type, values[i].type_, error);
948
+ if (error) return final_type;
949
+ }
950
+
951
+ return final_type;
952
+ } // Represents an arithmetic operation with one or more CSSNumericValues.
953
+
954
+
955
+ var CSSMathVariadic =
956
+ /** @class */
957
+ function (_super) {
958
+ (0, _tslib.__extends)(CSSMathVariadic, _super);
959
+
960
+ function CSSMathVariadic(values, type) {
961
+ var _this = _super.call(this, type) || this;
962
+
963
+ _this.values = values;
964
+ return _this;
965
+ }
966
+
967
+ CSSMathVariadic.prototype.numericValues = function () {
968
+ return this.values;
969
+ };
970
+
971
+ CSSMathVariadic.prototype.equals = function (other) {
972
+ if (this.getType() !== other.getType()) {
973
+ return false;
974
+ }
975
+
976
+ return this.values.every(function (value, i) {
977
+ return value.equals(other.values[i]);
978
+ });
979
+ };
980
+
981
+ return CSSMathVariadic;
982
+ }(CSSMathValue);
983
+
984
+ exports.CSSMathVariadic = CSSMathVariadic;
985
+
986
+ // Represents the minimum of one or more CSSNumericValues.
987
+ // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
988
+ var CSSMathMin =
989
+ /** @class */
990
+ function (_super) {
991
+ (0, _tslib.__extends)(CSSMathMin, _super);
992
+
993
+ function CSSMathMin() {
994
+ var _this = _super !== null && _super.apply(this, arguments) || this;
995
+
996
+ _this.operator = 'min';
997
+ return _this;
998
+ }
999
+
1000
+ CSSMathMin.create = function (values) {
1001
+ var error = false;
1002
+ var final_type = typeCheck(values, _CSSNumericValueType.CSSNumericValueType.add, error);
1003
+ return error ? null : new CSSMathMin(values, final_type);
1004
+ };
1005
+
1006
+ CSSMathMin.prototype.clone = function () {
1007
+ return new CSSMathMin(this.values, this.type_);
1008
+ };
1009
+
1010
+ CSSMathMin.prototype.getType = function () {
1011
+ return _CSSStyleValue.CSSStyleValueType.kMinType;
1012
+ };
1013
+
1014
+ CSSMathMin.prototype.sumValue = function () {
1015
+ var e_4, _a;
1016
+
1017
+ var cur_min = this.numericValues()[0].sumValue();
1018
+
1019
+ if (!cur_min.length) {
1020
+ return null;
1021
+ }
1022
+
1023
+ try {
1024
+ for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
1025
+ var value = _c.value;
1026
+ var child_sum = value.sumValue();
1027
+
1028
+ if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_min[0].units)) {
1029
+ return null;
1030
+ }
1031
+
1032
+ if (child_sum[0].value < cur_min[0].value) {
1033
+ cur_min = child_sum;
1034
+ }
1035
+ }
1036
+ } catch (e_4_1) {
1037
+ e_4 = {
1038
+ error: e_4_1
1039
+ };
1040
+ } finally {
1041
+ try {
1042
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1043
+ } finally {
1044
+ if (e_4) throw e_4.error;
1045
+ }
1046
+ }
1047
+
1048
+ return cur_min;
1049
+ }; // toCalcExpressionNode() {
1050
+ // const operands: CSSMathExpressionOperation[] = [];
1051
+ // for (const value of this.numericValues()) {
1052
+ // const operand = value.toCalcExpressionNode();
1053
+ // if (!operand) {
1054
+ // continue;
1055
+ // }
1056
+ // operands.push(operand as CSSMathExpressionOperation);
1057
+ // }
1058
+ // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMin);
1059
+ // }
1060
+
1061
+
1062
+ CSSMathMin.prototype.buildCSSText = function (nested, paren_less, result) {
1063
+ var e_5, _a;
1064
+
1065
+ result += 'min(';
1066
+ var first_iteration = true;
1067
+
1068
+ try {
1069
+ for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
1070
+ var value = _c.value;
1071
+ if (!first_iteration) result += ', ';
1072
+ first_iteration = false;
1073
+ result = value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kYes, result);
1074
+ }
1075
+ } catch (e_5_1) {
1076
+ e_5 = {
1077
+ error: e_5_1
1078
+ };
1079
+ } finally {
1080
+ try {
1081
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1082
+ } finally {
1083
+ if (e_5) throw e_5.error;
1084
+ }
1085
+ }
1086
+
1087
+ result += ')';
1088
+ return result;
1089
+ };
1090
+
1091
+ return CSSMathMin;
1092
+ }(CSSMathVariadic);
1093
+
1094
+ exports.CSSMathMin = CSSMathMin;
1095
+
1096
+ // Represents the maximum of one or more CSSNumericValues.
1097
+ // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
1098
+ var CSSMathMax =
1099
+ /** @class */
1100
+ function (_super) {
1101
+ (0, _tslib.__extends)(CSSMathMax, _super);
1102
+
1103
+ function CSSMathMax() {
1104
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1105
+
1106
+ _this.operator = 'max';
1107
+ return _this;
1108
+ }
1109
+
1110
+ CSSMathMax.create = function (values) {
1111
+ var error = false;
1112
+ var final_type = typeCheck(values, _CSSNumericValueType.CSSNumericValueType.add, error);
1113
+ return error ? null : new CSSMathMax(values, final_type);
1114
+ };
1115
+
1116
+ CSSMathMax.prototype.clone = function () {
1117
+ return new CSSMathMax(this.values, this.type_);
1118
+ };
1119
+
1120
+ CSSMathMax.prototype.getType = function () {
1121
+ return _CSSStyleValue.CSSStyleValueType.kMaxType;
1122
+ };
1123
+
1124
+ CSSMathMax.prototype.sumValue = function () {
1125
+ var e_6, _a;
1126
+
1127
+ var cur_max = this.numericValues()[0].sumValue();
1128
+
1129
+ if (!cur_max.length) {
1130
+ return null;
1131
+ }
1132
+
1133
+ try {
1134
+ for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
1135
+ var value = _c.value;
1136
+ var child_sum = value.sumValue();
1137
+
1138
+ if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_max[0].units)) {
1139
+ return null;
1140
+ }
1141
+
1142
+ if (child_sum[0].value < cur_max[0].value) {
1143
+ cur_max = child_sum;
1144
+ }
1145
+ }
1146
+ } catch (e_6_1) {
1147
+ e_6 = {
1148
+ error: e_6_1
1149
+ };
1150
+ } finally {
1151
+ try {
1152
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1153
+ } finally {
1154
+ if (e_6) throw e_6.error;
1155
+ }
1156
+ }
1157
+
1158
+ return cur_max;
1159
+ }; // toCalcExpressionNode() {
1160
+ // const operands: CSSMathExpressionOperation[] = [];
1161
+ // for (const value of this.numericValues()) {
1162
+ // const operand = value.toCalcExpressionNode();
1163
+ // if (!operand) {
1164
+ // continue;
1165
+ // }
1166
+ // operands.push(operand as CSSMathExpressionOperation);
1167
+ // }
1168
+ // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMax);
1169
+ // }
1170
+
1171
+
1172
+ CSSMathMax.prototype.buildCSSText = function (nested, paren_less, result) {
1173
+ var e_7, _a;
1174
+
1175
+ result += 'max(';
1176
+ var first_iteration = true;
1177
+
1178
+ try {
1179
+ for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
1180
+ var value = _c.value;
1181
+ if (!first_iteration) result += ', ';
1182
+ first_iteration = false;
1183
+ result = value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kYes, result);
1184
+ }
1185
+ } catch (e_7_1) {
1186
+ e_7 = {
1187
+ error: e_7_1
1188
+ };
1189
+ } finally {
1190
+ try {
1191
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1192
+ } finally {
1193
+ if (e_7) throw e_7.error;
1194
+ }
1195
+ }
1196
+
1197
+ result += ')';
1198
+ return result;
1199
+ };
1200
+
1201
+ return CSSMathMax;
1202
+ }(CSSMathVariadic);
1203
+
1204
+ exports.CSSMathMax = CSSMathMax;
1205
+
1206
+ /**
1207
+ * Represents the sum of one or more CSSNumericValues.
1208
+ * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
1209
+ */
1210
+ var CSSMathSum =
1211
+ /** @class */
1212
+ function (_super) {
1213
+ (0, _tslib.__extends)(CSSMathSum, _super);
1214
+
1215
+ function CSSMathSum() {
1216
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1217
+
1218
+ _this.operator = 'sum';
1219
+ return _this;
1220
+ }
1221
+
1222
+ CSSMathSum.create = function (values) {
1223
+ var error = false;
1224
+ var finalType = typeCheck(values, _CSSNumericValueType.CSSNumericValueType.add, error);
1225
+ return error ? null : new CSSMathSum(values, finalType);
1226
+ };
1227
+
1228
+ CSSMathSum.numericTypeFromUnitMap = function (units) {
1229
+ var type = new _CSSNumericValueType.CSSNumericValueType();
1230
+ Object.keys(units).forEach(function (key) {
1231
+ var exp = units[key];
1232
+ var error = false;
1233
+ type = _CSSNumericValueType.CSSNumericValueType.multiply(type, new _CSSNumericValueType.CSSNumericValueType(Number(key), exp), error);
1234
+ (0, _utils.DCHECK)(!error);
1235
+ });
1236
+ return type;
1237
+ };
1238
+
1239
+ CSSMathSum.canCreateNumericTypeFromSumValue = function (sum) {
1240
+ var _this = this;
1241
+
1242
+ (0, _utils.DCHECK)(!!sum.length);
1243
+ var first_type = this.numericTypeFromUnitMap(sum[0].units);
1244
+ return sum.every(function (term) {
1245
+ var error = false;
1246
+
1247
+ _CSSNumericValueType.CSSNumericValueType.add(first_type, _this.numericTypeFromUnitMap(term.units), error);
1248
+
1249
+ return !error;
1250
+ });
1251
+ };
1252
+
1253
+ CSSMathSum.prototype.clone = function () {
1254
+ return new CSSMathSum(this.values, this.type_);
1255
+ };
1256
+
1257
+ CSSMathSum.prototype.getType = function () {
1258
+ return _CSSStyleValue.CSSStyleValueType.kSumType;
1259
+ }; // toCalcExpressionNode() {
1260
+ // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
1261
+ // }
1262
+
1263
+
1264
+ CSSMathSum.prototype.sumValue = function () {
1265
+ var sum = [];
1266
+ this.numericValues().forEach(function (value) {
1267
+ var child_sum = value.sumValue();
1268
+
1269
+ if (!child_sum.length) {
1270
+ return null;
1271
+ }
1272
+
1273
+ child_sum.forEach(function (term) {
1274
+ var index = sum.findIndex(function (s) {
1275
+ return JSON.stringify(s.units) === JSON.stringify(term.units);
1276
+ });
1277
+
1278
+ if (index === -1) {
1279
+ sum.push((0, _tslib.__assign)({}, term));
1280
+ } else {
1281
+ sum[index].value += term.value;
1282
+ }
1283
+ });
1284
+ });
1285
+ if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
1286
+ return sum;
1287
+ };
1288
+
1289
+ CSSMathSum.prototype.buildCSSText = function (nested, paren_less, result) {
1290
+ if (paren_less == _types.ParenLess.kNo) {
1291
+ result += nested === _types.Nested.kYes ? '(' : 'calc(';
1292
+ }
1293
+
1294
+ var values = this.numericValues();
1295
+ result = values[0].buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1296
+
1297
+ for (var i = 1; i < values.length; i++) {
1298
+ var arg = values[i];
1299
+
1300
+ if (arg.getType() === _CSSStyleValue.CSSStyleValueType.kNegateType) {
1301
+ result += ' - ';
1302
+ result = arg.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1303
+ } else {
1304
+ result += ' + ';
1305
+ result = arg.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1306
+ }
1307
+ }
1308
+
1309
+ if (paren_less === _types.ParenLess.kNo) {
1310
+ result += ')';
1311
+ }
1312
+
1313
+ return result;
1314
+ };
1315
+
1316
+ return CSSMathSum;
1317
+ }(CSSMathVariadic);
1318
+
1319
+ exports.CSSMathSum = CSSMathSum;
1320
+
1321
+ /**
1322
+ * Represents the product of one or more CSSNumericValues.
1323
+ * @see https://drafts.css-houdini.org/css-typed-om/#cssmathproduct
1324
+ */
1325
+ var CSSMathProduct =
1326
+ /** @class */
1327
+ function (_super) {
1328
+ (0, _tslib.__extends)(CSSMathProduct, _super);
1329
+
1330
+ function CSSMathProduct() {
1331
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1332
+
1333
+ _this.operator = 'product';
1334
+ return _this;
1335
+ }
1336
+
1337
+ CSSMathProduct.create = function (values) {
1338
+ var error = false;
1339
+ var finalType = typeCheck(values, _CSSNumericValueType.CSSNumericValueType.multiply, error);
1340
+ return error ? null : new CSSMathProduct(values, finalType);
1341
+ };
1342
+
1343
+ CSSMathProduct.multiplyUnitMaps = function (a, b) {
1344
+ Object.keys(b).forEach(function (key) {
1345
+ (0, _utils.DCHECK_NE)(b[key].value, 0);
1346
+ var old_value = key in a ? a[key].value : 0;
1347
+
1348
+ if (old_value + b[key].value === 0) {
1349
+ delete a[key];
1350
+ } else {
1351
+ a[key] = old_value + b[key].value;
1352
+ }
1353
+ });
1354
+ return a;
1355
+ };
1356
+
1357
+ CSSMathProduct.prototype.clone = function () {
1358
+ return new CSSMathProduct(this.values, this.type_);
1359
+ };
1360
+
1361
+ CSSMathProduct.prototype.getType = function () {
1362
+ return _CSSStyleValue.CSSStyleValueType.kProductType;
1363
+ }; // toCalcExpressionNode() {
1364
+ // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kMultiply);
1365
+ // }
1366
+
1367
+
1368
+ CSSMathProduct.prototype.sumValue = function () {
1369
+ var sum = [{
1370
+ value: 1,
1371
+ units: {}
1372
+ }];
1373
+ this.numericValues().forEach(function (value) {
1374
+ var child_sum = value.sumValue();
1375
+
1376
+ if (!child_sum.length) {
1377
+ return null;
1378
+ }
1379
+
1380
+ var new_sum = [];
1381
+ sum.forEach(function (a) {
1382
+ child_sum.forEach(function (b) {
1383
+ new_sum.push({
1384
+ value: a.value * b.value,
1385
+ units: CSSMathProduct.multiplyUnitMaps(a.units, b.units)
1386
+ });
1387
+ });
1388
+ });
1389
+ sum = new_sum;
1390
+ });
1391
+ return sum;
1392
+ };
1393
+
1394
+ CSSMathProduct.prototype.buildCSSText = function (nested, paren_less, result) {
1395
+ if (paren_less == _types.ParenLess.kNo) {
1396
+ result += nested === _types.Nested.kYes ? '(' : 'calc(';
1397
+ }
1398
+
1399
+ var values = this.numericValues();
1400
+ result = values[0].buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1401
+
1402
+ for (var i = 1; i < values.length; i++) {
1403
+ var arg = values[i];
1404
+
1405
+ if (arg.getType() === _CSSStyleValue.CSSStyleValueType.kInvertType) {
1406
+ result += ' / ';
1407
+ result = arg.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1408
+ } else {
1409
+ result += ' * ';
1410
+ result = arg.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
1411
+ }
1412
+ }
1413
+
1414
+ if (paren_less === _types.ParenLess.kNo) {
1415
+ result += ')';
1416
+ }
1417
+
1418
+ return result;
1419
+ };
1420
+
1421
+ return CSSMathProduct;
1422
+ }(CSSMathVariadic);
1423
+
1424
+ exports.CSSMathProduct = CSSMathProduct;