@antv/g-lite 1.0.11 → 1.0.13

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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/Canvas.d.ts +2 -9
  3. package/dist/Canvas.d.ts.map +1 -1
  4. package/dist/camera/Camera.d.ts.map +1 -1
  5. package/dist/css/StyleValueRegistry.d.ts +1 -1
  6. package/dist/css/StyleValueRegistry.d.ts.map +1 -1
  7. package/dist/display-objects/DisplayObject.d.ts +70 -1
  8. package/dist/display-objects/DisplayObject.d.ts.map +1 -1
  9. package/dist/display-objects/DisplayObjectPool.d.ts +2 -2
  10. package/dist/display-objects/DisplayObjectPool.d.ts.map +1 -1
  11. package/dist/display-objects/Line.d.ts +2 -2
  12. package/dist/display-objects/Line.d.ts.map +1 -1
  13. package/dist/display-objects/Path.d.ts +2 -2
  14. package/dist/display-objects/Path.d.ts.map +1 -1
  15. package/dist/display-objects/Polyline.d.ts +2 -2
  16. package/dist/display-objects/Polyline.d.ts.map +1 -1
  17. package/dist/display-objects/Text.d.ts +2 -2
  18. package/dist/display-objects/Text.d.ts.map +1 -1
  19. package/dist/dom/Element.d.ts.map +1 -1
  20. package/dist/dom/EventTarget.d.ts +1 -1
  21. package/dist/dom/EventTarget.d.ts.map +1 -1
  22. package/dist/dom/interfaces.d.ts +3 -9
  23. package/dist/dom/interfaces.d.ts.map +1 -1
  24. package/dist/index.esm.js +376 -225
  25. package/dist/index.js +376 -225
  26. package/dist/index.umd.js +381 -232
  27. package/dist/index.umd.min.js +2 -2
  28. package/dist/plugins/PrepareRendererPlugin.d.ts +0 -1
  29. package/dist/plugins/PrepareRendererPlugin.d.ts.map +1 -1
  30. package/dist/services/EventService.d.ts +1 -1
  31. package/dist/services/EventService.d.ts.map +1 -1
  32. package/dist/services/RenderingService.d.ts.map +1 -1
  33. package/dist/services/SceneGraphService.d.ts.map +1 -1
  34. package/dist/services/TextService.d.ts.map +1 -1
  35. package/dist/shapes/AABB.d.ts +1 -1
  36. package/dist/shapes/AABB.d.ts.map +1 -1
  37. package/dist/utils/assert.d.ts +4 -1
  38. package/dist/utils/assert.d.ts.map +1 -1
  39. package/dist/utils/text.d.ts.map +1 -1
  40. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -104,6 +104,14 @@ var AABB = /*#__PURE__*/function () {
104
104
  };
105
105
 
