@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.umd.js CHANGED
@@ -2860,36 +2860,6 @@
2860
2860
  out[2] = a[2] * b[2];
2861
2861
  return out;
2862
2862
  }
2863
- /**
2864
- * Returns the minimum of two vec3's
2865
- *
2866
- * @param {vec3} out the receiving vector
2867
- * @param {ReadonlyVec3} a the first operand
2868
- * @param {ReadonlyVec3} b the second operand
2869
- * @returns {vec3} out
2870
- */
2871
-
2872
- function min(out, a, b) {
2873
- out[0] = Math.min(a[0], b[0]);
2874
- out[1] = Math.min(a[1], b[1]);
2875
- out[2] = Math.min(a[2], b[2]);
2876
- return out;
2877
- }
2878
- /**
2879
- * Returns the maximum of two vec3's
2880
- *
2881
- * @param {vec3} out the receiving vector
2882
- * @param {ReadonlyVec3} a the first operand
2883
- * @param {ReadonlyVec3} b the second operand
2884
- * @returns {vec3} out
2885
- */
2886
-
2887
- function max(out, a, b) {
2888
- out[0] = Math.max(a[0], b[0]);
2889
- out[1] = Math.max(a[1], b[1]);
2890
- out[2] = Math.max(a[2], b[2]);
2891
- return out;
2892
- }
2893
2863
  /**
2894
2864
  * Scales a vec3 by a scalar number
2895
2865
  *
@@ -3079,12 +3049,6 @@
3079
3049
  b2 = b[2];
3080
3050
  return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));
3081
3051
  }
3082
- /**
3083
- * Alias for {@link vec3.subtract}
3084
- * @function
3085
- */
3086
-
3087
- var sub$1 = subtract$1;
3088
3052
  /**
3089
3053
  * Alias for {@link vec3.length}
3090
3054
  * @function
@@ -5399,7 +5363,7 @@
5399
5363
  * // => 1250010
5400
5364
  * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
5401
5365
  */
