@antv/g-lite 1.0.34 → 1.0.35

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.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import RBush from 'rbush/rbush.js';
2
2
  export { default as RBush } from 'rbush/rbush.js';
3
3
  import { isString, isNil, isObject, clamp, isNumber, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isBoolean, isUndefined, getPointAtLength, distanceSquareRoot, getTotalLength, min, max, isNumberEqual, mod } from '@antv/util';
4
- import { vec3, quat as quat$1, mat4, vec2, mat3, vec4 } from 'gl-matrix';
5
4
  import { color } from 'd3-color';
6
5
  import { Polyline as Polyline$1, Line as Line$1, Arc, Cubic, Quad } from '@antv/g-math';
6
+ import { mat4, vec3, quat as quat$1, mat3, vec4, vec2 } from 'gl-matrix';
7
7
  import EventEmitter from 'eventemitter3';
8
8
 
9
9
  /**
@@ -73,383 +73,6 @@ var PropertySyntax;
73
73
  PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
74
74
  })(PropertySyntax || (PropertySyntax = {}));
75
75
 
76
- /**
77
- * Axis-Aligned Bounding Box
78
- * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
79
- * @see https://github.com/antvis/GWebGPUEngine/issues/3
80
- */
81
- var AABB = /*#__PURE__*/function () {
82
- AABB.isEmpty = function isEmpty(aabb) {
83
- return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
84
- };
85
- function AABB(center, halfExtents) {
86
- if (center === void 0) {
87
- center = [0, 0, 0];
88
- }
89
- if (halfExtents === void 0) {
90
- halfExtents = [0, 0, 0];
91
- }
92
- this.center = vec3.create();
93
- this.halfExtents = vec3.create();
94
- this.min = vec3.create();
95
- this.max = vec3.create();
96
- this.update(center, halfExtents);
97
- }
98
- var _proto = AABB.prototype;
99
- _proto.update = function update(center, halfExtents) {
100
- vec3.copy(this.center, center);
101
- vec3.copy(this.halfExtents, halfExtents);
102
- vec3.sub(this.min, this.center, this.halfExtents);
103
- vec3.add(this.max, this.center, this.halfExtents);
104
- };
105
- _proto.setMinMax = function setMinMax(min, max) {
106
- vec3.add(this.center, max, min);
107
- vec3.scale(this.center, this.center, 0.5);
108
- vec3.sub(this.halfExtents, max, min);
109
- vec3.scale(this.halfExtents, this.halfExtents, 0.5);
110
- vec3.copy(this.min, min);
111
- vec3.copy(this.max, max);
112
- };
113
- _proto.getMin = function getMin() {
114
- return this.min;
115
- };
116
- _proto.getMax = function getMax() {
117
- return this.max;
118
- };
119
- _proto.add = function add(aabb) {
120
- if (AABB.isEmpty(aabb)) {
121
- return;
122
- }
123
- if (AABB.isEmpty(this)) {
124
- this.setMinMax(aabb.getMin(), aabb.getMax());
125
- return;
126
- }
127
- var tc = this.center;
128
- var tcx = tc[0];
129
- var tcy = tc[1];
130
- var tcz = tc[2];
131
- var th = this.halfExtents;
132
- var thx = th[0];
133
- var thy = th[1];
134
- var thz = th[2];
135
- var tminx = tcx - thx;
136
- var tmaxx = tcx + thx;
137
- var tminy = tcy - thy;
138
- var tmaxy = tcy + thy;
139
- var tminz = tcz - thz;
140
- var tmaxz = tcz + thz;
141
- var oc = aabb.center;
142
- var ocx = oc[0];
143
- var ocy = oc[1];
144
- var ocz = oc[2];
145
- var oh = aabb.halfExtents;
146
- var ohx = oh[0];
147
- var ohy = oh[1];
148
- var ohz = oh[2];
149
- var ominx = ocx - ohx;
150
- var omaxx = ocx + ohx;
151
- var ominy = ocy - ohy;
152
- var omaxy = ocy + ohy;
153
- var ominz = ocz - ohz;
154
- var omaxz = ocz + ohz;
155
- if (ominx < tminx) {
156
- tminx = ominx;
157
- }
158
- if (omaxx > tmaxx) {
159
- tmaxx = omaxx;
160
- }
161
- if (ominy < tminy) {
162
- tminy = ominy;
163
- }
164
- if (omaxy > tmaxy) {
165
- tmaxy = omaxy;
166
- }
167
- if (ominz < tminz) {
168
- tminz = ominz;
169
- }
170
- if (omaxz > tmaxz) {
171
- tmaxz = omaxz;
172
- }
173
- tc[0] = (tminx + tmaxx) * 0.5;
174
- tc[1] = (tminy + tmaxy) * 0.5;
175
- tc[2] = (tminz + tmaxz) * 0.5;
176
- th[0] = (tmaxx - tminx) * 0.5;
177
- th[1] = (tmaxy - tminy) * 0.5;
178
- th[2] = (tmaxz - tminz) * 0.5;
179
- this.min[0] = tminx;
180
- this.min[1] = tminy;
181
- this.min[2] = tminz;
182
- this.max[0] = tmaxx;
183
- this.max[1] = tmaxy;
184
- this.max[2] = tmaxz;
185
- };
186
- _proto.setFromTransformedAABB = function setFromTransformedAABB(aabb, m) {
187
- var bc = this.center;
188
- var br = this.halfExtents;
189
- var ac = aabb.center;
190
- var ar = aabb.halfExtents;
191
- var mx0 = m[0];
192
- var mx1 = m[4];
193
- var mx2 = m[8];
194
- var my0 = m[1];
195
- var my1 = m[5];
196
- var my2 = m[9];
197
- var mz0 = m[2];
198
- var mz1 = m[6];
199
- var mz2 = m[10];
200
- var mx0a = Math.abs(mx0);
201
- var mx1a = Math.abs(mx1);
202
- var mx2a = Math.abs(mx2);
203
- var my0a = Math.abs(my0);
204
- var my1a = Math.abs(my1);
205
- var my2a = Math.abs(my2);
206
- var mz0a = Math.abs(mz0);
207
- var mz1a = Math.abs(mz1);
208
- var mz2a = Math.abs(mz2);
209
- vec3.set(bc, m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2], m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2], m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2]);
210
- vec3.set(br, mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2], my0a * ar[0] + my1a * ar[1] + my2a * ar[2], mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2]);
211
- this.min = vec3.sub(this.min, bc, br);
212
- this.max = vec3.add(this.max, bc, br);
213
- };
214
- _proto.intersects = function intersects(aabb) {
215
- var aMax = this.getMax();
216
- var aMin = this.getMin();
217
- var bMax = aabb.getMax();
218
- var bMin = aabb.getMin();
219
- return aMin[0] <= bMax[0] && aMax[0] >= bMin[0] && aMin[1] <= bMax[1] && aMax[1] >= bMin[1] && aMin[2] <= bMax[2] && aMax[2] >= bMin[2];
220
- };
221
- _proto.intersection = function intersection(aabb) {
222
- if (!this.intersects(aabb)) {
223
- return null;
224
- }
225
- var intersection = new AABB();
226
- var min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
227
- var max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
228
- intersection.setMinMax(min, max);
229
- return intersection;
230
- };
231
- _proto.containsPoint = function containsPoint(point) {
232
- var min = this.getMin();
233
- var max = this.getMax();
234
- return !(point[0] < min[0] || point[0] > max[0] || point[1] < min[1] || point[1] > max[1] || point[2] < min[2] || point[2] > max[2]);
235
- }
236
- /**
237
- * get n-vertex
238
- * @param plane plane of CullingVolume
239
- */;
240
- _proto.getNegativeFarPoint = function getNegativeFarPoint(plane) {
241
- if (plane.pnVertexFlag === 0x111) {
242
- return vec3.copy(vec3.create(), this.min);
243
- } else if (plane.pnVertexFlag === 0x110) {
244
- return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
245
- } else if (plane.pnVertexFlag === 0x101) {
246
- return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
247
- } else if (plane.pnVertexFlag === 0x100) {
248
- return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
249
- } else if (plane.pnVertexFlag === 0x011) {
250
- return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
251
- } else if (plane.pnVertexFlag === 0x010) {
252
- return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
253
- } else if (plane.pnVertexFlag === 0x001) {
254
- return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
255
- } else {
256
- return vec3.fromValues(this.max[0], this.max[1], this.max[2]);
257
- }
258
- }
259
- /**
260
- * get p-vertex
261
- * @param plane plane of CullingVolume
262
- */;
263
- _proto.getPositiveFarPoint = function getPositiveFarPoint(plane) {
264
- if (plane.pnVertexFlag === 0x111) {
265
- return vec3.copy(vec3.create(), this.max);
266
- } else if (plane.pnVertexFlag === 0x110) {
267
- return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
268
- } else if (plane.pnVertexFlag === 0x101) {
269
- return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
270
- } else if (plane.pnVertexFlag === 0x100) {
271
- return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
272
- } else if (plane.pnVertexFlag === 0x011) {
273
- return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
274
- } else if (plane.pnVertexFlag === 0x010) {
275
- return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
276
- } else if (plane.pnVertexFlag === 0x001) {
277
- return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
278
- } else {
279
- return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
280
- }
281
- };
282
- return AABB;
283
- }();
284
-
285
- var Plane = /*#__PURE__*/function () {
286
- /**
287
- * lookup table for p-vertex & n-vertex when doing frustum culling
288
- */
289
-
290
- function Plane(distance, normal) {
291
- this.distance = void 0;
292
- this.normal = void 0;
293
- this.pnVertexFlag = void 0;
294
- this.distance = distance || 0;
295
- this.normal = normal || vec3.fromValues(0, 1, 0);
296
- this.updatePNVertexFlag();
297
- }
298
- var _proto = Plane.prototype;
299
- _proto.updatePNVertexFlag = function updatePNVertexFlag() {
300
- this.pnVertexFlag = (Number(this.normal[0] >= 0) << 8) + (Number(this.normal[1] >= 0) << 4) + Number(this.normal[2] >= 0);
301
- };
302
- _proto.distanceToPoint = function distanceToPoint(point) {
303
- return vec3.dot(point, this.normal) - this.distance;
304
- };
305
- _proto.normalize = function normalize() {
306
- var invLen = 1 / vec3.len(this.normal);
307
- vec3.scale(this.normal, this.normal, invLen);
308
- this.distance *= invLen;
309
- };
310
- _proto.intersectsLine = function intersectsLine(start, end, point) {
311
- var d0 = this.distanceToPoint(start);
312
- var d1 = this.distanceToPoint(end);
313
- var t = d0 / (d0 - d1);
314
- var intersects = t >= 0 && t <= 1;
315
- if (intersects && point) {
316
- vec3.lerp(point, start, end, t);
317
- }
318
- return intersects;
319
- };
320
- return Plane;
321
- }();
322
-
323
- var Mask;
324
- (function (Mask) {
325
- Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
326
- Mask[Mask["INSIDE"] = 0] = "INSIDE";
327
- Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
328
- })(Mask || (Mask = {}));
329
- var Frustum = /*#__PURE__*/function () {
330
- function Frustum(planes) {
331
- this.planes = [];
332
- if (planes) {
333
- this.planes = planes;
334
- } else {
335
- for (var i = 0; i < 6; i++) {
336
- this.planes.push(new Plane());
337
- }
338
- }
339
- }
340
- /**
341
- * extract 6 planes from projectionMatrix
342
- * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
343
- */
344
- var _proto = Frustum.prototype;
345
- _proto.extractFromVPMatrix = function extractFromVPMatrix(projectionMatrix) {
346
- // @ts-ignore
347
- var m0 = projectionMatrix[0],
348
- m1 = projectionMatrix[1],
349
- m2 = projectionMatrix[2],
350
- m3 = projectionMatrix[3],
351
- m4 = projectionMatrix[4],
352
- m5 = projectionMatrix[5],
353
- m6 = projectionMatrix[6],
354
- m7 = projectionMatrix[7],
355
- m8 = projectionMatrix[8],
356
- m9 = projectionMatrix[9],
357
- m10 = projectionMatrix[10],
358
- m11 = projectionMatrix[11],
359
- m12 = projectionMatrix[12],
360
- m13 = projectionMatrix[13],
361
- m14 = projectionMatrix[14],
362
- m15 = projectionMatrix[15];
363
- // right
364
- vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
365
- this.planes[0].distance = m15 - m12;
366
- // left
367
- vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
368
- this.planes[1].distance = m15 + m12;
369
- // bottom
370
- vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
371
- this.planes[2].distance = m15 + m13;
372
- // top
373
- vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
374
- this.planes[3].distance = m15 - m13;
375
- // far
376
- vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
377
- this.planes[4].distance = m15 - m14;
378
- // near
379
- vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
380
- this.planes[5].distance = m15 + m14;
381
- this.planes.forEach(function (plane) {
382
- plane.normalize();
383
- plane.updatePNVertexFlag();
384
- });
385
- };
386
- return Frustum;
387
- }();
388
-
389
- var Point = /*#__PURE__*/function () {
390
- function Point(x, y) {
391
- if (x === void 0) {
392
- x = 0;
393
- }
394
- if (y === void 0) {
395
- y = 0;
396
- }
397
- this.x = 0;
398
- this.y = 0;
399
- this.x = x;
400
- this.y = y;
401
- }
402
- var _proto = Point.prototype;
403
- _proto.clone = function clone() {
404
- return new Point(this.x, this.y);
405
- };
406
- _proto.copyFrom = function copyFrom(p) {
407
- this.x = p.x;
408
- this.y = p.y;
409
- };
410
- return Point;
411
- }();
412
-
413
- var Rectangle = /*#__PURE__*/function () {
414
- function Rectangle(x, y, width, height) {
415
- this.x = void 0;
416
- this.y = void 0;
417
- this.width = void 0;
418
- this.height = void 0;
419
- this.left = void 0;
420
- this.right = void 0;
421
- this.top = void 0;
422
- this.bottom = void 0;
423
- this.x = x;
424
- this.y = y;
425
- this.width = width;
426
- this.height = height;
427
- this.left = x;
428
- this.right = x + width;
429
- this.top = y;
430
- this.bottom = y + height;
431
- }
432
- var _proto = Rectangle.prototype;
433
- _proto.toJSON = function toJSON() {};
434
- return Rectangle;
435
- }();
436
-
437
- var Shape;
438
- (function (Shape) {
439
- Shape["GROUP"] = "g";
440
- Shape["CIRCLE"] = "circle";
441
- Shape["ELLIPSE"] = "ellipse";
442
- Shape["IMAGE"] = "image";
443
- Shape["RECT"] = "rect";
444
- Shape["LINE"] = "line";
445
- Shape["POLYLINE"] = "polyline";
446
- Shape["POLYGON"] = "polygon";
447
- Shape["TEXT"] = "text";
448
- Shape["PATH"] = "path";
449
- Shape["HTML"] = "html";
450
- Shape["MESH"] = "mesh";
451
- })(Shape || (Shape = {}));
452
-
453
76
  function memoize(func, resolver) {
454
77
  if (typeof func !== 'function' || resolver != null && typeof resolver !== 'function') {
455
78
  throw new TypeError('Expected a function');
@@ -486,16 +109,6 @@ function DCHECK(bool) {
486
109
  throw new Error();
487
110
  }
488
111
  }
489
- function DCHECK_EQ(a, b) {
490
- if (a !== b) {
491
- throw new Error();
492
- }
493
- }
494
- function DCHECK_NE(a, b) {
495
- if (a === b) {
496
- throw new Error();
497
- }
498
- }
499
112
  function isFunction(func) {
500
113
  return typeof func === 'function';
501
114
  }
@@ -1659,650 +1272,107 @@ var CSSColorValue = /*#__PURE__*/function (_CSSStyleValue) {
1659
1272
  function CSSColorValue(colorSpace) {
1660
1273
  var _this;
1661
1274
  _this = _CSSStyleValue.call(this) || this;
1662
- _this.colorSpace = void 0;
1663
- _this.colorSpace = colorSpace;
1664
- return _this;
1665
- }
1666
- var _proto = CSSColorValue.prototype;
1667
- _proto.getType = function getType() {
1668
- return CSSStyleValueType.kColorType;
1669
- }
1670
- // buildCSSText(n: Nested, p: ParenLess, result: string): string {
1671
- // let text = '';
1672
- // if (this.colorSpace === 'rgb') {
1673
- // text = `rgba(${this.channels.join(',')},${this.alpha})`;
1674
- // }
1675
- // return (result += text);
1676
- // }
1677
- /**
1678
- * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to
1679
- */;
1680
- _proto.to = function to(colorSpace) {
1681
- return this;
1682
- };
1683
- return CSSColorValue;
1684
- }(CSSStyleValue);
1685
-
1686
- var GradientType;
1687
- (function (GradientType) {
1688
- GradientType[GradientType["Constant"] = 0] = "Constant";
1689
- GradientType[GradientType["LinearGradient"] = 1] = "LinearGradient";
1690
- GradientType[GradientType["RadialGradient"] = 2] = "RadialGradient";
1691
- })(GradientType || (GradientType = {}));
1692
- var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
1693
- _inheritsLoose(CSSGradientValue, _CSSStyleValue);
1694
- function CSSGradientValue(type, value) {
1695
- var _this;
1696
- _this = _CSSStyleValue.call(this) || this;
1697
- _this.type = void 0;
1698
- _this.value = void 0;
1699
- _this.type = type;
1700
- _this.value = value;
1701
- return _this;
1702
- }
1703
- var _proto = CSSGradientValue.prototype;
1704
- _proto.clone = function clone() {
1705
- return new CSSGradientValue(this.type, this.value);
1706
- };
1707
- _proto.buildCSSText = function buildCSSText(n, p, result) {
1708
- return result;
1709
- };
1710
- _proto.getType = function getType() {
1711
- return CSSStyleValueType.kColorType;
1712
- };
1713
- return CSSGradientValue;
1714
- }(CSSStyleValue);
1715
-
1716
- /**
1717
- * CSSKeywordValue represents CSS Values that are specified as keywords
1718
- * eg. 'initial'
1719
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue
1720
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl
1721
- */
1722
- var CSSKeywordValue = /*#__PURE__*/function (_CSSStyleValue) {
1723
- _inheritsLoose(CSSKeywordValue, _CSSStyleValue);
1724
- function CSSKeywordValue(value) {
1725
- var _this;
1726
- _this = _CSSStyleValue.call(this) || this;
1727
- _this.value = void 0;
1728
- _this.value = value;
1729
- return _this;
1730
- }
1731
- var _proto = CSSKeywordValue.prototype;
1732
- _proto.clone = function clone() {
1733
- return new CSSKeywordValue(this.value);
1734
- };
1735
- _proto.getType = function getType() {
1736
- return CSSStyleValueType.kKeywordType;
1737
- };
1738
- _proto.buildCSSText = function buildCSSText(n, p, result) {
1739
- return result + this.value;
1740
- };
1741
- return CSSKeywordValue;
1742
- }(CSSStyleValue);
1743
-
1744
- var CSSMathOperator;
1745
- (function (CSSMathOperator) {
1746
- CSSMathOperator["kAdd"] = "+";
1747
- CSSMathOperator["kSubtract"] = "-";
1748
- CSSMathOperator["kMultiply"] = "*";
1749
- CSSMathOperator["kDivide"] = "/";
1750
- CSSMathOperator["kMin"] = "min";
1751
- CSSMathOperator["kMax"] = "max";
1752
- CSSMathOperator["kClamp"] = "clamp";
1753
- CSSMathOperator["kInvalid"] = "";
1754
- })(CSSMathOperator || (CSSMathOperator = {}));
1755
-
1756
- // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
1757
- var BaseType;
1758
- (function (BaseType) {
1759
- BaseType[BaseType["kLength"] = 0] = "kLength";
1760
- BaseType[BaseType["kAngle"] = 1] = "kAngle";
1761
- BaseType[BaseType["kTime"] = 2] = "kTime";
1762
- BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
1763
- BaseType[BaseType["kResolution"] = 4] = "kResolution";
1764
- BaseType[BaseType["kFlex"] = 5] = "kFlex";
1765
- BaseType[BaseType["kPercent"] = 6] = "kPercent";
1766
- BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
1767
- })(BaseType || (BaseType = {}));
1768
- function unitTypeToBaseType(unit) {
1769
- DCHECK_NE(unit, UnitType.kNumber);
1770
- switch (unit) {
1771
- case UnitType.kEms:
1772
- // case UnitType.kExs:
1773
- case UnitType.kPixels:
1774
- // case UnitType.kCentimeters:
1775
- // case UnitType.kMillimeters:
1776
- // case UnitType.kQuarterMillimeters:
1777
- // case UnitType.kInches:
1778
- // case UnitType.kPoints:
1779
- // case UnitType.kPicas:
1780
- // case UnitType.kUserUnits:
1781
- // case UnitType.kViewportWidth:
1782
- // case UnitType.kViewportHeight:
1783
- // case UnitType.kViewportInlineSize:
1784
- // case UnitType.kViewportBlockSize:
1785
- // case UnitType.kViewportMin:
1786
- // case UnitType.kViewportMax:
1787
- // case UnitType.kSmallViewportWidth:
1788
- // case UnitType.kSmallViewportHeight:
1789
- // case UnitType.kSmallViewportInlineSize:
1790
- // case UnitType.kSmallViewportBlockSize:
1791
- // case UnitType.kSmallViewportMin:
1792
- // case UnitType.kSmallViewportMax:
1793
- // case UnitType.kLargeViewportWidth:
1794
- // case UnitType.kLargeViewportHeight:
1795
- // case UnitType.kLargeViewportInlineSize:
1796
- // case UnitType.kLargeViewportBlockSize:
1797
- // case UnitType.kLargeViewportMin:
1798
- // case UnitType.kLargeViewportMax:
1799
- // case UnitType.kDynamicViewportWidth:
1800
- // case UnitType.kDynamicViewportHeight:
1801
- // case UnitType.kDynamicViewportInlineSize:
1802
- // case UnitType.kDynamicViewportBlockSize:
1803
- // case UnitType.kDynamicViewportMin:
1804
- // case UnitType.kDynamicViewportMax:
1805
- // case UnitType.kContainerWidth:
1806
- // case UnitType.kContainerHeight:
1807
- // case UnitType.kContainerInlineSize:
1808
- // case UnitType.kContainerBlockSize:
1809
- // case UnitType.kContainerMin:
1810
- // case UnitType.kContainerMax:
1811
- case UnitType.kRems:
1812
- // case UnitType.kChs:
1813
- return BaseType.kLength;
1814
- case UnitType.kMilliseconds:
1815
- case UnitType.kSeconds:
1816
- return BaseType.kTime;
1817
- case UnitType.kDegrees:
1818
- case UnitType.kRadians:
1819
- case UnitType.kGradians:
1820
- case UnitType.kTurns:
1821
- return BaseType.kAngle;
1822
- // case UnitType.kHertz:
1823
- // case UnitType.kKilohertz:
1824
- // return BaseType.kFrequency;
1825
- // case UnitType.kDotsPerPixel:
1826
- // case UnitType.kDotsPerInch:
1827
- // case UnitType.kDotsPerCentimeter:
1828
- // return BaseType.kResolution;
1829
- // case UnitType.kFraction:
1830
- // return BaseType.kFlex;
1831
- case UnitType.kPercentage:
1832
- return BaseType.kPercent;
1833
- default:
1834
- return BaseType.kLength;
1835
- }
1836
- }
1837
- function baseTypeToString(baseType) {
1838
- switch (baseType) {
1839
- case BaseType.kLength:
1840
- return 'length';
1841
- case BaseType.kAngle:
1842
- return 'angle';
1843
- case BaseType.kTime:
1844
- return 'time';
1845
- case BaseType.kFrequency:
1846
- return 'frequency';
1847
- case BaseType.kResolution:
1848
- return 'resolution';
1849
- case BaseType.kFlex:
1850
- return 'flex';
1851
- case BaseType.kPercent:
1852
- return 'percent';
1853
- }
1854
- return '';
1855
- }
1856
- var CSSNumericValueType = /*#__PURE__*/function () {
1857
- function CSSNumericValueType(unit, exponent) {
1858
- if (unit === void 0) {
1859
- unit = UnitType.kNumber;
1860
- }
1861
- if (exponent === void 0) {
1862
- exponent = 1;
1863
- }
1864
- this.exponents = [];
1865
- this.numNonZeroEntries = 0;
1866
- this.percentHint = BaseType.kPercent;
1867
- this.hasPercentHint = false;
1868
- this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
1869
- if (unit !== UnitType.kNumber) {
1870
- this.setExponent(unitTypeToBaseType(unit), exponent);
1871
- }
1872
- }
1873
- var _proto = CSSNumericValueType.prototype;
1874
- _proto.applyPercentHint = function applyPercentHint(hint) {
1875
- DCHECK_NE(hint, BaseType.kPercent);
1876
- this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
1877
- this.setExponent(BaseType.kPercent, 0);
1878
- this.percentHint = hint;
1879
- this.hasPercentHint = true;
1880
- };
1881
- _proto.hasNonZeroEntries = function hasNonZeroEntries() {
1882
- return this.numNonZeroEntries > 0;
1883
- };
1884
- _proto.isOnlyNonZeroEntry = function isOnlyNonZeroEntry(baseType, value) {
1885
- DCHECK_NE(value, 0);
1886
- return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
1887
- };
1888
- _proto.exponent = function exponent(type) {
1889
- return this.exponents[type];
1890
- };
1891
- _proto.setExponent = function setExponent(type, newValue) {
1892
- var oldValue = this.exponents[type];
1893
- if (oldValue == 0 && newValue !== 0) {
1894
- this.numNonZeroEntries++;
1895
- } else if (oldValue !== 0 && newValue == 0) {
1896
- this.numNonZeroEntries--;
1897
- }
1898
- this.exponents[type] = newValue;
1899
- };
1900
- CSSNumericValueType.negateExponents = function negateExponents(type) {
1901
- type.exponents.forEach(function (v) {
1902
- return v *= -1;
1903
- });
1904
- return type;
1905
- };
1906
- _proto.matchesBaseType = function matchesBaseType(baseType) {
1907
- DCHECK_NE(baseType, BaseType.kPercent);
1908
- return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
1909
- };
1910
- _proto.matchesPercentage = function matchesPercentage() {
1911
- return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
1912
- };
1913
- _proto.matchesBaseTypePercentage = function matchesBaseTypePercentage(baseType) {
1914
- DCHECK_NE(baseType, BaseType.kPercent);
1915
- return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
1916
- };
1917
- _proto.matchesNumber = function matchesNumber() {
1918
- return !this.hasNonZeroEntries() && !this.hasPercentHint;
1919
- };
1920
- _proto.matchesNumberPercentage = function matchesNumberPercentage() {
1921
- return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
1922
- };
1923
- CSSNumericValueType.add = function add(type1, type2, error) {
1924
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
1925
- return type1;
1926
- }
1927
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
1928
- DCHECK_EQ(type1.percentHint, type2.percentHint);
1929
- // Match up base types. Try to use the percent hint to match up any
1930
- // differences.
1931
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
1932
- var base_type = i;
1933
- if (type1.exponents[i] !== type2.exponents[i]) {
1934
- if (base_type !== BaseType.kPercent) {
1935
- type1.applyPercentHint(base_type);
1936
- type2.applyPercentHint(base_type);
1937
- }
1938
- if (type1.exponents[i] !== type2.exponents[i]) {
1939
- return type1;
1940
- }
1941
- }
1942
- }
1943
- return type1;
1944
- };
1945
- CSSNumericValueType.multiply = function multiply(type1, type2, error) {
1946
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
1947
- return type1;
1948
- }
1949
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
1950
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
1951
- var base_type = i;
1952
- type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
1953
- }
1954
- return type1;
1955
- };
1956
- return CSSNumericValueType;
1957
- }();
1958
- var fromNumberish = function fromNumberish(value) {
1959
- if (typeof value === 'number') {
1960
- return new CSSUnitValue(value, UnitType.kNumber);
1961
- }
1962
- return value;
1963
- };
1964
- /**
1965
- * CSSNumericValue is the base class for numeric and length typed CSS Values.
1966
- * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
1967
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue
1968
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl
1969
- */
1970
- var CSSNumericValue = /*#__PURE__*/function (_CSSStyleValue) {
1971
- _inheritsLoose(CSSNumericValue, _CSSStyleValue);
1972
- /**
1973
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#296
1974
- */
1975
- // static fromPercentish(value: CSSNumberish): CSSNumericValue {
1976
- // if (typeof value === 'number') {
1977
- // return new CSSUnitValue(value * 100, UnitType.kPercentage);
1978
- // }
1979
- // return value;
1980
- // }
1981
- function CSSNumericValue(type_) {
1982
- var _this;
1983
- _this = _CSSStyleValue.call(this) || this;
1984
- _this.type_ = void 0;
1985
- _this.type_ = type_;
1986
- return _this;
1987
- }
1988
- var _proto2 = CSSNumericValue.prototype;
1989
- _proto2.getType = function getType() {
1990
- return CSSStyleValueType.kUnknownType;
1991
- }
1992
- // toCSSValue() {
1993
- // return null;
1994
- // }
1995
- /**
1996
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/equals
1997
- */;
1998
- _proto2.equals = function equals() {
1999
- var _this2 = this;
2000
- for (var _len = arguments.length, numberishes = new Array(_len), _key = 0; _key < _len; _key++) {
2001
- numberishes[_key] = arguments[_key];
2002
- }
2003
- var values = cssNumberishesToNumericValues(numberishes);
2004
- return values.every(function (value) {
2005
- return _this2.equals(value);
2006
- });
2007
- }
2008
- /**
2009
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#439
2010
- */;
2011
- _proto2.add = function add() {
2012
- for (var _len2 = arguments.length, numberishes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2013
- numberishes[_key2] = arguments[_key2];
2014
- }
2015
- var values = cssNumberishesToNumericValues(numberishes);
2016
- prependValueForArithmetic(CSSStyleValueType.kSumType, values, this);
2017
- // eg. 1px + 2px = 3px
2018
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kAdd);
2019
- if (unitValue) {
2020
- return unitValue;
2021
- }
2022
- return CSSMathSum.create(values);
2023
- }
2024
- /**
2025
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#452
2026
- */;
2027
- _proto2.sub = function sub() {
2028
- for (var _len3 = arguments.length, numberishes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2029
- numberishes[_key3] = arguments[_key3];
2030
- }
2031
- var values = cssNumberishesToNumericValues(numberishes);
2032
- values = values.map(function (value) {
2033
- return value.negate();
2034
- });
2035
- prependValueForArithmetic(CSSStyleValueType.kSumType, values, this);
2036
- // eg. 3px - 2px = 1px
2037
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kAdd);
2038
- if (unitValue) {
2039
- return unitValue;
2040
- }
2041
- return CSSMathSum.create(values);
2042
- }
2043
- /**
2044
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/mul
2045
- */;
2046
- _proto2.mul = function mul() {
2047
- for (var _len4 = arguments.length, numberishes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2048
- numberishes[_key4] = arguments[_key4];
2049
- }
2050
- var values = cssNumberishesToNumericValues(numberishes);
2051
- prependValueForArithmetic(CSSStyleValueType.kProductType, values, this);
2052
- var unitValue = maybeMultiplyAsUnitValue(values);
2053
- if (unitValue) {
2054
- return unitValue;
2055
- }
2056
- return CSSMathProduct.create(values);
2057
- }
2058
- /**
2059
- * eg. calc(24px / 4%)
2060
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/div
2061
- */;
2062
- _proto2.div = function div() {
2063
- for (var _len5 = arguments.length, numberishes = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2064
- numberishes[_key5] = arguments[_key5];
2065
- }
2066
- var values = cssNumberishesToNumericValues(numberishes);
2067
- values = values.map(function (value) {
2068
- return value.invert();
2069
- });
2070
- prependValueForArithmetic(CSSStyleValueType.kProductType, values, this);
2071
- var unitValue = maybeMultiplyAsUnitValue(values);
2072
- if (unitValue) {
2073
- return unitValue;
2074
- }
2075
- return CSSMathProduct.create(values);
2076
- };
2077
- _proto2.min = function min() {
2078
- for (var _len6 = arguments.length, numberishes = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
2079
- numberishes[_key6] = arguments[_key6];
2080
- }
2081
- var values = cssNumberishesToNumericValues(numberishes);
2082
- prependValueForArithmetic(CSSStyleValueType.kMinType, values, this);
2083
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kMin);
2084
- if (unitValue) {
2085
- return unitValue;
2086
- }
2087
- return CSSMathMin.create(values);
2088
- };
2089
- _proto2.max = function max() {
2090
- for (var _len7 = arguments.length, numberishes = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
2091
- numberishes[_key7] = arguments[_key7];
2092
- }
2093
- var values = cssNumberishesToNumericValues(numberishes);
2094
- prependValueForArithmetic(CSSStyleValueType.kMaxType, values, this);
2095
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kMax);
2096
- if (unitValue) {
2097
- return unitValue;
2098
- }
2099
- return CSSMathMax.create(values);
2100
- }
2101
- /**
2102
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/to
2103
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#331
2104
- */;
2105
- _proto2.to = function to(unitOrName) {
2106
- var sum = this.sumValue();
2107
- if (sum.length === 0 || sum.length !== 1) return null;
2108
- var value = cssNumericSumValueEntryToUnitValue(sum[0]);
2109
- if (!value) return null;
2110
- var unit;
2111
- if (typeof unitOrName === 'string') {
2112
- unit = unitFromName(unitOrName);
2113
- } else {
2114
- unit = unitOrName;
2115
- }
2116
- return value.convertTo(unit);
2117
- }
2118
- /**
2119
- * converts the object's value to a CSSMathSum object to values of the specified unit.
2120
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/toSum
2121
- */;
2122
- _proto2.toSum = function toSum() {
2123
- for (var _len8 = arguments.length, unit_strings = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
2124
- unit_strings[_key8] = arguments[_key8];
2125
- }
2126
- for (var _i = 0, _unit_strings = unit_strings; _i < _unit_strings.length; _i++) {
2127
- var unit_string = _unit_strings[_i];
2128
- if (!CSSNumericValue.isValidUnit(unitFromName(unit_string))) {
2129
- return null;
2130
- }
2131
- }
2132
- var sum = this.sumValue();
2133
- if (!sum.length) {
2134
- return null;
2135
- }
2136
- var values = [];
2137
- for (var _iterator = _createForOfIteratorHelperLoose(sum), _step; !(_step = _iterator()).done;) {
2138
- var term = _step.value;
2139
- var value = cssNumericSumValueEntryToUnitValue(term);
2140
- if (!value) {
2141
- return null;
2142
- }
2143
- values.push(value);
2144
- }
2145
- if (unit_strings.length === 0) {
2146
- values.sort(function (a, b) {
2147
- return a.unit - b.unit;
2148
- });
2149
- // We got 'values' from a sum value, so it must be a valid CSSMathSum.
2150
- var _result = CSSMathSum.create(values);
2151
- DCHECK(!!_result);
2152
- return _result;
2153
- }
2154
- var result = [];
2155
- var _loop = function _loop() {
2156
- var unit_string = _unit_strings2[_i2];
2157
- var target_unit = unitFromName(unit_string);
2158
- DCHECK(CSSNumericValue.isValidUnit(target_unit));
2159
- // Collect all the terms that are compatible with this unit.
2160
- // We mark used terms as null so we don't use them again.
2161
- var total_value = values.reduce(function (cur_sum, value, i) {
2162
- if (value) {
2163
- var unit_value = value;
2164
- var converted_value = unit_value.convertTo(target_unit);
2165
- if (converted_value) {
2166
- cur_sum += converted_value.value;
2167
- values[i] = null;
2168
- }
2169
- }
2170
- return cur_sum;
2171
- }, 0);
2172
- result.push(new CSSUnitValue(total_value, target_unit));
2173
- };
2174
- for (var _i2 = 0, _unit_strings2 = unit_strings; _i2 < _unit_strings2.length; _i2++) {
2175
- _loop();
2176
- }
2177
- if (values.some(function (v) {
2178
- return !!v;
2179
- })) {
2180
- throw new Error('There were leftover terms that were not converted');
2181
- }
2182
- return CSSMathSum.create(result);
1275
+ _this.colorSpace = void 0;
1276
+ _this.colorSpace = colorSpace;
1277
+ return _this;
1278
+ }
1279
+ var _proto = CSSColorValue.prototype;
1280
+ _proto.getType = function getType() {
1281
+ return CSSStyleValueType.kColorType;
2183
1282
  }
