@antv/g 5.5.3 → 5.6.1

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
@@ -8736,12 +8736,12 @@ function convertToMatrix(transformList) {
8736
8736
 
8737
8737
  function makeMatrixDecomposition(transformList) {
8738
8738
  var translate = [0, 0, 0];
8739
- var scale = [0, 0, 0];
8739
+ var scale = [1, 1, 1];
8740
8740
  var skew = [0, 0, 0];
8741
8741
  var perspective = [0, 0, 0, 1];
8742
8742
  var quaternion = [0, 0, 0, 1];
8743
8743
  decomposeMatrix__default['default'](convertToMatrix(transformList), translate, scale, skew, perspective, quaternion);
8744
- return [translate, scale, skew, quaternion, perspective];
8744
+ return [[translate, scale, skew, quaternion, perspective]];
8745
8745
  }
8746
8746
 
8747
8747
  var composeMatrix = function () {
@@ -8836,14 +8836,16 @@ function mergeMatrices(left, right) {
8836
8836
 
8837
8837
  if (left.decompositionPair !== right) {
8838
8838
  // @ts-ignore
8839
- left.decompositionPair = right;
8839
+ left.decompositionPair = right; // @ts-ignore
8840
+
8840
8841
  leftArgs = makeMatrixDecomposition(left);
8841
8842
  } // @ts-ignore
8842
8843
 
8843
8844
 
8844
8845
  if (right.decompositionPair !== left) {
8845
8846
  // @ts-ignore
8846
- right.decompositionPair = left;
8847
+ right.decompositionPair = left; // @ts-ignore
8848
+
8847
8849
  rightArgs = makeMatrixDecomposition(right);
8848
8850
  }
8849
8851
 
@@ -9030,7 +9032,15 @@ function mergeTransforms(left, right, target) {
9030
9032
  var stringifiedArgs = args.map(function (arg, j) {
9031
9033
  return types[i][1][j](arg);
9032
9034
  }).join(',');
9033
- if (types[i][0] === 'matrix' && stringifiedArgs.split(',').length === 16) types[i][0] = 'matrix3d';
9035
+
9036
+ if (types[i][0] === 'matrix' && stringifiedArgs.split(',').length === 16) {
9037
+ types[i][0] = 'matrix3d';
9038
+ }
9039
+
9040
+ if (types[i][0] === 'matrix3d' && stringifiedArgs.split(',').length === 6) {
9041
+ types[i][0] = 'matrix';
9042
+ }
9043
+
9034
9044
  return types[i][0] + '(' + stringifiedArgs + ')';
9035
9045
  }).join(' ');
9036
9046
  }];
