@antv/g-lite 2.0.11 → 2.1.0-alpha.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 +1400 -2083
  33. package/dist/index.esm.js.map +1 -1
  34. package/dist/index.js +1517 -2199
  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.js CHANGED
@@ -609,6 +609,7 @@ var RBush = rbush.exports;
609
609
  exports.Shape = void 0;
610
610
  (function (Shape) {
611
611
  Shape["GROUP"] = "g";
612
+ Shape["FRAGMENT"] = "fragment";
612
613
  Shape["CIRCLE"] = "circle";
613
614
  Shape["ELLIPSE"] = "ellipse";
614
615
  Shape["IMAGE"] = "image";
@@ -691,366 +692,7 @@ var AbstractRenderer = /** @class */ (function () {
691
692
  return AbstractRenderer;
692
693
  }());
693
694
 
694
- function copyVec3(a, b) {
695
- a[0] = b[0];
696
- a[1] = b[1];
697
- a[2] = b[2];
698
- return a;
699
- }
700
- function subVec3(o, a, b) {
701
- o[0] = a[0] - b[0];
702
- o[1] = a[1] - b[1];
703
- o[2] = a[2] - b[2];
704
- return o;
705
- }
706
- function addVec3(o, a, b) {
707
- o[0] = a[0] + b[0];
708
- o[1] = a[1] + b[1];
709
- o[2] = a[2] + b[2];
710
- return o;
711
- }
712
- function scaleVec3(o, a, b) {
713
- o[0] = a[0] * b;
714
- o[1] = a[1] * b;
715
- o[2] = a[2] * b;
716
- return o;
717
- }
718
- function maxVec3(o, a, b) {
719
- o[0] = Math.max(a[0], b[0]);
720
- o[1] = Math.max(a[1], b[1]);
721
- o[2] = Math.max(a[2], b[2]);
722
- return o;
723
- }
724
- function minVec3(o, a, b) {
725
- o[0] = Math.min(a[0], b[0]);
726
- o[1] = Math.min(a[1], b[1]);
727
- o[2] = Math.min(a[2], b[2]);
728
- return o;
729
- }
730
- function getAngle(angle) {
731
- if (angle === undefined) {
732
- return 0;
733
- }
734
- else if (angle > 360 || angle < -360) {
735
- return angle % 360;
736
- }
737
- return angle;
738
- }
739
- function createVec3(x, y, z) {
740
- if (y === void 0) { y = 0; }
741
- if (z === void 0) { z = 0; }
742
- if (Array.isArray(x) && x.length === 3) {
743
- return glMatrix.vec3.clone(x);
744
- }
745
- if (util.isNumber(x)) {
746
- return glMatrix.vec3.fromValues(x, y, z);
747
- }
748
- return glMatrix.vec3.fromValues(x[0], x[1] || y, x[2] || z);
749
- }
750
- function deg2rad(deg) {
751
- return deg * (Math.PI / 180);
752
- }
753
- function rad2deg(rad) {
754
- return rad * (180 / Math.PI);
755
- }
756
- function grad2deg(grads) {
757
- grads = grads % 400;
758
- if (grads < 0) {
759
- grads += 400;
760
- }
761
- return (grads / 400) * 360;
762
- }
763
- function deg2turn(deg) {
764
- return deg / 360;
765
- }
766
- function turn2deg(turn) {
767
- return 360 * turn;
768
- }
769
- function getEulerFromQuat(out, quat) {
770
- var x = quat[0];
771
- var y = quat[1];
772
- var z = quat[2];
773
- var w = quat[3];
774
- var x2 = x * x;
775
- var y2 = y * y;
776
- var z2 = z * z;
777
- var w2 = w * w;
778
- var unit = x2 + y2 + z2 + w2;
779
- var test = x * w - y * z;
780
- if (test > 0.499995 * unit) {
781
- // TODO: Use glmatrix.EPSILON
782
- // singularity at the north pole
783
- out[0] = Math.PI / 2;
784
- out[1] = 2 * Math.atan2(y, x);
785
- out[2] = 0;
786
- }
787
- else if (test < -0.499995 * unit) {
788
- //TODO: Use glmatrix.EPSILON
789
- // singularity at the south pole
790
- out[0] = -Math.PI / 2;
791
- out[1] = 2 * Math.atan2(y, x);
792
- out[2] = 0;
793
- }
794
- else {
795
- out[0] = Math.asin(2 * (x * z - w * y));
796
- out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
797
- out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
798
- }
799
- // TODO: Return them as degrees and not as radians
800
- return out;
801
- }
802
- function getEulerFromMat4(out, m) {
803
- var x;
804
- var z;
805
- var halfPi = Math.PI * 0.5;
806
- var _a = tslib.__read(glMatrix.mat4.getScaling(glMatrix.vec3.create(), m), 3), sx = _a[0], sy = _a[1], sz = _a[2];
807
- var y = Math.asin(-m[2] / sx);
808
- if (y < halfPi) {
809
- if (y > -halfPi) {
810
- x = Math.atan2(m[6] / sy, m[10] / sz);
811
- z = Math.atan2(m[1] / sx, m[0] / sx);
812
- }
813
- else {
814
- // Not a unique solution
815
- z = 0;
816
- x = -Math.atan2(m[4] / sy, m[5] / sy);
817
- }
818
- }
819
- else {
820
- // Not a unique solution
821
- z = 0;
822
- x = Math.atan2(m[4] / sy, m[5] / sy);
823
- }
824
- out[0] = x;
825
- out[1] = y;
826
- out[2] = z;
827
- return out;
828
- }
829
- /**
830
- * @see https://github.com/toji/gl-matrix/issues/329
831
- * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
832
- */
833
- function getEuler(out, quat) {
834
- if (quat.length === 16) {
835
- return getEulerFromMat4(out, quat);
836
- }
837
- else {
838
- return getEulerFromQuat(out, quat);
839
- }
840
- }
841
- function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
842
- var cos = Math.cos(rotation);
843
- var sin = Math.sin(rotation);
844
- return glMatrix.mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
845
- }
846
- function makePerspective(out, left, right, top, bottom, near, far, zero) {
847
- if (zero === void 0) { zero = false; }
848
- var x = (2 * near) / (right - left);
849
- var y = (2 * near) / (top - bottom);
850
- var a = (right + left) / (right - left);
851
- var b = (top + bottom) / (top - bottom);
852
- var c;
853
- var d;
854
- if (zero) {
855
- c = -far / (far - near);
856
- d = (-far * near) / (far - near);
857
- }
858
- else {
859
- c = -(far + near) / (far - near);
860
- d = (-2 * far * near) / (far - near);
861
- }
862
- out[0] = x;
863
- out[1] = 0;
864
- out[2] = 0;
865
- out[3] = 0;
866
- out[4] = 0;
867
- out[5] = y;
868
- out[6] = 0;
869
- out[7] = 0;
870
- out[8] = a;
871
- out[9] = b;
872
- out[10] = c;
873
- out[11] = -1;
874
- out[12] = 0;
875
- out[13] = 0;
876
- out[14] = d;
877
- out[15] = 0;
878
- return out;
879
- }
880
- function decompose(mat) {
881
- var row0x = mat[0];
882
- var row0y = mat[1];
883
- var row1x = mat[3];
884
- var row1y = mat[4];
885
- // decompose 3x3 matrix
886
- // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
887
- var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
888
- var scalingY = Math.sqrt(row1x * row1x + row1y * row1y);
889
- // If determinant is negative, one axis was flipped.
890
- var determinant = row0x * row1y - row0y * row1x;
891
- if (determinant < 0) {
892
- // Flip axis with minimum unit vector dot product.
893
- if (row0x < row1y) {
894
- scalingX = -scalingX;
895
- }
896
- else {
897
- scalingY = -scalingY;
898
- }
899
- }
900
- // Renormalize matrix to remove scale.
901
- if (scalingX) {
902
- row0x *= 1 / scalingX;
903
- row0y *= 1 / scalingX;
904
- }
905
- if (scalingY) {
906
- row1x *= 1 / scalingY;
907
- row1y *= 1 / scalingY;
908
- }
909
- // Compute rotation and renormalize matrix.
910
- var rotation = Math.atan2(row0y, row0x);
911
- var angle = rad2deg(rotation);
912
- return [mat[6], mat[7], scalingX, scalingY, angle];
913
- }
914
- var tmp = glMatrix.mat4.create();
915
- var perspectiveMatrix = glMatrix.mat4.create();
916
- var tmpVec4 = glMatrix.vec4.create();
917
- var row = [glMatrix.vec3.create(), glMatrix.vec3.create(), glMatrix.vec3.create()];
918
- var pdum3 = glMatrix.vec3.create();
919
- /*
920
- Input: matrix ; a 4x4 matrix
921
- Output: translation ; a 3 component vector
922
- scale ; a 3 component vector
923
- skew ; skew factors XY,XZ,YZ represented as a 3 component vector
924
- perspective ; a 4 component vector
925
- quaternion ; a 4 component vector
926
- Returns false if the matrix cannot be decomposed, true if it can
927
-
928
-
929
- References:
930
- https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
931
- https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
932
- http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
933
- */
934
- function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
935
- //normalize, if not possible then bail out early
936
- if (!normalize(tmp, matrix))
937
- return false;
938
- // perspectiveMatrix is used to solve for perspective, but it also provides
939
- // an easy way to test for singularity of the upper 3x3 component.
940
- glMatrix.mat4.copy(perspectiveMatrix, tmp);
941
- perspectiveMatrix[3] = 0;
942
- perspectiveMatrix[7] = 0;
943
- perspectiveMatrix[11] = 0;
944
- perspectiveMatrix[15] = 1;
945
- // If the perspectiveMatrix is not invertible, we are also unable to
946
- // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
947
- if (Math.abs(glMatrix.mat4.determinant(perspectiveMatrix)) < 1e-8)
948
- return false;
949
- var a03 = tmp[3], a13 = tmp[7], a23 = tmp[11], a30 = tmp[12], a31 = tmp[13], a32 = tmp[14], a33 = tmp[15];
950
- // First, isolate perspective.
951
- if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
952
- tmpVec4[0] = a03;
953
- tmpVec4[1] = a13;
954
- tmpVec4[2] = a23;
955
- tmpVec4[3] = a33;
956
- // Solve the equation by inverting perspectiveMatrix and multiplying
957
- // rightHandSide by the inverse.
958
- // resuing the perspectiveMatrix here since it's no longer needed
959
- var ret = glMatrix.mat4.invert(perspectiveMatrix, perspectiveMatrix);
960
- if (!ret)
961
- return false;
962
- glMatrix.mat4.transpose(perspectiveMatrix, perspectiveMatrix);
963
- //multiply by transposed inverse perspective matrix, into perspective vec4
964
- glMatrix.vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
965
- }
966
- else {
967
- //no perspective
968
- perspective[0] = perspective[1] = perspective[2] = 0;
969
- perspective[3] = 1;
970
- }
971
- // Next take care of translation
972
- translation[0] = a30;
973
- translation[1] = a31;
974
- translation[2] = a32;
975
- // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
976
- mat3from4(row, tmp);
977
- // Compute X scale factor and normalize first row.
978
- scale[0] = glMatrix.vec3.length(row[0]);
979
- glMatrix.vec3.normalize(row[0], row[0]);
980
- // Compute XY shear factor and make 2nd row orthogonal to 1st.
981
- skew[0] = glMatrix.vec3.dot(row[0], row[1]);
982
- combine(row[1], row[1], row[0], 1.0, -skew[0]);
983
- // Now, compute Y scale and normalize 2nd row.
984
- scale[1] = glMatrix.vec3.length(row[1]);
985
- glMatrix.vec3.normalize(row[1], row[1]);
986
- skew[0] /= scale[1];
987
- // Compute XZ and YZ shears, orthogonalize 3rd row
988
- skew[1] = glMatrix.vec3.dot(row[0], row[2]);
989
- combine(row[2], row[2], row[0], 1.0, -skew[1]);
990
- skew[2] = glMatrix.vec3.dot(row[1], row[2]);
991
- combine(row[2], row[2], row[1], 1.0, -skew[2]);
992
- // Next, get Z scale and normalize 3rd row.
993
- scale[2] = glMatrix.vec3.length(row[2]);
994
- glMatrix.vec3.normalize(row[2], row[2]);
995
- skew[1] /= scale[2];
996
- skew[2] /= scale[2];
997
- // At this point, the matrix (in rows) is orthonormal.
998
- // Check for a coordinate system flip. If the determinant
999
- // is -1, then negate the matrix and the scaling factors.
1000
- glMatrix.vec3.cross(pdum3, row[1], row[2]);
1001
- if (glMatrix.vec3.dot(row[0], pdum3) < 0) {
1002
- for (var i = 0; i < 3; i++) {
1003
- scale[i] *= -1;
1004
- row[i][0] *= -1;
1005
- row[i][1] *= -1;
1006
- row[i][2] *= -1;
1007
- }
1008
- }
1009
- // Now, get the rotations out
1010
- quaternion[0] =
1011
- 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
1012
- quaternion[1] =
1013
- 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
1014
- quaternion[2] =
1015
- 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
1016
- quaternion[3] =
1017
- 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
1018
- if (row[2][1] > row[1][2])
1019
- quaternion[0] = -quaternion[0];
1020
- if (row[0][2] > row[2][0])
1021
- quaternion[1] = -quaternion[1];
1022
- if (row[1][0] > row[0][1])
1023
- quaternion[2] = -quaternion[2];
1024
- return true;
1025
- }
1026
- function normalize(out, mat) {
1027
- var m44 = mat[15];
1028
- // Cannot normalize.
1029
- if (m44 === 0)
1030
- return false;
1031
- var scale = 1 / m44;
1032
- for (var i = 0; i < 16; i++)
1033
- out[i] = mat[i] * scale;
1034
- return true;
1035
- }
1036
- //gets upper-left of a 4x4 matrix into a 3x3 of vectors
1037
- function mat3from4(out, mat4x4) {
1038
- out[0][0] = mat4x4[0];
1039
- out[0][1] = mat4x4[1];
1040
- out[0][2] = mat4x4[2];
1041
- out[1][0] = mat4x4[4];
1042
- out[1][1] = mat4x4[5];
1043
- out[1][2] = mat4x4[6];
1044
- out[2][0] = mat4x4[8];
1045
- out[2][1] = mat4x4[9];
1046
- out[2][2] = mat4x4[10];
1047
- }
1048
- function combine(out, a, b, scale1, scale2) {
1049
- out[0] = a[0] * scale1 + b[0] * scale2;
1050
- out[1] = a[1] * scale1 + b[1] * scale2;
1051
- out[2] = a[2] * scale1 + b[2] * scale2;
1052
- }
1053
-
695
+ var addVec3 = glMatrix.vec3.add, copyVec3 = glMatrix.vec3.copy, maxVec3 = glMatrix.vec3.max, minVec3 = glMatrix.vec3.min, scaleVec3 = glMatrix.vec3.scale, subVec3 = glMatrix.vec3.sub;
1054
696
  /**
1055
697
  * Axis-Aligned Bounding Box
1056
698
  * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
@@ -1069,27 +711,13 @@ var AABB = /** @class */ (function () {
1069
711
  aabb.halfExtents[1] === 0 &&
1070
712
  aabb.halfExtents[2] === 0));
1071
713
  };
1072
- // center: vec3 = vec3.create();
1073
- // halfExtents: vec3 = vec3.create();
1074
- // min: vec3 = vec3.create();
1075
- // max: vec3 = vec3.create();
1076
714
  AABB.prototype.update = function (center, halfExtents) {
1077
715
  copyVec3(this.center, center);
1078
716
  copyVec3(this.halfExtents, halfExtents);
1079
717
  subVec3(this.min, this.center, this.halfExtents);
1080
718
  addVec3(this.max, this.center, this.halfExtents);
1081
- // vec3.copy(this.center, center);
1082
- // vec3.copy(this.halfExtents, halfExtents);
1083
- // vec3.sub(this.min, this.center, this.halfExtents);
1084
- // vec3.add(this.max, this.center, this.halfExtents);
1085
719
  };