106
106
  function AABB(center, halfExtents) {
107
+ if (center === void 0) {
108
+ center = [0, 0, 0];
109
+ }
110
+
111
+ if (halfExtents === void 0) {
112
+ halfExtents = [0, 0, 0];
113
+ }
114
+
107
115
  this.center = glMatrix.vec3.create();
108
116
  this.halfExtents = glMatrix.vec3.create();
109
117
  this.min = glMatrix.vec3.create();
@@ -114,16 +122,10 @@ var AABB = /*#__PURE__*/function () {
114
122
  var _proto = AABB.prototype;
115
123
 
116
124
  _proto.update = function update(center, halfExtents) {
117
- if (center) {
118
- glMatrix.vec3.copy(this.center, center);
119
- }
120
-
121
- if (halfExtents) {
122
- glMatrix.vec3.copy(this.halfExtents, halfExtents || glMatrix.vec3.fromValues(0, 0, 0));
123
- }
124
-
125
- this.min = glMatrix.vec3.sub(this.min, this.center, this.halfExtents);
126
- this.max = glMatrix.vec3.add(this.max, this.center, this.halfExtents);
125
+ glMatrix.vec3.copy(this.center, center);
126
+ glMatrix.vec3.copy(this.halfExtents, halfExtents);
127
+ glMatrix.vec3.sub(this.min, this.center, this.halfExtents);
128
+ glMatrix.vec3.add(this.max, this.center, this.halfExtents);
127
129
  };
128
130
 
129
131
  _proto.setMinMax = function setMinMax(min, max) {
@@ -561,10 +563,7 @@ var FORMAT_ATTR_MAP = {
561
563
  alias: 'lineWidth'
562
564
  },
563
565
  textAnchor: {
564
- alias: 'textAlign',
565
- values: {
566
- middle: 'center'
567
- }
566
+ alias: 'textAlign'
568
567
  },
569
568
  src: {
570
569
  alias: 'img'
@@ -574,18 +573,8 @@ var formatAttributeName = util.memoize(function (name) {
574
573
  var attributeName = camelCase(name);
575
574
  var map = FORMAT_ATTR_MAP[attributeName];
576
575
  attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
577
- return [attributeName, map];
576
+ return attributeName;
578
577
  });
579
- function formatAttribute(name, value) {
580
- var _map$values;
581
-
582
- var _formatAttributeName = formatAttributeName(name),
583
- attributeName = _formatAttributeName[0],
584
- map = _formatAttributeName[1];
585
-
586
- var attributeValue = util.isString(value) && (map === null || map === void 0 ? void 0 : (_map$values = map.values) === null || _map$values === void 0 ? void 0 : _map$values[value]) || value;
587
- return [attributeName, attributeValue];
588
- }
589
578
 
590
579
  var canvasMap = {};
591
580
  var defaultCanvasIdCounter = 0;
@@ -5441,16 +5430,23 @@ var CSSPropertyOffsetDistance = /*#__PURE__*/function () {
5441
5430
  };
5442
5431
 
5443
5432
  _proto.postProcessor = function postProcessor(object) {
5444
- if (!object.attributes.offsetPath) {
5433
+ var _object$parsedStyle = object.parsedStyle,
5434
+ offsetPath = _object$parsedStyle.offsetPath,
5435
+ offsetDistance = _object$parsedStyle.offsetDistance;
5436
+
5437
+ if (!offsetPath) {
5445
5438
  return;
5446
5439
  }
5447
5440
 
5448
- var offsetPathNodeName = object.attributes.offsetPath.nodeName;
5441
+ var nodeName = offsetPath.nodeName;
5449
5442
 
5450
- if (offsetPathNodeName === exports.Shape.LINE || offsetPathNodeName === exports.Shape.PATH || offsetPathNodeName === exports.Shape.POLYLINE) {
5451
- var point = object.attributes.offsetPath.getPoint(object.parsedStyle.offsetDistance);
5443
+ if (nodeName === exports.Shape.LINE || nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYLINE) {
5444
+ // set position in world space
5445
+ var point = offsetPath.getPoint(offsetDistance);
5452
5446
 
5453
5447
  if (point) {
5448
+ object.parsedStyle.defX = point.x;
5449
+ object.parsedStyle.defY = point.y;
5454
5450
  object.setLocalPosition(point.x, point.y);
5455
5451
  }
5456
5452
  }
@@ -8060,6 +8056,7 @@ var SyncWaterfallHook = /*#__PURE__*/function (_SyncHook) {
8060
8056
  // SyncWaterfallHook.prototype = null;
8061
8057
 
8062
8058
  var genericFontFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
8059
+ var stringRegExp = /([\"\'])[^\'\"]+\1/;
8063
8060
  function toFontString(attributes) {
8064
8061
  var fontSize = attributes.fontSize,
8065
8062
  fontFamily = attributes.fontFamily,
@@ -8079,7 +8076,7 @@ function toFontString(attributes) {
8079
8076
  var _fontFamily = fontFamilies[i].trim(); // Check if font already contains strings
8080
8077
 
8081
8078
 
8082
- if (!/([\"\'])[^\'\"]+\1/.test(_fontFamily) && genericFontFamilies.indexOf(_fontFamily) < 0) {
8079
+ if (!stringRegExp.test(_fontFamily) && genericFontFamilies.indexOf(_fontFamily) < 0) {
8083
8080
  _fontFamily = "\"" + _fontFamily + "\"";
8084
8081
  }
8085
8082
 
@@ -8555,7 +8552,7 @@ var BUILT_IN_PROPERTIES = [{
8555
8552
  n: 'textAlign',
8556
8553
  l: true,
8557
8554
  inh: true,
8558
- k: ['start', 'center', 'end', 'left', 'right'],
8555
+ k: ['start', 'center', 'middle', 'end', 'left', 'right'],
8559
8556
  d: 'start'
8560
8557
  }, // {
8561
8558
  // n: 'whiteSpace',
@@ -8584,7 +8581,7 @@ var BUILT_IN_PROPERTIES = [{
8584
8581
  d: '0'
8585
8582
  }];
8586
8583
  var propertyMetadataCache = {};
8587
- var unresolvedProperties = {};
8584
+ var unresolvedProperties = new WeakMap();
8588
8585
  var priorityMap = {};
8589
8586
  var sortAttributeNames = util.memoize(function (attributeNames) {
8590
8587
  return attributeNames.sort(function (a, b) {
@@ -8596,11 +8593,13 @@ var tmpVec3b = glMatrix.vec3.create();
8596
8593
  var tmpVec3c = glMatrix.vec3.create();
8597
8594
 
8598
8595
  var isPropertyResolved = function isPropertyResolved(object, name) {
8599
- if (!unresolvedProperties[object.entity] || unresolvedProperties[object.entity].length === 0) {
8596
+ var properties = unresolvedProperties.get(object);
8597
+
8598
+ if (!properties || properties.length === 0) {
8600
8599
  return true;
8601
8600
  }
8602
8601
 
8603
- return unresolvedProperties[object.entity].includes(name);
8602
+ return properties.includes(name);
8604
8603
  };
8605
8604
 
8606
8605
  var DefaultStyleValueRegistry = /*#__PURE__*/function () {
@@ -8665,12 +8664,10 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8665
8664
  attributeNames.forEach(function (attributeName) {
8666
8665
  var _propertyMetadataCach;
8667
8666
 
8668
- var _formatAttribute = formatAttribute(attributeName, attributes[attributeName]),
8669
- name = _formatAttribute[0],
8670
- value = _formatAttribute[1];
8667
+ var name = formatAttributeName(attributeName);
8671
8668
 
8672
8669
  if (!skipUpdateAttribute) {
8673
- object.attributes[name] = value;
8670
+ object.attributes[name] = attributes[attributeName];
8674
8671
  }
8675
8672
 
8676
8673
  if (!needUpdateGeometry && ((_propertyMetadataCach = propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.l)) {
@@ -8846,12 +8843,15 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8846
8843
  ;
8847
8844
 
8848
8845
  _proto.addUnresolveProperty = function addUnresolveProperty(object, name) {
8849
- if (!unresolvedProperties[object.entity]) {
8850
- unresolvedProperties[object.entity] = [];
8846
+ var properties = unresolvedProperties.get(object);
8847
+
8848
+ if (!properties) {
8849
+ unresolvedProperties.set(object, []);
8850
+ properties = unresolvedProperties.get(object);
8851
8851
  }
8852
8852
 
8853
- if (unresolvedProperties[object.entity].indexOf(name) === -1) {
8854
- unresolvedProperties[object.entity].push(name);
8853
+ if (properties.indexOf(name) === -1) {
8854
+ properties.push(name);
8855
8855
  }
8856
8856
  };
8857
8857
 
@@ -8887,7 +8887,7 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8887
8887
  };
8888
8888
 
8889
8889
  _proto.recalc = function recalc(object) {
8890
- var properties = unresolvedProperties[object.entity];
8890
+ var properties = unresolvedProperties.get(object);
8891
8891
 
8892
8892
  if (properties && properties.length) {
8893
8893
  var attributes = {};
@@ -8895,7 +8895,7 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8895
8895
  attributes[property] = object.attributes[property];
8896
8896
  });
8897
8897
  this.processProperties(object, attributes);
8898
- delete unresolvedProperties[object.entity];
8898
+ unresolvedProperties.delete(object);
8899
8899
  }
8900
8900
  }
8901
8901
  /**
@@ -9451,7 +9451,11 @@ var EventTarget = /*#__PURE__*/function () {
9451
9451
  */
9452
9452
  ;
9453
9453
 
9454
- _proto.dispatchEvent = function dispatchEvent(e) {
9454
+ _proto.dispatchEvent = function dispatchEvent(e, skipPropagate) {
9455
+ if (skipPropagate === void 0) {
9456
+ skipPropagate = false;
9457
+ }
9458
+
9455
9459
  if (!(e instanceof FederatedEvent)) {
9456
9460
  throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
9457
9461
  } // should account for Element / Document / Canvas
@@ -9481,8 +9485,12 @@ var EventTarget = /*#__PURE__*/function () {
9481
9485
 
9482
9486
  e.defaultPrevented = false;
9483
9487
  e.path = [];
9484
- e.target = this;
9485
- (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e);
9488
+
9489
+ if (!skipPropagate) {
9490
+ e.target = this;
9491
+ }
9492
+
9493
+ (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e, e.type, skipPropagate);
9486
9494
  }
9487
9495
 
9488
9496
  return !e.defaultPrevented;
@@ -10263,22 +10271,12 @@ var Document = /*#__PURE__*/function (_Node) {
10263
10271
  */
10264
10272
 
10265
10273
  ElementEvent["INSERTED"] = "DOMNodeInserted";
10266
- /**
10267
- * it has had a child inserted
10268
- */
10269
-
10270
- ElementEvent["CHILD_INSERTED"] = "child-inserted";
10271
10274
  /**
10272
10275
  * it is being removed
10273
10276
  * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeRemoved
10274
10277
  */
10275
10278
 
10276
10279
  ElementEvent["REMOVED"] = "removed";
10277
- /**
10278
- * it has had a child removed
10279
- */
10280
-
10281
- ElementEvent["CHILD_REMOVED"] = "child-removed";
10282
10280
  /**
10283
10281
  * @see https://www.w3.org/TR/DOM-Level-3-Events/#domnodeinsertedintodocument
10284
10282
  */
@@ -10333,17 +10331,10 @@ MutationEvent.REMOVAL = 3;
10333
10331
  var entityCounter = 0;
10334
10332
  function resetEntityCounter() {
10335
10333
  entityCounter = 0;
10336
- } // let this.sceneGraphService: SceneGraphService;
10337
-
10338
- var childInsertedEvent = new CustomEvent(exports.ElementEvent.CHILD_INSERTED, {
10339
- child: null
10340
- });
10334
+ }
10341
10335
  var insertedEvent = new MutationEvent(exports.ElementEvent.INSERTED, null, '', '', '', 0, '', '');
10342
10336
  var removedEvent = new MutationEvent(exports.ElementEvent.REMOVED, null, '', '', '', 0, '', '');
10343
10337
  var destroyEvent = new CustomEvent(exports.ElementEvent.DESTROY);
10344
- var childRemovedEvent = new CustomEvent(exports.ElementEvent.CHILD_REMOVED, {
10345
- child: null
10346
- });
10347
10338
  /**
10348
10339
  * Has following capabilities:
10349
10340
  * * Node insert/remove, eg. appendChild, removeChild, remove...
@@ -10481,19 +10472,13 @@ var Element = /*#__PURE__*/function (_Node) {
10481
10472
  };
10482
10473
 
10483
10474
  _proto.appendChild = function appendChild(child, index) {
10484
- runtime.sceneGraphService.attach(child, this, index); // this.dispatchEvent(
10485
- // new CustomEvent(ElementEvent.CHILD_INSERTED, {
10486
- // child,
10487
- // }),
10488
- // );
10489
-
10490
- childInsertedEvent.detail.child = child; // @ts-ignore
10491
- // this.ownerDocument?.defaultView?.mountChildren(child);
10492
-
10493
- this.dispatchEvent(childInsertedEvent); // child.emit(ElementEvent.INSERTED, {
10494
- // parent: this,
10495
- // index,
10496
- // });
10475
+ var _this$ownerDocument;
10476
+
10477
+ runtime.sceneGraphService.attach(child, this, index);
10478
+
10479
+ if ((_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.defaultView) {
10480
+ this.ownerDocument.defaultView.mountChildren(child);
10481
+ }
10497
10482
 
10498
10483
  insertedEvent.relatedNode = this;
10499
10484
  child.dispatchEvent(insertedEvent);
@@ -10519,36 +10504,18 @@ var Element = /*#__PURE__*/function (_Node) {
10519
10504
  };
10520
10505
 
10521
10506
  _proto.removeChild = function removeChild(child) {
10507
+ var _child$ownerDocument;
10508
+
10522
10509
  // should emit on itself before detach
10523
- // child.emit(ElementEvent.REMOVED, {
10524
- // parent: this,
10525
- // });
10526
10510
  removedEvent.relatedNode = this;
10527
- child.dispatchEvent(removedEvent); // emit destroy event
10528
- // if (destroy) {
10529
- // // child.destroy();
10530
- // child.dispatchEvent(destroyEvent);
10531
- // (child as unknown as Element).destroyed = true;
10532
- // }
10533
- // emit on parent
10534
-
10535
- childRemovedEvent.detail.child = child;
10536
- this.dispatchEvent(childRemovedEvent); // this.dispatchEvent(
10537
- // new CustomEvent(ElementEvent.CHILD_REMOVED, {
10538
- // child,
10539
- // }),
10540
- // );
10541
- // remove from scene graph
10542
-
10543
- runtime.sceneGraphService.detach(child); // cannot emit Destroy event now
10544
- // if (destroy) {
10545
- // // this.removeChildren();
10546
- // // remove event listeners
10547
- // // @ts-ignore
10548
- // child.emitter.removeAllListeners();
10549
- // displayObjectPool.remove((child as unknown as Element).entity);
10550
- // }
10511
+ child.dispatchEvent(removedEvent);
10512
+
10513
+ if ((_child$ownerDocument = child.ownerDocument) === null || _child$ownerDocument === void 0 ? void 0 : _child$ownerDocument.defaultView) {
10514
+ child.ownerDocument.defaultView.unmountChildren(child);
10515
+ } // remove from scene graph
10516
+
10551
10517
 
10518
+ runtime.sceneGraphService.detach(child);
10552
10519
  return child;
10553
10520
  }
10554
10521
  /**
@@ -10841,14 +10808,13 @@ var Element = /*#__PURE__*/function (_Node) {
10841
10808
  var value = this.attributes[name];
10842
10809
 
10843
10810
  if (value === undefined) {
10844
- var _formatAttribute = formatAttribute(name.toString(), ''),
10845
- attributeName = _formatAttribute[0];
10811
+ var attributeName = formatAttributeName(name);
10812
+ value = this.attributes[attributeName]; // if the given attribute does not exist, the value returned will either be null or ""
10846
10813
 
10847
- value = this.attributes[attributeName];
10848
- } // if the given attribute does not exist, the value returned will either be null or ""
10849
-
10850
-
10851
- return util.isNil(value) ? null : value;
10814
+ return util.isNil(value) ? null : value;
10815
+ } else {
10816
+ return value;
10817
+ }
10852
10818
  }
10853
10819
  /**
10854
10820
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
@@ -11251,6 +11217,7 @@ var DEFAULT_PARSED_STYLE_PROPS = {
11251
11217
  filter: [],
11252
11218
  shadowType: 'outer'
11253
11219
  };
11220
+ var INHERITABLE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform'];
11254
11221
  /**
11255
11222
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
11256
11223
  *
@@ -11290,7 +11257,13 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11290
11257
 
11291
11258
  _this.config = void 0;
11292
11259
  _this.isCustomElement = false;
11260
+ _this.isMutationObserved = false;
11293
11261
  _this.activeAnimations = [];
11262
+
11263
+ _this.getClip = function () {
11264
+ return this.style.clipPath || null;
11265
+ };
11266
+
11294
11267
  _this.config = config; // compatible with G 3.0
11295
11268
 
11296
11269
  _this.config.interactive = (_this$config$capture = _this.config.capture) !== null && _this$config$capture !== void 0 ? _this$config$capture : _this.config.interactive; // init scene graph node
@@ -11419,14 +11392,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11419
11392
 
11420
11393
  runtime.styleValueRegistry.processProperties(this, attributes, {
11421
11394
  forceUpdateGeometry: true,
11422
- usedAttributes: [// 'anchor',
11423
- // 'transform',
11424
- // 'zIndex',
11425
- // 'filter',
11426
- // 'shadowType',
11427
- // 'fill',
11428
- // 'stroke',
11429
- 'opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']
11395
+ usedAttributes: INHERITABLE_STYLE_PROPS
11430
11396
  }); // redraw at next frame
11431
11397
 
11432
11398
  renderable.dirty = true;
@@ -11437,19 +11403,16 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11437
11403
  force = false;
11438
11404
  }
11439
11405
 
11440
- var _formatAttribute = formatAttribute(name, value),
11441
- attributeName = _formatAttribute[0],
11442
- attributeValue = _formatAttribute[1]; // ignore undefined value
11443
-
11406
+ var attributeName = formatAttributeName(name); // ignore undefined value
11444
11407
 
11445
11408
  if (util.isUndefined(value)) {
11446
11409
  return;
11447
11410
  }
11448
11411
 
11449
- if (force || attributeValue !== this.attributes[attributeName]) {
11450
- this.internalSetAttribute(attributeName, attributeValue);
11412
+ if (force || value !== this.attributes[attributeName]) {
11413
+ this.internalSetAttribute(attributeName, value);
11451
11414
 
11452
- _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
11415
+ _Element.prototype.setAttribute.call(this, attributeName, value);
11453
11416
  }
11454
11417
  }
11455
11418
  /**
@@ -11479,7 +11442,13 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11479
11442
  mutationEvent.attrName = name;
11480
11443
  mutationEvent.prevParsedValue = oldParsedValue;
11481
11444
  mutationEvent.newParsedValue = newParsedValue;
11482
- this.dispatchEvent(mutationEvent);
11445
+
11446
+ if (this.isMutationObserved) {
11447
+ this.dispatchEvent(mutationEvent);
11448
+ } else {
11449
+ mutationEvent.target = this;
11450
+ this.ownerDocument.defaultView.dispatchEvent(mutationEvent, true);
11451
+ }
11483
11452
  }
11484
11453
 
11485
11454
  if ((this.isCustomElement && this.isConnected || !this.isCustomElement) && this.attributeChangedCallback) {
@@ -11663,10 +11632,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11663
11632
  ;
11664
11633
 
11665
11634
  _proto.getEulerAngles = function getEulerAngles() {
11666
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11667
11635
  var _getEuler = getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getWorldTransform(this)),
11668
- ex = _getEuler[0],
11669
- ey = _getEuler[1],
11670
11636
  ez = _getEuler[2];
11671
11637
 
11672
11638
  return rad2deg(ez);
@@ -11677,10 +11643,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11677
11643
  ;
11678
11644
 
11679
11645
  _proto.getLocalEulerAngles = function getLocalEulerAngles() {
11680
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11681
11646
  var _getEuler2 = getEuler(glMatrix.vec3.create(), runtime.sceneGraphService.getLocalRotation(this)),
11682
- ex = _getEuler2[0],
11683
- ey = _getEuler2[1],
11684
11647
  ez = _getEuler2[2];
11685
11648
 
11686
11649
  return rad2deg(ez);
@@ -11907,11 +11870,10 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11907
11870
  sx = _mat4$getScaling[0],
11908
11871
  sy = _mat4$getScaling[1];
11909
11872
 
11910
- var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
11873
+ var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform);
11911
11874
 
11912
11875
  var _getEuler3 = getEuler(glMatrix.vec3.create(), rotation),
11913
11876
  eux = _getEuler3[0],
11914
- euy = _getEuler3[1],
11915
11877
  euz = _getEuler3[2]; // gimbal lock at 90 degrees
11916
11878
 
11917
11879
 
@@ -11975,6 +11937,145 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11975
11937
 
11976
11938
  _proto.hide = function hide() {
11977
11939
  this.style.visibility = 'hidden';
11940
+ }
11941
+ /**
11942
+ * Use `childElementCount` instead.
11943
+ * @deprecated
11944
+ */
11945
+ ;
11946
+
11947
+ _proto.getCount = function getCount() {
11948
+ return this.childElementCount;
11949
+ }
11950
+ /**
11951
+ * Use `parentElement` instead.
11952
+ * @deprecated
11953
+ */
11954
+ ;
11955
+
11956
+ _proto.getParent = function getParent() {
11957
+ return this.parentElement;
11958
+ }
11959
+ /**
11960
+ * Use `children` instead.
11961
+ * @deprecated
11962
+ */
11963
+ ;
11964
+
11965
+ _proto.getChildren = function getChildren() {
11966
+ return this.children;
11967
+ }
11968
+ /**
11969
+ * Use `firstElementChild` instead.
11970
+ * @deprecated
11971
+ */
11972
+ ;
11973
+
11974
+ _proto.getFirst = function getFirst() {
11975
+ return this.firstElementChild;
11976
+ }
11977
+ /**
11978
+ * Use `lastElementChild` instead.
11979
+ * @deprecated
11980
+ */
11981
+ ;
11982
+
11983
+ _proto.getLast = function getLast() {
11984
+ return this.lastElementChild;
11985
+ }
11986
+ /**
11987
+ * Use `this.children[index]` instead.
11988
+ * @deprecated
11989
+ */
11990
+ ;
11991
+
11992
+ _proto.getChildByIndex = function getChildByIndex(index) {
11993
+ return this.children[index] || null;
11994
+ }
11995
+ /**
11996
+ * Use `appendChild` instead.
11997
+ * @deprecated
11998
+ */
11999
+ ;
12000
+
12001
+ _proto.add = function add(child, index) {
12002
+ return this.appendChild(child, index);
12003
+ }
12004
+ /**
12005
+ * Use `this.style.clipPath` instead.
12006
+ * @deprecated
12007
+ */
12008
+ ;
12009
+
12010
+ _proto.setClip = function setClip(clipPath) {
12011
+ this.style.clipPath = clipPath;
12012
+ }
12013
+ /**
12014
+ * Use `this.style.clipPath` instead.
12015
+ * @deprecated
12016
+ */
12017
+ ;
12018
+
12019
+ /**
12020
+ * @deprecated
12021
+ */
12022
+ _proto.set = function set(name, value) {
12023
+ // @ts-ignore
12024
+ this.config[name] = value;
12025
+ }
12026
+ /**
12027
+ * @deprecated
12028
+ */
12029
+ ;
12030
+
12031
+ _proto.get = function get(name) {
12032
+ return this.config[name];
12033
+ }
12034
+ /**
12035
+ * Use `setPosition` instead.
12036
+ * @deprecated
12037
+ */
12038
+ ;
12039
+
12040
+ _proto.moveTo = function moveTo(position, y, z) {
12041
+ if (y === void 0) {
12042
+ y = 0;
12043
+ }
12044
+
12045
+ if (z === void 0) {
12046
+ z = 0;
12047
+ }
12048
+
12049
+ this.setPosition(position, y, z);
12050
+ return this;
12051
+ }
12052
+ /**
12053
+ * Use `setPosition` instead.
12054
+ * @deprecated
12055
+ */
12056
+ ;
12057
+
12058
+ _proto.move = function move(position, y, z) {
12059
+ if (y === void 0) {
12060
+ y = 0;
12061
+ }
12062
+
12063
+ if (z === void 0) {
12064
+ z = 0;
12065
+ }
12066
+
12067
+ this.setPosition(position, y, z);
12068
+ return this;
12069
+ }
12070
+ /**
12071
+ * Use `this.style.zIndex` instead.
12072
+ * @deprecated
12073
+ */
12074
+ ;
12075
+
12076
+ _proto.setZIndex = function setZIndex(zIndex) {
12077
+ this.style.zIndex = zIndex;
12078
+ return this;
11978
12079
  };
11979
12080
 
11980
12081
  _createClass(DisplayObject, [{
@@ -12404,7 +12505,11 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12404
12505
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
12405
12506
  };
12406
12507
 
12407
- _proto.getPoint = function getPoint(ratio) {
12508
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
12509
+ if (inWorldSpace === void 0) {
12510
+ inWorldSpace = false;
12511
+ }
12512
+
12408
12513
  // TODO: account for z1/z2 in 3D line
12409
12514
  var _this$parsedStyle3 = this.parsedStyle,
12410
12515
  x1 = _this$parsedStyle3.x1,
@@ -12418,13 +12523,17 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12418
12523
  x = _LineUtil$pointAt.x,
12419
12524
  y = _LineUtil$pointAt.y;
12420
12525
 
12421
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12526
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12422
12527
 
12423
12528
  return new Point(transformed[0], transformed[1]);
12424
12529
  };
12425
12530
 
12426
- _proto.getPointAtLength = function getPointAtLength(distance) {
12427
- return this.getPoint(distance / this.getTotalLength());
12531
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
12532
+ if (inWorldSpace === void 0) {
12533
+ inWorldSpace = false;
12534
+ }
12535
+
12536
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
12428
12537
  };
12429
12538
 
12430
12539
  _proto.getTotalLength = function getTotalLength() {
@@ -12621,7 +12730,11 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12621
12730
  */
12622
12731
  ;
12623
12732
 
12624
- _proto.getPointAtLength = function getPointAtLength(distance) {
12733
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
12734
+ if (inWorldSpace === void 0) {
12735
+ inWorldSpace = false;
12736
+ }
12737
+
12625
12738
  var _this$parsedStyle4 = this.parsedStyle,
12626
12739
  defX = _this$parsedStyle4.defX,
12627
12740
  defY = _this$parsedStyle4.defY,
@@ -12631,7 +12744,7 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12631
12744
  x = _getPointAtLength2.x,
12632
12745
  y = _getPointAtLength2.y;
12633
12746
 
12634
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12747
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12635
12748
 
12636
12749
  return new Point(transformed[0], transformed[1]);
12637
12750
  }
@@ -12640,8 +12753,12 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12640
12753
  */
12641
12754
  ;
12642
12755
 
12643
- _proto.getPoint = function getPoint(ratio) {
12644
- return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this));
12756
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
12757
+ if (inWorldSpace === void 0) {
12758
+ inWorldSpace = false;
12759
+ }
12760
+
12761
+ return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this), inWorldSpace);
12645
12762
  }
12646
12763
  /**
12647
12764
  * Get start tangent vector
@@ -12900,11 +13017,19 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
12900
13017
  return this.parsedStyle.points.totalLength;
12901
13018
  };
12902
13019
 
12903
- _proto.getPointAtLength = function getPointAtLength(distance) {
12904
- return this.getPoint(distance / this.getTotalLength());
13020
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
13021
+ if (inWorldSpace === void 0) {
13022
+ inWorldSpace = false;
13023
+ }
13024
+
13025
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
12905
13026
  };
12906
13027
 
12907
- _proto.getPoint = function getPoint(ratio) {
13028
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
13029
+ if (inWorldSpace === void 0) {
13030
+ inWorldSpace = false;
13031
+ }
13032
+
12908
13033
  var _this$parsedStyle = this.parsedStyle,
12909
13034
  defX = _this$parsedStyle.defX,
12910
13035
  defY = _this$parsedStyle.defY,
@@ -12924,7 +13049,7 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
12924
13049
  x = _LineUtil$pointAt.x,
12925
13050
  y = _LineUtil$pointAt.y;
12926
13051
 
12927
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
13052
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12928
13053
 
12929
13054
  return new Point(transformed[0], transformed[1]);
12930
13055
  };
@@ -13430,18 +13555,25 @@ var Camera = /*#__PURE__*/function () {
13430
13555
  ox = _this$canvas$viewport.x,
13431
13556
  oy = _this$canvas$viewport.y;
13432
13557
 
13558
+ var roll = this.roll;
13559
+ this.rotate(0, 0, -roll);
13433
13560
  this.setPosition(ox, oy);
13434
13561
  this.setFocalPoint(ox, oy);
13435
13562
  this.setZoom(zoom);
13563
+ this.rotate(0, 0, roll);
13436
13564
 
13437
13565
  var _this$canvas$viewport2 = this.canvas.viewport2Canvas({
13438
13566
  x: viewportPoint[0],
13439
13567
  y: viewportPoint[1]
13440
13568
  }),
13441
13569
  cx = _this$canvas$viewport2.x,
13442
- cy = _this$canvas$viewport2.y;
13570
+ cy = _this$canvas$viewport2.y; // project to rotated axis
13571
+
13443
13572
 
13444
- this.pan(ox - cx, oy - cy);
13573
+ var dvec = glMatrix.vec3.fromValues(cx - ox, cy - oy, 0);
13574
+ var dx = glMatrix.vec3.dot(dvec, this.right) / glMatrix.vec3.length(this.right);
13575
+ var dy = glMatrix.vec3.dot(dvec, this.up) / glMatrix.vec3.length(this.up);
13576
+ this.pan(-dx, -dy);
13445
13577
  return this;
13446
13578
  };
13447
13579
 
@@ -14105,7 +14237,7 @@ var TextUpdater = /*#__PURE__*/function () {
14105
14237
  var anchor = [0, 1];
14106
14238
  var lineXOffset = 0;
14107
14239
 
14108
- if (textAlign === 'center') {
14240
+ if (textAlign === 'center' || textAlign === 'middle') {
14109
14241
  lineXOffset = lineWidth / 2;
14110
14242
  anchor = [0.5, 1];
14111
14243
  } else if (textAlign === 'right' || textAlign === 'end') {
@@ -14830,10 +14962,20 @@ var EventService = /*#__PURE__*/function () {
14830
14962
  }
14831
14963
  };
14832
14964
 
14833
- _proto.dispatchEvent = function dispatchEvent(e, type) {
14834
- e.propagationStopped = false;
14835
- e.propagationImmediatelyStopped = false;
14836
- this.propagate(e, type);
14965
+ _proto.dispatchEvent = function dispatchEvent(e, type, skipPropagate) {
14966
+ // Canvas should skip
14967
+ if (!skipPropagate) {
14968
+ e.propagationStopped = false;
14969
+ e.propagationImmediatelyStopped = false;
14970
+ this.propagate(e, type);
14971
+ } else {
14972
+ // target phase
14973
+ e.eventPhase = e.AT_TARGET;
14974
+ var canvas = this.rootTarget.defaultView || null;
14975
+ e.currentTarget = canvas;
14976
+ this.notifyListeners(e, type);
14977
+ }
14978
+
14837
14979
  this.emitter.emit(type || e.type, e);
14838
14980
  };
14839
14981
 
@@ -15639,10 +15781,11 @@ var RenderingService = /*#__PURE__*/function () {
15639
15781
 
15640
15782
  if (renderOrderChanged) {
15641
15783
  displayObject.forEach(function (child) {
15784
+ _this2.renderOrderChangedEvent.target = child;
15642
15785
  _this2.renderOrderChangedEvent.detail = {
15643
15786
  renderOrder: child.sortable.renderOrder
15644
15787
  };
15645
- child.dispatchEvent(_this2.renderOrderChangedEvent);
15788
+ child.ownerDocument.defaultView.dispatchEvent(_this2.renderOrderChangedEvent, true);
15646
15789
  });
15647
15790
  }
15648
15791
  };
@@ -16303,9 +16446,10 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16303
16446
  var set = new Set();
16304
16447
 
16305
16448
  var trigger = function trigger(element, detail) {
16306
- if (!set.has(element.entity)) {
16449
+ if (element.isConnected && !set.has(element.entity)) {
16307
16450
  _this2.boundsChangedEvent.detail = detail;
16308
- element.dispatchEvent(_this2.boundsChangedEvent);
16451
+ _this2.boundsChangedEvent.target = element;
16452
+ element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent, true);
16309
16453
  set.add(element.entity);
16310
16454
  }
16311
16455
  };
@@ -16323,6 +16467,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16323
16467
  }
16324
16468
  });
16325
16469
  this.pendingEvents = [];
16470
+ set.clear();
16326
16471
  };
16327
16472
 
16328
16473
  _proto.dirtifyToRoot = function dirtifyToRoot(element, affectChildren) {
@@ -16973,7 +17118,7 @@ var TextService = /*#__PURE__*/function () {
16973
17118
  lineMetrics: lineWidths.map(function (width, i) {
16974
17119
  var offsetX = 0; // handle horizontal text align
16975
17120
 
16976
- if (textAlign === 'center') {
17121
+ if (textAlign === 'center' || textAlign === 'middle') {
16977
17122
  offsetX -= width / 2;
16978
17123
  } else if (textAlign === 'right' || textAlign === 'end') {
16979
17124
  offsetX -= width;
@@ -17803,21 +17948,14 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17803
17948
 
17804
17949
  var _proto = PrepareRendererPlugin.prototype;
17805
17950
 
17806
- _proto.pushToSync = function pushToSync(list) {
17807
- var _this = this;
17808
-
17809
- list.forEach(function (i) {
17810
- _this.toSync.add(i);
17811
- });
17812
- } // private isFirstTimeRendering = true;
17813
- ;
17814
-
17951
+ // private isFirstTimeRendering = true;
17815
17952
  _proto.apply = function apply(context) {
17816
- var _this2 = this;
17953
+ var _this = this;
17817
17954
 
17818
17955
  var renderingService = context.renderingService,
17819
17956
  renderingContext = context.renderingContext,
17820
17957
  rBushRoot = context.rBushRoot;
17958
+ var canvas = renderingContext.root.ownerDocument.defaultView;
17821
17959
  this.rBush = rBushRoot;
17822
17960
 
17823
17961
  var handleAttributeChanged = function handleAttributeChanged(e) {
@@ -17832,20 +17970,26 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17832
17970
 
17833
17971
  if (affectChildren) {
17834
17972
  object.forEach(function (node) {
17835
- _this2.pushToSync([node]);
17973
+ _this.toSync.add(node);
17836
17974
  });
17837
17975
  }
17838
17976
 
17839
- _this2.pushToSync(e.composedPath().slice(0, -2));
17977
+ var p = object;
17978
+
17979
+ while (p) {
17980
+ if (p.renderable) {
17981
+ _this.toSync.add(p);
17982
+ }
17983
+
17984
+ p = p.parentElement;
17985
+ } // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
17986
+
17840
17987
 
17841
17988
  renderingService.dirtify();
17842
17989
  };
17843
17990
 
17844
17991
  var handleMounted = function handleMounted(e) {
17845
- var object = e.target;
17846
-
17847
- _this2.pushToSync(e.composedPath().slice(0, -2)); // recalc style values
17848
-
17992
+ var object = e.target; // recalc style values
17849
17993
 
17850
17994
  runtime.styleValueRegistry.recalc(object);
17851
17995
  runtime.sceneGraphService.dirtifyToRoot(object);
@@ -17857,12 +18001,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17857
18001
  var rBushNode = object.rBushNode;
17858
18002
 
17859
18003
  if (rBushNode.aabb) {
17860
- _this2.rBush.remove(rBushNode.aabb);
18004
+ _this.rBush.remove(rBushNode.aabb);
17861
18005
  }
17862
18006
 
17863
- _this2.toSync.delete(object);
18007
+ _this.toSync.delete(object);
17864
18008
 
17865
- runtime.sceneGraphService.dirtifyToRoot(e.target);
18009
+ runtime.sceneGraphService.dirtifyToRoot(object);
17866
18010
  renderingService.dirtify();
17867
18011
  };
17868
18012
 
@@ -17871,10 +18015,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17871
18015
  while (1) {
17872
18016
  switch (_context.prev = _context.next) {
17873
18017
  case 0:
17874
- renderingContext.root.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
17875
- renderingContext.root.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
17876
- renderingContext.root.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
17877
- renderingContext.root.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18018
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
18019
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
18020
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18021
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
17878
18022
 
17879
18023
  case 4:
17880
18024
  case "end":
@@ -17884,10 +18028,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17884
18028
  }, _callee);
17885
18029
  })));
17886
18030
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
17887
- renderingContext.root.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
17888
- renderingContext.root.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
17889
- renderingContext.root.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
17890
- renderingContext.root.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18031
+ canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
18032
+ canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
18033
+ canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18034
+ canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
17891
18035
  });
17892
18036
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
17893
18037
  // if (this.isFirstTimeRendering) {
@@ -17897,12 +18041,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17897
18041
  // } else {
17898
18042
  // this.syncRTree();
17899
18043
  // }
17900
- _this2.syncRTree();
18044
+ _this.syncRTree();
17901
18045
  });
17902
18046
  };
17903
18047
 
17904
18048
  _proto.syncRTree = function syncRTree() {
17905
- var _this3 = this;
18049
+ var _this2 = this;
17906
18050
 
17907
18051
  // bounds changed, need re-inserting its children
17908
18052
  var bulk = [];
@@ -17913,7 +18057,7 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17913
18057
  var rBushNode = node.rBushNode; // clear dirty node
17914
18058
 
17915
18059
  if (rBushNode && rBushNode.aabb) {
17916
- _this3.rBush.remove(rBushNode.aabb);
18060
+ _this2.rBush.remove(rBushNode.aabb);
17917
18061
  }
17918
18062
 
17919
18063
  var renderBounds = node.getRenderBounds();
@@ -17970,6 +18114,14 @@ PrepareRendererPlugin.tag = 'Prepare';
17970
18114
  var DEFAULT_CAMERA_Z = 500;
17971
18115
  var DEFAULT_CAMERA_NEAR = 0.1;
17972
18116
  var DEFAULT_CAMERA_FAR = 1000;
18117
+ /**
18118
+ * reuse custom event preventing from re-create them in every frame
18119
+ */
18120
+
18121
+ var mountedEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
18122
+ var unmountedEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
18123
+ var beforeRenderEvent = new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);
18124
+ var afterRenderEvent = new CustomEvent(exports.CanvasEvent.AFTER_RENDER);
17973
18125
  /**
17974
18126
  * can be treated like Window in DOM
17975
18127
  * provide some extra methods like `window`, such as:
@@ -18027,10 +18179,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18027
18179
  /**
18028
18180
  * rAF in auto rendering
18029
18181
  */
18030
-
18031
- /**
18032
- * reuse custom event preventing from re-create them in every frame
18033
- */
18034
18182
  function Canvas(config) {
18035
18183
  var _this;
18036
18184
 
@@ -18050,10 +18198,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18050
18198
  _this.inited = false;
18051
18199
  _this.readyPromise = void 0;
18052
18200
  _this.resolveReadyPromise = void 0;
18053
- _this.mountEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
18054
- _this.unmountEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
18055
- _this.beforeRenderEvent = new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);
18056
- _this.afterRenderEvent = new CustomEvent(exports.CanvasEvent.AFTER_RENDER);
18057
18201
  _this.context = {};
18058
18202
  _this.document = new Document();
18059
18203
  _this.document.defaultView = _assertThisInitialized(_this); // create registry of custom elements
@@ -18158,8 +18302,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18158
18302
  var _proto = Canvas.prototype;
18159
18303
 
18160
18304
  _proto.initRenderingContext = function initRenderingContext(mergedConfig) {
18161
- var _this2 = this;
18162
-
18163
18305
  this.context.config = mergedConfig; // bind rendering context, shared by all renderers
18164
18306
 
18165
18307
  this.context.renderingContext = {
@@ -18173,16 +18315,10 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18173
18315
  force: false,
18174
18316
  dirty: false
18175
18317
  };
18176
- this.document.documentElement.addEventListener(exports.ElementEvent.CHILD_INSERTED, function (e) {
18177
- _this2.mountChildren(e.detail.child);
18178
- });
18179
- this.document.documentElement.addEventListener(exports.ElementEvent.CHILD_REMOVED, function (e) {
18180
- _this2.unmountChildren(e.detail.child);
18181
- });
18182
18318
  };
18183
18319
 
18184
18320
  _proto.initDefaultCamera = function initDefaultCamera(width, height) {
18185
- var _this3 = this;
18321
+ var _this2 = this;
18186
18322
 
18187
18323
  // set a default ortho camera
18188
18324
  var camera = new runtime.CameraContribution();
@@ -18191,7 +18327,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18191
18327
  camera.canvas = this; // redraw when camera changed
18192
18328
 
18193
18329
  camera.eventEmitter.on(CameraEvent.UPDATED, function () {
18194
- _this3.context.renderingContext.renderReasons.add(exports.RenderReason.CAMERA_CHANGED);
18330
+ _this2.context.renderingContext.renderReasons.add(exports.RenderReason.CAMERA_CHANGED);
18195
18331
  }); // bind camera
18196
18332
 
18197
18333
  this.context.camera = camera;
@@ -18335,19 +18471,19 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18335
18471
  };
18336
18472
 
18337
18473
  _proto.render = function render() {
18338
- this.dispatchEvent(this.beforeRenderEvent);
18474
+ this.dispatchEvent(beforeRenderEvent);
18339
18475
  var renderingService = this.getRenderingService();
18340
18476
  renderingService.render(this.getConfig());
18341
- this.dispatchEvent(this.afterRenderEvent);
18477
+ this.dispatchEvent(afterRenderEvent);
18342
18478
  };
18343
18479
 
18344
18480
  _proto.run = function run() {
18345
- var _this4 = this;
18481
+ var _this3 = this;
18346
18482
 
18347
18483
  var tick = function tick() {
18348
- _this4.render();
18484
+ _this3.render();
18349
18485
 
18350
- _this4.frameId = requestAnimationFrame(tick);
18486
+ _this3.frameId = requestAnimationFrame(tick);
18351
18487
  };
18352
18488
 
18353
18489
  tick();
@@ -18425,12 +18561,12 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18425
18561
  }();
18426
18562
 
18427
18563
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
18428
- var _this5 = this;
18564
+ var _this4 = this;
18429
18565
 
18430
18566
  // load other container modules provided by g-canvas/g-svg/g-webgl
18431
18567
  var plugins = renderer.getPlugins();
18432
18568
  plugins.forEach(function (plugin) {
18433
- plugin.context = _this5.context;
18569
+ plugin.context = _this4.context;
18434
18570
  plugin.init();
18435
18571
  });
18436
18572
  };
@@ -18486,7 +18622,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18486
18622
  };
18487
18623
 
18488
18624
  _proto.unmountChildren = function unmountChildren(parent) {
18489
- var _this6 = this;
18625
+ var _this5 = this;
18490
18626
 
18491
18627
  if (this.inited) {
18492
18628
  var path = [];
@@ -18498,15 +18634,22 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18498
18634
 
18499
18635
  path.reverse().forEach(function (child) {
18500
18636
  // trigger before unmounted
18501
- if (child instanceof CustomElement) {
18637
+ if (child.isCustomElement) {
18502
18638
  if (child.disconnectedCallback) {
18503
18639
  child.disconnectedCallback();
18504
18640
  }
18505
18641
  }
18506
18642
 
18507
- child.dispatchEvent(_this6.unmountEvent); // skip document.documentElement
18643
+ if (child.isMutationObserved) {
18644
+ child.dispatchEvent(unmountedEvent);
18645
+ } else {
18646
+ unmountedEvent.target = child;
18647
+
18648
+ _this5.dispatchEvent(unmountedEvent, true);
18649
+ } // skip document.documentElement
18650
+
18508
18651
 
18509
- if (child !== _this6.document.documentElement) {
18652
+ if (child !== _this5.document.documentElement) {
18510
18653
  child.ownerDocument = null;
18511
18654
  }
18512
18655
 
@@ -18516,16 +18659,24 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18516
18659
  };
18517
18660
 
18518
18661
  _proto.mountChildren = function mountChildren(parent) {
18519
- var _this7 = this;
18662
+ var _this6 = this;
18520
18663
 
18521
18664
  if (this.inited) {
18522
18665
  parent.forEach(function (child) {
18523
18666
  if (!child.isConnected) {
18524
- child.ownerDocument = _this7.document;
18667
+ child.ownerDocument = _this6.document;
18525
18668
  child.isConnected = true;
18526
- child.dispatchEvent(_this7.mountEvent); // trigger after mounted
18527
18669
 
18528
- if (child instanceof CustomElement) {
18670
+ if (child.isMutationObserved) {
18671
+ child.dispatchEvent(mountedEvent);
18672
+ } else {
18673
+ mountedEvent.target = child;
18674
+
18675
+ _this6.dispatchEvent(mountedEvent, true);
18676
+ } // trigger after mounted
18677
+
18678
+
18679
+ if (child.isCustomElement) {
18529
18680
  if (child.connectedCallback) {
18530
18681
  child.connectedCallback();
18531
18682
  }
@@ -18580,12 +18731,12 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18580
18731
  _createClass(Canvas, [{
18581
18732
  key: "ready",
18582
18733
  get: function get() {
18583
- var _this8 = this;
18734
+ var _this7 = this;
18584
18735
 
18585
18736
  if (!this.readyPromise) {
18586
18737
  this.readyPromise = new Promise(function (resolve) {
18587
- _this8.resolveReadyPromise = function () {
18588
- resolve(_this8);
18738
+ _this7.resolveReadyPromise = function () {
18739
+ resolve(_this7);
18589
18740
  };
18590
18741
  });
18591
18742