5402
- var max$1 = (function (arr) {
5366
+ var max = (function (arr) {
5403
5367
  if (!isArray(arr)) {
5404
5368
  return undefined;
5405
5369
  }
@@ -5425,7 +5389,7 @@
5425
5389
  * // => 1250010
5426
5390
  * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
5427
5391
  */
5428
- var min$1 = (function (arr) {
5392
+ var min = (function (arr) {
5429
5393
  if (!isArray(arr)) {
5430
5394
  return undefined;
5431
5395
  }
@@ -5480,427 +5444,42 @@
5480
5444
  return value === undefined;
5481
5445
  };
5482
5446
 
5483
- /**
5484
- * Axis-Aligned Bounding Box
5485
- * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
5486
- * @see https://github.com/antvis/GWebGPUEngine/issues/3
5487
- */
5488
- var AABB = /*#__PURE__*/function () {
5489
- AABB.isEmpty = function isEmpty(aabb) {
5490
- return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
5491
- };
5492
- function AABB(center, halfExtents) {
5493
- if (center === void 0) {
5494
- center = [0, 0, 0];
5495
- }
5496
- if (halfExtents === void 0) {
5497
- halfExtents = [0, 0, 0];
5498
- }
5499
- this.center = create$2();
5500
- this.halfExtents = create$2();
5501
- this.min = create$2();
5502
- this.max = create$2();
5503
- this.update(center, halfExtents);
5504
- }
5505
- var _proto = AABB.prototype;
5506
- _proto.update = function update(center, halfExtents) {
5507
- copy$1(this.center, center);
5508
- copy$1(this.halfExtents, halfExtents);
5509
- sub$1(this.min, this.center, this.halfExtents);
5510
- add$1(this.max, this.center, this.halfExtents);
5511
- };
5512
- _proto.setMinMax = function setMinMax(min, max) {
5513
- add$1(this.center, max, min);
5514
- scale$1(this.center, this.center, 0.5);
5515
- sub$1(this.halfExtents, max, min);
5516
- scale$1(this.halfExtents, this.halfExtents, 0.5);
5517
- copy$1(this.min, min);
5518
- copy$1(this.max, max);
5519
- };
5520
- _proto.getMin = function getMin() {
5521
- return this.min;
5522
- };
5523
- _proto.getMax = function getMax() {
5524
- return this.max;
5525
- };
5526
- _proto.add = function add(aabb) {
5527
- if (AABB.isEmpty(aabb)) {
5528
- return;
5529
- }
5530
- if (AABB.isEmpty(this)) {
5531
- this.setMinMax(aabb.getMin(), aabb.getMax());
5532
- return;
5533
- }
5534
- var tc = this.center;
5535
- var tcx = tc[0];
5536
- var tcy = tc[1];
5537
- var tcz = tc[2];
5538
- var th = this.halfExtents;
5539
- var thx = th[0];
5540
- var thy = th[1];
5541
- var thz = th[2];
5542
- var tminx = tcx - thx;
5543
- var tmaxx = tcx + thx;
5544
- var tminy = tcy - thy;
5545
- var tmaxy = tcy + thy;
5546
- var tminz = tcz - thz;
5547
- var tmaxz = tcz + thz;
5548
- var oc = aabb.center;
5549
- var ocx = oc[0];
5550
- var ocy = oc[1];
5551
- var ocz = oc[2];
5552
- var oh = aabb.halfExtents;
5553
- var ohx = oh[0];
5554
- var ohy = oh[1];
5555
- var ohz = oh[2];
5556
- var ominx = ocx - ohx;
5557
- var omaxx = ocx + ohx;
5558
- var ominy = ocy - ohy;
5559
- var omaxy = ocy + ohy;
5560
- var ominz = ocz - ohz;
5561
- var omaxz = ocz + ohz;
5562
- if (ominx < tminx) {
5563
- tminx = ominx;
5564
- }
5565
- if (omaxx > tmaxx) {
5566
- tmaxx = omaxx;
5567
- }
5568
- if (ominy < tminy) {
5569
- tminy = ominy;
5570
- }
5571
- if (omaxy > tmaxy) {
5572
- tmaxy = omaxy;
5573
- }
5574
- if (ominz < tminz) {
5575
- tminz = ominz;
5576
- }
5577
- if (omaxz > tmaxz) {
5578
- tmaxz = omaxz;
5579
- }
5580
- tc[0] = (tminx + tmaxx) * 0.5;
5581
- tc[1] = (tminy + tmaxy) * 0.5;
5582
- tc[2] = (tminz + tmaxz) * 0.5;
5583
- th[0] = (tmaxx - tminx) * 0.5;
5584
- th[1] = (tmaxy - tminy) * 0.5;
5585
- th[2] = (tmaxz - tminz) * 0.5;
5586
- this.min[0] = tminx;
5587
- this.min[1] = tminy;
5588
- this.min[2] = tminz;
5589
- this.max[0] = tmaxx;
5590
- this.max[1] = tmaxy;
5591
- this.max[2] = tmaxz;
5592
- };
5593
- _proto.setFromTransformedAABB = function setFromTransformedAABB(aabb, m) {
5594
- var bc = this.center;
5595
- var br = this.halfExtents;
5596
- var ac = aabb.center;
5597
- var ar = aabb.halfExtents;
5598
- var mx0 = m[0];
5599
- var mx1 = m[4];
5600
- var mx2 = m[8];
5601
- var my0 = m[1];
5602
- var my1 = m[5];
5603
- var my2 = m[9];
5604
- var mz0 = m[2];
5605
- var mz1 = m[6];
5606
- var mz2 = m[10];
5607
- var mx0a = Math.abs(mx0);
5608
- var mx1a = Math.abs(mx1);
5609
- var mx2a = Math.abs(mx2);
5610
- var my0a = Math.abs(my0);
5611
- var my1a = Math.abs(my1);
5612
- var my2a = Math.abs(my2);
5613
- var mz0a = Math.abs(mz0);
5614
- var mz1a = Math.abs(mz1);
5615
- var mz2a = Math.abs(mz2);
5616
- set$1(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]);
5617
- set$1(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]);
5618
- this.min = sub$1(this.min, bc, br);
5619
- this.max = add$1(this.max, bc, br);
5620
- };
5621
- _proto.intersects = function intersects(aabb) {
5622
- var aMax = this.getMax();
5623
- var aMin = this.getMin();
5624
- var bMax = aabb.getMax();
5625
- var bMin = aabb.getMin();
5626
- 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];
5627
- };
5628
- _proto.intersection = function intersection(aabb) {
5629
- if (!this.intersects(aabb)) {
5630
- return null;
5631
- }
5632
- var intersection = new AABB();
5633
- var min$1 = max(create$2(), this.getMin(), aabb.getMin());
5634
- var max$1 = min(create$2(), this.getMax(), aabb.getMax());
5635
- intersection.setMinMax(min$1, max$1);
5636
- return intersection;
5637
- };
5638
- _proto.containsPoint = function containsPoint(point) {
5639
- var min = this.getMin();
5640
- var max = this.getMax();
5641
- 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]);
5447
+ function memoize(func, resolver) {
5448
+ if (typeof func !== 'function' || resolver != null && typeof resolver !== 'function') {
5449
+ throw new TypeError('Expected a function');
5642
5450
  }
5643
- /**
5644
- * get n-vertex
5645
- * @param plane plane of CullingVolume
5646
- */;
5647
- _proto.getNegativeFarPoint = function getNegativeFarPoint(plane) {
5648
- if (plane.pnVertexFlag === 0x111) {
5649
- return copy$1(create$2(), this.min);
5650
- } else if (plane.pnVertexFlag === 0x110) {
5651
- return fromValues$2(this.min[0], this.min[1], this.max[2]);
5652
- } else if (plane.pnVertexFlag === 0x101) {
5653
- return fromValues$2(this.min[0], this.max[1], this.min[2]);
5654
- } else if (plane.pnVertexFlag === 0x100) {
5655
- return fromValues$2(this.min[0], this.max[1], this.max[2]);
5656
- } else if (plane.pnVertexFlag === 0x011) {
5657
- return fromValues$2(this.max[0], this.min[1], this.min[2]);
5658
- } else if (plane.pnVertexFlag === 0x010) {
5659
- return fromValues$2(this.max[0], this.min[1], this.max[2]);
5660
- } else if (plane.pnVertexFlag === 0x001) {
5661
- return fromValues$2(this.max[0], this.max[1], this.min[2]);
5662
- } else {
5663
- return fromValues$2(this.max[0], this.max[1], this.max[2]);
5451
+ var memoized = function memoized() {
5452
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5453
+ args[_key] = arguments[_key];
5664
5454
  }
5665
- }
5666
- /**
5667
- * get p-vertex
5668
- * @param plane plane of CullingVolume
5669
- */;
5670
- _proto.getPositiveFarPoint = function getPositiveFarPoint(plane) {
5671
- if (plane.pnVertexFlag === 0x111) {
5672
- return copy$1(create$2(), this.max);
5673
- } else if (plane.pnVertexFlag === 0x110) {
5674
- return fromValues$2(this.max[0], this.max[1], this.min[2]);
5675
- } else if (plane.pnVertexFlag === 0x101) {
5676
- return fromValues$2(this.max[0], this.min[1], this.max[2]);
5677
- } else if (plane.pnVertexFlag === 0x100) {
5678
- return fromValues$2(this.max[0], this.min[1], this.min[2]);
5679
- } else if (plane.pnVertexFlag === 0x011) {
5680
- return fromValues$2(this.min[0], this.max[1], this.max[2]);
5681
- } else if (plane.pnVertexFlag === 0x010) {
5682
- return fromValues$2(this.min[0], this.max[1], this.min[2]);
5683
- } else if (plane.pnVertexFlag === 0x001) {
5684
- return fromValues$2(this.min[0], this.min[1], this.max[2]);
5685
- } else {
5686
- return fromValues$2(this.min[0], this.min[1], this.min[2]);
5455
+ var key = resolver ? resolver.apply(this, args) : args[0];
5456
+ var cache = memoized.cache;
5457
+ if (cache.has(key)) {
5458
+ return cache.get(key);
5687
5459
  }
5460
+ var result = func.apply(this, args);
5461
+ memoized.cache = cache.set(key, result) || cache;
5462
+ return result;
5688
5463
  };
5689
- return AABB;
5690
- }();
5691
-
5692
- var Plane = /*#__PURE__*/function () {
5693
- /**
5694
- * lookup table for p-vertex & n-vertex when doing frustum culling
5695
- */
5464
+ memoized.cache = new (memoize.Cache || Map)();
5465
+ return memoized;
5466
+ }
5467
+ memoize.Cache = Map;
5696
5468
 
5697
- function Plane(distance, normal) {
5698
- this.distance = void 0;
5699
- this.normal = void 0;
5700
- this.pnVertexFlag = void 0;
5701
- this.distance = distance || 0;
5702
- this.normal = normal || fromValues$2(0, 1, 0);
5703
- this.updatePNVertexFlag();
5469
+ var camelCase = memoize(function (str) {
5470
+ if (str === void 0) {
5471
+ str = '';
5704
5472
  }
5705
- var _proto = Plane.prototype;
5706
- _proto.updatePNVertexFlag = function updatePNVertexFlag() {
5707
- this.pnVertexFlag = (Number(this.normal[0] >= 0) << 8) + (Number(this.normal[1] >= 0) << 4) + Number(this.normal[2] >= 0);
5708
- };
5709
- _proto.distanceToPoint = function distanceToPoint(point) {
5710
- return dot(point, this.normal) - this.distance;
5711
- };
5712
- _proto.normalize = function normalize() {
5713
- var invLen = 1 / len(this.normal);
5714
- scale$1(this.normal, this.normal, invLen);
5715
- this.distance *= invLen;
5716
- };
5717
- _proto.intersectsLine = function intersectsLine(start, end, point) {
5718
- var d0 = this.distanceToPoint(start);
5719
- var d1 = this.distanceToPoint(end);
5720
- var t = d0 / (d0 - d1);
5721
- var intersects = t >= 0 && t <= 1;
5722
- if (intersects && point) {
5723
- lerp(point, start, end, t);
5724
- }
5725
- return intersects;
5726
- };
5727
- return Plane;
5728
- }();
5729
-
5730
- (function (Mask) {
5731
- Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
5732
- Mask[Mask["INSIDE"] = 0] = "INSIDE";
5733
- Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
5734
- })(exports.Mask || (exports.Mask = {}));
5735
- var Frustum = /*#__PURE__*/function () {
5736
- function Frustum(planes) {
5737
- this.planes = [];
5738
- if (planes) {
5739
- this.planes = planes;
5740
- } else {
5741
- for (var i = 0; i < 6; i++) {
5742
- this.planes.push(new Plane());
5743
- }
5744
- }
5745
- }
5746
- /**
5747
- * extract 6 planes from projectionMatrix
5748
- * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
5749
- */
5750
- var _proto = Frustum.prototype;
5751
- _proto.extractFromVPMatrix = function extractFromVPMatrix(projectionMatrix) {
5752
- // @ts-ignore
5753
- var m0 = projectionMatrix[0],
5754
- m1 = projectionMatrix[1],
5755
- m2 = projectionMatrix[2],
5756
- m3 = projectionMatrix[3],
5757
- m4 = projectionMatrix[4],
5758
- m5 = projectionMatrix[5],
5759
- m6 = projectionMatrix[6],
5760
- m7 = projectionMatrix[7],
5761
- m8 = projectionMatrix[8],
5762
- m9 = projectionMatrix[9],
5763
- m10 = projectionMatrix[10],
5764
- m11 = projectionMatrix[11],
5765
- m12 = projectionMatrix[12],
5766
- m13 = projectionMatrix[13],
5767
- m14 = projectionMatrix[14],
5768
- m15 = projectionMatrix[15];
5769
- // right
5770
- set$1(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
5771
- this.planes[0].distance = m15 - m12;
5772
- // left
5773
- set$1(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
5774
- this.planes[1].distance = m15 + m12;
5775
- // bottom
5776
- set$1(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
5777
- this.planes[2].distance = m15 + m13;
5778
- // top
5779
- set$1(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
5780
- this.planes[3].distance = m15 - m13;
5781
- // far
5782
- set$1(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
5783
- this.planes[4].distance = m15 - m14;
5784
- // near
5785
- set$1(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
5786
- this.planes[5].distance = m15 + m14;
5787
- this.planes.forEach(function (plane) {
5788
- plane.normalize();
5789
- plane.updatePNVertexFlag();
5790
- });
5791
- };
5792
- return Frustum;
5793
- }();
5794
-
5795
- var Point = /*#__PURE__*/function () {
5796
- function Point(x, y) {
5797
- if (x === void 0) {
5798
- x = 0;
5799
- }
5800
- if (y === void 0) {
5801
- y = 0;
5802
- }
5803
- this.x = 0;
5804
- this.y = 0;
5805
- this.x = x;
5806
- this.y = y;
5807
- }
5808
- var _proto = Point.prototype;
5809
- _proto.clone = function clone() {
5810
- return new Point(this.x, this.y);
5811
- };
5812
- _proto.copyFrom = function copyFrom(p) {
5813
- this.x = p.x;
5814
- this.y = p.y;
5815
- };
5816
- return Point;
5817
- }();
5818
-
5819
- var Rectangle = /*#__PURE__*/function () {
5820
- function Rectangle(x, y, width, height) {
5821
- this.x = void 0;
5822
- this.y = void 0;
5823
- this.width = void 0;
5824
- this.height = void 0;
5825
- this.left = void 0;
5826
- this.right = void 0;
5827
- this.top = void 0;
5828
- this.bottom = void 0;
5829
- this.x = x;
5830
- this.y = y;
5831
- this.width = width;
5832
- this.height = height;
5833
- this.left = x;
5834
- this.right = x + width;
5835
- this.top = y;
5836
- this.bottom = y + height;
5837
- }
5838
- var _proto = Rectangle.prototype;
5839
- _proto.toJSON = function toJSON() {};
5840
- return Rectangle;
5841
- }();
5842
-
5843
- (function (Shape) {
5844
- Shape["GROUP"] = "g";
5845
- Shape["CIRCLE"] = "circle";
5846
- Shape["ELLIPSE"] = "ellipse";
5847
- Shape["IMAGE"] = "image";
5848
- Shape["RECT"] = "rect";
5849
- Shape["LINE"] = "line";
5850
- Shape["POLYLINE"] = "polyline";
5851
- Shape["POLYGON"] = "polygon";
5852
- Shape["TEXT"] = "text";
5853
- Shape["PATH"] = "path";
5854
- Shape["HTML"] = "html";
5855
- Shape["MESH"] = "mesh";
5856
- })(exports.Shape || (exports.Shape = {}));
5857
-
5858
- function memoize(func, resolver) {
5859
- if (typeof func !== 'function' || resolver != null && typeof resolver !== 'function') {
5860
- throw new TypeError('Expected a function');
5861
- }
5862
- var memoized = function memoized() {
5863
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5864
- args[_key] = arguments[_key];
5865
- }
5866
- var key = resolver ? resolver.apply(this, args) : args[0];
5867
- var cache = memoized.cache;
5868
- if (cache.has(key)) {
5869
- return cache.get(key);
5870
- }
5871
- var result = func.apply(this, args);
5872
- memoized.cache = cache.set(key, result) || cache;
5873
- return result;
5874
- };
5875
- memoized.cache = new (memoize.Cache || Map)();
5876
- return memoized;
5877
- }
5878
- memoize.Cache = Map;
5879
-
5880
- var camelCase = memoize(function (str) {
5881
- if (str === void 0) {
5882
- str = '';
5883
- }
5884
- return str.replace(/-([a-z])/g, function (g) {
5885
- return g[1].toUpperCase();
5886
- });
5887
- });
5473
+ return str.replace(/-([a-z])/g, function (g) {
5474
+ return g[1].toUpperCase();
5475
+ });
5476
+ });
5888
5477
 
5889
5478
  function DCHECK(bool) {
5890
5479
  if (!bool) {
5891
5480
  throw new Error();
5892
5481
  }
5893
5482
  }
5894
- function DCHECK_EQ(a, b) {
5895
- if (a !== b) {
5896
- throw new Error();
5897
- }
5898
- }
5899
- function DCHECK_NE(a, b) {
5900
- if (a === b) {
5901
- throw new Error();
5902
- }
5903
- }
5904
5483
  function isFunction(func) {
5905
5484
  return typeof func === 'function';
5906
5485
  }
@@ -7143,568 +6722,25 @@
7143
6722
  return CSSKeywordValue;
7144
6723
  }(CSSStyleValue);
7145
6724
 
7146
- var CSSMathOperator;
7147
- (function (CSSMathOperator) {
7148
- CSSMathOperator["kAdd"] = "+";
7149
- CSSMathOperator["kSubtract"] = "-";
7150
- CSSMathOperator["kMultiply"] = "*";
7151
- CSSMathOperator["kDivide"] = "/";
7152
- CSSMathOperator["kMin"] = "min";
7153
- CSSMathOperator["kMax"] = "max";
7154
- CSSMathOperator["kClamp"] = "clamp";
7155
- CSSMathOperator["kInvalid"] = "";
7156
- })(CSSMathOperator || (CSSMathOperator = {}));
7157
-
7158
- // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
7159
- var BaseType;
7160
- (function (BaseType) {
7161
- BaseType[BaseType["kLength"] = 0] = "kLength";
7162
- BaseType[BaseType["kAngle"] = 1] = "kAngle";
7163
- BaseType[BaseType["kTime"] = 2] = "kTime";
7164
- BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
7165
- BaseType[BaseType["kResolution"] = 4] = "kResolution";
7166
- BaseType[BaseType["kFlex"] = 5] = "kFlex";
7167
- BaseType[BaseType["kPercent"] = 6] = "kPercent";
7168
- BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
7169
- })(BaseType || (BaseType = {}));
7170
- function unitTypeToBaseType(unit) {
7171
- DCHECK_NE(unit, exports.UnitType.kNumber);
7172
- switch (unit) {
7173
- case exports.UnitType.kEms:
7174
- // case UnitType.kExs:
7175
- case exports.UnitType.kPixels:
7176
- // case UnitType.kCentimeters:
7177
- // case UnitType.kMillimeters:
7178
- // case UnitType.kQuarterMillimeters:
7179
- // case UnitType.kInches:
7180
- // case UnitType.kPoints:
7181
- // case UnitType.kPicas:
7182
- // case UnitType.kUserUnits:
7183
- // case UnitType.kViewportWidth:
7184
- // case UnitType.kViewportHeight:
7185
- // case UnitType.kViewportInlineSize:
7186
- // case UnitType.kViewportBlockSize:
7187
- // case UnitType.kViewportMin:
7188
- // case UnitType.kViewportMax:
7189
- // case UnitType.kSmallViewportWidth:
7190
- // case UnitType.kSmallViewportHeight:
7191
- // case UnitType.kSmallViewportInlineSize:
7192
- // case UnitType.kSmallViewportBlockSize:
7193
- // case UnitType.kSmallViewportMin:
7194
- // case UnitType.kSmallViewportMax:
7195
- // case UnitType.kLargeViewportWidth:
7196
- // case UnitType.kLargeViewportHeight:
7197
- // case UnitType.kLargeViewportInlineSize:
7198
- // case UnitType.kLargeViewportBlockSize:
7199
- // case UnitType.kLargeViewportMin:
7200
- // case UnitType.kLargeViewportMax:
7201
- // case UnitType.kDynamicViewportWidth:
7202
- // case UnitType.kDynamicViewportHeight:
7203
- // case UnitType.kDynamicViewportInlineSize:
7204
- // case UnitType.kDynamicViewportBlockSize:
7205
- // case UnitType.kDynamicViewportMin:
7206
- // case UnitType.kDynamicViewportMax:
7207
- // case UnitType.kContainerWidth:
7208
- // case UnitType.kContainerHeight:
7209
- // case UnitType.kContainerInlineSize:
7210
- // case UnitType.kContainerBlockSize:
7211
- // case UnitType.kContainerMin:
7212
- // case UnitType.kContainerMax:
7213
- case exports.UnitType.kRems:
7214
- // case UnitType.kChs:
7215
- return BaseType.kLength;
7216
- case exports.UnitType.kMilliseconds:
7217
- case exports.UnitType.kSeconds:
7218
- return BaseType.kTime;
7219
- case exports.UnitType.kDegrees:
7220
- case exports.UnitType.kRadians:
7221
- case exports.UnitType.kGradians:
7222
- case exports.UnitType.kTurns:
7223
- return BaseType.kAngle;
7224
- // case UnitType.kHertz:
7225
- // case UnitType.kKilohertz:
7226
- // return BaseType.kFrequency;
7227
- // case UnitType.kDotsPerPixel:
7228
- // case UnitType.kDotsPerInch:
7229
- // case UnitType.kDotsPerCentimeter:
7230
- // return BaseType.kResolution;
7231
- // case UnitType.kFraction:
7232
- // return BaseType.kFlex;
7233
- case exports.UnitType.kPercentage:
7234
- return BaseType.kPercent;
7235
- default:
7236
- return BaseType.kLength;
7237
- }
7238
- }
7239
- function baseTypeToString(baseType) {
7240
- switch (baseType) {
7241
- case BaseType.kLength:
7242
- return 'length';
7243
- case BaseType.kAngle:
7244
- return 'angle';
7245
- case BaseType.kTime:
7246
- return 'time';
7247
- case BaseType.kFrequency:
7248
- return 'frequency';
7249
- case BaseType.kResolution:
7250
- return 'resolution';
7251
- case BaseType.kFlex:
7252
- return 'flex';
7253
- case BaseType.kPercent:
7254
- return 'percent';
7255
- }
7256
- return '';
7257
- }
7258
- var CSSNumericValueType = /*#__PURE__*/function () {
7259
- function CSSNumericValueType(unit, exponent) {
7260
- if (unit === void 0) {
7261
- unit = exports.UnitType.kNumber;
7262
- }
7263
- if (exponent === void 0) {
7264
- exponent = 1;
7265
- }
7266
- this.exponents = [];
7267
- this.numNonZeroEntries = 0;
7268
- this.percentHint = BaseType.kPercent;
7269
- this.hasPercentHint = false;
7270
- this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
7271
- if (unit !== exports.UnitType.kNumber) {
7272
- this.setExponent(unitTypeToBaseType(unit), exponent);
7273
- }
7274
- }
7275
- var _proto = CSSNumericValueType.prototype;
7276
- _proto.applyPercentHint = function applyPercentHint(hint) {
7277
- DCHECK_NE(hint, BaseType.kPercent);
7278
- this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
7279
- this.setExponent(BaseType.kPercent, 0);
7280
- this.percentHint = hint;
7281
- this.hasPercentHint = true;
7282
- };
7283
- _proto.hasNonZeroEntries = function hasNonZeroEntries() {
7284
- return this.numNonZeroEntries > 0;
7285
- };
7286
- _proto.isOnlyNonZeroEntry = function isOnlyNonZeroEntry(baseType, value) {
7287
- DCHECK_NE(value, 0);
7288
- return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
7289
- };
7290
- _proto.exponent = function exponent(type) {
7291
- return this.exponents[type];
7292
- };
7293
- _proto.setExponent = function setExponent(type, newValue) {
7294
- var oldValue = this.exponents[type];
7295
- if (oldValue == 0 && newValue !== 0) {
7296
- this.numNonZeroEntries++;
7297
- } else if (oldValue !== 0 && newValue == 0) {
7298
- this.numNonZeroEntries--;
7299
- }
7300
- this.exponents[type] = newValue;
7301
- };
7302
- CSSNumericValueType.negateExponents = function negateExponents(type) {
7303
- type.exponents.forEach(function (v) {
7304
- return v *= -1;
7305
- });
7306
- return type;
7307
- };
7308
- _proto.matchesBaseType = function matchesBaseType(baseType) {
7309
- DCHECK_NE(baseType, BaseType.kPercent);
7310
- return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
7311
- };
7312
- _proto.matchesPercentage = function matchesPercentage() {
7313
- return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
7314
- };
7315
- _proto.matchesBaseTypePercentage = function matchesBaseTypePercentage(baseType) {
7316
- DCHECK_NE(baseType, BaseType.kPercent);
7317
- return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
7318
- };
7319
- _proto.matchesNumber = function matchesNumber() {
7320
- return !this.hasNonZeroEntries() && !this.hasPercentHint;
7321
- };
7322
- _proto.matchesNumberPercentage = function matchesNumberPercentage() {
7323
- return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
7324
- };
7325
- CSSNumericValueType.add = function add(type1, type2, error) {
7326
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
7327
- return type1;
7328
- }
7329
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
7330
- DCHECK_EQ(type1.percentHint, type2.percentHint);
7331
- // Match up base types. Try to use the percent hint to match up any
7332
- // differences.
7333
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
7334
- var base_type = i;
7335
- if (type1.exponents[i] !== type2.exponents[i]) {
7336
- if (base_type !== BaseType.kPercent) {
7337
- type1.applyPercentHint(base_type);
7338
- type2.applyPercentHint(base_type);
7339
- }
7340
- if (type1.exponents[i] !== type2.exponents[i]) {
7341
- return type1;
7342
- }
7343
- }
7344
- }
7345
- return type1;
7346
- };
7347
- CSSNumericValueType.multiply = function multiply(type1, type2, error) {
7348
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
7349
- return type1;
7350
- }
7351
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
7352
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
7353
- var base_type = i;
7354
- type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
7355
- }
7356
- return type1;
7357
- };
7358
- return CSSNumericValueType;
7359
- }();
7360
- var fromNumberish = function fromNumberish(value) {
7361
- if (typeof value === 'number') {
7362
- return new CSSUnitValue(value, exports.UnitType.kNumber);
7363
- }
7364
- return value;
7365
- };
7366
- /**
7367
- * CSSNumericValue is the base class for numeric and length typed CSS Values.
7368
- * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
7369
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue
7370
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl
7371
- */
7372
- var CSSNumericValue = /*#__PURE__*/function (_CSSStyleValue) {
7373
- _inheritsLoose(CSSNumericValue, _CSSStyleValue);
7374
- /**
7375
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#296
7376
- */
7377
- // static fromPercentish(value: CSSNumberish): CSSNumericValue {
7378
- // if (typeof value === 'number') {
7379
- // return new CSSUnitValue(value * 100, UnitType.kPercentage);
7380
- // }
7381
- // return value;
7382
- // }
7383
- function CSSNumericValue(type_) {
7384
- var _this;
7385
- _this = _CSSStyleValue.call(this) || this;
7386
- _this.type_ = void 0;
7387
- _this.type_ = type_;
7388
- return _this;
7389
- }
7390
- var _proto2 = CSSNumericValue.prototype;
7391
- _proto2.getType = function getType() {
7392
- return CSSStyleValueType.kUnknownType;
7393
- }
7394
- // toCSSValue() {
7395
- // return null;
7396
- // }
7397
- /**
7398
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/equals
7399
- */;
7400
- _proto2.equals = function equals() {
7401
- var _this2 = this;
7402
- for (var _len = arguments.length, numberishes = new Array(_len), _key = 0; _key < _len; _key++) {
7403
- numberishes[_key] = arguments[_key];
7404
- }
7405
- var values = cssNumberishesToNumericValues(numberishes);
7406
- return values.every(function (value) {
7407
- return _this2.equals(value);
7408
- });
7409
- }
7410
- /**
7411
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#439
7412
- */;
7413
- _proto2.add = function add() {
7414
- for (var _len2 = arguments.length, numberishes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
7415
- numberishes[_key2] = arguments[_key2];
7416
- }
7417
- var values = cssNumberishesToNumericValues(numberishes);
7418
- prependValueForArithmetic(CSSStyleValueType.kSumType, values, this);
7419
- // eg. 1px + 2px = 3px
7420
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kAdd);
7421
- if (unitValue) {
7422
- return unitValue;
7423
- }
7424
- return CSSMathSum.create(values);
7425
- }
7426
- /**
7427
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#452
7428
- */;
7429
- _proto2.sub = function sub() {
7430
- for (var _len3 = arguments.length, numberishes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
7431
- numberishes[_key3] = arguments[_key3];
7432
- }
7433
- var values = cssNumberishesToNumericValues(numberishes);
7434
- values = values.map(function (value) {
7435
- return value.negate();
7436
- });
7437
- prependValueForArithmetic(CSSStyleValueType.kSumType, values, this);
7438
- // eg. 3px - 2px = 1px
7439
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kAdd);
7440
- if (unitValue) {
7441
- return unitValue;
7442
- }
7443
- return CSSMathSum.create(values);
7444
- }
7445
- /**
7446
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/mul
7447
- */;
7448
- _proto2.mul = function mul() {
7449
- for (var _len4 = arguments.length, numberishes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
7450
- numberishes[_key4] = arguments[_key4];
7451
- }
7452
- var values = cssNumberishesToNumericValues(numberishes);
7453
- prependValueForArithmetic(CSSStyleValueType.kProductType, values, this);
7454
- var unitValue = maybeMultiplyAsUnitValue(values);
7455
- if (unitValue) {
7456
- return unitValue;
7457
- }
7458
- return CSSMathProduct.create(values);
7459
- }
7460
- /**
7461
- * eg. calc(24px / 4%)
7462
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/div
7463
- */;
7464
- _proto2.div = function div() {
7465
- for (var _len5 = arguments.length, numberishes = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
7466
- numberishes[_key5] = arguments[_key5];
7467
- }
7468
- var values = cssNumberishesToNumericValues(numberishes);
7469
- values = values.map(function (value) {
7470
- return value.invert();
7471
- });
7472
- prependValueForArithmetic(CSSStyleValueType.kProductType, values, this);
7473
- var unitValue = maybeMultiplyAsUnitValue(values);
7474
- if (unitValue) {
7475
- return unitValue;
7476
- }
7477
- return CSSMathProduct.create(values);
7478
- };
7479
- _proto2.min = function min() {
7480
- for (var _len6 = arguments.length, numberishes = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
7481
- numberishes[_key6] = arguments[_key6];
7482
- }
7483
- var values = cssNumberishesToNumericValues(numberishes);
7484
- prependValueForArithmetic(CSSStyleValueType.kMinType, values, this);
7485
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kMin);
7486
- if (unitValue) {
7487
- return unitValue;
7488
- }
7489
- return CSSMathMin.create(values);
7490
- };
7491
- _proto2.max = function max() {
7492
- for (var _len7 = arguments.length, numberishes = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
7493
- numberishes[_key7] = arguments[_key7];
7494
- }
7495
- var values = cssNumberishesToNumericValues(numberishes);
7496
- prependValueForArithmetic(CSSStyleValueType.kMaxType, values, this);
7497
- var unitValue = maybeSimplifyAsUnitValue(values, CSSMathOperator.kMax);
7498
- if (unitValue) {
7499
- return unitValue;
7500
- }
7501
- return CSSMathMax.create(values);
7502
- }
7503
- /**
7504
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/to
7505
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#331
7506
- */;
7507
- _proto2.to = function to(unitOrName) {
7508
- var sum = this.sumValue();
7509
- if (sum.length === 0 || sum.length !== 1) return null;
7510
- var value = cssNumericSumValueEntryToUnitValue(sum[0]);
7511
- if (!value) return null;
7512
- var unit;
7513
- if (typeof unitOrName === 'string') {
7514
- unit = unitFromName(unitOrName);
7515
- } else {
7516
- unit = unitOrName;
7517
- }
7518
- return value.convertTo(unit);
7519
- }
7520
- /**
7521
- * converts the object's value to a CSSMathSum object to values of the specified unit.
7522
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/toSum
7523
- */;
7524
- _proto2.toSum = function toSum() {
7525
- for (var _len8 = arguments.length, unit_strings = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
7526
- unit_strings[_key8] = arguments[_key8];
7527
- }
7528
- for (var _i = 0, _unit_strings = unit_strings; _i < _unit_strings.length; _i++) {
7529
- var unit_string = _unit_strings[_i];
7530
- if (!CSSNumericValue.isValidUnit(unitFromName(unit_string))) {
7531
- return null;
7532
- }
7533
- }
7534
- var sum = this.sumValue();
7535
- if (!sum.length) {
7536
- return null;
7537
- }
7538
- var values = [];
7539
- for (var _iterator = _createForOfIteratorHelperLoose(sum), _step; !(_step = _iterator()).done;) {
7540
- var term = _step.value;
7541
- var value = cssNumericSumValueEntryToUnitValue(term);
7542
- if (!value) {
7543
- return null;
7544
- }
7545
- values.push(value);
7546
- }
7547
- if (unit_strings.length === 0) {
7548
- values.sort(function (a, b) {
7549
- return a.unit - b.unit;
7550
- });
7551
- // We got 'values' from a sum value, so it must be a valid CSSMathSum.
7552
- var _result = CSSMathSum.create(values);
7553
- DCHECK(!!_result);
7554
- return _result;
7555
- }
7556
- var result = [];
7557
- var _loop = function _loop() {
7558
- var unit_string = _unit_strings2[_i2];
7559
- var target_unit = unitFromName(unit_string);
7560
- DCHECK(CSSNumericValue.isValidUnit(target_unit));
7561
- // Collect all the terms that are compatible with this unit.
7562
- // We mark used terms as null so we don't use them again.
7563
- var total_value = values.reduce(function (cur_sum, value, i) {
7564
- if (value) {
7565
- var unit_value = value;
7566
- var converted_value = unit_value.convertTo(target_unit);
7567
- if (converted_value) {
7568
- cur_sum += converted_value.value;
7569
- values[i] = null;
7570
- }
7571
- }
7572
- return cur_sum;
7573
- }, 0);
7574
- result.push(new CSSUnitValue(total_value, target_unit));
7575
- };
7576
- for (var _i2 = 0, _unit_strings2 = unit_strings; _i2 < _unit_strings2.length; _i2++) {
7577
- _loop();
7578
- }
7579
- if (values.some(function (v) {
7580
- return !!v;
7581
- })) {
7582
- throw new Error('There were leftover terms that were not converted');
7583
- }
7584
- return CSSMathSum.create(result);
7585
- }
7586
- /**
7587
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/type
7588
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.cc#414
7589
- */;
7590
- _proto2.type = function type() {
7591
- var type = {
7592
- length: 0,
7593
- angle: 0,
7594
- time: 0,
7595
- frequency: 0,
7596
- resolution: 0,
7597
- flex: 0,
7598
- percent: 0,
7599
- percentHint: 'length'
7600
- };
7601
- var exponent = this.type_.exponent(BaseType.kLength);
7602
- if (exponent) {
7603
- type.length = exponent;
7604
- }
7605
- exponent = this.type_.exponent(BaseType.kAngle);
7606
- if (exponent) {
7607
- type.angle = exponent;
7608
- }
7609
- exponent = this.type_.exponent(BaseType.kTime);
7610
- if (exponent) {
7611
- type.time = exponent;
7612
- }
7613
- exponent = this.type_.exponent(BaseType.kFrequency);
7614
- if (exponent) {
7615
- type.frequency = exponent;
7616
- }
7617
- exponent = this.type_.exponent(BaseType.kResolution);
7618
- if (exponent) {
7619
- type.resolution = exponent;
7620
- }
7621
- exponent = this.type_.exponent(BaseType.kFlex);
7622
- if (exponent) {
7623
- type.flex = exponent;
7624
- }
7625
- exponent = this.type_.exponent(BaseType.kPercent);
7626
- if (exponent) {
7627
- type.percent = exponent;
7628
- }
7629
- if (this.type_.hasPercentHint) {
7630
- type.percentHint = baseTypeToString(this.type_.percentHint);
7631
- }
7632
- return type;
7633
- };
7634
- CSSNumericValue.isValidUnit = function isValidUnit(unit) {
7635
- // if (unit === UnitType.kUserUnits) return false;
7636
- if (unit === exports.UnitType.kNumber || unit == exports.UnitType.kPercentage || this.isLength(unit) || this.isAngle(unit) || this.isTime(unit)
7637
- // this.isFrequency(unit) ||
7638
- // this.isResolution(unit) ||
7639
- // this.isFlex(unit)
7640
- ) return true;
7641
- return false;
7642
- };
7643
- _proto2.negate = function negate() {
7644
- return CSSMathNegate.create(this);
7645
- };
7646
- _proto2.invert = function invert() {
7647
- return CSSMathInvert.create(this);
7648
- };
7649
- return CSSNumericValue;
7650
- }(CSSStyleValue);
7651
- function cssNumberishesToNumericValues(values) {
7652
- return values.map(fromNumberish);
7653
- }
7654
- function prependValueForArithmetic(type, values, value) {
7655
- DCHECK(!!value);
7656
- if (value.getType() === type) {
7657
- values.unshift.apply(values, value.numericValues());
7658
- } else {
7659
- values.unshift(value);
7660
- }
7661
- }
7662
- function cssNumericSumValueEntryToUnitValue(term) {
7663
- if (Object.keys(term.units).length === 0) {
7664
- return new CSSUnitValue(term.value);
7665
- }
7666
- if (Object.keys(term.units).length === 1 && term.units[Object.keys(term.units)[0]] === 1) {
7667
- return new CSSUnitValue(term.value, Number(Object.keys(term.units)[0]));
7668
- }
7669
- return null;
7670
- }
7671
- function maybeSimplifyAsUnitValue(values, operator) {
7672
- DCHECK(!!values.length);
7673
- var first_unit_value = values[0] instanceof CSSUnitValue ? values[0] : null;
7674
- if (!first_unit_value) return null;
7675
- var final_value = first_unit_value.value;
7676
- for (var i = 1; i < values.length; i++) {
7677
- var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
7678
- if (!unit_value || unit_value.unit !== first_unit_value.unit) return null;
7679
- if (operator === CSSMathOperator.kAdd) {
7680
- final_value += unit_value.value;
7681
- } else if (operator === CSSMathOperator.kMax) {
7682
- final_value = Math.max(final_value, unit_value.value);
7683
- } else if (operator === CSSMathOperator.kMin) {
7684
- final_value = Math.min(final_value, unit_value.value);
7685
- }
7686
- }
7687
- return new CSSUnitValue(final_value, first_unit_value.unit);
7688
- }
7689
- function maybeMultiplyAsUnitValue(values) {
7690
- DCHECK(!!values.length);
7691
- // We are allowed one unit value with type other than kNumber.
7692
- var unit_other_than_number = exports.UnitType.kNumber;
7693
- var final_value = 1.0;
7694
- for (var i = 0; i < values.length; i++) {
7695
- var unit_value = values[i] instanceof CSSUnitValue ? values[i] : null;
7696
- if (!unit_value) return null;
7697
- if (unit_value.unit !== exports.UnitType.kNumber) {
7698
- if (unit_other_than_number !== exports.UnitType.kNumber) return null;
7699
- unit_other_than_number = unit_value.unit;
7700
- }
7701
- final_value *= unit_value.value;
7702
- }
7703
- return new CSSUnitValue(final_value, unit_other_than_number);
7704
- }
7705
- var toCanonicalUnit = function toCanonicalUnit(unit) {
7706
- return canonicalUnitTypeForCategory(unitTypeToUnitCategory(unit));
7707
- };
6725
+ // type CSSNumericBaseType =
6726
+ // | 'length'
6727
+ // | 'angle'
6728
+ // | 'time'
6729
+ // | 'frequency'
6730
+ // | 'resolution'
6731
+ // | 'flex'
6732
+ // | 'percent';
6733
+ // https://drafts.css-houdini.org/css-typed-om/#dictdef-cssnumerictype
6734
+ // interface CSSNumericType {
6735
+ // length: number;
6736
+ // angle: number;
6737
+ // time: number;
6738
+ // frequency: number;
6739
+ // resolution: number;
6740
+ // flex: number;
6741
+ // percent: number;
6742
+ // percentHint: CSSNumericBaseType;
6743
+ // }
7708
6744
  var formatInfinityOrNaN = function formatInfinityOrNaN(number, suffix) {
7709
6745
  if (suffix === void 0) {
7710
6746
  suffix = '';
@@ -7718,49 +6754,52 @@
7718
6754
  }
7719
6755
  return result += suffix;
7720
6756
  };
7721
- var toCanonicalUnitIfPossible = function toCanonicalUnitIfPossible(unit) {
7722
- var canonical_unit = toCanonicalUnit(unit);
7723
- if (canonical_unit === exports.UnitType.kUnknown) return unit;
7724
- return canonical_unit;
6757
+ var toCanonicalUnit = function toCanonicalUnit(unit) {
6758
+ return canonicalUnitTypeForCategory(unitTypeToUnitCategory(unit));
7725
6759
  };
6760
+ /**
6761
+ * CSSNumericValue is the base class for numeric and length typed CSS Values.
6762
+ * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
6763
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue
6764
+ * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl
6765
+ */
7726
6766
  /**
7727
6767
  * Represents numeric values that can be expressed as a single number plus a
7728
6768
  * unit (or a naked number or percentage).
7729
6769
  * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
7730
6770
  */
7731
- var CSSUnitValue = /*#__PURE__*/function (_CSSNumericValue) {
7732
- _inheritsLoose(CSSUnitValue, _CSSNumericValue);
7733
- // static fromCSSValue(value: CSSNumericLiteralValue) {
7734
- // let unit = value.type;
7735
- // if (unit === UnitType.kInteger) unit = UnitType.kNumber;
7736
- // if (!this.isValidUnit(unit)) return null;
7737
- // return new CSSUnitValue(value.getDoubleValue(), unit);
7738
- // }
7739
-
6771
+ var CSSUnitValue = /*#__PURE__*/function (_CSSStyleValue) {
6772
+ _inheritsLoose(CSSUnitValue, _CSSStyleValue);
7740
6773
  function CSSUnitValue(value, unitOrName) {
7741
- var _this3;
6774
+ var _this;
7742
6775
  if (unitOrName === void 0) {
7743
6776
  unitOrName = exports.UnitType.kNumber;
7744
6777
  }
6778
+ _this = _CSSStyleValue.call(this) || this;
6779
+ _this.unit = void 0;
6780
+ _this.value = void 0;
7745
6781
  var unit;
7746
6782
  if (typeof unitOrName === 'string') {
7747
6783
  unit = unitFromName(unitOrName);
7748
6784
  } else {
7749
6785
  unit = unitOrName;
7750
6786
  }
7751
- // DCHECK(CSSUnitValue.isValidUnit(unit));
7752
- _this3 = _CSSNumericValue.call(this, new CSSNumericValueType(unit)) || this;
7753
- _this3.unit = void 0;
7754
- _this3.value = void 0;
7755
- _this3.unit = unit;
7756
- _this3.value = value;
7757
- return _this3;
6787
+ _this.unit = unit;
6788
+ _this.value = value;
6789
+ return _this;
7758
6790
  }
7759
- var _proto3 = CSSUnitValue.prototype;
7760
- _proto3.clone = function clone() {
6791
+ var _proto = CSSUnitValue.prototype;
6792
+ _proto.clone = function clone() {
7761
6793
  return new CSSUnitValue(this.value, this.unit);
7762
6794
  };
7763
- _proto3.convertTo = function convertTo(target_unit) {
6795
+ _proto.equals = function equals(other) {
6796
+ var other_unit_value = other;
6797
+ return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
6798
+ };
6799
+ _proto.getType = function getType() {
6800
+ return CSSStyleValueType.kUnitType;
6801
+ };
6802
+ _proto.convertTo = function convertTo(target_unit) {
7764
6803
  if (this.unit === target_unit) {
7765
6804
  return new CSSUnitValue(this.value, this.unit);
7766
6805
  }
@@ -7774,46 +6813,7 @@
7774
6813
  var scale_factor = conversionToCanonicalUnitsScaleFactor(this.unit) / conversionToCanonicalUnitsScaleFactor(target_unit);
7775
6814
  return new CSSUnitValue(this.value * scale_factor, target_unit);
7776
6815
  };
7777
- _proto3.equals = function equals(other) {
7778
- var other_unit_value = other;
7779
- return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
7780
- };
7781
- _proto3.getType = function getType() {
7782
- return CSSStyleValueType.kUnitType;
7783
- }
7784
- // toCSSValue() {
7785
- // return new CSSNumericLiteralValue(this.value, this.unit);
7786
- // }
7787
- // // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
7788
- // toCalcExpressionNode() {
7789
- // return CSSMathExpressionNumericLiteral.create(
7790
- // new CSSNumericLiteralValue(this.value, this.unit),
7791
- // );
7792
- // }
7793
- ;
7794
- _proto3.sumValue = function sumValue() {
7795
- var sum = [];
7796
- var unit_map = {};
7797
- if (this.unit !== exports.UnitType.kNumber) {
7798
- unit_map[toCanonicalUnitIfPossible(this.unit)] = 1;
7799
- }
7800
- sum.push({
7801
- value: this.value * conversionToCanonicalUnitsScaleFactor(this.unit),
7802
- units: unit_map
7803
- });
7804
- return sum;
7805
- };
7806
- _proto3.negate = function negate() {
7807
- return new CSSUnitValue(-this.value, this.unit);
7808
- };
7809
- _proto3.invert = function invert() {
7810
- if (this.unit === exports.UnitType.kNumber) {
7811
- if (this.value === 0) return null;
7812
- return new CSSUnitValue(1.0 / this.value, this.unit);
7813
- }
7814
- return CSSMathInvert.create(this);
7815
- };
7816
- _proto3.buildCSSText = function buildCSSText(n, p, result) {
6816
+ _proto.buildCSSText = function buildCSSText(n, p, result) {
7817
6817
  var text;
7818
6818
  switch (this.unit) {
7819
6819
  case exports.UnitType.kUnknown:
@@ -7848,12 +6848,7 @@
7848
6848
  // case UnitType.kHertz:
7849
6849
  // case UnitType.kKilohertz:
7850
6850
  case exports.UnitType.kTurns:
7851
- // 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:
7852
- // case UnitType.kContainerWidth:
7853
- // case UnitType.kContainerHeight:
7854
- // case UnitType.kContainerInlineSize:
7855
- // case UnitType.kContainerBlockSize:
7856
- // case UnitType.kContainerMin:
6851
+ // 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:
7857
6852
  // case UnitType.kContainerMax: {
7858
6853
  {
7859
6854
  var kMinInteger = -999999;
@@ -7876,504 +6871,7 @@
7876
6871
  return result;
7877
6872
  };
7878
6873
  return CSSUnitValue;
7879
- }(CSSNumericValue);
7880
- /**
7881
- * The CSSMathValue interface of the CSS_Object_Model a base class for classes representing complex numeric values.
7882
- *
7883
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue
7884
- * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_math_value.idl
7885
- */
7886
- var CSSMathValue = /*#__PURE__*/function (_CSSNumericValue2) {
7887
- _inheritsLoose(CSSMathValue, _CSSNumericValue2);
7888
- function CSSMathValue() {
7889
- return _CSSNumericValue2.apply(this, arguments) || this;
7890
- }
7891
- var _proto4 = CSSMathValue.prototype;
7892
- // From CSSNumericValue
7893
- _proto4.isUnitValue = function isUnitValue() {
7894
- return false;
7895
- };
7896
- return CSSMathValue;
7897
- }(CSSNumericValue);
7898
- var CSSMathInvert = /*#__PURE__*/function (_CSSMathValue) {
7899
- _inheritsLoose(CSSMathInvert, _CSSMathValue);
7900
- CSSMathInvert.create = function create(value) {
7901
- var type = CSSNumericValueType.negateExponents(value.type_);
7902
- return new CSSMathInvert(value, type);
7903
- };
7904
- function CSSMathInvert(value, type) {
7905
- var _this4;
7906
- _this4 = _CSSMathValue.call(this, type) || this;
7907
- _this4.value = void 0;
7908
- _this4.operator = 'invert';
7909
- _this4.value = value;
7910
- return _this4;
7911
- }
7912
- var _proto5 = CSSMathInvert.prototype;
7913
- _proto5.clone = function clone() {
7914
- return new CSSMathInvert(this.value, this.type_);
7915
- };
7916
- _proto5.getType = function getType() {
7917
- return CSSStyleValueType.kInvertType;
7918
- };
7919
- _proto5.equals = function equals(other) {
7920
- if (other.getType() !== CSSStyleValueType.kInvertType) {
7921
- return false;
7922
- }
7923
- // We can safely cast here as we know 'other' has the same type as us.
7924
- var other_invert = other;
7925
- return this.value.equals(other_invert.value);
7926
- };
7927
- _proto5.sumValue = function sumValue() {
7928
- var sum = this.value.sumValue();
7929
- if (sum.length === 0 || sum.length !== 1 || sum[0].value === 0) {
7930
- return null;
7931
- }
7932
- Object.keys(sum[0].units).forEach(function (key) {
7933
- sum[0].units[key] *= -1;
7934
- });
7935
- sum[0].value = 1.0 / sum[0].value;
7936
- return sum;
7937
- }
7938
- // toCalcExpressionNode(): CSSMathExpressionNode {
7939
- // const right_side = this.value.toCalcExpressionNode();
7940
- // if (!right_side) {
7941
- // return null;
7942
- // }
7943
- // // return CSSMathExpressionOperation::CreateArithmeticOperation(
7944
- // // CSSMathExpressionNumericLiteral::Create(
7945
- // // 1, UnitType.kNumber),
7946
- // // right_side, CSSMathOperator.kDivide);
7947
- // return null;
7948
- // }
7949
- ;
7950
- _proto5.buildCSSText = function buildCSSText(nested, paren_less, result) {
7951
- if (paren_less == ParenLess.kNo) {
7952
- result += nested === Nested.kYes ? '(' : 'calc(';
7953
- }
7954
- result += '1 / ';
7955
- result = this.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
7956
- if (paren_less === ParenLess.kNo) {
7957
- result += ')';
7958
- }
7959
- return result;
7960
- };
7961
- return CSSMathInvert;
7962
- }(CSSMathValue);
7963
- var CSSMathNegate = /*#__PURE__*/function (_CSSMathValue2) {
7964
- _inheritsLoose(CSSMathNegate, _CSSMathValue2);
7965
- CSSMathNegate.create = function create(value) {
7966
- return new CSSMathNegate(value, value.type_);
7967
- };
7968
- function CSSMathNegate(value, type) {
7969
- var _this5;
7970
- _this5 = _CSSMathValue2.call(this, type) || this;
7971
- _this5.value = void 0;
7972
- _this5.operator = 'negate';
7973
- _this5.value = value;
7974
- return _this5;
7975
- }
7976
- var _proto6 = CSSMathNegate.prototype;
7977
- _proto6.clone = function clone() {
7978
- return new CSSMathNegate(this.value, this.type_);
7979
- };
7980
- _proto6.getType = function getType() {
7981
- return CSSStyleValueType.kNegateType;
7982
- };
7983
- _proto6.equals = function equals(other) {
7984
- if (other.getType() !== CSSStyleValueType.kNegateType) {
7985
- return false;
7986
- }
7987
- var other_invert = other;
7988
- return this.value.equals(other_invert.value);
7989
- };
7990
- _proto6.sumValue = function sumValue() {
7991
- var sum = this.value.sumValue();
7992
- if (sum.length === 0) {
7993
- return null;
7994
- }
7995
- sum.forEach(function (term) {
7996
- term.value *= -1;
7997
- });
7998
- return sum;
7999
- }
8000
- // toCalcExpressionNode(): CSSMathExpressionNode {
8001
- // const right_side = this.value.toCalcExpressionNode();
8002
- // if (!right_side) {
8003
- // return null;
8004
- // }
8005
- // // return CSSMathExpressionOperation::CreateArithmeticOperationSimplified(
8006
- // // CSSMathExpressionNumericLiteral::Create(
8007
- // // -1, CSSPrimitiveValue::UnitType::kNumber),
8008
- // // right_side, CSSMathOperator::kMultiply);
8009
- // }
8010
- ;
8011
- _proto6.buildCSSText = function buildCSSText(nested, paren_less, result) {
8012
- if (paren_less == ParenLess.kNo) {
8013
- result += nested === Nested.kYes ? '(' : 'calc(';
8014
- }
8015
- result += '-';
8016
- result = this.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
8017
- if (paren_less === ParenLess.kNo) {
8018
- result += ')';
8019
- }
8020
- return result;
8021
- };
8022
- return CSSMathNegate;
8023
- }(CSSMathValue);
8024
- function typeCheck(values, op, error) {
8025
- error = false;
8026
- var final_type = values[0].type_;
8027
- for (var i = 1; i < values.length; i++) {
8028
- final_type = op(final_type, values[i].type_, error);
8029
- if (error) return final_type;
8030
- }
8031
- return final_type;
8032
- }
8033
- // Represents an arithmetic operation with one or more CSSNumericValues.
8034
- var CSSMathVariadic = /*#__PURE__*/function (_CSSMathValue3) {
8035
- _inheritsLoose(CSSMathVariadic, _CSSMathValue3);
8036
- function CSSMathVariadic(values, type) {
8037
- var _this6;
8038
- _this6 = _CSSMathValue3.call(this, type) || this;
8039
- _this6.values = void 0;
8040
- _this6.values = values;
8041
- return _this6;
8042
- }
8043
- var _proto7 = CSSMathVariadic.prototype;
8044
- _proto7.numericValues = function numericValues() {
8045
- return this.values;
8046
- };
8047
- _proto7.equals = function equals(other) {
8048
- if (this.getType() !== other.getType()) {
8049
- return false;
8050
- }
8051
- return this.values.every(function (value, i) {
8052
- return value.equals(other.values[i]);
8053
- });
8054
- };
8055
- return CSSMathVariadic;
8056
- }(CSSMathValue);
8057
- // Represents the minimum of one or more CSSNumericValues.
8058
- // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
8059
- var CSSMathMin = /*#__PURE__*/function (_CSSMathVariadic) {
8060
- _inheritsLoose(CSSMathMin, _CSSMathVariadic);
8061
- function CSSMathMin() {
8062
- var _this7;
8063
- for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
8064
- args[_key9] = arguments[_key9];
8065
- }
8066
- _this7 = _CSSMathVariadic.call.apply(_CSSMathVariadic, [this].concat(args)) || this;
8067
- _this7.operator = 'min';
8068
- return _this7;
8069
- }
8070
- CSSMathMin.create = function create(values) {
8071
- var error = false;
8072
- var final_type = typeCheck(values, CSSNumericValueType.add, error);
8073
- return new CSSMathMin(values, final_type);
8074
- };
8075
- var _proto8 = CSSMathMin.prototype;
8076
- _proto8.clone = function clone() {
8077
- return new CSSMathMin(this.values, this.type_);
8078
- };
8079
- _proto8.getType = function getType() {
8080
- return CSSStyleValueType.kMinType;
8081
- };
8082
- _proto8.sumValue = function sumValue() {
8083
- var cur_min = this.numericValues()[0].sumValue();
8084
- if (!cur_min.length) {
8085
- return null;
8086
- }
8087
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.numericValues()), _step2; !(_step2 = _iterator2()).done;) {
8088
- var value = _step2.value;
8089
- var child_sum = value.sumValue();
8090
- if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_min[0].units)) {
8091
- return null;
8092
- }
8093
- if (child_sum[0].value < cur_min[0].value) {
8094
- cur_min = child_sum;
8095
- }
8096
- }
8097
- return cur_min;
8098
- }
8099
- // toCalcExpressionNode() {
8100
- // const operands: CSSMathExpressionOperation[] = [];
8101
- // for (const value of this.numericValues()) {
8102
- // const operand = value.toCalcExpressionNode();
8103
- // if (!operand) {
8104
- // continue;
8105
- // }
8106
- // operands.push(operand as CSSMathExpressionOperation);
8107
- // }
8108
- // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMin);
8109
- // }
8110
- ;
8111
- _proto8.buildCSSText = function buildCSSText(nested, paren_less, result) {
8112
- result += 'min(';
8113
- var first_iteration = true;
8114
- for (var _iterator3 = _createForOfIteratorHelperLoose(this.numericValues()), _step3; !(_step3 = _iterator3()).done;) {
8115
- var value = _step3.value;
8116
- if (!first_iteration) result += ', ';
8117
- first_iteration = false;
8118
- result = value.buildCSSText(Nested.kYes, ParenLess.kYes, result);
8119
- }
8120
- result += ')';
8121
- return result;
8122
- };
8123
- return CSSMathMin;
8124
- }(CSSMathVariadic);
8125
- // Represents the maximum of one or more CSSNumericValues.
8126
- // @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
8127
- var CSSMathMax = /*#__PURE__*/function (_CSSMathVariadic2) {
8128
- _inheritsLoose(CSSMathMax, _CSSMathVariadic2);
8129
- function CSSMathMax() {
8130
- var _this8;
8131
- for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
8132
- args[_key10] = arguments[_key10];
8133
- }
8134
- _this8 = _CSSMathVariadic2.call.apply(_CSSMathVariadic2, [this].concat(args)) || this;
8135
- _this8.operator = 'max';
8136
- return _this8;
8137
- }
8138
- CSSMathMax.create = function create(values) {
8139
- var error = false;
8140
- var final_type = typeCheck(values, CSSNumericValueType.add, error);
8141
- return new CSSMathMax(values, final_type);
8142
- };
8143
- var _proto9 = CSSMathMax.prototype;
8144
- _proto9.clone = function clone() {
8145
- return new CSSMathMax(this.values, this.type_);
8146
- };
8147
- _proto9.getType = function getType() {
8148
- return CSSStyleValueType.kMaxType;
8149
- };
8150
- _proto9.sumValue = function sumValue() {
8151
- var cur_max = this.numericValues()[0].sumValue();
8152
- if (!cur_max.length) {
8153
- return null;
8154
- }
8155
- for (var _iterator4 = _createForOfIteratorHelperLoose(this.numericValues()), _step4; !(_step4 = _iterator4()).done;) {
8156
- var value = _step4.value;
8157
- var child_sum = value.sumValue();
8158
- if (!child_sum.length || JSON.stringify(child_sum[0].units) !== JSON.stringify(cur_max[0].units)) {
8159
- return null;
8160
- }
8161
- if (child_sum[0].value < cur_max[0].value) {
8162
- cur_max = child_sum;
8163
- }
8164
- }
8165
- return cur_max;
8166
- }
8167
- // toCalcExpressionNode() {
8168
- // const operands: CSSMathExpressionOperation[] = [];
8169
- // for (const value of this.numericValues()) {
8170
- // const operand = value.toCalcExpressionNode();
8171
- // if (!operand) {
8172
- // continue;
8173
- // }
8174
- // operands.push(operand as CSSMathExpressionOperation);
8175
- // }
8176
- // return CSSMathExpressionOperation.createComparisonFunction(operands, CSSMathOperator.kMax);
8177
- // }
8178
- ;
8179
- _proto9.buildCSSText = function buildCSSText(nested, paren_less, result) {
8180
- result += 'max(';
8181
- var first_iteration = true;
8182
- for (var _iterator5 = _createForOfIteratorHelperLoose(this.numericValues()), _step5; !(_step5 = _iterator5()).done;) {
8183
- var value = _step5.value;
8184
- if (!first_iteration) result += ', ';
8185
- first_iteration = false;
8186
- result = value.buildCSSText(Nested.kYes, ParenLess.kYes, result);
8187
- }
8188
- result += ')';
8189
- return result;
8190
- };
8191
- return CSSMathMax;
8192
- }(CSSMathVariadic);
8193
- /**
8194
- * Represents the sum of one or more CSSNumericValues.
8195
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathsum
8196
- */
8197
- var CSSMathSum = /*#__PURE__*/function (_CSSMathVariadic3) {
8198
- _inheritsLoose(CSSMathSum, _CSSMathVariadic3);
8199
- function CSSMathSum() {
8200
- var _this9;
8201
- for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
8202
- args[_key11] = arguments[_key11];
8203
- }
8204
- _this9 = _CSSMathVariadic3.call.apply(_CSSMathVariadic3, [this].concat(args)) || this;
8205
- _this9.operator = 'sum';
8206
- return _this9;
8207
- }
8208
- CSSMathSum.create = function create(values) {
8209
- var error = false;
8210
- var finalType = typeCheck(values, CSSNumericValueType.add, error);
8211
- return new CSSMathSum(values, finalType);
8212
- };
8213
- CSSMathSum.numericTypeFromUnitMap = function numericTypeFromUnitMap(units) {
8214
- var type = new CSSNumericValueType();
8215
- Object.keys(units).forEach(function (key) {
8216
- var exp = units[key];
8217
- var error = false;
8218
- type = CSSNumericValueType.multiply(type, new CSSNumericValueType(Number(key), exp), error);
8219
- DCHECK(!error);
8220
- });
8221
- return type;
8222
- };
8223
- CSSMathSum.canCreateNumericTypeFromSumValue = function canCreateNumericTypeFromSumValue(sum) {
8224
- var _this10 = this;
8225
- DCHECK(!!sum.length);
8226
- var first_type = this.numericTypeFromUnitMap(sum[0].units);
8227
- return sum.every(function (term) {
8228
- var error = false;
8229
- CSSNumericValueType.add(first_type, _this10.numericTypeFromUnitMap(term.units), error);
8230
- return !error;
8231
- });
8232
- };
8233
- var _proto10 = CSSMathSum.prototype;
8234
- _proto10.clone = function clone() {
8235
- return new CSSMathSum(this.values, this.type_);
8236
- };
8237
- _proto10.getType = function getType() {
8238
- return CSSStyleValueType.kSumType;
8239
- }
8240
- // toCalcExpressionNode() {
8241
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kAdd);
8242
- // }
8243
- ;
8244
- _proto10.sumValue = function sumValue() {
8245
- var sum = [];
8246
- this.numericValues().forEach(function (value) {
8247
- var child_sum = value.sumValue();
8248
- if (!child_sum.length) {
8249
- return null;
8250
- }
8251
- child_sum.forEach(function (term) {
8252
- var index = sum.findIndex(function (s) {
8253
- return JSON.stringify(s.units) === JSON.stringify(term.units);
8254
- });
8255
- if (index === -1) {
8256
- sum.push(_extends({}, term));
8257
- } else {
8258
- sum[index].value += term.value;
8259
- }
8260
- });
8261
- });
8262
- if (!CSSMathSum.canCreateNumericTypeFromSumValue(sum)) return null;
8263
- return sum;
8264
- };
8265
- _proto10.buildCSSText = function buildCSSText(nested, paren_less, result) {
8266
- if (paren_less == ParenLess.kNo) {
8267
- result += nested === Nested.kYes ? '(' : 'calc(';
8268
- }
8269
- var values = this.numericValues();
8270
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
8271
- for (var i = 1; i < values.length; i++) {
8272
- var arg = values[i];
8273
- if (arg.getType() === CSSStyleValueType.kNegateType) {
8274
- result += ' - ';
8275
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
8276
- } else {
8277
- result += ' + ';
8278
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
8279
- }
8280
- }
8281
- if (paren_less === ParenLess.kNo) {
8282
- result += ')';
8283
- }
8284
- return result;
8285
- };
8286
- return CSSMathSum;
8287
- }(CSSMathVariadic);
8288
- /**
8289
- * Represents the product of one or more CSSNumericValues.
8290
- * @see https://drafts.css-houdini.org/css-typed-om/#cssmathproduct
8291
- */
8292
- var CSSMathProduct = /*#__PURE__*/function (_CSSMathVariadic4) {
8293
- _inheritsLoose(CSSMathProduct, _CSSMathVariadic4);
8294
- function CSSMathProduct() {
8295
- var _this11;
8296
- for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
8297
- args[_key12] = arguments[_key12];
8298
- }
8299
- _this11 = _CSSMathVariadic4.call.apply(_CSSMathVariadic4, [this].concat(args)) || this;
8300
- _this11.operator = 'product';
8301
- return _this11;
8302
- }
8303
- CSSMathProduct.create = function create(values) {
8304
- var error = false;
8305
- var finalType = typeCheck(values, CSSNumericValueType.multiply, error);
8306
- return new CSSMathProduct(values, finalType);
8307
- };
8308
- CSSMathProduct.multiplyUnitMaps = function multiplyUnitMaps(a, b) {
8309
- Object.keys(b).forEach(function (key) {
8310
- DCHECK_NE(b[key].value, 0);
8311
- var old_value = key in a ? a[key].value : 0;
8312
- if (old_value + b[key].value === 0) {
8313
- delete a[key];
8314
- } else {
8315
- a[key] = old_value + b[key].value;
8316
- }
8317
- });
8318
- return a;
8319
- };
8320
- var _proto11 = CSSMathProduct.prototype;
8321
- _proto11.clone = function clone() {
8322
- return new CSSMathProduct(this.values, this.type_);
8323
- };
8324
- _proto11.getType = function getType() {
8325
- return CSSStyleValueType.kProductType;
8326
- }
8327
- // toCalcExpressionNode() {
8328
- // return this.toCalcExporessionNodeForVariadic(CSSMathOperator.kMultiply);
8329
- // }
8330
- ;
8331
- _proto11.sumValue = function sumValue() {
8332
- var sum = [{
8333
- value: 1,
8334
- units: {}
8335
- }];
8336
- this.numericValues().forEach(function (value) {
8337
- var child_sum = value.sumValue();
8338
- if (!child_sum.length) {
8339
- return null;
8340
- }
8341
- var new_sum = [];
8342
- sum.forEach(function (a) {
8343
- child_sum.forEach(function (b) {
8344
- new_sum.push({
8345
- value: a.value * b.value,
8346
- units: CSSMathProduct.multiplyUnitMaps(a.units, b.units)
8347
- });
8348
- });
8349
- });
8350
- sum = new_sum;
8351
- });
8352
- return sum;
8353
- };
8354
- _proto11.buildCSSText = function buildCSSText(nested, paren_less, result) {
8355
- if (paren_less == ParenLess.kNo) {
8356
- result += nested === Nested.kYes ? '(' : 'calc(';
8357
- }
8358
- var values = this.numericValues();
8359
- result = values[0].buildCSSText(Nested.kYes, ParenLess.kNo, result);
8360
- for (var i = 1; i < values.length; i++) {
8361
- var arg = values[i];
8362
- if (arg.getType() === CSSStyleValueType.kInvertType) {
8363
- result += ' / ';
8364
- result = arg.value.buildCSSText(Nested.kYes, ParenLess.kNo, result);
8365
- } else {
8366
- result += ' * ';
8367
- result = arg.buildCSSText(Nested.kYes, ParenLess.kNo, result);
8368
- }
8369
- }
8370
- if (paren_less === ParenLess.kNo) {
8371
- result += ')';
8372
- }
8373
- return result;
8374
- };
8375
- return CSSMathProduct;
8376
- }(CSSMathVariadic);
6874
+ }(CSSStyleValue);
8377
6875
  var Opx = new CSSUnitValue(0, 'px');