1283
+ // buildCSSText(n: Nested, p: ParenLess, result: string): string {
1284
+ // let text = '';
1285
+ // if (this.colorSpace === 'rgb') {
1286
+ // text = `rgba(${this.channels.join(',')},${this.alpha})`;
1287
+ // }
1288
+ // return (result += text);
1289
+ // }
2184
1290
  /**
2185
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/type
2186
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#414
1291
+ * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to
2187
1292
  */;
2188
- _proto2.type = function type() {
2189
- var type = {
2190
- length: 0,
2191
- angle: 0,
2192
- time: 0,
2193
- frequency: 0,
2194
- resolution: 0,
2195
- flex: 0,
2196
- percent: 0,
2197
- percentHint: 'length'
2198
- };
2199
- var exponent = this.type_.exponent(BaseType.kLength);
2200
- if (exponent) {
2201
- type.length = exponent;
2202
- }
2203
- exponent = this.type_.exponent(BaseType.kAngle);
2204
- if (exponent) {
2205
- type.angle = exponent;
2206
- }
2207
- exponent = this.type_.exponent(BaseType.kTime);
2208
- if (exponent) {
2209
- type.time = exponent;
2210
- }
2211
- exponent = this.type_.exponent(BaseType.kFrequency);
2212
- if (exponent) {
2213
- type.frequency = exponent;
2214
- }
2215
- exponent = this.type_.exponent(BaseType.kResolution);
2216
- if (exponent) {
2217
- type.resolution = exponent;
2218
- }
2219
- exponent = this.type_.exponent(BaseType.kFlex);
2220
- if (exponent) {
2221
- type.flex = exponent;
2222
- }
2223
- exponent = this.type_.exponent(BaseType.kPercent);
2224
- if (exponent) {
2225
- type.percent = exponent;
2226
- }
2227
- if (this.type_.hasPercentHint) {
2228
- type.percentHint = baseTypeToString(this.type_.percentHint);
2229
- }
2230
- return type;
2231
- };
2232
- CSSNumericValue.isValidUnit = function isValidUnit(unit) {
2233
- // if (unit === UnitType.kUserUnits) return false;
2234
- if (unit === UnitType.kNumber || unit == UnitType.kPercentage || this.isLength(unit) || this.isAngle(unit) || this.isTime(unit)
2235
- // this.isFrequency(unit) ||
2236
- // this.isResolution(unit) ||
2237
- // this.isFlex(unit)
2238
- ) return true;
2239
- return false;
1293
+ _proto.to = function to(colorSpace) {
1294
+ return this;
1295
+ };
1296
+ return CSSColorValue;
1297
+ }(CSSStyleValue);
1298
+
1299
+ var GradientType;
1300
+ (function (GradientType) {
1301
+ GradientType[GradientType["Constant"] = 0] = "Constant";
1302
+ GradientType[GradientType["LinearGradient"] = 1] = "LinearGradient";
1303
+ GradientType[GradientType["RadialGradient"] = 2] = "RadialGradient";
1304
+ })(GradientType || (GradientType = {}));
1305
+ var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
1306
+ _inheritsLoose(CSSGradientValue, _CSSStyleValue);
1307
+ function CSSGradientValue(type, value) {
1308
+ var _this;
1309
+ _this = _CSSStyleValue.call(this) || this;
1310
+ _this.type = void 0;
1311
+ _this.value = void 0;
1312
+ _this.type = type;
1313
+ _this.value = value;
1314
+ return _this;
1315
+ }
1316
+ var _proto = CSSGradientValue.prototype;
1317
+ _proto.clone = function clone() {
1318
+ return new CSSGradientValue(this.type, this.value);
2240
1319
  };