@@ -9043,6 +9053,10 @@ function mergeTransforms(left, right, target) {
9043
9053
 
9044
9054
  function parseTransformOrigin(value) {
9045
9055
  if (isString(value)) {
9056
+ if (value === 'text-anchor') {
9057
+ return [new CSSUnitValue(0, 'px'), new CSSUnitValue(0, 'px')];
9058
+ }
9059
+
9046
9060
  var values = value.split(' ');
9047
9061
 
9048
9062
  if (values.length === 1) {
@@ -10533,2337 +10547,2320 @@ var Element = /*#__PURE__*/function (_Node) {
10533
10547
  return Element;
10534
10548
  }(Node);
10535
10549
 
10536
- /**
10537
- * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationPlaybackEvent
10538
- */
10550
+ exports.DisplayObjectPool = /*#__PURE__*/function () {
10551
+ function DisplayObjectPool() {
10552
+ this.pool = {};
10553
+ this.htmlPool = [];
10554
+ }
10539
10555
 
10540
- var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) {
10541
- _inheritsLoose(AnimationEvent, _FederatedEvent);
10556
+ var _proto = DisplayObjectPool.prototype;
10542
10557
 
10543
- function AnimationEvent(manager, target, currentTime, timelineTime) {
10544
- var _this;
10558
+ _proto.getByEntity = function getByEntity(entity) {
10559
+ return this.pool[entity];
10560
+ };
10545
10561
 
10546
- _this = _FederatedEvent.call(this, manager) || this;
10547
- _this.currentTime = void 0;
10548
- _this.timelineTime = void 0;
10549
- _this.currentTime = currentTime;
10550
- _this.timelineTime = timelineTime; // @ts-ignore
10562
+ _proto.add = function add(entity, groupOrShape) {
10563
+ this.pool[entity] = groupOrShape;
10551
10564
 
10552
- _this.target = target;
10553
- _this.type = 'finish';
10554
- _this.bubbles = false; // @ts-ignore
10565
+ if (groupOrShape.nodeName === exports.Shape.HTML) {
10566
+ this.htmlPool.push(groupOrShape);
10567
+ }
10568
+ };
10555
10569
 
10556
- _this.currentTarget = target;
10557
- _this.defaultPrevented = false;
10558
- _this.eventPhase = _this.AT_TARGET;
10559
- _this.timeStamp = Date.now();
10560
- _this.currentTime = currentTime;
10561
- _this.timelineTime = timelineTime;
10562
- return _this;
10563
- }
10570
+ _proto.remove = function remove(entity) {
10571
+ var existed = this.pool[entity];
10572
+ delete this.pool[entity];
10564
10573
 
10565
- return AnimationEvent;
10566
- }(FederatedEvent);
10574
+ if (existed.nodeName === exports.Shape.HTML) {
10575
+ var index = this.htmlPool.indexOf(existed);
10576
+ this.htmlPool.splice(index, 1);
10577
+ }
10578
+ };
10567
10579
 
10568
- var sequenceNumber = 0;
10580
+ _proto.getHTMLs = function getHTMLs() {
10581
+ return this.htmlPool;
10582
+ };
10583
+
10584
+ return DisplayObjectPool;
10585
+ }();
10586
+
10587
+ exports.DisplayObjectPool = tslib.__decorate([manaSyringe.singleton()], exports.DisplayObjectPool);
10588
+
10589
+ var DEFAULT_STYLE_PROPS = {
10590
+ anchor: '',
10591
+ opacity: '',
10592
+ fillOpacity: '',
10593
+ strokeOpacity: '',
10594
+ fill: '',
10595
+ stroke: '',
10596
+ transform: '',
10597
+ transformOrigin: '',
10598
+ visibility: '',
10599
+ pointerEvents: '',
10600
+ lineWidth: '',
10601
+ lineCap: '',
10602
+ lineJoin: '',
10603
+ increasedLineWidthForHitTesting: '',
10604
+ fontSize: '',
10605
+ fontFamily: '',
10606
+ fontStyle: '',
10607
+ fontWeight: '',
10608
+ fontVariant: '',
10609
+ textAlign: '',
10610
+ textBaseline: '',
10611
+ textTransform: '',
10612
+ zIndex: '',
10613
+ filter: '',
10614
+ shadowType: ''
10615
+ };
10569
10616
  /**
10570
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/Animation
10617
+ * prototype chains: DisplayObject -> Element -> Node -> EventTarget
10618
+ *
10619
+ * mixins: Animatable, Transformable, Visible
10620
+ * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes
10621
+ *
10622
+ * Provide abilities in scene graph, such as:
10623
+ * * transform `translate/rotate/scale`
10624
+ * * add/remove child
10625
+ * * visibility and z-index
10626
+ *
10627
+ * Those abilities are implemented with those components: `Transform/Sortable/Visible`.
10628
+ *
10629
+ * Emit following events:
10630
+ * * init
10631
+ * * destroy
10632
+ * * attributeChanged
10571
10633
  */
10572
10634
 
10573
- var Animation = /*#__PURE__*/function () {
10574
- function Animation(effect, timeline) {
10575
- this.effect = void 0;
10576
- this.timeline = void 0;
10577
- this.id = void 0;
10578
- this.currentTimePending = false;
10579
- this._idle = true;
10580
- this._paused = false;
10581
- this._finishedFlag = true;
10582
- this.oldPlayState = void 0;
10583
- this._holdTime = void 0;
10584
- this.readyPromise = void 0;
10585
- this.finishedPromise = void 0;
10586
- this.resolveReadyPromise = void 0;
10587
- this.rejectReadyPromise = void 0;
10588
- this.resolveFinishedPromise = void 0;
10589
- this.rejectFinishedPromise = void 0;
10590
- this.onfinish = void 0;
10591
- this.oncancel = void 0;
10592
- this.onframe = void 0;
10593
- this._currentTime = 0;
10594
- this._startTime = void 0;
10595
- this._playbackRate = 1;
10596
- this._inEffect = void 0;
10597
- this._inTimeline = true;
10598
- this.onremove = void 0;
10599
- this.effect = effect;
10600
- effect.animation = this;
10601
- this.timeline = timeline;
10602
- this.id = "" + sequenceNumber++;
10603
- this._inEffect = !!this.effect.update(0);
10604
- this._holdTime = 0;
10605
- this._paused = false;
10606
- this.oldPlayState = 'idle';
10607
- this.updatePromises();
10608
- }
10635
+ var DisplayObject = /*#__PURE__*/function (_Element) {
10636
+ _inheritsLoose(DisplayObject, _Element);
10637
+
10609
10638
  /**
10610
- * state machine,
10611
- * resolve/reject ready/finished Promise according to current state
10639
+ * contains style props in constructor's params, eg. fill, stroke...
10612
10640
  */
10613
10641
 
10642
+ /**
10643
+ * push to active animations after calling `animate()`
10644
+ */
10645
+ function DisplayObject(config) {
10646
+ var _this$config$capture;
10614
10647
 
10615
- var _proto = Animation.prototype;
10616
-
10617
- _proto.updatePromises = function updatePromises() {
10618
- var oldPlayState = this.oldPlayState;
10619
- var newPlayState = this.pending ? 'pending' : this.playState;
10620
-
10621
- if (this.readyPromise && newPlayState !== oldPlayState) {
10622
- if (newPlayState === 'idle') {
10623
- this.rejectReadyPromise();
10624
- this.readyPromise = undefined;
10625
- } else if (oldPlayState === 'pending') {
10626
- this.resolveReadyPromise();
10627
- } else if (newPlayState === 'pending') {
10628
- this.readyPromise = undefined;
10629
- }
10630
- }
10631
-
10632
- if (this.finishedPromise && newPlayState !== oldPlayState) {
10633
- if (newPlayState === 'idle') {
10634
- this.rejectFinishedPromise();
10635
- this.finishedPromise = undefined;
10636
- } else if (newPlayState === 'finished') {
10637
- this.resolveFinishedPromise();
10638
- } else if (oldPlayState === 'finished') {
10639
- this.finishedPromise = undefined;
10640
- }
10641
- }
10648
+ var _this;
10642
10649
 
10643
- this.oldPlayState = newPlayState;
10644
- return this.readyPromise || this.finishedPromise;
10645
- };
10650
+ _this = _Element.call(this) || this; // assign name, id to config
10651
+ // eg. group.get('name')
10646
10652
 
10647
- _proto.play = function play() {
10648
- this.updatePromises();
10649
- this._paused = false;
10653
+ _this.config = void 0;
10654
+ _this.styleValueRegistry = manaSyringe.GlobalContainer.get(StyleValueRegistry);
10655
+ _this.isCustomElement = false;
10656
+ _this.activeAnimations = [];
10657
+ _this.mutationEvent = new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, _assertThisInitialized(_this), null, null, null, MutationEvent.MODIFICATION, null, null);
10658
+ _this.config = config; // compatible with G 3.0
10650
10659
 
10651
- if (this._isFinished || this._idle) {
10652
- this.rewind();
10653
- this._startTime = null;
10654
- }
10660
+ _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
10655
10661
 
10656
- this._finishedFlag = false;
10657
- this._idle = false;
10658
- this.ensureAlive();
10659
- this.timeline.applyDirtiedAnimation(this);
10662
+ _this.id = _this.config.id || '';
10663
+ _this.name = _this.config.name || '';
10660
10664
 
10661
- if (this.timeline.animations.indexOf(this) === -1) {
10662
- this.timeline.animations.push(this);
10665
+ if (_this.config.className || _this.config.class) {
10666
+ _this.className = _this.config.className || _this.config.class;
10663
10667
  }
10664
10668
 
10665
- this.updatePromises();
10666
- };
10669
+ _this.nodeName = _this.config.type || exports.Shape.GROUP; // compatible with G 3.0
10667
10670
 
10668
- _proto.pause = function pause() {
10669
- this.updatePromises();
10671
+ _this.config.style = _extends({}, DEFAULT_STYLE_PROPS, _this.config.style, _this.config.attrs);
10670
10672
 
10671
- if (this.currentTime) {
10672
- this._holdTime = this.currentTime;
10673
+ if (_this.config.visible != null) {
10674
+ _this.config.style.visibility = _this.config.visible === false ? 'hidden' : 'visible';
10673
10675
  }
10674
10676
 
10675
- if (!this._isFinished && !this._paused && !this._idle) {
10676
- this.currentTimePending = true;
10677
- } else if (this._idle) {
10678
- this.rewind();
10679
- this._idle = false;
10677
+ if (_this.config.interactive != null) {
10678
+ _this.config.style.pointerEvents = _this.config.interactive === false ? 'none' : 'auto';
10680
10679
  }
10681
10680
 
10682
- this._startTime = null;
10683
- this._paused = true;
10684
- this.updatePromises();
10685
- };
10681
+ _this.style = new Proxy(_extends({}, _this.attributes, {
10682
+ setProperty: function setProperty(propertyName, value) {
10683
+ _this.setAttribute(propertyName, value);
10684
+ },
10685
+ getPropertyValue: function getPropertyValue(propertyName) {
10686
+ return _this.getAttribute(propertyName);
10687
+ },
10688
+ removeProperty: function removeProperty(propertyName) {
10689
+ _this.removeAttribute(propertyName);
10690
+ },
10691
+ item: function item() {
10692
+ return '';
10693
+ }
10694
+ }), {
10695
+ get: function get(target, name) {
10696
+ if (target[name] !== undefined) {
10697
+ // if (name in target) {
10698
+ return target[name];
10699
+ }
10686
10700
 
10687
- _proto.finish = function finish() {
10688
- this.updatePromises();
10689
- if (this._idle) return;
10690
- this.currentTime = this._playbackRate > 0 ? this.totalDuration : 0;
10691
- this._startTime = this.totalDuration - this.currentTime;
10692
- this.currentTimePending = false;
10693
- this.timeline.applyDirtiedAnimation(this);
10694
- this.updatePromises();
10695
- };
10696
-
10697
- _proto.cancel = function cancel() {
10698
- this.updatePromises();
10699
- if (!this._inEffect) return;
10700
- this._inEffect = false;
10701
- this._idle = true;
10702
- this._paused = false;
10703
- this._finishedFlag = true;
10704
- this._currentTime = 0;
10705
- this._startTime = null;
10706
- this.effect.update(null); // effects are invalid after cancellation as the animation state
10707
- // needs to un-apply.
10701
+ return _this.getAttribute(name);
10702
+ },
10703
+ set: function set(_, prop, value) {
10704
+ _this.setAttribute(prop, value);
10708
10705
 
10709
- this.timeline.applyDirtiedAnimation(this);
10710
- this.updatePromises();
10711
- };
10706
+ return true;
10707
+ }
10708
+ });
10712
10709
 
10713
- _proto.reverse = function reverse() {
10714
- this.updatePromises();
10715
- var oldCurrentTime = this.currentTime;
10716
- this.playbackRate *= -1;
10717
- this.play();
10710
+ _this.initAttributes(_this.config.style); // insert this group into pool
10718
10711
 
10719
- if (oldCurrentTime !== null) {
10720
- this.currentTime = oldCurrentTime;
10721
- }
10722
10712
 
10723
- this.updatePromises();
10713
+ manaSyringe.GlobalContainer.get(exports.DisplayObjectPool).add(_this.entity, _assertThisInitialized(_this));
10714
+ return _this;
10724
10715
  }
10725
- /**
10726
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate
10727
- */
10728
- ;
10729
10716
 
10730
- _proto.updatePlaybackRate = function updatePlaybackRate(playbackRate) {
10731
- this.playbackRate = playbackRate;
10732
- };
10717
+ var _proto = DisplayObject.prototype;
10733
10718
 
10734
- _proto.targetAnimations = function targetAnimations() {
10735
- var _this$effect;
10719
+ _proto.destroy = function destroy() {
10720
+ _Element.prototype.destroy.call(this); // remove from into pool
10736
10721
 
10737
- var target = (_this$effect = this.effect) === null || _this$effect === void 0 ? void 0 : _this$effect.target;
10738
- return target.getAnimations();
10739
- };
10740
10722
 
10741
- _proto.markTarget = function markTarget() {
10742
- var animations = this.targetAnimations();
10723
+ manaSyringe.GlobalContainer.get(exports.DisplayObjectPool).remove(this.entity); // stop all active animations
10743
10724
 
10744
- if (animations.indexOf(this) === -1) {
10745
- animations.push(this);
10746
- }
10725
+ this.getAnimations().forEach(function (animation) {
10726
+ animation.cancel();
10727
+ });
10747
10728
  };
10748
10729
 
10749
- _proto.unmarkTarget = function unmarkTarget() {
10750
- var animations = this.targetAnimations();
10751
- var index = animations.indexOf(this);
10730
+ _proto.cloneNode = function cloneNode(deep) {
10731
+ var cloned = new this.constructor({
10732
+ // copy id & name
10733
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
10734
+ id: this.id,
10735
+ name: this.name,
10736
+ className: this.name,
10737
+ interactive: this.interactive,
10738
+ style: _extends({}, this.attributes)
10739
+ }); // apply transform
10752
10740
 
10753
- if (index !== -1) {
10754
- animations.splice(index, 1);
10755
- }
10756
- };
10741
+ cloned.setLocalTransform(this.getLocalTransform());
10757
10742
 
10758
- _proto.tick = function tick(timelineTime, isAnimationFrame) {
10759
- if (!this._idle && !this._paused) {
10760
- if (this._startTime === null) {
10761
- if (isAnimationFrame) {
10762
- this.startTime = timelineTime - this._currentTime / this.playbackRate;
10763
- }
10764
- } else if (!this._isFinished) {
10765
- this.tickCurrentTime((timelineTime - this._startTime) * this.playbackRate);
10766
- }
10743
+ if (deep) {
10744
+ this.children.forEach(function (child) {
10745
+ var clonedChild = child.cloneNode(deep);
10746
+ cloned.appendChild(clonedChild);
10747
+ });
10767
10748
  }
10768
10749
 
10769
- if (isAnimationFrame) {
10770
- this.currentTimePending = false;
10771
- this.fireEvents(timelineTime);
10772
- }
10750
+ return cloned;
10773
10751
  };
10774
10752
 
10775
- _proto.rewind = function rewind() {
10776
- if (this.playbackRate >= 0) {
10777
- this.currentTime = 0;
10778
- } else if (this.totalDuration < Infinity) {
10779
- this.currentTime = this.totalDuration;
10780
- } else {
10781
- throw new Error('Unable to rewind negative playback rate animation with infinite duration');
10753
+ _proto.initAttributes = function initAttributes(attributes) {
10754
+ if (attributes === void 0) {
10755
+ attributes = {};
10782
10756
  }
10783
- };
10784
10757
 
10785
- _proto.persist = function persist() {
10786
- throw new Error('Method not implemented.');
10787
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
10788
- ;
10789
-
10790
- _proto.addEventListener = function addEventListener(type, listener, options) {
10791
- throw new Error('Method not implemented.');
10792
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
10793
- ;
10794
-
10795
- _proto.removeEventListener = function removeEventListener(type, listener, options) {
10796
- throw new Error('Method not implemented.');
10797
- } // eslint-disable-next-line @typescript-eslint/no-unused-vars
10798
- ;
10758
+ var renderable = this.renderable;
10759
+ this.styleValueRegistry.processProperties(this, attributes); // redraw at next frame
10799
10760
 
10800
- _proto.dispatchEvent = function dispatchEvent(event) {
10801
- throw new Error('Method not implemented.');
10761
+ renderable.dirty = true;
10802
10762
  };
10803
10763
 
10804
- // replaceState: AnimationReplaceState;
10805
- _proto.commitStyles = function commitStyles() {
10806
- throw new Error('Method not implemented.');
10807
- };
10764
+ _proto.setAttribute = function setAttribute(name, value, force) {
10765
+ if (force === void 0) {
10766
+ force = false;
10767
+ }
10808
10768
 
10809
- _proto.ensureAlive = function ensureAlive() {
10810
- // If an animation is playing backwards and is not fill backwards/both
10811
- // then it should go out of effect when it reaches the start of its
10812
- // active interval (currentTime === 0).
10813
- if (this.playbackRate < 0 && this.currentTime === 0) {
10814
- var _this$effect2;
10769
+ var _formatAttribute = formatAttribute(name, value),
10770
+ attributeName = _formatAttribute[0],
10771
+ attributeValue = _formatAttribute[1]; // ignore undefined value
10815
10772
 
10816
- this._inEffect = !!((_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.update(-1));
10817
- } else {
10818
- var _this$effect3;
10819
10773
 
10820
- this._inEffect = !!((_this$effect3 = this.effect) === null || _this$effect3 === void 0 ? void 0 : _this$effect3.update(this.currentTime));
10774
+ if (isUndefined(value)) {
10775
+ return;
10821
10776
  }
10822
10777
 
10823
- if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) {
10824
- this._inTimeline = true;
10825
- this.timeline.animations.push(this);
10826
- }
10827
- };
10778
+ if (force || attributeValue !== this.attributes[attributeName]) {
10779
+ this.internalSetAttribute(attributeName, attributeValue);
10828
10780
 
10829
- _proto.tickCurrentTime = function tickCurrentTime(newTime, ignoreLimit) {
10830
- if (newTime !== this._currentTime) {
10831
- this._currentTime = newTime;
10781
+ _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
10782
+ }
10783
+ }
10784
+ /**
10785
+ * called when attributes get changed or initialized
10786
+ */
10787
+ ;
10832
10788
 
10833
- if (this._isFinished && !ignoreLimit) {
10834
- this._currentTime = this._playbackRate > 0 ? this.totalDuration : 0;
10835
- }
10789
+ _proto.internalSetAttribute = function internalSetAttribute(name, value, parseOptions) {
10790
+ var _this$styleValueRegis,
10791
+ _this2 = this;
10836
10792
 
10837
- this.ensureAlive();
10793
+ if (parseOptions === void 0) {
10794
+ parseOptions = {};
10838
10795
  }
10839
- };
10840
10796
 
10841
- _proto.fireEvents = function fireEvents(baseTime) {
10842
- var _this = this;
10797
+ var renderable = this.renderable;
10798
+ var oldValue = this.attributes[name];
10799
+ var oldParsedValue = this.parsedStyle[name];
10800
+ this.styleValueRegistry.processProperties(this, (_this$styleValueRegis = {}, _this$styleValueRegis[name] = value, _this$styleValueRegis), parseOptions); // inform clip path targets
10843
10801
 
10844
- if (this._isFinished) {
10845
- if (!this._finishedFlag) {
10846
- if (this.onfinish) {
10847
- var event = new AnimationEvent(null, this, this.currentTime, baseTime);
10848
- setTimeout(function () {
10849
- if (_this.onfinish) {
10850
- _this.onfinish(event);
10851
- }
10852
- });
10802
+ if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
10803
+ this.parsedStyle.clipPathTargets.forEach(function (target) {
10804
+ _this2.sceneGraphService.dirtifyToRoot(target);
10805
+
10806
+ target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, 'clipPath', MutationEvent.MODIFICATION, _this2, _this2));
10807
+
10808
+ if (target.isCustomElement && target.isConnected) {
10809
+ if (target.attributeChangedCallback) {
10810
+ target.attributeChangedCallback('clipPath', _this2, _this2);
10811
+ }
10853
10812
  }
10813
+ });
10814
+ } // redraw at next frame
10854
10815
 
10855
- this._finishedFlag = true;
10856
- }
10857
- } else {
10858
- if (this.onframe && this.playState === 'running') {
10859
- var _event = new AnimationEvent(null, this, this.currentTime, baseTime);
10860
10816
 
10861
- this.onframe(_event);
10862
- }
10817
+ renderable.dirty = true; // trigger later
10818
+ // this.sceneGraphService.pendingEvents.push([ElementEvent.ATTR_MODIFIED, { affectChildren }]);
10863
10819
 
10864
- this._finishedFlag = false;
10865
- }
10866
- };
10820
+ this.mutationEvent.prevValue = oldValue;
10821
+ this.mutationEvent.newValue = value;
10822
+ this.mutationEvent.attrName = name;
10823
+ this.mutationEvent.prevParsedValue = oldParsedValue;
10824
+ this.mutationEvent.newParsedValue = this.parsedStyle[name];
10825
+ this.dispatchEvent(this.mutationEvent);
10867
10826
 
10868
- _createClass(Animation, [{
10869
- key: "pending",
10870
- get:
10871
- /**
10872
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/effect
10873
- */
10827
+ if (this.isCustomElement && this.isConnected) {
10828
+ if (this.attributeChangedCallback) {
10829
+ this.attributeChangedCallback(name, oldValue, value);
10830
+ }
10831
+ }
10832
+ } // #region transformable
10874
10833
 
10875
- /**
10876
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/timeline
10877
- */
10834
+ /**
10835
+ * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
10836
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
10837
+ *
10838
+ * FIXME: It is worth noting that getBBox responds to original untransformed values of a drawn object.
10839
+ * @see https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox
10840
+ */
10841
+ ;
10878
10842
 
10879
- /**
10880
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/id
10881
- */
10882
- // animation: InternalAnimation | null;
10843
+ _proto.getBBox = function getBBox() {
10844
+ var aabb = this.getBounds();
10883
10845
 
10884
- /**
10885
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending
10886
- */
10887
- function get() {
10888
- return this._startTime === null && !this._paused && this.playbackRate !== 0 || this.currentTimePending;
10889
- }
10890
- }, {
10891
- key: "playState",
10892
- get: function get() {
10893
- if (this._idle) return 'idle';
10894
- if (this._isFinished) return 'finished';
10895
- if (this._paused) return 'paused';
10896
- return 'running';
10897
- }
10898
- /**
10899
- * record previos state
10900
- */
10901
-
10902
- }, {
10903
- key: "ready",
10904
- get:
10905
- /**
10906
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/ready
10907
- * @example
10908
- animation.pause();
10909
- animation.ready.then(function() {
10910
- // Displays 'running'
10911
- alert(animation.playState);
10912
- });
10913
- animation.play();
10914
- */
10915
- function get() {
10916
- var _this2 = this;
10917
-
10918
- if (!this.readyPromise) {
10919
- if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
10920
- this.timeline.animationsWithPromises.push(this);
10921
- }
10922
-
10923
- this.readyPromise = new Promise(function (resolve, reject) {
10924
- _this2.resolveReadyPromise = function () {
10925
- resolve(_this2);
10926
- };
10846
+ var _aabb$getMin = aabb.getMin(),
10847
+ left = _aabb$getMin[0],
10848
+ top = _aabb$getMin[1];
10927
10849
 
10928
- _this2.rejectReadyPromise = function () {
10929
- reject(new Error());
10930
- };
10931
- });
10850
+ var _aabb$getMax = aabb.getMax(),
10851
+ right = _aabb$getMax[0],
10852
+ bottom = _aabb$getMax[1];
10932
10853
 
10933
- if (!this.pending) {
10934
- this.resolveReadyPromise();
10935
- }
10936
- }
10854
+ return new Rectangle(left, top, right - left, bottom - top);
10855
+ };
10937
10856
 
10938
- return this.readyPromise;
10857
+ _proto.setOrigin = function setOrigin(position, y, z) {
10858
+ if (y === void 0) {
10859
+ y = 0;
10939
10860
  }
10940
- /**
10941
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/finished
10942
- * @example
10943
- Promise.all(
10944
- elem.getAnimations().map(
10945
- function(animation) {
10946
- return animation.finished
10947
- }
10948
- )
10949
- ).then(
10950
- function() {
10951
- return elem.remove();
10952
- }
10953
- );
10954
- */
10955
-
10956
- }, {
10957
- key: "finished",
10958
- get: function get() {
10959
- var _this3 = this;
10960
-
10961
- if (!this.finishedPromise) {
10962
- if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
10963
- this.timeline.animationsWithPromises.push(this);
10964
- }
10965
-
10966
- this.finishedPromise = new Promise(function (resolve, reject) {
10967
- _this3.resolveFinishedPromise = function () {
10968
- resolve(_this3);
10969
- };
10970
10861
 
10971
- _this3.rejectFinishedPromise = function () {
10972
- reject(new Error());
10973
- };
10974
- });
10975
-
10976
- if (this.playState === 'finished') {
10977
- this.resolveFinishedPromise();
10978
- }
10979
- }
10980
-
10981
- return this.finishedPromise;
10862
+ if (z === void 0) {
10863
+ z = 0;
10982
10864
  }
10983
- /**
10984
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/onfinish
10985
- */
10986
-
10987
- }, {
10988
- key: "currentTime",
10989
- get:
10990
- /**
10991
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
10992
- */
10993
- function get() {
10994
- this.updatePromises();
10995
- return this._idle || this.currentTimePending ? null : this._currentTime;
10996
- },
10997
- set: function set(newTime) {
10998
- newTime = Number(newTime);
10999
- if (isNaN(newTime)) return;
11000
- this.timeline.restart();
11001
10865
 
11002
- if (!this._paused && this._startTime !== null) {
11003
- var _this$timeline;
11004
-
11005
- this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate;
11006
- }
11007
-
11008
- this.currentTimePending = false;
11009
-
11010
- if (this._currentTime === newTime) {
11011
- return;
11012
- }
10866
+ this.sceneGraphService.setOrigin(this, createVec3(position, y, z));
10867
+ return this;
10868
+ };
11013
10869
 
11014
- if (this._idle) {
11015
- this._idle = false;
11016
- this._paused = true;
11017
- }
10870
+ _proto.getOrigin = function getOrigin() {
10871
+ return this.sceneGraphService.getOrigin(this);
10872
+ }
10873
+ /**
10874
+ * set position in world space
10875
+ */
10876
+ ;
11018
10877
 
11019
- this.tickCurrentTime(newTime, true);
11020
- this.timeline.applyDirtiedAnimation(this);
10878
+ _proto.setPosition = function setPosition(position, y, z) {
10879
+ if (y === void 0) {
10880
+ y = 0;
11021
10881
  }
11022
- /**
11023
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/startTime
11024
- */
11025
10882
 
11026
- }, {
11027
- key: "startTime",
11028
- get: function get() {
11029
- return this._startTime;
11030
- },
11031
- set: function set(newTime) {
11032
- if (newTime !== null) {
11033
- this.updatePromises();
11034
- newTime = Number(newTime);
11035
- if (isNaN(newTime)) return;
11036
- if (this._paused || this._idle) return;
11037
- this._startTime = newTime;
11038
- this.tickCurrentTime((Number(this.timeline.currentTime) - this._startTime) * this.playbackRate);
11039
- this.timeline.applyDirtiedAnimation(this);
11040
- this.updatePromises();
11041
- }
10883
+ if (z === void 0) {
10884
+ z = 0;
11042
10885
  }
11043
- }, {
11044
- key: "playbackRate",
11045
- get: function get() {
11046
- return this._playbackRate;
11047
- },
11048
- set: function set(value) {
11049
- if (value === this._playbackRate) {
11050
- return;
11051
- }
11052
-
11053
- this.updatePromises();
11054
- var oldCurrentTime = this.currentTime;
11055
- this._playbackRate = value;
11056
- this.startTime = null;
11057
-
11058
- if (this.playState !== 'paused' && this.playState !== 'idle') {
11059
- this._finishedFlag = false;
11060
- this._idle = false;
11061
- this.ensureAlive();
11062
- this.timeline.applyDirtiedAnimation(this);
11063
- }
11064
10886
 
11065
- if (oldCurrentTime !== null) {
11066
- this.currentTime = oldCurrentTime;
11067
- }
10887
+ this.sceneGraphService.setPosition(this, createVec3(position, y, z));
10888
+ return this;
10889
+ }
10890
+ /**
10891
+ * set position in local space
10892
+ */
10893
+ ;
11068
10894
 
11069
- this.updatePromises();
11070
- }
11071
- }, {
11072
- key: "_isFinished",
11073
- get: function get() {
11074
- return !this._idle && (this._playbackRate > 0 && Number(this._currentTime) >= this.totalDuration || this._playbackRate < 0 && Number(this._currentTime) <= 0);
10895
+ _proto.setLocalPosition = function setLocalPosition(position, y, z) {
10896
+ if (y === void 0) {
10897
+ y = 0;
11075
10898
  }
11076
- }, {
11077
- key: "totalDuration",
11078
- get: function get() {
11079
- var _this$effect4;
11080
10899
 
11081
- return Number((_this$effect4 = this.effect) === null || _this$effect4 === void 0 ? void 0 : _this$effect4.getComputedTiming().endTime);
11082
- }
11083
- }, {
11084
- key: "_needsTick",
11085
- get: function get() {
11086
- return this.pending || this.playState === 'running' || !this._finishedFlag;
10900
+ if (z === void 0) {
10901
+ z = 0;
11087
10902
  }
11088
- }]);
11089
-
11090
- return Animation;
11091
- }();
11092
-
11093
- function compareAnimations(leftAnimation, rightAnimation) {
11094
- return Number(leftAnimation.id) - Number(rightAnimation.id);
11095
- }
11096
- /**
11097
- * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web-animations-js/index.d.ts
11098
- */
11099
10903
 
11100
- var AnimationTimeline = /*#__PURE__*/function () {
10904
+ this.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
10905
+ return this;
10906
+ }
11101
10907
  /**
11102
- * all active animations
10908
+ * translate in world space
11103
10909
  */
11104
- function AnimationTimeline(document) {
11105
- var _this = this;
11106
-
11107
- this.document = void 0;
11108
- this.animations = [];
11109
- this.ticking = false;
11110
- this.timelineTicking = false;
11111
- this.hasRestartedThisFrame = false;
11112
- this.animationsWithPromises = [];
11113
- this.inTick = false;
11114
- this.pendingEffects = [];
11115
- this.currentTime = null;
11116
- this.rafId = 0;
11117
- this.rafCallbacks = [];
11118
- this.frameId = void 0;
11119
-
11120
- this.webAnimationsNextTick = function (t) {
11121
- _this.currentTime = t;
11122
-
11123
- _this.discardAnimations();
11124
-
11125
- if (_this.animations.length === 0) {
11126
- _this.timelineTicking = false;
11127
- } else {
11128
- _this.requestAnimationFrame(_this.webAnimationsNextTick);
11129
- }
11130
- };
11131
-
11132
- this.processRafCallbacks = function (t) {
11133
- var processing = _this.rafCallbacks;
11134
- _this.rafCallbacks = [];
11135
- if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
11136
-
11137
- _this.animations.sort(compareAnimations);
10910
+ ;
11138
10911
 
11139
- _this.animations = _this.tick(t, true, _this.animations)[0];
11140
- processing.forEach(function (entry) {
11141
- entry[1](t);
11142
- });
10912
+ _proto.translate = function translate(position, y, z) {
10913
+ if (y === void 0) {
10914
+ y = 0;
10915
+ }
11143
10916
 
11144
- _this.applyPendingEffects();
11145
- };
10917
+ if (z === void 0) {
10918
+ z = 0;
10919
+ }
11146
10920
 
11147
- this.document = document;
10921
+ this.sceneGraphService.translate(this, createVec3(position, y, z));
10922
+ return this;
11148
10923
  }
11149
-
11150
- var _proto = AnimationTimeline.prototype;
11151
-
11152
- _proto.getAnimations = function getAnimations() {
11153
- this.discardAnimations();
11154
- return this.animations.slice();
11155
- };
11156
-
11157
- _proto.isTicking = function isTicking() {
11158
- return this.inTick;
11159
- };
11160
-
11161
- _proto.play = function play(effect) {
11162
- var animation = new Animation(effect, this);
11163
- this.animations.push(animation);
11164
- this.restartWebAnimationsNextTick();
11165
- animation.updatePromises();
11166
- animation.play();
11167
- animation.updatePromises();
11168
- return animation;
11169
- } // RAF is supposed to be the last script to occur before frame rendering but not
11170
- // all browsers behave like this. This function is for synchonously updating an
11171
- // animation's effects whenever its state is mutated by script to work around
11172
- // incorrect script execution ordering by the browser.
10924
+ /**
10925
+ * translate in local space
10926
+ */
11173
10927
  ;
11174
10928
 
11175
- _proto.applyDirtiedAnimation = function applyDirtiedAnimation(animation) {
11176
- var _this2 = this;
11177
-
11178
- if (this.inTick) {
11179
- return;
11180
- } // update active animations in displayobject
11181
-
11182
-
11183
- animation.markTarget();
11184
- var animations = animation.targetAnimations();
11185
- animations.sort(compareAnimations); // clear inactive animations
11186
-
11187
- var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1];
11188
- inactiveAnimations.forEach(function (animation) {
11189
- var index = _this2.animations.indexOf(animation);
11190
-
11191
- if (index !== -1) {
11192
- _this2.animations.splice(index, 1);
11193
- }
11194
- });
11195
- this.applyPendingEffects();
11196
- };
11197
-
11198
- _proto.restart = function restart() {
11199
- if (!this.ticking) {
11200
- this.ticking = true;
11201
- this.requestAnimationFrame(function () {});
11202
- this.hasRestartedThisFrame = true;
10929
+ _proto.translateLocal = function translateLocal(position, y, z) {
10930
+ if (y === void 0) {
10931
+ y = 0;
11203
10932
  }
11204
10933
 
11205
- return this.hasRestartedThisFrame;
11206
- };
11207
-
11208
- _proto.destroy = function destroy() {
11209
- this.document.defaultView.cancelAnimationFrame(this.frameId);
11210
- };
10934
+ if (z === void 0) {
10935
+ z = 0;
10936
+ }
11211
10937
 
11212
- _proto.applyPendingEffects = function applyPendingEffects() {
11213
- this.pendingEffects.forEach(function (effect) {
11214
- effect === null || effect === void 0 ? void 0 : effect.applyInterpolations();
11215
- });
11216
- this.pendingEffects = [];
10938
+ this.sceneGraphService.translateLocal(this, createVec3(position, y, z));
10939
+ return this;
11217
10940
  };
11218
10941
 
11219
- _proto.updateAnimationsPromises = function updateAnimationsPromises() {
11220
- this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) {
11221
- return animation.updatePromises();
11222
- });
10942
+ _proto.getPosition = function getPosition() {
10943
+ return this.sceneGraphService.getPosition(this);
11223
10944
  };
11224
10945
 
11225
- _proto.discardAnimations = function discardAnimations() {
11226
- this.updateAnimationsPromises();
11227
- this.animations = this.animations.filter(function (animation) {
11228
- return animation.playState !== 'finished' && animation.playState !== 'idle';
11229
- });
11230
- };
10946
+ _proto.getLocalPosition = function getLocalPosition() {
10947
+ return this.sceneGraphService.getLocalPosition(this);
10948
+ }
10949
+ /**
10950
+ * compatible with G 3.0
10951
+ *
10952
+ * scaling in local space
10953
+ * scale(10) = scale(10, 10, 10)
10954
+ *
10955
+ * we can't set scale in world space
10956
+ */
10957
+ ;
11231
10958
 
11232
- _proto.restartWebAnimationsNextTick = function restartWebAnimationsNextTick() {
11233
- if (!this.timelineTicking) {
11234
- this.timelineTicking = true;
11235
- this.requestAnimationFrame(this.webAnimationsNextTick);
11236
- }
10959
+ _proto.scale = function scale(scaling, y, z) {
10960
+ return this.scaleLocal(scaling, y, z);
11237
10961
  };
11238
10962
 
11239
- _proto.rAF = function rAF(f) {
11240
- var id = this.rafId++;
11241
-
11242
- if (this.rafCallbacks.length === 0) {
11243
- this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks);
10963
+ _proto.scaleLocal = function scaleLocal(scaling, y, z) {
10964
+ if (typeof scaling === 'number') {
10965
+ y = y || scaling;
10966
+ z = z || scaling;
10967
+ scaling = createVec3(scaling, y, z);
11244
10968
  }
11245
10969
 
11246
- this.rafCallbacks.push([id, f]);
11247
- return id;
11248
- };
10970
+ this.sceneGraphService.scaleLocal(this, scaling);
10971
+ return this;
10972
+ }
10973
+ /**
10974
+ * set scaling in local space
10975
+ */
10976
+ ;
11249
10977
 
11250
- _proto.requestAnimationFrame = function requestAnimationFrame(f) {
11251
- var _this3 = this;
10978
+ _proto.setLocalScale = function setLocalScale(scaling, y, z) {
10979
+ if (typeof scaling === 'number') {
10980
+ y = y || scaling;
10981
+ z = z || scaling;
10982
+ scaling = createVec3(scaling, y, z);
10983
+ }
11252
10984
 
11253
- return this.rAF(function (x) {
11254
- _this3.updateAnimationsPromises();
10985
+ this.sceneGraphService.setLocalScale(this, scaling);
10986
+ return this;
10987
+ }
10988
+ /**
10989
+ * get scaling in local space
10990
+ */
10991
+ ;
11255
10992
 
11256
- f(x);
10993
+ _proto.getLocalScale = function getLocalScale() {
10994
+ return this.sceneGraphService.getLocalScale(this);
10995
+ }
10996
+ /**
10997
+ * get scaling in world space
10998
+ */
10999
+ ;
11257
11000
 
11258
- _this3.updateAnimationsPromises();
11259
- });
11260
- };
11001
+ _proto.getScale = function getScale() {
11002
+ return this.sceneGraphService.getScale(this);
11003
+ }
11004
+ /**
11005
+ * only return degrees of Z axis in world space
11006
+ */
11007
+ ;
11261
11008
 
11262
- _proto.tick = function tick(t, isAnimationFrame, updatingAnimations) {
11263
- var _this4 = this,
11264
- _this$pendingEffects,
11265
- _this$pendingEffects2;
11009
+ _proto.getEulerAngles = function getEulerAngles() {
11010
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11011
+ var _getEuler = getEuler(glMatrix.vec3.create(), this.sceneGraphService.getWorldTransform(this)),
11012
+ ex = _getEuler[0],
11013
+ ey = _getEuler[1],
11014
+ ez = _getEuler[2];
11266
11015
 
11267
- this.inTick = true;
11268
- this.hasRestartedThisFrame = false;
11269
- this.currentTime = t;
11270
- this.ticking = false;
11271
- var newPendingClears = [];
11272
- var newPendingEffects = [];
11273
- var activeAnimations = [];
11274
- var inactiveAnimations = [];
11275
- updatingAnimations.forEach(function (animation) {
11276
- animation.tick(t, isAnimationFrame);
11016
+ return rad2deg(ez);
11017
+ }
11018
+ /**
11019
+ * only return degrees of Z axis in local space
11020
+ */
11021
+ ;
11277
11022
 
11278
- if (!animation._inEffect) {
11279
- newPendingClears.push(animation.effect);
11280
- animation.unmarkTarget();
11281
- } else {
11282
- newPendingEffects.push(animation.effect);
11283
- animation.markTarget();
11284
- }
11023
+ _proto.getLocalEulerAngles = function getLocalEulerAngles() {
11024
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11025
+ var _getEuler2 = getEuler(glMatrix.vec3.create(), this.sceneGraphService.getLocalRotation(this)),
11026
+ ex = _getEuler2[0],
11027
+ ey = _getEuler2[1],
11028
+ ez = _getEuler2[2];
11285
11029
 
11286
- if (animation._needsTick) _this4.ticking = true;
11287
- var alive = animation._inEffect || animation._needsTick;
11288
- animation._inTimeline = alive;
11030
+ return rad2deg(ez);
11031
+ }
11032
+ /**
11033
+ * set euler angles(degrees) in world space
11034
+ */
11035
+ ;
11289
11036
 
11290
- if (alive) {
11291
- activeAnimations.push(animation);
11292
- } else {
11293
- inactiveAnimations.push(animation);
11294
- }
11295
- });
11037
+ _proto.setEulerAngles = function setEulerAngles(z) {
11038
+ this.sceneGraphService.setEulerAngles(this, 0, 0, z);
11039
+ return this;
11040
+ }
11041
+ /**
11042
+ * set euler angles(degrees) in local space
11043
+ */
11044
+ ;
11296
11045
 
11297
- (_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears);
11046
+ _proto.setLocalEulerAngles = function setLocalEulerAngles(z) {
11047
+ this.sceneGraphService.setLocalEulerAngles(this, 0, 0, z);
11048
+ return this;
11049
+ };
11298
11050
 
11299
- (_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects);
11051
+ _proto.rotateLocal = function rotateLocal(x, y, z) {
11052
+ if (isNil(y) && isNil(z)) {
11053
+ this.sceneGraphService.rotateLocal(this, 0, 0, x);
11054
+ } else {
11055
+ this.sceneGraphService.rotateLocal(this, x, y, z);
11056
+ }
11300
11057
 
11301
- if (this.ticking) this.requestAnimationFrame(function () {});
11302
- this.inTick = false;
11303
- return [activeAnimations, inactiveAnimations];
11058
+ return this;
11304
11059
  };
11305
11060
 
11306
- return AnimationTimeline;
11307
- }();
11308
-
11309
- exports.DisplayObjectPool = /*#__PURE__*/function () {
11310
- function DisplayObjectPool() {
11311
- this.pool = {};
11312
- this.htmlPool = [];
11313
- }
11061
+ _proto.rotate = function rotate(x, y, z) {
11062
+ if (isNil(y) && isNil(z)) {
11063
+ this.sceneGraphService.rotate(this, 0, 0, x);
11064
+ } else {
11065
+ this.sceneGraphService.rotate(this, x, y, z);
11066
+ }
11314
11067
 
11315
- var _proto = DisplayObjectPool.prototype;
11068
+ return this;
11069
+ };
11316
11070
 
11317
- _proto.getByEntity = function getByEntity(entity) {
11318
- return this.pool[entity];
11071
+ _proto.setRotation = function setRotation(rotation, y, z, w) {
11072
+ this.sceneGraphService.setRotation(this, rotation, y, z, w);
11073
+ return this;
11319
11074
  };
11320
11075
 
11321
- _proto.add = function add(entity, groupOrShape) {
11322
- this.pool[entity] = groupOrShape;
11076
+ _proto.setLocalRotation = function setLocalRotation(rotation, y, z, w) {
11077
+ this.sceneGraphService.setLocalRotation(this, rotation, y, z, w);
11078
+ return this;
11079
+ };
11323
11080
 
11324
- if (groupOrShape.nodeName === exports.Shape.HTML) {
11325
- this.htmlPool.push(groupOrShape);
11326
- }
11081
+ _proto.setLocalSkew = function setLocalSkew(skew, y) {
11082
+ this.sceneGraphService.setLocalSkew(this, skew, y);
11083
+ return this;
11327
11084
  };
11328
11085
 
11329
- _proto.remove = function remove(entity) {
11330
- var existed = this.pool[entity];
11331
- delete this.pool[entity];
11086
+ _proto.getRotation = function getRotation() {
11087
+ return this.sceneGraphService.getRotation(this);
11088
+ };
11332
11089
 
11333
- if (existed.nodeName === exports.Shape.HTML) {
11334
- var index = this.htmlPool.indexOf(existed);
11335
- this.htmlPool.splice(index, 1);
11336
- }
11090
+ _proto.getLocalRotation = function getLocalRotation() {
11091
+ return this.sceneGraphService.getLocalRotation(this);
11337
11092
  };
11338
11093
 
11339
- _proto.getHTMLs = function getHTMLs() {
11340
- return this.htmlPool;
11094
+ _proto.getLocalSkew = function getLocalSkew() {
11095
+ return this.sceneGraphService.getLocalSkew(this);
11341
11096
  };
11342
11097
 
11343
- return DisplayObjectPool;
11344
- }();
11098
+ _proto.getLocalTransform = function getLocalTransform() {
11099
+ return this.sceneGraphService.getLocalTransform(this);
11100
+ };
11345
11101
 
11346
- exports.DisplayObjectPool = tslib.__decorate([manaSyringe.singleton()], exports.DisplayObjectPool);
11102
+ _proto.getWorldTransform = function getWorldTransform() {
11103
+ return this.sceneGraphService.getWorldTransform(this);
11104
+ };
11347
11105
 
11348
- var DEFAULT_STYLE_PROPS = {
11349
- anchor: '',
11350
- opacity: '',
11351
- fillOpacity: '',
11352
- strokeOpacity: '',
11353
- fill: '',
11354
- stroke: '',
11355
- transform: '',
11356
- transformOrigin: '',
11357
- visibility: '',
11358
- pointerEvents: '',
11359
- lineWidth: '',
11360
- lineCap: '',
11361
- lineJoin: '',
11362
- increasedLineWidthForHitTesting: '',
11363
- fontSize: '',
11364
- fontFamily: '',
11365
- fontStyle: '',
11366
- fontWeight: '',
11367
- fontVariant: '',
11368
- textAlign: '',
11369
- textBaseline: '',
11370
- textTransform: '',
11371
- zIndex: '',
11372
- filter: ''
11373
- };
11374
- /**
11375
- * prototype chains: DisplayObject -> Element -> Node -> EventTarget
11376
- *
11377
- * mixins: Animatable, Transformable, Visible
11378
- * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes
11379
- *
11380
- * Provide abilities in scene graph, such as:
11381
- * * transform `translate/rotate/scale`
11382
- * * add/remove child
11383
- * * visibility and z-index
11384
- *
11385
- * Those abilities are implemented with those components: `Transform/Sortable/Visible`.
11386
- *
11387
- * Emit following events:
11388
- * * init
11389
- * * destroy
11390
- * * attributeChanged
11391
- */
11106
+ _proto.setLocalTransform = function setLocalTransform(transform) {
11107
+ this.sceneGraphService.setLocalTransform(this, transform);
11108
+ return this;
11109
+ };
11392
11110
 
11393
- var DisplayObject = /*#__PURE__*/function (_Element) {
11394
- _inheritsLoose(DisplayObject, _Element);
11111
+ _proto.resetLocalTransform = function resetLocalTransform() {
11112
+ this.sceneGraphService.resetLocalTransform(this);
11113
+ } // #endregion transformable
11114
+ // #region animatable
11395
11115
 
11396
11116
  /**
11397
- * contains style props in constructor's params, eg. fill, stroke...
11117
+ * returns an array of all Animation objects affecting this element
11118
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
11398
11119
  */
11120
+ ;
11399
11121
 
11122
+ _proto.getAnimations = function getAnimations() {
11123
+ return this.activeAnimations;
11124
+ }
11400
11125
  /**
11401
- * push to active animations after calling `animate()`
11126
+ * create an animation with WAAPI
11127
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
11402
11128
  */
11403
- function DisplayObject(config) {
11404
- var _this$config$capture;
11129
+ ;
11405
11130
 
11406
- var _this;
11131
+ _proto.animate = function animate(keyframes, options) {
11132
+ var _this$ownerDocument;
11407
11133
 
11408
- _this = _Element.call(this) || this; // assign name, id to config
11409
- // eg. group.get('name')
11134
+ var timeline = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.timeline; // account for clip path, use target's timeline
11410
11135
 
11411
- _this.config = void 0;
11412
- _this.styleValueRegistry = manaSyringe.GlobalContainer.get(StyleValueRegistry);
11413
- _this.isCustomElement = false;
11414
- _this.activeAnimations = [];
11415
- _this.mutationEvent = new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, _assertThisInitialized(_this), null, null, null, MutationEvent.MODIFICATION, null, null);
11416
- _this.config = config; // compatible with G 3.0
11136
+ if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
11137
+ var _target$ownerDocument;
11417
11138
 
11418
- _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
11139
+ var target = this.parsedStyle.clipPathTargets[0];
11140
+ timeline = (_target$ownerDocument = target.ownerDocument) === null || _target$ownerDocument === void 0 ? void 0 : _target$ownerDocument.timeline;
11141
+ } // clear old parsed transform
11419
11142
 
11420
- _this.id = _this.config.id || '';
11421
- _this.name = _this.config.name || '';
11422
11143
 
11423
- if (_this.config.className || _this.config.class) {
11424
- _this.className = _this.config.className || _this.config.class;
11144
+ delete this.parsedStyle.transform;
11145
+
11146
+ if (timeline) {
11147
+ return timeline.play(new KeyframeEffect(this, keyframes, options));
11425
11148
  }
11426
11149
 
11427
- _this.nodeName = _this.config.type || exports.Shape.GROUP; // compatible with G 3.0
11150
+ return null;
11151
+ } // #endregion animatable
11152
+ // #region visible
11428
11153
 
11429
- _this.config.style = _extends({}, DEFAULT_STYLE_PROPS, _this.config.style, _this.config.attrs);
11154
+ /**
11155
+ * show group, which will also change visibility of its children in sceneGraphNode
11156
+ *
11157
+ * @deprecated
11158
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility
11159
+ */
11160
+ ;
11430
11161
 
11431
- if (_this.config.visible != null) {
11432
- _this.config.style.visibility = _this.config.visible === false ? 'hidden' : 'visible';
11433
- }
11162
+ _proto.show = function show() {
11163
+ this.style.visibility = 'visible';
11164
+ }
11165
+ /**
11166
+ * @deprecated
11167
+ * hide group, which will also change visibility of its children in sceneGraphNode
11168
+ */
11169
+ ;
11434
11170
 
11435
- if (_this.config.interactive != null) {
11436
- _this.config.style.pointerEvents = _this.config.interactive === false ? 'none' : 'auto';
11171
+ _proto.hide = function hide() {
11172
+ this.style.visibility = 'hidden';
11173
+ }
11174
+ /**
11175
+ * shortcut for Used value of `visibility`
11176
+ */
11177
+ ;
11178
+
11179
+ _proto.isVisible = function isVisible() {
11180
+ var _this$parsedStyle, _this$parsedStyle$vis;
11181
+
11182
+ return ((_this$parsedStyle = this.parsedStyle) === null || _this$parsedStyle === void 0 ? void 0 : (_this$parsedStyle$vis = _this$parsedStyle.visibility) === null || _this$parsedStyle$vis === void 0 ? void 0 : _this$parsedStyle$vis.value) === 'visible';
11183
+ };
11184
+
11185
+ _proto.isInteractive = function isInteractive() {
11186
+ var _this$parsedStyle2, _this$parsedStyle2$po;
11187
+
11188
+ return ((_this$parsedStyle2 = this.parsedStyle) === null || _this$parsedStyle2 === void 0 ? void 0 : (_this$parsedStyle2$po = _this$parsedStyle2.pointerEvents) === null || _this$parsedStyle2$po === void 0 ? void 0 : _this$parsedStyle2$po.value) !== 'none';
11189
+ };
11190
+
11191
+ _proto.isCulled = function isCulled() {
11192
+ return !!(this.cullable && this.cullable.isCulled());
11193
+ }
11194
+ /**
11195
+ * bring to front in current group
11196
+ */
11197
+ ;
11198
+
11199
+ _proto.toFront = function toFront() {
11200
+ if (this.parentNode) {
11201
+ this.style.zIndex = Math.max.apply(Math, this.parentNode.children.map(function (child) {
11202
+ return Number(child.style.zIndex);
11203
+ })) + 1;
11437
11204
  }
11438
11205
 
11439
- _this.style = new Proxy(_extends({}, _this.attributes, {
11440
- setProperty: function setProperty(propertyName, value) {
11441
- _this.setAttribute(propertyName, value);
11442
- },
11443
- getPropertyValue: function getPropertyValue(propertyName) {
11444
- return _this.getAttribute(propertyName);
11445
- },
11446
- removeProperty: function removeProperty(propertyName) {
11447
- _this.removeAttribute(propertyName);
11448
- },
11449
- item: function item() {
11450
- return '';
11451
- }
11452
- }), {
11453
- get: function get(target, name) {
11454
- if (target[name] !== undefined) {
11455
- // if (name in target) {
11456
- return target[name];
11457
- }
11206
+ return this;
11207
+ }
11208
+ /**
11209
+ * send to back in current group
11210
+ */
11211
+ ;
11458
11212
 
11459
- return _this.getAttribute(name);
11460
- },
11461
- set: function set(_, prop, value) {
11462
- _this.setAttribute(prop, value);
11213
+ _proto.toBack = function toBack() {
11214
+ if (this.parentNode) {
11215
+ this.style.zIndex = Math.min.apply(Math, this.parentNode.children.map(function (child) {
11216
+ return Number(child.style.zIndex);
11217
+ })) - 1;
11218
+ }
11463
11219
 
11464
- return true;
11465
- }
11466
- });
11220
+ return this;
11221
+ } // #endregion visible
11222
+ // #region deprecated
11467
11223
 
11468
- _this.initAttributes(_this.config.style); // insert this group into pool
11224
+ /**
11225
+ * @deprecated
11226
+ * compatible with G 3.0
11227
+ * @deprecated
11228
+ */
11229
+ ;
11469
11230
 
11231
+ _proto.getCount = function getCount() {
11232
+ return this.childElementCount;
11233
+ }
11234
+ /**
11235
+ * @deprecated
11236
+ * compatible with G 3.0
11237
+ * @deprecated
11238
+ */
11239
+ ;
11470
11240
 
11471
- manaSyringe.GlobalContainer.get(exports.DisplayObjectPool).add(_this.entity, _assertThisInitialized(_this));
11472
- return _this;
11241
+ _proto.getParent = function getParent() {
11242
+ return this.parentElement;
11473
11243
  }
11244
+ /**
11245
+ * @deprecated
11246
+ * compatible with G 3.0
11247
+ * @deprecated
11248
+ */
11249
+ ;
11474
11250
 
11475
- var _proto = DisplayObject.prototype;
11251
+ _proto.getChildren = function getChildren() {
11252
+ return this.children;
11253
+ }
11254
+ /**
11255
+ * @deprecated
11256
+ * compatible with G 3.0
11257
+ * @deprecated
11258
+ */
11259
+ ;
11476
11260
 
11477
- _proto.destroy = function destroy() {
11478
- _Element.prototype.destroy.call(this); // remove from into pool
11261
+ _proto.getFirst = function getFirst() {
11262
+ return this.firstElementChild;
11263
+ }
11264
+ /**
11265
+ * @deprecated
11266
+ * compatible with G 3.0
11267
+ * @deprecated
11268
+ * get last child group/shape
11269
+ */
11270
+ ;
11479
11271
 
11272
+ _proto.getLast = function getLast() {
11273
+ return this.lastElementChild;
11274
+ }
11275
+ /**
11276
+ * @deprecated
11277
+ * compatible with G 3.0
11278
+ * @deprecated
11279
+ * get child group/shape by index
11280
+ */
11281
+ ;
11480
11282
 
11481
- manaSyringe.GlobalContainer.get(exports.DisplayObjectPool).remove(this.entity); // stop all active animations
11283
+ _proto.getChildByIndex = function getChildByIndex(index) {
11284
+ return this.children[index] || null;
11285
+ }
11286
+ /**
11287
+ * compatible with G 3.0
11288
+ * @deprecated
11289
+ */
11290
+ ;
11482
11291
 
11483
- this.getAnimations().forEach(function (animation) {
11484
- animation.cancel();
11485
- });
11486
- };
11292
+ _proto.add = function add(child, index) {
11293
+ return this.appendChild(child, index);
11294
+ }
11295
+ /**
11296
+ * @alias style.clipPath
11297
+ * @deprecated
11298
+ */
11299
+ ;
11487
11300
 
11488
- _proto.cloneNode = function cloneNode(deep) {
11489
- var cloned = new this.constructor({
11490
- // copy id & name
11491
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
11492
- id: this.id,
11493
- name: this.name,
11494
- className: this.name,
11495
- interactive: this.interactive,
11496
- style: _extends({}, this.attributes)
11497
- }); // apply transform
11301
+ _proto.setClip = function setClip(clipPath) {
11302
+ this.style.clipPath = clipPath;
11303
+ }
11304
+ /**
11305
+ * @alias style.clipPath
11306
+ * @deprecated
11307
+ */
11308
+ ;
11498
11309
 
11499
- cloned.setLocalTransform(this.getLocalTransform());
11310
+ _proto.getClip = function getClip() {
11311
+ return this.style.clipPath || null;
11312
+ }
11313
+ /**
11314
+ * compatible with G 3.0
11315
+ * @deprecated
11316
+ */
11317
+ ;
11500
11318
 
11501
- if (deep) {
11502
- this.children.forEach(function (child) {
11503
- var clonedChild = child.cloneNode(deep);
11504
- cloned.appendChild(clonedChild);
11505
- });
11506
- }
11319
+ _proto.set = function set(name, value) {
11320
+ this.config[name] = value;
11321
+ }
11322
+ /**
11323
+ * compatible with G 3.0
11324
+ * @deprecated
11325
+ */
11326
+ ;
11507
11327
 
11508
- return cloned;
11328
+ _proto.get = function get(name) {
11329
+ return this.config[name];
11330
+ }
11331
+ /**
11332
+ * compatible with G 3.0
11333
+ * @alias object.config
11334
+ * @deprecated
11335
+ */
11336
+ ;
11337
+
11338
+ _proto.getConfig = function getConfig() {
11339
+ return this.config;
11509
11340
  };
11510
11341
 
11511
- _proto.initAttributes = function initAttributes(attributes) {
11512
- if (attributes === void 0) {
11513
- attributes = {};
11342
+ _proto.attr = function attr() {
11343
+ var _this3 = this;
11344
+
11345
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11346
+ args[_key] = arguments[_key];
11514
11347
  }
11515
11348
 
11516
- var renderable = this.renderable;
11517
- this.styleValueRegistry.processProperties(this, attributes); // redraw at next frame
11349
+ var name = args[0],
11350
+ value = args[1];
11518
11351
 
11519
- renderable.dirty = true;
11520
- };
11352
+ if (!name) {
11353
+ return this.attributes;
11354
+ }
11521
11355
 
11522
- _proto.setAttribute = function setAttribute(name, value, force) {
11523
- if (force === void 0) {
11524
- force = false;
11356
+ if (isObject(name)) {
11357
+ Object.keys(name).forEach(function (key) {
11358
+ _this3.setAttribute(key, name[key]);
11359
+ });
11360
+ return this;
11525
11361
  }
11526
11362
 
11527
- var _formatAttribute = formatAttribute(name, value),
11528
- attributeName = _formatAttribute[0],
11529
- attributeValue = _formatAttribute[1]; // ignore undefined value
11363
+ if (args.length === 2) {
11364
+ this.setAttribute(name, value);
11365
+ return this;
11366
+ }
11530
11367
 
11368
+ return this.attributes[name];
11369
+ }
11370
+ /**
11371
+ * @alias setPosition
11372
+ * @deprecated
11373
+ */
11374
+ ;
11531
11375
 
11532
- if (isUndefined(value)) {
11533
- return;
11376
+ _proto.moveTo = function moveTo(position, y, z) {
11377
+ if (y === void 0) {
11378
+ y = 0;
11534
11379
  }
11535
11380
 
11536
- if (force || attributeValue !== this.attributes[attributeName]) {
11537
- this.internalSetAttribute(attributeName, attributeValue);
11538
-
11539
- _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
11381
+ if (z === void 0) {
11382
+ z = 0;
11540
11383
  }
11384
+
11385
+ this.setPosition(position, y, z);
11386
+ return this;
11541
11387
  }
11542
11388
  /**
11543
- * called when attributes get changed or initialized
11389
+ * @alias setPosition
11390
+ * @deprecated
11544
11391
  */
11545
11392
  ;
11546
11393
 
11547
- _proto.internalSetAttribute = function internalSetAttribute(name, value, parseOptions) {
11548
- var _this$styleValueRegis,
11549
- _this2 = this;
11394
+ _proto.move = function move(position, y, z) {
11395
+ if (y === void 0) {
11396
+ y = 0;
11397
+ }
11550
11398
 
11551
- if (parseOptions === void 0) {
11552
- parseOptions = {};
11399
+ if (z === void 0) {
11400
+ z = 0;
11553
11401
  }
11554
11402
 
11555
- var renderable = this.renderable;
11556
- var oldValue = this.attributes[name];
11557
- var oldParsedValue = this.parsedStyle[name];
11558
- this.styleValueRegistry.processProperties(this, (_this$styleValueRegis = {}, _this$styleValueRegis[name] = value, _this$styleValueRegis), parseOptions); // inform clip path targets
11403
+ this.setPosition(position, y, z);
11404
+ return this;
11405
+ }
11406
+ /**
11407
+ * @alias style.zIndex
11408
+ * @deprecated
11409
+ */
11410
+ ;
11559
11411
 
11560
- if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
11561
- this.parsedStyle.clipPathTargets.forEach(function (target) {
11562
- _this2.sceneGraphService.dirtifyToRoot(target);
11412
+ _proto.setZIndex = function setZIndex(zIndex) {
11413
+ this.style.zIndex = zIndex;
11414
+ return this;
11415
+ }
11416
+ /**
11417
+ * return 3x3 matrix in world space
11418
+ * @deprecated
11419
+ */
11420
+ ;
11563
11421
 
11564
- target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, 'clipPath', MutationEvent.MODIFICATION, _this2, _this2));
11422
+ _proto.getMatrix = function getMatrix(transformMat4) {
11423
+ var transform = transformMat4 || this.getWorldTransform();
11565
11424
 
11566
- if (target.isCustomElement && target.isConnected) {
11567
- if (target.attributeChangedCallback) {
11568
- target.attributeChangedCallback('clipPath', _this2, _this2);
11569
- }
11570
- }
11571
- });
11572
- } // redraw at next frame
11425
+ var _mat4$getTranslation = glMatrix.mat4.getTranslation(glMatrix.vec3.create(), transform),
11426
+ tx = _mat4$getTranslation[0],
11427
+ ty = _mat4$getTranslation[1];
11573
11428
 
11429
+ var _mat4$getScaling = glMatrix.mat4.getScaling(glMatrix.vec3.create(), transform),
11430
+ sx = _mat4$getScaling[0],
11431
+ sy = _mat4$getScaling[1];
11574
11432
 
11575
- renderable.dirty = true; // trigger later
11576
- // this.sceneGraphService.pendingEvents.push([ElementEvent.ATTR_MODIFIED, { affectChildren }]);
11433
+ var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
11577
11434
 
11578
- this.mutationEvent.prevValue = oldValue;
11579
- this.mutationEvent.newValue = value;
11580
- this.mutationEvent.attrName = name;
11581
- this.mutationEvent.prevParsedValue = oldParsedValue;
11582
- this.mutationEvent.newParsedValue = this.parsedStyle[name];
11583
- this.dispatchEvent(this.mutationEvent);
11435
+ var _getEuler3 = getEuler(glMatrix.vec3.create(), rotation),
11436
+ eux = _getEuler3[0],
11437
+ euy = _getEuler3[1],
11438
+ euz = _getEuler3[2]; // gimbal lock at 90 degrees
11584
11439
 
11585
- if (this.isCustomElement && this.isConnected) {
11586
- if (this.attributeChangedCallback) {
11587
- this.attributeChangedCallback(name, oldValue, value);
11588
- }
11589
- }
11590
- } // #region transformable
11591
11440
 
11441
+ return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
11442
+ }
11592
11443
  /**
11593
- * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
11594
- * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
11595
- *
11596
- * FIXME: It is worth noting that getBBox responds to original untransformed values of a drawn object.
11597
- * @see https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox
11444
+ * return 3x3 matrix in local space
11445
+ * @deprecated
11598
11446
  */
11599
11447
  ;
11600
11448
 
11601
- _proto.getBBox = function getBBox() {
11602
- var aabb = this.getBounds();
11449
+ _proto.getLocalMatrix = function getLocalMatrix() {
11450
+ return this.getMatrix(this.getLocalTransform());
11451
+ }
11452
+ /**
11453
+ * set 3x3 matrix in world space
11454
+ * @deprecated
11455
+ */
11456
+ ;
11603
11457
 
11604
- var _aabb$getMin = aabb.getMin(),
11605
- left = _aabb$getMin[0],
11606
- top = _aabb$getMin[1];
11458
+ _proto.setMatrix = function setMatrix(mat) {
11459
+ var _decompose = decompose(mat),
11460
+ tx = _decompose[0],
11461
+ ty = _decompose[1],
11462
+ scalingX = _decompose[2],
11463
+ scalingY = _decompose[3],
11464
+ angle = _decompose[4];
11607
11465
 
11608
- var _aabb$getMax = aabb.getMax(),
11609
- right = _aabb$getMax[0],
11610
- bottom = _aabb$getMax[1];
11466
+ this.setEulerAngles(angle).setPosition(tx, ty).setLocalScale(scalingX, scalingY);
11467
+ }
11468
+ /**
11469
+ * set 3x3 matrix in local space
11470
+ * @deprecated
11471
+ */
11472
+ ;
11611
11473
 
11612
- return new Rectangle(left, top, right - left, bottom - top);
11474
+ _proto.setLocalMatrix = function setLocalMatrix(mat) {
11475
+ var _decompose2 = decompose(mat),
11476
+ tx = _decompose2[0],
11477
+ ty = _decompose2[1],
11478
+ scalingX = _decompose2[2],
11479
+ scalingY = _decompose2[3],
11480
+ angle = _decompose2[4];
11481
+
11482
+ this.setLocalEulerAngles(angle).setLocalPosition(tx, ty).setLocalScale(scalingX, scalingY);
11613
11483
  };
11614
11484
 
11615
- _proto.setOrigin = function setOrigin(position, y, z) {
11616
- if (y === void 0) {
11617
- y = 0;
11485
+ _createClass(DisplayObject, [{
11486
+ key: "interactive",
11487
+ get: function get() {
11488
+ return this.isInteractive();
11489
+ },
11490
+ set: function set(b) {
11491
+ this.style.pointerEvents = b ? 'auto' : 'none';
11618
11492
  }
11493
+ }]);
11494
+
11495
+ return DisplayObject;
11496
+ }(Element);
11497
+
11498
+ var _excluded = ["style"];
11499
+ /**
11500
+ * shadow root
11501
+ * @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
11502
+ */
11503
+
11504
+ var CustomElement = /*#__PURE__*/function (_DisplayObject) {
11505
+ _inheritsLoose(CustomElement, _DisplayObject);
11506
+
11507
+ // static get observedAttributes(): string[] {
11508
+ // return [];
11509
+ // }
11510
+ // private shadowNodes: DisplayObject[] = [];
11511
+ function CustomElement(_temp) {
11512
+ var _this;
11513
+
11514
+ var _ref = _temp === void 0 ? {} : _temp,
11515
+ style = _ref.style,
11516
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
11517
+
11518
+ _this = _DisplayObject.call(this, _extends({
11519
+ style: _extends({
11520
+ x: '',
11521
+ y: ''
11522
+ }, style)
11523
+ }, rest)) || this;
11524
+ _this.isCustomElement = true;
11525
+ return _this;
11526
+ }
11527
+
11528
+ return CustomElement;
11529
+ }(DisplayObject);
11530
+
11531
+ var _excluded$1 = ["style"];
11532
+ var Circle = /*#__PURE__*/function (_DisplayObject) {
11533
+ _inheritsLoose(Circle, _DisplayObject);
11534
+
11535
+ function Circle(_temp) {
11536
+ var _ref = _temp === void 0 ? {} : _temp,
11537
+ style = _ref.style,
11538
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
11539
+
11540
+ return _DisplayObject.call(this, _extends({
11541
+ type: exports.Shape.CIRCLE,
11542
+ style: _extends({
11543
+ cx: '',
11544
+ cy: '',
11545
+ r: ''
11546
+ }, style)
11547
+ }, rest)) || this;
11548
+ }
11549
+
11550
+ return Circle;
11551
+ }(DisplayObject);
11619
11552
 
11620
- if (z === void 0) {
11621
- z = 0;
11622
- }
11553
+ var _excluded$2 = ["style"];
11554
+ var Ellipse = /*#__PURE__*/function (_DisplayObject) {
11555
+ _inheritsLoose(Ellipse, _DisplayObject);
11623
11556
 
11624
- this.sceneGraphService.setOrigin(this, createVec3(position, y, z));
11625
- return this;
11626
- };
11557
+ function Ellipse(_temp) {
11558
+ var _ref = _temp === void 0 ? {} : _temp,
11559
+ style = _ref.style,
11560
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
11627
11561
 
11628
- _proto.getOrigin = function getOrigin() {
11629
- return this.sceneGraphService.getOrigin(this);
11562
+ return _DisplayObject.call(this, _extends({
11563
+ type: exports.Shape.ELLIPSE,
11564
+ style: _extends({
11565
+ cx: '',
11566
+ cy: '',
11567
+ rx: '',
11568
+ ry: ''
11569
+ }, style)
11570
+ }, rest)) || this;
11630
11571
  }
11631
- /**
11632
- * set position in world space
11633
- */
11634
- ;
11635
-
11636
- _proto.setPosition = function setPosition(position, y, z) {
11637
- if (y === void 0) {
11638
- y = 0;
11639
- }
11640
11572
 
11641
- if (z === void 0) {
11642
- z = 0;
11643
- }
11573
+ return Ellipse;
11574
+ }(DisplayObject);
11644
11575
 
11645
- this.sceneGraphService.setPosition(this, createVec3(position, y, z));
11646
- return this;
11647
- }
11648
- /**
11649
- * set position in local space
11650
- */
11651
- ;
11576
+ var _excluded$3 = ["style"];
11577
+ /**
11578
+ * its attributes are inherited by its children.
11579
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
11580
+ *
11581
+ * @example
11582
+ * <g fill="white" stroke="green" stroke-width="5">
11583
+ <circle cx="40" cy="40" r="25" />
11584
+ <circle cx="60" cy="60" r="25" />
11585
+ </g>
11586
+ */
11652
11587
 
11653
- _proto.setLocalPosition = function setLocalPosition(position, y, z) {
11654
- if (y === void 0) {
11655
- y = 0;
11656
- }
11588
+ var Group = /*#__PURE__*/function (_DisplayObject) {
11589
+ _inheritsLoose(Group, _DisplayObject);
11657
11590
 
11658
- if (z === void 0) {
11659
- z = 0;
11660
- }
11591
+ function Group(_temp) {
11592
+ var _ref = _temp === void 0 ? {} : _temp,
11593
+ style = _ref.style,
11594
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
11661
11595
 
11662
- this.sceneGraphService.setLocalPosition(this, createVec3(position, y, z));
11663
- return this;
11596
+ return _DisplayObject.call(this, _extends({
11597
+ type: exports.Shape.GROUP,
11598
+ style: _extends({
11599
+ x: '',
11600
+ y: '',
11601
+ width: '',
11602
+ height: ''
11603
+ }, style)
11604
+ }, rest)) || this;
11664
11605
  }
11665
- /**
11666
- * translate in world space
11667
- */
11668
- ;
11669
11606
 
11670
- _proto.translate = function translate(position, y, z) {
11671
- if (y === void 0) {
11672
- y = 0;
11673
- }
11607
+ return Group;
11608
+ }(DisplayObject);
11674
11609
 
11675
- if (z === void 0) {
11676
- z = 0;
11677
- }
11610
+ var _excluded$4 = ["style"];
11611
+ var Image = /*#__PURE__*/function (_DisplayObject) {
11612
+ _inheritsLoose(Image, _DisplayObject);
11678
11613
 
11679
- this.sceneGraphService.translate(this, createVec3(position, y, z));
11680
- return this;
11681
- }
11682
- /**
11683
- * translate in local space
11684
- */
11685
- ;
11614
+ function Image(_temp) {
11615
+ var _ref = _temp === void 0 ? {} : _temp,
11616
+ style = _ref.style,
11617
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
11686
11618
 
11687
- _proto.translateLocal = function translateLocal(position, y, z) {
11688
- if (y === void 0) {
11689
- y = 0;
11690
- }
11619
+ return _DisplayObject.call(this, _extends({
11620
+ type: exports.Shape.IMAGE,
11621
+ style: _extends({
11622
+ x: '',
11623
+ y: '',
11624
+ img: '',
11625
+ width: '',
11626
+ height: ''
11627
+ }, style)
11628
+ }, rest)) || this;
11629
+ }
11691
11630
 
11692
- if (z === void 0) {
11693
- z = 0;
11694
- }
11631
+ return Image;
11632
+ }(DisplayObject);
11695
11633
 
11696
- this.sceneGraphService.translateLocal(this, createVec3(position, y, z));
11697
- return this;
11698
- };
11634
+ var _excluded$5 = ["style"];
11635
+ var Line = /*#__PURE__*/function (_DisplayObject) {
11636
+ _inheritsLoose(Line, _DisplayObject);
11699
11637
 
11700
- _proto.getPosition = function getPosition() {
11701
- return this.sceneGraphService.getPosition(this);
11702
- };
11638
+ function Line(_temp) {
11639
+ var _ref = _temp === void 0 ? {} : _temp,
11640
+ style = _ref.style,
11641
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
11703
11642
 
11704
- _proto.getLocalPosition = function getLocalPosition() {
11705
- return this.sceneGraphService.getLocalPosition(this);
11643
+ return _DisplayObject.call(this, _extends({
11644
+ type: exports.Shape.LINE,
11645
+ style: _extends({
11646
+ x1: 0,
11647
+ y1: 0,
11648
+ x2: 0,
11649
+ y2: 0,
11650
+ z1: 0,
11651
+ z2: 0,
11652
+ isBillboard: false
11653
+ }, style)
11654
+ }, rest)) || this;
11706
11655
  }
11707
- /**
11708
- * compatible with G 3.0
11709
- *
11710
- * scaling in local space
11711
- * scale(10) = scale(10, 10, 10)
11712
- *
11713
- * we can't set scale in world space
11714
- */
11715
- ;
11716
11656
 
11717
- _proto.scale = function scale(scaling, y, z) {
11718
- return this.scaleLocal(scaling, y, z);
11719
- };
11657
+ var _proto = Line.prototype;
11720
11658
 
11721
- _proto.scaleLocal = function scaleLocal(scaling, y, z) {
11722
- if (typeof scaling === 'number') {
11723
- y = y || scaling;
11724
- z = z || scaling;
11725
- scaling = createVec3(scaling, y, z);
11726
- }
11659
+ _proto.getPoint = function getPoint(ratio) {
11660
+ // TODO: account for z1/z2 in 3D line
11661
+ var _this$parsedStyle = this.parsedStyle,
11662
+ x1 = _this$parsedStyle.x1,
11663
+ y1 = _this$parsedStyle.y1,
11664
+ x2 = _this$parsedStyle.x2,
11665
+ y2 = _this$parsedStyle.y2,
11666
+ defX = _this$parsedStyle.defX,
11667
+ defY = _this$parsedStyle.defY;
11727
11668
 
11728
- this.sceneGraphService.scaleLocal(this, scaling);
11729
- return this;
11730
- }
11731
- /**
11732
- * set scaling in local space
11733
- */
11734
- ;
11669
+ var _LineUtil$pointAt = gMath.Line.pointAt(x1.value, y1.value, x2.value, y2.value, ratio),
11670
+ x = _LineUtil$pointAt.x,
11671
+ y = _LineUtil$pointAt.y;
11735
11672
 
11736
- _proto.setLocalScale = function setLocalScale(scaling, y, z) {
11737
- if (typeof scaling === 'number') {
11738
- y = y || scaling;
11739
- z = z || scaling;
11740
- scaling = createVec3(scaling, y, z);
11741
- }
11673
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
11742
11674
 
11743
- this.sceneGraphService.setLocalScale(this, scaling);
11744
- return this;
11745
- }
11746
- /**
11747
- * get scaling in local space
11748
- */
11749
- ;
11675
+ return new Point(transformed[0], transformed[1]);
11676
+ };
11750
11677
 
11751
- _proto.getLocalScale = function getLocalScale() {
11752
- return this.sceneGraphService.getLocalScale(this);
11753
- }
11754
- /**
11755
- * get scaling in world space
11756
- */
11757
- ;
11678
+ _proto.getTotalLength = function getTotalLength() {
11679
+ // TODO: account for z1/z2 in 3D line
11680
+ var _this$parsedStyle2 = this.parsedStyle,
11681
+ x1 = _this$parsedStyle2.x1,
11682
+ y1 = _this$parsedStyle2.y1,
11683
+ x2 = _this$parsedStyle2.x2,
11684
+ y2 = _this$parsedStyle2.y2;
11685
+ return gMath.Line.length(x1.value, y1.value, x2.value, y2.value);
11686
+ };
11758
11687
 
11759
- _proto.getScale = function getScale() {
11760
- return this.sceneGraphService.getScale(this);
11761
- }
11762
- /**
11763
- * only return degrees of Z axis in world space
11764
- */
11765
- ;
11688
+ return Line;
11689
+ }(DisplayObject);
11766
11690
 
11767
- _proto.getEulerAngles = function getEulerAngles() {
11768
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11769
- var _getEuler = getEuler(glMatrix.vec3.create(), this.sceneGraphService.getWorldTransform(this)),
11770
- ex = _getEuler[0],
11771
- ey = _getEuler[1],
11772
- ez = _getEuler[2];
11691
+ var _excluded$6 = ["style"];
11692
+ var Path = /*#__PURE__*/function (_DisplayObject) {
11693
+ _inheritsLoose(Path, _DisplayObject);
11773
11694
 
11774
- return rad2deg(ez);
11695
+ function Path(_temp) {
11696
+ var _ref = _temp === void 0 ? {} : _temp,
11697
+ style = _ref.style,
11698
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
11699
+
11700
+ return _DisplayObject.call(this, _extends({
11701
+ type: exports.Shape.PATH,
11702
+ style: _extends({
11703
+ path: '',
11704
+ miterLimit: ''
11705
+ }, style)
11706
+ }, rest)) || this;
11775
11707
  }
11776
- /**
11777
- * only return degrees of Z axis in local space
11778
- */
11779
- ;
11780
11708
 
11781
- _proto.getLocalEulerAngles = function getLocalEulerAngles() {
11782
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11783
- var _getEuler2 = getEuler(glMatrix.vec3.create(), this.sceneGraphService.getLocalRotation(this)),
11784
- ex = _getEuler2[0],
11785
- ey = _getEuler2[1],
11786
- ez = _getEuler2[2];
11709
+ var _proto = Path.prototype;
11787
11710
 
11788
- return rad2deg(ez);
11711
+ _proto.getTotalLength = function getTotalLength() {
11712
+ return this.parsedStyle.path.totalLength;
11789
11713
  }
11790
11714
  /**
11791
- * set euler angles(degrees) in world space
11715
+ * Get point according to ratio
11792
11716
  */
11793
11717
  ;
11794
11718
 
11795
- _proto.setEulerAngles = function setEulerAngles(z) {
11796
- this.sceneGraphService.setEulerAngles(this, 0, 0, z);
11797
- return this;
11719
+ _proto.getPoint = function getPoint(ratio) {
11720
+ var _this$parsedStyle = this.parsedStyle,
11721
+ defX = _this$parsedStyle.defX,
11722
+ defY = _this$parsedStyle.defY,
11723
+ _this$parsedStyle$pat = _this$parsedStyle.path,
11724
+ totalLength = _this$parsedStyle$pat.totalLength,
11725
+ absolutePath = _this$parsedStyle$pat.absolutePath;
11726
+
11727
+ var _getPointAtLength = util.getPointAtLength(absolutePath, ratio * totalLength),
11728
+ x = _getPointAtLength.x,
11729
+ y = _getPointAtLength.y;
11730
+
11731
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
11732
+
11733
+ return new Point(transformed[0], transformed[1]);
11798
11734
  }
11799
11735
  /**
11800
- * set euler angles(degrees) in local space
11736
+ * Get start tangent vector
11801
11737
  */
11802
11738
  ;
11803
11739
 
11804
- _proto.setLocalEulerAngles = function setLocalEulerAngles(z) {
11805
- this.sceneGraphService.setLocalEulerAngles(this, 0, 0, z);
11806
- return this;
11807
- };
11808
-
11809
- _proto.rotateLocal = function rotateLocal(x, y, z) {
11810
- if (isNil(y) && isNil(z)) {
11811
- this.sceneGraphService.rotateLocal(this, 0, 0, x);
11812
- } else {
11813
- this.sceneGraphService.rotateLocal(this, x, y, z);
11814
- }
11740
+ _proto.getStartTangent = function getStartTangent() {
11741
+ var segments = this.parsedStyle.path.segments;
11742
+ var result = [];
11815
11743
 
11816
- return this;
11817
- };
11744
+ if (segments.length > 1) {
11745
+ var startPoint = segments[0].currentPoint;
11746
+ var endPoint = segments[1].currentPoint;
11747
+ var tangent = segments[1].startTangent;
11748
+ result = [];
11818
11749
 
11819
- _proto.rotate = function rotate(x, y, z) {
11820
- if (isNil(y) && isNil(z)) {
11821
- this.sceneGraphService.rotate(this, 0, 0, x);
11822
- } else {
11823
- this.sceneGraphService.rotate(this, x, y, z);
11750
+ if (tangent) {
11751
+ result.push([startPoint[0] - tangent[0], startPoint[1] - tangent[1]]);
11752
+ result.push([startPoint[0], startPoint[1]]);
11753
+ } else {
11754
+ result.push([endPoint[0], endPoint[1]]);
11755
+ result.push([startPoint[0], startPoint[1]]);
11756
+ }
11824
11757
  }
11825
11758
 
11826
- return this;
11827
- };
11828
-
11829
- _proto.setRotation = function setRotation(rotation, y, z, w) {
11830
- this.sceneGraphService.setRotation(this, rotation, y, z, w);
11831
- return this;
11832
- };
11833
-
11834
- _proto.setLocalRotation = function setLocalRotation(rotation, y, z, w) {
11835
- this.sceneGraphService.setLocalRotation(this, rotation, y, z, w);
11836
- return this;
11837
- };
11838
-
11839
- _proto.setLocalSkew = function setLocalSkew(skew, y) {
11840
- this.sceneGraphService.setLocalSkew(this, skew, y);
11841
- return this;
11842
- };
11843
-
11844
- _proto.getRotation = function getRotation() {
11845
- return this.sceneGraphService.getRotation(this);
11846
- };
11759
+ return result;
11760
+ }
11761
+ /**
11762
+ * Get end tangent vector
11763
+ */
11764
+ ;
11847
11765
 
11848
- _proto.getLocalRotation = function getLocalRotation() {
11849
- return this.sceneGraphService.getLocalRotation(this);
11850
- };
11766
+ _proto.getEndTangent = function getEndTangent() {
11767
+ var segments = this.parsedStyle.path.segments;
11768
+ var length = segments.length;
11769
+ var result = [];
11851
11770
 
11852
- _proto.getLocalSkew = function getLocalSkew() {
11853
- return this.sceneGraphService.getLocalSkew(this);
11854
- };
11771
+ if (length > 1) {
11772
+ var startPoint = segments[length - 2].currentPoint;
11773
+ var endPoint = segments[length - 1].currentPoint;
11774
+ var tangent = segments[length - 1].endTangent;
11775
+ result = [];
11855
11776
 
11856
- _proto.getLocalTransform = function getLocalTransform() {
11857
- return this.sceneGraphService.getLocalTransform(this);
11858
- };
11777
+ if (tangent) {
11778
+ result.push([endPoint[0] - tangent[0], endPoint[1] - tangent[1]]);
11779
+ result.push([endPoint[0], endPoint[1]]);
11780
+ } else {
11781
+ result.push([startPoint[0], startPoint[1]]);
11782
+ result.push([endPoint[0], endPoint[1]]);
11783
+ }
11784
+ }
11859
11785
 
11860
- _proto.getWorldTransform = function getWorldTransform() {
11861
- return this.sceneGraphService.getWorldTransform(this);
11786
+ return result;
11862
11787
  };
11863
11788
 
11864
- _proto.setLocalTransform = function setLocalTransform(transform) {
11865
- this.sceneGraphService.setLocalTransform(this, transform);
11866
- return this;
11867
- };
11789
+ return Path;
11790
+ }(DisplayObject);
11868
11791
 
11869
- _proto.resetLocalTransform = function resetLocalTransform() {
11870
- this.sceneGraphService.resetLocalTransform(this);
11871
- } // #endregion transformable
11872
- // #region animatable
11792
+ var _excluded$7 = ["style"];
11793
+ var Polygon = /*#__PURE__*/function (_DisplayObject) {
11794
+ _inheritsLoose(Polygon, _DisplayObject);
11873
11795
 
11874
- /**
11875
- * returns an array of all Animation objects affecting this element
11876
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
11877
- */
11878
- ;
11796
+ function Polygon(_temp) {
11797
+ var _ref = _temp === void 0 ? {} : _temp,
11798
+ style = _ref.style,
11799
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
11879
11800
 
11880
- _proto.getAnimations = function getAnimations() {
11881
- return this.activeAnimations;
11801
+ return _DisplayObject.call(this, _extends({
11802
+ type: exports.Shape.POLYGON,
11803
+ style: _extends({
11804
+ points: '',
11805
+ miterLimit: ''
11806
+ }, style)
11807
+ }, rest)) || this;
11882
11808
  }
11883
- /**
11884
- * create an animation with WAAPI
11885
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
11886
- */
11887
- ;
11888
11809
 
11889
- _proto.animate = function animate(keyframes, options) {
11890
- var _this$ownerDocument;
11891
-
11892
- var timeline = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : _this$ownerDocument.timeline; // account for clip path, use target's timeline
11810
+ return Polygon;
11811
+ }(DisplayObject);
11893
11812
 
11894
- if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
11895
- var _target$ownerDocument;
11813
+ var _excluded$8 = ["style"];
11814
+ var Polyline = /*#__PURE__*/function (_DisplayObject) {
11815
+ _inheritsLoose(Polyline, _DisplayObject);
11896
11816
 
11897
- var target = this.parsedStyle.clipPathTargets[0];
11898
- timeline = (_target$ownerDocument = target.ownerDocument) === null || _target$ownerDocument === void 0 ? void 0 : _target$ownerDocument.timeline;
11899
- } // clear old parsed transform
11817
+ function Polyline(_temp) {
11818
+ var _ref = _temp === void 0 ? {} : _temp,
11819
+ style = _ref.style,
11820
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
11900
11821
 
11822
+ return _DisplayObject.call(this, _extends({
11823
+ type: exports.Shape.POLYLINE,
11824
+ style: _extends({
11825
+ points: '',
11826
+ miterLimit: ''
11827
+ }, style)
11828
+ }, rest)) || this;
11829
+ }
11901
11830
 
11902
- delete this.parsedStyle.transform;
11831
+ var _proto = Polyline.prototype;
11903
11832
 
11904
- if (timeline) {
11905
- return timeline.play(new KeyframeEffect(this, keyframes, options));
11906
- }
11833
+ _proto.getTotalLength = function getTotalLength() {
11834
+ return this.parsedStyle.points.totalLength;
11835
+ };
11907
11836
 
11908
- return null;
11909
- } // #endregion animatable
11910
- // #region visible
11837
+ _proto.getPoint = function getPoint(ratio) {
11838
+ var _this$parsedStyle = this.parsedStyle,
11839
+ defX = _this$parsedStyle.defX,
11840
+ defY = _this$parsedStyle.defY,
11841
+ _this$parsedStyle$poi = _this$parsedStyle.points,
11842
+ points = _this$parsedStyle$poi.points,
11843
+ segments = _this$parsedStyle$poi.segments;
11844
+ var subt = 0;
11845
+ var index = 0;
11846
+ segments.forEach(function (v, i) {
11847
+ if (ratio >= v[0] && ratio <= v[1]) {
11848
+ subt = (ratio - v[0]) / (v[1] - v[0]);
11849
+ index = i;
11850
+ }
11851
+ });
11911
11852
 
11912
- /**
11913
- * show group, which will also change visibility of its children in sceneGraphNode
11914
- *
11915
- * @deprecated
11916
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility
11917
- */
11918
- ;
11853
+ var _LineUtil$pointAt = gMath.Line.pointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt),
11854
+ x = _LineUtil$pointAt.x,
11855
+ y = _LineUtil$pointAt.y;
11919
11856
 
11920
- _proto.show = function show() {
11921
- this.style.visibility = 'visible';
11922
- }
11923
- /**
11924
- * @deprecated
11925
- * hide group, which will also change visibility of its children in sceneGraphNode
11926
- */
11927
- ;
11857
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
11928
11858
 
11929
- _proto.hide = function hide() {
11930
- this.style.visibility = 'hidden';
11931
- }
11932
- /**
11933
- * shortcut for Used value of `visibility`
11934
- */
11935
- ;
11859
+ return new Point(transformed[0], transformed[1]);
11860
+ };
11936
11861
 
11937
- _proto.isVisible = function isVisible() {
11938
- var _this$parsedStyle, _this$parsedStyle$vis;
11862
+ _proto.getStartTangent = function getStartTangent() {
11863
+ var points = this.parsedStyle.points.points;
11864
+ var result = [];
11865
+ result.push([points[1][0], points[1][1]]);
11866
+ result.push([points[0][0], points[0][1]]);
11867
+ return result;
11868
+ };
11939
11869
 
11940
- return ((_this$parsedStyle = this.parsedStyle) === null || _this$parsedStyle === void 0 ? void 0 : (_this$parsedStyle$vis = _this$parsedStyle.visibility) === null || _this$parsedStyle$vis === void 0 ? void 0 : _this$parsedStyle$vis.value) === 'visible';
11870
+ _proto.getEndTangent = function getEndTangent() {
11871
+ var points = this.parsedStyle.points.points;
11872
+ var l = points.length - 1;
11873
+ var result = [];
11874
+ result.push([points[l - 1][0], points[l - 1][1]]);
11875
+ result.push([points[l][0], points[l][1]]);
11876
+ return result;
11941
11877
  };
11942
11878
 
11943
- _proto.isInteractive = function isInteractive() {
11944
- var _this$parsedStyle2, _this$parsedStyle2$po;
11945
-
11946
- return ((_this$parsedStyle2 = this.parsedStyle) === null || _this$parsedStyle2 === void 0 ? void 0 : (_this$parsedStyle2$po = _this$parsedStyle2.pointerEvents) === null || _this$parsedStyle2$po === void 0 ? void 0 : _this$parsedStyle2$po.value) !== 'none';
11947
- };
11879
+ return Polyline;
11880
+ }(DisplayObject);
11948
11881
 
11949
- _proto.isCulled = function isCulled() {
11950
- return !!(this.cullable && this.cullable.isCulled());
11951
- }
11952
- /**
11953
- * bring to front in current group
11954
- */
11955
- ;
11882
+ var _excluded$9 = ["style"];
11883
+ var Rect = /*#__PURE__*/function (_DisplayObject) {
11884
+ _inheritsLoose(Rect, _DisplayObject);
11956
11885
 
11957
- _proto.toFront = function toFront() {
11958
- if (this.parentNode) {
11959
- this.style.zIndex = Math.max.apply(Math, this.parentNode.children.map(function (child) {
11960
- return Number(child.style.zIndex);
11961
- })) + 1;
11962
- }
11886
+ function Rect(_temp) {
11887
+ var _ref = _temp === void 0 ? {} : _temp,
11888
+ style = _ref.style,
11889
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$9);
11963
11890
 
11964
- return this;
11891
+ return _DisplayObject.call(this, _extends({
11892
+ type: exports.Shape.RECT,
11893
+ style: _extends({
11894
+ x: '',
11895
+ y: '',
11896
+ width: '',
11897
+ height: '',
11898
+ radius: ''
11899
+ }, style)
11900
+ }, rest)) || this;
11965
11901
  }
11966
- /**
11967
- * send to back in current group
11968
- */
11969
- ;
11970
-
11971
- _proto.toBack = function toBack() {
11972
- if (this.parentNode) {
11973
- this.style.zIndex = Math.min.apply(Math, this.parentNode.children.map(function (child) {
11974
- return Number(child.style.zIndex);
11975
- })) - 1;
11976
- }
11977
-
11978
- return this;
11979
- } // #endregion visible
11980
- // #region deprecated
11981
-
11982
- /**
11983
- * @deprecated
11984
- * compatible with G 3.0
11985
- * @deprecated
11986
- */
11987
- ;
11988
11902
 
11989
- _proto.getCount = function getCount() {
11990
- return this.childElementCount;
11991
- }
11992
- /**
11993
- * @deprecated
11994
- * compatible with G 3.0
11995
- * @deprecated
11996
- */
11997
- ;
11903
+ return Rect;
11904
+ }(DisplayObject);
11998
11905
 
11999
- _proto.getParent = function getParent() {
12000
- return this.parentElement;
12001
- }
12002
- /**
12003
- * @deprecated
12004
- * compatible with G 3.0
12005
- * @deprecated
12006
- */
12007
- ;
11906
+ var _excluded$a = ["style"];
11907
+ /**
11908
+ * <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
11909
+ */
12008
11910
 
12009
- _proto.getChildren = function getChildren() {
12010
- return this.children;
12011
- }
12012
- /**
12013
- * @deprecated
12014
- * compatible with G 3.0
12015
- * @deprecated
12016
- */
12017
- ;
11911
+ var Text = /*#__PURE__*/function (_DisplayObject) {
11912
+ _inheritsLoose(Text, _DisplayObject);
12018
11913
 
12019
- _proto.getFirst = function getFirst() {
12020
- return this.firstElementChild;
12021
- }
12022
11914
  /**
12023
- * @deprecated
12024
- * compatible with G 3.0
12025
- * @deprecated
12026
- * get last child group/shape
11915
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants
12027
11916
  */
12028
- ;
11917
+ // LENGTHADJUST_SPACING: number = 1;
11918
+ // LENGTHADJUST_SPACINGANDGLYPHS: number = 2;
11919
+ // LENGTHADJUST_UNKNOWN: number = 0;
11920
+ function Text(_temp) {
11921
+ var _ref = _temp === void 0 ? {} : _temp,
11922
+ style = _ref.style,
11923
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
12029
11924
 
12030
- _proto.getLast = function getLast() {
12031
- return this.lastElementChild;
12032
- }
12033
- /**
12034
- * @deprecated
12035
- * compatible with G 3.0
12036
- * @deprecated
12037
- * get child group/shape by index
12038
- */
12039
- ;
11925
+ return _DisplayObject.call(this, _extends({
11926
+ type: exports.Shape.TEXT,
11927
+ style: _extends({
11928
+ x: '',
11929
+ y: '',
11930
+ text: '',
11931
+ fontSize: '',
11932
+ fontFamily: '',
11933
+ fontStyle: '',
11934
+ fontWeight: '',
11935
+ fontVariant: '',
11936
+ textAlign: '',
11937
+ textBaseline: '',
11938
+ textTransform: '',
11939
+ fill: 'black',
11940
+ letterSpacing: '',
11941
+ lineHeight: '',
11942
+ miterLimit: '',
11943
+ whiteSpace: 'pre',
11944
+ wordWrap: false,
11945
+ wordWrapWidth: 0,
11946
+ leading: 0,
11947
+ dx: '',
11948
+ dy: ''
11949
+ }, style)
11950
+ }, rest)) || this;
11951
+ } // lengthAdjust: SVGAnimatedEnumeration;
11952
+ // textLength: SVGAnimatedLength;
11953
+ // getCharNumAtPosition(point?: DOMPointInit): number {
11954
+ // throw new Error('Method not implemented.');
11955
+ // }
12040
11956
 
12041
- _proto.getChildByIndex = function getChildByIndex(index) {
12042
- return this.children[index] || null;
12043
- }
12044
11957
  /**
12045
- * compatible with G 3.0
12046
- * @deprecated
11958
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
12047
11959
  */
12048
- ;
12049
11960
 
12050
- _proto.add = function add(child, index) {
12051
- return this.appendChild(child, index);
12052
- }
12053
- /**
12054
- * @alias style.clipPath
12055
- * @deprecated
12056
- */
12057
- ;
12058
11961
 
12059
- _proto.setClip = function setClip(clipPath) {
12060
- this.style.clipPath = clipPath;
12061
- }
12062
- /**
12063
- * @alias style.clipPath
12064
- * @deprecated
12065
- */
12066
- ;
11962
+ var _proto = Text.prototype;
12067
11963
 
12068
- _proto.getClip = function getClip() {
12069
- return this.style.clipPath || null;
12070
- }
12071
- /**
12072
- * compatible with G 3.0
12073
- * @deprecated
12074
- */
12075
- ;
11964
+ _proto.getComputedTextLength = function getComputedTextLength() {
11965
+ var _this$parsedStyle$met;
12076
11966
 
12077
- _proto.set = function set(name, value) {
12078
- this.config[name] = value;
12079
- }
12080
- /**
12081
- * compatible with G 3.0
12082
- * @deprecated
12083
- */
11967
+ return ((_this$parsedStyle$met = this.parsedStyle.metrics) === null || _this$parsedStyle$met === void 0 ? void 0 : _this$parsedStyle$met.maxLineWidth) || 0;
11968
+ } // getEndPositionOfChar(charnum: number): DOMPoint {
11969
+ // throw new Error('Method not implemented.');
11970
+ // }
11971
+ // getExtentOfChar(charnum: number): DOMRect {
11972
+ // throw new Error('Method not implemented.');
11973
+ // }
11974
+ // getNumberOfChars(): number {
11975
+ // throw new Error('Method not implemented.');
11976
+ // }
11977
+ // getRotationOfChar(charnum: number): number {
11978
+ // throw new Error('Method not implemented.');
11979
+ // }
11980
+ // getStartPositionOfChar(charnum: number): DOMPoint {
11981
+ // throw new Error('Method not implemented.');
11982
+ // }
11983
+ // getSubStringLength(charnum: number, nchars: number): number {
11984
+ // throw new Error('Method not implemented.');
11985
+ // }
11986
+ // selectSubString(charnum: number, nchars: number): void {
11987
+ // throw new Error('Method not implemented.');
11988
+ // }
12084
11989
  ;
12085
11990
 
12086
- _proto.get = function get(name) {
12087
- return this.config[name];
12088
- }
12089
- /**
12090
- * compatible with G 3.0
12091
- * @alias object.config
12092
- * @deprecated
12093
- */
12094
- ;
11991
+ _proto.getLineBoundingRects = function getLineBoundingRects() {
11992
+ var _this$parsedStyle$met2;
12095
11993
 
12096
- _proto.getConfig = function getConfig() {
12097
- return this.config;
11994
+ return ((_this$parsedStyle$met2 = this.parsedStyle.metrics) === null || _this$parsedStyle$met2 === void 0 ? void 0 : _this$parsedStyle$met2.lineMetrics) || [];
12098
11995
  };
12099
11996
 
12100
- _proto.attr = function attr() {
12101
- var _this3 = this;
12102
-
12103
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12104
- args[_key] = arguments[_key];
12105
- }
11997
+ return Text;
11998
+ }(DisplayObject);
12106
11999
 
12107
- var name = args[0],
12108
- value = args[1];
12000
+ var _excluded$b = ["style"];
12001
+ /**
12002
+ * HTML container
12003
+ * @see https://github.com/pmndrs/drei#html
12004
+ */
12109
12005
 
12110
- if (!name) {
12111
- return this.attributes;
12112
- }
12006
+ var HTML = /*#__PURE__*/function (_DisplayObject) {
12007
+ _inheritsLoose(HTML, _DisplayObject);
12113
12008
 
12114
- if (isObject(name)) {
12115
- Object.keys(name).forEach(function (key) {
12116
- _this3.setAttribute(key, name[key]);
12117
- });
12118
- return this;
12119
- }
12009
+ function HTML(_temp) {
12010
+ var _this;
12120
12011
 
12121
- if (args.length === 2) {
12122
- this.setAttribute(name, value);
12123
- return this;
12124
- }
12012
+ var _ref = _temp === void 0 ? {} : _temp,
12013
+ style = _ref.style,
12014
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$b);
12125
12015
 
12126
- return this.attributes[name];
12016
+ _this = _DisplayObject.call(this, _extends({
12017
+ type: exports.Shape.HTML,
12018
+ style: _extends({
12019
+ x: '',
12020
+ y: '',
12021
+ width: 'auto',
12022
+ height: 'auto',
12023
+ innerHTML: ''
12024
+ }, style)
12025
+ }, rest)) || this;
12026
+ _this.cullable.enable = false;
12027
+ return _this;
12127
12028
  }
12128
- /**
12129
- * @alias setPosition
12130
- * @deprecated
12029
+ /**
12030
+ * return wrapper HTMLElement
12031
+ * * <div> in g-webgl/canvas
12032
+ * * <foreignObject> in g-svg
12131
12033
  */
12132
- ;
12133
12034
 
12134
- _proto.moveTo = function moveTo(position, y, z) {
12135
- if (y === void 0) {
12136
- y = 0;
12137
- }
12138
12035
 
12139
- if (z === void 0) {
12140
- z = 0;
12141
- }
12036
+ var _proto = HTML.prototype;
12142
12037
 
12143
- this.setPosition(position, y, z);
12144
- return this;
12038
+ _proto.getDomElement = function getDomElement() {
12039
+ return this.parsedStyle.$el;
12145
12040
  }
12146
12041
  /**
12147
- * @alias setPosition
12148
- * @deprecated
12042
+ * override with $el.getBoundingClientRect
12043
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
12149
12044
  */
12150
12045
  ;
12151
12046
 
12152
- _proto.move = function move(position, y, z) {
12153
- if (y === void 0) {
12154
- y = 0;
12155
- }
12047
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
12048
+ return this.parsedStyle.$el.getBoundingClientRect();
12049
+ };
12156
12050
 
12157
- if (z === void 0) {
12158
- z = 0;
12051
+ _proto.getClientRects = function getClientRects() {
12052
+ return [this.getBoundingClientRect()];
12053
+ };
12054
+
12055
+ _proto.getBounds = function getBounds() {
12056
+ var _this$ownerDocument, _this$ownerDocument$d;
12057
+
12058
+ var clientRect = this.getBoundingClientRect(); // calc context's offset
12059
+ // @ts-ignore
12060
+
12061
+ var canvasRect = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : (_this$ownerDocument$d = _this$ownerDocument.defaultView) === null || _this$ownerDocument$d === void 0 ? void 0 : _this$ownerDocument$d.getContextService().getBoundingClientRect();
12062
+
12063
+ if (canvasRect) {
12064
+ var minX = clientRect.left - canvasRect.left;
12065
+ var minY = clientRect.top - canvasRect.top;
12066
+ var aabb = new AABB();
12067
+ aabb.setMinMax(glMatrix.vec3.fromValues(minX, minY, 0), glMatrix.vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0));
12068
+ return aabb;
12159
12069
  }
12160
12070
 
12161
- this.setPosition(position, y, z);
12162
- return this;
12163
- }
12164
- /**
12165
- * @alias style.zIndex
12166
- * @deprecated
12167
- */
12168
- ;
12071
+ return null;
12072
+ };
12169
12073
 
12170
- _proto.setZIndex = function setZIndex(zIndex) {
12171
- this.style.zIndex = zIndex;
12172
- return this;
12173
- }
12174
- /**
12175
- * return 3x3 matrix in world space
12176
- * @deprecated
12177
- */
12178
- ;
12074
+ _proto.getLocalBounds = function getLocalBounds() {
12075
+ if (this.parentNode) {
12076
+ var parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), this.parentNode.getWorldTransform());
12077
+ var bounds = this.getBounds();
12179
12078
 
12180
- _proto.getMatrix = function getMatrix(transformMat4) {
12181
- var transform = transformMat4 || this.getWorldTransform();
12079
+ if (!AABB.isEmpty(bounds)) {
12080
+ var localBounds = new AABB();
12081
+ localBounds.setFromTransformedAABB(bounds, parentInvert);
12082
+ return localBounds;
12083
+ }
12084
+ }
12182
12085
 
12183
- var _mat4$getTranslation = glMatrix.mat4.getTranslation(glMatrix.vec3.create(), transform),
12184
- tx = _mat4$getTranslation[0],
12185
- ty = _mat4$getTranslation[1];
12086
+ return this.getBounds();
12087
+ };
12186
12088
 
12187
- var _mat4$getScaling = glMatrix.mat4.getScaling(glMatrix.vec3.create(), transform),
12188
- sx = _mat4$getScaling[0],
12189
- sy = _mat4$getScaling[1];
12089
+ return HTML;
12090
+ }(DisplayObject);
12190
12091
 
12191
- var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
12092
+ /**
12093
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationPlaybackEvent
12094
+ */
12192
12095
 
12193
- var _getEuler3 = getEuler(glMatrix.vec3.create(), rotation),
12194
- eux = _getEuler3[0],
12195
- euy = _getEuler3[1],
12196
- euz = _getEuler3[2]; // gimbal lock at 90 degrees
12096
+ var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) {
12097
+ _inheritsLoose(AnimationEvent, _FederatedEvent);
12197
12098
 
12099
+ function AnimationEvent(manager, target, currentTime, timelineTime) {
12100
+ var _this;
12198
12101
 
12199
- return fromRotationTranslationScale(eux || euz, tx, ty, sx, sy);
12200
- }
12201
- /**
12202
- * return 3x3 matrix in local space
12203
- * @deprecated
12204
- */
12205
- ;
12102
+ _this = _FederatedEvent.call(this, manager) || this;
12103
+ _this.currentTime = void 0;
12104
+ _this.timelineTime = void 0;
12105
+ _this.currentTime = currentTime;
12106
+ _this.timelineTime = timelineTime; // @ts-ignore
12206
12107
 
12207
- _proto.getLocalMatrix = function getLocalMatrix() {
12208
- return this.getMatrix(this.getLocalTransform());
12108
+ _this.target = target;
12109
+ _this.type = 'finish';
12110
+ _this.bubbles = false; // @ts-ignore
12111
+
12112
+ _this.currentTarget = target;
12113
+ _this.defaultPrevented = false;
12114
+ _this.eventPhase = _this.AT_TARGET;
12115
+ _this.timeStamp = Date.now();
12116
+ _this.currentTime = currentTime;
12117
+ _this.timelineTime = timelineTime;
12118
+ return _this;
12209
12119
  }
12210
- /**
12211
- * set 3x3 matrix in world space
12212
- * @deprecated
12213
- */
12214
- ;
12215
12120
 
12216
- _proto.setMatrix = function setMatrix(mat) {
12217
- var _decompose = decompose(mat),
12218
- tx = _decompose[0],
12219
- ty = _decompose[1],
12220
- scalingX = _decompose[2],
12221
- scalingY = _decompose[3],
12222
- angle = _decompose[4];
12121
+ return AnimationEvent;
12122
+ }(FederatedEvent);
12223
12123
 
12224
- this.setEulerAngles(angle).setPosition(tx, ty).setLocalScale(scalingX, scalingY);
12124
+ var sequenceNumber = 0;
12125
+ /**
12126
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/Animation
12127
+ */
12128
+
12129
+ var Animation = /*#__PURE__*/function () {
12130
+ function Animation(effect, timeline) {
12131
+ this.effect = void 0;
12132
+ this.timeline = void 0;
12133
+ this.id = void 0;
12134
+ this.currentTimePending = false;
12135
+ this._idle = true;
12136
+ this._paused = false;
12137
+ this._finishedFlag = true;
12138
+ this.oldPlayState = void 0;
12139
+ this._holdTime = void 0;
12140
+ this.readyPromise = void 0;
12141
+ this.finishedPromise = void 0;
12142
+ this.resolveReadyPromise = void 0;
12143
+ this.rejectReadyPromise = void 0;
12144
+ this.resolveFinishedPromise = void 0;
12145
+ this.rejectFinishedPromise = void 0;
12146
+ this.onfinish = void 0;
12147
+ this.oncancel = void 0;
12148
+ this.onframe = void 0;
12149
+ this._currentTime = 0;
12150
+ this._startTime = void 0;
12151
+ this._playbackRate = 1;
12152
+ this._inEffect = void 0;
12153
+ this._inTimeline = true;
12154
+ this.onremove = void 0;
12155
+ this.effect = effect;
12156
+ effect.animation = this;
12157
+ this.timeline = timeline;
12158
+ this.id = "" + sequenceNumber++;
12159
+ this._inEffect = !!this.effect.update(0);
12160
+ this._holdTime = 0;
12161
+ this._paused = false;
12162
+ this.oldPlayState = 'idle';
12163
+ this.updatePromises();
12225
12164
  }
12226
12165
  /**
12227
- * set 3x3 matrix in local space
12228
- * @deprecated
12166
+ * state machine,
12167
+ * resolve/reject ready/finished Promise according to current state
12229
12168
  */
12230
- ;
12231
12169
 
12232
- _proto.setLocalMatrix = function setLocalMatrix(mat) {
12233
- var _decompose2 = decompose(mat),
12234
- tx = _decompose2[0],
12235
- ty = _decompose2[1],
12236
- scalingX = _decompose2[2],
12237
- scalingY = _decompose2[3],
12238
- angle = _decompose2[4];
12239
12170
 
12240
- this.setLocalEulerAngles(angle).setLocalPosition(tx, ty).setLocalScale(scalingX, scalingY);
12241
- };
12171
+ var _proto = Animation.prototype;
12242
12172
 
12243
- _createClass(DisplayObject, [{
12244
- key: "interactive",
12245
- get: function get() {
12246
- return this.isInteractive();
12247
- },
12248
- set: function set(b) {
12249
- this.style.pointerEvents = b ? 'auto' : 'none';
12173
+ _proto.updatePromises = function updatePromises() {
12174
+ var oldPlayState = this.oldPlayState;
12175
+ var newPlayState = this.pending ? 'pending' : this.playState;
12176
+
12177
+ if (this.readyPromise && newPlayState !== oldPlayState) {
12178
+ if (newPlayState === 'idle') {
12179
+ this.rejectReadyPromise();
12180
+ this.readyPromise = undefined;
12181
+ } else if (oldPlayState === 'pending') {
12182
+ this.resolveReadyPromise();
12183
+ } else if (newPlayState === 'pending') {
12184
+ this.readyPromise = undefined;
12185
+ }
12250
12186
  }
12251
- }]);
12252
12187
 
12253
- return DisplayObject;
12254
- }(Element);
12188
+ if (this.finishedPromise && newPlayState !== oldPlayState) {
12189
+ if (newPlayState === 'idle') {
12190
+ this.rejectFinishedPromise();
12191
+ this.finishedPromise = undefined;
12192
+ } else if (newPlayState === 'finished') {
12193
+ this.resolveFinishedPromise();
12194
+ } else if (oldPlayState === 'finished') {
12195
+ this.finishedPromise = undefined;
12196
+ }
12197
+ }
12255
12198
 
12256
- var _excluded = ["style"];
12257
- /**
12258
- * shadow root
12259
- * @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
12260
- */
12199
+ this.oldPlayState = newPlayState;
12200
+ return this.readyPromise || this.finishedPromise;
12201
+ };
12261
12202
 
12262
- var CustomElement = /*#__PURE__*/function (_DisplayObject) {
12263
- _inheritsLoose(CustomElement, _DisplayObject);
12203
+ _proto.play = function play() {
12204
+ this.updatePromises();
12205
+ this._paused = false;
12206
+
12207
+ if (this._isFinished || this._idle) {
12208
+ this.rewind();
12209
+ this._startTime = null;
12210
+ }
12211
+
12212
+ this._finishedFlag = false;
12213
+ this._idle = false;
12214
+ this.ensureAlive();
12215
+ this.timeline.applyDirtiedAnimation(this);
12216
+
12217
+ if (this.timeline.animations.indexOf(this) === -1) {
12218
+ this.timeline.animations.push(this);
12219
+ }
12264
12220
 
12265
- // static get observedAttributes(): string[] {
12266
- // return [];
12267
- // }
12268
- // private shadowNodes: DisplayObject[] = [];
12269
- function CustomElement(_temp) {
12270
- var _this;
12221
+ this.updatePromises();
12222
+ };
12271
12223
 
12272
- var _ref = _temp === void 0 ? {} : _temp,
12273
- style = _ref.style,
12274
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
12224
+ _proto.pause = function pause() {
12225
+ this.updatePromises();
12275
12226
 
12276
- _this = _DisplayObject.call(this, _extends({
12277
- style: _extends({
12278
- x: '',
12279
- y: ''
12280
- }, style)
12281
- }, rest)) || this;
12282
- _this.isCustomElement = true;
12283
- return _this;
12284
- }
12227
+ if (this.currentTime) {
12228
+ this._holdTime = this.currentTime;
12229
+ }
12285
12230
 
12286
- return CustomElement;
12287
- }(DisplayObject);
12231
+ if (!this._isFinished && !this._paused && !this._idle) {
12232
+ this.currentTimePending = true;
12233
+ } else if (this._idle) {
12234
+ this.rewind();
12235
+ this._idle = false;
12236
+ }
12288
12237
 
12289
- var _excluded$1 = ["style"];
12290
- var Circle = /*#__PURE__*/function (_DisplayObject) {
12291
- _inheritsLoose(Circle, _DisplayObject);
12238
+ this._startTime = null;
12239
+ this._paused = true;
12240
+ this.updatePromises();
12241
+ };
12292
12242
 
12293
- function Circle(_temp) {
12294
- var _ref = _temp === void 0 ? {} : _temp,
12295
- style = _ref.style,
12296
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
12243
+ _proto.finish = function finish() {
12244
+ this.updatePromises();
12245
+ if (this._idle) return;
12246
+ this.currentTime = this._playbackRate > 0 ? this.totalDuration : 0;
12247
+ this._startTime = this.totalDuration - this.currentTime;
12248
+ this.currentTimePending = false;
12249
+ this.timeline.applyDirtiedAnimation(this);
12250
+ this.updatePromises();
12251
+ };
12297
12252
 
12298
- return _DisplayObject.call(this, _extends({
12299
- type: exports.Shape.CIRCLE,
12300
- style: _extends({
12301
- cx: '',
12302
- cy: '',
12303
- r: ''
12304
- }, style)
12305
- }, rest)) || this;
12306
- }
12253
+ _proto.cancel = function cancel() {
12254
+ this.updatePromises();
12255
+ if (!this._inEffect) return;
12256
+ this._inEffect = false;
12257
+ this._idle = true;
12258
+ this._paused = false;
12259
+ this._finishedFlag = true;
12260
+ this._currentTime = 0;
12261
+ this._startTime = null;
12262
+ this.effect.update(null); // effects are invalid after cancellation as the animation state
12263
+ // needs to un-apply.
12307
12264
 
12308
- return Circle;
12309
- }(DisplayObject);
12265
+ this.timeline.applyDirtiedAnimation(this);
12266
+ this.updatePromises();
12267
+ };
12310
12268
 
12311
- var _excluded$2 = ["style"];
12312
- var Ellipse = /*#__PURE__*/function (_DisplayObject) {
12313
- _inheritsLoose(Ellipse, _DisplayObject);
12269
+ _proto.reverse = function reverse() {
12270
+ this.updatePromises();
12271
+ var oldCurrentTime = this.currentTime;
12272
+ this.playbackRate *= -1;
12273
+ this.play();
12314
12274
 
12315
- function Ellipse(_temp) {
12316
- var _ref = _temp === void 0 ? {} : _temp,
12317
- style = _ref.style,
12318
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
12275
+ if (oldCurrentTime !== null) {
12276
+ this.currentTime = oldCurrentTime;
12277
+ }
12319
12278
 
12320
- return _DisplayObject.call(this, _extends({
12321
- type: exports.Shape.ELLIPSE,
12322
- style: _extends({
12323
- cx: '',
12324
- cy: '',
12325
- rx: '',
12326
- ry: ''
12327
- }, style)
12328
- }, rest)) || this;
12279
+ this.updatePromises();
12329
12280
  }
12281
+ /**
12282
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate
12283
+ */
12284
+ ;
12330
12285
 
12331
- return Ellipse;
12332
- }(DisplayObject);
12286
+ _proto.updatePlaybackRate = function updatePlaybackRate(playbackRate) {
12287
+ this.playbackRate = playbackRate;
12288
+ };
12333
12289
 
12334
- var _excluded$3 = ["style"];
12335
- /**
12336
- * its attributes are inherited by its children.
12337
- * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g
12338
- *
12339
- * @example
12340
- * <g fill="white" stroke="green" stroke-width="5">
12341
- <circle cx="40" cy="40" r="25" />
12342
- <circle cx="60" cy="60" r="25" />
12343
- </g>
12344
- */
12290
+ _proto.targetAnimations = function targetAnimations() {
12291
+ var _this$effect;
12345
12292
 
12346
- var Group = /*#__PURE__*/function (_DisplayObject) {
12347
- _inheritsLoose(Group, _DisplayObject);
12293
+ var target = (_this$effect = this.effect) === null || _this$effect === void 0 ? void 0 : _this$effect.target;
12294
+ return target.getAnimations();
12295
+ };
12348
12296
 
12349
- function Group(_temp) {
12350
- var _ref = _temp === void 0 ? {} : _temp,
12351
- style = _ref.style,
12352
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
12297
+ _proto.markTarget = function markTarget() {
12298
+ var animations = this.targetAnimations();
12353
12299
 
12354
- return _DisplayObject.call(this, _extends({
12355
- type: exports.Shape.GROUP,
12356
- style: _extends({
12357
- x: '',
12358
- y: '',
12359
- width: '',
12360
- height: ''
12361
- }, style)
12362
- }, rest)) || this;
12363
- }
12300
+ if (animations.indexOf(this) === -1) {
12301
+ animations.push(this);
12302
+ }
12303
+ };
12364
12304
 
12365
- return Group;
12366
- }(DisplayObject);
12305
+ _proto.unmarkTarget = function unmarkTarget() {
12306
+ var animations = this.targetAnimations();
12307
+ var index = animations.indexOf(this);
12367
12308
 
12368
- var _excluded$4 = ["style"];
12369
- var Image = /*#__PURE__*/function (_DisplayObject) {
12370
- _inheritsLoose(Image, _DisplayObject);
12309
+ if (index !== -1) {
12310
+ animations.splice(index, 1);
12311
+ }
12312
+ };
12371
12313
 
12372
- function Image(_temp) {
12373
- var _ref = _temp === void 0 ? {} : _temp,
12374
- style = _ref.style,
12375
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
12314
+ _proto.tick = function tick(timelineTime, isAnimationFrame) {
12315
+ if (!this._idle && !this._paused) {
12316
+ if (this._startTime === null) {
12317
+ if (isAnimationFrame) {
12318
+ this.startTime = timelineTime - this._currentTime / this.playbackRate;
12319
+ }
12320
+ } else if (!this._isFinished) {
12321
+ this.tickCurrentTime((timelineTime - this._startTime) * this.playbackRate);
12322
+ }
12323
+ }
12376
12324
 
12377
- return _DisplayObject.call(this, _extends({
12378
- type: exports.Shape.IMAGE,
12379
- style: _extends({
12380
- x: '',
12381
- y: '',
12382
- img: '',
12383
- width: '',
12384
- height: ''
12385
- }, style)
12386
- }, rest)) || this;
12387
- }
12325
+ if (isAnimationFrame) {
12326
+ this.currentTimePending = false;
12327
+ this.fireEvents(timelineTime);
12328
+ }
12329
+ };
12388
12330
 
12389
- return Image;
12390
- }(DisplayObject);
12331
+ _proto.rewind = function rewind() {
12332
+ if (this.playbackRate >= 0) {
12333
+ this.currentTime = 0;
12334
+ } else if (this.totalDuration < Infinity) {
12335
+ this.currentTime = this.totalDuration;
12336
+ } else {
12337
+ throw new Error('Unable to rewind negative playback rate animation with infinite duration');
12338
+ }
12339
+ };
12391
12340
 
12392
- var _excluded$5 = ["style"];
12393
- var Line = /*#__PURE__*/function (_DisplayObject) {
12394
- _inheritsLoose(Line, _DisplayObject);
12341
+ _proto.persist = function persist() {
12342
+ throw new Error('Method not implemented.');
12343
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
12344
+ ;
12395
12345
 
12396
- function Line(_temp) {
12397
- var _ref = _temp === void 0 ? {} : _temp,
12398
- style = _ref.style,
12399
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
12346
+ _proto.addEventListener = function addEventListener(type, listener, options) {
12347
+ throw new Error('Method not implemented.');
12348
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
12349
+ ;
12400
12350
 
12401
- return _DisplayObject.call(this, _extends({
12402
- type: exports.Shape.LINE,
12403
- style: _extends({
12404
- x1: 0,
12405
- y1: 0,
12406
- x2: 0,
12407
- y2: 0,
12408
- z1: 0,
12409
- z2: 0,
12410
- isBillboard: false
12411
- }, style)
12412
- }, rest)) || this;
12413
- }
12351
+ _proto.removeEventListener = function removeEventListener(type, listener, options) {
12352
+ throw new Error('Method not implemented.');
12353
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
12354
+ ;
12414
12355
 
12415
- var _proto = Line.prototype;
12356
+ _proto.dispatchEvent = function dispatchEvent(event) {
12357
+ throw new Error('Method not implemented.');
12358
+ };
12416
12359
 
12417
- _proto.getPoint = function getPoint(ratio) {
12418
- // TODO: account for z1/z2 in 3D line
12419
- var _this$parsedStyle = this.parsedStyle,
12420
- x1 = _this$parsedStyle.x1,
12421
- y1 = _this$parsedStyle.y1,
12422
- x2 = _this$parsedStyle.x2,
12423
- y2 = _this$parsedStyle.y2,
12424
- defX = _this$parsedStyle.defX,
12425
- defY = _this$parsedStyle.defY;
12360
+ // replaceState: AnimationReplaceState;
12361
+ _proto.commitStyles = function commitStyles() {
12362
+ throw new Error('Method not implemented.');
12363
+ };
12364
+
12365
+ _proto.ensureAlive = function ensureAlive() {
12366
+ // If an animation is playing backwards and is not fill backwards/both
12367
+ // then it should go out of effect when it reaches the start of its
12368
+ // active interval (currentTime === 0).
12369
+ if (this.playbackRate < 0 && this.currentTime === 0) {
12370
+ var _this$effect2;
12426
12371
 
12427
- var _LineUtil$pointAt = gMath.Line.pointAt(x1.value, y1.value, x2.value, y2.value, ratio),
12428
- x = _LineUtil$pointAt.x,
12429
- y = _LineUtil$pointAt.y;
12372
+ this._inEffect = !!((_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.update(-1));
12373
+ } else {
12374
+ var _this$effect3;
12430
12375
 
12431
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12376
+ this._inEffect = !!((_this$effect3 = this.effect) === null || _this$effect3 === void 0 ? void 0 : _this$effect3.update(this.currentTime));
12377
+ }
12432
12378
 
12433
- return new Point(transformed[0], transformed[1]);
12379
+ if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) {
12380
+ this._inTimeline = true;
12381
+ this.timeline.animations.push(this);
12382
+ }
12434
12383
  };
12435
12384
 
12436
- _proto.getTotalLength = function getTotalLength() {
12437
- // TODO: account for z1/z2 in 3D line
12438
- var _this$parsedStyle2 = this.parsedStyle,
12439
- x1 = _this$parsedStyle2.x1,
12440
- y1 = _this$parsedStyle2.y1,
12441
- x2 = _this$parsedStyle2.x2,
12442
- y2 = _this$parsedStyle2.y2;
12443
- return gMath.Line.length(x1.value, y1.value, x2.value, y2.value);
12385
+ _proto.tickCurrentTime = function tickCurrentTime(newTime, ignoreLimit) {
12386
+ if (newTime !== this._currentTime) {
12387
+ this._currentTime = newTime;
12388
+
12389
+ if (this._isFinished && !ignoreLimit) {
12390
+ this._currentTime = this._playbackRate > 0 ? this.totalDuration : 0;
12391
+ }
12392
+
12393
+ this.ensureAlive();
12394
+ }
12444
12395
  };
12445
12396
 
12446
- return Line;
12447
- }(DisplayObject);
12397
+ _proto.fireEvents = function fireEvents(baseTime) {
12398
+ var _this = this;
12448
12399
 
12449
- var _excluded$6 = ["style"];
12450
- var Path = /*#__PURE__*/function (_DisplayObject) {
12451
- _inheritsLoose(Path, _DisplayObject);
12400
+ if (this._isFinished) {
12401
+ if (!this._finishedFlag) {
12402
+ if (this.onfinish) {
12403
+ var event = new AnimationEvent(null, this, this.currentTime, baseTime);
12404
+ setTimeout(function () {
12405
+ if (_this.onfinish) {
12406
+ _this.onfinish(event);
12407
+ }
12408
+ });
12409
+ }
12452
12410
 
12453
- function Path(_temp) {
12454
- var _ref = _temp === void 0 ? {} : _temp,
12455
- style = _ref.style,
12456
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
12411
+ this._finishedFlag = true;
12412
+ }
12413
+ } else {
12414
+ if (this.onframe && this.playState === 'running') {
12415
+ var _event = new AnimationEvent(null, this, this.currentTime, baseTime);
12457
12416
 
12458
- return _DisplayObject.call(this, _extends({
12459
- type: exports.Shape.PATH,
12460
- style: _extends({
12461
- path: '',
12462
- miterLimit: 4
12463
- }, style)
12464
- }, rest)) || this;
12465
- }
12417
+ this.onframe(_event);
12418
+ }
12466
12419
 
12467
- var _proto = Path.prototype;
12420
+ this._finishedFlag = false;
12421
+ }
12422
+ };
12468
12423
 
12469
- _proto.getTotalLength = function getTotalLength() {
12470
- return this.parsedStyle.path.totalLength;
12471
- }
12472
- /**
12473
- * Get point according to ratio
12474
- */
12475
- ;
12424
+ _createClass(Animation, [{
12425
+ key: "pending",
12426
+ get:
12427
+ /**
12428
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/effect
12429
+ */
12476
12430
 
12477
- _proto.getPoint = function getPoint(ratio) {
12478
- var _this$parsedStyle = this.parsedStyle,
12479
- defX = _this$parsedStyle.defX,
12480
- defY = _this$parsedStyle.defY,
12481
- _this$parsedStyle$pat = _this$parsedStyle.path,
12482
- totalLength = _this$parsedStyle$pat.totalLength,
12483
- absolutePath = _this$parsedStyle$pat.absolutePath;
12431
+ /**
12432
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/timeline
12433
+ */
12484
12434
 
12485
- var _getPointAtLength = util.getPointAtLength(absolutePath, ratio * totalLength),
12486
- x = _getPointAtLength.x,
12487
- y = _getPointAtLength.y;
12435
+ /**
12436
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/id
12437
+ */
12438
+ // animation: InternalAnimation | null;
12488
12439
 
12489
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12440
+ /**
12441
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending
12442
+ */
12443
+ function get() {
12444
+ return this._startTime === null && !this._paused && this.playbackRate !== 0 || this.currentTimePending;
12445
+ }
12446
+ }, {
12447
+ key: "playState",
12448
+ get: function get() {
12449
+ if (this._idle) return 'idle';
12450
+ if (this._isFinished) return 'finished';
12451
+ if (this._paused) return 'paused';
12452
+ return 'running';
12453
+ }
12454
+ /**
12455
+ * record previos state
12456
+ */
12490
12457
 
12491
- return new Point(transformed[0], transformed[1]);
12492
- }
12493
- /**
12494
- * Get start tangent vector
12495
- */
12496
- ;
12458
+ }, {
12459
+ key: "ready",
12460
+ get:
12461
+ /**
12462
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/ready
12463
+ * @example
12464
+ animation.pause();
12465
+ animation.ready.then(function() {
12466
+ // Displays 'running'
12467
+ alert(animation.playState);
12468
+ });
12469
+ animation.play();
12470
+ */
12471
+ function get() {
12472
+ var _this2 = this;
12497
12473
 
12498
- _proto.getStartTangent = function getStartTangent() {
12499
- var segments = this.parsedStyle.path.segments;
12500
- var result = [];
12474
+ if (!this.readyPromise) {
12475
+ if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
12476
+ this.timeline.animationsWithPromises.push(this);
12477
+ }
12501
12478
 
12502
- if (segments.length > 1) {
12503
- var startPoint = segments[0].currentPoint;
12504
- var endPoint = segments[1].currentPoint;
12505
- var tangent = segments[1].startTangent;
12506
- result = [];
12479
+ this.readyPromise = new Promise(function (resolve, reject) {
12480
+ _this2.resolveReadyPromise = function () {
12481
+ resolve(_this2);
12482
+ };
12507
12483
 
12508
- if (tangent) {
12509
- result.push([startPoint[0] - tangent[0], startPoint[1] - tangent[1]]);
12510
- result.push([startPoint[0], startPoint[1]]);
12511
- } else {
12512
- result.push([endPoint[0], endPoint[1]]);
12513
- result.push([startPoint[0], startPoint[1]]);
12484
+ _this2.rejectReadyPromise = function () {
12485
+ reject(new Error());
12486
+ };
12487
+ });
12488
+
12489
+ if (!this.pending) {
12490
+ this.resolveReadyPromise();
12491
+ }
12514
12492
  }
12493
+
12494
+ return this.readyPromise;
12515
12495
  }
12496
+ /**
12497
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/finished
12498
+ * @example
12499
+ Promise.all(
12500
+ elem.getAnimations().map(
12501
+ function(animation) {
12502
+ return animation.finished
12503
+ }
12504
+ )
12505
+ ).then(
12506
+ function() {
12507
+ return elem.remove();
12508
+ }
12509
+ );
12510
+ */
12516
12511
 
12517
- return result;
12518
- }
12519
- /**
12520
- * Get end tangent vector
12521
- */
12522
- ;
12512
+ }, {
12513
+ key: "finished",
12514
+ get: function get() {
12515
+ var _this3 = this;
12523
12516
 
12524
- _proto.getEndTangent = function getEndTangent() {
12525
- var segments = this.parsedStyle.path.segments;
12526
- var length = segments.length;
12527
- var result = [];
12517
+ if (!this.finishedPromise) {
12518
+ if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
12519
+ this.timeline.animationsWithPromises.push(this);
12520
+ }
12528
12521
 
12529
- if (length > 1) {
12530
- var startPoint = segments[length - 2].currentPoint;
12531
- var endPoint = segments[length - 1].currentPoint;
12532
- var tangent = segments[length - 1].endTangent;
12533
- result = [];
12522
+ this.finishedPromise = new Promise(function (resolve, reject) {
12523
+ _this3.resolveFinishedPromise = function () {
12524
+ resolve(_this3);
12525
+ };
12534
12526
 
12535
- if (tangent) {
12536
- result.push([endPoint[0] - tangent[0], endPoint[1] - tangent[1]]);
12537
- result.push([endPoint[0], endPoint[1]]);
12538
- } else {
12539
- result.push([startPoint[0], startPoint[1]]);
12540
- result.push([endPoint[0], endPoint[1]]);
12541
- }
12542
- }
12527
+ _this3.rejectFinishedPromise = function () {
12528
+ reject(new Error());
12529
+ };
12530
+ });
12543
12531
 
12544
- return result;
12545
- };
12532
+ if (this.playState === 'finished') {
12533
+ this.resolveFinishedPromise();
12534
+ }
12535
+ }
12546
12536
 
12547
- return Path;
12548
- }(DisplayObject);
12537
+ return this.finishedPromise;
12538
+ }
12539
+ /**
12540
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/onfinish
12541
+ */
12549
12542
 
12550
- var _excluded$7 = ["style"];
12551
- var Polygon = /*#__PURE__*/function (_DisplayObject) {
12552
- _inheritsLoose(Polygon, _DisplayObject);
12543
+ }, {
12544
+ key: "currentTime",
12545
+ get:
12546
+ /**
12547
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
12548
+ */
12549
+ function get() {
12550
+ this.updatePromises();
12551
+ return this._idle || this.currentTimePending ? null : this._currentTime;
12552
+ },
12553
+ set: function set(newTime) {
12554
+ newTime = Number(newTime);
12555
+ if (isNaN(newTime)) return;
12556
+ this.timeline.restart();
12553
12557
 
12554
- function Polygon(_temp) {
12555
- var _ref = _temp === void 0 ? {} : _temp,
12556
- style = _ref.style,
12557
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
12558
+ if (!this._paused && this._startTime !== null) {
12559
+ var _this$timeline;
12558
12560
 
12559
- return _DisplayObject.call(this, _extends({
12560
- type: exports.Shape.POLYGON,
12561
- style: _extends({
12562
- points: '',
12563
- miterLimit: 4
12564
- }, style)
12565
- }, rest)) || this;
12566
- }
12561
+ this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate;
12562
+ }
12567
12563
 
12568
- return Polygon;
12569
- }(DisplayObject);
12564
+ this.currentTimePending = false;
12570
12565
 
12571
- var _excluded$8 = ["style"];
12572
- var Polyline = /*#__PURE__*/function (_DisplayObject) {
12573
- _inheritsLoose(Polyline, _DisplayObject);
12566
+ if (this._currentTime === newTime) {
12567
+ return;
12568
+ }
12574
12569
 
12575
- function Polyline(_temp) {
12576
- var _ref = _temp === void 0 ? {} : _temp,
12577
- style = _ref.style,
12578
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
12570
+ if (this._idle) {
12571
+ this._idle = false;
12572
+ this._paused = true;
12573
+ }
12579
12574
 
12580
- return _DisplayObject.call(this, _extends({
12581
- type: exports.Shape.POLYLINE,
12582
- style: _extends({
12583
- points: '',
12584
- miterLimit: 4
12585
- }, style)
12586
- }, rest)) || this;
12587
- }
12575
+ this.tickCurrentTime(newTime, true);
12576
+ this.timeline.applyDirtiedAnimation(this);
12577
+ }
12578
+ /**
12579
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/startTime
12580
+ */
12588
12581
 
12589
- var _proto = Polyline.prototype;
12582
+ }, {
12583
+ key: "startTime",
12584
+ get: function get() {
12585
+ return this._startTime;
12586
+ },
12587
+ set: function set(newTime) {
12588
+ if (newTime !== null) {
12589
+ this.updatePromises();
12590
+ newTime = Number(newTime);
12591
+ if (isNaN(newTime)) return;
12592
+ if (this._paused || this._idle) return;
12593
+ this._startTime = newTime;
12594
+ this.tickCurrentTime((Number(this.timeline.currentTime) - this._startTime) * this.playbackRate);
12595
+ this.timeline.applyDirtiedAnimation(this);
12596
+ this.updatePromises();
12597
+ }
12598
+ }
12599
+ }, {
12600
+ key: "playbackRate",
12601
+ get: function get() {
12602
+ return this._playbackRate;
12603
+ },
12604
+ set: function set(value) {
12605
+ if (value === this._playbackRate) {
12606
+ return;
12607
+ }
12590
12608
 
12591
- _proto.getTotalLength = function getTotalLength() {
12592
- return this.parsedStyle.points.totalLength;
12593
- };
12609
+ this.updatePromises();
12610
+ var oldCurrentTime = this.currentTime;
12611
+ this._playbackRate = value;
12612
+ this.startTime = null;
12594
12613
 
12595
- _proto.getPoint = function getPoint(ratio) {
12596
- var _this$parsedStyle = this.parsedStyle,
12597
- defX = _this$parsedStyle.defX,
12598
- defY = _this$parsedStyle.defY,
12599
- _this$parsedStyle$poi = _this$parsedStyle.points,
12600
- points = _this$parsedStyle$poi.points,
12601
- segments = _this$parsedStyle$poi.segments;
12602
- var subt = 0;
12603
- var index = 0;
12604
- segments.forEach(function (v, i) {
12605
- if (ratio >= v[0] && ratio <= v[1]) {
12606
- subt = (ratio - v[0]) / (v[1] - v[0]);
12607
- index = i;
12614
+ if (this.playState !== 'paused' && this.playState !== 'idle') {
12615
+ this._finishedFlag = false;
12616
+ this._idle = false;
12617
+ this.ensureAlive();
12618
+ this.timeline.applyDirtiedAnimation(this);
12608
12619
  }
12609
- });
12610
12620
 
12611
- var _LineUtil$pointAt = gMath.Line.pointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt),
12612
- x = _LineUtil$pointAt.x,
12613
- y = _LineUtil$pointAt.y;
12621
+ if (oldCurrentTime !== null) {
12622
+ this.currentTime = oldCurrentTime;
12623
+ }
12614
12624
 
12615
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12625
+ this.updatePromises();
12626
+ }
12627
+ }, {
12628
+ key: "_isFinished",
12629
+ get: function get() {
12630
+ return !this._idle && (this._playbackRate > 0 && Number(this._currentTime) >= this.totalDuration || this._playbackRate < 0 && Number(this._currentTime) <= 0);
12631
+ }
12632
+ }, {
12633
+ key: "totalDuration",
12634
+ get: function get() {
12635
+ var _this$effect4;
12616
12636
 
12617
- return new Point(transformed[0], transformed[1]);
12618
- };
12637
+ return Number((_this$effect4 = this.effect) === null || _this$effect4 === void 0 ? void 0 : _this$effect4.getComputedTiming().endTime);
12638
+ }
12639
+ }, {
12640
+ key: "_needsTick",
12641
+ get: function get() {
12642
+ return this.pending || this.playState === 'running' || !this._finishedFlag;
12643
+ }
12644
+ }]);
12619
12645
 
12620
- _proto.getStartTangent = function getStartTangent() {
12621
- var points = this.parsedStyle.points.points;
12622
- var result = [];
12623
- result.push([points[1][0], points[1][1]]);
12624
- result.push([points[0][0], points[0][1]]);
12625
- return result;
12626
- };
12646
+ return Animation;
12647
+ }();
12627
12648
 
12628
- _proto.getEndTangent = function getEndTangent() {
12629
- var points = this.parsedStyle.points.points;
12630
- var l = points.length - 1;
12631
- var result = [];
12632
- result.push([points[l - 1][0], points[l - 1][1]]);
12633
- result.push([points[l][0], points[l][1]]);
12634
- return result;
12635
- };
12649
+ function compareAnimations(leftAnimation, rightAnimation) {
12650
+ return Number(leftAnimation.id) - Number(rightAnimation.id);
12651
+ }
12652
+ /**
12653
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web-animations-js/index.d.ts
12654
+ */
12636
12655
 
12637
- return Polyline;
12638
- }(DisplayObject);
12656
+ var AnimationTimeline = /*#__PURE__*/function () {
12657
+ /**
12658
+ * all active animations
12659
+ */
12660
+ function AnimationTimeline(document) {
12661
+ var _this = this;
12639
12662
 
12640
- var _excluded$9 = ["style"];
12641
- var Rect = /*#__PURE__*/function (_DisplayObject) {
12642
- _inheritsLoose(Rect, _DisplayObject);
12663
+ this.document = void 0;
12664
+ this.animations = [];
12665
+ this.ticking = false;
12666
+ this.timelineTicking = false;
12667
+ this.hasRestartedThisFrame = false;
12668
+ this.animationsWithPromises = [];
12669
+ this.inTick = false;
12670
+ this.pendingEffects = [];
12671
+ this.currentTime = null;
12672
+ this.rafId = 0;
12673
+ this.rafCallbacks = [];
12674
+ this.frameId = void 0;
12643
12675
 
12644
- function Rect(_temp) {
12645
- var _ref = _temp === void 0 ? {} : _temp,
12646
- style = _ref.style,
12647
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$9);
12676
+ this.webAnimationsNextTick = function (t) {
12677
+ _this.currentTime = t;
12648
12678
 
12649
- return _DisplayObject.call(this, _extends({
12650
- type: exports.Shape.RECT,
12651
- style: _extends({
12652
- x: '',
12653
- y: '',
12654
- width: '',
12655
- height: '',
12656
- radius: ''
12657
- }, style)
12658
- }, rest)) || this;
12659
- }
12679
+ _this.discardAnimations();
12660
12680
 
12661
- return Rect;
12662
- }(DisplayObject);
12681
+ if (_this.animations.length === 0) {
12682
+ _this.timelineTicking = false;
12683
+ } else {
12684
+ _this.requestAnimationFrame(_this.webAnimationsNextTick);
12685
+ }
12686
+ };
12663
12687
 
12664
- var _excluded$a = ["style"];
12665
- /**
12666
- * <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
12667
- */
12688
+ this.processRafCallbacks = function (t) {
12689
+ var processing = _this.rafCallbacks;
12690
+ _this.rafCallbacks = [];
12691
+ if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
12668
12692
 
12669
- var Text = /*#__PURE__*/function (_DisplayObject) {
12670
- _inheritsLoose(Text, _DisplayObject);
12693
+ _this.animations.sort(compareAnimations);
12671
12694
 
12672
- /**
12673
- * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants
12674
- */
12675
- function Text(_temp) {
12676
- var _this;
12695
+ _this.animations = _this.tick(t, true, _this.animations)[0];
12696
+ processing.forEach(function (entry) {
12697
+ entry[1](t);
12698
+ });
12677
12699
 
12678
- var _ref = _temp === void 0 ? {} : _temp,
12679
- style = _ref.style,
12680
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
12700
+ _this.applyPendingEffects();
12701
+ };
12681
12702
 
12682
- _this = _DisplayObject.call(this, _extends({
12683
- type: exports.Shape.TEXT,
12684
- style: _extends({
12685
- x: '',
12686
- y: '',
12687
- text: '',
12688
- fontSize: '',
12689
- fontFamily: '',
12690
- fontStyle: '',
12691
- fontWeight: '',
12692
- fontVariant: '',
12693
- textAlign: '',
12694
- textBaseline: '',
12695
- textTransform: '',
12696
- // dropShadow: false,
12697
- // dropShadowAlpha: 1,
12698
- // dropShadowAngle: Math.PI / 6,
12699
- // dropShadowBlur: 0,
12700
- // dropShadowColor: '#000',
12701
- // dropShadowDistance: 5,
12702
- fill: 'black',
12703
- // stroke: 'black',
12704
- letterSpacing: 0,
12705
- lineHeight: 0,
12706
- miterLimit: 10,
12707
- whiteSpace: 'pre',
12708
- wordWrap: false,
12709
- wordWrapWidth: 0,
12710
- leading: 0,
12711
- dx: '',
12712
- dy: ''
12713
- }, style)
12714
- }, rest)) || this;
12715
- _this.LENGTHADJUST_SPACING = 1;
12716
- _this.LENGTHADJUST_SPACINGANDGLYPHS = 2;
12717
- _this.LENGTHADJUST_UNKNOWN = 0;
12718
- _this.lengthAdjust = void 0;
12719
- _this.textLength = void 0;
12720
- return _this;
12703
+ this.document = document;
12721
12704
  }
12722
12705
 
12723
- var _proto = Text.prototype;
12706
+ var _proto = AnimationTimeline.prototype;
12707
+
12708
+ _proto.getAnimations = function getAnimations() {
12709
+ this.discardAnimations();
12710
+ return this.animations.slice();
12711
+ };
12712
+
12713
+ _proto.isTicking = function isTicking() {
12714
+ return this.inTick;
12715
+ };
12724
12716
 
12725
- _proto.getCharNumAtPosition = function getCharNumAtPosition(point) {
12726
- throw new Error('Method not implemented.');
12727
- }
12728
- /**
12729
- * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
12730
- */
12717
+ _proto.play = function play(effect) {
12718
+ var animation = new Animation(effect, this);
12719
+ this.animations.push(animation);
12720
+ this.restartWebAnimationsNextTick();
12721
+ animation.updatePromises();
12722
+ animation.play();
12723
+ animation.updatePromises();
12724
+ return animation;
12725
+ } // RAF is supposed to be the last script to occur before frame rendering but not
12726
+ // all browsers behave like this. This function is for synchonously updating an
12727
+ // animation's effects whenever its state is mutated by script to work around
12728
+ // incorrect script execution ordering by the browser.
12731
12729
  ;
12732
12730
 
12733
- _proto.getComputedTextLength = function getComputedTextLength() {
12734
- var _this$parsedStyle$met;
12731
+ _proto.applyDirtiedAnimation = function applyDirtiedAnimation(animation) {
12732
+ var _this2 = this;
12735
12733
 
12736
- return ((_this$parsedStyle$met = this.parsedStyle.metrics) === null || _this$parsedStyle$met === void 0 ? void 0 : _this$parsedStyle$met.maxLineWidth) || 0;
12737
- };
12734
+ if (this.inTick) {
12735
+ return;
12736
+ } // update active animations in displayobject
12738
12737
 
12739
- _proto.getEndPositionOfChar = function getEndPositionOfChar(charnum) {
12740
- throw new Error('Method not implemented.');
12741
- };
12742
12738
 
12743
- _proto.getExtentOfChar = function getExtentOfChar(charnum) {
12744
- throw new Error('Method not implemented.');
12745
- };
12739
+ animation.markTarget();
12740
+ var animations = animation.targetAnimations();
12741
+ animations.sort(compareAnimations); // clear inactive animations
12746
12742
 
12747
- _proto.getNumberOfChars = function getNumberOfChars() {
12748
- throw new Error('Method not implemented.');
12749
- };
12743
+ var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1];
12744
+ inactiveAnimations.forEach(function (animation) {
12745
+ var index = _this2.animations.indexOf(animation);
12750
12746
 
12751
- _proto.getRotationOfChar = function getRotationOfChar(charnum) {
12752
- throw new Error('Method not implemented.');
12747
+ if (index !== -1) {
12748
+ _this2.animations.splice(index, 1);
12749
+ }
12750
+ });
12751
+ this.applyPendingEffects();
12753
12752
  };
12754
12753
 
12755
- _proto.getStartPositionOfChar = function getStartPositionOfChar(charnum) {
12756
- throw new Error('Method not implemented.');
12757
- };
12754
+ _proto.restart = function restart() {
12755
+ if (!this.ticking) {
12756
+ this.ticking = true;
12757
+ this.requestAnimationFrame(function () {});
12758
+ this.hasRestartedThisFrame = true;
12759
+ }
12758
12760
 
12759
- _proto.getSubStringLength = function getSubStringLength(charnum, nchars) {
12760
- throw new Error('Method not implemented.');
12761
+ return this.hasRestartedThisFrame;
12761
12762
  };
12762
12763
 
12763
- _proto.selectSubString = function selectSubString(charnum, nchars) {
12764
- throw new Error('Method not implemented.');
12764
+ _proto.destroy = function destroy() {
12765
+ this.document.defaultView.cancelAnimationFrame(this.frameId);
12765
12766
  };
12766
12767
 
12767
- _proto.getLineBoundingRects = function getLineBoundingRects() {
12768
- var _this$parsedStyle$met2;
12769
-
12770
- return ((_this$parsedStyle$met2 = this.parsedStyle.metrics) === null || _this$parsedStyle$met2 === void 0 ? void 0 : _this$parsedStyle$met2.lineMetrics) || [];
12768
+ _proto.applyPendingEffects = function applyPendingEffects() {
12769
+ this.pendingEffects.forEach(function (effect) {
12770
+ effect === null || effect === void 0 ? void 0 : effect.applyInterpolations();
12771
+ });
12772
+ this.pendingEffects = [];
12771
12773
  };
12772
12774
 
12773
- return Text;
12774
- }(DisplayObject);
12775
-
12776
- var _excluded$b = ["style"];
12777
- /**
12778
- * HTML container
12779
- * @see https://github.com/pmndrs/drei#html
12780
- */
12775
+ _proto.updateAnimationsPromises = function updateAnimationsPromises() {
12776
+ this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) {
12777
+ return animation.updatePromises();
12778
+ });
12779
+ };
12781
12780
 
12782
- var HTML = /*#__PURE__*/function (_DisplayObject) {
12783
- _inheritsLoose(HTML, _DisplayObject);
12781
+ _proto.discardAnimations = function discardAnimations() {
12782
+ this.updateAnimationsPromises();
12783
+ this.animations = this.animations.filter(function (animation) {
12784
+ return animation.playState !== 'finished' && animation.playState !== 'idle';
12785
+ });
12786
+ };
12784
12787
 
12785
- function HTML(_temp) {
12786
- var _this;
12788
+ _proto.restartWebAnimationsNextTick = function restartWebAnimationsNextTick() {
12789
+ if (!this.timelineTicking) {
12790
+ this.timelineTicking = true;
12791
+ this.requestAnimationFrame(this.webAnimationsNextTick);
12792
+ }
12793
+ };
12787
12794
 
12788
- var _ref = _temp === void 0 ? {} : _temp,
12789
- style = _ref.style,
12790
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$b);
12795
+ _proto.rAF = function rAF(f) {
12796
+ var id = this.rafId++;
12791
12797
 
12792
- _this = _DisplayObject.call(this, _extends({
12793
- type: exports.Shape.HTML,
12794
- style: _extends({
12795
- x: '',
12796
- y: '',
12797
- width: 'auto',
12798
- height: 'auto',
12799
- innerHTML: ''
12800
- }, style)
12801
- }, rest)) || this;
12802
- _this.cullable.enable = false;
12803
- return _this;
12804
- }
12805
- /**
12806
- * return wrapper HTMLElement
12807
- * * <div> in g-webgl/canvas
12808
- * * <foreignObject> in g-svg
12809
- */
12798
+ if (this.rafCallbacks.length === 0) {
12799
+ this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks);
12800
+ }
12810
12801
 
12802
+ this.rafCallbacks.push([id, f]);
12803
+ return id;
12804
+ };
12811
12805
 
12812
- var _proto = HTML.prototype;
12806
+ _proto.requestAnimationFrame = function requestAnimationFrame(f) {
12807
+ var _this3 = this;
12813
12808
 
12814
- _proto.getDomElement = function getDomElement() {
12815
- return this.parsedStyle.$el;
12816
- }
12817
- /**
12818
- * override with $el.getBoundingClientRect
12819
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
12820
- */
12821
- ;
12809
+ return this.rAF(function (x) {
12810
+ _this3.updateAnimationsPromises();
12822
12811
 
12823
- _proto.getBoundingClientRect = function getBoundingClientRect() {
12824
- return this.parsedStyle.$el.getBoundingClientRect();
12825
- };
12812
+ f(x);
12826
12813
 
12827
- _proto.getClientRects = function getClientRects() {
12828
- return [this.getBoundingClientRect()];
12814
+ _this3.updateAnimationsPromises();
12815
+ });
12829
12816
  };
12830
12817
 
12831
- _proto.getBounds = function getBounds() {
12832
- var _this$ownerDocument, _this$ownerDocument$d;
12818
+ _proto.tick = function tick(t, isAnimationFrame, updatingAnimations) {
12819
+ var _this4 = this,
12820
+ _this$pendingEffects,
12821
+ _this$pendingEffects2;
12833
12822
 
12834
- var clientRect = this.getBoundingClientRect(); // calc context's offset
12835
- // @ts-ignore
12823
+ this.inTick = true;
12824
+ this.hasRestartedThisFrame = false;
12825
+ this.currentTime = t;
12826
+ this.ticking = false;
12827
+ var newPendingClears = [];
12828
+ var newPendingEffects = [];
12829
+ var activeAnimations = [];
12830
+ var inactiveAnimations = [];
12831
+ updatingAnimations.forEach(function (animation) {
12832
+ animation.tick(t, isAnimationFrame);
12836
12833
 
12837
- var canvasRect = (_this$ownerDocument = this.ownerDocument) === null || _this$ownerDocument === void 0 ? void 0 : (_this$ownerDocument$d = _this$ownerDocument.defaultView) === null || _this$ownerDocument$d === void 0 ? void 0 : _this$ownerDocument$d.getContextService().getBoundingClientRect();
12834
+ if (!animation._inEffect) {
12835
+ newPendingClears.push(animation.effect);
12836
+ animation.unmarkTarget();
12837
+ } else {
12838
+ newPendingEffects.push(animation.effect);
12839
+ animation.markTarget();
12840
+ }
12838
12841
 
12839
- if (canvasRect) {
12840
- var minX = clientRect.left - canvasRect.left;
12841
- var minY = clientRect.top - canvasRect.top;
12842
- var aabb = new AABB();
12843
- aabb.setMinMax(glMatrix.vec3.fromValues(minX, minY, 0), glMatrix.vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0));
12844
- return aabb;
12845
- }
12842
+ if (animation._needsTick) _this4.ticking = true;
12843
+ var alive = animation._inEffect || animation._needsTick;
12844
+ animation._inTimeline = alive;
12846
12845
 
12847
- return null;
12848
- };
12846
+ if (alive) {
12847
+ activeAnimations.push(animation);
12848
+ } else {
12849
+ inactiveAnimations.push(animation);
12850
+ }
12851
+ });
12849
12852
 
12850
- _proto.getLocalBounds = function getLocalBounds() {
12851
- if (this.parentNode) {
12852
- var parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), this.parentNode.getWorldTransform());
12853
- var bounds = this.getBounds();
12853
+ (_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears);
12854
12854
 
12855
- if (!AABB.isEmpty(bounds)) {
12856
- var localBounds = new AABB();
12857
- localBounds.setFromTransformedAABB(bounds, parentInvert);
12858
- return localBounds;
12859
- }
12860
- }
12855
+ (_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects);
12861
12856
 
12862
- return this.getBounds();
12857
+ if (this.ticking) this.requestAnimationFrame(function () {});
12858
+ this.inTick = false;
12859
+ return [activeAnimations, inactiveAnimations];
12863
12860
  };
12864
12861
 
12865
- return HTML;
12866
- }(DisplayObject);
12862
+ return AnimationTimeline;
12863
+ }();
12867
12864
 
12868
12865
  /**
12869
12866
  * the entry of DOM tree
@@ -12898,7 +12895,7 @@ var Document = /*#__PURE__*/function (_Node) {
12898
12895
  defaultValue = _ref.defaultValue;
12899
12896
 
12900
12897
  if (inherited && defaultValue) {
12901
- initialStyle[name] = defaultValue;
12898
+ initialStyle[name] = isFunction(defaultValue) ? defaultValue(exports.Shape.GROUP) : defaultValue;
12902
12899
  }
12903
12900
  }); // like <html> in DOM tree
12904
12901
 
@@ -12918,7 +12915,12 @@ var Document = /*#__PURE__*/function (_Node) {
12918
12915
  * @example const circle = document.createElement('circle', { style: { r: 10 } });
12919
12916
  */
12920
12917
  _proto.createElement = function createElement(tagName, options) {
12921
- // d3 will use <tspan>
12918
+ // @observablehq/plot will create <svg>
12919
+ if (tagName === 'svg') {
12920
+ return this.documentElement;
12921
+ } // d3 will use <tspan>
12922
+
12923
+
12922
12924
  var clazz = this.defaultView.customElements.get(tagName);
12923
12925
 
12924
12926
  if (!clazz) {
@@ -12926,7 +12928,9 @@ var Document = /*#__PURE__*/function (_Node) {
12926
12928
  clazz = tagName === 'tspan' ? Text : Group;
12927
12929
  }
12928
12930
 
12929
- return new clazz(options);
12931
+ var shape = new clazz(options);
12932
+ shape.ownerDocument = this;
12933
+ return shape;
12930
12934
  };
12931
12935
 
12932
12936
  _proto.createElementNS = function createElementNS(namespaceURI, tagName, options) {
@@ -16576,20 +16580,15 @@ exports.RenderingService = /*#__PURE__*/function () {
16576
16580
 
16577
16581
  if (this.renderingContext.renderReasons.size && this.inited) {
16578
16582
  this.renderDisplayObject(this.renderingContext.root, canvasConfig);
16583
+ this.hooks.beginFrame.call();
16584
+ this.renderingContext.renderListCurrentFrame.forEach(function (object) {
16585
+ _this2.hooks.beforeRender.call(object);
16579
16586
 
16580
- if (this.renderingContext.renderListCurrentFrame.length || this.renderingContext.renderListLastFrame.length !== this.renderingContext.renderListCurrentFrame.length) {
16581
- this.hooks.beginFrame.call();
16582
- this.renderingContext.renderListCurrentFrame.forEach(function (object) {
16583
- _this2.hooks.beforeRender.call(object);
16584
-
16585
- _this2.hooks.render.call(object);
16586
-
16587
- _this2.hooks.afterRender.call(object);
16588
- });
16589
- this.hooks.endFrame.call();
16590
- }
16587
+ _this2.hooks.render.call(object);
16591
16588
 
16592
- this.renderingContext.renderListLastFrame = [].concat(this.renderingContext.renderListCurrentFrame);
16589
+ _this2.hooks.afterRender.call(object);
16590
+ });
16591
+ this.hooks.endFrame.call();
16593
16592
  this.renderingContext.renderListCurrentFrame = [];
16594
16593
  this.renderingContext.renderReasons.clear();
16595
16594
  } // console.log('stats', this.stats);
@@ -18085,13 +18084,11 @@ exports.TextService = /*#__PURE__*/function () {
18085
18084
  _proto.measureText = function measureText(text, parsedStyle, offscreenCanvas) {
18086
18085
  var fontSize = parsedStyle.fontSize,
18087
18086
  wordWrap = parsedStyle.wordWrap,
18088
- _parsedStyle$lineHeig = parsedStyle.lineHeight,
18089
- strokeHeight = _parsedStyle$lineHeig === void 0 ? 0 : _parsedStyle$lineHeig,
18087
+ strokeHeight = parsedStyle.lineHeight,
18090
18088
  lineWidth = parsedStyle.lineWidth,
18091
18089
  textBaseline = parsedStyle.textBaseline,
18092
18090
  textAlign = parsedStyle.textAlign,
18093
- _parsedStyle$letterSp = parsedStyle.letterSpacing,
18094
- letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
18091
+ letterSpacing = parsedStyle.letterSpacing,
18095
18092
  _parsedStyle$leading = parsedStyle.leading,
18096
18093
  leading = _parsedStyle$leading === void 0 ? 0 : _parsedStyle$leading;
18097
18094
  var font = toFontString(parsedStyle);
@@ -18111,7 +18108,7 @@ exports.TextService = /*#__PURE__*/function () {
18111
18108
  var maxLineWidth = 0;
18112
18109
 
18113
18110
  for (var i = 0; i < lines.length; i++) {
18114
- var _lineWidth = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
18111
+ var _lineWidth = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing.value;
18115
18112
 
18116
18113
  lineWidths[i] = _lineWidth;
18117
18114
  maxLineWidth = Math.max(maxLineWidth, _lineWidth);
@@ -18121,7 +18118,7 @@ exports.TextService = /*#__PURE__*/function () {
18121
18118
  // width += dropShadowDistance;
18122
18119
  // }
18123
18120
 
18124
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth.value;
18121
+ var lineHeight = strokeHeight.value || fontProperties.fontSize + lineWidth.value;
18125
18122
  var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth.value) + (lines.length - 1) * (lineHeight + leading); // if (dropShadow) {
18126
18123
  // height += dropShadowDistance;
18127
18124
  // }
@@ -18166,17 +18163,16 @@ exports.TextService = /*#__PURE__*/function () {
18166
18163
 
18167
18164
  var _ref$wordWrapWidth = _ref.wordWrapWidth,
18168
18165
  wordWrapWidth = _ref$wordWrapWidth === void 0 ? 0 : _ref$wordWrapWidth,
18169
- _ref$letterSpacing = _ref.letterSpacing,
18170
- letterSpacing = _ref$letterSpacing === void 0 ? 0 : _ref$letterSpacing;
18166
+ letterSpacing = _ref.letterSpacing;
18171
18167
  var context = this.offscreenCanvas.getOrCreateContext(offscreenCanvas);
18172
- var maxWidth = wordWrapWidth + letterSpacing;
18168
+ var maxWidth = wordWrapWidth + letterSpacing.value;
18173
18169
  var lines = [];
18174
18170
  var currentIndex = 0;
18175
18171
  var currentWidth = 0;
18176
18172
  var cache = {};
18177
18173
 
18178
18174
  var calcWidth = function calcWidth(char) {
18179
- return _this2.getFromCache(char, letterSpacing, cache, context);
18175
+ return _this2.getFromCache(char, letterSpacing.value, cache, context);
18180
18176
  };
18181
18177
 
18182
18178
  Array.from(text).forEach(function (char, i) {
@@ -18761,7 +18757,7 @@ function getFontSize(object) {
18761
18757
  return fontSize.clone();
18762
18758
  }
18763
18759
 
18764
- return new CSSUnitValue(0, 'px');
18760
+ return null;
18765
18761
  }
18766
18762
  /**
18767
18763
  * <length> & <percentage>
@@ -18789,8 +18785,13 @@ exports.CSSPropertyLengthOrPercentage = /*#__PURE__*/function () {
18789
18785
  } else if (computed.unit === exports.UnitType.kEms) {
18790
18786
  if (object.parentNode) {
18791
18787
  var fontSize = getFontSize(object.parentNode);
18792
- fontSize.value *= computed.value;
18793
- return fontSize;
18788
+
18789
+ if (fontSize) {
18790
+ fontSize.value *= computed.value;
18791
+ return fontSize;
18792
+ } else {
18793
+ registry.addUnresolveProperty(object, name);
18794
+ }
18794
18795
  }
18795
18796
 
18796
18797
  return new CSSUnitValue(0, 'px');
@@ -18800,8 +18801,12 @@ exports.CSSPropertyLengthOrPercentage = /*#__PURE__*/function () {
18800
18801
  if (object === null || object === void 0 ? void 0 : (_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.documentElement) {
18801
18802
  var _fontSize = getFontSize(object.ownerDocument.documentElement);
18802
18803
 
18803
- _fontSize.value *= computed.value;
18804
- return _fontSize;
18804
+ if (_fontSize) {
18805
+ _fontSize.value *= computed.value;
18806
+ return _fontSize;
18807
+ } else {
18808
+ registry.addUnresolveProperty(object, name);
18809
+ }
18805
18810
  }
18806
18811
 
18807
18812
  return new CSSUnitValue(0, 'px');
@@ -19319,32 +19324,32 @@ exports.CSSPropertyTransform = /*#__PURE__*/function () {
19319
19324
 
19320
19325
  if (t === 'scale') {
19321
19326
  // scale(1) scale(1, 1)
19322
- var newScale = d.map(function (s) {
19327
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19323
19328
  return s.value;
19324
- }) || [1, 1];
19329
+ })) || [1, 1];
19325
19330
  object.scaleLocal(newScale[0], newScale[1], 1);
19326
19331
  } else if (t === 'scalex') {
19327
- var _newScale = d.map(function (s) {
19332
+ var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19328
19333
  return s.value;
19329
- }) || [1];
19334
+ })) || [1];
19330
19335
 
19331
19336
  object.scaleLocal(_newScale[0], 1, 1);
19332
19337
  } else if (t === 'scaley') {
19333
- var _newScale2 = d.map(function (s) {
19338
+ var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19334
19339
  return s.value;
19335
- }) || [1];
19340
+ })) || [1];
19336
19341
 
19337
19342
  object.scaleLocal(1, _newScale2[0], 1);
19338
19343
  } else if (t === 'scalez') {
19339
- var _newScale3 = d.map(function (s) {
19344
+ var _newScale3 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19340
19345
  return s.value;
19341
- }) || [1];
19346
+ })) || [1];
19342
19347
 
19343
19348
  object.scaleLocal(1, 1, _newScale3[0]);
19344
19349
  } else if (t === 'scale3d') {
19345
- var _newScale4 = d.map(function (s) {
19350
+ var _newScale4 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19346
19351
  return s.value;
19347
- }) || [1, 1, 1];
19352
+ })) || [1, 1, 1];
19348
19353
 
19349
19354
  object.scaleLocal(_newScale4[0], _newScale4[1], _newScale4[2]);
19350
19355
  } else if (t === 'translate') {
@@ -19382,22 +19387,42 @@ exports.CSSPropertyTransform = /*#__PURE__*/function () {
19382
19387
 
19383
19388
  object.rotateLocal(0, 0, _newAngles3[0].value);
19384
19389
  } else if (t === 'rotate3d') ; else if (t === 'skew') {
19385
- var newSkew = d.map(function (s) {
19390
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19386
19391
  return s.value;
19387
- }) || [0, 0];
19392
+ })) || [0, 0];
19388
19393
  object.setLocalSkew(deg2rad(newSkew[0]), deg2rad(newSkew[1]));
19389
19394
  } else if (t === 'skewx') {
19390
- var _newSkew = d.map(function (s) {
19395
+ var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19391
19396
  return s.value;
19392
- }) || [0];
19397
+ })) || [0];
19393
19398
 
19394
19399
  object.setLocalSkew(deg2rad(_newSkew[0]), object.getLocalSkew()[1]);
19395
19400
  } else if (t === 'skewy') {
19396
- var _newSkew2 = d.map(function (s) {
19401
+ var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
19397
19402
  return s.value;
19398
- }) || [0];
19403
+ })) || [0];
19399
19404
 
19400
19405
  object.setLocalSkew(object.getLocalSkew()[0], deg2rad(_newSkew2[0]));
19406
+ } else if (t === 'matrix') {
19407
+ var _d$map = d.map(function (s) {
19408
+ return s.value;
19409
+ }),
19410
+ a = _d$map[0],
19411
+ b = _d$map[1],
19412
+ c = _d$map[2],
19413
+ dd = _d$map[3],
19414
+ tx = _d$map[4],
19415
+ ty = _d$map[5];
19416
+
19417
+ object.setLocalTransform(glMatrix.mat4.fromValues(a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx + defX, ty + defY, 0, 1));
19418
+ } else if (t === 'matrix3d') {
19419
+ // @ts-ignore
19420
+ var mat = glMatrix.mat4.fromValues.apply(glMatrix.mat4, d.map(function (s) {
19421
+ return s.value;
19422
+ }));
19423
+ mat[12] += defX;
19424
+ mat[13] += defY;
19425
+ object.setLocalTransform(mat);
19401
19426
  }
19402
19427
  });
19403
19428
  }
@@ -19527,6 +19552,11 @@ var BUILT_IN_PROPERTIES = [{
19527
19552
  keywords: ['none'],
19528
19553
  defaultValue: 'none',
19529
19554
  syntax: exports.PropertySyntax.PAINT
19555
+ }, {
19556
+ name: 'shadowType',
19557
+ keywords: ['inner', 'outer', 'both'],
19558
+ defaultValue: 'outer',
19559
+ layoutDependent: true
19530
19560
  }, {
19531
19561
  name: 'shadowColor',
19532
19562
  interpolable: true,
@@ -19663,6 +19693,10 @@ var BUILT_IN_PROPERTIES = [{
19663
19693
  return 'center';
19664
19694
  }
19665
19695
 
19696
+ if (nodeName === exports.Shape.TEXT) {
19697
+ return 'text-anchor';
19698
+ }
19699
+
19666
19700
  return 'left top';
19667
19701
  },
19668
19702
  layoutDependent: true,
@@ -19854,16 +19888,27 @@ var BUILT_IN_PROPERTIES = [{
19854
19888
  defaultValue: 'normal'
19855
19889
  }, {
19856
19890
  name: 'lineHeight',
19857
- layoutDependent: true // interpolable: true,
19858
- // inherited: true,
19859
- // defaultValue: '-100%'
19860
-
19891
+ layoutDependent: true,
19892
+ syntax: exports.PropertySyntax.LENGTH,
19893
+ interpolable: true,
19894
+ defaultValue: '0'
19861
19895
  }, {
19862
19896
  name: 'letterSpacing',
19863
- layoutDependent: true // interpolable: true,
19864
- // inherited: true,
19865
- // defaultValue: '0',
19897
+ layoutDependent: true,
19898
+ syntax: exports.PropertySyntax.LENGTH,
19899
+ interpolable: true,
19900
+ defaultValue: '0'
19901
+ }, {
19902
+ name: 'miterLimit',
19903
+ layoutDependent: true,
19904
+ syntax: exports.PropertySyntax.NUMBER,
19905
+ defaultValue: function defaultValue(nodeName) {
19906
+ if (nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYGON || nodeName === exports.Shape.POLYLINE) {
19907
+ return '4';
19908
+ }
19866
19909
 
19910
+ return '10';
19911
+ }
19867
19912
  }, {
19868
19913
  name: 'wordWrap',
19869
19914
  layoutDependent: true
@@ -20256,8 +20301,10 @@ exports.DefaultStyleValueRegistry = /*#__PURE__*/function () {
20256
20301
 
20257
20302
  var halfExtents = glMatrix.vec3.fromValues(Math.abs(width) / 2, Math.abs(height) / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
20258
20303
 
20259
- var lineWidth = parsedStyle.lineWidth,
20304
+ var stroke = parsedStyle.stroke,
20305
+ lineWidth = parsedStyle.lineWidth,
20260
20306
  increasedLineWidthForHitTesting = parsedStyle.increasedLineWidthForHitTesting,
20307
+ shadowType = parsedStyle.shadowType,
20261
20308
  shadowColor = parsedStyle.shadowColor,
20262
20309
  _parsedStyle$filter = parsedStyle.filter,
20263
20310
  filter = _parsedStyle$filter === void 0 ? [] : _parsedStyle$filter,
@@ -20278,13 +20325,18 @@ exports.DefaultStyleValueRegistry = /*#__PURE__*/function () {
20278
20325
  // if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
20279
20326
  // expansion = Math.SQRT1_2 * miterLimit;
20280
20327
  // }
20328
+ // append border only if stroke existed
20329
+
20330
+ var hasStroke = stroke && !stroke.isNone;
20281
20331
 
20282
- var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) * expansion; // append border
20332
+ if (hasStroke) {
20333
+ var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) * expansion;
20334
+ glMatrix.vec3.add(halfExtents, halfExtents, glMatrix.vec3.fromValues(halfLineWidth, halfLineWidth, 0));
20335
+ }
20283
20336
 
20284
- glMatrix.vec3.add(halfExtents, halfExtents, glMatrix.vec3.fromValues(halfLineWidth, halfLineWidth, 0));
20285
20337
  geometry.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
20286
20338
 
20287
- if (shadowColor) {
20339
+ if (shadowColor && (shadowType === null || shadowType === void 0 ? void 0 : shadowType.value) !== 'inner') {
20288
20340
  var _geometry$renderBound = geometry.renderBounds,
20289
20341
  min = _geometry$renderBound.min,
20290
20342
  max = _geometry$renderBound.max;
@@ -20536,6 +20588,9 @@ var containerModule = manaSyringe.Module(function (register) {
20536
20588
  });
20537
20589
  });
20538
20590
 
20591
+ var AbstractRendererPlugin = function AbstractRendererPlugin() {
20592
+ this.container = void 0;
20593
+ };
20539
20594
  var AbstractRenderer = /*#__PURE__*/function () {
20540
20595
  function AbstractRenderer(config) {
20541
20596
  this.plugins = [];
@@ -20555,7 +20610,8 @@ var AbstractRenderer = /*#__PURE__*/function () {
20555
20610
  /**
20556
20611
  * enable dirty rectangle rendering by default
20557
20612
  */
20558
- enableDirtyRectangleRendering: true
20613
+ enableDirtyRectangleRendering: true,
20614
+ enableDirtyRectangleRenderingDebug: false
20559
20615
  }, config);
20560
20616
  }
20561
20617
 
@@ -20643,9 +20699,8 @@ var CullingPlugin = CullingPlugin_1 = (_class$1 = /*#__PURE__*/function () {
20643
20699
  if (!cullable.isCulled() && object.isVisible()) {
20644
20700
  return object;
20645
20701
  } else {
20646
- if (_this.renderingContext.renderListLastFrame.indexOf(object) > -1) {
20647
- object.dispatchEvent(new CustomEvent(exports.ElementEvent.CULLED));
20648
- }
20702
+ // if (this.renderingContext.renderListLastFrame.indexOf(object) > -1) {
20703
+ object.dispatchEvent(new CustomEvent(exports.ElementEvent.CULLED)); // }
20649
20704
  }
20650
20705
 
20651
20706
  return null;
@@ -21314,6 +21369,7 @@ var containerModule$1 = manaSyringe.Module(function (register) {
21314
21369
  CanvasEvent["BEFORE_DESTROY"] = "beforedestroy";
21315
21370
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
21316
21371
  CanvasEvent["RESIZE"] = "resize";
21372
+ CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
21317
21373
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
21318
21374
  /**
21319
21375
  * can be treated like Window in DOM
@@ -21517,7 +21573,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21517
21573
  * the root node in scene graph
21518
21574
  */
21519
21575
  root: this.document.documentElement,
21520
- renderListLastFrame: [],
21521
21576
  renderListCurrentFrame: [],
21522
21577
  unculledEntities: [],
21523
21578
  renderReasons: new Set(),
@@ -21798,14 +21853,13 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21798
21853
  // load other container modules provided by g-canvas/g-svg/g-webgl
21799
21854
  var plugins = renderer.getPlugins();
21800
21855
  plugins.forEach(function (plugin) {
21801
- plugin.init(_this4.container);
21856
+ plugin.container = _this4.container;
21857
+ plugin.init();
21802
21858
  });
21803
21859
  };
21804
21860
 
21805
21861
  _proto.setRenderer = /*#__PURE__*/function () {
21806
21862
  var _setRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderer) {
21807
- var _this5 = this;
21808
-
21809
21863
  var canvasConfig, oldRenderer;
21810
21864
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
21811
21865
  while (1) {
@@ -21828,7 +21882,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21828
21882
  this.destroy(false, true); // destroy all plugins, reverse will mutate origin array
21829
21883
 
21830
21884
  [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
21831
- plugin.destroy(_this5.container);
21885
+ plugin.destroy();
21832
21886
  });
21833
21887
  _context3.next = 9;
21834
21888
  return this.initRenderer(renderer);
@@ -21853,7 +21907,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21853
21907
  };
21854
21908
 
21855
21909
  _proto.unmountChildren = function unmountChildren(parent) {
21856
- var _this6 = this;
21910
+ var _this5 = this;
21857
21911
 
21858
21912
  if (this.inited) {
21859
21913
  var path = [];
@@ -21873,7 +21927,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21873
21927
 
21874
21928
  child.dispatchEvent(new CustomEvent(exports.ElementEvent.UNMOUNTED)); // skip document.documentElement
21875
21929
 
21876
- if (child !== _this6.document.documentElement) {
21930
+ if (child !== _this5.document.documentElement) {
21877
21931
  child.ownerDocument = null;
21878
21932
  }
21879
21933
 
@@ -21883,12 +21937,12 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21883
21937
  };
21884
21938
 
21885
21939
  _proto.mountChildren = function mountChildren(parent) {
21886
- var _this7 = this;
21940
+ var _this6 = this;
21887
21941
 
21888
21942
  if (this.inited) {
21889
21943
  parent.forEach(function (child) {
21890
21944
  if (!child.isConnected) {
21891
- child.ownerDocument = _this7.document;
21945
+ child.ownerDocument = _this6.document;
21892
21946
  child.isConnected = true;
21893
21947
  child.dispatchEvent(new CustomEvent(exports.ElementEvent.MOUNTED)); // trigger after mounted
21894
21948
 
@@ -21947,12 +22001,12 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21947
22001
  _createClass(Canvas, [{
21948
22002
  key: "ready",
21949
22003
  get: function get() {
21950
- var _this8 = this;
22004
+ var _this7 = this;
21951
22005
 
21952
22006
  if (!this.readyPromise) {
21953
22007
  this.readyPromise = new Promise(function (resolve) {
21954
- _this8.resolveReadyPromise = function () {
21955
- resolve(_this8);
22008
+ _this7.resolveReadyPromise = function () {
22009
+ resolve(_this7);
21956
22010
  };
21957
22011
  });
21958
22012
 
@@ -21968,7 +22022,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21968
22022
  return Canvas;
21969
22023
  }(EventTarget);
21970
22024
 
21971
- // import * as ManaSyringe from 'mana-syringe';
21972
22025
  manaSyringe.GlobalContainer.load(containerModule);
21973
22026
  var layoutEngine = manaSyringe.GlobalContainer.get(exports.LayoutEngine);
21974
22027
 
@@ -21989,6 +22042,7 @@ Object.defineProperty(exports, 'RBush', {
21989
22042
  exports.AABB = AABB;
21990
22043
  exports.AbstractLayoutDefinition = AbstractLayoutDefinition;
21991
22044
  exports.AbstractRenderer = AbstractRenderer;
22045
+ exports.AbstractRendererPlugin = AbstractRendererPlugin;
21992
22046
  exports.Animation = Animation;
21993
22047
  exports.AnimationEffectTiming = AnimationEffectTiming;
21994
22048
  exports.AnimationEvent = AnimationEvent;
@@ -22102,6 +22156,7 @@ exports.clampedMergeNumbers = clampedMergeNumbers;
22102
22156
  exports.cleanExistedCanvas = cleanExistedCanvas;
22103
22157
  exports.colorStopToString = colorStopToString;
22104
22158
  exports.compareAnimations = compareAnimations;
22159
+ exports.composeMatrix = composeMatrix;
22105
22160
  exports.computeLinearGradient = computeLinearGradient;
22106
22161
  exports.computeRadialGradient = computeRadialGradient;
22107
22162
  exports.convertAngleUnit = convertAngleUnit;