@vunk/plus 1.3.10 → 1.3.12

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 (119) hide show
  1. package/components/SharedSystems.mjs +3195 -0
  2. package/components/WebGLRenderer.mjs +3617 -0
  3. package/components/WebGPURenderer.mjs +2103 -0
  4. package/components/_commonjsHelpers.mjs +7 -0
  5. package/components/agent-chat-provider/index.d.ts +7 -0
  6. package/components/agent-chat-provider/src/api.d.ts +3 -0
  7. package/components/agent-chat-provider/src/const-roles.d.ts +8 -0
  8. package/components/agent-chat-provider/src/const.d.ts +1 -0
  9. package/components/agent-chat-provider/src/index.vue.d.ts +47 -0
  10. package/components/agent-chat-provider/src/types.d.ts +43 -0
  11. package/components/agent-chat-provider/src/use.d.ts +29 -0
  12. package/components/avatar/index.d.ts +4 -0
  13. package/components/avatar/src/ctx.d.ts +18 -0
  14. package/components/avatar/src/index.vue.d.ts +121 -0
  15. package/components/avatar/src/types.d.ts +1 -0
  16. package/components/broadcasting-markdown/index.d.ts +7 -0
  17. package/components/broadcasting-markdown/index.mjs +238 -306
  18. package/components/broadcasting-markdown/src/const.d.ts +13 -0
  19. package/components/broadcasting-markdown/src/ctx.d.ts +115 -0
  20. package/components/broadcasting-markdown/src/howler-speech.vue.d.ts +97 -0
  21. package/components/broadcasting-markdown/src/index.vue.d.ts +383 -0
  22. package/components/broadcasting-markdown/src/paragraph.vue.d.ts +79 -0
  23. package/components/broadcasting-markdown/src/speech-error.vue.d.ts +60 -0
  24. package/components/broadcasting-markdown/src/types.d.ts +25 -0
  25. package/components/broadcasting-markdown/src/use.d.ts +21 -0
  26. package/components/browserAll.mjs +3187 -0
  27. package/components/bubble-list/index.d.ts +5 -0
  28. package/components/bubble-list/index.mjs +2 -1
  29. package/components/bubble-list/src/ctx.d.ts +30 -0
  30. package/components/bubble-list/src/index.vue.d.ts +867 -0
  31. package/components/bubble-list/src/types.d.ts +4 -0
  32. package/components/bubble-templates/index.d.ts +4 -0
  33. package/components/bubble-templates/src/index.vue.d.ts +539 -0
  34. package/components/bubble-templates/src/types.d.ts +40 -0
  35. package/components/chat-independent/index.d.ts +4 -0
  36. package/components/chat-independent/index.mjs +3 -0
  37. package/components/chat-independent/src/const.d.ts +13 -0
  38. package/components/chat-independent/src/ctx.d.ts +20 -0
  39. package/components/chat-independent/src/index.vue.d.ts +2343 -0
  40. package/components/chat-independent/src/types.d.ts +13 -0
  41. package/components/colorToUniform.mjs +266 -0
  42. package/components/index.d.ts +0 -0
  43. package/components/index2.mjs +21227 -0
  44. package/components/init.mjs +3779 -0
  45. package/components/lottie-animation/index.d.ts +4 -0
  46. package/components/lottie-animation/src/ctx.d.ts +10 -0
  47. package/components/lottie-animation/src/index.vue.d.ts +21 -0
  48. package/components/lottie-animation/src/types.d.ts +4 -0
  49. package/components/monaco-editor/index.d.ts +5 -0
  50. package/components/monaco-editor/src/ctx.d.ts +23 -0
  51. package/components/monaco-editor/src/index.vue.d.ts +40 -0
  52. package/components/monaco-editor/src/types.d.ts +1 -0
  53. package/components/monaco-environment/index.d.ts +4 -0
  54. package/components/monaco-environment/src/ctx.d.ts +8 -0
  55. package/components/monaco-environment/src/index.vue.d.ts +2 -0
  56. package/components/monaco-environment/src/types.d.ts +1 -0
  57. package/components/pixi-frame/index.css +4 -0
  58. package/components/pixi-frame/index.d.ts +7 -0
  59. package/components/pixi-frame/index.mjs +6 -0
  60. package/components/pixi-frame/src/app.vue.d.ts +29 -0
  61. package/components/pixi-frame/src/core.vue.d.ts +122 -0
  62. package/components/pixi-frame/src/ctx.d.ts +40 -0
  63. package/components/pixi-frame/src/index.vue.d.ts +218 -0
  64. package/components/pixi-frame/src/types.d.ts +1 -0
  65. package/components/pixi-frame/src/use.d.ts +3 -0
  66. package/components/recorder-button/index.d.ts +4 -0
  67. package/components/recorder-button/src/ctx.d.ts +41 -0
  68. package/components/recorder-button/src/index.vue.d.ts +300 -0
  69. package/components/recorder-button/src/speech-to-text.d.ts +1 -0
  70. package/components/recorder-button/src/types.d.ts +7 -0
  71. package/components/routes-menu-content/index.d.ts +4 -0
  72. package/components/routes-menu-content/src/ctx.d.ts +17 -0
  73. package/components/routes-menu-content/src/index.vue.d.ts +472 -0
  74. package/components/routes-menu-content/src/item/core/ctx.d.ts +18 -0
  75. package/components/routes-menu-content/src/item/core/index.vue.d.ts +307 -0
  76. package/components/routes-menu-content/src/item/ctx.d.ts +14 -0
  77. package/components/routes-menu-content/src/item/index.vue.d.ts +438 -0
  78. package/components/routes-menu-content/src/types.d.ts +1 -0
  79. package/components/sender/index.d.ts +4 -0
  80. package/components/sender/src/SenderHeader.vue.d.ts +256 -0
  81. package/components/sender/src/ctx.d.ts +62 -0
  82. package/components/sender/src/index.vue.d.ts +787 -0
  83. package/components/sender/src/types.d.ts +1 -0
  84. package/components/speech-button/index.d.ts +4 -0
  85. package/components/speech-button/src/LoadingIcon.vue.d.ts +2 -0
  86. package/components/speech-button/src/RecordingIcon.vue.d.ts +2 -0
  87. package/components/speech-button/src/ctx.d.ts +10 -0
  88. package/components/speech-button/src/index.vue.d.ts +22 -0
  89. package/components/speech-button/src/types.d.ts +1 -0
  90. package/components/table-columns/index.d.ts +5 -0
  91. package/components/table-columns/src/ctx.d.ts +66 -0
  92. package/components/table-columns/src/el-ctx.d.ts +63 -0
  93. package/components/table-columns/src/index.vue.d.ts +282 -0
  94. package/components/table-columns/src/types.d.ts +21 -0
  95. package/components/tables-v1/index.d.ts +5 -0
  96. package/components/tables-v1/src/ctx.d.ts +281 -0
  97. package/components/tables-v1/src/el-ctx.d.ts +269 -0
  98. package/components/tables-v1/src/index.vue.d.ts +3014 -0
  99. package/components/tables-v1/src/types.d.ts +4 -0
  100. package/components/tables-v1-checkbox/index.d.ts +5 -0
  101. package/components/tables-v1-checkbox/src/ctx.d.ts +321 -0
  102. package/components/tables-v1-checkbox/src/index.vue.d.ts +3796 -0
  103. package/components/tables-v1-checkbox/src/types.d.ts +1 -0
  104. package/components/typing-markdown/index.d.ts +4 -0
  105. package/components/typing-markdown/src/core.d.ts +2 -0
  106. package/components/typing-markdown/src/ctx.d.ts +33 -0
  107. package/components/typing-markdown/src/index.vue.d.ts +57 -0
  108. package/components/typing-markdown/src/types.d.ts +1 -0
  109. package/components/vditor/index.d.ts +5 -0
  110. package/components/vditor/src/ctx.d.ts +37 -0
  111. package/components/vditor/src/handle-fullscreen.vue.d.ts +18 -0
  112. package/components/vditor/src/handle-value.vue.d.ts +18 -0
  113. package/components/vditor/src/index.vue.d.ts +144 -0
  114. package/components/vditor/src/types.d.ts +9 -0
  115. package/components/vditor/src/use.d.ts +4 -0
  116. package/components/webworkerAll.mjs +8 -0
  117. package/index.css +5 -4
  118. package/package.json +8 -4
  119. package/components/broadcasting-markdown/index.css +0 -3
