@antv/g 5.0.23-alpha.0 → 5.0.23-alpha.12
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.
- package/dist/index.umd.min.js +2 -2
- package/es/css/StyleValueRegistry.d.ts +2 -0
- package/es/css/StyleValueRegistry.js +7 -3
- package/es/css/cssom/CSSKeywordValue.d.ts +1 -1
- package/es/css/cssom/CSSNumericSumValue.d.ts +1 -1
- package/es/css/cssom/CSSNumericValue.d.ts +141 -4
- package/es/css/cssom/CSSNumericValue.js +1166 -5
- package/es/css/cssom/CSSTransformValue.d.ts +1 -1
- package/es/css/cssom/index.d.ts +0 -10
- package/es/css/cssom/index.js +1 -11
- package/es/css/parser/numeric.d.ts +1 -1
- package/es/css/parser/numeric.js +1 -1
- package/es/css/parser/transform-origin.d.ts +1 -1
- package/es/css/parser/transform-origin.js +1 -1
- package/es/css/parser/transform.d.ts +1 -3
- package/es/css/parser/transform.js +9 -8
- package/es/css/properties/CSSPropertyTransform.js +2 -2
- package/es/plugins/PrepareRendererPlugin.js +2 -2
- package/es/services/RenderingService.js +2 -2
- package/lib/css/StyleValueRegistry.d.ts +2 -0
- package/lib/css/StyleValueRegistry.js +13 -5
- package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
- package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
- package/lib/css/cssom/CSSNumericValue.d.ts +141 -4
- package/lib/css/cssom/CSSNumericValue.js +1232 -58
- package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
- package/lib/css/cssom/index.d.ts +0 -10
- package/lib/css/cssom/index.js +0 -130
- package/lib/css/parser/numeric.d.ts +1 -1
- package/lib/css/parser/numeric.js +4 -4
- package/lib/css/parser/transform-origin.d.ts +1 -1
- package/lib/css/parser/transform-origin.js +2 -2
- package/lib/css/parser/transform.d.ts +1 -3
- package/lib/css/parser/transform.js +25 -24
- package/lib/css/properties/CSSPropertyTransform.js +18 -18
- package/lib/plugins/PrepareRendererPlugin.js +2 -2
- package/lib/services/RenderingService.js +2 -2
- package/package.json +3 -3
- package/es/css/cssom/CSSMathInvert.d.ts +0 -14
- package/es/css/cssom/CSSMathInvert.js +0 -84
- package/es/css/cssom/CSSMathMax.d.ts +0 -17
- package/es/css/cssom/CSSMathMax.js +0 -118
- package/es/css/cssom/CSSMathMin.d.ts +0 -17
- package/es/css/cssom/CSSMathMin.js +0 -119
- package/es/css/cssom/CSSMathNegate.d.ts +0 -14
- package/es/css/cssom/CSSMathNegate.js +0 -80
- package/es/css/cssom/CSSMathProduct.d.ts +0 -16
- package/es/css/cssom/CSSMathProduct.js +0 -109
- package/es/css/cssom/CSSMathSum.d.ts +0 -17
- package/es/css/cssom/CSSMathSum.js +0 -117
- package/es/css/cssom/CSSMathValue.d.ts +0 -11
- package/es/css/cssom/CSSMathValue.js +0 -27
- package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
- package/es/css/cssom/CSSMathVariadic.js +0 -44
- package/es/css/cssom/CSSNumericValueType.d.ts +0 -33
- package/es/css/cssom/CSSNumericValueType.js +0 -259
- package/es/css/cssom/CSSUnitValue.d.ts +0 -33
- package/es/css/cssom/CSSUnitValue.js +0 -252
- package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
- package/lib/css/cssom/CSSMathInvert.js +0 -94
- package/lib/css/cssom/CSSMathMax.d.ts +0 -17
- package/lib/css/cssom/CSSMathMax.js +0 -128
- package/lib/css/cssom/CSSMathMin.d.ts +0 -17
- package/lib/css/cssom/CSSMathMin.js +0 -128
- package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
- package/lib/css/cssom/CSSMathNegate.js +0 -89
- package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
- package/lib/css/cssom/CSSMathProduct.js +0 -119
- package/lib/css/cssom/CSSMathSum.d.ts +0 -17
- package/lib/css/cssom/CSSMathSum.js +0 -129
- package/lib/css/cssom/CSSMathValue.d.ts +0 -11
- package/lib/css/cssom/CSSMathValue.js +0 -35
- package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
- package/lib/css/cssom/CSSMathVariadic.js +0 -55
- package/lib/css/cssom/CSSNumericValueType.d.ts +0 -33
- package/lib/css/cssom/CSSNumericValueType.js +0 -272
- package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
- package/lib/css/cssom/CSSUnitValue.js +0 -267
|
@@ -3,15 +3,280 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.CSSNumericValue = void 0;
|
|
6
|
+
exports.Opx = exports.Odeg = exports.CSSUnitValue = exports.CSSNumericValueType = exports.CSSNumericValue = exports.CSSMathVariadic = exports.CSSMathValue = exports.CSSMathSum = exports.CSSMathProduct = exports.CSSMathNegate = exports.CSSMathMin = exports.CSSMathMax = exports.CSSMathInvert = exports.BaseType = void 0;
|
|
7
|
+
exports.baseTypeToString = baseTypeToString;
|
|
8
|
+
exports.typeCheck = typeCheck;
|
|
9
|
+
exports.unitTypeToBaseType = unitTypeToBaseType;
|
|
7
10
|
|
|
8
11
|
var _tslib = require("tslib");
|
|
9
12
|
|
|
10
|
-
var
|
|
13
|
+
var _assert = require("../../utils/assert");
|
|
14
|
+
|
|
15
|
+
var _CSSMathOperator = require("./CSSMathOperator");
|
|
11
16
|
|
|
12
17
|
var _CSSStyleValue = require("./CSSStyleValue");
|
|
13
18
|
|
|
14
|
-
var
|
|
19
|
+
var _types = require("./types");
|
|
20
|
+
|
|
21
|
+
// https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
|
|
22
|
+
var BaseType;
|
|
23
|
+
exports.BaseType = BaseType;
|
|
24
|
+
|
|
25
|
+
(function (BaseType) {
|
|
26
|
+
BaseType[BaseType["kLength"] = 0] = "kLength";
|
|
27
|
+
BaseType[BaseType["kAngle"] = 1] = "kAngle";
|
|
28
|
+
BaseType[BaseType["kTime"] = 2] = "kTime";
|
|
29
|
+
BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
|
|
30
|
+
BaseType[BaseType["kResolution"] = 4] = "kResolution";
|
|
31
|
+
BaseType[BaseType["kFlex"] = 5] = "kFlex";
|
|
32
|
+
BaseType[BaseType["kPercent"] = 6] = "kPercent";
|
|
33
|
+
BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
|
|
34
|
+
})(BaseType || (exports.BaseType = BaseType = {}));
|
|
35
|
+
|
|
36
|
+
function unitTypeToBaseType(unit) {
|
|
37
|
+
(0, _assert.DCHECK_NE)(unit, _types.UnitType.kNumber);
|
|
38
|
+
|
|
39
|
+
switch (unit) {
|
|
40
|
+
case _types.UnitType.kEms:
|
|
41
|
+
case _types.UnitType.kExs:
|
|
42
|
+
case _types.UnitType.kPixels:
|
|
43
|
+
case _types.UnitType.kCentimeters:
|
|
44
|
+
case _types.UnitType.kMillimeters:
|
|
45
|
+
case _types.UnitType.kQuarterMillimeters:
|
|
46
|
+
case _types.UnitType.kInches:
|
|
47
|
+
case _types.UnitType.kPoints:
|
|
48
|
+
case _types.UnitType.kPicas:
|
|
49
|
+
case _types.UnitType.kUserUnits:
|
|
50
|
+
case _types.UnitType.kViewportWidth:
|
|
51
|
+
case _types.UnitType.kViewportHeight:
|
|
52
|
+
case _types.UnitType.kViewportInlineSize:
|
|
53
|
+
case _types.UnitType.kViewportBlockSize:
|
|
54
|
+
case _types.UnitType.kViewportMin:
|
|
55
|
+
case _types.UnitType.kViewportMax:
|
|
56
|
+
case _types.UnitType.kSmallViewportWidth:
|
|
57
|
+
case _types.UnitType.kSmallViewportHeight:
|
|
58
|
+
case _types.UnitType.kSmallViewportInlineSize:
|
|
59
|
+
case _types.UnitType.kSmallViewportBlockSize:
|
|
60
|
+
case _types.UnitType.kSmallViewportMin:
|
|
61
|
+
case _types.UnitType.kSmallViewportMax:
|
|
62
|
+
case _types.UnitType.kLargeViewportWidth:
|
|
63
|
+
case _types.UnitType.kLargeViewportHeight:
|
|
64
|
+
case _types.UnitType.kLargeViewportInlineSize:
|
|
65
|
+
case _types.UnitType.kLargeViewportBlockSize:
|
|
66
|
+
case _types.UnitType.kLargeViewportMin:
|
|
67
|
+
case _types.UnitType.kLargeViewportMax:
|
|
68
|
+
case _types.UnitType.kDynamicViewportWidth:
|
|
69
|
+
case _types.UnitType.kDynamicViewportHeight:
|
|
70
|
+
case _types.UnitType.kDynamicViewportInlineSize:
|
|
71
|
+
case _types.UnitType.kDynamicViewportBlockSize:
|
|
72
|
+
case _types.UnitType.kDynamicViewportMin:
|
|
73
|
+
case _types.UnitType.kDynamicViewportMax:
|
|
74
|
+
case _types.UnitType.kContainerWidth:
|
|
75
|
+
case _types.UnitType.kContainerHeight:
|
|
76
|
+
case _types.UnitType.kContainerInlineSize:
|
|
77
|
+
case _types.UnitType.kContainerBlockSize:
|
|
78
|
+
case _types.UnitType.kContainerMin:
|
|
79
|
+
case _types.UnitType.kContainerMax:
|
|
80
|
+
case _types.UnitType.kRems:
|
|
81
|
+
case _types.UnitType.kChs:
|
|
82
|
+
return BaseType.kLength;
|
|
83
|
+
|
|
84
|
+
case _types.UnitType.kMilliseconds:
|
|
85
|
+
case _types.UnitType.kSeconds:
|
|
86
|
+
return BaseType.kTime;
|
|
87
|
+
|
|
88
|
+
case _types.UnitType.kDegrees:
|
|
89
|
+
case _types.UnitType.kRadians:
|
|
90
|
+
case _types.UnitType.kGradians:
|
|
91
|
+
case _types.UnitType.kTurns:
|
|
92
|
+
return BaseType.kAngle;
|
|
93
|
+
|
|
94
|
+
case _types.UnitType.kHertz:
|
|
95
|
+
case _types.UnitType.kKilohertz:
|
|
96
|
+
return BaseType.kFrequency;
|
|
97
|
+
|
|
98
|
+
case _types.UnitType.kDotsPerPixel:
|
|
99
|
+
case _types.UnitType.kDotsPerInch:
|
|
100
|
+
case _types.UnitType.kDotsPerCentimeter:
|
|
101
|
+
return BaseType.kResolution;
|
|
102
|
+
|
|
103
|
+
case _types.UnitType.kFraction:
|
|
104
|
+
return BaseType.kFlex;
|
|
105
|
+
|
|
106
|
+
case _types.UnitType.kPercentage:
|
|
107
|
+
return BaseType.kPercent;
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
return BaseType.kLength;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function baseTypeToString(baseType) {
|
|
115
|
+
switch (baseType) {
|
|
116
|
+
case BaseType.kLength:
|
|
117
|
+
return 'length';
|
|
118
|
+
|
|
119
|
+
case BaseType.kAngle:
|
|
120
|
+
return 'angle';
|
|
121
|
+
|
|
122
|
+
case BaseType.kTime:
|
|
123
|
+
return 'time';
|
|
124
|
+
|
|
125
|
+
case BaseType.kFrequency:
|
|
126
|
+
return 'frequency';
|
|
127
|
+
|
|
128
|
+
case BaseType.kResolution:
|
|
129
|
+
return 'resolution';
|
|
130
|
+
|
|
131
|
+
case BaseType.kFlex:
|
|
132
|
+
return 'flex';
|
|
133
|
+
|
|
134
|
+
case BaseType.kPercent:
|
|
135
|
+
return 'percent';
|
|
136
|
+
|
|
137
|
+
default:
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
var CSSNumericValueType =
|
|
145
|
+
/** @class */
|
|
146
|
+
function () {
|
|
147
|
+
function CSSNumericValueType(unit, exponent) {
|
|
148
|
+
if (unit === void 0) {
|
|
149
|
+
unit = _types.UnitType.kNumber;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (exponent === void 0) {
|
|
153
|
+
exponent = 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.exponents = [];
|
|
157
|
+
this.numNonZeroEntries = 0;
|
|
158
|
+
this.percentHint = BaseType.kPercent;
|
|
159
|
+
this.hasPercentHint = false;
|
|
160
|
+
this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
|
|
161
|
+
|
|
162
|
+
if (unit !== _types.UnitType.kNumber) {
|
|
163
|
+
this.setExponent(unitTypeToBaseType(unit), exponent);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
CSSNumericValueType.prototype.applyPercentHint = function (hint) {
|
|
168
|
+
(0, _assert.DCHECK_NE)(hint, BaseType.kPercent);
|
|
169
|
+
this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
|
|
170
|
+
this.setExponent(BaseType.kPercent, 0);
|
|
171
|
+
this.percentHint = hint;
|
|
172
|
+
this.hasPercentHint = true;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
CSSNumericValueType.prototype.hasNonZeroEntries = function () {
|
|
176
|
+
return this.numNonZeroEntries > 0;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
CSSNumericValueType.prototype.isOnlyNonZeroEntry = function (baseType, value) {
|
|
180
|
+
(0, _assert.DCHECK_NE)(value, 0);
|
|
181
|
+
return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
CSSNumericValueType.prototype.exponent = function (type) {
|
|
185
|
+
return this.exponents[type];
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
CSSNumericValueType.prototype.setExponent = function (type, newValue) {
|
|
189
|
+
var oldValue = this.exponents[type];
|
|
190
|
+
|
|
191
|
+
if (oldValue == 0 && newValue !== 0) {
|
|
192
|
+
this.numNonZeroEntries++;
|
|
193
|
+
} else if (oldValue !== 0 && newValue == 0) {
|
|
194
|
+
this.numNonZeroEntries--;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.exponents[type] = newValue;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
CSSNumericValueType.negateExponents = function (type) {
|
|
201
|
+
type.exponents.forEach(function (v) {
|
|
202
|
+
return v *= -1;
|
|
203
|
+
});
|
|
204
|
+
return type;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
CSSNumericValueType.prototype.matchesBaseType = function (baseType) {
|
|
208
|
+
(0, _assert.DCHECK_NE)(baseType, BaseType.kPercent);
|
|
209
|
+
return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
CSSNumericValueType.prototype.matchesPercentage = function () {
|
|
213
|
+
return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
CSSNumericValueType.prototype.matchesBaseTypePercentage = function (baseType) {
|
|
217
|
+
(0, _assert.DCHECK_NE)(baseType, BaseType.kPercent);
|
|
218
|
+
return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
CSSNumericValueType.prototype.matchesNumber = function () {
|
|
222
|
+
return !this.hasNonZeroEntries() && !this.hasPercentHint;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
CSSNumericValueType.prototype.matchesNumberPercentage = function () {
|
|
226
|
+
return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
CSSNumericValueType.add = function (type1, type2, error) {
|
|
230
|
+
if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
|
|
231
|
+
error = true;
|
|
232
|
+
return type1;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
|
|
236
|
+
(0, _assert.DCHECK_EQ)(type1.percentHint, type2.percentHint); // Match up base types. Try to use the percent hint to match up any
|
|
237
|
+
// differences.
|
|
238
|
+
|
|
239
|
+
for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
|
|
240
|
+
var base_type = i;
|
|
241
|
+
|
|
242
|
+
if (type1.exponents[i] !== type2.exponents[i]) {
|
|
243
|
+
if (base_type !== BaseType.kPercent) {
|
|
244
|
+
type1.applyPercentHint(base_type);
|
|
245
|
+
type2.applyPercentHint(base_type);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (type1.exponents[i] !== type2.exponents[i]) {
|
|
249
|
+
error = true;
|
|
250
|
+
return type1;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
error = false;
|
|
256
|
+
return type1;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
CSSNumericValueType.multiply = function (type1, type2, error) {
|
|
260
|
+
if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
|
|
261
|
+
error = true;
|
|
262
|
+
return type1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
|
|
266
|
+
|
|
267
|
+
for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
|
|
268
|
+
var base_type = i;
|
|
269
|
+
type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
error = false;
|
|
273
|
+
return type1;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
return CSSNumericValueType;
|
|
277
|
+
}();
|
|
278
|
+
|
|
279
|
+
exports.CSSNumericValueType = CSSNumericValueType;
|
|
15
280
|
|
|
16
281
|
/**
|
|
17
282
|
* CSSNumericValue is the base class for numeric and length typed CSS Values.
|
|
@@ -37,7 +302,7 @@ function (_super) {
|
|
|
37
302
|
|
|
38
303
|
CSSNumericValue.fromNumberish = function (value) {
|
|
39
304
|
if (typeof value === 'number') {
|
|
40
|
-
return new
|
|
305
|
+
return new CSSUnitValue(value, _types.UnitType.kNumber);
|
|
41
306
|
}
|
|
42
307
|
|
|
43
308
|
return value;
|
|
@@ -45,14 +310,14 @@ function (_super) {
|
|
|
45
310
|
|
|
46
311
|
CSSNumericValue.fromPercentish = function (value) {
|
|
47
312
|
if (typeof value === 'number') {
|
|
48
|
-
return new
|
|
313
|
+
return new CSSUnitValue(value * 100, _types.UnitType.kPercentage);
|
|
49
314
|
}
|
|
50
315
|
|
|
51
316
|
return value;
|
|
52
317
|
};
|
|
53
318
|
|
|
54
319
|
CSSNumericValue.prototype.getType = function () {
|
|
55
|
-
return
|
|
320
|
+
return _CSSStyleValue.CSSStyleValueType.kUnknownType;
|
|
56
321
|
}; // toCSSValue() {
|
|
57
322
|
// return null;
|
|
58
323
|
// }
|
|
@@ -89,15 +354,15 @@ function (_super) {
|
|
|
89
354
|
}
|
|
90
355
|
|
|
91
356
|
var values = cssNumberishesToNumericValues(numberishes);
|
|
92
|
-
prependValueForArithmetic(
|
|
357
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kSumType, values, this); // eg. 1px + 2px = 3px
|
|
93
358
|
|
|
94
|
-
var unitValue = maybeSimplifyAsUnitValue(values,
|
|
359
|
+
var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kAdd);
|
|
95
360
|
|
|
96
361
|
if (unitValue) {
|
|
97
362
|
return unitValue;
|
|
98
363
|
}
|
|
99
364
|
|
|
100
|
-
return
|
|
365
|
+
return CSSMathSum.create(values);
|
|
101
366
|
};
|
|
102
367
|
/**
|
|
103
368
|
* @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#452
|
|
@@ -115,15 +380,15 @@ function (_super) {
|
|
|
115
380
|
values = values.map(function (value) {
|
|
116
381
|
return value.negate();
|
|
117
382
|
});
|
|
118
|
-
prependValueForArithmetic(
|
|
383
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kSumType, values, this); // eg. 3px - 2px = 1px
|
|
119
384
|
|
|
120
|
-
var unitValue = maybeSimplifyAsUnitValue(values,
|
|
385
|
+
var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kAdd);
|
|
121
386
|
|
|
122
387
|
if (unitValue) {
|
|
123
388
|
return unitValue;
|
|
124
389
|
}
|
|
125
390
|
|
|
126
|
-
return
|
|
391
|
+
return CSSMathSum.create(values);
|
|
127
392
|
};
|
|
128
393
|
/**
|
|
129
394
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/mul
|
|
@@ -138,14 +403,14 @@ function (_super) {
|
|
|
138
403
|
}
|
|
139
404
|
|
|
140
405
|
var values = cssNumberishesToNumericValues(numberishes);
|
|
141
|
-
prependValueForArithmetic(
|
|
406
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kProductType, values, this);
|
|
142
407
|
var unitValue = maybeMultiplyAsUnitValue(values);
|
|
143
408
|
|
|
144
409
|
if (unitValue) {
|
|
145
410
|
return unitValue;
|
|
146
411
|
}
|
|
147
412
|
|
|
148
|
-
return
|
|
413
|
+
return CSSMathProduct.create(values);
|
|
149
414
|
};
|
|
150
415
|
/**
|
|
151
416
|
* eg. calc(24px / 4%)
|
|
@@ -164,14 +429,14 @@ function (_super) {
|
|
|
164
429
|
values = values.map(function (value) {
|
|
165
430
|
return value.invert();
|
|
166
431
|
});
|
|
167
|
-
prependValueForArithmetic(
|
|
432
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kProductType, values, this);
|
|
168
433
|
var unitValue = maybeMultiplyAsUnitValue(values);
|
|
169
434
|
|
|
170
435
|
if (unitValue) {
|
|
171
436
|
return unitValue;
|
|
172
437
|
}
|
|
173
438
|
|
|
174
|
-
return
|
|
439
|
+
return CSSMathProduct.create(values);
|
|
175
440
|
};
|
|
176
441
|
|
|
177
442
|
CSSNumericValue.prototype.min = function () {
|
|
@@ -182,14 +447,14 @@ function (_super) {
|
|
|
182
447
|
}
|
|
183
448
|
|
|
184
449
|
var values = cssNumberishesToNumericValues(numberishes);
|
|
185
|
-
prependValueForArithmetic(
|
|
186
|
-
var unitValue = maybeSimplifyAsUnitValue(values,
|
|
450
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kMinType, values, this);
|
|
451
|
+
var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kMin);
|
|
187
452
|
|
|
188
453
|
if (unitValue) {
|
|
189
454
|
return unitValue;
|
|
190
455
|
}
|
|
191
456
|
|
|
192
|
-
return
|
|
457
|
+
return CSSMathMin.create(values);
|
|
193
458
|
};
|
|
194
459
|
|
|
195
460
|
CSSNumericValue.prototype.max = function () {
|
|
@@ -200,14 +465,14 @@ function (_super) {
|
|
|
200
465
|
}
|
|
201
466
|
|
|
202
467
|
var values = cssNumberishesToNumericValues(numberishes);
|
|
203
|
-
prependValueForArithmetic(
|
|
204
|
-
var unitValue = maybeSimplifyAsUnitValue(values,
|
|
468
|
+
prependValueForArithmetic(_CSSStyleValue.CSSStyleValueType.kMaxType, values, this);
|
|
469
|
+
var unitValue = maybeSimplifyAsUnitValue(values, _CSSMathOperator.CSSMathOperator.kMax);
|
|
205
470
|
|
|
206
471
|
if (unitValue) {
|
|
207
472
|
return unitValue;
|
|
208
473
|
}
|
|
209
474
|
|
|
210
|
-
return
|
|
475
|
+
return CSSMathMax.create(values);
|
|
211
476
|
};
|
|
212
477
|
/**
|
|
213
478
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/to
|
|
@@ -223,7 +488,7 @@ function (_super) {
|
|
|
223
488
|
var unit;
|
|
224
489
|
|
|
225
490
|
if (typeof unitOrName === 'string') {
|
|
226
|
-
unit =
|
|
491
|
+
unit = CSSUnitValue.unitFromName(unitOrName);
|
|
227
492
|
} else {
|
|
228
493
|
unit = unitOrName;
|
|
229
494
|
}
|
|
@@ -301,9 +566,8 @@ function (_super) {
|
|
|
301
566
|
return a.unit - b.unit;
|
|
302
567
|
}); // We got 'values' from a sum value, so it must be a valid CSSMathSum.
|
|
303
568
|
|
|
304
|
-
var result_1 =
|
|
305
|
-
|
|
306
|
-
(0, _utils.DCHECK)(!!result_1);
|
|
569
|
+
var result_1 = CSSMathSum.create(values);
|
|
570
|
+
(0, _assert.DCHECK)(!!result_1);
|
|
307
571
|
return result_1;
|
|
308
572
|
}
|
|
309
573
|
|
|
@@ -311,7 +575,7 @@ function (_super) {
|
|
|
311
575
|
|
|
312
576
|
var _loop_1 = function _loop_1(unit_string) {
|
|
313
577
|
var target_unit = CSSNumericValue.unitFromName(unit_string);
|
|
314
|
-
(0,
|
|
578
|
+
(0, _assert.DCHECK)(CSSNumericValue.isValidUnit(target_unit)); // Collect all the terms that are compatible with this unit.
|
|
315
579
|
// We mark used terms as null so we don't use them again.
|
|
316
580
|
|
|
317
581
|
var total_value = values.reduce(function (cur_sum, value, i) {
|
|
@@ -327,7 +591,7 @@ function (_super) {
|
|
|
327
591
|
|
|
328
592
|
return cur_sum;
|
|
329
593
|
}, 0);
|
|
330
|
-
result.push(new
|
|
594
|
+
result.push(new CSSUnitValue(total_value, target_unit));
|
|
331
595
|
};
|
|
332
596
|
|
|
333
597
|
try {
|
|
@@ -354,7 +618,7 @@ function (_super) {
|
|
|
354
618
|
throw new Error('There were leftover terms that were not converted');
|
|
355
619
|
}
|
|
356
620
|
|
|
357
|
-
return
|
|
621
|
+
return CSSMathSum.create(result);
|
|
358
622
|
};
|
|
359
623
|
/**
|
|
360
624
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/type
|
|
@@ -373,67 +637,67 @@ function (_super) {
|
|
|
373
637
|
percent: 0,
|
|
374
638
|
percentHint: 'length'
|
|
375
639
|
};
|
|
376
|
-
var exponent = this.type_.exponent(
|
|
640
|
+
var exponent = this.type_.exponent(BaseType.kLength);
|
|
377
641
|
|
|
378
642
|
if (exponent) {
|
|
379
643
|
type.length = exponent;
|
|
380
644
|
}
|
|
381
645
|
|
|
382
|
-
exponent = this.type_.exponent(
|
|
646
|
+
exponent = this.type_.exponent(BaseType.kAngle);
|
|
383
647
|
|
|
384
648
|
if (exponent) {
|
|
385
649
|
type.angle = exponent;
|
|
386
650
|
}
|
|
387
651
|
|
|
388
|
-
exponent = this.type_.exponent(
|
|
652
|
+
exponent = this.type_.exponent(BaseType.kTime);
|
|
389
653
|
|
|
390
654
|
if (exponent) {
|
|
391
655
|
type.time = exponent;
|
|
392
656
|
}
|
|
393
657
|
|
|
394
|
-
exponent = this.type_.exponent(
|
|
658
|
+
exponent = this.type_.exponent(BaseType.kFrequency);
|
|
395
659
|
|
|
396
660
|
if (exponent) {
|
|
397
661
|
type.frequency = exponent;
|
|
398
662
|
}
|
|
399
663
|
|
|
400
|
-
exponent = this.type_.exponent(
|
|
664
|
+
exponent = this.type_.exponent(BaseType.kResolution);
|
|
401
665
|
|
|
402
666
|
if (exponent) {
|
|
403
667
|
type.resolution = exponent;
|
|
404
668
|
}
|
|
405
669
|
|
|
406
|
-
exponent = this.type_.exponent(
|
|
670
|
+
exponent = this.type_.exponent(BaseType.kFlex);
|
|
407
671
|
|
|
408
672
|
if (exponent) {
|
|
409
673
|
type.flex = exponent;
|
|
410
674
|
}
|
|
411
675
|
|
|
412
|
-
exponent = this.type_.exponent(
|
|
676
|
+
exponent = this.type_.exponent(BaseType.kPercent);
|
|
413
677
|
|
|
414
678
|
if (exponent) {
|
|
415
679
|
type.percent = exponent;
|
|
416
680
|
}
|
|
417
681
|
|
|
418
682
|
if (this.type_.hasPercentHint) {
|
|
419
|
-
type.percentHint =
|
|
683
|
+
type.percentHint = baseTypeToString(this.type_.percentHint);
|
|
420
684
|
}
|
|
421
685
|
|
|
422
686
|
return type;
|
|
423
687
|
};
|
|
424
688
|
|
|
425
689
|
CSSNumericValue.isValidUnit = function (unit) {
|
|
426
|
-
if (unit ===
|
|
427
|
-
if (unit ===
|
|
690
|
+
if (unit === _types.UnitType.kUserUnits) return false;
|
|
691
|
+
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
692
|
return false;
|
|
429
693
|
};
|
|
430
694
|
|
|
431
695
|
CSSNumericValue.prototype.negate = function () {
|
|
432
|
-
return
|
|
696
|
+
return CSSMathNegate.create(this);
|
|
433
697
|
};
|
|
434
698
|
|
|
435
699
|
CSSNumericValue.prototype.invert = function () {
|
|
436
|
-
return
|
|
700
|
+
return CSSMathInvert.create(this);
|
|
437
701
|
};
|
|
438
702
|
|
|
439
703
|
return CSSNumericValue;
|
|
@@ -446,7 +710,7 @@ function cssNumberishesToNumericValues(values) {
|
|
|
446
710
|
}
|
|
447
711
|
|
|
448
712
|
function prependValueForArithmetic(type, values, value) {
|
|
449
|
-
(0,
|
|
713
|
+
(0, _assert.DCHECK)(!!value);
|
|
450
714
|
|
|
451
715
|
if (value.getType() === type) {
|
|
452
716
|
values.unshift.apply(values, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(value.numericValues()), false));
|
|
@@ -457,55 +721,965 @@ function prependValueForArithmetic(type, values, value) {
|
|
|
457
721
|
|
|
458
722
|
function cssNumericSumValueEntryToUnitValue(term) {
|
|
459
723
|
if (Object.keys(term.units).length === 0) {
|
|
460
|
-
return new
|
|
724
|
+
return new CSSUnitValue(term.value);
|
|
461
725
|
}
|
|
462
726
|
|
|
463
727
|
if (Object.keys(term.units).length === 1 && term.units[Object.keys(term.units)[0]] === 1) {
|
|
464
|
-
return new
|
|
728
|
+
return new CSSUnitValue(term.value, Number(Object.keys(term.units)[0]));
|
|
465
729
|
}
|
|
466
730
|
|
|
467
731
|
return null;
|
|
468
732
|
}
|
|
469
733
|
|
|
470
734
|
function maybeSimplifyAsUnitValue(values, operator) {
|
|
471
|
-
(0,
|
|
472
|
-
var first_unit_value = values[0] instanceof
|
|
735
|
+
(0, _assert.DCHECK)(!!values.length);
|
|
736
|
+
var first_unit_value = values[0] instanceof CSSUnitValue ? values[0] : null;
|
|
473
737
|
if (!first_unit_value) return null;
|
|
474
738
|
var final_value = first_unit_value.value;
|
|
475
739
|
|
|
476
740
|
for (var i = 1; i < values.length; i++) {
|
|
477
|
-
var unit_value = values[i] instanceof
|
|
741
|
+
var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
|
|
478
742
|
if (!unit_value || unit_value.unit !== first_unit_value.unit) return null;
|
|
479
743
|
|
|
480
|
-
if (operator ===
|
|
744
|
+
if (operator === _CSSMathOperator.CSSMathOperator.kAdd) {
|
|
481
745
|
final_value += unit_value.value;
|
|
482
|
-
} else if (operator ===
|
|
746
|
+
} else if (operator === _CSSMathOperator.CSSMathOperator.kMax) {
|
|
483
747
|
final_value = Math.max(final_value, unit_value.value);
|
|
484
|
-
} else if (operator ===
|
|
748
|
+
} else if (operator === _CSSMathOperator.CSSMathOperator.kMin) {
|
|
485
749
|
final_value = Math.min(final_value, unit_value.value);
|
|
486
750
|
}
|
|
487
751
|
}
|
|
488
752
|
|
|
489
|
-
return new
|
|
753
|
+
return new CSSUnitValue(final_value, first_unit_value.unit);
|
|
490
754
|
}
|
|
491
755
|
|
|
492
756
|
function maybeMultiplyAsUnitValue(values) {
|
|
493
|
-
(0,
|
|
757
|
+
(0, _assert.DCHECK)(!!values.length); // We are allowed one unit value with type other than kNumber.
|
|
494
758
|
|
|
495
|
-
var unit_other_than_number =
|
|
759
|
+
var unit_other_than_number = _types.UnitType.kNumber;
|
|
496
760
|
var final_value = 1.0;
|
|
497
761
|
|
|
498
762
|
for (var i = 0; i < values.length; i++) {
|
|
499
|
-
var unit_value = values[i] instanceof
|
|
763
|
+
var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
|
|
500
764
|
if (!unit_value) return null;
|
|
501
765
|
|
|
502
|
-
if (unit_value.unit !==
|
|
503
|
-
if (unit_other_than_number !==
|
|
766
|
+
if (unit_value.unit !== _types.UnitType.kNumber) {
|
|
767
|
+
if (unit_other_than_number !== _types.UnitType.kNumber) return null;
|
|
504
768
|
unit_other_than_number = unit_value.unit;
|
|
505
769
|
}
|
|
506
770
|
|
|
507
771
|
final_value *= unit_value.value;
|
|
508
772
|
}
|
|
509
773
|
|
|
510
|
-
return new
|
|
511
|
-
}
|
|
774
|
+
return new CSSUnitValue(final_value, unit_other_than_number);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Represents numeric values that can be expressed as a single number plus a
|
|
778
|
+
* unit (or a naked number or percentage).
|
|
779
|
+
* @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
|
|
780
|
+
*/
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
var CSSUnitValue =
|
|
784
|
+
/** @class */
|
|
785
|
+
function (_super) {
|
|
786
|
+
(0, _tslib.__extends)(CSSUnitValue, _super);
|
|
787
|
+
|
|
788
|
+
function CSSUnitValue(value, unitOrName) {
|
|
789
|
+
if (unitOrName === void 0) {
|
|
790
|
+
unitOrName = _types.UnitType.kNumber;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
var _this = this;
|
|
794
|
+
|
|
795
|
+
var unit;
|
|
796
|
+
|
|
797
|
+
if (typeof unitOrName === 'string') {
|
|
798
|
+
unit = CSSUnitValue.unitFromName(unitOrName);
|
|
799
|
+
} else {
|
|
800
|
+
unit = unitOrName;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
(0, _assert.DCHECK)(CSSUnitValue.isValidUnit(unit));
|
|
804
|
+
_this = _super.call(this, new CSSNumericValueType(unit)) || this;
|
|
805
|
+
_this.unit = unit;
|
|
806
|
+
_this.value = value;
|
|
807
|
+
return _this;
|
|
808
|
+
} // static fromCSSValue(value: CSSNumericLiteralValue) {
|
|
809
|
+
// let unit = value.type;
|
|
810
|
+
// if (unit === UnitType.kInteger) unit = UnitType.kNumber;
|
|
811
|
+
// if (!this.isValidUnit(unit)) return null;
|
|
812
|
+
// return new CSSUnitValue(value.getDoubleValue(), unit);
|
|
813
|
+
// }
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
CSSUnitValue.toCanonicalUnit = function (unit) {
|
|
817
|
+
return this.canonicalUnitTypeForCategory(this.unitTypeToUnitCategory(unit));
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
CSSUnitValue.toCanonicalUnitIfPossible = function (unit) {
|
|
821
|
+
var canonical_unit = this.toCanonicalUnit(unit);
|
|
822
|
+
if (canonical_unit === _types.UnitType.kUnknown) return unit;
|
|
823
|
+
return canonical_unit;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
CSSUnitValue.formatInfinityOrNaN = function (number, suffix) {
|
|
827
|
+
if (suffix === void 0) {
|
|
828
|
+
suffix = '';
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
var result = '';
|
|
832
|
+
|
|
833
|
+
if (!Number.isFinite(number)) {
|
|
834
|
+
if (number > 0) result = 'infinity';else result = '-infinity';
|
|
835
|
+
} else {
|
|
836
|
+
(0, _assert.DCHECK)(Number.isNaN(number));
|
|
837
|
+
result = 'NaN';
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
return result += suffix;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
CSSUnitValue.formatNumber = function (number, suffix) {
|
|
844
|
+
if (suffix === void 0) {
|
|
845
|
+
suffix = '';
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
return number + suffix;
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
CSSUnitValue.prototype.clone = function () {
|
|
852
|
+
return new CSSUnitValue(this.value, this.unit);
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
CSSUnitValue.prototype.convertTo = function (target_unit) {
|
|
856
|
+
if (this.unit === target_unit) {
|
|
857
|
+
return new CSSUnitValue(this.value, this.unit);
|
|
858
|
+
} // Instead of defining the scale factors for every unit to every other unit,
|
|
859
|
+
// we simply convert to the canonical unit and back since we already have
|
|
860
|
+
// the scale factors for canonical units.
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
var canonical_unit = CSSUnitValue.toCanonicalUnit(this.unit);
|
|
864
|
+
|
|
865
|
+
if (canonical_unit !== CSSUnitValue.toCanonicalUnit(target_unit) || canonical_unit === _types.UnitType.kUnknown) {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
var scale_factor = _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit) / _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(target_unit);
|
|
870
|
+
|
|
871
|
+
return new CSSUnitValue(this.value * scale_factor, target_unit);
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
CSSUnitValue.prototype.equals = function (other) {
|
|
875
|
+
var other_unit_value = other;
|
|
876
|
+
return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
CSSUnitValue.prototype.getType = function () {
|
|
880
|
+
return _CSSStyleValue.CSSStyleValueType.kUnitType;
|
|
881
|
+
}; // toCSSValue() {
|
|
882
|
+
// return new CSSNumericLiteralValue(this.value, this.unit);
|
|
883
|
+
// }
|
|
884
|
+
// // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
|
|
885
|
+
// toCalcExpressionNode() {
|
|
886
|
+
// return CSSMathExpressionNumericLiteral.create(
|
|
887
|
+
// new CSSNumericLiteralValue(this.value, this.unit),
|
|
888
|
+
// );
|
|
889
|
+
// }
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
CSSUnitValue.prototype.sumValue = function () {
|
|
893
|
+
var sum = [];
|
|
894
|
+
var unit_map = {};
|
|
895
|
+
|
|
896
|
+
if (this.unit !== _types.UnitType.kNumber) {
|
|
897
|
+
unit_map[CSSUnitValue.toCanonicalUnitIfPossible(this.unit)] = 1;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
sum.push({
|
|
901
|
+
value: this.value * _CSSStyleValue.CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit),
|
|
902
|
+
units: unit_map
|
|
903
|
+
});
|
|
904
|
+
return sum;
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
CSSUnitValue.prototype.negate = function () {
|
|
908
|
+
return new CSSUnitValue(-this.value, this.unit);
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
CSSUnitValue.prototype.invert = function () {
|
|
912
|
+
if (this.unit === _types.UnitType.kNumber) {
|
|
913
|
+
if (this.value === 0) return null;
|
|
914
|
+
return new CSSUnitValue(1.0 / this.value, this.unit);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
return CSSMathInvert.create(this);
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
CSSUnitValue.prototype.buildCSSText = function (n, p, result) {
|
|
921
|
+
var text;
|
|
922
|
+
|
|
923
|
+
switch (this.unit) {
|
|
924
|
+
case _types.UnitType.kUnknown:
|
|
925
|
+
// FIXME
|
|
926
|
+
break;
|
|
927
|
+
|
|
928
|
+
case _types.UnitType.kInteger:
|
|
929
|
+
text = Number(this.value).toFixed(0);
|
|
930
|
+
break;
|
|
931
|
+
|
|
932
|
+
case _types.UnitType.kNumber:
|
|
933
|
+
case _types.UnitType.kPercentage:
|
|
934
|
+
case _types.UnitType.kEms:
|
|
935
|
+
case _types.UnitType.kQuirkyEms:
|
|
936
|
+
case _types.UnitType.kExs:
|
|
937
|
+
case _types.UnitType.kRems:
|
|
938
|
+
case _types.UnitType.kChs:
|
|
939
|
+
case _types.UnitType.kPixels:
|
|
940
|
+
case _types.UnitType.kCentimeters:
|
|
941
|
+
case _types.UnitType.kDotsPerPixel:
|
|
942
|
+
case _types.UnitType.kDotsPerInch:
|
|
943
|
+
case _types.UnitType.kDotsPerCentimeter:
|
|
944
|
+
case _types.UnitType.kMillimeters:
|
|
945
|
+
case _types.UnitType.kQuarterMillimeters:
|
|
946
|
+
case _types.UnitType.kInches:
|
|
947
|
+
case _types.UnitType.kPoints:
|
|
948
|
+
case _types.UnitType.kPicas:
|
|
949
|
+
case _types.UnitType.kUserUnits:
|
|
950
|
+
case _types.UnitType.kDegrees:
|
|
951
|
+
case _types.UnitType.kRadians:
|
|
952
|
+
case _types.UnitType.kGradians:
|
|
953
|
+
case _types.UnitType.kMilliseconds:
|
|
954
|
+
case _types.UnitType.kSeconds:
|
|
955
|
+
case _types.UnitType.kHertz:
|
|
956
|
+
case _types.UnitType.kKilohertz:
|
|
957
|
+
case _types.UnitType.kTurns:
|
|
958
|
+
case _types.UnitType.kFraction:
|
|
959
|
+
case _types.UnitType.kViewportWidth:
|
|
960
|
+
case _types.UnitType.kViewportHeight:
|
|
961
|
+
case _types.UnitType.kViewportInlineSize:
|
|
962
|
+
case _types.UnitType.kViewportBlockSize:
|
|
963
|
+
case _types.UnitType.kViewportMin:
|
|
964
|
+
case _types.UnitType.kViewportMax:
|
|
965
|
+
case _types.UnitType.kSmallViewportWidth:
|
|
966
|
+
case _types.UnitType.kSmallViewportHeight:
|
|
967
|
+
case _types.UnitType.kSmallViewportInlineSize:
|
|
968
|
+
case _types.UnitType.kSmallViewportBlockSize:
|
|
969
|
+
case _types.UnitType.kSmallViewportMin:
|
|
970
|
+
case _types.UnitType.kSmallViewportMax:
|
|
971
|
+
case _types.UnitType.kLargeViewportWidth:
|
|
972
|
+
case _types.UnitType.kLargeViewportHeight:
|
|
973
|
+
case _types.UnitType.kLargeViewportInlineSize:
|
|
974
|
+
case _types.UnitType.kLargeViewportBlockSize:
|
|
975
|
+
case _types.UnitType.kLargeViewportMin:
|
|
976
|
+
case _types.UnitType.kLargeViewportMax:
|
|
977
|
+
case _types.UnitType.kDynamicViewportWidth:
|
|
978
|
+
case _types.UnitType.kDynamicViewportHeight:
|
|
979
|
+
case _types.UnitType.kDynamicViewportInlineSize:
|
|
980
|
+
case _types.UnitType.kDynamicViewportBlockSize:
|
|
981
|
+
case _types.UnitType.kDynamicViewportMin:
|
|
982
|
+
case _types.UnitType.kDynamicViewportMax:
|
|
983
|
+
case _types.UnitType.kContainerWidth:
|
|
984
|
+
case _types.UnitType.kContainerHeight:
|
|
985
|
+
case _types.UnitType.kContainerInlineSize:
|
|
986
|
+
case _types.UnitType.kContainerBlockSize:
|
|
987
|
+
case _types.UnitType.kContainerMin:
|
|
988
|
+
case _types.UnitType.kContainerMax:
|
|
989
|
+
{
|
|
990
|
+
var kMinInteger = -999999;
|
|
991
|
+
var kMaxInteger = 999999;
|
|
992
|
+
var value = this.value;
|
|
993
|
+
var unit = CSSUnitValue.unitTypeToString(this.unit);
|
|
994
|
+
|
|
995
|
+
if (value < kMinInteger || value > kMaxInteger) {
|
|
996
|
+
var unit_1 = CSSUnitValue.unitTypeToString(this.unit);
|
|
997
|
+
|
|
998
|
+
if (!Number.isFinite(value) || Number.isNaN(value)) {
|
|
999
|
+
text = CSSUnitValue.formatInfinityOrNaN(value, unit_1);
|
|
1000
|
+
} else {
|
|
1001
|
+
text = CSSUnitValue.formatNumber(value, unit_1);
|
|
1002
|
+
}
|
|
1003
|
+
} else {
|
|
1004
|
+
text = "".concat(value).concat(unit);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
result += text;
|
|
1010
|
+
return result;
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
return CSSUnitValue;
|
|
1014
|
+
}(CSSNumericValue);
|
|
1015
|
+
|
|
1016
|
+
exports.CSSUnitValue = CSSUnitValue;
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
|
|
1020
|
+
*
|
|
1021
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
|
|
1022
|
+
* @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
|
|
1023
|
+
*/
|
|
1024
|
+
var CSSMathValue =
|
|
1025
|
+
/** @class */
|
|
1026
|
+
function (_super) {
|
|
1027
|
+
(0, _tslib.__extends)(CSSMathValue, _super);
|
|
1028
|
+
|
|
1029
|
+
function CSSMathValue() {
|
|
1030
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1031
|
+
} // From CSSNumericValue
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
CSSMathValue.prototype.isUnitValue = function () {
|
|
1035
|
+
return false;
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
return CSSMathValue;
|
|
1039
|
+
}(CSSNumericValue);
|
|
1040
|
+
|
|
1041
|
+
exports.CSSMathValue = CSSMathValue;
|
|
1042
|
+
|
|
1043
|
+
var CSSMathInvert =
|
|
1044
|
+
/** @class */
|
|
1045
|
+
function (_super) {
|
|
1046
|
+
(0, _tslib.__extends)(CSSMathInvert, _super);
|
|
1047
|
+
|
|
1048
|
+
function CSSMathInvert(value, type) {
|
|
1049
|
+
var _this = _super.call(this, type) || this;
|
|
1050
|
+
|
|
1051
|
+
_this.value = value;
|
|
1052
|
+
_this.operator = 'invert';
|
|
1053
|
+
return _this;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
CSSMathInvert.create = function (value) {
|
|
1057
|
+
var type = CSSNumericValueType.negateExponents(value.type_);
|
|
1058
|
+
return new CSSMathInvert(value, type);
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
CSSMathInvert.prototype.clone = function () {
|
|
1062
|
+
return new CSSMathInvert(this.value, this.type_);
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
CSSMathInvert.prototype.getType = function () {
|
|
1066
|
+
return _CSSStyleValue.CSSStyleValueType.kInvertType;
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
CSSMathInvert.prototype.equals = function (other) {
|
|
1070
|
+
if (other.getType() !== _CSSStyleValue.CSSStyleValueType.kInvertType) {
|
|
1071
|
+
return false;
|
|
1072
|
+
} // We can safely cast here as we know 'other' has the same type as us.
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
var other_invert = other;
|
|
1076
|
+
return this.value.equals(other_invert.value);
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
CSSMathInvert.prototype.sumValue = function () {
|
|
1080
|
+
var sum = this.value.sumValue();
|
|
1081
|
+
|
|
1082
|
+
if (sum.length === 0 || sum.length !== 1 || sum[0].value === 0) {
|
|
1083
|
+
return null;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
Object.keys(sum[0].units).forEach(function (key) {
|
|
1087
|
+
sum[0].units[key] *= -1;
|
|
1088
|
+
});
|
|
1089
|
+
sum[0].value = 1.0 / sum[0].value;
|
|
1090
|
+
return sum;
|
|
1091
|
+
}; // toCalcExpressionNode(): CSSMathExpressionNode {
|
|
1092
|
+
// const right_side = this.value.toCalcExpressionNode();
|
|
1093
|
+
// if (!right_side) {
|
|
1094
|
+
// return null;
|
|
1095
|
+
// }
|
|
1096
|
+
// // return CSSMathExpressionOperation::CreateArithmeticOperation(
|
|
1097
|
+
// // CSSMathExpressionNumericLiteral::Create(
|
|
1098
|
+
// // 1, UnitType.kNumber),
|
|
1099
|
+
// // right_side, CSSMathOperator.kDivide);
|
|
1100
|
+
// return null;
|
|
1101
|
+
// }
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
CSSMathInvert.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1105
|
+
if (paren_less == _types.ParenLess.kNo) {
|
|
1106
|
+
result += nested === _types.Nested.kYes ? '(' : 'calc(';
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
result += '1 / ';
|
|
1110
|
+
result = this.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1111
|
+
|
|
1112
|
+
if (paren_less === _types.ParenLess.kNo) {
|
|
1113
|
+
result += ')';
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
return result;
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
return CSSMathInvert;
|
|
1120
|
+
}(CSSMathValue);
|
|
1121
|
+
|
|
1122
|
+
exports.CSSMathInvert = CSSMathInvert;
|
|
1123
|
+
|
|
1124
|
+
var CSSMathNegate =
|
|
1125
|
+
/** @class */
|
|
1126
|
+
function (_super) {
|
|
1127
|
+
(0, _tslib.__extends)(CSSMathNegate, _super);
|
|
1128
|
+
|
|
1129
|
+
function CSSMathNegate(value, type) {
|
|
1130
|
+
var _this = _super.call(this, type) || this;
|
|
1131
|
+
|
|
1132
|
+
_this.value = value;
|
|
1133
|
+
_this.operator = 'negate';
|
|
1134
|
+
return _this;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
CSSMathNegate.create = function (value) {
|
|
1138
|
+
return new CSSMathNegate(value, value.type_);
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
CSSMathNegate.prototype.clone = function () {
|
|
1142
|
+
return new CSSMathNegate(this.value, this.type_);
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
CSSMathNegate.prototype.getType = function () {
|
|
1146
|
+
return _CSSStyleValue.CSSStyleValueType.kNegateType;
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
CSSMathNegate.prototype.equals = function (other) {
|
|
1150
|
+
if (other.getType() !== _CSSStyleValue.CSSStyleValueType.kNegateType) {
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
var other_invert = other;
|
|
1155
|
+
return this.value.equals(other_invert.value);
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
CSSMathNegate.prototype.sumValue = function () {
|
|
1159
|
+
var sum = this.value.sumValue();
|
|
1160
|
+
|
|
1161
|
+
if (sum.length === 0) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
sum.forEach(function (term) {
|
|
1166
|
+
term.value *= -1;
|
|
1167
|
+
});
|
|
1168
|
+
return sum;
|
|
1169
|
+
}; // toCalcExpressionNode(): CSSMathExpressionNode {
|
|
1170
|
+
// const right_side = this.value.toCalcExpressionNode();
|
|
1171
|
+
// if (!right_side) {
|
|
1172
|
+
// return null;
|
|
1173
|
+
// }
|
|
1174
|
+
// // return CSSMathExpressionOperation::CreateArithmeticOperationSimplified(
|
|
1175
|
+
// // CSSMathExpressionNumericLiteral::Create(
|
|
1176
|
+
// // -1, CSSPrimitiveValue::UnitType::kNumber),
|
|
1177
|
+
// // right_side, CSSMathOperator::kMultiply);
|
|
1178
|
+
// }
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
CSSMathNegate.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1182
|
+
if (paren_less == _types.ParenLess.kNo) {
|
|
1183
|
+
result += nested === _types.Nested.kYes ? '(' : 'calc(';
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
result += '-';
|
|
1187
|
+
result = this.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1188
|
+
|
|
1189
|
+
if (paren_less === _types.ParenLess.kNo) {
|
|
1190
|
+
result += ')';
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
return result;
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
return CSSMathNegate;
|
|
1197
|
+
}(CSSMathValue);
|
|
1198
|
+
|
|
1199
|
+
exports.CSSMathNegate = CSSMathNegate;
|
|
1200
|
+
|
|
1201
|
+
function typeCheck(values, op, error) {
|
|
1202
|
+
error = false;
|
|
1203
|
+
var final_type = values[0].type_;
|
|
1204
|
+
|
|
1205
|
+
for (var i = 1; i < values.length; i++) {
|
|
1206
|
+
final_type = op(final_type, values[i].type_, error);
|
|
1207
|
+
if (error) return final_type;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
return final_type;
|
|
1211
|
+
} // Represents an arithmetic operation with one or more CSSNumericValues.
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
var CSSMathVariadic =
|
|
1215
|
+
/** @class */
|
|
1216
|
+
function (_super) {
|
|
1217
|
+
(0, _tslib.__extends)(CSSMathVariadic, _super);
|
|
1218
|
+
|
|
1219
|
+
function CSSMathVariadic(values, type) {
|
|
1220
|
+
var _this = _super.call(this, type) || this;
|
|
1221
|
+
|
|
1222
|
+
_this.values = values;
|
|
1223
|
+
return _this;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
CSSMathVariadic.prototype.numericValues = function () {
|
|
1227
|
+
return this.values;
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
CSSMathVariadic.prototype.equals = function (other) {
|
|
1231
|
+
if (this.getType() !== other.getType()) {
|
|
1232
|
+
return false;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
return this.values.every(function (value, i) {
|
|
1236
|
+
return value.equals(other.values[i]);
|
|
1237
|
+
});
|
|
1238
|
+
};
|
|
1239
|
+
|
|
1240
|
+
return CSSMathVariadic;
|
|
1241
|
+
}(CSSMathValue);
|
|
1242
|
+
|
|
1243
|
+
exports.CSSMathVariadic = CSSMathVariadic;
|
|
1244
|
+
|
|
1245
|
+
// Represents the minimum of one or more CSSNumericValues.
|
|
1246
|
+
// @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
|
|
1247
|
+
var CSSMathMin =
|
|
1248
|
+
/** @class */
|
|
1249
|
+
function (_super) {
|
|
1250
|
+
(0, _tslib.__extends)(CSSMathMin, _super);
|
|
1251
|
+
|
|
1252
|
+
function CSSMathMin() {
|
|
1253
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1254
|
+
|
|
1255
|
+
_this.operator = 'min';
|
|
1256
|
+
return _this;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
CSSMathMin.create = function (values) {
|
|
1260
|
+
var error = false;
|
|
1261
|
+
var final_type = typeCheck(values, CSSNumericValueType.add, error);
|
|
1262
|
+
return error ? null : new CSSMathMin(values, final_type);
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
CSSMathMin.prototype.clone = function () {
|
|
1266
|
+
return new CSSMathMin(this.values, this.type_);
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
CSSMathMin.prototype.getType = function () {
|
|
1270
|
+
return _CSSStyleValue.CSSStyleValueType.kMinType;
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
CSSMathMin.prototype.sumValue = function () {
|
|
1274
|
+
var e_4, _a;
|
|
1275
|
+
|
|
1276
|
+
var cur_min = this.numericValues()[0].sumValue();
|
|
1277
|
+
|
|
1278
|
+
if (!cur_min.length) {
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
try {
|
|
1283
|
+
for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1284
|
+
var value = _c.value;
|
|
1285
|
+
var child_sum = value.sumValue();
|
|
1286
|
+
|
|
1287
|
+
if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_min[0].units)) {
|
|
1288
|
+
return null;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
if (child_sum[0].value < cur_min[0].value) {
|
|
1292
|
+
cur_min = child_sum;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
} catch (e_4_1) {
|
|
1296
|
+
e_4 = {
|
|
1297
|
+
error: e_4_1
|
|
1298
|
+
};
|
|
1299
|
+
} finally {
|
|
1300
|
+
try {
|
|
1301
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1302
|
+
} finally {
|
|
1303
|
+
if (e_4) throw e_4.error;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
return cur_min;
|
|
1308
|
+
}; // toCalcExpressionNode() {
|
|
1309
|
+
// const operands: CSSMathExpressionOperation[] = [];
|
|
1310
|
+
// for (const value of this.numericValues()) {
|
|
1311
|
+
// const operand = value.toCalcExpressionNode();
|
|
1312
|
+
// if (!operand) {
|
|
1313
|
+
// continue;
|
|
1314
|
+
// }
|
|
1315
|
+
// operands.push(operand as CSSMathExpressionOperation);
|
|
1316
|
+
// }
|
|
1317
|
+
// return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMin);
|
|
1318
|
+
// }
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
CSSMathMin.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1322
|
+
var e_5, _a;
|
|
1323
|
+
|
|
1324
|
+
result += 'min(';
|
|
1325
|
+
var first_iteration = true;
|
|
1326
|
+
|
|
1327
|
+
try {
|
|
1328
|
+
for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1329
|
+
var value = _c.value;
|
|
1330
|
+
if (!first_iteration) result += ', ';
|
|
1331
|
+
first_iteration = false;
|
|
1332
|
+
result = value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kYes, result);
|
|
1333
|
+
}
|
|
1334
|
+
} catch (e_5_1) {
|
|
1335
|
+
e_5 = {
|
|
1336
|
+
error: e_5_1
|
|
1337
|
+
};
|
|
1338
|
+
} finally {
|
|
1339
|
+
try {
|
|
1340
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1341
|
+
} finally {
|
|
1342
|
+
if (e_5) throw e_5.error;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
result += ')';
|
|
1347
|
+
return result;
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
return CSSMathMin;
|
|
1351
|
+
}(CSSMathVariadic);
|
|
1352
|
+
|
|
1353
|
+
exports.CSSMathMin = CSSMathMin;
|
|
1354
|
+
|
|
1355
|
+
// Represents the maximum of one or more CSSNumericValues.
|
|
1356
|
+
// @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
|
|
1357
|
+
var CSSMathMax =
|
|
1358
|
+
/** @class */
|
|
1359
|
+
function (_super) {
|
|
1360
|
+
(0, _tslib.__extends)(CSSMathMax, _super);
|
|
1361
|
+
|
|
1362
|
+
function CSSMathMax() {
|
|
1363
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1364
|
+
|
|
1365
|
+
_this.operator = 'max';
|
|
1366
|
+
return _this;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
CSSMathMax.create = function (values) {
|
|
1370
|
+
var error = false;
|
|
1371
|
+
var final_type = typeCheck(values, CSSNumericValueType.add, error);
|
|
1372
|
+
return error ? null : new CSSMathMax(values, final_type);
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
CSSMathMax.prototype.clone = function () {
|
|
1376
|
+
return new CSSMathMax(this.values, this.type_);
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
CSSMathMax.prototype.getType = function () {
|
|
1380
|
+
return _CSSStyleValue.CSSStyleValueType.kMaxType;
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
CSSMathMax.prototype.sumValue = function () {
|
|
1384
|
+
var e_6, _a;
|
|
1385
|
+
|
|
1386
|
+
var cur_max = this.numericValues()[0].sumValue();
|
|
1387
|
+
|
|
1388
|
+
if (!cur_max.length) {
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
try {
|
|
1393
|
+
for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1394
|
+
var value = _c.value;
|
|
1395
|
+
var child_sum = value.sumValue();
|
|
1396
|
+
|
|
1397
|
+
if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_max[0].units)) {
|
|
1398
|
+
return null;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
if (child_sum[0].value < cur_max[0].value) {
|
|
1402
|
+
cur_max = child_sum;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
} catch (e_6_1) {
|
|
1406
|
+
e_6 = {
|
|
1407
|
+
error: e_6_1
|
|
1408
|
+
};
|
|
1409
|
+
} finally {
|
|
1410
|
+
try {
|
|
1411
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1412
|
+
} finally {
|
|
1413
|
+
if (e_6) throw e_6.error;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
return cur_max;
|
|
1418
|
+
}; // toCalcExpressionNode() {
|
|
1419
|
+
// const operands: CSSMathExpressionOperation[] = [];
|
|
1420
|
+
// for (const value of this.numericValues()) {
|
|
1421
|
+
// const operand = value.toCalcExpressionNode();
|
|
1422
|
+
// if (!operand) {
|
|
1423
|
+
// continue;
|
|
1424
|
+
// }
|
|
1425
|
+
// operands.push(operand as CSSMathExpressionOperation);
|
|
1426
|
+
// }
|
|
1427
|
+
// return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMax);
|
|
1428
|
+
// }
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
CSSMathMax.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1432
|
+
var e_7, _a;
|
|
1433
|
+
|
|
1434
|
+
result += 'max(';
|
|
1435
|
+
var first_iteration = true;
|
|
1436
|
+
|
|
1437
|
+
try {
|
|
1438
|
+
for (var _b = (0, _tslib.__values)(this.numericValues()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1439
|
+
var value = _c.value;
|
|
1440
|
+
if (!first_iteration) result += ', ';
|
|
1441
|
+
first_iteration = false;
|
|
1442
|
+
result = value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kYes, result);
|
|
1443
|
+
}
|
|
1444
|
+
} catch (e_7_1) {
|
|
1445
|
+
e_7 = {
|
|
1446
|
+
error: e_7_1
|
|
1447
|
+
};
|
|
1448
|
+
} finally {
|
|
1449
|
+
try {
|
|
1450
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1451
|
+
} finally {
|
|
1452
|
+
if (e_7) throw e_7.error;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
result += ')';
|
|
1457
|
+
return result;
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
return CSSMathMax;
|
|
1461
|
+
}(CSSMathVariadic);
|
|
1462
|
+
|
|
1463
|
+
exports.CSSMathMax = CSSMathMax;
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* Represents the sum of one or more CSSNumericValues.
|
|
1467
|
+
* @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
|
|
1468
|
+
*/
|
|
1469
|
+
var CSSMathSum =
|
|
1470
|
+
/** @class */
|
|
1471
|
+
function (_super) {
|
|
1472
|
+
(0, _tslib.__extends)(CSSMathSum, _super);
|
|
1473
|
+
|
|
1474
|
+
function CSSMathSum() {
|
|
1475
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1476
|
+
|
|
1477
|
+
_this.operator = 'sum';
|
|
1478
|
+
return _this;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
CSSMathSum.create = function (values) {
|
|
1482
|
+
var error = false;
|
|
1483
|
+
var finalType = typeCheck(values, CSSNumericValueType.add, error);
|
|
1484
|
+
return error ? null : new CSSMathSum(values, finalType);
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
CSSMathSum.numericTypeFromUnitMap = function (units) {
|
|
1488
|
+
var type = new CSSNumericValueType();
|
|
1489
|
+
Object.keys(units).forEach(function (key) {
|
|
1490
|
+
var exp = units[key];
|
|
1491
|
+
var error = false;
|
|
1492
|
+
type = CSSNumericValueType.multiply(type, new CSSNumericValueType(Number(key), exp), error);
|
|
1493
|
+
(0, _assert.DCHECK)(!error);
|
|
1494
|
+
});
|
|
1495
|
+
return type;
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
CSSMathSum.canCreateNumericTypeFromSumValue = function (sum) {
|
|
1499
|
+
var _this = this;
|
|
1500
|
+
|
|
1501
|
+
(0, _assert.DCHECK)(!!sum.length);
|
|
1502
|
+
var first_type = this.numericTypeFromUnitMap(sum[0].units);
|
|
1503
|
+
return sum.every(function (term) {
|
|
1504
|
+
var error = false;
|
|
1505
|
+
CSSNumericValueType.add(first_type, _this.numericTypeFromUnitMap(term.units), error);
|
|
1506
|
+
return !error;
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
CSSMathSum.prototype.clone = function () {
|
|
1511
|
+
return new CSSMathSum(this.values, this.type_);
|
|
1512
|
+
};
|
|
1513
|
+
|
|
1514
|
+
CSSMathSum.prototype.getType = function () {
|
|
1515
|
+
return _CSSStyleValue.CSSStyleValueType.kSumType;
|
|
1516
|
+
}; // toCalcExpressionNode() {
|
|
1517
|
+
// return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
|
|
1518
|
+
// }
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
CSSMathSum.prototype.sumValue = function () {
|
|
1522
|
+
var sum = [];
|
|
1523
|
+
this.numericValues().forEach(function (value) {
|
|
1524
|
+
var child_sum = value.sumValue();
|
|
1525
|
+
|
|
1526
|
+
if (!child_sum.length) {
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
child_sum.forEach(function (term) {
|
|
1531
|
+
var index = sum.findIndex(function (s) {
|
|
1532
|
+
return JSON.stringify(s.units) === JSON.stringify(term.units);
|
|
1533
|
+
});
|
|
1534
|
+
|
|
1535
|
+
if (index === -1) {
|
|
1536
|
+
sum.push((0, _tslib.__assign)({}, term));
|
|
1537
|
+
} else {
|
|
1538
|
+
sum[index].value += term.value;
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
|
|
1543
|
+
return sum;
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
CSSMathSum.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1547
|
+
if (paren_less == _types.ParenLess.kNo) {
|
|
1548
|
+
result += nested === _types.Nested.kYes ? '(' : 'calc(';
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
var values = this.numericValues();
|
|
1552
|
+
result = values[0].buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1553
|
+
|
|
1554
|
+
for (var i = 1; i < values.length; i++) {
|
|
1555
|
+
var arg = values[i];
|
|
1556
|
+
|
|
1557
|
+
if (arg.getType() === _CSSStyleValue.CSSStyleValueType.kNegateType) {
|
|
1558
|
+
result += ' - ';
|
|
1559
|
+
result = arg.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1560
|
+
} else {
|
|
1561
|
+
result += ' + ';
|
|
1562
|
+
result = arg.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
if (paren_less === _types.ParenLess.kNo) {
|
|
1567
|
+
result += ')';
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
return result;
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
return CSSMathSum;
|
|
1574
|
+
}(CSSMathVariadic);
|
|
1575
|
+
|
|
1576
|
+
exports.CSSMathSum = CSSMathSum;
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* Represents the product of one or more CSSNumericValues.
|
|
1580
|
+
* @see https://drafts.css-houdini.org/css-typed-om/#cssmathproduct
|
|
1581
|
+
*/
|
|
1582
|
+
var CSSMathProduct =
|
|
1583
|
+
/** @class */
|
|
1584
|
+
function (_super) {
|
|
1585
|
+
(0, _tslib.__extends)(CSSMathProduct, _super);
|
|
1586
|
+
|
|
1587
|
+
function CSSMathProduct() {
|
|
1588
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1589
|
+
|
|
1590
|
+
_this.operator = 'product';
|
|
1591
|
+
return _this;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
CSSMathProduct.create = function (values) {
|
|
1595
|
+
var error = false;
|
|
1596
|
+
var finalType = typeCheck(values, CSSNumericValueType.multiply, error);
|
|
1597
|
+
return error ? null : new CSSMathProduct(values, finalType);
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
CSSMathProduct.multiplyUnitMaps = function (a, b) {
|
|
1601
|
+
Object.keys(b).forEach(function (key) {
|
|
1602
|
+
(0, _assert.DCHECK_NE)(b[key].value, 0);
|
|
1603
|
+
var old_value = key in a ? a[key].value : 0;
|
|
1604
|
+
|
|
1605
|
+
if (old_value + b[key].value === 0) {
|
|
1606
|
+
delete a[key];
|
|
1607
|
+
} else {
|
|
1608
|
+
a[key] = old_value + b[key].value;
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
return a;
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
CSSMathProduct.prototype.clone = function () {
|
|
1615
|
+
return new CSSMathProduct(this.values, this.type_);
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
CSSMathProduct.prototype.getType = function () {
|
|
1619
|
+
return _CSSStyleValue.CSSStyleValueType.kProductType;
|
|
1620
|
+
}; // toCalcExpressionNode() {
|
|
1621
|
+
// return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kMultiply);
|
|
1622
|
+
// }
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
CSSMathProduct.prototype.sumValue = function () {
|
|
1626
|
+
var sum = [{
|
|
1627
|
+
value: 1,
|
|
1628
|
+
units: {}
|
|
1629
|
+
}];
|
|
1630
|
+
this.numericValues().forEach(function (value) {
|
|
1631
|
+
var child_sum = value.sumValue();
|
|
1632
|
+
|
|
1633
|
+
if (!child_sum.length) {
|
|
1634
|
+
return null;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
var new_sum = [];
|
|
1638
|
+
sum.forEach(function (a) {
|
|
1639
|
+
child_sum.forEach(function (b) {
|
|
1640
|
+
new_sum.push({
|
|
1641
|
+
value: a.value * b.value,
|
|
1642
|
+
units: CSSMathProduct.multiplyUnitMaps(a.units, b.units)
|
|
1643
|
+
});
|
|
1644
|
+
});
|
|
1645
|
+
});
|
|
1646
|
+
sum = new_sum;
|
|
1647
|
+
});
|
|
1648
|
+
return sum;
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
CSSMathProduct.prototype.buildCSSText = function (nested, paren_less, result) {
|
|
1652
|
+
if (paren_less == _types.ParenLess.kNo) {
|
|
1653
|
+
result += nested === _types.Nested.kYes ? '(' : 'calc(';
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
var values = this.numericValues();
|
|
1657
|
+
result = values[0].buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1658
|
+
|
|
1659
|
+
for (var i = 1; i < values.length; i++) {
|
|
1660
|
+
var arg = values[i];
|
|
1661
|
+
|
|
1662
|
+
if (arg.getType() === _CSSStyleValue.CSSStyleValueType.kInvertType) {
|
|
1663
|
+
result += ' / ';
|
|
1664
|
+
result = arg.value.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1665
|
+
} else {
|
|
1666
|
+
result += ' * ';
|
|
1667
|
+
result = arg.buildCSSText(_types.Nested.kYes, _types.ParenLess.kNo, result);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
if (paren_less === _types.ParenLess.kNo) {
|
|
1672
|
+
result += ')';
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
return result;
|
|
1676
|
+
};
|
|
1677
|
+
|
|
1678
|
+
return CSSMathProduct;
|
|
1679
|
+
}(CSSMathVariadic);
|
|
1680
|
+
|
|
1681
|
+
exports.CSSMathProduct = CSSMathProduct;
|
|
1682
|
+
var Opx = new CSSUnitValue(0, 'px');
|
|
1683
|
+
exports.Opx = Opx;
|
|
1684
|
+
var Odeg = new CSSUnitValue(0, 'deg');
|
|
1685
|
+
exports.Odeg = Odeg;
|