2241
- _proto2.negate = function negate() {
2242
- return CSSMathNegate.create(this);
1320
+ _proto.buildCSSText = function buildCSSText(n, p, result) {
1321
+ return result;
2243
1322
  };
2244
- _proto2.invert = function invert() {
2245
- return CSSMathInvert.create(this);
1323
+ _proto.getType = function getType() {
1324
+ return CSSStyleValueType.kColorType;
2246
1325
  };
2247
- return CSSNumericValue;
1326
+ return CSSGradientValue;
2248
1327
  }(CSSStyleValue);
2249
- function cssNumberishesToNumericValues(values) {
2250
- return values.map(fromNumberish);
2251
- }
2252
- function prependValueForArithmetic(type, values, value) {
2253
- DCHECK(!!value);
2254
- if (value.getType() === type) {
2255
- values.unshift.apply(values, value.numericValues());
2256
- } else {
2257
- values.unshift(value);
2258
- }
2259
- }
2260
- function cssNumericSumValueEntryToUnitValue(term) {
2261
- if (Object.keys(term.units).length === 0) {
2262
- return new CSSUnitValue(term.value);
2263
- }
2264
- if (Object.keys(term.units).length === 1 && term.units[Object.keys(term.units)[0]] === 1) {
2265
- return new CSSUnitValue(term.value, Number(Object.keys(term.units)[0]));
1328
+
1329
+ /**
1330
+ * CSSKeywordValue represents CSS Values that are specified as keywords
1331
+ * eg. 'initial'
1332
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue
1333
+ * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl
1334
+ */
1335
+ var CSSKeywordValue = /*#__PURE__*/function (_CSSStyleValue) {
1336
+ _inheritsLoose(CSSKeywordValue, _CSSStyleValue);
1337
+ function CSSKeywordValue(value) {
1338
+ var _this;
1339
+ _this = _CSSStyleValue.call(this) || this;
1340
+ _this.value = void 0;
1341
+ _this.value = value;
1342
+ return _this;
2266
1343
  }
2267
- return null;
2268
- }
2269
- function maybeSimplifyAsUnitValue(values, operator) {
2270
- DCHECK(!!values.length);
2271
- var first_unit_value = values[0] instanceof CSSUnitValue ? values[0] : null;
2272
- if (!first_unit_value) return null;
2273
- var final_value = first_unit_value.value;
2274
- for (var i = 1; i < values.length; i++) {
2275
- var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
2276
- if (!unit_value || unit_value.unit !== first_unit_value.unit) return null;
2277
- if (operator === CSSMathOperator.kAdd) {
2278
- final_value += unit_value.value;
2279
- } else if (operator === CSSMathOperator.kMax) {
2280
- final_value = Math.max(final_value, unit_value.value);
2281
- } else if (operator === CSSMathOperator.kMin) {
2282
- final_value = Math.min(final_value, unit_value.value);
2283
- }
2284
- }
2285
- return new CSSUnitValue(final_value, first_unit_value.unit);
2286
- }
2287
- function maybeMultiplyAsUnitValue(values) {
2288
- DCHECK(!!values.length);
2289
- // We are allowed one unit value with type other than kNumber.
2290
- var unit_other_than_number = UnitType.kNumber;
2291
- var final_value = 1.0;
2292
- for (var i = 0; i < values.length; i++) {
2293
- var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
2294
- if (!unit_value) return null;
2295
- if (unit_value.unit !== UnitType.kNumber) {
2296
- if (unit_other_than_number !== UnitType.kNumber) return null;
2297
- unit_other_than_number = unit_value.unit;
2298
- }
2299
- final_value *= unit_value.value;
2300
- }
2301
- return new CSSUnitValue(final_value, unit_other_than_number);
2302
- }
2303
- var toCanonicalUnit = function toCanonicalUnit(unit) {
2304
- return canonicalUnitTypeForCategory(unitTypeToUnitCategory(unit));
2305
- };
1344
+ var _proto = CSSKeywordValue.prototype;
1345
+ _proto.clone = function clone() {
1346
+ return new CSSKeywordValue(this.value);
1347
+ };
1348
+ _proto.getType = function getType() {
1349
+ return CSSStyleValueType.kKeywordType;
1350
+ };
1351
+ _proto.buildCSSText = function buildCSSText(n, p, result) {
1352
+ return result + this.value;
1353
+ };
1354
+ return CSSKeywordValue;
1355
+ }(CSSStyleValue);
1356
+
1357
+ // type CSSNumericBaseType =
1358
+ // | 'length'
1359
+ // | 'angle'
1360
+ // | 'time'
1361
+ // | 'frequency'
1362
+ // | 'resolution'
1363
+ // | 'flex'
1364
+ // | 'percent';
1365
+ // https://drafts.css-houdini.org/css-typed-om/#dictdef-cssnumerictype
1366
+ // interface CSSNumericType {
1367
+ // length: number;
1368
+ // angle: number;
1369
+ // time: number;
1370
+ // frequency: number;
1371
+ // resolution: number;
1372
+ // flex: number;
1373
+ // percent: number;
1374
+ // percentHint: CSSNumericBaseType;
1375
+ // }
2306
1376
  var formatInfinityOrNaN = function formatInfinityOrNaN(number, suffix) {
2307
1377
  if (suffix === void 0) {
2308
1378
  suffix = '';
@@ -2316,49 +1386,52 @@ var formatInfinityOrNaN = function formatInfinityOrNaN(number, suffix) {
2316
1386
  }
2317
1387
  return result += suffix;
2318
1388
  };
2319
- var toCanonicalUnitIfPossible = function toCanonicalUnitIfPossible(unit) {
2320
- var canonical_unit = toCanonicalUnit(unit);
2321
- if (canonical_unit === UnitType.kUnknown) return unit;
2322
- return canonical_unit;
1389
+ var toCanonicalUnit = function toCanonicalUnit(unit) {
1390
+ return canonicalUnitTypeForCategory(unitTypeToUnitCategory(unit));
2323
1391
  };
1392
+ /**
1393
+ * CSSNumericValue is the base class for numeric and length typed CSS Values.
1394
+ * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
1395
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue
1396
+ * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl
1397
+ */
2324
1398
  /**
2325
1399
  * Represents numeric values that can be expressed as a single number plus a
2326
1400
  * unit (or a naked number or percentage).
2327
1401
  * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
2328
1402
  */
2329
- var CSSUnitValue = /*#__PURE__*/function (_CSSNumericValue) {
2330
- _inheritsLoose(CSSUnitValue, _CSSNumericValue);
2331
- // static fromCSSValue(value: CSSNumericLiteralValue) {
2332
- // let unit = value.type;
2333
- // if (unit === UnitType.kInteger) unit = UnitType.kNumber;
2334
- // if (!this.isValidUnit(unit)) return null;
2335
- // return new CSSUnitValue(value.getDoubleValue(), unit);
2336
- // }
2337
-
1403
+ var CSSUnitValue = /*#__PURE__*/function (_CSSStyleValue) {
1404
+ _inheritsLoose(CSSUnitValue, _CSSStyleValue);
2338
1405
  function CSSUnitValue(value, unitOrName) {
2339
- var _this3;
1406
+ var _this;
2340
1407
  if (unitOrName === void 0) {
2341
1408
  unitOrName = UnitType.kNumber;
2342
1409
  }
1410
+ _this = _CSSStyleValue.call(this) || this;
1411
+ _this.unit = void 0;
1412
+ _this.value = void 0;
2343
1413
  var unit;
2344
1414
  if (typeof unitOrName === 'string') {
2345
1415
  unit = unitFromName(unitOrName);
2346
1416
  } else {
2347
1417
  unit = unitOrName;
2348
1418
  }
2349
- // DCHECK(CSSUnitValue.isValidUnit(unit));
2350
- _this3 = _CSSNumericValue.call(this, new CSSNumericValueType(unit)) || this;
2351
- _this3.unit = void 0;
2352
- _this3.value = void 0;
2353
- _this3.unit = unit;
2354
- _this3.value = value;
2355
- return _this3;
1419
+ _this.unit = unit;
1420
+ _this.value = value;
1421
+ return _this;
2356
1422
  }
2357
- var _proto3 = CSSUnitValue.prototype;
2358
- _proto3.clone = function clone() {
1423
+ var _proto = CSSUnitValue.prototype;
1424
+ _proto.clone = function clone() {
2359
1425
  return new CSSUnitValue(this.value, this.unit);
2360
1426
  };
2361
- _proto3.convertTo = function convertTo(target_unit) {
1427
+ _proto.equals = function equals(other) {
1428
+ var other_unit_value = other;
1429
+ return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
1430
+ };
1431
+ _proto.getType = function getType() {
1432
+ return CSSStyleValueType.kUnitType;
1433
+ };
1434
+ _proto.convertTo = function convertTo(target_unit) {
2362
1435
  if (this.unit === target_unit) {
2363
1436
  return new CSSUnitValue(this.value, this.unit);
2364
1437
  }
@@ -2372,46 +1445,7 @@ var CSSUnitValue = /*#__PURE__*/function (_CSSNumericValue) {
2372
1445
  var scale_factor = conversionToCanonicalUnitsScaleFactor(this.unit) / conversionToCanonicalUnitsScaleFactor(target_unit);
2373
1446
  return new CSSUnitValue(this.value * scale_factor, target_unit);
2374
1447
  };
2375
- _proto3.equals = function equals(other) {
2376
- var other_unit_value = other;
2377
- return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
2378
- };
2379
- _proto3.getType = function getType() {
2380
- return CSSStyleValueType.kUnitType;
2381
- }
2382
- // toCSSValue() {
2383
- // return new CSSNumericLiteralValue(this.value, this.unit);
2384
- // }
2385
- // // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
2386
- // toCalcExpressionNode() {
2387
- // return CSSMathExpressionNumericLiteral.create(
2388
- // new CSSNumericLiteralValue(this.value, this.unit),
2389
- // );
2390
- // }
2391
- ;
2392
- _proto3.sumValue = function sumValue() {
2393
- var sum = [];
2394
- var unit_map = {};
2395
- if (this.unit !== UnitType.kNumber) {
2396
- unit_map[toCanonicalUnitIfPossible(this.unit)] = 1;
2397
- }
2398
- sum.push({
2399
- value: this.value * conversionToCanonicalUnitsScaleFactor(this.unit),
2400
- units: unit_map
2401
- });
2402
- return sum;
2403
- };
2404
- _proto3.negate = function negate() {
2405
- return new CSSUnitValue(-this.value, this.unit);
2406
- };
2407
- _proto3.invert = function invert() {
2408
- if (this.unit === UnitType.kNumber) {
2409
- if (this.value === 0) return null;
2410
- return new CSSUnitValue(1.0 / this.value, this.unit);
2411
- }
2412
- return CSSMathInvert.create(this);
2413
- };
2414
- _proto3.buildCSSText = function buildCSSText(n, p, result) {
1448
+ _proto.buildCSSText = function buildCSSText(n, p, result) {
2415
1449
  var text;
2416
1450
  switch (this.unit) {
2417
1451
  case UnitType.kUnknown:
@@ -2446,12 +1480,7 @@ var CSSUnitValue = /*#__PURE__*/function (_CSSNumericValue) {
2446
1480
  // case UnitType.kHertz:
2447
1481
  // case UnitType.kKilohertz:
2448
1482
  case UnitType.kTurns:
2449
- // case UnitType.kDynamicViewportMax: // case UnitType.kDynamicViewportMin: // case UnitType.kDynamicViewportBlockSize: // case UnitType.kDynamicViewportInlineSize: // case UnitType.kDynamicViewportHeight: // case UnitType.kDynamicViewportWidth: // case UnitType.kLargeViewportMax: // case UnitType.kLargeViewportMin: // case UnitType.kLargeViewportBlockSize: // case UnitType.kLargeViewportInlineSize: // case UnitType.kLargeViewportHeight: // case UnitType.kLargeViewportWidth: // case UnitType.kSmallViewportMax: // case UnitType.kSmallViewportMin: // case UnitType.kSmallViewportBlockSize: // case UnitType.kSmallViewportInlineSize: // case UnitType.kSmallViewportHeight: // case UnitType.kSmallViewportWidth: // case UnitType.kViewportMax: // case UnitType.kViewportMin: // case UnitType.kViewportBlockSize: // case UnitType.kViewportInlineSize: // case UnitType.kViewportHeight: // case UnitType.kViewportWidth: // case UnitType.kFraction:
2450
- // case UnitType.kContainerWidth:
2451
- // case UnitType.kContainerHeight:
2452
- // case UnitType.kContainerInlineSize:
2453
- // case UnitType.kContainerBlockSize:
2454
- // case UnitType.kContainerMin:
1483
+ // case UnitType.kContainerMin: // case UnitType.kContainerBlockSize: // case UnitType.kContainerInlineSize: // case UnitType.kContainerHeight: // case UnitType.kContainerWidth: // case UnitType.kDynamicViewportMax: // case UnitType.kDynamicViewportMin: // case UnitType.kDynamicViewportBlockSize: // case UnitType.kDynamicViewportInlineSize: // case UnitType.kDynamicViewportHeight: // case UnitType.kDynamicViewportWidth: // case UnitType.kLargeViewportMax: // case UnitType.kLargeViewportMin: // case UnitType.kLargeViewportBlockSize: // case UnitType.kLargeViewportInlineSize: // case UnitType.kLargeViewportHeight: // case UnitType.kLargeViewportWidth: // case UnitType.kSmallViewportMax: // case UnitType.kSmallViewportMin: // case UnitType.kSmallViewportBlockSize: // case UnitType.kSmallViewportInlineSize: // case UnitType.kSmallViewportHeight: // case UnitType.kSmallViewportWidth: // case UnitType.kViewportMax: // case UnitType.kViewportMin: // case UnitType.kViewportBlockSize: // case UnitType.kViewportInlineSize: // case UnitType.kViewportHeight: // case UnitType.kViewportWidth: // case UnitType.kFraction:
2455
1484
  // case UnitType.kContainerMax: {
2456
1485
  {
2457
1486
  var kMinInteger = -999999;
@@ -2474,504 +1503,7 @@ var CSSUnitValue = /*#__PURE__*/function (_CSSNumericValue) {
2474
1503
  return result;
2475
1504
  };
2476
1505
  return CSSUnitValue;
2477
- }(CSSNumericValue);
2478
- /**
2479
- * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
2480
- *
2481
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
2482
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
2483
- */
2484
- var CSSMathValue = /*#__PURE__*/function (_CSSNumericValue2) {
2485
- _inheritsLoose(CSSMathValue, _CSSNumericValue2);
2486
- function CSSMathValue() {
2487
- return _CSSNumericValue2.apply(this, arguments) || this;
2488
- }
2489
- var _proto4 = CSSMathValue.prototype;
2490
- // From CSSNumericValue
2491
- _proto4.isUnitValue = function isUnitValue() {
2492
- return false;
2493
- };
2494
- return CSSMathValue;
2495
- }(CSSNumericValue);
2496
- var CSSMathInvert = /*#__PURE__*/function (_CSSMathValue) {
2497
- _inheritsLoose(CSSMathInvert, _CSSMathValue);
2498
- CSSMathInvert.create = function create(value) {
2499
- var type = CSSNumericValueType.negateExponents(value.type_);
2500
- return new CSSMathInvert(value, type);
2501
- };
2502
- function CSSMathInvert(value, type) {
2503
- var _this4;
2504
- _this4 = _CSSMathValue.call(this, type) || this;
2505
- _this4.value = void 0;
2506
- _this4.operator = 'invert';
2507
- _this4.value = value;
2508
- return _this4;
2509
- }
2510
- var _proto5 = CSSMathInvert.prototype;
2511
- _proto5.clone = function clone() {
2512
- return new CSSMathInvert(this.value, this.type_);
2513
- };
2514
- _proto5.getType = function getType() {
2515
- return CSSStyleValueType.kInvertType;
2516
- };
2517
- _proto5.equals = function equals(other) {
2518
- if (other.getType() !== CSSStyleValueType.kInvertType) {
2519
- return false;
2520
- }
2521
- // We can safely cast here as we know 'other' has the same type as us.
2522
- var other_invert = other;
2523
- return this.value.equals(other_invert.value);
2524
- };
2525
- _proto5.sumValue = function sumValue() {
2526
- var sum = this.value.sumValue();
2527
- if (sum.length === 0 || sum.length !== 1 || sum[0].value === 0) {
2528
- return null;
2529
- }
2530
- Object.keys(sum[0].units).forEach(function (key) {
2531
- sum[0].units[key] *= -1;
2532
- });
2533
- sum[0].value = 1.0 / sum[0].value;
2534
- return sum;
2535
- }
2536
- // toCalcExpressionNode(): CSSMathExpressionNode {
2537
- // const right_side = this.value.toCalcExpressionNode();
2538
- // if (!right_side) {
2539
- // return null;
2540
- // }
2541
- // // return CSSMathExpressionOperation::CreateArithmeticOperation(
2542
- // // CSSMathExpressionNumericLiteral::Create(
2543
- // // 1, UnitType.kNumber),
2544
- // // right_side, CSSMathOperator.kDivide);
2545
- // return null;
2546
- // }
2547
- ;
2548
- _proto5.buildCSSText = function buildCSSText(nested, paren_less, result) {
2549
- if (paren_less == ParenLess.kNo) {
2550
- result += nested === Nested.kYes ? '(' : 'calc(';
2551
- }
2552
- result += '1 / ';
2553
- result = this.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2554
- if (paren_less === ParenLess.kNo) {
2555
- result += ')';
2556
- }
2557
- return result;
2558
- };
2559
- return CSSMathInvert;
2560
- }(CSSMathValue);
2561
- var CSSMathNegate = /*#__PURE__*/function (_CSSMathValue2) {
2562
- _inheritsLoose(CSSMathNegate, _CSSMathValue2);
2563
- CSSMathNegate.create = function create(value) {
2564
- return new CSSMathNegate(value, value.type_);
2565
- };
2566
- function CSSMathNegate(value, type) {
2567
- var _this5;
2568
- _this5 = _CSSMathValue2.call(this, type) || this;
2569
- _this5.value = void 0;
2570
- _this5.operator = 'negate';
2571
- _this5.value = value;
2572
- return _this5;
2573
- }
2574
- var _proto6 = CSSMathNegate.prototype;
2575
- _proto6.clone = function clone() {
2576
- return new CSSMathNegate(this.value, this.type_);
2577
- };
2578
- _proto6.getType = function getType() {
2579
- return CSSStyleValueType.kNegateType;
2580
- };
2581
- _proto6.equals = function equals(other) {
2582
- if (other.getType() !== CSSStyleValueType.kNegateType) {
2583
- return false;
2584
- }
2585
- var other_invert = other;
2586
- return this.value.equals(other_invert.value);
2587
- };
2588
- _proto6.sumValue = function sumValue() {
2589
- var sum = this.value.sumValue();
2590
- if (sum.length === 0) {
2591
- return null;
2592
- }
2593
- sum.forEach(function (term) {
2594
- term.value *= -1;
2595
- });
2596
- return sum;
2597
- }
2598
- // toCalcExpressionNode(): CSSMathExpressionNode {
2599
- // const right_side = this.value.toCalcExpressionNode();
2600
- // if (!right_side) {
2601
- // return null;
2602
- // }
2603
- // // return CSSMathExpressionOperation::CreateArithmeticOperationSimplified(
2604
- // // CSSMathExpressionNumericLiteral::Create(
2605
- // // -1, CSSPrimitiveValue::UnitType::kNumber),
2606
- // // right_side, CSSMathOperator::kMultiply);
2607
- // }
2608
- ;
2609
- _proto6.buildCSSText = function buildCSSText(nested, paren_less, result) {
2610
- if (paren_less == ParenLess.kNo) {
2611
- result += nested === Nested.kYes ? '(' : 'calc(';
2612
- }
2613
- result += '-';
2614
- result = this.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2615
- if (paren_less === ParenLess.kNo) {
2616
- result += ')';
2617
- }
2618
- return result;
2619
- };
2620
- return CSSMathNegate;
2621
- }(CSSMathValue);
2622
- function typeCheck(values, op, error) {
2623
- error = false;
2624
- var final_type = values[0].type_;
2625
- for (var i = 1; i < values.length; i++) {
2626
- final_type = op(final_type, values[i].type_, error);
2627
- if (error) return final_type;
2628
- }
2629
- return final_type;
2630
- }
2631
- // Represents an arithmetic operation with one or more CSSNumericValues.
2632
- var CSSMathVariadic = /*#__PURE__*/function (_CSSMathValue3) {
2633
- _inheritsLoose(CSSMathVariadic, _CSSMathValue3);
2634
- function CSSMathVariadic(values, type) {
2635
- var _this6;
2636
- _this6 = _CSSMathValue3.call(this, type) || this;
2637
- _this6.values = void 0;
2638
- _this6.values = values;
2639
- return _this6;
2640
- }
2641
- var _proto7 = CSSMathVariadic.prototype;
2642
- _proto7.numericValues = function numericValues() {
2643
- return this.values;
2644
- };
2645
- _proto7.equals = function equals(other) {
2646
- if (this.getType() !== other.getType()) {
2647
- return false;
2648
- }
2649
- return this.values.every(function (value, i) {
2650
- return value.equals(other.values[i]);
2651
- });
2652
- };
2653
- return CSSMathVariadic;
2654
- }(CSSMathValue);
2655
- // Represents the minimum of one or more CSSNumericValues.
2656
- // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
2657
- var CSSMathMin = /*#__PURE__*/function (_CSSMathVariadic) {
2658
- _inheritsLoose(CSSMathMin, _CSSMathVariadic);
2659
- function CSSMathMin() {
2660
- var _this7;
2661
- for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
2662
- args[_key9] = arguments[_key9];
2663
- }
2664
- _this7 = _CSSMathVariadic.call.apply(_CSSMathVariadic, [this].concat(args)) || this;
2665
- _this7.operator = 'min';
2666
- return _this7;
2667
- }
2668
- CSSMathMin.create = function create(values) {
2669
- var error = false;
2670
- var final_type = typeCheck(values, CSSNumericValueType.add, error);
2671
- return new CSSMathMin(values, final_type);
2672
- };
2673
- var _proto8 = CSSMathMin.prototype;
2674
- _proto8.clone = function clone() {
2675
- return new CSSMathMin(this.values, this.type_);
2676
- };
2677
- _proto8.getType = function getType() {
2678
- return CSSStyleValueType.kMinType;
2679
- };
2680
- _proto8.sumValue = function sumValue() {
2681
- var cur_min = this.numericValues()[0].sumValue();
2682
- if (!cur_min.length) {
2683
- return null;
2684
- }
2685
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.numericValues()), _step2; !(_step2 = _iterator2()).done;) {
2686
- var value = _step2.value;
2687
- var child_sum = value.sumValue();
2688
- if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_min[0].units)) {
2689
- return null;
2690
- }
2691
- if (child_sum[0].value < cur_min[0].value) {
2692
- cur_min = child_sum;
2693
- }
2694
- }
2695
- return cur_min;
2696
- }
2697
- // toCalcExpressionNode() {
2698
- // const operands: CSSMathExpressionOperation[] = [];
2699
- // for (const value of this.numericValues()) {
2700
- // const operand = value.toCalcExpressionNode();
2701
- // if (!operand) {
2702
- // continue;
2703
- // }
2704
- // operands.push(operand as CSSMathExpressionOperation);
2705
- // }
2706
- // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMin);
2707
- // }
2708
- ;
2709
- _proto8.buildCSSText = function buildCSSText(nested, paren_less, result) {
2710
- result += 'min(';
2711
- var first_iteration = true;
2712
- for (var _iterator3 = _createForOfIteratorHelperLoose(this.numericValues()), _step3; !(_step3 = _iterator3()).done;) {
2713
- var value = _step3.value;
2714
- if (!first_iteration) result += ', ';
2715
- first_iteration = false;
2716
- result = value.buildCSSText(Nested.kYes, ParenLess.kYes, result);
2717
- }
2718
- result += ')';
2719
- return result;
2720
- };
2721
- return CSSMathMin;
2722
- }(CSSMathVariadic);
2723
- // Represents the maximum of one or more CSSNumericValues.
2724
- // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
2725
- var CSSMathMax = /*#__PURE__*/function (_CSSMathVariadic2) {
2726
- _inheritsLoose(CSSMathMax, _CSSMathVariadic2);
2727
- function CSSMathMax() {
2728
- var _this8;
2729
- for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
2730
- args[_key10] = arguments[_key10];
2731
- }
2732
- _this8 = _CSSMathVariadic2.call.apply(_CSSMathVariadic2, [this].concat(args)) || this;
2733
- _this8.operator = 'max';
2734
- return _this8;
2735
- }
2736
- CSSMathMax.create = function create(values) {
2737
- var error = false;
2738
- var final_type = typeCheck(values, CSSNumericValueType.add, error);
2739
- return new CSSMathMax(values, final_type);
2740
- };
2741
- var _proto9 = CSSMathMax.prototype;
2742
- _proto9.clone = function clone() {
2743
- return new CSSMathMax(this.values, this.type_);
2744
- };
2745
- _proto9.getType = function getType() {
2746
- return CSSStyleValueType.kMaxType;
2747
- };
2748
- _proto9.sumValue = function sumValue() {
2749
- var cur_max = this.numericValues()[0].sumValue();
2750
- if (!cur_max.length) {
2751
- return null;
2752
- }
2753
- for (var _iterator4 = _createForOfIteratorHelperLoose(this.numericValues()), _step4; !(_step4 = _iterator4()).done;) {
2754
- var value = _step4.value;
2755
- var child_sum = value.sumValue();
2756
- if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_max[0].units)) {
2757
- return null;
2758
- }
2759
- if (child_sum[0].value < cur_max[0].value) {
2760
- cur_max = child_sum;
2761
- }
2762
- }
2763
- return cur_max;
2764
- }
2765
- // toCalcExpressionNode() {
2766
- // const operands: CSSMathExpressionOperation[] = [];
2767
- // for (const value of this.numericValues()) {
2768
- // const operand = value.toCalcExpressionNode();
2769
- // if (!operand) {
2770
- // continue;
2771
- // }
2772
- // operands.push(operand as CSSMathExpressionOperation);
2773
- // }
2774
- // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMax);
2775
- // }
2776
- ;
2777
- _proto9.buildCSSText = function buildCSSText(nested, paren_less, result) {
2778
- result += 'max(';
2779
- var first_iteration = true;
2780
- for (var _iterator5 = _createForOfIteratorHelperLoose(this.numericValues()), _step5; !(_step5 = _iterator5()).done;) {
2781
- var value = _step5.value;
2782
- if (!first_iteration) result += ', ';
2783
- first_iteration = false;
2784
- result = value.buildCSSText(Nested.kYes, ParenLess.kYes, result);
2785
- }
2786
- result += ')';
2787
- return result;
2788
- };
2789
- return CSSMathMax;
2790
- }(CSSMathVariadic);
2791
- /**
2792
- * Represents the sum of one or more CSSNumericValues.
2793
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
2794
- */
2795
- var CSSMathSum = /*#__PURE__*/function (_CSSMathVariadic3) {
2796
- _inheritsLoose(CSSMathSum, _CSSMathVariadic3);
2797
- function CSSMathSum() {
2798
- var _this9;
2799
- for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
2800
- args[_key11] = arguments[_key11];
2801
- }
2802
- _this9 = _CSSMathVariadic3.call.apply(_CSSMathVariadic3, [this].concat(args)) || this;
2803
- _this9.operator = 'sum';
2804
- return _this9;
2805
- }
2806
- CSSMathSum.create = function create(values) {
2807
- var error = false;
2808
- var finalType = typeCheck(values, CSSNumericValueType.add, error);
2809
- return new CSSMathSum(values, finalType);
2810
- };
2811
- CSSMathSum.numericTypeFromUnitMap = function numericTypeFromUnitMap(units) {
2812
- var type = new CSSNumericValueType();
2813
- Object.keys(units).forEach(function (key) {
2814
- var exp = units[key];
2815
- var error = false;
2816
- type = CSSNumericValueType.multiply(type, new CSSNumericValueType(Number(key), exp), error);
2817
- DCHECK(!error);
2818
- });
2819
- return type;
2820
- };
2821
- CSSMathSum.canCreateNumericTypeFromSumValue = function canCreateNumericTypeFromSumValue(sum) {
2822
- var _this10 = this;
2823
- DCHECK(!!sum.length);
2824
- var first_type = this.numericTypeFromUnitMap(sum[0].units);
2825
- return sum.every(function (term) {
2826
- var error = false;
2827
- CSSNumericValueType.add(first_type, _this10.numericTypeFromUnitMap(term.units), error);
2828
- return !error;
2829
- });
2830
- };
2831
- var _proto10 = CSSMathSum.prototype;
2832
- _proto10.clone = function clone() {
2833
- return new CSSMathSum(this.values, this.type_);
2834
- };
2835
- _proto10.getType = function getType() {
2836
- return CSSStyleValueType.kSumType;
2837
- }
2838
- // toCalcExpressionNode() {
2839
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
2840
- // }
2841
- ;
2842
- _proto10.sumValue = function sumValue() {
2843
- var sum = [];
2844
- this.numericValues().forEach(function (value) {
2845
- var child_sum = value.sumValue();
2846
- if (!child_sum.length) {
2847
- return null;
2848
- }
2849
- child_sum.forEach(function (term) {
2850
- var index = sum.findIndex(function (s) {
2851
- return JSON.stringify(s.units) === JSON.stringify(term.units);
2852
- });
2853
- if (index === -1) {
2854
- sum.push(_extends({}, term));
2855
- } else {
2856
- sum[index].value += term.value;
2857
- }
2858
- });
2859
- });
2860
- if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
2861
- return sum;
2862
- };
2863
- _proto10.buildCSSText = function buildCSSText(nested, paren_less, result) {
2864
- if (paren_less == ParenLess.kNo) {
2865
- result += nested === Nested.kYes ? '(' : 'calc(';
2866
- }
2867
- var values = this.numericValues();
2868
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
2869
- for (var i = 1; i < values.length; i++) {
2870
- var arg = values[i];
2871
- if (arg.getType() === CSSStyleValueType.kNegateType) {
2872
- result += ' - ';
2873
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2874
- } else {
2875
- result += ' + ';
2876
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2877
- }
2878
- }
2879
- if (paren_less === ParenLess.kNo) {
2880
- result += ')';
2881
- }
2882
- return result;
2883
- };
2884
- return CSSMathSum;
2885
- }(CSSMathVariadic);
2886
- /**
2887
- * Represents the product of one or more CSSNumericValues.
2888
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathproduct
2889
- */
2890
- var CSSMathProduct = /*#__PURE__*/function (_CSSMathVariadic4) {
2891
- _inheritsLoose(CSSMathProduct, _CSSMathVariadic4);
2892
- function CSSMathProduct() {
2893
- var _this11;
2894
- for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
2895
- args[_key12] = arguments[_key12];
2896
- }
2897
- _this11 = _CSSMathVariadic4.call.apply(_CSSMathVariadic4, [this].concat(args)) || this;
2898
- _this11.operator = 'product';
2899
- return _this11;
2900
- }
2901
- CSSMathProduct.create = function create(values) {
2902
- var error = false;
2903
- var finalType = typeCheck(values, CSSNumericValueType.multiply, error);
2904
- return new CSSMathProduct(values, finalType);
2905
- };
2906
- CSSMathProduct.multiplyUnitMaps = function multiplyUnitMaps(a, b) {
2907
- Object.keys(b).forEach(function (key) {
2908
- DCHECK_NE(b[key].value, 0);
2909
- var old_value = key in a ? a[key].value : 0;
2910
- if (old_value + b[key].value === 0) {
2911
- delete a[key];
2912
- } else {
2913
- a[key] = old_value + b[key].value;
2914
- }
2915
- });
2916
- return a;
2917
- };
2918
- var _proto11 = CSSMathProduct.prototype;
2919
- _proto11.clone = function clone() {
2920
- return new CSSMathProduct(this.values, this.type_);
2921
- };
2922
- _proto11.getType = function getType() {
2923
- return CSSStyleValueType.kProductType;
2924
- }
2925
- // toCalcExpressionNode() {
2926
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kMultiply);
2927
- // }
2928
- ;
2929
- _proto11.sumValue = function sumValue() {
2930
- var sum = [{
2931
- value: 1,
2932
- units: {}
2933
- }];
2934
- this.numericValues().forEach(function (value) {
2935
- var child_sum = value.sumValue();
2936
- if (!child_sum.length) {
2937
- return null;
2938
- }
2939
- var new_sum = [];
2940
- sum.forEach(function (a) {
2941
- child_sum.forEach(function (b) {
2942
- new_sum.push({
2943
- value: a.value * b.value,
2944
- units: CSSMathProduct.multiplyUnitMaps(a.units, b.units)
2945
- });
2946
- });
2947
- });
2948
- sum = new_sum;
2949
- });
2950
- return sum;
2951
- };
2952
- _proto11.buildCSSText = function buildCSSText(nested, paren_less, result) {
2953
- if (paren_less == ParenLess.kNo) {
2954
- result += nested === Nested.kYes ? '(' : 'calc(';
2955
- }
2956
- var values = this.numericValues();
2957
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
2958
- for (var i = 1; i < values.length; i++) {
2959
- var arg = values[i];
2960
- if (arg.getType() === CSSStyleValueType.kInvertType) {
2961
- result += ' / ';
2962
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2963
- } else {
2964
- result += ' * ';
2965
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
2966
- }
2967
- }
2968
- if (paren_less === ParenLess.kNo) {
2969
- result += ')';
2970
- }
2971
- return result;
2972
- };
2973
- return CSSMathProduct;
2974
- }(CSSMathVariadic);
1506
+ }(CSSStyleValue);
2975
1507
  var Opx = new CSSUnitValue(0, 'px');
2976
1508
  var Lpx = new CSSUnitValue(1, 'px');
2977
1509
  var Odeg = new CSSUnitValue(0, 'deg');
@@ -3153,17 +1685,20 @@ var getOrCreateRGBA = memoize(function (r, g, b, a) {
3153
1685
  }, function (r, g, b, a) {
3154
1686
  return "rgba(" + r + "," + g + "," + b + "," + a + ")";
3155
1687
  });
3156
- var getOrCreateUnitValue = memoize(function (value, unitOrName) {
1688
+ // export const getOrCreateUnitValue = memoize(
1689
+ // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
1690
+ // return new CSSUnitValue(value, unitOrName);
1691
+ // },
1692
+ // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
1693
+ // return `${value}${unitOrName}`;
1694
+ // },
1695
+ // );
1696
+ var getOrCreateUnitValue = function getOrCreateUnitValue(value, unitOrName) {
3157
1697
  if (unitOrName === void 0) {
3158
1698
  unitOrName = UnitType.kNumber;
3159
1699
  }
3160
1700
  return new CSSUnitValue(value, unitOrName);
3161
- }, function (value, unitOrName) {
3162
- if (unitOrName === void 0) {
3163
- unitOrName = UnitType.kNumber;
3164
- }
3165
- return "" + value + unitOrName;
3166
- });
1701
+ };
3167
1702
 
3168
1703
  var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
3169
1704
  var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
@@ -3286,7 +1821,7 @@ var parseGradient = memoize(function (colorStr) {
3286
1821
  var steps = colorStops.map(function (colorStop) {
3287
1822
  // TODO: only support % for now, should calc percentage of axis length when using px/em
3288
1823
  return {
3289
- offset: getOrCreateUnitValue(colorStop.length.value, '%'),
1824
+ offset: getOrCreateUnitValue(Number(colorStop.length.value), '%'),
3290
1825
  color: colorStopToString(colorStop)
3291
1826
  };
3292
1827
  });
@@ -3481,6 +2016,22 @@ function mergeColors(left, right) {
3481
2016
  }];
3482
2017
  }
3483
2018
 
2019
+ var Shape;
2020
+ (function (Shape) {
2021
+ Shape["GROUP"] = "g";
2022
+ Shape["CIRCLE"] = "circle";
2023
+ Shape["ELLIPSE"] = "ellipse";
2024
+ Shape["IMAGE"] = "image";
2025
+ Shape["RECT"] = "rect";
2026
+ Shape["LINE"] = "line";
2027
+ Shape["POLYLINE"] = "polyline";
2028
+ Shape["POLYGON"] = "polygon";
2029
+ Shape["TEXT"] = "text";
2030
+ Shape["PATH"] = "path";
2031
+ Shape["HTML"] = "html";
2032
+ Shape["MESH"] = "mesh";
2033
+ })(Shape || (Shape = {}));
2034
+
3484
2035
  function parseDimension(unitRegExp, string) {
3485
2036
  if (isNil(string)) {
3486
2037
  return getOrCreateUnitValue(0, 'px');
@@ -3524,12 +2075,20 @@ var parserPercentage = memoize(function (css) {
3524
2075
  *
3525
2076
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length-percentage
3526
2077
  */
3527
- var parseLengthOrPercentage = memoize(function (css) {
2078
+ // export const parseLengthOrPercentage = memoize((css: string): CSSUnitValue => {
2079
+ // if (isNumber(css) || isFinite(Number(css))) {
2080
+ // return getOrCreateUnitValue(Number(css), 'px');
2081
+ // }
2082
+ // return parseDimension(new RegExp('px|%|em|rem', 'g'), css) as CSSUnitValue;
2083
+ // });
2084
+ var parseLengthOrPercentage = function parseLengthOrPercentage(css) {
3528
2085
  if (isNumber(css) || isFinite(Number(css))) {
3529
2086
  return getOrCreateUnitValue(Number(css), 'px');
2087
+ // return Number(css);
3530
2088
  }
2089
+
3531
2090
  return parseDimension(new RegExp('px|%|em|rem', 'g'), css);
3532
- });
2091
+ };
3533
2092
  var parseAngle = memoize(function (css) {
3534
2093
  return parseDimension(new RegExp('deg|rad|grad|turn', 'g'), css);
3535
2094
  });
@@ -4460,6 +3019,9 @@ var CSSPropertyLengthOrPercentage = /*#__PURE__*/function () {
4460
3019
  * CSS.percent(50) -> CSS.px(0.5 * parent.width)
4461
3020
  */
4462
3021
  _proto.calculator = function calculator(name, oldParsed, computed, object, registry) {
3022
+ if (isNumber(computed)) {
3023
+ return computed;
3024
+ }
4463
3025
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
4464
3026
  if (computed.unit === UnitType.kPercentage) {
4465
3027
  // TODO: merge dimensions
@@ -4956,6 +3518,30 @@ var CustomElementRegistry = /*#__PURE__*/function () {
4956
3518
  return CustomElementRegistry;
4957
3519
  }();
4958
3520
 
3521
+ var Point = /*#__PURE__*/function () {
3522
+ function Point(x, y) {
3523
+ if (x === void 0) {
3524
+ x = 0;
3525
+ }
3526
+ if (y === void 0) {
3527
+ y = 0;
3528
+ }
3529
+ this.x = 0;
3530
+ this.y = 0;
3531
+ this.x = x;
3532
+ this.y = y;
3533
+ }
3534
+ var _proto = Point.prototype;
3535
+ _proto.clone = function clone() {
3536
+ return new Point(this.x, this.y);
3537
+ };
3538
+ _proto.copyFrom = function copyFrom(p) {
3539
+ this.x = p.x;
3540
+ this.y = p.y;
3541
+ };
3542
+ return Point;
3543
+ }();
3544
+
4959
3545
  function isFederatedEvent(value) {
4960
3546
  return !!value.type;
4961
3547
  }
@@ -6053,16 +4639,26 @@ var Element = /*#__PURE__*/function (_Node) {
6053
4639
  dirtyFlag: false,
6054
4640
  localDirtyFlag: false,
6055
4641
  frozen: false,
6056
- localPosition: vec3.fromValues(0, 0, 0),
6057
- localRotation: quat$1.fromValues(0, 0, 0, 1),
6058
- localScale: vec3.fromValues(1, 1, 1),
4642
+ // localPosition: vec3.fromValues(0, 0, 0),
4643
+ // localRotation: quat.fromValues(0, 0, 0, 1),
4644
+ // localScale: vec3.fromValues(1, 1, 1),
4645
+ // localTransform: mat4.create(),
4646
+ // localSkew: vec2.fromValues(0, 0),
4647
+ // position: vec3.fromValues(0, 0, 0),
4648
+ // rotation: quat.fromValues(0, 0, 0, 1),
4649
+ // scaling: vec3.fromValues(1, 1, 1),
4650
+ // worldTransform: mat4.create(),
4651
+ // origin: vec3.fromValues(0, 0, 0),
4652
+ localPosition: [0, 0, 0],
4653
+ localRotation: [0, 0, 0, 1],
4654
+ localScale: [1, 1, 1],
6059
4655
  localTransform: mat4.create(),
6060
- localSkew: vec2.fromValues(0, 0),
6061
- position: vec3.fromValues(0, 0, 0),
6062
- rotation: quat$1.fromValues(0, 0, 0, 1),
6063
- scaling: vec3.fromValues(1, 1, 1),
4656
+ localSkew: [0, 0],
4657
+ position: [0, 0, 0],
4658
+ rotation: [0, 0, 0, 1],
4659
+ scaling: [1, 1, 1],
6064
4660
  worldTransform: mat4.create(),
6065
- origin: vec3.fromValues(0, 0, 0)
4661
+ origin: [0, 0, 0]
6066
4662
  };
6067
4663
  _this.sortable = {
6068
4664
  dirty: false,
@@ -6779,6 +5375,20 @@ var DEFAULT_PARSED_STYLE_PROPS = {
6779
5375
  filter: [],
6780
5376
  shadowType: 'outer'
6781
5377
  };
5378
+ var DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = _extends({}, DEFAULT_PARSED_STYLE_PROPS, {
5379
+ opacity: 1,
5380
+ fillOpacity: 1,
5381
+ strokeOpacity: 1,
5382
+ visibility: 'visible',
5383
+ pointerEvents: 'auto',
5384
+ lineWidth: 1,
5385
+ lineCap: 'butt',
5386
+ lineJoin: 'miter',
5387
+ increasedLineWidthForHitTesting: 0,
5388
+ fillRule: 'nonzero'
5389
+ // TODO: transformOrigin
5390
+ });
5391
+
6782
5392
  var INHERITABLE_BASE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting'];
6783
5393
  var INHERITABLE_STYLE_PROPS = [].concat(INHERITABLE_BASE_STYLE_PROPS, ['fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']);
6784
5394
  /**
@@ -6833,7 +5443,13 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
6833
5443
  }
6834
5444
  _this.nodeName = _this.config.type || Shape.GROUP;
6835
5445
  // compatible with G 3.0
6836
- _this.config.style = _extends({}, _this.config.style, _this.config.attrs);
5446
+ _this.config.style = _this.config.style || _this.config.attrs || {};
5447
+ Object.assign(_this.config.style, _this.config.attrs);
5448
+ // this.config.style = {
5449
+ // // ...DEFAULT_STYLE_PROPS,
5450
+ // ...this.config.style,
5451
+ // ...this.config.attrs,
5452
+ // };
6837
5453
  if (_this.config.visible != null) {
6838
5454
  _this.config.style.visibility = _this.config.visible === false ? 'hidden' : 'visible';
6839
5455
  }
@@ -6841,8 +5457,10 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
6841
5457
  _this.config.style.pointerEvents = _this.config.interactive === false ? 'none' : 'auto';
6842
5458
  }
6843
5459
  // merge parsed value
6844
- Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
6845
- Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
5460
+ Object.assign(_this.parsedStyle, runtime.enableCSSParsing ? DEFAULT_PARSED_STYLE_PROPS : DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED, _this.config.initialParsedStyle);
5461
+ if (runtime.enableCSSParsing) {
5462
+ Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
5463
+ }
6846
5464
  // start to process attributes
6847
5465
  _this.initAttributes(_this.config.style);
6848
5466
  _this.style = new Proxy(
@@ -6937,16 +5555,21 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
6937
5555
  attributes = {};
6938
5556
  }
6939
5557
  var renderable = this.renderable;
6940
- // account for FCP, process properties as less as possible
6941
- runtime.styleValueRegistry.processProperties(this, attributes, {
6942
- forceUpdateGeometry: true,
6943
- usedAttributes: INHERITABLE_STYLE_PROPS
5558
+ var options = {
5559
+ forceUpdateGeometry: true
6944
5560
  // usedAttributes:
6945
5561
  // // only Group / Text should account for text relative props
6946
5562
  // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT
6947
5563
  // ? INHERITABLE_STYLE_PROPS
6948
5564
  // : INHERITABLE_BASE_STYLE_PROPS,
6949
- });
5565
+ };
5566
+
5567
+ if (runtime.enableCSSParsing) {
5568
+ // @ts-ignore
5569
+ options.usedAttributes = INHERITABLE_STYLE_PROPS;
5570
+ }
5571
+ // account for FCP, process properties as less as possible
5572
+ runtime.styleValueRegistry.processProperties(this, attributes, options);
6950
5573
  // redraw at next frame
6951
5574
  renderable.dirty = true;
6952
5575
  };
@@ -7681,7 +6304,11 @@ var HTML = /*#__PURE__*/function (_DisplayObject) {
7681
6304
  var minX = clientRect.left - canvasRect.left;
7682
6305
  var minY = clientRect.top - canvasRect.top;
7683
6306
  var aabb = new AABB();
7684
- aabb.setMinMax(vec3.fromValues(minX, minY, 0), vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0));
6307
+ // aabb.setMinMax(
6308
+ // vec3.fromValues(minX, minY, 0),
6309
+ // vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0),
6310
+ // );
6311
+ aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
7685
6312
  return aabb;
7686
6313
  }
7687
6314
  return null;
@@ -8426,6 +7053,42 @@ var Text = /*#__PURE__*/function (_DisplayObject) {
8426
7053
  return Text;
8427
7054
  }(DisplayObject);
8428
7055
 
7056
+ function copyVec3(a, b) {
7057
+ a[0] = b[0];
7058
+ a[1] = b[1];
7059
+ a[2] = b[2];
7060
+ return a;
7061
+ }
7062
+ function subVec3(o, a, b) {
7063
+ o[0] = a[0] - b[0];
7064
+ o[1] = a[1] - b[1];
7065
+ o[2] = a[2] - b[2];
7066
+ return o;
7067
+ }
7068
+ function addVec3(o, a, b) {
7069
+ o[0] = a[0] + b[0];
7070
+ o[1] = a[1] + b[1];
7071
+ o[2] = a[2] + b[2];
7072
+ return o;
7073
+ }
7074
+ function scaleVec3(o, a, b) {
7075
+ o[0] = a[0] * b;
7076
+ o[1] = a[1] * b;
7077
+ o[2] = a[2] * b;
7078
+ return o;
7079
+ }
7080
+ function maxVec3(o, a, b) {
7081
+ o[0] = Math.max(a[0], b[0]);
7082
+ o[1] = Math.max(a[1], b[1]);
7083
+ o[2] = Math.max(a[2], b[2]);
7084
+ return o;
7085
+ }
7086
+ function minVec3(o, a, b) {
7087
+ o[0] = Math.min(a[0], b[0]);
7088
+ o[1] = Math.min(a[1], b[1]);
7089
+ o[2] = Math.min(a[2], b[2]);
7090
+ return o;
7091
+ }
8429
7092
  function getAngle(angle) {
8430
7093
  if (angle === undefined) {
8431
7094
  return 0;
@@ -8795,16 +7458,16 @@ function parsedTransformToMat4(transform, object) {
8795
7458
  object.translateLocal(_newTranslation4[0].value, _newTranslation4[1].value, _newTranslation4[2].value);
8796
7459
  } else if (t === 'rotate') {
8797
7460
  var newAngles = d || [Odeg];
8798
- object.rotateLocal(0, 0, newAngles[0].value);
7461
+ object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
8799
7462
  } else if (t === 'rotatex') {
8800
7463
  var _newAngles = d || [Odeg];
8801
- object.rotateLocal(_newAngles[0].value, 0, 0);
7464
+ object.rotateLocal(convertAngleUnit(_newAngles[0]), 0, 0);
8802
7465
  } else if (t === 'rotatey') {
8803
7466
  var _newAngles2 = d || [Odeg];
8804
- object.rotateLocal(0, _newAngles2[0].value, 0);
7467
+ object.rotateLocal(0, convertAngleUnit(_newAngles2[0]), 0);
8805
7468
  } else if (t === 'rotatez') {
8806
7469
  var _newAngles3 = d || [Odeg];
8807
- object.rotateLocal(0, 0, _newAngles3[0].value);
7470
+ object.rotateLocal(0, 0, convertAngleUnit(_newAngles3[0]));
8808
7471
  } else if (t === 'rotate3d') ; else if (t === 'skew') {
8809
7472
  var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
8810
7473
  return s.value;
@@ -10843,90 +9506,484 @@ function toFontString(attributes) {
10843
9506
  if (!stringRegExp.test(_fontFamily) && genericFontFamilies.indexOf(_fontFamily) < 0) {
10844
9507
  _fontFamily = "\"" + _fontFamily + "\"";
10845
9508
  }
10846
- fontFamilies[i] = _fontFamily;
9509
+ fontFamilies[i] = _fontFamily;
9510
+ }
9511
+ return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
9512
+ }
9513
+
9514
+ /**
9515
+ * Thanks for following contributor of codes
9516
+ * https://gist.github.com/1866474
9517
+ * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
9518
+ * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
9519
+ * https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/requestAnimationFrame/polyfill.js
9520
+ **/
9521
+ var uId = 1;
9522
+ var uniqueId = function uniqueId() {
9523
+ return uId++;
9524
+ };
9525
+ // We use `self` instead of `window` for `WebWorker` support.
9526
+ var root = typeof self === 'object' && self.self == self ? self :
9527
+ // @ts-ignore
9528
+ typeof global === 'object' && global.global == global ?
9529
+ // @ts-ignore
9530
+ global : {};
9531
+ var nowOffset = Date.now();
9532
+ // use performance api if exist, otherwise use Date.now.
9533
+ // Date.now polyfill required.
9534
+ var pnow = function pnow() {
9535
+ if (root.performance && typeof root.performance.now === 'function') {
9536
+ return root.performance.now();
9537
+ }
9538
+ // fallback
9539
+ return Date.now() - nowOffset;
9540
+ };
9541
+ var reservedCBs = {};
9542
+ var lastTime = Date.now();
9543
+ var polyfillRaf = function polyfillRaf(callback) {
9544
+ if (typeof callback !== 'function') {
9545
+ throw new TypeError(callback + ' is not a function');
9546
+ }
9547
+ var currentTime = Date.now();
9548
+ var gap = currentTime - lastTime;
9549
+ var delay = gap > 16 ? 0 : 16 - gap;
9550
+ var id = uniqueId();
9551
+ reservedCBs[id] = callback;
9552
+ // keys(reservedCBs).length > 1 의미는 이미 setTimeout 이 걸려있는 경우.
9553
+ // 함께 callback 이 실행될 수 있게 reservedCBs 에만 추가해주고 return
9554
+ if (Object.keys(reservedCBs).length > 1) return id;
9555
+ setTimeout(function () {
9556
+ lastTime = currentTime;
9557
+ var copied = reservedCBs;
9558
+ reservedCBs = {};
9559
+ Object.keys(copied).forEach(function (key) {
9560
+ return copied[key](pnow());
9561
+ });
9562
+ }, delay);
9563
+ return id;
9564
+ };
9565
+ var polyfillCaf = function polyfillCaf(id) {
9566
+ delete reservedCBs[id];
9567
+ };
9568
+ var vendorPrefixes = ['', 'webkit', 'moz', 'ms', 'o'];
9569
+ var getRequestAnimationFrame = function getRequestAnimationFrame(vp) {
9570
+ if (typeof vp !== 'string') return polyfillRaf;
9571
+ if (vp === '') return root['requestAnimationFrame'];
9572
+ return root[vp + 'RequestAnimationFrame'];
9573
+ };
9574
+ var getCancelAnimationFrame = function getCancelAnimationFrame(vp) {
9575
+ if (typeof vp !== 'string') return polyfillCaf;
9576
+ if (vp === '') return root['cancelAnimationFrame'];
9577
+ return root[vp + 'CancelAnimationFrame'] || root[vp + 'CancelRequestAnimationFrame'];
9578
+ };
9579
+ var find = function find(arr, predicate) {
9580
+ var i = 0;
9581
+ while (arr[i] !== void 0) {
9582
+ if (predicate(arr[i])) return arr[i];
9583
+ i = i + 1;
9584
+ }
9585
+ };
9586
+ var vp = find(vendorPrefixes, function (vp) {
9587
+ return !!getRequestAnimationFrame(vp);
9588
+ });
9589
+ var raf = getRequestAnimationFrame(vp);
9590
+ var caf = getCancelAnimationFrame(vp);
9591
+ root.requestAnimationFrame = raf;
9592
+ root.cancelAnimationFrame = caf;
9593
+
9594
+ /**
9595
+ * Axis-Aligned Bounding Box
9596
+ * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
9597
+ * @see https://github.com/antvis/GWebGPUEngine/issues/3
9598
+ */
9599
+ var AABB = /*#__PURE__*/function () {
9600
+ AABB.isEmpty = function isEmpty(aabb) {
9601
+ return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
9602
+ };
9603
+ // center: vec3 = vec3.create();
9604
+ // halfExtents: vec3 = vec3.create();
9605
+ // min: vec3 = vec3.create();
9606
+ // max: vec3 = vec3.create();
9607
+ function AABB(center, halfExtents) {
9608
+ if (center === void 0) {
9609
+ center = [0, 0, 0];
9610
+ }
9611
+ if (halfExtents === void 0) {
9612
+ halfExtents = [0, 0, 0];
9613
+ }
9614
+ this.center = [0, 0, 0];
9615
+ this.halfExtents = [0, 0, 0];
9616
+ this.min = [0, 0, 0];
9617
+ this.max = [0, 0, 0];
9618
+ this.update(center, halfExtents);
9619
+ }
9620
+ var _proto = AABB.prototype;
9621
+ _proto.update = function update(center, halfExtents) {
9622
+ copyVec3(this.center, center);
9623
+ copyVec3(this.halfExtents, halfExtents);
9624
+ subVec3(this.min, this.center, this.halfExtents);
9625
+ addVec3(this.max, this.center, this.halfExtents);
9626
+ // vec3.copy(this.center, center);
9627
+ // vec3.copy(this.halfExtents, halfExtents);
9628
+ // vec3.sub(this.min, this.center, this.halfExtents);
9629
+ // vec3.add(this.max, this.center, this.halfExtents);
9630
+ };
9631
+ _proto.setMinMax = function setMinMax(min, max) {
9632
+ // vec3.add(this.center, max, min);
9633
+ // vec3.scale(this.center, this.center, 0.5);
9634
+ // vec3.sub(this.halfExtents, max, min);
9635
+ // vec3.scale(this.halfExtents, this.halfExtents, 0.5);
9636
+ // vec3.copy(this.min, min);
9637
+ // vec3.copy(this.max, max);
9638
+ addVec3(this.center, max, min);
9639
+ scaleVec3(this.center, this.center, 0.5);
9640
+ subVec3(this.halfExtents, max, min);
9641
+ scaleVec3(this.halfExtents, this.halfExtents, 0.5);
9642
+ copyVec3(this.min, min);
9643
+ copyVec3(this.max, max);
9644
+ };
9645
+ _proto.getMin = function getMin() {
9646
+ return this.min;
9647
+ };
9648
+ _proto.getMax = function getMax() {
9649
+ return this.max;
9650
+ };
9651
+ _proto.add = function add(aabb) {
9652
+ if (AABB.isEmpty(aabb)) {
9653
+ return;
9654
+ }
9655
+ if (AABB.isEmpty(this)) {
9656
+ this.setMinMax(aabb.getMin(), aabb.getMax());
9657
+ return;
9658
+ }
9659
+ var tc = this.center;
9660
+ var tcx = tc[0];
9661
+ var tcy = tc[1];
9662
+ var tcz = tc[2];
9663
+ var th = this.halfExtents;
9664
+ var thx = th[0];
9665
+ var thy = th[1];
9666
+ var thz = th[2];
9667
+ var tminx = tcx - thx;
9668
+ var tmaxx = tcx + thx;
9669
+ var tminy = tcy - thy;
9670
+ var tmaxy = tcy + thy;
9671
+ var tminz = tcz - thz;
9672
+ var tmaxz = tcz + thz;
9673
+ var oc = aabb.center;
9674
+ var ocx = oc[0];
9675
+ var ocy = oc[1];
9676
+ var ocz = oc[2];
9677
+ var oh = aabb.halfExtents;
9678
+ var ohx = oh[0];
9679
+ var ohy = oh[1];
9680
+ var ohz = oh[2];
9681
+ var ominx = ocx - ohx;
9682
+ var omaxx = ocx + ohx;
9683
+ var ominy = ocy - ohy;
9684
+ var omaxy = ocy + ohy;
9685
+ var ominz = ocz - ohz;
9686
+ var omaxz = ocz + ohz;
9687
+ if (ominx < tminx) {
9688
+ tminx = ominx;
9689
+ }
9690
+ if (omaxx > tmaxx) {
9691
+ tmaxx = omaxx;
9692
+ }
9693
+ if (ominy < tminy) {
9694
+ tminy = ominy;
9695
+ }
9696
+ if (omaxy > tmaxy) {
9697
+ tmaxy = omaxy;
9698
+ }
9699
+ if (ominz < tminz) {
9700
+ tminz = ominz;
9701
+ }
9702
+ if (omaxz > tmaxz) {
9703
+ tmaxz = omaxz;
9704
+ }
9705
+ tc[0] = (tminx + tmaxx) * 0.5;
9706
+ tc[1] = (tminy + tmaxy) * 0.5;
9707
+ tc[2] = (tminz + tmaxz) * 0.5;
9708
+ th[0] = (tmaxx - tminx) * 0.5;
9709
+ th[1] = (tmaxy - tminy) * 0.5;
9710
+ th[2] = (tmaxz - tminz) * 0.5;
9711
+ this.min[0] = tminx;
9712
+ this.min[1] = tminy;
9713
+ this.min[2] = tminz;
9714
+ this.max[0] = tmaxx;
9715
+ this.max[1] = tmaxy;
9716
+ this.max[2] = tmaxz;
9717
+ };
9718
+ _proto.setFromTransformedAABB = function setFromTransformedAABB(aabb, m) {
9719
+ var bc = this.center;
9720
+ var br = this.halfExtents;
9721
+ var ac = aabb.center;
9722
+ var ar = aabb.halfExtents;
9723
+ var mx0 = m[0];
9724
+ var mx1 = m[4];
9725
+ var mx2 = m[8];
9726
+ var my0 = m[1];
9727
+ var my1 = m[5];
9728
+ var my2 = m[9];
9729
+ var mz0 = m[2];
9730
+ var mz1 = m[6];
9731
+ var mz2 = m[10];
9732
+ var mx0a = Math.abs(mx0);
9733
+ var mx1a = Math.abs(mx1);
9734
+ var mx2a = Math.abs(mx2);
9735
+ var my0a = Math.abs(my0);
9736
+ var my1a = Math.abs(my1);
9737
+ var my2a = Math.abs(my2);
9738
+ var mz0a = Math.abs(mz0);
9739
+ var mz1a = Math.abs(mz1);
9740
+ var mz2a = Math.abs(mz2);
9741
+ bc[0] = m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2];
9742
+ bc[1] = m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2];
9743
+ bc[2] = m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2];
9744
+ // vec3.set(
9745
+ // bc,
9746
+ // m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2],
9747
+ // m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2],
9748
+ // m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2],
9749
+ // );
9750
+ br[0] = mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2];
9751
+ br[1] = my0a * ar[0] + my1a * ar[1] + my2a * ar[2];
9752
+ br[2] = mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2];
9753
+ // vec3.set(
9754
+ // br,
9755
+ // mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2],
9756
+ // my0a * ar[0] + my1a * ar[1] + my2a * ar[2],
9757
+ // mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2],
9758
+ // );
9759
+ // this.min = vec3.sub(this.min, bc, br);
9760
+ // this.max = vec3.add(this.max, bc, br);
9761
+ subVec3(this.min, bc, br);
9762
+ addVec3(this.max, bc, br);
9763
+ };
9764
+ _proto.intersects = function intersects(aabb) {
9765
+ var aMax = this.getMax();
9766
+ var aMin = this.getMin();
9767
+ var bMax = aabb.getMax();
9768
+ var bMin = aabb.getMin();
9769
+ return aMin[0] <= bMax[0] && aMax[0] >= bMin[0] && aMin[1] <= bMax[1] && aMax[1] >= bMin[1] && aMin[2] <= bMax[2] && aMax[2] >= bMin[2];
9770
+ };
9771
+ _proto.intersection = function intersection(aabb) {
9772
+ if (!this.intersects(aabb)) {
9773
+ return null;
9774
+ }
9775
+ var intersection = new AABB();
9776
+ // const min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
9777
+ // const max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
9778
+ var min = maxVec3([0, 0, 0], this.getMin(), aabb.getMin());
9779
+ var max = minVec3([0, 0, 0], this.getMax(), aabb.getMax());
9780
+ intersection.setMinMax(min, max);
9781
+ return intersection;
10847
9782
  }
10848
- return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
10849
- }
9783
+ // containsPoint(point: vec3) {
9784
+ // const min = this.getMin();
9785
+ // const max = this.getMax();
9786
+ // return !(
9787
+ // point[0] < min[0] ||
9788
+ // point[0] > max[0] ||
9789
+ // point[1] < min[1] ||
9790
+ // point[1] > max[1] ||
9791
+ // point[2] < min[2] ||
9792
+ // point[2] > max[2]
9793
+ // );
9794
+ // }
9795
+ /**
9796
+ * get n-vertex
9797
+ * @param plane plane of CullingVolume
9798
+ */;
9799
+ _proto.getNegativeFarPoint = function getNegativeFarPoint(plane) {
9800
+ if (plane.pnVertexFlag === 0x111) {
9801
+ return copyVec3([0, 0, 0], this.min);
9802
+ // return vec3.copy(vec3.create(), this.min);
9803
+ } else if (plane.pnVertexFlag === 0x110) {
9804
+ return [this.min[0], this.min[1], this.max[2]];
9805
+ // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
9806
+ } else if (plane.pnVertexFlag === 0x101) {
9807
+ return [this.min[0], this.max[1], this.min[2]];
9808
+ // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
9809
+ } else if (plane.pnVertexFlag === 0x100) {
9810
+ return [this.min[0], this.max[1], this.max[2]];
9811
+ // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
9812
+ } else if (plane.pnVertexFlag === 0x011) {
9813
+ return [this.max[0], this.min[1], this.min[2]];
9814
+ // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
9815
+ } else if (plane.pnVertexFlag === 0x010) {
9816
+ return [this.max[0], this.min[1], this.max[2]];
9817
+ // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
9818
+ } else if (plane.pnVertexFlag === 0x001) {
9819
+ return [this.max[0], this.max[1], this.min[2]];
9820
+ // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
9821
+ } else {
9822
+ return [this.max[0], this.max[1], this.max[2]];
9823
+ // return vec3.fromValues(this.max[0], this.max[1], this.max[2]);
9824
+ }
9825
+ }
9826
+ /**
9827
+ * get p-vertex
9828
+ * @param plane plane of CullingVolume
9829
+ */;
9830
+ _proto.getPositiveFarPoint = function getPositiveFarPoint(plane) {
9831
+ if (plane.pnVertexFlag === 0x111) {
9832
+ return copyVec3([0, 0, 0], this.max);
9833
+ // return vec3.copy(vec3.create(), this.max);
9834
+ } else if (plane.pnVertexFlag === 0x110) {
9835
+ return [this.max[0], this.max[1], this.min[2]];
9836
+ // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
9837
+ } else if (plane.pnVertexFlag === 0x101) {
9838
+ return [this.max[0], this.min[1], this.max[2]];
9839
+ // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
9840
+ } else if (plane.pnVertexFlag === 0x100) {
9841
+ return [this.max[0], this.min[1], this.min[2]];
9842
+ // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
9843
+ } else if (plane.pnVertexFlag === 0x011) {
9844
+ return [this.min[0], this.max[1], this.max[2]];
9845
+ // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
9846
+ } else if (plane.pnVertexFlag === 0x010) {
9847
+ return [this.min[0], this.max[1], this.min[2]];
9848
+ // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
9849
+ } else if (plane.pnVertexFlag === 0x001) {
9850
+ return [this.min[0], this.min[1], this.max[2]];
9851
+ // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
9852
+ } else {
9853
+ return [this.min[0], this.min[1], this.min[2]];
9854
+ // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
9855
+ }
9856
+ };
9857
+ return AABB;
9858
+ }();
10850
9859
 
10851
- /**
10852
- * Thanks for following contributor of codes
10853
- * https://gist.github.com/1866474
10854
- * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
10855
- * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
10856
- * https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/requestAnimationFrame/polyfill.js
10857
- **/
10858
- var uId = 1;
10859
- var uniqueId = function uniqueId() {
10860
- return uId++;
10861
- };
10862
- // We use `self` instead of `window` for `WebWorker` support.
10863
- var root = typeof self === 'object' && self.self == self ? self :
10864
- // @ts-ignore
10865
- typeof global === 'object' && global.global == global ?
10866
- // @ts-ignore
10867
- global : {};
10868
- var nowOffset = Date.now();
10869
- // use performance api if exist, otherwise use Date.now.
10870
- // Date.now polyfill required.
10871
- var pnow = function pnow() {
10872
- if (root.performance && typeof root.performance.now === 'function') {
10873
- return root.performance.now();
9860
+ var Plane = /*#__PURE__*/function () {
9861
+ /**
9862
+ * lookup table for p-vertex & n-vertex when doing frustum culling
9863
+ */
9864
+
9865
+ function Plane(distance, normal) {
9866
+ this.distance = void 0;
9867
+ this.normal = void 0;
9868
+ this.pnVertexFlag = void 0;
9869
+ this.distance = distance || 0;
9870
+ this.normal = normal || vec3.fromValues(0, 1, 0);
9871
+ this.updatePNVertexFlag();
10874
9872
  }
10875
- // fallback
10876
- return Date.now() - nowOffset;
10877
- };
10878
- var reservedCBs = {};
10879
- var lastTime = Date.now();
10880
- var polyfillRaf = function polyfillRaf(callback) {
10881
- if (typeof callback !== 'function') {
10882
- throw new TypeError(callback + ' is not a function');
9873
+ var _proto = Plane.prototype;
9874
+ _proto.updatePNVertexFlag = function updatePNVertexFlag() {
9875
+ this.pnVertexFlag = (Number(this.normal[0] >= 0) << 8) + (Number(this.normal[1] >= 0) << 4) + Number(this.normal[2] >= 0);
9876
+ };
9877
+ _proto.distanceToPoint = function distanceToPoint(point) {
9878
+ return vec3.dot(point, this.normal) - this.distance;
9879
+ };
9880
+ _proto.normalize = function normalize() {
9881
+ var invLen = 1 / vec3.len(this.normal);
9882
+ vec3.scale(this.normal, this.normal, invLen);
9883
+ this.distance *= invLen;
9884
+ };
9885
+ _proto.intersectsLine = function intersectsLine(start, end, point) {
9886
+ var d0 = this.distanceToPoint(start);
9887
+ var d1 = this.distanceToPoint(end);
9888
+ var t = d0 / (d0 - d1);
9889
+ var intersects = t >= 0 && t <= 1;
9890
+ if (intersects && point) {
9891
+ vec3.lerp(point, start, end, t);
9892
+ }
9893
+ return intersects;
9894
+ };
9895
+ return Plane;
9896
+ }();
9897
+
9898
+ var Mask;
9899
+ (function (Mask) {
9900
+ Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
9901
+ Mask[Mask["INSIDE"] = 0] = "INSIDE";
9902
+ Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
9903
+ })(Mask || (Mask = {}));
9904
+ var Frustum = /*#__PURE__*/function () {
9905
+ function Frustum(planes) {
9906
+ this.planes = [];
9907
+ if (planes) {
9908
+ this.planes = planes;
9909
+ } else {
9910
+ for (var i = 0; i < 6; i++) {
9911
+ this.planes.push(new Plane());
9912
+ }
9913
+ }
10883
9914
  }
10884
- var currentTime = Date.now();
10885
- var gap = currentTime - lastTime;
10886
- var delay = gap > 16 ? 0 : 16 - gap;
10887
- var id = uniqueId();
10888
- reservedCBs[id] = callback;
10889
- // keys(reservedCBs).length > 1 의미는 이미 setTimeout 이 걸려있는 경우.
10890
- // 함께 callback 이 실행될 수 있게 reservedCBs 에만 추가해주고 return
10891
- if (Object.keys(reservedCBs).length > 1) return id;
10892
- setTimeout(function () {
10893
- lastTime = currentTime;
10894
- var copied = reservedCBs;
10895
- reservedCBs = {};
10896
- Object.keys(copied).forEach(function (key) {
10897
- return copied[key](pnow());
9915
+ /**
9916
+ * extract 6 planes from projectionMatrix
9917
+ * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
9918
+ */
9919
+ var _proto = Frustum.prototype;
9920
+ _proto.extractFromVPMatrix = function extractFromVPMatrix(projectionMatrix) {
9921
+ // @ts-ignore
9922
+ var m0 = projectionMatrix[0],
9923
+ m1 = projectionMatrix[1],
9924
+ m2 = projectionMatrix[2],
9925
+ m3 = projectionMatrix[3],
9926
+ m4 = projectionMatrix[4],
9927
+ m5 = projectionMatrix[5],
9928
+ m6 = projectionMatrix[6],
9929
+ m7 = projectionMatrix[7],
9930
+ m8 = projectionMatrix[8],
9931
+ m9 = projectionMatrix[9],
9932
+ m10 = projectionMatrix[10],
9933
+ m11 = projectionMatrix[11],
9934
+ m12 = projectionMatrix[12],
9935
+ m13 = projectionMatrix[13],
9936
+ m14 = projectionMatrix[14],
9937
+ m15 = projectionMatrix[15];
9938
+ // right
9939
+ vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
9940
+ this.planes[0].distance = m15 - m12;
9941
+ // left
9942
+ vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
9943
+ this.planes[1].distance = m15 + m12;
9944
+ // bottom
9945
+ vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
9946
+ this.planes[2].distance = m15 + m13;
9947
+ // top
9948
+ vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
9949
+ this.planes[3].distance = m15 - m13;
9950
+ // far
9951
+ vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
9952
+ this.planes[4].distance = m15 - m14;
9953
+ // near
9954
+ vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
9955
+ this.planes[5].distance = m15 + m14;
9956
+ this.planes.forEach(function (plane) {
9957
+ plane.normalize();
9958
+ plane.updatePNVertexFlag();
10898
9959
  });
10899
- }, delay);
10900
- return id;
10901
- };
10902
- var polyfillCaf = function polyfillCaf(id) {
10903
- delete reservedCBs[id];
10904
- };
10905
- var vendorPrefixes = ['', 'webkit', 'moz', 'ms', 'o'];
10906
- var getRequestAnimationFrame = function getRequestAnimationFrame(vp) {
10907
- if (typeof vp !== 'string') return polyfillRaf;
10908
- if (vp === '') return root['requestAnimationFrame'];
10909
- return root[vp + 'RequestAnimationFrame'];
10910
- };
10911
- var getCancelAnimationFrame = function getCancelAnimationFrame(vp) {
10912
- if (typeof vp !== 'string') return polyfillCaf;
10913
- if (vp === '') return root['cancelAnimationFrame'];
10914
- return root[vp + 'CancelAnimationFrame'] || root[vp + 'CancelRequestAnimationFrame'];
10915
- };
10916
- var find = function find(arr, predicate) {
10917
- var i = 0;
10918
- while (arr[i] !== void 0) {
10919
- if (predicate(arr[i])) return arr[i];
10920
- i = i + 1;
9960
+ };
9961
+ return Frustum;
9962
+ }();
9963
+
9964
+ var Rectangle = /*#__PURE__*/function () {
9965
+ function Rectangle(x, y, width, height) {
9966
+ this.x = void 0;
9967
+ this.y = void 0;
9968
+ this.width = void 0;
9969
+ this.height = void 0;
9970
+ this.left = void 0;
9971
+ this.right = void 0;
9972
+ this.top = void 0;
9973
+ this.bottom = void 0;
9974
+ this.x = x;
9975
+ this.y = y;
9976
+ this.width = width;
9977
+ this.height = height;
9978
+ this.left = x;
9979
+ this.right = x + width;
9980
+ this.top = y;
9981
+ this.bottom = y + height;
10921
9982
  }
10922
- };
10923
- var vp = find(vendorPrefixes, function (vp) {
10924
- return !!getRequestAnimationFrame(vp);
10925
- });
10926
- var raf = getRequestAnimationFrame(vp);
10927
- var caf = getCancelAnimationFrame(vp);
10928
- root.requestAnimationFrame = raf;
10929
- root.cancelAnimationFrame = caf;
9983
+ var _proto = Rectangle.prototype;
9984
+ _proto.toJSON = function toJSON() {};
9985
+ return Rectangle;
9986
+ }();
10930
9987
 
10931
9988
  /**
10932
9989
  * Blink used them in code generation(css_properties.json5)
@@ -11423,9 +10480,9 @@ var BUILT_IN_PROPERTIES = [{
11423
10480
  var propertyMetadataCache = {};
11424
10481
  var unresolvedProperties = new WeakMap();
11425
10482
  // const uniqueAttributeSet = new Set<string>();
11426
- var tmpVec3a = vec3.create();
11427
- var tmpVec3b = vec3.create();
11428
- var tmpVec3c = vec3.create();
10483
+ // const tmpVec3a = vec3.create();
10484
+ // const tmpVec3b = vec3.create();
10485
+ // const tmpVec3c = vec3.create();
11429
10486
  var isPropertyResolved = function isPropertyResolved(object, name) {
11430
10487
  var properties = unresolvedProperties.get(object);
11431
10488
  if (!properties || properties.length === 0) {
@@ -11475,6 +10532,25 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11475
10532
  usedAttributes: []
11476
10533
  };
11477
10534
  }
10535
+ if (!runtime.enableCSSParsing) {
10536
+ Object.assign(object.attributes, attributes);
10537
+ object.parsedStyle = Object.assign(object.parsedStyle, attributes);
10538
+ if (attributes.fill) {
10539
+ object.parsedStyle.fill = parseColor(attributes.fill);
10540
+ }
10541
+ if (attributes.stroke) {
10542
+ object.parsedStyle.stroke = parseColor(attributes.stroke);
10543
+ }
10544
+ // @ts-ignore
10545
+ if (attributes.cx || attributes.cy) {
10546
+ // @ts-ignore
10547
+ runtime.CSSPropertySyntaxFactory['<coordinate>'].postProcessor(object);
10548
+ }
10549
+ // console.log(object.parsedStyle);
10550
+ // console.log(attributes);
10551
+ this.updateGeometry(object);
10552
+ return;
10553
+ }
11478
10554
  var _options = options,
11479
10555
  skipUpdateAttribute = _options.skipUpdateAttribute,
11480
10556
  skipParse = _options.skipParse,
@@ -11536,7 +10612,7 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11536
10612
  _this2.postProcessProperty(name, object, attributeNames);
11537
10613
  }
11538
10614
  });
11539
- if (object.children.length) {
10615
+ if (runtime.enableCSSParsing && object.children.length) {
11540
10616
  attributeNames.forEach(function (name) {
11541
10617
  if (name in object.parsedStyle && _this2.isPropertyInheritable(name)) {
11542
10618
  // update children's inheritable
@@ -11730,7 +10806,13 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11730
10806
  var flipY = width < 0;
11731
10807
  var flipX = height < 0;
11732
10808
  // init with content box
11733
- var halfExtents = vec3.set(tmpVec3a, Math.abs(width) / 2, Math.abs(height) / 2, depth / 2);
10809
+ var halfExtents = [Math.abs(width) / 2, Math.abs(height) / 2, depth / 2];
10810
+ // const halfExtents = vec3.set(
10811
+ // tmpVec3a,
10812
+ // Math.abs(width) / 2,
10813
+ // Math.abs(height) / 2,
10814
+ // depth / 2,
10815
+ // );
11734
10816
  // anchor is center by default, don't account for lineWidth here
11735
10817
  var stroke = parsedStyle.stroke,
11736
10818
  lineWidth = parsedStyle.lineWidth,
@@ -11745,7 +10827,13 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11745
10827
  if (object.nodeName === Shape.TEXT) {
11746
10828
  delete parsedStyle.anchor;
11747
10829
  }
11748
- var center = vec3.set(tmpVec3b, (1 - (anchor && anchor[0] || 0) * 2) * width / 2 + offsetX, (1 - (anchor && anchor[1] || 0) * 2) * height / 2 + offsetY, (1 - (anchor && anchor[2] || 0) * 2) * halfExtents[2] + offsetZ);
10830
+ var center = [(1 - (anchor && anchor[0] || 0) * 2) * width / 2 + offsetX, (1 - (anchor && anchor[1] || 0) * 2) * height / 2 + offsetY, (1 - (anchor && anchor[2] || 0) * 2) * halfExtents[2] + offsetZ];
10831
+ // const center = vec3.set(
10832
+ // tmpVec3b,
10833
+ // ((1 - ((anchor && anchor[0]) || 0) * 2) * width) / 2 + offsetX,
10834
+ // ((1 - ((anchor && anchor[1]) || 0) * 2) * height) / 2 + offsetY,
10835
+ // (1 - ((anchor && anchor[2]) || 0) * 2) * halfExtents[2] + offsetZ,
10836
+ // );
11749
10837
  // update geometry's AABB
11750
10838
  geometry.contentBounds.update(center, halfExtents);
11751
10839
  // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
@@ -11762,8 +10850,15 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11762
10850
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) * expansion;
11763
10851
  // halfExtents[0] += halfLineWidth[0];
11764
10852
  // halfExtents[1] += halfLineWidth[1];
11765
- vec3.add(halfExtents, halfExtents, vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0));
10853
+ halfExtents[0] += halfLineWidth;
10854
+ halfExtents[1] += halfLineWidth;
10855
+ // vec3.add(
10856
+ // halfExtents,
10857
+ // halfExtents,
10858
+ // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
10859
+ // );
11766
10860
  }
10861
+
11767
10862
  geometry.renderBounds.update(center, halfExtents);
11768
10863
  // account for shadow, only support constant value now
11769
10864
  if (shadowColor && shadowType && shadowType !== 'inner') {
@@ -11792,7 +10887,7 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11792
10887
  params = _ref.params;
11793
10888
  if (name === 'blur') {
11794
10889
  var blurRadius = params[0].value;
11795
- geometry.renderBounds.update(geometry.renderBounds.center, vec3.add(geometry.renderBounds.halfExtents, geometry.renderBounds.halfExtents, vec3.fromValues(blurRadius, blurRadius, 0)));
10890
+ geometry.renderBounds.update(geometry.renderBounds.center, addVec3(geometry.renderBounds.halfExtents, geometry.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
11796
10891
  } else if (name === 'drop-shadow') {
11797
10892
  var _shadowOffsetX = params[0].value;
11798
10893
  var _shadowOffsetY = params[1].value;
@@ -11813,8 +10908,8 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
11813
10908
  });
11814
10909
  anchor = parsedStyle.anchor;
11815
10910
  // set transform origin
11816
- var usedOriginXValue = (flipY ? -1 : 1) * convertPercentUnit(transformOrigin[0], 0, object);
11817
- var usedOriginYValue = (flipX ? -1 : 1) * convertPercentUnit(transformOrigin[1], 1, object);
10911
+ var usedOriginXValue = (flipY ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[0], 0, object) : 0);
10912
+ var usedOriginYValue = (flipX ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[1], 1, object) : 0);
11818
10913
  usedOriginXValue = usedOriginXValue - (flipY ? -1 : 1) * (anchor && anchor[0] || 0) * geometry.contentBounds.halfExtents[0] * 2;
11819
10914
  usedOriginYValue = usedOriginYValue - (flipX ? -1 : 1) * (anchor && anchor[1] || 0) * geometry.contentBounds.halfExtents[1] * 2;
11820
10915
  object.setOrigin(usedOriginXValue, usedOriginYValue);
@@ -13707,37 +12802,37 @@ var OffscreenCanvasCreator = /*#__PURE__*/function () {
13707
12802
  this.context = void 0;
13708
12803
  }
13709
12804
  var _proto = OffscreenCanvasCreator.prototype;
13710
- _proto.getOrCreateCanvas = function getOrCreateCanvas(offscreenCanvas) {
12805
+ _proto.getOrCreateCanvas = function getOrCreateCanvas(offscreenCanvas, contextAttributes) {
13711
12806
  if (this.canvas) {
13712
12807
  return this.canvas;
13713
12808
  }
13714
12809
  // user-defined offscreen canvas
13715
12810
  if (offscreenCanvas) {
13716
12811
  this.canvas = offscreenCanvas;
13717
- this.context = this.canvas.getContext('2d');
12812
+ this.context = this.canvas.getContext('2d', contextAttributes);
13718
12813
  } else {
13719
12814
  try {
13720
12815
  // OffscreenCanvas2D measureText can be up to 40% faster.
13721
12816
  this.canvas = new window.OffscreenCanvas(0, 0);
13722
- this.context = this.canvas.getContext('2d');
12817
+ this.context = this.canvas.getContext('2d', contextAttributes);
13723
12818
  if (!this.context || !this.context.measureText) {
13724
12819
  this.canvas = document.createElement('canvas');
13725
12820
  this.context = this.canvas.getContext('2d');
13726
12821
  }
13727
12822
  } catch (ex) {
13728
12823
  this.canvas = document.createElement('canvas');
13729
- this.context = this.canvas.getContext('2d');
12824
+ this.context = this.canvas.getContext('2d', contextAttributes);
13730
12825
  }
13731
12826
  }
13732
12827
  this.canvas.width = 10;
13733
12828
  this.canvas.height = 10;
13734
12829
  return this.canvas;
13735
12830
  };
13736
- _proto.getOrCreateContext = function getOrCreateContext(offscreenCanvas) {
12831
+ _proto.getOrCreateContext = function getOrCreateContext(offscreenCanvas, contextAttributes) {
13737
12832
  if (this.context) {
13738
12833
  return this.context;
13739
12834
  }
13740
- this.getOrCreateCanvas(offscreenCanvas);
12835
+ this.getOrCreateCanvas(offscreenCanvas, contextAttributes);
13741
12836
  return this.context;
13742
12837
  };
13743
12838
  return OffscreenCanvasCreator;
@@ -13904,7 +12999,9 @@ var RenderingService = /*#__PURE__*/function () {
13904
12999
  enableDirtyCheck = _canvasConfig$rendere.enableDirtyCheck,
13905
13000
  enableCulling = _canvasConfig$rendere.enableCulling;
13906
13001
  // recalc style values
13907
- this.globalRuntime.styleValueRegistry.recalc(displayObject);
13002
+ if (this.globalRuntime.enableCSSParsing) {
13003
+ this.globalRuntime.styleValueRegistry.recalc(displayObject);
13004
+ }
13908
13005
  // TODO: relayout
13909
13006
  // dirtycheck first
13910
13007
  var objectChanged = enableDirtyCheck ? this.hooks.dirtycheck.call(displayObject) : displayObject;
@@ -15240,6 +14337,7 @@ runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
15240
14337
  runtime.styleValueRegistry = new DefaultStyleValueRegistry();
15241
14338
  runtime.layoutRegistry = null;
15242
14339
  runtime.globalThis = getGlobalThis();
14340
+ runtime.enableCSSParsing = true;
15243
14341
 
15244
14342
  var AbstractRendererPlugin = /*#__PURE__*/function () {
15245
14343
  function AbstractRendererPlugin() {
@@ -15782,8 +14880,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
15782
14880
  };
15783
14881
  var handleMounted = function handleMounted(e) {
15784
14882
  var object = e.target;
15785
- // recalc style values
15786
- runtime.styleValueRegistry.recalc(object);
14883
+ if (runtime.enableCSSParsing) {
14884
+ // recalc style values
14885
+ runtime.styleValueRegistry.recalc(object);
14886
+ }
15787
14887
  runtime.sceneGraphService.dirtifyToRoot(object);
15788
14888
  renderingService.dirtify();
15789
14889
  };
@@ -15818,6 +14918,7 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
15818
14918
  canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
15819
14919
  canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
15820
14920
  canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14921
+ _this.toSync.clear();
15821
14922
  });
15822
14923
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
15823
14924
  // if (this.isFirstTimeRendering) {