8378
6876
  var Lpx = new CSSUnitValue(1, 'px');
8379
6877
  var Odeg = new CSSUnitValue(0, 'deg');
@@ -8555,17 +7053,20 @@
8555
7053
  }, function (r, g, b, a) {
8556
7054
  return "rgba(" + r + "," + g + "," + b + "," + a + ")";
8557
7055
  });
8558
- var getOrCreateUnitValue = memoize(function (value, unitOrName) {
7056
+ // export const getOrCreateUnitValue = memoize(
7057
+ // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
7058
+ // return new CSSUnitValue(value, unitOrName);
7059
+ // },
7060
+ // (value: number, unitOrName: UnitType | string = UnitType.kNumber) => {
7061
+ // return `${value}${unitOrName}`;
7062
+ // },
7063
+ // );
7064
+ var getOrCreateUnitValue = function getOrCreateUnitValue(value, unitOrName) {
8559
7065
  if (unitOrName === void 0) {
8560
7066
  unitOrName = exports.UnitType.kNumber;
8561
7067
  }
8562
7068
  return new CSSUnitValue(value, unitOrName);
8563
- }, function (value, unitOrName) {
8564
- if (unitOrName === void 0) {
8565
- unitOrName = exports.UnitType.kNumber;
8566
- }
8567
- return "" + value + unitOrName;
8568
- });
7069
+ };
8569
7070
 
