@antv/g 5.0.22 → 5.0.23-alpha.4

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 +139 -4
  7. package/es/css/cssom/CSSNumericValue.js +1164 -5
  8. package/es/css/cssom/CSSTransformValue.d.ts +1 -1
  9. package/es/css/cssom/index.d.ts +0 -10
  10. package/es/css/cssom/index.js +1 -11
  11. package/es/css/parser/color.js +1 -1
  12. package/es/css/parser/dimension.js +1 -2
  13. package/es/css/parser/numeric.js +1 -1
  14. package/es/css/parser/path.d.ts +2 -2
  15. package/es/css/parser/path.js +1 -1
  16. package/es/css/parser/points.js +1 -1
  17. package/es/css/parser/transform-origin.js +1 -1
  18. package/es/css/properties/CSSPropertyPath.d.ts +14 -2
  19. package/es/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  20. package/es/css/properties/CSSPropertyTransform.js +1 -2
  21. package/es/display-objects/DisplayObject.js +4 -5
  22. package/es/display-objects/Path.d.ts +15 -15
  23. package/es/display-objects/Path.js +1 -1
  24. package/es/display-objects/Polygon.d.ts +8 -1
  25. package/es/display-objects/Polyline.d.ts +7 -5
  26. package/es/dom/Document.js +2 -2
  27. package/es/dom/Element.js +1 -2
  28. package/es/dom/EventTarget.js +1 -1
  29. package/es/dom/FederatedTouchEvent.d.ts +5 -3
  30. package/es/plugins/CullingPlugin.d.ts +0 -1
  31. package/es/plugins/CullingPlugin.js +3 -8
  32. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  33. package/es/plugins/DirtyCheckPlugin.js +9 -8
  34. package/es/plugins/EventPlugin.d.ts +1 -1
  35. package/es/plugins/EventPlugin.js +163 -148
  36. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  37. package/es/plugins/PrepareRendererPlugin.js +15 -16
  38. package/es/services/EventService.d.ts +8 -0
  39. package/es/services/EventService.js +274 -20
  40. package/es/services/RenderingService.d.ts +17 -16
  41. package/es/services/RenderingService.js +18 -17
  42. package/es/services/SceneGraphService.js +1 -1
  43. package/es/services/aabb/PathUpdater.d.ts +3 -3
  44. package/es/services/aabb/PolylineUpdater.d.ts +3 -3
  45. package/es/services/aabb/RectUpdater.js +1 -1
  46. package/es/types.d.ts +5 -3
  47. package/es/utils/assert.d.ts +6 -0
  48. package/es/utils/assert.js +18 -0
  49. package/es/utils/event.d.ts +18 -16
  50. package/es/utils/hooks.d.ts +280 -0
  51. package/es/utils/hooks.js +753 -0
  52. package/es/utils/index.d.ts +1 -0
  53. package/es/utils/index.js +2 -1
  54. package/es/utils/math.d.ts +1 -0
  55. package/es/utils/math.js +13 -2
  56. package/es/utils/string.d.ts +1 -0
  57. package/es/utils/string.js +8 -0
  58. package/es/utils/text.js +2 -1
  59. package/lib/AbstractRenderer.js +5 -0
  60. package/lib/camera/Camera.js +4 -4
  61. package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
  62. package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
  63. package/lib/css/cssom/CSSNumericValue.d.ts +139 -4
  64. package/lib/css/cssom/CSSNumericValue.js +1222 -52
  65. package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
  66. package/lib/css/cssom/index.d.ts +0 -10
  67. package/lib/css/cssom/index.js +0 -130
  68. package/lib/css/parser/color.js +5 -5
  69. package/lib/css/parser/dimension.js +1 -3
  70. package/lib/css/parser/numeric.js +3 -3
  71. package/lib/css/parser/path.d.ts +2 -2
  72. package/lib/css/parser/path.js +4 -4
  73. package/lib/css/parser/points.js +2 -2
  74. package/lib/css/parser/transform-origin.js +2 -2
  75. package/lib/css/properties/CSSPropertyPath.d.ts +14 -2
  76. package/lib/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  77. package/lib/css/properties/CSSPropertyTransform.js +0 -2
  78. package/lib/display-objects/DisplayObject.js +7 -9
  79. package/lib/display-objects/Path.d.ts +15 -15
  80. package/lib/display-objects/Path.js +3 -3
  81. package/lib/display-objects/Polygon.d.ts +8 -1
  82. package/lib/display-objects/Polyline.d.ts +7 -5
  83. package/lib/dom/Document.js +2 -2
  84. package/lib/dom/Element.js +1 -3
  85. package/lib/dom/EventTarget.js +9 -9
  86. package/lib/dom/FederatedTouchEvent.d.ts +5 -3
  87. package/lib/plugins/CullingPlugin.d.ts +0 -1
  88. package/lib/plugins/CullingPlugin.js +3 -7
  89. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  90. package/lib/plugins/DirtyCheckPlugin.js +10 -8
  91. package/lib/plugins/EventPlugin.d.ts +1 -1
  92. package/lib/plugins/EventPlugin.js +172 -156
  93. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  94. package/lib/plugins/PrepareRendererPlugin.js +14 -14
  95. package/lib/services/EventService.d.ts +8 -0
  96. package/lib/services/EventService.js +274 -19
  97. package/lib/services/RenderingService.d.ts +17 -16
  98. package/lib/services/RenderingService.js +19 -18
  99. package/lib/services/SceneGraphService.js +3 -3
  100. package/lib/services/aabb/PathUpdater.d.ts +3 -3
  101. package/lib/services/aabb/PolylineUpdater.d.ts +3 -3
  102. package/lib/services/aabb/RectUpdater.js +3 -3
  103. package/lib/types.d.ts +5 -3
  104. package/lib/utils/assert.d.ts +6 -0
  105. package/lib/utils/assert.js +30 -0
  106. package/lib/utils/event.d.ts +18 -16
  107. package/lib/utils/hooks.d.ts +280 -0
  108. package/lib/utils/hooks.js +759 -0
  109. package/lib/utils/index.d.ts +1 -0
  110. package/lib/utils/index.js +13 -0
  111. package/lib/utils/math.d.ts +1 -0
  112. package/lib/utils/math.js +17 -4
  113. package/lib/utils/string.d.ts +1 -0
  114. package/lib/utils/string.js +11 -0
  115. package/lib/utils/text.js +5 -3
  116. package/package.json +4 -7
  117. package/es/css/cssom/CSSMathInvert.d.ts +0 -14
  118. package/es/css/cssom/CSSMathInvert.js +0 -84
  119. package/es/css/cssom/CSSMathMax.d.ts +0 -17
  120. package/es/css/cssom/CSSMathMax.js +0 -118
  121. package/es/css/cssom/CSSMathMin.d.ts +0 -17
  122. package/es/css/cssom/CSSMathMin.js +0 -119
  123. package/es/css/cssom/CSSMathNegate.d.ts +0 -14
  124. package/es/css/cssom/CSSMathNegate.js +0 -80
  125. package/es/css/cssom/CSSMathProduct.d.ts +0 -16
  126. package/es/css/cssom/CSSMathProduct.js +0 -109
  127. package/es/css/cssom/CSSMathSum.d.ts +0 -17
  128. package/es/css/cssom/CSSMathSum.js +0 -117
  129. package/es/css/cssom/CSSMathValue.d.ts +0 -11
  130. package/es/css/cssom/CSSMathValue.js +0 -27
  131. package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
  132. package/es/css/cssom/CSSMathVariadic.js +0 -44
  133. package/es/css/cssom/CSSNumericValueType.d.ts +0 -33
  134. package/es/css/cssom/CSSNumericValueType.js +0 -259
  135. package/es/css/cssom/CSSUnitValue.d.ts +0 -33
  136. package/es/css/cssom/CSSUnitValue.js +0 -252
  137. package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
  138. package/lib/css/cssom/CSSMathInvert.js +0 -94
  139. package/lib/css/cssom/CSSMathMax.d.ts +0 -17
  140. package/lib/css/cssom/CSSMathMax.js +0 -128
  141. package/lib/css/cssom/CSSMathMin.d.ts +0 -17
  142. package/lib/css/cssom/CSSMathMin.js +0 -128
  143. package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
  144. package/lib/css/cssom/CSSMathNegate.js +0 -89
  145. package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
  146. package/lib/css/cssom/CSSMathProduct.js +0 -119
  147. package/lib/css/cssom/CSSMathSum.d.ts +0 -17
  148. package/lib/css/cssom/CSSMathSum.js +0 -129
  149. package/lib/css/cssom/CSSMathValue.d.ts +0 -11
  150. package/lib/css/cssom/CSSMathValue.js +0 -35
  151. package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
  152. package/lib/css/cssom/CSSMathVariadic.js +0 -55
  153. package/lib/css/cssom/CSSNumericValueType.d.ts +0 -33
  154. package/lib/css/cssom/CSSNumericValueType.js +0 -272
  155. package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
  156. package/lib/css/cssom/CSSUnitValue.js +0 -267
