@visactor/vrender-core 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/cjs/common/generator.d.ts +0 -1
  2. package/cjs/common/generator.js +13 -2
  3. package/cjs/common/generator.js.map +1 -1
  4. package/cjs/core/contributions/layerHandler/modules.js +4 -2
  5. package/cjs/core/contributions/layerHandler/modules.js.map +1 -1
  6. package/cjs/core/stage.d.ts +10 -3
  7. package/cjs/core/stage.js +39 -20
  8. package/cjs/core/stage.js.map +1 -1
  9. package/cjs/event/event-manager.d.ts +29 -1
  10. package/cjs/event/event-manager.js +161 -42
  11. package/cjs/event/event-manager.js.map +1 -1
  12. package/cjs/event/event-system.d.ts +19 -3
  13. package/cjs/event/event-system.js +110 -62
  14. package/cjs/event/event-system.js.map +1 -1
  15. package/cjs/event/federated-event/base-event.js +3 -1
  16. package/cjs/event/federated-event/base-event.js.map +1 -1
  17. package/cjs/event/input-source.d.ts +7 -0
  18. package/cjs/event/input-source.js +37 -0
  19. package/cjs/event/input-source.js.map +1 -0
  20. package/cjs/graphic/graphic.js +1 -0
  21. package/cjs/graphic/graphic.js.map +1 -1
  22. package/cjs/graphic/text.js +17 -7
  23. package/cjs/graphic/text.js.map +1 -1
  24. package/cjs/graphic/wrap-text.js +4 -2
  25. package/cjs/graphic/wrap-text.js.map +1 -1
  26. package/cjs/interface/event.d.ts +9 -0
  27. package/cjs/interface/event.js.map +1 -1
  28. package/cjs/interface/stage.d.ts +10 -2
  29. package/cjs/interface/stage.js.map +1 -1
  30. package/cjs/render/contributions/render/draw-interceptor.js +13 -3
  31. package/cjs/render/contributions/render/draw-interceptor.js.map +1 -1
  32. package/dist/index.es.js +642 -157
  33. package/es/common/generator.d.ts +0 -1
  34. package/es/common/generator.js +12 -3
  35. package/es/common/generator.js.map +1 -1
  36. package/es/core/contributions/layerHandler/modules.js +6 -2
  37. package/es/core/contributions/layerHandler/modules.js.map +1 -1
  38. package/es/core/stage.d.ts +10 -3
  39. package/es/core/stage.js +40 -21
  40. package/es/core/stage.js.map +1 -1
  41. package/es/event/event-manager.d.ts +29 -1
  42. package/es/event/event-manager.js +162 -41
  43. package/es/event/event-manager.js.map +1 -1
  44. package/es/event/event-system.d.ts +19 -3
  45. package/es/event/event-system.js +110 -62
  46. package/es/event/event-system.js.map +1 -1
  47. package/es/event/federated-event/base-event.js +2 -1
  48. package/es/event/federated-event/base-event.js.map +1 -1
  49. package/es/event/input-source.d.ts +7 -0
  50. package/es/event/input-source.js +29 -0
  51. package/es/event/input-source.js.map +1 -0
  52. package/es/graphic/graphic.js +1 -0
  53. package/es/graphic/graphic.js.map +1 -1
  54. package/es/graphic/text.js +17 -7
  55. package/es/graphic/text.js.map +1 -1
  56. package/es/graphic/wrap-text.js +4 -2
  57. package/es/graphic/wrap-text.js.map +1 -1
  58. package/es/interface/event.d.ts +9 -0
  59. package/es/interface/event.js.map +1 -1
  60. package/es/interface/stage.d.ts +10 -2
  61. package/es/interface/stage.js.map +1 -1
  62. package/es/render/contributions/render/draw-interceptor.js +12 -3
  63. package/es/render/contributions/render/draw-interceptor.js.map +1 -1
  64. package/package.json +3 -3
package/dist/index.es.js CHANGED
@@ -133,12 +133,17 @@ class SyncHook extends Hook {
133
133
  }
134
134
  }
135
135
 
136
+ const GENERATOR_STATE_SYMBOL = Symbol.for('@visactor/vrender-core/generator-state');
137
+ function getGeneratorState() {
138
+ const scope = globalThis;
139
+ return scope[GENERATOR_STATE_SYMBOL] || (scope[GENERATOR_STATE_SYMBOL] = { autoIncrementId: 0 });
140
+ }
141
+ const generatorState = getGeneratorState();
136
142
  class Generator {
137
143
  static GenAutoIncrementId() {
138
- return Generator.auto_increment_id++;
144
+ return generatorState.autoIncrementId++;
139
145
  }
140
146
  }
141
- Generator.auto_increment_id = 0;
142
147
 
143
148
  class Application {
144
149
  }
@@ -1331,13 +1336,14 @@ class FederatedEvent {
1331
1336
  }
1332
1337
  }
1333
1338
  preventDefault() {
1339
+ var _a;
1334
1340
  try {
1335
1341
  if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
1336
1342
  this.nativeEvent.preventDefault();
1337
1343
  }
1338
1344
  }
1339
1345
  catch (err) {
1340
- this.nativeEvent.preventDefault &&
1346
+ ((_a = this.nativeEvent) === null || _a === void 0 ? void 0 : _a.preventDefault) &&
1341
1347
  isFunction(this.nativeEvent.preventDefault) &&
1342
1348
  this.nativeEvent.preventDefault();
1343
1349
  }
@@ -1510,6 +1516,43 @@ class CustomEvent extends FederatedEvent {
1510
1516
  }
1511
1517
  }
1512
1518
 
1519
+ class InputSource {
1520
+ constructor() {
1521
+ this.listeners = {};
1522
+ this.source = {
1523
+ on: (type, listener) => {
1524
+ var _a;
1525
+ this.listeners[type] = ((_a = this.listeners[type]) !== null && _a !== void 0 ? _a : []).concat(listener);
1526
+ },
1527
+ off: (type, listener) => {
1528
+ const list = this.listeners[type];
1529
+ if (list) {
1530
+ this.listeners[type] = list.filter(fn => fn !== listener);
1531
+ }
1532
+ }
1533
+ };
1534
+ }
1535
+ emit(type, event, valid) {
1536
+ const list = this.listeners[type];
1537
+ if (!list) {
1538
+ return;
1539
+ }
1540
+ const originalType = event.type;
1541
+ event.type = type;
1542
+ try {
1543
+ for (let i = 0; i < list.length && valid(); i++) {
1544
+ list[i](event);
1545
+ }
1546
+ }
1547
+ finally {
1548
+ event.type = originalType;
1549
+ }
1550
+ }
1551
+ clear() {
1552
+ this.listeners = {};
1553
+ }
1554
+ }
1555
+
1513
1556
  const WILDCARD = '*';
1514
1557
 
1515
1558
  const clock = typeof performance === 'object' && performance.now ? performance : Date;
@@ -1519,6 +1562,16 @@ function isMouseLike(pointerType) {
1519
1562
  return pointerType === 'mouse' || pointerType === 'pen';
1520
1563
  }
1521
1564
  const DEFAULT_CLICK_INTERVAL = 200;