8570
7071
  function define(constructor, factory, prototype) {
8571
7072
  constructor.prototype = factory.prototype = prototype;
@@ -9069,7 +7570,7 @@
9069
7570
  var steps = colorStops.map(function (colorStop) {
9070
7571
  // TODO: only support % for now, should calc percentage of axis length when using px/em
9071
7572
  return {
9072
- offset: getOrCreateUnitValue(colorStop.length.value, '%'),
7573
+ offset: getOrCreateUnitValue(Number(colorStop.length.value), '%'),
9073
7574
  color: colorStopToString(colorStop)
9074
7575
  };
9075
7576
  });
@@ -9264,6 +7765,21 @@
9264
7765
  }];
9265
7766
  }
9266
7767
 
7768
+ (function (Shape) {
7769
+ Shape["GROUP"] = "g";
7770
+ Shape["CIRCLE"] = "circle";
7771
+ Shape["ELLIPSE"] = "ellipse";
7772
+ Shape["IMAGE"] = "image";
7773
+ Shape["RECT"] = "rect";
7774
+ Shape["LINE"] = "line";
7775
+ Shape["POLYLINE"] = "polyline";
7776
+ Shape["POLYGON"] = "polygon";
7777
+ Shape["TEXT"] = "text";
7778
+ Shape["PATH"] = "path";
7779
+ Shape["HTML"] = "html";
7780
+ Shape["MESH"] = "mesh";
7781
+ })(exports.Shape || (exports.Shape = {}));
7782
+
9267
7783
  function parseDimension(unitRegExp, string) {
9268
7784
  if (isNil(string)) {
9269
7785
  return getOrCreateUnitValue(0, 'px');
@@ -9307,12 +7823,20 @@
9307
7823
  *
9308
7824
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length-percentage
9309
7825
  */
9310
- var parseLengthOrPercentage = memoize(function (css) {
7826
+ // export const parseLengthOrPercentage = memoize((css: string): CSSUnitValue => {
7827
+ // if (isNumber(css) || isFinite(Number(css))) {
7828
+ // return getOrCreateUnitValue(Number(css), 'px');
7829
+ // }
7830
+ // return parseDimension(new RegExp('px|%|em|rem', 'g'), css) as CSSUnitValue;
7831
+ // });
7832
+ var parseLengthOrPercentage = function parseLengthOrPercentage(css) {
9311
7833
  if (isNumber(css) || isFinite(Number(css))) {
9312
7834
  return getOrCreateUnitValue(Number(css), 'px');
7835
+ // return Number(css);
9313
7836
  }
7837
+
9314
7838
  return parseDimension(new RegExp('px|%|em|rem', 'g'), css);
9315
- });
7839
+ };
9316
7840
  var parseAngle = memoize(function (css) {
9317
7841
  return parseDimension(new RegExp('deg|rad|grad|turn', 'g'), css);
9318
7842
  });
@@ -11134,6 +9658,9 @@
11134
9658
  * CSS.percent(50) -> CSS.px(0.5 * parent.width)
11135
9659
  */
11136
9660
  _proto.calculator = function calculator(name, oldParsed, computed, object, registry) {
9661
+ if (isNumber(computed)) {
9662
+ return computed;
9663
+ }
11137
9664
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
11138
9665
  if (computed.unit === exports.UnitType.kPercentage) {
11139
9666
  // TODO: merge dimensions
@@ -11630,6 +10157,30 @@
11630
10157
  return CustomElementRegistry;
11631
10158
  }();
11632
10159
 
10160
+ var Point = /*#__PURE__*/function () {
10161
+ function Point(x, y) {
10162
+ if (x === void 0) {
10163
+ x = 0;
10164
+ }
10165
+ if (y === void 0) {
10166
+ y = 0;
10167
+ }
10168
+ this.x = 0;
10169
+ this.y = 0;
10170
+ this.x = x;
10171
+ this.y = y;
10172
+ }
10173
+ var _proto = Point.prototype;
10174
+ _proto.clone = function clone() {
10175
+ return new Point(this.x, this.y);
10176
+ };
10177
+ _proto.copyFrom = function copyFrom(p) {
10178
+ this.x = p.x;
10179
+ this.y = p.y;
10180
+ };
10181
+ return Point;
10182
+ }();
10183
+
11633
10184
  function isFederatedEvent(value) {
11634
10185
  return !!value.type;
11635
10186
  }
@@ -13063,16 +11614,26 @@
13063
11614
  dirtyFlag: false,
13064
11615
  localDirtyFlag: false,
13065
11616
  frozen: false,
13066
- localPosition: fromValues$2(0, 0, 0),
13067
- localRotation: fromValues$4(0, 0, 0, 1),
13068
- localScale: fromValues$2(1, 1, 1),
11617
+ // localPosition: vec3.fromValues(0, 0, 0),
11618
+ // localRotation: quat.fromValues(0, 0, 0, 1),
11619
+ // localScale: vec3.fromValues(1, 1, 1),
11620
+ // localTransform: mat4.create(),
11621
+ // localSkew: vec2.fromValues(0, 0),
11622
+ // position: vec3.fromValues(0, 0, 0),
11623
+ // rotation: quat.fromValues(0, 0, 0, 1),
11624
+ // scaling: vec3.fromValues(1, 1, 1),
11625
+ // worldTransform: mat4.create(),
11626
+ // origin: vec3.fromValues(0, 0, 0),
11627
+ localPosition: [0, 0, 0],
11628
+ localRotation: [0, 0, 0, 1],
11629
+ localScale: [1, 1, 1],
13069
11630
  localTransform: create$1(),
13070
- localSkew: fromValues$5(0, 0),
13071
- position: fromValues$2(0, 0, 0),
13072
- rotation: fromValues$4(0, 0, 0, 1),
13073
- scaling: fromValues$2(1, 1, 1),
11631
+ localSkew: [0, 0],
11632
+ position: [0, 0, 0],
11633
+ rotation: [0, 0, 0, 1],
11634
+ scaling: [1, 1, 1],
13074
11635
  worldTransform: create$1(),
13075
- origin: fromValues$2(0, 0, 0)
11636
+ origin: [0, 0, 0]
13076
11637
  };
13077
11638
  _this.sortable = {
13078
11639
  dirty: false,
@@ -13789,6 +12350,20 @@
13789
12350
  filter: [],
13790
12351
  shadowType: 'outer'
13791
12352
  };
12353
+ var DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = _extends({}, DEFAULT_PARSED_STYLE_PROPS, {
12354
+ opacity: 1,
12355
+ fillOpacity: 1,
12356
+ strokeOpacity: 1,
12357
+ visibility: 'visible',
12358
+ pointerEvents: 'auto',
12359
+ lineWidth: 1,
12360
+ lineCap: 'butt',
12361
+ lineJoin: 'miter',
12362
+ increasedLineWidthForHitTesting: 0,
12363
+ fillRule: 'nonzero'
12364
+ // TODO: transformOrigin
12365
+ });
12366
+
13792
12367
  var INHERITABLE_BASE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting'];
13793
12368
  var INHERITABLE_STYLE_PROPS = [].concat(INHERITABLE_BASE_STYLE_PROPS, ['fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']);
13794
12369
  /**
@@ -13843,7 +12418,13 @@
13843
12418
  }
13844
12419
  _this.nodeName = _this.config.type || exports.Shape.GROUP;
13845
12420
  // compatible with G 3.0
13846
- _this.config.style = _extends({}, _this.config.style, _this.config.attrs);
12421
+ _this.config.style = _this.config.style || _this.config.attrs || {};
12422
+ Object.assign(_this.config.style, _this.config.attrs);
12423
+ // this.config.style = {
12424
+ // // ...DEFAULT_STYLE_PROPS,
12425
+ // ...this.config.style,
12426
+ // ...this.config.attrs,
12427
+ // };
13847
12428
  if (_this.config.visible != null) {
13848
12429
  _this.config.style.visibility = _this.config.visible === false ? 'hidden' : 'visible';
13849
12430
  }
@@ -13851,8 +12432,10 @@
13851
12432
  _this.config.style.pointerEvents = _this.config.interactive === false ? 'none' : 'auto';
13852
12433
  }
13853
12434
  // merge parsed value
13854
- Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
13855
- Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12435
+ Object.assign(_this.parsedStyle, runtime.enableCSSParsing ? DEFAULT_PARSED_STYLE_PROPS : DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED, _this.config.initialParsedStyle);
12436
+ if (runtime.enableCSSParsing) {
12437
+ Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12438
+ }
13856
12439
  // start to process attributes
13857
12440
  _this.initAttributes(_this.config.style);
13858
12441
  _this.style = new Proxy(
@@ -13947,16 +12530,21 @@
13947
12530
  attributes = {};
13948
12531
  }
13949
12532
  var renderable = this.renderable;
13950
- // account for FCP, process properties as less as possible
13951
- runtime.styleValueRegistry.processProperties(this, attributes, {
13952
- forceUpdateGeometry: true,
13953
- usedAttributes: INHERITABLE_STYLE_PROPS
12533
+ var options = {
12534
+ forceUpdateGeometry: true
13954
12535
  // usedAttributes:
13955
12536
  // // only Group / Text should account for text relative props
13956
12537
  // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT
13957
12538
  // ? INHERITABLE_STYLE_PROPS
13958
12539
  // : INHERITABLE_BASE_STYLE_PROPS,
13959
- });
12540
+ };
12541
+
12542
+ if (runtime.enableCSSParsing) {
12543
+ // @ts-ignore
12544
+ options.usedAttributes = INHERITABLE_STYLE_PROPS;
12545
+ }
12546
+ // account for FCP, process properties as less as possible
12547
+ runtime.styleValueRegistry.processProperties(this, attributes, options);
13960
12548
  // redraw at next frame
13961
12549
  renderable.dirty = true;
13962
12550
  };
@@ -14691,7 +13279,11 @@
14691
13279
  var minX = clientRect.left - canvasRect.left;
14692
13280
  var minY = clientRect.top - canvasRect.top;
14693
13281
  var aabb = new AABB();
14694
- aabb.setMinMax(fromValues$2(minX, minY, 0), fromValues$2(minX + clientRect.width, minY + clientRect.height, 0));
13282
+ // aabb.setMinMax(
13283
+ // vec3.fromValues(minX, minY, 0),
13284
+ // vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0),
13285
+ // );
13286
+ aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
14695
13287
  return aabb;
14696
13288
  }
14697
13289
  return null;
@@ -15436,6 +14028,42 @@
15436
14028
  return Text;
15437
14029
  }(DisplayObject);
15438
14030
 
14031
+ function copyVec3(a, b) {
14032
+ a[0] = b[0];
14033
+ a[1] = b[1];
14034
+ a[2] = b[2];
14035
+ return a;
14036
+ }
14037
+ function subVec3(o, a, b) {
14038
+ o[0] = a[0] - b[0];
14039
+ o[1] = a[1] - b[1];
14040
+ o[2] = a[2] - b[2];
14041
+ return o;
14042
+ }
14043
+ function addVec3(o, a, b) {
14044
+ o[0] = a[0] + b[0];
14045
+ o[1] = a[1] + b[1];
14046
+ o[2] = a[2] + b[2];
14047
+ return o;
14048
+ }
14049
+ function scaleVec3(o, a, b) {
14050
+ o[0] = a[0] * b;
14051
+ o[1] = a[1] * b;
14052
+ o[2] = a[2] * b;
14053
+ return o;
14054
+ }
14055
+ function maxVec3(o, a, b) {
14056
+ o[0] = Math.max(a[0], b[0]);
14057
+ o[1] = Math.max(a[1], b[1]);
14058
+ o[2] = Math.max(a[2], b[2]);
14059
+ return o;
14060
+ }
14061
+ function minVec3(o, a, b) {
14062
+ o[0] = Math.min(a[0], b[0]);
14063
+ o[1] = Math.min(a[1], b[1]);
14064
+ o[2] = Math.min(a[2], b[2]);
14065
+ return o;
14066
+ }
15439
14067
  function getAngle$1(angle) {
15440
14068
  if (angle === undefined) {
15441
14069
  return 0;
@@ -15805,16 +14433,16 @@
15805
14433
  object.translateLocal(_newTranslation4[0].value, _newTranslation4[1].value, _newTranslation4[2].value);
15806
14434
  } else if (t === 'rotate') {
15807
14435
  var newAngles = d || [Odeg];
15808
- object.rotateLocal(0, 0, newAngles[0].value);
14436
+ object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
15809
14437
  } else if (t === 'rotatex') {
15810
14438
  var _newAngles = d || [Odeg];
15811
- object.rotateLocal(_newAngles[0].value, 0, 0);
14439
+ object.rotateLocal(convertAngleUnit(_newAngles[0]), 0, 0);
15812
14440
  } else if (t === 'rotatey') {
15813
14441
  var _newAngles2 = d || [Odeg];
15814
- object.rotateLocal(0, _newAngles2[0].value, 0);
14442
+ object.rotateLocal(0, convertAngleUnit(_newAngles2[0]), 0);
15815
14443
  } else if (t === 'rotatez') {
15816
14444
  var _newAngles3 = d || [Odeg];
15817
- object.rotateLocal(0, 0, _newAngles3[0].value);
14445
+ object.rotateLocal(0, 0, convertAngleUnit(_newAngles3[0]));
15818
14446
  } else if (t === 'rotate3d') ; else if (t === 'skew') {
15819
14447
  var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
15820
14448
  return s.value;
@@ -16288,10 +14916,10 @@
16288
14916
  yArr = yArr.filter(function (item) {
16289
14917
  return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
16290
14918
  });
16291
- var minX = min$1(xArr);
16292
- var minY = min$1(yArr);
16293
- var maxX = max$1(xArr);
16294
- var maxY = max$1(yArr);
14919
+ var minX = min(xArr);
14920
+ var minY = min(yArr);
14921
+ var maxX = max(xArr);
14922
+ var maxY = max(yArr);
16295
14923
  if (segmentsWithAngle.length === 0) {
16296
14924
  return {
16297
14925
  x: minX,
@@ -17853,90 +16481,483 @@
17853
16481
  if (!stringRegExp.test(_fontFamily) && genericFontFamilies.indexOf(_fontFamily) < 0) {
17854
16482
  _fontFamily = "\"" + _fontFamily + "\"";
17855
16483
  }
17856
- fontFamilies[i] = _fontFamily;
16484
+ fontFamilies[i] = _fontFamily;
16485
+ }
16486
+ return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
16487
+ }
16488
+
16489
+ /**
16490
+ * Thanks for following contributor of codes
16491
+ * https://gist.github.com/1866474
16492
+ * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
16493
+ * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
16494
+ * https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/requestAnimationFrame/polyfill.js
16495
+ **/
16496
+ var uId = 1;
16497
+ var uniqueId = function uniqueId() {
16498
+ return uId++;
16499
+ };
16500
+ // We use `self` instead of `window` for `WebWorker` support.
16501
+ var root = typeof self === 'object' && self.self == self ? self :
16502
+ // @ts-ignore
16503
+ typeof global === 'object' && global.global == global ?
16504
+ // @ts-ignore
16505
+ global : {};
16506
+ var nowOffset = Date.now();
16507
+ // use performance api if exist, otherwise use Date.now.
16508
+ // Date.now polyfill required.
16509
+ var pnow = function pnow() {
16510
+ if (root.performance && typeof root.performance.now === 'function') {
16511
+ return root.performance.now();
16512
+ }
16513
+ // fallback
16514
+ return Date.now() - nowOffset;
16515
+ };
16516
+ var reservedCBs = {};
16517
+ var lastTime = Date.now();
16518
+ var polyfillRaf = function polyfillRaf(callback) {
16519
+ if (typeof callback !== 'function') {
16520
+ throw new TypeError(callback + ' is not a function');
16521
+ }
16522
+ var currentTime = Date.now();
16523
+ var gap = currentTime - lastTime;
16524
+ var delay = gap > 16 ? 0 : 16 - gap;
16525
+ var id = uniqueId();
16526
+ reservedCBs[id] = callback;
16527
+ // keys(reservedCBs).length > 1 의미는 이미 setTimeout 이 걸려있는 경우.
16528
+ // 함께 callback 이 실행될 수 있게 reservedCBs 에만 추가해주고 return
16529
+ if (Object.keys(reservedCBs).length > 1) return id;
16530
+ setTimeout(function () {
16531
+ lastTime = currentTime;
16532
+ var copied = reservedCBs;
16533
+ reservedCBs = {};
16534
+ Object.keys(copied).forEach(function (key) {
16535
+ return copied[key](pnow());
16536
+ });
16537
+ }, delay);
16538
+ return id;
16539
+ };
16540
+ var polyfillCaf = function polyfillCaf(id) {
16541
+ delete reservedCBs[id];
16542
+ };
16543
+ var vendorPrefixes = ['', 'webkit', 'moz', 'ms', 'o'];
16544
+ var getRequestAnimationFrame = function getRequestAnimationFrame(vp) {
16545
+ if (typeof vp !== 'string') return polyfillRaf;
16546
+ if (vp === '') return root['requestAnimationFrame'];
16547
+ return root[vp + 'RequestAnimationFrame'];
16548
+ };
16549
+ var getCancelAnimationFrame = function getCancelAnimationFrame(vp) {
16550
+ if (typeof vp !== 'string') return polyfillCaf;
16551
+ if (vp === '') return root['cancelAnimationFrame'];
16552
+ return root[vp + 'CancelAnimationFrame'] || root[vp + 'CancelRequestAnimationFrame'];
16553
+ };
16554
+ var find = function find(arr, predicate) {
16555
+ var i = 0;
16556
+ while (arr[i] !== void 0) {
16557
+ if (predicate(arr[i])) return arr[i];
16558
+ i = i + 1;
16559
+ }
16560
+ };
16561
+ var vp = find(vendorPrefixes, function (vp) {
16562
+ return !!getRequestAnimationFrame(vp);
16563
+ });
16564
+ var raf = getRequestAnimationFrame(vp);
16565
+ var caf = getCancelAnimationFrame(vp);
16566
+ root.requestAnimationFrame = raf;
16567
+ root.cancelAnimationFrame = caf;
16568
+
16569
+ /**
16570
+ * Axis-Aligned Bounding Box
16571
+ * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
16572
+ * @see https://github.com/antvis/GWebGPUEngine/issues/3
16573
+ */
16574
+ var AABB = /*#__PURE__*/function () {
16575
+ AABB.isEmpty = function isEmpty(aabb) {
16576
+ return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
16577
+ };
16578
+ // center: vec3 = vec3.create();
16579
+ // halfExtents: vec3 = vec3.create();
16580
+ // min: vec3 = vec3.create();
16581
+ // max: vec3 = vec3.create();
16582
+ function AABB(center, halfExtents) {
16583
+ if (center === void 0) {
16584
+ center = [0, 0, 0];
16585
+ }
16586
+ if (halfExtents === void 0) {
16587
+ halfExtents = [0, 0, 0];
16588
+ }
16589
+ this.center = [0, 0, 0];
16590
+ this.halfExtents = [0, 0, 0];
16591
+ this.min = [0, 0, 0];
16592
+ this.max = [0, 0, 0];
16593
+ this.update(center, halfExtents);
16594
+ }
16595
+ var _proto = AABB.prototype;
16596
+ _proto.update = function update(center, halfExtents) {
16597
+ copyVec3(this.center, center);
16598
+ copyVec3(this.halfExtents, halfExtents);
16599
+ subVec3(this.min, this.center, this.halfExtents);
16600
+ addVec3(this.max, this.center, this.halfExtents);
16601
+ // vec3.copy(this.center, center);
16602
+ // vec3.copy(this.halfExtents, halfExtents);
16603
+ // vec3.sub(this.min, this.center, this.halfExtents);
16604
+ // vec3.add(this.max, this.center, this.halfExtents);
16605
+ };
16606
+ _proto.setMinMax = function setMinMax(min, max) {
16607
+ // vec3.add(this.center, max, min);
16608
+ // vec3.scale(this.center, this.center, 0.5);
16609
+ // vec3.sub(this.halfExtents, max, min);
16610
+ // vec3.scale(this.halfExtents, this.halfExtents, 0.5);
16611
+ // vec3.copy(this.min, min);
16612
+ // vec3.copy(this.max, max);
16613
+ addVec3(this.center, max, min);
16614
+ scaleVec3(this.center, this.center, 0.5);
16615
+ subVec3(this.halfExtents, max, min);
16616
+ scaleVec3(this.halfExtents, this.halfExtents, 0.5);
16617
+ copyVec3(this.min, min);
16618
+ copyVec3(this.max, max);
16619
+ };
16620
+ _proto.getMin = function getMin() {
16621
+ return this.min;
16622
+ };
16623
+ _proto.getMax = function getMax() {
16624
+ return this.max;
16625
+ };
16626
+ _proto.add = function add(aabb) {
16627
+ if (AABB.isEmpty(aabb)) {
16628
+ return;
16629
+ }
16630
+ if (AABB.isEmpty(this)) {
16631
+ this.setMinMax(aabb.getMin(), aabb.getMax());
16632
+ return;
16633
+ }
16634
+ var tc = this.center;
16635
+ var tcx = tc[0];
16636
+ var tcy = tc[1];
16637
+ var tcz = tc[2];
16638
+ var th = this.halfExtents;
16639
+ var thx = th[0];
16640
+ var thy = th[1];
16641
+ var thz = th[2];
16642
+ var tminx = tcx - thx;
16643
+ var tmaxx = tcx + thx;
16644
+ var tminy = tcy - thy;
16645
+ var tmaxy = tcy + thy;
16646
+ var tminz = tcz - thz;
16647
+ var tmaxz = tcz + thz;
16648
+ var oc = aabb.center;
16649
+ var ocx = oc[0];
16650
+ var ocy = oc[1];
16651
+ var ocz = oc[2];
16652
+ var oh = aabb.halfExtents;
16653
+ var ohx = oh[0];
16654
+ var ohy = oh[1];
16655
+ var ohz = oh[2];
16656
+ var ominx = ocx - ohx;
16657
+ var omaxx = ocx + ohx;
16658
+ var ominy = ocy - ohy;
16659
+ var omaxy = ocy + ohy;
16660
+ var ominz = ocz - ohz;
16661
+ var omaxz = ocz + ohz;
16662
+ if (ominx < tminx) {
16663
+ tminx = ominx;
16664
+ }
16665
+ if (omaxx > tmaxx) {
16666
+ tmaxx = omaxx;
16667
+ }
16668
+ if (ominy < tminy) {
16669
+ tminy = ominy;
16670
+ }
16671
+ if (omaxy > tmaxy) {
16672
+ tmaxy = omaxy;
16673
+ }
16674
+ if (ominz < tminz) {
16675
+ tminz = ominz;
16676
+ }
16677
+ if (omaxz > tmaxz) {
16678
+ tmaxz = omaxz;
16679
+ }
16680
+ tc[0] = (tminx + tmaxx) * 0.5;
16681
+ tc[1] = (tminy + tmaxy) * 0.5;
16682
+ tc[2] = (tminz + tmaxz) * 0.5;
16683
+ th[0] = (tmaxx - tminx) * 0.5;
16684
+ th[1] = (tmaxy - tminy) * 0.5;
16685
+ th[2] = (tmaxz - tminz) * 0.5;
16686
+ this.min[0] = tminx;
16687
+ this.min[1] = tminy;
16688
+ this.min[2] = tminz;
16689
+ this.max[0] = tmaxx;
16690
+ this.max[1] = tmaxy;
16691
+ this.max[2] = tmaxz;
16692
+ };
16693
+ _proto.setFromTransformedAABB = function setFromTransformedAABB(aabb, m) {
16694
+ var bc = this.center;
16695
+ var br = this.halfExtents;
16696
+ var ac = aabb.center;
16697
+ var ar = aabb.halfExtents;
16698
+ var mx0 = m[0];
16699
+ var mx1 = m[4];
16700
+ var mx2 = m[8];
16701
+ var my0 = m[1];
16702
+ var my1 = m[5];
16703
+ var my2 = m[9];
16704
+ var mz0 = m[2];
16705
+ var mz1 = m[6];
16706
+ var mz2 = m[10];
16707
+ var mx0a = Math.abs(mx0);
16708
+ var mx1a = Math.abs(mx1);
16709
+ var mx2a = Math.abs(mx2);
16710
+ var my0a = Math.abs(my0);
16711
+ var my1a = Math.abs(my1);
16712
+ var my2a = Math.abs(my2);
16713
+ var mz0a = Math.abs(mz0);
16714
+ var mz1a = Math.abs(mz1);
16715
+ var mz2a = Math.abs(mz2);
16716
+ bc[0] = m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2];
16717
+ bc[1] = m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2];
16718
+ bc[2] = m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2];
16719
+ // vec3.set(
16720
+ // bc,
16721
+ // m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2],
16722
+ // m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2],
16723
+ // m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2],
16724
+ // );
16725
+ br[0] = mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2];
16726
+ br[1] = my0a * ar[0] + my1a * ar[1] + my2a * ar[2];
16727
+ br[2] = mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2];
16728
+ // vec3.set(
16729
+ // br,
16730
+ // mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2],
16731
+ // my0a * ar[0] + my1a * ar[1] + my2a * ar[2],
16732
+ // mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2],
16733
+ // );
16734
+ // this.min = vec3.sub(this.min, bc, br);
16735
+ // this.max = vec3.add(this.max, bc, br);
16736
+ subVec3(this.min, bc, br);
16737
+ addVec3(this.max, bc, br);
16738
+ };
16739
+ _proto.intersects = function intersects(aabb) {
16740
+ var aMax = this.getMax();
16741
+ var aMin = this.getMin();
16742
+ var bMax = aabb.getMax();
16743
+ var bMin = aabb.getMin();
16744
+ 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];
16745
+ };
16746
+ _proto.intersection = function intersection(aabb) {
16747
+ if (!this.intersects(aabb)) {
16748
+ return null;
16749
+ }
16750
+ var intersection = new AABB();
16751
+ // const min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
16752
+ // const max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
16753
+ var min = maxVec3([0, 0, 0], this.getMin(), aabb.getMin());
16754
+ var max = minVec3([0, 0, 0], this.getMax(), aabb.getMax());
16755
+ intersection.setMinMax(min, max);
16756
+ return intersection;
17857
16757
  }
