@antv/g-lite 2.0.11 → 2.0.12-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 (50) hide show
  1. package/dist/Canvas.d.ts +3 -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 +1403 -2080
  33. package/dist/index.esm.js.map +1 -1
  34. package/dist/index.js +1403 -2079
  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/types.d.ts +54 -1
  41. package/dist/utils/assert.d.ts +0 -9
  42. package/dist/utils/canvas.d.ts +1 -1
  43. package/dist/utils/fragment.d.ts +2 -0
  44. package/dist/utils/index.d.ts +1 -1
  45. package/dist/utils/math.d.ts +1 -8
  46. package/package.json +1 -1
  47. package/dist/css/cssom/CSSMathOperator.d.ts +0 -11
  48. package/dist/css/cssom/CSSNumericSumValue.d.ts +0 -7
  49. package/dist/css/properties/CSSPropertyLocalPosition.d.ts +0 -13
  50. 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
@@ -1424,67 +1038,405 @@ var Point = /** @class */ (function () {
1424
1038
  this.x = x;
1425
1039
  this.y = y;
1426
1040
  }
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
- }());
1436
-
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;
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);
1197
+ }
1198
+ }
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;
1280
+ }
1281
+ else {
1282
+ scalingY = -scalingY;
1283
+ }
1284
+ }
1285
+ // Renormalize matrix to remove scale.
1286
+ if (scalingX) {
1287
+ var invScalingX = 1 / scalingX;
1288
+ row0x *= invScalingX;
1289
+ row0y *= invScalingX;
1290
+ }
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
1314
+
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;
1447
1357
  }
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.';
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
+ }
1395
+ }
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
  */
@@ -2945,82 +2975,6 @@ var CSSKeywordValue = /** @class */ (function (_super) {
2945
2975
  return CSSKeywordValue;
2946
2976
  }(CSSStyleValue));
2947
2977
 
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
- });
3004
-
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
@@ -4145,16 +4005,6 @@ function parseDimensionArrayFormat(string, size) {
4145
4005
  }
4146
4006
  }
4147
4007
  }
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
4008
  // export function mergeDimensionList(
4159
4009
  // left: CSSUnitValue[],
4160
4010
  // right: CSSUnitValue[],
@@ -5183,6 +5033,7 @@ function mergePoints(left, right) {
5183
5033
  }
5184
5034
 
5185
5035
  var _ = null;
5036
+ var TRANSFORM_REGEXP = /\s*(\w+)\(([^)]*)\)/g;
5186
5037
  function cast(pattern) {
5187
5038
  return function (contents) {
5188
5039
  var i = 0;
@@ -5201,48 +5052,75 @@ var transformFunctions = {
5201
5052
  matrix: ['NNNNNN', [_, _, 0, 0, _, _, 0, 0, 0, 0, 1, 0, _, _, 0, 1], id],
5202
5053
  matrix3d: ['NNNNNNNNNNNNNNNN', id],
5203
5054
  rotate: ['A'],
5204
- rotatex: ['A'],
5205
- rotatey: ['A'],
5206
- rotatez: ['A'],
5055
+ rotateX: ['A'],
5056
+ rotateY: ['A'],
5057
+ rotateZ: ['A'],
5207
5058
  rotate3d: ['NNNA'],
5208
5059
  perspective: ['L'],
5209
5060
  scale: ['Nn', cast([_, _, new CSSUnitValue(1)]), id],
5210
- scalex: [
5061
+ scaleX: [
5211
5062
  'N',
5212
5063
  cast([_, new CSSUnitValue(1), new CSSUnitValue(1)]),
5213
5064
  cast([_, new CSSUnitValue(1)]),
5214
5065
  ],
5215
- scaley: [
5066
+ scaleY: [
5216
5067
  'N',
5217
5068
  cast([new CSSUnitValue(1), _, new CSSUnitValue(1)]),
5218
5069
  cast([new CSSUnitValue(1), _]),
5219
5070
  ],
5220
- scalez: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5071
+ scaleZ: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5221
5072
  scale3d: ['NNN', id],
5222
5073
  skew: ['Aa', null, id],
5223
- skewx: ['A', null, cast([_, Odeg])],
5224
- skewy: ['A', null, cast([Odeg, _])],
5074
+ skewX: ['A', null, cast([_, Odeg])],
5075
+ skewY: ['A', null, cast([Odeg, _])],
5225
5076
  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, _])],
5077
+ translateX: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5078
+ translateY: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5079
+ translateZ: ['L', cast([Opx, Opx, _])],
5229
5080
  translate3d: ['TTL', id],
5230
5081
  };
5082
+ function parseArrayTransform(transform) {
5083
+ var result = [];
5084
+ var length = transform.length;
5085
+ for (var i = 0; i < length; i++) {
5086
+ var item = transform[i];
5087
+ var name_1 = item[0];
5088
+ var args = item.slice(1);
5089
+ // infer default value
5090
+ if (name_1 === 'translate' || name_1 === 'skew') {
5091
+ if (args.length === 1)
5092
+ args.push(0);
5093
+ }
5094
+ else if (name_1 === 'scale') {
5095
+ if (args.length === 1)
5096
+ args.push(args[0]);
5097
+ }
5098
+ var functionData = transformFunctions[name_1];
5099
+ if (!functionData)
5100
+ return [];
5101
+ var parsedArgs = args.map(function (value) { return getOrCreateUnitValue(value); });
5102
+ result.push({ t: name_1, d: parsedArgs });
5103
+ }
5104
+ return result;
5105
+ }
5231
5106
  /**
5232
5107
  * none
5233
5108
  * scale(1) scale(1, 2)
5234
5109
  * scaleX(1)
5235
5110
  */
5236
- function parseTransform(string) {
5237
- string = (string || 'none').toLowerCase().trim();
5238
- if (string === 'none') {
5111
+ function parseTransform(transform) {
5112
+ if (Array.isArray(transform)) {
5113
+ return parseArrayTransform(transform);
5114
+ }
5115
+ transform = (transform || 'none').trim();
5116
+ if (transform === 'none') {
5239
5117
  return [];
5240
5118
  }
5241
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5242
5119
  var result = [];
5243
5120
  var match;
5244
5121
  var prevLastIndex = 0;
5245
- while ((match = transformRegExp.exec(string))) {
5122
+ TRANSFORM_REGEXP.lastIndex = 0;
5123
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5246
5124
  if (match.index !== prevLastIndex) {
5247
5125
  return [];
5248
5126
  }
@@ -5289,22 +5167,25 @@ function parseTransform(string) {
5289
5167
  parsedArgs.push(parsedArg);
5290
5168
  }
5291
5169
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5292
- if (transformRegExp.lastIndex === string.length) {
5170
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5293
5171
  return result;
5294
5172
  }
5295
5173
  }
5296
5174
  return [];
5297
5175
  }
5298
- function parseTransformUnmemoize(string) {
5299
- string = (string || 'none').toLowerCase().trim();
5300
- if (string === 'none') {
5176
+ function parseTransformUnmemoize(transform) {
5177
+ if (Array.isArray(transform)) {
5178
+ return parseArrayTransform(transform);
5179
+ }
5180
+ transform = (transform || 'none').trim();
5181
+ if (transform === 'none') {
5301
5182
  return [];
5302
5183
  }
5303
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5304
5184
  var result = [];
5305
5185
  var match;
5306
5186
  var prevLastIndex = 0;
5307
- while ((match = transformRegExp.exec(string))) {
5187
+ TRANSFORM_REGEXP.lastIndex = 0;
5188
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5308
5189
  if (match.index !== prevLastIndex) {
5309
5190
  return [];
5310
5191
  }
@@ -5351,7 +5232,7 @@ function parseTransformUnmemoize(string) {
5351
5232
  parsedArgs.push(parsedArg);
5352
5233
  }
5353
5234
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5354
- if (transformRegExp.lastIndex === string.length) {
5235
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5355
5236
  return result;
5356
5237
  }
5357
5238
  }
@@ -5363,7 +5244,7 @@ function convertItemToMatrix(item) {
5363
5244
  var z;
5364
5245
  var angle;
5365
5246
  switch (item.t) {
5366
- case 'rotatex':
5247
+ case 'rotateX':
5367
5248
  angle = deg2rad(convertAngleUnit(item.d[0]));
5368
5249
  return [
5369
5250
  1,
@@ -5383,7 +5264,7 @@ function convertItemToMatrix(item) {
5383
5264
  0,
5384
5265
  1,
5385
5266
  ];
5386
- case 'rotatey':
5267
+ case 'rotateY':
5387
5268
  angle = deg2rad(convertAngleUnit(item.d[0]));
5388
5269
  return [
5389
5270
  Math.cos(angle),
@@ -5404,7 +5285,7 @@ function convertItemToMatrix(item) {
5404
5285
  1,
5405
5286
  ];
5406
5287
  case 'rotate':
5407
- case 'rotatez':
5288
+ case 'rotateZ':
5408
5289
  angle = deg2rad(convertAngleUnit(item.d[0]));
5409
5290
  return [
5410
5291
  Math.cos(angle),
@@ -5481,11 +5362,11 @@ function convertItemToMatrix(item) {
5481
5362
  0,
5482
5363
  1,
5483
5364
  ];
5484
- case 'scalex':
5365
+ case 'scaleX':
5485
5366
  return [item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5486
- case 'scaley':
5367
+ case 'scaleY':
5487
5368
  return [1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5488
- case 'scalez':
5369
+ case 'scaleZ':
5489
5370
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1];
5490
5371
  case 'scale3d':
5491
5372
  return [
@@ -5527,10 +5408,10 @@ function convertItemToMatrix(item) {
5527
5408
  0,
5528
5409
  1,
5529
5410
  ];
5530
- case 'skewx':
5411
+ case 'skewX':
5531
5412
  angle = deg2rad(convertAngleUnit(item.d[0]));
5532
5413
  return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5533
- case 'skewy':
5414
+ case 'skewY':
5534
5415
  angle = deg2rad(convertAngleUnit(item.d[0]));
5535
5416
  return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5536
5417
  case 'translate':
@@ -5538,13 +5419,13 @@ function convertItemToMatrix(item) {
5538
5419
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5539
5420
  y = convertPercentUnit(item.d[1], 0, null) || 0;
5540
5421
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, 0, 1];
5541
- case 'translatex':
5422
+ case 'translateX':
5542
5423
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5543
5424
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
5544
- case 'translatey':
5425
+ case 'translateY':
5545
5426
  y = convertPercentUnit(item.d[0], 0, null) || 0;
5546
5427
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, y, 0, 1];
5547
- case 'translatez':
5428
+ case 'translateZ':
5548
5429
  z = convertPercentUnit(item.d[0], 0, null) || 0;
5549
5430
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, z, 1];
5550
5431
  case 'translate3d':
@@ -5785,13 +5666,13 @@ function quat(fromQ, toQ, f) {
5785
5666
  }
5786
5667
  return quat;
5787
5668
  }
5788
- // scalex/y/z -> scale
5669
+ // scaleX/Y/Z -> scale
5789
5670
  function typeTo2D(type) {
5790
- return type.replace(/[xy]/, '');
5671
+ return type.replace(/[XY]/, '');
5791
5672
  }
5792
- // scalex/y/z -> scale3d
5673
+ // scaleX/Y/Z -> scale3d
5793
5674
  function typeTo3D(type) {
5794
- return type.replace(/(x|y|z|3d)?$/, '3d');
5675
+ return type.replace(/(X|Y|Z|3d)?$/, '3d');
5795
5676
  }
5796
5677
  var isMatrixOrPerspective = function (lt, rt) {
5797
5678
  return ((lt === 'perspective' && rt === 'perspective') ||
@@ -5972,39 +5853,6 @@ var parseTransformOrigin = memoize(function (value) {
5972
5853
  ];
5973
5854
  }
5974
5855
  });
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
5856
  function convertKeyword2Percent(keyword) {
6009
5857
  if (keyword === 'center') {
6010
5858
  return '50%';
@@ -6599,23 +6447,7 @@ var BUILT_IN_PROPERTIES = [
6599
6447
  ];
6600
6448
  var GEOMETRY_ATTRIBUTE_NAMES = BUILT_IN_PROPERTIES.filter(function (n) { return !!n.l; }).map(function (n) { return n.n; });
6601
6449
  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
6450
  var DefaultStyleValueRegistry = /** @class */ (function () {
6615
- /**
6616
- * need recalc later
6617
- */
6618
- // dirty = false;
6619
6451
  function DefaultStyleValueRegistry(runtime) {
6620
6452
  var _this = this;
6621
6453
  this.runtime = runtime;
@@ -6628,9 +6460,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6628
6460
  propertyMetadataCache[name] = metadata;
6629
6461
  });
6630
6462
  };
6631
- DefaultStyleValueRegistry.prototype.unregisterMetadata = function (name) {
6632
- delete propertyMetadataCache[name];
6633
- };
6634
6463
  DefaultStyleValueRegistry.prototype.getPropertySyntax = function (syntax) {
6635
6464
  return this.runtime.CSSPropertySyntaxFactory[syntax];
6636
6465
  };
@@ -6644,7 +6473,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6644
6473
  * * post process
6645
6474
  */
6646
6475
  DefaultStyleValueRegistry.prototype.processProperties = function (object, attributes, options) {
6647
- var _this = this;
6648
6476
  if (options === void 0) { options = {
6649
6477
  skipUpdateAttribute: false,
6650
6478
  skipParse: false,
@@ -6652,365 +6480,116 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6652
6480
  usedAttributes: [],
6653
6481
  memoize: true,
6654
6482
  }; }
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
- }
6483
+ Object.assign(object.attributes, attributes);
6484
+ // clipPath
6485
+ var oldClipPath = object.parsedStyle.clipPath;
6486
+ var oldOffsetPath = object.parsedStyle.offsetPath;
6487
+ Object.assign(object.parsedStyle, attributes);
6488
+ var needUpdateGeometry = !!options.forceUpdateGeometry;
6489
+ if (!needUpdateGeometry &&
6490
+ GEOMETRY_ATTRIBUTE_NAMES.some(function (name) { return name in attributes; })) {
6491
+ needUpdateGeometry = true;
6492
+ }
6493
+ if (attributes.fill) {
6494
+ object.parsedStyle.fill = parseColor(attributes.fill);
6495
+ }
6496
+ if (attributes.stroke) {
6497
+ object.parsedStyle.stroke = parseColor(attributes.stroke);
6498
+ }
6499
+ if (attributes.shadowColor) {
6500
+ object.parsedStyle.shadowColor = parseColor(attributes.shadowColor);
6501
+ }
6502
+ if (attributes.filter) {
6503
+ object.parsedStyle.filter = parseFilter(attributes.filter);
6504
+ }
6505
+ // Rect
6506
+ // @ts-ignore
6507
+ if (!util.isNil(attributes.radius)) {
6705
6508
  // @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
6509
+ object.parsedStyle.radius = parseDimensionArrayFormat(
6728
6510
  // @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
- }
6511
+ attributes.radius, 4);
6512
+ }
6513
+ // Polyline
6514
+ if (!util.isNil(attributes.lineDash)) {
6515
+ object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6516
+ }
6517
+ // @ts-ignore
6518
+ if (attributes.points) {
6736
6519
  // @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
- }
6520
+ object.parsedStyle.points = parsePoints(attributes.points);
6521
+ }
6522
+ // Path
6523
+ // @ts-ignore
6524
+ if (attributes.d === '') {
6525
+ object.parsedStyle.d = tslib.__assign({}, EMPTY_PARSED_PATH);
6526
+ }
6527
+ // @ts-ignore
6528
+ if (attributes.d) {
6529
+ object.parsedStyle.d = parsePath(
6744
6530
  // @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
- }
6531
+ attributes.d);
6772
6532
  }
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
- }
6533
+ // Text
6534
+ if (attributes.textTransform) {
6535
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TEXT_TRANSFORM].calculator(null, null, { value: attributes.textTransform }, object, null);
6854
6536
  }
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';
6537
+ if (!util.isUndefined(attributes.clipPath)) {
6538
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.DEFINED_PATH].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6539
+ }
6540
+ if (attributes.offsetPath) {
6541
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.DEFINED_PATH].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6542
+ }
6543
+ if (attributes.transform) {
6544
+ object.parsedStyle.transform = parseTransform(attributes.transform);
6545
+ }
6546
+ if (attributes.transformOrigin) {
6547
+ object.parsedStyle.transformOrigin = parseTransformOrigin(attributes.transformOrigin);
6864
6548
  }
6865
- if (value === 'unset' || value === 'initial' || value === 'inherit') {
6866
- // computed = new CSSKeywordValue(value);
6867
- computed = getOrCreateKeyword(value);
6549
+ // Marker
6550
+ // @ts-ignore
6551
+ if (attributes.markerStart) {
6552
+ object.parsedStyle.markerStart = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator(null,
6553
+ // @ts-ignore
6554
+ attributes.markerStart,
6555
+ // @ts-ignore
6556
+ attributes.markerStart, null, null);
6868
6557
  }
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
- }
6558
+ // @ts-ignore
6559
+ if (attributes.markerEnd) {
6560
+ object.parsedStyle.markerEnd = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator(null,
6561
+ // @ts-ignore
6562
+ attributes.markerEnd,
6563
+ // @ts-ignore
6564
+ attributes.markerEnd, null, null);
6888
6565
  }
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
- }
6566
+ // @ts-ignore
6567
+ if (attributes.markerMid) {
6568
+ object.parsedStyle.markerMid = this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.MARKER].calculator('',
6569
+ // @ts-ignore
6570
+ attributes.markerMid,
6571
+ // @ts-ignore
6572
+ attributes.markerMid, null, null);
6951
6573
  }
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
- }
6574
+ if (!util.isNil(attributes.zIndex)) {
6575
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.Z_INDEX].postProcessor(object);
6964
6576
  }
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);
6577
+ if (!util.isNil(attributes.offsetDistance)) {
6578
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.OFFSET_DISTANCE].postProcessor(object);
6974
6579
  }