1086
720
  AABB.prototype.setMinMax = function (min, max) {
1087
- // vec3.add(this.center, max, min);
1088
- // vec3.scale(this.center, this.center, 0.5);
1089
- // vec3.sub(this.halfExtents, max, min);
1090
- // vec3.scale(this.halfExtents, this.halfExtents, 0.5);
1091
- // vec3.copy(this.min, min);
1092
- // vec3.copy(this.max, max);
1093
721
  addVec3(this.center, max, min);
1094
722
  scaleVec3(this.center, this.center, 0.5);
1095
723
  subVec3(this.halfExtents, max, min);
@@ -1233,25 +861,11 @@ var AABB = /** @class */ (function () {
1233
861
  return null;
1234
862
  }
1235
863
  var intersection = new AABB();
1236
- // const min = vec3.max(vec3.create(), this.getMin(), aabb.getMin());
1237
- // const max = vec3.min(vec3.create(), this.getMax(), aabb.getMax());
1238
864
  var min = maxVec3([0, 0, 0], this.getMin(), aabb.getMin());
1239
865
  var max = minVec3([0, 0, 0], this.getMax(), aabb.getMax());
1240
866
  intersection.setMinMax(min, max);
1241
867
  return intersection;
1242
868
  };
1243
- // containsPoint(point: vec3) {
1244
- // const min = this.getMin();
1245
- // const max = this.getMax();
1246
- // return !(
1247
- // point[0] < min[0] ||
1248
- // point[0] > max[0] ||
1249
- // point[1] < min[1] ||
1250
- // point[1] > max[1] ||
1251
- // point[2] < min[2] ||
1252
- // point[2] > max[2]
1253
- // );
1254
- // }
1255
869
  /**
1256
870
  * get n-vertex
1257
871
  * @param plane plane of CullingVolume
@@ -1324,167 +938,505 @@ var AABB = /** @class */ (function () {
1324
938
  // return vec3.fromValues(this.min[0], this.min[1], this.max[2]);
1325
939
  }
1326
940
  else {
1327
- return [this.min[0], this.min[1], this.min[2]];
1328
- // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
941
+ return [this.min[0], this.min[1], this.min[2]];
942
+ // return vec3.fromValues(this.min[0], this.min[1], this.min[2]);
943
+ }
944
+ };
945
+ return AABB;
946
+ }());
947
+
948
+ var Plane = /** @class */ (function () {
949
+ function Plane(distance, normal) {
950
+ this.distance = distance || 0;
951
+ this.normal = normal || glMatrix.vec3.fromValues(0, 1, 0);
952
+ this.updatePNVertexFlag();
953
+ }
954
+ Plane.prototype.updatePNVertexFlag = function () {
955
+ this.pnVertexFlag =
956
+ (Number(this.normal[0] >= 0) << 8) +
957
+ (Number(this.normal[1] >= 0) << 4) +
958
+ Number(this.normal[2] >= 0);
959
+ };
960
+ Plane.prototype.distanceToPoint = function (point) {
961
+ return glMatrix.vec3.dot(point, this.normal) - this.distance;
962
+ };
963
+ Plane.prototype.normalize = function () {
964
+ var invLen = 1 / glMatrix.vec3.len(this.normal);
965
+ glMatrix.vec3.scale(this.normal, this.normal, invLen);
966
+ this.distance *= invLen;
967
+ };
968
+ Plane.prototype.intersectsLine = function (start, end, point) {
969
+ var d0 = this.distanceToPoint(start);
970
+ var d1 = this.distanceToPoint(end);
971
+ var t = d0 / (d0 - d1);
972
+ var intersects = t >= 0 && t <= 1;
973
+ if (intersects && point) {
974
+ glMatrix.vec3.lerp(point, start, end, t);
975
+ }
976
+ return intersects;
977
+ };
978
+ return Plane;
979
+ }());
980
+
981
+ exports.Mask = void 0;
982
+ (function (Mask) {
983
+ Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
984
+ Mask[Mask["INSIDE"] = 0] = "INSIDE";
985
+ Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
986
+ })(exports.Mask || (exports.Mask = {}));
987
+ var Frustum = /** @class */ (function () {
988
+ function Frustum(planes) {
989
+ this.planes = [];
990
+ if (planes) {
991
+ this.planes = planes;
992
+ }
993
+ else {
994
+ for (var i = 0; i < 6; i++) {
995
+ this.planes.push(new Plane());
996
+ }
997
+ }
998
+ }
999
+ /**
1000
+ * extract 6 planes from projectionMatrix
1001
+ * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
1002
+ */
1003
+ Frustum.prototype.extractFromVPMatrix = function (projectionMatrix) {
1004
+ // @ts-ignore
1005
+ var _a = tslib.__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];
1006
+ // right
1007
+ glMatrix.vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
1008
+ this.planes[0].distance = m15 - m12;
1009
+ // left
1010
+ glMatrix.vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
1011
+ this.planes[1].distance = m15 + m12;
1012
+ // bottom
1013
+ glMatrix.vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
1014
+ this.planes[2].distance = m15 + m13;
1015
+ // top
1016
+ glMatrix.vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
1017
+ this.planes[3].distance = m15 - m13;
1018
+ // far
1019
+ glMatrix.vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
1020
+ this.planes[4].distance = m15 - m14;
1021
+ // near
1022
+ glMatrix.vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
1023
+ this.planes[5].distance = m15 + m14;
1024
+ this.planes.forEach(function (plane) {
1025
+ plane.normalize();
1026
+ plane.updatePNVertexFlag();
1027
+ });
1028
+ };
1029
+ return Frustum;
1030
+ }());
1031
+
1032
+ var Point = /** @class */ (function () {
1033
+ function Point(x, y) {
1034
+ if (x === void 0) { x = 0; }
1035
+ if (y === void 0) { y = 0; }
1036
+ this.x = 0;
1037
+ this.y = 0;
1038
+ this.x = x;
1039
+ this.y = y;
1040
+ }
1041
+ Point.prototype.clone = function () {
1042
+ return new Point(this.x, this.y);
1043
+ };
1044
+ Point.prototype.copyFrom = function (p) {
1045
+ this.x = p.x;
1046
+ this.y = p.y;
1047
+ };
1048
+ return Point;
1049
+ }());
1050
+
1051
+ var Rectangle = /** @class */ (function () {
1052
+ function Rectangle(x, y, width, height) {
1053
+ this.x = x;
1054
+ this.y = y;
1055
+ this.width = width;
1056
+ this.height = height;
1057
+ this.left = x;
1058
+ this.right = x + width;
1059
+ this.top = y;
1060
+ this.bottom = y + height;
1061
+ }
1062
+ /**
1063
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect/fromRect_static
1064
+ */
1065
+ Rectangle.fromRect = function (rect) {
1066
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
1067
+ };
1068
+ /**
1069
+ * will return a new rect instance
1070
+ */
1071
+ Rectangle.applyTransform = function (rect, matrix) {
1072
+ var topLeft = glMatrix.vec4.fromValues(rect.x, rect.y, 0, 1);
1073
+ var topRight = glMatrix.vec4.fromValues(rect.x + rect.width, rect.y, 0, 1);
1074
+ var bottomLeft = glMatrix.vec4.fromValues(rect.x, rect.y + rect.height, 0, 1);
1075
+ var bottomRight = glMatrix.vec4.fromValues(rect.x + rect.width, rect.y + rect.height, 0, 1);
1076
+ var transformedTopLeft = glMatrix.vec4.create();
1077
+ var transformedTopRight = glMatrix.vec4.create();
1078
+ var transformedBottomLeft = glMatrix.vec4.create();
1079
+ var transformedBottomRight = glMatrix.vec4.create();
1080
+ glMatrix.vec4.transformMat4(transformedTopLeft, topLeft, matrix);
1081
+ glMatrix.vec4.transformMat4(transformedTopRight, topRight, matrix);
1082
+ glMatrix.vec4.transformMat4(transformedBottomLeft, bottomLeft, matrix);
1083
+ glMatrix.vec4.transformMat4(transformedBottomRight, bottomRight, matrix);
1084
+ var minX = Math.min(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1085
+ var minY = Math.min(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1086
+ var maxX = Math.max(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1087
+ var maxY = Math.max(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1088
+ return Rectangle.fromRect({
1089
+ x: minX,
1090
+ y: minY,
1091
+ width: maxX - minX,
1092
+ height: maxY - minY,
1093
+ });
1094
+ };
1095
+ Rectangle.prototype.toJSON = function () { };
1096
+ return Rectangle;
1097
+ }());
1098
+
1099
+ var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
1100
+ var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
1101
+ var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
1102
+
1103
+ function getAngle(angle) {
1104
+ if (angle === undefined) {
1105
+ return 0;
1106
+ }
1107
+ else if (angle > 360 || angle < -360) {
1108
+ return angle % 360;
1109
+ }
1110
+ return angle;
1111
+ }
1112
+ var $vec3$2 = glMatrix.vec3.create();
1113
+ function createVec3(x, y, z, clone) {
1114
+ if (y === void 0) { y = 0; }
1115
+ if (z === void 0) { z = 0; }
1116
+ if (clone === void 0) { clone = true; }
1117
+ if (Array.isArray(x) && x.length === 3) {
1118
+ return clone ? glMatrix.vec3.clone(x) : glMatrix.vec3.copy($vec3$2, x);
1119
+ }
1120
+ if (util.isNumber(x)) {
1121
+ return clone ? glMatrix.vec3.fromValues(x, y, z) : glMatrix.vec3.set($vec3$2, x, y, z);
1122
+ }
1123
+ return clone
1124
+ ? glMatrix.vec3.fromValues(x[0], x[1] || y, x[2] || z)
1125
+ : glMatrix.vec3.set($vec3$2, x[0], x[1] || y, x[2] || z);
1126
+ }
1127
+ var DEG_RAD = Math.PI / 180;
1128
+ function deg2rad(deg) {
1129
+ return deg * DEG_RAD;
1130
+ }
1131
+ var RAD_DEG = 180 / Math.PI;
1132
+ function rad2deg(rad) {
1133
+ return rad * RAD_DEG;
1134
+ }
1135
+ var GRAD_DEG = 0.9; // 360 / 400;
1136
+ function grad2deg(grads) {
1137
+ grads = grads % 400;
1138
+ if (grads < 0) {
1139
+ grads += 400;
1140
+ }
1141
+ return grads * GRAD_DEG;
1142
+ }
1143
+ function deg2turn(deg) {
1144
+ return deg / 360;
1145
+ }
1146
+ function turn2deg(turn) {
1147
+ return 360 * turn;
1148
+ }
1149
+ var HALF_PI = Math.PI / 2;
1150
+ function getEulerFromQuat(out, quat) {
1151
+ var x = quat[0];
1152
+ var y = quat[1];
1153
+ var z = quat[2];
1154
+ var w = quat[3];
1155
+ var x2 = x * x;
1156
+ var y2 = y * y;
1157
+ var z2 = z * z;
1158
+ var w2 = w * w;
1159
+ var unit = x2 + y2 + z2 + w2;
1160
+ var test = x * w - y * z;
1161
+ if (test > 0.499995 * unit) {
1162
+ // TODO: Use glmatrix.EPSILON
1163
+ // singularity at the north pole
1164
+ out[0] = HALF_PI;
1165
+ out[1] = 2 * Math.atan2(y, x);
1166
+ out[2] = 0;
1167
+ }
1168
+ else if (test < -0.499995 * unit) {
1169
+ //TODO: Use glmatrix.EPSILON
1170
+ // singularity at the south pole
1171
+ out[0] = -HALF_PI;
1172
+ out[1] = 2 * Math.atan2(y, x);
1173
+ out[2] = 0;
1174
+ }
1175
+ else {
1176
+ out[0] = Math.asin(2 * (x * z - w * y));
1177
+ out[1] = Math.atan2(2 * (x * w + y * z), 1 - 2 * (z2 + w2));
1178
+ out[2] = Math.atan2(2 * (x * y + z * w), 1 - 2 * (y2 + z2));
1179
+ }
1180
+ // TODO: Return them as degrees and not as radians
1181
+ return out;
1182
+ }
1183
+ function getEulerFromMat4(out, m) {
1184
+ var x;
1185
+ var z;
1186
+ var _a = tslib.__read(glMatrix.mat4.getScaling(glMatrix.vec3.create(), m), 3), sx = _a[0], sy = _a[1], sz = _a[2];
1187
+ var y = Math.asin(-m[2] / sx);
1188
+ if (y < HALF_PI) {
1189
+ if (y > -HALF_PI) {
1190
+ x = Math.atan2(m[6] / sy, m[10] / sz);
1191
+ z = Math.atan2(m[1] / sx, m[0] / sx);
1192
+ }
1193
+ else {
1194
+ // Not a unique solution
1195
+ z = 0;
1196
+ x = -Math.atan2(m[4] / sy, m[5] / sy);
1329
1197
  }
1330
- };
1331
- return AABB;
1332
- }());
1333
-
1334
- var Plane = /** @class */ (function () {
1335
- function Plane(distance, normal) {
1336
- this.distance = distance || 0;
1337
- this.normal = normal || glMatrix.vec3.fromValues(0, 1, 0);
1338
- this.updatePNVertexFlag();
1339
1198
  }
1340
- Plane.prototype.updatePNVertexFlag = function () {
1341
- this.pnVertexFlag =
1342
- (Number(this.normal[0] >= 0) << 8) +
1343
- (Number(this.normal[1] >= 0) << 4) +
1344
- Number(this.normal[2] >= 0);
1345
- };
1346
- Plane.prototype.distanceToPoint = function (point) {
1347
- return glMatrix.vec3.dot(point, this.normal) - this.distance;
1348
- };
1349
- Plane.prototype.normalize = function () {
1350
- var invLen = 1 / glMatrix.vec3.len(this.normal);
1351
- glMatrix.vec3.scale(this.normal, this.normal, invLen);
1352
- this.distance *= invLen;
1353
- };
1354
- Plane.prototype.intersectsLine = function (start, end, point) {
1355
- var d0 = this.distanceToPoint(start);
1356
- var d1 = this.distanceToPoint(end);
1357
- var t = d0 / (d0 - d1);
1358
- var intersects = t >= 0 && t <= 1;
1359
- if (intersects && point) {
1360
- glMatrix.vec3.lerp(point, start, end, t);
1361
- }
1362
- return intersects;
1363
- };
1364
- return Plane;
1365
- }());
1366
-
1367
- exports.Mask = void 0;
1368
- (function (Mask) {
1369
- Mask[Mask["OUTSIDE"] = 4294967295] = "OUTSIDE";
1370
- Mask[Mask["INSIDE"] = 0] = "INSIDE";
1371
- Mask[Mask["INDETERMINATE"] = 2147483647] = "INDETERMINATE";
1372
- })(exports.Mask || (exports.Mask = {}));
1373
- var Frustum = /** @class */ (function () {
1374
- function Frustum(planes) {
1375
- this.planes = [];
1376
- if (planes) {
1377
- this.planes = planes;
1199
+ else {
1200
+ // Not a unique solution
1201
+ z = 0;
1202
+ x = Math.atan2(m[4] / sy, m[5] / sy);
1203
+ }
1204
+ out[0] = x;
1205
+ out[1] = y;
1206
+ out[2] = z;
1207
+ return out;
1208
+ }
1209
+ /**
1210
+ * @see https://github.com/toji/gl-matrix/issues/329
1211
+ * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
1212
+ */
1213
+ function getEuler(out, quat) {
1214
+ if (quat.length === 16) {
1215
+ return getEulerFromMat4(out, quat);
1216
+ }
1217
+ else {
1218
+ return getEulerFromQuat(out, quat);
1219
+ }
1220
+ }
1221
+ function fromRotationTranslationScale(rotation, x, y, scaleX, scaleY) {
1222
+ var cos = Math.cos(rotation);
1223
+ var sin = Math.sin(rotation);
1224
+ return glMatrix.mat3.fromValues(scaleX * cos, scaleY * sin, 0, -scaleX * sin, scaleY * cos, 0, x, y, 1);
1225
+ }
1226
+ function makePerspective(out, left, right, top, bottom, near, far, zero) {
1227
+ if (zero === void 0) { zero = false; }
1228
+ var twoNear = 2 * near;
1229
+ var rightMinusLeft = right - left;
1230
+ var topMinusBottom = top - bottom;
1231
+ var x = twoNear / rightMinusLeft;
1232
+ var y = twoNear / topMinusBottom;
1233
+ var a = (right + left) / rightMinusLeft;
1234
+ var b = (top + bottom) / topMinusBottom;
1235
+ var c;
1236
+ var d;
1237
+ var farMinusNear = far - near;
1238
+ var farMulNear = far * near;
1239
+ if (zero) {
1240
+ c = -far / farMinusNear;
1241
+ d = -farMulNear / farMinusNear;
1242
+ }
1243
+ else {
1244
+ c = -(far + near) / farMinusNear;
1245
+ d = (-2 * farMulNear) / farMinusNear;
1246
+ }
1247
+ out[0] = x;
1248
+ out[1] = 0;
1249
+ out[2] = 0;
1250
+ out[3] = 0;
1251
+ out[4] = 0;
1252
+ out[5] = y;
1253
+ out[6] = 0;
1254
+ out[7] = 0;
1255
+ out[8] = a;
1256
+ out[9] = b;
1257
+ out[10] = c;
1258
+ out[11] = -1;
1259
+ out[12] = 0;
1260
+ out[13] = 0;
1261
+ out[14] = d;
1262
+ out[15] = 0;
1263
+ return out;
1264
+ }
1265
+ function decompose(mat) {
1266
+ var row0x = mat[0];
1267
+ var row0y = mat[1];
1268
+ var row1x = mat[3];
1269
+ var row1y = mat[4];
1270
+ // decompose 3x3 matrix
1271
+ // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
1272
+ var scalingX = Math.sqrt(row0x * row0x + row0y * row0y);
1273
+ var scalingY = Math.sqrt(row1x * row1x + row1y * row1y);
1274
+ // If determinant is negative, one axis was flipped.
1275
+ var determinant = row0x * row1y - row0y * row1x;
1276
+ if (determinant < 0) {
1277
+ // Flip axis with minimum unit vector dot product.
1278
+ if (row0x < row1y) {
1279
+ scalingX = -scalingX;
1378
1280
  }
1379
1281
  else {
1380
- for (var i = 0; i < 6; i++) {
1381
- this.planes.push(new Plane());
1382
- }
1282
+ scalingY = -scalingY;
1383
1283
  }
1384
1284
  }
1385
- /**
1386
- * extract 6 planes from projectionMatrix
1387
- * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
1388
- */
1389
- Frustum.prototype.extractFromVPMatrix = function (projectionMatrix) {
1390
- // @ts-ignore
1391
- var _a = tslib.__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];
1392
- // right
1393
- glMatrix.vec3.set(this.planes[0].normal, m3 - m0, m7 - m4, m11 - m8);
1394
- this.planes[0].distance = m15 - m12;
1395
- // left
1396
- glMatrix.vec3.set(this.planes[1].normal, m3 + m0, m7 + m4, m11 + m8);
1397
- this.planes[1].distance = m15 + m12;
1398
- // bottom
1399
- glMatrix.vec3.set(this.planes[2].normal, m3 + m1, m7 + m5, m11 + m9);
1400
- this.planes[2].distance = m15 + m13;
1401
- // top
1402
- glMatrix.vec3.set(this.planes[3].normal, m3 - m1, m7 - m5, m11 - m9);
1403
- this.planes[3].distance = m15 - m13;
1404
- // far
1405
- glMatrix.vec3.set(this.planes[4].normal, m3 - m2, m7 - m6, m11 - m10);
1406
- this.planes[4].distance = m15 - m14;
1407
- // near
1408
- glMatrix.vec3.set(this.planes[5].normal, m3 + m2, m7 + m6, m11 + m10);
1409
- this.planes[5].distance = m15 + m14;
1410
- this.planes.forEach(function (plane) {
1411
- plane.normalize();
1412
- plane.updatePNVertexFlag();
1413
- });
1414
- };
1415
- return Frustum;
1416
- }());
1417
-
1418
- var Point = /** @class */ (function () {
1419
- function Point(x, y) {
1420
- if (x === void 0) { x = 0; }
1421
- if (y === void 0) { y = 0; }
1422
- this.x = 0;
1423
- this.y = 0;
1424
- this.x = x;
1425
- this.y = y;
1285
+ // Renormalize matrix to remove scale.
1286
+ if (scalingX) {
1287
+ var invScalingX = 1 / scalingX;
1288
+ row0x *= invScalingX;
1289
+ row0y *= invScalingX;
1426
1290
  }
1427
- Point.prototype.clone = function () {
1428
- return new Point(this.x, this.y);
1429
- };
1430
- Point.prototype.copyFrom = function (p) {
1431
- this.x = p.x;
1432
- this.y = p.y;
1433
- };
1434
- return Point;
1435
- }());
1291
+ if (scalingY) {
1292
+ var invScalingY = 1 / scalingY;
1293
+ row1x *= invScalingY;
1294
+ row1y *= invScalingY;
1295
+ }
1296
+ // Compute rotation and renormalize matrix.
1297
+ var rotation = Math.atan2(row0y, row0x);
1298
+ var angle = rad2deg(rotation);
1299
+ return [mat[6], mat[7], scalingX, scalingY, angle];
1300
+ }
1301
+ var tmp = glMatrix.mat4.create();
1302
+ var perspectiveMatrix = glMatrix.mat4.create();
1303
+ var tmpVec4 = glMatrix.vec4.create();
1304
+ var row = [glMatrix.vec3.create(), glMatrix.vec3.create(), glMatrix.vec3.create()];
1305
+ var pdum3 = glMatrix.vec3.create();
1306
+ /*
1307
+ Input: matrix ; a 4x4 matrix
1308
+ Output: translation ; a 3 component vector
1309
+ scale ; a 3 component vector
1310
+ skew ; skew factors XY,XZ,YZ represented as a 3 component vector
1311
+ perspective ; a 4 component vector
1312
+ quaternion ; a 4 component vector
1313
+ Returns false if the matrix cannot be decomposed, true if it can
1436
1314
 
1437
- var Rectangle = /** @class */ (function () {
1438
- function Rectangle(x, y, width, height) {
1439
- this.x = x;
1440
- this.y = y;
1441
- this.width = width;
1442
- this.height = height;
1443
- this.left = x;
1444
- this.right = x + width;
1445
- this.top = y;
1446
- this.bottom = y + height;
1315
+
1316
+ References:
1317
+ https://github.com/kamicane/matrix3d/blob/master/lib/Matrix3d.js
1318
+ https://github.com/ChromiumWebApps/chromium/blob/master/ui/gfx/transform_util.cc
1319
+ http://www.w3.org/TR/css3-transforms/#decomposing-a-3d-matrix
1320
+ */
1321
+ function decomposeMat4(matrix, translation, scale, skew, perspective, quaternion) {
1322
+ //normalize, if not possible then bail out early
1323
+ if (!normalize(tmp, matrix))
1324
+ return false;
1325
+ // perspectiveMatrix is used to solve for perspective, but it also provides
1326
+ // an easy way to test for singularity of the upper 3x3 component.
1327
+ glMatrix.mat4.copy(perspectiveMatrix, tmp);
1328
+ perspectiveMatrix[3] = 0;
1329
+ perspectiveMatrix[7] = 0;
1330
+ perspectiveMatrix[11] = 0;
1331
+ perspectiveMatrix[15] = 1;
1332
+ // If the perspectiveMatrix is not invertible, we are also unable to
1333
+ // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
1334
+ if (Math.abs(glMatrix.mat4.determinant(perspectiveMatrix)) < 1e-8)
1335
+ return false;
1336
+ var a03 = tmp[3], a13 = tmp[7], a23 = tmp[11], a30 = tmp[12], a31 = tmp[13], a32 = tmp[14], a33 = tmp[15];
1337
+ // First, isolate perspective.
1338
+ if (a03 !== 0 || a13 !== 0 || a23 !== 0) {
1339
+ tmpVec4[0] = a03;
1340
+ tmpVec4[1] = a13;
1341
+ tmpVec4[2] = a23;
1342
+ tmpVec4[3] = a33;
1343
+ // Solve the equation by inverting perspectiveMatrix and multiplying
1344
+ // rightHandSide by the inverse.
1345
+ // resuing the perspectiveMatrix here since it's no longer needed
1346
+ var ret = glMatrix.mat4.invert(perspectiveMatrix, perspectiveMatrix);
1347
+ if (!ret)
1348
+ return false;
1349
+ glMatrix.mat4.transpose(perspectiveMatrix, perspectiveMatrix);
1350
+ //multiply by transposed inverse perspective matrix, into perspective vec4
1351
+ glMatrix.vec4.transformMat4(perspective, tmpVec4, perspectiveMatrix);
1352
+ }
1353
+ else {
1354
+ //no perspective
1355
+ perspective[0] = perspective[1] = perspective[2] = 0;
1356
+ perspective[3] = 1;
1357
+ }
1358
+ // Next take care of translation
1359
+ translation[0] = a30;
1360
+ translation[1] = a31;
1361
+ translation[2] = a32;
1362
+ // Now get scale and shear. 'row' is a 3 element array of 3 component vectors
1363
+ mat3from4(row, tmp);
1364
+ // Compute X scale factor and normalize first row.
1365
+ scale[0] = glMatrix.vec3.length(row[0]);
1366
+ glMatrix.vec3.normalize(row[0], row[0]);
1367
+ // Compute XY shear factor and make 2nd row orthogonal to 1st.
1368
+ skew[0] = glMatrix.vec3.dot(row[0], row[1]);
1369
+ combine(row[1], row[1], row[0], 1.0, -skew[0]);
1370
+ // Now, compute Y scale and normalize 2nd row.
1371
+ scale[1] = glMatrix.vec3.length(row[1]);
1372
+ glMatrix.vec3.normalize(row[1], row[1]);
1373
+ skew[0] /= scale[1];
1374
+ // Compute XZ and YZ shears, orthogonalize 3rd row
1375
+ skew[1] = glMatrix.vec3.dot(row[0], row[2]);
1376
+ combine(row[2], row[2], row[0], 1.0, -skew[1]);
1377
+ skew[2] = glMatrix.vec3.dot(row[1], row[2]);
1378
+ combine(row[2], row[2], row[1], 1.0, -skew[2]);
1379
+ // Next, get Z scale and normalize 3rd row.
1380
+ scale[2] = glMatrix.vec3.length(row[2]);
1381
+ glMatrix.vec3.normalize(row[2], row[2]);
1382
+ skew[1] /= scale[2];
1383
+ skew[2] /= scale[2];
1384
+ // At this point, the matrix (in rows) is orthonormal.
1385
+ // Check for a coordinate system flip. If the determinant
1386
+ // is -1, then negate the matrix and the scaling factors.
1387
+ glMatrix.vec3.cross(pdum3, row[1], row[2]);
1388
+ if (glMatrix.vec3.dot(row[0], pdum3) < 0) {
1389
+ for (var i = 0; i < 3; i++) {
1390
+ scale[i] *= -1;
1391
+ row[i][0] *= -1;
1392
+ row[i][1] *= -1;
1393
+ row[i][2] *= -1;
1394
+ }
1447
1395
  }
1448
- /**
1449
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect/fromRect_static
1450
- */
1451
- Rectangle.fromRect = function (rect) {
1452
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
1453
- };
1454
- /**
1455
- * will return a new rect instance
1456
- */
1457
- Rectangle.applyTransform = function (rect, matrix) {
1458
- var topLeft = glMatrix.vec4.fromValues(rect.x, rect.y, 0, 1);
1459
- var topRight = glMatrix.vec4.fromValues(rect.x + rect.width, rect.y, 0, 1);
1460
- var bottomLeft = glMatrix.vec4.fromValues(rect.x, rect.y + rect.height, 0, 1);
1461
- var bottomRight = glMatrix.vec4.fromValues(rect.x + rect.width, rect.y + rect.height, 0, 1);
1462
- var transformedTopLeft = glMatrix.vec4.create();
1463
- var transformedTopRight = glMatrix.vec4.create();
1464
- var transformedBottomLeft = glMatrix.vec4.create();
1465
- var transformedBottomRight = glMatrix.vec4.create();
1466
- glMatrix.vec4.transformMat4(transformedTopLeft, topLeft, matrix);
1467
- glMatrix.vec4.transformMat4(transformedTopRight, topRight, matrix);
1468
- glMatrix.vec4.transformMat4(transformedBottomLeft, bottomLeft, matrix);
1469
- glMatrix.vec4.transformMat4(transformedBottomRight, bottomRight, matrix);
1470
- var minX = Math.min(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1471
- var minY = Math.min(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1472
- var maxX = Math.max(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1473
- var maxY = Math.max(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1474
- return Rectangle.fromRect({
1475
- x: minX,
1476
- y: minY,
1477
- width: maxX - minX,
1478
- height: maxY - minY,
1479
- });
1480
- };
1481
- Rectangle.prototype.toJSON = function () { };
1482
- return Rectangle;
1483
- }());
1484
-
1485
- var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
1486
- var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
1487
- var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
1396
+ // Now, get the rotations out
1397
+ quaternion[0] =
1398
+ 0.5 * Math.sqrt(Math.max(1 + row[0][0] - row[1][1] - row[2][2], 0));
1399
+ quaternion[1] =
1400
+ 0.5 * Math.sqrt(Math.max(1 - row[0][0] + row[1][1] - row[2][2], 0));
1401
+ quaternion[2] =
1402
+ 0.5 * Math.sqrt(Math.max(1 - row[0][0] - row[1][1] + row[2][2], 0));
1403
+ quaternion[3] =
1404
+ 0.5 * Math.sqrt(Math.max(1 + row[0][0] + row[1][1] + row[2][2], 0));
1405
+ if (row[2][1] > row[1][2])
1406
+ quaternion[0] = -quaternion[0];
1407
+ if (row[0][2] > row[2][0])
1408
+ quaternion[1] = -quaternion[1];
1409
+ if (row[1][0] > row[0][1])
1410
+ quaternion[2] = -quaternion[2];
1411
+ return true;
1412
+ }
1413
+ function normalize(out, mat) {
1414
+ var m44 = mat[15];
1415
+ // Cannot normalize.
1416
+ if (m44 === 0)
1417
+ return false;
1418
+ var scale = 1 / m44;
1419
+ for (var i = 0; i < 16; i++)
1420
+ out[i] = mat[i] * scale;
1421
+ return true;
1422
+ }
1423
+ //gets upper-left of a 4x4 matrix into a 3x3 of vectors
1424
+ function mat3from4(out, mat4x4) {
1425
+ out[0][0] = mat4x4[0];
1426
+ out[0][1] = mat4x4[1];
1427
+ out[0][2] = mat4x4[2];
1428
+ out[1][0] = mat4x4[4];
1429
+ out[1][1] = mat4x4[5];
1430
+ out[1][2] = mat4x4[6];
1431
+ out[2][0] = mat4x4[8];
1432
+ out[2][1] = mat4x4[9];
1433
+ out[2][2] = mat4x4[10];
1434
+ }
1435
+ function combine(out, a, b, scale1, scale2) {
1436
+ out[0] = a[0] * scale1 + b[0] * scale2;
1437
+ out[1] = a[1] * scale1 + b[1] * scale2;
1438
+ out[2] = a[2] * scale1 + b[2] * scale2;
1439
+ }
1488
1440
 
1489
1441
  /**
1490
1442
  * Different type of cameras, eg. simple camera used in 2D scene or
@@ -2236,6 +2188,99 @@ var Camera = /** @class */ (function () {
2236
2188
  return Camera;
2237
2189
  }());
2238
2190
 
2191
+ /**
2192
+ * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
2193
+ */
2194
+ exports.Strategy = void 0;
2195
+ (function (Strategy) {
2196
+ Strategy[Strategy["Standard"] = 0] = "Standard";
2197
+ })(exports.Strategy || (exports.Strategy = {}));
2198
+
2199
+ exports.SortReason = void 0;
2200
+ (function (SortReason) {
2201
+ SortReason[SortReason["ADDED"] = 0] = "ADDED";
2202
+ SortReason[SortReason["REMOVED"] = 1] = "REMOVED";
2203
+ SortReason[SortReason["Z_INDEX_CHANGED"] = 2] = "Z_INDEX_CHANGED";
2204
+ })(exports.SortReason || (exports.SortReason = {}));
2205
+
2206
+ var EMPTY_PARSED_PATH = {
2207
+ absolutePath: [],
2208
+ hasArc: false,
2209
+ segments: [],
2210
+ polygons: [],
2211
+ polylines: [],
2212
+ curve: null,
2213
+ totalLength: 0,
2214
+ rect: new Rectangle(0, 0, 0, 0),
2215
+ };
2216
+
2217
+ /**
2218
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
2219
+ */
2220
+ exports.PropertySyntax = void 0;
2221
+ (function (PropertySyntax) {
2222
+ /**
2223
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
2224
+ */
2225
+ PropertySyntax["COORDINATE"] = "<coordinate>";
2226
+ /**
2227
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
2228
+ */
2229
+ PropertySyntax["COLOR"] = "<color>";
2230
+ /**
2231
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
2232
+ */
2233
+ PropertySyntax["PAINT"] = "<paint>";
2234
+ /**
2235
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
2236
+ */
2237
+ PropertySyntax["NUMBER"] = "<number>";
2238
+ /**
2239
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle
2240
+ */
2241
+ PropertySyntax["ANGLE"] = "<angle>";
2242
+ /**
2243
+ * <number> with range 0..1
2244
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
2245
+ */
2246
+ PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
2247
+ /**
2248
+ * <number> with range 0..Infinity
2249
+ */
2250
+ PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
2251
+ /**
2252
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
2253
+ */
2254
+ PropertySyntax["LENGTH"] = "<length>";
2255
+ /**
2256
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
2257
+ */
2258
+ PropertySyntax["PERCENTAGE"] = "<percentage>";
2259
+ PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
2260
+ PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
2261
+ /**
2262
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
2263
+ */
2264
+ PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
2265
+ /**
2266
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
2267
+ */
2268
+ PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
2269
+ PropertySyntax["PATH"] = "<path>";
2270
+ /**
2271
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
2272
+ */
2273
+ PropertySyntax["FILTER"] = "<filter>";
2274
+ PropertySyntax["Z_INDEX"] = "<z-index>";
2275
+ PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
2276
+ PropertySyntax["DEFINED_PATH"] = "<defined-path>";
2277
+ PropertySyntax["MARKER"] = "<marker>";
2278
+ PropertySyntax["TRANSFORM"] = "<transform>";
2279
+ PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
2280
+ PropertySyntax["TEXT"] = "<text>";
2281
+ PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
2282
+ })(exports.PropertySyntax || (exports.PropertySyntax = {}));
2283
+
2239
2284
  function memoize(func, resolver) {
2240
2285
  if (typeof func !== 'function' ||
2241
2286
  (resolver != null && typeof resolver !== 'function')) {
@@ -2352,14 +2397,6 @@ var UnitCategory;
2352
2397
  // kUResolution,
2353
2398
  UnitCategory[UnitCategory["kUOther"] = 5] = "kUOther";
2354
2399
  })(UnitCategory || (UnitCategory = {}));
2355
- var ValueRange;
2356
- (function (ValueRange) {
2357
- ValueRange[ValueRange["kAll"] = 0] = "kAll";
2358
- ValueRange[ValueRange["kNonNegative"] = 1] = "kNonNegative";
2359
- ValueRange[ValueRange["kInteger"] = 2] = "kInteger";
2360
- ValueRange[ValueRange["kNonNegativeInteger"] = 3] = "kNonNegativeInteger";
2361
- ValueRange[ValueRange["kPositiveInteger"] = 4] = "kPositiveInteger";
2362
- })(ValueRange || (ValueRange = {}));
2363
2400
  var Nested;
2364
2401
  (function (Nested) {
2365
2402
  Nested[Nested["kYes"] = 0] = "kYes";
@@ -2878,13 +2915,6 @@ var CSSColorValue = /** @class */ (function (_super) {
2878
2915
  CSSColorValue.prototype.getType = function () {
2879
2916
  return CSSStyleValueType.kColorType;
2880
2917
  };
2881
- // buildCSSText(n: Nested, p: ParenLess, result: string): string {
2882
- // let text = '';
2883
- // if (this.colorSpace === 'rgb') {
2884
- // text = `rgba(${this.channels.join(',')},${this.alpha})`;
2885
- // }
2886
- // return (result += text);
2887
- // }
2888
2918
  /**
2889
2919
  * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to
2890
2920
  */
@@ -2925,102 +2955,26 @@ var CSSGradientValue = /** @class */ (function (_super) {
2925
2955
  * eg. 'initial'
2926
2956
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue
2927
2957
  * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl
2928
- */
2929
- var CSSKeywordValue = /** @class */ (function (_super) {
2930
- tslib.__extends(CSSKeywordValue, _super);
2931
- function CSSKeywordValue(value) {
2932
- var _this = _super.call(this) || this;
2933
- _this.value = value;
2934
- return _this;
2935
- }
2936
- CSSKeywordValue.prototype.clone = function () {
2937
- return new CSSKeywordValue(this.value);
2938
- };
2939
- CSSKeywordValue.prototype.getType = function () {
2940
- return CSSStyleValueType.kKeywordType;
2941
- };
2942
- CSSKeywordValue.prototype.buildCSSText = function (n, p, result) {
2943
- return result + this.value;
2944
- };
2945
- return CSSKeywordValue;
2946
- }(CSSStyleValue));
2947
-
2948
- var camelCase = memoize(function (str) {
2949
- if (str === void 0) { str = ''; }
2950
- return str.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
2951
- });
2952
- var kebabize = function (str) {
2953
- return str
2954
- .split('')
2955
- .map(function (letter, idx) {
2956
- return letter.toUpperCase() === letter
2957
- ? "".concat(idx !== 0 ? '-' : '').concat(letter.toLowerCase())
2958
- : letter;
2959
- })
2960
- .join('');
2961
- };
2962
-
2963
- function DCHECK(bool) {
2964
- if (!bool) {
2965
- throw new Error();
2966
- }
2967
- }
2968
- function isFunction(func) {
2969
- return typeof func === 'function';
2970
- }
2971
- function isSymbol(value) {
2972
- // @see https://github.com/lodash/lodash/blob/master/isSymbol.js
2973
- return typeof value === 'symbol';
2974
- }
2975
- var definedProps = function (obj) {
2976
- return Object.fromEntries(Object.entries(obj).filter(function (_a) {
2977
- var _b = tslib.__read(_a, 2), v = _b[1];
2978
- return v !== undefined;
2979
- }));
2980
- };
2981
- var FORMAT_ATTR_MAP = {
2982
- d: {
2983
- alias: 'path',
2984
- },
2985
- strokeDasharray: {
2986
- alias: 'lineDash',
2987
- },
2988
- strokeWidth: {
2989
- alias: 'lineWidth',
2990
- },
2991
- textAnchor: {
2992
- alias: 'textAlign',
2993
- },
2994
- src: {
2995
- alias: 'img',
2996
- },
2997
- };
2998
- var formatAttributeName = memoize(function (name) {
2999
- var attributeName = camelCase(name);
3000
- var map = FORMAT_ATTR_MAP[attributeName];
3001
- attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
3002
- return attributeName;
3003
- });
2958
+ */
2959
+ var CSSKeywordValue = /** @class */ (function (_super) {
2960
+ tslib.__extends(CSSKeywordValue, _super);
2961
+ function CSSKeywordValue(value) {
2962
+ var _this = _super.call(this) || this;
2963
+ _this.value = value;
2964
+ return _this;
2965
+ }
2966
+ CSSKeywordValue.prototype.clone = function () {
2967
+ return new CSSKeywordValue(this.value);
2968
+ };
2969
+ CSSKeywordValue.prototype.getType = function () {
2970
+ return CSSStyleValueType.kKeywordType;
2971
+ };
2972
+ CSSKeywordValue.prototype.buildCSSText = function (n, p, result) {
2973
+ return result + this.value;
2974
+ };
2975
+ return CSSKeywordValue;
2976
+ }(CSSStyleValue));
3004
2977
 
3005
- // type CSSNumericBaseType =
3006
- // | 'length'
3007
- // | 'angle'
3008
- // | 'time'
3009
- // | 'frequency'
3010
- // | 'resolution'
3011
- // | 'flex'
3012
- // | 'percent';
3013
- // https://drafts.css-houdini.org/css-typed-om/#dictdef-cssnumerictype
3014
- // interface CSSNumericType {
3015
- // length: number;
3016
- // angle: number;
3017
- // time: number;
3018
- // frequency: number;
3019
- // resolution: number;
3020
- // flex: number;
3021
- // percent: number;
3022
- // percentHint: CSSNumericBaseType;
3023
- // }
3024
2978
  var formatInfinityOrNaN = function (number, suffix) {
3025
2979
  if (suffix === void 0) { suffix = ''; }
3026
2980
  var result = '';
@@ -3031,7 +2985,6 @@ var formatInfinityOrNaN = function (number, suffix) {
3031
2985
  result = '-infinity';
3032
2986
  }
3033
2987
  else {
3034
- DCHECK(Number.isNaN(number));
3035
2988
  result = 'NaN';
3036
2989
  }
3037
2990
  return (result += suffix);
@@ -3127,25 +3080,25 @@ var CSSUnitValue = /** @class */ (function (_super) {
3127
3080
  case exports.UnitType.kSeconds:
3128
3081
  // case UnitType.kHertz:
3129
3082
  // case UnitType.kKilohertz:
3130
- case exports.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:
3131
- {
3132
- var kMinInteger = -999999;
3133
- var kMaxInteger = 999999;
3134
- var value = this.value;
3135
- var unit = unitTypeToString(this.unit);
3136
- if (value < kMinInteger || value > kMaxInteger) {
3137
- var unit_1 = unitTypeToString(this.unit);
3138
- if (!Number.isFinite(value) || Number.isNaN(value)) {
3139
- text = formatInfinityOrNaN(value, unit_1);
3140
- }
3141
- else {
3142
- text = value + (unit_1 || '');
3143
- }
3083
+ case exports.UnitType.kTurns: {
3084
+ // 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:
3085
+ var kMinInteger = -999999;
3086
+ var kMaxInteger = 999999;
3087
+ var value = this.value;
3088
+ var unit = unitTypeToString(this.unit);
3089
+ if (value < kMinInteger || value > kMaxInteger) {
3090
+ var unit_1 = unitTypeToString(this.unit);
3091
+ if (!Number.isFinite(value) || Number.isNaN(value)) {
3092
+ text = formatInfinityOrNaN(value, unit_1);
3144
3093
  }
3145
3094
  else {
3146
- text = "".concat(value).concat(unit);
3095
+ text = value + (unit_1 || '');
3147
3096
  }
3148
3097
  }
3098
+ else {
3099
+ text = "".concat(value).concat(unit);
3100
+ }
3101
+ }
3149
3102
  }
3150
3103
  result += text;
3151
3104
  return result;
@@ -3229,99 +3182,6 @@ var getOrCreateUnitValue = function (value, unitOrName) {
3229
3182
  };
3230
3183
  new CSSUnitValue(50, '%');
3231
3184
 
3232
- /**
3233
- * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
3234
- */
3235
- exports.Strategy = void 0;
3236
- (function (Strategy) {
3237
- Strategy[Strategy["Standard"] = 0] = "Standard";
3238
- })(exports.Strategy || (exports.Strategy = {}));
3239
-
3240
- exports.SortReason = void 0;
3241
- (function (SortReason) {
3242
- SortReason[SortReason["ADDED"] = 0] = "ADDED";
3243
- SortReason[SortReason["REMOVED"] = 1] = "REMOVED";
3244
- SortReason[SortReason["Z_INDEX_CHANGED"] = 2] = "Z_INDEX_CHANGED";
3245
- })(exports.SortReason || (exports.SortReason = {}));
3246
-
3247
- var EMPTY_PARSED_PATH = {
3248
- absolutePath: [],
3249
- hasArc: false,
3250
- segments: [],
3251
- polygons: [],
3252
- polylines: [],
3253
- curve: null,
3254
- totalLength: 0,
3255
- rect: new Rectangle(0, 0, 0, 0),
3256
- };
3257
-
3258
- /**
3259
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
3260
- */
3261
- exports.PropertySyntax = void 0;
3262
- (function (PropertySyntax) {
3263
- /**
3264
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
3265
- */
3266
- PropertySyntax["COORDINATE"] = "<coordinate>";
3267
- /**
3268
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
3269
- */
3270
- PropertySyntax["COLOR"] = "<color>";
3271
- /**
3272
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
3273
- */
3274
- PropertySyntax["PAINT"] = "<paint>";
3275
- /**
3276
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
3277
- */
3278
- PropertySyntax["NUMBER"] = "<number>";
3279
- /**
3280
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle
3281
- */
3282
- PropertySyntax["ANGLE"] = "<angle>";
3283
- /**
3284
- * <number> with range 0..1
3285
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
3286
- */
3287
- PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
3288
- /**
3289
- * <number> with range 0..Infinity
3290
- */
3291
- PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
3292
- /**
3293
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
3294
- */
3295
- PropertySyntax["LENGTH"] = "<length>";
3296
- /**
3297
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
3298
- */
3299
- PropertySyntax["PERCENTAGE"] = "<percentage>";
3300
- PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
3301
- PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
3302
- /**
3303
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
3304
- */
3305
- PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
3306
- /**
3307
- * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
3308
- */
3309
- PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
3310
- PropertySyntax["PATH"] = "<path>";
3311
- /**
3312
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
3313
- */
3314
- PropertySyntax["FILTER"] = "<filter>";
3315
- PropertySyntax["Z_INDEX"] = "<z-index>";
3316
- PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
3317
- PropertySyntax["DEFINED_PATH"] = "<defined-path>";
3318
- PropertySyntax["MARKER"] = "<marker>";
3319
- PropertySyntax["TRANSFORM"] = "<transform>";
3320
- PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
3321
- PropertySyntax["TEXT"] = "<text>";
3322
- PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
3323
- })(exports.PropertySyntax || (exports.PropertySyntax = {}));
3324
-
3325
3185
  /**
3326
3186
  * borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
3327
3187
  * @see https://github.com/rafaelcaricio/gradient-parser
@@ -4080,12 +3940,6 @@ function mergeDimensions(left, right, target, nonNegative, index) {
4080
3940
  unit = 'px';
4081
3941
  }
4082
3942
  }
4083
- // // format 'rad' 'turn' to 'deg'
4084
- // if (CSSUnitValue.isAngle(left.unit) || CSSUnitValue.isAngle(right.unit)) {
4085
- // leftValue = convertAngleUnit(left);
4086
- // rightValue = convertAngleUnit(right);
4087
- // unit = 'deg';
4088
- // }
4089
3943
  return [
4090
3944
  leftValue,
4091
3945
  rightValue,
@@ -4108,6 +3962,9 @@ function convertAngleUnit(value) {
4108
3962
  else if (value.unit === exports.UnitType.kTurns) {
4109
3963
  deg = turn2deg(Number(value.value));
4110
3964
  }
3965
+ else if (value.value) {
3966
+ deg = value.value;
3967
+ }
4111
3968
  return deg;
4112
3969
  }
4113
3970
  function parseDimensionArrayFormat(string, size) {
@@ -4145,16 +4002,6 @@ function parseDimensionArrayFormat(string, size) {
4145
4002
  }
4146
4003
  }
4147
4004
  }
4148
- function parseDimensionArray(string) {
4149
- if (util.isString(string)) {
4150
- // "1px 2px 3px"
4151
- return string.split(' ').map(function (segment) { return parseLengthOrPercentage(segment); });
4152
- }
4153
- else {
4154
- // [1, '2px', 3]
4155
- return string.map(function (segment) { return parseLengthOrPercentage(segment.toString()); });
4156
- }
4157
- }
4158
4005
  // export function mergeDimensionList(
4159
4006
  // left: CSSUnitValue[],
4160
4007
  // right: CSSUnitValue[],
@@ -5183,6 +5030,7 @@ function mergePoints(left, right) {
5183
5030
  }
5184
5031
 
5185
5032
  var _ = null;
5033
+ var TRANSFORM_REGEXP = /\s*(\w+)\(([^)]*)\)/g;
5186
5034
  function cast(pattern) {
5187
5035
  return function (contents) {
5188
5036
  var i = 0;
@@ -5201,48 +5049,75 @@ var transformFunctions = {
5201
5049
  matrix: ['NNNNNN', [_, _, 0, 0, _, _, 0, 0, 0, 0, 1, 0, _, _, 0, 1], id],
5202
5050
  matrix3d: ['NNNNNNNNNNNNNNNN', id],
5203
5051
  rotate: ['A'],
5204
- rotatex: ['A'],
5205
- rotatey: ['A'],
5206
- rotatez: ['A'],
5052
+ rotateX: ['A'],
5053
+ rotateY: ['A'],
5054
+ rotateZ: ['A'],
5207
5055
  rotate3d: ['NNNA'],
5208
5056
  perspective: ['L'],
5209
5057
  scale: ['Nn', cast([_, _, new CSSUnitValue(1)]), id],
5210
- scalex: [
5058
+ scaleX: [
5211
5059
  'N',
5212
5060
  cast([_, new CSSUnitValue(1), new CSSUnitValue(1)]),
5213
5061
  cast([_, new CSSUnitValue(1)]),
5214
5062
  ],
5215
- scaley: [
5063
+ scaleY: [
5216
5064
  'N',
5217
5065
  cast([new CSSUnitValue(1), _, new CSSUnitValue(1)]),
5218
5066
  cast([new CSSUnitValue(1), _]),
5219
5067
  ],
5220
- scalez: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5068
+ scaleZ: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5221
5069
  scale3d: ['NNN', id],
5222
5070
  skew: ['Aa', null, id],
5223
- skewx: ['A', null, cast([_, Odeg])],
5224
- skewy: ['A', null, cast([Odeg, _])],
5071
+ skewX: ['A', null, cast([_, Odeg])],
5072
+ skewY: ['A', null, cast([Odeg, _])],
5225
5073
  translate: ['Tt', cast([_, _, Opx]), id],
5226
- translatex: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5227
- translatey: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5228
- translatez: ['L', cast([Opx, Opx, _])],
5074
+ translateX: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5075
+ translateY: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5076
+ translateZ: ['L', cast([Opx, Opx, _])],
5229
5077
  translate3d: ['TTL', id],
5230
5078
  };
5079
+ function parseArrayTransform(transform) {
5080
+ var result = [];
5081
+ var length = transform.length;
5082
+ for (var i = 0; i < length; i++) {
5083
+ var item = transform[i];
5084
+ var name_1 = item[0];
5085
+ var args = item.slice(1);
5086
+ // infer default value
5087
+ if (name_1 === 'translate' || name_1 === 'skew') {
5088
+ if (args.length === 1)
5089
+ args.push(0);
5090
+ }
5091
+ else if (name_1 === 'scale') {
5092
+ if (args.length === 1)
5093
+ args.push(args[0]);
5094
+ }
5095
+ var functionData = transformFunctions[name_1];
5096
+ if (!functionData)
5097
+ return [];
5098
+ var parsedArgs = args.map(function (value) { return getOrCreateUnitValue(value); });
5099
+ result.push({ t: name_1, d: parsedArgs });
5100
+ }
5101
+ return result;
5102
+ }
5231
5103
  /**
5232
5104
  * none
5233
5105
  * scale(1) scale(1, 2)
5234
5106
  * scaleX(1)
5235
5107
  */
5236
- function parseTransform(string) {
5237
- string = (string || 'none').toLowerCase().trim();
5238
- if (string === 'none') {
5108
+ function parseTransform(transform) {
5109
+ if (Array.isArray(transform)) {
5110
+ return parseArrayTransform(transform);
5111
+ }
5112
+ transform = (transform || 'none').trim();
5113
+ if (transform === 'none') {
5239
5114
  return [];
5240
5115
  }
5241
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5242
5116
  var result = [];
5243
5117
  var match;
5244
5118
  var prevLastIndex = 0;
5245
- while ((match = transformRegExp.exec(string))) {
5119
+ TRANSFORM_REGEXP.lastIndex = 0;
5120
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5246
5121
  if (match.index !== prevLastIndex) {
5247
5122
  return [];
5248
5123
  }
@@ -5289,22 +5164,25 @@ function parseTransform(string) {
5289
5164
  parsedArgs.push(parsedArg);
5290
5165
  }
5291
5166
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5292
- if (transformRegExp.lastIndex === string.length) {
5167
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5293
5168
  return result;
5294
5169
  }
5295
5170
  }
5296
5171
  return [];
5297
5172
  }
5298
- function parseTransformUnmemoize(string) {
5299
- string = (string || 'none').toLowerCase().trim();
5300
- if (string === 'none') {
5173
+ function parseTransformUnmemoize(transform) {
5174
+ if (Array.isArray(transform)) {
5175
+ return parseArrayTransform(transform);
5176
+ }
5177
+ transform = (transform || 'none').trim();
5178
+ if (transform === 'none') {
5301
5179
  return [];
5302
5180
  }
5303
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5304
5181
  var result = [];
5305
5182
  var match;
5306
5183
  var prevLastIndex = 0;
5307
- while ((match = transformRegExp.exec(string))) {
5184
+ TRANSFORM_REGEXP.lastIndex = 0;
5185
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5308
5186
  if (match.index !== prevLastIndex) {
5309
5187
  return [];
5310
5188
  }
@@ -5351,7 +5229,7 @@ function parseTransformUnmemoize(string) {
5351
5229
  parsedArgs.push(parsedArg);
5352
5230
  }
5353
5231
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5354
- if (transformRegExp.lastIndex === string.length) {
5232
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5355
5233
  return result;
5356
5234
  }
5357
5235
  }
@@ -5363,7 +5241,7 @@ function convertItemToMatrix(item) {
5363
5241
  var z;
5364
5242
  var angle;
5365
5243
  switch (item.t) {
5366
- case 'rotatex':
5244
+ case 'rotateX':
5367
5245
  angle = deg2rad(convertAngleUnit(item.d[0]));
5368
5246
  return [
5369
5247
  1,
@@ -5383,7 +5261,7 @@ function convertItemToMatrix(item) {
5383
5261
  0,
5384
5262
  1,
5385
5263
  ];
5386
- case 'rotatey':
5264
+ case 'rotateY':
5387
5265
  angle = deg2rad(convertAngleUnit(item.d[0]));
5388
5266
  return [
5389
5267
  Math.cos(angle),
@@ -5404,7 +5282,7 @@ function convertItemToMatrix(item) {
5404
5282
  1,
5405
5283
  ];
5406
5284
  case 'rotate':
5407
- case 'rotatez':
5285
+ case 'rotateZ':
5408
5286
  angle = deg2rad(convertAngleUnit(item.d[0]));
5409
5287
  return [
5410
5288
  Math.cos(angle),
@@ -5481,11 +5359,11 @@ function convertItemToMatrix(item) {
5481
5359
  0,
5482
5360
  1,
5483
5361
  ];
5484
- case 'scalex':
5362
+ case 'scaleX':
5485
5363
  return [item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5486
- case 'scaley':
5364
+ case 'scaleY':
5487
5365
  return [1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5488
- case 'scalez':
5366
+ case 'scaleZ':
5489
5367
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1];
5490
5368
  case 'scale3d':
5491
5369
  return [
@@ -5527,10 +5405,10 @@ function convertItemToMatrix(item) {
5527
5405
  0,
5528
5406
  1,
5529
5407
  ];
5530
- case 'skewx':
5408
+ case 'skewX':
5531
5409
  angle = deg2rad(convertAngleUnit(item.d[0]));
5532
5410
  return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5533
- case 'skewy':
5411
+ case 'skewY':
5534
5412
  angle = deg2rad(convertAngleUnit(item.d[0]));
5535
5413
  return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5536
5414
  case 'translate':
@@ -5538,13 +5416,13 @@ function convertItemToMatrix(item) {
5538
5416
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5539
5417
  y = convertPercentUnit(item.d[1], 0, null) || 0;
5540
5418
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, 0, 1];
5541
- case 'translatex':
5419
+ case 'translateX':
5542
5420
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5543
5421
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
5544
- case 'translatey':
5422
+ case 'translateY':
5545
5423
  y = convertPercentUnit(item.d[0], 0, null) || 0;
5546
5424
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, y, 0, 1];
5547
- case 'translatez':
5425
+ case 'translateZ':
5548
5426
  z = convertPercentUnit(item.d[0], 0, null) || 0;
5549
5427
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, z, 1];
5550
5428
  case 'translate3d':
@@ -5785,13 +5663,13 @@ function quat(fromQ, toQ, f) {
5785
5663
  }
5786
5664
  return quat;
5787
5665
  }
5788
- // scalex/y/z -> scale
5666
+ // scaleX/Y/Z -> scale
5789
5667
  function typeTo2D(type) {
5790
- return type.replace(/[xy]/, '');
5668
+ return type.replace(/[XY]/, '');
5791
5669
  }
5792
- // scalex/y/z -> scale3d
5670
+ // scaleX/Y/Z -> scale3d
5793
5671
  function typeTo3D(type) {
5794
- return type.replace(/(x|y|z|3d)?$/, '3d');
5672
+ return type.replace(/(X|Y|Z|3d)?$/, '3d');
5795
5673
  }
5796
5674
  var isMatrixOrPerspective = function (lt, rt) {
5797
5675
  return ((lt === 'perspective' && rt === 'perspective') ||
@@ -5972,39 +5850,6 @@ var parseTransformOrigin = memoize(function (value) {
5972
5850
  ];
5973
5851
  }
5974
5852
  });
5975
- var parseTransformOriginUnmemoize = function (value) {
5976
- if (util.isString(value)) {
5977
- if (value === 'text-anchor') {
5978
- return [getOrCreateUnitValue(0, 'px'), getOrCreateUnitValue(0, 'px')];
5979
- }
5980
- var values = value.split(' ');
5981
- if (values.length === 1) {
5982
- if (values[0] === 'top' || values[0] === 'bottom') {
5983
- // 'top' -> 'center top'
5984
- values[1] = values[0];
5985
- values[0] = 'center';
5986
- }
5987
- else {
5988
- // '50px' -> '50px center'
5989
- values[1] = 'center';
5990
- }
5991
- }
5992
- if (values.length !== 2) {
5993
- return null;
5994
- }
5995
- // eg. center bottom
5996
- return [
5997
- parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[0])),
5998
- parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[1])),
5999
- ];
6000
- }
6001
- else {
6002
- return [
6003
- getOrCreateUnitValue(value[0] || 0, 'px'),
6004
- getOrCreateUnitValue(value[1] || 0, 'px'),
6005
- ];
6006
- }
6007
- };
6008
5853
  function convertKeyword2Percent(keyword) {
6009
5854
  if (keyword === 'center') {
6010
5855
  return '50%';
@@ -6599,23 +6444,7 @@ var BUILT_IN_PROPERTIES = [
6599
6444
  ];
6600
6445
  var GEOMETRY_ATTRIBUTE_NAMES = BUILT_IN_PROPERTIES.filter(function (n) { return !!n.l; }).map(function (n) { return n.n; });
6601
6446
  var propertyMetadataCache = {};
6602
- var unresolvedProperties = new WeakMap();
6603
- // const uniqueAttributeSet = new Set<string>();
6604
- // const tmpVec3a = vec3.create();
6605
- // const tmpVec3b = vec3.create();
6606
- // const tmpVec3c = vec3.create();
6607
- var isPropertyResolved = function (object, name) {
6608
- var properties = unresolvedProperties.get(object);
6609
- if (!properties || properties.length === 0) {
6610
- return true;
6611
- }
6612
- return properties.includes(name);
6613
- };
6614
6447
  var DefaultStyleValueRegistry = /** @class */ (function () {
6615
- /**
6616
- * need recalc later
6617
- */
6618
- // dirty = false;
6619
6448
  function DefaultStyleValueRegistry(runtime) {
6620
6449
  var _this = this;
6621
6450
  this.runtime = runtime;
@@ -6628,9 +6457,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6628
6457
  propertyMetadataCache[name] = metadata;
6629
6458
  });
6630
6459
  };
6631
- DefaultStyleValueRegistry.prototype.unregisterMetadata = function (name) {
6632
- delete propertyMetadataCache[name];
6633
- };
6634
6460
  DefaultStyleValueRegistry.prototype.getPropertySyntax = function (syntax) {
6635
6461
  return this.runtime.CSSPropertySyntaxFactory[syntax];
6636
6462
  };
@@ -6644,7 +6470,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6644
6470
  * * post process
6645
6471
  */
6646
6472
  DefaultStyleValueRegistry.prototype.processProperties = function (object, attributes, options) {
6647
- var _this = this;
6648
6473
  if (options === void 0) { options = {
6649
6474
  skipUpdateAttribute: false,
6650
6475
  skipParse: false,
@@ -6652,365 +6477,116 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6652
6477
  usedAttributes: [],
6653
6478
  memoize: true,
6654
6479
  }; }
6655
- if (!this.runtime.enableCSSParsing) {
6656
- Object.assign(object.attributes, attributes);
6657
- var attributeNames = Object.keys(attributes);
6658
- // clipPath
6659
- var oldClipPath = object.parsedStyle.clipPath;
6660
- var oldOffsetPath = object.parsedStyle.offsetPath;
6661
- object.parsedStyle = Object.assign(object.parsedStyle, attributes);
6662
- var needUpdateGeometry = !!options.forceUpdateGeometry;
6663
- if (!needUpdateGeometry) {
6664
- for (var i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
6665
- if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
6666
- needUpdateGeometry = true;
6667
- break;
6668
- }
6669
- }
6670
- }
6671
- if (attributes.fill) {
6672
- object.parsedStyle.fill = parseColor(attributes.fill);
6673
- }
6674
- if (attributes.stroke) {
6675
- object.parsedStyle.stroke = parseColor(attributes.stroke);
6676
- }
6677
- if (attributes.shadowColor) {
6678
- object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
6679
- }
6680
- if (attributes.filter) {
6681
- object.parsedStyle.filter = parseFilter(attributes.filter);
6682
- }
6683
- // Rect
6684
- // @ts-ignore
6685
- if (!util.isNil(attributes.radius)) {
6686
- // @ts-ignore
6687
- object.parsedStyle.radius = parseDimensionArrayFormat(
6688
- // @ts-ignore
6689
- attributes.radius, 4);
6690
- }
6691
- // Polyline
6692
- if (!util.isNil(attributes.lineDash)) {
6693
- object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6694
- }
6695
- // @ts-ignore
6696
- if (attributes.points) {
6697
- // @ts-ignore
6698
- object.parsedStyle.points = parsePoints(attributes.points);
6699
- }
6700
- // Path
6701
- // @ts-ignore
6702
- if (attributes.d === '') {
6703
- object.parsedStyle.d = tslib.__assign({}, EMPTY_PARSED_PATH);
6704
- }
6480
+ Object.assign(object.attributes, attributes);
6481
+ // clipPath
6482
+ var oldClipPath = object.parsedStyle.clipPath;
6483
+ var oldOffsetPath = object.parsedStyle.offsetPath;
6484
+ Object.assign(object.parsedStyle, attributes);
6485
+ var needUpdateGeometry = !!options.forceUpdateGeometry;
6486
+ if (!needUpdateGeometry &&
6487
+ GEOMETRY_ATTRIBUTE_NAMES.some(function (name) { return name in attributes; })) {
6488
+ needUpdateGeometry = true;
6489
+ }
6490
+ if (attributes.fill) {
6491
+ object.parsedStyle.fill = parseColor(attributes.fill);
6492
+ }
6493
+ if (attributes.stroke) {
6494
+ object.parsedStyle.stroke = parseColor(attributes.stroke);
6495
+ }
6496
+ if (attributes.shadowColor) {
6497
+ object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
6498
+ }
6499
+ if (attributes.filter) {
6500
+ object.parsedStyle.filter = parseFilter(attributes.filter);
6501
+ }
6502
+ // Rect
6503
+ // @ts-ignore
6504
+ if (!util.isNil(attributes.radius)) {
6705
6505
  // @ts-ignore
6706
- if (attributes.d) {
6707
- object.parsedStyle.d = parsePath(
6708
- // @ts-ignore
6709
- attributes.d);
6710
- }
6711
- // Text
6712
- if (attributes.textTransform) {
6713
- this.runtime.CSSPropertySyntaxFactory['<text-transform>'].calculator(null, null, { value: attributes.textTransform }, object, null);
6714
- }
6715
- if (!util.isUndefined(attributes.clipPath)) {
6716
- this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6717
- }
6718
- if (attributes.offsetPath) {
6719
- this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6720
- }
6721
- if (attributes.transform) {
6722
- object.parsedStyle.transform = parseTransform(attributes.transform);
6723
- }
6724
- if (attributes.transformOrigin) {
6725
- object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
6726
- }
6727
- // Marker
6506
+ object.parsedStyle.radius = parseDimensionArrayFormat(
6728
6507
  // @ts-ignore
6729
- if (attributes.markerStart) {
6730
- object.parsedStyle.markerStart = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
6731
- // @ts-ignore
6732
- attributes.markerStart,
6733
- // @ts-ignore
6734
- attributes.markerStart, null, null);
6735
- }
6508
+ attributes.radius, 4);
6509
+ }
6510
+ // Polyline
6511
+ if (!util.isNil(attributes.lineDash)) {
6512
+ object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6513
+ }
6514
+ // @ts-ignore
6515
+ if (attributes.points) {
6736
6516
  // @ts-ignore
6737
- if (attributes.markerEnd) {
6738
- object.parsedStyle.markerEnd = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator(null,
6739
- // @ts-ignore
6740
- attributes.markerEnd,
6741
- // @ts-ignore
6742
- attributes.markerEnd, null, null);
6743
- }
6517
+ object.parsedStyle.points = parsePoints(attributes.points);
6518
+ }
6519
+ // Path
6520
+ // @ts-ignore
6521
+ if (attributes.d === '') {
6522
+ object.parsedStyle.d = tslib.__assign({}, EMPTY_PARSED_PATH);
6523
+ }
6524
+ // @ts-ignore
6525
+ if (attributes.d) {
6526
+ object.parsedStyle.d = parsePath(
6744
6527
  // @ts-ignore
6745
- if (attributes.markerMid) {
6746
- object.parsedStyle.markerMid = this.runtime.CSSPropertySyntaxFactory['<marker>'].calculator('',
6747
- // @ts-ignore
6748
- attributes.markerMid,
6749
- // @ts-ignore
6750
- attributes.markerMid, null, null);
6751
- }
6752
- if (!util.isNil(attributes.zIndex)) {
6753
- this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames);
6754
- }
6755
- if (!util.isNil(attributes.offsetDistance)) {
6756
- this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames);
6757
- }
6758
- if (attributes.transform) {
6759
- this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames);
6760
- }
6761
- if (attributes.transformOrigin) {
6762
- this.runtime.CSSPropertySyntaxFactory['<transform-origin>'].postProcessor(object, attributeNames);
6763
- }
6764
- if (needUpdateGeometry) {
6765
- object.geometry.dirty = true;
6766
- object.renderable.boundsDirty = true;
6767
- object.renderable.renderBoundsDirty = true;
6768
- if (!options.forceUpdateGeometry) {
6769
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6770
- }
6771
- }
6528
+ attributes.d);
6772
6529
  }
6773
- else {
6774
- var skipUpdateAttribute_1 = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize_1 = options.memoize;
6775
- var needUpdateGeometry_1 = forceUpdateGeometry;
6776
- var attributeNames_1 = Object.keys(attributes);
6777
- attributeNames_1.forEach(function (attributeName) {
6778
- var _a;
6779
- if (!skipUpdateAttribute_1) {
6780
- object.attributes[attributeName] = attributes[attributeName];
6781
- }
6782
- if (!needUpdateGeometry_1 && ((_a = propertyMetadataCache[attributeName]) === null || _a === void 0 ? void 0 : _a.l)) {
6783
- needUpdateGeometry_1 = true;
6784
- }
6785
- });
6786
- if (!skipParse) {
6787
- attributeNames_1.forEach(function (name) {
6788
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize_1);
6789
- });
6790
- }
6791
- // let hasUnresolvedProperties = false;
6792
- // parse according to priority
6793
- // path 50
6794
- // points 50
6795
- // text 50
6796
- // textTransform 51
6797
- // transform 100
6798
- // transformOrigin 100
6799
- if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
6800
- // uniqueAttributeSet.clear();
6801
- attributeNames_1 = Array.from(new Set(attributeNames_1.concat(usedAttributes)));
6802
- }
6803
- // [
6804
- // 'path',
6805
- // 'points',
6806
- // 'text',
6807
- // 'textTransform',
6808
- // 'transform',
6809
- // 'transformOrigin',
6810
- // ].forEach((name) => {
6811
- // const index = attributeNames.indexOf(name);
6812
- // if (index > -1) {
6813
- // attributeNames.splice(index, 1);
6814
- // attributeNames.push(name);
6815
- // }
6816
- // });
6817
- attributeNames_1.forEach(function (name) {
6818
- // some style props maybe deleted after parsing such as `anchor` in Text
6819
- if (name in object.computedStyle) {
6820
- object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize_1);
6821
- }
6822
- });
6823
- // if (hasUnresolvedProperties) {
6824
- // this.dirty = true;
6825
- // return;
6826
- // }
6827
- // update geometry
6828
- if (needUpdateGeometry_1) {
6829
- object.geometry.dirty = true;
6830
- object.renderable.boundsDirty = true;
6831
- object.renderable.renderBoundsDirty = true;
6832
- if (!options.forceUpdateGeometry) {
6833
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6834
- }
6835
- }
6836
- attributeNames_1.forEach(function (name) {
6837
- if (name in object.parsedStyle) {
6838
- _this.postProcessProperty(name, object, attributeNames_1);
6839
- }
6840
- });
6841
- if (this.runtime.enableCSSParsing && object.children.length) {
6842
- attributeNames_1.forEach(function (name) {
6843
- if (name in object.parsedStyle && _this.isPropertyInheritable(name)) {
6844
- // update children's inheritable
6845
- object.children.forEach(function (child) {
6846
- child.internalSetAttribute(name, null, {
6847
- skipUpdateAttribute: true,
6848
- skipParse: true,
6849
- });
6850
- });
6851
- }
6852
- });
6853
- }
6530
+ // Text
6531
+ if (attributes.textTransform) {
6532
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TEXT_TRANSFORM].calculator(null, null, { value: attributes.textTransform }, object, null);
6854
6533
  }
6855
- };
6856
- /**
6857
- * string -> parsed value
6858
- */
6859
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object, memoized) {
6860
- var metadata = propertyMetadataCache[name];
6861
- var computed = value;
6862
- if (value === '' || util.isNil(value)) {
6863
- value = 'unset';
6534
+ if (!util.isUndefined(attributes.clipPath)) {
6535
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.DEFINED_PATH].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6864
6536
  }
6865
- if (value === 'unset' || value === 'initial' || value === 'inherit') {
6866
- // computed = new CSSKeywordValue(value);
6867
- computed = getOrCreateKeyword(value);
6537
+ if (attributes.offsetPath) {
6538
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.DEFINED_PATH].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6868
6539
  }
6869
- else {
6870
- if (metadata) {
6871
- var keywords = metadata.k, syntax = metadata.syntax;
6872
- var handler = syntax && this.getPropertySyntax(syntax);
6873
- // use keywords
6874
- if (keywords && keywords.indexOf(value) > -1) {
6875
- // computed = new CSSKeywordValue(value);
6876
- computed = getOrCreateKeyword(value);
6877
- }
6878
- else if (handler) {
6879
- if (!memoized && handler.parserUnmemoize) {
6880
- computed = handler.parserUnmemoize(value, object);
6881
- }
6882
- else if (handler.parser) {
6883
- // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
6884
- computed = handler.parser(value, object);
6885
- }
6886
- }
6887
- }
6540
+ if (attributes.transform) {
6541
+ object.parsedStyle.transform = parseTransform(attributes.transform);
6542
+ }
6543
+ if (attributes.transformOrigin) {
6544
+ object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
6545
+ }
6546
+ // Marker
6547
+ // @ts-ignore
6548
+ if (attributes.markerStart) {
6549
+ object.parsedStyle.markerStart = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator(null,
6550
+ // @ts-ignore
6551
+ attributes.markerStart,
6552
+ // @ts-ignore
6553
+ attributes.markerStart, null, null);
6888
6554
  }
6889
- return computed;
6890
- };
6891
- /**
6892
- * computed value -> used value
6893
- */
6894
- DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object, memoized) {
6895
- var metadata = propertyMetadataCache[name];
6896
- var isDocumentElement = object.id === 'g-root';
6897
- // let used: CSSStyleValue = computed instanceof CSSStyleValue ? computed.clone() : computed;
6898
- var used = computed;
6899
- if (metadata) {
6900
- var syntax = metadata.syntax, inherited = metadata.inh, defaultValue = metadata.d;
6901
- if (computed instanceof CSSKeywordValue) {
6902
- var value = computed.value;
6903
- /**
6904
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/unset
6905
- */
6906
- if (value === 'unset') {
6907
- if (inherited && !isDocumentElement) {
6908
- value = 'inherit';
6909
- }
6910
- else {
6911
- value = 'initial';
6912
- }
6913
- }
6914
- if (value === 'initial') {
6915
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
6916
- if (!util.isNil(defaultValue)) {
6917
- computed = this.parseProperty(name, isFunction(defaultValue)
6918
- ? defaultValue(object.nodeName)
6919
- : defaultValue, object, memoized);
6920
- }
6921
- }
6922
- else if (value === 'inherit') {
6923
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
6924
- // behave like `inherit`
6925
- var resolved = this.tryToResolveProperty(object, name, {
6926
- inherited: true,
6927
- });
6928
- if (!util.isNil(resolved)) {
6929
- // object.parsedStyle[name] = resolved;
6930
- // return false;
6931
- return resolved;
6932
- }
6933
- else {
6934
- this.addUnresolveProperty(object, name);
6935
- return;
6936
- }
6937
- }
6938
- }
6939
- var handler = syntax && this.getPropertySyntax(syntax);
6940
- if (handler && handler.calculator) {
6941
- // convert computed value to used value
6942
- var oldParsedValue = object.parsedStyle[name];
6943
- used = handler.calculator(name, oldParsedValue, computed, object, this.runtime);
6944
- }
6945
- else if (computed instanceof CSSKeywordValue) {
6946
- used = computed.value;
6947
- }
6948
- else {
6949
- used = computed;
6950
- }
6555
+ // @ts-ignore
6556
+ if (attributes.markerEnd) {
6557
+ object.parsedStyle.markerEnd = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator(null,
6558
+ // @ts-ignore
6559
+ attributes.markerEnd,
6560
+ // @ts-ignore
6561
+ attributes.markerEnd, null, null);
6951
6562
  }
6952
- // object.parsedStyle[name] = used;
6953
- // return false;
6954
- return used;
6955
- };
6956
- DefaultStyleValueRegistry.prototype.postProcessProperty = function (name, object, attributes) {
6957
- var metadata = propertyMetadataCache[name];
6958
- if (metadata && metadata.syntax) {
6959
- var handler = metadata.syntax && this.getPropertySyntax(metadata.syntax);
6960
- var propertyHandler = handler;
6961
- if (propertyHandler && propertyHandler.postProcessor) {
6962
- propertyHandler.postProcessor(object, attributes);
6963
- }
6563
+ // @ts-ignore
6564
+ if (attributes.markerMid) {
6565
+ object.parsedStyle.markerMid = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator('',
6566
+ // @ts-ignore
6567
+ attributes.markerMid,
6568
+ // @ts-ignore
6569
+ attributes.markerMid, null, null);
6964
6570
  }
6965
- };
6966
- /**
6967
- * resolve later
6968
- */
6969
- DefaultStyleValueRegistry.prototype.addUnresolveProperty = function (object, name) {
6970
- var properties = unresolvedProperties.get(object);
6971
- if (!properties) {
6972
- unresolvedProperties.set(object, []);
6973
- properties = unresolvedProperties.get(object);
6571
+ if (!util.isNil(attributes.zIndex)) {
6572
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.Z_INDEX].postProcessor(object);
6974
6573
  }
6975
- if (properties.indexOf(name) === -1) {
6976
- properties.push(name);
6574
+ if (!util.isNil(attributes.offsetDistance)) {
6575
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.OFFSET_DISTANCE].postProcessor(object);
6977
6576
  }
6978
- };
6979
- DefaultStyleValueRegistry.prototype.tryToResolveProperty = function (object, name, options) {
6980
- if (options === void 0) { options = {}; }
6981
- var inherited = options.inherited;
6982
- if (inherited) {
6983
- if (object.parentElement &&
6984
- isPropertyResolved(object.parentElement, name)) {
6985
- // const computedValue = object.parentElement.computedStyle[name];
6986
- var usedValue = object.parentElement.parsedStyle[name];
6987
- if (
6988
- // usedValue instanceof CSSKeywordValue &&
6989
- usedValue === 'unset' ||
6990
- usedValue === 'initial' ||
6991
- usedValue === 'inherit') {
6992
- return;
6993
- }
6994
- // else if (
6995
- // usedValue instanceof CSSUnitValue &&
6996
- // CSSUnitValue.isRelativeUnit(usedValue.unit)
6997
- // ) {
6998
- // return false;
6999
- // }
7000
- return usedValue;
7001
- }
6577
+ if (attributes.transform) {
6578
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TRANSFORM].postProcessor(object);
7002
6579
  }
7003
- return;
7004
- };
7005
- DefaultStyleValueRegistry.prototype.recalc = function (object) {
7006
- var properties = unresolvedProperties.get(object);
7007
- if (properties && properties.length) {
7008
- var attributes_1 = {};
7009
- properties.forEach(function (property) {
7010
- attributes_1[property] = object.attributes[property];
7011
- });
7012
- this.processProperties(object, attributes_1);
7013
- unresolvedProperties.delete(object);
6580
+ if (attributes.transformOrigin) {
6581
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TRANSFORM_ORIGIN].postProcessor(object);
6582
+ }
6583
+ if (needUpdateGeometry) {
6584
+ object.geometry.dirty = true;
6585
+ object.renderable.boundsDirty = true;
6586
+ object.renderable.renderBoundsDirty = true;
6587
+ if (!options.forceUpdateGeometry) {
6588
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6589
+ }
7014
6590
  }
7015
6591
  };
7016
6592
  /**
@@ -7036,12 +6612,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7036
6612
  Math.abs(hheight),
7037
6613
  hdepth,
7038
6614
  ];
7039
- // const halfExtents = vec3.set(
7040
- // tmpVec3a,
7041
- // Math.abs(width) / 2,
7042
- // Math.abs(height) / 2,
7043
- // depth / 2,
7044
- // );
7045
6615
  // anchor is center by default, don't account for lineWidth here
7046
6616
  var _h = parsedStyle, stroke = _h.stroke, _j = _h.lineWidth, lineWidth = _j === void 0 ? 1 : _j,
7047
6617
  // lineCap,
@@ -7061,26 +6631,13 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7061
6631
  nodeName === exports.Shape.PATH
7062
6632
  ? Math.SQRT2
7063
6633
  : 0.5;
7064
- // if (lineCap?.value === 'square') {
7065
- // expansion = Math.SQRT1_2;
7066
- // }
7067
- // if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
7068
- // expansion = Math.SQRT1_2 * miterLimit;
7069
- // }
7070
6634
  // append border only if stroke existed
7071
6635
  var hasStroke = stroke && !stroke.isNone;
7072
6636
  if (hasStroke) {
7073
6637
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) *
7074
6638
  expansion;
7075
- // halfExtents[0] += halfLineWidth[0];
7076
- // halfExtents[1] += halfLineWidth[1];
7077
6639
  halfExtents[0] += halfLineWidth;
7078
6640
  halfExtents[1] += halfLineWidth;
7079
- // vec3.add(
7080
- // halfExtents,
7081
- // halfExtents,
7082
- // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
7083
- // );
7084
6641
  }
7085
6642
  geometry_1.renderBounds.update(center, halfExtents);
7086
6643
  // account for shadow, only support constant value now
@@ -7105,7 +6662,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7105
6662
  var name = _a.name, params = _a.params;
7106
6663
  if (name === 'blur') {
7107
6664
  var blurRadius = params[0].value;
7108
- geometry_1.renderBounds.update(geometry_1.renderBounds.center, addVec3(geometry_1.renderBounds.halfExtents, geometry_1.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
6665
+ geometry_1.renderBounds.update(geometry_1.renderBounds.center, glMatrix.vec3.add(geometry_1.renderBounds.halfExtents, geometry_1.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
7109
6666
  }
7110
6667
  else if (name === 'drop-shadow') {
7111
6668
  var shadowOffsetX = params[0].value;
@@ -7167,21 +6724,11 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7167
6724
  }
7168
6725
  }
7169
6726
  };
7170
- DefaultStyleValueRegistry.prototype.isPropertyInheritable = function (name) {
7171
- var metadata = propertyMetadataCache[name];
7172
- if (!metadata) {
7173
- return false;
7174
- }
7175
- return metadata.inh;
7176
- };
7177
6727
  return DefaultStyleValueRegistry;
7178
6728
  }());
7179
6729
 
7180
6730
  var CSSPropertyAngle = /** @class */ (function () {
7181
6731
  function CSSPropertyAngle() {
7182
- this.parser = parseAngle;
7183
- this.parserUnmemoize = parseAngleUnmemoize;
7184
- this.parserWithCSSDisabled = null;
7185
6732
  this.mixer = mergeNumbers;
7186
6733
  }
7187
6734
  CSSPropertyAngle.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7218,7 +6765,6 @@ var CSSPropertyClipPath = /** @class */ (function () {
7218
6765
  var CSSPropertyColor = /** @class */ (function () {
7219
6766
  function CSSPropertyColor() {
7220
6767
  this.parser = parseColor;
7221
- this.parserWithCSSDisabled = parseColor;
7222
6768
  this.mixer = mergeColors;
7223
6769
  }
7224
6770
  CSSPropertyColor.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7233,7 +6779,6 @@ var CSSPropertyColor = /** @class */ (function () {
7233
6779
 
7234
6780
  var CSSPropertyFilter = /** @class */ (function () {
7235
6781
  function CSSPropertyFilter() {
7236
- this.parser = parseFilter;
7237
6782
  }
7238
6783
  CSSPropertyFilter.prototype.calculator = function (name, oldParsed, parsed) {
7239
6784
  // unset or none
@@ -7254,9 +6799,6 @@ function getFontSize(object) {
7254
6799
  */
7255
6800
  var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7256
6801
  function CSSPropertyLengthOrPercentage() {
7257
- this.parser = parseLengthOrPercentage;
7258
- this.parserUnmemoize = parseLengthOrPercentageUnmemoize;
7259
- this.parserWithCSSDisabled = null;
7260
6802
  this.mixer = mergeNumbers;
7261
6803
  }
7262
6804
  /**
@@ -7271,7 +6813,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7271
6813
  return computed;
7272
6814
  }
7273
6815
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
7274
- var registry = runtime.styleValueRegistry;
7275
6816
  if (computed.unit === exports.UnitType.kPercentage) {
7276
6817
  // TODO: merge dimensions
7277
6818
  return 0;
@@ -7283,12 +6824,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7283
6824
  fontSize *= computed.value;
7284
6825
  return fontSize;
7285
6826
  }
7286
- else {
7287
- registry.addUnresolveProperty(object, name);
7288
- }
7289
- }
7290
- else {
7291
- registry.addUnresolveProperty(object, name);
7292
6827
  }
7293
6828
  return 0;
7294
6829
  }
@@ -7299,12 +6834,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7299
6834
  fontSize *= computed.value;
7300
6835
  return fontSize;
7301
6836
  }
7302
- else {
7303
- registry.addUnresolveProperty(object, name);
7304
- }
7305
- }
7306
- else {
7307
- registry.addUnresolveProperty(object, name);
7308
6837
  }
7309
6838
  return 0;
7310
6839
  }
@@ -7331,17 +6860,6 @@ var CSSPropertyLengthOrPercentage12 = /** @class */ (function () {
7331
6860
  function CSSPropertyLengthOrPercentage12() {
7332
6861
  this.mixer = mergeNumberLists;
7333
6862
  }
7334
- CSSPropertyLengthOrPercentage12.prototype.parser = function (radius) {
7335
- var parsed = parseDimensionArray(util.isNumber(radius) ? [radius] : radius);
7336
- var formatted;
7337
- if (parsed.length === 1) {
7338
- formatted = [parsed[0], parsed[0]];
7339
- }
7340
- else {
7341
- formatted = [parsed[0], parsed[1]];
7342
- }
7343
- return formatted;
7344
- };
7345
6863
  CSSPropertyLengthOrPercentage12.prototype.calculator = function (name, oldParsed, computed) {
7346
6864
  return computed.map(function (c) { return c.value; });
7347
6865
  };
@@ -7360,24 +6878,6 @@ var CSSPropertyLengthOrPercentage14 = /** @class */ (function () {
7360
6878
  function CSSPropertyLengthOrPercentage14() {
7361
6879
  this.mixer = mergeNumberLists;
7362
6880
  }
7363
- CSSPropertyLengthOrPercentage14.prototype.parser = function (radius) {
7364
- var parsed = parseDimensionArray(util.isNumber(radius) ? [radius] : radius);
7365
- var formatted;
7366
- // format to Tuple<CSSUnitValue>
7367
- if (parsed.length === 1) {
7368
- formatted = [parsed[0], parsed[0], parsed[0], parsed[0]];
7369
- }
7370
- else if (parsed.length === 2) {
7371
- formatted = [parsed[0], parsed[1], parsed[0], parsed[1]];
7372
- }
7373
- else if (parsed.length === 3) {
7374
- formatted = [parsed[0], parsed[1], parsed[2], parsed[1]];
7375
- }
7376
- else {
7377
- formatted = [parsed[0], parsed[1], parsed[2], parsed[3]];
7378
- }
7379
- return formatted;
7380
- };
7381
6881
  CSSPropertyLengthOrPercentage14.prototype.calculator = function (name, oldParsed, computed) {
7382
6882
  return computed.map(function (c) { return c.value; });
7383
6883
  };
@@ -7405,9 +6905,6 @@ var CSSPropertyMarker = /** @class */ (function () {
7405
6905
  var CSSPropertyNumber = /** @class */ (function () {
7406
6906
  function CSSPropertyNumber() {
7407
6907
  this.mixer = mergeNumbers;
7408
- this.parser = parseNumber;
7409
- this.parserUnmemoize = parseNumberUnmemoize;
7410
- this.parserWithCSSDisabled = null;
7411
6908
  }
7412
6909
  CSSPropertyNumber.prototype.calculator = function (name, oldParsed, computed) {
7413
6910
  return computed.value;
@@ -7417,9 +6914,6 @@ var CSSPropertyNumber = /** @class */ (function () {
7417
6914
 
7418
6915
  var CSSPropertyOffsetDistance = /** @class */ (function () {
7419
6916
  function CSSPropertyOffsetDistance() {
7420
- this.parser = parseNumber;
7421
- this.parserUnmemoize = parseNumberUnmemoize;
7422
- this.parserWithCSSDisabled = null;
7423
6917
  this.mixer = clampedMergeNumbers(0, 1);
7424
6918
  }
7425
6919
  CSSPropertyOffsetDistance.prototype.calculator = function (name, oldParsed, computed) {
@@ -7449,9 +6943,6 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
7449
6943
  */
7450
6944
  var CSSPropertyOpacity = /** @class */ (function () {
7451
6945
  function CSSPropertyOpacity() {
7452
- this.parser = parseNumber;
7453
- this.parserUnmemoize = parseNumberUnmemoize;
7454
- this.parserWithCSSDisabled = null;
7455
6946
  this.mixer = clampedMergeNumbers(0, 1);
7456
6947
  }
7457
6948
  CSSPropertyOpacity.prototype.calculator = function (name, oldParsed, computed) {
@@ -7466,7 +6957,6 @@ var CSSPropertyPath = /** @class */ (function () {
7466
6957
  * path2Curve
7467
6958
  */
7468
6959
  this.parser = parsePath;
7469
- this.parserWithCSSDisabled = parsePath;
7470
6960
  this.mixer = mergePaths;
7471
6961
  }
7472
6962
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
@@ -7490,7 +6980,6 @@ var CSSPropertyPath = /** @class */ (function () {
7490
6980
 
7491
6981
  var CSSPropertyPoints = /** @class */ (function () {
7492
6982
  function CSSPropertyPoints() {
7493
- this.parser = parsePoints;
7494
6983
  this.mixer = mergePoints;
7495
6984
  }
7496
6985
  return CSSPropertyPoints;
@@ -7554,20 +7043,26 @@ var CSSPropertyTextTransform = /** @class */ (function () {
7554
7043
  return CSSPropertyTextTransform;
7555
7044
  }());
7556
7045
 
7557
- var canvasMap = {};
7558
- var defaultCanvasIdCounter = 0;
7046
+ var definedProps = function (obj) {
7047
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
7048
+ var _b = tslib.__read(_a, 2), v = _b[1];
7049
+ return v !== undefined;
7050
+ }));
7051
+ };
7052
+
7053
+ var CANVAS_Map = new WeakMap();
7559
7054
  /**
7560
7055
  * destroy existed canvas with the same id
7561
7056
  */
7562
- function cleanExistedCanvas(container, canvas) {
7057
+ function cleanExistedCanvas(container, canvas, cleanUp) {
7563
7058
  if (container) {
7564
- var id = typeof container === 'string'
7565
- ? container
7566
- : container.id || defaultCanvasIdCounter++;
7567
- if (canvasMap[id]) {
7568
- canvasMap[id].destroy();
7569
- }
7570
- canvasMap[id] = canvas;
7059
+ var $dom = typeof container === 'string'
7060
+ ? document.getElementById(container)
7061
+ : container;
7062
+ if (CANVAS_Map.has($dom))
7063
+ CANVAS_Map.get($dom).destroy(cleanUp);
7064
+ else
7065
+ CANVAS_Map.set($dom, canvas);
7571
7066
  }
7572
7067
  }
7573
7068
  var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
@@ -7652,6 +7147,12 @@ var TOUCH_TO_POINTER = {
7652
7147
  };
7653
7148
  var clock = typeof performance === 'object' && performance.now ? performance : Date;
7654
7149
 
7150
+ function isInFragment(node) {
7151
+ if (node.nodeName === exports.Shape.FRAGMENT)
7152
+ return true;
7153
+ return node.getRootNode().nodeName === exports.Shape.FRAGMENT;
7154
+ }
7155
+
7655
7156
  function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
7656
7157
  // account for pointerEvents
7657
7158
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
@@ -7910,114 +7411,102 @@ function createSkewMatrix(skewMatrix, skewX, skewY) {
7910
7411
  skewMatrix[1] = Math.tan(skewY); // Skew X axis in Y direction
7911
7412
  return skewMatrix;
7912
7413
  }
7913
- var SCALE_EPSILON = 0.00001;
7914
- var tmpMat1 = glMatrix.mat4.create();
7915
- var tmpMat2 = glMatrix.mat4.create();
7414
+ var $mat4_1 = glMatrix.mat4.create();
7415
+ var $mat4_2 = glMatrix.mat4.create();
7416
+ var parser = {
7417
+ scale: function (d) {
7418
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7419
+ },
7420
+ scaleX: function (d) {
7421
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7422
+ },
7423
+ scaleY: function (d) {
7424
+ glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7425
+ },
7426
+ scaleZ: function (d) {
7427
+ glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7428
+ },
7429
+ scale3d: function (d) {
7430
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7431
+ },
7432
+ translate: function (d) {
7433
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
7434
+ },
7435
+ translateX: function (d) {
7436
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, 0, 0]);
7437
+ },
7438
+ translateY: function (d) {
7439
+ glMatrix.mat4.fromTranslation($mat4_1, [0, d[0].value, 0]);
7440
+ },
7441
+ translateZ: function (d) {
7442
+ glMatrix.mat4.fromTranslation($mat4_1, [0, 0, d[0].value]);
7443
+ },
7444
+ translate3d: function (d) {
7445
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, d[2].value]);
7446
+ },
7447
+ rotate: function (d) {
7448
+ glMatrix.mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7449
+ },
7450
+ rotateX: function (d) {
7451
+ glMatrix.mat4.fromXRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7452
+ },
7453
+ rotateY: function (d) {
7454
+ glMatrix.mat4.fromYRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7455
+ },
7456
+ rotateZ: function (d) {
7457
+ glMatrix.mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7458
+ },
7459
+ rotate3d: function (d) {
7460
+ glMatrix.mat4.fromRotation($mat4_1, deg2rad(convertAngleUnit(d[3])), [
7461
+ d[0].value,
7462
+ d[1].value,
7463
+ d[2].value,
7464
+ ]);
7465
+ },
7466
+ skew: function (d) {
7467
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), deg2rad(d[1].value));
7468
+ },
7469
+ skewX: function (d) {
7470
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), 0);
7471
+ },
7472
+ skewY: function (d) {
7473
+ createSkewMatrix($mat4_1, 0, deg2rad(d[0].value));
7474
+ },
7475
+ matrix: function (d) {
7476
+ // prettier-ignore
7477
+ glMatrix.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);
7478
+ },
7479
+ matrix3d: function (d) {
7480
+ // @ts-ignore
7481
+ glMatrix.mat4.set.apply(glMatrix.mat4, tslib.__spreadArray([$mat4_1], tslib.__read(d.map(function (s) { return s.value; })), false));
7482
+ },
7483
+ };
7484
+ var $vec3One$1 = glMatrix.vec3.fromValues(1, 1, 1);
7485
+ var $vec3Zero$1 = glMatrix.vec3.create();
7486
+ var optimizer = {
7487
+ translate: function (object, d) {
7488
+ runtime.sceneGraphService.setLocalScale(object, $vec3One$1, false);
7489
+ runtime.sceneGraphService.setLocalEulerAngles(object, $vec3Zero$1, undefined, undefined, false);
7490
+ runtime.sceneGraphService.setLocalPosition(object, [d[0].value, d[1].value, 0], false);
7491
+ runtime.sceneGraphService.dirtifyLocal(object, object.transformable);
7492
+ },
7493
+ };
7916
7494
  function parsedTransformToMat4(transform, object) {
7917
7495
  if (transform.length) {
7918
- var m_1 = glMatrix.mat4.identity(tmpMat1);
7919
- transform.forEach(function (parsed) {
7920
- var t = parsed.t, d = parsed.d;
7921
- if (t === 'scale') {
7922
- // scale(1) scale(1, 1)
7923
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7924
- 1, 1,
7925
- ];
7926
- glMatrix.mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], 1]);
7927
- }
7928
- else if (t === 'scalex') {
7929
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7930
- glMatrix.mat4.fromScaling(tmpMat2, [newScale[0], 1, 1]);
7931
- }
7932
- else if (t === 'scaley') {
7933
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7934
- glMatrix.mat4.fromScaling(tmpMat2, [1, newScale[0], 1]);
7935
- }
7936
- else if (t === 'scalez') {
7937
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7938
- glMatrix.mat4.fromScaling(tmpMat2, [1, 1, newScale[0]]);
7939
- }
7940
- else if (t === 'scale3d') {
7941
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7942
- 1, 1, 1,
7943
- ];
7944
- glMatrix.mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], newScale[2]]);
7945
- }
7946
- else if (t === 'translate') {
7947
- var newTranslation = d || [Opx, Opx];
7948
- glMatrix.mat4.fromTranslation(tmpMat2, [
7949
- newTranslation[0].value,
7950
- newTranslation[1].value,
7951
- 0,
7952
- ]);
7953
- }
7954
- else if (t === 'translatex') {
7955
- var newTranslation = d || [Opx];
7956
- glMatrix.mat4.fromTranslation(tmpMat2, [newTranslation[0].value, 0, 0]);
7957
- }
7958
- else if (t === 'translatey') {
7959
- var newTranslation = d || [Opx];
7960
- glMatrix.mat4.fromTranslation(tmpMat2, [0, newTranslation[0].value, 0]);
7961
- }
7962
- else if (t === 'translatez') {
7963
- var newTranslation = d || [Opx];
7964
- glMatrix.mat4.fromTranslation(tmpMat2, [0, 0, newTranslation[0].value]);
7965
- }
7966
- else if (t === 'translate3d') {
7967
- var newTranslation = d || [Opx, Opx, Opx];
7968
- glMatrix.mat4.fromTranslation(tmpMat2, [
7969
- newTranslation[0].value,
7970
- newTranslation[1].value,
7971
- newTranslation[2].value,
7972
- ]);
7973
- }
7974
- else if (t === 'rotate') {
7975
- var newAngles = d || [Odeg];
7976
- glMatrix.mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7977
- }
7978
- else if (t === 'rotatex') {
7979
- var newAngles = d || [Odeg];
7980
- glMatrix.mat4.fromXRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7981
- }
7982
- else if (t === 'rotatey') {
7983
- var newAngles = d || [Odeg];
7984
- glMatrix.mat4.fromYRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7985
- }
7986
- else if (t === 'rotatez') {
7987
- var newAngles = d || [Odeg];
7988
- glMatrix.mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7989
- }
7990
- else if (t === 'rotate3d') {
7991
- var newAngles = d || [Opx, Opx, Opx, Odeg];
7992
- glMatrix.mat4.fromRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[3])), [
7993
- newAngles[0].value,
7994
- newAngles[1].value,
7995
- newAngles[2].value,
7996
- ]);
7997
- }
7998
- else if (t === 'skew') {
7999
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0, 0];
8000
- createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), deg2rad(newSkew[1]));
8001
- }
8002
- else if (t === 'skewx') {
8003
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
8004
- createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), 0);
8005
- }
8006
- else if (t === 'skewy') {
8007
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
8008
- createSkewMatrix(tmpMat2, 0, deg2rad(newSkew[0]));
8009
- }
8010
- else if (t === 'matrix') {
8011
- var _a = tslib.__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];
8012
- glMatrix.mat4.set(tmpMat2, a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1);
8013
- }
8014
- else if (t === 'matrix3d') {
8015
- // @ts-ignore
8016
- glMatrix.mat4.set.apply(glMatrix.mat4, tslib.__spreadArray([tmpMat2], tslib.__read(d.map(function (s) { return s.value; })), false));
7496
+ if (transform.length === 1 && optimizer[transform[0].t]) {
7497
+ optimizer[transform[0].t](object, transform[0].d);
7498
+ return;
7499
+ }
7500
+ var m = glMatrix.mat4.identity($mat4_2);
7501
+ for (var i = 0; i < transform.length; i++) {
7502
+ var _a = transform[i], t = _a.t, d = _a.d;
7503
+ var p = parser[t];
7504
+ if (p) {
7505
+ p(d);
7506
+ glMatrix.mat4.mul(m, m, $mat4_1);
8017
7507
  }
8018
- glMatrix.mat4.mul(m_1, m_1, tmpMat2);
8019
- });
8020
- object.setLocalTransform(m_1);
7508
+ }
7509
+ object.setLocalTransform(m);
8021
7510
  }
8022
7511
  else {
8023
7512
  object.resetLocalTransform();
@@ -8057,9 +7546,7 @@ function parsedTransformToMat4(transform, object) {
8057
7546
  */
8058
7547
  var CSSPropertyTransform = /** @class */ (function () {
8059
7548
  function CSSPropertyTransform() {
8060
- this.parser = parseTransform;
8061
- this.parserUnmemoize = parseTransformUnmemoize;
8062
- this.parserWithCSSDisabled = parseTransformUnmemoize;
7549
+ this.parser = parseTransformUnmemoize;
8063
7550
  this.mixer = mergeTransforms;
8064
7551
  }
8065
7552
  CSSPropertyTransform.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -8070,8 +7557,7 @@ var CSSPropertyTransform = /** @class */ (function () {
8070
7557
  return parsed;
8071
7558
  };
8072
7559
  CSSPropertyTransform.prototype.postProcessor = function (object) {
8073
- var transform = object.parsedStyle.transform;
8074
- parsedTransformToMat4(transform, object);
7560
+ parsedTransformToMat4(object.parsedStyle.transform, object);
8075
7561
  };
8076
7562
  return CSSPropertyTransform;
8077
7563
  }());
@@ -8083,8 +7569,6 @@ var CSSPropertyTransform = /** @class */ (function () {
8083
7569
  */
8084
7570
  var CSSPropertyTransformOrigin = /** @class */ (function () {
8085
7571
  function CSSPropertyTransformOrigin() {
8086
- this.parser = parseTransformOrigin;
8087
- this.parserUnmemoize = parseTransformOriginUnmemoize;
8088
7572
  }
8089
7573
  CSSPropertyTransformOrigin.prototype.postProcessor = function (object) {
8090
7574
  var transformOrigin = object.parsedStyle.transformOrigin;
@@ -8102,8 +7586,6 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
8102
7586
 
8103
7587
  var CSSPropertyZIndex = /** @class */ (function () {
8104
7588
  function CSSPropertyZIndex() {
8105
- this.parser = parseNumber;
8106
- this.parserUnmemoize = parseNumberUnmemoize;
8107
7589
  }
8108
7590
  CSSPropertyZIndex.prototype.calculator = function (name, oldParsed, computed, object) {
8109
7591
  return computed.value;
@@ -8262,17 +7744,8 @@ var TextUpdater = /** @class */ (function () {
8262
7744
  this.globalRuntime = globalRuntime;
8263
7745
  }
8264
7746
  TextUpdater.prototype.isReadyToMeasure = function (parsedStyle, object) {
8265
- 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;
8266
- return runtime.enableCSSParsing
8267
- ? text &&
8268
- fontSize &&
8269
- fontStyle &&
8270
- fontWeight &&
8271
- fontVariant &&
8272
- textAlign &&
8273
- textBaseline &&
8274
- !util.isNil(lineWidth)
8275
- : text;
7747
+ var text = parsedStyle.text;
7748
+ return text;
8276
7749
  };
8277
7750
  TextUpdater.prototype.update = function (parsedStyle, object) {
8278
7751
  var _a, _b;
@@ -8303,7 +7776,7 @@ var TextUpdater = /** @class */ (function () {
8303
7776
  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;
8304
7777
  var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
8305
7778
  parsedStyle.metrics = metrics;
8306
- var width = metrics.width, height = metrics.height, lineHeight = metrics.lineHeight, fontProperties = metrics.fontProperties;
7779
+ var width = metrics.width, height = metrics.height;
8307
7780
  var hwidth = width / 2;
8308
7781
  var hheight = height / 2;
8309
7782
  // default 'left'
@@ -8316,18 +7789,12 @@ var TextUpdater = /** @class */ (function () {
8316
7789
  }
8317
7790
  var lineYOffset = y - hheight;
8318
7791
  if (textBaseline === 'middle') {
8319
- // eslint-disable-next-line prefer-destructuring
8320
7792
  lineYOffset += hheight;
8321
7793
  }
8322
7794
  else if (textBaseline === 'top' || textBaseline === 'hanging') {
8323
7795
  lineYOffset += hheight * 2;
8324
7796
  }
8325
- else if (textBaseline === 'alphabetic') {
8326
- // prevent calling getImageData for ascent metrics
8327
- lineYOffset += this.globalRuntime.enableCSSParsing
8328
- ? lineHeight - fontProperties.ascent
8329
- : 0;
8330
- }
7797
+ else if (textBaseline === 'alphabetic') ;
8331
7798
  else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
8332
7799
  lineYOffset += 0;
8333
7800
  }
@@ -8783,7 +8250,7 @@ var CustomEvent = /** @class */ (function (_super) {
8783
8250
  return CustomEvent;
8784
8251
  }(FederatedEvent));
8785
8252
 
8786
- var DELEGATION_SPLITTER = ':';
8253
+ var CANVAS_CACHE = new WeakMap();
8787
8254
  /**
8788
8255
  * Objects that can receive events and may have listeners for them.
8789
8256
  * eg. Element, Canvas, DisplayObject
@@ -8809,43 +8276,21 @@ var EventTarget = /** @class */ (function () {
8809
8276
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener
8810
8277
  */
8811
8278
  EventTarget.prototype.addEventListener = function (type, listener, options) {
8812
- var capture = (util.isBoolean(options) && options) || (util.isObject(options) && options.capture);
8813
- var once = util.isObject(options) && options.once;
8814
- var context = isFunction(listener) ? undefined : listener;
8815
- // compatible with G 3.0
8816
- // support using delegate name in event type, eg. 'node:click'
8817
- var useDelegatedName = false;
8818
- var delegatedName = '';
8819
- if (type.indexOf(DELEGATION_SPLITTER) > -1) {
8820
- var _a = tslib.__read(type.split(DELEGATION_SPLITTER), 2), name_1 = _a[0], eventType = _a[1];
8821
- type = eventType;
8822
- delegatedName = name_1;
8823
- useDelegatedName = true;
8824
- }
8825
- type = capture ? "".concat(type, "capture") : type;
8826
- listener = isFunction(listener) ? listener : listener.handleEvent;
8827
- // compatible with G 3.0
8828
- if (useDelegatedName) {
8829
- var originListener_1 = listener;
8830
- listener = function () {
8831
- var _a;
8832
- var args = [];
8833
- for (var _i = 0; _i < arguments.length; _i++) {
8834
- args[_i] = arguments[_i];
8835
- }
8836
- if (((_a = args[0].target) === null || _a === void 0 ? void 0 : _a.name) !== delegatedName) {
8837
- return;
8838
- }
8839
- // @ts-ignore
8840
- originListener_1.apply(void 0, tslib.__spreadArray([], tslib.__read(args), false));
8841
- };
8842
- }
8843
- if (once) {
8279
+ var _a, _b;
8280
+ var capture = false;
8281
+ var once = false;
8282
+ if (util.isBoolean(options))
8283
+ capture = options;
8284
+ else if (options)
8285
+ (_a = options.capture, capture = _a === void 0 ? false : _a, _b = options.once, once = _b === void 0 ? false : _b);
8286
+ if (capture)
8287
+ type += 'capture';
8288
+ listener = util.isFunction(listener) ? listener : listener.handleEvent;
8289
+ var context = util.isFunction(listener) ? undefined : listener;
8290
+ if (once)
8844
8291
  this.emitter.once(type, listener, context);
8845
- }
8846
- else {
8292
+ else
8847
8293
  this.emitter.on(type, listener, context);
8848
- }
8849
8294
  return this;
8850
8295
  };
8851
8296
  /**
@@ -8863,13 +8308,17 @@ var EventTarget = /** @class */ (function () {
8863
8308
  return this;
8864
8309
  };
8865
8310
  EventTarget.prototype.removeAllEventListeners = function () {
8866
- this.emitter.removeAllListeners();
8311
+ var _a;
8312
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
8867
8313
  };
8868
8314
  EventTarget.prototype.removeEventListener = function (type, listener, options) {
8869
- var capture = (util.isBoolean(options) && options) || (util.isObject(options) && options.capture);
8870
- var context = isFunction(listener) ? undefined : listener;
8871
- type = capture ? "".concat(type, "capture") : type;
8872
- listener = isFunction(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
8315
+ if (!this.emitter)
8316
+ return this;
8317
+ var capture = util.isBoolean(options) ? options : options === null || options === void 0 ? void 0 : options.capture;
8318
+ if (capture)
8319
+ type += 'capture';
8320
+ listener = util.isFunction(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
8321
+ var context = util.isFunction(listener) ? undefined : listener;
8873
8322
  this.emitter.off(type, listener, context);
8874
8323
  return this;
8875
8324
  };
@@ -8885,36 +8334,34 @@ var EventTarget = /** @class */ (function () {
8885
8334
  * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
8886
8335
  */
8887
8336
  EventTarget.prototype.dispatchEvent = function (e, skipPropagate) {
8888
- var _a, _b;
8337
+ var _a;
8889
8338
  if (skipPropagate === void 0) { skipPropagate = false; }
8890
- if (!isFederatedEvent(e)) {
8891
- throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
8892
- }
8893
- // should account for Element / Document / Canvas
8894
- var canvas;
8895
- // @ts-ignore
8896
- if (this.document) {
8897
- canvas = this;
8898
- // @ts-ignore
8899
- }
8900
- else if (this.defaultView) {
8901
- canvas = this.defaultView;
8902
- }
8903
- else {
8904
- canvas = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
8339
+ var canvas = CANVAS_CACHE.get(this);
8340
+ if (!canvas) {
8341
+ // @ts-expect-error document may be defined in inherited class
8342
+ if (this.document)
8343
+ canvas = this;
8344
+ // @ts-expect-error defaultView may be defined in inherited class
8345
+ else if (this.defaultView)
8346
+ canvas = this.defaultView;
8347
+ else
8348
+ canvas = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
8349
+ if (canvas)
8350
+ CANVAS_CACHE.set(this, canvas);
8905
8351
  }
8906
- // assign event manager
8907
8352
  if (canvas) {
8908
- e.manager = canvas.getEventService() || null;
8909
- if (!e.manager) {
8353
+ e.manager = canvas.getEventService();
8354
+ if (!e.manager)
8910
8355
  return false;
8911
- }
8912
8356
  e.defaultPrevented = false;
8913
- e.path = [];
8914
- if (!skipPropagate) {
8357
+ if (e.path)
8358
+ e.path.length = 0;
8359
+ // @ts-ignore
8360
+ else
8361
+ e.page = [];
8362
+ if (!skipPropagate)
8915
8363
  e.target = this;
8916
- }
8917
- (_b = e.manager) === null || _b === void 0 ? void 0 : _b.dispatchEvent(e, e.type, skipPropagate);
8364
+ e.manager.dispatchEvent(e, e.type, skipPropagate);
8918
8365
  }
8919
8366
  return !e.defaultPrevented;
8920
8367
  };
@@ -9212,12 +8659,19 @@ var Node = /** @class */ (function (_super) {
9212
8659
  }
9213
8660
  return temp;
9214
8661
  };
9215
- Node.prototype.forEach = function (callback, assigned) {
9216
- if (assigned === void 0) { assigned = false; }
9217
- if (!callback(this)) {
9218
- (assigned ? this.childNodes.slice() : this.childNodes).forEach(function (child) {
9219
- child.forEach(callback);
9220
- });
8662
+ /**
8663
+ * iterate current node and its descendants
8664
+ * @param callback - callback to execute for each node, return false to break
8665
+ * @param assigned - whether to iterate assigned nodes
8666
+ */
8667
+ Node.prototype.forEach = function (callback) {
8668
+ var result = callback(this);
8669
+ if (result !== false) {
8670
+ var nodes = this.childNodes;
8671
+ var length_1 = nodes.length;
8672
+ for (var i = 0; i < length_1; i++) {
8673
+ nodes[i].forEach(callback);
8674
+ }
9221
8675
  }
9222
8676
  };
9223
8677
  /**
@@ -10217,10 +9671,6 @@ var RenderingService = /** @class */ (function () {
10217
9671
  RenderingService.prototype.renderDisplayObject = function (displayObject, canvasConfig, renderingContext) {
10218
9672
  var _this = this;
10219
9673
  var _a = canvasConfig.renderer.getConfig(), enableDirtyCheck = _a.enableDirtyCheck, enableCulling = _a.enableCulling;
10220
- // recalc style values
10221
- if (this.globalRuntime.enableCSSParsing) {
10222
- this.globalRuntime.styleValueRegistry.recalc(displayObject);
10223
- }
10224
9674
  // TODO: relayout
10225
9675
  // dirtycheck first
10226
9676
  var renderable = displayObject.renderable;
@@ -10427,26 +9877,6 @@ var DefaultSceneGraphSelector = /** @class */ (function () {
10427
9877
  return DefaultSceneGraphSelector;
10428
9878
  }());
10429
9879
 
10430
- var MutationEvent = /** @class */ (function (_super) {
10431
- tslib.__extends(MutationEvent, _super);
10432
- function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
10433
- var _this = _super.call(this, null) || this;
10434
- _this.relatedNode = relatedNode;
10435
- _this.prevValue = prevValue;
10436
- _this.newValue = newValue;
10437
- _this.attrName = attrName;
10438
- _this.attrChange = attrChange;
10439
- _this.prevParsedValue = prevParsedValue;
10440
- _this.newParsedValue = newParsedValue;
10441
- _this.type = typeArg;
10442
- return _this;
10443
- }
10444
- MutationEvent.ADDITION = 2;
10445
- MutationEvent.MODIFICATION = 1;
10446
- MutationEvent.REMOVAL = 3;
10447
- return MutationEvent;
10448
- }(FederatedEvent));
10449
-
10450
9880
  /**
10451
9881
  * built-in events for element
10452
9882
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent
@@ -10484,6 +9914,26 @@ exports.ElementEvent = void 0;
10484
9914
  ElementEvent["CULLED"] = "culled";
10485
9915
  })(exports.ElementEvent || (exports.ElementEvent = {}));
10486
9916
 
9917
+ var MutationEvent = /** @class */ (function (_super) {
9918
+ tslib.__extends(MutationEvent, _super);
9919
+ function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
9920
+ var _this = _super.call(this, null) || this;
9921
+ _this.relatedNode = relatedNode;
9922
+ _this.prevValue = prevValue;
9923
+ _this.newValue = newValue;
9924
+ _this.attrName = attrName;
9925
+ _this.attrChange = attrChange;
9926
+ _this.prevParsedValue = prevParsedValue;
9927
+ _this.newParsedValue = newParsedValue;
9928
+ _this.type = typeArg;
9929
+ return _this;
9930
+ }
9931
+ MutationEvent.ADDITION = 2;
9932
+ MutationEvent.MODIFICATION = 1;
9933
+ MutationEvent.REMOVAL = 3;
9934
+ return MutationEvent;
9935
+ }(FederatedEvent));
9936
+
10487
9937
  function markRenderableDirty(e) {
10488
9938
  var renderable = e.renderable;
10489
9939
  if (renderable) {
@@ -10492,260 +9942,45 @@ function markRenderableDirty(e) {
10492
9942
  }
10493
9943
  }
10494
9944
  var reparentEvent = new MutationEvent(exports.ElementEvent.REPARENT, null, '', '', '', 0, '', '');
10495
- /**
10496
- * update transform in scene graph
10497
- *
10498
- * @see https://community.khronos.org/t/scene-graphs/50542/7
10499
- */
10500
- var DefaultSceneGraphService = /** @class */ (function () {
10501
- function DefaultSceneGraphService(runtime) {
10502
- var _this = this;
10503
- this.runtime = runtime;
10504
- this.pendingEvents = [];
10505
- this.boundsChangedEvent = new CustomEvent(exports.ElementEvent.BOUNDS_CHANGED);
10506
- /**
10507
- * rotate in world space
10508
- */
10509
- this.rotate = (function () {
10510
- var parentInvertRotation = glMatrix.quat.create();
10511
- return function (element, degrees, y, z, dirtify) {
10512
- if (y === void 0) { y = 0; }
10513
- if (z === void 0) { z = 0; }
10514
- if (dirtify === void 0) { dirtify = true; }
10515
- if (typeof degrees === 'number') {
10516
- degrees = glMatrix.vec3.fromValues(degrees, y, z);
10517
- }
10518
- var transform = element.transformable;
10519
- if (element.parentNode === null ||
10520
- !element.parentNode.transformable) {
10521
- _this.rotateLocal(element, degrees);
10522
- }
10523
- else {
10524
- var rotation = glMatrix.quat.create();
10525
- glMatrix.quat.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10526
- var rot = _this.getRotation(element);
10527
- var parentRot = _this.getRotation(element.parentNode);
10528
- glMatrix.quat.copy(parentInvertRotation, parentRot);
10529
- glMatrix.quat.invert(parentInvertRotation, parentInvertRotation);
10530
- glMatrix.quat.multiply(rotation, parentInvertRotation, rotation);
10531
- glMatrix.quat.multiply(transform.localRotation, rotation, rot);
10532
- glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10533
- if (dirtify) {
10534
- _this.dirtifyLocal(element, transform);
10535
- }
10536
- }
10537
- };
10538
- })();
10539
- /**
10540
- * rotate in local space
10541
- * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
10542
- */
10543
- this.rotateLocal = (function () {
10544
- var rotation = glMatrix.quat.create();
10545
- return function (element, degrees, y, z, dirtify) {
10546
- if (y === void 0) { y = 0; }
10547
- if (z === void 0) { z = 0; }
10548
- if (dirtify === void 0) { dirtify = true; }
10549
- if (typeof degrees === 'number') {
10550
- degrees = glMatrix.vec3.fromValues(degrees, y, z);
10551
- }
10552
- var transform = element.transformable;
10553
- glMatrix.quat.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10554
- glMatrix.quat.mul(transform.localRotation, transform.localRotation, rotation);
10555
- if (dirtify) {
10556
- _this.dirtifyLocal(element, transform);
10557
- }
10558
- };
10559
- })();
10560
- /**
10561
- * set euler angles(degrees) in world space
10562
- */
10563
- this.setEulerAngles = (function () {
10564
- var invParentRot = glMatrix.quat.create();
10565
- return function (element, degrees, y, z, dirtify) {
10566
- if (y === void 0) { y = 0; }
10567
- if (z === void 0) { z = 0; }
10568
- if (dirtify === void 0) { dirtify = true; }
10569
- if (typeof degrees === 'number') {
10570
- degrees = glMatrix.vec3.fromValues(degrees, y, z);
10571
- }
10572
- var transform = element.transformable;
10573
- if (element.parentNode === null ||
10574
- !element.parentNode.transformable) {
10575
- _this.setLocalEulerAngles(element, degrees);
10576
- }
10577
- else {
10578
- glMatrix.quat.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
10579
- var parentRotation = _this.getRotation(element.parentNode);
10580
- glMatrix.quat.copy(invParentRot, glMatrix.quat.invert(glMatrix.quat.create(), parentRotation));
10581
- glMatrix.quat.mul(transform.localRotation, transform.localRotation, invParentRot);
10582
- if (dirtify) {
10583
- _this.dirtifyLocal(element, transform);
10584
- }
10585
- }
10586
- };
10587
- })();
10588
- /**
10589
- * translate in local space
10590
- *
10591
- * @example
10592
- * ```
10593
- * translateLocal(x, y, z)
10594
- * translateLocal(vec3(x, y, z))
10595
- * ```
10596
- */
10597
- this.translateLocal = (function () {
10598
- return function (element, translation, y, z, dirtify) {
10599
- if (y === void 0) { y = 0; }
10600
- if (z === void 0) { z = 0; }
10601
- if (dirtify === void 0) { dirtify = true; }
10602
- if (typeof translation === 'number') {
10603
- translation = glMatrix.vec3.fromValues(translation, y, z);
10604
- }
10605
- var transform = element.transformable;
10606
- if (glMatrix.vec3.equals(translation, glMatrix.vec3.create())) {
10607
- return;
10608
- }
10609
- glMatrix.vec3.transformQuat(translation, translation, transform.localRotation);
10610
- glMatrix.vec3.add(transform.localPosition, transform.localPosition, translation);
10611
- if (dirtify) {
10612
- _this.dirtifyLocal(element, transform);
10613
- }
10614
- };
10615
- })();
10616
- /**
10617
- * move to position in world space
10618
- *
10619
- * 对应 g 原版的 move/moveTo
10620
- * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
10621
- */
10622
- this.setPosition = (function () {
10623
- var parentInvertMatrix = glMatrix.mat4.create();
10624
- var tmpPosition = glMatrix.vec3.create();
10625
- return function (element, position, dirtify) {
10626
- if (dirtify === void 0) { dirtify = true; }
10627
- var transform = element.transformable;
10628
- tmpPosition[0] = position[0];
10629
- tmpPosition[1] = position[1];
10630
- tmpPosition[2] = position[2] || 0;
10631
- if (glMatrix.vec3.equals(_this.getPosition(element), tmpPosition)) {
10632
- return;
10633
- }
10634
- glMatrix.vec3.copy(transform.position, tmpPosition);
10635
- if (element.parentNode === null ||
10636
- !element.parentNode.transformable) {
10637
- glMatrix.vec3.copy(transform.localPosition, tmpPosition);
10638
- }
10639
- else {
10640
- var parentTransform = element.parentNode.transformable;
10641
- glMatrix.mat4.copy(parentInvertMatrix, parentTransform.worldTransform);
10642
- glMatrix.mat4.invert(parentInvertMatrix, parentInvertMatrix);
10643
- glMatrix.vec3.transformMat4(transform.localPosition, tmpPosition, parentInvertMatrix);
10644
- }
10645
- if (dirtify) {
10646
- _this.dirtifyLocal(element, transform);
10647
- }
10648
- };
10649
- })();
10650
- /**
10651
- * move to position in local space
10652
- */
10653
- this.setLocalPosition = (function () {
10654
- var tmpPosition = glMatrix.vec3.create();
10655
- return function (element, position, dirtify) {
10656
- if (dirtify === void 0) { dirtify = true; }
10657
- var transform = element.transformable;
10658
- tmpPosition[0] = position[0];
10659
- tmpPosition[1] = position[1];
10660
- tmpPosition[2] = position[2] || 0;
10661
- if (glMatrix.vec3.equals(transform.localPosition, tmpPosition)) {
10662
- return;
10663
- }
10664
- glMatrix.vec3.copy(transform.localPosition, tmpPosition);
10665
- if (dirtify) {
10666
- _this.dirtifyLocal(element, transform);
10667
- }
10668
- };
10669
- })();
10670
- /**
10671
- * translate in world space
10672
- *
10673
- * @example
10674
- * ```
10675
- * translate(x, y, z)
10676
- * translate(vec3(x, y, z))
10677
- * ```
10678
- *
10679
- * 对应 g 原版的 translate 2D
10680
- * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
10681
- */
10682
- this.translate = (function () {
10683
- var zeroVec3 = glMatrix.vec3.create();
10684
- var tmpVec3 = glMatrix.vec3.create();
10685
- var tr = glMatrix.vec3.create();
10686
- return function (element, translation, y, z, dirtify) {
10687
- if (y === void 0) { y = 0; }
10688
- if (z === void 0) { z = 0; }
10689
- if (dirtify === void 0) { dirtify = true; }
10690
- if (typeof translation === 'number') {
10691
- translation = glMatrix.vec3.set(tmpVec3, translation, y, z);
10692
- }
10693
- if (glMatrix.vec3.equals(translation, zeroVec3)) {
10694
- return;
10695
- }
10696
- glMatrix.vec3.add(tr, _this.getPosition(element), translation);
10697
- _this.setPosition(element, tr, dirtify);
10698
- };
10699
- })();
10700
- this.setRotation = function () {
10701
- var parentInvertRotation = glMatrix.quat.create();
10702
- return function (element, rotation, y, z, w, dirtify) {
10703
- if (dirtify === void 0) { dirtify = true; }
10704
- var transform = element.transformable;
10705
- if (typeof rotation === 'number') {
10706
- rotation = glMatrix.quat.fromValues(rotation, y, z, w);
10707
- }
10708
- if (element.parentNode === null ||
10709
- !element.parentNode.transformable) {
10710
- _this.setLocalRotation(element, rotation);
10711
- }
10712
- else {
10713
- var parentRot = _this.getRotation(element.parentNode);
10714
- glMatrix.quat.copy(parentInvertRotation, parentRot);
10715
- glMatrix.quat.invert(parentInvertRotation, parentInvertRotation);
10716
- glMatrix.quat.multiply(transform.localRotation, parentInvertRotation, rotation);
10717
- glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10718
- if (dirtify) {
10719
- _this.dirtifyLocal(element, transform);
10720
- }
10721
- }
10722
- };
10723
- };
9945
+ // Object pooling
9946
+ /** do not modify this objects */
9947
+ var $vec2Zero = glMatrix.vec2.create();
9948
+ /** do not modify this objects */
9949
+ var $vec3Zero = glMatrix.vec3.create();
9950
+ /** do not modify this objects */
9951
+ var $vec3One = glMatrix.vec3.fromValues(1, 1, 1);
9952
+ /** do not modify this objects */
9953
+ var $mat4Identity = glMatrix.mat4.create();
9954
+ /** shared objects */
9955
+ var $vec2 = glMatrix.vec2.create();
9956
+ /** shared objects */
9957
+ var $vec3$1 = glMatrix.vec3.create();
9958
+ /** shared objects */
9959
+ var $mat4 = glMatrix.mat4.create();
9960
+ /** shared objects */
9961
+ var $quat$1 = glMatrix.quat.create();
9962
+ var $setLocalTransform_1 = glMatrix.vec3.create();
9963
+ var $setLocalTransform_2 = glMatrix.quat.create();
9964
+ var $setLocalTransform_3 = glMatrix.vec3.create();
9965
+ var $setLocalPosition = glMatrix.vec3.create();
9966
+ var $setPosition_1 = glMatrix.vec3.create();
9967
+ var $setPosition_ParentInvertMatrix = glMatrix.mat4.create();
9968
+ var $setEulerAngles_InvParentRot = glMatrix.quat.create();
9969
+ var $rotateLocal = glMatrix.quat.create();
9970
+ var $rotate_ParentInvertRotation = glMatrix.quat.create();
9971
+ var $triggerPendingEvents_detail = { affectChildren: true };
9972
+ /**
9973
+ * update transform in scene graph
9974
+ *
9975
+ * @see https://community.khronos.org/t/scene-graphs/50542/7
9976
+ */
9977
+ var DefaultSceneGraphService = /** @class */ (function () {
9978
+ function DefaultSceneGraphService(runtime) {
9979
+ this.runtime = runtime;
9980
+ // target -> affectChildren
9981
+ this.pendingEvents = new Map();
9982
+ this.boundsChangedEvent = new CustomEvent(exports.ElementEvent.BOUNDS_CHANGED);
10724
9983
  this.displayObjectDependencyMap = new WeakMap();
10725
- this.calcLocalTransform = (function () {
10726
- var tmpMat = glMatrix.mat4.create();
10727
- var tmpPosition = glMatrix.vec3.create();
10728
- var tmpQuat = glMatrix.quat.fromValues(0, 0, 0, 1);
10729
- return function (transform) {
10730
- var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
10731
- if (hasSkew) {
10732
- glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, glMatrix.vec3.fromValues(1, 1, 1), transform.origin);
10733
- // apply skew2D
10734
- if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
10735
- var tmpMat4 = glMatrix.mat4.identity(tmpMat);
10736
- tmpMat4[4] = Math.tan(transform.localSkew[0]);
10737
- tmpMat4[1] = Math.tan(transform.localSkew[1]);
10738
- glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, tmpMat4);
10739
- }
10740
- var scaling = glMatrix.mat4.fromRotationTranslationScaleOrigin(tmpMat, tmpQuat, tmpPosition, transform.localScale, transform.origin);
10741
- glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, scaling);
10742
- }
10743
- else {
10744
- // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
10745
- glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, transform.localScale, transform.origin);
10746
- }
10747
- };
10748
- })();
10749
9984
  }
10750
9985
  DefaultSceneGraphService.prototype.matches = function (query, root) {
10751
9986
  return this.runtime.sceneGraphSelector.is(query, root);
@@ -10764,12 +9999,23 @@ var DefaultSceneGraphService = /** @class */ (function () {
10764
9999
  detached = child.parentNode !== parent;
10765
10000
  this.detach(child);
10766
10001
  }
10002
+ var isChildFragment = child.nodeName === exports.Shape.FRAGMENT;
10003
+ var isAttachToFragment = isInFragment(parent);
10767
10004
  child.parentNode = parent;
10768
- if (!util.isNil(index)) {
10769
- child.parentNode.childNodes.splice(index, 0, child);
10005
+ var nodes = isChildFragment
10006
+ ? child.childNodes
10007
+ : [child];
10008
+ if (util.isNumber(index)) {
10009
+ nodes.forEach(function (node) {
10010
+ parent.childNodes.splice(index, 0, node);
10011
+ node.parentNode = parent;
10012
+ });
10770
10013
  }
10771
10014
  else {
10772
- child.parentNode.childNodes.push(child);
10015
+ nodes.forEach(function (node) {
10016
+ parent.childNodes.push(node);
10017
+ node.parentNode = parent;
10018
+ });
10773
10019
  }
10774
10020
  // parent needs re-sort
10775
10021
  var sortable = parent.sortable;
@@ -10783,13 +10029,15 @@ var DefaultSceneGraphService = /** @class */ (function () {
10783
10029
  sortable.dirty = true;
10784
10030
  sortable.dirtyReason = exports.SortReason.ADDED;
10785
10031
  }
10786
- // this.updateGraphDepth(child);
10787
- var transform = child.transformable;
10788
- if (transform) {
10789
- this.dirtifyWorld(child, transform);
10790
- }
10791
- if (transform.frozen) {
10792
- this.unfreezeParentToRoot(child);
10032
+ if (isAttachToFragment)
10033
+ return;
10034
+ if (isChildFragment)
10035
+ this.dirtifyFragment(child);
10036
+ else {
10037
+ var transform = child.transformable;
10038
+ if (transform) {
10039
+ this.dirtifyWorld(child, transform);
10040
+ }
10793
10041
  }
10794
10042
  if (detached) {
10795
10043
  child.dispatchEvent(reparentEvent);
@@ -10857,6 +10105,70 @@ var DefaultSceneGraphService = /** @class */ (function () {
10857
10105
  originVec[2] = origin[2] || 0;
10858
10106
  this.dirtifyLocal(element, transform);
10859
10107
  };
10108
+ /**
10109
+ * rotate in world space
10110
+ */
10111
+ DefaultSceneGraphService.prototype.rotate = function (element, degrees, y, z) {
10112
+ if (y === void 0) { y = 0; }
10113
+ if (z === void 0) { z = 0; }
10114
+ if (typeof degrees === 'number') {
10115
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10116
+ }
10117
+ var transform = element.transformable;
10118
+ if (element.parentNode === null ||
10119
+ !element.parentNode.transformable) {
10120
+ this.rotateLocal(element, degrees);
10121
+ }
10122
+ else {
10123
+ var rotation = $quat$1;
10124
+ glMatrix.quat.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10125
+ var rot = this.getRotation(element);
10126
+ var parentRot = this.getRotation(element.parentNode);
10127
+ glMatrix.quat.copy($rotate_ParentInvertRotation, parentRot);
10128
+ glMatrix.quat.invert($rotate_ParentInvertRotation, $rotate_ParentInvertRotation);
10129
+ glMatrix.quat.multiply(rotation, $rotate_ParentInvertRotation, rotation);
10130
+ glMatrix.quat.multiply(transform.localRotation, rotation, rot);
10131
+ glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10132
+ this.dirtifyLocal(element, transform);
10133
+ }
10134
+ };
10135
+ /**
10136
+ * rotate in local space
10137
+ * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
10138
+ */
10139
+ DefaultSceneGraphService.prototype.rotateLocal = function (element, degrees, y, z) {
10140
+ if (y === void 0) { y = 0; }
10141
+ if (z === void 0) { z = 0; }
10142
+ if (typeof degrees === 'number') {
10143
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10144
+ }
10145
+ var transform = element.transformable;
10146
+ glMatrix.quat.fromEuler($rotateLocal, degrees[0], degrees[1], degrees[2]);
10147
+ glMatrix.quat.mul(transform.localRotation, transform.localRotation, $rotateLocal);
10148
+ this.dirtifyLocal(element, transform);
10149
+ };
10150
+ /**
10151
+ * set euler angles(degrees) in world space
10152
+ */
10153
+ DefaultSceneGraphService.prototype.setEulerAngles = function (element, degrees, y, z) {
10154
+ if (y === void 0) { y = 0; }
10155
+ if (z === void 0) { z = 0; }
10156
+ if (typeof degrees === 'number') {
10157
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10158
+ }
10159
+ var transform = element.transformable;
10160
+ if (element.parentNode === null ||
10161
+ !element.parentNode.transformable) {
10162
+ this.setLocalEulerAngles(element, degrees);
10163
+ }
10164
+ else {
10165
+ glMatrix.quat.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
10166
+ var parentRotation = this.getRotation(element.parentNode);
10167
+ glMatrix.quat.copy($setEulerAngles_InvParentRot, glMatrix.quat.invert($quat$1, parentRotation));
10168
+ glMatrix.quat.mul(transform.localRotation, transform.localRotation, $setEulerAngles_InvParentRot);
10169
+ this.dirtifyLocal(element, transform);
10170
+ }
10171
+ };
10860
10172
  /**
10861
10173
  * set euler angles(degrees) in local space
10862
10174
  */
@@ -10874,32 +10186,140 @@ var DefaultSceneGraphService = /** @class */ (function () {
10874
10186
  }
10875
10187
  };
10876
10188
  /**
10877
- * scale in local space
10189
+ * translate in local space
10190
+ *
10191
+ * @example
10192
+ * ```
10193
+ * translateLocal(x, y, z)
10194
+ * translateLocal(vec3(x, y, z))
10195
+ * ```
10196
+ */
10197
+ DefaultSceneGraphService.prototype.translateLocal = function (element, translation, y, z) {
10198
+ if (y === void 0) { y = 0; }
10199
+ if (z === void 0) { z = 0; }
10200
+ if (typeof translation === 'number') {
10201
+ translation = glMatrix.vec3.fromValues(translation, y, z);
10202
+ }
10203
+ var transform = element.transformable;
10204
+ if (glMatrix.vec3.equals(translation, $vec3Zero))
10205
+ return;
10206
+ glMatrix.vec3.transformQuat(translation, translation, transform.localRotation);
10207
+ glMatrix.vec3.add(transform.localPosition, transform.localPosition, translation);
10208
+ this.dirtifyLocal(element, transform);
10209
+ };
10210
+ /**
10211
+ * move to position in world space
10212
+ *
10213
+ * 对应 g 原版的 move/moveTo
10214
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
10215
+ */
10216
+ DefaultSceneGraphService.prototype.setPosition = function (element, position) {
10217
+ var _a;
10218
+ var transform = element.transformable;
10219
+ $setPosition_1[0] = position[0];
10220
+ $setPosition_1[1] = position[1];
10221
+ $setPosition_1[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10222
+ if (glMatrix.vec3.equals(this.getPosition(element), $setPosition_1)) {
10223
+ return;
10224
+ }
10225
+ glMatrix.vec3.copy(transform.position, $setPosition_1);
10226
+ if (element.parentNode === null ||
10227
+ !element.parentNode.transformable) {
10228
+ glMatrix.vec3.copy(transform.localPosition, $setPosition_1);
10229
+ }
10230
+ else {
10231
+ var parentTransform = element.parentNode.transformable;
10232
+ glMatrix.mat4.copy($setPosition_ParentInvertMatrix, parentTransform.worldTransform);
10233
+ glMatrix.mat4.invert($setPosition_ParentInvertMatrix, $setPosition_ParentInvertMatrix);
10234
+ glMatrix.vec3.transformMat4(transform.localPosition, $setPosition_1, $setPosition_ParentInvertMatrix);
10235
+ }
10236
+ this.dirtifyLocal(element, transform);
10237
+ };
10238
+ /**
10239
+ * move to position in local space
10878
10240
  */
10879
- DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling, dirtify) {
10241
+ DefaultSceneGraphService.prototype.setLocalPosition = function (element, position, dirtify) {
10242
+ var _a;
10880
10243
  if (dirtify === void 0) { dirtify = true; }
10881
10244
  var transform = element.transformable;
10882
- glMatrix.vec3.multiply(transform.localScale, transform.localScale, glMatrix.vec3.fromValues(scaling[0], scaling[1], scaling[2] || 1));
10245
+ $setLocalPosition[0] = position[0];
10246
+ $setLocalPosition[1] = position[1];
10247
+ $setLocalPosition[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10248
+ if (glMatrix.vec3.equals(transform.localPosition, $setLocalPosition)) {
10249
+ return;
10250
+ }
10251
+ glMatrix.vec3.copy(transform.localPosition, $setLocalPosition);
10883
10252
  if (dirtify) {
10884
10253
  this.dirtifyLocal(element, transform);
10885
10254
  }
10886
10255
  };
10256
+ /**
10257
+ * scale in local space
10258
+ */
10259
+ DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling) {
10260
+ var _a;
10261
+ var transform = element.transformable;
10262
+ glMatrix.vec3.multiply(transform.localScale, transform.localScale, glMatrix.vec3.set($vec3$1, scaling[0], scaling[1], (_a = scaling[2]) !== null && _a !== void 0 ? _a : 1));
10263
+ this.dirtifyLocal(element, transform);
10264
+ };
10887
10265
  DefaultSceneGraphService.prototype.setLocalScale = function (element, scaling, dirtify) {
10266
+ var _a;
10888
10267
  if (dirtify === void 0) { dirtify = true; }
10889
10268
  var transform = element.transformable;
10890
- var updatedScaling = glMatrix.vec3.fromValues(scaling[0], scaling[1], scaling[2] || transform.localScale[2]);
10891
- if (glMatrix.vec3.equals(updatedScaling, transform.localScale)) {
10269
+ glMatrix.vec3.set($vec3$1, scaling[0], scaling[1], (_a = scaling[2]) !== null && _a !== void 0 ? _a : transform.localScale[2]);
10270
+ if (glMatrix.vec3.equals($vec3$1, transform.localScale)) {
10892
10271
  return;
10893
10272
  }
10894
- glMatrix.vec3.copy(transform.localScale, updatedScaling);
10273
+ glMatrix.vec3.copy(transform.localScale, $vec3$1);
10895
10274
  if (dirtify) {
10896
10275
  this.dirtifyLocal(element, transform);
10897
10276
  }
10898
10277
  };
10278
+ /**
10279
+ * translate in world space
10280
+ *
10281
+ * @example
10282
+ * ```
10283
+ * translate(x, y, z)
10284
+ * translate(vec3(x, y, z))
10285
+ * ```
10286
+ *
10287
+ * 对应 g 原版的 translate 2D
10288
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
10289
+ */
10290
+ DefaultSceneGraphService.prototype.translate = function (element, translation, y, z) {
10291
+ if (y === void 0) { y = 0; }
10292
+ if (z === void 0) { z = 0; }
10293
+ if (typeof translation === 'number') {
10294
+ translation = glMatrix.vec3.set($vec3$1, translation, y, z);
10295
+ }
10296
+ if (glMatrix.vec3.equals(translation, $vec3Zero))
10297
+ return;
10298
+ glMatrix.vec3.add($vec3$1, this.getPosition(element), translation);
10299
+ this.setPosition(element, $vec3$1);
10300
+ };
10301
+ DefaultSceneGraphService.prototype.setRotation = function (element, rotation, y, z, w) {
10302
+ var transform = element.transformable;
10303
+ if (typeof rotation === 'number') {
10304
+ rotation = glMatrix.quat.fromValues(rotation, y, z, w);
10305
+ }
10306
+ if (element.parentNode === null ||
10307
+ !element.parentNode.transformable) {
10308
+ this.setLocalRotation(element, rotation);
10309
+ }
10310
+ else {
10311
+ var parentRot = this.getRotation(element.parentNode);
10312
+ glMatrix.quat.copy($quat$1, parentRot);
10313
+ glMatrix.quat.invert($quat$1, $quat$1);
10314
+ glMatrix.quat.multiply(transform.localRotation, $quat$1, rotation);
10315
+ glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10316
+ this.dirtifyLocal(element, transform);
10317
+ }
10318
+ };
10899
10319
  DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w, dirtify) {
10900
10320
  if (dirtify === void 0) { dirtify = true; }
10901
10321
  if (typeof rotation === 'number') {
10902
- rotation = glMatrix.quat.fromValues(rotation, y, z, w);
10322
+ rotation = glMatrix.quat.set($quat$1, rotation, y, z, w);
10903
10323
  }
10904
10324
  var transform = element.transformable;
10905
10325
  glMatrix.quat.copy(transform.localRotation, rotation);
@@ -10907,15 +10327,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
10907
10327
  this.dirtifyLocal(element, transform);
10908
10328
  }
10909
10329
  };
10910
- DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y) {
10330
+ DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y, dirtify) {
10331
+ if (dirtify === void 0) { dirtify = true; }
10911
10332
  if (typeof skew === 'number') {
10912
- skew = glMatrix.vec2.fromValues(skew, y);
10333
+ skew = glMatrix.vec2.set($vec2, skew, y);
10913
10334
  }
10914
10335
  var transform = element.transformable;
10915
10336
  glMatrix.vec2.copy(transform.localSkew, skew);
10916
- this.dirtifyLocal(element, transform);
10337
+ if (dirtify) {
10338
+ this.dirtifyLocal(element, transform);
10339
+ }
10917
10340
  };
10918
10341
  DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
10342
+ if (isInFragment(element))
10343
+ return;
10919
10344
  if (!transform.localDirtyFlag) {
10920
10345
  transform.localDirtyFlag = true;
10921
10346
  if (!transform.dirtyFlag) {
@@ -10930,11 +10355,43 @@ var DefaultSceneGraphService = /** @class */ (function () {
10930
10355
  this.dirtifyWorldInternal(element, transform);
10931
10356
  this.dirtifyToRoot(element, true);
10932
10357
  };
10358
+ DefaultSceneGraphService.prototype.dirtifyFragment = function (element) {
10359
+ var transform = element.transformable;
10360
+ if (transform) {
10361
+ transform.frozen = false;
10362
+ transform.dirtyFlag = true;
10363
+ transform.localDirtyFlag = true;
10364
+ }
10365
+ var renderable = element.renderable;
10366
+ if (renderable) {
10367
+ renderable.renderBoundsDirty = true;
10368
+ renderable.boundsDirty = true;
10369
+ renderable.dirty = true;
10370
+ }
10371
+ var length = element.childNodes.length;
10372
+ for (var i = 0; i < length; i++) {
10373
+ this.dirtifyFragment(element.childNodes[i]);
10374
+ }
10375
+ if (element.nodeName === exports.Shape.FRAGMENT) {
10376
+ this.pendingEvents.set(element, false);
10377
+ }
10378
+ };
10933
10379
  DefaultSceneGraphService.prototype.triggerPendingEvents = function () {
10934
10380
  var _this = this;
10935
- var set = new Set();
10381
+ var triggered = new Set();
10382
+ var skipped = new Set();
10383
+ this.pendingEvents.forEach(function (_, element) {
10384
+ if (element.nodeName === exports.Shape.FRAGMENT) {
10385
+ element.forEach(function (e) {
10386
+ if (e !== element)
10387
+ skipped.add(e);
10388
+ });
10389
+ }
10390
+ });
10936
10391
  var trigger = function (element, detail) {
10937
- if (element.isConnected && !set.has(element.entity)) {
10392
+ if (element.isConnected &&
10393
+ !triggered.has(element) &&
10394
+ !skipped.has(element)) {
10938
10395
  _this.boundsChangedEvent.detail = detail;
10939
10396
  _this.boundsChangedEvent.target = element;
10940
10397
  if (element.isMutationObserved) {
@@ -10943,25 +10400,25 @@ var DefaultSceneGraphService = /** @class */ (function () {
10943
10400
  else {
10944
10401
  element.ownerDocument.defaultView.dispatchEvent(_this.boundsChangedEvent, true);
10945
10402
  }
10946
- set.add(element.entity);
10403
+ triggered.add(element);
10947
10404
  }
10948
10405
  };
10949
- this.pendingEvents.forEach(function (_a) {
10950
- var _b = tslib.__read(_a, 2), element = _b[0], detail = _b[1];
10951
- if (detail.affectChildren) {
10406
+ this.pendingEvents.forEach(function (affectChildren, element) {
10407
+ $triggerPendingEvents_detail.affectChildren = affectChildren;
10408
+ if (affectChildren) {
10952
10409
  element.forEach(function (e) {
10953
- trigger(e, detail);
10410
+ trigger(e, $triggerPendingEvents_detail);
10954
10411
  });
10955
10412
  }
10956
- else {
10957
- trigger(element, detail);
10958
- }
10413
+ else
10414
+ trigger(element, $triggerPendingEvents_detail);
10959
10415
  });
10416
+ triggered.clear();
10417
+ skipped.clear();
10960
10418
  this.clearPendingEvents();
10961
- set.clear();
10962
10419
  };
10963
10420
  DefaultSceneGraphService.prototype.clearPendingEvents = function () {
10964
- this.pendingEvents = [];
10421
+ this.pendingEvents.clear();
10965
10422
  };
10966
10423
  DefaultSceneGraphService.prototype.dirtifyToRoot = function (element, affectChildren) {
10967
10424
  if (affectChildren === void 0) { affectChildren = false; }
@@ -10979,10 +10436,8 @@ var DefaultSceneGraphService = /** @class */ (function () {
10979
10436
  markRenderableDirty(e);
10980
10437
  });
10981
10438
  }
10982
- // inform dependencies
10983
10439
  this.informDependentDisplayObjects(element);
10984
- // reuse the same custom event
10985
- this.pendingEvents.push([element, { affectChildren: affectChildren }]);
10440
+ this.pendingEvents.set(element, affectChildren);
10986
10441
  };
10987
10442
  DefaultSceneGraphService.prototype.updateDisplayObjectDependency = function (name, oldPath, newPath, object) {
10988
10443
  // clear ref to old clip path
@@ -11057,6 +10512,45 @@ var DefaultSceneGraphService = /** @class */ (function () {
11057
10512
  DefaultSceneGraphService.prototype.getLocalSkew = function (element) {
11058
10513
  return element.transformable.localSkew;
11059
10514
  };
10515
+ DefaultSceneGraphService.prototype.calcLocalTransform = function (transform) {
10516
+ var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
10517
+ if (hasSkew) {
10518
+ glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, glMatrix.vec3.fromValues(1, 1, 1), transform.origin);
10519
+ // apply skew2D
10520
+ if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
10521
+ glMatrix.mat4.identity($mat4);
10522
+ $mat4[4] = Math.tan(transform.localSkew[0]);
10523
+ $mat4[1] = Math.tan(transform.localSkew[1]);
10524
+ glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, $mat4);
10525
+ }
10526
+ var scaling = glMatrix.mat4.fromRotationTranslationScaleOrigin($mat4, glMatrix.quat.set($quat$1, 0, 0, 0, 1), glMatrix.vec3.set($vec3$1, 1, 1, 1), transform.localScale, transform.origin);
10527
+ glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, scaling);
10528
+ }
10529
+ else {
10530
+ var localTransform = transform.localTransform, localPosition = transform.localPosition, localRotation = transform.localRotation, localScale = transform.localScale, origin_1 = transform.origin;
10531
+ var hasPosition = localPosition[0] !== 0 ||
10532
+ localPosition[1] !== 0 ||
10533
+ localPosition[2] !== 0;
10534
+ var hasRotation = localRotation[3] !== 1 ||
10535
+ localRotation[0] !== 0 ||
10536
+ localRotation[1] !== 0 ||
10537
+ localRotation[2] !== 0;
10538
+ var hasScale = localScale[0] !== 1 || localScale[1] !== 1 || localScale[2] !== 1;
10539
+ var hasOrigin = origin_1[0] !== 0 || origin_1[1] !== 0 || origin_1[2] !== 0;
10540
+ if (!hasRotation && !hasScale && !hasOrigin) {
10541
+ if (hasPosition) {
10542
+ glMatrix.mat4.fromTranslation(localTransform, localPosition);
10543
+ }
10544
+ else {
10545
+ glMatrix.mat4.identity(localTransform);
10546
+ }
10547
+ }
10548
+ else {
10549
+ // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
10550
+ glMatrix.mat4.fromRotationTranslationScaleOrigin(localTransform, localRotation, localPosition, localScale, origin_1);
10551
+ }
10552
+ }
10553
+ };
11060
10554
  DefaultSceneGraphService.prototype.getLocalTransform = function (element) {
11061
10555
  var transform = element.transformable;
11062
10556
  if (transform.localDirtyFlag) {
@@ -11066,19 +10560,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
11066
10560
  return transform.localTransform;
11067
10561
  };
11068
10562
  DefaultSceneGraphService.prototype.setLocalTransform = function (element, transform) {
11069
- var t = glMatrix.mat4.getTranslation(glMatrix.vec3.create(), transform);
11070
- var r = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform);
11071
- var s = glMatrix.mat4.getScaling(glMatrix.vec3.create(), transform);
10563
+ var t = glMatrix.mat4.getTranslation($setLocalTransform_1, transform);
10564
+ var r = glMatrix.mat4.getRotation($setLocalTransform_2, transform);
10565
+ var s = glMatrix.mat4.getScaling($setLocalTransform_3, transform);
11072
10566
  this.setLocalScale(element, s, false);
11073
10567
  this.setLocalPosition(element, t, false);
11074
10568
  this.setLocalRotation(element, r, undefined, undefined, undefined, false);
11075
10569
  this.dirtifyLocal(element, element.transformable);
11076
10570
  };
11077
10571
  DefaultSceneGraphService.prototype.resetLocalTransform = function (element) {
11078
- this.setLocalScale(element, [1, 1, 1]);
11079
- this.setLocalPosition(element, [0, 0, 0]);
11080
- this.setLocalEulerAngles(element, [0, 0, 0]);
11081
- this.setLocalSkew(element, [0, 0]);
10572
+ this.setLocalScale(element, $vec3One, false);
10573
+ this.setLocalPosition(element, $vec3Zero, false);
10574
+ this.setLocalEulerAngles(element, $vec3Zero, undefined, undefined, false);
10575
+ this.setLocalSkew(element, $vec2Zero, undefined, false);
10576
+ this.dirtifyLocal(element, element.transformable);
11082
10577
  };
11083
10578
  DefaultSceneGraphService.prototype.getTransformedGeometryBounds = function (element, render, existedAABB) {
11084
10579
  if (render === void 0) { render = false; }
@@ -11170,9 +10665,9 @@ var DefaultSceneGraphService = /** @class */ (function () {
11170
10665
  */
11171
10666
  DefaultSceneGraphService.prototype.getLocalBounds = function (element) {
11172
10667
  if (element.parentNode) {
11173
- var parentInvert = glMatrix.mat4.create();
10668
+ var parentInvert = $mat4Identity;
11174
10669
  if (element.parentNode.transformable) {
11175
- parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), this.getWorldTransform(element.parentNode));
10670
+ parentInvert = glMatrix.mat4.invert($mat4, this.getWorldTransform(element.parentNode));
11176
10671
  }
11177
10672
  var bounds = this.getBounds(element);
11178
10673
  if (!AABB.isEmpty(bounds)) {
@@ -11425,19 +10920,12 @@ var TextService = /** @class */ (function () {
11425
10920
  // dropShadowDistance = 0,
11426
10921
  leading = _g === void 0 ? 0 : _g;
11427
10922
  var font = toFontString(parsedStyle);
11428
- // if (runtime.enableCSSParsing) {
11429
10923
  var fontProperties = this.measureFont(font, offscreenCanvas);
11430
10924
  // fallback in case UA disallow canvas data extraction
11431
- // (toDataURI, getImageData functions)
11432
10925
  if (fontProperties.fontSize === 0) {
11433
10926
  fontProperties.fontSize = fontSize;
11434
10927
  fontProperties.ascent = fontSize;
11435
10928
  }
11436
- // } else {
11437
- // fontProperties = {
11438
- // fontSize,
11439
- // };
11440
- // }
11441
10929
  var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11442
10930
  context.font = font;
11443
10931
  // no overflowing by default
@@ -11759,10 +11247,7 @@ runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
11759
11247
  runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime);
11760
11248
  runtime.layoutRegistry = null;
11761
11249
  runtime.globalThis = getGlobalThis();
11762
- runtime.enableCSSParsing = false;
11763
- runtime.enableDataset = false;
11764
11250
  runtime.enableStyleSyntax = true;
11765
- runtime.enableAttributeDashCased = false;
11766
11251
  runtime.enableSizeAttenuation = false;
11767
11252
 
11768
11253
  var entityCounter = 0;
@@ -11851,34 +11336,7 @@ var Element = /** @class */ (function (_super) {
11851
11336
  * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
11852
11337
  */
11853
11338
  _this.style = {};
11854
- _this.computedStyle = runtime.enableCSSParsing
11855
- ? {
11856
- opacity: unsetKeywordValue,
11857
- fillOpacity: unsetKeywordValue,
11858
- strokeOpacity: unsetKeywordValue,
11859
- fill: unsetKeywordValue,
11860
- stroke: unsetKeywordValue,
11861
- transform: unsetKeywordValue,
11862
- transformOrigin: unsetKeywordValue,
11863
- visibility: unsetKeywordValue,
11864
- pointerEvents: unsetKeywordValue,
11865
- lineWidth: unsetKeywordValue,
11866
- lineCap: unsetKeywordValue,
11867
- lineJoin: unsetKeywordValue,
11868
- increasedLineWidthForHitTesting: unsetKeywordValue,
11869
- fontSize: unsetKeywordValue,
11870
- fontFamily: unsetKeywordValue,
11871
- fontStyle: unsetKeywordValue,
11872
- fontWeight: unsetKeywordValue,
11873
- fontVariant: unsetKeywordValue,
11874
- textAlign: unsetKeywordValue,
11875
- textBaseline: unsetKeywordValue,
11876
- textTransform: unsetKeywordValue,
11877
- zIndex: unsetKeywordValue,
11878
- filter: unsetKeywordValue,
11879
- shadowType: unsetKeywordValue,
11880
- }
11881
- : null;
11339
+ _this.computedStyle = {};
11882
11340
  /**
11883
11341
  * Renderers will use these used values.
11884
11342
  */
@@ -12007,7 +11465,12 @@ var Element = /** @class */ (function (_super) {
12007
11465
  }
12008
11466
  runtime.sceneGraphService.attach(child, this, index);
12009
11467
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
12010
- this.ownerDocument.defaultView.mountChildren(child);
11468
+ if (!isInFragment(this) && child.nodeName === exports.Shape.FRAGMENT) {
11469
+ this.ownerDocument.defaultView.mountFragment(child);
11470
+ }
11471
+ else {
11472
+ this.ownerDocument.defaultView.mountChildren(child);
11473
+ }
12011
11474
  }
12012
11475
  // @ts-ignore
12013
11476
  if (this.isMutationObserved) {
@@ -12121,9 +11584,9 @@ var Element = /** @class */ (function (_super) {
12121
11584
  this.forEach(function (object) {
12122
11585
  if (object !== _this && filter(object)) {
12123
11586
  target = object;
12124
- return true;
11587
+ return false;
12125
11588
  }
12126
- return false;
11589
+ return true;
12127
11590
  });
12128
11591
  return target;
12129
11592
  };
@@ -12281,17 +11744,13 @@ var Element = /** @class */ (function (_super) {
12281
11744
  */
12282
11745
  Element.prototype.getAttribute = function (name) {
12283
11746
  // @see https://github.com/antvis/G/issues/1267
12284
- if (isSymbol(name)) {
12285
- return runtime.enableCSSParsing ? null : undefined;
11747
+ if (typeof name === 'symbol') {
11748
+ return undefined;
12286
11749
  }
12287
11750
  var value = this.attributes[name];
12288
11751
  if (value === undefined) {
12289
- if (runtime.enableAttributeDashCased) {
12290
- var attributeName = formatAttributeName(name);
12291
- value = this.attributes[attributeName];
12292
- }
12293
11752
  // if the given attribute does not exist, the value returned will either be null or ""
12294
- return runtime.enableCSSParsing ? (util.isNil(value) ? null : value) : value;
11753
+ return value;
12295
11754
  }
12296
11755
  else {
12297
11756
  return value;
@@ -12363,78 +11822,8 @@ var Proxy = runtime.globalThis.Proxy
12363
11822
  ? runtime.globalThis.Proxy
12364
11823
  : function () { };
12365
11824
  var mutationEvent = new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, null, null, null, null, MutationEvent.MODIFICATION, null, null);
12366
- var DEFAULT_STYLE_PROPS = {
12367
- opacity: '',
12368
- fillOpacity: '',
12369
- strokeOpacity: '',
12370
- fill: '',
12371
- stroke: '',
12372
- transform: '',
12373
- transformOrigin: '',
12374
- visibility: '',
12375
- pointerEvents: '',
12376
- lineWidth: '',
12377
- lineCap: '',
12378
- lineJoin: '',
12379
- increasedLineWidthForHitTesting: '',
12380
- fontSize: '',
12381
- fontFamily: '',
12382
- fontStyle: '',
12383
- fontWeight: '',
12384
- fontVariant: '',
12385
- textAlign: '',
12386
- textBaseline: '',
12387
- textTransform: '',
12388
- zIndex: '',
12389
- filter: '',
12390
- shadowType: '',
12391
- };
12392
- var DEFAULT_PARSED_STYLE_PROPS = {
12393
- fill: noneColor,
12394
- stroke: noneColor,
12395
- transform: [],
12396
- zIndex: 0,
12397
- filter: [],
12398
- shadowType: 'outer',
12399
- miterLimit: 10,
12400
- };
12401
- // const DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = {
12402
- // ...DEFAULT_PARSED_STYLE_PROPS,
12403
- // opacity: 1,
12404
- // fillOpacity: 1,
12405
- // strokeOpacity: 1,
12406
- // visibility: 'visible',
12407
- // pointerEvents: 'auto',
12408
- // lineWidth: 1,
12409
- // lineCap: 'butt',
12410
- // lineJoin: 'miter',
12411
- // increasedLineWidthForHitTesting: 0,
12412
- // fillRule: 'nonzero',
12413
- // // TODO: transformOrigin
12414
- // };
12415
- var INHERITABLE_BASE_STYLE_PROPS = [
12416
- 'opacity',
12417
- 'fillOpacity',
12418
- 'strokeOpacity',
12419
- 'transformOrigin',
12420
- 'visibility',
12421
- 'pointerEvents',
12422
- 'lineWidth',
12423
- 'lineCap',
12424
- 'lineJoin',
12425
- 'increasedLineWidthForHitTesting',
12426
- ];
12427
- var INHERITABLE_STYLE_PROPS = tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(INHERITABLE_BASE_STYLE_PROPS), false), [
12428
- 'fontSize',
12429
- 'fontFamily',
12430
- 'fontStyle',
12431
- 'fontWeight',
12432
- 'fontVariant',
12433
- 'textAlign',
12434
- 'textBaseline',
12435
- 'textTransform',
12436
- ], false);
12437
- var DATASET_PREFIX = 'data-';
11825
+ var $vec3 = glMatrix.vec3.create();
11826
+ var $quat = glMatrix.quat.create();
12438
11827
  /**
12439
11828
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
12440
11829
  *
@@ -12467,38 +11856,17 @@ var DisplayObject = /** @class */ (function (_super) {
12467
11856
  // eg. group.get('name')
12468
11857
  _this.config = config;
12469
11858
  // init scene graph node
12470
- _this.id = _this.config.id || '';
12471
- _this.name = _this.config.name || '';
12472
- if (_this.config.className || _this.config.class) {
12473
- _this.className = _this.config.className || _this.config.class;
11859
+ _this.id = config.id || '';
11860
+ _this.name = config.name || '';
11861
+ if (config.className || config.class) {
11862
+ _this.className = config.className || config.class;
12474
11863
  }
12475
- _this.nodeName = _this.config.type || exports.Shape.GROUP;
12476
- if (runtime.enableCSSParsing) {
12477
- Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12478
- Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
12479
- }
12480
- else if (_this.config.initialParsedStyle) {
12481
- Object.assign(_this.parsedStyle,
12482
- // DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED,
12483
- _this.config.initialParsedStyle);
11864
+ _this.nodeName = config.type || exports.Shape.GROUP;
11865
+ if (config.initialParsedStyle) {
11866
+ Object.assign(_this.parsedStyle, config.initialParsedStyle);
12484
11867
  }
12485
11868
  // start to process attributes
12486
- _this.initAttributes(_this.config.style);
12487
- if (runtime.enableDataset) {
12488
- _this.dataset = new Proxy({}, {
12489
- get: function (target, name) {
12490
- var formattedName = "".concat(DATASET_PREFIX).concat(kebabize(name));
12491
- if (target[formattedName] !== undefined) {
12492
- return target[formattedName];
12493
- }
12494
- return _this.getAttribute(formattedName);
12495
- },
12496
- set: function (_, prop, value) {
12497
- _this.setAttribute("".concat(DATASET_PREFIX).concat(kebabize(prop)), value);
12498
- return true;
12499
- },
12500
- });
12501
- }
11869
+ _this.initAttributes(config.style);
12502
11870
  if (runtime.enableStyleSyntax) {
12503
11871
  _this.style = new Proxy(
12504
11872
  // @ts-ignore
@@ -12538,13 +11906,6 @@ var DisplayObject = /** @class */ (function (_super) {
12538
11906
  this.getAnimations().forEach(function (animation) {
12539
11907
  animation.cancel();
12540
11908
  });
12541
- // FIXME
12542
- // this.renderable = null;
12543
- // this.cullable = null;
12544
- // this.transformable = null;
12545
- // this.rBushNode = null;
12546
- // this.geometry = null;
12547
- // this.sortable = null;
12548
11909
  };
12549
11910
  DisplayObject.prototype.cloneNode = function (deep, customCloneFunc) {
12550
11911
  var clonedStyle = tslib.__assign({}, this.attributes);
@@ -12587,39 +11948,16 @@ var DisplayObject = /** @class */ (function (_super) {
12587
11948
  };
12588
11949
  DisplayObject.prototype.initAttributes = function (attributes) {
12589
11950
  if (attributes === void 0) { attributes = {}; }
12590
- var renderable = this.renderable;
12591
11951
  var options = {
12592
11952
  forceUpdateGeometry: true,
12593
- // usedAttributes:
12594
- // // only Group / Text should account for text relative props
12595
- // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT
12596
- // ? INHERITABLE_STYLE_PROPS
12597
- // : INHERITABLE_BASE_STYLE_PROPS,
12598
11953
  };
12599
- if (runtime.enableCSSParsing) {
12600
- // @ts-ignore
12601
- options.usedAttributes = INHERITABLE_STYLE_PROPS;
12602
- }
12603
- // account for FCP, process properties as less as possible
12604
- var formattedAttributes = attributes;
12605
- if (runtime.enableAttributeDashCased) {
12606
- // @ts-ignore
12607
- formattedAttributes = {};
12608
- for (var name_1 in attributes) {
12609
- var attributeName = formatAttributeName(name_1);
12610
- formattedAttributes[attributeName] = attributes[name_1];
12611
- }
12612
- }
12613
- runtime.styleValueRegistry.processProperties(this, formattedAttributes, options);
11954
+ runtime.styleValueRegistry.processProperties(this, attributes, options);
12614
11955
  // redraw at next frame
12615
- renderable.dirty = true;
11956
+ this.renderable.dirty = true;
12616
11957
  };
12617
11958
  DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12618
11959
  if (force === void 0) { force = false; }
12619
11960
  if (memoize === void 0) { memoize = true; }
12620
- if (runtime.enableAttributeDashCased) {
12621
- name = formatAttributeName(name);
12622
- }
12623
11961
  // ignore undefined value
12624
11962
  if (util.isUndefined(value)) {
12625
11963
  return;
@@ -12681,7 +12019,7 @@ var DisplayObject = /** @class */ (function (_super) {
12681
12019
  DisplayObject.prototype.setOrigin = function (position, y, z) {
12682
12020
  if (y === void 0) { y = 0; }
12683
12021
  if (z === void 0) { z = 0; }
12684
- runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z));
12022
+ runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z, false));
12685
12023
  return this;
12686
12024
  };
12687
12025
  DisplayObject.prototype.getOrigin = function () {
@@ -12693,7 +12031,7 @@ var DisplayObject = /** @class */ (function (_super) {
12693
12031
  DisplayObject.prototype.setPosition = function (position, y, z) {
12694
12032
  if (y === void 0) { y = 0; }
12695
12033
  if (z === void 0) { z = 0; }
12696
- runtime.sceneGraphService.setPosition(this, createVec3(position, y, z));
12034
+ runtime.sceneGraphService.setPosition(this, createVec3(position, y, z, false));
12697
12035
  return this;
12698
12036
  };
12699
12037
  /**
@@ -12702,7 +12040,7 @@ var DisplayObject = /** @class */ (function (_super) {
12702
12040
  DisplayObject.prototype.setLocalPosition = function (position, y, z) {
12703
12041
  if (y === void 0) { y = 0; }
12704
12042
  if (z === void 0) { z = 0; }
12705
- runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
12043
+ runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z, false));
12706
12044
  return this;
12707
12045
  };
12708
12046
  /**
@@ -12711,7 +12049,7 @@ var DisplayObject = /** @class */ (function (_super) {
12711
12049
  DisplayObject.prototype.translate = function (position, y, z) {
12712
12050
  if (y === void 0) { y = 0; }
12713
12051
  if (z === void 0) { z = 0; }
12714
- runtime.sceneGraphService.translate(this, createVec3(position, y, z));
12052
+ runtime.sceneGraphService.translate(this, createVec3(position, y, z, false));
12715
12053
  return this;
12716
12054
  };
12717
12055
  /**
@@ -12720,7 +12058,7 @@ var DisplayObject = /** @class */ (function (_super) {
12720
12058
  DisplayObject.prototype.translateLocal = function (position, y, z) {
12721
12059
  if (y === void 0) { y = 0; }
12722
12060
  if (z === void 0) { z = 0; }
12723
- runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z));
12061
+ runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z, false));
12724
12062
  return this;
12725
12063
  };
12726
12064
  DisplayObject.prototype.getPosition = function () {
@@ -12744,7 +12082,7 @@ var DisplayObject = /** @class */ (function (_super) {
12744
12082
  if (typeof scaling === 'number') {
12745
12083
  y = y || scaling;
12746
12084
  z = z || scaling;
12747
- scaling = createVec3(scaling, y, z);
12085
+ scaling = createVec3(scaling, y, z, false);
12748
12086
  }
12749
12087
  runtime.sceneGraphService.scaleLocal(this, scaling);
12750
12088
  return this;
@@ -12756,7 +12094,7 @@ var DisplayObject = /** @class */ (function (_super) {
12756
12094
  if (typeof scaling === 'number') {
12757
12095
  y = y || scaling;
12758
12096
  z = z || scaling;
12759
- scaling = createVec3(scaling, y, z);
12097
+ scaling = createVec3(scaling, y, z, false);
12760
12098
  }
12761
12099
  runtime.sceneGraphService.setLocalScale(this, scaling);
12762
12100
  return this;
@@ -12777,14 +12115,14 @@ var DisplayObject = /** @class */ (function (_super) {
12777
12115
  * only return degrees of Z axis in world space
12778
12116
  */
12779
12117
  DisplayObject.prototype.getEulerAngles = function () {
12780
- var _a = tslib.__read(getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12118
+ var _a = tslib.__read(getEuler($vec3, runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12781
12119
  return rad2deg(ez);
12782
12120
  };
12783
12121
  /**
12784
12122
  * only return degrees of Z axis in local space
12785
12123
  */
12786
12124
  DisplayObject.prototype.getLocalEulerAngles = function () {
12787
- var _a = tslib.__read(getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12125
+ var _a = tslib.__read(getEuler($vec3, runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12788
12126
  return rad2deg(ez);
12789
12127
  };
12790
12128
  /**
@@ -12880,10 +12218,8 @@ var DisplayObject = /** @class */ (function (_super) {
12880
12218
  * shortcut for Used value of `visibility`
12881
12219
  */
12882
12220
  DisplayObject.prototype.isVisible = function () {
12883
- var _a, _b;
12884
- return runtime.enableCSSParsing
12885
- ? ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible'
12886
- : ((_b = this.parsedStyle) === null || _b === void 0 ? void 0 : _b.visibility) !== 'hidden';
12221
+ var _a;
12222
+ return ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) !== 'hidden';
12887
12223
  };
12888
12224
  Object.defineProperty(DisplayObject.prototype, "interactive", {
12889
12225
  get: function () {
@@ -12964,10 +12300,10 @@ var DisplayObject = /** @class */ (function (_super) {
12964
12300
  */
12965
12301
  DisplayObject.prototype.getMatrix = function (transformMat4) {
12966
12302
  var transform = transformMat4 || this.getWorldTransform();
12967
- var _a = tslib.__read(glMatrix.mat4.getTranslation(glMatrix.vec3.create(), transform), 2), tx = _a[0], ty = _a[1];
12968
- var _b = tslib.__read(glMatrix.mat4.getScaling(glMatrix.vec3.create(), transform), 2), sx = _b[0], sy = _b[1];
12969
- var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform);
12970
- var _c = tslib.__read(getEuler(glMatrix.vec3.create(), rotation), 3), eux = _c[0], euz = _c[2];
12303
+ var _a = tslib.__read(glMatrix.mat4.getTranslation($vec3, transform), 2), tx = _a[0], ty = _a[1];
12304
+ var _b = tslib.__read(glMatrix.mat4.getScaling($vec3, transform), 2), sx = _b[0], sy = _b[1];
12305
+ var rotation = glMatrix.mat4.getRotation($quat, transform);
12306
+ var _c = tslib.__read(getEuler($vec3, rotation), 3), eux = _c[0], euz = _c[2];
12971
12307
  // gimbal lock at 90 degrees
12972
12308
  return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
12973
12309
  };
@@ -13003,28 +12339,18 @@ var DisplayObject = /** @class */ (function (_super) {
13003
12339
  * @deprecated
13004
12340
  */
13005
12341
  DisplayObject.prototype.show = function () {
13006
- if (runtime.enableCSSParsing) {
13007
- this.style.visibility = 'visible';
13008
- }
13009
- else {
13010
- this.forEach(function (object) {
13011
- object.style.visibility = 'visible';
13012
- });
13013
- }
12342
+ this.forEach(function (object) {
12343
+ object.style.visibility = 'visible';
12344
+ });
13014
12345
  };
13015
12346
  /**
13016
12347
  * Use `visibility: hidden` instead.
13017
12348
  * @deprecated
13018
12349
  */
13019
12350
  DisplayObject.prototype.hide = function () {
13020
- if (runtime.enableCSSParsing) {
13021
- this.style.visibility = 'hidden';
13022
- }
13023
- else {
13024
- this.forEach(function (object) {
13025
- object.style.visibility = 'hidden';
13026
- });
13027
- }
12351
+ this.forEach(function (object) {
12352
+ object.style.visibility = 'hidden';
12353
+ });
13028
12354
  };
13029
12355
  /**
13030
12356
  * Use `childElementCount` instead.
@@ -13139,8 +12465,7 @@ var CustomElement = /** @class */ (function (_super) {
13139
12465
  if (_a === void 0) { _a = {}; }
13140
12466
  var _this = this;
13141
12467
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13142
- _this = _super.call(this, tslib.__assign({ style: runtime.enableCSSParsing
13143
- ? tslib.__assign({}, style) : tslib.__assign({}, style) }, rest)) || this;
12468
+ _this = _super.call(this, tslib.__assign({ style: style }, rest)) || this;
13144
12469
  // static get observedAttributes(): string[] {
13145
12470
  // return [];
13146
12471
  // }
@@ -13159,6 +12484,23 @@ var Ellipse = /** @class */ (function (_super) {
13159
12484
  return Ellipse;
13160
12485
  }(DisplayObject));
13161
12486
 
12487
+ /**
12488
+ * 节点片段,用于包裹多个节点并批量操作
12489
+ *
12490
+ * 向 Fragment 或者根节点为 Fragment 的节点添加子节点时,不会触发渲染和事件。
12491
+ *
12492
+ * 当 Fragment 被挂载到 Canvas 中的节点时,其子节点会一次性被渲染,并触发合并事件。
12493
+ *
12494
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
12495
+ */
12496
+ var Fragment = /** @class */ (function (_super) {
12497
+ tslib.__extends(Fragment, _super);
12498
+ function Fragment() {
12499
+ return _super.call(this, { type: exports.Shape.FRAGMENT }) || this;
12500
+ }
12501
+ return Fragment;
12502
+ }(DisplayObject));
12503
+
13162
12504
  /**
13163
12505
  * its attributes are inherited by its children.
13164
12506
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
@@ -13188,8 +12530,7 @@ var HTML = /** @class */ (function (_super) {
13188
12530
  if (_a === void 0) { _a = {}; }
13189
12531
  var _this = this;
13190
12532
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13191
- _this = _super.call(this, tslib.__assign({ type: exports.Shape.HTML, style: runtime.enableCSSParsing
13192
- ? tslib.__assign({ x: '', y: '', width: 'auto', height: 'auto', innerHTML: '' }, style) : tslib.__assign({}, style) }, rest)) || this;
12533
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.HTML, style: style }, rest)) || this;
13193
12534
  _this.cullable.enable = false;
13194
12535
  return _this;
13195
12536
  }
@@ -13381,13 +12722,10 @@ var Path = /** @class */ (function (_super) {
13381
12722
  if (_a === void 0) { _a = {}; }
13382
12723
  var _this = this;
13383
12724
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13384
- _this = _super.call(this, tslib.__assign({ type: exports.Shape.PATH, style: runtime.enableCSSParsing
13385
- ? tslib.__assign({ d: '', miterLimit: '' }, style) : tslib.__assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13386
- ? null
13387
- : {
13388
- miterLimit: 4,
13389
- d: tslib.__assign({}, EMPTY_PARSED_PATH),
13390
- } }, rest)) || this;
12725
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.PATH, style: style, initialParsedStyle: {
12726
+ miterLimit: 4,
12727
+ d: tslib.__assign({}, EMPTY_PARSED_PATH),
12728
+ } }, rest)) || this;
13391
12729
  _this.markerStartAngle = 0;
13392
12730
  _this.markerEndAngle = 0;
13393
12731
  /**
@@ -13582,18 +12920,15 @@ var Polygon = /** @class */ (function (_super) {
13582
12920
  if (_a === void 0) { _a = {}; }
13583
12921
  var _this = this;
13584
12922
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13585
- _this = _super.call(this, tslib.__assign({ type: exports.Shape.POLYGON, style: runtime.enableCSSParsing
13586
- ? tslib.__assign({ points: '', miterLimit: '', isClosed: true }, style) : tslib.__assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13587
- ? null
13588
- : {
13589
- points: {
13590
- points: [],
13591
- totalLength: 0,
13592
- segments: [],
13593
- },
13594
- miterLimit: 4,
13595
- isClosed: true,
13596
- } }, rest)) || this;
12923
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.POLYGON, style: style, initialParsedStyle: {
12924
+ points: {
12925
+ points: [],
12926
+ totalLength: 0,
12927
+ segments: [],
12928
+ },
12929
+ miterLimit: 4,
12930
+ isClosed: true,
12931
+ } }, rest)) || this;
13597
12932
  _this.markerStartAngle = 0;
13598
12933
  _this.markerEndAngle = 0;
13599
12934
  /**
@@ -13728,18 +13063,15 @@ var Polyline = /** @class */ (function (_super) {
13728
13063
  function Polyline(_a) {
13729
13064
  if (_a === void 0) { _a = {}; }
13730
13065
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13731
- return _super.call(this, tslib.__assign({ type: exports.Shape.POLYLINE, style: runtime.enableCSSParsing
13732
- ? tslib.__assign({ points: '', miterLimit: '', isClosed: false }, style) : tslib.__assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13733
- ? null
13734
- : {
13735
- points: {
13736
- points: [],
13737
- totalLength: 0,
13738
- segments: [],
13739
- },
13740
- miterLimit: 4,
13741
- isClosed: false,
13742
- } }, rest)) || this;
13066
+ return _super.call(this, tslib.__assign({ type: exports.Shape.POLYLINE, style: style, initialParsedStyle: {
13067
+ points: {
13068
+ points: [],
13069
+ totalLength: 0,
13070
+ segments: [],
13071
+ },
13072
+ miterLimit: 4,
13073
+ isClosed: false,
13074
+ } }, rest)) || this;
13743
13075
  }
13744
13076
  Polyline.prototype.getTotalLength = function () {
13745
13077
  return getOrCalculatePolylineTotalLength(this);
@@ -13823,16 +13155,8 @@ var Text = /** @class */ (function (_super) {
13823
13155
  function Text(_a) {
13824
13156
  if (_a === void 0) { _a = {}; }
13825
13157
  var style = _a.style, rest = tslib.__rest(_a, ["style"]);
13826
- return _super.call(this, tslib.__assign({ type: exports.Shape.TEXT, style: runtime.enableCSSParsing
13827
- ? tslib.__assign({ x: '', y: '', text: '', fontSize: '', fontFamily: '', fontStyle: '', fontWeight: '', fontVariant: '', textAlign: '', textBaseline: '', textTransform: '', fill: 'black', letterSpacing: '', lineHeight: '', miterLimit: '',
13828
- // whiteSpace: 'pre',
13829
- wordWrap: false, wordWrapWidth: 0, leading: 0, dx: '', dy: '' }, style) : tslib.__assign({ fill: 'black' }, style) }, rest)) || this;
13830
- }
13831
- // lengthAdjust: SVGAnimatedEnumeration;
13832
- // textLength: SVGAnimatedLength;
13833
- // getCharNumAtPosition(point?: DOMPointInit): number {
13834
- // throw new Error('Method not implemented.');
13835
- // }
13158
+ return _super.call(this, tslib.__assign({ type: exports.Shape.TEXT, style: tslib.__assign({ fill: 'black' }, style) }, rest)) || this;
13159
+ }
13836
13160
  /**
13837
13161
  * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
13838
13162
  */
@@ -13841,27 +13165,6 @@ var Text = /** @class */ (function (_super) {
13841
13165
  this.getGeometryBounds();
13842
13166
  return ((_a = this.parsedStyle.metrics) === null || _a === void 0 ? void 0 : _a.maxLineWidth) || 0;
13843
13167
  };
13844
- // getEndPositionOfChar(charnum: number): DOMPoint {
13845
- // throw new Error('Method not implemented.');
13846
- // }
13847
- // getExtentOfChar(charnum: number): DOMRect {
13848
- // throw new Error('Method not implemented.');
13849
- // }
13850
- // getNumberOfChars(): number {
13851
- // throw new Error('Method not implemented.');
13852
- // }
13853
- // getRotationOfChar(charnum: number): number {
13854
- // throw new Error('Method not implemented.');
13855
- // }
13856
- // getStartPositionOfChar(charnum: number): DOMPoint {
13857
- // throw new Error('Method not implemented.');
13858
- // }
13859
- // getSubStringLength(charnum: number, nchars: number): number {
13860
- // throw new Error('Method not implemented.');
13861
- // }
13862
- // selectSubString(charnum: number, nchars: number): void {
13863
- // throw new Error('Method not implemented.');
13864
- // }
13865
13168
  Text.prototype.getLineBoundingRects = function () {
13866
13169
  var _a;
13867
13170
  this.getGeometryBounds();
@@ -14039,7 +13342,7 @@ var Document = /** @class */ (function (_super) {
14039
13342
  BUILT_IN_PROPERTIES.forEach(function (_a) {
14040
13343
  var n = _a.n, inh = _a.inh, d = _a.d;
14041
13344
  if (inh && d) {
14042
- initialStyle[n] = isFunction(d) ? d(exports.Shape.GROUP) : d;
13345
+ initialStyle[n] = util.isFunction(d) ? d(exports.Shape.GROUP) : d;
14043
13346
  }
14044
13347
  });
14045
13348
  // like <html> in DOM tree
@@ -14816,10 +14119,7 @@ var FrustumCullingStrategy = /** @class */ (function () {
14816
14119
 
14817
14120
  var PrepareRendererPlugin = /** @class */ (function () {
14818
14121
  function PrepareRendererPlugin() {
14819
- /**
14820
- * sync to RBush later
14821
- */
14822
- this.toSync = new Set();
14122
+ this.syncTasks = new Map();
14823
14123
  this.isFirstTimeRendering = true;
14824
14124
  this.syncing = false;
14825
14125
  this.isFirstTimeRenderingFinished = false;
@@ -14836,21 +14136,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14836
14136
  renderingService.dirtify();
14837
14137
  };
14838
14138
  var handleBoundsChanged = function (e) {
14839
- var affectChildren = e.detail.affectChildren;
14840
- var object = e.target;
14841
- if (affectChildren) {
14842
- object.forEach(function (node) {
14843
- _this.toSync.add(node);
14844
- });
14845
- }
14846
- var p = object;
14847
- while (p) {
14848
- if (p.renderable) {
14849
- _this.toSync.add(p);
14850
- }
14851
- p = p.parentElement;
14852
- }
14853
- // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
14139
+ _this.syncTasks.set(e.target, e.detail.affectChildren);
14854
14140
  renderingService.dirtify();
14855
14141
  };
14856
14142
  var handleMounted = function (e) {
@@ -14858,12 +14144,6 @@ var PrepareRendererPlugin = /** @class */ (function () {
14858
14144
  if (runtime.enableSizeAttenuation) {
14859
14145
  runtime.styleValueRegistry.updateSizeAttenuation(object, canvas.getCamera().getZoom());
14860
14146
  }
14861
- if (runtime.enableCSSParsing) {
14862
- // recalc style values
14863
- runtime.styleValueRegistry.recalc(object);
14864
- }
14865
- runtime.sceneGraphService.dirtifyToRoot(object);
14866
- renderingService.dirtify();
14867
14147
  };
14868
14148
  var handleUnmounted = function (e) {
14869
14149
  var object = e.target;
@@ -14871,7 +14151,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14871
14151
  if (rBushNode.aabb) {
14872
14152
  _this.rBush.remove(rBushNode.aabb);
14873
14153
  }
14874
- _this.toSync.delete(object);
14154
+ _this.syncTasks.delete(object);
14875
14155
  runtime.sceneGraphService.dirtifyToRoot(object);
14876
14156
  renderingService.dirtify();
14877
14157
  };
@@ -14886,7 +14166,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14886
14166
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
14887
14167
  canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14888
14168
  canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14889
- _this.toSync.clear();
14169
+ _this.syncTasks.clear();
14890
14170
  });
14891
14171
  var ric = (_a = runtime.globalThis.requestIdleCallback) !== null && _a !== void 0 ? _a : raf.bind(runtime.globalThis);
14892
14172
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
@@ -14903,60 +14183,78 @@ var PrepareRendererPlugin = /** @class */ (function () {
14903
14183
  }
14904
14184
  });
14905
14185
  };
14186
+ PrepareRendererPlugin.prototype.syncNode = function (node, force) {
14187
+ if (force === void 0) { force = false; }
14188
+ if (!node.isConnected)
14189
+ return;
14190
+ var rBushNode = node.rBushNode;
14191
+ // clear dirty node
14192
+ if (rBushNode.aabb)
14193
+ this.rBush.remove(rBushNode.aabb);
14194
+ var renderBounds = node.getRenderBounds();
14195
+ if (renderBounds) {
14196
+ var renderable = node.renderable;
14197
+ if (force) {
14198
+ if (!renderable.dirtyRenderBounds) {
14199
+ renderable.dirtyRenderBounds = new AABB();
14200
+ }
14201
+ // save last dirty aabb
14202
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14203
+ }
14204
+ var _a = tslib.__read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14205
+ var _b = tslib.__read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14206
+ if (!rBushNode.aabb) {
14207
+ rBushNode.aabb = {};
14208
+ }
14209
+ rBushNode.aabb.displayObject = node;
14210
+ rBushNode.aabb.minX = minX;
14211
+ rBushNode.aabb.minY = minY;
14212
+ rBushNode.aabb.maxX = maxX;
14213
+ rBushNode.aabb.maxY = maxY;
14214
+ }
14215
+ if (rBushNode.aabb) {
14216
+ // TODO: NaN occurs when width/height of Rect is 0
14217
+ if (!isNaN(rBushNode.aabb.maxX) &&
14218
+ !isNaN(rBushNode.aabb.maxX) &&
14219
+ !isNaN(rBushNode.aabb.minX) &&
14220
+ !isNaN(rBushNode.aabb.minY)) {
14221
+ return rBushNode.aabb;
14222
+ }
14223
+ }
14224
+ };
14906
14225
  PrepareRendererPlugin.prototype.syncRTree = function (force) {
14907
14226
  var _this = this;
14908
14227
  if (force === void 0) { force = false; }
14909
- if (!force && (this.syncing || this.toSync.size === 0)) {
14228
+ if (!force && (this.syncing || this.syncTasks.size === 0)) {
14910
14229
  return;
14911
14230
  }
14912
14231
  this.syncing = true;
14913
14232
  // bounds changed, need re-inserting its children
14914
14233
  var bulk = [];
14915
- Array.from(this.toSync)
14916
- // some objects may be removed since last frame
14917
- .filter(function (object) { return object.isConnected; })
14918
- .forEach(function (node) {
14919
- var rBushNode = node.rBushNode;
14920
- // clear dirty node
14921
- if (rBushNode && rBushNode.aabb) {
14922
- _this.rBush.remove(rBushNode.aabb);
14923
- }
14924
- var renderBounds = node.getRenderBounds();
14925
- if (renderBounds) {
14926
- var renderable = node.renderable;
14927
- if (force) {
14928
- if (!renderable.dirtyRenderBounds) {
14929
- renderable.dirtyRenderBounds = new AABB();
14930
- }
14931
- // save last dirty aabb
14932
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14933
- }
14934
- var _a = tslib.__read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14935
- var _b = tslib.__read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14936
- if (!rBushNode.aabb) {
14937
- rBushNode.aabb = {};
14234
+ var synced = new Set();
14235
+ var sync = function (node) {
14236
+ if (!synced.has(node) && node.renderable) {
14237
+ var aabb = _this.syncNode(node, force);
14238
+ if (aabb) {
14239
+ bulk.push(aabb);
14240
+ synced.add(node);
14938
14241
  }
14939
- rBushNode.aabb.displayObject = node;
14940
- rBushNode.aabb.minX = minX;
14941
- rBushNode.aabb.minY = minY;
14942
- rBushNode.aabb.maxX = maxX;
14943
- rBushNode.aabb.maxY = maxY;
14944
14242
  }
14945
- if (rBushNode.aabb) {
14946
- // TODO: NaN occurs when width/height of Rect is 0
14947
- if (!isNaN(rBushNode.aabb.maxX) &&
14948
- !isNaN(rBushNode.aabb.maxX) &&
14949
- !isNaN(rBushNode.aabb.minX) &&
14950
- !isNaN(rBushNode.aabb.minY)) {
14951
- bulk.push(rBushNode.aabb);
14952
- }
14243
+ };
14244
+ this.syncTasks.forEach(function (affectChildren, node) {
14245
+ if (affectChildren) {
14246
+ node.forEach(sync);
14247
+ }
14248
+ var parent = node;
14249
+ while (parent) {
14250
+ sync(parent);
14251
+ parent = parent.parentElement;
14953
14252
  }
14954
14253
  });
14955
14254
  // use bulk inserting, which is ~2-3 times faster
14956
14255
  // @see https://github.com/mourner/rbush#bulk-inserting-data
14957
14256
  this.rBush.load(bulk);
14958
14257
  bulk.length = 0;
14959
- this.toSync.clear();
14960
14258
  this.syncing = false;
14961
14259
  };
14962
14260
  PrepareRendererPlugin.tag = 'Prepare';
@@ -15012,9 +14310,9 @@ var Canvas = /** @class */ (function (_super) {
15012
14310
  _this.document.defaultView = _this;
15013
14311
  // create registry of custom elements
15014
14312
  _this.customElements = new CustomElementRegistry();
15015
- 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;
14313
+ 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;
15016
14314
  if (!supportsMutipleCanvasesInOneContainer) {
15017
- cleanExistedCanvas(container, _this);
14315
+ cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15018
14316
  }
15019
14317
  var canvasWidth = width;
15020
14318
  var canvasHeight = height;
@@ -15075,6 +14373,7 @@ var Canvas = /** @class */ (function (_super) {
15075
14373
  document: document,
15076
14374
  supportsCSSTransform: supportsCSSTransform,
15077
14375
  useNativeClickEvent: useNativeClickEvent,
14376
+ cleanUpOnDestroy: cleanUpOnDestroy,
15078
14377
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas,
15079
14378
  });
15080
14379
  _this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
@@ -15185,7 +14484,8 @@ var Canvas = /** @class */ (function (_super) {
15185
14484
  */
15186
14485
  Canvas.prototype.destroy = function (cleanUp, skipTriggerEvent) {
15187
14486
  if (cleanUp === void 0) { cleanUp = true; }
15188
- if (skipTriggerEvent === void 0) { skipTriggerEvent = false; }
14487
+ if (skipTriggerEvent === undefined)
14488
+ skipTriggerEvent = this.getConfig().fastCleanExistingCanvas;
15189
14489
  if (!skipTriggerEvent) {
15190
14490
  this.dispatchEvent(new CustomEvent(exports.CanvasEvent.BEFORE_DESTROY));
15191
14491
  }
@@ -15214,6 +14514,17 @@ var Canvas = /** @class */ (function (_super) {
15214
14514
  if (!skipTriggerEvent) {
15215
14515
  this.dispatchEvent(new CustomEvent(exports.CanvasEvent.AFTER_DESTROY));
15216
14516
  }
14517
+ var clearEventRetain = function (event) {
14518
+ event.currentTarget = null;
14519
+ event.manager = null;
14520
+ event.target = null;
14521
+ };
14522
+ clearEventRetain(mountedEvent);
14523
+ clearEventRetain(unmountedEvent);
14524
+ clearEventRetain(beforeRenderEvent);
14525
+ clearEventRetain(rerenderEvent);
14526
+ clearEventRetain(afterRenderEvent);
14527
+ this.cancelAnimationFrame(this.frameId);
15217
14528
  };
15218
14529
  /**
15219
14530
  * compatible with G 3.0
@@ -15421,35 +14732,41 @@ var Canvas = /** @class */ (function (_super) {
15421
14732
  }
15422
14733
  }
15423
14734
  };
15424
- Canvas.prototype.mountChildren = function (parent) {
14735
+ Canvas.prototype.mountChildren = function (child, skipTriggerEvent) {
15425
14736
  var _this = this;
14737
+ if (skipTriggerEvent === void 0) { skipTriggerEvent = isInFragment(child); }
15426
14738
  if (this.inited) {
15427
- if (!parent.isConnected) {
15428
- parent.ownerDocument = this.document;
15429
- parent.isConnected = true;
15430
- if (parent.isMutationObserved) {
15431
- parent.dispatchEvent(mountedEvent);
15432
- }
15433
- else {
15434
- mountedEvent.target = parent;
15435
- this.dispatchEvent(mountedEvent, true);
14739
+ if (!child.isConnected) {
14740
+ child.ownerDocument = this.document;
14741
+ child.isConnected = true;
14742
+ if (!skipTriggerEvent) {
14743
+ if (child.isMutationObserved) {
14744
+ child.dispatchEvent(mountedEvent);
14745
+ }
14746
+ else {
14747
+ mountedEvent.target = child;
14748
+ this.dispatchEvent(mountedEvent, true);
14749
+ }
15436
14750
  }
15437
14751
  }
15438
14752
  }
15439
14753
  else {
15440
- 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);
14754
+ 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);
15441
14755
  }
15442
14756
  // recursively mount children
15443
- parent.childNodes.forEach(function (child) {
15444
- _this.mountChildren(child);
14757
+ child.childNodes.forEach(function (c) {
14758
+ _this.mountChildren(c, skipTriggerEvent);
15445
14759
  });
15446
14760
  // trigger after mounted
15447
- if (parent.isCustomElement) {
15448
- if (parent.connectedCallback) {
15449
- parent.connectedCallback();
14761
+ if (child.isCustomElement) {
14762
+ if (child.connectedCallback) {
14763
+ child.connectedCallback();
15450
14764
  }
15451
14765
  }
15452
14766
  };
14767
+ Canvas.prototype.mountFragment = function (child) {
14768
+ this.mountChildren(child, false);
14769
+ };
15453
14770
  Canvas.prototype.client2Viewport = function (client) {
15454
14771
  return this.getEventService().client2Viewport(client);
15455
14772
  };
@@ -15511,6 +14828,7 @@ exports.FederatedEvent = FederatedEvent;
15511
14828
  exports.FederatedMouseEvent = FederatedMouseEvent;
15512
14829
  exports.FederatedPointerEvent = FederatedPointerEvent;
15513
14830
  exports.FederatedWheelEvent = FederatedWheelEvent;
14831
+ exports.Fragment = Fragment;
15514
14832
  exports.Frustum = Frustum;
15515
14833
  exports.Group = Group;
15516
14834
  exports.GroupUpdater = GroupUpdater;