17858
- return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSizeString + " " + fontFamilies.join(',');
17859
- }
16758
+ // containsPoint(point: vec3) {
16759
+ // const min = this.getMin();
16760
+ // const max = this.getMax();
16761
+ // return !(
16762
+ // point[0] < min[0] ||
16763
+ // point[0] > max[0] ||
16764
+ // point[1] < min[1] ||
16765
+ // point[1] > max[1] ||
16766
+ // point[2] < min[2] ||
16767
+ // point[2] > max[2]
16768
+ // );
16769
+ // }
16770
+ /**
16771
+ * get n-vertex
16772
+ * @param plane plane of CullingVolume
16773
+ */;
16774
+ _proto.getNegativeFarPoint = function getNegativeFarPoint(plane) {
16775
+ if (plane.pnVertexFlag === 0x111) {
16776
+ return copyVec3([0, 0, 0], this.min);
16777
+ // return vec3.copy(vec3.create(), this.min);
16778
+ } else if (plane.pnVertexFlag === 0x110) {
16779
+ return [this.min[0], this.min[1], this.max[2]];
16780
+ // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
16781
+ } else if (plane.pnVertexFlag === 0x101) {
16782
+ return [this.min[0], this.max[1], this.min[2]];
16783
+ // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
16784
+ } else if (plane.pnVertexFlag === 0x100) {
16785
+ return [this.min[0], this.max[1], this.max[2]];
16786
+ // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
16787
+ } else if (plane.pnVertexFlag === 0x011) {
16788
+ return [this.max[0], this.min[1], this.min[2]];
16789
+ // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
16790
+ } else if (plane.pnVertexFlag === 0x010) {
16791
+ return [this.max[0], this.min[1], this.max[2]];
16792
+ // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
16793
+ } else if (plane.pnVertexFlag === 0x001) {
16794
+ return [this.max[0], this.max[1], this.min[2]];
16795
+ // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
16796
+ } else {
16797
+ return [this.max[0], this.max[1], this.max[2]];
16798
+ // return vec3.fromValues(this.max[0], this.max[1], this.max[2]);
16799
+ }
16800
+ }
16801
+ /**
16802
+ * get p-vertex
16803
+ * @param plane plane of CullingVolume
16804
+ */;
16805
+ _proto.getPositiveFarPoint = function getPositiveFarPoint(plane) {
16806
+ if (plane.pnVertexFlag === 0x111) {
16807
+ return copyVec3([0, 0, 0], this.max);
16808
+ // return vec3.copy(vec3.create(), this.max);
16809
+ } else if (plane.pnVertexFlag === 0x110) {
16810
+ return [this.max[0], this.max[1], this.min[2]];
16811
+ // return vec3.fromValues(this.max[0], this.max[1], this.min[2]);
16812
+ } else if (plane.pnVertexFlag === 0x101) {
16813
+ return [this.max[0], this.min[1], this.max[2]];
16814
+ // return vec3.fromValues(this.max[0], this.min[1], this.max[2]);
16815
+ } else if (plane.pnVertexFlag === 0x100) {
16816
+ return [this.max[0], this.min[1], this.min[2]];
16817
+ // return vec3.fromValues(this.max[0], this.min[1], this.min[2]);
16818
+ } else if (plane.pnVertexFlag === 0x011) {
16819
+ return [this.min[0], this.max[1], this.max[2]];
16820
+ // return vec3.fromValues(this.min[0], this.max[1], this.max[2]);
16821
+ } else if (plane.pnVertexFlag === 0x010) {
16822
+ return [this.min[0], this.max[1], this.min[2]];
16823
+ // return vec3.fromValues(this.min[0], this.max[1], this.min[2]);
16824
+ } else if (plane.pnVertexFlag === 0x001) {
16825
+ return [this.min[0], this.min[1], this.max[2]];
16826
+ // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
16827
+ } else {
16828
+ return [this.min[0], this.min[1], this.min[2]];
16829
+ // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
16830
+ }
16831
+ };
16832
+ return AABB;
16833
+ }();
17860
16834
 