1565
+ const TOUCH_INPUT_TYPES = {
1566
+ pointerdown: 'touchstart',
1567
+ pointermove: 'touchmove',
1568
+ pointerup: 'touchend'
1569
+ };
1570
+ const MOUSE_INPUT_TYPES = {
1571
+ pointerdown: 'mousedown',
1572
+ pointermove: 'mousemove',
1573
+ pointerup: 'mouseup'
1574
+ };
1522
1575
  class EventManager {
1523
1576
  constructor(root, config) {
1524
1577
  this.dispatch = new EventEmitter();
@@ -1528,12 +1581,26 @@ class EventManager {
1528
1581
  trackingData: {}
1529
1582
  };
1530
1583
  this.eventPool = new Map();
1584
+ this.canvasInput = new InputSource();
1585
+ this.windowInput = new InputSource();
1586
+ this.input = { canvas: this.canvasInput.source, window: this.windowInput.source };
1587
+ this.currentGeneration = 0;
1588
+ this.terminalDepth = 0;
1589
+ this.inputValid = () => !!this.rootTarget &&
1590
+ (this.terminalDepth > 0 || !this.currentTracking || this.currentTracking.generation === this.currentGeneration);
1591
+ this.onPointerCancel = (from) => {
1592
+ if (from instanceof FederatedPointerEvent) {
1593
+ this.cancelPointer(from.pointerId);
1594
+ }
1595
+ };
1531
1596
  this.onPointerDown = (from, target) => {
1532
1597
  if (!(from instanceof FederatedPointerEvent)) {
1533
1598
  Logger.getInstance().warn('EventManager cannot map a non-pointer event as a pointer event');
1534
1599
  return;
1535
1600
  }
1536
1601
  const e = this.createPointerEvent(from, from.type, target);
1602
+ const trackingData = this.trackingData(from.pointerId);
1603
+ trackingData.pressTargetsByButton[from.button] = e.composedPath();
1537
1604
  this.dispatchEvent(e, 'pointerdown');
1538
1605
  if (e.pointerType === 'touch') {
1539
1606
  this.dispatchEvent(e, 'touchstart');
@@ -1542,8 +1609,6 @@ class EventManager {
1542
1609
  const isRightButton = e.button === 2;
1543
1610
  this.dispatchEvent(e, isRightButton ? 'rightdown' : 'mousedown');
1544
1611
  }
1545
- const trackingData = this.trackingData(from.pointerId);
1546
- trackingData.pressTargetsByButton[from.button] = e.composedPath();
1547
1612
  this.freeEvent(e);
1548
1613
  };
1549
1614
  this.onPointerMove = (from, target) => {
@@ -1586,13 +1651,13 @@ class EventManager {
1586
1651
  this.dispatchEvent(overEvent, 'mouseover');
1587
1652
  }
1588
1653
  let overTargetAncestor = outTarget === null || outTarget === void 0 ? void 0 : outTarget.parent;
1589
- while (overTargetAncestor && overTargetAncestor !== this.rootTarget.parent) {
1654
+ while (this.inputValid() && overTargetAncestor && overTargetAncestor !== this.rootTarget.parent) {
1590
1655
  if (overTargetAncestor === e.target) {
1591
1656
  break;
1592
1657
  }
1593
1658
  overTargetAncestor = overTargetAncestor.parent;
1594
1659
  }
1595
- const didPointerEnter = !overTargetAncestor || overTargetAncestor === this.rootTarget.parent;
1660
+ const didPointerEnter = this.inputValid() && (!overTargetAncestor || overTargetAncestor === this.rootTarget.parent);
1596
1661
  if (didPointerEnter) {
1597
1662
  const enterEvent = this.clonePointerEvent(e, 'pointerenter');
1598
1663
  enterEvent.eventPhase = enterEvent.AT_TARGET;
@@ -1603,7 +1668,10 @@ class EventManager {
1603
1668
  outTargetAncestors.add(ancestor);
1604
1669
  ancestor = ancestor.parent;
1605
1670
  }
1606
- while (currentTarget && currentTarget !== outTarget && currentTarget !== this.rootTarget.parent) {
1671
+ while (this.inputValid() &&
1672
+ currentTarget &&
1673
+ currentTarget !== outTarget &&
1674
+ currentTarget !== this.rootTarget.parent) {
1607
1675
  if (!outTargetAncestors.has(currentTarget)) {
1608
1676
  enterEvent.currentTarget = currentTarget;
1609
1677
  this.notifyTarget(enterEvent);
@@ -1622,12 +1690,14 @@ class EventManager {
1622
1690
  if (e.pointerType === 'touch') {
1623
1691
  this[propagationMethod](e, 'touchmove');
1624
1692
  }
1625
- if (isMouse) {
1693
+ if (isMouse && this.inputValid()) {
1626
1694
  this[propagationMethod](e, 'mousemove');
1627
1695
  this.cursorTarget = e.target;
1628
1696
  this.cursor = ((_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.attribute) === null || _b === void 0 ? void 0 : _b.cursor) || this.rootTarget.getCursor();
1629
1697
  }
1630
- trackingData.overTargets = e.composedPath();
1698
+ if (this.inputValid()) {
1699
+ trackingData.overTargets = e.composedPath();
1700
+ }
1631
1701
  this.freeEvent(e);
1632
1702
  };
1633
1703
  this.onPointerOver = (from, target) => {
@@ -1643,13 +1713,13 @@ class EventManager {
1643
1713
  if (isMouse) {
1644
1714
  this.dispatchEvent(e, 'mouseover');
1645
1715
  }
1646
- if (e.pointerType === 'mouse') {
1716
+ if (e.pointerType === 'mouse' && this.inputValid()) {
1647
1717
  this.cursorTarget = e.target;
1648
1718
  this.cursor = ((_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.attribute) === null || _b === void 0 ? void 0 : _b.cursor) || this.rootTarget.getCursor();
1649
1719
  }
1650
1720
  const enterEvent = this.clonePointerEvent(e, 'pointerenter');
1651
1721
  enterEvent.eventPhase = enterEvent.AT_TARGET;
1652
- while (enterEvent.target && enterEvent.target !== this.rootTarget.parent) {
1722
+ while (this.inputValid() && enterEvent.target && enterEvent.target !== this.rootTarget.parent) {
1653
1723
  enterEvent.currentTarget = enterEvent.target;
1654
1724
  this.notifyTarget(enterEvent);
1655
1725
  if (isMouse) {
@@ -1657,7 +1727,9 @@ class EventManager {
1657
1727
  }
1658
1728
  enterEvent.target = enterEvent.target.parent;
1659
1729
  }
1660
- trackingData.overTargets = e.composedPath();
1730
+ if (this.inputValid()) {
1731
+ trackingData.overTargets = e.composedPath();
1732
+ }
1661
1733
  this.freeEvent(e);
1662
1734
  this.freeEvent(enterEvent);
1663
1735
  };
@@ -1677,7 +1749,7 @@ class EventManager {
1677
1749
  }
1678
1750
  const leaveEvent = this.createPointerEvent(from, 'pointerleave', outTarget || undefined);
1679
1751
  leaveEvent.eventPhase = leaveEvent.AT_TARGET;
1680
- while (leaveEvent.target && leaveEvent.target !== this.rootTarget.parent) {
1752
+ while (this.inputValid() && leaveEvent.target && leaveEvent.target !== this.rootTarget.parent) {
1681
1753
  leaveEvent.currentTarget = leaveEvent.target;
1682
1754
  this.notifyTarget(leaveEvent);
1683
1755
  if (isMouse) {
@@ -1700,6 +1772,9 @@ class EventManager {
1700
1772
  }
1701
1773
  const now = clock.now();
1702
1774
  const e = this.createPointerEvent(from, from.type, target);
1775
+ const trackingData = this.trackingData(from.pointerId);
1776
+ trackingData.ending = trackingData.pressTargetsByButton[from.button];
1777
+ delete trackingData.pressTargetsByButton[from.button];
1703
1778
  this.dispatchEvent(e, 'pointerup');
1704
1779
  if (e.pointerType === 'touch') {
1705
1780
  this.dispatchEvent(e, 'touchend');
@@ -1708,8 +1783,7 @@ class EventManager {
1708
1783
  const isRightButton = e.button === 2;
1709
1784
  this.dispatchEvent(e, isRightButton ? 'rightup' : 'mouseup');
1710
1785
  }
1711
- const trackingData = this.trackingData(from.pointerId);
1712
- const pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
1786
+ const pressTarget = this.findMountedTarget(trackingData.ending);
1713
1787
  let clickTarget = pressTarget;
1714
1788
  if (pressTarget && !e.composedPath().includes(pressTarget)) {
1715
1789
  let currentTarget = pressTarget;
@@ -1728,7 +1802,8 @@ class EventManager {
1728
1802
  delete trackingData.pressTargetsByButton[from.button];
1729
1803
  clickTarget = currentTarget;
1730
1804
  }
1731
- if (clickTarget) {
1805
+ this.emitPointerInput(e, 'pointerup');
1806
+ if (clickTarget && this.inputValid()) {
1732
1807
  const clickEvent = this.clonePointerEvent(e, 'click');
1733
1808
  clickEvent.target = clickTarget;
1734
1809
  clickEvent.path = [];
@@ -1753,17 +1828,22 @@ class EventManager {
1753
1828
  clickEvent.detail = clickHistory.clickCount;
1754
1829
  if (isMouseLike(clickEvent.pointerType)) {
1755
1830
  this.dispatchEvent(clickEvent, 'click');
1831
+ this.emitInput(clickEvent, 'click');
1756
1832
  if (clickHistory.clickCount === 2) {
1757
1833
  this.dispatchEvent(clickEvent, 'dblclick');
1834
+ this.emitInput(clickEvent, 'dblclick');
1758
1835
  }
1759
1836
  }
1760
1837
  else if (clickEvent.pointerType === 'touch' && this._config.supportsTouchEvents) {
1761
1838
  this.dispatchEvent(clickEvent, 'tap');
1839
+ this.emitInput(clickEvent, 'tap');
1762
1840
  if (clickHistory.clickCount === 2) {
1763
1841
  this.dispatchEvent(clickEvent, 'dbltap');
1842
+ this.emitInput(clickEvent, 'dbltap');
1764
1843
  }
1765
1844
  }
1766
1845
  this.dispatchEvent(clickEvent, 'pointertap');
1846
+ this.emitInput(clickEvent, 'pointertap');
1767
1847
  this.freeEvent(clickEvent);
1768
1848
  }
1769
1849
  this.freeEvent(e);
@@ -1774,7 +1854,9 @@ class EventManager {
1774
1854
  return;
1775
1855
  }
1776
1856
  const trackingData = this.trackingData(from.pointerId);
1777
- const pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
1857
+ trackingData.ending = trackingData.pressTargetsByButton[from.button];
1858
+ delete trackingData.pressTargetsByButton[from.button];
1859
+ const pressTarget = this.findMountedTarget(trackingData.ending);
1778
1860
  const e = this.createPointerEvent(from, from.type, target);
1779
1861
  if (pressTarget) {
1780
1862
  let currentTarget = pressTarget;
@@ -1791,6 +1873,7 @@ class EventManager {
1791
1873
  }
1792
1874
  delete trackingData.pressTargetsByButton[from.button];
1793
1875
  }
1876
+ this.emitPointerInput(e, 'pointerup');
1794
1877
  this.freeEvent(e);
1795
1878
  };
1796
1879
  this.onWheel = (from, target) => {
@@ -1812,8 +1895,159 @@ class EventManager {
1812
1895
  this.addEventMapping('pointerover', this.onPointerOver);
1813
1896
  this.addEventMapping('pointerup', this.onPointerUp);
1814
1897
  this.addEventMapping('pointerupoutside', this.onPointerUpOutside);
1898
+ this.addEventMapping('pointercancel', this.onPointerCancel);
1815
1899
  this.addEventMapping('wheel', this.onWheel);
1816
1900
  }
1901
+ hasPointer(id) {
1902
+ const data = this.mappingState.trackingData[id];
1903
+ if (!data) {
1904
+ return false;
1905
+ }
1906
+ if (data.inside || data.ending) {
1907
+ return true;
1908
+ }
1909
+ for (const button in data.pressTargetsByButton) {
1910
+ if (data.pressTargetsByButton[button]) {
1911
+ return true;
1912
+ }
1913
+ }
1914
+ return false;
1915
+ }
1916
+ cancelAllPointers() {
1917
+ for (const id in this.mappingState.trackingData) {
1918
+ this.cancelPointer(Number(id));
1919
+ }
1920
+ }
1921
+ cancelPointer(id) {
1922
+ var _a;
1923
+ if (!this.rootTarget || !this.hasPointer(id)) {
1924
+ return;
1925
+ }
1926
+ const data = this.trackingData(id);
1927
+ let press = data.ending;
1928
+ for (const button in data.pressTargetsByButton) {
1929
+ press = data.pressTargetsByButton[button];
1930
+ break;
1931
+ }
1932
+ const over = data.overTargets;
1933
+ const inside = data.inside;
1934
+ data.generation++;
1935
+ data.pressTargetsByButton = {};
1936
+ data.clicksByButton = {};
1937
+ data.ending = undefined;
1938
+ data.inside = false;
1939
+ data.overTargets = [];
1940
+ if (this.dispatchingEvent instanceof FederatedPointerEvent && this.dispatchingEvent.pointerId === id) {
1941
+ this.dispatchingEvent.stopImmediatePropagation();
1942
+ }
1943
+ const event = this.allocateEvent(FederatedPointerEvent);
1944
+ event.type = 'pointercancel';
1945
+ event.pointerId = id;
1946
+ event.pointerType = data.pointerType;
1947
+ event.button = data.button;
1948
+ event.nativeEvent = null;
1949
+ event.canvas.x = data.canvasX;
1950
+ event.canvas.y = data.canvasY;
1951
+ event.viewport.x = data.viewX;
1952
+ event.viewport.y = data.viewY;
1953
+ event.target = (_a = this.findMountedTarget(press)) !== null && _a !== void 0 ? _a : this.findMountedTarget(over);
1954
+ this.terminalDepth++;
1955
+ try {
1956
+ this.dispatchEvent(event);
1957
+ if (event.pointerType === 'touch') {
1958
+ this.dispatchEvent(event, 'touchcancel');
1959
+ }
1960
+ this.windowInput.emit('pointercancel', event, this.inputValid);
1961
+ if (event.pointerType === 'touch') {
1962
+ this.windowInput.emit('touchcancel', event, this.inputValid);
1963
+ }
1964
+ if (inside) {
1965
+ this.canvasInput.emit('pointercancel', event, this.inputValid);
1966
+ if (event.pointerType === 'touch') {
1967
+ this.canvasInput.emit('touchcancel', event, this.inputValid);
1968
+ }
1969
+ this.emitBoundary(event, false);
1970
+ }
1971
+ if ((over === null || over === void 0 ? void 0 : over.length) && this.rootTarget) {
1972
+ event.target = this.findMountedTarget(over);
1973
+ event.path = [];
1974
+ this.dispatchEvent(event, 'pointerout');
1975
+ if (isMouseLike(event.pointerType)) {
1976
+ this.dispatchEvent(event, 'mouseout');
1977
+ }
1978
+ event.eventPhase = event.AT_TARGET;
1979
+ while (event.target && this.rootTarget) {
1980
+ event.currentTarget = event.target;
1981
+ this.notifyTarget(event, 'pointerleave');
1982
+ if (isMouseLike(event.pointerType)) {
1983
+ this.notifyTarget(event, 'mouseleave');
1984
+ }
1985
+ event.target = event.target.parent;
1986
+ }
1987
+ }
1988
+ }
1989
+ finally {
1990
+ this.terminalDepth--;
1991
+ this.freeEvent(event);
1992
+ this.cursorTarget = null;
1993
+ this.cursor = '';
1994
+ }
1995
+ }
1996
+ emitBoundary(event, inside) {
1997
+ this.canvasInput.emit(inside ? 'pointerover' : 'pointerout', event, this.inputValid);
1998
+ this.canvasInput.emit(inside ? 'pointerenter' : 'pointerleave', event, this.inputValid);
1999
+ if (isMouseLike(event.pointerType)) {
2000
+ this.canvasInput.emit(inside ? 'mouseover' : 'mouseout', event, this.inputValid);
2001
+ this.canvasInput.emit(inside ? 'mouseenter' : 'mouseleave', event, this.inputValid);
2002
+ }
2003
+ }
2004
+ emitInput(event, type = event.type) {
2005
+ if (!this.inputValid()) {
2006
+ return;
2007
+ }
2008
+ this.windowInput.emit(type, event, this.inputValid);
2009
+ if (!this.inputValid()) {
2010
+ return;
2011
+ }
2012
+ const data = event instanceof FederatedPointerEvent ? this.trackingData(event.pointerId) : undefined;
2013
+ if (data && data.previousInside !== data.inside) {
2014
+ data.previousInside = data.inside;
2015
+ this.emitBoundary(event, data.inside);
2016
+ }
2017
+ if (!data || data.inside) {
2018
+ this.canvasInput.emit(type, event, this.inputValid);
2019
+ }
2020
+ }
2021
+ emitPointerInput(event, type = event.type) {
2022
+ if (!this.inputValid()) {
2023
+ return;
2024
+ }
2025
+ if (type === 'pointerover' || type === 'pointerout' || type === 'pointerleave') {
2026
+ const data = this.trackingData(event.pointerId);
2027
+ if (data.previousInside !== data.inside) {
2028
+ data.previousInside = data.inside;
2029
+ this.emitBoundary(event, data.inside);
2030
+ }
2031
+ return;
2032
+ }
2033
+ this.emitInput(event, type);
2034
+ if (event.pointerType === 'touch') {
2035
+ const alias = TOUCH_INPUT_TYPES[type];
2036
+ if (alias) {
2037
+ this.emitInput(event, alias);
2038
+ }
2039
+ }
2040
+ else if (isMouseLike(event.pointerType)) {
2041
+ const alias = event.button === 2 && type === 'pointerdown'
2042
+ ? 'rightdown'
2043
+ : event.button === 2 && type === 'pointerup'
2044
+ ? 'rightup'
2045
+ : MOUSE_INPUT_TYPES[type];
2046
+ if (alias) {
2047
+ this.emitInput(event, alias);
2048
+ }
2049
+ }
2050
+ }
1817
2051
  addEventMapping(type, fn) {
1818
2052
  if (!this.mappingTable[type]) {
1819
2053
  this.mappingTable[type] = [];
@@ -1825,41 +2059,90 @@ class EventManager {
1825
2059
  this.mappingTable[type].sort((a, b) => a.priority - b.priority);
1826
2060
  }
1827
2061
  dispatchEvent(e, type) {
2062
+ if (!this.inputValid()) {
2063
+ return;
2064
+ }
2065
+ const previous = this.dispatchingEvent;
2066
+ this.dispatchingEvent = e;
1828
2067
  e.propagationStopped = false;
1829
2068
  e.propagationImmediatelyStopped = false;
1830
- this.propagate(e, type);
1831
- this.dispatch.emit(type || e.type, e);
2069
+ try {
2070
+ this.propagate(e, type);
2071
+ if (this.inputValid()) {
2072
+ this.dispatch.emit(type || e.type, e);
2073
+ }
2074
+ }
2075
+ finally {
2076
+ this.dispatchingEvent = previous;
2077
+ }
1832
2078
  }
1833
- mapEvent(e) {
1834
- var _a, _b, _c, _d, _e, _f, _g;
2079
+ mapEvent(e, inViewport = true) {
2080
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1835
2081
  if (!this.rootTarget) {
1836
2082
  return;
1837
2083
  }
1838
- const mappers = this.mappingTable[e.type];
1839
- let target;
1840
- const cacheKey = `${e.canvasX}-${e.canvasY}`;
1841
- if (((_a = this._prePointTargetCache) === null || _a === void 0 ? void 0 : _a[cacheKey]) &&
1842
- ((_c = (_b = this._prePointTargetCache) === null || _b === void 0 ? void 0 : _b[cacheKey]) === null || _c === void 0 ? void 0 : _c.stage) &&
1843
- ((_e = (_d = this._prePointTargetCache) === null || _d === void 0 ? void 0 : _d[cacheKey]) === null || _e === void 0 ? void 0 : _e.stage.renderCount) ===
1844
- ((_f = this._prePointTargetCache) === null || _f === void 0 ? void 0 : _f.stageRenderCount)) {
1845
- target = this._prePointTargetCache[cacheKey];
1846
- }
1847
- else {
1848
- target = this.pickTarget(e.viewX, e.viewY, e);
1849
- if (!e.pickParams) {
1850
- this._prePointTargetCache = {
1851
- [cacheKey]: target,
1852
- stageRenderCount: (_g = target === null || target === void 0 ? void 0 : target.stage.renderCount) !== null && _g !== void 0 ? _g : -1
1853
- };
2084
+ const previous = this.currentTracking;
2085
+ const generation = this.currentGeneration;
2086
+ const tracking = e instanceof FederatedPointerEvent ? this.trackingData(e.pointerId) : undefined;
2087
+ this.currentTracking = tracking;
2088
+ this.currentGeneration = (_a = tracking === null || tracking === void 0 ? void 0 : tracking.generation) !== null && _a !== void 0 ? _a : 0;
2089
+ if (tracking) {
2090
+ tracking.previousInside = tracking.inside;
2091
+ tracking.inside = inViewport;
2092
+ tracking.pointerType = e.pointerType;
2093
+ tracking.button = e.button;
2094
+ tracking.canvasX = e.canvasX;
2095
+ tracking.canvasY = e.canvasY;
2096
+ tracking.viewX = e.viewX;
2097
+ tracking.viewY = e.viewY;
2098
+ }
2099
+ const type = e.type === 'pointerup' && !inViewport ? 'pointerupoutside' : e.type;
2100
+ const mappers = this.mappingTable[type];
2101
+ try {
2102
+ let target;
2103
+ const cacheKey = `${e.canvasX}-${e.canvasY}`;
2104
+ if (!inViewport) {
2105
+ target = null;
1854
2106
  }
1855
- }
1856
- if (mappers) {
1857
- for (let i = 0, j = mappers.length; i < j; i++) {
1858
- mappers[i].fn(e, target);
2107
+ else if (((_b = this._prePointTargetCache) === null || _b === void 0 ? void 0 : _b[cacheKey]) &&
2108
+ ((_d = (_c = this._prePointTargetCache) === null || _c === void 0 ? void 0 : _c[cacheKey]) === null || _d === void 0 ? void 0 : _d.stage) &&
2109
+ ((_f = (_e = this._prePointTargetCache) === null || _e === void 0 ? void 0 : _e[cacheKey]) === null || _f === void 0 ? void 0 : _f.stage.renderCount) ===
2110
+ ((_g = this._prePointTargetCache) === null || _g === void 0 ? void 0 : _g.stageRenderCount)) {
2111
+ target = this._prePointTargetCache[cacheKey];
2112
+ }
2113
+ else {
2114
+ target = this.pickTarget(e.viewX, e.viewY, e);
2115
+ if (!e.pickParams) {
2116
+ this._prePointTargetCache = {
2117
+ [cacheKey]: target,
2118
+ stageRenderCount: (_h = target === null || target === void 0 ? void 0 : target.stage.renderCount) !== null && _h !== void 0 ? _h : -1
2119
+ };
2120
+ }
2121
+ }
2122
+ if (mappers) {
2123
+ for (let i = 0, j = mappers.length; i < j && this.inputValid(); i++) {
2124
+ mappers[i].fn(e, target);
2125
+ }
2126
+ }
2127
+ else {
2128
+ Logger.getInstance().warn(`[EventManager]: Event mapping not defined for ${e.type}`);
2129
+ }
2130
+ if (e instanceof FederatedPointerEvent &&
2131
+ type !== 'pointerup' &&
2132
+ type !== 'pointerupoutside' &&
2133
+ type !== 'pointercancel') {
2134
+ this.emitPointerInput(e);
2135
+ }
2136
+ else if (e instanceof FederatedWheelEvent) {
2137
+ this.emitInput(e);
1859
2138
  }
1860
2139
  }
1861
- else {
1862
- Logger.getInstance().warn(`[EventManager]: Event mapping not defined for ${e.type}`);
2140
+ finally {
2141
+ if (tracking) {
2142
+ tracking.ending = undefined;
2143
+ }
2144
+ this.currentTracking = previous;
2145
+ this.currentGeneration = generation;
1863
2146
  }
1864
2147
  }
1865
2148
  propagate(e, type) {
@@ -1903,13 +2186,17 @@ class EventManager {
1903
2186
  return propagationPath;
1904
2187
  }
1905
2188
  notifyTarget(e, type) {
2189
+ if (!this.inputValid()) {
2190
+ e.stopImmediatePropagation();
2191
+ return;
2192
+ }
1906
2193
  if (this.pauseNotify) {
1907
2194
  return;
1908
2195
  }
1909
2196
  type = type !== null && type !== void 0 ? type : e.type;
1910
2197
  const key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${type}capture` : type;
1911
2198
  this.notifyListeners(e, key);
1912
- if (e.eventPhase === e.AT_TARGET) {
2199
+ if (e.eventPhase === e.AT_TARGET && this.inputValid() && !e.propagationImmediatelyStopped) {
1913
2200
  this.notifyListeners(e, type);
1914
2201
  }
1915
2202
  }
@@ -1936,7 +2223,7 @@ class EventManager {
1936
2223
  this.copyData(from, event);
1937
2224
  event.nativeEvent = from.nativeEvent;
1938
2225
  event.originalEvent = from;
1939
- if (target) {
2226
+ if (target !== undefined) {
1940
2227
  event.target = target;
1941
2228
  }
1942
2229
  else {
@@ -2025,6 +2312,9 @@ class EventManager {
2025
2312
  trackingData(id) {
2026
2313
  if (!this.mappingState.trackingData[id]) {
2027
2314
  this.mappingState.trackingData[id] = {
2315
+ generation: 0,
2316
+ inside: false,
2317
+ previousInside: false,
2028
2318
  pressTargetsByButton: {},
2029
2319
  clicksByButton: {},
2030
2320
  overTarget: null
@@ -2047,6 +2337,11 @@ class EventManager {
2047
2337
  }
2048
2338
  freeEvent(event) {
2049
2339
  var _a;
2340
+ event.nativeEvent = null;
2341
+ event.originalEvent = null;
2342
+ if (!this.rootTarget) {
2343
+ return;
2344
+ }
2050
2345
  if (event.manager !== this) {
2051
2346
  throw new Error('It is illegal to free an event not managed by this EventManager!');
2052
2347
  }
@@ -2064,6 +2359,9 @@ class EventManager {
2064
2359
  (_a = this.eventPool.get(constructor)) === null || _a === void 0 ? void 0 : _a.push(event);
2065
2360
  }
2066
2361
  notifyListeners(e, type) {
2362
+ if (!this.inputValid() || !e.currentTarget) {
2363
+ return;
2364
+ }
2067
2365
  const events = e.currentTarget._events;
2068
2366
  const listeners = events[type];
2069
2367
  if (listeners) {
@@ -2074,7 +2372,7 @@ class EventManager {
2074
2372
  listeners.fn.call(listeners.context, e);
2075
2373
  }
2076
2374
  else {
2077
- for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++) {
2375
+ for (let i = 0, j = listeners.length; i < j && this.inputValid() && !e.propagationImmediatelyStopped; i++) {
2078
2376
  if (listeners[i].once) {
2079
2377
  e.currentTarget.removeEventListener(type, listeners[i].fn, { once: true });
2080
2378
  }
@@ -2082,9 +2380,14 @@ class EventManager {
2082
2380
  }
2083
2381
  }
2084
2382
  }
2085
- this.emitDelegation(e, type);
2383
+ if (this.inputValid()) {
2384
+ this.emitDelegation(e, type);
2385
+ }
2086
2386
  }
2087
2387
  emitDelegation(e, type) {
2388
+ if (!this.inputValid() || !e.currentTarget) {
2389
+ return;
2390
+ }
2088
2391
  const events = e.currentTarget._events;
2089
2392
  const listeners = events[WILDCARD];
2090
2393
  if (listeners) {
@@ -2092,7 +2395,7 @@ class EventManager {
2092
2395
  listeners.fn.call(listeners.context, e, type);
2093
2396
  }
2094
2397
  else {
2095
- for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++) {
2398
+ for (let i = 0, j = listeners.length; i < j && this.inputValid() && !e.propagationImmediatelyStopped; i++) {
2096
2399
  listeners[i].fn.call(listeners[i].context, e, type);
2097
2400
  }
2098
2401
  }
@@ -2119,11 +2422,15 @@ class EventManager {
2119
2422
  return target;
2120
2423
  }
2121
2424
  release() {
2425
+ var _a;
2122
2426
  this.dispatch.removeAllListeners();
2123
2427
  this.eventPool.clear();
2124
2428
  this.rootTarget = null;
2125
2429
  this.mappingTable = null;
2126
- this.mappingState = null;
2430
+ this.mappingState = { trackingData: {} };
2431
+ this.canvasInput.clear();
2432
+ this.windowInput.clear();
2433
+ (_a = this.dispatchingEvent) === null || _a === void 0 ? void 0 : _a.stopImmediatePropagation();
2127
2434
  this.cursorTarget = null;
2128
2435
  }
2129
2436
  }
@@ -2157,70 +2464,15 @@ const TOUCH_TO_POINTER = {
2157
2464
  class EventSystem {
2158
2465
  constructor(params) {
2159
2466
  this.resolution = 1;
2160
- this.onPointerDown = (nativeEvent) => {
2161
- if (this.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
2162
- return;
2163
- }
2164
- const events = this.normalizeToPointerData(nativeEvent);
2165
- if (this.autoPreventDefault && events[0].isNormalized) {
2166
- const cancelable = nativeEvent.cancelable || !('cancelable' in nativeEvent);
2167
- if (cancelable) {
2168
- nativeEvent.preventDefault();
2169
- }
2170
- }
2171
- for (let i = 0, j = events.length; i < j; i++) {
2172
- const nativeEvent = events[i];
2173
- const federatedEvent = this.bootstrapEvent(this.rootPointerEvent, nativeEvent);
2174
- this.manager.mapEvent(federatedEvent);
2175
- }
2176
- this.setCursor(this.manager.cursor, this.manager.cursorTarget);
2177
- this.rootPointerEvent.nativeEvent = null;
2178
- };
2179
- this.onPointerMove = (nativeEvent) => {
2180
- if (this.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
2181
- return;
2182
- }
2183
- if (this.isEventOutsideOfTargetElement(nativeEvent)) {
2184
- return;
2185
- }
2186
- const normalizedEvents = this.normalizeToPointerData(nativeEvent);
2187
- for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2188
- const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
2189
- this.manager.mapEvent(event);
2190
- }
2191
- this.setCursor(this.manager.cursor, this.manager.cursorTarget);
2192
- this.rootPointerEvent.nativeEvent = null;
2193
- };
2194
- this.onPointerUp = (nativeEvent) => {
2195
- if (this.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
2196
- return;
2197
- }
2198
- const outside = this.isEventOutsideOfTargetViewPort(nativeEvent) ? 'outside' : '';
2199
- const normalizedEvents = this.normalizeToPointerData(nativeEvent);
2200
- for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2201
- const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
2202
- event.type += outside;
2203
- this.manager.mapEvent(event);
2204
- }
2205
- this.setCursor(this.manager.cursor, this.manager.cursorTarget);
2206
- this.rootPointerEvent.nativeEvent = null;
2207
- };
2208
- this.onPointerOverOut = (nativeEvent) => {
2209
- if (this.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
2210
- return;
2211
- }
2212
- const normalizedEvents = this.normalizeToPointerData(nativeEvent);
2213
- for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2214
- const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
2215
- this.manager.mapEvent(event);
2216
- }
2217
- this.setCursor(this.manager.cursor, this.manager.cursorTarget);
2218
- this.rootPointerEvent.nativeEvent = null;
2219
- };
2220
- this.onWheel = (nativeEvent) => {
2221
- const wheelEvent = this.normalizeWheelEvent(nativeEvent);
2222
- this.manager.mapEvent(wheelEvent);
2223
- };
2467
+ this.released = false;
2468
+ this.processingInput = false;
2469
+ this.onPointerDown = (event) => this.handleNativeEvent(event);
2470
+ this.onPointerMove = (event) => this.handleNativeEvent(event);
2471
+ this.onPointerUp = (event) => this.handleNativeEvent(event);
2472
+ this.onPointerCancel = (event) => this.handleNativeEvent(event);
2473
+ this.onPointerOverOut = (event) => this.handleNativeEvent(event);
2474
+ this.onWheel = (event) => this.handleNativeEvent(event);
2475
+ this.onBlur = () => this.cancelAllPointers();
2224
2476
  const { targetElement, resolution, rootNode, global, autoPreventDefault = false, clickInterval, supportsTouchEvents = global.supportsTouchEvents, supportsPointerEvents = global.supportsPointerEvents } = params;
2225
2477
  this.manager = new EventManager(rootNode, {
2226
2478
  clickInterval,
@@ -2239,15 +2491,25 @@ class EventSystem {
2239
2491
  default: 'inherit',
2240
2492
  pointer: 'pointer'
2241
2493
  };
2494
+ this.useNativeEvents = params.useNativeEvents !== false;
2242
2495
  this.resolution = resolution;
2243
2496
  this.setTargetElement(targetElement);
2244
2497
  }
2245
2498
  release() {
2246
- this.removeEvents();
2247
- this.manager && this.manager.release();
2248
- this.domElement = null;
2249
- this.manager = null;
2250
- this.globalObj = null;
2499
+ if (this.released) {
2500
+ return;
2501
+ }
2502
+ this.released = true;
2503
+ this.pendingInputs = undefined;
2504
+ try {
2505
+ this.manager.cancelAllPointers();
2506
+ }
2507
+ finally {
2508
+ this.removeEvents();
2509
+ this.manager.release();
2510
+ this.domElement = null;
2511
+ this.globalObj = null;
2512
+ }
2251
2513
  }
2252
2514
  setCursor(mode, target) {
2253
2515
  if (!target && !this.manager.rootTarget.window._handler.canvas.controled) {
@@ -2277,13 +2539,118 @@ class EventSystem {
2277
2539
  domElement.style.cursor = mode;
2278
2540
  }
2279
2541
  }
2542
+ get input() {
2543
+ return this.manager.input;
2544
+ }
2545
+ handleNativeEvent(event, options) {
2546
+ var _a;
2547
+ if (this.released) {
2548
+ return;
2549
+ }
2550
+ if (this.processingInput) {
2551
+ ((_a = this.pendingInputs) !== null && _a !== void 0 ? _a : (this.pendingInputs = [])).push({
2552
+ event,
2553
+ options: options && {
2554
+ canvasPoint: { x: options.canvasPoint.x, y: options.canvasPoint.y },
2555
+ inViewport: options.inViewport
2556
+ }
2557
+ });
2558
+ return;
2559
+ }
2560
+ this.processingInput = true;
2561
+ try {
2562
+ this.processInput(event, options);
2563
+ this.drainInputQueue();
2564
+ }
2565
+ finally {
2566
+ this.processingInput = false;
2567
+ this.pendingInputs = undefined;
2568
+ this.rootPointerEvent.nativeEvent = null;
2569
+ this.rootWheelEvent.nativeEvent = null;
2570
+ }
2571
+ }
2572
+ cancelPointer(pointerId) {
2573
+ this.cancelInput(pointerId);
2574
+ }
2575
+ cancelAllPointers() {
2576
+ this.cancelInput();
2577
+ }
2578
+ cancelInput(pointerId) {
2579
+ if (this.released) {
2580
+ return;
2581
+ }
2582
+ const processing = this.processingInput;
2583
+ this.processingInput = true;
2584
+ try {
2585
+ if (pointerId === undefined) {
2586
+ this.manager.cancelAllPointers();
2587
+ }
2588
+ else {
2589
+ this.manager.cancelPointer(pointerId);
2590
+ }
2591
+ if (!processing) {
2592
+ this.drainInputQueue();
2593
+ }
2594
+ }
2595
+ finally {
2596
+ this.processingInput = processing;
2597
+ if (!processing) {
2598
+ this.pendingInputs = undefined;
2599
+ this.rootPointerEvent.nativeEvent = null;
2600
+ this.rootWheelEvent.nativeEvent = null;
2601
+ }
2602
+ }
2603
+ }
2604
+ drainInputQueue() {
2605
+ var _a;
2606
+ while (!this.released && ((_a = this.pendingInputs) === null || _a === void 0 ? void 0 : _a.length)) {
2607
+ const next = this.pendingInputs.shift();
2608
+ this.processInput(next.event, next.options);
2609
+ }
2610
+ }
2611
+ processInput(nativeEvent, options) {
2612
+ var _a, _b, _c;
2613
+ if (!options && this.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
2614
+ return;
2615
+ }
2616
+ if (nativeEvent.type === 'wheel') {
2617
+ const event = this.normalizeWheelEvent(nativeEvent, options === null || options === void 0 ? void 0 : options.canvasPoint);
2618
+ if ((_a = options === null || options === void 0 ? void 0 : options.inViewport) !== null && _a !== void 0 ? _a : !this.isEventOutsideOfTargetViewPort(nativeEvent, event)) {
2619
+ this.manager.mapEvent(event);
2620
+ }
2621
+ return;
2622
+ }
2623
+ const events = this.normalizeToPointerData(nativeEvent);
2624
+ if (this.autoPreventDefault && ((_b = events[0]) === null || _b === void 0 ? void 0 : _b.isNormalized) && nativeEvent.cancelable) {
2625
+ nativeEvent.preventDefault();
2626
+ }
2627
+ for (let i = 0; i < events.length && !this.released; i++) {
2628
+ const event = this.bootstrapEvent(this.rootPointerEvent, events[i], options === null || options === void 0 ? void 0 : options.canvasPoint);
2629
+ event.nativeEvent = nativeEvent;
2630
+ if (event.type === 'pointercancel') {
2631
+ this.manager.cancelPointer(event.pointerId);
2632
+ continue;
2633
+ }
2634
+ const inside = event.type !== 'pointerout' &&
2635
+ event.type !== 'pointerleave' &&
2636
+ ((_c = options === null || options === void 0 ? void 0 : options.inViewport) !== null && _c !== void 0 ? _c : !this.isEventOutsideOfTargetViewPort(nativeEvent, event));
2637
+ if (!inside && (event.type === 'pointerdown' || !this.manager.hasPointer(event.pointerId))) {
2638
+ continue;
2639
+ }
2640
+ this.manager.mapEvent(event, inside);
2641
+ }
2642
+ if (!options && !this.released) {
2643
+ this.setCursor(this.manager.cursor, this.manager.cursorTarget);
2644
+ }
2645
+ }
2280
2646
  setTargetElement(element) {
2281
2647
  this.removeEvents();
2282
2648
  this.domElement = element;
2283
2649
  this.addEvents();
2284
2650
  }
2285
2651
  addEvents() {
2286
- if (this.eventsAdded || !this.domElement) {
2652
+ var _a, _b, _c;
2653
+ if (!this.useNativeEvents || this.eventsAdded || !this.domElement) {
2287
2654
  return;
2288
2655
  }
2289
2656
  const { globalObj, domElement } = this;
@@ -2291,10 +2658,12 @@ class EventSystem {
2291
2658
  if (globalObj.getDocument()) {
2292
2659
  globalObj.addEventListener('pointermove', this.onPointerMove, true);
2293
2660
  globalObj.addEventListener('pointerup', this.onPointerUp, true);
2661
+ globalObj.addEventListener('pointercancel', this.onPointerCancel, true);
2294
2662
  }
2295
2663
  else {
2296
2664
  domElement.addEventListener('pointermove', this.onPointerMove, true);
2297
2665
  domElement.addEventListener('pointerup', this.onPointerUp, true);
2666
+ domElement.addEventListener('pointercancel', this.onPointerCancel, true);
2298
2667
  }
2299
2668
  domElement.addEventListener('pointerdown', this.onPointerDown, true);
2300
2669
  domElement.addEventListener('pointerleave', this.onPointerOverOut, true);
@@ -2316,26 +2685,32 @@ class EventSystem {
2316
2685
  if (this.supportsTouchEvents) {
2317
2686
  domElement.addEventListener('touchstart', this.onPointerDown, true);
2318
2687
  domElement.addEventListener('touchend', this.onPointerUp, true);
2319
- domElement.addEventListener('touchmove', this.onPointerMove, true);
2688
+ domElement.addEventListener('touchcancel', this.onPointerCancel, true);
2689
+ domElement.addEventListener('touchmove', this.onPointerMove, { capture: true, passive: false });
2320
2690
  }
2321
2691
  domElement.addEventListener('wheel', this.onWheel, {
2322
2692
  capture: true
2323
2693
  });
2694
+ (_c = (_b = (_a = globalObj.getDocument) === null || _a === void 0 ? void 0 : _a.call(globalObj)) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.addEventListener('blur', this.onBlur);
2324
2695
  this.eventsAdded = true;
2325
2696
  }
2326
2697
  removeEvents() {
2698
+ var _a, _b, _c;
2327
2699
  if (!this.eventsAdded || !this.domElement) {
2328
2700
  return;
2329
2701
  }
2330
2702
  const { globalObj, domElement } = this;
2703
+ (_c = (_b = (_a = globalObj.getDocument) === null || _a === void 0 ? void 0 : _a.call(globalObj)) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.removeEventListener('blur', this.onBlur);
2331
2704
  if (this.supportsPointerEvents) {
2332
2705
  if (globalObj.getDocument()) {
2333
2706
  globalObj.removeEventListener('pointermove', this.onPointerMove, true);
2334
2707
  globalObj.removeEventListener('pointerup', this.onPointerUp, true);
2708
+ globalObj.removeEventListener('pointercancel', this.onPointerCancel, true);
2335
2709
  }
2336
2710
  else {
2337
2711
  domElement.removeEventListener('pointermove', this.onPointerMove, true);
2338
2712
  domElement.removeEventListener('pointerup', this.onPointerUp, true);
2713
+ domElement.removeEventListener('pointercancel', this.onPointerCancel, true);
2339
2714
  }
2340
2715
  domElement.removeEventListener('pointerdown', this.onPointerDown, true);
2341
2716
  domElement.removeEventListener('pointerleave', this.onPointerOverOut, true);
@@ -2357,6 +2732,7 @@ class EventSystem {
2357
2732
  if (this.supportsTouchEvents) {
2358
2733
  domElement.removeEventListener('touchstart', this.onPointerDown, true);
2359
2734
  domElement.removeEventListener('touchend', this.onPointerUp, true);
2735
+ domElement.removeEventListener('touchcancel', this.onPointerCancel, true);
2360
2736
  domElement.removeEventListener('touchmove', this.onPointerMove, true);
2361
2737
  }
2362
2738
  domElement.removeEventListener('wheel', this.onWheel, true);
@@ -2487,14 +2863,14 @@ class EventSystem {
2487
2863
  }
2488
2864
  return normalizedEvents;
2489
2865
  }
2490
- normalizeWheelEvent(nativeEvent) {
2866
+ normalizeWheelEvent(nativeEvent, canvasPoint) {
2491
2867
  const event = this.rootWheelEvent;
2492
2868
  this.transferMouseData(event, nativeEvent);
2493
2869
  event.deltaMode = nativeEvent.deltaMode;
2494
2870
  event.deltaX = nativeEvent.deltaX;
2495
2871
  event.deltaY = nativeEvent.deltaY;
2496
2872
  event.deltaZ = nativeEvent.deltaZ;
2497
- const { x: canvasX, y: canvasY } = this.mapToCanvasPoint(nativeEvent);
2873
+ const { x: canvasX, y: canvasY } = canvasPoint !== null && canvasPoint !== void 0 ? canvasPoint : this.mapToCanvasPoint(nativeEvent);
2498
2874
  event.canvas.x = canvasX;
2499
2875
  event.canvas.y = canvasY;
2500
2876
  event.global.x = canvasX;
@@ -2508,7 +2884,7 @@ class EventSystem {
2508
2884
  event.type = nativeEvent.type;
2509
2885
  return event;
2510
2886
  }
2511
- bootstrapEvent(event, nativeEvent) {
2887
+ bootstrapEvent(event, nativeEvent, canvasPoint) {
2512
2888
  event.originalEvent = null;
2513
2889
  event.nativeEvent = nativeEvent;
2514
2890
  event.pointerId = nativeEvent.pointerId;
@@ -2522,7 +2898,7 @@ class EventSystem {
2522
2898
  event.tiltY = nativeEvent.tiltY;
2523
2899
  event.twist = nativeEvent.twist;
2524
2900
  this.transferMouseData(event, nativeEvent);
2525
- const { x: canvasX, y: canvasY } = this.mapToCanvasPoint(nativeEvent);
2901
+ const { x: canvasX, y: canvasY } = canvasPoint !== null && canvasPoint !== void 0 ? canvasPoint : this.mapToCanvasPoint(nativeEvent);
2526
2902
  event.canvas.x = canvasX;
2527
2903
  event.canvas.y = canvasY;
2528
2904
  event.global.x = canvasX;
@@ -2563,12 +2939,12 @@ class EventSystem {
2563
2939
  event.page.y = nativeEvent.pageY;
2564
2940
  event.relatedTarget = null;
2565
2941
  }
2566
- isEventOutsideOfTargetViewPort(nativeEvent) {
2942
+ isEventOutsideOfTargetViewPort(nativeEvent, event) {
2567
2943
  if (this.isEventOutsideOfTargetElement(nativeEvent)) {
2568
2944
  return true;
2569
2945
  }
2570
2946
  if (this.domElement.getViewBox) {
2571
- const p = this.mapToViewportPoint(this.mapToCanvasPoint(nativeEvent));
2947
+ const p = event.viewport;
2572
2948
  const b = this.domElement.getViewBox();
2573
2949
  const w = b.width();
2574
2950
  const h = b.height();
@@ -11020,6 +11396,7 @@ class Graphic extends Node {
11020
11396
  this.commitBaseAttributeBySingleKey(key, value, !!forceUpdateTag, context);
11021
11397
  }
11022
11398
  else {
11399
+ this.detachAttributeFromBaseAttributes();
11023
11400
  const nextAttrs = { [key]: value };
11024
11401
  this.applyBaseAttributes(nextAttrs);
11025
11402
  this.commitBaseAttributeMutation(!!forceUpdateTag, context);
@@ -12752,6 +13129,8 @@ const TEXT_UPDATE_TAG_KEY = [
12752
13129
  'fontSize',
12753
13130
  'fontFamily',
12754
13131
  'fontWeight',
13132
+ 'fontStyle',
13133
+ 'fontVariant',
12755
13134
  'ellipsis',
12756
13135
  'lineHeight',
12757
13136
  'direction',
@@ -12921,7 +13300,7 @@ class Text extends Graphic {
12921
13300
  var _a, _b;
12922
13301
  const textTheme = this.getGraphicTheme();
12923
13302
  const attribute = this.attribute;
12924
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, wrap = textTheme.wrap, measureMode = textTheme.measureMode, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition, ignoreBuf = textTheme.ignoreBuf, keepCenterInLine = textTheme.keepCenterInLine } = attribute;
13303
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontStyle = textTheme.fontStyle, fontVariant = textTheme.fontVariant, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, wrap = textTheme.wrap, measureMode = textTheme.measureMode, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace, suffixPosition = textTheme.suffixPosition, ignoreBuf = textTheme.ignoreBuf, keepCenterInLine = textTheme.keepCenterInLine } = attribute;
12925
13304
  const buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize);
12926
13305
  const lineHeight = this.getLineHeight(attribute, textTheme, buf);
12927
13306
  if (whiteSpace === 'normal' || wrap) {
@@ -12936,7 +13315,7 @@ class Text extends Graphic {
12936
13315
  return this._AABBBounds;
12937
13316
  }
12938
13317
  const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || ((_b = this.stage) === null || _b === void 0 ? void 0 : _b.textMeasureId));
12939
- const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily, lineHeight }, textMeasure);
13318
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily, fontStyle, fontVariant, lineHeight }, textMeasure);
12940
13319
  const layoutData = layoutObj.GetLayoutByLines(text, textAlign, textBaseline, lineHeight, ellipsis === true ? textTheme.ellipsis : ellipsis || undefined, false, {
12941
13320
  lineWidth: maxLineWidth,
12942
13321
  suffixPosition,
@@ -12955,7 +13334,7 @@ class Text extends Graphic {
12955
13334
  updateWrapAABBBounds(text) {
12956
13335
  var _a, _b, _c, _d;
12957
13336
  const textTheme = this.getGraphicTheme();
12958
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, measureMode = textTheme.measureMode, suffixPosition = textTheme.suffixPosition, heightLimit = 0, lineClamp, keepCenterInLine = textTheme.keepCenterInLine } = this.attribute;
13337
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, fontStyle = textTheme.fontStyle, fontVariant = textTheme.fontVariant, ignoreBuf = textTheme.ignoreBuf, measureMode = textTheme.measureMode, suffixPosition = textTheme.suffixPosition, heightLimit = 0, lineClamp, keepCenterInLine = textTheme.keepCenterInLine } = this.attribute;
12959
13338
  const buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize);
12960
13339
  const lineHeight = this.getLineHeight(this.attribute, textTheme, buf);
12961
13340
  if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
@@ -12967,7 +13346,7 @@ class Text extends Graphic {
12967
13346
  return this._AABBBounds;
12968
13347
  }
12969
13348
  const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || ((_b = this.stage) === null || _b === void 0 ? void 0 : _b.textMeasureId));
12970
- const textOptions = { fontSize, fontWeight, fontFamily, lineHeight };
13349
+ const textOptions = { fontSize, fontWeight, fontFamily, fontStyle, fontVariant, lineHeight };
12971
13350
  const layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure);
12972
13351
  const lines = isArray(text) ? text.map(l => l.toString()) : [text.toString()];
12973
13352
  const linesLayout = [];
@@ -13087,7 +13466,7 @@ class Text extends Graphic {
13087
13466
  const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || ((_a = this.stage) === null || _a === void 0 ? void 0 : _a.textMeasureId));
13088
13467
  let width;
13089
13468
  const attribute = this.attribute;
13090
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode, suffixPosition = textTheme.suffixPosition } = attribute;
13469
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontStyle = textTheme.fontStyle, fontVariant = textTheme.fontVariant, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode, suffixPosition = textTheme.suffixPosition } = attribute;
13091
13470
  const lineHeight = this.getLineHeight(attribute, textTheme, 0);
13092
13471
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
13093
13472
  if (!verticalMode) {
@@ -13117,12 +13496,12 @@ class Text extends Graphic {
13117
13496
  if (Number.isFinite(maxLineWidth)) {
13118
13497
  if (ellipsis) {
13119
13498
  const strEllipsis = (ellipsis === true ? textTheme.ellipsis : ellipsis);
13120
- const data = textMeasure.clipTextWithSuffixVertical(verticalData, { fontSize, fontWeight, fontFamily }, maxLineWidth, strEllipsis, false, suffixPosition);
13499
+ const data = textMeasure.clipTextWithSuffixVertical(verticalData, { fontSize, fontWeight, fontFamily, fontStyle, fontVariant }, maxLineWidth, strEllipsis, false, suffixPosition);
13121
13500
  verticalLists[i] = data.verticalList;
13122
13501
  width = data.width;
13123
13502
  }
13124
13503
  else {
13125
- const data = textMeasure.clipTextVertical(verticalData, { fontSize, fontWeight, fontFamily }, maxLineWidth, false);
13504
+ const data = textMeasure.clipTextVertical(verticalData, { fontSize, fontWeight, fontFamily, fontStyle, fontVariant }, maxLineWidth, false);
13126
13505
  verticalLists[i] = data.verticalList;
13127
13506
  width = data.width;
13128
13507
  }
@@ -13132,7 +13511,7 @@ class Text extends Graphic {
13132
13511
  verticalData.forEach(t => {
13133
13512
  const w = t.direction === TextDirection.HORIZONTAL
13134
13513
  ? fontSize
13135
- : textMeasure.measureTextWidth(t.text, { fontSize, fontWeight, fontFamily });
13514
+ : textMeasure.measureTextWidth(t.text, { fontSize, fontWeight, fontFamily, fontStyle, fontVariant });
13136
13515
  width += w;
13137
13516
  t.width = w;
13138
13517
  });
@@ -13217,7 +13596,7 @@ class WrapText extends Text {
13217
13596
  updateMultilineAABBBounds(text) {
13218
13597
  var _a, _b, _c, _d, _e;
13219
13598
  const textTheme = this.getGraphicTheme();
13220
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, suffixPosition = textTheme.suffixPosition, lineClamp } = this.attribute;
13599
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, fontStyle = textTheme.fontStyle, fontVariant = textTheme.fontVariant, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, suffixPosition = textTheme.suffixPosition, lineClamp } = this.attribute;
13221
13600
  const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
13222
13601
  const buf = ignoreBuf ? 0 : 2;
13223
13602
  if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
@@ -13229,7 +13608,7 @@ class WrapText extends Text {
13229
13608
  return this._AABBBounds;
13230
13609
  }
13231
13610
  const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || ((_c = this.stage) === null || _c === void 0 ? void 0 : _c.textMeasureId));
13232
- const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
13611
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily, fontStyle, fontVariant }, textMeasure);
13233
13612
  const lines = text.map(l => l.toString());
13234
13613
  const linesLayout = [];
13235
13614
  const bboxWH = [0, 0];
@@ -19950,7 +20329,7 @@ class Stage extends Group {
19950
20329
  this.pickerServiceFactory =
19951
20330
  (_e = deps.pickerServiceFactory) !== null && _e !== void 0 ? _e : (deps.pickerService
19952
20331
  ? () => deps.pickerService
19953
- : (_f = application.pickerServiceFactory) !== null && _f !== void 0 ? _f : (() => new DefaultGlobalPickerService()));
20332
+ : ((_f = application.pickerServiceFactory) !== null && _f !== void 0 ? _f : (() => new DefaultGlobalPickerService())));
19954
20333
  this.window = (_g = deps.window) !== null && _g !== void 0 ? _g : this.windowFactory();
19955
20334
  this.renderService =
19956
20335
  (_l = (_k = (_h = deps.renderService) !== null && _h !== void 0 ? _h : (_j = application.renderServiceFactory) === null || _j === void 0 ? void 0 : _j.call(application)) !== null && _k !== void 0 ? _k : application.renderService) !== null && _l !== void 0 ? _l : new DefaultRenderService();
@@ -20336,6 +20715,9 @@ class Stage extends Group {
20336
20715
  canvasId
20337
20716
  });
20338
20717
  this.appendChild(layer);
20718
+ if (this.interactiveLayer && layer !== this.interactiveLayer) {
20719
+ this.appendChild(this.interactiveLayer);
20720
+ }
20339
20721
  return layer;
20340
20722
  }
20341
20723
  sortLayer(cb) {
@@ -20345,6 +20727,9 @@ class Stage extends Group {
20345
20727
  children.forEach(c => {
20346
20728
  this.appendChild(c);
20347
20729
  });
20730
+ if (this.interactiveLayer) {
20731
+ this.appendChild(this.interactiveLayer);
20732
+ }
20348
20733
  }
20349
20734
  removeLayer(ILayerId) {
20350
20735
  return this.removeChild(this.findChildByUid(ILayerId));
@@ -20354,12 +20739,18 @@ class Stage extends Group {
20354
20739
  return;
20355
20740
  }
20356
20741
  if (this.supportInteractiveLayer && !this.interactiveLayer) {
20357
- this.interactiveLayer = this.createLayer();
20742
+ this.interactiveLayer = this.createLayer(undefined, this.params.interactiveLayerMode);
20358
20743
  this.interactiveLayer.name = '_builtin_interactive';
20359
20744
  this.interactiveLayer.attribute.pickable = false;
20360
20745
  this.nextFrameRenderLayerSet.add(this.interactiveLayer);
20361
20746
  }
20362
20747
  }
20748
+ prepareRenderLayers() {
20749
+ if (this.params.interactiveLayerMode === 'virtual') {
20750
+ this.tryInitInteractiveLayer();
20751
+ }
20752
+ this.layerService.prepareStageLayer(this);
20753
+ }
20363
20754
  clearViewBox(color) {
20364
20755
  this.window.clearViewBox(color);
20365
20756
  }
@@ -20367,14 +20758,18 @@ class Stage extends Group {
20367
20758
  if (this.releaseStatus === 'released') {
20368
20759
  return;
20369
20760
  }
20761
+ if (this.params.requestRender) {
20762
+ this.params.requestRender();
20763
+ return;
20764
+ }
20370
20765
  this.startAnimate();
20371
20766
  const state = this.state;
20372
20767
  this.state = 'rendering';
20373
- this.layerService.prepareStageLayer(this);
20374
20768
  if (!this._skipRender) {
20375
20769
  this.lastRenderparams = params;
20376
20770
  this.hooks.beforeRender.call(this);
20377
20771
  if (!this._skipRender) {
20772
+ this.prepareRenderLayers();
20378
20773
  this.renderLayerList(this.children);
20379
20774
  this.combineLayersToWindow();
20380
20775
  this.nextFrameRenderLayerSet.clear();
@@ -20400,6 +20795,15 @@ class Stage extends Group {
20400
20795
  return;
20401
20796
  }
20402
20797
  renderNextFrame(layers, force) {
20798
+ if (this.releaseStatus === 'released') {
20799
+ return;
20800
+ }
20801
+ if (this.params.requestRender) {
20802
+ if (this.state !== 'rendering') {
20803
+ this.params.requestRender();
20804
+ }
20805
+ return;
20806
+ }
20403
20807
  if (this.nextFrameRenderLayerSet.size !== this.childrenCount) {
20404
20808
  (layers || this).forEach((layer) => {
20405
20809
  this.nextFrameRenderLayerSet.add(layer);
@@ -20427,10 +20831,10 @@ class Stage extends Group {
20427
20831
  this.startAnimate();
20428
20832
  const state = this.state;
20429
20833
  this.state = 'rendering';
20430
- this.layerService.prepareStageLayer(this);
20431
20834
  if (this.nextFrameRenderLayerSet.size && !this._skipRender) {
20432
20835
  this.hooks.beforeRender.call(this);
20433
20836
  if (!this._skipRender) {
20837
+ this.prepareRenderLayers();
20434
20838
  this.renderLayerList(Array.from(this.nextFrameRenderLayerSet.values()), this.lastRenderparams || {});
20435
20839
  this.combineLayersToWindow();
20436
20840
  this.nextFrameRenderLayerSet.clear();
@@ -20597,20 +21001,35 @@ class Stage extends Group {
20597
21001
  const layer = this.children.filter(layer => layer.name === name);
20598
21002
  return layer[0];
20599
21003
  }
20600
- renderTo(window) {
21004
+ renderTo(window, _params, options) {
20601
21005
  if (this.releaseStatus === 'released') {
20602
21006
  return;
20603
21007
  }
20604
- this.forEachChildren((layer, i) => {
20605
- layer.drawTo(window, {
20606
- renderService: this.renderService,
20607
- viewBox: window.getViewBox(),
20608
- transMatrix: window.getViewBoxTransform(),
20609
- background: layer === this.defaultLayer ? this.background : undefined,
20610
- clear: i === 0,
20611
- updateBounds: !!(this.dirtyBounds && !this.dirtyBounds.empty())
21008
+ const state = this.state;
21009
+ this.state = 'rendering';
21010
+ try {
21011
+ if (this.params.requestRender) {
21012
+ this.hooks.beforeRender.call(this);
21013
+ }
21014
+ this.prepareRenderLayers();
21015
+ this.forEachChildren((layer, i) => {
21016
+ var _a, _b;
21017
+ layer.drawTo(window, {
21018
+ renderService: this.renderService,
21019
+ viewBox: (_a = options === null || options === void 0 ? void 0 : options.viewBox) !== null && _a !== void 0 ? _a : window.getViewBox(),
21020
+ transMatrix: (_b = options === null || options === void 0 ? void 0 : options.transMatrix) !== null && _b !== void 0 ? _b : window.getViewBoxTransform(),
21021
+ background: layer === this.defaultLayer ? this.background : undefined,
21022
+ clear: i === 0 && (options === null || options === void 0 ? void 0 : options.clear) !== false,
21023
+ updateBounds: !!(this.dirtyBounds && !this.dirtyBounds.empty())
21024
+ });
20612
21025
  });
20613
- });
21026
+ if (this.params.requestRender) {
21027
+ this.hooks.afterRender.call(this);
21028
+ }
21029
+ }
21030
+ finally {
21031
+ this.state = state;
21032
+ }
20614
21033
  }
20615
21034
  renderToNewWindow(fullImage = true, viewBox) {
20616
21035
  if (this.releaseStatus === 'released') {
@@ -20667,6 +21086,9 @@ class Stage extends Group {
20667
21086
  return this._cursor;
20668
21087
  }
20669
21088
  eventPointTransform(e) {
21089
+ if (e instanceof FederatedMouseEvent) {
21090
+ return { x: e.viewX, y: e.viewY };
21091
+ }
20670
21092
  const point = this.global.mapToCanvasPoint(e, this.window);
20671
21093
  return this.stage.window.pointTransform(point.x, point.y);
20672
21094
  }
@@ -21860,9 +22282,60 @@ class CanvasLayerHandlerContribution {
21860
22282
  }
21861
22283
  }
21862
22284
 
22285
+ class EmptyLayerHandlerContribution {
22286
+ constructor() {
22287
+ this.offscreen = false;
22288
+ this.type = 'virtual';
22289
+ this.global = application.global;
22290
+ }
22291
+ setDpr(dpr) {
22292
+ return;
22293
+ }
22294
+ init(layer, window, params) {
22295
+ this.layer = layer;
22296
+ this.window = window;
22297
+ if (params.main) {
22298
+ throw new Error('virtual layer不能作为main layer');
22299
+ }
22300
+ this.main = false;
22301
+ this.canvas = null;
22302
+ this.context = null;
22303
+ }
22304
+ resize(w, h) {
22305
+ return;
22306
+ }
22307
+ resizeView(w, h) {
22308
+ return;
22309
+ }
22310
+ render(group, params, userParams) {
22311
+ this.mainHandler.render(group, params, Object.assign(Object.assign({}, userParams), { clear: false }));
22312
+ return;
22313
+ }
22314
+ merge(layerHandlers) {
22315
+ return;
22316
+ }
22317
+ prepare(dirtyBounds, params) {
22318
+ return;
22319
+ }
22320
+ drawTo(target, group, params) {
22321
+ var _a;
22322
+ const context = target.getContext();
22323
+ params.renderService.render(group, Object.assign(Object.assign({ context }, params), { clear: params.clear ? (_a = params.background) !== null && _a !== void 0 ? _a : '#fff' : undefined }));
22324
+ return;
22325
+ }
22326
+ getContext() {
22327
+ return null;
22328
+ }
22329
+ release() {
22330
+ return;
22331
+ }
22332
+ }
22333
+
21863
22334
  function bindLayerHandlerModules({ bind }) {
21864
22335
  bind(CanvasLayerHandlerContribution).toSelf();
22336
+ bind(EmptyLayerHandlerContribution).toSelf();
21865
22337
  bind(StaticLayerHandlerContribution).toService(CanvasLayerHandlerContribution);
22338
+ bind(VirtualLayerHandlerContribution).toService(EmptyLayerHandlerContribution);
21866
22339
  }
21867
22340
 
21868
22341
  function load$1(container) {
@@ -23700,12 +24173,24 @@ class InteractiveDrawItemInterceptorContribution {
23700
24173
  this.processing = true;
23701
24174
  const { context } = drawContext;
23702
24175
  context.highPerformanceSave();
23703
- context.setTransformFromMatrix(baseGraphic.parent.globalTransMatrix, true);
23704
- baseGraphic.isContainer
23705
- ? drawContribution.renderGroup(baseGraphic, drawContext, baseGraphic.parent.globalTransMatrix)
23706
- : drawContribution.renderItem(baseGraphic, drawContext);
23707
- context.highPerformanceRestore();
23708
- this.processing = false;
24176
+ const parent = baseGraphic.parent.globalTransMatrix;
24177
+ const matrix = matrixAllocate.allocateByObj(parent);
24178
+ if (drawContext.transMatrix) {
24179
+ const outer = drawContext.transMatrix;
24180
+ matrix.setValue(outer.a, outer.b, outer.c, outer.d, outer.e, outer.f);
24181
+ matrix.multiply(parent.a, parent.b, parent.c, parent.d, parent.e, parent.f);
24182
+ }
24183
+ try {
24184
+ context.setTransformFromMatrix(matrix, true);
24185
+ baseGraphic.isContainer
24186
+ ? drawContribution.renderGroup(baseGraphic, drawContext, matrix)
24187
+ : drawContribution.renderItem(baseGraphic, drawContext);
24188
+ }
24189
+ finally {
24190
+ context.highPerformanceRestore();
24191
+ matrixAllocate.free(matrix);
24192
+ this.processing = false;
24193
+ }
23709
24194
  return true;
23710
24195
  }
23711
24196
  return false;