@antv/g-lite 2.0.11 → 2.1.0-alpha.0

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