17861
- /**
17862
- * Thanks for following contributor of codes
17863
- * https://gist.github.com/1866474
17864
- * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
17865
- * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
17866
- * https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/requestAnimationFrame/polyfill.js
17867
- **/
17868
- var uId = 1;
17869
- var uniqueId = function uniqueId() {
17870
- return uId++;
17871
- };
17872
- // We use `self` instead of `window` for `WebWorker` support.
17873
- var root = typeof self === 'object' && self.self == self ? self :
17874
- // @ts-ignore
17875
- typeof global === 'object' && global.global == global ?
17876
- // @ts-ignore
17877
- global : {};
17878
- var nowOffset = Date.now();
17879
- // use performance api if exist, otherwise use Date.now.
17880
- // Date.now polyfill required.
17881
- var pnow = function pnow() {
17882
- if (root.performance && typeof root.performance.now === 'function') {
17883
- return root.performance.now();
16835
+ var Plane = /*#__PURE__*/function () {
16836
+ /**
16837
+ * lookup table for p-vertex & n-vertex when doing frustum culling
16838
+ */
16839
+
16840
+ function Plane(distance, normal) {
16841
+ this.distance = void 0;
16842
+ this.normal = void 0;
16843
+ this.pnVertexFlag = void 0;
16844
+ this.distance = distance || 0;
16845
+ this.normal = normal || fromValues$2(0, 1, 0);
16846
+ this.updatePNVertexFlag();
17884
16847
  }
17885
- // fallback
17886
- return Date.now() - nowOffset;
17887
- };
17888
- var reservedCBs = {};
17889
- var lastTime = Date.now();
17890
- var polyfillRaf = function polyfillRaf(callback) {
17891
- if (typeof callback !== 'function') {
17892
- throw new TypeError(callback + ' is not a function');
16848
+ var _proto = Plane.prototype;
16849
+ _proto.updatePNVertexFlag = function updatePNVertexFlag() {
16850
+ this.pnVertexFlag = (Number(this.normal[0] >= 0) << 8) + (Number(this.normal[1] >= 0) << 4) + Number(this.normal[2] >= 0);
16851
+ };
16852
+ _proto.distanceToPoint = function distanceToPoint(point) {
16853
+ return dot(point, this.normal) - this.distance;
16854
+ };
16855
+ _proto.normalize = function normalize() {
16856
+ var invLen = 1 / len(this.normal);
16857
+ scale$1(this.normal, this.normal, invLen);
16858
+ this.distance *= invLen;
16859
+ };
16860
+ _proto.intersectsLine = function intersectsLine(start, end, point) {
16861
+ var d0 = this.distanceToPoint(start);
16862
+ var d1 = this.distanceToPoint(end);
16863
+ var t = d0 / (d0 - d1);
16864
+ var intersects = t >= 0 && t <= 1;
16865
+ if (intersects && point) {
16866
+ lerp(point, start, end, t);
16867
+ }
16868
+ return intersects;
16869
+ };
16870
+ return Plane;
16871
+ }();
16872
+
16873
+ (function (Mask) {
16874
+ Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
16875
+ Mask[Mask["INSIDE"] = 0] = "INSIDE";
16876
+ Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
16877
+ })(exports.Mask || (exports.Mask = {}));
16878
+ var Frustum = /*#__PURE__*/function () {
16879
+ function Frustum(planes) {
16880
+ this.planes = [];
16881
+ if (planes) {
16882
+ this.planes = planes;
16883
+ } else {
16884
+ for (var i = 0; i < 6; i++) {
16885
+ this.planes.push(new Plane());
16886
+ }
16887
+ }
17893
16888
  }
17894
- var currentTime = Date.now();
17895
- var gap = currentTime - lastTime;
17896
- var delay = gap > 16 ? 0 : 16 - gap;
17897
- var id = uniqueId();
17898
- reservedCBs[id] = callback;
17899
- // keys(reservedCBs).length > 1 의미는 이미 setTimeout 이 걸려있는 경우.
17900
- // 함께 callback 이 실행될 수 있게 reservedCBs 에만 추가해주고 return
17901
- if (Object.keys(reservedCBs).length > 1) return id;
17902
- setTimeout(function () {
17903
- lastTime = currentTime;
17904
- var copied = reservedCBs;
17905
- reservedCBs = {};
17906
- Object.keys(copied).forEach(function (key) {
17907
- return copied[key](pnow());
16889
+ /**
16890
+ * extract 6 planes from projectionMatrix
16891
+ * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
16892
+ */
16893
+ var _proto = Frustum.prototype;
16894
+ _proto.extractFromVPMatrix = function extractFromVPMatrix(projectionMatrix) {
16895
+ // @ts-ignore
16896
+ var m0 = projectionMatrix[0],
16897
+ m1 = projectionMatrix[1],
16898
+ m2 = projectionMatrix[2],
16899
+ m3 = projectionMatrix[3],
16900
+ m4 = projectionMatrix[4],
16901
+ m5 = projectionMatrix[5],
16902
+ m6 = projectionMatrix[6],
16903
+ m7 = projectionMatrix[7],
16904
+ m8 = projectionMatrix[8],
16905
+ m9 = projectionMatrix[9],
16906
+ m10 = projectionMatrix[10],
16907
+ m11 = projectionMatrix[11],
16908
+ m12 = projectionMatrix[12],
16909
+ m13 = projectionMatrix[13],
16910
+ m14 = projectionMatrix[14],
16911
+ m15 = projectionMatrix[15];
16912
+ // right
16913
+ set$1(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
16914
+ this.planes[0].distance = m15 - m12;
16915
+ // left
16916
+ set$1(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
16917
+ this.planes[1].distance = m15 + m12;
16918
+ // bottom
16919
+ set$1(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
16920
+ this.planes[2].distance = m15 + m13;
16921
+ // top
16922
+ set$1(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
16923
+ this.planes[3].distance = m15 - m13;
16924
+ // far
16925
+ set$1(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
16926
+ this.planes[4].distance = m15 - m14;
16927
+ // near
16928
+ set$1(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
16929
+ this.planes[5].distance = m15 + m14;
16930
+ this.planes.forEach(function (plane) {
16931
+ plane.normalize();
16932
+ plane.updatePNVertexFlag();
17908
16933
  });
17909
- }, delay);
17910
- return id;
17911
- };
17912
- var polyfillCaf = function polyfillCaf(id) {
17913
- delete reservedCBs[id];
17914
- };
17915
- var vendorPrefixes = ['', 'webkit', 'moz', 'ms', 'o'];
17916
- var getRequestAnimationFrame = function getRequestAnimationFrame(vp) {
17917
- if (typeof vp !== 'string') return polyfillRaf;
17918
- if (vp === '') return root['requestAnimationFrame'];
17919
- return root[vp + 'RequestAnimationFrame'];
17920
- };
17921
- var getCancelAnimationFrame = function getCancelAnimationFrame(vp) {
17922
- if (typeof vp !== 'string') return polyfillCaf;
17923
- if (vp === '') return root['cancelAnimationFrame'];
17924
- return root[vp + 'CancelAnimationFrame'] || root[vp + 'CancelRequestAnimationFrame'];
17925
- };
17926
- var find = function find(arr, predicate) {
17927
- var i = 0;
17928
- while (arr[i] !== void 0) {
17929
- if (predicate(arr[i])) return arr[i];
17930
- i = i + 1;
16934
+ };
16935
+ return Frustum;
16936
+ }();
16937
+
16938
+ var Rectangle = /*#__PURE__*/function () {
16939
+ function Rectangle(x, y, width, height) {
16940
+ this.x = void 0;
16941
+ this.y = void 0;
16942
+ this.width = void 0;
16943
+ this.height = void 0;
16944
+ this.left = void 0;
16945
+ this.right = void 0;
16946
+ this.top = void 0;
16947
+ this.bottom = void 0;
16948
+ this.x = x;
16949
+ this.y = y;
16950
+ this.width = width;
16951
+ this.height = height;
16952
+ this.left = x;
16953
+ this.right = x + width;
16954
+ this.top = y;
16955
+ this.bottom = y + height;
17931
16956
  }
17932
- };
17933
- var vp = find(vendorPrefixes, function (vp) {
17934
- return !!getRequestAnimationFrame(vp);
17935
- });
17936
- var raf = getRequestAnimationFrame(vp);
17937
- var caf = getCancelAnimationFrame(vp);
17938
- root.requestAnimationFrame = raf;
17939
- root.cancelAnimationFrame = caf;
16957
+ var _proto = Rectangle.prototype;
16958
+ _proto.toJSON = function toJSON() {};
16959
+ return Rectangle;
16960
+ }();
17940
16961
 
17941
16962
  /**
17942
16963
  * Blink used them in code generation(css_properties.json5)
@@ -18433,9 +17454,9 @@
18433
17454
  var propertyMetadataCache = {};
18434
17455
  var unresolvedProperties = new WeakMap();
18435
17456
  // const uniqueAttributeSet = new Set<string>();
18436
- var tmpVec3a = create$2();
18437
- var tmpVec3b = create$2();
18438
- var tmpVec3c = create$2();
17457
+ // const tmpVec3a = vec3.create();
17458
+ // const tmpVec3b = vec3.create();
17459
+ // const tmpVec3c = vec3.create();
18439
17460
  var isPropertyResolved = function isPropertyResolved(object, name) {
18440
17461
  var properties = unresolvedProperties.get(object);
18441
17462
  if (!properties || properties.length === 0) {
@@ -18485,6 +17506,25 @@
18485
17506
  usedAttributes: []
18486
17507
  };
18487
17508
  }
17509
+ if (!runtime.enableCSSParsing) {
17510
+ Object.assign(object.attributes, attributes);
17511
+ object.parsedStyle = Object.assign(object.parsedStyle, attributes);
17512
+ if (attributes.fill) {
17513
+ object.parsedStyle.fill = parseColor(attributes.fill);
17514
+ }
17515
+ if (attributes.stroke) {
17516
+ object.parsedStyle.stroke = parseColor(attributes.stroke);
17517
+ }
17518
+ // @ts-ignore
17519
+ if (attributes.cx || attributes.cy) {
17520
+ // @ts-ignore
17521
+ runtime.CSSPropertySyntaxFactory['<coordinate>'].postProcessor(object);
17522
+ }
17523
+ // console.log(object.parsedStyle);
17524
+ // console.log(attributes);
17525
+ this.updateGeometry(object);
17526
+ return;
17527
+ }
18488
17528
  var _options = options,
18489
17529
  skipUpdateAttribute = _options.skipUpdateAttribute,
18490
17530
  skipParse = _options.skipParse,
@@ -18546,7 +17586,7 @@
18546
17586
  _this2.postProcessProperty(name, object, attributeNames);
18547
17587
  }
18548
17588
  });
18549
- if (object.children.length) {
17589
+ if (runtime.enableCSSParsing && object.children.length) {
18550
17590
  attributeNames.forEach(function (name) {
18551
17591
  if (name in object.parsedStyle && _this2.isPropertyInheritable(name)) {
18552
17592
  // update children's inheritable
@@ -18740,7 +17780,13 @@
18740
17780
  var flipY = width < 0;
18741
17781
  var flipX = height < 0;
18742
17782
  // init with content box
18743
- var halfExtents = set$1(tmpVec3a, Math.abs(width) / 2, Math.abs(height) / 2, depth / 2);
17783
+ var halfExtents = [Math.abs(width) / 2, Math.abs(height) / 2, depth / 2];
17784
+ // const halfExtents = vec3.set(
17785
+ // tmpVec3a,
17786
+ // Math.abs(width) / 2,
17787
+ // Math.abs(height) / 2,
17788
+ // depth / 2,
17789
+ // );
18744
17790
  // anchor is center by default, don't account for lineWidth here
18745
17791
  var stroke = parsedStyle.stroke,
18746
17792
  lineWidth = parsedStyle.lineWidth,
@@ -18755,7 +17801,13 @@
18755
17801
  if (object.nodeName === exports.Shape.TEXT) {
18756
17802
  delete parsedStyle.anchor;
18757
17803
  }
18758
- var center = set$1(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);
17804
+ 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];
17805
+ // const center = vec3.set(
17806
+ // tmpVec3b,
17807
+ // ((1 - ((anchor && anchor[0]) || 0) * 2) * width) / 2 + offsetX,
17808
+ // ((1 - ((anchor && anchor[1]) || 0) * 2) * height) / 2 + offsetY,
17809
+ // (1 - ((anchor && anchor[2]) || 0) * 2) * halfExtents[2] + offsetZ,
17810
+ // );
18759
17811
  // update geometry's AABB
18760
17812
  geometry.contentBounds.update(center, halfExtents);
18761
17813
  // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
@@ -18772,8 +17824,15 @@
18772
17824
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) * expansion;
18773
17825
  // halfExtents[0] += halfLineWidth[0];
18774
17826
  // halfExtents[1] += halfLineWidth[1];
18775
- add$1(halfExtents, halfExtents, set$1(tmpVec3c, halfLineWidth, halfLineWidth, 0));
17827
+ halfExtents[0] += halfLineWidth;
17828
+ halfExtents[1] += halfLineWidth;
17829
+ // vec3.add(
17830
+ // halfExtents,
17831
+ // halfExtents,
17832
+ // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
17833
+ // );
18776
17834
  }
17835
+
18777
17836
  geometry.renderBounds.update(center, halfExtents);
18778
17837
  // account for shadow, only support constant value now
18779
17838
  if (shadowColor && shadowType && shadowType !== 'inner') {
@@ -18802,7 +17861,7 @@
18802
17861
  params = _ref.params;
18803
17862
  if (name === 'blur') {
18804
17863
  var blurRadius = params[0].value;
18805
- geometry.renderBounds.update(geometry.renderBounds.center, add$1(geometry.renderBounds.halfExtents, geometry.renderBounds.halfExtents, fromValues$2(blurRadius, blurRadius, 0)));
17864
+ geometry.renderBounds.update(geometry.renderBounds.center, addVec3(geometry.renderBounds.halfExtents, geometry.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
18806
17865
  } else if (name === 'drop-shadow') {
18807
17866
  var _shadowOffsetX = params[0].value;
18808
17867
  var _shadowOffsetY = params[1].value;
@@ -18823,8 +17882,8 @@
18823
17882
  });
18824
17883
  anchor = parsedStyle.anchor;
18825
17884
  // set transform origin
18826
- var usedOriginXValue = (flipY ? -1 : 1) * convertPercentUnit(transformOrigin[0], 0, object);
18827
- var usedOriginYValue = (flipX ? -1 : 1) * convertPercentUnit(transformOrigin[1], 1, object);
17885
+ var usedOriginXValue = (flipY ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[0], 0, object) : 0);
17886
+ var usedOriginYValue = (flipX ? -1 : 1) * (transformOrigin ? convertPercentUnit(transformOrigin[1], 1, object) : 0);
18828
17887
  usedOriginXValue = usedOriginXValue - (flipY ? -1 : 1) * (anchor && anchor[0] || 0) * geometry.contentBounds.halfExtents[0] * 2;
18829
17888
  usedOriginYValue = usedOriginYValue - (flipX ? -1 : 1) * (anchor && anchor[1] || 0) * geometry.contentBounds.halfExtents[1] * 2;
18830
17889
  object.setOrigin(usedOriginXValue, usedOriginYValue);
@@ -20711,37 +19770,37 @@
20711
19770
  this.context = void 0;
20712
19771
  }
20713
19772
  var _proto = OffscreenCanvasCreator.prototype;
20714
- _proto.getOrCreateCanvas = function getOrCreateCanvas(offscreenCanvas) {
19773
+ _proto.getOrCreateCanvas = function getOrCreateCanvas(offscreenCanvas, contextAttributes) {
20715
19774
  if (this.canvas) {
20716
19775
  return this.canvas;
20717
19776
  }
20718
19777
  // user-defined offscreen canvas
20719
19778
  if (offscreenCanvas) {
20720
19779
  this.canvas = offscreenCanvas;
20721
- this.context = this.canvas.getContext('2d');
19780
+ this.context = this.canvas.getContext('2d', contextAttributes);
20722
19781
  } else {
20723
19782
  try {
20724
19783
  // OffscreenCanvas2D measureText can be up to 40% faster.
20725
19784
  this.canvas = new window.OffscreenCanvas(0, 0);
20726
- this.context = this.canvas.getContext('2d');
19785
+ this.context = this.canvas.getContext('2d', contextAttributes);
20727
19786
  if (!this.context || !this.context.measureText) {
20728
19787
  this.canvas = document.createElement('canvas');
20729
19788
  this.context = this.canvas.getContext('2d');
20730
19789
  }
20731
19790
  } catch (ex) {
20732
19791
  this.canvas = document.createElement('canvas');
20733
- this.context = this.canvas.getContext('2d');
19792
+ this.context = this.canvas.getContext('2d', contextAttributes);
20734
19793
  }
20735
19794
  }
20736
19795
  this.canvas.width = 10;
20737
19796
  this.canvas.height = 10;
20738
19797
  return this.canvas;
20739
19798
  };
20740
- _proto.getOrCreateContext = function getOrCreateContext(offscreenCanvas) {
19799
+ _proto.getOrCreateContext = function getOrCreateContext(offscreenCanvas, contextAttributes) {
20741
19800
  if (this.context) {
20742
19801
  return this.context;
20743
19802
  }
20744
- this.getOrCreateCanvas(offscreenCanvas);
19803
+ this.getOrCreateCanvas(offscreenCanvas, contextAttributes);
20745
19804
  return this.context;
20746
19805
  };
20747
19806
  return OffscreenCanvasCreator;
@@ -20907,7 +19966,9 @@
20907
19966
  enableDirtyCheck = _canvasConfig$rendere.enableDirtyCheck,
20908
19967
  enableCulling = _canvasConfig$rendere.enableCulling;
20909
19968
  // recalc style values
20910
- this.globalRuntime.styleValueRegistry.recalc(displayObject);
19969
+ if (this.globalRuntime.enableCSSParsing) {
19970
+ this.globalRuntime.styleValueRegistry.recalc(displayObject);
19971
+ }
20911
19972
  // TODO: relayout
20912
19973
  // dirtycheck first
20913
19974
  var objectChanged = enableDirtyCheck ? this.hooks.dirtycheck.call(displayObject) : displayObject;
@@ -22243,6 +21304,7 @@
22243
21304
  runtime.styleValueRegistry = new DefaultStyleValueRegistry();
22244
21305
  runtime.layoutRegistry = null;
22245
21306
  runtime.globalThis = getGlobalThis();
21307
+ runtime.enableCSSParsing = true;
22246
21308
 
22247
21309
  var AbstractRendererPlugin = /*#__PURE__*/function () {
22248
21310
  function AbstractRendererPlugin() {
@@ -22785,8 +21847,10 @@
22785
21847
  };
22786
21848
  var handleMounted = function handleMounted(e) {
22787
21849
  var object = e.target;
22788
- // recalc style values
22789
- runtime.styleValueRegistry.recalc(object);
21850
+ if (runtime.enableCSSParsing) {
21851
+ // recalc style values
21852
+ runtime.styleValueRegistry.recalc(object);
21853
+ }
22790
21854
  runtime.sceneGraphService.dirtifyToRoot(object);
22791
21855
  renderingService.dirtify();
22792
21856
  };
@@ -22821,6 +21885,7 @@
22821
21885
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
22822
21886
  canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
22823
21887
  canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
21888
+ _this.toSync.clear();
22824
21889
  });
22825
21890
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
22826
21891
  // if (this.isFirstTimeRendering) {