@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
@@ -1,129 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CSSMathSum = void 0;
7
-
8
- var _tslib = require("tslib");
9
-
10
- var _utils = require("../../utils");
11
-
12
- var _CSSMathVariadic = require("./CSSMathVariadic");
13
-
14
- var _ = require(".");
15
-
16
- /**
17
- * Represents the sum of one or more CSSNumericValues.
18
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
19
- */
20
- var CSSMathSum =
21
- /** @class */
22
- function (_super) {
23
- (0, _tslib.__extends)(CSSMathSum, _super);
24
-
25
- function CSSMathSum() {
26
- var _this = _super !== null && _super.apply(this, arguments) || this;
27
-
28
- _this.operator = 'sum';
29
- return _this;
30
- }
31
-
32
- CSSMathSum.create = function (values) {
33
- var error = false;
34
- var finalType = (0, _.typeCheck)(values, _.CSSNumericValueType.add, error);
35
- return error ? null : new CSSMathSum(values, finalType);
36
- };
37
-
38
- CSSMathSum.numericTypeFromUnitMap = function (units) {
39
- var type = new _.CSSNumericValueType();
40
- Object.keys(units).forEach(function (key) {
41
- var exp = units[key];
42
- var error = false;
43
- type = _.CSSNumericValueType.multiply(type, new _.CSSNumericValueType(Number(key), exp), error);
44
- (0, _utils.DCHECK)(!error);
45
- });
46
- return type;
47
- };
48
-
49
- CSSMathSum.canCreateNumericTypeFromSumValue = function (sum) {
50
- var _this = this;
51
-
52
- (0, _utils.DCHECK)(!!sum.length);
53
- var first_type = this.numericTypeFromUnitMap(sum[0].units);
54
- return sum.every(function (term) {
55
- var error = false;
56
-
57
- _.CSSNumericValueType.add(first_type, _this.numericTypeFromUnitMap(term.units), error);
58
-
59
- return !error;
60
- });
61
- };
62
-
63
- CSSMathSum.prototype.clone = function () {
64
- return new CSSMathSum(this.values, this.type_);
65
- };
66
-
67
- CSSMathSum.prototype.getType = function () {
68
- return _.CSSStyleValueType.kSumType;
69
- }; // toCalcExpressionNode() {
70
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
71
- // }
72
-
73
-
74
- CSSMathSum.prototype.sumValue = function () {
75
- var sum = [];
76
- this.numericValues().forEach(function (value) {
77
- var child_sum = value.sumValue();
78
-
79
- if (!child_sum.length) {
80
- return null;
81
- }
82
-
83
- child_sum.forEach(function (term) {
84
- var index = sum.findIndex(function (s) {
85
- return JSON.stringify(s.units) === JSON.stringify(term.units);
86
- });
87
-
88
- if (index === -1) {
89
- sum.push((0, _tslib.__assign)({}, term));
90
- } else {
91
- sum[index].value += term.value;
92
- }
93
- });
94
- });
95
- if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
96
- return sum;
97
- };
98
-
99
- CSSMathSum.prototype.buildCSSText = function (nested, paren_less, result) {
100
- if (paren_less == _.ParenLess.kNo) {
101
- result += nested === _.Nested.kYes ? '(' : 'calc(';
102
- }
103
-
104
- var values = this.numericValues();
105
- result = values[0].buildCSSText(_.Nested.kYes, _.ParenLess.kNo, result);
106
-
107
- for (var i = 1; i < values.length; i++) {
108
- var arg = values[i];
109
-
110
- if (arg.getType() === _.CSSStyleValueType.kNegateType) {
111
- result += ' - ';
112
- result = arg.value.buildCSSText(_.Nested.kYes, _.ParenLess.kNo, result);
113
- } else {
114
- result += ' + ';
115
- result = arg.buildCSSText(_.Nested.kYes, _.ParenLess.kNo, result);
116
- }
117
- }
118
-
119
- if (paren_less === _.ParenLess.kNo) {
120
- result += ')';
121
- }
122
-
123
- return result;
124
- };
125
-
126
- return CSSMathSum;
127
- }(_CSSMathVariadic.CSSMathVariadic);
128
-
129
- exports.CSSMathSum = CSSMathSum;
@@ -1,11 +0,0 @@
1
- import { CSSNumericValue } from './CSSNumericValue';
2
- /**
3
- * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
4
- *
5
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
6
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
7
- */
8
- export declare abstract class CSSMathValue extends CSSNumericValue {
9
- abstract operator: string;
10
- isUnitValue(): boolean;
11
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CSSMathValue = void 0;
7
-
8
- var _tslib = require("tslib");
9
-
10
- var _CSSNumericValue = require("./CSSNumericValue");
11
-
12
- /**
13
- * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
14
- *
15
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
16
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
17
- */
18
- var CSSMathValue =
19
- /** @class */
20
- function (_super) {
21
- (0, _tslib.__extends)(CSSMathValue, _super);
22
-
23
- function CSSMathValue() {
24
- return _super !== null && _super.apply(this, arguments) || this;
25
- } // From CSSNumericValue
26
-
27
-
28
- CSSMathValue.prototype.isUnitValue = function () {
29
- return false;
30
- };
31
-
32
- return CSSMathValue;
33
- }(_CSSNumericValue.CSSNumericValue);
34
-
35
- exports.CSSMathValue = CSSMathValue;
@@ -1,9 +0,0 @@
1
- import { CSSMathValue } from './CSSMathValue';
2
- import type { CSSNumericValue, CSSNumericValueType } from '.';
3
- export declare function typeCheck(values: CSSNumericValue[], op: Function, error: boolean): CSSNumericValueType;
4
- export declare abstract class CSSMathVariadic extends CSSMathValue {
5
- values: CSSNumericValue[];
6
- constructor(values: CSSNumericValue[], type: CSSNumericValueType);
7
- numericValues(): CSSNumericValue[];
8
- equals(other: CSSNumericValue): any;
9
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CSSMathVariadic = void 0;
7
- exports.typeCheck = typeCheck;
8
-
9
- var _tslib = require("tslib");
10
-
11
- var _CSSMathValue = require("./CSSMathValue");
12
-
13
- function typeCheck(values, op, error) {
14
- error = false;
15
- var final_type = values[0].type_;
16
-
17
- for (var i = 1; i < values.length; i++) {
18
- final_type = op(final_type, values[i].type_, error);
19
- if (error) return final_type;
20
- }
21
-
22
- return final_type;
23
- } // Represents an arithmetic operation with one or more CSSNumericValues.
24
-
25
-
26
- var CSSMathVariadic =
27
- /** @class */
28
- function (_super) {
29
- (0, _tslib.__extends)(CSSMathVariadic, _super);
30
-
31
- function CSSMathVariadic(values, type) {
32
- var _this = _super.call(this, type) || this;
33
-
34
- _this.values = values;
35
- return _this;
36
- }
37
-
38
- CSSMathVariadic.prototype.numericValues = function () {
39
- return this.values;
40
- };
41
-
42
- CSSMathVariadic.prototype.equals = function (other) {
43
- if (this.getType() !== other.getType()) {
44
- return false;
45
- }
46
-
47
- return this.values.every(function (value, i) {
48
- return value.equals(other.values[i]);
49
- });
50
- };
51
-
52
- return CSSMathVariadic;
53
- }(_CSSMathValue.CSSMathValue);
54
-
55
- exports.CSSMathVariadic = CSSMathVariadic;
@@ -1,33 +0,0 @@
1
- /**
2
- * The CSSUnitValue interface of the CSS_Object_Model represents values that contain a single unit type.
3
- * For example, "42px" would be represented by a CSSNumericValue.
4
- *
5
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSUnitValue
6
- */
7
- import { CSSMathInvert } from './CSSMathInvert';
8
- import type { CSSNumericSumValue } from './CSSNumericSumValue';
9
- import type { Nested, ParenLess } from '.';
10
- import { CSSNumericValue } from './CSSNumericValue';
11
- import { CSSStyleValueType, UnitType } from '.';
12
- /**
13
- * Represents numeric values that can be expressed as a single number plus a
14
- * unit (or a naked number or percentage).
15
- * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
16
- */
17
- export declare class CSSUnitValue extends CSSNumericValue {
18
- static toCanonicalUnit(unit: UnitType): UnitType.kUnknown | UnitType.kNumber | UnitType.kPixels | UnitType.kDegrees | UnitType.kSeconds | UnitType.kHertz | UnitType.kDotsPerPixel;
19
- static toCanonicalUnitIfPossible(unit: UnitType): UnitType;
20
- static formatInfinityOrNaN(number: number, suffix?: string): string;
21
- static formatNumber(number: number, suffix?: string): string;
22
- unit: UnitType;
23
- value: number;
24
- constructor(value: number, unitOrName?: UnitType | string);
25
- clone(): CSSUnitValue;
26
- convertTo(target_unit: UnitType): CSSUnitValue;
27
- equals(other: CSSNumericValue): boolean;
28
- getType(): CSSStyleValueType;
29
- sumValue(): CSSNumericSumValue;
30
- negate(): CSSUnitValue;
31
- invert(): CSSUnitValue | CSSMathInvert;
32
- buildCSSText(n: Nested, p: ParenLess, result: string): string;
33
- }
@@ -1,267 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CSSUnitValue = void 0;
7
-
8
- var _tslib = require("tslib");
9
-
10
- var _utils = require("../../utils");
11
-
12
- var _CSSMathInvert = require("./CSSMathInvert");
13
-
14
- var _CSSNumericValue = require("./CSSNumericValue");
15
-
16
- var _CSSNumericValueType = require("./CSSNumericValueType");
17
-
18
- var _ = require(".");
19
-
20
- var _CSSStyleValue = require("./CSSStyleValue");
21
-
22
- /**
23
- * The CSSUnitValue interface of the CSS_Object_Model represents values that contain a single unit type.
24
- * For example, "42px" would be represented by a CSSNumericValue.
25
- *
26
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSUnitValue
27
- */
28
-
29
- /**
30
- * Represents numeric values that can be expressed as a single number plus a
31
- * unit (or a naked number or percentage).
32
- * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
33
- */
34
- var CSSUnitValue =
35
- /** @class */
36
- function (_super) {
37
- (0, _tslib.__extends)(CSSUnitValue, _super);
38
-
39
- function CSSUnitValue(value, unitOrName) {
40
- if (unitOrName === void 0) {
41
- unitOrName = _.UnitType.kNumber;
42
- }
43
-
44
- var _this = this;
45
-
46
- var unit;
47
-
48
- if (typeof unitOrName === 'string') {
49
- unit = CSSUnitValue.unitFromName(unitOrName);
50
- } else {
51
- unit = unitOrName;
52
- }
53
-
54
- (0, _utils.DCHECK)(CSSUnitValue.isValidUnit(unit));
55
- _this = _super.call(this, new _CSSNumericValueType.CSSNumericValueType(unit)) || this;
56
- _this.unit = unit;
57
- _this.value = value;
58
- return _this;
59
- } // static fromCSSValue(value: CSSNumericLiteralValue) {
60
- // let unit = value.type;
61
- // if (unit === UnitType.kInteger) unit = UnitType.kNumber;
62
- // if (!this.isValidUnit(unit)) return null;
63
- // return new CSSUnitValue(value.getDoubleValue(), unit);
64
- // }
65
-
66
-
67
- CSSUnitValue.toCanonicalUnit = function (unit) {
68
- return this.canonicalUnitTypeForCategory(this.unitTypeToUnitCategory(unit));
69
- };
70
-
71
- CSSUnitValue.toCanonicalUnitIfPossible = function (unit) {
72
- var canonical_unit = this.toCanonicalUnit(unit);
73
- if (canonical_unit === _.UnitType.kUnknown) return unit;
74
- return canonical_unit;
75
- };
76
-
77
- CSSUnitValue.formatInfinityOrNaN = function (number, suffix) {
78
- if (suffix === void 0) {
79
- suffix = '';
80
- }
81
-
82
- var result = '';
83
-
84
- if (!Number.isFinite(number)) {
85
- if (number > 0) result = 'infinity';else result = '-infinity';
86
- } else {
87
- (0, _utils.DCHECK)(Number.isNaN(number));
88
- result = 'NaN';
89
- }
90
-
91
- return result += suffix;
92
- };
93
-
94
- CSSUnitValue.formatNumber = function (number, suffix) {
95
- if (suffix === void 0) {
96
- suffix = '';
97
- }
98
-
99
- return number + suffix;
100
- };
101
-
102
- CSSUnitValue.prototype.clone = function () {
103
- return new CSSUnitValue(this.value, this.unit);
104
- };
105
-
106
- CSSUnitValue.prototype.convertTo = function (target_unit) {
107
- if (this.unit === target_unit) {
108
- return new CSSUnitValue(this.value, this.unit);
109
- } // Instead of defining the scale factors for every unit to every other unit,
110
- // we simply convert to the canonical unit and back since we already have
111
- // the scale factors for canonical units.
112
-
113
-
114
- var canonical_unit = CSSUnitValue.toCanonicalUnit(this.unit);
115
-
116
- if (canonical_unit !== CSSUnitValue.toCanonicalUnit(target_unit) || canonical_unit === _.UnitType.kUnknown) {
117
- return null;
118
- }
119
-
120
- var scale_factor = _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit) / _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(target_unit);
121
-
122
- return new CSSUnitValue(this.value * scale_factor, target_unit);
123
- };
124
-
125
- CSSUnitValue.prototype.equals = function (other) {
126
- var other_unit_value = other;
127
- return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
128
- };
129
-
130
- CSSUnitValue.prototype.getType = function () {
131
- return _.CSSStyleValueType.kUnitType;
132
- }; // toCSSValue() {
133
- // return new CSSNumericLiteralValue(this.value, this.unit);
134
- // }
135
- // // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
136
- // toCalcExpressionNode() {
137
- // return CSSMathExpressionNumericLiteral.create(
138
- // new CSSNumericLiteralValue(this.value, this.unit),
139
- // );
140
- // }
141
-
142
-
143
- CSSUnitValue.prototype.sumValue = function () {
144
- var sum = [];
145
- var unit_map = {};
146
-
147
- if (this.unit !== _.UnitType.kNumber) {
148
- unit_map[CSSUnitValue.toCanonicalUnitIfPossible(this.unit)] = 1;
149
- }
150
-
151
- sum.push({
152
- value: this.value * _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit),
153
- units: unit_map
154
- });
155
- return sum;
156
- };
157
-
158
- CSSUnitValue.prototype.negate = function () {
159
- return new CSSUnitValue(-this.value, this.unit);
160
- };
161
-
162
- CSSUnitValue.prototype.invert = function () {
163
- if (this.unit === _.UnitType.kNumber) {
164
- if (this.value === 0) return null;
165
- return new CSSUnitValue(1.0 / this.value, this.unit);
166
- }
167
-
168
- return _CSSMathInvert.CSSMathInvert.create(this);
169
- };
170
-
171
- CSSUnitValue.prototype.buildCSSText = function (n, p, result) {
172
- var text;
173
-
174
- switch (this.unit) {
175
- case _.UnitType.kUnknown:
176
- // FIXME
177
- break;
178
-
179
- case _.UnitType.kInteger:
180
- text = Number(this.value).toFixed(0);
181
- break;
182
-
183
- case _.UnitType.kNumber:
184
- case _.UnitType.kPercentage:
185
- case _.UnitType.kEms:
186
- case _.UnitType.kQuirkyEms:
187
- case _.UnitType.kExs:
188
- case _.UnitType.kRems:
189
- case _.UnitType.kChs:
190
- case _.UnitType.kPixels:
191
- case _.UnitType.kCentimeters:
192
- case _.UnitType.kDotsPerPixel:
193
- case _.UnitType.kDotsPerInch:
194
- case _.UnitType.kDotsPerCentimeter:
195
- case _.UnitType.kMillimeters:
196
- case _.UnitType.kQuarterMillimeters:
197
- case _.UnitType.kInches:
198
- case _.UnitType.kPoints:
199
- case _.UnitType.kPicas:
200
- case _.UnitType.kUserUnits:
201
- case _.UnitType.kDegrees:
202
- case _.UnitType.kRadians:
203
- case _.UnitType.kGradians:
204
- case _.UnitType.kMilliseconds:
205
- case _.UnitType.kSeconds:
206
- case _.UnitType.kHertz:
207
- case _.UnitType.kKilohertz:
208
- case _.UnitType.kTurns:
209
- case _.UnitType.kFraction:
210
- case _.UnitType.kViewportWidth:
211
- case _.UnitType.kViewportHeight:
212
- case _.UnitType.kViewportInlineSize:
213
- case _.UnitType.kViewportBlockSize:
214
- case _.UnitType.kViewportMin:
215
- case _.UnitType.kViewportMax:
216
- case _.UnitType.kSmallViewportWidth:
217
- case _.UnitType.kSmallViewportHeight:
218
- case _.UnitType.kSmallViewportInlineSize:
219
- case _.UnitType.kSmallViewportBlockSize:
220
- case _.UnitType.kSmallViewportMin:
221
- case _.UnitType.kSmallViewportMax:
222
- case _.UnitType.kLargeViewportWidth:
223
- case _.UnitType.kLargeViewportHeight:
224
- case _.UnitType.kLargeViewportInlineSize:
225
- case _.UnitType.kLargeViewportBlockSize:
226
- case _.UnitType.kLargeViewportMin:
227
- case _.UnitType.kLargeViewportMax:
228
- case _.UnitType.kDynamicViewportWidth:
229
- case _.UnitType.kDynamicViewportHeight:
230
- case _.UnitType.kDynamicViewportInlineSize:
231
- case _.UnitType.kDynamicViewportBlockSize:
232
- case _.UnitType.kDynamicViewportMin:
233
- case _.UnitType.kDynamicViewportMax:
234
- case _.UnitType.kContainerWidth:
235
- case _.UnitType.kContainerHeight:
236
- case _.UnitType.kContainerInlineSize:
237
- case _.UnitType.kContainerBlockSize:
238
- case _.UnitType.kContainerMin:
239
- case _.UnitType.kContainerMax:
240
- {
241
- var kMinInteger = -999999;
242
- var kMaxInteger = 999999;
243
- var value = this.value;
244
- var unit = CSSUnitValue.unitTypeToString(this.unit);
245
-
246
- if (value < kMinInteger || value > kMaxInteger) {
247
- var unit_1 = CSSUnitValue.unitTypeToString(this.unit);
248
-
249
- if (!Number.isFinite(value) || Number.isNaN(value)) {
250
- text = CSSUnitValue.formatInfinityOrNaN(value, unit_1);
251
- } else {
252
- text = CSSUnitValue.formatNumber(value, unit_1);
253
- }
254
- } else {
255
- text = "".concat(value).concat(unit);
256
- }
257
- }
258
- }
259
-
260
- result += text;
261
- return result;
262
- };
263
-
264
- return CSSUnitValue;
265
- }(_CSSNumericValue.CSSNumericValue);
266
-
267
- exports.CSSUnitValue = CSSUnitValue;