@antv/g-lite 2.0.11 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/Canvas.d.ts +2 -1
  2. package/dist/css/CSSProperty.d.ts +2 -10
  3. package/dist/css/StyleValueRegistry.d.ts +0 -23
  4. package/dist/css/cssom/CSSColorValue.d.ts +1 -0
  5. package/dist/css/cssom/CSSStyleValue.d.ts +1 -1
  6. package/dist/css/cssom/index.d.ts +0 -1
  7. package/dist/css/cssom/types.d.ts +0 -7
  8. package/dist/css/interfaces.d.ts +0 -6
  9. package/dist/css/parser/transform-origin.d.ts +0 -2
  10. package/dist/css/parser/transform.d.ts +3 -2
  11. package/dist/css/properties/CSSPropertyAngle.d.ts +0 -6
  12. package/dist/css/properties/CSSPropertyColor.d.ts +0 -4
  13. package/dist/css/properties/CSSPropertyFilter.d.ts +0 -2
  14. package/dist/css/properties/CSSPropertyLengthOrPercentage.d.ts +0 -6
  15. package/dist/css/properties/CSSPropertyLengthOrPercentage12.d.ts +0 -1
  16. package/dist/css/properties/CSSPropertyLengthOrPercentage14.d.ts +0 -1
  17. package/dist/css/properties/CSSPropertyNumber.d.ts +0 -6
  18. package/dist/css/properties/CSSPropertyOffsetDistance.d.ts +0 -6
  19. package/dist/css/properties/CSSPropertyOpacity.d.ts +0 -6
  20. package/dist/css/properties/CSSPropertyPath.d.ts +0 -1
  21. package/dist/css/properties/CSSPropertyPoints.d.ts +1 -2
  22. package/dist/css/properties/CSSPropertyTransform.d.ts +2 -4
  23. package/dist/css/properties/CSSPropertyTransformOrigin.d.ts +0 -5
  24. package/dist/css/properties/CSSPropertyZIndex.d.ts +0 -5
  25. package/dist/display-objects/DisplayObject.d.ts +0 -8
  26. package/dist/display-objects/Fragment.d.ts +13 -0
  27. package/dist/display-objects/index.d.ts +1 -0
  28. package/dist/dom/Element.d.ts +2 -2
  29. package/dist/dom/Node.d.ts +6 -1
  30. package/dist/dom/interfaces.d.ts +2 -1
  31. package/dist/global-runtime.d.ts +0 -12
  32. package/dist/index.esm.js +1512 -2192
  33. package/dist/index.esm.js.map +1 -1
  34. package/dist/index.js +1495 -2174
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.umd.min.js +1 -1
  37. package/dist/index.umd.min.js.map +1 -1
  38. package/dist/plugins/PrepareRendererPlugin.d.ts +2 -4
  39. package/dist/services/SceneGraphService.d.ts +12 -11
  40. package/dist/services/interfaces.d.ts +6 -5
  41. package/dist/types.d.ts +54 -1
  42. package/dist/utils/assert.d.ts +0 -9
  43. package/dist/utils/canvas.d.ts +1 -1
  44. package/dist/utils/fragment.d.ts +2 -0
  45. package/dist/utils/index.d.ts +1 -1
  46. package/dist/utils/math.d.ts +1 -8
  47. package/package.json +1 -1
  48. package/dist/css/cssom/CSSMathOperator.d.ts +0 -11
  49. package/dist/css/cssom/CSSNumericSumValue.d.ts +0 -7
  50. package/dist/css/properties/CSSPropertyLocalPosition.d.ts +0 -13
  51. package/dist/utils/string.d.ts +0 -5
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __assign, __read, __extends, __spreadArray, __awaiter, __generator, __values, __rest } from 'tslib';
2
2
  import EventEmitter from 'eventemitter3';
3
- import { mat4, vec4, vec3, mat3, quat as quat$1, vec2 } from 'gl-matrix';
4
- import { isNumber, distanceSquareRoot, isString, isNil, clamp, getTotalLength, min, max, isNumberEqual, mod, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isUndefined, isArray, isBoolean, isObject, getPointAtLength } from '@antv/util';
3
+ import { vec3, vec4, mat4, mat3, quat as quat$1, vec2 } from 'gl-matrix';
4
+ import { isNumber, distanceSquareRoot, isString, isNil, clamp, getTotalLength, min, max, isNumberEqual, mod, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isUndefined, isArray, isBoolean, isFunction, isObject, getPointAtLength } from '@antv/util';
5
5
  import * as d3 from 'd3-color';
6
6
  import { polylineLength, arcBox, cubicBox, quadBox, linePointAt, lineLength } from '@antv/g-math';
7
7
 
@@ -588,6 +588,7 @@ var RBush = rbush.exports;
588
588
  var Shape;
589
589
  (function (Shape) {
590
590
  Shape["GROUP"] = "g";
591
+ Shape["FRAGMENT"] = "fragment";
591
592
  Shape["CIRCLE"] = "circle";
592
593
  Shape["ELLIPSE"] = "ellipse";
593
594
  Shape["IMAGE"] = "image";
@@ -670,366 +671,7 @@ var AbstractRenderer = /** @class */ (function () {
670
671
  return AbstractRenderer;
671
672
  }());
672
673
 
673
- function copyVec3(a, b) {
674
- a[0] = b[0];
675
- a[1] = b[1];
676
- a[2] = b[2];
677
- return a;
678
- }
679
- function subVec3(o, a, b) {
680
- o[0] = a[0] - b[0];
681
- o[1] = a[1] - b[1];
682
- o[2] = a[2] - b[2];
683
- return o;
684
- }
685
- function addVec3(o, a, b) {
686
- o[0] = a[0] + b[0];
687
- o[1] = a[1] + b[1];
688
- o[2] = a[2] + b[2];
689
- return o;
690
- }
691
- function scaleVec3(o, a, b) {
692
- o[0] = a[0] * b;
693
- o[1] = a[1] * b;
694
- o[2] = a[2] * b;
695
- return o;
696
- }
697
- function maxVec3(o, a, b) {
698
- o[0] = Math.max(a[0], b[0]);
699
- o[1] = Math.max(a[1], b[1]);
700
- o[2] = Math.max(a[2], b[2]);
701
- return o;
702
- }
703
- function minVec3(o, a, b) {
704
- o[0] = Math.min(a[0], b[0]);
705
- o[1] = Math.min(a[1], b[1]);
706
- o[2] = Math.min(a[2], b[2]);
707
- return o;
708
- }
709
- function getAngle(angle) {
710
- if (angle === undefined) {
711
- return 0;
712
- }
713
- else if (angle > 360 || angle < -360) {
714
- return angle % 360;
715
- }
716
- return angle;
717
- }
718
- function createVec3(x, y, z) {
719
- if (y === void 0) { y = 0; }
720
- if (z === void 0) { z = 0; }
721
- if (Array.isArray(x) && x.length === 3) {
722
- return vec3.clone(x);
723
- }
724
- if (isNumber(x)) {
725
- return vec3.fromValues(x, y, z);
726
- }
727
- return vec3.fromValues(x[0], x[1] || y, x[2] || z);
728
- }
729
- function deg2rad(deg) {
730
- return deg * (Math.PI / 180);
731
- }
732
- function rad2deg(rad) {
733
- return rad * (180 / Math.PI);
734
- }
735
- function grad2deg(grads) {
736
- grads = grads % 400;
737
- if (grads < 0) {
738
- grads += 400;
739
- }
740
- return (grads / 400) * 360;
741
- }
742
- function deg2turn(deg) {
743
- return deg / 360;
744
- }
745
- function turn2deg(turn) {
746
- return 360 * turn;
747
- }
748
- function getEulerFromQuat(out, quat) {
749
- var x = quat[0];
750
- var y = quat[1];
751
- var z = quat[2];
752
- var w = quat[3];
753
- var x2 = x * x;
754
- var y2 = y * y;
755
- var z2 = z * z;
756
- var w2 = w * w;
757
- var unit = x2 + y2 + z2 + w2;
758
- var test = x * w - y * z;
759
- if (test > 0.499995 * unit) {
760
- // TODO: Use glmatrix.EPSILON
761
- // singularity at the north pole
762
- out[0] = Math.PI / 2;
763
- out[1] = 2 * Math.atan2(y, x);
764
- out[2] = 0;
765
- }
766
- else if (test < -0.499995 * unit) {
767
- //TODO: Use glmatrix.EPSILON
768
- // singularity at the south pole
769
- out[0] = -Math.PI / 2;
770
- out[1] = 2 * Math.atan2(y, x);
771
- out[2] = 0;
772
- }
773
- else {
774
- out[0] = Math.asin(2 * (x * z - w * y));
775
- out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
776
- out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
777
- }
778
- // TODO: Return them as degrees and not as radians
779
- return out;
780
- }
781
- function getEulerFromMat4(out, m) {
782
- var x;
783
- var z;
784
- var halfPi = Math.PI * 0.5;
785
- var _a = __read(mat4.getScaling(vec3.create(), m), 3), sx = _a[0], sy = _a[1], sz = _a[2];
786
- var y = Math.asin(-m[2] / sx);
787
- if (y < halfPi) {
788
- if (y > -halfPi) {
789
- x = Math.atan2(m[6] / sy, m[10] / sz);
790
- z = Math.atan2(m[1] / sx, m[0] / sx);
791
- }
792
- else {
793
- // Not a unique solution
794
- z = 0;
795
- x = -Math.atan2(m[4] / sy, m[5] / sy);
796
- }
797
- }
798
- else {
799
- // Not a unique solution
800
- z = 0;
801
- x = Math.atan2(m[4] / sy, m[5] / sy);
802
- }
803
- out[0] = x;
804
- out[1] = y;
805
- out[2] = z;
806
- return out;
807
- }
808
- /**
809
- * @see https://github.com/toji/gl-matrix/issues/329
810
- * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
811
- */
812
- function getEuler(out, quat) {
813
- if (quat.length === 16) {
814
- return getEulerFromMat4(out, quat);
815
- }
816
- else {
817
- return getEulerFromQuat(out, quat);
818
- }
819
- }
820
- function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
821
- var cos = Math.cos(rotation);
822
- var sin = Math.sin(rotation);
823
- return mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
824
- }
825
- function makePerspective(out, left, right, top, bottom, near, far, zero) {
826
- if (zero === void 0) { zero = false; }
827
- var x = (2 * near) / (right - left);
828
- var y = (2 * near) / (top - bottom);
829
- var a = (right + left) / (right - left);
830
- var b = (top + bottom) / (top - bottom);
831
- var c;
832
- var d;
833
- if (zero) {
834
- c = -far / (far - near);
835
- d = (-far * near) / (far - near);
836
- }
837
- else {
838
- c = -(far + near) / (far - near);
839
- d = (-2 * far * near) / (far - near);
840
- }
841
- out[0] = x;
842
- out[1] = 0;
843
- out[2] = 0;
844
- out[3] = 0;
845
- out[4] = 0;
846
- out[5] = y;
847
- out[6] = 0;
848
- out[7] = 0;
849
- out[8] = a;
850
- out[9] = b;
851
- out[10] = c;
852
- out[11] = -1;
853
- out[12] = 0;
854
- out[13] = 0;
855
- out[14] = d;
856
- out[15] = 0;
857
- return out;
858
- }
859
- function decompose(mat) {
860
- var row0x = mat[0];
861
- var row0y = mat[1];
862
- var row1x = mat[3];
863
- var row1y = mat[4];
864
- // decompose 3x3 matrix
865
- // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
866
- var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
867
- var scalingY = Math.sqrt(row1x * row1x + row1y * row1y);
868
- // If determinant is negative, one axis was flipped.
869
- var determinant = row0x * row1y - row0y * row1x;
870
- if (determinant < 0) {
871
- // Flip axis with minimum unit vector dot product.
872
- if (row0x < row1y) {
873
- scalingX = -scalingX;
874
- }
875
- else {
876
- scalingY = -scalingY;
877
- }
878
- }
879
- // Renormalize matrix to remove scale.
880
- if (scalingX) {
881
- row0x *= 1 / scalingX;
882
- row0y *= 1 / scalingX;
883
- }
884
- if (scalingY) {
885
- row1x *= 1 / scalingY;
886
- row1y *= 1 / scalingY;
887
- }
888
- // Compute rotation and renormalize matrix.
889
- var rotation = Math.atan2(row0y, row0x);
890
- var angle = rad2deg(rotation);
891
- return [mat[6], mat[7], scalingX, scalingY, angle];
892
- }
893
- var tmp = mat4.create();
894
- var perspectiveMatrix = mat4.create();
895
- var tmpVec4 = vec4.create();
896
- var row = [vec3.create(), vec3.create(), vec3.create()];
897
- var pdum3 = vec3.create();
898
- /*
899
- Input: matrix ; a 4x4 matrix
900
- Output: translation ; a 3 component vector
901
- scale ; a 3 component vector
902
- skew ; skew factors XY,XZ,YZ represented as a 3 component vector
903
- perspective ; a 4 component vector
904
- quaternion ; a 4 component vector
905
- Returns false if the matrix cannot be decomposed, true if it can
906
-
907
-
908
- References:
909
- https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
910
- https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
911
- http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
912
- */
913
- function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
914
- //normalize, if not possible then bail out early
915
- if (!normalize(tmp, matrix))
916
- return false;
917
- // perspectiveMatrix is used to solve for perspective, but it also provides
918
- // an easy way to test for singularity of the upper 3x3 component.
919
- mat4.copy(perspectiveMatrix, tmp);
920
- perspectiveMatrix[3] = 0;
921
- perspectiveMatrix[7] = 0;
922
- perspectiveMatrix[11] = 0;
923
- perspectiveMatrix[15] = 1;
924
- // If the perspectiveMatrix is not invertible, we are also unable to
925
- // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
926
- if (Math.abs(mat4.determinant(perspectiveMatrix)) < 1e-8)
927
- return false;
928
- var a03 = tmp[3], a13 = tmp[7], a23 = tmp[11], a30 = tmp[12], a31 = tmp[13], a32 = tmp[14], a33 = tmp[15];
929
- // First, isolate perspective.
930
- if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
931
- tmpVec4[0] = a03;
932
- tmpVec4[1] = a13;
933
- tmpVec4[2] = a23;
934
- tmpVec4[3] = a33;
935
- // Solve the equation by inverting perspectiveMatrix and multiplying
936
- // rightHandSide by the inverse.
937
- // resuing the perspectiveMatrix here since it's no longer needed
938
- var ret = mat4.invert(perspectiveMatrix, perspectiveMatrix);
939
- if (!ret)
940
- return false;
941
- mat4.transpose(perspectiveMatrix, perspectiveMatrix);
942
- //multiply by transposed inverse perspective matrix, into perspective vec4
943
- vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
944
- }
945
- else {
946
- //no perspective
947
- perspective[0] = perspective[1] = perspective[2] = 0;
948
- perspective[3] = 1;
949
- }
950
- // Next take care of translation
951
- translation[0] = a30;
952
- translation[1] = a31;
953
- translation[2] = a32;
954
- // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
955
- mat3from4(row, tmp);
956
- // Compute X scale factor and normalize first row.
957
- scale[0] = vec3.length(row[0]);
958
- vec3.normalize(row[0], row[0]);
959
- // Compute XY shear factor and make 2nd row orthogonal to 1st.
960
- skew[0] = vec3.dot(row[0], row[1]);
961
- combine(row[1], row[1], row[0], 1.0, -skew[0]);
962
- // Now, compute Y scale and normalize 2nd row.
963
- scale[1] = vec3.length(row[1]);
964
- vec3.normalize(row[1], row[1]);
965
- skew[0] /= scale[1];
966
- // Compute XZ and YZ shears, orthogonalize 3rd row
967
- skew[1] = vec3.dot(row[0], row[2]);
968
- combine(row[2], row[2], row[0], 1.0, -skew[1]);
969
- skew[2] = vec3.dot(row[1], row[2]);
970
- combine(row[2], row[2], row[1], 1.0, -skew[2]);
971
- // Next, get Z scale and normalize 3rd row.
972
- scale[2] = vec3.length(row[2]);
973
- vec3.normalize(row[2], row[2]);
974
- skew[1] /= scale[2];
975
- skew[2] /= scale[2];
976
- // At this point, the matrix (in rows) is orthonormal.
977
- // Check for a coordinate system flip. If the determinant
978
- // is -1, then negate the matrix and the scaling factors.
979
- vec3.cross(pdum3, row[1], row[2]);
980
- if (vec3.dot(row[0], pdum3) < 0) {
981
- for (var i = 0; i < 3; i++) {
982
- scale[i] *= -1;
983
- row[i][0] *= -1;
984
- row[i][1] *= -1;
985
- row[i][2] *= -1;
986
- }
987
- }
988
- // Now, get the rotations out
989
- quaternion[0] =
990
- 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
991
- quaternion[1] =
992
- 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
993
- quaternion[2] =
994
- 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
995
- quaternion[3] =
996
- 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
997
- if (row[2][1] > row[1][2])
998
- quaternion[0] = -quaternion[0];
999
- if (row[0][2] > row[2][0])
1000
- quaternion[1] = -quaternion[1];
1001
- if (row[1][0] > row[0][1])
1002
- quaternion[2] = -quaternion[2];
1003
- return true;
1004
- }
1005
- function normalize(out, mat) {
1006
- var m44 = mat[15];
1007
- // Cannot normalize.
1008
- if (m44 === 0)
1009
- return false;
1010
- var scale = 1 / m44;
1011
- for (var i = 0; i < 16; i++)
1012
- out[i] = mat[i] * scale;
1013
- return true;
1014
- }
1015
- //gets upper-left of a 4x4 matrix into a 3x3 of vectors
1016
- function mat3from4(out, mat4x4) {
1017
- out[0][0] = mat4x4[0];
1018
- out[0][1] = mat4x4[1];
1019
- out[0][2] = mat4x4[2];
1020
- out[1][0] = mat4x4[4];
1021
- out[1][1] = mat4x4[5];
1022
- out[1][2] = mat4x4[6];
1023
- out[2][0] = mat4x4[8];
1024
- out[2][1] = mat4x4[9];
1025
- out[2][2] = mat4x4[10];
1026
- }
1027
- function combine(out, a, b, scale1, scale2) {
1028
- out[0] = a[0] * scale1 + b[0] * scale2;
1029
- out[1] = a[1] * scale1 + b[1] * scale2;
1030
- out[2] = a[2] * scale1 + b[2] * scale2;
1031
- }
1032
-
674
+ var addVec3 = vec3.add, copyVec3 = vec3.copy, maxVec3 = vec3.max, minVec3 = vec3.min, scaleVec3 = vec3.scale, subVec3 = vec3.sub;
1033
675
  /**
1034
676
  * Axis-Aligned Bounding Box
1035
677
  * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
@@ -1048,27 +690,13 @@ var AABB = /** @class */ (function () {
1048
690
  aabb.halfExtents[1] === 0 &&
1049
691
  aabb.halfExtents[2] === 0));
1050
692
  };
1051
- // center: vec3 = vec3.create();
1052
- // halfExtents: vec3 = vec3.create();
1053
- // min: vec3 = vec3.create();
1054
- // max: vec3 = vec3.create();
1055
693
  AABB.prototype.update = function (center, halfExtents) {
1056
694
  copyVec3(this.center, center);
1057
695
  copyVec3(this.halfExtents, halfExtents);
1058
696
  subVec3(this.min, this.center, this.halfExtents);
1059
697
  addVec3(this.max, this.center, this.halfExtents);
1060
- // vec3.copy(this.center, center);
1061
- // vec3.copy(this.halfExtents, halfExtents);
1062
- // vec3.sub(this.min, this.center, this.halfExtents);
1063
- // vec3.add(this.max, this.center, this.halfExtents);
1064
698
  };
