@antv/g-lite 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -657,6 +657,7 @@ function getHeight($el) {
657
657
 
658
658
  var ERROR_MSG_METHOD_NOT_IMPLEMENTED = 'Method not implemented.';
659
659
  var ERROR_MSG_USE_DOCUMENT_ELEMENT = 'Use document.documentElement instead.';
660
+ var ERROR_MSG_APPEND_DESTROYED_ELEMENT = 'Cannot append a destroyed element.';
660
661
 
661
662
  // borrow from hammer.js
662
663
  var MOUSE_POINTER_ID = 1;
@@ -4289,9 +4290,8 @@ var internalParsePath = function internalParsePath(path) {
4289
4290
  segments: [],
4290
4291
  polygons: [],
4291
4292
  polylines: [],
4292
- curve: [],
4293
+ curve: null,
4293
4294
  totalLength: 0,
4294
- zCommandIndexes: [],
4295
4295
  rect: {
4296
4296
  x: 0,
4297
4297
  y: 0,
@@ -4314,13 +4314,7 @@ var internalParsePath = function internalParsePath(path) {
4314
4314
 
4315
4315
  var _extractPolygons = extractPolygons(absolutePath),
4316
4316
  polygons = _extractPolygons.polygons,
4317
- polylines = _extractPolygons.polylines; // convert to curves to do morphing & picking later
4318
- // @see http://thednp.github.io/kute.js/svgCubicMorph.html
4319
-
4320
-
4321
- var _path2Curve = util.path2Curve(absolutePath, true),
4322
- curve = _path2Curve[0],
4323
- zCommandIndexes = _path2Curve[1]; // for later use
4317
+ polylines = _extractPolygons.polylines; // for later use
4324
4318
 
4325
4319
 
4326
4320
  var segments = path2Segments(absolutePath); // Only calculate bbox here since we don't need length now.
@@ -4337,10 +4331,9 @@ var internalParsePath = function internalParsePath(path) {
4337
4331
  segments: segments,
4338
4332
  polygons: polygons,
4339
4333
  polylines: polylines,
4340
- curve: curve,
4334
+ // curve,
4341
4335
  // Delay the calculation of length.
4342
4336
  totalLength: 0,
4343
- zCommandIndexes: zCommandIndexes,
4344
4337
  rect: {
4345
4338
  x: Number.isFinite(x) ? x : 0,
4346
4339
  y: Number.isFinite(y) ? y : 0,
@@ -4364,6 +4357,19 @@ function parsePath(path, object) {
4364
4357
  function mergePaths(left, right, object) {
4365
4358
  var curve1 = left.curve;
4366
4359
  var curve2 = right.curve;
4360
+
4361
+ if (!curve1 || curve1.length === 0) {
4362
+ // convert to curves to do morphing & picking later
4363
+ // @see http://thednp.github.io/kute.js/svgCubicMorph.html
4364
+ curve1 = util.path2Curve(left.absolutePath, false);
4365
+ left.curve = curve1;
4366
+ }
4367
+
4368
+ if (!curve2 || curve2.length === 0) {
4369
+ curve2 = util.path2Curve(right.absolutePath, false);
4370
+ right.curve = curve2;
4371
+ }
4372
+
4367
4373
  var curves = [curve1, curve2];
4368
4374
 
4369
4375
  if (curve1.length !== curve2.length) {
@@ -5483,9 +5489,8 @@ var CSSPropertyPath = /*#__PURE__*/function () {
5483
5489
  segments: [],
5484
5490
  polygons: [],
5485
5491
  polylines: [],
5486
- curve: [],
5492
+ curve: null,
5487
5493
  totalLength: 0,
5488
- zCommandIndexes: [],
5489
5494
  rect: new Rectangle(0, 0, 0, 0)
5490
5495
  };
5491
5496
  }
@@ -6768,6 +6773,118 @@ function toSymmetry(point, center) {
6768
6773
  return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
6769
6774
  }
6770
6775
 
6776
+ var angleBetween = function angleBetween(v0, v1) {
6777
+ var p = v0.x * v1.x + v0.y * v1.y;
6778
+ var n = Math.sqrt((Math.pow(v0.x, 2) + Math.pow(v0.y, 2)) * (Math.pow(v1.x, 2) + Math.pow(v1.y, 2)));
6779
+ var sign = v0.x * v1.y - v0.y * v1.x < 0 ? -1 : 1;
6780
+ var angle = sign * Math.acos(p / n);
6781
+ return angle;
6782
+ };
6783
+ /**
6784
+ * @see https://github.com/rveciana/svg-path-properties/blob/b6bd9a322966f6ef7a311872d80c56e3718de861/src/arc.ts#L121
6785
+ */
6786
+
6787
+
6788
+ var pointOnEllipticalArc = function pointOnEllipticalArc(p0, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, p1, t) {
6789
+ // In accordance to: http://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters
6790
+ rx = Math.abs(rx);
6791
+ ry = Math.abs(ry);
6792
+ xAxisRotation = util.mod(xAxisRotation, 360);
6793
+ var xAxisRotationRadians = deg2rad(xAxisRotation); // If the endpoints are identical, then this is equivalent to omitting the elliptical arc segment entirely.
6794
+
6795
+ if (p0.x === p1.x && p0.y === p1.y) {
6796
+ return {
6797
+ x: p0.x,
6798
+ y: p0.y,
6799
+ ellipticalArcAngle: 0
6800
+ }; // Check if angle is correct
6801
+ } // If rx = 0 or ry = 0 then this arc is treated as a straight line segment joining the endpoints.
6802
+
6803
+
6804
+ if (rx === 0 || ry === 0) {
6805
+ //return this.pointOnLine(p0, p1, t);
6806
+ return {
6807
+ x: 0,
6808
+ y: 0,
6809
+ ellipticalArcAngle: 0
6810
+ }; // Check if angle is correct
6811
+ } // Following "Conversion from endpoint to center parameterization"
6812
+ // http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
6813
+ // Step #1: Compute transformedPoint
6814
+
6815
+
6816
+ var dx = (p0.x - p1.x) / 2;
6817
+ var dy = (p0.y - p1.y) / 2;
6818
+ var transformedPoint = {
6819
+ x: Math.cos(xAxisRotationRadians) * dx + Math.sin(xAxisRotationRadians) * dy,
6820
+ y: -Math.sin(xAxisRotationRadians) * dx + Math.cos(xAxisRotationRadians) * dy
6821
+ }; // Ensure radii are large enough
6822
+
6823
+ var radiiCheck = Math.pow(transformedPoint.x, 2) / Math.pow(rx, 2) + Math.pow(transformedPoint.y, 2) / Math.pow(ry, 2);
6824
+
6825
+ if (radiiCheck > 1) {
6826
+ rx = Math.sqrt(radiiCheck) * rx;
6827
+ ry = Math.sqrt(radiiCheck) * ry;
6828
+ } // Step #2: Compute transformedCenter
6829
+
6830
+
6831
+ var cSquareNumerator = Math.pow(rx, 2) * Math.pow(ry, 2) - Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) - Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
6832
+ var cSquareRootDenom = Math.pow(rx, 2) * Math.pow(transformedPoint.y, 2) + Math.pow(ry, 2) * Math.pow(transformedPoint.x, 2);
6833
+ var cRadicand = cSquareNumerator / cSquareRootDenom; // Make sure this never drops below zero because of precision
6834
+
6835
+ cRadicand = cRadicand < 0 ? 0 : cRadicand;
6836
+ var cCoef = (largeArcFlag !== sweepFlag ? 1 : -1) * Math.sqrt(cRadicand);
6837
+ var transformedCenter = {
6838
+ x: cCoef * (rx * transformedPoint.y / ry),
6839
+ y: cCoef * (-(ry * transformedPoint.x) / rx)
6840
+ }; // Step #3: Compute center
6841
+
6842
+ var center = {
6843
+ x: Math.cos(xAxisRotationRadians) * transformedCenter.x - Math.sin(xAxisRotationRadians) * transformedCenter.y + (p0.x + p1.x) / 2,
6844
+ y: Math.sin(xAxisRotationRadians) * transformedCenter.x + Math.cos(xAxisRotationRadians) * transformedCenter.y + (p0.y + p1.y) / 2
6845
+ }; // Step #4: Compute start/sweep angles
6846
+ // Start angle of the elliptical arc prior to the stretch and rotate operations.
6847
+ // Difference between the start and end angles
6848
+
6849
+ var startVector = {
6850
+ x: (transformedPoint.x - transformedCenter.x) / rx,
6851
+ y: (transformedPoint.y - transformedCenter.y) / ry
6852
+ };
6853
+ var startAngle = angleBetween({
6854
+ x: 1,
6855
+ y: 0
6856
+ }, startVector);
6857
+ var endVector = {
6858
+ x: (-transformedPoint.x - transformedCenter.x) / rx,
6859
+ y: (-transformedPoint.y - transformedCenter.y) / ry
6860
+ };
6861
+ var sweepAngle = angleBetween(startVector, endVector);
6862
+
6863
+ if (!sweepFlag && sweepAngle > 0) {
6864
+ sweepAngle -= 2 * Math.PI;
6865
+ } else if (sweepFlag && sweepAngle < 0) {
6866
+ sweepAngle += 2 * Math.PI;
6867
+ } // We use % instead of `mod(..)` because we want it to be -360deg to 360deg(but actually in radians)
6868
+
6869
+
6870
+ sweepAngle %= 2 * Math.PI; // From http://www.w3.org/TR/SVG/implnote.html#ArcParameterizationAlternatives
6871
+
6872
+ var angle = startAngle + sweepAngle * t;
6873
+ var ellipseComponentX = rx * Math.cos(angle);
6874
+ var ellipseComponentY = ry * Math.sin(angle);
6875
+ var point = {
6876
+ x: Math.cos(xAxisRotationRadians) * ellipseComponentX - Math.sin(xAxisRotationRadians) * ellipseComponentY + center.x,
6877
+ y: Math.sin(xAxisRotationRadians) * ellipseComponentX + Math.cos(xAxisRotationRadians) * ellipseComponentY + center.y,
6878
+ ellipticalArcStartAngle: startAngle,
6879
+ ellipticalArcEndAngle: startAngle + sweepAngle,
6880
+ ellipticalArcAngle: angle,
6881
+ ellipticalArcCenter: center,
6882
+ resultantRx: rx,
6883
+ resultantRy: ry
6884
+ };
6885
+ return point;
6886
+ };
6887
+
6771
6888
  function path2Segments(path) {
6772
6889
  var segments = [];
6773
6890
  var currentPoint = null; // 当前图形
@@ -6793,7 +6910,8 @@ function path2Segments(path) {
6793
6910
  endTangent: null,
6794
6911
  currentPoint: null,
6795
6912
  nextPoint: null,
6796
- arcParams: null
6913
+ arcParams: null,
6914
+ box: null
6797
6915
  };
6798
6916
 
6799
6917
  switch (command) {
@@ -6897,42 +7015,64 @@ function path2Segments(path) {
6897
7015
  segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
6898
7016
  }
6899
7017
  } else if (command === 'A') {
6900
- var d = 0.001;
6901
-
6902
- var _ref = segment.arcParams || {},
6903
- _ref$cx = _ref.cx,
6904
- cx = _ref$cx === void 0 ? 0 : _ref$cx,
6905
- _ref$cy = _ref.cy,
6906
- cy = _ref$cy === void 0 ? 0 : _ref$cy,
6907
- _ref$rx = _ref.rx,
6908
- rx = _ref$rx === void 0 ? 0 : _ref$rx,
6909
- _ref$ry = _ref.ry,
6910
- ry = _ref$ry === void 0 ? 0 : _ref$ry,
6911
- _ref$sweepFlag = _ref.sweepFlag,
6912
- sweepFlag = _ref$sweepFlag === void 0 ? 0 : _ref$sweepFlag,
6913
- _ref$startAngle = _ref.startAngle,
6914
- startAngle = _ref$startAngle === void 0 ? 0 : _ref$startAngle,
6915
- _ref$endAngle = _ref.endAngle,
6916
- endAngle = _ref$endAngle === void 0 ? 0 : _ref$endAngle;
6917
-
6918
- if (sweepFlag === 0) {
6919
- d *= -1;
6920
- }
7018
+ var _getTangentAtRatio = getTangentAtRatio(segment, 0),
7019
+ dx1 = _getTangentAtRatio.x,
7020
+ dy1 = _getTangentAtRatio.y;
7021
+
7022
+ var _getTangentAtRatio2 = getTangentAtRatio(segment, 1, false),
7023
+ dx2 = _getTangentAtRatio2.x,
7024
+ dy2 = _getTangentAtRatio2.y;
6921
7025
 
6922
- var dx1 = rx * Math.cos(startAngle - d) + cx;
6923
- var dy1 = ry * Math.sin(startAngle - d) + cy;
6924
- segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
6925
- var dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
6926
- var dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
6927
- segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
7026
+ segment.startTangent = [dx1, dy1];
7027
+ segment.endTangent = [dx2, dy2];
6928
7028
  }
6929
7029
 
6930
7030
  segments.push(segment);
6931
7031
  }
6932
7032
 
6933
7033
  return segments;
7034
+ }
7035
+ /**
7036
+ * Use length instead of ratio
7037
+ */
7038
+
7039
+ function getTangentAtRatio(segment, ratio, sign) {
7040
+ if (sign === void 0) {
7041
+ sign = true;
7042
+ }
7043
+
7044
+ var _segment$arcParams = segment.arcParams,
7045
+ _segment$arcParams$rx = _segment$arcParams.rx,
7046
+ rx = _segment$arcParams$rx === void 0 ? 0 : _segment$arcParams$rx,
7047
+ _segment$arcParams$ry = _segment$arcParams.ry,
7048
+ ry = _segment$arcParams$ry === void 0 ? 0 : _segment$arcParams$ry,
7049
+ xRotation = _segment$arcParams.xRotation,
7050
+ arcFlag = _segment$arcParams.arcFlag,
7051
+ sweepFlag = _segment$arcParams.sweepFlag;
7052
+ var p1 = pointOnEllipticalArc({
7053
+ x: segment.prePoint[0],
7054
+ y: segment.prePoint[1]
7055
+ }, rx, ry, xRotation, !!arcFlag, !!sweepFlag, {
7056
+ x: segment.currentPoint[0],
7057
+ y: segment.currentPoint[1]
7058
+ }, ratio);
7059
+ var p2 = pointOnEllipticalArc({
7060
+ x: segment.prePoint[0],
7061
+ y: segment.prePoint[1]
7062
+ }, rx, ry, xRotation, !!arcFlag, !!sweepFlag, {
7063
+ x: segment.currentPoint[0],
7064
+ y: segment.currentPoint[1]
7065
+ }, sign ? ratio + 0.005 : ratio - 0.005);
7066
+ var xDist = p2.x - p1.x;
7067
+ var yDist = p2.y - p1.y;
7068
+ var dist = Math.sqrt(xDist * xDist + yDist * yDist);
7069
+ return {
7070
+ x: -xDist / dist,
7071
+ y: -yDist / dist
7072
+ };
6934
7073
  } // 向量长度
6935
7074
 
7075
+
6936
7076
  function vMag(v) {
6937
7077
  return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
6938
7078
  } // u.v/|u||v|,计算夹角的余弦值
@@ -7064,6 +7204,17 @@ function commandsToPathString(commands, object, transform) {
7064
7204
  }
7065
7205
 
7066
7206
  path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "," + cur[5] + "," + c[0] + "," + c[1];
7207
+ } else if (cur[0] === 'Q') {
7208
+ var _p = glMatrix.vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
7209
+
7210
+ var _p2 = glMatrix.vec3.fromValues(cur[3] - defX, cur[4] - defY, 0);
7211
+
7212
+ if (transform) {
7213
+ glMatrix.vec3.transformMat4(_p, _p, transform);
7214
+ glMatrix.vec3.transformMat4(_p2, _p2, transform);
7215
+ }
7216
+
7217
+ path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "}";
7067
7218
  }
7068
7219
 
7069
7220
  return prev += path;
@@ -7183,13 +7334,8 @@ function convertToPath(object, transform) {
7183
7334
  break;
7184
7335
 
7185
7336
  case exports.Shape.PATH:
7186
- var _object$parsedStyle$p = object.parsedStyle.path,
7187
- curve = _object$parsedStyle$p.curve,
7188
- zCommandIndexes = _object$parsedStyle$p.zCommandIndexes;
7189
- commands = [].concat(curve);
7190
- zCommandIndexes.forEach(function (zIndex, index) {
7191
- commands.splice(zIndex + index + 1, 0, ['Z']);
7192
- });
7337
+ var absolutePath = object.parsedStyle.path.absolutePath;
7338
+ commands = [].concat(absolutePath);
7193
7339
  break;
7194
7340
  }
7195
7341
 
@@ -7197,7 +7343,7 @@ function convertToPath(object, transform) {
7197
7343
  return commandsToPathString(commands, object, transform);
7198
7344
  }
7199
7345
  }
7200
- function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
7346
+ function translatePathToString(absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
7201
7347
  if (startOffsetX === void 0) {
7202
7348
  startOffsetX = 0;
7203
7349
  }
@@ -7214,27 +7360,32 @@ function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endO
7214
7360
  endOffsetY = 0;
7215
7361
  }
7216
7362
 
7217
- var newValue = pathArray.map(function (params, i) {
7363
+ var newValue = absolutePath.map(function (params, i) {
7218
7364
  var command = params[0];
7219
- var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
7220
- var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
7221
- var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
7365
+ var nextSegment = absolutePath[i + 1];
7366
+ var useStartOffset = i === 0 && startOffsetX !== 0 && startOffsetY !== 0;
7367
+ var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0;
7222
7368
 
7223
7369
  switch (command) {
7224
7370
  case 'M':
7225
- return "M " + (params[1] - x + startOffsetX) + "," + (params[2] - y + startOffsetY);
7371
+ // Use start marker offset
7372
+ if (useStartOffset) {
7373
+ return "M " + (params[1] - defX + startOffsetX) + "," + (params[2] - defY + startOffsetY) + " L " + (params[1] - defX) + "," + (params[2] - defY);
7374
+ } else {
7375
+ return "M " + (params[1] - defX) + "," + (params[2] - defY);
7376
+ }
7226
7377
 
7227
7378
  case 'L':
7228
- return "L " + (params[1] - x + offsetX) + "," + (params[2] - y + offsetY);
7379
+ return "L " + (params[1] - defX + (useEndOffset ? endOffsetX : 0)) + "," + (params[2] - defY + (useEndOffset ? endOffsetY : 0));
7229
7380
 
7230
7381
  case 'Q':
7231
- return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x + offsetX) + " " + (params[4] - y + offsetY);
7382
+ return "Q " + (params[1] - defX) + " " + (params[2] - defY) + "," + (params[3] - defX) + " " + (params[4] - defY) + (useEndOffset ? " L " + (params[3] - defX + endOffsetX) + "," + (params[4] - defY + endOffsetY) : '');
7232
7383
 
7233
7384
  case 'C':
7234
- return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x + offsetX) + " " + (params[6] - y + offsetY);
7385
+ return "C " + (params[1] - defX) + " " + (params[2] - defY) + "," + (params[3] - defX) + " " + (params[4] - defY) + "," + (params[5] - defX) + " " + (params[6] - defY) + (useEndOffset ? " L " + (params[5] - defX + endOffsetX) + "," + (params[6] - defY + endOffsetY) : '');
7235
7386
 
7236
7387
  case 'A':
7237
- return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x + offsetX) + " " + (params[7] - y + offsetY);
7388
+ return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - defX) + " " + (params[7] - defY) + (useEndOffset ? " L " + (params[6] - defX + endOffsetX) + "," + (params[7] - defY + endOffsetY) : '');
7238
7389
 
7239
7390
  case 'Z':
7240
7391
  return 'Z';
@@ -10779,6 +10930,10 @@ var Element = /*#__PURE__*/function (_Node) {
10779
10930
  _proto.appendChild = function appendChild(child, index) {
10780
10931
  var _this$ownerDocument;
10781
10932
 
10933
+ if (child.destroyed) {
10934
+ throw new Error(ERROR_MSG_APPEND_DESTROYED_ELEMENT);
10935
+ }
10936
+
10782
10937
  runtime.sceneGraphService.attach(child, this, index);
10783
10938
 
10784
10939
  if ((_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.defaultView) {
@@ -10824,7 +10979,7 @@ var Element = /*#__PURE__*/function (_Node) {
10824
10979
  return child;
10825
10980
  }
10826
10981
  /**
10827
- * Remove all children and destroy them.
10982
+ * Remove all children which can be appended to its original parent later again.
10828
10983
  */
10829
10984
  ;
10830
10985
 
@@ -10833,7 +10988,16 @@ var Element = /*#__PURE__*/function (_Node) {
10833
10988
 
10834
10989
  this.childNodes.slice().forEach(function (child) {
10835
10990
  _this2.removeChild(child);
10991
+ });
10992
+ }
10993
+ /**
10994
+ * Recursively destroy all children which can not be appended to its original parent later again.
10995
+ */
10996
+ ;
10836
10997
 
10998
+ _proto.destroyChildren = function destroyChildren() {
10999
+ this.childNodes.slice().forEach(function (child) {
11000
+ child.destroyChildren();
10837
11001
  child.destroy();
10838
11002
  });
10839
11003
  }
@@ -13004,7 +13168,6 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
13004
13168
  });
13005
13169
 
13006
13170
  if (marker && marker instanceof DisplayObject) {
13007
- // FIXME: should use original path instead of parsed curve
13008
13171
  for (var i = 1; i < segments.length - 1; i++) {
13009
13172
  var _segments$i$currentPo = segments[i].currentPoint,
13010
13173
  ox = _segments$i$currentPo[0],
@@ -18765,10 +18928,22 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18765
18928
 
18766
18929
  _proto.removeChild = function removeChild(child) {
18767
18930
  return this.document.documentElement.removeChild(child);
18768
- };
18931
+ }
18932
+ /**
18933
+ * Remove all children which can be appended to its original parent later again.
18934
+ */
18935
+ ;
18769
18936
 
18770
18937
  _proto.removeChildren = function removeChildren() {
18771
18938
  this.document.documentElement.removeChildren();
18939
+ }
18940
+ /**
18941
+ * Recursively destroy all children which can not be appended to its original parent later again.
18942
+ */
18943
+ ;
18944
+
18945
+ _proto.destroyChildren = function destroyChildren() {
18946
+ this.document.documentElement.destroyChildren();
18772
18947
  };
18773
18948
 
18774
18949
  _proto.render = function render() {
@@ -18925,37 +19100,32 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18925
19100
  _proto.unmountChildren = function unmountChildren(parent) {
18926
19101
  var _this5 = this;
18927
19102
 
18928
- if (this.inited) {
18929
- var path = [];
18930
- parent.forEach(function (child) {
18931
- if (child.isConnected) {
18932
- path.push(child);
18933
- }
18934
- }); // unmount from leaf to root
19103
+ // unmountChildren recursively
19104
+ parent.childNodes.forEach(function (child) {
19105
+ _this5.unmountChildren(child);
19106
+ });
18935
19107
 
18936
- path.reverse().forEach(function (child) {
18937
- // trigger before unmounted
18938
- if (child.isCustomElement) {
18939
- if (child.disconnectedCallback) {
18940
- child.disconnectedCallback();
18941
- }
18942
- }
19108
+ if (this.inited) {
19109
+ if (parent.isMutationObserved) {
19110
+ parent.dispatchEvent(unmountedEvent);
19111
+ } else {
19112
+ unmountedEvent.target = parent;
19113
+ this.dispatchEvent(unmountedEvent, true);
19114
+ } // skip document.documentElement
18943
19115
 
18944
- if (child.isMutationObserved) {
18945
- child.dispatchEvent(unmountedEvent);
18946
- } else {
18947
- unmountedEvent.target = child;
18948
19116
 
18949
- _this5.dispatchEvent(unmountedEvent, true);
18950
- } // skip document.documentElement
19117
+ if (parent !== this.document.documentElement) {
19118
+ parent.ownerDocument = null;
19119
+ }
18951
19120
 
19121
+ parent.isConnected = false;
19122
+ } // trigger after unmounted
18952
19123
 
18953
- if (child !== _this5.document.documentElement) {
18954
- child.ownerDocument = null;
18955
- }
18956
19124
 
18957
- child.isConnected = false;
18958
- });
19125
+ if (parent.isCustomElement) {
19126
+ if (parent.disconnectedCallback) {
19127
+ parent.disconnectedCallback();
19128
+ }
18959
19129
  }
18960
19130
  };
18961
19131
 
@@ -18963,29 +19133,30 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18963
19133
  var _this6 = this;
18964
19134
 
18965
19135
  if (this.inited) {
18966
- parent.forEach(function (child) {
18967
- if (!child.isConnected) {
18968
- child.ownerDocument = _this6.document;
18969
- child.isConnected = true;
18970
-
18971
- if (child.isMutationObserved) {
18972
- child.dispatchEvent(mountedEvent);
18973
- } else {
18974
- mountedEvent.target = child;
18975
-
18976
- _this6.dispatchEvent(mountedEvent, true);
18977
- } // trigger after mounted
19136
+ if (!parent.isConnected) {
19137
+ parent.ownerDocument = this.document;
19138
+ parent.isConnected = true;
18978
19139
 
18979
-
18980
- if (child.isCustomElement) {
18981
- if (child.connectedCallback) {
18982
- child.connectedCallback();
18983
- }
18984
- }
19140
+ if (parent.isMutationObserved) {
19141
+ parent.dispatchEvent(mountedEvent);
19142
+ } else {
19143
+ mountedEvent.target = parent;
19144
+ this.dispatchEvent(mountedEvent, true);
18985
19145
  }
18986
- });
19146
+ }
18987
19147
  } else {
18988
19148
  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);
19149
+ } // recursively mount children
19150
+
19151
+
19152
+ parent.childNodes.forEach(function (child) {
19153
+ _this6.mountChildren(child);
19154
+ }); // trigger after mounted
19155
+
19156
+ if (parent.isCustomElement) {
19157
+ if (parent.connectedCallback) {
19158
+ parent.connectedCallback();
19159
+ }
18989
19160
  }
18990
19161
  };
18991
19162