@@ -1,109 +0,0 @@
1
- import { __extends } from "tslib";
2
- import { DCHECK_NE } from '../../utils';
3
- import { CSSMathVariadic } from './CSSMathVariadic';
4
- import { typeCheck, CSSStyleValueType, CSSNumericValueType, Nested, ParenLess } from '.';
5
- /**
6
- * Represents the product of one or more CSSNumericValues.
7
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathproduct
8
- */
9
-
10
- var CSSMathProduct =
11
- /** @class */
12
- function (_super) {
13
- __extends(CSSMathProduct, _super);
14
-
15
- function CSSMathProduct() {
16
- var _this = _super !== null && _super.apply(this, arguments) || this;
17
-
18
- _this.operator = 'product';
19
- return _this;
20
- }
21
-
22
- CSSMathProduct.create = function (values) {
23
- var error = false;
24
- var finalType = typeCheck(values, CSSNumericValueType.multiply, error);
25
- return error ? null : new CSSMathProduct(values, finalType);
26
- };
27
-
28
- CSSMathProduct.multiplyUnitMaps = function (a, b) {
29
- Object.keys(b).forEach(function (key) {
30
- DCHECK_NE(b[key].value, 0);
31
- var old_value = key in a ? a[key].value : 0;
32
-
33
- if (old_value + b[key].value === 0) {
34
- delete a[key];
35
- } else {
36
- a[key] = old_value + b[key].value;
37
- }
38
- });
39
- return a;
40
- };
41
-
42
- CSSMathProduct.prototype.clone = function () {
43
- return new CSSMathProduct(this.values, this.type_);
44
- };
45
-
46
- CSSMathProduct.prototype.getType = function () {
47
- return CSSStyleValueType.kProductType;
48
- }; // toCalcExpressionNode() {
49
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kMultiply);
50
- // }
51
-
52
-
53
- CSSMathProduct.prototype.sumValue = function () {
54
- var sum = [{
55
- value: 1,
56
- units: {}
57
- }];
58
- this.numericValues().forEach(function (value) {
59
- var child_sum = value.sumValue();
60
-
61
- if (!child_sum.length) {
62
- return null;
63
- }
64
-
65
- var new_sum = [];
66
- sum.forEach(function (a) {
67
- child_sum.forEach(function (b) {
68
- new_sum.push({
69
- value: a.value * b.value,
70
- units: CSSMathProduct.multiplyUnitMaps(a.units, b.units)
71
- });
72
- });
73
- });
74
- sum = new_sum;
75
- });
76
- return sum;
77
- };
78
-
79
- CSSMathProduct.prototype.buildCSSText = function (nested, paren_less, result) {
80
- if (paren_less == ParenLess.kNo) {
81
- result += nested === Nested.kYes ? '(' : 'calc(';
82
- }
83
-
84
- var values = this.numericValues();
85
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
86
-
87
- for (var i = 1; i < values.length; i++) {
88
- var arg = values[i];
89
-
90
- if (arg.getType() === CSSStyleValueType.kInvertType) {
91
- result += ' / ';
92
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
93
- } else {
94
- result += ' * ';
95
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
96
- }
97
- }
98
-
99
- if (paren_less === ParenLess.kNo) {
100
- result += ')';
101
- }
102
-
103
- return result;
104
- };
105
-
106
- return CSSMathProduct;
107
- }(CSSMathVariadic);
108
-
109
- export { CSSMathProduct };
@@ -1,17 +0,0 @@
1
- import type { CSSNumericValue, CSSNumericSumValue, UnitMap } from '.';
2
- import { CSSMathVariadic } from './CSSMathVariadic';
3
- import { CSSStyleValueType, CSSNumericValueType, Nested, ParenLess } from '.';
4
- /**
5
- * Represents the sum of one or more CSSNumericValues.
6
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
7
- */
8
- export declare class CSSMathSum extends CSSMathVariadic {
9
- static create(values: CSSNumericValue[]): CSSMathSum;
10
- static numericTypeFromUnitMap(units: UnitMap): CSSNumericValueType;
11
- static canCreateNumericTypeFromSumValue(sum: CSSNumericSumValue): boolean;
12
- operator: string;
13
- clone(): CSSMathSum;
14
- getType(): CSSStyleValueType;
15
- sumValue(): CSSNumericSumValue;
16
- buildCSSText(nested: Nested, paren_less: ParenLess, result: string): string;
17
- }
@@ -1,117 +0,0 @@
1
- import { __assign, __extends } from "tslib";
2
- import { DCHECK } from '../../utils';
3
- import { CSSMathVariadic } from './CSSMathVariadic';
4
- import { typeCheck, CSSStyleValueType, CSSNumericValueType, Nested, ParenLess } from '.';
5
- /**
6
- * Represents the sum of one or more CSSNumericValues.
7
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
8
- */
9
-
10
- var CSSMathSum =
11
- /** @class */
12
- function (_super) {
13
- __extends(CSSMathSum, _super);
14
-
15
- function CSSMathSum() {
16
- var _this = _super !== null && _super.apply(this, arguments) || this;
17
-
18
- _this.operator = 'sum';
19
- return _this;
20
- }
21
-
22
- CSSMathSum.create = function (values) {
23
- var error = false;
24
- var finalType = typeCheck(values, CSSNumericValueType.add, error);
25
- return error ? null : new CSSMathSum(values, finalType);
26
- };
27
-
28
- CSSMathSum.numericTypeFromUnitMap = function (units) {
29
- var type = new CSSNumericValueType();
30
- Object.keys(units).forEach(function (key) {
31
- var exp = units[key];
32
- var error = false;
33
- type = CSSNumericValueType.multiply(type, new CSSNumericValueType(Number(key), exp), error);
34
- DCHECK(!error);
35
- });
36
- return type;
37
- };
38
-
39
- CSSMathSum.canCreateNumericTypeFromSumValue = function (sum) {
40
- var _this = this;
41
-
42
- DCHECK(!!sum.length);
43
- var first_type = this.numericTypeFromUnitMap(sum[0].units);
44
- return sum.every(function (term) {
45
- var error = false;
46
- CSSNumericValueType.add(first_type, _this.numericTypeFromUnitMap(term.units), error);
47
- return !error;
48
- });
49
- };
50
-
51
- CSSMathSum.prototype.clone = function () {
52
- return new CSSMathSum(this.values, this.type_);
53
- };
54
-
55
- CSSMathSum.prototype.getType = function () {
56
- return CSSStyleValueType.kSumType;
57
- }; // toCalcExpressionNode() {
58
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
59
- // }
60
-
61
-
62
- CSSMathSum.prototype.sumValue = function () {
63
- var sum = [];
64
- this.numericValues().forEach(function (value) {
65
- var child_sum = value.sumValue();
66
-
67
- if (!child_sum.length) {
68
- return null;
69
- }
70
-
71
- child_sum.forEach(function (term) {
72
- var index = sum.findIndex(function (s) {
73
- return JSON.stringify(s.units) === JSON.stringify(term.units);
74
- });
75
-
76
- if (index === -1) {
77
- sum.push(__assign({}, term));
78
- } else {
79
- sum[index].value += term.value;
80
- }
81
- });
82
- });
83
- if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
84
- return sum;
85
- };
86
-
87
- CSSMathSum.prototype.buildCSSText = function (nested, paren_less, result) {
88
- if (paren_less == ParenLess.kNo) {
89
- result += nested === Nested.kYes ? '(' : 'calc(';
90
- }
91
-
92
- var values = this.numericValues();
93
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
94
-
95
- for (var i = 1; i < values.length; i++) {
96
- var arg = values[i];
97
-
98
- if (arg.getType() === CSSStyleValueType.kNegateType) {
99
- result += ' - ';
100
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
101
- } else {
102
- result += ' + ';
103
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
104
- }
105
- }
106
-
107
- if (paren_less === ParenLess.kNo) {
108
- result += ')';
109
- }
110
-
111
- return result;
112
- };
113
-
114
- return CSSMathSum;
115
- }(CSSMathVariadic);
116
-
117
- export { 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,27 +0,0 @@
1
- import { __extends } from "tslib";
2
- import { CSSNumericValue } from './CSSNumericValue';
3
- /**
4
- * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
5
- *
6
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
7
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
8
- */
9
-
10
- var CSSMathValue =
11
- /** @class */
12
- function (_super) {
13
- __extends(CSSMathValue, _super);
14
-
15
- function CSSMathValue() {
16
- return _super !== null && _super.apply(this, arguments) || this;
17
- } // From CSSNumericValue
18
-
19
-
20
- CSSMathValue.prototype.isUnitValue = function () {
21
- return false;
22
- };
23
-
24
- return CSSMathValue;
25
- }(CSSNumericValue);
26
-
27
- export { 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,44 +0,0 @@
1
- import { __extends } from "tslib";
2
- import { CSSMathValue } from './CSSMathValue';
3
- export function typeCheck(values, op, error) {
4
- error = false;
5
- var final_type = values[0].type_;
6
-
7
- for (var i = 1; i < values.length; i++) {
8
- final_type = op(final_type, values[i].type_, error);
9
- if (error) return final_type;
10
- }
11
-
12
- return final_type;
13
- } // Represents an arithmetic operation with one or more CSSNumericValues.
14
-
15
- var CSSMathVariadic =
16
- /** @class */
17
- function (_super) {
18
- __extends(CSSMathVariadic, _super);
19
-
20
- function CSSMathVariadic(values, type) {
21
- var _this = _super.call(this, type) || this;
22
-
23
- _this.values = values;
24
- return _this;
25
- }
26
-
27
- CSSMathVariadic.prototype.numericValues = function () {
28
- return this.values;
29
- };
30
-
31
- CSSMathVariadic.prototype.equals = function (other) {
32
- if (this.getType() !== other.getType()) {
33
- return false;
34
- }
35
-
36
- return this.values.every(function (value, i) {
37
- return value.equals(other.values[i]);
38
- });
39
- };
40
-
41
- return CSSMathVariadic;
42
- }(CSSMathValue);
43
-
44
- export { CSSMathVariadic };
@@ -1,33 +0,0 @@
1
- import { UnitType } from '.';
2
- export declare enum BaseType {
3
- kLength = 0,
4
- kAngle = 1,
5
- kTime = 2,
6
- kFrequency = 3,
7
- kResolution = 4,
8
- kFlex = 5,
9
- kPercent = 6,
10
- kNumBaseTypes = 7
11
- }
12
- export declare function unitTypeToBaseType(unit: UnitType): BaseType.kLength | BaseType.kAngle | BaseType.kTime | BaseType.kFrequency | BaseType.kResolution | BaseType.kFlex | BaseType.kPercent;
13
- export declare function baseTypeToString(baseType: BaseType): "" | "percent" | "length" | "angle" | "time" | "frequency" | "resolution" | "flex";
14
- export declare class CSSNumericValueType {
15
- private exponents;
16
- private numNonZeroEntries;
17
- percentHint: BaseType;
18
- hasPercentHint: boolean;
19
- constructor(unit?: UnitType, exponent?: number);
20
- applyPercentHint(hint: BaseType): void;
21
- hasNonZeroEntries(): boolean;
22
- isOnlyNonZeroEntry(baseType: BaseType, value: number): boolean;
23
- exponent(type: BaseType): number;
24
- setExponent(type: BaseType, newValue: number): void;
25
- static negateExponents(type: CSSNumericValueType): CSSNumericValueType;
26
- matchesBaseType(baseType: BaseType): boolean;
27
- matchesPercentage(): boolean;
28
- matchesBaseTypePercentage(baseType: BaseType): boolean;
29
- matchesNumber(): boolean;
30
- matchesNumberPercentage(): boolean;
31
- static add(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
32
- static multiply(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
33
- }
@@ -1,259 +0,0 @@
1
- import { DCHECK_EQ, DCHECK_NE } from '../../utils';
2
- import { UnitType } from '.'; // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
3
-
4
- export var BaseType;
5
-
6
- (function (BaseType) {
7
- BaseType[BaseType["kLength"] = 0] = "kLength";
8
- BaseType[BaseType["kAngle"] = 1] = "kAngle";
9
- BaseType[BaseType["kTime"] = 2] = "kTime";
10
- BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
11
- BaseType[BaseType["kResolution"] = 4] = "kResolution";
12
- BaseType[BaseType["kFlex"] = 5] = "kFlex";
13
- BaseType[BaseType["kPercent"] = 6] = "kPercent";
14
- BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
15
- })(BaseType || (BaseType = {}));
16
-
17
- export function unitTypeToBaseType(unit) {
18
- DCHECK_NE(unit, UnitType.kNumber);
19
-
20
- switch (unit) {
21
- case UnitType.kEms:
22
- case UnitType.kExs:
23
- case UnitType.kPixels:
24
- case UnitType.kCentimeters:
25
- case UnitType.kMillimeters:
26
- case UnitType.kQuarterMillimeters:
27
- case UnitType.kInches:
28
- case UnitType.kPoints:
29
- case UnitType.kPicas:
30
- case UnitType.kUserUnits:
31
- case UnitType.kViewportWidth:
32
- case UnitType.kViewportHeight:
33
- case UnitType.kViewportInlineSize:
34
- case UnitType.kViewportBlockSize:
35
- case UnitType.kViewportMin:
36
- case UnitType.kViewportMax:
37
- case UnitType.kSmallViewportWidth:
38
- case UnitType.kSmallViewportHeight:
39
- case UnitType.kSmallViewportInlineSize:
40
- case UnitType.kSmallViewportBlockSize:
41
- case UnitType.kSmallViewportMin:
42
- case UnitType.kSmallViewportMax:
43
- case UnitType.kLargeViewportWidth:
44
- case UnitType.kLargeViewportHeight:
45
- case UnitType.kLargeViewportInlineSize:
46
- case UnitType.kLargeViewportBlockSize:
47
- case UnitType.kLargeViewportMin:
48
- case UnitType.kLargeViewportMax:
49
- case UnitType.kDynamicViewportWidth:
50
- case UnitType.kDynamicViewportHeight:
51
- case UnitType.kDynamicViewportInlineSize:
52
- case UnitType.kDynamicViewportBlockSize:
53
- case UnitType.kDynamicViewportMin:
54
- case UnitType.kDynamicViewportMax:
55
- case UnitType.kContainerWidth:
56
- case UnitType.kContainerHeight:
57
- case UnitType.kContainerInlineSize:
58
- case UnitType.kContainerBlockSize:
59
- case UnitType.kContainerMin:
60
- case UnitType.kContainerMax:
61
- case UnitType.kRems:
62
- case UnitType.kChs:
63
- return BaseType.kLength;
64
-
65
- case UnitType.kMilliseconds:
66
- case UnitType.kSeconds:
67
- return BaseType.kTime;
68
-
69
- case UnitType.kDegrees:
70
- case UnitType.kRadians:
71
- case UnitType.kGradians:
72
- case UnitType.kTurns:
73
- return BaseType.kAngle;
74
-
75
- case UnitType.kHertz:
76
- case UnitType.kKilohertz:
77
- return BaseType.kFrequency;
78
-
79
- case UnitType.kDotsPerPixel:
80
- case UnitType.kDotsPerInch:
81
- case UnitType.kDotsPerCentimeter:
82
- return BaseType.kResolution;
83
-
84
- case UnitType.kFraction:
85
- return BaseType.kFlex;
86
-
87
- case UnitType.kPercentage:
88
- return BaseType.kPercent;
89
-
90
- default:
91
- return BaseType.kLength;
92
- }
93
- }
94
- export function baseTypeToString(baseType) {
95
- switch (baseType) {
96
- case BaseType.kLength:
97
- return 'length';
98
-
99
- case BaseType.kAngle:
100
- return 'angle';
101
-
102
- case BaseType.kTime:
103
- return 'time';
104
-
105
- case BaseType.kFrequency:
106
- return 'frequency';
107
-
108
- case BaseType.kResolution:
109
- return 'resolution';
110
-
111
- case BaseType.kFlex:
112
- return 'flex';
113
-
114
- case BaseType.kPercent:
115
- return 'percent';
116
-
117
- default:
118
- break;
119
- }
120
-
121
- return '';
122
- }
123
-
124
- var CSSNumericValueType =
125
- /** @class */
126
- function () {
127
- function CSSNumericValueType(unit, exponent) {
128
- if (unit === void 0) {
129
- unit = UnitType.kNumber;
130
- }
131
-
132
- if (exponent === void 0) {
133
- exponent = 1;
134
- }
135
-
136
- this.exponents = [];
137
- this.numNonZeroEntries = 0;
138
- this.percentHint = BaseType.kPercent;
139
- this.hasPercentHint = false;
140
- this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
141
-
142
- if (unit !== UnitType.kNumber) {
143
- this.setExponent(unitTypeToBaseType(unit), exponent);
144
- }
145
- }
146
-
147
- CSSNumericValueType.prototype.applyPercentHint = function (hint) {
148
- DCHECK_NE(hint, BaseType.kPercent);
149
- this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
150
- this.setExponent(BaseType.kPercent, 0);
151
- this.percentHint = hint;
152
- this.hasPercentHint = true;
153
- };
154
-
155
- CSSNumericValueType.prototype.hasNonZeroEntries = function () {
156
- return this.numNonZeroEntries > 0;
157
- };
158
-
159
- CSSNumericValueType.prototype.isOnlyNonZeroEntry = function (baseType, value) {
160
- DCHECK_NE(value, 0);
161
- return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
162
- };
163
-
164
- CSSNumericValueType.prototype.exponent = function (type) {
165
- return this.exponents[type];
166
- };
167
-
168
- CSSNumericValueType.prototype.setExponent = function (type, newValue) {
169
- var oldValue = this.exponents[type];
170
-
171
- if (oldValue == 0 && newValue !== 0) {
172
- this.numNonZeroEntries++;
173
- } else if (oldValue !== 0 && newValue == 0) {
174
- this.numNonZeroEntries--;
175
- }
176
-
177
- this.exponents[type] = newValue;
178
- };
179
-
180
- CSSNumericValueType.negateExponents = function (type) {
181
- type.exponents.forEach(function (v) {
182
- return v *= -1;
183
- });
184
- return type;
185
- };
186
-
187
- CSSNumericValueType.prototype.matchesBaseType = function (baseType) {
188
- DCHECK_NE(baseType, BaseType.kPercent);
189
- return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
190
- };
191
-
192
- CSSNumericValueType.prototype.matchesPercentage = function () {
193
- return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
194
- };
195
-
196
- CSSNumericValueType.prototype.matchesBaseTypePercentage = function (baseType) {
197
- DCHECK_NE(baseType, BaseType.kPercent);
198
- return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
199
- };
200
-
201
- CSSNumericValueType.prototype.matchesNumber = function () {
202
- return !this.hasNonZeroEntries() && !this.hasPercentHint;
203
- };
204
-
205
- CSSNumericValueType.prototype.matchesNumberPercentage = function () {
206
- return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
207
- };
208
-
209
- CSSNumericValueType.add = function (type1, type2, error) {
210
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
211
- error = true;
212
- return type1;
213
- }
214
-
215
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
216
- DCHECK_EQ(type1.percentHint, type2.percentHint); // Match up base types. Try to use the percent hint to match up any
217
- // differences.
218
-
219
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
220
- var base_type = i;
221
-
222
- if (type1.exponents[i] !== type2.exponents[i]) {
223
- if (base_type !== BaseType.kPercent) {
224
- type1.applyPercentHint(base_type);
225
- type2.applyPercentHint(base_type);
226
- }
227
-
228
- if (type1.exponents[i] !== type2.exponents[i]) {
229
- error = true;
230
- return type1;
231
- }
232
- }
233
- }
234
-
235
- error = false;
236
- return type1;
237
- };
238
-
239
- CSSNumericValueType.multiply = function (type1, type2, error) {
240
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
241
- error = true;
242
- return type1;
243
- }
244
-
245
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
246
-
247
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
248
- var base_type = i;
249
- type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
250
- }
251
-
252
- error = false;
253
- return type1;
254
- };
255
-
256
- return CSSNumericValueType;
257
- }();
258
-
259
- export { CSSNumericValueType };
@@ -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
- }