1065
699
  AABB.prototype.setMinMax = function (min, max) {
1066
- // vec3.add(this.center, max, min);
1067
- // vec3.scale(this.center, this.center, 0.5);
1068
- // vec3.sub(this.halfExtents, max, min);
1069
- // vec3.scale(this.halfExtents, this.halfExtents, 0.5);
1070
- // vec3.copy(this.min, min);
1071
- // vec3.copy(this.max, max);
1072
700
  addVec3(this.center, max, min);
1073
701
  scaleVec3(this.center, this.center, 0.5);
1074
702
  subVec3(this.halfExtents, max, min);
@@ -1212,25 +840,11 @@ var AABB = /** @class */ (function () {
1212
840
  return null;
1213
841
  }
1214
842
  var intersection = new AABB();
1215
- // const min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
1216
- // const max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
1217
843
  var min = maxVec3([0, 0, 0], this.getMin(), aabb.getMin());
1218
844
  var max = minVec3([0, 0, 0], this.getMax(), aabb.getMax());
1219
845
  intersection.setMinMax(min, max);
1220
846
  return intersection;
1221
847
  };
1222
- // containsPoint(point: vec3) {
1223
- // const min = this.getMin();
1224
- // const max = this.getMax();
1225
- // return !(
1226
- // point[0] < min[0] ||
1227
- // point[0] > max[0] ||
1228
- // point[1] < min[1] ||
1229
- // point[1] > max[1] ||
1230
- // point[2] < min[2] ||
1231
- // point[2] > max[2]
1232
- // );
1233
- // }
1234
848
  /**
1235
849
  * get n-vertex
1236
850
  * @param plane plane of CullingVolume
@@ -1303,167 +917,505 @@ var AABB = /** @class */ (function () {
1303
917
  // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
1304
918
  }
1305
919
  else {
1306
- return [this.min[0], this.min[1], this.min[2]];
1307
- // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
920
+ return [this.min[0], this.min[1], this.min[2]];
921
+ // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
922
+ }
923
+ };
924
+ return AABB;
925
+ }());
926
+
927
+ var Plane = /** @class */ (function () {
928
+ function Plane(distance, normal) {
929
+ this.distance = distance || 0;
930
+ this.normal = normal || vec3.fromValues(0, 1, 0);
931
+ this.updatePNVertexFlag();
932
+ }
933
+ Plane.prototype.updatePNVertexFlag = function () {
934
+ this.pnVertexFlag =
935
+ (Number(this.normal[0] >= 0) << 8) +
936
+ (Number(this.normal[1] >= 0) << 4) +
937
+ Number(this.normal[2] >= 0);
938
+ };
939
+ Plane.prototype.distanceToPoint = function (point) {
940
+ return vec3.dot(point, this.normal) - this.distance;
941
+ };
942
+ Plane.prototype.normalize = function () {
943
+ var invLen = 1 / vec3.len(this.normal);
944
+ vec3.scale(this.normal, this.normal, invLen);
945
+ this.distance *= invLen;
946
+ };
947
+ Plane.prototype.intersectsLine = function (start, end, point) {
948
+ var d0 = this.distanceToPoint(start);
949
+ var d1 = this.distanceToPoint(end);
950
+ var t = d0 / (d0 - d1);
951
+ var intersects = t >= 0 && t <= 1;
952
+ if (intersects && point) {
953
+ vec3.lerp(point, start, end, t);
954
+ }
955
+ return intersects;
956
+ };
957
+ return Plane;
958
+ }());
959
+
960
+ var Mask;
961
+ (function (Mask) {
962
+ Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
963
+ Mask[Mask["INSIDE"] = 0] = "INSIDE";
964
+ Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
965
+ })(Mask || (Mask = {}));
966
+ var Frustum = /** @class */ (function () {
967
+ function Frustum(planes) {
968
+ this.planes = [];
969
+ if (planes) {
970
+ this.planes = planes;
971
+ }
972
+ else {
973
+ for (var i = 0; i < 6; i++) {
974
+ this.planes.push(new Plane());
975
+ }
976
+ }
977
+ }
978
+ /**
979
+ * extract 6 planes from projectionMatrix
980
+ * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
981
+ */
982
+ Frustum.prototype.extractFromVPMatrix = function (projectionMatrix) {
983
+ // @ts-ignore
984
+ var _a = __read(projectionMatrix, 16), m0 = _a[0], m1 = _a[1], m2 = _a[2], m3 = _a[3], m4 = _a[4], m5 = _a[5], m6 = _a[6], m7 = _a[7], m8 = _a[8], m9 = _a[9], m10 = _a[10], m11 = _a[11], m12 = _a[12], m13 = _a[13], m14 = _a[14], m15 = _a[15];
985
+ // right
986
+ vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
987
+ this.planes[0].distance = m15 - m12;
988
+ // left
989
+ vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
990
+ this.planes[1].distance = m15 + m12;
991
+ // bottom
992
+ vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
993
+ this.planes[2].distance = m15 + m13;
994
+ // top
995
+ vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
996
+ this.planes[3].distance = m15 - m13;
997
+ // far
998
+ vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
999
+ this.planes[4].distance = m15 - m14;
1000
+ // near
1001
+ vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
1002
+ this.planes[5].distance = m15 + m14;
1003
+ this.planes.forEach(function (plane) {
1004
+ plane.normalize();
1005
+ plane.updatePNVertexFlag();
1006
+ });
1007
+ };
1008
+ return Frustum;
1009
+ }());
1010
+
1011
+ var Point = /** @class */ (function () {
1012
+ function Point(x, y) {
1013
+ if (x === void 0) { x = 0; }
1014
+ if (y === void 0) { y = 0; }
1015
+ this.x = 0;
1016
+ this.y = 0;
1017
+ this.x = x;
1018
+ this.y = y;
1019
+ }
1020
+ Point.prototype.clone = function () {
1021
+ return new Point(this.x, this.y);
1022
+ };
1023
+ Point.prototype.copyFrom = function (p) {
1024
+ this.x = p.x;
1025
+ this.y = p.y;
1026
+ };
1027
+ return Point;
1028
+ }());
1029
+
1030
+ var Rectangle = /** @class */ (function () {
1031
+ function Rectangle(x, y, width, height) {
1032
+ this.x = x;
1033
+ this.y = y;
1034
+ this.width = width;
1035
+ this.height = height;
1036
+ this.left = x;
1037
+ this.right = x + width;
1038
+ this.top = y;
1039
+ this.bottom = y + height;
1040
+ }
1041
+ /**
1042
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect/fromRect_static
1043
+ */
1044
+ Rectangle.fromRect = function (rect) {
1045
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
1046
+ };
1047
+ /**
1048
+ * will return a new rect instance
1049
+ */
1050
+ Rectangle.applyTransform = function (rect, matrix) {
1051
+ var topLeft = vec4.fromValues(rect.x, rect.y, 0, 1);
1052
+ var topRight = vec4.fromValues(rect.x + rect.width, rect.y, 0, 1);
1053
+ var bottomLeft = vec4.fromValues(rect.x, rect.y + rect.height, 0, 1);
1054
+ var bottomRight = vec4.fromValues(rect.x + rect.width, rect.y + rect.height, 0, 1);
1055
+ var transformedTopLeft = vec4.create();
1056
+ var transformedTopRight = vec4.create();
1057
+ var transformedBottomLeft = vec4.create();
1058
+ var transformedBottomRight = vec4.create();
1059
+ vec4.transformMat4(transformedTopLeft, topLeft, matrix);
1060
+ vec4.transformMat4(transformedTopRight, topRight, matrix);
1061
+ vec4.transformMat4(transformedBottomLeft, bottomLeft, matrix);
1062
+ vec4.transformMat4(transformedBottomRight, bottomRight, matrix);
1063
+ var minX = Math.min(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1064
+ var minY = Math.min(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1065
+ var maxX = Math.max(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1066
+ var maxY = Math.max(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1067
+ return Rectangle.fromRect({
1068
+ x: minX,
1069
+ y: minY,
1070
+ width: maxX - minX,
1071
+ height: maxY - minY,
1072
+ });
1073
+ };
1074
+ Rectangle.prototype.toJSON = function () { };
1075
+ return Rectangle;
1076
+ }());
1077
+
1078
+ var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
1079
+ var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
1080
+ var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
1081
+
1082
+ function getAngle(angle) {
1083
+ if (angle === undefined) {
1084
+ return 0;
1085
+ }
1086
+ else if (angle > 360 || angle < -360) {
1087
+ return angle % 360;
1088
+ }
1089
+ return angle;
1090
+ }
1091
+ var $vec3$2 = vec3.create();
1092
+ function createVec3(x, y, z, clone) {
1093
+ if (y === void 0) { y = 0; }
1094
+ if (z === void 0) { z = 0; }
1095
+ if (clone === void 0) { clone = true; }
1096
+ if (Array.isArray(x) && x.length === 3) {
1097
+ return clone ? vec3.clone(x) : vec3.copy($vec3$2, x);
1098
+ }
1099
+ if (isNumber(x)) {
1100
+ return clone ? vec3.fromValues(x, y, z) : vec3.set($vec3$2, x, y, z);
1101
+ }
1102
+ return clone
1103
+ ? vec3.fromValues(x[0], x[1] || y, x[2] || z)
1104
+ : vec3.set($vec3$2, x[0], x[1] || y, x[2] || z);
1105
+ }
1106
+ var DEG_RAD = Math.PI / 180;
1107
+ function deg2rad(deg) {
1108
+ return deg * DEG_RAD;
1109
+ }
1110
+ var RAD_DEG = 180 / Math.PI;
1111
+ function rad2deg(rad) {
1112
+ return rad * RAD_DEG;
1113
+ }
1114
+ var GRAD_DEG = 0.9; // 360 / 400;
1115
+ function grad2deg(grads) {
1116
+ grads = grads % 400;
1117
+ if (grads < 0) {
1118
+ grads += 400;
1119
+ }
1120
+ return grads * GRAD_DEG;
1121
+ }
1122
+ function deg2turn(deg) {
1123
+ return deg / 360;
1124
+ }
1125
+ function turn2deg(turn) {
1126
+ return 360 * turn;
1127
+ }
1128
+ var HALF_PI = Math.PI / 2;
1129
+ function getEulerFromQuat(out, quat) {
1130
+ var x = quat[0];
1131
+ var y = quat[1];
1132
+ var z = quat[2];
1133
+ var w = quat[3];
1134
+ var x2 = x * x;
1135
+ var y2 = y * y;
1136
+ var z2 = z * z;
1137
+ var w2 = w * w;
1138
+ var unit = x2 + y2 + z2 + w2;
1139
+ var test = x * w - y * z;
1140
+ if (test > 0.499995 * unit) {
1141
+ // TODO: Use glmatrix.EPSILON
1142
+ // singularity at the north pole
1143
+ out[0] = HALF_PI;
1144
+ out[1] = 2 * Math.atan2(y, x);
1145
+ out[2] = 0;
1146
+ }
1147
+ else if (test < -0.499995 * unit) {
1148
+ //TODO: Use glmatrix.EPSILON
1149
+ // singularity at the south pole
1150
+ out[0] = -HALF_PI;
1151
+ out[1] = 2 * Math.atan2(y, x);
1152
+ out[2] = 0;
1153
+ }
1154
+ else {
1155
+ out[0] = Math.asin(2 * (x * z - w * y));
1156
+ out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
1157
+ out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
1158
+ }
1159
+ // TODO: Return them as degrees and not as radians
1160
+ return out;
1161
+ }
1162
+ function getEulerFromMat4(out, m) {
1163
+ var x;
1164
+ var z;
1165
+ var _a = __read(mat4.getScaling(vec3.create(), m), 3), sx = _a[0], sy = _a[1], sz = _a[2];
1166
+ var y = Math.asin(-m[2] / sx);
1167
+ if (y < HALF_PI) {
1168
+ if (y > -HALF_PI) {
1169
+ x = Math.atan2(m[6] / sy, m[10] / sz);
1170
+ z = Math.atan2(m[1] / sx, m[0] / sx);
1171
+ }
1172
+ else {
1173
+ // Not a unique solution
1174
+ z = 0;
1175
+ x = -Math.atan2(m[4] / sy, m[5] / sy);
1308
1176
  }
1309
- };
1310
- return AABB;
1311
- }());
1312
-
1313
- var Plane = /** @class */ (function () {
1314
- function Plane(distance, normal) {
1315
- this.distance = distance || 0;
1316
- this.normal = normal || vec3.fromValues(0, 1, 0);
1317
- this.updatePNVertexFlag();
1318
1177
  }
1319
- Plane.prototype.updatePNVertexFlag = function () {
1320
- this.pnVertexFlag =
1321
- (Number(this.normal[0] >= 0) << 8) +
1322
- (Number(this.normal[1] >= 0) << 4) +
1323
- Number(this.normal[2] >= 0);
1324
- };
1325
- Plane.prototype.distanceToPoint = function (point) {
1326
- return vec3.dot(point, this.normal) - this.distance;
1327
- };
1328
- Plane.prototype.normalize = function () {
1329
- var invLen = 1 / vec3.len(this.normal);
1330
- vec3.scale(this.normal, this.normal, invLen);
1331
- this.distance *= invLen;
1332
- };
1333
- Plane.prototype.intersectsLine = function (start, end, point) {
1334
- var d0 = this.distanceToPoint(start);
1335
- var d1 = this.distanceToPoint(end);
1336
- var t = d0 / (d0 - d1);
1337
- var intersects = t >= 0 && t <= 1;
1338
- if (intersects && point) {
1339
- vec3.lerp(point, start, end, t);
1340
- }
1341
- return intersects;
1342
- };
1343
- return Plane;
1344
- }());
1345
-
1346
- var Mask;
1347
- (function (Mask) {
1348
- Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
1349
- Mask[Mask["INSIDE"] = 0] = "INSIDE";
1350
- Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
1351
- })(Mask || (Mask = {}));
1352
- var Frustum = /** @class */ (function () {
1353
- function Frustum(planes) {
1354
- this.planes = [];
1355
- if (planes) {
1356
- this.planes = planes;
1178
+ else {
1179
+ // Not a unique solution
1180
+ z = 0;
1181
+ x = Math.atan2(m[4] / sy, m[5] / sy);
1182
+ }
1183
+ out[0] = x;
1184
+ out[1] = y;
1185
+ out[2] = z;
1186
+ return out;
1187
+ }
1188
+ /**
1189
+ * @see https://github.com/toji/gl-matrix/issues/329
1190
+ * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
1191
+ */
1192
+ function getEuler(out, quat) {
1193
+ if (quat.length === 16) {
1194
+ return getEulerFromMat4(out, quat);
1195
+ }
1196
+ else {
1197
+ return getEulerFromQuat(out, quat);
1198
+ }
1199
+ }
1200
+ function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
1201
+ var cos = Math.cos(rotation);
1202
+ var sin = Math.sin(rotation);
1203
+ return mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
1204
+ }
1205
+ function makePerspective(out, left, right, top, bottom, near, far, zero) {
1206
+ if (zero === void 0) { zero = false; }
1207
+ var twoNear = 2 * near;
1208
+ var rightMinusLeft = right - left;
1209
+ var topMinusBottom = top - bottom;
1210
+ var x = twoNear / rightMinusLeft;
1211
+ var y = twoNear / topMinusBottom;
1212
+ var a = (right + left) / rightMinusLeft;
1213
+ var b = (top + bottom) / topMinusBottom;
1214
+ var c;
1215
+ var d;
1216
+ var farMinusNear = far - near;
1217
+ var farMulNear = far * near;
1218
+ if (zero) {
1219
+ c = -far / farMinusNear;
1220
+ d = -farMulNear / farMinusNear;
1221
+ }
1222
+ else {
1223
+ c = -(far + near) / farMinusNear;
1224
+ d = (-2 * farMulNear) / farMinusNear;
1225
+ }
1226
+ out[0] = x;
1227
+ out[1] = 0;
1228
+ out[2] = 0;
1229
+ out[3] = 0;
1230
+ out[4] = 0;
1231
+ out[5] = y;
1232
+ out[6] = 0;
1233
+ out[7] = 0;
1234
+ out[8] = a;
1235
+ out[9] = b;
1236
+ out[10] = c;
1237
+ out[11] = -1;
1238
+ out[12] = 0;
1239
+ out[13] = 0;
1240
+ out[14] = d;
1241
+ out[15] = 0;
1242
+ return out;
1243
+ }
1244
+ function decompose(mat) {
1245
+ var row0x = mat[0];
1246
+ var row0y = mat[1];
1247
+ var row1x = mat[3];
1248
+ var row1y = mat[4];
1249
+ // decompose 3x3 matrix
1250
+ // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
1251
+ var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
1252
+ var scalingY = Math.sqrt(row1x * row1x + row1y * row1y);
1253
+ // If determinant is negative, one axis was flipped.
1254
+ var determinant = row0x * row1y - row0y * row1x;
1255
+ if (determinant < 0) {
1256
+ // Flip axis with minimum unit vector dot product.
1257
+ if (row0x < row1y) {
1258
+ scalingX = -scalingX;
1357
1259
  }
1358
1260
  else {
1359
- for (var i = 0; i < 6; i++) {
1360
- this.planes.push(new Plane());
1361
- }
1261
+ scalingY = -scalingY;
1362
1262
  }
1363
1263
  }
1364
- /**
1365
- * extract 6 planes from projectionMatrix
1366
- * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
1367
- */
1368
- Frustum.prototype.extractFromVPMatrix = function (projectionMatrix) {
1369
- // @ts-ignore
1370
- var _a = __read(projectionMatrix, 16), m0 = _a[0], m1 = _a[1], m2 = _a[2], m3 = _a[3], m4 = _a[4], m5 = _a[5], m6 = _a[6], m7 = _a[7], m8 = _a[8], m9 = _a[9], m10 = _a[10], m11 = _a[11], m12 = _a[12], m13 = _a[13], m14 = _a[14], m15 = _a[15];
1371
- // right
1372
- vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
1373
- this.planes[0].distance = m15 - m12;
1374
- // left
1375
- vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
1376
- this.planes[1].distance = m15 + m12;
1377
- // bottom
1378
- vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
1379
- this.planes[2].distance = m15 + m13;
1380
- // top
1381
- vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
1382
- this.planes[3].distance = m15 - m13;
1383
- // far
1384
- vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
1385
- this.planes[4].distance = m15 - m14;
1386
- // near
1387
- vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
1388
- this.planes[5].distance = m15 + m14;
1389
- this.planes.forEach(function (plane) {
1390
- plane.normalize();
1391
- plane.updatePNVertexFlag();
1392
- });
1393
- };
1394
- return Frustum;
1395
- }());
1396
-
1397
- var Point = /** @class */ (function () {
1398
- function Point(x, y) {
1399
- if (x === void 0) { x = 0; }
1400
- if (y === void 0) { y = 0; }
1401
- this.x = 0;
1402
- this.y = 0;
1403
- this.x = x;
1404
- this.y = y;
1264
+ // Renormalize matrix to remove scale.
1265
+ if (scalingX) {
1266
+ var invScalingX = 1 / scalingX;
1267
+ row0x *= invScalingX;
1268
+ row0y *= invScalingX;
1405
1269
  }
1406
- Point.prototype.clone = function () {
1407
- return new Point(this.x, this.y);
1408
- };
1409
- Point.prototype.copyFrom = function (p) {
1410
- this.x = p.x;
1411
- this.y = p.y;
1412
- };
1413
- return Point;
1414
- }());
1270
+ if (scalingY) {
1271
+ var invScalingY = 1 / scalingY;
1272
+ row1x *= invScalingY;
1273
+ row1y *= invScalingY;
1274
+ }
1275
+ // Compute rotation and renormalize matrix.
1276
+ var rotation = Math.atan2(row0y, row0x);
1277
+ var angle = rad2deg(rotation);
1278
+ return [mat[6], mat[7], scalingX, scalingY, angle];
1279
+ }
1280
+ var tmp = mat4.create();
1281
+ var perspectiveMatrix = mat4.create();
1282
+ var tmpVec4 = vec4.create();
1283
+ var row = [vec3.create(), vec3.create(), vec3.create()];
1284
+ var pdum3 = vec3.create();
1285
+ /*
1286
+ Input: matrix ; a 4x4 matrix
1287
+ Output: translation ; a 3 component vector
1288
+ scale ; a 3 component vector
1289
+ skew ; skew factors XY,XZ,YZ represented as a 3 component vector
1290
+ perspective ; a 4 component vector
1291
+ quaternion ; a 4 component vector
1292
+ Returns false if the matrix cannot be decomposed, true if it can
1415
1293
 
1416
- var Rectangle = /** @class */ (function () {
1417
- function Rectangle(x, y, width, height) {
1418
- this.x = x;
1419
- this.y = y;
1420
- this.width = width;
1421
- this.height = height;
1422
- this.left = x;
1423
- this.right = x + width;
1424
- this.top = y;
1425
- this.bottom = y + height;
1294
+
1295
+ References:
1296
+ https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
1297
+ https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
1298
+ http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
1299
+ */
1300
+ function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
1301
+ //normalize, if not possible then bail out early
1302
+ if (!normalize(tmp, matrix))
1303
+ return false;
1304
+ // perspectiveMatrix is used to solve for perspective, but it also provides
1305
+ // an easy way to test for singularity of the upper 3x3 component.
1306
+ mat4.copy(perspectiveMatrix, tmp);
1307
+ perspectiveMatrix[3] = 0;
1308
+ perspectiveMatrix[7] = 0;
1309
+ perspectiveMatrix[11] = 0;
1310
+ perspectiveMatrix[15] = 1;
1311
+ // If the perspectiveMatrix is not invertible, we are also unable to
1312
+ // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
1313
+ if (Math.abs(mat4.determinant(perspectiveMatrix)) < 1e-8)
1314
+ return false;
1315
+ var a03 = tmp[3], a13 = tmp[7], a23 = tmp[11], a30 = tmp[12], a31 = tmp[13], a32 = tmp[14], a33 = tmp[15];
1316
+ // First, isolate perspective.
1317
+ if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
1318
+ tmpVec4[0] = a03;
1319
+ tmpVec4[1] = a13;
1320
+ tmpVec4[2] = a23;
1321
+ tmpVec4[3] = a33;
1322
+ // Solve the equation by inverting perspectiveMatrix and multiplying
1323
+ // rightHandSide by the inverse.
1324
+ // resuing the perspectiveMatrix here since it's no longer needed
1325
+ var ret = mat4.invert(perspectiveMatrix, perspectiveMatrix);
1326
+ if (!ret)
1327
+ return false;
1328
+ mat4.transpose(perspectiveMatrix, perspectiveMatrix);
1329
+ //multiply by transposed inverse perspective matrix, into perspective vec4
1330
+ vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
1331
+ }
1332
+ else {
1333
+ //no perspective
1334
+ perspective[0] = perspective[1] = perspective[2] = 0;
1335
+ perspective[3] = 1;
1336
+ }
1337
+ // Next take care of translation
1338
+ translation[0] = a30;
1339
+ translation[1] = a31;
1340
+ translation[2] = a32;
1341
+ // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
1342
+ mat3from4(row, tmp);
1343
+ // Compute X scale factor and normalize first row.
1344
+ scale[0] = vec3.length(row[0]);
1345
+ vec3.normalize(row[0], row[0]);
1346
+ // Compute XY shear factor and make 2nd row orthogonal to 1st.
1347
+ skew[0] = vec3.dot(row[0], row[1]);
1348
+ combine(row[1], row[1], row[0], 1.0, -skew[0]);
1349
+ // Now, compute Y scale and normalize 2nd row.
1350
+ scale[1] = vec3.length(row[1]);
1351
+ vec3.normalize(row[1], row[1]);
1352
+ skew[0] /= scale[1];
1353
+ // Compute XZ and YZ shears, orthogonalize 3rd row
1354
+ skew[1] = vec3.dot(row[0], row[2]);
1355
+ combine(row[2], row[2], row[0], 1.0, -skew[1]);
1356
+ skew[2] = vec3.dot(row[1], row[2]);
1357
+ combine(row[2], row[2], row[1], 1.0, -skew[2]);
1358
+ // Next, get Z scale and normalize 3rd row.
1359
+ scale[2] = vec3.length(row[2]);
1360
+ vec3.normalize(row[2], row[2]);
1361
+ skew[1] /= scale[2];
1362
+ skew[2] /= scale[2];
1363
+ // At this point, the matrix (in rows) is orthonormal.
1364
+ // Check for a coordinate system flip. If the determinant
1365
+ // is -1, then negate the matrix and the scaling factors.
1366
+ vec3.cross(pdum3, row[1], row[2]);
1367
+ if (vec3.dot(row[0], pdum3) < 0) {
1368
+ for (var i = 0; i < 3; i++) {
1369
+ scale[i] *= -1;
1370
+ row[i][0] *= -1;
1371
+ row[i][1] *= -1;
1372
+ row[i][2] *= -1;
1373
+ }
1426
1374
  }
1427
- /**
1428
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect/fromRect_static
1429
- */
1430
- Rectangle.fromRect = function (rect) {
1431
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
1432
- };
1433
- /**
1434
- * will return a new rect instance
1435
- */
1436
- Rectangle.applyTransform = function (rect, matrix) {
1437
- var topLeft = vec4.fromValues(rect.x, rect.y, 0, 1);
1438
- var topRight = vec4.fromValues(rect.x + rect.width, rect.y, 0, 1);
1439
- var bottomLeft = vec4.fromValues(rect.x, rect.y + rect.height, 0, 1);
1440
- var bottomRight = vec4.fromValues(rect.x + rect.width, rect.y + rect.height, 0, 1);
1441
- var transformedTopLeft = vec4.create();
1442
- var transformedTopRight = vec4.create();
1443
- var transformedBottomLeft = vec4.create();
1444
- var transformedBottomRight = vec4.create();
1445
- vec4.transformMat4(transformedTopLeft, topLeft, matrix);
1446
- vec4.transformMat4(transformedTopRight, topRight, matrix);
1447
- vec4.transformMat4(transformedBottomLeft, bottomLeft, matrix);
1448
- vec4.transformMat4(transformedBottomRight, bottomRight, matrix);
1449
- var minX = Math.min(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1450
- var minY = Math.min(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1451
- var maxX = Math.max(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1452
- var maxY = Math.max(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1453
- return Rectangle.fromRect({
1454
- x: minX,
1455
- y: minY,
1456
- width: maxX - minX,
1457
- height: maxY - minY,
1458
- });
1459
- };
1460
- Rectangle.prototype.toJSON = function () { };
1461
- return Rectangle;
1462
- }());
1463
-
1464
- var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
1465
- var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
1466
- var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
1375
+ // Now, get the rotations out
1376
+ quaternion[0] =
1377
+ 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
1378
+ quaternion[1] =
1379
+ 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
1380
+ quaternion[2] =
1381
+ 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
1382
+ quaternion[3] =
1383
+ 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
1384
+ if (row[2][1] > row[1][2])
1385
+ quaternion[0] = -quaternion[0];
1386
+ if (row[0][2] > row[2][0])
1387
+ quaternion[1] = -quaternion[1];
1388
+ if (row[1][0] > row[0][1])
1389
+ quaternion[2] = -quaternion[2];
1390
+ return true;
1391
+ }
1392
+ function normalize(out, mat) {
1393
+ var m44 = mat[15];
1394
+ // Cannot normalize.
1395
+ if (m44 === 0)
1396
+ return false;
1397
+ var scale = 1 / m44;
1398
+ for (var i = 0; i < 16; i++)
1399
+ out[i] = mat[i] * scale;
1400
+ return true;
1401
+ }
1402
+ //gets upper-left of a 4x4 matrix into a 3x3 of vectors
1403
+ function mat3from4(out, mat4x4) {
1404
+ out[0][0] = mat4x4[0];
1405
+ out[0][1] = mat4x4[1];
1406
+ out[0][2] = mat4x4[2];
1407
+ out[1][0] = mat4x4[4];
1408
+ out[1][1] = mat4x4[5];
1409
+ out[1][2] = mat4x4[6];
1410
+ out[2][0] = mat4x4[8];
1411
+ out[2][1] = mat4x4[9];
1412
+ out[2][2] = mat4x4[10];
1413
+ }
1414
+ function combine(out, a, b, scale1, scale2) {
1415
+ out[0] = a[0] * scale1 + b[0] * scale2;
1416
+ out[1] = a[1] * scale1 + b[1] * scale2;
1417
+ out[2] = a[2] * scale1 + b[2] * scale2;
1418
+ }
1467
1419
 
1468
1420
  /**
1469
1421
  * Different type of cameras, eg. simple camera used in 2D scene or
@@ -2215,6 +2167,99 @@ var Camera = /** @class */ (function () {
2215
2167
  return Camera;
2216
2168
  }());
2217
2169
 
2170
+ /**
2171
+ * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
2172
+ */
2173
+ var Strategy;
2174
+ (function (Strategy) {
2175
+ Strategy[Strategy["Standard"] = 0] = "Standard";
2176
+ })(Strategy || (Strategy = {}));
2177
+
2178
+ var SortReason;
2179
+ (function (SortReason) {
2180
+ SortReason[SortReason["ADDED"] = 0] = "ADDED";
2181
+ SortReason[SortReason["REMOVED"] = 1] = "REMOVED";
2182
+ SortReason[SortReason["Z_INDEX_CHANGED"] = 2] = "Z_INDEX_CHANGED";
2183
+ })(SortReason || (SortReason = {}));
2184
+
2185
+ var EMPTY_PARSED_PATH = {
2186
+ absolutePath: [],
2187
+ hasArc: false,
2188
+ segments: [],
2189
+ polygons: [],
2190
+ polylines: [],
2191
+ curve: null,
2192
+ totalLength: 0,
2193
+ rect: new Rectangle(0, 0, 0, 0),
2194
+ };
2195
+
2196
+ /**
2197
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
2198
+ */
2199
+ var PropertySyntax;
2200
+ (function (PropertySyntax) {
2201
+ /**
2202
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
2203
+ */
2204
+ PropertySyntax["COORDINATE"] = "<coordinate>";
2205
+ /**
2206
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
2207
+ */
2208
+ PropertySyntax["COLOR"] = "<color>";
2209
+ /**
2210
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
2211
+ */
2212
+ PropertySyntax["PAINT"] = "<paint>";
2213
+ /**
2214
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
2215
+ */
2216
+ PropertySyntax["NUMBER"] = "<number>";
2217
+ /**
2218
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle
2219
+ */
2220
+ PropertySyntax["ANGLE"] = "<angle>";
2221
+ /**
2222
+ * <number> with range 0..1
2223
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
2224
+ */
2225
+ PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
2226
+ /**
2227
+ * <number> with range 0..Infinity
2228
+ */
2229
+ PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
2230
+ /**
2231
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
2232
+ */
2233
+ PropertySyntax["LENGTH"] = "<length>";
2234
+ /**
2235
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
2236
+ */
2237
+ PropertySyntax["PERCENTAGE"] = "<percentage>";
2238
+ PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
2239
+ PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
2240
+ /**
2241
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
2242
+ */
2243
+ PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
2244
+ /**
2245
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
2246
+ */
2247
+ PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
2248
+ PropertySyntax["PATH"] = "<path>";
2249
+ /**
2250
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
2251
+ */
2252
+ PropertySyntax["FILTER"] = "<filter>";
2253
+ PropertySyntax["Z_INDEX"] = "<z-index>";
2254
+ PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
2255
+ PropertySyntax["DEFINED_PATH"] = "<defined-path>";
2256
+ PropertySyntax["MARKER"] = "<marker>";
2257
+ PropertySyntax["TRANSFORM"] = "<transform>";
2258
+ PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
2259
+ PropertySyntax["TEXT"] = "<text>";
2260
+ PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
2261
+ })(PropertySyntax || (PropertySyntax = {}));
2262
+
2218
2263
  function memoize(func, resolver) {
2219
2264
  if (typeof func !== 'function' ||
2220
2265
  (resolver != null && typeof resolver !== 'function')) {
@@ -2331,14 +2376,6 @@ var UnitCategory;
2331
2376
  // kUResolution,
2332
2377
  UnitCategory[UnitCategory["kUOther"] = 5] = "kUOther";
2333
2378
  })(UnitCategory || (UnitCategory = {}));
2334
- var ValueRange;
2335
- (function (ValueRange) {
2336
- ValueRange[ValueRange["kAll"] = 0] = "kAll";
2337
- ValueRange[ValueRange["kNonNegative"] = 1] = "kNonNegative";
2338
- ValueRange[ValueRange["kInteger"] = 2] = "kInteger";
2339
- ValueRange[ValueRange["kNonNegativeInteger"] = 3] = "kNonNegativeInteger";
2340
- ValueRange[ValueRange["kPositiveInteger"] = 4] = "kPositiveInteger";
2341
- })(ValueRange || (ValueRange = {}));
2342
2379
  var Nested;
2343
2380
  (function (Nested) {
2344
2381
  Nested[Nested["kYes"] = 0] = "kYes";
@@ -2857,13 +2894,6 @@ var CSSColorValue = /** @class */ (function (_super) {
2857
2894
  CSSColorValue.prototype.getType = function () {
2858
2895
  return CSSStyleValueType.kColorType;
2859
2896
  };
2860
- // buildCSSText(n: Nested, p: ParenLess, result: string): string {
2861
- // let text = '';
2862
- // if (this.colorSpace === 'rgb') {
2863
- // text = `rgba(${this.channels.join(',')},${this.alpha})`;
2864
- // }
2865
- // return (result += text);
2866
- // }
2867
2897
  /**
2868
2898
  * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to
2869
2899
  */
@@ -2905,101 +2935,25 @@ var CSSGradientValue = /** @class */ (function (_super) {
2905
2935
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue
2906
2936
  * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl
2907
2937
  */
2908
- var CSSKeywordValue = /** @class */ (function (_super) {
2909
- __extends(CSSKeywordValue, _super);
2910
- function CSSKeywordValue(value) {
2911
- var _this = _super.call(this) || this;
2912
- _this.value = value;
2913
- return _this;
2914
- }
2915
- CSSKeywordValue.prototype.clone = function () {
2916
- return new CSSKeywordValue(this.value);
2917
- };
2918
- CSSKeywordValue.prototype.getType = function () {
2919
- return CSSStyleValueType.kKeywordType;
2920
- };
2921
- CSSKeywordValue.prototype.buildCSSText = function (n, p, result) {
2922
- return result + this.value;
2923
- };
2924
- return CSSKeywordValue;
2925
- }(CSSStyleValue));
2926
-
2927
- var camelCase = memoize(function (str) {
2928
- if (str === void 0) { str = ''; }
2929
- return str.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
2930
- });
2931
- var kebabize = function (str) {
2932
- return str
2933
- .split('')
2934
- .map(function (letter, idx) {
2935
- return letter.toUpperCase() === letter
2936
- ? "".concat(idx !== 0 ? '-' : '').concat(letter.toLowerCase())
2937
- : letter;
2938
- })
2939
- .join('');
2940
- };
2941
-
2942
- function DCHECK(bool) {
2943
- if (!bool) {
2944
- throw new Error();
2945
- }
2946
- }
2947
- function isFunction(func) {
2948
- return typeof func === 'function';
2949
- }
2950
- function isSymbol(value) {
2951
- // @see https://github.com/lodash/lodash/blob/master/isSymbol.js
2952
- return typeof value === 'symbol';
2953
- }
2954
- var definedProps = function (obj) {
2955
- return Object.fromEntries(Object.entries(obj).filter(function (_a) {
2956
- var _b = __read(_a, 2), v = _b[1];
2957
- return v !== undefined;
2958
- }));
2959
- };
2960
- var FORMAT_ATTR_MAP = {
2961
- d: {
2962
- alias: 'path',
2963
- },
2964
- strokeDasharray: {
2965
- alias: 'lineDash',
2966
- },
2967
- strokeWidth: {
2968
- alias: 'lineWidth',
2969
- },
2970
- textAnchor: {
2971
- alias: 'textAlign',
2972
- },
2973
- src: {
2974
- alias: 'img',
2975
- },
2976
- };
2977
- var formatAttributeName = memoize(function (name) {
2978
- var attributeName = camelCase(name);
2979
- var map = FORMAT_ATTR_MAP[attributeName];
2980
- attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
2981
- return attributeName;
2982
- });
2938
+ var CSSKeywordValue = /** @class */ (function (_super) {
2939
+ __extends(CSSKeywordValue, _super);
2940
+ function CSSKeywordValue(value) {
2941
+ var _this = _super.call(this) || this;
2942
+ _this.value = value;
2943
+ return _this;
2944
+ }
2945
+ CSSKeywordValue.prototype.clone = function () {
2946
+ return new CSSKeywordValue(this.value);
2947
+ };
2948
+ CSSKeywordValue.prototype.getType = function () {
2949
+ return CSSStyleValueType.kKeywordType;
2950
+ };
2951
+ CSSKeywordValue.prototype.buildCSSText = function (n, p, result) {
2952
+ return result + this.value;
2953
+ };
2954
+ return CSSKeywordValue;
2955
+ }(CSSStyleValue));
2983
2956
 
2984
- // type CSSNumericBaseType =
2985
- // | 'length'
2986
- // | 'angle'
2987
- // | 'time'
2988
- // | 'frequency'
2989
- // | 'resolution'
2990
- // | 'flex'
2991
- // | 'percent';
2992
- // https://drafts.css-houdini.org/css-typed-om/#dictdef-cssnumerictype
2993
- // interface CSSNumericType {
2994
- // length: number;
2995
- // angle: number;
2996
- // time: number;
2997
- // frequency: number;
2998
- // resolution: number;
2999
- // flex: number;
3000
- // percent: number;
3001
- // percentHint: CSSNumericBaseType;
3002
- // }
3003
2957
  var formatInfinityOrNaN = function (number, suffix) {
3004
2958
  if (suffix === void 0) { suffix = ''; }
3005
2959
  var result = '';
@@ -3010,7 +2964,6 @@ var formatInfinityOrNaN = function (number, suffix) {
3010
2964
  result = '-infinity';
3011
2965
  }
3012
2966
  else {
3013
- DCHECK(Number.isNaN(number));
3014
2967
  result = 'NaN';
3015
2968
  }
3016
2969
  return (result += suffix);
@@ -3106,25 +3059,25 @@ var CSSUnitValue = /** @class */ (function (_super) {
3106
3059
  case UnitType.kSeconds:
3107
3060
  // case UnitType.kHertz:
3108
3061
  // case UnitType.kKilohertz:
3109
- case UnitType.kTurns: // case UnitType.kContainerMax: { // 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:
3110
- {
3111
- var kMinInteger = -999999;
3112
- var kMaxInteger = 999999;
3113
- var value = this.value;
3114
- var unit = unitTypeToString(this.unit);
3115
- if (value < kMinInteger || value > kMaxInteger) {
3116
- var unit_1 = unitTypeToString(this.unit);
3117
- if (!Number.isFinite(value) || Number.isNaN(value)) {
3118
- text = formatInfinityOrNaN(value, unit_1);
3119
- }
3120
- else {
3121
- text = value + (unit_1 || '');
3122
- }
3062
+ case UnitType.kTurns: {
3063
+ // case UnitType.kContainerMax: { // 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:
3064
+ var kMinInteger = -999999;
3065
+ var kMaxInteger = 999999;
3066
+ var value = this.value;
3067
+ var unit = unitTypeToString(this.unit);
3068
+ if (value < kMinInteger || value > kMaxInteger) {
3069
+ var unit_1 = unitTypeToString(this.unit);
3070
+ if (!Number.isFinite(value) || Number.isNaN(value)) {
3071
+ text = formatInfinityOrNaN(value, unit_1);
3123
3072
  }
3124
3073
  else {
3125
- text = "".concat(value).concat(unit);
3074
+ text = value + (unit_1 || '');
3126
3075
  }
3127
3076
  }
3077
+ else {
3078
+ text = "".concat(value).concat(unit);
3079
+ }
3080
+ }
3128
3081
  }
3129
3082
  result += text;
3130
3083
  return result;
@@ -3208,99 +3161,6 @@ var getOrCreateUnitValue = function (value, unitOrName) {
3208
3161
  };
3209
3162
  new CSSUnitValue(50, '%');
3210
3163
 
3211
- /**
3212
- * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
3213
- */
3214
- var Strategy;
3215
- (function (Strategy) {
3216
- Strategy[Strategy["Standard"] = 0] = "Standard";
3217
- })(Strategy || (Strategy = {}));
3218
-
3219
- var SortReason;
3220
- (function (SortReason) {
3221
- SortReason[SortReason["ADDED"] = 0] = "ADDED";
3222
- SortReason[SortReason["REMOVED"] = 1] = "REMOVED";
3223
- SortReason[SortReason["Z_INDEX_CHANGED"] = 2] = "Z_INDEX_CHANGED";
3224
- })(SortReason || (SortReason = {}));
3225
-
3226
- var EMPTY_PARSED_PATH = {
3227
- absolutePath: [],
3228
- hasArc: false,
3229
- segments: [],
3230
- polygons: [],
3231
- polylines: [],
3232
- curve: null,
3233
- totalLength: 0,
3234
- rect: new Rectangle(0, 0, 0, 0),
3235
- };
3236
-
3237
- /**
3238
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
3239
- */
3240
- var PropertySyntax;
3241
- (function (PropertySyntax) {
3242
- /**
3243
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
3244
- */
3245
- PropertySyntax["COORDINATE"] = "<coordinate>";
3246
- /**
3247
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
3248
- */
3249
- PropertySyntax["COLOR"] = "<color>";
3250
- /**
3251
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
3252
- */
3253
- PropertySyntax["PAINT"] = "<paint>";
3254
- /**
3255
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
3256
- */
3257
- PropertySyntax["NUMBER"] = "<number>";
3258
- /**
3259
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle
3260
- */
3261
- PropertySyntax["ANGLE"] = "<angle>";
3262
- /**
3263
- * <number> with range 0..1
3264
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
3265
- */
3266
- PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
3267
- /**
3268
- * <number> with range 0..Infinity
3269
- */
3270
- PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
3271
- /**
3272
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
3273
- */
3274
- PropertySyntax["LENGTH"] = "<length>";
3275
- /**
3276
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
3277
- */
3278
- PropertySyntax["PERCENTAGE"] = "<percentage>";
3279
- PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
3280
- PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
3281
- /**
3282
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
3283
- */
3284
- PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
3285
- /**
3286
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
3287
- */
3288
- PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
3289
- PropertySyntax["PATH"] = "<path>";
3290
- /**
3291
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
3292
- */
3293
- PropertySyntax["FILTER"] = "<filter>";
3294
- PropertySyntax["Z_INDEX"] = "<z-index>";
3295
- PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
3296
- PropertySyntax["DEFINED_PATH"] = "<defined-path>";
3297
- PropertySyntax["MARKER"] = "<marker>";
3298
- PropertySyntax["TRANSFORM"] = "<transform>";
3299
- PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
3300
- PropertySyntax["TEXT"] = "<text>";
3301
- PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
3302
- })(PropertySyntax || (PropertySyntax = {}));
3303
-
3304
3164
  /**
3305
3165
  * borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
3306
3166
  * @see https://github.com/rafaelcaricio/gradient-parser
@@ -4124,16 +3984,6 @@ function parseDimensionArrayFormat(string, size) {
4124
3984
  }
4125
3985
  }
4126
3986
  }
4127
- function parseDimensionArray(string) {
4128
- if (isString(string)) {
4129
- // "1px 2px 3px"
4130
- return string.split(' ').map(function (segment) { return parseLengthOrPercentage(segment); });
4131
- }
4132
- else {
4133
- // [1, '2px', 3]
4134
- return string.map(function (segment) { return parseLengthOrPercentage(segment.toString()); });
4135
- }
4136
- }
4137
3987
  // export function mergeDimensionList(
4138
3988
  // left: CSSUnitValue[],
4139
3989
  // right: CSSUnitValue[],
@@ -5162,6 +5012,7 @@ function mergePoints(left, right) {
5162
5012
  }
5163
5013
 
5164
5014
  var _ = null;
5015
+ var TRANSFORM_REGEXP = /\s*(\w+)\(([^)]*)\)/g;
5165
5016
  function cast(pattern) {
5166
5017
  return function (contents) {
5167
5018
  var i = 0;
@@ -5180,48 +5031,75 @@ var transformFunctions = {
5180
5031
  matrix: ['NNNNNN', [_, _, 0, 0, _, _, 0, 0, 0, 0, 1, 0, _, _, 0, 1], id],
5181
5032
  matrix3d: ['NNNNNNNNNNNNNNNN', id],
5182
5033
  rotate: ['A'],
5183
- rotatex: ['A'],
5184
- rotatey: ['A'],
5185
- rotatez: ['A'],
5034
+ rotateX: ['A'],
5035
+ rotateY: ['A'],
5036
+ rotateZ: ['A'],
5186
5037
  rotate3d: ['NNNA'],
5187
5038
  perspective: ['L'],
5188
5039
  scale: ['Nn', cast([_, _, new CSSUnitValue(1)]), id],
5189
- scalex: [
5040
+ scaleX: [
5190
5041
  'N',
5191
5042
  cast([_, new CSSUnitValue(1), new CSSUnitValue(1)]),
5192
5043
  cast([_, new CSSUnitValue(1)]),
5193
5044
  ],
5194
- scaley: [
5045
+ scaleY: [
5195
5046
  'N',
5196
5047
  cast([new CSSUnitValue(1), _, new CSSUnitValue(1)]),
5197
5048
  cast([new CSSUnitValue(1), _]),
5198
5049
  ],
5199
- scalez: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5050
+ scaleZ: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5200
5051
  scale3d: ['NNN', id],
5201
5052
  skew: ['Aa', null, id],
5202
- skewx: ['A', null, cast([_, Odeg])],
5203
- skewy: ['A', null, cast([Odeg, _])],
5053
+ skewX: ['A', null, cast([_, Odeg])],
5054
+ skewY: ['A', null, cast([Odeg, _])],
5204
5055
  translate: ['Tt', cast([_, _, Opx]), id],
5205
- translatex: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5206
- translatey: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5207
- translatez: ['L', cast([Opx, Opx, _])],
5056
+ translateX: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5057
+ translateY: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5058
+ translateZ: ['L', cast([Opx, Opx, _])],
5208
5059
  translate3d: ['TTL', id],
5209
5060
  };
5061
+ function parseArrayTransform(transform) {
5062
+ var result = [];
5063
+ var length = transform.length;
5064
+ for (var i = 0; i < length; i++) {
5065
+ var item = transform[i];
5066
+ var name_1 = item[0];
5067
+ var args = item.slice(1);
5068
+ // infer default value
5069
+ if (name_1 === 'translate' || name_1 === 'skew') {
5070
+ if (args.length === 1)
5071
+ args.push(0);
5072
+ }
5073
+ else if (name_1 === 'scale') {
5074
+ if (args.length === 1)
5075
+ args.push(args[0]);
5076
+ }
5077
+ var functionData = transformFunctions[name_1];
5078
+ if (!functionData)
5079
+ return [];
5080
+ var parsedArgs = args.map(function (value) { return getOrCreateUnitValue(value); });
5081
+ result.push({ t: name_1, d: parsedArgs });
5082
+ }
5083
+ return result;
5084
+ }
5210
5085
  /**
5211
5086
  * none
5212
5087
  * scale(1) scale(1, 2)
5213
5088
  * scaleX(1)
5214
5089
  */
5215
- function parseTransform(string) {
5216
- string = (string || 'none').toLowerCase().trim();
5217
- if (string === 'none') {
5090
+ function parseTransform(transform) {
5091
+ if (Array.isArray(transform)) {
5092
+ return parseArrayTransform(transform);
5093
+ }
5094
+ transform = (transform || 'none').trim();
5095
+ if (transform === 'none') {
5218
5096
  return [];
5219
5097
  }
5220
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5221
5098
  var result = [];
5222
5099
  var match;
5223
5100
  var prevLastIndex = 0;
5224
- while ((match = transformRegExp.exec(string))) {
5101
+ TRANSFORM_REGEXP.lastIndex = 0;
5102
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5225
5103
  if (match.index !== prevLastIndex) {
5226
5104
  return [];
5227
5105
  }
@@ -5268,22 +5146,25 @@ function parseTransform(string) {
5268
5146
  parsedArgs.push(parsedArg);
5269
5147
  }
5270
5148
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5271
- if (transformRegExp.lastIndex === string.length) {
5149
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5272
5150
  return result;
5273
5151
  }
5274
5152
  }
5275
5153
  return [];
5276
5154
  }
5277
- function parseTransformUnmemoize(string) {
5278
- string = (string || 'none').toLowerCase().trim();
5279
- if (string === 'none') {
5155
+ function parseTransformUnmemoize(transform) {
5156
+ if (Array.isArray(transform)) {
5157
+ return parseArrayTransform(transform);
5158
+ }
5159
+ transform = (transform || 'none').trim();
5160
+ if (transform === 'none') {
5280
5161
  return [];
5281
5162
  }
5282
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5283
5163
  var result = [];
5284
5164
  var match;
5285
5165
  var prevLastIndex = 0;
5286
- while ((match = transformRegExp.exec(string))) {
5166
+ TRANSFORM_REGEXP.lastIndex = 0;
5167
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5287
5168
  if (match.index !== prevLastIndex) {
5288
5169
  return [];
5289
5170
  }
@@ -5330,7 +5211,7 @@ function parseTransformUnmemoize(string) {
5330
5211
  parsedArgs.push(parsedArg);
5331
5212
  }
5332
5213
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5333
- if (transformRegExp.lastIndex === string.length) {
5214
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5334
5215
  return result;
5335
5216
  }
5336
5217
  }
@@ -5342,7 +5223,7 @@ function convertItemToMatrix(item) {
5342
5223
  var z;
5343
5224
  var angle;
5344
5225
  switch (item.t) {
5345
- case 'rotatex':
5226
+ case 'rotateX':
5346
5227
  angle = deg2rad(convertAngleUnit(item.d[0]));
5347
5228
  return [
5348
5229
  1,
@@ -5362,7 +5243,7 @@ function convertItemToMatrix(item) {
5362
5243
  0,
5363
5244
  1,
5364
5245
  ];
5365
- case 'rotatey':
5246
+ case 'rotateY':
5366
5247
  angle = deg2rad(convertAngleUnit(item.d[0]));
5367
5248
  return [
5368
5249
  Math.cos(angle),
@@ -5383,7 +5264,7 @@ function convertItemToMatrix(item) {
5383
5264
  1,
5384
5265
  ];
5385
5266
  case 'rotate':
5386
- case 'rotatez':
5267
+ case 'rotateZ':
5387
5268
  angle = deg2rad(convertAngleUnit(item.d[0]));
5388
5269
  return [
5389
5270
  Math.cos(angle),
@@ -5460,11 +5341,11 @@ function convertItemToMatrix(item) {
5460
5341
  0,
5461
5342
  1,
5462
5343
  ];
5463
- case 'scalex':
5344
+ case 'scaleX':
5464
5345
  return [item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5465
- case 'scaley':
5346
+ case 'scaleY':
5466
5347
  return [1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5467
- case 'scalez':
5348
+ case 'scaleZ':
5468
5349
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1];
5469
5350
  case 'scale3d':
5470
5351
  return [
@@ -5506,10 +5387,10 @@ function convertItemToMatrix(item) {
5506
5387
  0,
5507
5388
  1,
5508
5389
  ];
5509
- case 'skewx':
5390
+ case 'skewX':
5510
5391
  angle = deg2rad(convertAngleUnit(item.d[0]));
5511
5392
  return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5512
- case 'skewy':
5393
+ case 'skewY':
5513
5394
  angle = deg2rad(convertAngleUnit(item.d[0]));
5514
5395
  return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5515
5396
  case 'translate':
@@ -5517,13 +5398,13 @@ function convertItemToMatrix(item) {
5517
5398
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5518
5399
  y = convertPercentUnit(item.d[1], 0, null) || 0;
5519
5400
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, 0, 1];
5520
- case 'translatex':
5401
+ case 'translateX':
5521
5402
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5522
5403
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
5523
- case 'translatey':
5404
+ case 'translateY':
5524
5405
  y = convertPercentUnit(item.d[0], 0, null) || 0;
5525
5406
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, y, 0, 1];
5526
- case 'translatez':
5407
+ case 'translateZ':
5527
5408
  z = convertPercentUnit(item.d[0], 0, null) || 0;
5528
5409
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, z, 1];
5529
5410
  case 'translate3d':
@@ -5764,13 +5645,13 @@ function quat(fromQ, toQ, f) {
5764
5645
  }
5765
5646
  return quat;
5766
5647
  }
5767
- // scalex/y/z -> scale
5648
+ // scaleX/Y/Z -> scale
5768
5649
  function typeTo2D(type) {
5769
- return type.replace(/[xy]/, '');
5650
+ return type.replace(/[XY]/, '');
5770
5651
  }
5771
- // scalex/y/z -> scale3d
5652
+ // scaleX/Y/Z -> scale3d
5772
5653
  function typeTo3D(type) {
5773
- return type.replace(/(x|y|z|3d)?$/, '3d');
5654
+ return type.replace(/(X|Y|Z|3d)?$/, '3d');
5774
5655
  }
5775
5656
  var isMatrixOrPerspective = function (lt, rt) {
5776
5657
  return ((lt === 'perspective' && rt === 'perspective') ||
@@ -5951,39 +5832,6 @@ var parseTransformOrigin = memoize(function (value) {
5951
5832
  ];
5952
5833
  }
5953
5834
  });
5954
- var parseTransformOriginUnmemoize = function (value) {
5955
- if (isString(value)) {
5956
- if (value === 'text-anchor') {
5957
- return [getOrCreateUnitValue(0, 'px'), getOrCreateUnitValue(0, 'px')];
5958
- }
5959
- var values = value.split(' ');
5960
- if (values.length === 1) {
5961
- if (values[0] === 'top' || values[0] === 'bottom') {
5962
- // 'top' -> 'center top'
5963
- values[1] = values[0];
5964
- values[0] = 'center';
5965
- }
5966
- else {
5967
- // '50px' -> '50px center'
5968
- values[1] = 'center';
5969
- }
5970
- }
5971
- if (values.length !== 2) {
5972
- return null;
5973
- }
5974
- // eg. center bottom
5975
- return [
5976
- parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[0])),
5977
- parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[1])),
5978
- ];
5979
- }
5980
- else {
5981
- return [
5982
- getOrCreateUnitValue(value[0] || 0, 'px'),
5983
- getOrCreateUnitValue(value[1] || 0, 'px'),
5984
- ];
5985
- }
5986
- };
5987
5835
  function convertKeyword2Percent(keyword) {
5988
5836
  if (keyword === 'center') {
5989
5837
  return '50%';
@@ -6578,23 +6426,7 @@ var BUILT_IN_PROPERTIES = [
6578
6426
  ];
6579
6427
  var GEOMETRY_ATTRIBUTE_NAMES = BUILT_IN_PROPERTIES.filter(function (n) { return !!n.l; }).map(function (n) { return n.n; });
6580
6428
  var propertyMetadataCache = {};
6581
- var unresolvedProperties = new WeakMap();
6582
- // const uniqueAttributeSet = new Set<string>();
6583
- // const tmpVec3a = vec3.create();
6584
- // const tmpVec3b = vec3.create();
6585
- // const tmpVec3c = vec3.create();
6586
- var isPropertyResolved = function (object, name) {
6587
- var properties = unresolvedProperties.get(object);
6588
- if (!properties || properties.length === 0) {
6589
- return true;
6590
- }
6591
- return properties.includes(name);
6592
- };
6593
6429
  var DefaultStyleValueRegistry = /** @class */ (function () {
6594
- /**
6595
- * need recalc later
6596
- */
6597
- // dirty = false;
6598
6430
  function DefaultStyleValueRegistry(runtime) {
6599
6431
  var _this = this;
6600
6432
  this.runtime = runtime;
@@ -6607,9 +6439,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6607
6439
  propertyMetadataCache[name] = metadata;
6608
6440
  });
6609
6441
  };
6610
- DefaultStyleValueRegistry.prototype.unregisterMetadata = function (name) {
6611
- delete propertyMetadataCache[name];
6612
- };
6613
6442
  DefaultStyleValueRegistry.prototype.getPropertySyntax = function (syntax) {
6614
6443
  return this.runtime.CSSPropertySyntaxFactory[syntax];
6615
6444
  };
@@ -6623,7 +6452,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6623
6452
  * * post process
6624
6453
  */
6625
6454
  DefaultStyleValueRegistry.prototype.processProperties = function (object, attributes, options) {
6626
- var _this = this;
6627
6455
  if (options === void 0) { options = {
6628
6456
  skipUpdateAttribute: false,
6629
6457
  skipParse: false,
@@ -6631,365 +6459,116 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6631
6459
  usedAttributes: [],
6632
6460
  memoize: true,
6633
6461
  }; }
6634
- if (!this.runtime.enableCSSParsing) {
6635
- Object.assign(object.attributes, attributes);
6636
- var attributeNames = Object.keys(attributes);
6637
- // clipPath
6638
- var oldClipPath = object.parsedStyle.clipPath;
6639
- var oldOffsetPath = object.parsedStyle.offsetPath;
6640
- object.parsedStyle = Object.assign(object.parsedStyle, attributes);
6641
- var needUpdateGeometry = !!options.forceUpdateGeometry;
6642
- if (!needUpdateGeometry) {
6643
- for (var i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
6644
- if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
6645
- needUpdateGeometry = true;
6646
- break;
6647
- }
6648
- }
6649
- }
6650
- if (attributes.fill) {
6651
- object.parsedStyle.fill = parseColor(attributes.fill);
6652
- }
6653
- if (attributes.stroke) {
6654
- object.parsedStyle.stroke = parseColor(attributes.stroke);
6655
- }
6656
- if (attributes.shadowColor) {
6657
- object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
6658
- }
6659
- if (attributes.filter) {
6660
- object.parsedStyle.filter = parseFilter(attributes.filter);
6661
- }
6662
- // Rect
6663
- // @ts-ignore
6664
- if (!isNil(attributes.radius)) {
6665
- // @ts-ignore
6666
- object.parsedStyle.radius = parseDimensionArrayFormat(
6667
- // @ts-ignore
6668
- attributes.radius, 4);
6669
- }
6670
- // Polyline
6671
- if (!isNil(attributes.lineDash)) {
6672
- object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6673
- }
6674
- // @ts-ignore
6675
- if (attributes.points) {
6676
- // @ts-ignore
6677
- object.parsedStyle.points = parsePoints(attributes.points);
6678
- }
6679
- // Path
6680
- // @ts-ignore
6681
- if (attributes.d === '') {
6682
- object.parsedStyle.d = __assign({}, EMPTY_PARSED_PATH);
6683
- }
6462
+ Object.assign(object.attributes, attributes);
6463
+ // clipPath
6464
+ var oldClipPath = object.parsedStyle.clipPath;
6465
+ var oldOffsetPath = object.parsedStyle.offsetPath;
6466
+ Object.assign(object.parsedStyle, attributes);
6467
+ var needUpdateGeometry = !!options.forceUpdateGeometry;
6468
+ if (!needUpdateGeometry &&
6469
+ GEOMETRY_ATTRIBUTE_NAMES.some(function (name) { return name in attributes; })) {
6470
+ needUpdateGeometry = true;
6471
+ }
6472
+ if (attributes.fill) {
6473
+ object.parsedStyle.fill = parseColor(attributes.fill);
6474
+ }
6475
+ if (attributes.stroke) {
6476
+ object.parsedStyle.stroke = parseColor(attributes.stroke);
6477
+ }
6478
+ if (attributes.shadowColor) {
6479
+ object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
6480
+ }
6481
+ if (attributes.filter) {
6482
+ object.parsedStyle.filter = parseFilter(attributes.filter);
6483
+ }
6484
+ // Rect
6485
+ // @ts-ignore
6486
+ if (!isNil(attributes.radius)) {
6684
6487
  // @ts-ignore
6685
- if (attributes.d) {
6686
- object.parsedStyle.d = parsePath(
6687
- // @ts-ignore
6688
- attributes.d);
6689
- }
6690
- // Text
6691
- if (attributes.textTransform) {
6692
- this.runtime.CSSPropertySyntaxFactory['<text-transform>'].calculator(null, null, { value: attributes.textTransform }, object, null);
6693
- }
6694
- if (!isUndefined(attributes.clipPath)) {
6695
- this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6696
- }
6697
- if (attributes.offsetPath) {
6698
- this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6699
- }
6700
- if (attributes.transform) {
6701
- object.parsedStyle.transform = parseTransform(attributes.transform);
6702
- }
6703
- if (attributes.transformOrigin) {
6704
- object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
6705
- }
6706
- // Marker
6488
+ object.parsedStyle.radius = parseDimensionArrayFormat(
6707
6489
  // @ts-ignore
6708
- if (attributes.markerStart) {
6709
- object.parsedStyle.markerStart = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
6710
- // @ts-ignore
6711
- attributes.markerStart,
6712
- // @ts-ignore
6713
- attributes.markerStart, null, null);
6714
- }
6490
+ attributes.radius, 4);
6491
+ }
6492
+ // Polyline
6493
+ if (!isNil(attributes.lineDash)) {
6494
+ object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6495
+ }
6496
+ // @ts-ignore
6497
+ if (attributes.points) {
6715
6498
  // @ts-ignore
6716
- if (attributes.markerEnd) {
6717
- object.parsedStyle.markerEnd = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
6718
- // @ts-ignore
6719
- attributes.markerEnd,
6720
- // @ts-ignore
6721
- attributes.markerEnd, null, null);
6722
- }
6499
+ object.parsedStyle.points = parsePoints(attributes.points);
6500
+ }
6501
+ // Path
6502
+ // @ts-ignore
6503
+ if (attributes.d === '') {
6504
+ object.parsedStyle.d = __assign({}, EMPTY_PARSED_PATH);
6505
+ }
6506
+ // @ts-ignore
6507
+ if (attributes.d) {
6508
+ object.parsedStyle.d = parsePath(
6723
6509
  // @ts-ignore
6724
- if (attributes.markerMid) {
6725
- object.parsedStyle.markerMid = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator('',
6726
- // @ts-ignore
6727
- attributes.markerMid,
6728
- // @ts-ignore
6729
- attributes.markerMid, null, null);
6730
- }
6731
- if (!isNil(attributes.zIndex)) {
6732
- this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames);
6733
- }
6734
- if (!isNil(attributes.offsetDistance)) {
6735
- this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames);
6736
- }
6737
- if (attributes.transform) {
6738
- this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames);
6739
- }
6740
- if (attributes.transformOrigin) {
6741
- this.runtime.CSSPropertySyntaxFactory['<transform-origin>'].postProcessor(object, attributeNames);
6742
- }
6743
- if (needUpdateGeometry) {
6744
- object.geometry.dirty = true;
6745
- object.renderable.boundsDirty = true;
6746
- object.renderable.renderBoundsDirty = true;
6747
- if (!options.forceUpdateGeometry) {
6748
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6749
- }
6750
- }
6510
+ attributes.d);
6751
6511
  }
6752
- else {
6753
- var skipUpdateAttribute_1 = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize_1 = options.memoize;
6754
- var needUpdateGeometry_1 = forceUpdateGeometry;
6755
- var attributeNames_1 = Object.keys(attributes);
6756
- attributeNames_1.forEach(function (attributeName) {
6757
- var _a;
6758
- if (!skipUpdateAttribute_1) {
6759
- object.attributes[attributeName] = attributes[attributeName];
6760
- }
6761
- if (!needUpdateGeometry_1 && ((_a = propertyMetadataCache[attributeName]) === null || _a === void 0 ? void 0 : _a.l)) {
6762
- needUpdateGeometry_1 = true;
6763
- }
6764
- });
6765
- if (!skipParse) {
6766
- attributeNames_1.forEach(function (name) {
6767
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize_1);
6768
- });
6769
- }
6770
- // let hasUnresolvedProperties = false;
6771
- // parse according to priority
6772
- // path 50
6773
- // points 50
6774
- // text 50
6775
- // textTransform 51
6776
- // transform 100
6777
- // transformOrigin 100
6778
- if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
6779
- // uniqueAttributeSet.clear();
6780
- attributeNames_1 = Array.from(new Set(attributeNames_1.concat(usedAttributes)));
6781
- }
6782
- // [
6783
- // 'path',
6784
- // 'points',
6785
- // 'text',
6786
- // 'textTransform',
6787
- // 'transform',
6788
- // 'transformOrigin',
6789
- // ].forEach((name) => {
6790
- // const index = attributeNames.indexOf(name);
6791
- // if (index > -1) {
6792
- // attributeNames.splice(index, 1);
6793
- // attributeNames.push(name);
6794
- // }
6795
- // });
6796
- attributeNames_1.forEach(function (name) {
6797
- // some style props maybe deleted after parsing such as `anchor` in Text
6798
- if (name in object.computedStyle) {
6799
- object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize_1);
6800
- }
6801
- });
6802
- // if (hasUnresolvedProperties) {
6803
- // this.dirty = true;
6804
- // return;
6805
- // }
6806
- // update geometry
6807
- if (needUpdateGeometry_1) {
6808
- object.geometry.dirty = true;
6809
- object.renderable.boundsDirty = true;
6810
- object.renderable.renderBoundsDirty = true;
6811
- if (!options.forceUpdateGeometry) {
6812
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6813
- }
6814
- }
6815
- attributeNames_1.forEach(function (name) {
6816
- if (name in object.parsedStyle) {
6817
- _this.postProcessProperty(name, object, attributeNames_1);
6818
- }
6819
- });
6820
- if (this.runtime.enableCSSParsing && object.children.length) {
6821
- attributeNames_1.forEach(function (name) {
6822
- if (name in object.parsedStyle && _this.isPropertyInheritable(name)) {
6823
- // update children's inheritable
6824
- object.children.forEach(function (child) {
6825
- child.internalSetAttribute(name, null, {
6826
- skipUpdateAttribute: true,
6827
- skipParse: true,
6828
- });
6829
- });
6830
- }
6831
- });
6832
- }
6512
+ // Text
6513
+ if (attributes.textTransform) {
6514
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.TEXT_TRANSFORM].calculator(null, null, { value: attributes.textTransform }, object, null);
6833
6515
  }
6834
- };
6835
- /**
6836
- * string -> parsed value
6837
- */
6838
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object, memoized) {
6839
- var metadata = propertyMetadataCache[name];
6840
- var computed = value;
6841
- if (value === '' || isNil(value)) {
6842
- value = 'unset';
6516
+ if (!isUndefined(attributes.clipPath)) {
6517
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.DEFINED_PATH].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6843
6518
  }
6844
- if (value === 'unset' || value === 'initial' || value === 'inherit') {
6845
- // computed = new CSSKeywordValue(value);
6846
- computed = getOrCreateKeyword(value);
6519
+ if (attributes.offsetPath) {
6520
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.DEFINED_PATH].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6847
6521
  }
6848
- else {
6849
- if (metadata) {
6850
- var keywords = metadata.k, syntax = metadata.syntax;
6851
- var handler = syntax && this.getPropertySyntax(syntax);
6852
- // use keywords
6853
- if (keywords && keywords.indexOf(value) > -1) {
6854
- // computed = new CSSKeywordValue(value);
6855
- computed = getOrCreateKeyword(value);
6856
- }
6857
- else if (handler) {
6858
- if (!memoized && handler.parserUnmemoize) {
6859
- computed = handler.parserUnmemoize(value, object);
6860
- }
6861
- else if (handler.parser) {
6862
- // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
6863
- computed = handler.parser(value, object);
6864
- }
6865
- }
6866
- }
6522
+ if (attributes.transform) {
6523
+ object.parsedStyle.transform = parseTransform(attributes.transform);
6524
+ }
6525
+ if (attributes.transformOrigin) {
6526
+ object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
6527
+ }
6528
+ // Marker
6529
+ // @ts-ignore
6530
+ if (attributes.markerStart) {
6531
+ object.parsedStyle.markerStart = this.runtime.CSSPropertySyntaxFactory[PropertySyntax.MARKER].calculator(null,
6532
+ // @ts-ignore
6533
+ attributes.markerStart,
6534
+ // @ts-ignore
6535
+ attributes.markerStart, null, null);
6536
+ }
6537
+ // @ts-ignore
6538
+ if (attributes.markerEnd) {
6539
+ object.parsedStyle.markerEnd = this.runtime.CSSPropertySyntaxFactory[PropertySyntax.MARKER].calculator(null,
6540
+ // @ts-ignore
6541
+ attributes.markerEnd,
6542
+ // @ts-ignore
6543
+ attributes.markerEnd, null, null);
6867
6544
  }
6868
- return computed;
6869
- };
6870
- /**
6871
- * computed value -> used value
6872
- */
6873
- DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object, memoized) {
6874
- var metadata = propertyMetadataCache[name];
6875
- var isDocumentElement = object.id === 'g-root';
6876
- // let used: CSSStyleValue = computed instanceof CSSStyleValue ? computed.clone() : computed;
6877
- var used = computed;
6878
- if (metadata) {
6879
- var syntax = metadata.syntax, inherited = metadata.inh, defaultValue = metadata.d;
6880
- if (computed instanceof CSSKeywordValue) {
6881
- var value = computed.value;
6882
- /**
6883
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/unset
6884
- */
6885
- if (value === 'unset') {
6886
- if (inherited && !isDocumentElement) {
6887
- value = 'inherit';
6888
- }
6889
- else {
6890
- value = 'initial';
6891
- }
6892
- }
6893
- if (value === 'initial') {
6894
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
6895
- if (!isNil(defaultValue)) {
6896
- computed = this.parseProperty(name, isFunction(defaultValue)
6897
- ? defaultValue(object.nodeName)
6898
- : defaultValue, object, memoized);
6899
- }
6900
- }
6901
- else if (value === 'inherit') {
6902
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
6903
- // behave like `inherit`
6904
- var resolved = this.tryToResolveProperty(object, name, {
6905
- inherited: true,
6906
- });
6907
- if (!isNil(resolved)) {
6908
- // object.parsedStyle[name] = resolved;
6909
- // return false;
6910
- return resolved;
6911
- }
6912
- else {
6913
- this.addUnresolveProperty(object, name);
6914
- return;
6915
- }
6916
- }
6917
- }
6918
- var handler = syntax && this.getPropertySyntax(syntax);
6919
- if (handler && handler.calculator) {
6920
- // convert computed value to used value
6921
- var oldParsedValue = object.parsedStyle[name];
6922
- used = handler.calculator(name, oldParsedValue, computed, object, this.runtime);
6923
- }
6924
- else if (computed instanceof CSSKeywordValue) {
6925
- used = computed.value;
6926
- }
6927
- else {
6928
- used = computed;
6929
- }
6545
+ // @ts-ignore
6546
+ if (attributes.markerMid) {
6547
+ object.parsedStyle.markerMid = this.runtime.CSSPropertySyntaxFactory[PropertySyntax.MARKER].calculator('',
6548
+ // @ts-ignore
6549
+ attributes.markerMid,
6550
+ // @ts-ignore
6551
+ attributes.markerMid, null, null);
6930
6552
  }
6931
- // object.parsedStyle[name] = used;
6932
- // return false;
6933
- return used;
6934
- };
6935
- DefaultStyleValueRegistry.prototype.postProcessProperty = function (name, object, attributes) {
6936
- var metadata = propertyMetadataCache[name];
6937
- if (metadata && metadata.syntax) {
6938
- var handler = metadata.syntax && this.getPropertySyntax(metadata.syntax);
6939
- var propertyHandler = handler;
6940
- if (propertyHandler && propertyHandler.postProcessor) {
6941
- propertyHandler.postProcessor(object, attributes);
6942
- }
6553
+ if (!isNil(attributes.zIndex)) {
6554
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.Z_INDEX].postProcessor(object);
6943
6555
  }
6944
- };
6945
- /**
6946
- * resolve later
6947
- */
6948
- DefaultStyleValueRegistry.prototype.addUnresolveProperty = function (object, name) {
6949
- var properties = unresolvedProperties.get(object);
6950
- if (!properties) {
6951
- unresolvedProperties.set(object, []);
6952
- properties = unresolvedProperties.get(object);
6556
+ if (!isNil(attributes.offsetDistance)) {
6557
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.OFFSET_DISTANCE].postProcessor(object);
6953
6558
  }
6954
- if (properties.indexOf(name) === -1) {
6955
- properties.push(name);
6559
+ if (attributes.transform) {
6560
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.TRANSFORM].postProcessor(object);
6956
6561
  }
6957
- };
6958
- DefaultStyleValueRegistry.prototype.tryToResolveProperty = function (object, name, options) {
6959
- if (options === void 0) { options = {}; }
6960
- var inherited = options.inherited;
6961
- if (inherited) {
6962
- if (object.parentElement &&
6963
- isPropertyResolved(object.parentElement, name)) {
6964
- // const computedValue = object.parentElement.computedStyle[name];
6965
- var usedValue = object.parentElement.parsedStyle[name];
6966
- if (
6967
- // usedValue instanceof CSSKeywordValue &&
6968
- usedValue === 'unset' ||
6969
- usedValue === 'initial' ||
6970
- usedValue === 'inherit') {
6971
- return;
6972
- }
6973
- // else if (
6974
- // usedValue instanceof CSSUnitValue &&
6975
- // CSSUnitValue.isRelativeUnit(usedValue.unit)
6976
- // ) {
6977
- // return false;
6978
- // }
6979
- return usedValue;
6980
- }
6562
+ if (attributes.transformOrigin) {
6563
+ this.runtime.CSSPropertySyntaxFactory[PropertySyntax.TRANSFORM_ORIGIN].postProcessor(object);
6981
6564
  }
6982
- return;
6983
- };
6984
- DefaultStyleValueRegistry.prototype.recalc = function (object) {
6985
- var properties = unresolvedProperties.get(object);
6986
- if (properties && properties.length) {
6987
- var attributes_1 = {};
6988
- properties.forEach(function (property) {
6989
- attributes_1[property] = object.attributes[property];
6990
- });
6991
- this.processProperties(object, attributes_1);
6992
- unresolvedProperties.delete(object);
6565
+ if (needUpdateGeometry) {
6566
+ object.geometry.dirty = true;
6567
+ object.renderable.boundsDirty = true;
6568
+ object.renderable.renderBoundsDirty = true;
6569
+ if (!options.forceUpdateGeometry) {
6570
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6571
+ }
6993
6572
  }
6994
6573
  };
6995
6574
  /**
@@ -7015,12 +6594,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7015
6594
  Math.abs(hheight),
7016
6595
  hdepth,
7017
6596
  ];
7018
- // const halfExtents = vec3.set(
7019
- // tmpVec3a,
7020
- // Math.abs(width) / 2,
7021
- // Math.abs(height) / 2,
7022
- // depth / 2,
7023
- // );
7024
6597
  // anchor is center by default, don't account for lineWidth here
7025
6598
  var _h = parsedStyle, stroke = _h.stroke, _j = _h.lineWidth, lineWidth = _j === void 0 ? 1 : _j,
7026
6599
  // lineCap,
@@ -7040,26 +6613,13 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7040
6613
  nodeName === Shape.PATH
7041
6614
  ? Math.SQRT2
7042
6615
  : 0.5;
7043
- // if (lineCap?.value === 'square') {
7044
- // expansion = Math.SQRT1_2;
7045
- // }
7046
- // if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
7047
- // expansion = Math.SQRT1_2 * miterLimit;
7048
- // }
7049
6616
  // append border only if stroke existed
7050
6617
  var hasStroke = stroke && !stroke.isNone;
7051
6618
  if (hasStroke) {
7052
6619
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) *
7053
6620
  expansion;
7054
- // halfExtents[0] += halfLineWidth[0];
7055
- // halfExtents[1] += halfLineWidth[1];
7056
6621
  halfExtents[0] += halfLineWidth;
7057
6622
  halfExtents[1] += halfLineWidth;
7058
- // vec3.add(
7059
- // halfExtents,
7060
- // halfExtents,
7061
- // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
7062
- // );
7063
6623
  }
7064
6624
  geometry_1.renderBounds.update(center, halfExtents);
7065
6625
  // account for shadow, only support constant value now
@@ -7084,7 +6644,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7084
6644
  var name = _a.name, params = _a.params;
7085
6645
  if (name === 'blur') {
7086
6646
  var blurRadius = params[0].value;
7087
- geometry_1.renderBounds.update(geometry_1.renderBounds.center, addVec3(geometry_1.renderBounds.halfExtents, geometry_1.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
6647
+ geometry_1.renderBounds.update(geometry_1.renderBounds.center, vec3.add(geometry_1.renderBounds.halfExtents, geometry_1.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
7088
6648
  }
7089
6649
  else if (name === 'drop-shadow') {
7090
6650
  var shadowOffsetX = params[0].value;
@@ -7146,21 +6706,11 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7146
6706
  }
7147
6707
  }
7148
6708
  };
7149
- DefaultStyleValueRegistry.prototype.isPropertyInheritable = function (name) {
7150
- var metadata = propertyMetadataCache[name];
7151
- if (!metadata) {
7152
- return false;
7153
- }
7154
- return metadata.inh;
7155
- };
7156
6709
  return DefaultStyleValueRegistry;
7157
6710
  }());
7158
6711
 
7159
6712
  var CSSPropertyAngle = /** @class */ (function () {
7160
6713
  function CSSPropertyAngle() {
7161
- this.parser = parseAngle;
7162
- this.parserUnmemoize = parseAngleUnmemoize;
7163
- this.parserWithCSSDisabled = null;
7164
6714
  this.mixer = mergeNumbers;
7165
6715
  }
7166
6716
  CSSPropertyAngle.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7197,7 +6747,6 @@ var CSSPropertyClipPath = /** @class */ (function () {
7197
6747
  var CSSPropertyColor = /** @class */ (function () {
7198
6748
  function CSSPropertyColor() {
7199
6749
  this.parser = parseColor;
7200
- this.parserWithCSSDisabled = parseColor;
7201
6750
  this.mixer = mergeColors;
7202
6751
  }
7203
6752
  CSSPropertyColor.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7212,7 +6761,6 @@ var CSSPropertyColor = /** @class */ (function () {
7212
6761
 
7213
6762
  var CSSPropertyFilter = /** @class */ (function () {
7214
6763
  function CSSPropertyFilter() {
7215
- this.parser = parseFilter;
7216
6764
  }
7217
6765
  CSSPropertyFilter.prototype.calculator = function (name, oldParsed, parsed) {
7218
6766
  // unset or none
@@ -7233,9 +6781,6 @@ function getFontSize(object) {
7233
6781
  */
7234
6782
  var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7235
6783
  function CSSPropertyLengthOrPercentage() {
7236
- this.parser = parseLengthOrPercentage;
7237
- this.parserUnmemoize = parseLengthOrPercentageUnmemoize;
7238
- this.parserWithCSSDisabled = null;
7239
6784
  this.mixer = mergeNumbers;
7240
6785
  }
7241
6786
  /**
@@ -7250,7 +6795,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7250
6795
  return computed;
7251
6796
  }
7252
6797
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
7253
- var registry = runtime.styleValueRegistry;
7254
6798
  if (computed.unit === UnitType.kPercentage) {
7255
6799
  // TODO: merge dimensions
7256
6800
  return 0;
@@ -7262,12 +6806,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7262
6806
  fontSize *= computed.value;
7263
6807
  return fontSize;
7264
6808
  }
7265
- else {
7266
- registry.addUnresolveProperty(object, name);
7267
- }
7268
- }
7269
- else {
7270
- registry.addUnresolveProperty(object, name);
7271
6809
  }
7272
6810
  return 0;
7273
6811
  }
@@ -7278,12 +6816,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7278
6816
  fontSize *= computed.value;
7279
6817
  return fontSize;
7280
6818
  }
7281
- else {
7282
- registry.addUnresolveProperty(object, name);
7283
- }
7284
- }
7285
- else {
7286
- registry.addUnresolveProperty(object, name);
7287
6819
  }
7288
6820
  return 0;
7289
6821
  }
@@ -7310,17 +6842,6 @@ var CSSPropertyLengthOrPercentage12 = /** @class */ (function () {
7310
6842
  function CSSPropertyLengthOrPercentage12() {
7311
6843
  this.mixer = mergeNumberLists;
7312
6844
  }
7313
- CSSPropertyLengthOrPercentage12.prototype.parser = function (radius) {
7314
- var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
7315
- var formatted;
7316
- if (parsed.length === 1) {
7317
- formatted = [parsed[0], parsed[0]];
7318
- }
7319
- else {
7320
- formatted = [parsed[0], parsed[1]];
7321
- }
7322
- return formatted;
7323
- };
7324
6845
  CSSPropertyLengthOrPercentage12.prototype.calculator = function (name, oldParsed, computed) {
7325
6846
  return computed.map(function (c) { return c.value; });
7326
6847
  };
@@ -7339,24 +6860,6 @@ var CSSPropertyLengthOrPercentage14 = /** @class */ (function () {
7339
6860
  function CSSPropertyLengthOrPercentage14() {
7340
6861
  this.mixer = mergeNumberLists;
7341
6862
  }
7342
- CSSPropertyLengthOrPercentage14.prototype.parser = function (radius) {
7343
- var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
7344
- var formatted;
7345
- // format to Tuple<CSSUnitValue>
7346
- if (parsed.length === 1) {
7347
- formatted = [parsed[0], parsed[0], parsed[0], parsed[0]];
7348
- }
7349
- else if (parsed.length === 2) {
7350
- formatted = [parsed[0], parsed[1], parsed[0], parsed[1]];
7351
- }
7352
- else if (parsed.length === 3) {
7353
- formatted = [parsed[0], parsed[1], parsed[2], parsed[1]];
7354
- }
7355
- else {
7356
- formatted = [parsed[0], parsed[1], parsed[2], parsed[3]];
7357
- }
7358
- return formatted;
7359
- };
7360
6863
  CSSPropertyLengthOrPercentage14.prototype.calculator = function (name, oldParsed, computed) {
7361
6864
  return computed.map(function (c) { return c.value; });
7362
6865
  };
@@ -7384,9 +6887,6 @@ var CSSPropertyMarker = /** @class */ (function () {
7384
6887
  var CSSPropertyNumber = /** @class */ (function () {
7385
6888
  function CSSPropertyNumber() {
7386
6889
  this.mixer = mergeNumbers;
7387
- this.parser = parseNumber;
7388
- this.parserUnmemoize = parseNumberUnmemoize;
7389
- this.parserWithCSSDisabled = null;
7390
6890
  }
7391
6891
  CSSPropertyNumber.prototype.calculator = function (name, oldParsed, computed) {
7392
6892
  return computed.value;
@@ -7396,9 +6896,6 @@ var CSSPropertyNumber = /** @class */ (function () {
7396
6896
 
7397
6897
  var CSSPropertyOffsetDistance = /** @class */ (function () {
7398
6898
  function CSSPropertyOffsetDistance() {
7399
- this.parser = parseNumber;
7400
- this.parserUnmemoize = parseNumberUnmemoize;
7401
- this.parserWithCSSDisabled = null;
7402
6899
  this.mixer = clampedMergeNumbers(0, 1);
7403
6900
  }
7404
6901
  CSSPropertyOffsetDistance.prototype.calculator = function (name, oldParsed, computed) {
@@ -7428,9 +6925,6 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
7428
6925
  */
7429
6926
  var CSSPropertyOpacity = /** @class */ (function () {
7430
6927
  function CSSPropertyOpacity() {
7431
- this.parser = parseNumber;
7432
- this.parserUnmemoize = parseNumberUnmemoize;
7433
- this.parserWithCSSDisabled = null;
7434
6928
  this.mixer = clampedMergeNumbers(0, 1);
7435
6929
  }
7436
6930
  CSSPropertyOpacity.prototype.calculator = function (name, oldParsed, computed) {
@@ -7445,7 +6939,6 @@ var CSSPropertyPath = /** @class */ (function () {
7445
6939
  * path2Curve
7446
6940
  */
7447
6941
  this.parser = parsePath;
7448
- this.parserWithCSSDisabled = parsePath;
7449
6942
  this.mixer = mergePaths;
7450
6943
  }
7451
6944
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
@@ -7469,7 +6962,6 @@ var CSSPropertyPath = /** @class */ (function () {
7469
6962
 
7470
6963
  var CSSPropertyPoints = /** @class */ (function () {
7471
6964
  function CSSPropertyPoints() {
7472
- this.parser = parsePoints;
7473
6965
  this.mixer = mergePoints;
7474
6966
  }
7475
6967
  return CSSPropertyPoints;
@@ -7533,20 +7025,26 @@ var CSSPropertyTextTransform = /** @class */ (function () {
7533
7025
  return CSSPropertyTextTransform;
7534
7026
  }());
7535
7027
 
7536
- var canvasMap = {};
7537
- var defaultCanvasIdCounter = 0;
7028
+ var definedProps = function (obj) {
7029
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
7030
+ var _b = __read(_a, 2), v = _b[1];
7031
+ return v !== undefined;
7032
+ }));
7033
+ };
7034
+
7035
+ var CANVAS_Map = new WeakMap();
7538
7036
  /**
7539
7037
  * destroy existed canvas with the same id
7540
7038
  */
7541
- function cleanExistedCanvas(container, canvas) {
7039
+ function cleanExistedCanvas(container, canvas, cleanUp) {
7542
7040
  if (container) {
7543
- var id = typeof container === 'string'
7544
- ? container
7545
- : container.id || defaultCanvasIdCounter++;
7546
- if (canvasMap[id]) {
7547
- canvasMap[id].destroy();
7548
- }
7549
- canvasMap[id] = canvas;
7041
+ var $dom = typeof container === 'string'
7042
+ ? document.getElementById(container)
7043
+ : container;
7044
+ if (CANVAS_Map.has($dom))
7045
+ CANVAS_Map.get($dom).destroy(cleanUp);
7046
+ else
7047
+ CANVAS_Map.set($dom, canvas);
7550
7048
  }
7551
7049
  }
7552
7050
  var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
@@ -7631,6 +7129,12 @@ var TOUCH_TO_POINTER = {
7631
7129
  };
7632
7130
  var clock = typeof performance === 'object' && performance.now ? performance : Date;
7633
7131
 
7132
+ function isInFragment(node) {
7133
+ if (node.nodeName === Shape.FRAGMENT)
7134
+ return true;
7135
+ return node.getRootNode().nodeName === Shape.FRAGMENT;
7136
+ }
7137
+
7634
7138
  function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
7635
7139
  // account for pointerEvents
7636
7140
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
@@ -7889,114 +7393,102 @@ function createSkewMatrix(skewMatrix, skewX, skewY) {
7889
7393
  skewMatrix[1] = Math.tan(skewY); // Skew X axis in Y direction
7890
7394
  return skewMatrix;
7891
7395
  }
7892
- var SCALE_EPSILON = 0.00001;
7893
- var tmpMat1 = mat4.create();
7894
- var tmpMat2 = mat4.create();
7396
+ var $mat4_1 = mat4.create();
7397
+ var $mat4_2 = mat4.create();
7398
+ var parser = {
7399
+ scale: function (d) {
7400
+ mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7401
+ },
7402
+ scaleX: function (d) {
7403
+ mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7404
+ },
7405
+ scaleY: function (d) {
7406
+ mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7407
+ },
7408
+ scaleZ: function (d) {
7409
+ mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7410
+ },
7411
+ scale3d: function (d) {
7412
+ mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7413
+ },
7414
+ translate: function (d) {
7415
+ mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
7416
+ },
7417
+ translateX: function (d) {
7418
+ mat4.fromTranslation($mat4_1, [d[0].value, 0, 0]);
7419
+ },
7420
+ translateY: function (d) {
7421
+ mat4.fromTranslation($mat4_1, [0, d[0].value, 0]);
7422
+ },
7423
+ translateZ: function (d) {
7424
+ mat4.fromTranslation($mat4_1, [0, 0, d[0].value]);
7425
+ },
7426
+ translate3d: function (d) {
7427
+ mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, d[2].value]);
7428
+ },
7429
+ rotate: function (d) {
7430
+ mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7431
+ },
7432
+ rotateX: function (d) {
7433
+ mat4.fromXRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7434
+ },
7435
+ rotateY: function (d) {
7436
+ mat4.fromYRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7437
+ },
7438
+ rotateZ: function (d) {
7439
+ mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7440
+ },
7441
+ rotate3d: function (d) {
7442
+ mat4.fromRotation($mat4_1, deg2rad(convertAngleUnit(d[3])), [
7443
+ d[0].value,
7444
+ d[1].value,
7445
+ d[2].value,
7446
+ ]);
7447
+ },
7448
+ skew: function (d) {
7449
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), deg2rad(d[1].value));
7450
+ },
7451
+ skewX: function (d) {
7452
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), 0);
7453
+ },
7454
+ skewY: function (d) {
7455
+ createSkewMatrix($mat4_1, 0, deg2rad(d[0].value));
7456
+ },
7457
+ matrix: function (d) {
7458
+ // prettier-ignore
7459
+ mat4.set($mat4_1, d[0].value, d[1].value, 0, 0, d[2].value, d[3].value, 0, 0, 0, 0, 1, 0, d[4].value, d[5].value, 0, 1);
7460
+ },
7461
+ matrix3d: function (d) {
7462
+ // @ts-ignore
7463
+ mat4.set.apply(mat4, __spreadArray([$mat4_1], __read(d.map(function (s) { return s.value; })), false));
7464
+ },
7465
+ };
7466
+ var $vec3One$1 = vec3.fromValues(1, 1, 1);
7467
+ var $vec3Zero$1 = vec3.create();
7468
+ var optimizer = {
7469
+ translate: function (object, d) {
7470
+ runtime.sceneGraphService.setLocalScale(object, $vec3One$1, false);
7471
+ runtime.sceneGraphService.setLocalEulerAngles(object, $vec3Zero$1, undefined, undefined, false);
7472
+ runtime.sceneGraphService.setLocalPosition(object, [d[0].value, d[1].value, 0], false);
7473
+ runtime.sceneGraphService.dirtifyLocal(object, object.transformable);
7474
+ },
7475
+ };
7895
7476
  function parsedTransformToMat4(transform, object) {
7896
7477
  if (transform.length) {
7897
- var m_1 = mat4.identity(tmpMat1);
7898
- transform.forEach(function (parsed) {
7899
- var t = parsed.t, d = parsed.d;
7900
- if (t === 'scale') {
7901
- // scale(1) scale(1, 1)
7902
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7903
- 1, 1,
7904
- ];
7905
- mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], 1]);
7906
- }
7907
- else if (t === 'scalex') {
7908
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7909
- mat4.fromScaling(tmpMat2, [newScale[0], 1, 1]);
7910
- }
7911
- else if (t === 'scaley') {
7912
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7913
- mat4.fromScaling(tmpMat2, [1, newScale[0], 1]);
7914
- }
7915
- else if (t === 'scalez') {
7916
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7917
- mat4.fromScaling(tmpMat2, [1, 1, newScale[0]]);
7918
- }
7919
- else if (t === 'scale3d') {
7920
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7921
- 1, 1, 1,
7922
- ];
7923
- mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], newScale[2]]);
7924
- }
7925
- else if (t === 'translate') {
7926
- var newTranslation = d || [Opx, Opx];
7927
- mat4.fromTranslation(tmpMat2, [
7928
- newTranslation[0].value,
7929
- newTranslation[1].value,
7930
- 0,
7931
- ]);
7932
- }
7933
- else if (t === 'translatex') {
7934
- var newTranslation = d || [Opx];
7935
- mat4.fromTranslation(tmpMat2, [newTranslation[0].value, 0, 0]);
7936
- }
7937
- else if (t === 'translatey') {
7938
- var newTranslation = d || [Opx];
7939
- mat4.fromTranslation(tmpMat2, [0, newTranslation[0].value, 0]);
7940
- }
7941
- else if (t === 'translatez') {
7942
- var newTranslation = d || [Opx];
7943
- mat4.fromTranslation(tmpMat2, [0, 0, newTranslation[0].value]);
7944
- }
7945
- else if (t === 'translate3d') {
7946
- var newTranslation = d || [Opx, Opx, Opx];
7947
- mat4.fromTranslation(tmpMat2, [
7948
- newTranslation[0].value,
7949
- newTranslation[1].value,
7950
- newTranslation[2].value,
7951
- ]);
7952
- }
7953
- else if (t === 'rotate') {
7954
- var newAngles = d || [Odeg];
7955
- mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7956
- }
7957
- else if (t === 'rotatex') {
7958
- var newAngles = d || [Odeg];
7959
- mat4.fromXRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7960
- }
7961
- else if (t === 'rotatey') {
7962
- var newAngles = d || [Odeg];
7963
- mat4.fromYRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7964
- }
7965
- else if (t === 'rotatez') {
7966
- var newAngles = d || [Odeg];
7967
- mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7968
- }
7969
- else if (t === 'rotate3d') {
7970
- var newAngles = d || [Opx, Opx, Opx, Odeg];
7971
- mat4.fromRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[3])), [
7972
- newAngles[0].value,
7973
- newAngles[1].value,
7974
- newAngles[2].value,
7975
- ]);
7976
- }
7977
- else if (t === 'skew') {
7978
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0, 0];
7979
- createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), deg2rad(newSkew[1]));
7980
- }
7981
- else if (t === 'skewx') {
7982
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7983
- createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), 0);
7984
- }
7985
- else if (t === 'skewy') {
7986
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7987
- createSkewMatrix(tmpMat2, 0, deg2rad(newSkew[0]));
7988
- }
7989
- else if (t === 'matrix') {
7990
- var _a = __read(d.map(function (s) { return s.value; }), 6), a = _a[0], b = _a[1], c = _a[2], dd = _a[3], tx = _a[4], ty = _a[5];
7991
- mat4.set(tmpMat2, a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1);
7992
- }
7993
- else if (t === 'matrix3d') {
7994
- // @ts-ignore
7995
- mat4.set.apply(mat4, __spreadArray([tmpMat2], __read(d.map(function (s) { return s.value; })), false));
7478
+ if (transform.length === 1 && optimizer[transform[0].t]) {
7479
+ optimizer[transform[0].t](object, transform[0].d);
7480
+ return;
7481
+ }
7482
+ var m = mat4.identity($mat4_2);
7483
+ for (var i = 0; i < transform.length; i++) {
7484
+ var _a = transform[i], t = _a.t, d = _a.d;
7485
+ var p = parser[t];
7486
+ if (p) {
7487
+ p(d);
7488
+ mat4.mul(m, m, $mat4_1);
7996
7489
  }
7997
- mat4.mul(m_1, m_1, tmpMat2);
7998
- });
7999
- object.setLocalTransform(m_1);
7490
+ }
7491
+ object.setLocalTransform(m);
8000
7492
  }
8001
7493
  else {
8002
7494
  object.resetLocalTransform();
@@ -8036,9 +7528,7 @@ function parsedTransformToMat4(transform, object) {
8036
7528
  */
8037
7529
  var CSSPropertyTransform = /** @class */ (function () {
8038
7530
  function CSSPropertyTransform() {
8039
- this.parser = parseTransform;
8040
- this.parserUnmemoize = parseTransformUnmemoize;
8041
- this.parserWithCSSDisabled = parseTransformUnmemoize;
7531
+ this.parser = parseTransformUnmemoize;
8042
7532
  this.mixer = mergeTransforms;
8043
7533
  }
8044
7534
  CSSPropertyTransform.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -8049,8 +7539,7 @@ var CSSPropertyTransform = /** @class */ (function () {
8049
7539
  return parsed;
8050
7540
  };
8051
7541
  CSSPropertyTransform.prototype.postProcessor = function (object) {
8052
- var transform = object.parsedStyle.transform;
8053
- parsedTransformToMat4(transform, object);
7542
+ parsedTransformToMat4(object.parsedStyle.transform, object);
8054
7543
  };
8055
7544
  return CSSPropertyTransform;
8056
7545
  }());
@@ -8062,8 +7551,6 @@ var CSSPropertyTransform = /** @class */ (function () {
8062
7551
  */
8063
7552
  var CSSPropertyTransformOrigin = /** @class */ (function () {
8064
7553
  function CSSPropertyTransformOrigin() {
8065
- this.parser = parseTransformOrigin;
8066
- this.parserUnmemoize = parseTransformOriginUnmemoize;
8067
7554
  }
8068
7555
  CSSPropertyTransformOrigin.prototype.postProcessor = function (object) {
8069
7556
  var transformOrigin = object.parsedStyle.transformOrigin;
@@ -8081,8 +7568,6 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
8081
7568
 
8082
7569
  var CSSPropertyZIndex = /** @class */ (function () {
8083
7570
  function CSSPropertyZIndex() {
8084
- this.parser = parseNumber;
8085
- this.parserUnmemoize = parseNumberUnmemoize;
8086
7571
  }
8087
7572
  CSSPropertyZIndex.prototype.calculator = function (name, oldParsed, computed, object) {
8088
7573
  return computed.value;
@@ -8241,17 +7726,8 @@ var TextUpdater = /** @class */ (function () {
8241
7726
  this.globalRuntime = globalRuntime;
8242
7727
  }
8243
7728
  TextUpdater.prototype.isReadyToMeasure = function (parsedStyle, object) {
8244
- var text = parsedStyle.text, textAlign = parsedStyle.textAlign, textBaseline = parsedStyle.textBaseline, fontSize = parsedStyle.fontSize, fontStyle = parsedStyle.fontStyle, fontWeight = parsedStyle.fontWeight, fontVariant = parsedStyle.fontVariant, lineWidth = parsedStyle.lineWidth;
8245
- return runtime.enableCSSParsing
8246
- ? text &&
8247
- fontSize &&
8248
- fontStyle &&
8249
- fontWeight &&
8250
- fontVariant &&
8251
- textAlign &&
8252
- textBaseline &&
8253
- !isNil(lineWidth)
8254
- : text;
7729
+ var text = parsedStyle.text;
7730
+ return text;
8255
7731
  };
8256
7732
  TextUpdater.prototype.update = function (parsedStyle, object) {
8257
7733
  var _a, _b;
@@ -8282,7 +7758,7 @@ var TextUpdater = /** @class */ (function () {
8282
7758
  var offscreenCanvas = (((_b = (_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getConfig()) || {}).offscreenCanvas;
8283
7759
  var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
8284
7760
  parsedStyle.metrics = metrics;
8285
- var width = metrics.width, height = metrics.height, lineHeight = metrics.lineHeight, fontProperties = metrics.fontProperties;
7761
+ var width = metrics.width, height = metrics.height;
8286
7762
  var hwidth = width / 2;
8287
7763
  var hheight = height / 2;
8288
7764
  // default 'left'
@@ -8295,18 +7771,12 @@ var TextUpdater = /** @class */ (function () {
8295
7771
  }
8296
7772
  var lineYOffset = y - hheight;
8297
7773
  if (textBaseline === 'middle') {
8298
- // eslint-disable-next-line prefer-destructuring
8299
7774
  lineYOffset += hheight;
8300
7775
  }
8301
7776
  else if (textBaseline === 'top' || textBaseline === 'hanging') {
8302
7777
  lineYOffset += hheight * 2;
8303
7778
  }
8304
- else if (textBaseline === 'alphabetic') {
8305
- // prevent calling getImageData for ascent metrics
8306
- lineYOffset += this.globalRuntime.enableCSSParsing
8307
- ? lineHeight - fontProperties.ascent
8308
- : 0;
8309
- }
7779
+ else if (textBaseline === 'alphabetic') ;
8310
7780
  else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
8311
7781
  lineYOffset += 0;
8312
7782
  }
@@ -8762,7 +8232,7 @@ var CustomEvent = /** @class */ (function (_super) {
8762
8232
  return CustomEvent;
8763
8233
  }(FederatedEvent));
8764
8234
 
8765
- var DELEGATION_SPLITTER = ':';
8235
+ var CANVAS_CACHE = new WeakMap();
8766
8236
  /**
8767
8237
  * Objects that can receive events and may have listeners for them.
8768
8238
  * eg. Element, Canvas, DisplayObject
@@ -8788,43 +8258,21 @@ var EventTarget = /** @class */ (function () {
8788
8258
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener
8789
8259
  */
8790
8260
  EventTarget.prototype.addEventListener = function (type, listener, options) {
8791
- var capture = (isBoolean(options) && options) || (isObject(options) && options.capture);
8792
- var once = isObject(options) && options.once;
8793
- var context = isFunction(listener) ? undefined : listener;
8794
- // compatible with G 3.0
8795
- // support using delegate name in event type, eg. 'node:click'
8796
- var useDelegatedName = false;
8797
- var delegatedName = '';
8798
- if (type.indexOf(DELEGATION_SPLITTER) > -1) {
8799
- var _a = __read(type.split(DELEGATION_SPLITTER), 2), name_1 = _a[0], eventType = _a[1];
8800
- type = eventType;
8801
- delegatedName = name_1;
8802
- useDelegatedName = true;
8803
- }
8804
- type = capture ? "".concat(type, "capture") : type;
8261
+ var _a, _b;
8262
+ var capture = false;
8263
+ var once = false;
8264
+ if (isBoolean(options))
8265
+ capture = options;
8266
+ else if (options)
8267
+ (_a = options.capture, capture = _a === void 0 ? false : _a, _b = options.once, once = _b === void 0 ? false : _b);
8268
+ if (capture)
8269
+ type += 'capture';
8805
8270
  listener = isFunction(listener) ? listener : listener.handleEvent;
8806
- // compatible with G 3.0
8807
- if (useDelegatedName) {
8808
- var originListener_1 = listener;
8809
- listener = function () {
8810
- var _a;
8811
- var args = [];
8812
- for (var _i = 0; _i < arguments.length; _i++) {
8813
- args[_i] = arguments[_i];
8814
- }
8815
- if (((_a = args[0].target) === null || _a === void 0 ? void 0 : _a.name) !== delegatedName) {
8816
- return;
8817
- }
8818
- // @ts-ignore
8819
- originListener_1.apply(void 0, __spreadArray([], __read(args), false));
8820
- };
8821
- }
8822
- if (once) {
8271
+ var context = isFunction(listener) ? undefined : listener;
8272
+ if (once)
8823
8273
  this.emitter.once(type, listener, context);
8824
- }
8825
- else {
8274
+ else
8826
8275
  this.emitter.on(type, listener, context);
8827
- }
8828
8276
  return this;
8829
8277
  };
8830
8278
  /**
@@ -8842,13 +8290,17 @@ var EventTarget = /** @class */ (function () {
8842
8290
  return this;
8843
8291
  };
8844
8292
  EventTarget.prototype.removeAllEventListeners = function () {
8845
- this.emitter.removeAllListeners();
8293
+ var _a;
8294
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
8846
8295
  };
8847
8296
  EventTarget.prototype.removeEventListener = function (type, listener, options) {
8848
- var capture = (isBoolean(options) && options) || (isObject(options) && options.capture);
8849
- var context = isFunction(listener) ? undefined : listener;
8850
- type = capture ? "".concat(type, "capture") : type;
8297
+ if (!this.emitter)
8298
+ return this;
8299
+ var capture = isBoolean(options) ? options : options === null || options === void 0 ? void 0 : options.capture;
8300
+ if (capture)
8301
+ type += 'capture';
8851
8302
  listener = isFunction(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
8303
+ var context = isFunction(listener) ? undefined : listener;
8852
8304
  this.emitter.off(type, listener, context);
8853
8305
  return this;
8854
8306
  };
@@ -8864,36 +8316,34 @@ var EventTarget = /** @class */ (function () {
8864
8316
  * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
8865
8317
  */
8866
8318
  EventTarget.prototype.dispatchEvent = function (e, skipPropagate) {
8867
- var _a, _b;
8319
+ var _a;
8868
8320
  if (skipPropagate === void 0) { skipPropagate = false; }
8869
- if (!isFederatedEvent(e)) {
8870
- throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
8871
- }
8872
- // should account for Element / Document / Canvas
8873
- var canvas;
8874
- // @ts-ignore
8875
- if (this.document) {
8876
- canvas = this;
8877
- // @ts-ignore
8878
- }
8879
- else if (this.defaultView) {
8880
- canvas = this.defaultView;
8881
- }
8882
- else {
8883
- canvas = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
8321
+ var canvas = CANVAS_CACHE.get(this);
8322
+ if (!canvas) {
8323
+ // @ts-expect-error document may be defined in inherited class
8324
+ if (this.document)
8325
+ canvas = this;
8326
+ // @ts-expect-error defaultView may be defined in inherited class
8327
+ else if (this.defaultView)
8328
+ canvas = this.defaultView;
8329
+ else
8330
+ canvas = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
8331
+ if (canvas)
8332
+ CANVAS_CACHE.set(this, canvas);
8884
8333
  }
8885
- // assign event manager
8886
8334
  if (canvas) {
8887
- e.manager = canvas.getEventService() || null;
8888
- if (!e.manager) {
8335
+ e.manager = canvas.getEventService();
8336
+ if (!e.manager)
8889
8337
  return false;
8890
- }
8891
8338
  e.defaultPrevented = false;
8892
- e.path = [];
8893
- if (!skipPropagate) {
8339
+ if (e.path)
8340
+ e.path.length = 0;
8341
+ // @ts-ignore
8342
+ else
8343
+ e.page = [];
8344
+ if (!skipPropagate)
8894
8345
  e.target = this;
8895
- }
8896
- (_b = e.manager) === null || _b === void 0 ? void 0 : _b.dispatchEvent(e, e.type, skipPropagate);
8346
+ e.manager.dispatchEvent(e, e.type, skipPropagate);
8897
8347
  }
8898
8348
  return !e.defaultPrevented;
8899
8349
  };
@@ -9191,12 +8641,19 @@ var Node = /** @class */ (function (_super) {
9191
8641
  }
9192
8642
  return temp;
9193
8643
  };
9194
- Node.prototype.forEach = function (callback, assigned) {
9195
- if (assigned === void 0) { assigned = false; }
9196
- if (!callback(this)) {
9197
- (assigned ? this.childNodes.slice() : this.childNodes).forEach(function (child) {
9198
- child.forEach(callback);
9199
- });
8644
+ /**
8645
+ * iterate current node and its descendants
8646
+ * @param callback - callback to execute for each node, return false to break
8647
+ * @param assigned - whether to iterate assigned nodes
8648
+ */
8649
+ Node.prototype.forEach = function (callback) {
8650
+ var result = callback(this);
8651
+ if (result !== false) {
8652
+ var nodes = this.childNodes;
8653
+ var length_1 = nodes.length;
8654
+ for (var i = 0; i < length_1; i++) {
8655
+ nodes[i].forEach(callback);
8656
+ }
9200
8657
  }
9201
8658
  };
9202
8659
  /**
@@ -10196,10 +9653,6 @@ var RenderingService = /** @class */ (function () {
10196
9653
  RenderingService.prototype.renderDisplayObject = function (displayObject, canvasConfig, renderingContext) {
10197
9654
  var _this = this;
10198
9655
  var _a = canvasConfig.renderer.getConfig(), enableDirtyCheck = _a.enableDirtyCheck, enableCulling = _a.enableCulling;
10199
- // recalc style values
10200
- if (this.globalRuntime.enableCSSParsing) {
10201
- this.globalRuntime.styleValueRegistry.recalc(displayObject);
10202
- }
10203
9656
  // TODO: relayout
10204
9657
  // dirtycheck first
10205
9658
  var renderable = displayObject.renderable;
@@ -10406,26 +9859,6 @@ var DefaultSceneGraphSelector = /** @class */ (function () {
10406
9859
  return DefaultSceneGraphSelector;
10407
9860
  }());
10408
9861
 
10409
- var MutationEvent = /** @class */ (function (_super) {
10410
- __extends(MutationEvent, _super);
10411
- function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
10412
- var _this = _super.call(this, null) || this;
10413
- _this.relatedNode = relatedNode;
10414
- _this.prevValue = prevValue;
10415
- _this.newValue = newValue;
10416
- _this.attrName = attrName;
10417
- _this.attrChange = attrChange;
10418
- _this.prevParsedValue = prevParsedValue;
10419
- _this.newParsedValue = newParsedValue;
10420
- _this.type = typeArg;
10421
- return _this;
10422
- }
10423
- MutationEvent.ADDITION = 2;
10424
- MutationEvent.MODIFICATION = 1;
10425
- MutationEvent.REMOVAL = 3;
10426
- return MutationEvent;
10427
- }(FederatedEvent));
10428
-
10429
9862
  /**
10430
9863
  * built-in events for element
10431
9864
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent
@@ -10463,6 +9896,26 @@ var ElementEvent;
10463
9896
  ElementEvent["CULLED"] = "culled";
10464
9897
  })(ElementEvent || (ElementEvent = {}));
10465
9898
 
9899
+ var MutationEvent = /** @class */ (function (_super) {
9900
+ __extends(MutationEvent, _super);
9901
+ function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
9902
+ var _this = _super.call(this, null) || this;
9903
+ _this.relatedNode = relatedNode;
9904
+ _this.prevValue = prevValue;
9905
+ _this.newValue = newValue;
9906
+ _this.attrName = attrName;
9907
+ _this.attrChange = attrChange;
9908
+ _this.prevParsedValue = prevParsedValue;
9909
+ _this.newParsedValue = newParsedValue;
9910
+ _this.type = typeArg;
9911
+ return _this;
9912
+ }
9913
+ MutationEvent.ADDITION = 2;
9914
+ MutationEvent.MODIFICATION = 1;
9915
+ MutationEvent.REMOVAL = 3;
9916
+ return MutationEvent;
9917
+ }(FederatedEvent));
9918
+
10466
9919
  function markRenderableDirty(e) {
10467
9920
  var renderable = e.renderable;
10468
9921
  if (renderable) {
@@ -10471,260 +9924,45 @@ function markRenderableDirty(e) {
10471
9924
  }
10472
9925
  }
10473
9926
  var reparentEvent = new MutationEvent(ElementEvent.REPARENT, null, '', '', '', 0, '', '');
10474
- /**
10475
- * update transform in scene graph
10476
- *
10477
- * @see https://community.khronos.org/t/scene-graphs/50542/7
10478
- */
10479
- var DefaultSceneGraphService = /** @class */ (function () {
10480
- function DefaultSceneGraphService(runtime) {
10481
- var _this = this;
10482
- this.runtime = runtime;
10483
- this.pendingEvents = [];
10484
- this.boundsChangedEvent = new CustomEvent(ElementEvent.BOUNDS_CHANGED);
10485
- /**
10486
- * rotate in world space
10487
- */
10488
- this.rotate = (function () {
10489
- var parentInvertRotation = quat$1.create();
10490
- return function (element, degrees, y, z, dirtify) {
10491
- if (y === void 0) { y = 0; }
10492
- if (z === void 0) { z = 0; }
10493
- if (dirtify === void 0) { dirtify = true; }
10494
- if (typeof degrees === 'number') {
10495
- degrees = vec3.fromValues(degrees, y, z);
10496
- }
10497
- var transform = element.transformable;
10498
- if (element.parentNode === null ||
10499
- !element.parentNode.transformable) {
10500
- _this.rotateLocal(element, degrees);
10501
- }
10502
- else {
10503
- var rotation = quat$1.create();
10504
- quat$1.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10505
- var rot = _this.getRotation(element);
10506
- var parentRot = _this.getRotation(element.parentNode);
10507
- quat$1.copy(parentInvertRotation, parentRot);
10508
- quat$1.invert(parentInvertRotation, parentInvertRotation);
10509
- quat$1.multiply(rotation, parentInvertRotation, rotation);
10510
- quat$1.multiply(transform.localRotation, rotation, rot);
10511
- quat$1.normalize(transform.localRotation, transform.localRotation);
10512
- if (dirtify) {
10513
- _this.dirtifyLocal(element, transform);
10514
- }
10515
- }
10516
- };
10517
- })();
10518
- /**
10519
- * rotate in local space
10520
- * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
10521
- */
10522
- this.rotateLocal = (function () {
10523
- var rotation = quat$1.create();
10524
- return function (element, degrees, y, z, dirtify) {
10525
- if (y === void 0) { y = 0; }
10526
- if (z === void 0) { z = 0; }
10527
- if (dirtify === void 0) { dirtify = true; }
10528
- if (typeof degrees === 'number') {
10529
- degrees = vec3.fromValues(degrees, y, z);
10530
- }
10531
- var transform = element.transformable;
10532
- quat$1.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10533
- quat$1.mul(transform.localRotation, transform.localRotation, rotation);
10534
- if (dirtify) {
10535
- _this.dirtifyLocal(element, transform);
10536
- }
10537
- };
10538
- })();
10539
- /**
10540
- * set euler angles(degrees) in world space
10541
- */
10542
- this.setEulerAngles = (function () {
10543
- var invParentRot = quat$1.create();
10544
- return function (element, degrees, y, z, dirtify) {
10545
- if (y === void 0) { y = 0; }
10546
- if (z === void 0) { z = 0; }
10547
- if (dirtify === void 0) { dirtify = true; }
10548
- if (typeof degrees === 'number') {
10549
- degrees = vec3.fromValues(degrees, y, z);
10550
- }
10551
- var transform = element.transformable;
10552
- if (element.parentNode === null ||
10553
- !element.parentNode.transformable) {
10554
- _this.setLocalEulerAngles(element, degrees);
10555
- }
10556
- else {
10557
- quat$1.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
10558
- var parentRotation = _this.getRotation(element.parentNode);
10559
- quat$1.copy(invParentRot, quat$1.invert(quat$1.create(), parentRotation));
10560
- quat$1.mul(transform.localRotation, transform.localRotation, invParentRot);
10561
- if (dirtify) {
10562
- _this.dirtifyLocal(element, transform);
10563
- }
10564
- }
10565
- };
10566
- })();
10567
- /**
10568
- * translate in local space
10569
- *
10570
- * @example
10571
- * ```
10572
- * translateLocal(x, y, z)
10573
- * translateLocal(vec3(x, y, z))
10574
- * ```
10575
- */
10576
- this.translateLocal = (function () {
10577
- return function (element, translation, y, z, dirtify) {
10578
- if (y === void 0) { y = 0; }
10579
- if (z === void 0) { z = 0; }
10580
- if (dirtify === void 0) { dirtify = true; }
10581
- if (typeof translation === 'number') {
10582
- translation = vec3.fromValues(translation, y, z);
10583
- }
10584
- var transform = element.transformable;
10585
- if (vec3.equals(translation, vec3.create())) {
10586
- return;
10587
- }
10588
- vec3.transformQuat(translation, translation, transform.localRotation);
10589
- vec3.add(transform.localPosition, transform.localPosition, translation);
10590
- if (dirtify) {
10591
- _this.dirtifyLocal(element, transform);
10592
- }
10593
- };
10594
- })();
10595
- /**
10596
- * move to position in world space
10597
- *
10598
- * 对应 g 原版的 move/moveTo
10599
- * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
10600
- */
10601
- this.setPosition = (function () {
10602
- var parentInvertMatrix = mat4.create();
10603
- var tmpPosition = vec3.create();
10604
- return function (element, position, dirtify) {
10605
- if (dirtify === void 0) { dirtify = true; }
10606
- var transform = element.transformable;
10607
- tmpPosition[0] = position[0];
10608
- tmpPosition[1] = position[1];
10609
- tmpPosition[2] = position[2] || 0;
10610
- if (vec3.equals(_this.getPosition(element), tmpPosition)) {
10611
- return;
10612
- }
10613
- vec3.copy(transform.position, tmpPosition);
10614
- if (element.parentNode === null ||
10615
- !element.parentNode.transformable) {
10616
- vec3.copy(transform.localPosition, tmpPosition);
10617
- }
10618
- else {
10619
- var parentTransform = element.parentNode.transformable;
10620
- mat4.copy(parentInvertMatrix, parentTransform.worldTransform);
10621
- mat4.invert(parentInvertMatrix, parentInvertMatrix);
10622
- vec3.transformMat4(transform.localPosition, tmpPosition, parentInvertMatrix);
10623
- }
10624
- if (dirtify) {
10625
- _this.dirtifyLocal(element, transform);
10626
- }
10627
- };
10628
- })();
10629
- /**
10630
- * move to position in local space
10631
- */
10632
- this.setLocalPosition = (function () {
10633
- var tmpPosition = vec3.create();
10634
- return function (element, position, dirtify) {
10635
- if (dirtify === void 0) { dirtify = true; }
10636
- var transform = element.transformable;
10637
- tmpPosition[0] = position[0];
10638
- tmpPosition[1] = position[1];
10639
- tmpPosition[2] = position[2] || 0;
10640
- if (vec3.equals(transform.localPosition, tmpPosition)) {
10641
- return;
10642
- }
10643
- vec3.copy(transform.localPosition, tmpPosition);
10644
- if (dirtify) {
10645
- _this.dirtifyLocal(element, transform);
10646
- }
10647
- };
10648
- })();
10649
- /**
10650
- * translate in world space
10651
- *
10652
- * @example
10653
- * ```
10654
- * translate(x, y, z)
10655
- * translate(vec3(x, y, z))
10656
- * ```
10657
- *
10658
- * 对应 g 原版的 translate 2D
10659
- * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
10660
- */
10661
- this.translate = (function () {
10662
- var zeroVec3 = vec3.create();
10663
- var tmpVec3 = vec3.create();
10664
- var tr = vec3.create();
10665
- return function (element, translation, y, z, dirtify) {
10666
- if (y === void 0) { y = 0; }
10667
- if (z === void 0) { z = 0; }
10668
- if (dirtify === void 0) { dirtify = true; }
10669
- if (typeof translation === 'number') {
10670
- translation = vec3.set(tmpVec3, translation, y, z);
10671
- }
10672
- if (vec3.equals(translation, zeroVec3)) {
10673
- return;
10674
- }
10675
- vec3.add(tr, _this.getPosition(element), translation);
10676
- _this.setPosition(element, tr, dirtify);
10677
- };
10678
- })();
10679
- this.setRotation = function () {
10680
- var parentInvertRotation = quat$1.create();
10681
- return function (element, rotation, y, z, w, dirtify) {
10682
- if (dirtify === void 0) { dirtify = true; }
10683
- var transform = element.transformable;
10684
- if (typeof rotation === 'number') {
10685
- rotation = quat$1.fromValues(rotation, y, z, w);
10686
- }
10687
- if (element.parentNode === null ||
10688
- !element.parentNode.transformable) {
10689
- _this.setLocalRotation(element, rotation);
10690
- }
10691
- else {
10692
- var parentRot = _this.getRotation(element.parentNode);
10693
- quat$1.copy(parentInvertRotation, parentRot);
10694
- quat$1.invert(parentInvertRotation, parentInvertRotation);
10695
- quat$1.multiply(transform.localRotation, parentInvertRotation, rotation);
10696
- quat$1.normalize(transform.localRotation, transform.localRotation);
10697
- if (dirtify) {
10698
- _this.dirtifyLocal(element, transform);
10699
- }
10700
- }
10701
- };
10702
- };
9927
+ // Object pooling
9928
+ /** do not modify this objects */
9929
+ var $vec2Zero = vec2.create();
9930
+ /** do not modify this objects */
9931
+ var $vec3Zero = vec3.create();
9932
+ /** do not modify this objects */
9933
+ var $vec3One = vec3.fromValues(1, 1, 1);
9934
+ /** do not modify this objects */
9935
+ var $mat4Identity = mat4.create();
9936
+ /** shared objects */
9937
+ var $vec2 = vec2.create();
9938
+ /** shared objects */
9939
+ var $vec3$1 = vec3.create();
9940
+ /** shared objects */
9941
+ var $mat4 = mat4.create();
9942
+ /** shared objects */
9943
+ var $quat$1 = quat$1.create();
9944
+ var $setLocalTransform_1 = vec3.create();
9945
+ var $setLocalTransform_2 = quat$1.create();
9946
+ var $setLocalTransform_3 = vec3.create();
9947
+ var $setLocalPosition = vec3.create();
9948
+ var $setPosition_1 = vec3.create();
9949
+ var $setPosition_ParentInvertMatrix = mat4.create();
9950
+ var $setEulerAngles_InvParentRot = quat$1.create();
9951
+ var $rotateLocal = quat$1.create();
9952
+ var $rotate_ParentInvertRotation = quat$1.create();
9953
+ var $triggerPendingEvents_detail = { affectChildren: true };
9954
+ /**
9955
+ * update transform in scene graph
9956
+ *
9957
+ * @see https://community.khronos.org/t/scene-graphs/50542/7
9958
+ */
9959
+ var DefaultSceneGraphService = /** @class */ (function () {
9960
+ function DefaultSceneGraphService(runtime) {
9961
+ this.runtime = runtime;
9962
+ // target -> affectChildren
9963
+ this.pendingEvents = new Map();
9964
+ this.boundsChangedEvent = new CustomEvent(ElementEvent.BOUNDS_CHANGED);
10703
9965
  this.displayObjectDependencyMap = new WeakMap();
10704
- this.calcLocalTransform = (function () {
10705
- var tmpMat = mat4.create();
10706
- var tmpPosition = vec3.create();
10707
- var tmpQuat = quat$1.fromValues(0, 0, 0, 1);
10708
- return function (transform) {
10709
- var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
10710
- if (hasSkew) {
10711
- mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, vec3.fromValues(1, 1, 1), transform.origin);
10712
- // apply skew2D
10713
- if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
10714
- var tmpMat4 = mat4.identity(tmpMat);
10715
- tmpMat4[4] = Math.tan(transform.localSkew[0]);
10716
- tmpMat4[1] = Math.tan(transform.localSkew[1]);
10717
- mat4.multiply(transform.localTransform, transform.localTransform, tmpMat4);
10718
- }
10719
- var scaling = mat4.fromRotationTranslationScaleOrigin(tmpMat, tmpQuat, tmpPosition, transform.localScale, transform.origin);
10720
- mat4.multiply(transform.localTransform, transform.localTransform, scaling);
10721
- }
10722
- else {
10723
- // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
10724
- mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, transform.localScale, transform.origin);
10725
- }
10726
- };
10727
- })();
10728
9966
  }
10729
9967
  DefaultSceneGraphService.prototype.matches = function (query, root) {
10730
9968
  return this.runtime.sceneGraphSelector.is(query, root);
@@ -10743,12 +9981,23 @@ var DefaultSceneGraphService = /** @class */ (function () {
10743
9981
  detached = child.parentNode !== parent;
10744
9982
  this.detach(child);
10745
9983
  }
9984
+ var isChildFragment = child.nodeName === Shape.FRAGMENT;
9985
+ var isAttachToFragment = isInFragment(parent);
10746
9986
  child.parentNode = parent;
10747
- if (!isNil(index)) {
10748
- child.parentNode.childNodes.splice(index, 0, child);
9987
+ var nodes = isChildFragment
9988
+ ? child.childNodes
9989
+ : [child];
9990
+ if (isNumber(index)) {
9991
+ nodes.forEach(function (node) {
9992
+ parent.childNodes.splice(index, 0, node);
9993
+ node.parentNode = parent;
9994
+ });
10749
9995
  }
10750
9996
  else {
10751
- child.parentNode.childNodes.push(child);
9997
+ nodes.forEach(function (node) {
9998
+ parent.childNodes.push(node);
9999
+ node.parentNode = parent;
10000
+ });
10752
10001
  }
10753
10002
  // parent needs re-sort
10754
10003
  var sortable = parent.sortable;
@@ -10762,13 +10011,15 @@ var DefaultSceneGraphService = /** @class */ (function () {
10762
10011
  sortable.dirty = true;
10763
10012
  sortable.dirtyReason = SortReason.ADDED;
10764
10013
  }
10765
- // this.updateGraphDepth(child);
10766
- var transform = child.transformable;
10767
- if (transform) {
10768
- this.dirtifyWorld(child, transform);
10769
- }
10770
- if (transform.frozen) {
10771
- this.unfreezeParentToRoot(child);
10014
+ if (isAttachToFragment)
10015
+ return;
10016
+ if (isChildFragment)
10017
+ this.dirtifyFragment(child);
10018
+ else {
10019
+ var transform = child.transformable;
10020
+ if (transform) {
10021
+ this.dirtifyWorld(child, transform);
10022
+ }
10772
10023
  }
10773
10024
  if (detached) {
10774
10025
  child.dispatchEvent(reparentEvent);
@@ -10836,6 +10087,70 @@ var DefaultSceneGraphService = /** @class */ (function () {
10836
10087
  originVec[2] = origin[2] || 0;
10837
10088
  this.dirtifyLocal(element, transform);
10838
10089
  };
10090
+ /**
10091
+ * rotate in world space
10092
+ */
10093
+ DefaultSceneGraphService.prototype.rotate = function (element, degrees, y, z) {
10094
+ if (y === void 0) { y = 0; }
10095
+ if (z === void 0) { z = 0; }
10096
+ if (typeof degrees === 'number') {
10097
+ degrees = vec3.fromValues(degrees, y, z);
10098
+ }
10099
+ var transform = element.transformable;
10100
+ if (element.parentNode === null ||
10101
+ !element.parentNode.transformable) {
10102
+ this.rotateLocal(element, degrees);
10103
+ }
10104
+ else {
10105
+ var rotation = $quat$1;
10106
+ quat$1.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10107
+ var rot = this.getRotation(element);
10108
+ var parentRot = this.getRotation(element.parentNode);
10109
+ quat$1.copy($rotate_ParentInvertRotation, parentRot);
10110
+ quat$1.invert($rotate_ParentInvertRotation, $rotate_ParentInvertRotation);
10111
+ quat$1.multiply(rotation, $rotate_ParentInvertRotation, rotation);
10112
+ quat$1.multiply(transform.localRotation, rotation, rot);
10113
+ quat$1.normalize(transform.localRotation, transform.localRotation);
10114
+ this.dirtifyLocal(element, transform);
10115
+ }
10116
+ };
10117
+ /**
10118
+ * rotate in local space
10119
+ * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
10120
+ */
10121
+ DefaultSceneGraphService.prototype.rotateLocal = function (element, degrees, y, z) {
10122
+ if (y === void 0) { y = 0; }
10123
+ if (z === void 0) { z = 0; }
10124
+ if (typeof degrees === 'number') {
10125
+ degrees = vec3.fromValues(degrees, y, z);
10126
+ }
10127
+ var transform = element.transformable;
10128
+ quat$1.fromEuler($rotateLocal, degrees[0], degrees[1], degrees[2]);
10129
+ quat$1.mul(transform.localRotation, transform.localRotation, $rotateLocal);
10130
+ this.dirtifyLocal(element, transform);
10131
+ };
10132
+ /**
10133
+ * set euler angles(degrees) in world space
10134
+ */
10135
+ DefaultSceneGraphService.prototype.setEulerAngles = function (element, degrees, y, z) {
10136
+ if (y === void 0) { y = 0; }
10137
+ if (z === void 0) { z = 0; }
10138
+ if (typeof degrees === 'number') {
10139
+ degrees = vec3.fromValues(degrees, y, z);
10140
+ }
10141
+ var transform = element.transformable;
10142
+ if (element.parentNode === null ||
10143
+ !element.parentNode.transformable) {
10144
+ this.setLocalEulerAngles(element, degrees);
10145
+ }
10146
+ else {
10147
+ quat$1.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
10148
+ var parentRotation = this.getRotation(element.parentNode);
10149
+ quat$1.copy($setEulerAngles_InvParentRot, quat$1.invert($quat$1, parentRotation));
10150
+ quat$1.mul(transform.localRotation, transform.localRotation, $setEulerAngles_InvParentRot);
10151
+ this.dirtifyLocal(element, transform);
10152
+ }
10153
+ };
10839
10154
  /**
10840
10155
  * set euler angles(degrees) in local space
10841
10156
  */
@@ -10853,32 +10168,140 @@ var DefaultSceneGraphService = /** @class */ (function () {
10853
10168
  }
10854
10169
  };
10855
10170
  /**
10856
- * scale in local space
10171
+ * translate in local space
10172
+ *
10173
+ * @example
10174
+ * ```
10175
+ * translateLocal(x, y, z)
10176
+ * translateLocal(vec3(x, y, z))
10177
+ * ```
10178
+ */
10179
+ DefaultSceneGraphService.prototype.translateLocal = function (element, translation, y, z) {
10180
+ if (y === void 0) { y = 0; }
10181
+ if (z === void 0) { z = 0; }
10182
+ if (typeof translation === 'number') {
10183
+ translation = vec3.fromValues(translation, y, z);
10184
+ }
10185
+ var transform = element.transformable;
10186
+ if (vec3.equals(translation, $vec3Zero))
10187
+ return;
10188
+ vec3.transformQuat(translation, translation, transform.localRotation);
10189
+ vec3.add(transform.localPosition, transform.localPosition, translation);
10190
+ this.dirtifyLocal(element, transform);
10191
+ };
10192
+ /**
10193
+ * move to position in world space
10194
+ *
10195
+ * 对应 g 原版的 move/moveTo
10196
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
10197
+ */
10198
+ DefaultSceneGraphService.prototype.setPosition = function (element, position) {
10199
+ var _a;
10200
+ var transform = element.transformable;
10201
+ $setPosition_1[0] = position[0];
10202
+ $setPosition_1[1] = position[1];
10203
+ $setPosition_1[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10204
+ if (vec3.equals(this.getPosition(element), $setPosition_1)) {
10205
+ return;
10206
+ }
10207
+ vec3.copy(transform.position, $setPosition_1);
10208
+ if (element.parentNode === null ||
10209
+ !element.parentNode.transformable) {
10210
+ vec3.copy(transform.localPosition, $setPosition_1);
10211
+ }
10212
+ else {
10213
+ var parentTransform = element.parentNode.transformable;
10214
+ mat4.copy($setPosition_ParentInvertMatrix, parentTransform.worldTransform);
10215
+ mat4.invert($setPosition_ParentInvertMatrix, $setPosition_ParentInvertMatrix);
10216
+ vec3.transformMat4(transform.localPosition, $setPosition_1, $setPosition_ParentInvertMatrix);
10217
+ }
10218
+ this.dirtifyLocal(element, transform);
10219
+ };
10220
+ /**
10221
+ * move to position in local space
10857
10222
  */
10858
- DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling, dirtify) {
10223
+ DefaultSceneGraphService.prototype.setLocalPosition = function (element, position, dirtify) {
10224
+ var _a;
10859
10225
  if (dirtify === void 0) { dirtify = true; }
10860
10226
  var transform = element.transformable;
10861
- vec3.multiply(transform.localScale, transform.localScale, vec3.fromValues(scaling[0], scaling[1], scaling[2] || 1));
10227
+ $setLocalPosition[0] = position[0];
10228
+ $setLocalPosition[1] = position[1];
10229
+ $setLocalPosition[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10230
+ if (vec3.equals(transform.localPosition, $setLocalPosition)) {
10231
+ return;
10232
+ }
10233
+ vec3.copy(transform.localPosition, $setLocalPosition);
10862
10234
  if (dirtify) {
10863
10235
  this.dirtifyLocal(element, transform);
10864
10236
  }
10865
10237
  };
10238
+ /**
10239
+ * scale in local space
10240
+ */
10241
+ DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling) {
10242
+ var _a;
10243
+ var transform = element.transformable;
10244
+ vec3.multiply(transform.localScale, transform.localScale, vec3.set($vec3$1, scaling[0], scaling[1], (_a = scaling[2]) !== null && _a !== void 0 ? _a : 1));
10245
+ this.dirtifyLocal(element, transform);
10246
+ };
10866
10247
  DefaultSceneGraphService.prototype.setLocalScale = function (element, scaling, dirtify) {
10248
+ var _a;
10867
10249
  if (dirtify === void 0) { dirtify = true; }
10868
10250
  var transform = element.transformable;
10869
- var updatedScaling = vec3.fromValues(scaling[0], scaling[1], scaling[2] || transform.localScale[2]);
10870
- if (vec3.equals(updatedScaling, transform.localScale)) {
10251
+ vec3.set($vec3$1, scaling[0], scaling[1], (_a = scaling[2]) !== null && _a !== void 0 ? _a : transform.localScale[2]);
10252
+ if (vec3.equals($vec3$1, transform.localScale)) {
10871
10253
  return;
10872
10254
  }
10873
- vec3.copy(transform.localScale, updatedScaling);
10255
+ vec3.copy(transform.localScale, $vec3$1);
10874
10256
  if (dirtify) {
10875
10257
  this.dirtifyLocal(element, transform);
10876
10258
  }
10877
10259
  };
10260
+ /**
10261
+ * translate in world space
10262
+ *
10263
+ * @example
10264
+ * ```
10265
+ * translate(x, y, z)
10266
+ * translate(vec3(x, y, z))
10267
+ * ```
10268
+ *
10269
+ * 对应 g 原版的 translate 2D
10270
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
10271
+ */
10272
+ DefaultSceneGraphService.prototype.translate = function (element, translation, y, z) {
10273
+ if (y === void 0) { y = 0; }
10274
+ if (z === void 0) { z = 0; }
10275
+ if (typeof translation === 'number') {
10276
+ translation = vec3.set($vec3$1, translation, y, z);
10277
+ }
10278
+ if (vec3.equals(translation, $vec3Zero))
10279
+ return;
10280
+ vec3.add($vec3$1, this.getPosition(element), translation);
10281
+ this.setPosition(element, $vec3$1);
10282
+ };
10283
+ DefaultSceneGraphService.prototype.setRotation = function (element, rotation, y, z, w) {
10284
+ var transform = element.transformable;
10285
+ if (typeof rotation === 'number') {
10286
+ rotation = quat$1.fromValues(rotation, y, z, w);
10287
+ }
10288
+ if (element.parentNode === null ||
10289
+ !element.parentNode.transformable) {
10290
+ this.setLocalRotation(element, rotation);
10291
+ }
10292
+ else {
10293
+ var parentRot = this.getRotation(element.parentNode);
10294
+ quat$1.copy($quat$1, parentRot);
10295
+ quat$1.invert($quat$1, $quat$1);
10296
+ quat$1.multiply(transform.localRotation, $quat$1, rotation);
10297
+ quat$1.normalize(transform.localRotation, transform.localRotation);
10298
+ this.dirtifyLocal(element, transform);
10299
+ }
10300
+ };
10878
10301
  DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w, dirtify) {
10879
10302
  if (dirtify === void 0) { dirtify = true; }
10880
10303
  if (typeof rotation === 'number') {
10881
- rotation = quat$1.fromValues(rotation, y, z, w);
10304
+ rotation = quat$1.set($quat$1, rotation, y, z, w);
10882
10305
  }
10883
10306
  var transform = element.transformable;
10884
10307
  quat$1.copy(transform.localRotation, rotation);
@@ -10886,15 +10309,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
10886
10309
  this.dirtifyLocal(element, transform);
10887
10310
  }
10888
10311
  };
10889
- DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y) {
10312
+ DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y, dirtify) {
10313
+ if (dirtify === void 0) { dirtify = true; }
10890
10314
  if (typeof skew === 'number') {
10891
- skew = vec2.fromValues(skew, y);
10315
+ skew = vec2.set($vec2, skew, y);
10892
10316
  }
10893
10317
  var transform = element.transformable;
10894
10318
  vec2.copy(transform.localSkew, skew);
10895
- this.dirtifyLocal(element, transform);
10319
+ if (dirtify) {
10320
+ this.dirtifyLocal(element, transform);
10321
+ }
10896
10322
  };
10897
10323
  DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
10324
+ if (isInFragment(element))
10325
+ return;
10898
10326
  if (!transform.localDirtyFlag) {
10899
10327
  transform.localDirtyFlag = true;
10900
10328
  if (!transform.dirtyFlag) {
@@ -10909,11 +10337,43 @@ var DefaultSceneGraphService = /** @class */ (function () {
10909
10337
  this.dirtifyWorldInternal(element, transform);
10910
10338
  this.dirtifyToRoot(element, true);
10911
10339
  };
10340
+ DefaultSceneGraphService.prototype.dirtifyFragment = function (element) {
10341
+ var transform = element.transformable;
10342
+ if (transform) {
10343
+ transform.frozen = false;
10344
+ transform.dirtyFlag = true;
10345
+ transform.localDirtyFlag = true;
10346
+ }
10347
+ var renderable = element.renderable;
10348
+ if (renderable) {
10349
+ renderable.renderBoundsDirty = true;
10350
+ renderable.boundsDirty = true;
10351
+ renderable.dirty = true;
10352
+ }
10353
+ var length = element.childNodes.length;
10354
+ for (var i = 0; i < length; i++) {
10355
+ this.dirtifyFragment(element.childNodes[i]);
10356
+ }
10357
+ if (element.nodeName === Shape.FRAGMENT) {
10358
+ this.pendingEvents.set(element, false);
10359
+ }
10360
+ };
10912
10361
  DefaultSceneGraphService.prototype.triggerPendingEvents = function () {
10913
10362
  var _this = this;
10914
- var set = new Set();
10363
+ var triggered = new Set();
10364
+ var skipped = new Set();
10365
+ this.pendingEvents.forEach(function (_, element) {
10366
+ if (element.nodeName === Shape.FRAGMENT) {
10367
+ element.forEach(function (e) {
10368
+ if (e !== element)
10369
+ skipped.add(e);
10370
+ });
10371
+ }
10372
+ });
10915
10373
  var trigger = function (element, detail) {
10916
- if (element.isConnected && !set.has(element.entity)) {
10374
+ if (element.isConnected &&
10375
+ !triggered.has(element) &&
10376
+ !skipped.has(element)) {
10917
10377
  _this.boundsChangedEvent.detail = detail;
10918
10378
  _this.boundsChangedEvent.target = element;
10919
10379
  if (element.isMutationObserved) {
@@ -10922,25 +10382,25 @@ var DefaultSceneGraphService = /** @class */ (function () {
10922
10382
  else {
10923
10383
  element.ownerDocument.defaultView.dispatchEvent(_this.boundsChangedEvent, true);
10924
10384
  }
10925
- set.add(element.entity);
10385
+ triggered.add(element);
10926
10386
  }
10927
10387
  };
10928
- this.pendingEvents.forEach(function (_a) {
10929
- var _b = __read(_a, 2), element = _b[0], detail = _b[1];
10930
- if (detail.affectChildren) {
10388
+ this.pendingEvents.forEach(function (affectChildren, element) {
10389
+ $triggerPendingEvents_detail.affectChildren = affectChildren;
10390
+ if (affectChildren) {
10931
10391
  element.forEach(function (e) {
10932
- trigger(e, detail);
10392
+ trigger(e, $triggerPendingEvents_detail);
10933
10393
  });
10934
10394
  }
10935
- else {
10936
- trigger(element, detail);
10937
- }
10395
+ else
10396
+ trigger(element, $triggerPendingEvents_detail);
10938
10397
  });
10398
+ triggered.clear();
10399
+ skipped.clear();
10939
10400
  this.clearPendingEvents();
10940
- set.clear();
10941
10401
  };
10942
10402
  DefaultSceneGraphService.prototype.clearPendingEvents = function () {
10943
- this.pendingEvents = [];
10403
+ this.pendingEvents.clear();
10944
10404
  };
10945
10405
  DefaultSceneGraphService.prototype.dirtifyToRoot = function (element, affectChildren) {
10946
10406
  if (affectChildren === void 0) { affectChildren = false; }
@@ -10958,10 +10418,8 @@ var DefaultSceneGraphService = /** @class */ (function () {
10958
10418
  markRenderableDirty(e);
10959
10419
  });
10960
10420
  }
10961
- // inform dependencies
10962
10421
  this.informDependentDisplayObjects(element);
10963
- // reuse the same custom event
10964
- this.pendingEvents.push([element, { affectChildren: affectChildren }]);
10422
+ this.pendingEvents.set(element, affectChildren);
10965
10423
  };
10966
10424
  DefaultSceneGraphService.prototype.updateDisplayObjectDependency = function (name, oldPath, newPath, object) {
10967
10425
  // clear ref to old clip path
@@ -11036,6 +10494,45 @@ var DefaultSceneGraphService = /** @class */ (function () {
11036
10494
  DefaultSceneGraphService.prototype.getLocalSkew = function (element) {
11037
10495
  return element.transformable.localSkew;
11038
10496
  };
10497
+ DefaultSceneGraphService.prototype.calcLocalTransform = function (transform) {
10498
+ var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
10499
+ if (hasSkew) {
10500
+ mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, vec3.fromValues(1, 1, 1), transform.origin);
10501
+ // apply skew2D
10502
+ if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
10503
+ mat4.identity($mat4);
10504
+ $mat4[4] = Math.tan(transform.localSkew[0]);
10505
+ $mat4[1] = Math.tan(transform.localSkew[1]);
10506
+ mat4.multiply(transform.localTransform, transform.localTransform, $mat4);
10507
+ }
10508
+ var scaling = mat4.fromRotationTranslationScaleOrigin($mat4, quat$1.set($quat$1, 0, 0, 0, 1), vec3.set($vec3$1, 1, 1, 1), transform.localScale, transform.origin);
10509
+ mat4.multiply(transform.localTransform, transform.localTransform, scaling);
10510
+ }
10511
+ else {
10512
+ var localTransform = transform.localTransform, localPosition = transform.localPosition, localRotation = transform.localRotation, localScale = transform.localScale, origin_1 = transform.origin;
10513
+ var hasPosition = localPosition[0] !== 0 ||
10514
+ localPosition[1] !== 0 ||
10515
+ localPosition[2] !== 0;
10516
+ var hasRotation = localRotation[3] !== 1 ||
10517
+ localRotation[0] !== 0 ||
10518
+ localRotation[1] !== 0 ||
10519
+ localRotation[2] !== 0;
10520
+ var hasScale = localScale[0] !== 1 || localScale[1] !== 1 || localScale[2] !== 1;
10521
+ var hasOrigin = origin_1[0] !== 0 || origin_1[1] !== 0 || origin_1[2] !== 0;
10522
+ if (!hasRotation && !hasScale && !hasOrigin) {
10523
+ if (hasPosition) {
10524
+ mat4.fromTranslation(localTransform, localPosition);
10525
+ }
10526
+ else {
10527
+ mat4.identity(localTransform);
10528
+ }
10529
+ }
10530
+ else {
10531
+ // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
10532
+ mat4.fromRotationTranslationScaleOrigin(localTransform, localRotation, localPosition, localScale, origin_1);
10533
+ }
10534
+ }
10535
+ };
11039
10536
  DefaultSceneGraphService.prototype.getLocalTransform = function (element) {
11040
10537
  var transform = element.transformable;
11041
10538
  if (transform.localDirtyFlag) {
@@ -11045,19 +10542,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
11045
10542
  return transform.localTransform;
11046
10543
  };
11047
10544
  DefaultSceneGraphService.prototype.setLocalTransform = function (element, transform) {
11048
- var t = mat4.getTranslation(vec3.create(), transform);
11049
- var r = mat4.getRotation(quat$1.create(), transform);
11050
- var s = mat4.getScaling(vec3.create(), transform);
10545
+ var t = mat4.getTranslation($setLocalTransform_1, transform);
10546
+ var r = mat4.getRotation($setLocalTransform_2, transform);
10547
+ var s = mat4.getScaling($setLocalTransform_3, transform);
11051
10548
  this.setLocalScale(element, s, false);
11052
10549
  this.setLocalPosition(element, t, false);
11053
10550
  this.setLocalRotation(element, r, undefined, undefined, undefined, false);
11054
10551
  this.dirtifyLocal(element, element.transformable);
11055
10552
  };
11056
10553
  DefaultSceneGraphService.prototype.resetLocalTransform = function (element) {
11057
- this.setLocalScale(element, [1, 1, 1]);
11058
- this.setLocalPosition(element, [0, 0, 0]);
11059
- this.setLocalEulerAngles(element, [0, 0, 0]);
11060
- this.setLocalSkew(element, [0, 0]);
10554
+ this.setLocalScale(element, $vec3One, false);
10555
+ this.setLocalPosition(element, $vec3Zero, false);
10556
+ this.setLocalEulerAngles(element, $vec3Zero, undefined, undefined, false);
10557
+ this.setLocalSkew(element, $vec2Zero, undefined, false);
10558
+ this.dirtifyLocal(element, element.transformable);
11061
10559
  };
11062
10560
  DefaultSceneGraphService.prototype.getTransformedGeometryBounds = function (element, render, existedAABB) {
11063
10561
  if (render === void 0) { render = false; }
@@ -11149,9 +10647,9 @@ var DefaultSceneGraphService = /** @class */ (function () {
11149
10647
  */
11150
10648
  DefaultSceneGraphService.prototype.getLocalBounds = function (element) {
11151
10649
  if (element.parentNode) {
11152
- var parentInvert = mat4.create();
10650
+ var parentInvert = $mat4Identity;
11153
10651
  if (element.parentNode.transformable) {
11154
- parentInvert = mat4.invert(mat4.create(), this.getWorldTransform(element.parentNode));
10652
+ parentInvert = mat4.invert($mat4, this.getWorldTransform(element.parentNode));
11155
10653
  }
11156
10654
  var bounds = this.getBounds(element);
11157
10655
  if (!AABB.isEmpty(bounds)) {
@@ -11404,19 +10902,12 @@ var TextService = /** @class */ (function () {
11404
10902
  // dropShadowDistance = 0,
11405
10903
  leading = _g === void 0 ? 0 : _g;
11406
10904
  var font = toFontString(parsedStyle);
11407
- // if (runtime.enableCSSParsing) {
11408
10905
  var fontProperties = this.measureFont(font, offscreenCanvas);
11409
10906
  // fallback in case UA disallow canvas data extraction
11410
- // (toDataURI, getImageData functions)
11411
10907
  if (fontProperties.fontSize === 0) {
11412
10908
  fontProperties.fontSize = fontSize;
11413
10909
  fontProperties.ascent = fontSize;
11414
10910
  }
11415
- // } else {
11416
- // fontProperties = {
11417
- // fontSize,
11418
- // };
11419
- // }
11420
10911
  var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11421
10912
  context.font = font;
11422
10913
  // no overflowing by default
@@ -11738,10 +11229,7 @@ runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
11738
11229
  runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime);
11739
11230
  runtime.layoutRegistry = null;
11740
11231
  runtime.globalThis = getGlobalThis();
11741
- runtime.enableCSSParsing = false;
11742
- runtime.enableDataset = false;
11743
11232
  runtime.enableStyleSyntax = true;
11744
- runtime.enableAttributeDashCased = false;
11745
11233
  runtime.enableSizeAttenuation = false;
11746
11234
 
11747
11235
  var entityCounter = 0;
@@ -11830,34 +11318,7 @@ var Element = /** @class */ (function (_super) {
11830
11318
  * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
11831
11319
  */
11832
11320
  _this.style = {};
11833
- _this.computedStyle = runtime.enableCSSParsing
11834
- ? {
11835
- opacity: unsetKeywordValue,
11836
- fillOpacity: unsetKeywordValue,
11837
- strokeOpacity: unsetKeywordValue,
11838
- fill: unsetKeywordValue,
11839
- stroke: unsetKeywordValue,
11840
- transform: unsetKeywordValue,
11841
- transformOrigin: unsetKeywordValue,
11842
- visibility: unsetKeywordValue,
11843
- pointerEvents: unsetKeywordValue,
11844
- lineWidth: unsetKeywordValue,
11845
- lineCap: unsetKeywordValue,
11846
- lineJoin: unsetKeywordValue,
11847
- increasedLineWidthForHitTesting: unsetKeywordValue,
11848
- fontSize: unsetKeywordValue,
11849
- fontFamily: unsetKeywordValue,
11850
- fontStyle: unsetKeywordValue,
11851
- fontWeight: unsetKeywordValue,
11852
- fontVariant: unsetKeywordValue,
11853
- textAlign: unsetKeywordValue,
11854
- textBaseline: unsetKeywordValue,
11855
- textTransform: unsetKeywordValue,
11856
- zIndex: unsetKeywordValue,
11857
- filter: unsetKeywordValue,
11858
- shadowType: unsetKeywordValue,
11859
- }
11860
- : null;
11321
+ _this.computedStyle = {};
11861
11322
  /**
11862
11323
  * Renderers will use these used values.
11863
11324
  */
@@ -11986,7 +11447,12 @@ var Element = /** @class */ (function (_super) {
11986
11447
  }
11987
11448
  runtime.sceneGraphService.attach(child, this, index);
11988
11449
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
11989
- this.ownerDocument.defaultView.mountChildren(child);
11450
+ if (!isInFragment(this) && child.nodeName === Shape.FRAGMENT) {
11451
+ this.ownerDocument.defaultView.mountFragment(child);
11452
+ }
11453
+ else {
11454
+ this.ownerDocument.defaultView.mountChildren(child);
11455
+ }
11990
11456
  }
11991
11457
  // @ts-ignore
11992
11458
  if (this.isMutationObserved) {
@@ -12100,9 +11566,9 @@ var Element = /** @class */ (function (_super) {
12100
11566
  this.forEach(function (object) {
12101
11567
  if (object !== _this && filter(object)) {
12102
11568
  target = object;
12103
- return true;
11569
+ return false;
12104
11570
  }
12105
- return false;
11571
+ return true;
12106
11572
  });
12107
11573
  return target;
12108
11574
  };
@@ -12260,17 +11726,13 @@ var Element = /** @class */ (function (_super) {
12260
11726
  */
12261
11727
  Element.prototype.getAttribute = function (name) {
12262
11728
  // @see https://github.com/antvis/G/issues/1267
12263
- if (isSymbol(name)) {
12264
- return runtime.enableCSSParsing ? null : undefined;
11729
+ if (typeof name === 'symbol') {
11730
+ return undefined;
12265
11731
  }
12266
11732
  var value = this.attributes[name];
12267
11733
  if (value === undefined) {
12268
- if (runtime.enableAttributeDashCased) {
12269
- var attributeName = formatAttributeName(name);
12270
- value = this.attributes[attributeName];
12271
- }
12272
11734
  // if the given attribute does not exist, the value returned will either be null or ""
12273
- return runtime.enableCSSParsing ? (isNil(value) ? null : value) : value;
11735
+ return value;
12274
11736
  }
12275
11737
  else {
12276
11738
  return value;
@@ -12342,78 +11804,8 @@ var Proxy = runtime.globalThis.Proxy
12342
11804
  ? runtime.globalThis.Proxy
12343
11805
  : function () { };
12344
11806
  var mutationEvent = new MutationEvent(ElementEvent.ATTR_MODIFIED, null, null, null, null, MutationEvent.MODIFICATION, null, null);
12345
- var DEFAULT_STYLE_PROPS = {
12346
- opacity: '',
12347
- fillOpacity: '',
12348
- strokeOpacity: '',
12349
- fill: '',
12350
- stroke: '',
12351
- transform: '',
12352
- transformOrigin: '',
12353
- visibility: '',
12354
- pointerEvents: '',
12355
- lineWidth: '',
12356
- lineCap: '',
12357
- lineJoin: '',
12358
- increasedLineWidthForHitTesting: '',
12359
- fontSize: '',
12360
- fontFamily: '',
12361
- fontStyle: '',
12362
- fontWeight: '',
12363
- fontVariant: '',
12364
- textAlign: '',
12365
- textBaseline: '',
12366
- textTransform: '',
12367
- zIndex: '',
12368
- filter: '',
12369
- shadowType: '',
12370
- };
12371
- var DEFAULT_PARSED_STYLE_PROPS = {
12372
- fill: noneColor,
12373
- stroke: noneColor,
12374
- transform: [],
12375
- zIndex: 0,
12376
- filter: [],
12377
- shadowType: 'outer',
12378
- miterLimit: 10,
12379
- };
12380
- // const DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = {
12381
- // ...DEFAULT_PARSED_STYLE_PROPS,
12382
- // opacity: 1,
12383
- // fillOpacity: 1,
12384
- // strokeOpacity: 1,
12385
- // visibility: 'visible',
12386
- // pointerEvents: 'auto',
12387
- // lineWidth: 1,
12388
- // lineCap: 'butt',
12389
- // lineJoin: 'miter',
12390
- // increasedLineWidthForHitTesting: 0,
12391
- // fillRule: 'nonzero',
12392
- // // TODO: transformOrigin
12393
- // };
12394
- var INHERITABLE_BASE_STYLE_PROPS = [
12395
- 'opacity',
12396
- 'fillOpacity',
12397
- 'strokeOpacity',
12398
- 'transformOrigin',
12399
- 'visibility',
12400
- 'pointerEvents',
12401
- 'lineWidth',
12402
- 'lineCap',
12403
- 'lineJoin',
12404
- 'increasedLineWidthForHitTesting',
12405
- ];
12406
- var INHERITABLE_STYLE_PROPS = __spreadArray(__spreadArray([], __read(INHERITABLE_BASE_STYLE_PROPS), false), [
12407
- 'fontSize',
12408
- 'fontFamily',
12409
- 'fontStyle',
12410
- 'fontWeight',
12411
- 'fontVariant',
12412
- 'textAlign',
12413
- 'textBaseline',
12414
- 'textTransform',
12415
- ], false);
12416
- var DATASET_PREFIX = 'data-';
11807
+ var $vec3 = vec3.create();
11808
+ var $quat = quat$1.create();
12417
11809
  /**
12418
11810
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
12419
11811
  *
@@ -12446,38 +11838,17 @@ var DisplayObject = /** @class */ (function (_super) {
12446
11838
  // eg. group.get('name')
12447
11839
  _this.config = config;
12448
11840
  // init scene graph node
12449
- _this.id = _this.config.id || '';
12450
- _this.name = _this.config.name || '';
12451
- if (_this.config.className || _this.config.class) {
12452
- _this.className = _this.config.className || _this.config.class;
11841
+ _this.id = config.id || '';
11842
+ _this.name = config.name || '';
11843
+ if (config.className || config.class) {
11844
+ _this.className = config.className || config.class;
12453
11845
  }
12454
- _this.nodeName = _this.config.type || Shape.GROUP;
12455
- if (runtime.enableCSSParsing) {
12456
- Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12457
- Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
12458
- }
12459
- else if (_this.config.initialParsedStyle) {
12460
- Object.assign(_this.parsedStyle,
12461
- // DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED,
12462
- _this.config.initialParsedStyle);
11846
+ _this.nodeName = config.type || Shape.GROUP;
11847
+ if (config.initialParsedStyle) {
11848
+ Object.assign(_this.parsedStyle, config.initialParsedStyle);
12463
11849
  }
12464
11850
  // start to process attributes
12465
- _this.initAttributes(_this.config.style);
12466
- if (runtime.enableDataset) {
12467
- _this.dataset = new Proxy({}, {
12468
- get: function (target, name) {
12469
- var formattedName = "".concat(DATASET_PREFIX).concat(kebabize(name));
12470
- if (target[formattedName] !== undefined) {
12471
- return target[formattedName];
12472
- }
12473
- return _this.getAttribute(formattedName);
12474
- },
12475
- set: function (_, prop, value) {
12476
- _this.setAttribute("".concat(DATASET_PREFIX).concat(kebabize(prop)), value);
12477
- return true;
12478
- },
12479
- });
12480
- }
11851
+ _this.initAttributes(config.style);
12481
11852
  if (runtime.enableStyleSyntax) {
12482
11853
  _this.style = new Proxy(
12483
11854
  // @ts-ignore
@@ -12517,13 +11888,6 @@ var DisplayObject = /** @class */ (function (_super) {
12517
11888
  this.getAnimations().forEach(function (animation) {
12518
11889
  animation.cancel();
12519
11890
  });
12520
- // FIXME
12521
- // this.renderable = null;
12522
- // this.cullable = null;
12523
- // this.transformable = null;
12524
- // this.rBushNode = null;
12525
- // this.geometry = null;
12526
- // this.sortable = null;
12527
11891
  };
12528
11892
  DisplayObject.prototype.cloneNode = function (deep, customCloneFunc) {
12529
11893
  var clonedStyle = __assign({}, this.attributes);
@@ -12566,39 +11930,16 @@ var DisplayObject = /** @class */ (function (_super) {
12566
11930
  };
12567
11931
  DisplayObject.prototype.initAttributes = function (attributes) {
12568
11932
  if (attributes === void 0) { attributes = {}; }
12569
- var renderable = this.renderable;
12570
11933
  var options = {
12571
11934
  forceUpdateGeometry: true,
12572
- // usedAttributes:
12573
- // // only Group / Text should account for text relative props
12574
- // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT
12575
- // ? INHERITABLE_STYLE_PROPS
12576
- // : INHERITABLE_BASE_STYLE_PROPS,
12577
11935
  };
12578
- if (runtime.enableCSSParsing) {
12579
- // @ts-ignore
12580
- options.usedAttributes = INHERITABLE_STYLE_PROPS;
12581
- }
12582
- // account for FCP, process properties as less as possible
12583
- var formattedAttributes = attributes;
12584
- if (runtime.enableAttributeDashCased) {
12585
- // @ts-ignore
12586
- formattedAttributes = {};
12587
- for (var name_1 in attributes) {
12588
- var attributeName = formatAttributeName(name_1);
12589
- formattedAttributes[attributeName] = attributes[name_1];
12590
- }
12591
- }
12592
- runtime.styleValueRegistry.processProperties(this, formattedAttributes, options);
11936
+ runtime.styleValueRegistry.processProperties(this, attributes, options);
12593
11937
  // redraw at next frame
12594
- renderable.dirty = true;
11938
+ this.renderable.dirty = true;
12595
11939
  };
12596
11940
  DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12597
11941
  if (force === void 0) { force = false; }
12598
11942
  if (memoize === void 0) { memoize = true; }
12599
- if (runtime.enableAttributeDashCased) {
12600
- name = formatAttributeName(name);
12601
- }
12602
11943
  // ignore undefined value
12603
11944
  if (isUndefined(value)) {
12604
11945
  return;
@@ -12660,7 +12001,7 @@ var DisplayObject = /** @class */ (function (_super) {
12660
12001
  DisplayObject.prototype.setOrigin = function (position, y, z) {
12661
12002
  if (y === void 0) { y = 0; }
12662
12003
  if (z === void 0) { z = 0; }
12663
- runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z));
12004
+ runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z, false));
12664
12005
  return this;
12665
12006
  };
12666
12007
  DisplayObject.prototype.getOrigin = function () {
@@ -12672,7 +12013,7 @@ var DisplayObject = /** @class */ (function (_super) {
12672
12013
  DisplayObject.prototype.setPosition = function (position, y, z) {
12673
12014
  if (y === void 0) { y = 0; }
12674
12015
  if (z === void 0) { z = 0; }
12675
- runtime.sceneGraphService.setPosition(this, createVec3(position, y, z));
12016
+ runtime.sceneGraphService.setPosition(this, createVec3(position, y, z, false));
12676
12017
  return this;
12677
12018
  };
12678
12019
  /**
@@ -12681,7 +12022,7 @@ var DisplayObject = /** @class */ (function (_super) {
12681
12022
  DisplayObject.prototype.setLocalPosition = function (position, y, z) {
12682
12023
  if (y === void 0) { y = 0; }
12683
12024
  if (z === void 0) { z = 0; }
12684
- runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
12025
+ runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z, false));
12685
12026
  return this;
12686
12027
  };
12687
12028
  /**
@@ -12690,7 +12031,7 @@ var DisplayObject = /** @class */ (function (_super) {
12690
12031
  DisplayObject.prototype.translate = function (position, y, z) {
12691
12032
  if (y === void 0) { y = 0; }
12692
12033
  if (z === void 0) { z = 0; }
12693
- runtime.sceneGraphService.translate(this, createVec3(position, y, z));
12034
+ runtime.sceneGraphService.translate(this, createVec3(position, y, z, false));
12694
12035
  return this;
12695
12036
  };
12696
12037
  /**
@@ -12699,7 +12040,7 @@ var DisplayObject = /** @class */ (function (_super) {
12699
12040
  DisplayObject.prototype.translateLocal = function (position, y, z) {
12700
12041
  if (y === void 0) { y = 0; }
12701
12042
  if (z === void 0) { z = 0; }
12702
- runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z));
12043
+ runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z, false));
12703
12044
  return this;
12704
12045
  };
12705
12046
  DisplayObject.prototype.getPosition = function () {
@@ -12723,7 +12064,7 @@ var DisplayObject = /** @class */ (function (_super) {
12723
12064
  if (typeof scaling === 'number') {
12724
12065
  y = y || scaling;
12725
12066
  z = z || scaling;
12726
- scaling = createVec3(scaling, y, z);
12067
+ scaling = createVec3(scaling, y, z, false);
12727
12068
  }
12728
12069
  runtime.sceneGraphService.scaleLocal(this, scaling);
12729
12070
  return this;
@@ -12735,7 +12076,7 @@ var DisplayObject = /** @class */ (function (_super) {
12735
12076
  if (typeof scaling === 'number') {
12736
12077
  y = y || scaling;
12737
12078
  z = z || scaling;
12738
- scaling = createVec3(scaling, y, z);
12079
+ scaling = createVec3(scaling, y, z, false);
12739
12080
  }
12740
12081
  runtime.sceneGraphService.setLocalScale(this, scaling);
12741
12082
  return this;
@@ -12756,14 +12097,14 @@ var DisplayObject = /** @class */ (function (_super) {
12756
12097
  * only return degrees of Z axis in world space
12757
12098
  */
12758
12099
  DisplayObject.prototype.getEulerAngles = function () {
12759
- var _a = __read(getEuler(vec3.create(), runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12100
+ var _a = __read(getEuler($vec3, runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12760
12101
  return rad2deg(ez);
12761
12102
  };
12762
12103
  /**
12763
12104
  * only return degrees of Z axis in local space
12764
12105
  */
12765
12106
  DisplayObject.prototype.getLocalEulerAngles = function () {
12766
- var _a = __read(getEuler(vec3.create(), runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12107
+ var _a = __read(getEuler($vec3, runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12767
12108
  return rad2deg(ez);
12768
12109
  };
12769
12110
  /**
@@ -12859,10 +12200,8 @@ var DisplayObject = /** @class */ (function (_super) {
12859
12200
  * shortcut for Used value of `visibility`
12860
12201
  */
12861
12202
  DisplayObject.prototype.isVisible = function () {
12862
- var _a, _b;
12863
- return runtime.enableCSSParsing
12864
- ? ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible'
12865
- : ((_b = this.parsedStyle) === null || _b === void 0 ? void 0 : _b.visibility) !== 'hidden';
12203
+ var _a;
12204
+ return ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) !== 'hidden';
12866
12205
  };
12867
12206
  Object.defineProperty(DisplayObject.prototype, "interactive", {
12868
12207
  get: function () {
@@ -12943,10 +12282,10 @@ var DisplayObject = /** @class */ (function (_super) {
12943
12282
  */
12944
12283
  DisplayObject.prototype.getMatrix = function (transformMat4) {
12945
12284
  var transform = transformMat4 || this.getWorldTransform();
12946
- var _a = __read(mat4.getTranslation(vec3.create(), transform), 2), tx = _a[0], ty = _a[1];
12947
- var _b = __read(mat4.getScaling(vec3.create(), transform), 2), sx = _b[0], sy = _b[1];
12948
- var rotation = mat4.getRotation(quat$1.create(), transform);
12949
- var _c = __read(getEuler(vec3.create(), rotation), 3), eux = _c[0], euz = _c[2];
12285
+ var _a = __read(mat4.getTranslation($vec3, transform), 2), tx = _a[0], ty = _a[1];
12286
+ var _b = __read(mat4.getScaling($vec3, transform), 2), sx = _b[0], sy = _b[1];
12287
+ var rotation = mat4.getRotation($quat, transform);
12288
+ var _c = __read(getEuler($vec3, rotation), 3), eux = _c[0], euz = _c[2];
12950
12289
  // gimbal lock at 90 degrees
12951
12290
  return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
12952
12291
  };
@@ -12982,28 +12321,18 @@ var DisplayObject = /** @class */ (function (_super) {
12982
12321
  * @deprecated
12983
12322
  */
12984
12323
  DisplayObject.prototype.show = function () {
12985
- if (runtime.enableCSSParsing) {
12986
- this.style.visibility = 'visible';
12987
- }
12988
- else {
12989
- this.forEach(function (object) {
12990
- object.style.visibility = 'visible';
12991
- });
12992
- }
12324
+ this.forEach(function (object) {
12325
+ object.style.visibility = 'visible';
12326
+ });
12993
12327
  };
12994
12328
  /**
12995
12329
  * Use `visibility: hidden` instead.
12996
12330
  * @deprecated
12997
12331
  */
12998
12332
  DisplayObject.prototype.hide = function () {
12999
- if (runtime.enableCSSParsing) {
13000
- this.style.visibility = 'hidden';
13001
- }
13002
- else {
13003
- this.forEach(function (object) {
13004
- object.style.visibility = 'hidden';
13005
- });
13006
- }
12333
+ this.forEach(function (object) {
12334
+ object.style.visibility = 'hidden';
12335
+ });
13007
12336
  };
13008
12337
  /**
13009
12338
  * Use `childElementCount` instead.
@@ -13118,8 +12447,7 @@ var CustomElement = /** @class */ (function (_super) {
13118
12447
  if (_a === void 0) { _a = {}; }
13119
12448
  var _this = this;
13120
12449
  var style = _a.style, rest = __rest(_a, ["style"]);
13121
- _this = _super.call(this, __assign({ style: runtime.enableCSSParsing
13122
- ? __assign({}, style) : __assign({}, style) }, rest)) || this;
12450
+ _this = _super.call(this, __assign({ style: style }, rest)) || this;
13123
12451
  // static get observedAttributes(): string[] {
13124
12452
  // return [];
13125
12453
  // }
@@ -13138,6 +12466,23 @@ var Ellipse = /** @class */ (function (_super) {
13138
12466
  return Ellipse;
13139
12467
  }(DisplayObject));
13140
12468
 
12469
+ /**
12470
+ * 节点片段,用于包裹多个节点并批量操作
12471
+ *
12472
+ * 向 Fragment 或者根节点为 Fragment 的节点添加子节点时,不会触发渲染和事件。
12473
+ *
12474
+ * 当 Fragment 被挂载到 Canvas 中的节点时,其子节点会一次性被渲染,并触发合并事件。
12475
+ *
12476
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
12477
+ */
12478
+ var Fragment = /** @class */ (function (_super) {
12479
+ __extends(Fragment, _super);
12480
+ function Fragment() {
12481
+ return _super.call(this, { type: Shape.FRAGMENT }) || this;
12482
+ }
12483
+ return Fragment;
12484
+ }(DisplayObject));
12485
+
13141
12486
  /**
13142
12487
  * its attributes are inherited by its children.
13143
12488
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
@@ -13167,8 +12512,7 @@ var HTML = /** @class */ (function (_super) {
13167
12512
  if (_a === void 0) { _a = {}; }
13168
12513
  var _this = this;
13169
12514
  var style = _a.style, rest = __rest(_a, ["style"]);
13170
- _this = _super.call(this, __assign({ type: Shape.HTML, style: runtime.enableCSSParsing
13171
- ? __assign({ x: '', y: '', width: 'auto', height: 'auto', innerHTML: '' }, style) : __assign({}, style) }, rest)) || this;
12515
+ _this = _super.call(this, __assign({ type: Shape.HTML, style: style }, rest)) || this;
13172
12516
  _this.cullable.enable = false;
13173
12517
  return _this;
13174
12518
  }
@@ -13360,13 +12704,10 @@ var Path = /** @class */ (function (_super) {
13360
12704
  if (_a === void 0) { _a = {}; }
13361
12705
  var _this = this;
13362
12706
  var style = _a.style, rest = __rest(_a, ["style"]);
13363
- _this = _super.call(this, __assign({ type: Shape.PATH, style: runtime.enableCSSParsing
13364
- ? __assign({ d: '', miterLimit: '' }, style) : __assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13365
- ? null
13366
- : {
13367
- miterLimit: 4,
13368
- d: __assign({}, EMPTY_PARSED_PATH),
13369
- } }, rest)) || this;
12707
+ _this = _super.call(this, __assign({ type: Shape.PATH, style: style, initialParsedStyle: {
12708
+ miterLimit: 4,
12709
+ d: __assign({}, EMPTY_PARSED_PATH),
12710
+ } }, rest)) || this;
13370
12711
  _this.markerStartAngle = 0;
13371
12712
  _this.markerEndAngle = 0;
13372
12713
  /**
@@ -13561,18 +12902,15 @@ var Polygon = /** @class */ (function (_super) {
13561
12902
  if (_a === void 0) { _a = {}; }
13562
12903
  var _this = this;
13563
12904
  var style = _a.style, rest = __rest(_a, ["style"]);
13564
- _this = _super.call(this, __assign({ type: Shape.POLYGON, style: runtime.enableCSSParsing
13565
- ? __assign({ points: '', miterLimit: '', isClosed: true }, style) : __assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13566
- ? null
13567
- : {
13568
- points: {
13569
- points: [],
13570
- totalLength: 0,
13571
- segments: [],
13572
- },
13573
- miterLimit: 4,
13574
- isClosed: true,
13575
- } }, rest)) || this;
12905
+ _this = _super.call(this, __assign({ type: Shape.POLYGON, style: style, initialParsedStyle: {
12906
+ points: {
12907
+ points: [],
12908
+ totalLength: 0,
12909
+ segments: [],
12910
+ },
12911
+ miterLimit: 4,
12912
+ isClosed: true,
12913
+ } }, rest)) || this;
13576
12914
  _this.markerStartAngle = 0;
13577
12915
  _this.markerEndAngle = 0;
13578
12916
  /**
@@ -13707,18 +13045,15 @@ var Polyline = /** @class */ (function (_super) {
13707
13045
  function Polyline(_a) {
13708
13046
  if (_a === void 0) { _a = {}; }
13709
13047
  var style = _a.style, rest = __rest(_a, ["style"]);
13710
- return _super.call(this, __assign({ type: Shape.POLYLINE, style: runtime.enableCSSParsing
13711
- ? __assign({ points: '', miterLimit: '', isClosed: false }, style) : __assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13712
- ? null
13713
- : {
13714
- points: {
13715
- points: [],
13716
- totalLength: 0,
13717
- segments: [],
13718
- },
13719
- miterLimit: 4,
13720
- isClosed: false,
13721
- } }, rest)) || this;
13048
+ return _super.call(this, __assign({ type: Shape.POLYLINE, style: style, initialParsedStyle: {
13049
+ points: {
13050
+ points: [],
13051
+ totalLength: 0,
13052
+ segments: [],
13053
+ },
13054
+ miterLimit: 4,
13055
+ isClosed: false,
13056
+ } }, rest)) || this;
13722
13057
  }
13723
13058
  Polyline.prototype.getTotalLength = function () {
13724
13059
  return getOrCalculatePolylineTotalLength(this);
@@ -13802,16 +13137,8 @@ var Text = /** @class */ (function (_super) {
13802
13137
  function Text(_a) {
13803
13138
  if (_a === void 0) { _a = {}; }
13804
13139
  var style = _a.style, rest = __rest(_a, ["style"]);
13805
- return _super.call(this, __assign({ type: Shape.TEXT, style: runtime.enableCSSParsing
13806
- ? __assign({ x: '', y: '', text: '', fontSize: '', fontFamily: '', fontStyle: '', fontWeight: '', fontVariant: '', textAlign: '', textBaseline: '', textTransform: '', fill: 'black', letterSpacing: '', lineHeight: '', miterLimit: '',
13807
- // whiteSpace: 'pre',
13808
- wordWrap: false, wordWrapWidth: 0, leading: 0, dx: '', dy: '' }, style) : __assign({ fill: 'black' }, style) }, rest)) || this;
13809
- }
13810
- // lengthAdjust: SVGAnimatedEnumeration;
13811
- // textLength: SVGAnimatedLength;
13812
- // getCharNumAtPosition(point?: DOMPointInit): number {
13813
- // throw new Error('Method not implemented.');
13814
- // }
13140
+ return _super.call(this, __assign({ type: Shape.TEXT, style: __assign({ fill: 'black' }, style) }, rest)) || this;
13141
+ }
13815
13142
  /**
13816
13143
  * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
13817
13144
  */
@@ -13820,27 +13147,6 @@ var Text = /** @class */ (function (_super) {
13820
13147
  this.getGeometryBounds();
13821
13148
  return ((_a = this.parsedStyle.metrics) === null || _a === void 0 ? void 0 : _a.maxLineWidth) || 0;
13822
13149
  };
13823
- // getEndPositionOfChar(charnum: number): DOMPoint {
13824
- // throw new Error('Method not implemented.');
13825
- // }
13826
- // getExtentOfChar(charnum: number): DOMRect {
13827
- // throw new Error('Method not implemented.');
13828
- // }
13829
- // getNumberOfChars(): number {
13830
- // throw new Error('Method not implemented.');
13831
- // }
13832
- // getRotationOfChar(charnum: number): number {
13833
- // throw new Error('Method not implemented.');
13834
- // }
13835
- // getStartPositionOfChar(charnum: number): DOMPoint {
13836
- // throw new Error('Method not implemented.');
13837
- // }
13838
- // getSubStringLength(charnum: number, nchars: number): number {
13839
- // throw new Error('Method not implemented.');
13840
- // }
13841
- // selectSubString(charnum: number, nchars: number): void {
13842
- // throw new Error('Method not implemented.');
13843
- // }
13844
13150
  Text.prototype.getLineBoundingRects = function () {
13845
13151
  var _a;
13846
13152
  this.getGeometryBounds();
@@ -14795,10 +14101,7 @@ var FrustumCullingStrategy = /** @class */ (function () {
14795
14101
 
14796
14102
  var PrepareRendererPlugin = /** @class */ (function () {
14797
14103
  function PrepareRendererPlugin() {
14798
- /**
14799
- * sync to RBush later
14800
- */
14801
- this.toSync = new Set();
14104
+ this.syncTasks = new Map();
14802
14105
  this.isFirstTimeRendering = true;
14803
14106
  this.syncing = false;
14804
14107
  this.isFirstTimeRenderingFinished = false;
@@ -14815,21 +14118,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14815
14118
  renderingService.dirtify();
14816
14119
  };
14817
14120
  var handleBoundsChanged = function (e) {
14818
- var affectChildren = e.detail.affectChildren;
14819
- var object = e.target;
14820
- if (affectChildren) {
14821
- object.forEach(function (node) {
14822
- _this.toSync.add(node);
14823
- });
14824
- }
14825
- var p = object;
14826
- while (p) {
14827
- if (p.renderable) {
14828
- _this.toSync.add(p);
14829
- }
14830
- p = p.parentElement;
14831
- }
14832
- // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
14121
+ _this.syncTasks.set(e.target, e.detail.affectChildren);
14833
14122
  renderingService.dirtify();
14834
14123
  };
14835
14124
  var handleMounted = function (e) {
@@ -14837,12 +14126,6 @@ var PrepareRendererPlugin = /** @class */ (function () {
14837
14126
  if (runtime.enableSizeAttenuation) {
14838
14127
  runtime.styleValueRegistry.updateSizeAttenuation(object, canvas.getCamera().getZoom());
14839
14128
  }
14840
- if (runtime.enableCSSParsing) {
14841
- // recalc style values
14842
- runtime.styleValueRegistry.recalc(object);
14843
- }
14844
- runtime.sceneGraphService.dirtifyToRoot(object);
14845
- renderingService.dirtify();
14846
14129
  };
14847
14130
  var handleUnmounted = function (e) {
14848
14131
  var object = e.target;
@@ -14850,7 +14133,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14850
14133
  if (rBushNode.aabb) {
14851
14134
  _this.rBush.remove(rBushNode.aabb);
14852
14135
  }
14853
- _this.toSync.delete(object);
14136
+ _this.syncTasks.delete(object);
14854
14137
  runtime.sceneGraphService.dirtifyToRoot(object);
14855
14138
  renderingService.dirtify();
14856
14139
  };
@@ -14865,7 +14148,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14865
14148
  canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
14866
14149
  canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14867
14150
  canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14868
- _this.toSync.clear();
14151
+ _this.syncTasks.clear();
14869
14152
  });
14870
14153
  var ric = (_a = runtime.globalThis.requestIdleCallback) !== null && _a !== void 0 ? _a : raf.bind(runtime.globalThis);
14871
14154
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
@@ -14882,60 +14165,78 @@ var PrepareRendererPlugin = /** @class */ (function () {
14882
14165
  }
14883
14166
  });
14884
14167
  };
14168
+ PrepareRendererPlugin.prototype.syncNode = function (node, force) {
14169
+ if (force === void 0) { force = false; }
14170
+ if (!node.isConnected)
14171
+ return;
14172
+ var rBushNode = node.rBushNode;
14173
+ // clear dirty node
14174
+ if (rBushNode.aabb)
14175
+ this.rBush.remove(rBushNode.aabb);
14176
+ var renderBounds = node.getRenderBounds();
14177
+ if (renderBounds) {
14178
+ var renderable = node.renderable;
14179
+ if (force) {
14180
+ if (!renderable.dirtyRenderBounds) {
14181
+ renderable.dirtyRenderBounds = new AABB();
14182
+ }
14183
+ // save last dirty aabb
14184
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14185
+ }
14186
+ var _a = __read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14187
+ var _b = __read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14188
+ if (!rBushNode.aabb) {
14189
+ rBushNode.aabb = {};
14190
+ }
14191
+ rBushNode.aabb.displayObject = node;
14192
+ rBushNode.aabb.minX = minX;
14193
+ rBushNode.aabb.minY = minY;
14194
+ rBushNode.aabb.maxX = maxX;
14195
+ rBushNode.aabb.maxY = maxY;
14196
+ }
14197
+ if (rBushNode.aabb) {
14198
+ // TODO: NaN occurs when width/height of Rect is 0
14199
+ if (!isNaN(rBushNode.aabb.maxX) &&
14200
+ !isNaN(rBushNode.aabb.maxX) &&
14201
+ !isNaN(rBushNode.aabb.minX) &&
14202
+ !isNaN(rBushNode.aabb.minY)) {
14203
+ return rBushNode.aabb;
14204
+ }
14205
+ }
14206
+ };
14885
14207
  PrepareRendererPlugin.prototype.syncRTree = function (force) {
14886
14208
  var _this = this;
14887
14209
  if (force === void 0) { force = false; }
14888
- if (!force && (this.syncing || this.toSync.size === 0)) {
14210
+ if (!force && (this.syncing || this.syncTasks.size === 0)) {
14889
14211
  return;
14890
14212
  }
14891
14213
  this.syncing = true;
14892
14214
  // bounds changed, need re-inserting its children
14893
14215
  var bulk = [];
14894
- Array.from(this.toSync)
14895
- // some objects may be removed since last frame
14896
- .filter(function (object) { return object.isConnected; })
14897
- .forEach(function (node) {
14898
- var rBushNode = node.rBushNode;
14899
- // clear dirty node
14900
- if (rBushNode && rBushNode.aabb) {
14901
- _this.rBush.remove(rBushNode.aabb);
14902
- }
14903
- var renderBounds = node.getRenderBounds();
14904
- if (renderBounds) {
14905
- var renderable = node.renderable;
14906
- if (force) {
14907
- if (!renderable.dirtyRenderBounds) {
14908
- renderable.dirtyRenderBounds = new AABB();
14909
- }
14910
- // save last dirty aabb
14911
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14912
- }
14913
- var _a = __read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14914
- var _b = __read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14915
- if (!rBushNode.aabb) {
14916
- rBushNode.aabb = {};
14216
+ var synced = new Set();
14217
+ var sync = function (node) {
14218
+ if (!synced.has(node) && node.renderable) {
14219
+ var aabb = _this.syncNode(node, force);
14220
+ if (aabb) {
14221
+ bulk.push(aabb);
14222
+ synced.add(node);
14917
14223
  }
14918
- rBushNode.aabb.displayObject = node;
14919
- rBushNode.aabb.minX = minX;
14920
- rBushNode.aabb.minY = minY;
14921
- rBushNode.aabb.maxX = maxX;
14922
- rBushNode.aabb.maxY = maxY;
14923
14224
  }
14924
- if (rBushNode.aabb) {
14925
- // TODO: NaN occurs when width/height of Rect is 0
14926
- if (!isNaN(rBushNode.aabb.maxX) &&
14927
- !isNaN(rBushNode.aabb.maxX) &&
14928
- !isNaN(rBushNode.aabb.minX) &&
14929
- !isNaN(rBushNode.aabb.minY)) {
14930
- bulk.push(rBushNode.aabb);
14931
- }
14225
+ };
14226
+ this.syncTasks.forEach(function (affectChildren, node) {
14227
+ if (affectChildren) {
14228
+ node.forEach(sync);
14229
+ }
14230
+ var parent = node;
14231
+ while (parent) {
14232
+ sync(parent);
14233
+ parent = parent.parentElement;
14932
14234
  }
14933
14235
  });
14934
14236
  // use bulk inserting, which is ~2-3 times faster
14935
14237
  // @see https://github.com/mourner/rbush#bulk-inserting-data
14936
14238
  this.rBush.load(bulk);
14937
14239
  bulk.length = 0;
14938
- this.toSync.clear();
14939
14240
  this.syncing = false;
14940
14241
  };
14941
14242
  PrepareRendererPlugin.tag = 'Prepare';
@@ -14991,9 +14292,9 @@ var Canvas = /** @class */ (function (_super) {
14991
14292
  _this.document.defaultView = _this;
14992
14293
  // create registry of custom elements
14993
14294
  _this.customElements = new CustomElementRegistry();
14994
- var container = config.container, canvas = config.canvas, offscreenCanvas = config.offscreenCanvas, width = config.width, height = config.height, devicePixelRatio = config.devicePixelRatio, renderer = config.renderer, background = config.background, cursor = config.cursor, document = config.document, requestAnimationFrame = config.requestAnimationFrame, cancelAnimationFrame = config.cancelAnimationFrame, createImage = config.createImage, supportsPointerEvents = config.supportsPointerEvents, supportsTouchEvents = config.supportsTouchEvents, supportsCSSTransform = config.supportsCSSTransform, supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer, useNativeClickEvent = config.useNativeClickEvent, alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas, isTouchEvent = config.isTouchEvent, isMouseEvent = config.isMouseEvent, dblClickSpeed = config.dblClickSpeed;
14295
+ var container = config.container, canvas = config.canvas, offscreenCanvas = config.offscreenCanvas, width = config.width, height = config.height, devicePixelRatio = config.devicePixelRatio, renderer = config.renderer, background = config.background, cursor = config.cursor, document = config.document, requestAnimationFrame = config.requestAnimationFrame, cancelAnimationFrame = config.cancelAnimationFrame, createImage = config.createImage, supportsPointerEvents = config.supportsPointerEvents, supportsTouchEvents = config.supportsTouchEvents, supportsCSSTransform = config.supportsCSSTransform, _a = config.cleanUpOnDestroy, cleanUpOnDestroy = _a === void 0 ? true : _a, supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer, useNativeClickEvent = config.useNativeClickEvent, alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas, isTouchEvent = config.isTouchEvent, isMouseEvent = config.isMouseEvent, dblClickSpeed = config.dblClickSpeed;
14995
14296
  if (!supportsMutipleCanvasesInOneContainer) {
14996
- cleanExistedCanvas(container, _this);
14297
+ cleanExistedCanvas(container, _this, cleanUpOnDestroy);
14997
14298
  }
14998
14299
  var canvasWidth = width;
14999
14300
  var canvasHeight = height;
@@ -15054,6 +14355,7 @@ var Canvas = /** @class */ (function (_super) {
15054
14355
  document: document,
15055
14356
  supportsCSSTransform: supportsCSSTransform,
15056
14357
  useNativeClickEvent: useNativeClickEvent,
14358
+ cleanUpOnDestroy: cleanUpOnDestroy,
15057
14359
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas,
15058
14360
  });
15059
14361
  _this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
@@ -15164,7 +14466,8 @@ var Canvas = /** @class */ (function (_super) {
15164
14466
  */
15165
14467
  Canvas.prototype.destroy = function (cleanUp, skipTriggerEvent) {
15166
14468
  if (cleanUp === void 0) { cleanUp = true; }
15167
- if (skipTriggerEvent === void 0) { skipTriggerEvent = false; }
14469
+ if (skipTriggerEvent === undefined)
14470
+ skipTriggerEvent = this.getConfig().fastCleanExistingCanvas;
15168
14471
  if (!skipTriggerEvent) {
15169
14472
  this.dispatchEvent(new CustomEvent(CanvasEvent.BEFORE_DESTROY));
15170
14473
  }
@@ -15193,6 +14496,17 @@ var Canvas = /** @class */ (function (_super) {
15193
14496
  if (!skipTriggerEvent) {
15194
14497
  this.dispatchEvent(new CustomEvent(CanvasEvent.AFTER_DESTROY));
15195
14498
  }
14499
+ var clearEventRetain = function (event) {
14500
+ event.currentTarget = null;
14501
+ event.manager = null;
14502
+ event.target = null;
14503
+ };
14504
+ clearEventRetain(mountedEvent);
14505
+ clearEventRetain(unmountedEvent);
14506
+ clearEventRetain(beforeRenderEvent);
14507
+ clearEventRetain(rerenderEvent);
14508
+ clearEventRetain(afterRenderEvent);
14509
+ this.cancelAnimationFrame(this.frameId);
15196
14510
  };
15197
14511
  /**
15198
14512
  * compatible with G 3.0
@@ -15400,35 +14714,41 @@ var Canvas = /** @class */ (function (_super) {
15400
14714
  }
15401
14715
  }
15402
14716
  };
15403
- Canvas.prototype.mountChildren = function (parent) {
14717
+ Canvas.prototype.mountChildren = function (child, skipTriggerEvent) {
15404
14718
  var _this = this;
14719
+ if (skipTriggerEvent === void 0) { skipTriggerEvent = isInFragment(child); }
15405
14720
  if (this.inited) {
15406
- if (!parent.isConnected) {
15407
- parent.ownerDocument = this.document;
15408
- parent.isConnected = true;
15409
- if (parent.isMutationObserved) {
15410
- parent.dispatchEvent(mountedEvent);
15411
- }
15412
- else {
15413
- mountedEvent.target = parent;
15414
- this.dispatchEvent(mountedEvent, true);
14721
+ if (!child.isConnected) {
14722
+ child.ownerDocument = this.document;
14723
+ child.isConnected = true;
14724
+ if (!skipTriggerEvent) {
14725
+ if (child.isMutationObserved) {
14726
+ child.dispatchEvent(mountedEvent);
14727
+ }
14728
+ else {
14729
+ mountedEvent.target = child;
14730
+ this.dispatchEvent(mountedEvent, true);
14731
+ }
15415
14732
  }
15416
14733
  }
15417
14734
  }
15418
14735
  else {
15419
- console.warn("[g]: You are trying to call `canvas.appendChild` before canvas' initialization finished. You can either await `canvas.ready` or listen to `CanvasEvent.READY` manually.", 'appended child: ', parent.nodeName);
14736
+ console.warn("[g]: You are trying to call `canvas.appendChild` before canvas' initialization finished. You can either await `canvas.ready` or listen to `CanvasEvent.READY` manually.", 'appended child: ', child.nodeName);
15420
14737
  }
15421
14738
  // recursively mount children
15422
- parent.childNodes.forEach(function (child) {
15423
- _this.mountChildren(child);
14739
+ child.childNodes.forEach(function (c) {
14740
+ _this.mountChildren(c, skipTriggerEvent);
15424
14741
  });
15425
14742
  // trigger after mounted
15426
- if (parent.isCustomElement) {
15427
- if (parent.connectedCallback) {
15428
- parent.connectedCallback();
14743
+ if (child.isCustomElement) {
14744
+ if (child.connectedCallback) {
14745
+ child.connectedCallback();
15429
14746
  }
15430
14747
  }
15431
14748
  };
14749
+ Canvas.prototype.mountFragment = function (child) {
14750
+ this.mountChildren(child, false);
14751
+ };
15432
14752
  Canvas.prototype.client2Viewport = function (client) {
15433
14753
  return this.getEventService().client2Viewport(client);
15434
14754
  };
@@ -15458,5 +14778,5 @@ var Canvas = /** @class */ (function (_super) {
15458
14778
  return Canvas;
15459
14779
  }(EventTarget));
15460
14780
 
15461
- export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GradientType, Group, GroupUpdater, HTML, HTMLUpdater, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBush, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };
14781
+ export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Fragment, Frustum, GradientType, Group, GroupUpdater, HTML, HTMLUpdater, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBush, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };
15462
14782
  //# sourceMappingURL=index.esm.js.map