@annotorious/openseadragon 3.2.0 → 3.2.2

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.
@@ -1,2057 +0,0 @@
1
- import { P as m, r as J, E as P, T as S, U as Q, a as ee, w as y, e as D, C as Z } from "./index-Bxy_vBCw.js";
2
- import "./init-CxAUULxM.js";
3
- class w {
4
- /**
5
- * @param manager - The event boundary which manages this event. Propagation can only occur
6
- * within the boundary's jurisdiction.
7
- */
8
- constructor(e) {
9
- this.bubbles = !0, this.cancelBubble = !0, this.cancelable = !1, this.composed = !1, this.defaultPrevented = !1, this.eventPhase = w.prototype.NONE, this.propagationStopped = !1, this.propagationImmediatelyStopped = !1, this.layer = new m(), this.page = new m(), this.NONE = 0, this.CAPTURING_PHASE = 1, this.AT_TARGET = 2, this.BUBBLING_PHASE = 3, this.manager = e;
10
- }
11
- /** @readonly */
12
- get layerX() {
13
- return this.layer.x;
14
- }
15
- /** @readonly */
16
- get layerY() {
17
- return this.layer.y;
18
- }
19
- /** @readonly */
20
- get pageX() {
21
- return this.page.x;
22
- }
23
- /** @readonly */
24
- get pageY() {
25
- return this.page.y;
26
- }
27
- /**
28
- * Fallback for the deprecated @code{InteractionEvent.data}.
29
- * @deprecated since 7.0.0
30
- */
31
- get data() {
32
- return this;
33
- }
34
- /** The propagation path for this event. Alias for {@link EventBoundary.propagationPath}. */
35
- composedPath() {
36
- return this.manager && (!this.path || this.path[this.path.length - 1] !== this.target) && (this.path = this.target ? this.manager.propagationPath(this.target) : []), this.path;
37
- }
38
- /**
39
- * Unimplemented method included for implementing the DOM interface {@code Event}. It will throw an {@code Error}.
40
- * @deprecated
41
- * @param _type
42
- * @param _bubbles
43
- * @param _cancelable
44
- */
45
- initEvent(e, t, i) {
46
- throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
47
- }
48
- /**
49
- * Unimplemented method included for implementing the DOM interface {@code UIEvent}. It will throw an {@code Error}.
50
- * @deprecated
51
- * @param _typeArg
52
- * @param _bubblesArg
53
- * @param _cancelableArg
54
- * @param _viewArg
55
- * @param _detailArg
56
- */
57
- initUIEvent(e, t, i, n, s) {
58
- throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
59
- }
60
- /** Prevent default behavior of PixiJS and the user agent. */
61
- preventDefault() {
62
- this.nativeEvent instanceof Event && this.nativeEvent.cancelable && this.nativeEvent.preventDefault(), this.defaultPrevented = !0;
63
- }
64
- /**
65
- * Stop this event from propagating to any addition listeners, including on the
66
- * {@link FederatedEventTarget.currentTarget currentTarget} and also the following
67
- * event targets on the propagation path.
68
- */
69
- stopImmediatePropagation() {
70
- this.propagationImmediatelyStopped = !0;
71
- }
72
- /**
73
- * Stop this event from propagating to the next {@link FederatedEventTarget}. The rest of the listeners
74
- * on the {@link FederatedEventTarget.currentTarget currentTarget} will still be notified.
75
- */
76
- stopPropagation() {
77
- this.propagationStopped = !0;
78
- }
79
- }
80
- var I = /iPhone/i, C = /iPod/i, U = /iPad/i, R = /\biOS-universal(?:.+)Mac\b/i, k = /\bAndroid(?:.+)Mobile\b/i, X = /Android/i, b = /(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i, M = /Silk/i, g = /Windows Phone/i, F = /\bWindows(?:.+)ARM\b/i, Y = /BlackBerry/i, H = /BB10/i, N = /Opera Mini/i, K = /\b(CriOS|Chrome)(?:.+)Mobile/i, $ = /Mobile(?:.+)Firefox\b/i, j = function(a) {
81
- return typeof a < "u" && a.platform === "MacIntel" && typeof a.maxTouchPoints == "number" && a.maxTouchPoints > 1 && typeof MSStream > "u";
82
- };
83
- function te(a) {
84
- return function(e) {
85
- return e.test(a);
86
- };
87
- }
88
- function G(a) {
89
- var e = {
90
- userAgent: "",
91
- platform: "",
92
- maxTouchPoints: 0
93
- };
94
- !a && typeof navigator < "u" ? e = {
95
- userAgent: navigator.userAgent,
96
- platform: navigator.platform,
97
- maxTouchPoints: navigator.maxTouchPoints || 0
98
- } : typeof a == "string" ? e.userAgent = a : a && a.userAgent && (e = {
99
- userAgent: a.userAgent,
100
- platform: a.platform,
101
- maxTouchPoints: a.maxTouchPoints || 0
102
- });
103
- var t = e.userAgent, i = t.split("[FBAN");
104
- typeof i[1] < "u" && (t = i[0]), i = t.split("Twitter"), typeof i[1] < "u" && (t = i[0]);
105
- var n = te(t), s = {
106
- apple: {
107
- phone: n(I) && !n(g),
108
- ipod: n(C),
109
- tablet: !n(I) && (n(U) || j(e)) && !n(g),
110
- universal: n(R),
111
- device: (n(I) || n(C) || n(U) || n(R) || j(e)) && !n(g)
112
- },
113
- amazon: {
114
- phone: n(b),
115
- tablet: !n(b) && n(M),
116
- device: n(b) || n(M)
117
- },
118
- android: {
119
- phone: !n(g) && n(b) || !n(g) && n(k),
120
- tablet: !n(g) && !n(b) && !n(k) && (n(M) || n(X)),
121
- device: !n(g) && (n(b) || n(M) || n(k) || n(X)) || n(/\bokhttp\b/i)
122
- },
123
- windows: {
124
- phone: n(g),
125
- tablet: n(F),
126
- device: n(g) || n(F)
127
- },
128
- other: {
129
- blackberry: n(Y),
130
- blackberry10: n(H),
131
- opera: n(N),
132
- firefox: n($),
133
- chrome: n(K),
134
- device: n(Y) || n(H) || n(N) || n($) || n(K)
135
- },
136
- any: !1,
137
- phone: !1,
138
- tablet: !1
139
- };
140
- return s.any = s.apple.device || s.android.device || s.windows.device || s.other.device, s.phone = s.apple.phone || s.android.phone || s.windows.phone, s.tablet = s.apple.tablet || s.android.tablet || s.windows.tablet, s;
141
- }
142
- const ie = G.default ?? G, ne = ie(globalThis.navigator), se = 9, A = 100, oe = 0, re = 0, W = 2, z = 1, ae = -1e3, he = -1e3, le = 2, B = class V {
143
- // 2fps
144
- // eslint-disable-next-line jsdoc/require-param
145
- /**
146
- * @param {WebGLRenderer|WebGPURenderer} renderer - A reference to the current renderer
147
- */
148
- constructor(e, t = ne) {
149
- this._mobileInfo = t, this.debug = !1, this._activateOnTab = !0, this._deactivateOnMouseMove = !0, this._isActive = !1, this._isMobileAccessibility = !1, this._div = null, this._pool = [], this._renderId = 0, this._children = [], this._androidUpdateCount = 0, this._androidUpdateFrequency = 500, this._hookDiv = null, (t.tablet || t.phone) && this._createTouchHook(), this._renderer = e;
150
- }
151
- /**
152
- * Value of `true` if accessibility is currently active and accessibility layers are showing.
153
- * @member {boolean}
154
- * @readonly
155
- */
156
- get isActive() {
157
- return this._isActive;
158
- }
159
- /**
160
- * Value of `true` if accessibility is enabled for touch devices.
161
- * @member {boolean}
162
- * @readonly
163
- */
164
- get isMobileAccessibility() {
165
- return this._isMobileAccessibility;
166
- }
167
- get hookDiv() {
168
- return this._hookDiv;
169
- }
170
- /**
171
- * Creates the touch hooks.
172
- * @private
173
- */
174
- _createTouchHook() {
175
- const e = document.createElement("button");
176
- e.style.width = `${z}px`, e.style.height = `${z}px`, e.style.position = "absolute", e.style.top = `${ae}px`, e.style.left = `${he}px`, e.style.zIndex = le.toString(), e.style.backgroundColor = "#FF0000", e.title = "select to enable accessibility for this content", e.addEventListener("focus", () => {
177
- this._isMobileAccessibility = !0, this._activate(), this._destroyTouchHook();
178
- }), document.body.appendChild(e), this._hookDiv = e;
179
- }
180
- /**
181
- * Destroys the touch hooks.
182
- * @private
183
- */
184
- _destroyTouchHook() {
185
- this._hookDiv && (document.body.removeChild(this._hookDiv), this._hookDiv = null);
186
- }
187
- /**
188
- * Activating will cause the Accessibility layer to be shown.
189
- * This is called when a user presses the tab key.
190
- * @private
191
- */
192
- _activate() {
193
- if (this._isActive)
194
- return;
195
- this._isActive = !0, this._div || (this._div = document.createElement("div"), this._div.style.width = `${A}px`, this._div.style.height = `${A}px`, this._div.style.position = "absolute", this._div.style.top = `${oe}px`, this._div.style.left = `${re}px`, this._div.style.zIndex = W.toString(), this._div.style.pointerEvents = "none"), this._activateOnTab && (this._onKeyDown = this._onKeyDown.bind(this), globalThis.addEventListener("keydown", this._onKeyDown, !1)), this._deactivateOnMouseMove && (this._onMouseMove = this._onMouseMove.bind(this), globalThis.document.addEventListener("mousemove", this._onMouseMove, !0));
196
- const e = this._renderer.view.canvas;
197
- if (e.parentNode)
198
- e.parentNode.appendChild(this._div), this._initAccessibilitySetup();
199
- else {
200
- const t = new MutationObserver(() => {
201
- e.parentNode && (e.parentNode.appendChild(this._div), t.disconnect(), this._initAccessibilitySetup());
202
- });
203
- t.observe(document.body, { childList: !0, subtree: !0 });
204
- }
205
- }
206
- // New method to handle initialization after div is ready
207
- _initAccessibilitySetup() {
208
- this._renderer.runners.postrender.add(this), this._renderer.lastObjectRendered && this._updateAccessibleObjects(this._renderer.lastObjectRendered);
209
- }
210
- /**
211
- * Deactivates the accessibility system. Removes listeners and accessibility elements.
212
- * @private
213
- */
214
- _deactivate() {
215
- if (!(!this._isActive || this._isMobileAccessibility)) {
216
- this._isActive = !1, globalThis.document.removeEventListener("mousemove", this._onMouseMove, !0), this._activateOnTab && globalThis.addEventListener("keydown", this._onKeyDown, !1), this._renderer.runners.postrender.remove(this);
217
- for (const e of this._children)
218
- e._accessibleDiv && e._accessibleDiv.parentNode && (e._accessibleDiv.parentNode.removeChild(e._accessibleDiv), e._accessibleDiv = null), e._accessibleActive = !1;
219
- this._pool.forEach((e) => {
220
- e.parentNode && e.parentNode.removeChild(e);
221
- }), this._div && this._div.parentNode && this._div.parentNode.removeChild(this._div), this._pool = [], this._children = [];
222
- }
223
- }
224
- /**
225
- * This recursive function will run through the scene graph and add any new accessible objects to the DOM layer.
226
- * @private
227
- * @param {Container} container - The Container to check.
228
- */
229
- _updateAccessibleObjects(e) {
230
- if (!e.visible || !e.accessibleChildren)
231
- return;
232
- e.accessible && (e._accessibleActive || this._addChild(e), e._renderId = this._renderId);
233
- const t = e.children;
234
- if (t)
235
- for (let i = 0; i < t.length; i++)
236
- this._updateAccessibleObjects(t[i]);
237
- }
238
- /**
239
- * Runner init called, view is available at this point.
240
- * @ignore
241
- */
242
- init(e) {
243
- const i = {
244
- accessibilityOptions: {
245
- ...V.defaultOptions,
246
- ...(e == null ? void 0 : e.accessibilityOptions) || {}
247
- }
248
- };
249
- this.debug = i.accessibilityOptions.debug, this._activateOnTab = i.accessibilityOptions.activateOnTab, this._deactivateOnMouseMove = i.accessibilityOptions.deactivateOnMouseMove, i.accessibilityOptions.enabledByDefault ? this._activate() : this._activateOnTab && (this._onKeyDown = this._onKeyDown.bind(this), globalThis.addEventListener("keydown", this._onKeyDown, !1)), this._renderer.runners.postrender.remove(this);
250
- }
251
- /**
252
- * Updates the accessibility layer during rendering.
253
- * - Removes divs for containers no longer in the scene
254
- * - Updates the position and dimensions of the root div
255
- * - Updates positions of active accessibility divs
256
- * Only fires while the accessibility system is active.
257
- * @ignore
258
- */
259
- postrender() {
260
- const e = performance.now();
261
- if (this._mobileInfo.android.device && e < this._androidUpdateCount || (this._androidUpdateCount = e + this._androidUpdateFrequency, !this._renderer.renderingToScreen || !this._renderer.view.canvas))
262
- return;
263
- const t = /* @__PURE__ */ new Set();
264
- if (this._renderer.lastObjectRendered) {
265
- this._updateAccessibleObjects(this._renderer.lastObjectRendered);
266
- for (const i of this._children)
267
- i._renderId === this._renderId && t.add(this._children.indexOf(i));
268
- }
269
- for (let i = this._children.length - 1; i >= 0; i--) {
270
- const n = this._children[i];
271
- t.has(i) || (n._accessibleDiv && n._accessibleDiv.parentNode && (n._accessibleDiv.parentNode.removeChild(n._accessibleDiv), this._pool.push(n._accessibleDiv), n._accessibleDiv = null), n._accessibleActive = !1, J(this._children, i, 1));
272
- }
273
- if (this._renderer.renderingToScreen) {
274
- const { x: i, y: n, width: s, height: o } = this._renderer.screen, r = this._div;
275
- r.style.left = `${i}px`, r.style.top = `${n}px`, r.style.width = `${s}px`, r.style.height = `${o}px`;
276
- }
277
- for (let i = 0; i < this._children.length; i++) {
278
- const n = this._children[i];
279
- if (!n._accessibleActive || !n._accessibleDiv)
280
- continue;
281
- const s = n._accessibleDiv, o = n.hitArea || n.getBounds().rectangle;
282
- if (n.hitArea) {
283
- const r = n.worldTransform, l = this._renderer.resolution, u = this._renderer.resolution;
284
- s.style.left = `${(r.tx + o.x * r.a) * l}px`, s.style.top = `${(r.ty + o.y * r.d) * u}px`, s.style.width = `${o.width * r.a * l}px`, s.style.height = `${o.height * r.d * u}px`;
285
- } else {
286
- this._capHitArea(o);
287
- const r = this._renderer.resolution, l = this._renderer.resolution;
288
- s.style.left = `${o.x * r}px`, s.style.top = `${o.y * l}px`, s.style.width = `${o.width * r}px`, s.style.height = `${o.height * l}px`;
289
- }
290
- }
291
- this._renderId++;
292
- }
293
- /**
294
- * private function that will visually add the information to the
295
- * accessibility div
296
- * @param {HTMLElement} div -
297
- */
298
- _updateDebugHTML(e) {
299
- e.innerHTML = `type: ${e.type}</br> title : ${e.title}</br> tabIndex: ${e.tabIndex}`;
300
- }
301
- /**
302
- * Adjust the hit area based on the bounds of a display object
303
- * @param {Rectangle} hitArea - Bounds of the child
304
- */
305
- _capHitArea(e) {
306
- e.x < 0 && (e.width += e.x, e.x = 0), e.y < 0 && (e.height += e.y, e.y = 0);
307
- const { width: t, height: i } = this._renderer;
308
- e.x + e.width > t && (e.width = t - e.x), e.y + e.height > i && (e.height = i - e.y);
309
- }
310
- /**
311
- * Creates or reuses a div element for a Container and adds it to the accessibility layer.
312
- * Sets up ARIA attributes, event listeners, and positioning based on the container's properties.
313
- * @private
314
- * @param {Container} container - The child to make accessible.
315
- */
316
- _addChild(e) {
317
- let t = this._pool.pop();
318
- t || (e.accessibleType === "button" ? t = document.createElement("button") : (t = document.createElement(e.accessibleType), t.style.cssText = `
319
- color: transparent;
320
- pointer-events: none;
321
- padding: 0;
322
- margin: 0;
323
- border: 0;
324
- outline: 0;
325
- background: transparent;
326
- box-sizing: border-box;
327
- user-select: none;
328
- -webkit-user-select: none;
329
- -moz-user-select: none;
330
- -ms-user-select: none;
331
- `, e.accessibleText && (t.innerText = e.accessibleText)), t.style.width = `${A}px`, t.style.height = `${A}px`, t.style.backgroundColor = this.debug ? "rgba(255,255,255,0.5)" : "transparent", t.style.position = "absolute", t.style.zIndex = W.toString(), t.style.borderStyle = "none", navigator.userAgent.toLowerCase().includes("chrome") ? t.setAttribute("aria-live", "off") : t.setAttribute("aria-live", "polite"), navigator.userAgent.match(/rv:.*Gecko\//) ? t.setAttribute("aria-relevant", "additions") : t.setAttribute("aria-relevant", "text"), t.addEventListener("click", this._onClick.bind(this)), t.addEventListener("focus", this._onFocus.bind(this)), t.addEventListener("focusout", this._onFocusOut.bind(this))), t.style.pointerEvents = e.accessiblePointerEvents, t.type = e.accessibleType, e.accessibleTitle && e.accessibleTitle !== null ? t.title = e.accessibleTitle : (!e.accessibleHint || e.accessibleHint === null) && (t.title = `container ${e.tabIndex}`), e.accessibleHint && e.accessibleHint !== null && t.setAttribute("aria-label", e.accessibleHint), this.debug && this._updateDebugHTML(t), e._accessibleActive = !0, e._accessibleDiv = t, t.container = e, this._children.push(e), this._div.appendChild(e._accessibleDiv), e.interactive && (e._accessibleDiv.tabIndex = e.tabIndex);
332
- }
333
- /**
334
- * Dispatch events with the EventSystem.
335
- * @param e
336
- * @param type
337
- * @private
338
- */
339
- _dispatchEvent(e, t) {
340
- const { container: i } = e.target, n = this._renderer.events.rootBoundary, s = Object.assign(new w(n), { target: i });
341
- n.rootTarget = this._renderer.lastObjectRendered, t.forEach((o) => n.dispatchEvent(s, o));
342
- }
343
- /**
344
- * Maps the div button press to pixi's EventSystem (click)
345
- * @private
346
- * @param {MouseEvent} e - The click event.
347
- */
348
- _onClick(e) {
349
- this._dispatchEvent(e, ["click", "pointertap", "tap"]);
350
- }
351
- /**
352
- * Maps the div focus events to pixi's EventSystem (mouseover)
353
- * @private
354
- * @param {FocusEvent} e - The focus event.
355
- */
356
- _onFocus(e) {
357
- e.target.getAttribute("aria-live") || e.target.setAttribute("aria-live", "assertive"), this._dispatchEvent(e, ["mouseover"]);
358
- }
359
- /**
360
- * Maps the div focus events to pixi's EventSystem (mouseout)
361
- * @private
362
- * @param {FocusEvent} e - The focusout event.
363
- */
364
- _onFocusOut(e) {
365
- e.target.getAttribute("aria-live") || e.target.setAttribute("aria-live", "polite"), this._dispatchEvent(e, ["mouseout"]);
366
- }
367
- /**
368
- * Is called when a key is pressed
369
- * @private
370
- * @param {KeyboardEvent} e - The keydown event.
371
- */
372
- _onKeyDown(e) {
373
- e.keyCode !== se || !this._activateOnTab || this._activate();
374
- }
375
- /**
376
- * Is called when the mouse moves across the renderer element
377
- * @private
378
- * @param {MouseEvent} e - The mouse event.
379
- */
380
- _onMouseMove(e) {
381
- e.movementX === 0 && e.movementY === 0 || this._deactivate();
382
- }
383
- /** Destroys the accessibility system. Removes all elements and listeners. */
384
- destroy() {
385
- this._deactivate(), this._destroyTouchHook(), this._div = null, this._pool = null, this._children = null, this._renderer = null, this._activateOnTab && globalThis.removeEventListener("keydown", this._onKeyDown);
386
- }
387
- /**
388
- * Enables or disables the accessibility system.
389
- * @param enabled - Whether to enable or disable accessibility.
390
- */
391
- setAccessibilityEnabled(e) {
392
- e ? this._activate() : this._deactivate();
393
- }
394
- };
395
- B.extension = {
396
- type: [
397
- P.WebGLSystem,
398
- P.WebGPUSystem
399
- ],
400
- name: "accessibility"
401
- };
402
- B.defaultOptions = {
403
- /**
404
- * Whether to enable accessibility features on initialization
405
- * @default false
406
- */
407
- enabledByDefault: !1,
408
- /**
409
- * Whether to visually show the accessibility divs for debugging
410
- * @default false
411
- */
412
- debug: !1,
413
- /**
414
- * Whether to activate accessibility when tab key is pressed
415
- * @default true
416
- */
417
- activateOnTab: !0,
418
- /**
419
- * Whether to deactivate accessibility when mouse moves
420
- * @default true
421
- */
422
- deactivateOnMouseMove: !0
423
- };
424
- let ce = B;
425
- const de = {
426
- /**
427
- * Flag for if the object is accessible. If true AccessibilityManager will overlay a
428
- * shadow div with attributes set
429
- * @member {boolean}
430
- * @memberof scene.Container#
431
- */
432
- accessible: !1,
433
- /**
434
- * Sets the title attribute of the shadow div
435
- * If accessibleTitle AND accessibleHint has not been this will default to 'container [tabIndex]'
436
- * @member {string}
437
- * @memberof scene.Container#
438
- */
439
- accessibleTitle: null,
440
- /**
441
- * Sets the aria-label attribute of the shadow div
442
- * @member {string}
443
- * @memberof scene.Container#
444
- */
445
- accessibleHint: null,
446
- /**
447
- * @member {number}
448
- * @memberof scene.Container#
449
- * @todo Needs docs.
450
- */
451
- tabIndex: 0,
452
- /**
453
- * @member {boolean}
454
- * @memberof scene.Container#
455
- * @private
456
- */
457
- _accessibleActive: !1,
458
- /**
459
- * @memberof scene.Container#
460
- * @private
461
- */
462
- _accessibleDiv: null,
463
- /**
464
- * Specify the type of div the accessible layer is. Screen readers treat the element differently
465
- * depending on this type. Defaults to button.
466
- * @member {string}
467
- * @memberof scene.Container#
468
- * @default 'button'
469
- */
470
- accessibleType: "button",
471
- /**
472
- * Sets the text content of the shadow div
473
- * @member {string}
474
- * @memberof scene.Container#
475
- */
476
- accessibleText: null,
477
- /**
478
- * Specify the pointer-events the accessible div will use
479
- * Defaults to auto.
480
- * @type {PointerEvents}
481
- * @memberof scene.Container#
482
- * @default 'auto'
483
- */
484
- accessiblePointerEvents: "auto",
485
- /**
486
- * Setting to false will prevent any children inside this container to
487
- * be accessible. Defaults to true.
488
- * @member {boolean}
489
- * @memberof scene.Container#
490
- * @default true
491
- */
492
- accessibleChildren: !0,
493
- /**
494
- * @member {number}
495
- * @memberof scene.Container#
496
- * @private
497
- */
498
- _renderId: -1
499
- };
500
- class ue {
501
- constructor() {
502
- this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this._tickerAdded = !1, this._pauseUpdate = !0;
503
- }
504
- /**
505
- * Initializes the event ticker.
506
- * @param events - The event system.
507
- */
508
- init(e) {
509
- this.removeTickerListener(), this.events = e, this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this._tickerAdded = !1, this._pauseUpdate = !0;
510
- }
511
- /** Whether to pause the update checks or not. */
512
- get pauseUpdate() {
513
- return this._pauseUpdate;
514
- }
515
- set pauseUpdate(e) {
516
- this._pauseUpdate = e;
517
- }
518
- /** Adds the ticker listener. */
519
- addTickerListener() {
520
- this._tickerAdded || !this.domElement || (S.system.add(this._tickerUpdate, this, Q.INTERACTION), this._tickerAdded = !0);
521
- }
522
- /** Removes the ticker listener. */
523
- removeTickerListener() {
524
- this._tickerAdded && (S.system.remove(this._tickerUpdate, this), this._tickerAdded = !1);
525
- }
526
- /** Sets flag to not fire extra events when the user has already moved there mouse */
527
- pointerMoved() {
528
- this._didMove = !0;
529
- }
530
- /** Updates the state of interactive objects. */
531
- _update() {
532
- if (!this.domElement || this._pauseUpdate)
533
- return;
534
- if (this._didMove) {
535
- this._didMove = !1;
536
- return;
537
- }
538
- const e = this.events._rootPointerEvent;
539
- this.events.supportsTouchEvents && e.pointerType === "touch" || globalThis.document.dispatchEvent(new PointerEvent("pointermove", {
540
- clientX: e.clientX,
541
- clientY: e.clientY,
542
- pointerType: e.pointerType,
543
- pointerId: e.pointerId
544
- }));
545
- }
546
- /**
547
- * Updates the state of interactive objects if at least {@link interactionFrequency}
548
- * milliseconds have passed since the last invocation.
549
- *
550
- * Invoked by a throttled ticker update from {@link Ticker.system}.
551
- * @param ticker - The throttled ticker.
552
- */
553
- _tickerUpdate(e) {
554
- this._deltaTime += e.deltaTime, !(this._deltaTime < this.interactionFrequency) && (this._deltaTime = 0, this._update());
555
- }
556
- }
557
- const _ = new ue();
558
- class O extends w {
559
- constructor() {
560
- super(...arguments), this.client = new m(), this.movement = new m(), this.offset = new m(), this.global = new m(), this.screen = new m();
561
- }
562
- /** @readonly */
563
- get clientX() {
564
- return this.client.x;
565
- }
566
- /** @readonly */
567
- get clientY() {
568
- return this.client.y;
569
- }
570
- /**
571
- * Alias for {@link FederatedMouseEvent.clientX this.clientX}.
572
- * @readonly
573
- */
574
- get x() {
575
- return this.clientX;
576
- }
577
- /**
578
- * Alias for {@link FederatedMouseEvent.clientY this.clientY}.
579
- * @readonly
580
- */
581
- get y() {
582
- return this.clientY;
583
- }
584
- /** @readonly */
585
- get movementX() {
586
- return this.movement.x;
587
- }
588
- /** @readonly */
589
- get movementY() {
590
- return this.movement.y;
591
- }
592
- /** @readonly */
593
- get offsetX() {
594
- return this.offset.x;
595
- }
596
- /** @readonly */
597
- get offsetY() {
598
- return this.offset.y;
599
- }
600
- /** @readonly */
601
- get globalX() {
602
- return this.global.x;
603
- }
604
- /** @readonly */
605
- get globalY() {
606
- return this.global.y;
607
- }
608
- /**
609
- * The pointer coordinates in the renderer's screen. Alias for {@code screen.x}.
610
- * @readonly
611
- */
612
- get screenX() {
613
- return this.screen.x;
614
- }
615
- /**
616
- * The pointer coordinates in the renderer's screen. Alias for {@code screen.y}.
617
- * @readonly
618
- */
619
- get screenY() {
620
- return this.screen.y;
621
- }
622
- /**
623
- * This will return the local coordinates of the specified container for this InteractionData
624
- * @param {Container} container - The Container that you would like the local
625
- * coords off
626
- * @param {PointData} point - A Point object in which to store the value, optional (otherwise
627
- * will create a new point)
628
- * @param {PointData} globalPos - A Point object containing your custom global coords, optional
629
- * (otherwise will use the current global coords)
630
- * @returns - A point containing the coordinates of the InteractionData position relative
631
- * to the Container
632
- */
633
- getLocalPosition(e, t, i) {
634
- return e.worldTransform.applyInverse(i || this.global, t);
635
- }
636
- /**
637
- * Whether the modifier key was pressed when this event natively occurred.
638
- * @param key - The modifier key.
639
- */
640
- getModifierState(e) {
641
- return "getModifierState" in this.nativeEvent && this.nativeEvent.getModifierState(e);
642
- }
643
- /**
644
- * Not supported.
645
- * @param _typeArg
646
- * @param _canBubbleArg
647
- * @param _cancelableArg
648
- * @param _viewArg
649
- * @param _detailArg
650
- * @param _screenXArg
651
- * @param _screenYArg
652
- * @param _clientXArg
653
- * @param _clientYArg
654
- * @param _ctrlKeyArg
655
- * @param _altKeyArg
656
- * @param _shiftKeyArg
657
- * @param _metaKeyArg
658
- * @param _buttonArg
659
- * @param _relatedTargetArg
660
- * @deprecated since 7.0.0
661
- */
662
- // eslint-disable-next-line max-params
663
- initMouseEvent(e, t, i, n, s, o, r, l, u, p, d, h, v, c, _e) {
664
- throw new Error("Method not implemented.");
665
- }
666
- }
667
- class f extends O {
668
- constructor() {
669
- super(...arguments), this.width = 0, this.height = 0, this.isPrimary = !1;
670
- }
671
- // Only included for completeness for now
672
- getCoalescedEvents() {
673
- return this.type === "pointermove" || this.type === "mousemove" || this.type === "touchmove" ? [this] : [];
674
- }
675
- // Only included for completeness for now
676
- getPredictedEvents() {
677
- throw new Error("getPredictedEvents is not supported!");
678
- }
679
- }
680
- class E extends O {
681
- constructor() {
682
- super(...arguments), this.DOM_DELTA_PIXEL = 0, this.DOM_DELTA_LINE = 1, this.DOM_DELTA_PAGE = 2;
683
- }
684
- }
685
- E.DOM_DELTA_PIXEL = 0;
686
- E.DOM_DELTA_LINE = 1;
687
- E.DOM_DELTA_PAGE = 2;
688
- const pe = 2048, ve = new m(), T = new m();
689
- class fe {
690
- /**
691
- * @param rootTarget - The holder of the event boundary.
692
- */
693
- constructor(e) {
694
- this.dispatch = new ee(), this.moveOnAll = !1, this.enableGlobalMoveEvents = !0, this.mappingState = {
695
- trackingData: {}
696
- }, this.eventPool = /* @__PURE__ */ new Map(), this._allInteractiveElements = [], this._hitElements = [], this._isPointerMoveEvent = !1, this.rootTarget = e, this.hitPruneFn = this.hitPruneFn.bind(this), this.hitTestFn = this.hitTestFn.bind(this), this.mapPointerDown = this.mapPointerDown.bind(this), this.mapPointerMove = this.mapPointerMove.bind(this), this.mapPointerOut = this.mapPointerOut.bind(this), this.mapPointerOver = this.mapPointerOver.bind(this), this.mapPointerUp = this.mapPointerUp.bind(this), this.mapPointerUpOutside = this.mapPointerUpOutside.bind(this), this.mapWheel = this.mapWheel.bind(this), this.mappingTable = {}, this.addEventMapping("pointerdown", this.mapPointerDown), this.addEventMapping("pointermove", this.mapPointerMove), this.addEventMapping("pointerout", this.mapPointerOut), this.addEventMapping("pointerleave", this.mapPointerOut), this.addEventMapping("pointerover", this.mapPointerOver), this.addEventMapping("pointerup", this.mapPointerUp), this.addEventMapping("pointerupoutside", this.mapPointerUpOutside), this.addEventMapping("wheel", this.mapWheel);
697
- }
698
- /**
699
- * Adds an event mapping for the event `type` handled by `fn`.
700
- *
701
- * Event mappings can be used to implement additional or custom events. They take an event
702
- * coming from the upstream scene (or directly from the {@link EventSystem}) and dispatch new downstream events
703
- * generally trickling down and bubbling up to {@link EventBoundary.rootTarget this.rootTarget}.
704
- *
705
- * To modify the semantics of existing events, the built-in mapping methods of EventBoundary should be overridden
706
- * instead.
707
- * @param type - The type of upstream event to map.
708
- * @param fn - The mapping method. The context of this function must be bound manually, if desired.
709
- */
710
- addEventMapping(e, t) {
711
- this.mappingTable[e] || (this.mappingTable[e] = []), this.mappingTable[e].push({
712
- fn: t,
713
- priority: 0
714
- }), this.mappingTable[e].sort((i, n) => i.priority - n.priority);
715
- }
716
- /**
717
- * Dispatches the given event
718
- * @param e - The event to dispatch.
719
- * @param type - The type of event to dispatch. Defaults to `e.type`.
720
- */
721
- dispatchEvent(e, t) {
722
- e.propagationStopped = !1, e.propagationImmediatelyStopped = !1, this.propagate(e, t), this.dispatch.emit(t || e.type, e);
723
- }
724
- /**
725
- * Maps the given upstream event through the event boundary and propagates it downstream.
726
- * @param e - The event to map.
727
- */
728
- mapEvent(e) {
729
- if (!this.rootTarget)
730
- return;
731
- const t = this.mappingTable[e.type];
732
- if (t)
733
- for (let i = 0, n = t.length; i < n; i++)
734
- t[i].fn(e);
735
- else
736
- y(`[EventBoundary]: Event mapping not defined for ${e.type}`);
737
- }
738
- /**
739
- * Finds the Container that is the target of a event at the given coordinates.
740
- *
741
- * The passed (x,y) coordinates are in the world space above this event boundary.
742
- * @param x - The x coordinate of the event.
743
- * @param y - The y coordinate of the event.
744
- */
745
- hitTest(e, t) {
746
- _.pauseUpdate = !0;
747
- const n = this._isPointerMoveEvent && this.enableGlobalMoveEvents ? "hitTestMoveRecursive" : "hitTestRecursive", s = this[n](
748
- this.rootTarget,
749
- this.rootTarget.eventMode,
750
- ve.set(e, t),
751
- this.hitTestFn,
752
- this.hitPruneFn
753
- );
754
- return s && s[0];
755
- }
756
- /**
757
- * Propagate the passed event from from {@link EventBoundary.rootTarget this.rootTarget} to its
758
- * target {@code e.target}.
759
- * @param e - The event to propagate.
760
- * @param type - The type of event to propagate. Defaults to `e.type`.
761
- */
762
- propagate(e, t) {
763
- if (!e.target)
764
- return;
765
- const i = e.composedPath();
766
- e.eventPhase = e.CAPTURING_PHASE;
767
- for (let n = 0, s = i.length - 1; n < s; n++)
768
- if (e.currentTarget = i[n], this.notifyTarget(e, t), e.propagationStopped || e.propagationImmediatelyStopped)
769
- return;
770
- if (e.eventPhase = e.AT_TARGET, e.currentTarget = e.target, this.notifyTarget(e, t), !(e.propagationStopped || e.propagationImmediatelyStopped)) {
771
- e.eventPhase = e.BUBBLING_PHASE;
772
- for (let n = i.length - 2; n >= 0; n--)
773
- if (e.currentTarget = i[n], this.notifyTarget(e, t), e.propagationStopped || e.propagationImmediatelyStopped)
774
- return;
775
- }
776
- }
777
- /**
778
- * Emits the event {@code e} to all interactive containers. The event is propagated in the bubbling phase always.
779
- *
780
- * This is used in the `globalpointermove` event.
781
- * @param e - The emitted event.
782
- * @param type - The listeners to notify.
783
- * @param targets - The targets to notify.
784
- */
785
- all(e, t, i = this._allInteractiveElements) {
786
- if (i.length === 0)
787
- return;
788
- e.eventPhase = e.BUBBLING_PHASE;
789
- const n = Array.isArray(t) ? t : [t];
790
- for (let s = i.length - 1; s >= 0; s--)
791
- n.forEach((o) => {
792
- e.currentTarget = i[s], this.notifyTarget(e, o);
793
- });
794
- }
795
- /**
796
- * Finds the propagation path from {@link EventBoundary.rootTarget rootTarget} to the passed
797
- * {@code target}. The last element in the path is {@code target}.
798
- * @param target - The target to find the propagation path to.
799
- */
800
- propagationPath(e) {
801
- const t = [e];
802
- for (let i = 0; i < pe && e !== this.rootTarget && e.parent; i++) {
803
- if (!e.parent)
804
- throw new Error("Cannot find propagation path to disconnected target");
805
- t.push(e.parent), e = e.parent;
806
- }
807
- return t.reverse(), t;
808
- }
809
- hitTestMoveRecursive(e, t, i, n, s, o = !1) {
810
- let r = !1;
811
- if (this._interactivePrune(e))
812
- return null;
813
- if ((e.eventMode === "dynamic" || t === "dynamic") && (_.pauseUpdate = !1), e.interactiveChildren && e.children) {
814
- const p = e.children;
815
- for (let d = p.length - 1; d >= 0; d--) {
816
- const h = p[d], v = this.hitTestMoveRecursive(
817
- h,
818
- this._isInteractive(t) ? t : h.eventMode,
819
- i,
820
- n,
821
- s,
822
- o || s(e, i)
823
- );
824
- if (v) {
825
- if (v.length > 0 && !v[v.length - 1].parent)
826
- continue;
827
- const c = e.isInteractive();
828
- (v.length > 0 || c) && (c && this._allInteractiveElements.push(e), v.push(e)), this._hitElements.length === 0 && (this._hitElements = v), r = !0;
829
- }
830
- }
831
- }
832
- const l = this._isInteractive(t), u = e.isInteractive();
833
- return u && u && this._allInteractiveElements.push(e), o || this._hitElements.length > 0 ? null : r ? this._hitElements : l && !s(e, i) && n(e, i) ? u ? [e] : [] : null;
834
- }
835
- /**
836
- * Recursive implementation for {@link EventBoundary.hitTest hitTest}.
837
- * @param currentTarget - The Container that is to be hit tested.
838
- * @param eventMode - The event mode for the `currentTarget` or one of its parents.
839
- * @param location - The location that is being tested for overlap.
840
- * @param testFn - Callback that determines whether the target passes hit testing. This callback
841
- * can assume that `pruneFn` failed to prune the container.
842
- * @param pruneFn - Callback that determiness whether the target and all of its children
843
- * cannot pass the hit test. It is used as a preliminary optimization to prune entire subtrees
844
- * of the scene graph.
845
- * @returns An array holding the hit testing target and all its ancestors in order. The first element
846
- * is the target itself and the last is {@link EventBoundary.rootTarget rootTarget}. This is the opposite
847
- * order w.r.t. the propagation path. If no hit testing target is found, null is returned.
848
- */
849
- hitTestRecursive(e, t, i, n, s) {
850
- if (this._interactivePrune(e) || s(e, i))
851
- return null;
852
- if ((e.eventMode === "dynamic" || t === "dynamic") && (_.pauseUpdate = !1), e.interactiveChildren && e.children) {
853
- const l = e.children, u = i;
854
- for (let p = l.length - 1; p >= 0; p--) {
855
- const d = l[p], h = this.hitTestRecursive(
856
- d,
857
- this._isInteractive(t) ? t : d.eventMode,
858
- u,
859
- n,
860
- s
861
- );
862
- if (h) {
863
- if (h.length > 0 && !h[h.length - 1].parent)
864
- continue;
865
- const v = e.isInteractive();
866
- return (h.length > 0 || v) && h.push(e), h;
867
- }
868
- }
869
- }
870
- const o = this._isInteractive(t), r = e.isInteractive();
871
- return o && n(e, i) ? r ? [e] : [] : null;
872
- }
873
- _isInteractive(e) {
874
- return e === "static" || e === "dynamic";
875
- }
876
- _interactivePrune(e) {
877
- return !e || !e.visible || !e.renderable || !e.measurable || e.eventMode === "none" || e.eventMode === "passive" && !e.interactiveChildren;
878
- }
879
- /**
880
- * Checks whether the container or any of its children cannot pass the hit test at all.
881
- *
882
- * {@link EventBoundary}'s implementation uses the {@link Container.hitArea hitArea}
883
- * and {@link Container._maskEffect} for pruning.
884
- * @param container - The container to prune.
885
- * @param location - The location to test for overlap.
886
- */
887
- hitPruneFn(e, t) {
888
- if (e.hitArea && (e.worldTransform.applyInverse(t, T), !e.hitArea.contains(T.x, T.y)))
889
- return !0;
890
- if (e.effects && e.effects.length)
891
- for (let i = 0; i < e.effects.length; i++) {
892
- const n = e.effects[i];
893
- if (n.containsPoint && !n.containsPoint(t, this.hitTestFn))
894
- return !0;
895
- }
896
- return !1;
897
- }
898
- /**
899
- * Checks whether the container passes hit testing for the given location.
900
- * @param container - The container to test.
901
- * @param location - The location to test for overlap.
902
- * @returns - Whether `container` passes hit testing for `location`.
903
- */
904
- hitTestFn(e, t) {
905
- return e.hitArea ? !0 : e != null && e.containsPoint ? (e.worldTransform.applyInverse(t, T), e.containsPoint(T)) : !1;
906
- }
907
- /**
908
- * Notify all the listeners to the event's `currentTarget`.
909
- *
910
- * If the `currentTarget` contains the property `on<type>`, then it is called here,
911
- * simulating the behavior from version 6.x and prior.
912
- * @param e - The event passed to the target.
913
- * @param type - The type of event to notify. Defaults to `e.type`.
914
- */
915
- notifyTarget(e, t) {
916
- var s, o;
917
- if (!e.currentTarget.isInteractive())
918
- return;
919
- t ?? (t = e.type);
920
- const i = `on${t}`;
921
- (o = (s = e.currentTarget)[i]) == null || o.call(s, e);
922
- const n = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${t}capture` : t;
923
- this._notifyListeners(e, n), e.eventPhase === e.AT_TARGET && this._notifyListeners(e, t);
924
- }
925
- /**
926
- * Maps the upstream `pointerdown` events to a downstream `pointerdown` event.
927
- *
928
- * `touchstart`, `rightdown`, `mousedown` events are also dispatched for specific pointer types.
929
- * @param from - The upstream `pointerdown` event.
930
- */
931
- mapPointerDown(e) {
932
- if (!(e instanceof f)) {
933
- y("EventBoundary cannot map a non-pointer event as a pointer event");
934
- return;
935
- }
936
- const t = this.createPointerEvent(e);
937
- if (this.dispatchEvent(t, "pointerdown"), t.pointerType === "touch")
938
- this.dispatchEvent(t, "touchstart");
939
- else if (t.pointerType === "mouse" || t.pointerType === "pen") {
940
- const n = t.button === 2;
941
- this.dispatchEvent(t, n ? "rightdown" : "mousedown");
942
- }
943
- const i = this.trackingData(e.pointerId);
944
- i.pressTargetsByButton[e.button] = t.composedPath(), this.freeEvent(t);
945
- }
946
- /**
947
- * Maps the upstream `pointermove` to downstream `pointerout`, `pointerover`, and `pointermove` events, in that order.
948
- *
949
- * The tracking data for the specific pointer has an updated `overTarget`. `mouseout`, `mouseover`,
950
- * `mousemove`, and `touchmove` events are fired as well for specific pointer types.
951
- * @param from - The upstream `pointermove` event.
952
- */
953
- mapPointerMove(e) {
954
- var l, u;
955
- if (!(e instanceof f)) {
956
- y("EventBoundary cannot map a non-pointer event as a pointer event");
957
- return;
958
- }
959
- this._allInteractiveElements.length = 0, this._hitElements.length = 0, this._isPointerMoveEvent = !0;
960
- const t = this.createPointerEvent(e);
961
- this._isPointerMoveEvent = !1;
962
- const i = t.pointerType === "mouse" || t.pointerType === "pen", n = this.trackingData(e.pointerId), s = this.findMountedTarget(n.overTargets);
963
- if (((l = n.overTargets) == null ? void 0 : l.length) > 0 && s !== t.target) {
964
- const p = e.type === "mousemove" ? "mouseout" : "pointerout", d = this.createPointerEvent(e, p, s);
965
- if (this.dispatchEvent(d, "pointerout"), i && this.dispatchEvent(d, "mouseout"), !t.composedPath().includes(s)) {
966
- const h = this.createPointerEvent(e, "pointerleave", s);
967
- for (h.eventPhase = h.AT_TARGET; h.target && !t.composedPath().includes(h.target); )
968
- h.currentTarget = h.target, this.notifyTarget(h), i && this.notifyTarget(h, "mouseleave"), h.target = h.target.parent;
969
- this.freeEvent(h);
970
- }
971
- this.freeEvent(d);
972
- }
973
- if (s !== t.target) {
974
- const p = e.type === "mousemove" ? "mouseover" : "pointerover", d = this.clonePointerEvent(t, p);
975
- this.dispatchEvent(d, "pointerover"), i && this.dispatchEvent(d, "mouseover");
976
- let h = s == null ? void 0 : s.parent;
977
- for (; h && h !== this.rootTarget.parent && h !== t.target; )
978
- h = h.parent;
979
- if (!h || h === this.rootTarget.parent) {
980
- const c = this.clonePointerEvent(t, "pointerenter");
981
- for (c.eventPhase = c.AT_TARGET; c.target && c.target !== s && c.target !== this.rootTarget.parent; )
982
- c.currentTarget = c.target, this.notifyTarget(c), i && this.notifyTarget(c, "mouseenter"), c.target = c.target.parent;
983
- this.freeEvent(c);
984
- }
985
- this.freeEvent(d);
986
- }
987
- const o = [], r = this.enableGlobalMoveEvents ?? !0;
988
- this.moveOnAll ? o.push("pointermove") : this.dispatchEvent(t, "pointermove"), r && o.push("globalpointermove"), t.pointerType === "touch" && (this.moveOnAll ? o.splice(1, 0, "touchmove") : this.dispatchEvent(t, "touchmove"), r && o.push("globaltouchmove")), i && (this.moveOnAll ? o.splice(1, 0, "mousemove") : this.dispatchEvent(t, "mousemove"), r && o.push("globalmousemove"), this.cursor = (u = t.target) == null ? void 0 : u.cursor), o.length > 0 && this.all(t, o), this._allInteractiveElements.length = 0, this._hitElements.length = 0, n.overTargets = t.composedPath(), this.freeEvent(t);
989
- }
990
- /**
991
- * Maps the upstream `pointerover` to downstream `pointerover` and `pointerenter` events, in that order.
992
- *
993
- * The tracking data for the specific pointer gets a new `overTarget`.
994
- * @param from - The upstream `pointerover` event.
995
- */
996
- mapPointerOver(e) {
997
- var o;
998
- if (!(e instanceof f)) {
999
- y("EventBoundary cannot map a non-pointer event as a pointer event");
1000
- return;
1001
- }
1002
- const t = this.trackingData(e.pointerId), i = this.createPointerEvent(e), n = i.pointerType === "mouse" || i.pointerType === "pen";
1003
- this.dispatchEvent(i, "pointerover"), n && this.dispatchEvent(i, "mouseover"), i.pointerType === "mouse" && (this.cursor = (o = i.target) == null ? void 0 : o.cursor);
1004
- const s = this.clonePointerEvent(i, "pointerenter");
1005
- for (s.eventPhase = s.AT_TARGET; s.target && s.target !== this.rootTarget.parent; )
1006
- s.currentTarget = s.target, this.notifyTarget(s), n && this.notifyTarget(s, "mouseenter"), s.target = s.target.parent;
1007
- t.overTargets = i.composedPath(), this.freeEvent(i), this.freeEvent(s);
1008
- }
1009
- /**
1010
- * Maps the upstream `pointerout` to downstream `pointerout`, `pointerleave` events, in that order.
1011
- *
1012
- * The tracking data for the specific pointer is cleared of a `overTarget`.
1013
- * @param from - The upstream `pointerout` event.
1014
- */
1015
- mapPointerOut(e) {
1016
- if (!(e instanceof f)) {
1017
- y("EventBoundary cannot map a non-pointer event as a pointer event");
1018
- return;
1019
- }
1020
- const t = this.trackingData(e.pointerId);
1021
- if (t.overTargets) {
1022
- const i = e.pointerType === "mouse" || e.pointerType === "pen", n = this.findMountedTarget(t.overTargets), s = this.createPointerEvent(e, "pointerout", n);
1023
- this.dispatchEvent(s), i && this.dispatchEvent(s, "mouseout");
1024
- const o = this.createPointerEvent(e, "pointerleave", n);
1025
- for (o.eventPhase = o.AT_TARGET; o.target && o.target !== this.rootTarget.parent; )
1026
- o.currentTarget = o.target, this.notifyTarget(o), i && this.notifyTarget(o, "mouseleave"), o.target = o.target.parent;
1027
- t.overTargets = null, this.freeEvent(s), this.freeEvent(o);
1028
- }
1029
- this.cursor = null;
1030
- }
1031
- /**
1032
- * Maps the upstream `pointerup` event to downstream `pointerup`, `pointerupoutside`,
1033
- * and `click`/`rightclick`/`pointertap` events, in that order.
1034
- *
1035
- * The `pointerupoutside` event bubbles from the original `pointerdown` target to the most specific
1036
- * ancestor of the `pointerdown` and `pointerup` targets, which is also the `click` event's target. `touchend`,
1037
- * `rightup`, `mouseup`, `touchendoutside`, `rightupoutside`, `mouseupoutside`, and `tap` are fired as well for
1038
- * specific pointer types.
1039
- * @param from - The upstream `pointerup` event.
1040
- */
1041
- mapPointerUp(e) {
1042
- if (!(e instanceof f)) {
1043
- y("EventBoundary cannot map a non-pointer event as a pointer event");
1044
- return;
1045
- }
1046
- const t = performance.now(), i = this.createPointerEvent(e);
1047
- if (this.dispatchEvent(i, "pointerup"), i.pointerType === "touch")
1048
- this.dispatchEvent(i, "touchend");
1049
- else if (i.pointerType === "mouse" || i.pointerType === "pen") {
1050
- const r = i.button === 2;
1051
- this.dispatchEvent(i, r ? "rightup" : "mouseup");
1052
- }
1053
- const n = this.trackingData(e.pointerId), s = this.findMountedTarget(n.pressTargetsByButton[e.button]);
1054
- let o = s;
1055
- if (s && !i.composedPath().includes(s)) {
1056
- let r = s;
1057
- for (; r && !i.composedPath().includes(r); ) {
1058
- if (i.currentTarget = r, this.notifyTarget(i, "pointerupoutside"), i.pointerType === "touch")
1059
- this.notifyTarget(i, "touchendoutside");
1060
- else if (i.pointerType === "mouse" || i.pointerType === "pen") {
1061
- const l = i.button === 2;
1062
- this.notifyTarget(i, l ? "rightupoutside" : "mouseupoutside");
1063
- }
1064
- r = r.parent;
1065
- }
1066
- delete n.pressTargetsByButton[e.button], o = r;
1067
- }
1068
- if (o) {
1069
- const r = this.clonePointerEvent(i, "click");
1070
- r.target = o, r.path = null, n.clicksByButton[e.button] || (n.clicksByButton[e.button] = {
1071
- clickCount: 0,
1072
- target: r.target,
1073
- timeStamp: t
1074
- });
1075
- const l = n.clicksByButton[e.button];
1076
- if (l.target === r.target && t - l.timeStamp < 200 ? ++l.clickCount : l.clickCount = 1, l.target = r.target, l.timeStamp = t, r.detail = l.clickCount, r.pointerType === "mouse") {
1077
- const u = r.button === 2;
1078
- this.dispatchEvent(r, u ? "rightclick" : "click");
1079
- } else r.pointerType === "touch" && this.dispatchEvent(r, "tap");
1080
- this.dispatchEvent(r, "pointertap"), this.freeEvent(r);
1081
- }
1082
- this.freeEvent(i);
1083
- }
1084
- /**
1085
- * Maps the upstream `pointerupoutside` event to a downstream `pointerupoutside` event, bubbling from the original
1086
- * `pointerdown` target to `rootTarget`.
1087
- *
1088
- * (The most specific ancestor of the `pointerdown` event and the `pointerup` event must the
1089
- * `{@link EventBoundary}'s root because the `pointerup` event occurred outside of the boundary.)
1090
- *
1091
- * `touchendoutside`, `mouseupoutside`, and `rightupoutside` events are fired as well for specific pointer
1092
- * types. The tracking data for the specific pointer is cleared of a `pressTarget`.
1093
- * @param from - The upstream `pointerupoutside` event.
1094
- */
1095
- mapPointerUpOutside(e) {
1096
- if (!(e instanceof f)) {
1097
- y("EventBoundary cannot map a non-pointer event as a pointer event");
1098
- return;
1099
- }
1100
- const t = this.trackingData(e.pointerId), i = this.findMountedTarget(t.pressTargetsByButton[e.button]), n = this.createPointerEvent(e);
1101
- if (i) {
1102
- let s = i;
1103
- for (; s; )
1104
- n.currentTarget = s, this.notifyTarget(n, "pointerupoutside"), n.pointerType === "touch" ? this.notifyTarget(n, "touchendoutside") : (n.pointerType === "mouse" || n.pointerType === "pen") && this.notifyTarget(n, n.button === 2 ? "rightupoutside" : "mouseupoutside"), s = s.parent;
1105
- delete t.pressTargetsByButton[e.button];
1106
- }
1107
- this.freeEvent(n);
1108
- }
1109
- /**
1110
- * Maps the upstream `wheel` event to a downstream `wheel` event.
1111
- * @param from - The upstream `wheel` event.
1112
- */
1113
- mapWheel(e) {
1114
- if (!(e instanceof E)) {
1115
- y("EventBoundary cannot map a non-wheel event as a wheel event");
1116
- return;
1117
- }
1118
- const t = this.createWheelEvent(e);
1119
- this.dispatchEvent(t), this.freeEvent(t);
1120
- }
1121
- /**
1122
- * Finds the most specific event-target in the given propagation path that is still mounted in the scene graph.
1123
- *
1124
- * This is used to find the correct `pointerup` and `pointerout` target in the case that the original `pointerdown`
1125
- * or `pointerover` target was unmounted from the scene graph.
1126
- * @param propagationPath - The propagation path was valid in the past.
1127
- * @returns - The most specific event-target still mounted at the same location in the scene graph.
1128
- */
1129
- findMountedTarget(e) {
1130
- if (!e)
1131
- return null;
1132
- let t = e[0];
1133
- for (let i = 1; i < e.length && e[i].parent === t; i++)
1134
- t = e[i];
1135
- return t;
1136
- }
1137
- /**
1138
- * Creates an event whose {@code originalEvent} is {@code from}, with an optional `type` and `target` override.
1139
- *
1140
- * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1141
- * @param from - The {@code originalEvent} for the returned event.
1142
- * @param [type=from.type] - The type of the returned event.
1143
- * @param target - The target of the returned event.
1144
- */
1145
- createPointerEvent(e, t, i) {
1146
- const n = this.allocateEvent(f);
1147
- return this.copyPointerData(e, n), this.copyMouseData(e, n), this.copyData(e, n), n.nativeEvent = e.nativeEvent, n.originalEvent = e, n.target = i ?? this.hitTest(n.global.x, n.global.y) ?? this._hitElements[0], typeof t == "string" && (n.type = t), n;
1148
- }
1149
- /**
1150
- * Creates a wheel event whose {@code originalEvent} is {@code from}.
1151
- *
1152
- * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1153
- * @param from - The upstream wheel event.
1154
- */
1155
- createWheelEvent(e) {
1156
- const t = this.allocateEvent(E);
1157
- return this.copyWheelData(e, t), this.copyMouseData(e, t), this.copyData(e, t), t.nativeEvent = e.nativeEvent, t.originalEvent = e, t.target = this.hitTest(t.global.x, t.global.y), t;
1158
- }
1159
- /**
1160
- * Clones the event {@code from}, with an optional {@code type} override.
1161
- *
1162
- * The event is allocated using {@link EventBoundary#allocateEvent this.allocateEvent}.
1163
- * @param from - The event to clone.
1164
- * @param [type=from.type] - The type of the returned event.
1165
- */
1166
- clonePointerEvent(e, t) {
1167
- const i = this.allocateEvent(f);
1168
- return i.nativeEvent = e.nativeEvent, i.originalEvent = e.originalEvent, this.copyPointerData(e, i), this.copyMouseData(e, i), this.copyData(e, i), i.target = e.target, i.path = e.composedPath().slice(), i.type = t ?? i.type, i;
1169
- }
1170
- /**
1171
- * Copies wheel {@link FederatedWheelEvent} data from {@code from} into {@code to}.
1172
- *
1173
- * The following properties are copied:
1174
- * + deltaMode
1175
- * + deltaX
1176
- * + deltaY
1177
- * + deltaZ
1178
- * @param from - The event to copy data from.
1179
- * @param to - The event to copy data into.
1180
- */
1181
- copyWheelData(e, t) {
1182
- t.deltaMode = e.deltaMode, t.deltaX = e.deltaX, t.deltaY = e.deltaY, t.deltaZ = e.deltaZ;
1183
- }
1184
- /**
1185
- * Copies pointer {@link FederatedPointerEvent} data from {@code from} into {@code to}.
1186
- *
1187
- * The following properties are copied:
1188
- * + pointerId
1189
- * + width
1190
- * + height
1191
- * + isPrimary
1192
- * + pointerType
1193
- * + pressure
1194
- * + tangentialPressure
1195
- * + tiltX
1196
- * + tiltY
1197
- * @param from - The event to copy data from.
1198
- * @param to - The event to copy data into.
1199
- */
1200
- copyPointerData(e, t) {
1201
- e instanceof f && t instanceof f && (t.pointerId = e.pointerId, t.width = e.width, t.height = e.height, t.isPrimary = e.isPrimary, t.pointerType = e.pointerType, t.pressure = e.pressure, t.tangentialPressure = e.tangentialPressure, t.tiltX = e.tiltX, t.tiltY = e.tiltY, t.twist = e.twist);
1202
- }
1203
- /**
1204
- * Copies mouse {@link FederatedMouseEvent} data from {@code from} to {@code to}.
1205
- *
1206
- * The following properties are copied:
1207
- * + altKey
1208
- * + button
1209
- * + buttons
1210
- * + clientX
1211
- * + clientY
1212
- * + metaKey
1213
- * + movementX
1214
- * + movementY
1215
- * + pageX
1216
- * + pageY
1217
- * + x
1218
- * + y
1219
- * + screen
1220
- * + shiftKey
1221
- * + global
1222
- * @param from - The event to copy data from.
1223
- * @param to - The event to copy data into.
1224
- */
1225
- copyMouseData(e, t) {
1226
- e instanceof O && t instanceof O && (t.altKey = e.altKey, t.button = e.button, t.buttons = e.buttons, t.client.copyFrom(e.client), t.ctrlKey = e.ctrlKey, t.metaKey = e.metaKey, t.movement.copyFrom(e.movement), t.screen.copyFrom(e.screen), t.shiftKey = e.shiftKey, t.global.copyFrom(e.global));
1227
- }
1228
- /**
1229
- * Copies base {@link FederatedEvent} data from {@code from} into {@code to}.
1230
- *
1231
- * The following properties are copied:
1232
- * + isTrusted
1233
- * + srcElement
1234
- * + timeStamp
1235
- * + type
1236
- * @param from - The event to copy data from.
1237
- * @param to - The event to copy data into.
1238
- */
1239
- copyData(e, t) {
1240
- t.isTrusted = e.isTrusted, t.srcElement = e.srcElement, t.timeStamp = performance.now(), t.type = e.type, t.detail = e.detail, t.view = e.view, t.which = e.which, t.layer.copyFrom(e.layer), t.page.copyFrom(e.page);
1241
- }
1242
- /**
1243
- * @param id - The pointer ID.
1244
- * @returns The tracking data stored for the given pointer. If no data exists, a blank
1245
- * state will be created.
1246
- */
1247
- trackingData(e) {
1248
- return this.mappingState.trackingData[e] || (this.mappingState.trackingData[e] = {
1249
- pressTargetsByButton: {},
1250
- clicksByButton: {},
1251
- overTarget: null
1252
- }), this.mappingState.trackingData[e];
1253
- }
1254
- /**
1255
- * Allocate a specific type of event from {@link EventBoundary#eventPool this.eventPool}.
1256
- *
1257
- * This allocation is constructor-agnostic, as long as it only takes one argument - this event
1258
- * boundary.
1259
- * @param constructor - The event's constructor.
1260
- */
1261
- allocateEvent(e) {
1262
- this.eventPool.has(e) || this.eventPool.set(e, []);
1263
- const t = this.eventPool.get(e).pop() || new e(this);
1264
- return t.eventPhase = t.NONE, t.currentTarget = null, t.defaultPrevented = !1, t.path = null, t.target = null, t;
1265
- }
1266
- /**
1267
- * Frees the event and puts it back into the event pool.
1268
- *
1269
- * It is illegal to reuse the event until it is allocated again, using `this.allocateEvent`.
1270
- *
1271
- * It is also advised that events not allocated from {@link EventBoundary#allocateEvent this.allocateEvent}
1272
- * not be freed. This is because of the possibility that the same event is freed twice, which can cause
1273
- * it to be allocated twice & result in overwriting.
1274
- * @param event - The event to be freed.
1275
- * @throws Error if the event is managed by another event boundary.
1276
- */
1277
- freeEvent(e) {
1278
- if (e.manager !== this)
1279
- throw new Error("It is illegal to free an event not managed by this EventBoundary!");
1280
- const t = e.constructor;
1281
- this.eventPool.has(t) || this.eventPool.set(t, []), this.eventPool.get(t).push(e);
1282
- }
1283
- /**
1284
- * Similar to {@link EventEmitter.emit}, except it stops if the `propagationImmediatelyStopped` flag
1285
- * is set on the event.
1286
- * @param e - The event to call each listener with.
1287
- * @param type - The event key.
1288
- */
1289
- _notifyListeners(e, t) {
1290
- const i = e.currentTarget._events[t];
1291
- if (i)
1292
- if ("fn" in i)
1293
- i.once && e.currentTarget.removeListener(t, i.fn, void 0, !0), i.fn.call(i.context, e);
1294
- else
1295
- for (let n = 0, s = i.length; n < s && !e.propagationImmediatelyStopped; n++)
1296
- i[n].once && e.currentTarget.removeListener(t, i[n].fn, void 0, !0), i[n].fn.call(i[n].context, e);
1297
- }
1298
- }
1299
- const ge = 1, me = {
1300
- touchstart: "pointerdown",
1301
- touchend: "pointerup",
1302
- touchendoutside: "pointerupoutside",
1303
- touchmove: "pointermove",
1304
- touchcancel: "pointercancel"
1305
- }, L = class x {
1306
- /**
1307
- * @param {Renderer} renderer
1308
- */
1309
- constructor(e) {
1310
- this.supportsTouchEvents = "ontouchstart" in globalThis, this.supportsPointerEvents = !!globalThis.PointerEvent, this.domElement = null, this.resolution = 1, this.renderer = e, this.rootBoundary = new fe(null), _.init(this), this.autoPreventDefault = !0, this._eventsAdded = !1, this._rootPointerEvent = new f(null), this._rootWheelEvent = new E(null), this.cursorStyles = {
1311
- default: "inherit",
1312
- pointer: "pointer"
1313
- }, this.features = new Proxy({ ...x.defaultEventFeatures }, {
1314
- set: (t, i, n) => (i === "globalMove" && (this.rootBoundary.enableGlobalMoveEvents = n), t[i] = n, !0)
1315
- }), this._onPointerDown = this._onPointerDown.bind(this), this._onPointerMove = this._onPointerMove.bind(this), this._onPointerUp = this._onPointerUp.bind(this), this._onPointerOverOut = this._onPointerOverOut.bind(this), this.onWheel = this.onWheel.bind(this);
1316
- }
1317
- /**
1318
- * The default interaction mode for all display objects.
1319
- * @see Container.eventMode
1320
- * @type {EventMode}
1321
- * @readonly
1322
- * @since 7.2.0
1323
- */
1324
- static get defaultEventMode() {
1325
- return this._defaultEventMode;
1326
- }
1327
- /**
1328
- * Runner init called, view is available at this point.
1329
- * @ignore
1330
- */
1331
- init(e) {
1332
- const { canvas: t, resolution: i } = this.renderer;
1333
- this.setTargetElement(t), this.resolution = i, x._defaultEventMode = e.eventMode ?? "passive", Object.assign(this.features, e.eventFeatures ?? {}), this.rootBoundary.enableGlobalMoveEvents = this.features.globalMove;
1334
- }
1335
- /**
1336
- * Handle changing resolution.
1337
- * @ignore
1338
- */
1339
- resolutionChange(e) {
1340
- this.resolution = e;
1341
- }
1342
- /** Destroys all event listeners and detaches the renderer. */
1343
- destroy() {
1344
- this.setTargetElement(null), this.renderer = null, this._currentCursor = null;
1345
- }
1346
- /**
1347
- * Sets the current cursor mode, handling any callbacks or CSS style changes.
1348
- * @param mode - cursor mode, a key from the cursorStyles dictionary
1349
- */
1350
- setCursor(e) {
1351
- e || (e = "default");
1352
- let t = !0;
1353
- if (globalThis.OffscreenCanvas && this.domElement instanceof OffscreenCanvas && (t = !1), this._currentCursor === e)
1354
- return;
1355
- this._currentCursor = e;
1356
- const i = this.cursorStyles[e];
1357
- if (i)
1358
- switch (typeof i) {
1359
- case "string":
1360
- t && (this.domElement.style.cursor = i);
1361
- break;
1362
- case "function":
1363
- i(e);
1364
- break;
1365
- case "object":
1366
- t && Object.assign(this.domElement.style, i);
1367
- break;
1368
- }
1369
- else t && typeof e == "string" && !Object.prototype.hasOwnProperty.call(this.cursorStyles, e) && (this.domElement.style.cursor = e);
1370
- }
1371
- /**
1372
- * The global pointer event.
1373
- * Useful for getting the pointer position without listening to events.
1374
- * @since 7.2.0
1375
- */
1376
- get pointer() {
1377
- return this._rootPointerEvent;
1378
- }
1379
- /**
1380
- * Event handler for pointer down events on {@link EventSystem#domElement this.domElement}.
1381
- * @param nativeEvent - The native mouse/pointer/touch event.
1382
- */
1383
- _onPointerDown(e) {
1384
- if (!this.features.click)
1385
- return;
1386
- this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
1387
- const t = this._normalizeToPointerData(e);
1388
- this.autoPreventDefault && t[0].isNormalized && (e.cancelable || !("cancelable" in e)) && e.preventDefault();
1389
- for (let i = 0, n = t.length; i < n; i++) {
1390
- const s = t[i], o = this._bootstrapEvent(this._rootPointerEvent, s);
1391
- this.rootBoundary.mapEvent(o);
1392
- }
1393
- this.setCursor(this.rootBoundary.cursor);
1394
- }
1395
- /**
1396
- * Event handler for pointer move events on on {@link EventSystem#domElement this.domElement}.
1397
- * @param nativeEvent - The native mouse/pointer/touch events.
1398
- */
1399
- _onPointerMove(e) {
1400
- if (!this.features.move)
1401
- return;
1402
- this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, _.pointerMoved();
1403
- const t = this._normalizeToPointerData(e);
1404
- for (let i = 0, n = t.length; i < n; i++) {
1405
- const s = this._bootstrapEvent(this._rootPointerEvent, t[i]);
1406
- this.rootBoundary.mapEvent(s);
1407
- }
1408
- this.setCursor(this.rootBoundary.cursor);
1409
- }
1410
- /**
1411
- * Event handler for pointer up events on {@link EventSystem#domElement this.domElement}.
1412
- * @param nativeEvent - The native mouse/pointer/touch event.
1413
- */
1414
- _onPointerUp(e) {
1415
- if (!this.features.click)
1416
- return;
1417
- this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
1418
- let t = e.target;
1419
- e.composedPath && e.composedPath().length > 0 && (t = e.composedPath()[0]);
1420
- const i = t !== this.domElement ? "outside" : "", n = this._normalizeToPointerData(e);
1421
- for (let s = 0, o = n.length; s < o; s++) {
1422
- const r = this._bootstrapEvent(this._rootPointerEvent, n[s]);
1423
- r.type += i, this.rootBoundary.mapEvent(r);
1424
- }
1425
- this.setCursor(this.rootBoundary.cursor);
1426
- }
1427
- /**
1428
- * Event handler for pointer over & out events on {@link EventSystem#domElement this.domElement}.
1429
- * @param nativeEvent - The native mouse/pointer/touch event.
1430
- */
1431
- _onPointerOverOut(e) {
1432
- if (!this.features.click)
1433
- return;
1434
- this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
1435
- const t = this._normalizeToPointerData(e);
1436
- for (let i = 0, n = t.length; i < n; i++) {
1437
- const s = this._bootstrapEvent(this._rootPointerEvent, t[i]);
1438
- this.rootBoundary.mapEvent(s);
1439
- }
1440
- this.setCursor(this.rootBoundary.cursor);
1441
- }
1442
- /**
1443
- * Passive handler for `wheel` events on {@link EventSystem.domElement this.domElement}.
1444
- * @param nativeEvent - The native wheel event.
1445
- */
1446
- onWheel(e) {
1447
- if (!this.features.wheel)
1448
- return;
1449
- const t = this.normalizeWheelEvent(e);
1450
- this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, this.rootBoundary.mapEvent(t);
1451
- }
1452
- /**
1453
- * Sets the {@link EventSystem#domElement domElement} and binds event listeners.
1454
- *
1455
- * To deregister the current DOM element without setting a new one, pass {@code null}.
1456
- * @param element - The new DOM element.
1457
- */
1458
- setTargetElement(e) {
1459
- this._removeEvents(), this.domElement = e, _.domElement = e, this._addEvents();
1460
- }
1461
- /** Register event listeners on {@link Renderer#domElement this.domElement}. */
1462
- _addEvents() {
1463
- if (this._eventsAdded || !this.domElement)
1464
- return;
1465
- _.addTickerListener();
1466
- const e = this.domElement.style;
1467
- e && (globalThis.navigator.msPointerEnabled ? (e.msContentZooming = "none", e.msTouchAction = "none") : this.supportsPointerEvents && (e.touchAction = "none")), this.supportsPointerEvents ? (globalThis.document.addEventListener("pointermove", this._onPointerMove, !0), this.domElement.addEventListener("pointerdown", this._onPointerDown, !0), this.domElement.addEventListener("pointerleave", this._onPointerOverOut, !0), this.domElement.addEventListener("pointerover", this._onPointerOverOut, !0), globalThis.addEventListener("pointerup", this._onPointerUp, !0)) : (globalThis.document.addEventListener("mousemove", this._onPointerMove, !0), this.domElement.addEventListener("mousedown", this._onPointerDown, !0), this.domElement.addEventListener("mouseout", this._onPointerOverOut, !0), this.domElement.addEventListener("mouseover", this._onPointerOverOut, !0), globalThis.addEventListener("mouseup", this._onPointerUp, !0), this.supportsTouchEvents && (this.domElement.addEventListener("touchstart", this._onPointerDown, !0), this.domElement.addEventListener("touchend", this._onPointerUp, !0), this.domElement.addEventListener("touchmove", this._onPointerMove, !0))), this.domElement.addEventListener("wheel", this.onWheel, {
1468
- passive: !0,
1469
- capture: !0
1470
- }), this._eventsAdded = !0;
1471
- }
1472
- /** Unregister event listeners on {@link EventSystem#domElement this.domElement}. */
1473
- _removeEvents() {
1474
- if (!this._eventsAdded || !this.domElement)
1475
- return;
1476
- _.removeTickerListener();
1477
- const e = this.domElement.style;
1478
- e && (globalThis.navigator.msPointerEnabled ? (e.msContentZooming = "", e.msTouchAction = "") : this.supportsPointerEvents && (e.touchAction = "")), this.supportsPointerEvents ? (globalThis.document.removeEventListener("pointermove", this._onPointerMove, !0), this.domElement.removeEventListener("pointerdown", this._onPointerDown, !0), this.domElement.removeEventListener("pointerleave", this._onPointerOverOut, !0), this.domElement.removeEventListener("pointerover", this._onPointerOverOut, !0), globalThis.removeEventListener("pointerup", this._onPointerUp, !0)) : (globalThis.document.removeEventListener("mousemove", this._onPointerMove, !0), this.domElement.removeEventListener("mousedown", this._onPointerDown, !0), this.domElement.removeEventListener("mouseout", this._onPointerOverOut, !0), this.domElement.removeEventListener("mouseover", this._onPointerOverOut, !0), globalThis.removeEventListener("mouseup", this._onPointerUp, !0), this.supportsTouchEvents && (this.domElement.removeEventListener("touchstart", this._onPointerDown, !0), this.domElement.removeEventListener("touchend", this._onPointerUp, !0), this.domElement.removeEventListener("touchmove", this._onPointerMove, !0))), this.domElement.removeEventListener("wheel", this.onWheel, !0), this.domElement = null, this._eventsAdded = !1;
1479
- }
1480
- /**
1481
- * Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
1482
- * resulting value is stored in the point. This takes into account the fact that the DOM
1483
- * element could be scaled and positioned anywhere on the screen.
1484
- * @param {PointData} point - the point that the result will be stored in
1485
- * @param {number} x - the x coord of the position to map
1486
- * @param {number} y - the y coord of the position to map
1487
- */
1488
- mapPositionToPoint(e, t, i) {
1489
- const n = this.domElement.isConnected ? this.domElement.getBoundingClientRect() : {
1490
- width: this.domElement.width,
1491
- height: this.domElement.height,
1492
- left: 0,
1493
- top: 0
1494
- }, s = 1 / this.resolution;
1495
- e.x = (t - n.left) * (this.domElement.width / n.width) * s, e.y = (i - n.top) * (this.domElement.height / n.height) * s;
1496
- }
1497
- /**
1498
- * Ensures that the original event object contains all data that a regular pointer event would have
1499
- * @param event - The original event data from a touch or mouse event
1500
- * @returns An array containing a single normalized pointer event, in the case of a pointer
1501
- * or mouse event, or a multiple normalized pointer events if there are multiple changed touches
1502
- */
1503
- _normalizeToPointerData(e) {
1504
- const t = [];
1505
- if (this.supportsTouchEvents && e instanceof TouchEvent)
1506
- for (let i = 0, n = e.changedTouches.length; i < n; i++) {
1507
- const s = e.changedTouches[i];
1508
- typeof s.button > "u" && (s.button = 0), typeof s.buttons > "u" && (s.buttons = 1), typeof s.isPrimary > "u" && (s.isPrimary = e.touches.length === 1 && e.type === "touchstart"), typeof s.width > "u" && (s.width = s.radiusX || 1), typeof s.height > "u" && (s.height = s.radiusY || 1), typeof s.tiltX > "u" && (s.tiltX = 0), typeof s.tiltY > "u" && (s.tiltY = 0), typeof s.pointerType > "u" && (s.pointerType = "touch"), typeof s.pointerId > "u" && (s.pointerId = s.identifier || 0), typeof s.pressure > "u" && (s.pressure = s.force || 0.5), typeof s.twist > "u" && (s.twist = 0), typeof s.tangentialPressure > "u" && (s.tangentialPressure = 0), typeof s.layerX > "u" && (s.layerX = s.offsetX = s.clientX), typeof s.layerY > "u" && (s.layerY = s.offsetY = s.clientY), s.isNormalized = !0, s.type = e.type, t.push(s);
1509
- }
1510
- else if (!globalThis.MouseEvent || e instanceof MouseEvent && (!this.supportsPointerEvents || !(e instanceof globalThis.PointerEvent))) {
1511
- const i = e;
1512
- typeof i.isPrimary > "u" && (i.isPrimary = !0), typeof i.width > "u" && (i.width = 1), typeof i.height > "u" && (i.height = 1), typeof i.tiltX > "u" && (i.tiltX = 0), typeof i.tiltY > "u" && (i.tiltY = 0), typeof i.pointerType > "u" && (i.pointerType = "mouse"), typeof i.pointerId > "u" && (i.pointerId = ge), typeof i.pressure > "u" && (i.pressure = 0.5), typeof i.twist > "u" && (i.twist = 0), typeof i.tangentialPressure > "u" && (i.tangentialPressure = 0), i.isNormalized = !0, t.push(i);
1513
- } else
1514
- t.push(e);
1515
- return t;
1516
- }
1517
- /**
1518
- * Normalizes the native {@link https://w3c.github.io/uievents/#interface-wheelevent WheelEvent}.
1519
- *
1520
- * The returned {@link FederatedWheelEvent} is a shared instance. It will not persist across
1521
- * multiple native wheel events.
1522
- * @param nativeEvent - The native wheel event that occurred on the canvas.
1523
- * @returns A federated wheel event.
1524
- */
1525
- normalizeWheelEvent(e) {
1526
- const t = this._rootWheelEvent;
1527
- return this._transferMouseData(t, e), t.deltaX = e.deltaX, t.deltaY = e.deltaY, t.deltaZ = e.deltaZ, t.deltaMode = e.deltaMode, this.mapPositionToPoint(t.screen, e.clientX, e.clientY), t.global.copyFrom(t.screen), t.offset.copyFrom(t.screen), t.nativeEvent = e, t.type = e.type, t;
1528
- }
1529
- /**
1530
- * Normalizes the `nativeEvent` into a federateed {@link FederatedPointerEvent}.
1531
- * @param event
1532
- * @param nativeEvent
1533
- */
1534
- _bootstrapEvent(e, t) {
1535
- return e.originalEvent = null, e.nativeEvent = t, e.pointerId = t.pointerId, e.width = t.width, e.height = t.height, e.isPrimary = t.isPrimary, e.pointerType = t.pointerType, e.pressure = t.pressure, e.tangentialPressure = t.tangentialPressure, e.tiltX = t.tiltX, e.tiltY = t.tiltY, e.twist = t.twist, this._transferMouseData(e, t), this.mapPositionToPoint(e.screen, t.clientX, t.clientY), e.global.copyFrom(e.screen), e.offset.copyFrom(e.screen), e.isTrusted = t.isTrusted, e.type === "pointerleave" && (e.type = "pointerout"), e.type.startsWith("mouse") && (e.type = e.type.replace("mouse", "pointer")), e.type.startsWith("touch") && (e.type = me[e.type] || e.type), e;
1536
- }
1537
- /**
1538
- * Transfers base & mouse event data from the {@code nativeEvent} to the federated event.
1539
- * @param event
1540
- * @param nativeEvent
1541
- */
1542
- _transferMouseData(e, t) {
1543
- e.isTrusted = t.isTrusted, e.srcElement = t.srcElement, e.timeStamp = performance.now(), e.type = t.type, e.altKey = t.altKey, e.button = t.button, e.buttons = t.buttons, e.client.x = t.clientX, e.client.y = t.clientY, e.ctrlKey = t.ctrlKey, e.metaKey = t.metaKey, e.movement.x = t.movementX, e.movement.y = t.movementY, e.page.x = t.pageX, e.page.y = t.pageY, e.relatedTarget = null, e.shiftKey = t.shiftKey;
1544
- }
1545
- };
1546
- L.extension = {
1547
- name: "events",
1548
- type: [
1549
- P.WebGLSystem,
1550
- P.CanvasSystem,
1551
- P.WebGPUSystem
1552
- ],
1553
- priority: -1
1554
- };
1555
- L.defaultEventFeatures = {
1556
- /** Enables pointer events associated with pointer movement. */
1557
- move: !0,
1558
- /** Enables global pointer move events. */
1559
- globalMove: !0,
1560
- /** Enables pointer events associated with clicking. */
1561
- click: !0,
1562
- /** Enables wheel events. */
1563
- wheel: !0
1564
- };
1565
- let q = L;
1566
- const ye = {
1567
- /**
1568
- * Property-based event handler for the `click` event.
1569
- * @memberof scene.Container#
1570
- * @default null
1571
- * @example
1572
- * this.onclick = (event) => {
1573
- * //some function here that happens on click
1574
- * }
1575
- */
1576
- onclick: null,
1577
- /**
1578
- * Property-based event handler for the `mousedown` event.
1579
- * @memberof scene.Container#
1580
- * @default null
1581
- * @example
1582
- * this.onmousedown = (event) => {
1583
- * //some function here that happens on mousedown
1584
- * }
1585
- */
1586
- onmousedown: null,
1587
- /**
1588
- * Property-based event handler for the `mouseenter` event.
1589
- * @memberof scene.Container#
1590
- * @default null
1591
- * @example
1592
- * this.onmouseenter = (event) => {
1593
- * //some function here that happens on mouseenter
1594
- * }
1595
- */
1596
- onmouseenter: null,
1597
- /**
1598
- * Property-based event handler for the `mouseleave` event.
1599
- * @memberof scene.Container#
1600
- * @default null
1601
- * @example
1602
- * this.onmouseleave = (event) => {
1603
- * //some function here that happens on mouseleave
1604
- * }
1605
- */
1606
- onmouseleave: null,
1607
- /**
1608
- * Property-based event handler for the `mousemove` event.
1609
- * @memberof scene.Container#
1610
- * @default null
1611
- * @example
1612
- * this.onmousemove = (event) => {
1613
- * //some function here that happens on mousemove
1614
- * }
1615
- */
1616
- onmousemove: null,
1617
- /**
1618
- * Property-based event handler for the `globalmousemove` event.
1619
- * @memberof scene.Container#
1620
- * @default null
1621
- * @example
1622
- * this.onglobalmousemove = (event) => {
1623
- * //some function here that happens on globalmousemove
1624
- * }
1625
- */
1626
- onglobalmousemove: null,
1627
- /**
1628
- * Property-based event handler for the `mouseout` event.
1629
- * @memberof scene.Container#
1630
- * @default null
1631
- * @example
1632
- * this.onmouseout = (event) => {
1633
- * //some function here that happens on mouseout
1634
- * }
1635
- */
1636
- onmouseout: null,
1637
- /**
1638
- * Property-based event handler for the `mouseover` event.
1639
- * @memberof scene.Container#
1640
- * @default null
1641
- * @example
1642
- * this.onmouseover = (event) => {
1643
- * //some function here that happens on mouseover
1644
- * }
1645
- */
1646
- onmouseover: null,
1647
- /**
1648
- * Property-based event handler for the `mouseup` event.
1649
- * @memberof scene.Container#
1650
- * @default null
1651
- * @example
1652
- * this.onmouseup = (event) => {
1653
- * //some function here that happens on mouseup
1654
- * }
1655
- */
1656
- onmouseup: null,
1657
- /**
1658
- * Property-based event handler for the `mouseupoutside` event.
1659
- * @memberof scene.Container#
1660
- * @default null
1661
- * @example
1662
- * this.onmouseupoutside = (event) => {
1663
- * //some function here that happens on mouseupoutside
1664
- * }
1665
- */
1666
- onmouseupoutside: null,
1667
- /**
1668
- * Property-based event handler for the `pointercancel` event.
1669
- * @memberof scene.Container#
1670
- * @default null
1671
- * @example
1672
- * this.onpointercancel = (event) => {
1673
- * //some function here that happens on pointercancel
1674
- * }
1675
- */
1676
- onpointercancel: null,
1677
- /**
1678
- * Property-based event handler for the `pointerdown` event.
1679
- * @memberof scene.Container#
1680
- * @default null
1681
- * @example
1682
- * this.onpointerdown = (event) => {
1683
- * //some function here that happens on pointerdown
1684
- * }
1685
- */
1686
- onpointerdown: null,
1687
- /**
1688
- * Property-based event handler for the `pointerenter` event.
1689
- * @memberof scene.Container#
1690
- * @default null
1691
- * @example
1692
- * this.onpointerenter = (event) => {
1693
- * //some function here that happens on pointerenter
1694
- * }
1695
- */
1696
- onpointerenter: null,
1697
- /**
1698
- * Property-based event handler for the `pointerleave` event.
1699
- * @memberof scene.Container#
1700
- * @default null
1701
- * @example
1702
- * this.onpointerleave = (event) => {
1703
- * //some function here that happens on pointerleave
1704
- * }
1705
- */
1706
- onpointerleave: null,
1707
- /**
1708
- * Property-based event handler for the `pointermove` event.
1709
- * @memberof scene.Container#
1710
- * @default null
1711
- * @example
1712
- * this.onpointermove = (event) => {
1713
- * //some function here that happens on pointermove
1714
- * }
1715
- */
1716
- onpointermove: null,
1717
- /**
1718
- * Property-based event handler for the `globalpointermove` event.
1719
- * @memberof scene.Container#
1720
- * @default null
1721
- * @example
1722
- * this.onglobalpointermove = (event) => {
1723
- * //some function here that happens on globalpointermove
1724
- * }
1725
- */
1726
- onglobalpointermove: null,
1727
- /**
1728
- * Property-based event handler for the `pointerout` event.
1729
- * @memberof scene.Container#
1730
- * @default null
1731
- * @example
1732
- * this.onpointerout = (event) => {
1733
- * //some function here that happens on pointerout
1734
- * }
1735
- */
1736
- onpointerout: null,
1737
- /**
1738
- * Property-based event handler for the `pointerover` event.
1739
- * @memberof scene.Container#
1740
- * @default null
1741
- * @example
1742
- * this.onpointerover = (event) => {
1743
- * //some function here that happens on pointerover
1744
- * }
1745
- */
1746
- onpointerover: null,
1747
- /**
1748
- * Property-based event handler for the `pointertap` event.
1749
- * @memberof scene.Container#
1750
- * @default null
1751
- * @example
1752
- * this.onpointertap = (event) => {
1753
- * //some function here that happens on pointertap
1754
- * }
1755
- */
1756
- onpointertap: null,
1757
- /**
1758
- * Property-based event handler for the `pointerup` event.
1759
- * @memberof scene.Container#
1760
- * @default null
1761
- * @example
1762
- * this.onpointerup = (event) => {
1763
- * //some function here that happens on pointerup
1764
- * }
1765
- */
1766
- onpointerup: null,
1767
- /**
1768
- * Property-based event handler for the `pointerupoutside` event.
1769
- * @memberof scene.Container#
1770
- * @default null
1771
- * @example
1772
- * this.onpointerupoutside = (event) => {
1773
- * //some function here that happens on pointerupoutside
1774
- * }
1775
- */
1776
- onpointerupoutside: null,
1777
- /**
1778
- * Property-based event handler for the `rightclick` event.
1779
- * @memberof scene.Container#
1780
- * @default null
1781
- * @example
1782
- * this.onrightclick = (event) => {
1783
- * //some function here that happens on rightclick
1784
- * }
1785
- */
1786
- onrightclick: null,
1787
- /**
1788
- * Property-based event handler for the `rightdown` event.
1789
- * @memberof scene.Container#
1790
- * @default null
1791
- * @example
1792
- * this.onrightdown = (event) => {
1793
- * //some function here that happens on rightdown
1794
- * }
1795
- */
1796
- onrightdown: null,
1797
- /**
1798
- * Property-based event handler for the `rightup` event.
1799
- * @memberof scene.Container#
1800
- * @default null
1801
- * @example
1802
- * this.onrightup = (event) => {
1803
- * //some function here that happens on rightup
1804
- * }
1805
- */
1806
- onrightup: null,
1807
- /**
1808
- * Property-based event handler for the `rightupoutside` event.
1809
- * @memberof scene.Container#
1810
- * @default null
1811
- * @example
1812
- * this.onrightupoutside = (event) => {
1813
- * //some function here that happens on rightupoutside
1814
- * }
1815
- */
1816
- onrightupoutside: null,
1817
- /**
1818
- * Property-based event handler for the `tap` event.
1819
- * @memberof scene.Container#
1820
- * @default null
1821
- * @example
1822
- * this.ontap = (event) => {
1823
- * //some function here that happens on tap
1824
- * }
1825
- */
1826
- ontap: null,
1827
- /**
1828
- * Property-based event handler for the `touchcancel` event.
1829
- * @memberof scene.Container#
1830
- * @default null
1831
- * @example
1832
- * this.ontouchcancel = (event) => {
1833
- * //some function here that happens on touchcancel
1834
- * }
1835
- */
1836
- ontouchcancel: null,
1837
- /**
1838
- * Property-based event handler for the `touchend` event.
1839
- * @memberof scene.Container#
1840
- * @default null
1841
- * @example
1842
- * this.ontouchend = (event) => {
1843
- * //some function here that happens on touchend
1844
- * }
1845
- */
1846
- ontouchend: null,
1847
- /**
1848
- * Property-based event handler for the `touchendoutside` event.
1849
- * @memberof scene.Container#
1850
- * @default null
1851
- * @example
1852
- * this.ontouchendoutside = (event) => {
1853
- * //some function here that happens on touchendoutside
1854
- * }
1855
- */
1856
- ontouchendoutside: null,
1857
- /**
1858
- * Property-based event handler for the `touchmove` event.
1859
- * @memberof scene.Container#
1860
- * @default null
1861
- * @example
1862
- * this.ontouchmove = (event) => {
1863
- * //some function here that happens on touchmove
1864
- * }
1865
- */
1866
- ontouchmove: null,
1867
- /**
1868
- * Property-based event handler for the `globaltouchmove` event.
1869
- * @memberof scene.Container#
1870
- * @default null
1871
- * @example
1872
- * this.onglobaltouchmove = (event) => {
1873
- * //some function here that happens on globaltouchmove
1874
- * }
1875
- */
1876
- onglobaltouchmove: null,
1877
- /**
1878
- * Property-based event handler for the `touchstart` event.
1879
- * @memberof scene.Container#
1880
- * @default null
1881
- * @example
1882
- * this.ontouchstart = (event) => {
1883
- * //some function here that happens on touchstart
1884
- * }
1885
- */
1886
- ontouchstart: null,
1887
- /**
1888
- * Property-based event handler for the `wheel` event.
1889
- * @memberof scene.Container#
1890
- * @default null
1891
- * @example
1892
- * this.onwheel = (event) => {
1893
- * //some function here that happens on wheel
1894
- * }
1895
- */
1896
- onwheel: null,
1897
- /**
1898
- * Enable interaction events for the Container. Touch, pointer and mouse
1899
- * @memberof scene.Container#
1900
- */
1901
- get interactive() {
1902
- return this.eventMode === "dynamic" || this.eventMode === "static";
1903
- },
1904
- set interactive(a) {
1905
- this.eventMode = a ? "static" : "passive";
1906
- },
1907
- /**
1908
- * @ignore
1909
- */
1910
- _internalEventMode: void 0,
1911
- /**
1912
- * Enable interaction events for the Container. Touch, pointer and mouse.
1913
- * There are 5 types of interaction settings:
1914
- * - `'none'`: Ignores all interaction events, even on its children.
1915
- * - `'passive'`: **(default)** Does not emit events and ignores all hit testing on itself and non-interactive children.
1916
- * Interactive children will still emit events.
1917
- * - `'auto'`: Does not emit events but is hit tested if parent is interactive. Same as `interactive = false` in v7
1918
- * - `'static'`: Emit events and is hit tested. Same as `interaction = true` in v7
1919
- * - `'dynamic'`: Emits events and is hit tested but will also receive mock interaction events fired from a ticker to
1920
- * allow for interaction when the mouse isn't moving
1921
- * @example
1922
- * import { Sprite } from 'pixi.js';
1923
- *
1924
- * const sprite = new Sprite(texture);
1925
- * sprite.eventMode = 'static';
1926
- * sprite.on('tap', (event) => {
1927
- * // Handle event
1928
- * });
1929
- * @memberof scene.Container#
1930
- * @since 7.2.0
1931
- */
1932
- get eventMode() {
1933
- return this._internalEventMode ?? q.defaultEventMode;
1934
- },
1935
- set eventMode(a) {
1936
- this._internalEventMode = a;
1937
- },
1938
- /**
1939
- * Determines if the container is interactive or not
1940
- * @returns {boolean} Whether the container is interactive or not
1941
- * @memberof scene.Container#
1942
- * @since 7.2.0
1943
- * @example
1944
- * import { Sprite } from 'pixi.js';
1945
- *
1946
- * const sprite = new Sprite(texture);
1947
- * sprite.eventMode = 'static';
1948
- * sprite.isInteractive(); // true
1949
- *
1950
- * sprite.eventMode = 'dynamic';
1951
- * sprite.isInteractive(); // true
1952
- *
1953
- * sprite.eventMode = 'none';
1954
- * sprite.isInteractive(); // false
1955
- *
1956
- * sprite.eventMode = 'passive';
1957
- * sprite.isInteractive(); // false
1958
- *
1959
- * sprite.eventMode = 'auto';
1960
- * sprite.isInteractive(); // false
1961
- */
1962
- isInteractive() {
1963
- return this.eventMode === "static" || this.eventMode === "dynamic";
1964
- },
1965
- /**
1966
- * Determines if the children to the container can be clicked/touched
1967
- * Setting this to false allows PixiJS to bypass a recursive `hitTest` function
1968
- * @memberof scene.Container#
1969
- */
1970
- interactiveChildren: !0,
1971
- /**
1972
- * Interaction shape. Children will be hit first, then this shape will be checked.
1973
- * Setting this will cause this shape to be checked in hit tests rather than the container's bounds.
1974
- * @example
1975
- * import { Rectangle, Sprite } from 'pixi.js';
1976
- *
1977
- * const sprite = new Sprite(texture);
1978
- * sprite.interactive = true;
1979
- * sprite.hitArea = new Rectangle(0, 0, 100, 100);
1980
- * @member {IHitArea}
1981
- * @memberof scene.Container#
1982
- */
1983
- hitArea: null,
1984
- /**
1985
- * Unlike `on` or `addListener` which are methods from EventEmitter, `addEventListener`
1986
- * seeks to be compatible with the DOM's `addEventListener` with support for options.
1987
- * @memberof scene.Container
1988
- * @param type - The type of event to listen to.
1989
- * @param listener - The listener callback or object.
1990
- * @param options - Listener options, used for capture phase.
1991
- * @example
1992
- * // Tell the user whether they did a single, double, triple, or nth click.
1993
- * button.addEventListener('click', {
1994
- * handleEvent(e): {
1995
- * let prefix;
1996
- *
1997
- * switch (e.detail) {
1998
- * case 1: prefix = 'single'; break;
1999
- * case 2: prefix = 'double'; break;
2000
- * case 3: prefix = 'triple'; break;
2001
- * default: prefix = e.detail + 'th'; break;
2002
- * }
2003
- *
2004
- * console.log('That was a ' + prefix + 'click');
2005
- * }
2006
- * });
2007
- *
2008
- * // But skip the first click!
2009
- * button.parent.addEventListener('click', function blockClickOnce(e) {
2010
- * e.stopImmediatePropagation();
2011
- * button.parent.removeEventListener('click', blockClickOnce, true);
2012
- * }, {
2013
- * capture: true,
2014
- * });
2015
- */
2016
- addEventListener(a, e, t) {
2017
- const i = typeof t == "boolean" && t || typeof t == "object" && t.capture, n = typeof t == "object" ? t.signal : void 0, s = typeof t == "object" ? t.once === !0 : !1, o = typeof e == "function" ? void 0 : e;
2018
- a = i ? `${a}capture` : a;
2019
- const r = typeof e == "function" ? e : e.handleEvent, l = this;
2020
- n && n.addEventListener("abort", () => {
2021
- l.off(a, r, o);
2022
- }), s ? l.once(a, r, o) : l.on(a, r, o);
2023
- },
2024
- /**
2025
- * Unlike `off` or `removeListener` which are methods from EventEmitter, `removeEventListener`
2026
- * seeks to be compatible with the DOM's `removeEventListener` with support for options.
2027
- * @memberof scene.Container
2028
- * @param type - The type of event the listener is bound to.
2029
- * @param listener - The listener callback or object.
2030
- * @param options - The original listener options. This is required to deregister a capture phase listener.
2031
- */
2032
- removeEventListener(a, e, t) {
2033
- const i = typeof t == "boolean" && t || typeof t == "object" && t.capture, n = typeof e == "function" ? void 0 : e;
2034
- a = i ? `${a}capture` : a, e = typeof e == "function" ? e : e.handleEvent, this.off(a, e, n);
2035
- },
2036
- /**
2037
- * Dispatch the event on this {@link Container} using the event's {@link EventBoundary}.
2038
- *
2039
- * The target of the event is set to `this` and the `defaultPrevented` flag is cleared before dispatch.
2040
- * @memberof scene.Container
2041
- * @param e - The event to dispatch.
2042
- * @returns Whether the {@link FederatedEvent.preventDefault preventDefault}() method was not invoked.
2043
- * @example
2044
- * // Reuse a click event!
2045
- * button.dispatchEvent(clickEvent);
2046
- */
2047
- dispatchEvent(a) {
2048
- if (!(a instanceof w))
2049
- throw new Error("Container cannot propagate events outside of the Federated Events API");
2050
- return a.defaultPrevented = !1, a.path = null, a.target = this, a.manager.dispatchEvent(a), !a.defaultPrevented;
2051
- }
2052
- };
2053
- D.add(ce);
2054
- D.mixin(Z, de);
2055
- D.add(q);
2056
- D.mixin(Z, ye);
2057
- //# sourceMappingURL=browserAll-BuClNU5V.js.map