6975
- if (properties.indexOf(name) === -1) {
6976
- properties.push(name);
6580
+ if (attributes.transform) {
6581
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TRANSFORM].postProcessor(object);
6977
6582
  }
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
- }
6583
+ if (attributes.transformOrigin) {
6584
+ this.runtime.CSSPropertySyntaxFactory[exports.PropertySyntax.TRANSFORM_ORIGIN].postProcessor(object);
7002
6585
  }
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);
6586
+ if (needUpdateGeometry) {
6587
+ object.geometry.dirty = true;
6588
+ object.renderable.boundsDirty = true;
6589
+ object.renderable.renderBoundsDirty = true;
6590
+ if (!options.forceUpdateGeometry) {
6591
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6592
+ }
7014
6593
  }
7015
6594
  };
7016
6595
  /**
@@ -7036,12 +6615,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7036
6615
  Math.abs(hheight),
7037
6616
  hdepth,
7038
6617
  ];
7039
- // const halfExtents = vec3.set(
7040
- // tmpVec3a,
7041
- // Math.abs(width) / 2,
7042
- // Math.abs(height) / 2,
7043
- // depth / 2,
7044
- // );
7045
6618
  // anchor is center by default, don't account for lineWidth here
7046
6619
  var _h = parsedStyle, stroke = _h.stroke, _j = _h.lineWidth, lineWidth = _j === void 0 ? 1 : _j,
7047
6620
  // lineCap,
@@ -7061,26 +6634,13 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7061
6634
  nodeName === exports.Shape.PATH
7062
6635
  ? Math.SQRT2
7063
6636
  : 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
6637
  // append border only if stroke existed
7071
6638
  var hasStroke = stroke && !stroke.isNone;
7072
6639
  if (hasStroke) {
7073
6640
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) *
7074
6641
  expansion;
7075
- // halfExtents[0] += halfLineWidth[0];
7076
- // halfExtents[1] += halfLineWidth[1];
7077
6642
  halfExtents[0] += halfLineWidth;
7078
6643
  halfExtents[1] += halfLineWidth;
7079
- // vec3.add(
7080
- // halfExtents,
7081
- // halfExtents,
7082
- // vec3.set(tmpVec3c, halfLineWidth, halfLineWidth, 0),
7083
- // );
7084
6644
  }
7085
6645
  geometry_1.renderBounds.update(center, halfExtents);
7086
6646
  // account for shadow, only support constant value now
@@ -7105,7 +6665,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7105
6665
  var name = _a.name, params = _a.params;
7106
6666
  if (name === 'blur') {
7107
6667
  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]));
6668
+ geometry_1.renderBounds.update(geometry_1.renderBounds.center, glMatrix.vec3.add(geometry_1.renderBounds.halfExtents, geometry_1.renderBounds.halfExtents, [blurRadius, blurRadius, 0]));
7109
6669
  }
7110
6670
  else if (name === 'drop-shadow') {
7111
6671
  var shadowOffsetX = params[0].value;
@@ -7167,21 +6727,11 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7167
6727
  }
7168
6728
  }
7169
6729
  };
7170
- DefaultStyleValueRegistry.prototype.isPropertyInheritable = function (name) {
7171
- var metadata = propertyMetadataCache[name];
7172
- if (!metadata) {
7173
- return false;
7174
- }
7175
- return metadata.inh;
7176
- };
7177
6730
  return DefaultStyleValueRegistry;
7178
6731
  }());
7179
6732
 
7180
6733
  var CSSPropertyAngle = /** @class */ (function () {
7181
6734
  function CSSPropertyAngle() {
7182
- this.parser = parseAngle;
7183
- this.parserUnmemoize = parseAngleUnmemoize;
7184
- this.parserWithCSSDisabled = null;
7185
6735
  this.mixer = mergeNumbers;
7186
6736
  }
7187
6737
  CSSPropertyAngle.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7218,7 +6768,6 @@ var CSSPropertyClipPath = /** @class */ (function () {
7218
6768
  var CSSPropertyColor = /** @class */ (function () {
7219
6769
  function CSSPropertyColor() {
7220
6770
  this.parser = parseColor;
7221
- this.parserWithCSSDisabled = parseColor;
7222
6771
  this.mixer = mergeColors;
7223
6772
  }
7224
6773
  CSSPropertyColor.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -7233,7 +6782,6 @@ var CSSPropertyColor = /** @class */ (function () {
7233
6782
 
7234
6783
  var CSSPropertyFilter = /** @class */ (function () {
7235
6784
  function CSSPropertyFilter() {
7236
- this.parser = parseFilter;
7237
6785
  }
7238
6786
  CSSPropertyFilter.prototype.calculator = function (name, oldParsed, parsed) {
7239
6787
  // unset or none
@@ -7254,9 +6802,6 @@ function getFontSize(object) {
7254
6802
  */
7255
6803
  var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7256
6804
  function CSSPropertyLengthOrPercentage() {
7257
- this.parser = parseLengthOrPercentage;
7258
- this.parserUnmemoize = parseLengthOrPercentageUnmemoize;
7259
- this.parserWithCSSDisabled = null;
7260
6805
  this.mixer = mergeNumbers;
7261
6806
  }
7262
6807
  /**
@@ -7271,7 +6816,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7271
6816
  return computed;
7272
6817
  }
7273
6818
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
7274
- var registry = runtime.styleValueRegistry;
7275
6819
  if (computed.unit === exports.UnitType.kPercentage) {
7276
6820
  // TODO: merge dimensions
7277
6821
  return 0;
@@ -7283,12 +6827,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7283
6827
  fontSize *= computed.value;
7284
6828
  return fontSize;
7285
6829
  }
7286
- else {
7287
- registry.addUnresolveProperty(object, name);
7288
- }
7289
- }
7290
- else {
7291
- registry.addUnresolveProperty(object, name);
7292
6830
  }
7293
6831
  return 0;
7294
6832
  }
@@ -7299,12 +6837,6 @@ var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7299
6837
  fontSize *= computed.value;
7300
6838
  return fontSize;
7301
6839
  }
7302
- else {
7303
- registry.addUnresolveProperty(object, name);
7304
- }
7305
- }
7306
- else {
7307
- registry.addUnresolveProperty(object, name);
7308
6840
  }
7309
6841
  return 0;
7310
6842
  }
@@ -7331,17 +6863,6 @@ var CSSPropertyLengthOrPercentage12 = /** @class */ (function () {
7331
6863
  function CSSPropertyLengthOrPercentage12() {
7332
6864
  this.mixer = mergeNumberLists;
7333
6865
  }
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
6866
  CSSPropertyLengthOrPercentage12.prototype.calculator = function (name, oldParsed, computed) {
7346
6867
  return computed.map(function (c) { return c.value; });
7347
6868
  };
@@ -7360,24 +6881,6 @@ var CSSPropertyLengthOrPercentage14 = /** @class */ (function () {
7360
6881
  function CSSPropertyLengthOrPercentage14() {
7361
6882
  this.mixer = mergeNumberLists;
7362
6883
  }
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
6884
  CSSPropertyLengthOrPercentage14.prototype.calculator = function (name, oldParsed, computed) {
7382
6885
  return computed.map(function (c) { return c.value; });
7383
6886
  };
@@ -7405,9 +6908,6 @@ var CSSPropertyMarker = /** @class */ (function () {
7405
6908
  var CSSPropertyNumber = /** @class */ (function () {
7406
6909
  function CSSPropertyNumber() {
7407
6910
  this.mixer = mergeNumbers;
7408
- this.parser = parseNumber;
7409
- this.parserUnmemoize = parseNumberUnmemoize;
7410
- this.parserWithCSSDisabled = null;
7411
6911
  }
7412
6912
  CSSPropertyNumber.prototype.calculator = function (name, oldParsed, computed) {
7413
6913
  return computed.value;
@@ -7417,9 +6917,6 @@ var CSSPropertyNumber = /** @class */ (function () {
7417
6917
 
7418
6918
  var CSSPropertyOffsetDistance = /** @class */ (function () {
7419
6919
  function CSSPropertyOffsetDistance() {
7420
- this.parser = parseNumber;
7421
- this.parserUnmemoize = parseNumberUnmemoize;
7422
- this.parserWithCSSDisabled = null;
7423
6920
  this.mixer = clampedMergeNumbers(0, 1);
7424
6921
  }
7425
6922
  CSSPropertyOffsetDistance.prototype.calculator = function (name, oldParsed, computed) {
@@ -7449,9 +6946,6 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
7449
6946
  */
7450
6947
  var CSSPropertyOpacity = /** @class */ (function () {
7451
6948
  function CSSPropertyOpacity() {
7452
- this.parser = parseNumber;
7453
- this.parserUnmemoize = parseNumberUnmemoize;
7454
- this.parserWithCSSDisabled = null;
7455
6949
  this.mixer = clampedMergeNumbers(0, 1);
7456
6950
  }
7457
6951
  CSSPropertyOpacity.prototype.calculator = function (name, oldParsed, computed) {
@@ -7466,7 +6960,6 @@ var CSSPropertyPath = /** @class */ (function () {
7466
6960
  * path2Curve
7467
6961
  */
7468
6962
  this.parser = parsePath;
7469
- this.parserWithCSSDisabled = parsePath;
7470
6963
  this.mixer = mergePaths;
7471
6964
  }
7472
6965
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
@@ -7490,7 +6983,6 @@ var CSSPropertyPath = /** @class */ (function () {
7490
6983
 
7491
6984
  var CSSPropertyPoints = /** @class */ (function () {
7492
6985
  function CSSPropertyPoints() {
7493
- this.parser = parsePoints;
7494
6986
  this.mixer = mergePoints;
7495
6987
  }
7496
6988
  return CSSPropertyPoints;
@@ -7554,20 +7046,26 @@ var CSSPropertyTextTransform = /** @class */ (function () {
7554
7046
  return CSSPropertyTextTransform;
7555
7047
  }());
7556
7048
 
7557
- var canvasMap = {};
7558
- var defaultCanvasIdCounter = 0;
7049
+ var definedProps = function (obj) {
7050
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
7051
+ var _b = tslib.__read(_a, 2), v = _b[1];
7052
+ return v !== undefined;
7053
+ }));
7054
+ };
7055
+
7056
+ var CANVAS_Map = new WeakMap();
7559
7057
  /**
7560
7058
  * destroy existed canvas with the same id
7561
7059
  */
7562
- function cleanExistedCanvas(container, canvas) {
7060
+ function cleanExistedCanvas(container, canvas, cleanUp) {
7563
7061
  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;
7062
+ var $dom = typeof container === 'string'
7063
+ ? document.getElementById(container)
7064
+ : container;
7065
+ if (CANVAS_Map.has($dom))
7066
+ CANVAS_Map.get($dom).destroy(cleanUp);
7067
+ else
7068
+ CANVAS_Map.set($dom, canvas);
7571
7069
  }
7572
7070
  }
7573
7071
  var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
@@ -7652,6 +7150,12 @@ var TOUCH_TO_POINTER = {
7652
7150
  };
7653
7151
  var clock = typeof performance === 'object' && performance.now ? performance : Date;
7654
7152
 
7153
+ function isInFragment(node) {
7154
+ if (node.nodeName === exports.Shape.FRAGMENT)
7155
+ return true;
7156
+ return node.getRootNode().nodeName === exports.Shape.FRAGMENT;
7157
+ }
7158
+
7655
7159
  function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
7656
7160
  // account for pointerEvents
7657
7161
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
@@ -7910,114 +7414,100 @@ function createSkewMatrix(skewMatrix, skewX, skewY) {
7910
7414
  skewMatrix[1] = Math.tan(skewY); // Skew X axis in Y direction
7911
7415
  return skewMatrix;
7912
7416
  }
7913
- var SCALE_EPSILON = 0.00001;
7914
- var tmpMat1 = glMatrix.mat4.create();
7915
- var tmpMat2 = glMatrix.mat4.create();
7417
+ var $mat4_1 = glMatrix.mat4.create();
7418
+ var $mat4_2 = glMatrix.mat4.create();
7419
+ var parser = {
7420
+ scale: function (d) {
7421
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7422
+ },
7423
+ scaleX: function (d) {
7424
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7425
+ },
7426
+ scaleY: function (d) {
7427
+ glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7428
+ },
7429
+ scaleZ: function (d) {
7430
+ glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7431
+ },
7432
+ scale3d: function (d) {
7433
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7434
+ },
7435
+ translate: function (d) {
7436
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
7437
+ },
7438
+ translateX: function (d) {
7439
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, 0, 0]);
7440
+ },
7441
+ translateY: function (d) {
7442
+ glMatrix.mat4.fromTranslation($mat4_1, [0, d[0].value, 0]);
7443
+ },
7444
+ translateZ: function (d) {
7445
+ glMatrix.mat4.fromTranslation($mat4_1, [0, 0, d[0].value]);
7446
+ },
7447
+ translate3d: function (d) {
7448
+ glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, d[2].value]);
7449
+ },
7450
+ rotate: function (d) {
7451
+ glMatrix.mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7452
+ },
7453
+ rotateX: function (d) {
7454
+ glMatrix.mat4.fromXRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7455
+ },
7456
+ rotateY: function (d) {
7457
+ glMatrix.mat4.fromYRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7458
+ },
7459
+ rotateZ: function (d) {
7460
+ glMatrix.mat4.fromZRotation($mat4_1, deg2rad(convertAngleUnit(d[0])));
7461
+ },
7462
+ rotate3d: function (d) {
7463
+ glMatrix.mat4.fromRotation($mat4_1, deg2rad(convertAngleUnit(d[3])), [
7464
+ d[0].value,
7465
+ d[1].value,
7466
+ d[2].value,
7467
+ ]);
7468
+ },
7469
+ skew: function (d) {
7470
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), deg2rad(d[1].value));
7471
+ },
7472
+ skewX: function (d) {
7473
+ createSkewMatrix($mat4_1, deg2rad(d[0].value), 0);
7474
+ },
7475
+ skewY: function (d) {
7476
+ createSkewMatrix($mat4_1, 0, deg2rad(d[0].value));
7477
+ },
7478
+ matrix: function (d) {
7479
+ // prettier-ignore
7480
+ 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);
7481
+ },
7482
+ matrix3d: function (d) {
7483
+ // @ts-ignore
7484
+ glMatrix.mat4.set.apply(glMatrix.mat4, tslib.__spreadArray([$mat4_1], tslib.__read(d.map(function (s) { return s.value; })), false));
7485
+ },
7486
+ };
7487
+ var optimizer = {
7488
+ translate: function (object, d) {
7489
+ object.setLocalPosition([d[0].value, d[1].value]);
7490
+ },
7491
+ translate3d: function (object, d) {
7492
+ object.setLocalPosition([d[0].value, d[1].value, d[2].value]);
7493
+ },
7494
+ };
7916
7495
  function parsedTransformToMat4(transform, object) {
7917
7496
  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));
7497
+ if (transform.length === 1 && optimizer[transform[0].t]) {
7498
+ optimizer[transform[0].t](object, transform[0].d);
7499
+ return;
7500
+ }
7501
+ var m = glMatrix.mat4.identity($mat4_2);
7502
+ for (var i = 0; i < transform.length; i++) {
7503
+ var _a = transform[i], t = _a.t, d = _a.d;
7504
+ var p = parser[t];
7505
+ if (p) {
7506
+ p(d);
7507
+ glMatrix.mat4.mul(m, m, $mat4_1);
8017
7508
  }
8018
- glMatrix.mat4.mul(m_1, m_1, tmpMat2);
8019
- });
8020
- object.setLocalTransform(m_1);
7509
+ }
7510
+ object.setLocalTransform(m);
8021
7511
  }
8022
7512
  else {
8023
7513
  object.resetLocalTransform();
@@ -8057,9 +7547,7 @@ function parsedTransformToMat4(transform, object) {
8057
7547
  */
8058
7548
  var CSSPropertyTransform = /** @class */ (function () {
8059
7549
  function CSSPropertyTransform() {
8060
- this.parser = parseTransform;
8061
- this.parserUnmemoize = parseTransformUnmemoize;
8062
- this.parserWithCSSDisabled = parseTransformUnmemoize;
7550
+ this.parser = parseTransformUnmemoize;
8063
7551
  this.mixer = mergeTransforms;
8064
7552
  }
8065
7553
  CSSPropertyTransform.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -8070,8 +7558,7 @@ var CSSPropertyTransform = /** @class */ (function () {
8070
7558
  return parsed;
8071
7559
  };
8072
7560
  CSSPropertyTransform.prototype.postProcessor = function (object) {
8073
- var transform = object.parsedStyle.transform;
8074
- parsedTransformToMat4(transform, object);
7561
+ parsedTransformToMat4(object.parsedStyle.transform, object);
8075
7562
  };
8076
7563
  return CSSPropertyTransform;
8077
7564
  }());
@@ -8083,8 +7570,6 @@ var CSSPropertyTransform = /** @class */ (function () {
8083
7570
  */
8084
7571
  var CSSPropertyTransformOrigin = /** @class */ (function () {
8085
7572
  function CSSPropertyTransformOrigin() {
8086
- this.parser = parseTransformOrigin;
8087
- this.parserUnmemoize = parseTransformOriginUnmemoize;
8088
7573
  }
8089
7574
  CSSPropertyTransformOrigin.prototype.postProcessor = function (object) {
8090
7575
  var transformOrigin = object.parsedStyle.transformOrigin;
@@ -8102,8 +7587,6 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
8102
7587
 
8103
7588
  var CSSPropertyZIndex = /** @class */ (function () {
8104
7589
  function CSSPropertyZIndex() {
8105
- this.parser = parseNumber;
8106
- this.parserUnmemoize = parseNumberUnmemoize;
8107
7590
  }
8108
7591
  CSSPropertyZIndex.prototype.calculator = function (name, oldParsed, computed, object) {
8109
7592
  return computed.value;
@@ -8262,17 +7745,8 @@ var TextUpdater = /** @class */ (function () {
8262
7745
  this.globalRuntime = globalRuntime;
8263
7746
  }
8264
7747
  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;
7748
+ var text = parsedStyle.text;
7749
+ return text;
8276
7750
  };
8277
7751
  TextUpdater.prototype.update = function (parsedStyle, object) {
8278
7752
  var _a, _b;
@@ -8303,7 +7777,7 @@ var TextUpdater = /** @class */ (function () {
8303
7777
  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
7778
  var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
8305
7779
  parsedStyle.metrics = metrics;
8306
- var width = metrics.width, height = metrics.height, lineHeight = metrics.lineHeight, fontProperties = metrics.fontProperties;
7780
+ var width = metrics.width, height = metrics.height;
8307
7781
  var hwidth = width / 2;
8308
7782
  var hheight = height / 2;
8309
7783
  // default 'left'
@@ -8316,18 +7790,12 @@ var TextUpdater = /** @class */ (function () {
8316
7790
  }
8317
7791
  var lineYOffset = y - hheight;
8318
7792
  if (textBaseline === 'middle') {
8319
- // eslint-disable-next-line prefer-destructuring
8320
7793
  lineYOffset += hheight;
8321
7794
  }
8322
7795
  else if (textBaseline === 'top' || textBaseline === 'hanging') {
8323
7796
  lineYOffset += hheight * 2;
8324
7797
  }
8325
- else if (textBaseline === 'alphabetic') {
8326
- // prevent calling getImageData for ascent metrics
8327
- lineYOffset += this.globalRuntime.enableCSSParsing
8328
- ? lineHeight - fontProperties.ascent
8329
- : 0;
8330
- }
7798
+ else if (textBaseline === 'alphabetic') ;
8331
7799
  else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
8332
7800
  lineYOffset += 0;
8333
7801
  }
@@ -8783,7 +8251,7 @@ var CustomEvent = /** @class */ (function (_super) {
8783
8251
  return CustomEvent;
8784
8252
  }(FederatedEvent));
8785
8253
 
8786
- var DELEGATION_SPLITTER = ':';
8254
+ var CANVAS_CACHE = new WeakMap();
8787
8255
  /**
8788
8256
  * Objects that can receive events and may have listeners for them.
8789
8257
  * eg. Element, Canvas, DisplayObject
@@ -8809,43 +8277,21 @@ var EventTarget = /** @class */ (function () {
8809
8277
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener
8810
8278
  */
8811
8279
  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) {
8280
+ var _a, _b;
8281
+ var capture = false;
8282
+ var once = false;
8283
+ if (util.isBoolean(options))
8284
+ capture = options;
8285
+ else if (options)
8286
+ (_a = options.capture, capture = _a === void 0 ? false : _a, _b = options.once, once = _b === void 0 ? false : _b);
8287
+ if (capture)
8288
+ type += 'capture';
8289
+ listener = util.isFunction(listener) ? listener : listener.handleEvent;
8290
+ var context = util.isFunction(listener) ? undefined : listener;
8291
+ if (once)
8844
8292
  this.emitter.once(type, listener, context);
8845
- }
8846
- else {
8293
+ else
8847
8294
  this.emitter.on(type, listener, context);
8848
- }
8849
8295
  return this;
8850
8296
  };
8851
8297
  /**
@@ -8863,13 +8309,17 @@ var EventTarget = /** @class */ (function () {
8863
8309
  return this;
8864
8310
  };
8865
8311
  EventTarget.prototype.removeAllEventListeners = function () {
8866
- this.emitter.removeAllListeners();
8312
+ var _a;
8313
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
8867
8314
  };
8868
8315
  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;
8316
+ if (!this.emitter)
8317
+ return this;
8318
+ var capture = util.isBoolean(options) ? options : options === null || options === void 0 ? void 0 : options.capture;
8319
+ if (capture)
8320
+ type += 'capture';
8321
+ listener = util.isFunction(listener) ? listener : listener === null || listener === void 0 ? void 0 : listener.handleEvent;
8322
+ var context = util.isFunction(listener) ? undefined : listener;
8873
8323
  this.emitter.off(type, listener, context);
8874
8324
  return this;
8875
8325
  };
@@ -8885,36 +8335,34 @@ var EventTarget = /** @class */ (function () {
8885
8335
  * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
8886
8336
  */
8887
8337
  EventTarget.prototype.dispatchEvent = function (e, skipPropagate) {
8888
- var _a, _b;
8338
+ var _a;
8889
8339
  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;
8340
+ var canvas = CANVAS_CACHE.get(this);
8341
+ if (!canvas) {
8342
+ // @ts-expect-error document may be defined in inherited class
8343
+ if (this.document)
8344
+ canvas = this;
8345
+ // @ts-expect-error defaultView may be defined in inherited class
8346
+ else if (this.defaultView)
8347
+ canvas = this.defaultView;
8348
+ else
8349
+ canvas = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
8350
+ if (canvas)
8351
+ CANVAS_CACHE.set(this, canvas);
8905
8352
  }
8906
- // assign event manager
8907
8353
  if (canvas) {
8908
- e.manager = canvas.getEventService() || null;
8909
- if (!e.manager) {
8354
+ e.manager = canvas.getEventService();
8355
+ if (!e.manager)
8910
8356
  return false;
8911
- }
8912
8357
  e.defaultPrevented = false;
8913
- e.path = [];
8914
- if (!skipPropagate) {
8358
+ if (e.path)
8359
+ e.path.length = 0;
8360
+ // @ts-ignore
8361
+ else
8362
+ e.page = [];
8363
+ if (!skipPropagate)
8915
8364
  e.target = this;
8916
- }
8917
- (_b = e.manager) === null || _b === void 0 ? void 0 : _b.dispatchEvent(e, e.type, skipPropagate);
8365
+ e.manager.dispatchEvent(e, e.type, skipPropagate);
8918
8366
  }
8919
8367
  return !e.defaultPrevented;
8920
8368
  };
@@ -9212,12 +8660,19 @@ var Node = /** @class */ (function (_super) {
9212
8660
  }
9213
8661
  return temp;
9214
8662
  };
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
- });
8663
+ /**
8664
+ * iterate current node and its descendants
8665
+ * @param callback - callback to execute for each node, return false to break
8666
+ * @param assigned - whether to iterate assigned nodes
8667
+ */
8668
+ Node.prototype.forEach = function (callback) {
8669
+ var result = callback(this);
8670
+ if (result !== false) {
8671
+ var nodes = this.childNodes;
8672
+ var length_1 = nodes.length;
8673
+ for (var i = 0; i < length_1; i++) {
8674
+ nodes[i].forEach(callback);
8675
+ }
9221
8676
  }
9222
8677
  };
9223
8678
  /**
@@ -10217,10 +9672,6 @@ var RenderingService = /** @class */ (function () {
10217
9672
  RenderingService.prototype.renderDisplayObject = function (displayObject, canvasConfig, renderingContext) {
10218
9673
  var _this = this;
10219
9674
  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
9675
  // TODO: relayout
10225
9676
  // dirtycheck first
10226
9677
  var renderable = displayObject.renderable;
@@ -10427,26 +9878,6 @@ var DefaultSceneGraphSelector = /** @class */ (function () {
10427
9878
  return DefaultSceneGraphSelector;
10428
9879
  }());
10429
9880
 
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
9881
  /**
10451
9882
  * built-in events for element
10452
9883
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent
@@ -10484,6 +9915,26 @@ exports.ElementEvent = void 0;
10484
9915
  ElementEvent["CULLED"] = "culled";
10485
9916
  })(exports.ElementEvent || (exports.ElementEvent = {}));
10486
9917
 
9918
+ var MutationEvent = /** @class */ (function (_super) {
9919
+ tslib.__extends(MutationEvent, _super);
9920
+ function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
9921
+ var _this = _super.call(this, null) || this;
9922
+ _this.relatedNode = relatedNode;
9923
+ _this.prevValue = prevValue;
9924
+ _this.newValue = newValue;
9925
+ _this.attrName = attrName;
9926
+ _this.attrChange = attrChange;
9927
+ _this.prevParsedValue = prevParsedValue;
9928
+ _this.newParsedValue = newParsedValue;
9929
+ _this.type = typeArg;
9930
+ return _this;
9931
+ }
9932
+ MutationEvent.ADDITION = 2;
9933
+ MutationEvent.MODIFICATION = 1;
9934
+ MutationEvent.REMOVAL = 3;
9935
+ return MutationEvent;
9936
+ }(FederatedEvent));
9937
+
10487
9938
  function markRenderableDirty(e) {
10488
9939
  var renderable = e.renderable;
10489
9940
  if (renderable) {
@@ -10492,6 +9943,33 @@ function markRenderableDirty(e) {
10492
9943
  }
10493
9944
  }
10494
9945
  var reparentEvent = new MutationEvent(exports.ElementEvent.REPARENT, null, '', '', '', 0, '', '');
9946
+ // Object pooling
9947
+ /** do not modify this objects */
9948
+ var $vec2Zero = glMatrix.vec2.create();
9949
+ /** do not modify this objects */
9950
+ var $vec3Zero = glMatrix.vec3.create();
9951
+ /** do not modify this objects */
9952
+ var $vec3One = glMatrix.vec3.fromValues(1, 1, 1);
9953
+ /** do not modify this objects */
9954
+ var $mat4Identity = glMatrix.mat4.create();
9955
+ /** shared objects */
9956
+ var $vec2 = glMatrix.vec2.create();
9957
+ /** shared objects */
9958
+ var $vec3$1 = glMatrix.vec3.create();
9959
+ /** shared objects */
9960
+ var $mat4 = glMatrix.mat4.create();
9961
+ /** shared objects */
9962
+ var $quat$1 = glMatrix.quat.create();
9963
+ var $setLocalTransform_1 = glMatrix.vec3.create();
9964
+ var $setLocalTransform_2 = glMatrix.quat.create();
9965
+ var $setLocalTransform_3 = glMatrix.vec3.create();
9966
+ var $setLocalPosition = glMatrix.vec3.create();
9967
+ var $setPosition_1 = glMatrix.vec3.create();
9968
+ var $setPosition_ParentInvertMatrix = glMatrix.mat4.create();
9969
+ var $setEulerAngles_InvParentRot = glMatrix.quat.create();
9970
+ var $rotateLocal = glMatrix.quat.create();
9971
+ var $rotate_ParentInvertRotation = glMatrix.quat.create();
9972
+ var $triggerPendingEvents_detail = { affectChildren: true };
10495
9973
  /**
10496
9974
  * update transform in scene graph
10497
9975
  *
@@ -10499,253 +9977,11 @@ var reparentEvent = new MutationEvent(exports.ElementEvent.REPARENT, null, '', '
10499
9977
  */
10500
9978
  var DefaultSceneGraphService = /** @class */ (function () {
10501
9979
  function DefaultSceneGraphService(runtime) {
10502
- var _this = this;
10503
9980
  this.runtime = runtime;
10504
- this.pendingEvents = [];
9981
+ // target -> affectChildren
9982
+ this.pendingEvents = new Map();
10505
9983
  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
- };
10724
9984
  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
9985
  }
10750
9986
  DefaultSceneGraphService.prototype.matches = function (query, root) {
10751
9987
  return this.runtime.sceneGraphSelector.is(query, root);
@@ -10764,12 +10000,23 @@ var DefaultSceneGraphService = /** @class */ (function () {
10764
10000
  detached = child.parentNode !== parent;
10765
10001
  this.detach(child);
10766
10002
  }
10003
+ var isChildFragment = child.nodeName === exports.Shape.FRAGMENT;
10004
+ var isAttachToFragment = isInFragment(parent);
10767
10005
  child.parentNode = parent;
10768
- if (!util.isNil(index)) {
10769
- child.parentNode.childNodes.splice(index, 0, child);
10006
+ var nodes = isChildFragment
10007
+ ? child.childNodes
10008
+ : [child];
10009
+ if (util.isNumber(index)) {
10010
+ nodes.forEach(function (node) {
10011
+ parent.childNodes.splice(index, 0, node);
10012
+ node.parentNode = parent;
10013
+ });
10770
10014
  }
10771
10015
  else {
10772
- child.parentNode.childNodes.push(child);
10016
+ nodes.forEach(function (node) {
10017
+ parent.childNodes.push(node);
10018
+ node.parentNode = parent;
10019
+ });
10773
10020
  }
10774
10021
  // parent needs re-sort
10775
10022
  var sortable = parent.sortable;
@@ -10783,13 +10030,15 @@ var DefaultSceneGraphService = /** @class */ (function () {
10783
10030
  sortable.dirty = true;
10784
10031
  sortable.dirtyReason = exports.SortReason.ADDED;
10785
10032
  }
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);
10033
+ if (isAttachToFragment)
10034
+ return;
10035
+ if (isChildFragment)
10036
+ this.dirtifyFragment(child);
10037
+ else {
10038
+ var transform = child.transformable;
10039
+ if (transform) {
10040
+ this.dirtifyWorld(child, transform);
10041
+ }
10793
10042
  }
10794
10043
  if (detached) {
10795
10044
  child.dispatchEvent(reparentEvent);
@@ -10857,6 +10106,70 @@ var DefaultSceneGraphService = /** @class */ (function () {
10857
10106
  originVec[2] = origin[2] || 0;
10858
10107
  this.dirtifyLocal(element, transform);
10859
10108
  };
10109
+ /**
10110
+ * rotate in world space
10111
+ */
10112
+ DefaultSceneGraphService.prototype.rotate = function (element, degrees, y, z) {
10113
+ if (y === void 0) { y = 0; }
10114
+ if (z === void 0) { z = 0; }
10115
+ if (typeof degrees === 'number') {
10116
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10117
+ }
10118
+ var transform = element.transformable;
10119
+ if (element.parentNode === null ||
10120
+ !element.parentNode.transformable) {
10121
+ this.rotateLocal(element, degrees);
10122
+ }
10123
+ else {
10124
+ var rotation = $quat$1;
10125
+ glMatrix.quat.fromEuler(rotation, degrees[0], degrees[1], degrees[2]);
10126
+ var rot = this.getRotation(element);
10127
+ var parentRot = this.getRotation(element.parentNode);
10128
+ glMatrix.quat.copy($rotate_ParentInvertRotation, parentRot);
10129
+ glMatrix.quat.invert($rotate_ParentInvertRotation, $rotate_ParentInvertRotation);
10130
+ glMatrix.quat.multiply(rotation, $rotate_ParentInvertRotation, rotation);
10131
+ glMatrix.quat.multiply(transform.localRotation, rotation, rot);
10132
+ glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10133
+ this.dirtifyLocal(element, transform);
10134
+ }
10135
+ };
10136
+ /**
10137
+ * rotate in local space
10138
+ * @see @see https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmquaternionrotationrollpitchyaw
10139
+ */
10140
+ DefaultSceneGraphService.prototype.rotateLocal = function (element, degrees, y, z) {
10141
+ if (y === void 0) { y = 0; }
10142
+ if (z === void 0) { z = 0; }
10143
+ if (typeof degrees === 'number') {
10144
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10145
+ }
10146
+ var transform = element.transformable;
10147
+ glMatrix.quat.fromEuler($rotateLocal, degrees[0], degrees[1], degrees[2]);
10148
+ glMatrix.quat.mul(transform.localRotation, transform.localRotation, $rotateLocal);
10149
+ this.dirtifyLocal(element, transform);
10150
+ };
10151
+ /**
10152
+ * set euler angles(degrees) in world space
10153
+ */
10154
+ DefaultSceneGraphService.prototype.setEulerAngles = function (element, degrees, y, z) {
10155
+ if (y === void 0) { y = 0; }
10156
+ if (z === void 0) { z = 0; }
10157
+ if (typeof degrees === 'number') {
10158
+ degrees = glMatrix.vec3.fromValues(degrees, y, z);
10159
+ }
10160
+ var transform = element.transformable;
10161
+ if (element.parentNode === null ||
10162
+ !element.parentNode.transformable) {
10163
+ this.setLocalEulerAngles(element, degrees);
10164
+ }
10165
+ else {
10166
+ glMatrix.quat.fromEuler(transform.localRotation, degrees[0], degrees[1], degrees[2]);
10167
+ var parentRotation = this.getRotation(element.parentNode);
10168
+ glMatrix.quat.copy($setEulerAngles_InvParentRot, glMatrix.quat.invert($quat$1, parentRotation));
10169
+ glMatrix.quat.mul(transform.localRotation, transform.localRotation, $setEulerAngles_InvParentRot);
10170
+ this.dirtifyLocal(element, transform);
10171
+ }
10172
+ };
10860
10173
  /**
10861
10174
  * set euler angles(degrees) in local space
10862
10175
  */
@@ -10874,32 +10187,140 @@ var DefaultSceneGraphService = /** @class */ (function () {
10874
10187
  }
10875
10188
  };
10876
10189
  /**
10877
- * scale in local space
10190
+ * translate in local space
10191
+ *
10192
+ * @example
10193
+ * ```
10194
+ * translateLocal(x, y, z)
10195
+ * translateLocal(vec3(x, y, z))
10196
+ * ```
10197
+ */
10198
+ DefaultSceneGraphService.prototype.translateLocal = function (element, translation, y, z) {
10199
+ if (y === void 0) { y = 0; }
10200
+ if (z === void 0) { z = 0; }
10201
+ if (typeof translation === 'number') {
10202
+ translation = glMatrix.vec3.fromValues(translation, y, z);
10203
+ }
10204
+ var transform = element.transformable;
10205
+ if (glMatrix.vec3.equals(translation, $vec3Zero))
10206
+ return;
10207
+ glMatrix.vec3.transformQuat(translation, translation, transform.localRotation);
10208
+ glMatrix.vec3.add(transform.localPosition, transform.localPosition, translation);
10209
+ this.dirtifyLocal(element, transform);
10210
+ };
10211
+ /**
10212
+ * move to position in world space
10213
+ *
10214
+ * 对应 g 原版的 move/moveTo
10215
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L684-L689
10216
+ */
10217
+ DefaultSceneGraphService.prototype.setPosition = function (element, position) {
10218
+ var _a;
10219
+ var transform = element.transformable;
10220
+ $setPosition_1[0] = position[0];
10221
+ $setPosition_1[1] = position[1];
10222
+ $setPosition_1[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10223
+ if (glMatrix.vec3.equals(this.getPosition(element), $setPosition_1)) {
10224
+ return;
10225
+ }
10226
+ glMatrix.vec3.copy(transform.position, $setPosition_1);
10227
+ if (element.parentNode === null ||
10228
+ !element.parentNode.transformable) {
10229
+ glMatrix.vec3.copy(transform.localPosition, $setPosition_1);
10230
+ }
10231
+ else {
10232
+ var parentTransform = element.parentNode.transformable;
10233
+ glMatrix.mat4.copy($setPosition_ParentInvertMatrix, parentTransform.worldTransform);
10234
+ glMatrix.mat4.invert($setPosition_ParentInvertMatrix, $setPosition_ParentInvertMatrix);
10235
+ glMatrix.vec3.transformMat4(transform.localPosition, $setPosition_1, $setPosition_ParentInvertMatrix);
10236
+ }
10237
+ this.dirtifyLocal(element, transform);
10238
+ };
10239
+ /**
10240
+ * move to position in local space
10878
10241
  */
10879
- DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling, dirtify) {
10242
+ DefaultSceneGraphService.prototype.setLocalPosition = function (element, position, dirtify) {
10243
+ var _a;
10880
10244
  if (dirtify === void 0) { dirtify = true; }
10881
10245
  var transform = element.transformable;
10882
- glMatrix.vec3.multiply(transform.localScale, transform.localScale, glMatrix.vec3.fromValues(scaling[0], scaling[1], scaling[2] || 1));
10246
+ $setLocalPosition[0] = position[0];
10247
+ $setLocalPosition[1] = position[1];
10248
+ $setLocalPosition[2] = (_a = position[2]) !== null && _a !== void 0 ? _a : 0;
10249
+ if (glMatrix.vec3.equals(transform.localPosition, $setLocalPosition)) {
10250
+ return;
10251
+ }
10252
+ glMatrix.vec3.copy(transform.localPosition, $setLocalPosition);
10883
10253
  if (dirtify) {
10884
10254
  this.dirtifyLocal(element, transform);
10885
10255
  }
10886
10256
  };
10257
+ /**
10258
+ * scale in local space
10259
+ */
10260
+ DefaultSceneGraphService.prototype.scaleLocal = function (element, scaling) {
10261
+ var _a;
10262
+ var transform = element.transformable;
10263
+ 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));
10264
+ this.dirtifyLocal(element, transform);
10265
+ };
10887
10266
  DefaultSceneGraphService.prototype.setLocalScale = function (element, scaling, dirtify) {
10267
+ var _a;
10888
10268
  if (dirtify === void 0) { dirtify = true; }
10889
10269
  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)) {
10270
+ glMatrix.vec3.set($vec3$1, scaling[0], scaling[1], (_a = scaling[2]) !== null && _a !== void 0 ? _a : transform.localScale[2]);
10271
+ if (glMatrix.vec3.equals($vec3$1, transform.localScale)) {
10892
10272
  return;
10893
10273
  }
10894
- glMatrix.vec3.copy(transform.localScale, updatedScaling);
10274
+ glMatrix.vec3.copy(transform.localScale, $vec3$1);
10895
10275
  if (dirtify) {
10896
10276
  this.dirtifyLocal(element, transform);
10897
10277
  }
10898
10278
  };
10279
+ /**
10280
+ * translate in world space
10281
+ *
10282
+ * @example
10283
+ * ```
10284
+ * translate(x, y, z)
10285
+ * translate(vec3(x, y, z))
10286
+ * ```
10287
+ *
10288
+ * 对应 g 原版的 translate 2D
10289
+ * @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
10290
+ */
10291
+ DefaultSceneGraphService.prototype.translate = function (element, translation, y, z) {
10292
+ if (y === void 0) { y = 0; }
10293
+ if (z === void 0) { z = 0; }
10294
+ if (typeof translation === 'number') {
10295
+ translation = glMatrix.vec3.set($vec3$1, translation, y, z);
10296
+ }
10297
+ if (glMatrix.vec3.equals(translation, $vec3Zero))
10298
+ return;
10299
+ glMatrix.vec3.add($vec3$1, this.getPosition(element), translation);
10300
+ this.setPosition(element, $vec3$1);
10301
+ };
10302
+ DefaultSceneGraphService.prototype.setRotation = function (element, rotation, y, z, w) {
10303
+ var transform = element.transformable;
10304
+ if (typeof rotation === 'number') {
10305
+ rotation = glMatrix.quat.fromValues(rotation, y, z, w);
10306
+ }
10307
+ if (element.parentNode === null ||
10308
+ !element.parentNode.transformable) {
10309
+ this.setLocalRotation(element, rotation);
10310
+ }
10311
+ else {
10312
+ var parentRot = this.getRotation(element.parentNode);
10313
+ glMatrix.quat.copy($quat$1, parentRot);
10314
+ glMatrix.quat.invert($quat$1, $quat$1);
10315
+ glMatrix.quat.multiply(transform.localRotation, $quat$1, rotation);
10316
+ glMatrix.quat.normalize(transform.localRotation, transform.localRotation);
10317
+ this.dirtifyLocal(element, transform);
10318
+ }
10319
+ };
10899
10320
  DefaultSceneGraphService.prototype.setLocalRotation = function (element, rotation, y, z, w, dirtify) {
10900
10321
  if (dirtify === void 0) { dirtify = true; }
10901
10322
  if (typeof rotation === 'number') {
10902
- rotation = glMatrix.quat.fromValues(rotation, y, z, w);
10323
+ rotation = glMatrix.quat.set($quat$1, rotation, y, z, w);
10903
10324
  }
10904
10325
  var transform = element.transformable;
10905
10326
  glMatrix.quat.copy(transform.localRotation, rotation);
@@ -10907,15 +10328,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
10907
10328
  this.dirtifyLocal(element, transform);
10908
10329
  }
10909
10330
  };
10910
- DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y) {
10331
+ DefaultSceneGraphService.prototype.setLocalSkew = function (element, skew, y, dirtify) {
10332
+ if (dirtify === void 0) { dirtify = true; }
10911
10333
  if (typeof skew === 'number') {
10912
- skew = glMatrix.vec2.fromValues(skew, y);
10334
+ skew = glMatrix.vec2.set($vec2, skew, y);
10913
10335
  }
10914
10336
  var transform = element.transformable;
10915
10337
  glMatrix.vec2.copy(transform.localSkew, skew);
10916
- this.dirtifyLocal(element, transform);
10338
+ if (dirtify) {
10339
+ this.dirtifyLocal(element, transform);
10340
+ }
10917
10341
  };
10918
10342
  DefaultSceneGraphService.prototype.dirtifyLocal = function (element, transform) {
10343
+ if (isInFragment(element))
10344
+ return;
10919
10345
  if (!transform.localDirtyFlag) {
10920
10346
  transform.localDirtyFlag = true;
10921
10347
  if (!transform.dirtyFlag) {
@@ -10930,11 +10356,43 @@ var DefaultSceneGraphService = /** @class */ (function () {
10930
10356
  this.dirtifyWorldInternal(element, transform);
10931
10357
  this.dirtifyToRoot(element, true);
10932
10358
  };
10359
+ DefaultSceneGraphService.prototype.dirtifyFragment = function (element) {
10360
+ var transform = element.transformable;
10361
+ if (transform) {
10362
+ transform.frozen = false;
10363
+ transform.dirtyFlag = true;
10364
+ transform.localDirtyFlag = true;
10365
+ }
10366
+ var renderable = element.renderable;
10367
+ if (renderable) {
10368
+ renderable.renderBoundsDirty = true;
10369
+ renderable.boundsDirty = true;
10370
+ renderable.dirty = true;
10371
+ }
10372
+ var length = element.childNodes.length;
10373
+ for (var i = 0; i < length; i++) {
10374
+ this.dirtifyFragment(element.childNodes[i]);
10375
+ }
10376
+ if (element.nodeName === exports.Shape.FRAGMENT) {
10377
+ this.pendingEvents.set(element, false);
10378
+ }
10379
+ };
10933
10380
  DefaultSceneGraphService.prototype.triggerPendingEvents = function () {
10934
10381
  var _this = this;
10935
- var set = new Set();
10382
+ var triggered = new Set();
10383
+ var skipped = new Set();
10384
+ this.pendingEvents.forEach(function (_, element) {
10385
+ if (element.nodeName === exports.Shape.FRAGMENT) {
10386
+ element.forEach(function (e) {
10387
+ if (e !== element)
10388
+ skipped.add(e);
10389
+ });
10390
+ }
10391
+ });
10936
10392
  var trigger = function (element, detail) {
10937
- if (element.isConnected && !set.has(element.entity)) {
10393
+ if (element.isConnected &&
10394
+ !triggered.has(element) &&
10395
+ !skipped.has(element)) {
10938
10396
  _this.boundsChangedEvent.detail = detail;
10939
10397
  _this.boundsChangedEvent.target = element;
10940
10398
  if (element.isMutationObserved) {
@@ -10943,25 +10401,25 @@ var DefaultSceneGraphService = /** @class */ (function () {
10943
10401
  else {
10944
10402
  element.ownerDocument.defaultView.dispatchEvent(_this.boundsChangedEvent, true);
10945
10403
  }
10946
- set.add(element.entity);
10404
+ triggered.add(element);
10947
10405
  }
10948
10406
  };
10949
- this.pendingEvents.forEach(function (_a) {
10950
- var _b = tslib.__read(_a, 2), element = _b[0], detail = _b[1];
10951
- if (detail.affectChildren) {
10407
+ this.pendingEvents.forEach(function (affectChildren, element) {
10408
+ $triggerPendingEvents_detail.affectChildren = affectChildren;
10409
+ if (affectChildren) {
10952
10410
  element.forEach(function (e) {
10953
- trigger(e, detail);
10411
+ trigger(e, $triggerPendingEvents_detail);
10954
10412
  });
10955
10413
  }
10956
- else {
10957
- trigger(element, detail);
10958
- }
10414
+ else
10415
+ trigger(element, $triggerPendingEvents_detail);
10959
10416
  });
10417
+ triggered.clear();
10418
+ skipped.clear();
10960
10419
  this.clearPendingEvents();
10961
- set.clear();
10962
10420
  };
10963
10421
  DefaultSceneGraphService.prototype.clearPendingEvents = function () {
10964
- this.pendingEvents = [];
10422
+ this.pendingEvents.clear();
10965
10423
  };
10966
10424
  DefaultSceneGraphService.prototype.dirtifyToRoot = function (element, affectChildren) {
10967
10425
  if (affectChildren === void 0) { affectChildren = false; }
@@ -10979,10 +10437,8 @@ var DefaultSceneGraphService = /** @class */ (function () {
10979
10437
  markRenderableDirty(e);
10980
10438
  });
10981
10439
  }
10982
- // inform dependencies
10983
10440
  this.informDependentDisplayObjects(element);
10984
- // reuse the same custom event
10985
- this.pendingEvents.push([element, { affectChildren: affectChildren }]);
10441
+ this.pendingEvents.set(element, affectChildren);
10986
10442
  };
10987
10443
  DefaultSceneGraphService.prototype.updateDisplayObjectDependency = function (name, oldPath, newPath, object) {
10988
10444
  // clear ref to old clip path
@@ -11057,6 +10513,45 @@ var DefaultSceneGraphService = /** @class */ (function () {
11057
10513
  DefaultSceneGraphService.prototype.getLocalSkew = function (element) {
11058
10514
  return element.transformable.localSkew;
11059
10515
  };
10516
+ DefaultSceneGraphService.prototype.calcLocalTransform = function (transform) {
10517
+ var hasSkew = transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0;
10518
+ if (hasSkew) {
10519
+ glMatrix.mat4.fromRotationTranslationScaleOrigin(transform.localTransform, transform.localRotation, transform.localPosition, glMatrix.vec3.fromValues(1, 1, 1), transform.origin);
10520
+ // apply skew2D
10521
+ if (transform.localSkew[0] !== 0 || transform.localSkew[1] !== 0) {
10522
+ glMatrix.mat4.identity($mat4);
10523
+ $mat4[4] = Math.tan(transform.localSkew[0]);
10524
+ $mat4[1] = Math.tan(transform.localSkew[1]);
10525
+ glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, $mat4);
10526
+ }
10527
+ 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);
10528
+ glMatrix.mat4.multiply(transform.localTransform, transform.localTransform, scaling);
10529
+ }
10530
+ else {
10531
+ var localTransform = transform.localTransform, localPosition = transform.localPosition, localRotation = transform.localRotation, localScale = transform.localScale, origin_1 = transform.origin;
10532
+ var hasPosition = localPosition[0] !== 0 ||
10533
+ localPosition[1] !== 0 ||
10534
+ localPosition[2] !== 0;
10535
+ var hasRotation = localRotation[3] !== 1 ||
10536
+ localRotation[0] !== 0 ||
10537
+ localRotation[1] !== 0 ||
10538
+ localRotation[2] !== 0;
10539
+ var hasScale = localScale[0] !== 1 || localScale[1] !== 1 || localScale[2] !== 1;
10540
+ var hasOrigin = origin_1[0] !== 0 || origin_1[1] !== 0 || origin_1[2] !== 0;
10541
+ if (!hasRotation && !hasScale && !hasOrigin) {
10542
+ if (hasPosition) {
10543
+ glMatrix.mat4.fromTranslation(localTransform, localPosition);
10544
+ }
10545
+ else {
10546
+ glMatrix.mat4.identity(localTransform);
10547
+ }
10548
+ }
10549
+ else {
10550
+ // @see https://github.com/mattdesl/css-mat4/blob/master/index.js
10551
+ glMatrix.mat4.fromRotationTranslationScaleOrigin(localTransform, localRotation, localPosition, localScale, origin_1);
10552
+ }
10553
+ }
10554
+ };
11060
10555
  DefaultSceneGraphService.prototype.getLocalTransform = function (element) {
11061
10556
  var transform = element.transformable;
11062
10557
  if (transform.localDirtyFlag) {
@@ -11066,19 +10561,20 @@ var DefaultSceneGraphService = /** @class */ (function () {
11066
10561
  return transform.localTransform;
11067
10562
  };
11068
10563
  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);
10564
+ var t = glMatrix.mat4.getTranslation($setLocalTransform_1, transform);
10565
+ var r = glMatrix.mat4.getRotation($setLocalTransform_2, transform);
10566
+ var s = glMatrix.mat4.getScaling($setLocalTransform_3, transform);
11072
10567
  this.setLocalScale(element, s, false);
11073
10568
  this.setLocalPosition(element, t, false);
11074
10569
  this.setLocalRotation(element, r, undefined, undefined, undefined, false);
11075
10570
  this.dirtifyLocal(element, element.transformable);
11076
10571
  };
11077
10572
  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]);
10573
+ this.setLocalScale(element, $vec3One, false);
10574
+ this.setLocalPosition(element, $vec3Zero, false);
10575
+ this.setLocalEulerAngles(element, $vec3Zero, undefined, undefined, false);
10576
+ this.setLocalSkew(element, $vec2Zero, undefined, false);
10577
+ this.dirtifyLocal(element, element.transformable);
11082
10578
  };
11083
10579
  DefaultSceneGraphService.prototype.getTransformedGeometryBounds = function (element, render, existedAABB) {
11084
10580
  if (render === void 0) { render = false; }
@@ -11170,9 +10666,9 @@ var DefaultSceneGraphService = /** @class */ (function () {
11170
10666
  */
11171
10667
  DefaultSceneGraphService.prototype.getLocalBounds = function (element) {
11172
10668
  if (element.parentNode) {
11173
- var parentInvert = glMatrix.mat4.create();
10669
+ var parentInvert = $mat4Identity;
11174
10670
  if (element.parentNode.transformable) {
11175
- parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), this.getWorldTransform(element.parentNode));
10671
+ parentInvert = glMatrix.mat4.invert($mat4, this.getWorldTransform(element.parentNode));
11176
10672
  }
11177
10673
  var bounds = this.getBounds(element);
11178
10674
  if (!AABB.isEmpty(bounds)) {
@@ -11425,19 +10921,12 @@ var TextService = /** @class */ (function () {
11425
10921
  // dropShadowDistance = 0,
11426
10922
  leading = _g === void 0 ? 0 : _g;
11427
10923
  var font = toFontString(parsedStyle);
11428
- // if (runtime.enableCSSParsing) {
11429
10924
  var fontProperties = this.measureFont(font, offscreenCanvas);
11430
10925
  // fallback in case UA disallow canvas data extraction
11431
- // (toDataURI, getImageData functions)
11432
10926
  if (fontProperties.fontSize === 0) {
11433
10927
  fontProperties.fontSize = fontSize;
11434
10928
  fontProperties.ascent = fontSize;
11435
10929
  }
11436
- // } else {
11437
- // fontProperties = {
11438
- // fontSize,
11439
- // };
11440
- // }
11441
10930
  var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11442
10931
  context.font = font;
11443
10932
  // no overflowing by default
@@ -11759,10 +11248,7 @@ runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
11759
11248
  runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime);
11760
11249
  runtime.layoutRegistry = null;
11761
11250
  runtime.globalThis = getGlobalThis();
11762
- runtime.enableCSSParsing = false;
11763
- runtime.enableDataset = false;
11764
11251
  runtime.enableStyleSyntax = true;
11765
- runtime.enableAttributeDashCased = false;
11766
11252
  runtime.enableSizeAttenuation = false;
11767
11253
 
11768
11254
  var entityCounter = 0;
@@ -11851,34 +11337,7 @@ var Element = /** @class */ (function (_super) {
11851
11337
  * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
11852
11338
  */
11853
11339
  _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;
11340
+ _this.computedStyle = {};
11882
11341
  /**
11883
11342
  * Renderers will use these used values.
11884
11343
  */
@@ -12007,7 +11466,12 @@ var Element = /** @class */ (function (_super) {
12007
11466
  }
12008
11467
  runtime.sceneGraphService.attach(child, this, index);
12009
11468
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
12010
- this.ownerDocument.defaultView.mountChildren(child);
11469
+ if (!isInFragment(this) && child.nodeName === exports.Shape.FRAGMENT) {
11470
+ this.ownerDocument.defaultView.mountFragment(child);
11471
+ }
11472
+ else {
11473
+ this.ownerDocument.defaultView.mountChildren(child);
11474
+ }
12011
11475
  }
12012
11476
  // @ts-ignore
12013
11477
  if (this.isMutationObserved) {
@@ -12121,9 +11585,9 @@ var Element = /** @class */ (function (_super) {
12121
11585
  this.forEach(function (object) {
12122
11586
  if (object !== _this && filter(object)) {
12123
11587
  target = object;
12124
- return true;
11588
+ return false;
12125
11589
  }
12126
- return false;
11590
+ return true;
12127
11591
  });
12128
11592
  return target;
12129
11593
  };
@@ -12281,17 +11745,13 @@ var Element = /** @class */ (function (_super) {
12281
11745
  */
12282
11746
  Element.prototype.getAttribute = function (name) {
12283
11747
  // @see https://github.com/antvis/G/issues/1267
12284
- if (isSymbol(name)) {
12285
- return runtime.enableCSSParsing ? null : undefined;
11748
+ if (typeof name === 'symbol') {
11749
+ return undefined;
12286
11750
  }
12287
11751
  var value = this.attributes[name];
12288
11752
  if (value === undefined) {
12289
- if (runtime.enableAttributeDashCased) {
12290
- var attributeName = formatAttributeName(name);
12291
- value = this.attributes[attributeName];
12292
- }
12293
11753
  // 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;
11754
+ return value;
12295
11755
  }
12296
11756
  else {
12297
11757
  return value;
@@ -12363,78 +11823,8 @@ var Proxy = runtime.globalThis.Proxy
12363
11823
  ? runtime.globalThis.Proxy
12364
11824
  : function () { };
12365
11825
  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-';
11826
+ var $vec3 = glMatrix.vec3.create();
11827
+ var $quat = glMatrix.quat.create();
12438
11828
  /**
12439
11829
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
12440
11830
  *
@@ -12467,38 +11857,17 @@ var DisplayObject = /** @class */ (function (_super) {
12467
11857
  // eg. group.get('name')
12468
11858
  _this.config = config;
12469
11859
  // 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;
12474
- }
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);
11860
+ _this.id = config.id || '';
11861
+ _this.name = config.name || '';
11862
+ if (config.className || config.class) {
11863
+ _this.className = config.className || config.class;
12479
11864
  }
12480
- else if (_this.config.initialParsedStyle) {
12481
- Object.assign(_this.parsedStyle,
12482
- // DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED,
12483
- _this.config.initialParsedStyle);
11865
+ _this.nodeName = config.type || exports.Shape.GROUP;
11866
+ if (config.initialParsedStyle) {
11867
+ Object.assign(_this.parsedStyle, config.initialParsedStyle);
12484
11868
  }
12485
11869
  // 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
- }
11870
+ _this.initAttributes(config.style);
12502
11871
  if (runtime.enableStyleSyntax) {
12503
11872
  _this.style = new Proxy(
12504
11873
  // @ts-ignore
@@ -12538,13 +11907,6 @@ var DisplayObject = /** @class */ (function (_super) {
12538
11907
  this.getAnimations().forEach(function (animation) {
12539
11908
  animation.cancel();
12540
11909
  });
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
11910
  };
12549
11911
  DisplayObject.prototype.cloneNode = function (deep, customCloneFunc) {
12550
11912
  var clonedStyle = tslib.__assign({}, this.attributes);
@@ -12587,39 +11949,16 @@ var DisplayObject = /** @class */ (function (_super) {
12587
11949
  };
12588
11950
  DisplayObject.prototype.initAttributes = function (attributes) {
12589
11951
  if (attributes === void 0) { attributes = {}; }
12590
- var renderable = this.renderable;
12591
11952
  var options = {
12592
11953
  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
11954
  };
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);
11955
+ runtime.styleValueRegistry.processProperties(this, attributes, options);
12614
11956
  // redraw at next frame
12615
- renderable.dirty = true;
11957
+ this.renderable.dirty = true;
12616
11958
  };
12617
11959
  DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12618
11960
  if (force === void 0) { force = false; }
12619
11961
  if (memoize === void 0) { memoize = true; }
12620
- if (runtime.enableAttributeDashCased) {
12621
- name = formatAttributeName(name);
12622
- }
12623
11962
  // ignore undefined value
12624
11963
  if (util.isUndefined(value)) {
12625
11964
  return;
@@ -12681,7 +12020,7 @@ var DisplayObject = /** @class */ (function (_super) {
12681
12020
  DisplayObject.prototype.setOrigin = function (position, y, z) {
12682
12021
  if (y === void 0) { y = 0; }
12683
12022
  if (z === void 0) { z = 0; }
12684
- runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z));
12023
+ runtime.sceneGraphService.setOrigin(this, createVec3(position, y, z, false));
12685
12024
  return this;
12686
12025
  };
12687
12026
  DisplayObject.prototype.getOrigin = function () {
@@ -12693,7 +12032,7 @@ var DisplayObject = /** @class */ (function (_super) {
12693
12032
  DisplayObject.prototype.setPosition = function (position, y, z) {
12694
12033
  if (y === void 0) { y = 0; }
12695
12034
  if (z === void 0) { z = 0; }
12696
- runtime.sceneGraphService.setPosition(this, createVec3(position, y, z));
12035
+ runtime.sceneGraphService.setPosition(this, createVec3(position, y, z, false));
12697
12036
  return this;
12698
12037
  };
12699
12038
  /**
@@ -12702,7 +12041,7 @@ var DisplayObject = /** @class */ (function (_super) {
12702
12041
  DisplayObject.prototype.setLocalPosition = function (position, y, z) {
12703
12042
  if (y === void 0) { y = 0; }
12704
12043
  if (z === void 0) { z = 0; }
12705
- runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
12044
+ runtime.sceneGraphService.setLocalPosition(this, createVec3(position, y, z, false));
12706
12045
  return this;
12707
12046
  };
12708
12047
  /**
@@ -12711,7 +12050,7 @@ var DisplayObject = /** @class */ (function (_super) {
12711
12050
  DisplayObject.prototype.translate = function (position, y, z) {
12712
12051
  if (y === void 0) { y = 0; }
12713
12052
  if (z === void 0) { z = 0; }
12714
- runtime.sceneGraphService.translate(this, createVec3(position, y, z));
12053
+ runtime.sceneGraphService.translate(this, createVec3(position, y, z, false));
12715
12054
  return this;
12716
12055
  };
12717
12056
  /**
@@ -12720,7 +12059,7 @@ var DisplayObject = /** @class */ (function (_super) {
12720
12059
  DisplayObject.prototype.translateLocal = function (position, y, z) {
12721
12060
  if (y === void 0) { y = 0; }
12722
12061
  if (z === void 0) { z = 0; }
12723
- runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z));
12062
+ runtime.sceneGraphService.translateLocal(this, createVec3(position, y, z, false));
12724
12063
  return this;
12725
12064
  };
12726
12065
  DisplayObject.prototype.getPosition = function () {
@@ -12744,7 +12083,7 @@ var DisplayObject = /** @class */ (function (_super) {
12744
12083
  if (typeof scaling === 'number') {
12745
12084
  y = y || scaling;
12746
12085
  z = z || scaling;
12747
- scaling = createVec3(scaling, y, z);
12086
+ scaling = createVec3(scaling, y, z, false);
12748
12087
  }
12749
12088
  runtime.sceneGraphService.scaleLocal(this, scaling);
12750
12089
  return this;
@@ -12756,7 +12095,7 @@ var DisplayObject = /** @class */ (function (_super) {
12756
12095
  if (typeof scaling === 'number') {
12757
12096
  y = y || scaling;
12758
12097
  z = z || scaling;
12759
- scaling = createVec3(scaling, y, z);
12098
+ scaling = createVec3(scaling, y, z, false);
12760
12099
  }
12761
12100
  runtime.sceneGraphService.setLocalScale(this, scaling);
12762
12101
  return this;
@@ -12777,14 +12116,14 @@ var DisplayObject = /** @class */ (function (_super) {
12777
12116
  * only return degrees of Z axis in world space
12778
12117
  */
12779
12118
  DisplayObject.prototype.getEulerAngles = function () {
12780
- var _a = tslib.__read(getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12119
+ var _a = tslib.__read(getEuler($vec3, runtime.sceneGraphService.getWorldTransform(this)), 3), ez = _a[2];
12781
12120
  return rad2deg(ez);
12782
12121
  };
12783
12122
  /**
12784
12123
  * only return degrees of Z axis in local space
12785
12124
  */
12786
12125
  DisplayObject.prototype.getLocalEulerAngles = function () {
12787
- var _a = tslib.__read(getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12126
+ var _a = tslib.__read(getEuler($vec3, runtime.sceneGraphService.getLocalRotation(this)), 3), ez = _a[2];
12788
12127
  return rad2deg(ez);
12789
12128
  };
12790
12129
  /**
@@ -12880,10 +12219,8 @@ var DisplayObject = /** @class */ (function (_super) {
12880
12219
  * shortcut for Used value of `visibility`
12881
12220
  */
12882
12221
  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';
12222
+ var _a;
12223
+ return ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) !== 'hidden';
12887
12224
  };
12888
12225
  Object.defineProperty(DisplayObject.prototype, "interactive", {
12889
12226
  get: function () {
@@ -12964,10 +12301,10 @@ var DisplayObject = /** @class */ (function (_super) {
12964
12301
  */
12965
12302
  DisplayObject.prototype.getMatrix = function (transformMat4) {
12966
12303
  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];
12304
+ var _a = tslib.__read(glMatrix.mat4.getTranslation($vec3, transform), 2), tx = _a[0], ty = _a[1];
12305
+ var _b = tslib.__read(glMatrix.mat4.getScaling($vec3, transform), 2), sx = _b[0], sy = _b[1];
12306
+ var rotation = glMatrix.mat4.getRotation($quat, transform);
12307
+ var _c = tslib.__read(getEuler($vec3, rotation), 3), eux = _c[0], euz = _c[2];
12971
12308
  // gimbal lock at 90 degrees
12972
12309
  return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
12973
12310
  };
@@ -13003,28 +12340,18 @@ var DisplayObject = /** @class */ (function (_super) {
13003
12340
  * @deprecated
13004
12341
  */
13005
12342
  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
- }
12343
+ this.forEach(function (object) {
12344
+ object.style.visibility = 'visible';
12345
+ });
13014
12346
  };
13015
12347
  /**
13016
12348
  * Use `visibility: hidden` instead.
13017
12349
  * @deprecated
13018
12350
  */
13019
12351
  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
- }
12352
+ this.forEach(function (object) {
12353
+ object.style.visibility = 'hidden';
12354
+ });
13028
12355
  };
13029
12356
  /**
13030
12357
  * Use `childElementCount` instead.
@@ -13139,8 +12466,7 @@ var CustomElement = /** @class */ (function (_super) {
13139
12466
  if (_a === void 0) { _a = {}; }
13140
12467
  var _this = this;
13141
12468
  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;
12469
+ _this = _super.call(this, tslib.__assign({ style: style }, rest)) || this;
13144
12470
  // static get observedAttributes(): string[] {
13145
12471
  // return [];
13146
12472
  // }
@@ -13159,6 +12485,23 @@ var Ellipse = /** @class */ (function (_super) {
13159
12485
  return Ellipse;
13160
12486
  }(DisplayObject));
13161
12487
 
12488
+ /**
12489
+ * 节点片段,用于包裹多个节点并批量操作
12490
+ *
12491
+ * 向 Fragment 或者根节点为 Fragment 的节点添加子节点时,不会触发渲染和事件。
12492
+ *
12493
+ * 当 Fragment 被挂载到 Canvas 中的节点时,其子节点会一次性被渲染,并触发合并事件。
12494
+ *
12495
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
12496
+ */
12497
+ var Fragment = /** @class */ (function (_super) {
12498
+ tslib.__extends(Fragment, _super);
12499
+ function Fragment() {
12500
+ return _super.call(this, { type: exports.Shape.FRAGMENT }) || this;
12501
+ }
12502
+ return Fragment;
12503
+ }(DisplayObject));
12504
+
13162
12505
  /**
13163
12506
  * its attributes are inherited by its children.
13164
12507
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
@@ -13188,8 +12531,7 @@ var HTML = /** @class */ (function (_super) {
13188
12531
  if (_a === void 0) { _a = {}; }
13189
12532
  var _this = this;
13190
12533
  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;
12534
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.HTML, style: style }, rest)) || this;
13193
12535
  _this.cullable.enable = false;
13194
12536
  return _this;
13195
12537
  }
@@ -13381,13 +12723,10 @@ var Path = /** @class */ (function (_super) {
13381
12723
  if (_a === void 0) { _a = {}; }
13382
12724
  var _this = this;
13383
12725
  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;
12726
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.PATH, style: style, initialParsedStyle: {
12727
+ miterLimit: 4,
12728
+ d: tslib.__assign({}, EMPTY_PARSED_PATH),
12729
+ } }, rest)) || this;
13391
12730
  _this.markerStartAngle = 0;
13392
12731
  _this.markerEndAngle = 0;
13393
12732
  /**
@@ -13582,18 +12921,15 @@ var Polygon = /** @class */ (function (_super) {
13582
12921
  if (_a === void 0) { _a = {}; }
13583
12922
  var _this = this;
13584
12923
  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;
12924
+ _this = _super.call(this, tslib.__assign({ type: exports.Shape.POLYGON, style: style, initialParsedStyle: {
12925
+ points: {
12926
+ points: [],
12927
+ totalLength: 0,
12928
+ segments: [],
12929
+ },
12930
+ miterLimit: 4,
12931
+ isClosed: true,
12932
+ } }, rest)) || this;
13597
12933
  _this.markerStartAngle = 0;
13598
12934
  _this.markerEndAngle = 0;
13599
12935
  /**
@@ -13728,18 +13064,15 @@ var Polyline = /** @class */ (function (_super) {
13728
13064
  function Polyline(_a) {
13729
13065
  if (_a === void 0) { _a = {}; }
13730
13066
  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;
13067
+ return _super.call(this, tslib.__assign({ type: exports.Shape.POLYLINE, style: style, initialParsedStyle: {
13068
+ points: {
13069
+ points: [],
13070
+ totalLength: 0,
13071
+ segments: [],
13072
+ },
13073
+ miterLimit: 4,
13074
+ isClosed: false,
13075
+ } }, rest)) || this;
13743
13076
  }
13744
13077
  Polyline.prototype.getTotalLength = function () {
13745
13078
  return getOrCalculatePolylineTotalLength(this);
@@ -13823,16 +13156,8 @@ var Text = /** @class */ (function (_super) {
13823
13156
  function Text(_a) {
13824
13157
  if (_a === void 0) { _a = {}; }
13825
13158
  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
- // }
13159
+ return _super.call(this, tslib.__assign({ type: exports.Shape.TEXT, style: tslib.__assign({ fill: 'black' }, style) }, rest)) || this;
13160
+ }
13836
13161
  /**
13837
13162
  * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
13838
13163
  */
@@ -13841,27 +13166,6 @@ var Text = /** @class */ (function (_super) {
13841
13166
  this.getGeometryBounds();
13842
13167
  return ((_a = this.parsedStyle.metrics) === null || _a === void 0 ? void 0 : _a.maxLineWidth) || 0;
13843
13168
  };
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
13169
  Text.prototype.getLineBoundingRects = function () {
13866
13170
  var _a;
13867
13171
  this.getGeometryBounds();
@@ -14039,7 +13343,7 @@ var Document = /** @class */ (function (_super) {
14039
13343
  BUILT_IN_PROPERTIES.forEach(function (_a) {
14040
13344
  var n = _a.n, inh = _a.inh, d = _a.d;
14041
13345
  if (inh && d) {
14042
- initialStyle[n] = isFunction(d) ? d(exports.Shape.GROUP) : d;
13346
+ initialStyle[n] = util.isFunction(d) ? d(exports.Shape.GROUP) : d;
14043
13347
  }
14044
13348
  });
14045
13349
  // like <html> in DOM tree
@@ -14816,10 +14120,7 @@ var FrustumCullingStrategy = /** @class */ (function () {
14816
14120
 
14817
14121
  var PrepareRendererPlugin = /** @class */ (function () {
14818
14122
  function PrepareRendererPlugin() {
14819
- /**
14820
- * sync to RBush later
14821
- */
14822
- this.toSync = new Set();
14123
+ this.syncTasks = new Map();
14823
14124
  this.isFirstTimeRendering = true;
14824
14125
  this.syncing = false;
14825
14126
  this.isFirstTimeRenderingFinished = false;
@@ -14836,21 +14137,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14836
14137
  renderingService.dirtify();
14837
14138
  };
14838
14139
  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[]);
14140
+ _this.syncTasks.set(e.target, e.detail.affectChildren);
14854
14141
  renderingService.dirtify();
14855
14142
  };
14856
14143
  var handleMounted = function (e) {
@@ -14858,12 +14145,6 @@ var PrepareRendererPlugin = /** @class */ (function () {
14858
14145
  if (runtime.enableSizeAttenuation) {
14859
14146
  runtime.styleValueRegistry.updateSizeAttenuation(object, canvas.getCamera().getZoom());
14860
14147
  }
14861
- if (runtime.enableCSSParsing) {
14862
- // recalc style values
14863
- runtime.styleValueRegistry.recalc(object);
14864
- }
14865
- runtime.sceneGraphService.dirtifyToRoot(object);
14866
- renderingService.dirtify();
14867
14148
  };
14868
14149
  var handleUnmounted = function (e) {
14869
14150
  var object = e.target;
@@ -14871,7 +14152,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14871
14152
  if (rBushNode.aabb) {
14872
14153
  _this.rBush.remove(rBushNode.aabb);
14873
14154
  }
14874
- _this.toSync.delete(object);
14155
+ _this.syncTasks.delete(object);
14875
14156
  runtime.sceneGraphService.dirtifyToRoot(object);
14876
14157
  renderingService.dirtify();
14877
14158
  };
@@ -14886,7 +14167,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14886
14167
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
14887
14168
  canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14888
14169
  canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14889
- _this.toSync.clear();
14170
+ _this.syncTasks.clear();
14890
14171
  });
14891
14172
  var ric = (_a = runtime.globalThis.requestIdleCallback) !== null && _a !== void 0 ? _a : raf.bind(runtime.globalThis);
14892
14173
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
@@ -14903,60 +14184,78 @@ var PrepareRendererPlugin = /** @class */ (function () {
14903
14184
  }
14904
14185
  });
14905
14186
  };
14187
+ PrepareRendererPlugin.prototype.syncNode = function (node, force) {
14188
+ if (force === void 0) { force = false; }
14189
+ if (!node.isConnected)
14190
+ return;
14191
+ var rBushNode = node.rBushNode;
14192
+ // clear dirty node
14193
+ if (rBushNode.aabb)
14194
+ this.rBush.remove(rBushNode.aabb);
14195
+ var renderBounds = node.getRenderBounds();
14196
+ if (renderBounds) {
14197
+ var renderable = node.renderable;
14198
+ if (force) {
14199
+ if (!renderable.dirtyRenderBounds) {
14200
+ renderable.dirtyRenderBounds = new AABB();
14201
+ }
14202
+ // save last dirty aabb
14203
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14204
+ }
14205
+ var _a = tslib.__read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14206
+ var _b = tslib.__read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14207
+ if (!rBushNode.aabb) {
14208
+ rBushNode.aabb = {};
14209
+ }
14210
+ rBushNode.aabb.displayObject = node;
14211
+ rBushNode.aabb.minX = minX;
14212
+ rBushNode.aabb.minY = minY;
14213
+ rBushNode.aabb.maxX = maxX;
14214
+ rBushNode.aabb.maxY = maxY;
14215
+ }
14216
+ if (rBushNode.aabb) {
14217
+ // TODO: NaN occurs when width/height of Rect is 0
14218
+ if (!isNaN(rBushNode.aabb.maxX) &&
14219
+ !isNaN(rBushNode.aabb.maxX) &&
14220
+ !isNaN(rBushNode.aabb.minX) &&
14221
+ !isNaN(rBushNode.aabb.minY)) {
14222
+ return rBushNode.aabb;
14223
+ }
14224
+ }
14225
+ };
14906
14226
  PrepareRendererPlugin.prototype.syncRTree = function (force) {
14907
14227
  var _this = this;
14908
14228
  if (force === void 0) { force = false; }
14909
- if (!force && (this.syncing || this.toSync.size === 0)) {
14229
+ if (!force && (this.syncing || this.syncTasks.size === 0)) {
14910
14230
  return;
14911
14231
  }
14912
14232
  this.syncing = true;
14913
14233
  // bounds changed, need re-inserting its children
14914
14234
  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);
14235
+ var synced = new Set();
14236
+ var sync = function (node) {
14237
+ if (!synced.has(node) && node.renderable) {
14238
+ var aabb = _this.syncNode(node, force);
14239
+ if (aabb) {
14240
+ bulk.push(aabb);
14241
+ synced.add(node);
14933
14242
  }
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 = {};
14938
- }
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
14243
  }
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
- }
14244
+ };
14245
+ this.syncTasks.forEach(function (affectChildren, node) {
14246
+ if (affectChildren) {
14247
+ node.forEach(sync);
14248
+ }
14249
+ var parent = node;
14250
+ while (parent) {
14251
+ sync(parent);
14252
+ parent = parent.parentElement;
14953
14253
  }
14954
14254
  });
14955
14255
  // use bulk inserting, which is ~2-3 times faster
14956
14256
  // @see https://github.com/mourner/rbush#bulk-inserting-data
14957
14257
  this.rBush.load(bulk);
14958
14258
  bulk.length = 0;
14959
- this.toSync.clear();
14960
14259
  this.syncing = false;
14961
14260
  };
14962
14261
  PrepareRendererPlugin.tag = 'Prepare';
@@ -15006,15 +14305,16 @@ var Canvas = /** @class */ (function (_super) {
15006
14305
  */
15007
14306
  _this.Element = DisplayObject;
15008
14307
  _this.inited = false;
14308
+ _this.destroyed = false;
15009
14309
  _this.context = {};
15010
14310
  // create document
15011
14311
  _this.document = new Document();
15012
14312
  _this.document.defaultView = _this;
15013
14313
  // create registry of custom elements
15014
14314
  _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;
14315
+ 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
14316
  if (!supportsMutipleCanvasesInOneContainer) {
15017
- cleanExistedCanvas(container, _this);
14317
+ cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15018
14318
  }
15019
14319
  var canvasWidth = width;
15020
14320
  var canvasHeight = height;
@@ -15075,6 +14375,7 @@ var Canvas = /** @class */ (function (_super) {
15075
14375
  document: document,
15076
14376
  supportsCSSTransform: supportsCSSTransform,
15077
14377
  useNativeClickEvent: useNativeClickEvent,
14378
+ cleanUpOnDestroy: cleanUpOnDestroy,
15078
14379
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas,
15079
14380
  });
15080
14381
  _this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
@@ -15185,7 +14486,8 @@ var Canvas = /** @class */ (function (_super) {
15185
14486
  */
15186
14487
  Canvas.prototype.destroy = function (cleanUp, skipTriggerEvent) {
15187
14488
  if (cleanUp === void 0) { cleanUp = true; }
15188
- if (skipTriggerEvent === void 0) { skipTriggerEvent = false; }
14489
+ if (skipTriggerEvent === undefined)
14490
+ skipTriggerEvent = this.getConfig().fastCleanExistingCanvas;
15189
14491
  if (!skipTriggerEvent) {
15190
14492
  this.dispatchEvent(new CustomEvent(exports.CanvasEvent.BEFORE_DESTROY));
15191
14493
  }
@@ -15214,6 +14516,17 @@ var Canvas = /** @class */ (function (_super) {
15214
14516
  if (!skipTriggerEvent) {
15215
14517
  this.dispatchEvent(new CustomEvent(exports.CanvasEvent.AFTER_DESTROY));
15216
14518
  }
14519
+ var clearEventRetain = function (event) {
14520
+ event.currentTarget = null;
14521
+ event.manager = null;
14522
+ event.target = null;
14523
+ };
14524
+ clearEventRetain(mountedEvent);
14525
+ clearEventRetain(unmountedEvent);
14526
+ clearEventRetain(beforeRenderEvent);
14527
+ clearEventRetain(rerenderEvent);
14528
+ clearEventRetain(afterRenderEvent);
14529
+ this.destroyed = true;
15217
14530
  };
15218
14531
  /**
15219
14532
  * compatible with G 3.0
@@ -15285,6 +14598,8 @@ var Canvas = /** @class */ (function (_super) {
15285
14598
  Canvas.prototype.run = function () {
15286
14599
  var _this = this;
15287
14600
  var tick = function (time, frame) {
14601
+ if (_this.destroyed)
14602
+ return _this.cancelAnimationFrame(_this.frameId);
15288
14603
  _this.render(frame);
15289
14604
  _this.frameId = _this.requestAnimationFrame(tick);
15290
14605
  };
@@ -15401,12 +14716,14 @@ var Canvas = /** @class */ (function (_super) {
15401
14716
  _this.unmountChildren(child);
15402
14717
  });
15403
14718
  if (this.inited) {
15404
- if (parent.isMutationObserved) {
15405
- parent.dispatchEvent(unmountedEvent);
15406
- }
15407
- else {
15408
- unmountedEvent.target = parent;
15409
- this.dispatchEvent(unmountedEvent, true);
14719
+ if (!this.getConfig().cleanUpOnDestroy) {
14720
+ if (parent.isMutationObserved) {
14721
+ parent.dispatchEvent(unmountedEvent);
14722
+ }
14723
+ else {
14724
+ unmountedEvent.target = parent;
14725
+ this.dispatchEvent(unmountedEvent, true);
14726
+ }
15410
14727
  }
15411
14728
  // skip document.documentElement
15412
14729
  if (parent !== this.document.documentElement) {
@@ -15421,35 +14738,41 @@ var Canvas = /** @class */ (function (_super) {
15421
14738
  }
15422
14739
  }
15423
14740
  };
15424
- Canvas.prototype.mountChildren = function (parent) {
14741
+ Canvas.prototype.mountChildren = function (child, skipTriggerEvent) {
15425
14742
  var _this = this;
14743
+ if (skipTriggerEvent === void 0) { skipTriggerEvent = isInFragment(child); }
15426
14744
  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);
14745
+ if (!child.isConnected) {
14746
+ child.ownerDocument = this.document;
14747
+ child.isConnected = true;
14748
+ if (!skipTriggerEvent) {
14749
+ if (child.isMutationObserved) {
14750
+ child.dispatchEvent(mountedEvent);
14751
+ }
14752
+ else {
14753
+ mountedEvent.target = child;
14754
+ this.dispatchEvent(mountedEvent, true);
14755
+ }
15436
14756
  }
15437
14757
  }
15438
14758
  }
15439
14759
  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);
14760
+ 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
14761
  }
15442
14762
  // recursively mount children
15443
- parent.childNodes.forEach(function (child) {
15444
- _this.mountChildren(child);
14763
+ child.childNodes.forEach(function (c) {
14764
+ _this.mountChildren(c, skipTriggerEvent);
15445
14765
  });
15446
14766
  // trigger after mounted
15447
- if (parent.isCustomElement) {
15448
- if (parent.connectedCallback) {
15449
- parent.connectedCallback();
14767
+ if (child.isCustomElement) {
14768
+ if (child.connectedCallback) {
14769
+ child.connectedCallback();
15450
14770
  }
15451
14771
  }
15452
14772
  };
14773
+ Canvas.prototype.mountFragment = function (child) {
14774
+ this.mountChildren(child, false);
14775
+ };
15453
14776
  Canvas.prototype.client2Viewport = function (client) {
15454
14777
  return this.getEventService().client2Viewport(client);
15455
14778
  };
@@ -15511,6 +14834,7 @@ exports.FederatedEvent = FederatedEvent;
15511
14834
  exports.FederatedMouseEvent = FederatedMouseEvent;
15512
14835
  exports.FederatedPointerEvent = FederatedPointerEvent;
15513
14836
  exports.FederatedWheelEvent = FederatedWheelEvent;
14837
+ exports.Fragment = Fragment;
15514
14838
  exports.Frustum = Frustum;
15515
14839
  exports.Group = Group;
15516
14840
  exports.GroupUpdater = GroupUpdater;