@@ -0,0 +1,3187 @@
1
+ import { P as Point, r as removeItems, E as ExtensionType, T as Ticker, U as UPDATE_PRIORITY, a as EventEmitter, w as warn, e as extensions, C as Container } from './index2.mjs';
2
+ import './init.mjs';
3
+ import 'vue';
4
+ import './_commonjsHelpers.mjs';
5
+ import '@vunk/shared/enum';
6
+ import './browser.mjs';
7
+ import './_plugin-vue_export-helper.mjs';
8
+ import './colorToUniform.mjs';
9
+
10
+ class FederatedEvent {
11
+ /**
12
+ * @param manager - The event boundary which manages this event. Propagation can only occur
13
+ * within the boundary's jurisdiction.
14
+ */
15
+ constructor(manager) {
16
+ /** Flags whether this event bubbles. This will take effect only if it is set before propagation. */
17
+ this.bubbles = true;
18
+ /** @deprecated since 7.0.0 */
19
+ this.cancelBubble = true;
20
+ /**
21
+ * Flags whether this event can be canceled using {@link FederatedEvent.preventDefault}. This is always
22
+ * false (for now).
23
+ */
24
+ this.cancelable = false;
25
+ /**
26
+ * Flag added for compatibility with DOM {@code Event}. It is not used in the Federated Events
27
+ * API.
28
+ * @see https://dom.spec.whatwg.org/#dom-event-composed
29
+ */
30
+ this.composed = false;
31
+ /** Flags whether the default response of the user agent was prevent through this event. */
32
+ this.defaultPrevented = false;
33
+ /**
34
+ * The propagation phase.
35
+ * @default {@link FederatedEvent.NONE}
36
+ */
37
+ this.eventPhase = FederatedEvent.prototype.NONE;
38
+ /** Flags whether propagation was stopped. */
39
+ this.propagationStopped = false;
40
+ /** Flags whether propagation was immediately stopped. */
41
+ this.propagationImmediatelyStopped = false;
42
+ /** The coordinates of the event relative to the nearest DOM layer. This is a non-standard property. */
43
+ this.layer = new Point();
44
+ /** The coordinates of the event relative to the DOM document. This is a non-standard property. */
45
+ this.page = new Point();
46
+ this.NONE = 0;
47
+ this.CAPTURING_PHASE = 1;
48
+ this.AT_TARGET = 2;
49
+ this.BUBBLING_PHASE = 3;
50
+ this.manager = manager;
51
+ }
52
+ /** @readonly */
53
+ get layerX() {
54
+ return this.layer.x;
55
+ }
56
+ /** @readonly */
57
+ get layerY() {
58
+ return this.layer.y;
59
+ }
60
+ /** @readonly */
61
+ get pageX() {
62
+ return this.page.x;
63
+ }
64
+ /** @readonly */
65
+ get pageY() {
66
+ return this.page.y;
67
+ }
68
+ /**
69
+ * Fallback for the deprecated @code{InteractionEvent.data}.
70
+ * @deprecated since 7.0.0
71
+ */
72
+ get data() {
73
+ return this;
74
+ }
75
+ /** The propagation path for this event. Alias for {@link EventBoundary.propagationPath}. */
76
+ composedPath() {
77
+ if (this.manager && (!this.path || this.path[this.path.length - 1] !== this.target)) {
78
+ this.path = this.target ? this.manager.propagationPath(this.target) : [];
79
+ }
80
+ return this.path;
81
+ }
82
+ /**
83
+ * Unimplemented method included for implementing the DOM interface {@code Event}. It will throw an {@code Error}.
84
+ * @deprecated
85
+ * @param _type
86
+ * @param _bubbles
87
+ * @param _cancelable
88
+ */
89
+ initEvent(_type, _bubbles, _cancelable) {
90
+ throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
91
+ }
92
+ /**
93
+ * Unimplemented method included for implementing the DOM interface {@code UIEvent}. It will throw an {@code Error}.
94
+ * @deprecated
95
+ * @param _typeArg
96
+ * @param _bubblesArg
97
+ * @param _cancelableArg
98
+ * @param _viewArg
99
+ * @param _detailArg
100
+ */
101
+ initUIEvent(_typeArg, _bubblesArg, _cancelableArg, _viewArg, _detailArg) {
102
+ throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
103
+ }
104
+ /** Prevent default behavior of PixiJS and the user agent. */
105
+ preventDefault() {
106
+ if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
107
+ this.nativeEvent.preventDefault();
108
+ }
109
+ this.defaultPrevented = true;
110
+ }
111
+ /**
112
+ * Stop this event from propagating to any addition listeners, including on the
113
+ * {@link FederatedEventTarget.currentTarget currentTarget} and also the following
114
+ * event targets on the propagation path.
115
+ */
116
+ stopImmediatePropagation() {
117
+ this.propagationImmediatelyStopped = true;
118
+ }
119
+ /**
120
+ * Stop this event from propagating to the next {@link FederatedEventTarget}. The rest of the listeners
121
+ * on the {@link FederatedEventTarget.currentTarget currentTarget} will still be notified.
122
+ */
123
+ stopPropagation() {
124
+ this.propagationStopped = true;
125
+ }
126
+ }
127
+
128
+ var appleIphone = /iPhone/i;
129
+ var appleIpod = /iPod/i;
130
+ var appleTablet = /iPad/i;
131
+ var appleUniversal = /\biOS-universal(?:.+)Mac\b/i;
132
+ var androidPhone = /\bAndroid(?:.+)Mobile\b/i;
133
+ var androidTablet = /Android/i;
134
+ var amazonPhone = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i;
135
+ var amazonTablet = /Silk/i;
136
+ var windowsPhone = /Windows Phone/i;
137
+ var windowsTablet = /\bWindows(?:.+)ARM\b/i;
138
+ var otherBlackBerry = /BlackBerry/i;
139
+ var otherBlackBerry10 = /BB10/i;
140
+ var otherOpera = /Opera Mini/i;
141
+ var otherChrome = /\b(CriOS|Chrome)(?:.+)Mobile/i;
142
+ var otherFirefox = /Mobile(?:.+)Firefox\b/i;
143
+ var isAppleTabletOnIos13 = function (navigator) {
144
+ return (typeof navigator !== 'undefined' &&
145
+ navigator.platform === 'MacIntel' &&
146
+ typeof navigator.maxTouchPoints === 'number' &&
147
+ navigator.maxTouchPoints > 1 &&
148
+ typeof MSStream === 'undefined');
149
+ };
150
+ function createMatch(userAgent) {
151
+ return function (regex) { return regex.test(userAgent); };
152
+ }
153
+ function isMobile$1(param) {
154
+ var nav = {
155
+ userAgent: '',
156
+ platform: '',
157
+ maxTouchPoints: 0
158
+ };
159
+ if (!param && typeof navigator !== 'undefined') {
160
+ nav = {
161
+ userAgent: navigator.userAgent,
162
+ platform: navigator.platform,
163
+ maxTouchPoints: navigator.maxTouchPoints || 0
164
+ };
165
+ }
166
+ else if (typeof param === 'string') {
167
+ nav.userAgent = param;
168
+ }
169
+ else if (param && param.userAgent) {
170
+ nav = {
171
+ userAgent: param.userAgent,
172
+ platform: param.platform,
173
+ maxTouchPoints: param.maxTouchPoints || 0
174
+ };
175
+ }
176
+ var userAgent = nav.userAgent;
177
+ var tmp = userAgent.split('[FBAN');
178
+ if (typeof tmp[1] !== 'undefined') {
179
+ userAgent = tmp[0];
180
+ }
181
+ tmp = userAgent.split('Twitter');
182
+ if (typeof tmp[1] !== 'undefined') {
183
+ userAgent = tmp[0];
184
+ }
185
+ var match = createMatch(userAgent);
186
+ var result = {
187
+ apple: {
188
+ phone: match(appleIphone) && !match(windowsPhone),
189
+ ipod: match(appleIpod),
190
+ tablet: !match(appleIphone) &&
191
+ (match(appleTablet) || isAppleTabletOnIos13(nav)) &&
192
+ !match(windowsPhone),
193
+ universal: match(appleUniversal),
194
+ device: (match(appleIphone) ||
195
+ match(appleIpod) ||
196
+ match(appleTablet) ||
197
+ match(appleUniversal) ||
198
+ isAppleTabletOnIos13(nav)) &&
199
+ !match(windowsPhone)
200
+ },
201
+ amazon: {
202
+ phone: match(amazonPhone),
203
+ tablet: !match(amazonPhone) && match(amazonTablet),
204
+ device: match(amazonPhone) || match(amazonTablet)
205
+ },
206
+ android: {
207
+ phone: (!match(windowsPhone) && match(amazonPhone)) ||
208
+ (!match(windowsPhone) && match(androidPhone)),
209
+ tablet: !match(windowsPhone) &&
210
+ !match(amazonPhone) &&
211
+ !match(androidPhone) &&
212
+ (match(amazonTablet) || match(androidTablet)),
213
+ device: (!match(windowsPhone) &&
214
+ (match(amazonPhone) ||
215
+ match(amazonTablet) ||
216
+ match(androidPhone) ||
217
+ match(androidTablet))) ||
218
+ match(/\bokhttp\b/i)
219
+ },
220
+ windows: {
221
+ phone: match(windowsPhone),
222
+ tablet: match(windowsTablet),
223
+ device: match(windowsPhone) || match(windowsTablet)
224
+ },
225
+ other: {
226
+ blackberry: match(otherBlackBerry),
227
+ blackberry10: match(otherBlackBerry10),
228
+ opera: match(otherOpera),
229
+ firefox: match(otherFirefox),
230
+ chrome: match(otherChrome),
231
+ device: match(otherBlackBerry) ||
232
+ match(otherBlackBerry10) ||
233
+ match(otherOpera) ||
234
+ match(otherFirefox) ||
235
+ match(otherChrome)
236
+ },
237
+ any: false,
238
+ phone: false,
239
+ tablet: false
240
+ };
241
+ result.any =
242
+ result.apple.device ||
243
+ result.android.device ||
244
+ result.windows.device ||
245
+ result.other.device;
246
+ result.phone =
247
+ result.apple.phone || result.android.phone || result.windows.phone;
248
+ result.tablet =
249
+ result.apple.tablet || result.android.tablet || result.windows.tablet;
250
+ return result;
251
+ }
252
+
253
+ const isMobileCall = isMobile$1.default ?? isMobile$1;
254
+ const isMobile = isMobileCall(globalThis.navigator);
255
+
256
+ const KEY_CODE_TAB = 9;
257
+ const DIV_TOUCH_SIZE = 100;
258
+ const DIV_TOUCH_POS_X = 0;
259
+ const DIV_TOUCH_POS_Y = 0;
260
+ const DIV_TOUCH_ZINDEX = 2;
261
+ const DIV_HOOK_SIZE = 1;
262
+ const DIV_HOOK_POS_X = -1e3;
263
+ const DIV_HOOK_POS_Y = -1e3;
264
+ const DIV_HOOK_ZINDEX = 2;
265
+ const _AccessibilitySystem = class _AccessibilitySystem {
266
+ // 2fps
267
+ // eslint-disable-next-line jsdoc/require-param
268
+ /**
269
+ * @param {WebGLRenderer|WebGPURenderer} renderer - A reference to the current renderer
270
+ */
271
+ constructor(renderer, _mobileInfo = isMobile) {
272
+ this._mobileInfo = _mobileInfo;
273
+ /** Whether accessibility divs are visible for debugging */
274
+ this.debug = false;
275
+ /** Whether to activate on tab key press */
276
+ this._activateOnTab = true;
277
+ /** Whether to deactivate accessibility when mouse moves */
278
+ this._deactivateOnMouseMove = true;
279
+ /** Internal variable, see isActive getter. */
280
+ this._isActive = false;
281
+ /** Internal variable, see isMobileAccessibility getter. */
282
+ this._isMobileAccessibility = false;
283
+ /** This is the dom element that will sit over the PixiJS element. This is where the div overlays will go. */
284
+ this._div = null;
285
+ /** A simple pool for storing divs. */
286
+ this._pool = [];
287
+ /** This is a tick used to check if an object is no longer being rendered. */
288
+ this._renderId = 0;
289
+ /** The array of currently active accessible items. */
290
+ this._children = [];
291
+ /** Count to throttle div updates on android devices. */
292
+ this._androidUpdateCount = 0;
293
+ /** The frequency to update the div elements. */
294
+ this._androidUpdateFrequency = 500;
295
+ this._hookDiv = null;
296
+ if (_mobileInfo.tablet || _mobileInfo.phone) {
297
+ this._createTouchHook();
298
+ }
299
+ this._renderer = renderer;
300
+ }
301
+ /**
302
+ * Value of `true` if accessibility is currently active and accessibility layers are showing.
303
+ * @member {boolean}
304
+ * @readonly
305
+ */
306
+ get isActive() {
307
+ return this._isActive;
308
+ }
309
+ /**
310
+ * Value of `true` if accessibility is enabled for touch devices.
311
+ * @member {boolean}
312
+ * @readonly
313
+ */
314
+ get isMobileAccessibility() {
315
+ return this._isMobileAccessibility;
316
+ }
317
+ get hookDiv() {
318
+ return this._hookDiv;
319
+ }
320
+ /**
321
+ * Creates the touch hooks.
322
+ * @private
323
+ */
324
+ _createTouchHook() {
325
+ const hookDiv = document.createElement("button");
326
+ hookDiv.style.width = `${DIV_HOOK_SIZE}px`;
327
+ hookDiv.style.height = `${DIV_HOOK_SIZE}px`;
328
+ hookDiv.style.position = "absolute";
329
+ hookDiv.style.top = `${DIV_HOOK_POS_X}px`;
330
+ hookDiv.style.left = `${DIV_HOOK_POS_Y}px`;
331
+ hookDiv.style.zIndex = DIV_HOOK_ZINDEX.toString();
332
+ hookDiv.style.backgroundColor = "#FF0000";
333
+ hookDiv.title = "select to enable accessibility for this content";
334
+ hookDiv.addEventListener("focus", () => {
335
+ this._isMobileAccessibility = true;
336
+ this._activate();
337
+ this._destroyTouchHook();
338
+ });
339
+ document.body.appendChild(hookDiv);
340
+ this._hookDiv = hookDiv;
341
+ }
342
+ /**
343
+ * Destroys the touch hooks.
344
+ * @private
345
+ */
346
+ _destroyTouchHook() {
347
+ if (!this._hookDiv) {
348
+ return;
349
+ }
350
+ document.body.removeChild(this._hookDiv);
351
+ this._hookDiv = null;
352
+ }
353
+ /**
354
+ * Activating will cause the Accessibility layer to be shown.
355
+ * This is called when a user presses the tab key.
356
+ * @private
357
+ */
358
+ _activate() {
359
+ if (this._isActive) {
360
+ return;
361
+ }
362
+ this._isActive = true;
363
+ if (!this._div) {
364
+ this._div = document.createElement("div");
365
+ this._div.style.width = `${DIV_TOUCH_SIZE}px`;
366
+ this._div.style.height = `${DIV_TOUCH_SIZE}px`;
367
+ this._div.style.position = "absolute";
368
+ this._div.style.top = `${DIV_TOUCH_POS_X}px`;
369
+ this._div.style.left = `${DIV_TOUCH_POS_Y}px`;
370
+ this._div.style.zIndex = DIV_TOUCH_ZINDEX.toString();
371
+ this._div.style.pointerEvents = "none";
372
+ }
373
+ if (this._activateOnTab) {
374
+ this._onKeyDown = this._onKeyDown.bind(this);
375
+ globalThis.addEventListener("keydown", this._onKeyDown, false);
376
+ }
377
+ if (this._deactivateOnMouseMove) {
378
+ this._onMouseMove = this._onMouseMove.bind(this);
379
+ globalThis.document.addEventListener("mousemove", this._onMouseMove, true);
380
+ }
381
+ const canvas = this._renderer.view.canvas;
382
+ if (!canvas.parentNode) {
383
+ const observer = new MutationObserver(() => {
384
+ if (canvas.parentNode) {
385
+ canvas.parentNode.appendChild(this._div);
386
+ observer.disconnect();
387
+ this._initAccessibilitySetup();
388
+ }
389
+ });
390
+ observer.observe(document.body, { childList: true, subtree: true });
391
+ } else {
392
+ canvas.parentNode.appendChild(this._div);
393
+ this._initAccessibilitySetup();
394
+ }
395
+ }
396
+ // New method to handle initialization after div is ready
397
+ _initAccessibilitySetup() {
398
+ this._renderer.runners.postrender.add(this);
399
+ if (this._renderer.lastObjectRendered) {
400
+ this._updateAccessibleObjects(this._renderer.lastObjectRendered);
401
+ }
402
+ }
403
+ /**
404
+ * Deactivates the accessibility system. Removes listeners and accessibility elements.
405
+ * @private
406
+ */
407
+ _deactivate() {
408
+ if (!this._isActive || this._isMobileAccessibility) {
409
+ return;
410
+ }
411
+ this._isActive = false;
412
+ globalThis.document.removeEventListener("mousemove", this._onMouseMove, true);
413
+ if (this._activateOnTab) {
414
+ globalThis.addEventListener("keydown", this._onKeyDown, false);
415
+ }
416
+ this._renderer.runners.postrender.remove(this);
417
+ for (const child of this._children) {
418
+ if (child._accessibleDiv && child._accessibleDiv.parentNode) {
419
+ child._accessibleDiv.parentNode.removeChild(child._accessibleDiv);
420
+ child._accessibleDiv = null;
421
+ }
422
+ child._accessibleActive = false;
423
+ }
424
+ this._pool.forEach((div) => {
425
+ if (div.parentNode) {
426
+ div.parentNode.removeChild(div);
427
+ }
428
+ });
429
+ if (this._div && this._div.parentNode) {
430
+ this._div.parentNode.removeChild(this._div);
431
+ }
432
+ this._pool = [];
433
+ this._children = [];
434
+ }
435
+ /**
436
+ * This recursive function will run through the scene graph and add any new accessible objects to the DOM layer.
437
+ * @private
438
+ * @param {Container} container - The Container to check.
439
+ */
440
+ _updateAccessibleObjects(container) {
441
+ if (!container.visible || !container.accessibleChildren) {
442
+ return;
443
+ }
444
+ if (container.accessible) {
445
+ if (!container._accessibleActive) {
446
+ this._addChild(container);
447
+ }
448
+ container._renderId = this._renderId;
449
+ }
450
+ const children = container.children;
451
+ if (children) {
452
+ for (let i = 0; i < children.length; i++) {
453
+ this._updateAccessibleObjects(children[i]);
454
+ }
455
+ }
456
+ }
457
+ /**
458
+ * Runner init called, view is available at this point.
459
+ * @ignore
460
+ */
461
+ init(options) {
462
+ const defaultOpts = _AccessibilitySystem.defaultOptions;
463
+ const mergedOptions = {
464
+ accessibilityOptions: {
465
+ ...defaultOpts,
466
+ ...options?.accessibilityOptions || {}
467
+ }
468
+ };
469
+ this.debug = mergedOptions.accessibilityOptions.debug;
470
+ this._activateOnTab = mergedOptions.accessibilityOptions.activateOnTab;
471
+ this._deactivateOnMouseMove = mergedOptions.accessibilityOptions.deactivateOnMouseMove;
472
+ if (mergedOptions.accessibilityOptions.enabledByDefault) {
473
+ this._activate();
474
+ } else if (this._activateOnTab) {
475
+ this._onKeyDown = this._onKeyDown.bind(this);
476
+ globalThis.addEventListener("keydown", this._onKeyDown, false);
477
+ }
478
+ this._renderer.runners.postrender.remove(this);
479
+ }
480
+ /**
481
+ * Updates the accessibility layer during rendering.
482
+ * - Removes divs for containers no longer in the scene
483
+ * - Updates the position and dimensions of the root div
484
+ * - Updates positions of active accessibility divs
485
+ * Only fires while the accessibility system is active.
486
+ * @ignore
487
+ */
488
+ postrender() {
489
+ const now = performance.now();
490
+ if (this._mobileInfo.android.device && now < this._androidUpdateCount) {
491
+ return;
492
+ }
493
+ this._androidUpdateCount = now + this._androidUpdateFrequency;
494
+ if (!this._renderer.renderingToScreen || !this._renderer.view.canvas) {
495
+ return;
496
+ }
497
+ const activeIds = /* @__PURE__ */ new Set();
498
+ if (this._renderer.lastObjectRendered) {
499
+ this._updateAccessibleObjects(this._renderer.lastObjectRendered);
500
+ for (const child of this._children) {
501
+ if (child._renderId === this._renderId) {
502
+ activeIds.add(this._children.indexOf(child));
503
+ }
504
+ }
505
+ }
506
+ for (let i = this._children.length - 1; i >= 0; i--) {
507
+ const child = this._children[i];
508
+ if (!activeIds.has(i)) {
509
+ if (child._accessibleDiv && child._accessibleDiv.parentNode) {
510
+ child._accessibleDiv.parentNode.removeChild(child._accessibleDiv);
511
+ this._pool.push(child._accessibleDiv);
512
+ child._accessibleDiv = null;
513
+ }
514
+ child._accessibleActive = false;
515
+ removeItems(this._children, i, 1);
516
+ }
517
+ }
518
+ if (this._renderer.renderingToScreen) {
519
+ const { x, y, width: viewWidth, height: viewHeight } = this._renderer.screen;
520
+ const div = this._div;
521
+ div.style.left = `${x}px`;
522
+ div.style.top = `${y}px`;
523
+ div.style.width = `${viewWidth}px`;
524
+ div.style.height = `${viewHeight}px`;
525
+ }
526
+ for (let i = 0; i < this._children.length; i++) {
527
+ const child = this._children[i];
528
+ if (!child._accessibleActive || !child._accessibleDiv) {
529
+ continue;
530
+ }
531
+ const div = child._accessibleDiv;
532
+ const hitArea = child.hitArea || child.getBounds().rectangle;
533
+ if (child.hitArea) {
534
+ const wt = child.worldTransform;
535
+ const sx = this._renderer.resolution;
536
+ const sy = this._renderer.resolution;
537
+ div.style.left = `${(wt.tx + hitArea.x * wt.a) * sx}px`;
538
+ div.style.top = `${(wt.ty + hitArea.y * wt.d) * sy}px`;
539
+ div.style.width = `${hitArea.width * wt.a * sx}px`;
540
+ div.style.height = `${hitArea.height * wt.d * sy}px`;
541
+ } else {
542
+ this._capHitArea(hitArea);
543
+ const sx = this._renderer.resolution;
544
+ const sy = this._renderer.resolution;
545
+ div.style.left = `${hitArea.x * sx}px`;
546
+ div.style.top = `${hitArea.y * sy}px`;
547
+ div.style.width = `${hitArea.width * sx}px`;
548
+ div.style.height = `${hitArea.height * sy}px`;
549
+ }
550
+ }
551
+ this._renderId++;
552
+ }
553
+ /**
554
+ * private function that will visually add the information to the
555
+ * accessibility div
556
+ * @param {HTMLElement} div -
557
+ */
558
+ _updateDebugHTML(div) {
559
+ div.innerHTML = `type: ${div.type}</br> title : ${div.title}</br> tabIndex: ${div.tabIndex}`;
560
+ }
561
+ /**
562
+ * Adjust the hit area based on the bounds of a display object
563
+ * @param {Rectangle} hitArea - Bounds of the child
564
+ */
565
+ _capHitArea(hitArea) {
566
+ if (hitArea.x < 0) {
567
+ hitArea.width += hitArea.x;
568
+ hitArea.x = 0;
569
+ }
570
+ if (hitArea.y < 0) {
571
+ hitArea.height += hitArea.y;
572
+ hitArea.y = 0;
573
+ }
574
+ const { width: viewWidth, height: viewHeight } = this._renderer;
575
+ if (hitArea.x + hitArea.width > viewWidth) {
576
+ hitArea.width = viewWidth - hitArea.x;
577
+ }
578
+ if (hitArea.y + hitArea.height > viewHeight) {
579
+ hitArea.height = viewHeight - hitArea.y;
580
+ }
581
+ }
582
+ /**
583
+ * Creates or reuses a div element for a Container and adds it to the accessibility layer.
584
+ * Sets up ARIA attributes, event listeners, and positioning based on the container's properties.
585
+ * @private
586
+ * @param {Container} container - The child to make accessible.
587
+ */
588
+ _addChild(container) {
589
+ let div = this._pool.pop();
590
+ if (!div) {
591
+ if (container.accessibleType === "button") {
592
+ div = document.createElement("button");
593
+ } else {
594
+ div = document.createElement(container.accessibleType);
595
+ div.style.cssText = `
596
+ color: transparent;
597
+ pointer-events: none;
598
+ padding: 0;
599
+ margin: 0;
600
+ border: 0;
601
+ outline: 0;
602
+ background: transparent;
603
+ box-sizing: border-box;
604
+ user-select: none;
605
+ -webkit-user-select: none;
606
+ -moz-user-select: none;
607
+ -ms-user-select: none;
608
+ `;
609
+ if (container.accessibleText) {
610
+ div.innerText = container.accessibleText;
611
+ }
612
+ }
613
+ div.style.width = `${DIV_TOUCH_SIZE}px`;
614
+ div.style.height = `${DIV_TOUCH_SIZE}px`;
615
+ div.style.backgroundColor = this.debug ? "rgba(255,255,255,0.5)" : "transparent";
616
+ div.style.position = "absolute";
617
+ div.style.zIndex = DIV_TOUCH_ZINDEX.toString();
618
+ div.style.borderStyle = "none";
619
+ if (navigator.userAgent.toLowerCase().includes("chrome")) {
620
+ div.setAttribute("aria-live", "off");
621
+ } else {
622
+ div.setAttribute("aria-live", "polite");
623
+ }
624
+ if (navigator.userAgent.match(/rv:.*Gecko\//)) {
625
+ div.setAttribute("aria-relevant", "additions");
626
+ } else {
627
+ div.setAttribute("aria-relevant", "text");
628
+ }
629
+ div.addEventListener("click", this._onClick.bind(this));
630
+ div.addEventListener("focus", this._onFocus.bind(this));
631
+ div.addEventListener("focusout", this._onFocusOut.bind(this));
632
+ }
633
+ div.style.pointerEvents = container.accessiblePointerEvents;
634
+ div.type = container.accessibleType;
635
+ if (container.accessibleTitle && container.accessibleTitle !== null) {
636
+ div.title = container.accessibleTitle;
637
+ } else if (!container.accessibleHint || container.accessibleHint === null) {
638
+ div.title = `container ${container.tabIndex}`;
639
+ }
640
+ if (container.accessibleHint && container.accessibleHint !== null) {
641
+ div.setAttribute("aria-label", container.accessibleHint);
642
+ }
643
+ if (this.debug) {
644
+ this._updateDebugHTML(div);
645
+ }
646
+ container._accessibleActive = true;
647
+ container._accessibleDiv = div;
648
+ div.container = container;
649
+ this._children.push(container);
650
+ this._div.appendChild(container._accessibleDiv);
651
+ if (container.interactive) {
652
+ container._accessibleDiv.tabIndex = container.tabIndex;
653
+ }
654
+ }
655
+ /**
656
+ * Dispatch events with the EventSystem.
657
+ * @param e
658
+ * @param type
659
+ * @private
660
+ */
661
+ _dispatchEvent(e, type) {
662
+ const { container: target } = e.target;
663
+ const boundary = this._renderer.events.rootBoundary;
664
+ const event = Object.assign(new FederatedEvent(boundary), { target });
665
+ boundary.rootTarget = this._renderer.lastObjectRendered;
666
+ type.forEach((type2) => boundary.dispatchEvent(event, type2));
667
+ }
668
+ /**
669
+ * Maps the div button press to pixi's EventSystem (click)
670
+ * @private
671
+ * @param {MouseEvent} e - The click event.
672
+ */
673
+ _onClick(e) {
674
+ this._dispatchEvent(e, ["click", "pointertap", "tap"]);
675
+ }
676
+ /**
677
+ * Maps the div focus events to pixi's EventSystem (mouseover)
678
+ * @private
679
+ * @param {FocusEvent} e - The focus event.
680
+ */
681
+ _onFocus(e) {
682
+ if (!e.target.getAttribute("aria-live")) {
683
+ e.target.setAttribute("aria-live", "assertive");
684
+ }
685
+ this._dispatchEvent(e, ["mouseover"]);
686
+ }
687
+ /**
688
+ * Maps the div focus events to pixi's EventSystem (mouseout)
689
+ * @private
690
+ * @param {FocusEvent} e - The focusout event.
691
+ */
692
+ _onFocusOut(e) {
693
+ if (!e.target.getAttribute("aria-live")) {
694
+ e.target.setAttribute("aria-live", "polite");
695
+ }
696
+ this._dispatchEvent(e, ["mouseout"]);
697
+ }
698
+ /**
699
+ * Is called when a key is pressed
700
+ * @private
701
+ * @param {KeyboardEvent} e - The keydown event.
702
+ */
703
+ _onKeyDown(e) {
704
+ if (e.keyCode !== KEY_CODE_TAB || !this._activateOnTab) {
705
+ return;
706
+ }
707
+ this._activate();
708
+ }
709
+ /**
710
+ * Is called when the mouse moves across the renderer element
711
+ * @private
712
+ * @param {MouseEvent} e - The mouse event.
713
+ */
714
+ _onMouseMove(e) {
715
+ if (e.movementX === 0 && e.movementY === 0) {
716
+ return;
717
+ }
718
+ this._deactivate();
719
+ }
720
+ /** Destroys the accessibility system. Removes all elements and listeners. */
721
+ destroy() {
722
+ this._deactivate();
723
+ this._destroyTouchHook();
724
+ this._div = null;
725
+ this._pool = null;
726
+ this._children = null;
727
+ this._renderer = null;
728
+ if (this._activateOnTab) {
729
+ globalThis.removeEventListener("keydown", this._onKeyDown);
730
+ }
731
+ }
732
+ /**
733
+ * Enables or disables the accessibility system.
734
+ * @param enabled - Whether to enable or disable accessibility.
735
+ */
736
+ setAccessibilityEnabled(enabled) {
737
+ if (enabled) {
738
+ this._activate();
739
+ } else {
740
+ this._deactivate();
741
+ }
742
+ }
743
+ };
744
+ /** @ignore */
745
+ _AccessibilitySystem.extension = {
746
+ type: [
747
+ ExtensionType.WebGLSystem,
748
+ ExtensionType.WebGPUSystem
749
+ ],
750
+ name: "accessibility"
751
+ };
752
+ /** default options used by the system */
753
+ _AccessibilitySystem.defaultOptions = {
754
+ /**
755
+ * Whether to enable accessibility features on initialization
756
+ * @default false
757
+ */
758
+ enabledByDefault: false,
759
+ /**
760
+ * Whether to visually show the accessibility divs for debugging
761
+ * @default false
762
+ */
763
+ debug: false,
764
+ /**
765
+ * Whether to activate accessibility when tab key is pressed
766
+ * @default true
767
+ */
768
+ activateOnTab: true,
769
+ /**
770
+ * Whether to deactivate accessibility when mouse moves
771
+ * @default true
772
+ */
773
+ deactivateOnMouseMove: true
774
+ };
775
+ let AccessibilitySystem = _AccessibilitySystem;
776
+
777
+ const accessibilityTarget = {
778
+ /**
779
+ * Flag for if the object is accessible. If true AccessibilityManager will overlay a
780
+ * shadow div with attributes set
781
+ * @member {boolean}
782
+ * @memberof scene.Container#
783
+ */
784
+ accessible: false,
785
+ /**
786
+ * Sets the title attribute of the shadow div
787
+ * If accessibleTitle AND accessibleHint has not been this will default to 'container [tabIndex]'
788
+ * @member {string}
789
+ * @memberof scene.Container#
790
+ */
791
+ accessibleTitle: null,
792
+ /**
793
+ * Sets the aria-label attribute of the shadow div
794
+ * @member {string}
795
+ * @memberof scene.Container#
796
+ */
797
+ accessibleHint: null,
798
+ /**
799
+ * @member {number}
800
+ * @memberof scene.Container#
801
+ * @todo Needs docs.
802
+ */
803
+ tabIndex: 0,
804
+ /**
805
+ * @member {boolean}
806
+ * @memberof scene.Container#
807
+ * @private
808
+ */
809
+ _accessibleActive: false,
810
+ /**
811
+ * @memberof scene.Container#
812
+ * @private
813
+ */
814
+ _accessibleDiv: null,
815
+ /**
816
+ * Specify the type of div the accessible layer is. Screen readers treat the element differently
817
+ * depending on this type. Defaults to button.
818
+ * @member {string}
819
+ * @memberof scene.Container#
820
+ * @default 'button'
821
+ */
822
+ accessibleType: "button",
823
+ /**
824
+ * Sets the text content of the shadow div
825
+ * @member {string}
826
+ * @memberof scene.Container#
827
+ */
828
+ accessibleText: null,
829
+ /**
830
+ * Specify the pointer-events the accessible div will use
831
+ * Defaults to auto.
832
+ * @type {PointerEvents}
833
+ * @memberof scene.Container#
834
+ * @default 'auto'
835
+ */
836
+ accessiblePointerEvents: "auto",
837
+ /**
838
+ * Setting to false will prevent any children inside this container to
839
+ * be accessible. Defaults to true.
840
+ * @member {boolean}
841
+ * @memberof scene.Container#
842
+ * @default true
843
+ */
844
+ accessibleChildren: true,
845
+ /**
846
+ * @member {number}
847
+ * @memberof scene.Container#
848
+ * @private
849
+ */
850
+ _renderId: -1
851
+ };
852
+
853
+ class DOMPipe {
854
+ /**
855
+ * Constructor for the DOMPipe class.
856
+ * @param renderer - The renderer instance that this DOMPipe will be associated with.
857
+ */
858
+ constructor(renderer) {
859
+ this._destroyRenderableBound = this.destroyRenderable.bind(this);
860
+ /** Array to keep track of attached DOM elements */
861
+ this._attachedDomElements = [];
862
+ this._renderer = renderer;
863
+ this._renderer.runners.postrender.add(this);
864
+ this._domElement = document.createElement("div");
865
+ this._domElement.style.position = "absolute";
866
+ this._domElement.style.top = "0";
867
+ this._domElement.style.left = "0";
868
+ this._domElement.style.pointerEvents = "none";
869
+ this._domElement.style.zIndex = "1000";
870
+ }
871
+ /**
872
+ * Adds a renderable DOM container to the list of attached elements.
873
+ * @param domContainer - The DOM container to be added.
874
+ * @param _instructionSet - The instruction set (unused).
875
+ */
876
+ addRenderable(domContainer, _instructionSet) {
877
+ if (!this._attachedDomElements.includes(domContainer)) {
878
+ this._attachedDomElements.push(domContainer);
879
+ domContainer.on("destroyed", this._destroyRenderableBound);
880
+ }
881
+ }
882
+ /**
883
+ * Updates a renderable DOM container.
884
+ * @param _domContainer - The DOM container to be updated (unused).
885
+ */
886
+ updateRenderable(_domContainer) {
887
+ }
888
+ /**
889
+ * Validates a renderable DOM container.
890
+ * @param _domContainer - The DOM container to be validated (unused).
891
+ * @returns Always returns true as validation is not required.
892
+ */
893
+ validateRenderable(_domContainer) {
894
+ return true;
895
+ }
896
+ /**
897
+ * Destroys a renderable DOM container, removing it from the list of attached elements.
898
+ * @param domContainer - The DOM container to be destroyed.
899
+ */
900
+ destroyRenderable(domContainer) {
901
+ const index = this._attachedDomElements.indexOf(domContainer);
902
+ if (index !== -1) {
903
+ this._attachedDomElements.splice(index, 1);
904
+ }
905
+ domContainer.off("destroyed", this._destroyRenderableBound);
906
+ }
907
+ /** Handles the post-rendering process, ensuring DOM elements are correctly positioned and visible. */
908
+ postrender() {
909
+ const attachedDomElements = this._attachedDomElements;
910
+ if (attachedDomElements.length === 0) {
911
+ this._domElement.remove();
912
+ return;
913
+ }
914
+ const canvas = this._renderer.view.canvas;
915
+ if (this._domElement.parentNode !== canvas.parentNode) {
916
+ canvas.parentNode?.appendChild(this._domElement);
917
+ }
918
+ this._domElement.style.transform = `translate(${canvas.offsetLeft}px, ${canvas.offsetTop}px)`;
919
+ for (let i = 0; i < attachedDomElements.length; i++) {
920
+ const domContainer = attachedDomElements[i];
921
+ const element = domContainer.element;
922
+ if (!domContainer.parent || domContainer.globalDisplayStatus < 7) {
923
+ element.remove();
924
+ attachedDomElements.splice(i, 1);
925
+ i--;
926
+ } else {
927
+ if (!this._domElement.contains(element)) {
928
+ element.style.position = "absolute";
929
+ element.style.pointerEvents = "auto";
930
+ this._domElement.appendChild(element);
931
+ }
932
+ const wt = domContainer.worldTransform;
933
+ const anchor = domContainer._anchor;
934
+ const ax = domContainer.width * anchor.x;
935
+ const ay = domContainer.height * anchor.y;
936
+ element.style.transformOrigin = `${ax}px ${ay}px`;
937
+ element.style.transform = `matrix(${wt.a}, ${wt.b}, ${wt.c}, ${wt.d}, ${wt.tx - ax}, ${wt.ty - ay})`;
938
+ element.style.opacity = domContainer.groupAlpha.toString();
939
+ }
940
+ }
941
+ }
942
+ /** Destroys the DOMPipe, removing all attached DOM elements and cleaning up resources. */
943
+ destroy() {
944
+ this._renderer.runners.postrender.remove(this);
945
+ for (let i = 0; i < this._attachedDomElements.length; i++) {
946
+ const domContainer = this._attachedDomElements[i];
947
+ domContainer.off("destroyed", this._destroyRenderableBound);
948
+ domContainer.element.remove();
949
+ }
950
+ this._attachedDomElements.length = 0;
951
+ this._domElement.remove();
952
+ this._renderer = null;
953
+ }
954
+ }
955
+ /**
956
+ * Static property defining the extension type and name for the DOMPipe.
957
+ * This is used to register the DOMPipe with different rendering pipelines.
958
+ */
959
+ DOMPipe.extension = {
960
+ type: [
961
+ ExtensionType.WebGLPipes,
962
+ ExtensionType.WebGPUPipes,
963
+ ExtensionType.CanvasPipes
964
+ ],
965
+ name: "dom"
966
+ };
967
+
968
+ class EventsTickerClass {
969
+ constructor() {
970
+ /** The frequency that fake events will be fired. */
971
+ this.interactionFrequency = 10;
972
+ this._deltaTime = 0;
973
+ this._didMove = false;
974
+ this._tickerAdded = false;
975
+ this._pauseUpdate = true;
976
+ }
977
+ /**
978
+ * Initializes the event ticker.
979
+ * @param events - The event system.
980
+ */
981
+ init(events) {
982
+ this.removeTickerListener();
983
+ this.events = events;
984
+ this.interactionFrequency = 10;
985
+ this._deltaTime = 0;
986
+ this._didMove = false;
987
+ this._tickerAdded = false;
988
+ this._pauseUpdate = true;
989
+ }
990
+ /** Whether to pause the update checks or not. */
991
+ get pauseUpdate() {
992
+ return this._pauseUpdate;
993
+ }
994
+ set pauseUpdate(paused) {
995
+ this._pauseUpdate = paused;
996
+ }
997
+ /** Adds the ticker listener. */
998
+ addTickerListener() {
999
+ if (this._tickerAdded || !this.domElement) {
1000
+ return;
1001
+ }
1002
+ Ticker.system.add(this._tickerUpdate, this, UPDATE_PRIORITY.INTERACTION);
1003
+ this._tickerAdded = true;
1004
+ }
1005
+ /** Removes the ticker listener. */
1006
+ removeTickerListener() {
1007
+ if (!this._tickerAdded) {
1008
+ return;
1009
+ }
1010
+ Ticker.system.remove(this._tickerUpdate, this);
1011
+ this._tickerAdded = false;
1012
+ }
1013
+ /** Sets flag to not fire extra events when the user has already moved there mouse */
1014
+ pointerMoved() {
1015
+ this._didMove = true;
1016
+ }
1017
+ /** Updates the state of interactive objects. */
1018
+ _update() {
1019
+ if (!this.domElement || this._pauseUpdate) {
1020
+ return;
1021
+ }
1022
+ if (this._didMove) {
1023
+ this._didMove = false;
1024
+ return;
1025
+ }
1026
+ const rootPointerEvent = this.events["_rootPointerEvent"];
1027
+ if (this.events.supportsTouchEvents && rootPointerEvent.pointerType === "touch") {
1028
+ return;
1029
+ }
1030
+ globalThis.document.dispatchEvent(new PointerEvent("pointermove", {
1031
+ clientX: rootPointerEvent.clientX,
1032
+ clientY: rootPointerEvent.clientY,
1033
+ pointerType: rootPointerEvent.pointerType,
1034
+ pointerId: rootPointerEvent.pointerId
1035
+ }));
1036
+ }
1037
+ /**
1038
+ * Updates the state of interactive objects if at least {@link interactionFrequency}
1039
+ * milliseconds have passed since the last invocation.
1040
+ *
1041
+ * Invoked by a throttled ticker update from {@link Ticker.system}.
1042
+ * @param ticker - The throttled ticker.
1043
+ */
1044
+ _tickerUpdate(ticker) {
1045
+ this._deltaTime += ticker.deltaTime;
1046
+ if (this._deltaTime < this.interactionFrequency) {
1047
+ return;
1048
+ }
1049
+ this._deltaTime = 0;
1050
+ this._update();
1051
+ }
1052
+ }
1053
+ const EventsTicker = new EventsTickerClass();
1054
+
1055
+ class FederatedMouseEvent extends FederatedEvent {
1056
+ constructor() {
1057
+ super(...arguments);
1058
+ /** The coordinates of the mouse event relative to the canvas. */
1059
+ this.client = new Point();
1060
+ /** The movement in this pointer relative to the last `mousemove` event. */
1061
+ this.movement = new Point();
1062
+ /** The offset of the pointer coordinates w.r.t. target Container in world space. This is not supported at the moment. */
1063
+ this.offset = new Point();
1064
+ /** The pointer coordinates in world space. */
1065
+ this.global = new Point();
1066
+ /**
1067
+ * The pointer coordinates in the renderer's {@link Renderer.screen screen}. This has slightly
1068
+ * different semantics than native PointerEvent screenX/screenY.
1069
+ */
1070
+ this.screen = new Point();
1071
+ }
1072
+ /** @readonly */
1073
+ get clientX() {
1074
+ return this.client.x;
1075
+ }
1076
+ /** @readonly */
1077
+ get clientY() {
1078
+ return this.client.y;
1079
+ }
1080
+ /**
1081
+ * Alias for {@link FederatedMouseEvent.clientX this.clientX}.
1082
+ * @readonly
1083
+ */
1084
+ get x() {
1085
+ return this.clientX;
1086
+ }
1087
+ /**
1088
+ * Alias for {@link FederatedMouseEvent.clientY this.clientY}.
1089
+ * @readonly
1090
+ */
1091
+ get y() {
1092
+ return this.clientY;
1093
+ }
1094
+ /** @readonly */
1095
+ get movementX() {
1096
+ return this.movement.x;
1097
+ }
1098
+ /** @readonly */
1099
+ get movementY() {
1100
+ return this.movement.y;
1101
+ }
1102
+ /** @readonly */
1103
+ get offsetX() {
1104
+ return this.offset.x;
1105
+ }
1106
+ /** @readonly */
1107
+ get offsetY() {
1108
+ return this.offset.y;
1109
+ }
1110
+ /** @readonly */
1111
+ get globalX() {
1112
+ return this.global.x;
1113
+ }
1114
+ /** @readonly */
1115
+ get globalY() {
1116
+ return this.global.y;
1117
+ }
1118
+ /**
1119
+ * The pointer coordinates in the renderer's screen. Alias for {@code screen.x}.
1120
+ * @readonly
1121
+ */
1122
+ get screenX() {
1123
+ return this.screen.x;
1124
+ }
1125
+ /**
1126
+ * The pointer coordinates in the renderer's screen. Alias for {@code screen.y}.
1127
+ * @readonly
1128
+ */
1129
+ get screenY() {
1130
+ return this.screen.y;
1131
+ }
1132
+ /**
1133
+ * This will return the local coordinates of the specified container for this InteractionData
1134
+ * @param {Container} container - The Container that you would like the local
1135
+ * coords off
1136
+ * @param {PointData} point - A Point object in which to store the value, optional (otherwise
1137
+ * will create a new point)
1138
+ * @param {PointData} globalPos - A Point object containing your custom global coords, optional
1139
+ * (otherwise will use the current global coords)
1140
+ * @returns - A point containing the coordinates of the InteractionData position relative
1141
+ * to the Container
1142
+ */
1143
+ getLocalPosition(container, point, globalPos) {
1144
+ return container.worldTransform.applyInverse(globalPos || this.global, point);
1145
+ }
1146
+ /**
1147
+ * Whether the modifier key was pressed when this event natively occurred.
1148
+ * @param key - The modifier key.
1149
+ */
1150
+ getModifierState(key) {
1151
+ return "getModifierState" in this.nativeEvent && this.nativeEvent.getModifierState(key);
1152
+ }
1153
+ /**
1154
+ * Not supported.
1155
+ * @param _typeArg
1156
+ * @param _canBubbleArg
1157
+ * @param _cancelableArg
1158
+ * @param _viewArg
1159
+ * @param _detailArg
1160
+ * @param _screenXArg
1161
+ * @param _screenYArg
1162
+ * @param _clientXArg
1163
+ * @param _clientYArg
1164
+ * @param _ctrlKeyArg
1165
+ * @param _altKeyArg
1166
+ * @param _shiftKeyArg
1167
+ * @param _metaKeyArg
1168
+ * @param _buttonArg
1169
+ * @param _relatedTargetArg
1170
+ * @deprecated since 7.0.0
1171
+ */
1172
+ // eslint-disable-next-line max-params
1173
+ initMouseEvent(_typeArg, _canBubbleArg, _cancelableArg, _viewArg, _detailArg, _screenXArg, _screenYArg, _clientXArg, _clientYArg, _ctrlKeyArg, _altKeyArg, _shiftKeyArg, _metaKeyArg, _buttonArg, _relatedTargetArg) {
1174
+ throw new Error("Method not implemented.");
1175
+ }
1176
+ }
1177
+
1178
+ class FederatedPointerEvent extends FederatedMouseEvent {
1179
+ constructor() {
1180
+ super(...arguments);
1181
+ /**
1182
+ * The width of the pointer's contact along the x-axis, measured in CSS pixels.
1183
+ * radiusX of TouchEvents will be represented by this value.
1184
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width
1185
+ */
1186
+ this.width = 0;
1187
+ /**
1188
+ * The height of the pointer's contact along the y-axis, measured in CSS pixels.
1189
+ * radiusY of TouchEvents will be represented by this value.
1190
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height
1191
+ */
1192
+ this.height = 0;
1193
+ /**
1194
+ * Indicates whether or not the pointer device that created the event is the primary pointer.
1195
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary
1196
+ */
1197
+ this.isPrimary = false;
1198
+ }
1199
+ // Only included for completeness for now
1200
+ getCoalescedEvents() {
1201
+ if (this.type === "pointermove" || this.type === "mousemove" || this.type === "touchmove") {
1202
+ return [this];
1203
+ }
1204
+ return [];
1205
+ }
1206
+ // Only included for completeness for now
1207
+ getPredictedEvents() {
1208
+ throw new Error("getPredictedEvents is not supported!");
1209
+ }
1210
+ }
1211
+
1212
+ class FederatedWheelEvent extends FederatedMouseEvent {
1213
+ constructor() {
1214
+ super(...arguments);
1215
+ /** Units specified in pixels. */
1216
+ this.DOM_DELTA_PIXEL = 0;
1217
+ /** Units specified in lines. */
1218
+ this.DOM_DELTA_LINE = 1;
1219
+ /** Units specified in pages. */
1220
+ this.DOM_DELTA_PAGE = 2;
1221
+ }
1222
+ }
1223
+ /** Units specified in pixels. */
1224
+ FederatedWheelEvent.DOM_DELTA_PIXEL = 0;
1225
+ /** Units specified in lines. */
1226
+ FederatedWheelEvent.DOM_DELTA_LINE = 1;
1227
+ /** Units specified in pages. */
1228
+ FederatedWheelEvent.DOM_DELTA_PAGE = 2;
1229
+
1230
+ const PROPAGATION_LIMIT = 2048;
1231
+ const tempHitLocation = new Point();
1232
+ const tempLocalMapping = new Point();
1233
+ class EventBoundary {
1234
+ /**
1235
+ * @param rootTarget - The holder of the event boundary.
1236
+ */
1237
+ constructor(rootTarget) {
1238
+ /**
1239
+ * Emits events after they were dispatched into the scene graph.
1240
+ *
1241
+ * This can be used for global events listening, regardless of the scene graph being used. It should
1242
+ * not be used by interactive libraries for normal use.
1243
+ *
1244
+ * Special events that do not bubble all the way to the root target are not emitted from here,
1245
+ * e.g. pointerenter, pointerleave, click.
1246
+ */
1247
+ this.dispatch = new EventEmitter();
1248
+ /**
1249
+ * This flag would emit `pointermove`, `touchmove`, and `mousemove` events on all Containers.
1250
+ *
1251
+ * The `moveOnAll` semantics mirror those of earlier versions of PixiJS. This was disabled in favor of
1252
+ * the Pointer Event API's approach.
1253
+ */
1254
+ this.moveOnAll = false;
1255
+ /** Enables the global move events. `globalpointermove`, `globaltouchmove`, and `globalmousemove` */
1256
+ this.enableGlobalMoveEvents = true;
1257
+ /**
1258
+ * State object for mapping methods.
1259
+ * @see EventBoundary#trackingData
1260
+ */
1261
+ this.mappingState = {
1262
+ trackingData: {}
1263
+ };
1264
+ /**
1265
+ * The event pool maps event constructors to an free pool of instances of those specific events.
1266
+ * @see EventBoundary#allocateEvent
1267
+ * @see EventBoundary#freeEvent
1268
+ */
1269
+ this.eventPool = /* @__PURE__ */ new Map();
1270
+ /** Every interactive element gathered from the scene. Only used in `pointermove` */
1271
+ this._allInteractiveElements = [];
1272
+ /** Every element that passed the hit test. Only used in `pointermove` */
1273
+ this._hitElements = [];
1274
+ /** Whether or not to collect all the interactive elements from the scene. Enabled in `pointermove` */
1275
+ this._isPointerMoveEvent = false;
1276
+ this.rootTarget = rootTarget;
1277
+ this.hitPruneFn = this.hitPruneFn.bind(this);
1278
+ this.hitTestFn = this.hitTestFn.bind(this);
1279
+ this.mapPointerDown = this.mapPointerDown.bind(this);
1280
+ this.mapPointerMove = this.mapPointerMove.bind(this);
1281
+ this.mapPointerOut = this.mapPointerOut.bind(this);
1282
+ this.mapPointerOver = this.mapPointerOver.bind(this);
1283
+ this.mapPointerUp = this.mapPointerUp.bind(this);
1284
+ this.mapPointerUpOutside = this.mapPointerUpOutside.bind(this);
1285
+ this.mapWheel = this.mapWheel.bind(this);
1286
+ this.mappingTable = {};
1287
+ this.addEventMapping("pointerdown", this.mapPointerDown);
1288
+ this.addEventMapping("pointermove", this.mapPointerMove);
1289
+ this.addEventMapping("pointerout", this.mapPointerOut);
1290
+ this.addEventMapping("pointerleave", this.mapPointerOut);
1291
+ this.addEventMapping("pointerover", this.mapPointerOver);
1292
+ this.addEventMapping("pointerup", this.mapPointerUp);
1293
+ this.addEventMapping("pointerupoutside", this.mapPointerUpOutside);
1294
+ this.addEventMapping("wheel", this.mapWheel);
1295
+ }
1296
+ /**
1297
+ * Adds an event mapping for the event `type` handled by `fn`.
1298
+ *
1299
+ * Event mappings can be used to implement additional or custom events. They take an event
1300
+ * coming from the upstream scene (or directly from the {@link EventSystem}) and dispatch new downstream events
1301
+ * generally trickling down and bubbling up to {@link EventBoundary.rootTarget this.rootTarget}.
1302
+ *
1303
+ * To modify the semantics of existing events, the built-in mapping methods of EventBoundary should be overridden
1304
+ * instead.
1305
+ * @param type - The type of upstream event to map.
1306
+ * @param fn - The mapping method. The context of this function must be bound manually, if desired.
1307
+ */
1308
+ addEventMapping(type, fn) {
1309
+ if (!this.mappingTable[type]) {
1310
+ this.mappingTable[type] = [];
1311
+ }
1312
+ this.mappingTable[type].push({
1313
+ fn,
1314
+ priority: 0
1315
+ });
1316
+ this.mappingTable[type].sort((a, b) => a.priority - b.priority);
1317
+ }
1318
+ /**
1319
+ * Dispatches the given event
1320
+ * @param e - The event to dispatch.
1321
+ * @param type - The type of event to dispatch. Defaults to `e.type`.
1322
+ */
1323
+ dispatchEvent(e, type) {
1324
+ e.propagationStopped = false;
1325
+ e.propagationImmediatelyStopped = false;
1326
+ this.propagate(e, type);
1327
+ this.dispatch.emit(type || e.type, e);
1328
+ }
1329
+ /**
1330
+ * Maps the given upstream event through the event boundary and propagates it downstream.
1331
+ * @param e - The event to map.
1332
+ */
1333
+ mapEvent(e) {
1334
+ if (!this.rootTarget) {
1335
+ return;
1336
+ }
1337
+ const mappers = this.mappingTable[e.type];
1338
+ if (mappers) {
1339
+ for (let i = 0, j = mappers.length; i < j; i++) {
1340
+ mappers[i].fn(e);
1341
+ }
1342
+ } else {
1343
+ warn(`[EventBoundary]: Event mapping not defined for ${e.type}`);
1344
+ }
1345
+ }
1346
+ /**
1347
+ * Finds the Container that is the target of a event at the given coordinates.
1348
+ *
1349
+ * The passed (x,y) coordinates are in the world space above this event boundary.
1350
+ * @param x - The x coordinate of the event.
1351
+ * @param y - The y coordinate of the event.
1352
+ */
1353
+ hitTest(x, y) {
1354
+ EventsTicker.pauseUpdate = true;
1355
+ const useMove = this._isPointerMoveEvent && this.enableGlobalMoveEvents;
1356
+ const fn = useMove ? "hitTestMoveRecursive" : "hitTestRecursive";
1357
+ const invertedPath = this[fn](
1358
+ this.rootTarget,
1359
+ this.rootTarget.eventMode,
1360
+ tempHitLocation.set(x, y),
1361
+ this.hitTestFn,
1362
+ this.hitPruneFn
1363
+ );
1364
+ return invertedPath && invertedPath[0];
1365
+ }
1366
+ /**
1367
+ * Propagate the passed event from from {@link EventBoundary.rootTarget this.rootTarget} to its
1368
+ * target {@code e.target}.
1369
+ * @param e - The event to propagate.
1370
+ * @param type - The type of event to propagate. Defaults to `e.type`.
1371
+ */
1372
+ propagate(e, type) {
1373
+ if (!e.target) {
1374
+ return;
1375
+ }
1376
+ const composedPath = e.composedPath();
1377
+ e.eventPhase = e.CAPTURING_PHASE;
1378
+ for (let i = 0, j = composedPath.length - 1; i < j; i++) {
1379
+ e.currentTarget = composedPath[i];
1380
+ this.notifyTarget(e, type);
1381
+ if (e.propagationStopped || e.propagationImmediatelyStopped)
1382
+ return;
1383
+ }
1384
+ e.eventPhase = e.AT_TARGET;
1385
+ e.currentTarget = e.target;
1386
+ this.notifyTarget(e, type);
1387
+ if (e.propagationStopped || e.propagationImmediatelyStopped)
1388
+ return;
1389
+ e.eventPhase = e.BUBBLING_PHASE;
1390
+ for (let i = composedPath.length - 2; i >= 0; i--) {
1391
+ e.currentTarget = composedPath[i];
1392
+ this.notifyTarget(e, type);
1393
+ if (e.propagationStopped || e.propagationImmediatelyStopped)
1394
+ return;
1395
+ }
1396
+ }
1397
+ /**
1398
+ * Emits the event {@code e} to all interactive containers. The event is propagated in the bubbling phase always.
1399
+ *
1400
+ * This is used in the `globalpointermove` event.
1401
+ * @param e - The emitted event.
1402
+ * @param type - The listeners to notify.
1403
+ * @param targets - The targets to notify.
1404
+ */
1405
+ all(e, type, targets = this._allInteractiveElements) {
1406
+ if (targets.length === 0)
1407
+ return;
1408
+ e.eventPhase = e.BUBBLING_PHASE;
1409
+ const events = Array.isArray(type) ? type : [type];
1410
+ for (let i = targets.length - 1; i >= 0; i--) {
1411
+ events.forEach((event) => {
1412
+ e.currentTarget = targets[i];
1413
+ this.notifyTarget(e, event);
1414
+ });
1415
+ }
1416
+ }
1417
+ /**
1418
+ * Finds the propagation path from {@link EventBoundary.rootTarget rootTarget} to the passed
1419
+ * {@code target}. The last element in the path is {@code target}.
1420
+ * @param target - The target to find the propagation path to.
1421
+ */
1422
+ propagationPath(target) {
1423
+ const propagationPath = [target];
1424
+ for (let i = 0; i < PROPAGATION_LIMIT && (target !== this.rootTarget && target.parent); i++) {
1425
+ if (!target.parent) {
1426
+ throw new Error("Cannot find propagation path to disconnected target");
1427
+ }
1428
+ propagationPath.push(target.parent);
1429
+ target = target.parent;
1430
+ }
1431
+ propagationPath.reverse();
1432
+ return propagationPath;
1433
+ }
1434
+ hitTestMoveRecursive(currentTarget, eventMode, location, testFn, pruneFn, ignore = false) {
1435
+ let shouldReturn = false;
1436
+ if (this._interactivePrune(currentTarget))
1437
+ return null;
1438
+ if (currentTarget.eventMode === "dynamic" || eventMode === "dynamic") {
1439
+ EventsTicker.pauseUpdate = false;
1440
+ }
1441
+ if (currentTarget.interactiveChildren && currentTarget.children) {
1442
+ const children = currentTarget.children;
1443
+ for (let i = children.length - 1; i >= 0; i--) {
1444
+ const child = children[i];
1445
+ const nestedHit = this.hitTestMoveRecursive(
1446
+ child,
1447
+ this._isInteractive(eventMode) ? eventMode : child.eventMode,
1448
+ location,
1449
+ testFn,
1450
+ pruneFn,
1451
+ ignore || pruneFn(currentTarget, location)
1452
+ );
1453
+ if (nestedHit) {
1454
+ if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent) {
1455
+ continue;
1456
+ }
1457
+ const isInteractive = currentTarget.isInteractive();
1458
+ if (nestedHit.length > 0 || isInteractive) {
1459
+ if (isInteractive)
1460
+ this._allInteractiveElements.push(currentTarget);
1461
+ nestedHit.push(currentTarget);
1462
+ }
1463
+ if (this._hitElements.length === 0)
1464
+ this._hitElements = nestedHit;
1465
+ shouldReturn = true;
1466
+ }
1467
+ }
1468
+ }
1469
+ const isInteractiveMode = this._isInteractive(eventMode);
1470
+ const isInteractiveTarget = currentTarget.isInteractive();
1471
+ if (isInteractiveTarget && isInteractiveTarget)
1472
+ this._allInteractiveElements.push(currentTarget);
1473
+ if (ignore || this._hitElements.length > 0)
1474
+ return null;
1475
+ if (shouldReturn)
1476
+ return this._hitElements;
1477
+ if (isInteractiveMode && (!pruneFn(currentTarget, location) && testFn(currentTarget, location))) {
1478
+ return isInteractiveTarget ? [currentTarget] : [];
1479
+ }
1480
+ return null;
1481
+ }
1482
+ /**
1483
+ * Recursive implementation for {@link EventBoundary.hitTest hitTest}.
1484
+ * @param currentTarget - The Container that is to be hit tested.
1485
+ * @param eventMode - The event mode for the `currentTarget` or one of its parents.
1486
+ * @param location - The location that is being tested for overlap.
1487
+ * @param testFn - Callback that determines whether the target passes hit testing. This callback
1488
+ * can assume that `pruneFn` failed to prune the container.
1489
+ * @param pruneFn - Callback that determiness whether the target and all of its children
1490
+ * cannot pass the hit test. It is used as a preliminary optimization to prune entire subtrees
1491
+ * of the scene graph.
1492
+ * @returns An array holding the hit testing target and all its ancestors in order. The first element
1493
+ * is the target itself and the last is {@link EventBoundary.rootTarget rootTarget}. This is the opposite
1494
+ * order w.r.t. the propagation path. If no hit testing target is found, null is returned.
1495
+ */
1496
+ hitTestRecursive(currentTarget, eventMode, location, testFn, pruneFn) {
1497
+ if (this._interactivePrune(currentTarget) || pruneFn(currentTarget, location)) {
1498
+ return null;
1499
+ }
1500
+ if (currentTarget.eventMode === "dynamic" || eventMode === "dynamic") {
1501
+ EventsTicker.pauseUpdate = false;
1502
+ }
1503
+ if (currentTarget.interactiveChildren && currentTarget.children) {
1504
+ const children = currentTarget.children;
1505
+ const relativeLocation = location;
1506
+ for (let i = children.length - 1; i >= 0; i--) {
1507
+ const child = children[i];
1508
+ const nestedHit = this.hitTestRecursive(
1509
+ child,
1510
+ this._isInteractive(eventMode) ? eventMode : child.eventMode,
1511
+ relativeLocation,
1512
+ testFn,
1513
+ pruneFn
1514
+ );
1515
+ if (nestedHit) {
1516
+ if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent) {
1517
+ continue;
1518
+ }
1519
+ const isInteractive = currentTarget.isInteractive();
1520
+ if (nestedHit.length > 0 || isInteractive)
1521
+ nestedHit.push(currentTarget);
1522
+ return nestedHit;
1523
+ }
1524
+ }
1525
+ }
1526
+ const isInteractiveMode = this._isInteractive(eventMode);
1527
+ const isInteractiveTarget = currentTarget.isInteractive();
1528
+ if (isInteractiveMode && testFn(currentTarget, location)) {
1529
+ return isInteractiveTarget ? [currentTarget] : [];
1530
+ }
1531
+ return null;
1532
+ }
1533
+ _isInteractive(int) {
1534
+ return int === "static" || int === "dynamic";
1535
+ }
1536
+ _interactivePrune(container) {
1537
+ if (!container || !container.visible || !container.renderable || !container.measurable) {
1538
+ return true;
1539
+ }
1540
+ if (container.eventMode === "none") {
1541
+ return true;
1542
+ }
1543
+ if (container.eventMode === "passive" && !container.interactiveChildren) {
1544
+ return true;
1545
+ }
1546
+ return false;
1547
+ }
1548
+ /**
1549
+ * Checks whether the container or any of its children cannot pass the hit test at all.
1550
+ *
1551
+ * {@link EventBoundary}'s implementation uses the {@link Container.hitArea hitArea}
1552
+ * and {@link Container._maskEffect} for pruning.
1553
+ * @param container - The container to prune.
1554
+ * @param location - The location to test for overlap.
1555
+ */
1556
+ hitPruneFn(container, location) {
1557
+ if (container.hitArea) {
1558
+ container.worldTransform.applyInverse(location, tempLocalMapping);
1559
+ if (!container.hitArea.contains(tempLocalMapping.x, tempLocalMapping.y)) {
1560
+ return true;
1561
+ }
1562
+ }
1563
+ if (container.effects && container.effects.length) {
1564
+ for (let i = 0; i < container.effects.length; i++) {
1565
+ const effect = container.effects[i];
1566
+ if (effect.containsPoint) {
1567
+ const effectContainsPoint = effect.containsPoint(location, this.hitTestFn);
1568
+ if (!effectContainsPoint) {
1569
+ return true;
1570
+ }
1571
+ }
1572
+ }
1573
+ }
1574
+ return false;
1575
+ }
1576
+ /**
1577
+ * Checks whether the container passes hit testing for the given location.
1578
+ * @param container - The container to test.
1579
+ * @param location - The location to test for overlap.
1580
+ * @returns - Whether `container` passes hit testing for `location`.
1581
+ */
1582
+ hitTestFn(container, location) {
1583
+ if (container.hitArea) {
1584
+ return true;
1585
+ }
1586
+ if (container?.containsPoint) {
1587
+ container.worldTransform.applyInverse(location, tempLocalMapping);
1588
+ return container.containsPoint(tempLocalMapping);
1589
+ }
1590
+ return false;
1591
+ }
1592
+ /**
1593
+ * Notify all the listeners to the event's `currentTarget`.
1594
+ *
1595
+ * If the `currentTarget` contains the property `on<type>`, then it is called here,
1596
+ * simulating the behavior from version 6.x and prior.
1597
+ * @param e - The event passed to the target.
1598
+ * @param type - The type of event to notify. Defaults to `e.type`.
1599
+ */
1600
+ notifyTarget(e, type) {
1601
+ if (!e.currentTarget.isInteractive()) {
1602
+ return;
1603
+ }
1604
+ type ?? (type = e.type);
1605
+ const handlerKey = `on${type}`;
1606
+ e.currentTarget[handlerKey]?.(e);
1607
+ const key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${type}capture` : type;
1608
+ this._notifyListeners(e, key);
1609
+ if (e.eventPhase === e.AT_TARGET) {
1610
+ this._notifyListeners(e, type);
1611
+ }
1612
+ }
1613
+ /**
1614
+ * Maps the upstream `pointerdown` events to a downstream `pointerdown` event.
1615
+ *
1616
+ * `touchstart`, `rightdown`, `mousedown` events are also dispatched for specific pointer types.
1617
+ * @param from - The upstream `pointerdown` event.
1618
+ */
1619
+ mapPointerDown(from) {
1620
+ if (!(from instanceof FederatedPointerEvent)) {
1621
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1622
+ return;
1623
+ }
1624
+ const e = this.createPointerEvent(from);
1625
+ this.dispatchEvent(e, "pointerdown");
1626
+ if (e.pointerType === "touch") {
1627
+ this.dispatchEvent(e, "touchstart");
1628
+ } else if (e.pointerType === "mouse" || e.pointerType === "pen") {
1629
+ const isRightButton = e.button === 2;
1630
+ this.dispatchEvent(e, isRightButton ? "rightdown" : "mousedown");
1631
+ }
1632
+ const trackingData = this.trackingData(from.pointerId);
1633
+ trackingData.pressTargetsByButton[from.button] = e.composedPath();
1634
+ this.freeEvent(e);
1635
+ }
1636
+ /**
1637
+ * Maps the upstream `pointermove` to downstream `pointerout`, `pointerover`, and `pointermove` events, in that order.
1638
+ *
1639
+ * The tracking data for the specific pointer has an updated `overTarget`. `mouseout`, `mouseover`,
1640
+ * `mousemove`, and `touchmove` events are fired as well for specific pointer types.
1641
+ * @param from - The upstream `pointermove` event.
1642
+ */
1643
+ mapPointerMove(from) {
1644
+ if (!(from instanceof FederatedPointerEvent)) {
1645
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1646
+ return;
1647
+ }
1648
+ this._allInteractiveElements.length = 0;
1649
+ this._hitElements.length = 0;
1650
+ this._isPointerMoveEvent = true;
1651
+ const e = this.createPointerEvent(from);
1652
+ this._isPointerMoveEvent = false;
1653
+ const isMouse = e.pointerType === "mouse" || e.pointerType === "pen";
1654
+ const trackingData = this.trackingData(from.pointerId);
1655
+ const outTarget = this.findMountedTarget(trackingData.overTargets);
1656
+ if (trackingData.overTargets?.length > 0 && outTarget !== e.target) {
1657
+ const outType = from.type === "mousemove" ? "mouseout" : "pointerout";
1658
+ const outEvent = this.createPointerEvent(from, outType, outTarget);
1659
+ this.dispatchEvent(outEvent, "pointerout");
1660
+ if (isMouse)
1661
+ this.dispatchEvent(outEvent, "mouseout");
1662
+ if (!e.composedPath().includes(outTarget)) {
1663
+ const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
1664
+ leaveEvent.eventPhase = leaveEvent.AT_TARGET;
1665
+ while (leaveEvent.target && !e.composedPath().includes(leaveEvent.target)) {
1666
+ leaveEvent.currentTarget = leaveEvent.target;
1667
+ this.notifyTarget(leaveEvent);
1668
+ if (isMouse)
1669
+ this.notifyTarget(leaveEvent, "mouseleave");
1670
+ leaveEvent.target = leaveEvent.target.parent;
1671
+ }
1672
+ this.freeEvent(leaveEvent);
1673
+ }
1674
+ this.freeEvent(outEvent);
1675
+ }
1676
+ if (outTarget !== e.target) {
1677
+ const overType = from.type === "mousemove" ? "mouseover" : "pointerover";
1678
+ const overEvent = this.clonePointerEvent(e, overType);
1679
+ this.dispatchEvent(overEvent, "pointerover");
1680
+ if (isMouse)
1681
+ this.dispatchEvent(overEvent, "mouseover");
1682
+ let overTargetAncestor = outTarget?.parent;
1683
+ while (overTargetAncestor && overTargetAncestor !== this.rootTarget.parent) {
1684
+ if (overTargetAncestor === e.target)
1685
+ break;
1686
+ overTargetAncestor = overTargetAncestor.parent;
1687
+ }
1688
+ const didPointerEnter = !overTargetAncestor || overTargetAncestor === this.rootTarget.parent;
1689
+ if (didPointerEnter) {
1690
+ const enterEvent = this.clonePointerEvent(e, "pointerenter");
1691
+ enterEvent.eventPhase = enterEvent.AT_TARGET;
1692
+ while (enterEvent.target && enterEvent.target !== outTarget && enterEvent.target !== this.rootTarget.parent) {
1693
+ enterEvent.currentTarget = enterEvent.target;
1694
+ this.notifyTarget(enterEvent);
1695
+ if (isMouse)
1696
+ this.notifyTarget(enterEvent, "mouseenter");
1697
+ enterEvent.target = enterEvent.target.parent;
1698
+ }
1699
+ this.freeEvent(enterEvent);
1700
+ }
1701
+ this.freeEvent(overEvent);
1702
+ }
1703
+ const allMethods = [];
1704
+ const allowGlobalPointerEvents = this.enableGlobalMoveEvents ?? true;
1705
+ this.moveOnAll ? allMethods.push("pointermove") : this.dispatchEvent(e, "pointermove");
1706
+ allowGlobalPointerEvents && allMethods.push("globalpointermove");
1707
+ if (e.pointerType === "touch") {
1708
+ this.moveOnAll ? allMethods.splice(1, 0, "touchmove") : this.dispatchEvent(e, "touchmove");
1709
+ allowGlobalPointerEvents && allMethods.push("globaltouchmove");
1710
+ }
1711
+ if (isMouse) {
1712
+ this.moveOnAll ? allMethods.splice(1, 0, "mousemove") : this.dispatchEvent(e, "mousemove");
1713
+ allowGlobalPointerEvents && allMethods.push("globalmousemove");
1714
+ this.cursor = e.target?.cursor;
1715
+ }
1716
+ if (allMethods.length > 0) {
1717
+ this.all(e, allMethods);
1718
+ }
1719
+ this._allInteractiveElements.length = 0;
1720
+ this._hitElements.length = 0;
1721
+ trackingData.overTargets = e.composedPath();
1722
+ this.freeEvent(e);
1723
+ }
1724
+ /**
1725
+ * Maps the upstream `pointerover` to downstream `pointerover` and `pointerenter` events, in that order.
1726
+ *
1727
+ * The tracking data for the specific pointer gets a new `overTarget`.
1728
+ * @param from - The upstream `pointerover` event.
1729
+ */
1730
+ mapPointerOver(from) {
1731
+ if (!(from instanceof FederatedPointerEvent)) {
1732
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1733
+ return;
1734
+ }
1735
+ const trackingData = this.trackingData(from.pointerId);
1736
+ const e = this.createPointerEvent(from);
1737
+ const isMouse = e.pointerType === "mouse" || e.pointerType === "pen";
1738
+ this.dispatchEvent(e, "pointerover");
1739
+ if (isMouse)
1740
+ this.dispatchEvent(e, "mouseover");
1741
+ if (e.pointerType === "mouse")
1742
+ this.cursor = e.target?.cursor;
1743
+ const enterEvent = this.clonePointerEvent(e, "pointerenter");
1744
+ enterEvent.eventPhase = enterEvent.AT_TARGET;
1745
+ while (enterEvent.target && enterEvent.target !== this.rootTarget.parent) {
1746
+ enterEvent.currentTarget = enterEvent.target;
1747
+ this.notifyTarget(enterEvent);
1748
+ if (isMouse)
1749
+ this.notifyTarget(enterEvent, "mouseenter");
1750
+ enterEvent.target = enterEvent.target.parent;
1751
+ }
1752
+ trackingData.overTargets = e.composedPath();
1753
+ this.freeEvent(e);
1754
+ this.freeEvent(enterEvent);
1755
+ }
1756
+ /**
1757
+ * Maps the upstream `pointerout` to downstream `pointerout`, `pointerleave` events, in that order.
1758
+ *
1759
+ * The tracking data for the specific pointer is cleared of a `overTarget`.
1760
+ * @param from - The upstream `pointerout` event.
1761
+ */
1762
+ mapPointerOut(from) {
1763
+ if (!(from instanceof FederatedPointerEvent)) {
1764
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1765
+ return;
1766
+ }
1767
+ const trackingData = this.trackingData(from.pointerId);
1768
+ if (trackingData.overTargets) {
1769
+ const isMouse = from.pointerType === "mouse" || from.pointerType === "pen";
1770
+ const outTarget = this.findMountedTarget(trackingData.overTargets);
1771
+ const outEvent = this.createPointerEvent(from, "pointerout", outTarget);
1772
+ this.dispatchEvent(outEvent);
1773
+ if (isMouse)
1774
+ this.dispatchEvent(outEvent, "mouseout");
1775
+ const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
1776
+ leaveEvent.eventPhase = leaveEvent.AT_TARGET;
1777
+ while (leaveEvent.target && leaveEvent.target !== this.rootTarget.parent) {
1778
+ leaveEvent.currentTarget = leaveEvent.target;
1779
+ this.notifyTarget(leaveEvent);
1780
+ if (isMouse)
1781
+ this.notifyTarget(leaveEvent, "mouseleave");
1782
+ leaveEvent.target = leaveEvent.target.parent;
1783
+ }
1784
+ trackingData.overTargets = null;
1785
+ this.freeEvent(outEvent);
1786
+ this.freeEvent(leaveEvent);
1787
+ }
1788
+ this.cursor = null;
1789
+ }
1790
+ /**
1791
+ * Maps the upstream `pointerup` event to downstream `pointerup`, `pointerupoutside`,
1792
+ * and `click`/`rightclick`/`pointertap` events, in that order.
1793
+ *
1794
+ * The `pointerupoutside` event bubbles from the original `pointerdown` target to the most specific
1795
+ * ancestor of the `pointerdown` and `pointerup` targets, which is also the `click` event's target. `touchend`,
1796
+ * `rightup`, `mouseup`, `touchendoutside`, `rightupoutside`, `mouseupoutside`, and `tap` are fired as well for
1797
+ * specific pointer types.
1798
+ * @param from - The upstream `pointerup` event.
1799
+ */
1800
+ mapPointerUp(from) {
1801
+ if (!(from instanceof FederatedPointerEvent)) {
1802
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1803
+ return;
1804
+ }
1805
+ const now = performance.now();
1806
+ const e = this.createPointerEvent(from);
1807
+ this.dispatchEvent(e, "pointerup");
1808
+ if (e.pointerType === "touch") {
1809
+ this.dispatchEvent(e, "touchend");
1810
+ } else if (e.pointerType === "mouse" || e.pointerType === "pen") {
1811
+ const isRightButton = e.button === 2;
1812
+ this.dispatchEvent(e, isRightButton ? "rightup" : "mouseup");
1813
+ }
1814
+ const trackingData = this.trackingData(from.pointerId);
1815
+ const pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
1816
+ let clickTarget = pressTarget;
1817
+ if (pressTarget && !e.composedPath().includes(pressTarget)) {
1818
+ let currentTarget = pressTarget;
1819
+ while (currentTarget && !e.composedPath().includes(currentTarget)) {
1820
+ e.currentTarget = currentTarget;
1821
+ this.notifyTarget(e, "pointerupoutside");
1822
+ if (e.pointerType === "touch") {
1823
+ this.notifyTarget(e, "touchendoutside");
1824
+ } else if (e.pointerType === "mouse" || e.pointerType === "pen") {
1825
+ const isRightButton = e.button === 2;
1826
+ this.notifyTarget(e, isRightButton ? "rightupoutside" : "mouseupoutside");
1827
+ }
1828
+ currentTarget = currentTarget.parent;
1829
+ }
1830
+ delete trackingData.pressTargetsByButton[from.button];
1831
+ clickTarget = currentTarget;
1832
+ }
1833
+ if (clickTarget) {
1834
+ const clickEvent = this.clonePointerEvent(e, "click");
1835
+ clickEvent.target = clickTarget;
1836
+ clickEvent.path = null;
1837
+ if (!trackingData.clicksByButton[from.button]) {
1838
+ trackingData.clicksByButton[from.button] = {
1839
+ clickCount: 0,
1840
+ target: clickEvent.target,
1841
+ timeStamp: now
1842
+ };
1843
+ }
1844
+ const clickHistory = trackingData.clicksByButton[from.button];
1845
+ if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < 200) {
1846
+ ++clickHistory.clickCount;
1847
+ } else {
1848
+ clickHistory.clickCount = 1;
1849
+ }
1850
+ clickHistory.target = clickEvent.target;
1851
+ clickHistory.timeStamp = now;
1852
+ clickEvent.detail = clickHistory.clickCount;
1853
+ if (clickEvent.pointerType === "mouse") {
1854
+ const isRightButton = clickEvent.button === 2;
1855
+ this.dispatchEvent(clickEvent, isRightButton ? "rightclick" : "click");
1856
+ } else if (clickEvent.pointerType === "touch") {
1857
+ this.dispatchEvent(clickEvent, "tap");
1858
+ }
1859
+ this.dispatchEvent(clickEvent, "pointertap");
1860
+ this.freeEvent(clickEvent);
1861
+ }
1862
+ this.freeEvent(e);
1863
+ }
1864
+ /**
1865
+ * Maps the upstream `pointerupoutside` event to a downstream `pointerupoutside` event, bubbling from the original
1866
+ * `pointerdown` target to `rootTarget`.
1867
+ *
1868
+ * (The most specific ancestor of the `pointerdown` event and the `pointerup` event must the
1869
+ * `{@link EventBoundary}'s root because the `pointerup` event occurred outside of the boundary.)
1870
+ *
1871
+ * `touchendoutside`, `mouseupoutside`, and `rightupoutside` events are fired as well for specific pointer
1872
+ * types. The tracking data for the specific pointer is cleared of a `pressTarget`.
1873
+ * @param from - The upstream `pointerupoutside` event.
1874
+ */
1875
+ mapPointerUpOutside(from) {
1876
+ if (!(from instanceof FederatedPointerEvent)) {
1877
+ warn("EventBoundary cannot map a non-pointer event as a pointer event");
1878
+ return;
1879
+ }
1880
+ const trackingData = this.trackingData(from.pointerId);
1881
+ const pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
1882
+ const e = this.createPointerEvent(from);
1883
+ if (pressTarget) {
1884
+ let currentTarget = pressTarget;
1885
+ while (currentTarget) {
1886
+ e.currentTarget = currentTarget;
1887
+ this.notifyTarget(e, "pointerupoutside");
1888
+ if (e.pointerType === "touch") {
1889
+ this.notifyTarget(e, "touchendoutside");
1890
+ } else if (e.pointerType === "mouse" || e.pointerType === "pen") {
1891
+ this.notifyTarget(e, e.button === 2 ? "rightupoutside" : "mouseupoutside");
1892
+ }
1893
+ currentTarget = currentTarget.parent;
1894
+ }
1895
+ delete trackingData.pressTargetsByButton[from.button];
1896
+ }
1897
+ this.freeEvent(e);
1898
+ }
1899
+ /**
1900
+ * Maps the upstream `wheel` event to a downstream `wheel` event.
1901
+ * @param from - The upstream `wheel` event.
1902
+ */
1903
+ mapWheel(from) {
1904
+ if (!(from instanceof FederatedWheelEvent)) {
1905
+ warn("EventBoundary cannot map a non-wheel event as a wheel event");
1906
+ return;
1907
+ }
1908
+ const wheelEvent = this.createWheelEvent(from);
1909
+ this.dispatchEvent(wheelEvent);
1910
+ this.freeEvent(wheelEvent);
1911
+ }
1912
+ /**
1913
+ * Finds the most specific event-target in the given propagation path that is still mounted in the scene graph.
1914
+ *
1915
+ * This is used to find the correct `pointerup` and `pointerout` target in the case that the original `pointerdown`
1916
+ * or `pointerover` target was unmounted from the scene graph.
1917
+ * @param propagationPath - The propagation path was valid in the past.
1918
+ * @returns - The most specific event-target still mounted at the same location in the scene graph.
1919
+ */
1920
+ findMountedTarget(propagationPath) {
1921
+ if (!propagationPath) {
1922
+ return null;
1923
+ }
1924
+ let currentTarget = propagationPath[0];
1925
+ for (let i = 1; i < propagationPath.length; i++) {
1926
+ if (propagationPath[i].parent === currentTarget) {
1927
+ currentTarget = propagationPath[i];
1928
+ } else {
1929
+ break;
1930
+ }
1931
+ }
1932
+ return currentTarget;
1933
+ }
1934
+ /**
1935
+ * Creates an event whose {@code originalEvent} is {@code from}, with an optional `type` and `target` override.
1936
+ *
1937
+ * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1938
+ * @param from - The {@code originalEvent} for the returned event.
1939
+ * @param [type=from.type] - The type of the returned event.
1940
+ * @param target - The target of the returned event.
1941
+ */
1942
+ createPointerEvent(from, type, target) {
1943
+ const event = this.allocateEvent(FederatedPointerEvent);
1944
+ this.copyPointerData(from, event);
1945
+ this.copyMouseData(from, event);
1946
+ this.copyData(from, event);
1947
+ event.nativeEvent = from.nativeEvent;
1948
+ event.originalEvent = from;
1949
+ event.target = target ?? this.hitTest(event.global.x, event.global.y) ?? this._hitElements[0];
1950
+ if (typeof type === "string") {
1951
+ event.type = type;
1952
+ }
1953
+ return event;
1954
+ }
1955
+ /**
1956
+ * Creates a wheel event whose {@code originalEvent} is {@code from}.
1957
+ *
1958
+ * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1959
+ * @param from - The upstream wheel event.
1960
+ */
1961
+ createWheelEvent(from) {
1962
+ const event = this.allocateEvent(FederatedWheelEvent);
1963
+ this.copyWheelData(from, event);
1964
+ this.copyMouseData(from, event);
1965
+ this.copyData(from, event);
1966
+ event.nativeEvent = from.nativeEvent;
1967
+ event.originalEvent = from;
1968
+ event.target = this.hitTest(event.global.x, event.global.y);
1969
+ return event;
1970
+ }
1971
+ /**
1972
+ * Clones the event {@code from}, with an optional {@code type} override.
1973
+ *
1974
+ * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1975
+ * @param from - The event to clone.
1976
+ * @param [type=from.type] - The type of the returned event.
1977
+ */
1978
+ clonePointerEvent(from, type) {
1979
+ const event = this.allocateEvent(FederatedPointerEvent);
1980
+ event.nativeEvent = from.nativeEvent;
1981
+ event.originalEvent = from.originalEvent;
1982
+ this.copyPointerData(from, event);
1983
+ this.copyMouseData(from, event);
1984
+ this.copyData(from, event);
1985
+ event.target = from.target;
1986
+ event.path = from.composedPath().slice();
1987
+ event.type = type ?? event.type;
1988
+ return event;
1989
+ }
1990
+ /**
1991
+ * Copies wheel {@link FederatedWheelEvent} data from {@code from} into {@code to}.
1992
+ *
1993
+ * The following properties are copied:
1994
+ * + deltaMode
1995
+ * + deltaX
1996
+ * + deltaY
1997
+ * + deltaZ
1998
+ * @param from - The event to copy data from.
1999
+ * @param to - The event to copy data into.
2000
+ */
2001
+ copyWheelData(from, to) {
2002
+ to.deltaMode = from.deltaMode;
2003
+ to.deltaX = from.deltaX;
2004
+ to.deltaY = from.deltaY;
2005
+ to.deltaZ = from.deltaZ;
2006
+ }
2007
+ /**
2008
+ * Copies pointer {@link FederatedPointerEvent} data from {@code from} into {@code to}.
2009
+ *
2010
+ * The following properties are copied:
2011
+ * + pointerId
2012
+ * + width
2013
+ * + height
2014
+ * + isPrimary
2015
+ * + pointerType
2016
+ * + pressure
2017
+ * + tangentialPressure
2018
+ * + tiltX
2019
+ * + tiltY
2020
+ * @param from - The event to copy data from.
2021
+ * @param to - The event to copy data into.
2022
+ */
2023
+ copyPointerData(from, to) {
2024
+ if (!(from instanceof FederatedPointerEvent && to instanceof FederatedPointerEvent))
2025
+ return;
2026
+ to.pointerId = from.pointerId;
2027
+ to.width = from.width;
2028
+ to.height = from.height;
2029
+ to.isPrimary = from.isPrimary;
2030
+ to.pointerType = from.pointerType;
2031
+ to.pressure = from.pressure;
2032
+ to.tangentialPressure = from.tangentialPressure;
2033
+ to.tiltX = from.tiltX;
2034
+ to.tiltY = from.tiltY;
2035
+ to.twist = from.twist;
2036
+ }
2037
+ /**
2038
+ * Copies mouse {@link FederatedMouseEvent} data from {@code from} to {@code to}.
2039
+ *
2040
+ * The following properties are copied:
2041
+ * + altKey
2042
+ * + button
2043
+ * + buttons
2044
+ * + clientX
2045
+ * + clientY
2046
+ * + metaKey
2047
+ * + movementX
2048
+ * + movementY
2049
+ * + pageX
2050
+ * + pageY
2051
+ * + x
2052
+ * + y
2053
+ * + screen
2054
+ * + shiftKey
2055
+ * + global
2056
+ * @param from - The event to copy data from.
2057
+ * @param to - The event to copy data into.
2058
+ */
2059
+ copyMouseData(from, to) {
2060
+ if (!(from instanceof FederatedMouseEvent && to instanceof FederatedMouseEvent))
2061
+ return;
2062
+ to.altKey = from.altKey;
2063
+ to.button = from.button;
2064
+ to.buttons = from.buttons;
2065
+ to.client.copyFrom(from.client);
2066
+ to.ctrlKey = from.ctrlKey;
2067
+ to.metaKey = from.metaKey;
2068
+ to.movement.copyFrom(from.movement);
2069
+ to.screen.copyFrom(from.screen);
2070
+ to.shiftKey = from.shiftKey;
2071
+ to.global.copyFrom(from.global);
2072
+ }
2073
+ /**
2074
+ * Copies base {@link FederatedEvent} data from {@code from} into {@code to}.
2075
+ *
2076
+ * The following properties are copied:
2077
+ * + isTrusted
2078
+ * + srcElement
2079
+ * + timeStamp
2080
+ * + type
2081
+ * @param from - The event to copy data from.
2082
+ * @param to - The event to copy data into.
2083
+ */
2084
+ copyData(from, to) {
2085
+ to.isTrusted = from.isTrusted;
2086
+ to.srcElement = from.srcElement;
2087
+ to.timeStamp = performance.now();
2088
+ to.type = from.type;
2089
+ to.detail = from.detail;
2090
+ to.view = from.view;
2091
+ to.which = from.which;
2092
+ to.layer.copyFrom(from.layer);
2093
+ to.page.copyFrom(from.page);
2094
+ }
2095
+ /**
2096
+ * @param id - The pointer ID.
2097
+ * @returns The tracking data stored for the given pointer. If no data exists, a blank
2098
+ * state will be created.
2099
+ */
2100
+ trackingData(id) {
2101
+ if (!this.mappingState.trackingData[id]) {
2102
+ this.mappingState.trackingData[id] = {
2103
+ pressTargetsByButton: {},
2104
+ clicksByButton: {},
2105
+ overTarget: null
2106
+ };
2107
+ }
2108
+ return this.mappingState.trackingData[id];
2109
+ }
2110
+ /**
2111
+ * Allocate a specific type of event from {@link EventBoundary#eventPool this.eventPool}.
2112
+ *
2113
+ * This allocation is constructor-agnostic, as long as it only takes one argument - this event
2114
+ * boundary.
2115
+ * @param constructor - The event's constructor.
2116
+ */
2117
+ allocateEvent(constructor) {
2118
+ if (!this.eventPool.has(constructor)) {
2119
+ this.eventPool.set(constructor, []);
2120
+ }
2121
+ const event = this.eventPool.get(constructor).pop() || new constructor(this);
2122
+ event.eventPhase = event.NONE;
2123
+ event.currentTarget = null;
2124
+ event.defaultPrevented = false;
2125
+ event.path = null;
2126
+ event.target = null;
2127
+ return event;
2128
+ }
2129
+ /**
2130
+ * Frees the event and puts it back into the event pool.
2131
+ *
2132
+ * It is illegal to reuse the event until it is allocated again, using `this.allocateEvent`.
2133
+ *
2134
+ * It is also advised that events not allocated from {@link EventBoundary#allocateEvent this.allocateEvent}
2135
+ * not be freed. This is because of the possibility that the same event is freed twice, which can cause
2136
+ * it to be allocated twice & result in overwriting.
2137
+ * @param event - The event to be freed.
2138
+ * @throws Error if the event is managed by another event boundary.
2139
+ */
2140
+ freeEvent(event) {
2141
+ if (event.manager !== this)
2142
+ throw new Error("It is illegal to free an event not managed by this EventBoundary!");
2143
+ const constructor = event.constructor;
2144
+ if (!this.eventPool.has(constructor)) {
2145
+ this.eventPool.set(constructor, []);
2146
+ }
2147
+ this.eventPool.get(constructor).push(event);
2148
+ }
2149
+ /**
2150
+ * Similar to {@link EventEmitter.emit}, except it stops if the `propagationImmediatelyStopped` flag
2151
+ * is set on the event.
2152
+ * @param e - The event to call each listener with.
2153
+ * @param type - The event key.
2154
+ */
2155
+ _notifyListeners(e, type) {
2156
+ const listeners = e.currentTarget._events[type];
2157
+ if (!listeners)
2158
+ return;
2159
+ if ("fn" in listeners) {
2160
+ if (listeners.once)
2161
+ e.currentTarget.removeListener(type, listeners.fn, void 0, true);
2162
+ listeners.fn.call(listeners.context, e);
2163
+ } else {
2164
+ for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++) {
2165
+ if (listeners[i].once)
2166
+ e.currentTarget.removeListener(type, listeners[i].fn, void 0, true);
2167
+ listeners[i].fn.call(listeners[i].context, e);
2168
+ }
2169
+ }
2170
+ }
2171
+ }
2172
+
2173
+ const MOUSE_POINTER_ID = 1;
2174
+ const TOUCH_TO_POINTER = {
2175
+ touchstart: "pointerdown",
2176
+ touchend: "pointerup",
2177
+ touchendoutside: "pointerupoutside",
2178
+ touchmove: "pointermove",
2179
+ touchcancel: "pointercancel"
2180
+ };
2181
+ const _EventSystem = class _EventSystem {
2182
+ /**
2183
+ * @param {Renderer} renderer
2184
+ */
2185
+ constructor(renderer) {
2186
+ /** Does the device support touch events https://www.w3.org/TR/touch-events/ */
2187
+ this.supportsTouchEvents = "ontouchstart" in globalThis;
2188
+ /** Does the device support pointer events https://www.w3.org/Submission/pointer-events/ */
2189
+ this.supportsPointerEvents = !!globalThis.PointerEvent;
2190
+ /**
2191
+ * The DOM element to which the root event listeners are bound. This is automatically set to
2192
+ * the renderer's {@link Renderer#view view}.
2193
+ */
2194
+ this.domElement = null;
2195
+ /** The resolution used to convert between the DOM client space into world space. */
2196
+ this.resolution = 1;
2197
+ this.renderer = renderer;
2198
+ this.rootBoundary = new EventBoundary(null);
2199
+ EventsTicker.init(this);
2200
+ this.autoPreventDefault = true;
2201
+ this._eventsAdded = false;
2202
+ this._rootPointerEvent = new FederatedPointerEvent(null);
2203
+ this._rootWheelEvent = new FederatedWheelEvent(null);
2204
+ this.cursorStyles = {
2205
+ default: "inherit",
2206
+ pointer: "pointer"
2207
+ };
2208
+ this.features = new Proxy({ ..._EventSystem.defaultEventFeatures }, {
2209
+ set: (target, key, value) => {
2210
+ if (key === "globalMove") {
2211
+ this.rootBoundary.enableGlobalMoveEvents = value;
2212
+ }
2213
+ target[key] = value;
2214
+ return true;
2215
+ }
2216
+ });
2217
+ this._onPointerDown = this._onPointerDown.bind(this);
2218
+ this._onPointerMove = this._onPointerMove.bind(this);
2219
+ this._onPointerUp = this._onPointerUp.bind(this);
2220
+ this._onPointerOverOut = this._onPointerOverOut.bind(this);
2221
+ this.onWheel = this.onWheel.bind(this);
2222
+ }
2223
+ /**
2224
+ * The default interaction mode for all display objects.
2225
+ * @see Container.eventMode
2226
+ * @type {EventMode}
2227
+ * @readonly
2228
+ * @since 7.2.0
2229
+ */
2230
+ static get defaultEventMode() {
2231
+ return this._defaultEventMode;
2232
+ }
2233
+ /**
2234
+ * Runner init called, view is available at this point.
2235
+ * @ignore
2236
+ */
2237
+ init(options) {
2238
+ const { canvas, resolution } = this.renderer;
2239
+ this.setTargetElement(canvas);
2240
+ this.resolution = resolution;
2241
+ _EventSystem._defaultEventMode = options.eventMode ?? "passive";
2242
+ Object.assign(this.features, options.eventFeatures ?? {});
2243
+ this.rootBoundary.enableGlobalMoveEvents = this.features.globalMove;
2244
+ }
2245
+ /**
2246
+ * Handle changing resolution.
2247
+ * @ignore
2248
+ */
2249
+ resolutionChange(resolution) {
2250
+ this.resolution = resolution;
2251
+ }
2252
+ /** Destroys all event listeners and detaches the renderer. */
2253
+ destroy() {
2254
+ this.setTargetElement(null);
2255
+ this.renderer = null;
2256
+ this._currentCursor = null;
2257
+ }
2258
+ /**
2259
+ * Sets the current cursor mode, handling any callbacks or CSS style changes.
2260
+ * @param mode - cursor mode, a key from the cursorStyles dictionary
2261
+ */
2262
+ setCursor(mode) {
2263
+ mode || (mode = "default");
2264
+ let applyStyles = true;
2265
+ if (globalThis.OffscreenCanvas && this.domElement instanceof OffscreenCanvas) {
2266
+ applyStyles = false;
2267
+ }
2268
+ if (this._currentCursor === mode) {
2269
+ return;
2270
+ }
2271
+ this._currentCursor = mode;
2272
+ const style = this.cursorStyles[mode];
2273
+ if (style) {
2274
+ switch (typeof style) {
2275
+ case "string":
2276
+ if (applyStyles) {
2277
+ this.domElement.style.cursor = style;
2278
+ }
2279
+ break;
2280
+ case "function":
2281
+ style(mode);
2282
+ break;
2283
+ case "object":
2284
+ if (applyStyles) {
2285
+ Object.assign(this.domElement.style, style);
2286
+ }
2287
+ break;
2288
+ }
2289
+ } else if (applyStyles && typeof mode === "string" && !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode)) {
2290
+ this.domElement.style.cursor = mode;
2291
+ }
2292
+ }
2293
+ /**
2294
+ * The global pointer event.
2295
+ * Useful for getting the pointer position without listening to events.
2296
+ * @since 7.2.0
2297
+ */
2298
+ get pointer() {
2299
+ return this._rootPointerEvent;
2300
+ }
2301
+ /**
2302
+ * Event handler for pointer down events on {@link EventSystem#domElement this.domElement}.
2303
+ * @param nativeEvent - The native mouse/pointer/touch event.
2304
+ */
2305
+ _onPointerDown(nativeEvent) {
2306
+ if (!this.features.click)
2307
+ return;
2308
+ this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
2309
+ const events = this._normalizeToPointerData(nativeEvent);
2310
+ if (this.autoPreventDefault && events[0].isNormalized) {
2311
+ const cancelable = nativeEvent.cancelable || !("cancelable" in nativeEvent);
2312
+ if (cancelable) {
2313
+ nativeEvent.preventDefault();
2314
+ }
2315
+ }
2316
+ for (let i = 0, j = events.length; i < j; i++) {
2317
+ const nativeEvent2 = events[i];
2318
+ const federatedEvent = this._bootstrapEvent(this._rootPointerEvent, nativeEvent2);
2319
+ this.rootBoundary.mapEvent(federatedEvent);
2320
+ }
2321
+ this.setCursor(this.rootBoundary.cursor);
2322
+ }
2323
+ /**
2324
+ * Event handler for pointer move events on on {@link EventSystem#domElement this.domElement}.
2325
+ * @param nativeEvent - The native mouse/pointer/touch events.
2326
+ */
2327
+ _onPointerMove(nativeEvent) {
2328
+ if (!this.features.move)
2329
+ return;
2330
+ this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
2331
+ EventsTicker.pointerMoved();
2332
+ const normalizedEvents = this._normalizeToPointerData(nativeEvent);
2333
+ for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2334
+ const event = this._bootstrapEvent(this._rootPointerEvent, normalizedEvents[i]);
2335
+ this.rootBoundary.mapEvent(event);
2336
+ }
2337
+ this.setCursor(this.rootBoundary.cursor);
2338
+ }
2339
+ /**
2340
+ * Event handler for pointer up events on {@link EventSystem#domElement this.domElement}.
2341
+ * @param nativeEvent - The native mouse/pointer/touch event.
2342
+ */
2343
+ _onPointerUp(nativeEvent) {
2344
+ if (!this.features.click)
2345
+ return;
2346
+ this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
2347
+ let target = nativeEvent.target;
2348
+ if (nativeEvent.composedPath && nativeEvent.composedPath().length > 0) {
2349
+ target = nativeEvent.composedPath()[0];
2350
+ }
2351
+ const outside = target !== this.domElement ? "outside" : "";
2352
+ const normalizedEvents = this._normalizeToPointerData(nativeEvent);
2353
+ for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2354
+ const event = this._bootstrapEvent(this._rootPointerEvent, normalizedEvents[i]);
2355
+ event.type += outside;
2356
+ this.rootBoundary.mapEvent(event);
2357
+ }
2358
+ this.setCursor(this.rootBoundary.cursor);
2359
+ }
2360
+ /**
2361
+ * Event handler for pointer over & out events on {@link EventSystem#domElement this.domElement}.
2362
+ * @param nativeEvent - The native mouse/pointer/touch event.
2363
+ */
2364
+ _onPointerOverOut(nativeEvent) {
2365
+ if (!this.features.click)
2366
+ return;
2367
+ this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
2368
+ const normalizedEvents = this._normalizeToPointerData(nativeEvent);
2369
+ for (let i = 0, j = normalizedEvents.length; i < j; i++) {
2370
+ const event = this._bootstrapEvent(this._rootPointerEvent, normalizedEvents[i]);
2371
+ this.rootBoundary.mapEvent(event);
2372
+ }
2373
+ this.setCursor(this.rootBoundary.cursor);
2374
+ }
2375
+ /**
2376
+ * Passive handler for `wheel` events on {@link EventSystem.domElement this.domElement}.
2377
+ * @param nativeEvent - The native wheel event.
2378
+ */
2379
+ onWheel(nativeEvent) {
2380
+ if (!this.features.wheel)
2381
+ return;
2382
+ const wheelEvent = this.normalizeWheelEvent(nativeEvent);
2383
+ this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
2384
+ this.rootBoundary.mapEvent(wheelEvent);
2385
+ }
2386
+ /**
2387
+ * Sets the {@link EventSystem#domElement domElement} and binds event listeners.
2388
+ *
2389
+ * To deregister the current DOM element without setting a new one, pass {@code null}.
2390
+ * @param element - The new DOM element.
2391
+ */
2392
+ setTargetElement(element) {
2393
+ this._removeEvents();
2394
+ this.domElement = element;
2395
+ EventsTicker.domElement = element;
2396
+ this._addEvents();
2397
+ }
2398
+ /** Register event listeners on {@link Renderer#domElement this.domElement}. */
2399
+ _addEvents() {
2400
+ if (this._eventsAdded || !this.domElement) {
2401
+ return;
2402
+ }
2403
+ EventsTicker.addTickerListener();
2404
+ const style = this.domElement.style;
2405
+ if (style) {
2406
+ if (globalThis.navigator.msPointerEnabled) {
2407
+ style.msContentZooming = "none";
2408
+ style.msTouchAction = "none";
2409
+ } else if (this.supportsPointerEvents) {
2410
+ style.touchAction = "none";
2411
+ }
2412
+ }
2413
+ if (this.supportsPointerEvents) {
2414
+ globalThis.document.addEventListener("pointermove", this._onPointerMove, true);
2415
+ this.domElement.addEventListener("pointerdown", this._onPointerDown, true);
2416
+ this.domElement.addEventListener("pointerleave", this._onPointerOverOut, true);
2417
+ this.domElement.addEventListener("pointerover", this._onPointerOverOut, true);
2418
+ globalThis.addEventListener("pointerup", this._onPointerUp, true);
2419
+ } else {
2420
+ globalThis.document.addEventListener("mousemove", this._onPointerMove, true);
2421
+ this.domElement.addEventListener("mousedown", this._onPointerDown, true);
2422
+ this.domElement.addEventListener("mouseout", this._onPointerOverOut, true);
2423
+ this.domElement.addEventListener("mouseover", this._onPointerOverOut, true);
2424
+ globalThis.addEventListener("mouseup", this._onPointerUp, true);
2425
+ if (this.supportsTouchEvents) {
2426
+ this.domElement.addEventListener("touchstart", this._onPointerDown, true);
2427
+ this.domElement.addEventListener("touchend", this._onPointerUp, true);
2428
+ this.domElement.addEventListener("touchmove", this._onPointerMove, true);
2429
+ }
2430
+ }
2431
+ this.domElement.addEventListener("wheel", this.onWheel, {
2432
+ passive: true,
2433
+ capture: true
2434
+ });
2435
+ this._eventsAdded = true;
2436
+ }
2437
+ /** Unregister event listeners on {@link EventSystem#domElement this.domElement}. */
2438
+ _removeEvents() {
2439
+ if (!this._eventsAdded || !this.domElement) {
2440
+ return;
2441
+ }
2442
+ EventsTicker.removeTickerListener();
2443
+ const style = this.domElement.style;
2444
+ if (style) {
2445
+ if (globalThis.navigator.msPointerEnabled) {
2446
+ style.msContentZooming = "";
2447
+ style.msTouchAction = "";
2448
+ } else if (this.supportsPointerEvents) {
2449
+ style.touchAction = "";
2450
+ }
2451
+ }
2452
+ if (this.supportsPointerEvents) {
2453
+ globalThis.document.removeEventListener("pointermove", this._onPointerMove, true);
2454
+ this.domElement.removeEventListener("pointerdown", this._onPointerDown, true);
2455
+ this.domElement.removeEventListener("pointerleave", this._onPointerOverOut, true);
2456
+ this.domElement.removeEventListener("pointerover", this._onPointerOverOut, true);
2457
+ globalThis.removeEventListener("pointerup", this._onPointerUp, true);
2458
+ } else {
2459
+ globalThis.document.removeEventListener("mousemove", this._onPointerMove, true);
2460
+ this.domElement.removeEventListener("mousedown", this._onPointerDown, true);
2461
+ this.domElement.removeEventListener("mouseout", this._onPointerOverOut, true);
2462
+ this.domElement.removeEventListener("mouseover", this._onPointerOverOut, true);
2463
+ globalThis.removeEventListener("mouseup", this._onPointerUp, true);
2464
+ if (this.supportsTouchEvents) {
2465
+ this.domElement.removeEventListener("touchstart", this._onPointerDown, true);
2466
+ this.domElement.removeEventListener("touchend", this._onPointerUp, true);
2467
+ this.domElement.removeEventListener("touchmove", this._onPointerMove, true);
2468
+ }
2469
+ }
2470
+ this.domElement.removeEventListener("wheel", this.onWheel, true);
2471
+ this.domElement = null;
2472
+ this._eventsAdded = false;
2473
+ }
2474
+ /**
2475
+ * Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
2476
+ * resulting value is stored in the point. This takes into account the fact that the DOM
2477
+ * element could be scaled and positioned anywhere on the screen.
2478
+ * @param {PointData} point - the point that the result will be stored in
2479
+ * @param {number} x - the x coord of the position to map
2480
+ * @param {number} y - the y coord of the position to map
2481
+ */
2482
+ mapPositionToPoint(point, x, y) {
2483
+ const rect = this.domElement.isConnected ? this.domElement.getBoundingClientRect() : {
2484
+ width: this.domElement.width,
2485
+ height: this.domElement.height,
2486
+ left: 0,
2487
+ top: 0
2488
+ };
2489
+ const resolutionMultiplier = 1 / this.resolution;
2490
+ point.x = (x - rect.left) * (this.domElement.width / rect.width) * resolutionMultiplier;
2491
+ point.y = (y - rect.top) * (this.domElement.height / rect.height) * resolutionMultiplier;
2492
+ }
2493
+ /**
2494
+ * Ensures that the original event object contains all data that a regular pointer event would have
2495
+ * @param event - The original event data from a touch or mouse event
2496
+ * @returns An array containing a single normalized pointer event, in the case of a pointer
2497
+ * or mouse event, or a multiple normalized pointer events if there are multiple changed touches
2498
+ */
2499
+ _normalizeToPointerData(event) {
2500
+ const normalizedEvents = [];
2501
+ if (this.supportsTouchEvents && event instanceof TouchEvent) {
2502
+ for (let i = 0, li = event.changedTouches.length; i < li; i++) {
2503
+ const touch = event.changedTouches[i];
2504
+ if (typeof touch.button === "undefined")
2505
+ touch.button = 0;
2506
+ if (typeof touch.buttons === "undefined")
2507
+ touch.buttons = 1;
2508
+ if (typeof touch.isPrimary === "undefined") {
2509
+ touch.isPrimary = event.touches.length === 1 && event.type === "touchstart";
2510
+ }
2511
+ if (typeof touch.width === "undefined")
2512
+ touch.width = touch.radiusX || 1;
2513
+ if (typeof touch.height === "undefined")
2514
+ touch.height = touch.radiusY || 1;
2515
+ if (typeof touch.tiltX === "undefined")
2516
+ touch.tiltX = 0;
2517
+ if (typeof touch.tiltY === "undefined")
2518
+ touch.tiltY = 0;
2519
+ if (typeof touch.pointerType === "undefined")
2520
+ touch.pointerType = "touch";
2521
+ if (typeof touch.pointerId === "undefined")
2522
+ touch.pointerId = touch.identifier || 0;
2523
+ if (typeof touch.pressure === "undefined")
2524
+ touch.pressure = touch.force || 0.5;
2525
+ if (typeof touch.twist === "undefined")
2526
+ touch.twist = 0;
2527
+ if (typeof touch.tangentialPressure === "undefined")
2528
+ touch.tangentialPressure = 0;
2529
+ if (typeof touch.layerX === "undefined")
2530
+ touch.layerX = touch.offsetX = touch.clientX;
2531
+ if (typeof touch.layerY === "undefined")
2532
+ touch.layerY = touch.offsetY = touch.clientY;
2533
+ touch.isNormalized = true;
2534
+ touch.type = event.type;
2535
+ normalizedEvents.push(touch);
2536
+ }
2537
+ } else if (!globalThis.MouseEvent || event instanceof MouseEvent && (!this.supportsPointerEvents || !(event instanceof globalThis.PointerEvent))) {
2538
+ const tempEvent = event;
2539
+ if (typeof tempEvent.isPrimary === "undefined")
2540
+ tempEvent.isPrimary = true;
2541
+ if (typeof tempEvent.width === "undefined")
2542
+ tempEvent.width = 1;
2543
+ if (typeof tempEvent.height === "undefined")
2544
+ tempEvent.height = 1;
2545
+ if (typeof tempEvent.tiltX === "undefined")
2546
+ tempEvent.tiltX = 0;
2547
+ if (typeof tempEvent.tiltY === "undefined")
2548
+ tempEvent.tiltY = 0;
2549
+ if (typeof tempEvent.pointerType === "undefined")
2550
+ tempEvent.pointerType = "mouse";
2551
+ if (typeof tempEvent.pointerId === "undefined")
2552
+ tempEvent.pointerId = MOUSE_POINTER_ID;
2553
+ if (typeof tempEvent.pressure === "undefined")
2554
+ tempEvent.pressure = 0.5;
2555
+ if (typeof tempEvent.twist === "undefined")
2556
+ tempEvent.twist = 0;
2557
+ if (typeof tempEvent.tangentialPressure === "undefined")
2558
+ tempEvent.tangentialPressure = 0;
2559
+ tempEvent.isNormalized = true;
2560
+ normalizedEvents.push(tempEvent);
2561
+ } else {
2562
+ normalizedEvents.push(event);
2563
+ }
2564
+ return normalizedEvents;
2565
+ }
2566
+ /**
2567
+ * Normalizes the native {@link https://w3c.github.io/uievents/#interface-wheelevent WheelEvent}.
2568
+ *
2569
+ * The returned {@link FederatedWheelEvent} is a shared instance. It will not persist across
2570
+ * multiple native wheel events.
2571
+ * @param nativeEvent - The native wheel event that occurred on the canvas.
2572
+ * @returns A federated wheel event.
2573
+ */
2574
+ normalizeWheelEvent(nativeEvent) {
2575
+ const event = this._rootWheelEvent;
2576
+ this._transferMouseData(event, nativeEvent);
2577
+ event.deltaX = nativeEvent.deltaX;
2578
+ event.deltaY = nativeEvent.deltaY;
2579
+ event.deltaZ = nativeEvent.deltaZ;
2580
+ event.deltaMode = nativeEvent.deltaMode;
2581
+ this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY);
2582
+ event.global.copyFrom(event.screen);
2583
+ event.offset.copyFrom(event.screen);
2584
+ event.nativeEvent = nativeEvent;
2585
+ event.type = nativeEvent.type;
2586
+ return event;
2587
+ }
2588
+ /**
2589
+ * Normalizes the `nativeEvent` into a federateed {@link FederatedPointerEvent}.
2590
+ * @param event
2591
+ * @param nativeEvent
2592
+ */
2593
+ _bootstrapEvent(event, nativeEvent) {
2594
+ event.originalEvent = null;
2595
+ event.nativeEvent = nativeEvent;
2596
+ event.pointerId = nativeEvent.pointerId;
2597
+ event.width = nativeEvent.width;
2598
+ event.height = nativeEvent.height;
2599
+ event.isPrimary = nativeEvent.isPrimary;
2600
+ event.pointerType = nativeEvent.pointerType;
2601
+ event.pressure = nativeEvent.pressure;
2602
+ event.tangentialPressure = nativeEvent.tangentialPressure;
2603
+ event.tiltX = nativeEvent.tiltX;
2604
+ event.tiltY = nativeEvent.tiltY;
2605
+ event.twist = nativeEvent.twist;
2606
+ this._transferMouseData(event, nativeEvent);
2607
+ this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY);
2608
+ event.global.copyFrom(event.screen);
2609
+ event.offset.copyFrom(event.screen);
2610
+ event.isTrusted = nativeEvent.isTrusted;
2611
+ if (event.type === "pointerleave") {
2612
+ event.type = "pointerout";
2613
+ }
2614
+ if (event.type.startsWith("mouse")) {
2615
+ event.type = event.type.replace("mouse", "pointer");
2616
+ }
2617
+ if (event.type.startsWith("touch")) {
2618
+ event.type = TOUCH_TO_POINTER[event.type] || event.type;
2619
+ }
2620
+ return event;
2621
+ }
2622
+ /**
2623
+ * Transfers base & mouse event data from the {@code nativeEvent} to the federated event.
2624
+ * @param event
2625
+ * @param nativeEvent
2626
+ */
2627
+ _transferMouseData(event, nativeEvent) {
2628
+ event.isTrusted = nativeEvent.isTrusted;
2629
+ event.srcElement = nativeEvent.srcElement;
2630
+ event.timeStamp = performance.now();
2631
+ event.type = nativeEvent.type;
2632
+ event.altKey = nativeEvent.altKey;
2633
+ event.button = nativeEvent.button;
2634
+ event.buttons = nativeEvent.buttons;
2635
+ event.client.x = nativeEvent.clientX;
2636
+ event.client.y = nativeEvent.clientY;
2637
+ event.ctrlKey = nativeEvent.ctrlKey;
2638
+ event.metaKey = nativeEvent.metaKey;
2639
+ event.movement.x = nativeEvent.movementX;
2640
+ event.movement.y = nativeEvent.movementY;
2641
+ event.page.x = nativeEvent.pageX;
2642
+ event.page.y = nativeEvent.pageY;
2643
+ event.relatedTarget = null;
2644
+ event.shiftKey = nativeEvent.shiftKey;
2645
+ }
2646
+ };
2647
+ /** @ignore */
2648
+ _EventSystem.extension = {
2649
+ name: "events",
2650
+ type: [
2651
+ ExtensionType.WebGLSystem,
2652
+ ExtensionType.CanvasSystem,
2653
+ ExtensionType.WebGPUSystem
2654
+ ],
2655
+ priority: -1
2656
+ };
2657
+ /**
2658
+ * The event features that are enabled by the EventSystem
2659
+ * (included in the **pixi.js** and **pixi.js-legacy** bundle), otherwise it will be ignored.
2660
+ * @since 7.2.0
2661
+ */
2662
+ _EventSystem.defaultEventFeatures = {
2663
+ /** Enables pointer events associated with pointer movement. */
2664
+ move: true,
2665
+ /** Enables global pointer move events. */
2666
+ globalMove: true,
2667
+ /** Enables pointer events associated with clicking. */
2668
+ click: true,
2669
+ /** Enables wheel events. */
2670
+ wheel: true
2671
+ };
2672
+ let EventSystem = _EventSystem;
2673
+
2674
+ const FederatedContainer = {
2675
+ /**
2676
+ * Property-based event handler for the `click` event.
2677
+ * @memberof scene.Container#
2678
+ * @default null
2679
+ * @example
2680
+ * this.onclick = (event) => {
2681
+ * //some function here that happens on click
2682
+ * }
2683
+ */
2684
+ onclick: null,
2685
+ /**
2686
+ * Property-based event handler for the `mousedown` event.
2687
+ * @memberof scene.Container#
2688
+ * @default null
2689
+ * @example
2690
+ * this.onmousedown = (event) => {
2691
+ * //some function here that happens on mousedown
2692
+ * }
2693
+ */
2694
+ onmousedown: null,
2695
+ /**
2696
+ * Property-based event handler for the `mouseenter` event.
2697
+ * @memberof scene.Container#
2698
+ * @default null
2699
+ * @example
2700
+ * this.onmouseenter = (event) => {
2701
+ * //some function here that happens on mouseenter
2702
+ * }
2703
+ */
2704
+ onmouseenter: null,
2705
+ /**
2706
+ * Property-based event handler for the `mouseleave` event.
2707
+ * @memberof scene.Container#
2708
+ * @default null
2709
+ * @example
2710
+ * this.onmouseleave = (event) => {
2711
+ * //some function here that happens on mouseleave
2712
+ * }
2713
+ */
2714
+ onmouseleave: null,
2715
+ /**
2716
+ * Property-based event handler for the `mousemove` event.
2717
+ * @memberof scene.Container#
2718
+ * @default null
2719
+ * @example
2720
+ * this.onmousemove = (event) => {
2721
+ * //some function here that happens on mousemove
2722
+ * }
2723
+ */
2724
+ onmousemove: null,
2725
+ /**
2726
+ * Property-based event handler for the `globalmousemove` event.
2727
+ * @memberof scene.Container#
2728
+ * @default null
2729
+ * @example
2730
+ * this.onglobalmousemove = (event) => {
2731
+ * //some function here that happens on globalmousemove
2732
+ * }
2733
+ */
2734
+ onglobalmousemove: null,
2735
+ /**
2736
+ * Property-based event handler for the `mouseout` event.
2737
+ * @memberof scene.Container#
2738
+ * @default null
2739
+ * @example
2740
+ * this.onmouseout = (event) => {
2741
+ * //some function here that happens on mouseout
2742
+ * }
2743
+ */
2744
+ onmouseout: null,
2745
+ /**
2746
+ * Property-based event handler for the `mouseover` event.
2747
+ * @memberof scene.Container#
2748
+ * @default null
2749
+ * @example
2750
+ * this.onmouseover = (event) => {
2751
+ * //some function here that happens on mouseover
2752
+ * }
2753
+ */
2754
+ onmouseover: null,
2755
+ /**
2756
+ * Property-based event handler for the `mouseup` event.
2757
+ * @memberof scene.Container#
2758
+ * @default null
2759
+ * @example
2760
+ * this.onmouseup = (event) => {
2761
+ * //some function here that happens on mouseup
2762
+ * }
2763
+ */
2764
+ onmouseup: null,
2765
+ /**
2766
+ * Property-based event handler for the `mouseupoutside` event.
2767
+ * @memberof scene.Container#
2768
+ * @default null
2769
+ * @example
2770
+ * this.onmouseupoutside = (event) => {
2771
+ * //some function here that happens on mouseupoutside
2772
+ * }
2773
+ */
2774
+ onmouseupoutside: null,
2775
+ /**
2776
+ * Property-based event handler for the `pointercancel` event.
2777
+ * @memberof scene.Container#
2778
+ * @default null
2779
+ * @example
2780
+ * this.onpointercancel = (event) => {
2781
+ * //some function here that happens on pointercancel
2782
+ * }
2783
+ */
2784
+ onpointercancel: null,
2785
+ /**
2786
+ * Property-based event handler for the `pointerdown` event.
2787
+ * @memberof scene.Container#
2788
+ * @default null
2789
+ * @example
2790
+ * this.onpointerdown = (event) => {
2791
+ * //some function here that happens on pointerdown
2792
+ * }
2793
+ */
2794
+ onpointerdown: null,
2795
+ /**
2796
+ * Property-based event handler for the `pointerenter` event.
2797
+ * @memberof scene.Container#
2798
+ * @default null
2799
+ * @example
2800
+ * this.onpointerenter = (event) => {
2801
+ * //some function here that happens on pointerenter
2802
+ * }
2803
+ */
2804
+ onpointerenter: null,
2805
+ /**
2806
+ * Property-based event handler for the `pointerleave` event.
2807
+ * @memberof scene.Container#
2808
+ * @default null
2809
+ * @example
2810
+ * this.onpointerleave = (event) => {
2811
+ * //some function here that happens on pointerleave
2812
+ * }
2813
+ */
2814
+ onpointerleave: null,
2815
+ /**
2816
+ * Property-based event handler for the `pointermove` event.
2817
+ * @memberof scene.Container#
2818
+ * @default null
2819
+ * @example
2820
+ * this.onpointermove = (event) => {
2821
+ * //some function here that happens on pointermove
2822
+ * }
2823
+ */
2824
+ onpointermove: null,
2825
+ /**
2826
+ * Property-based event handler for the `globalpointermove` event.
2827
+ * @memberof scene.Container#
2828
+ * @default null
2829
+ * @example
2830
+ * this.onglobalpointermove = (event) => {
2831
+ * //some function here that happens on globalpointermove
2832
+ * }
2833
+ */
2834
+ onglobalpointermove: null,
2835
+ /**
2836
+ * Property-based event handler for the `pointerout` event.
2837
+ * @memberof scene.Container#
2838
+ * @default null
2839
+ * @example
2840
+ * this.onpointerout = (event) => {
2841
+ * //some function here that happens on pointerout
2842
+ * }
2843
+ */
2844
+ onpointerout: null,
2845
+ /**
2846
+ * Property-based event handler for the `pointerover` event.
2847
+ * @memberof scene.Container#
2848
+ * @default null
2849
+ * @example
2850
+ * this.onpointerover = (event) => {
2851
+ * //some function here that happens on pointerover
2852
+ * }
2853
+ */
2854
+ onpointerover: null,
2855
+ /**
2856
+ * Property-based event handler for the `pointertap` event.
2857
+ * @memberof scene.Container#
2858
+ * @default null
2859
+ * @example
2860
+ * this.onpointertap = (event) => {
2861
+ * //some function here that happens on pointertap
2862
+ * }
2863
+ */
2864
+ onpointertap: null,
2865
+ /**
2866
+ * Property-based event handler for the `pointerup` event.
2867
+ * @memberof scene.Container#
2868
+ * @default null
2869
+ * @example
2870
+ * this.onpointerup = (event) => {
2871
+ * //some function here that happens on pointerup
2872
+ * }
2873
+ */
2874
+ onpointerup: null,
2875
+ /**
2876
+ * Property-based event handler for the `pointerupoutside` event.
2877
+ * @memberof scene.Container#
2878
+ * @default null
2879
+ * @example
2880
+ * this.onpointerupoutside = (event) => {
2881
+ * //some function here that happens on pointerupoutside
2882
+ * }
2883
+ */
2884
+ onpointerupoutside: null,
2885
+ /**
2886
+ * Property-based event handler for the `rightclick` event.
2887
+ * @memberof scene.Container#
2888
+ * @default null
2889
+ * @example
2890
+ * this.onrightclick = (event) => {
2891
+ * //some function here that happens on rightclick
2892
+ * }
2893
+ */
2894
+ onrightclick: null,
2895
+ /**
2896
+ * Property-based event handler for the `rightdown` event.
2897
+ * @memberof scene.Container#
2898
+ * @default null
2899
+ * @example
2900
+ * this.onrightdown = (event) => {
2901
+ * //some function here that happens on rightdown
2902
+ * }
2903
+ */
2904
+ onrightdown: null,
2905
+ /**
2906
+ * Property-based event handler for the `rightup` event.
2907
+ * @memberof scene.Container#
2908
+ * @default null
2909
+ * @example
2910
+ * this.onrightup = (event) => {
2911
+ * //some function here that happens on rightup
2912
+ * }
2913
+ */
2914
+ onrightup: null,
2915
+ /**
2916
+ * Property-based event handler for the `rightupoutside` event.
2917
+ * @memberof scene.Container#
2918
+ * @default null
2919
+ * @example
2920
+ * this.onrightupoutside = (event) => {
2921
+ * //some function here that happens on rightupoutside
2922
+ * }
2923
+ */
2924
+ onrightupoutside: null,
2925
+ /**
2926
+ * Property-based event handler for the `tap` event.
2927
+ * @memberof scene.Container#
2928
+ * @default null
2929
+ * @example
2930
+ * this.ontap = (event) => {
2931
+ * //some function here that happens on tap
2932
+ * }
2933
+ */
2934
+ ontap: null,
2935
+ /**
2936
+ * Property-based event handler for the `touchcancel` event.
2937
+ * @memberof scene.Container#
2938
+ * @default null
2939
+ * @example
2940
+ * this.ontouchcancel = (event) => {
2941
+ * //some function here that happens on touchcancel
2942
+ * }
2943
+ */
2944
+ ontouchcancel: null,
2945
+ /**
2946
+ * Property-based event handler for the `touchend` event.
2947
+ * @memberof scene.Container#
2948
+ * @default null
2949
+ * @example
2950
+ * this.ontouchend = (event) => {
2951
+ * //some function here that happens on touchend
2952
+ * }
2953
+ */
2954
+ ontouchend: null,
2955
+ /**
2956
+ * Property-based event handler for the `touchendoutside` event.
2957
+ * @memberof scene.Container#
2958
+ * @default null
2959
+ * @example
2960
+ * this.ontouchendoutside = (event) => {
2961
+ * //some function here that happens on touchendoutside
2962
+ * }
2963
+ */
2964
+ ontouchendoutside: null,
2965
+ /**
2966
+ * Property-based event handler for the `touchmove` event.
2967
+ * @memberof scene.Container#
2968
+ * @default null
2969
+ * @example
2970
+ * this.ontouchmove = (event) => {
2971
+ * //some function here that happens on touchmove
2972
+ * }
2973
+ */
2974
+ ontouchmove: null,
2975
+ /**
2976
+ * Property-based event handler for the `globaltouchmove` event.
2977
+ * @memberof scene.Container#
2978
+ * @default null
2979
+ * @example
2980
+ * this.onglobaltouchmove = (event) => {
2981
+ * //some function here that happens on globaltouchmove
2982
+ * }
2983
+ */
2984
+ onglobaltouchmove: null,
2985
+ /**
2986
+ * Property-based event handler for the `touchstart` event.
2987
+ * @memberof scene.Container#
2988
+ * @default null
2989
+ * @example
2990
+ * this.ontouchstart = (event) => {
2991
+ * //some function here that happens on touchstart
2992
+ * }
2993
+ */
2994
+ ontouchstart: null,
2995
+ /**
2996
+ * Property-based event handler for the `wheel` event.
2997
+ * @memberof scene.Container#
2998
+ * @default null
2999
+ * @example
3000
+ * this.onwheel = (event) => {
3001
+ * //some function here that happens on wheel
3002
+ * }
3003
+ */
3004
+ onwheel: null,
3005
+ /**
3006
+ * Enable interaction events for the Container. Touch, pointer and mouse
3007
+ * @memberof scene.Container#
3008
+ */
3009
+ get interactive() {
3010
+ return this.eventMode === "dynamic" || this.eventMode === "static";
3011
+ },
3012
+ set interactive(value) {
3013
+ this.eventMode = value ? "static" : "passive";
3014
+ },
3015
+ /**
3016
+ * @ignore
3017
+ */
3018
+ _internalEventMode: void 0,
3019
+ /**
3020
+ * Enable interaction events for the Container. Touch, pointer and mouse.
3021
+ * There are 5 types of interaction settings:
3022
+ * - `'none'`: Ignores all interaction events, even on its children.
3023
+ * - `'passive'`: **(default)** Does not emit events and ignores all hit testing on itself and non-interactive children.
3024
+ * Interactive children will still emit events.
3025
+ * - `'auto'`: Does not emit events but is hit tested if parent is interactive. Same as `interactive = false` in v7
3026
+ * - `'static'`: Emit events and is hit tested. Same as `interaction = true` in v7
3027
+ * - `'dynamic'`: Emits events and is hit tested but will also receive mock interaction events fired from a ticker to
3028
+ * allow for interaction when the mouse isn't moving
3029
+ * @example
3030
+ * import { Sprite } from 'pixi.js';
3031
+ *
3032
+ * const sprite = new Sprite(texture);
3033
+ * sprite.eventMode = 'static';
3034
+ * sprite.on('tap', (event) => {
3035
+ * // Handle event
3036
+ * });
3037
+ * @memberof scene.Container#
3038
+ * @since 7.2.0
3039
+ */
3040
+ get eventMode() {
3041
+ return this._internalEventMode ?? EventSystem.defaultEventMode;
3042
+ },
3043
+ set eventMode(value) {
3044
+ this._internalEventMode = value;
3045
+ },
3046
+ /**
3047
+ * Determines if the container is interactive or not
3048
+ * @returns {boolean} Whether the container is interactive or not
3049
+ * @memberof scene.Container#
3050
+ * @since 7.2.0
3051
+ * @example
3052
+ * import { Sprite } from 'pixi.js';
3053
+ *
3054
+ * const sprite = new Sprite(texture);
3055
+ * sprite.eventMode = 'static';
3056
+ * sprite.isInteractive(); // true
3057
+ *
3058
+ * sprite.eventMode = 'dynamic';
3059
+ * sprite.isInteractive(); // true
3060
+ *
3061
+ * sprite.eventMode = 'none';
3062
+ * sprite.isInteractive(); // false
3063
+ *
3064
+ * sprite.eventMode = 'passive';
3065
+ * sprite.isInteractive(); // false
3066
+ *
3067
+ * sprite.eventMode = 'auto';
3068
+ * sprite.isInteractive(); // false
3069
+ */
3070
+ isInteractive() {
3071
+ return this.eventMode === "static" || this.eventMode === "dynamic";
3072
+ },
3073
+ /**
3074
+ * Determines if the children to the container can be clicked/touched
3075
+ * Setting this to false allows PixiJS to bypass a recursive `hitTest` function
3076
+ * @memberof scene.Container#
3077
+ */
3078
+ interactiveChildren: true,
3079
+ /**
3080
+ * Interaction shape. Children will be hit first, then this shape will be checked.
3081
+ * Setting this will cause this shape to be checked in hit tests rather than the container's bounds.
3082
+ * @example
3083
+ * import { Rectangle, Sprite } from 'pixi.js';
3084
+ *
3085
+ * const sprite = new Sprite(texture);
3086
+ * sprite.interactive = true;
3087
+ * sprite.hitArea = new Rectangle(0, 0, 100, 100);
3088
+ * @member {IHitArea}
3089
+ * @memberof scene.Container#
3090
+ */
3091
+ hitArea: null,
3092
+ /**
3093
+ * Unlike `on` or `addListener` which are methods from EventEmitter, `addEventListener`
3094
+ * seeks to be compatible with the DOM's `addEventListener` with support for options.
3095
+ * @memberof scene.Container
3096
+ * @param type - The type of event to listen to.
3097
+ * @param listener - The listener callback or object.
3098
+ * @param options - Listener options, used for capture phase.
3099
+ * @example
3100
+ * // Tell the user whether they did a single, double, triple, or nth click.
3101
+ * button.addEventListener('click', {
3102
+ * handleEvent(e): {
3103
+ * let prefix;
3104
+ *
3105
+ * switch (e.detail) {
3106
+ * case 1: prefix = 'single'; break;
3107
+ * case 2: prefix = 'double'; break;
3108
+ * case 3: prefix = 'triple'; break;
3109
+ * default: prefix = e.detail + 'th'; break;
3110
+ * }
3111
+ *
3112
+ * console.log('That was a ' + prefix + 'click');
3113
+ * }
3114
+ * });
3115
+ *
3116
+ * // But skip the first click!
3117
+ * button.parent.addEventListener('click', function blockClickOnce(e) {
3118
+ * e.stopImmediatePropagation();
3119
+ * button.parent.removeEventListener('click', blockClickOnce, true);
3120
+ * }, {
3121
+ * capture: true,
3122
+ * });
3123
+ */
3124
+ addEventListener(type, listener, options) {
3125
+ const capture = typeof options === "boolean" && options || typeof options === "object" && options.capture;
3126
+ const signal = typeof options === "object" ? options.signal : void 0;
3127
+ const once = typeof options === "object" ? options.once === true : false;
3128
+ const context = typeof listener === "function" ? void 0 : listener;
3129
+ type = capture ? `${type}capture` : type;
3130
+ const listenerFn = typeof listener === "function" ? listener : listener.handleEvent;
3131
+ const emitter = this;
3132
+ if (signal) {
3133
+ signal.addEventListener("abort", () => {
3134
+ emitter.off(type, listenerFn, context);
3135
+ });
3136
+ }
3137
+ if (once) {
3138
+ emitter.once(type, listenerFn, context);
3139
+ } else {
3140
+ emitter.on(type, listenerFn, context);
3141
+ }
3142
+ },
3143
+ /**
3144
+ * Unlike `off` or `removeListener` which are methods from EventEmitter, `removeEventListener`
3145
+ * seeks to be compatible with the DOM's `removeEventListener` with support for options.
3146
+ * @memberof scene.Container
3147
+ * @param type - The type of event the listener is bound to.
3148
+ * @param listener - The listener callback or object.
3149
+ * @param options - The original listener options. This is required to deregister a capture phase listener.
3150
+ */
3151
+ removeEventListener(type, listener, options) {
3152
+ const capture = typeof options === "boolean" && options || typeof options === "object" && options.capture;
3153
+ const context = typeof listener === "function" ? void 0 : listener;
3154
+ type = capture ? `${type}capture` : type;
3155
+ listener = typeof listener === "function" ? listener : listener.handleEvent;
3156
+ this.off(type, listener, context);
3157
+ },
3158
+ /**
3159
+ * Dispatch the event on this {@link Container} using the event's {@link EventBoundary}.
3160
+ *
3161
+ * The target of the event is set to `this` and the `defaultPrevented` flag is cleared before dispatch.
3162
+ * @memberof scene.Container
3163
+ * @param e - The event to dispatch.
3164
+ * @returns Whether the {@link FederatedEvent.preventDefault preventDefault}() method was not invoked.
3165
+ * @example
3166
+ * // Reuse a click event!
3167
+ * button.dispatchEvent(clickEvent);
3168
+ */
3169
+ dispatchEvent(e) {
3170
+ if (!(e instanceof FederatedEvent)) {
3171
+ throw new Error("Container cannot propagate events outside of the Federated Events API");
3172
+ }
3173
+ e.defaultPrevented = false;
3174
+ e.path = null;
3175
+ e.target = this;
3176
+ e.manager.dispatchEvent(e);
3177
+ return !e.defaultPrevented;
3178
+ }
3179
+ };
3180
+
3181
+ extensions.add(AccessibilitySystem);
3182
+ extensions.mixin(Container, accessibilityTarget);
3183
+
3184
+ extensions.add(EventSystem);
3185
+ extensions.mixin(Container, FederatedContainer);
3186
+
3187
+ extensions.add(DOMPipe);