This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

21
resources/app/node_modules/@pixi/events/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2013-2023 Mathew Groves, Chad Engler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,610 @@
"use strict";
var core = require("@pixi/core"), EventTicker = require("./EventTicker.js"), FederatedMouseEvent = require("./FederatedMouseEvent.js"), FederatedPointerEvent = require("./FederatedPointerEvent.js"), FederatedWheelEvent = require("./FederatedWheelEvent.js");
const PROPAGATION_LIMIT = 2048, tempHitLocation = new core.Point(), tempLocalMapping = new core.Point();
class EventBoundary {
/**
* @param rootTarget - The holder of the event boundary.
*/
constructor(rootTarget) {
this.dispatch = new core.utils.EventEmitter(), this.moveOnAll = !1, this.enableGlobalMoveEvents = !0, this.mappingState = {
trackingData: {}
}, this.eventPool = /* @__PURE__ */ new Map(), this._allInteractiveElements = [], this._hitElements = [], this._isPointerMoveEvent = !1, this.rootTarget = rootTarget, 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);
}
/**
* Adds an event mapping for the event `type` handled by `fn`.
*
* Event mappings can be used to implement additional or custom events. They take an event
* coming from the upstream scene (or directly from the {@link PIXI.EventSystem}) and dispatch new downstream events
* generally trickling down and bubbling up to {@link PIXI.EventBoundary.rootTarget this.rootTarget}.
*
* To modify the semantics of existing events, the built-in mapping methods of EventBoundary should be overridden
* instead.
* @param type - The type of upstream event to map.
* @param fn - The mapping method. The context of this function must be bound manually, if desired.
*/
addEventMapping(type, fn) {
this.mappingTable[type] || (this.mappingTable[type] = []), this.mappingTable[type].push({
fn,
priority: 0
}), this.mappingTable[type].sort((a, b) => a.priority - b.priority);
}
/**
* Dispatches the given event
* @param e
* @param type
*/
dispatchEvent(e, type) {
e.propagationStopped = !1, e.propagationImmediatelyStopped = !1, this.propagate(e, type), this.dispatch.emit(type || e.type, e);
}
/**
* Maps the given upstream event through the event boundary and propagates it downstream.
* @param e
*/
mapEvent(e) {
if (!this.rootTarget)
return;
const mappers = this.mappingTable[e.type];
if (mappers)
for (let i = 0, j = mappers.length; i < j; i++)
mappers[i].fn(e);
else
console.warn(`[EventBoundary]: Event mapping not defined for ${e.type}`);
}
/**
* Finds the DisplayObject that is the target of a event at the given coordinates.
*
* The passed (x,y) coordinates are in the world space above this event boundary.
* @param x
* @param y
*/
hitTest(x, y) {
EventTicker.EventsTicker.pauseUpdate = !0;
const fn = this._isPointerMoveEvent && this.enableGlobalMoveEvents ? "hitTestMoveRecursive" : "hitTestRecursive", invertedPath = this[fn](
this.rootTarget,
this.rootTarget.eventMode,
tempHitLocation.set(x, y),
this.hitTestFn,
this.hitPruneFn
);
return invertedPath && invertedPath[0];
}
/**
* Propagate the passed event from from {@link PIXI.EventBoundary.rootTarget this.rootTarget} to its
* target {@code e.target}.
* @param e - The event to propagate.
* @param type
*/
propagate(e, type) {
if (!e.target)
return;
const composedPath = e.composedPath();
e.eventPhase = e.CAPTURING_PHASE;
for (let i = 0, j = composedPath.length - 1; i < j; i++)
if (e.currentTarget = composedPath[i], this.notifyTarget(e, type), e.propagationStopped || e.propagationImmediatelyStopped)
return;
if (e.eventPhase = e.AT_TARGET, e.currentTarget = e.target, this.notifyTarget(e, type), !(e.propagationStopped || e.propagationImmediatelyStopped)) {
e.eventPhase = e.BUBBLING_PHASE;
for (let i = composedPath.length - 2; i >= 0; i--)
if (e.currentTarget = composedPath[i], this.notifyTarget(e, type), e.propagationStopped || e.propagationImmediatelyStopped)
return;
}
}
/**
* Emits the event {@code e} to all interactive display objects. The event is propagated in the bubbling phase always.
*
* This is used in the `globalpointermove` event.
* @param e - The emitted event.
* @param type - The listeners to notify.
* @param targets - The targets to notify.
*/
all(e, type, targets = this._allInteractiveElements) {
if (targets.length === 0)
return;
e.eventPhase = e.BUBBLING_PHASE;
const events = Array.isArray(type) ? type : [type];
for (let i = targets.length - 1; i >= 0; i--)
events.forEach((event) => {
e.currentTarget = targets[i], this.notifyTarget(e, event);
});
}
/**
* Finds the propagation path from {@link PIXI.EventBoundary.rootTarget rootTarget} to the passed
* {@code target}. The last element in the path is {@code target}.
* @param target
*/
propagationPath(target) {
const propagationPath = [target];
for (let i = 0; i < PROPAGATION_LIMIT && target !== this.rootTarget; i++) {
if (!target.parent)
throw new Error("Cannot find propagation path to disconnected target");
propagationPath.push(target.parent), target = target.parent;
}
return propagationPath.reverse(), propagationPath;
}
hitTestMoveRecursive(currentTarget, eventMode, location, testFn, pruneFn, ignore = !1) {
let shouldReturn = !1;
if (this._interactivePrune(currentTarget))
return null;
if ((currentTarget.eventMode === "dynamic" || eventMode === "dynamic") && (EventTicker.EventsTicker.pauseUpdate = !1), currentTarget.interactiveChildren && currentTarget.children) {
const children = currentTarget.children;
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i], nestedHit = this.hitTestMoveRecursive(
child,
this._isInteractive(eventMode) ? eventMode : child.eventMode,
location,
testFn,
pruneFn,
ignore || pruneFn(currentTarget, location)
);
if (nestedHit) {
if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent)
continue;
const isInteractive = currentTarget.isInteractive();
(nestedHit.length > 0 || isInteractive) && (isInteractive && this._allInteractiveElements.push(currentTarget), nestedHit.push(currentTarget)), this._hitElements.length === 0 && (this._hitElements = nestedHit), shouldReturn = !0;
}
}
}
const isInteractiveMode = this._isInteractive(eventMode), isInteractiveTarget = currentTarget.isInteractive();
return isInteractiveMode && isInteractiveTarget && this._allInteractiveElements.push(currentTarget), ignore || this._hitElements.length > 0 ? null : shouldReturn ? this._hitElements : isInteractiveMode && !pruneFn(currentTarget, location) && testFn(currentTarget, location) ? isInteractiveTarget ? [currentTarget] : [] : null;
}
/**
* Recursive implementation for {@link PIXI.EventBoundary.hitTest hitTest}.
* @param currentTarget - The DisplayObject that is to be hit tested.
* @param eventMode - The event mode for the `currentTarget` or one of its parents.
* @param location - The location that is being tested for overlap.
* @param testFn - Callback that determines whether the target passes hit testing. This callback
* can assume that `pruneFn` failed to prune the display object.
* @param pruneFn - Callback that determiness whether the target and all of its children
* cannot pass the hit test. It is used as a preliminary optimization to prune entire subtrees
* of the scene graph.
* @returns An array holding the hit testing target and all its ancestors in order. The first element
* is the target itself and the last is {@link PIXI.EventBoundary.rootTarget rootTarget}. This is the opposite
* order w.r.t. the propagation path. If no hit testing target is found, null is returned.
*/
hitTestRecursive(currentTarget, eventMode, location, testFn, pruneFn) {
if (this._interactivePrune(currentTarget) || pruneFn(currentTarget, location))
return null;
if ((currentTarget.eventMode === "dynamic" || eventMode === "dynamic") && (EventTicker.EventsTicker.pauseUpdate = !1), currentTarget.interactiveChildren && currentTarget.children) {
const children = currentTarget.children;
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i], nestedHit = this.hitTestRecursive(
child,
this._isInteractive(eventMode) ? eventMode : child.eventMode,
location,
testFn,
pruneFn
);
if (nestedHit) {
if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent)
continue;
const isInteractive = currentTarget.isInteractive();
return (nestedHit.length > 0 || isInteractive) && nestedHit.push(currentTarget), nestedHit;
}
}
}
const isInteractiveMode = this._isInteractive(eventMode), isInteractiveTarget = currentTarget.isInteractive();
return isInteractiveMode && testFn(currentTarget, location) ? isInteractiveTarget ? [currentTarget] : [] : null;
}
_isInteractive(int) {
return int === "static" || int === "dynamic";
}
_interactivePrune(displayObject) {
return !!(!displayObject || displayObject.isMask || !displayObject.visible || !displayObject.renderable || displayObject.eventMode === "none" || displayObject.eventMode === "passive" && !displayObject.interactiveChildren || displayObject.isMask);
}
/**
* Checks whether the display object or any of its children cannot pass the hit test at all.
*
* {@link PIXI.EventBoundary}'s implementation uses the {@link PIXI.DisplayObject.hitArea hitArea}
* and {@link PIXI.DisplayObject._mask} for pruning.
* @param displayObject
* @param location
*/
hitPruneFn(displayObject, location) {
if (displayObject.hitArea && (displayObject.worldTransform.applyInverse(location, tempLocalMapping), !displayObject.hitArea.contains(tempLocalMapping.x, tempLocalMapping.y)))
return !0;
if (displayObject._mask) {
const maskObject = displayObject._mask.isMaskData ? displayObject._mask.maskObject : displayObject._mask;
if (maskObject && !maskObject.containsPoint?.(location))
return !0;
}
return !1;
}
/**
* Checks whether the display object passes hit testing for the given location.
* @param displayObject
* @param location
* @returns - Whether `displayObject` passes hit testing for `location`.
*/
hitTestFn(displayObject, location) {
return displayObject.eventMode === "passive" ? !1 : displayObject.hitArea ? !0 : displayObject.containsPoint ? displayObject.containsPoint(location) : !1;
}
/**
* Notify all the listeners to the event's `currentTarget`.
*
* If the `currentTarget` contains the property `on<type>`, then it is called here,
* simulating the behavior from version 6.x and prior.
* @param e - The event passed to the target.
* @param type
*/
notifyTarget(e, type) {
type = type ?? e.type;
const handlerKey = `on${type}`;
e.currentTarget[handlerKey]?.(e);
const key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${type}capture` : type;
this.notifyListeners(e, key), e.eventPhase === e.AT_TARGET && this.notifyListeners(e, type);
}
/**
* Maps the upstream `pointerdown` events to a downstream `pointerdown` event.
*
* `touchstart`, `rightdown`, `mousedown` events are also dispatched for specific pointer types.
* @param from
*/
mapPointerDown(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const e = this.createPointerEvent(from);
if (this.dispatchEvent(e, "pointerdown"), e.pointerType === "touch")
this.dispatchEvent(e, "touchstart");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.dispatchEvent(e, isRightButton ? "rightdown" : "mousedown");
}
const trackingData = this.trackingData(from.pointerId);
trackingData.pressTargetsByButton[from.button] = e.composedPath(), this.freeEvent(e);
}
/**
* Maps the upstream `pointermove` to downstream `pointerout`, `pointerover`, and `pointermove` events, in that order.
*
* The tracking data for the specific pointer has an updated `overTarget`. `mouseout`, `mouseover`,
* `mousemove`, and `touchmove` events are fired as well for specific pointer types.
* @param from - The upstream `pointermove` event.
*/
mapPointerMove(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
this._allInteractiveElements.length = 0, this._hitElements.length = 0, this._isPointerMoveEvent = !0;
const e = this.createPointerEvent(from);
this._isPointerMoveEvent = !1;
const isMouse = e.pointerType === "mouse" || e.pointerType === "pen", trackingData = this.trackingData(from.pointerId), outTarget = this.findMountedTarget(trackingData.overTargets);
if (trackingData.overTargets?.length > 0 && outTarget !== e.target) {
const outType = from.type === "mousemove" ? "mouseout" : "pointerout", outEvent = this.createPointerEvent(from, outType, outTarget);
if (this.dispatchEvent(outEvent, "pointerout"), isMouse && this.dispatchEvent(outEvent, "mouseout"), !e.composedPath().includes(outTarget)) {
const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; leaveEvent.target && !e.composedPath().includes(leaveEvent.target); )
leaveEvent.currentTarget = leaveEvent.target, this.notifyTarget(leaveEvent), isMouse && this.notifyTarget(leaveEvent, "mouseleave"), leaveEvent.target = leaveEvent.target.parent;
this.freeEvent(leaveEvent);
}
this.freeEvent(outEvent);
}
if (outTarget !== e.target) {
const overType = from.type === "mousemove" ? "mouseover" : "pointerover", overEvent = this.clonePointerEvent(e, overType);
this.dispatchEvent(overEvent, "pointerover"), isMouse && this.dispatchEvent(overEvent, "mouseover");
let overTargetAncestor = outTarget?.parent;
for (; overTargetAncestor && overTargetAncestor !== this.rootTarget.parent && overTargetAncestor !== e.target; )
overTargetAncestor = overTargetAncestor.parent;
if (!overTargetAncestor || overTargetAncestor === this.rootTarget.parent) {
const enterEvent = this.clonePointerEvent(e, "pointerenter");
for (enterEvent.eventPhase = enterEvent.AT_TARGET; enterEvent.target && enterEvent.target !== outTarget && enterEvent.target !== this.rootTarget.parent; )
enterEvent.currentTarget = enterEvent.target, this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter"), enterEvent.target = enterEvent.target.parent;
this.freeEvent(enterEvent);
}
this.freeEvent(overEvent);
}
const allMethods = [], allowGlobalPointerEvents = this.enableGlobalMoveEvents ?? !0;
this.moveOnAll ? allMethods.push("pointermove") : this.dispatchEvent(e, "pointermove"), allowGlobalPointerEvents && allMethods.push("globalpointermove"), e.pointerType === "touch" && (this.moveOnAll ? allMethods.splice(1, 0, "touchmove") : this.dispatchEvent(e, "touchmove"), allowGlobalPointerEvents && allMethods.push("globaltouchmove")), isMouse && (this.moveOnAll ? allMethods.splice(1, 0, "mousemove") : this.dispatchEvent(e, "mousemove"), allowGlobalPointerEvents && allMethods.push("globalmousemove"), this.cursor = e.target?.cursor), allMethods.length > 0 && this.all(e, allMethods), this._allInteractiveElements.length = 0, this._hitElements.length = 0, trackingData.overTargets = e.composedPath(), this.freeEvent(e);
}
/**
* Maps the upstream `pointerover` to downstream `pointerover` and `pointerenter` events, in that order.
*
* The tracking data for the specific pointer gets a new `overTarget`.
* @param from - The upstream `pointerover` event.
*/
mapPointerOver(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId), e = this.createPointerEvent(from), isMouse = e.pointerType === "mouse" || e.pointerType === "pen";
this.dispatchEvent(e, "pointerover"), isMouse && this.dispatchEvent(e, "mouseover"), e.pointerType === "mouse" && (this.cursor = e.target?.cursor);
const enterEvent = this.clonePointerEvent(e, "pointerenter");
for (enterEvent.eventPhase = enterEvent.AT_TARGET; enterEvent.target && enterEvent.target !== this.rootTarget.parent; )
enterEvent.currentTarget = enterEvent.target, this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter"), enterEvent.target = enterEvent.target.parent;
trackingData.overTargets = e.composedPath(), this.freeEvent(e), this.freeEvent(enterEvent);
}
/**
* Maps the upstream `pointerout` to downstream `pointerout`, `pointerleave` events, in that order.
*
* The tracking data for the specific pointer is cleared of a `overTarget`.
* @param from - The upstream `pointerout` event.
*/
mapPointerOut(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId);
if (trackingData.overTargets) {
const isMouse = from.pointerType === "mouse" || from.pointerType === "pen", outTarget = this.findMountedTarget(trackingData.overTargets), outEvent = this.createPointerEvent(from, "pointerout", outTarget);
this.dispatchEvent(outEvent), isMouse && this.dispatchEvent(outEvent, "mouseout");
const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; leaveEvent.target && leaveEvent.target !== this.rootTarget.parent; )
leaveEvent.currentTarget = leaveEvent.target, this.notifyTarget(leaveEvent), isMouse && this.notifyTarget(leaveEvent, "mouseleave"), leaveEvent.target = leaveEvent.target.parent;
trackingData.overTargets = null, this.freeEvent(outEvent), this.freeEvent(leaveEvent);
}
this.cursor = null;
}
/**
* Maps the upstream `pointerup` event to downstream `pointerup`, `pointerupoutside`,
* and `click`/`rightclick`/`pointertap` events, in that order.
*
* The `pointerupoutside` event bubbles from the original `pointerdown` target to the most specific
* ancestor of the `pointerdown` and `pointerup` targets, which is also the `click` event's target. `touchend`,
* `rightup`, `mouseup`, `touchendoutside`, `rightupoutside`, `mouseupoutside`, and `tap` are fired as well for
* specific pointer types.
* @param from - The upstream `pointerup` event.
*/
mapPointerUp(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const now = performance.now(), e = this.createPointerEvent(from);
if (this.dispatchEvent(e, "pointerup"), e.pointerType === "touch")
this.dispatchEvent(e, "touchend");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.dispatchEvent(e, isRightButton ? "rightup" : "mouseup");
}
const trackingData = this.trackingData(from.pointerId), pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
let clickTarget = pressTarget;
if (pressTarget && !e.composedPath().includes(pressTarget)) {
let currentTarget = pressTarget;
for (; currentTarget && !e.composedPath().includes(currentTarget); ) {
if (e.currentTarget = currentTarget, this.notifyTarget(e, "pointerupoutside"), e.pointerType === "touch")
this.notifyTarget(e, "touchendoutside");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.notifyTarget(e, isRightButton ? "rightupoutside" : "mouseupoutside");
}
currentTarget = currentTarget.parent;
}
delete trackingData.pressTargetsByButton[from.button], clickTarget = currentTarget;
}
if (clickTarget) {
const clickEvent = this.clonePointerEvent(e, "click");
clickEvent.target = clickTarget, clickEvent.path = null, trackingData.clicksByButton[from.button] || (trackingData.clicksByButton[from.button] = {
clickCount: 0,
target: clickEvent.target,
timeStamp: now
});
const clickHistory = trackingData.clicksByButton[from.button];
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < 200 ? ++clickHistory.clickCount : clickHistory.clickCount = 1, clickHistory.target = clickEvent.target, clickHistory.timeStamp = now, clickEvent.detail = clickHistory.clickCount, clickEvent.pointerType === "mouse") {
const isRightButton = clickEvent.button === 2;
this.dispatchEvent(clickEvent, isRightButton ? "rightclick" : "click");
} else
clickEvent.pointerType === "touch" && this.dispatchEvent(clickEvent, "tap");
this.dispatchEvent(clickEvent, "pointertap"), this.freeEvent(clickEvent);
}
this.freeEvent(e);
}
/**
* Maps the upstream `pointerupoutside` event to a downstream `pointerupoutside` event, bubbling from the original
* `pointerdown` target to `rootTarget`.
*
* (The most specific ancestor of the `pointerdown` event and the `pointerup` event must the
* `{@link PIXI.EventBoundary}'s root because the `pointerup` event occurred outside of the boundary.)
*
* `touchendoutside`, `mouseupoutside`, and `rightupoutside` events are fired as well for specific pointer
* types. The tracking data for the specific pointer is cleared of a `pressTarget`.
* @param from - The upstream `pointerupoutside` event.
*/
mapPointerUpOutside(from) {
if (!(from instanceof FederatedPointerEvent.FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId), pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]), e = this.createPointerEvent(from);
if (pressTarget) {
let currentTarget = pressTarget;
for (; currentTarget; )
e.currentTarget = currentTarget, this.notifyTarget(e, "pointerupoutside"), e.pointerType === "touch" ? this.notifyTarget(e, "touchendoutside") : (e.pointerType === "mouse" || e.pointerType === "pen") && this.notifyTarget(e, e.button === 2 ? "rightupoutside" : "mouseupoutside"), currentTarget = currentTarget.parent;
delete trackingData.pressTargetsByButton[from.button];
}
this.freeEvent(e);
}
/**
* Maps the upstream `wheel` event to a downstream `wheel` event.
* @param from - The upstream `wheel` event.
*/
mapWheel(from) {
if (!(from instanceof FederatedWheelEvent.FederatedWheelEvent)) {
console.warn("EventBoundary cannot map a non-wheel event as a wheel event");
return;
}
const wheelEvent = this.createWheelEvent(from);
this.dispatchEvent(wheelEvent), this.freeEvent(wheelEvent);
}
/**
* Finds the most specific event-target in the given propagation path that is still mounted in the scene graph.
*
* This is used to find the correct `pointerup` and `pointerout` target in the case that the original `pointerdown`
* or `pointerover` target was unmounted from the scene graph.
* @param propagationPath - The propagation path was valid in the past.
* @returns - The most specific event-target still mounted at the same location in the scene graph.
*/
findMountedTarget(propagationPath) {
if (!propagationPath)
return null;
let currentTarget = propagationPath[0];
for (let i = 1; i < propagationPath.length && propagationPath[i].parent === currentTarget; i++)
currentTarget = propagationPath[i];
return currentTarget;
}
/**
* Creates an event whose {@code originalEvent} is {@code from}, with an optional `type` and `target` override.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The {@code originalEvent} for the returned event.
* @param [type=from.type] - The type of the returned event.
* @param target - The target of the returned event.
*/
createPointerEvent(from, type, target) {
const event = this.allocateEvent(FederatedPointerEvent.FederatedPointerEvent);
return this.copyPointerData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = target ?? this.hitTest(event.global.x, event.global.y) ?? this._hitElements[0], typeof type == "string" && (event.type = type), event;
}
/**
* Creates a wheel event whose {@code originalEvent} is {@code from}.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The upstream wheel event.
*/
createWheelEvent(from) {
const event = this.allocateEvent(FederatedWheelEvent.FederatedWheelEvent);
return this.copyWheelData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = this.hitTest(event.global.x, event.global.y), event;
}
/**
* Clones the event {@code from}, with an optional {@code type} override.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The event to clone.
* @param [type=from.type] - The type of the returned event.
*/
clonePointerEvent(from, type) {
const event = this.allocateEvent(FederatedPointerEvent.FederatedPointerEvent);
return event.nativeEvent = from.nativeEvent, event.originalEvent = from.originalEvent, this.copyPointerData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.target = from.target, event.path = from.composedPath().slice(), event.type = type ?? event.type, event;
}
/**
* Copies wheel {@link PIXI.FederatedWheelEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + deltaMode
* + deltaX
* + deltaY
* + deltaZ
* @param from
* @param to
*/
copyWheelData(from, to) {
to.deltaMode = from.deltaMode, to.deltaX = from.deltaX, to.deltaY = from.deltaY, to.deltaZ = from.deltaZ;
}
/**
* Copies pointer {@link PIXI.FederatedPointerEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + pointerId
* + width
* + height
* + isPrimary
* + pointerType
* + pressure
* + tangentialPressure
* + tiltX
* + tiltY
* @param from
* @param to
*/
copyPointerData(from, to) {
from instanceof FederatedPointerEvent.FederatedPointerEvent && to instanceof FederatedPointerEvent.FederatedPointerEvent && (to.pointerId = from.pointerId, to.width = from.width, to.height = from.height, to.isPrimary = from.isPrimary, to.pointerType = from.pointerType, to.pressure = from.pressure, to.tangentialPressure = from.tangentialPressure, to.tiltX = from.tiltX, to.tiltY = from.tiltY, to.twist = from.twist);
}
/**
* Copies mouse {@link PIXI.FederatedMouseEvent} data from {@code from} to {@code to}.
*
* The following properties are copied:
* + altKey
* + button
* + buttons
* + clientX
* + clientY
* + metaKey
* + movementX
* + movementY
* + pageX
* + pageY
* + x
* + y
* + screen
* + shiftKey
* + global
* @param from
* @param to
*/
copyMouseData(from, to) {
from instanceof FederatedMouseEvent.FederatedMouseEvent && to instanceof FederatedMouseEvent.FederatedMouseEvent && (to.altKey = from.altKey, to.button = from.button, to.buttons = from.buttons, to.client.copyFrom(from.client), to.ctrlKey = from.ctrlKey, to.metaKey = from.metaKey, to.movement.copyFrom(from.movement), to.screen.copyFrom(from.screen), to.shiftKey = from.shiftKey, to.global.copyFrom(from.global));
}
/**
* Copies base {@link PIXI.FederatedEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + isTrusted
* + srcElement
* + timeStamp
* + type
* @param from - The event to copy data from.
* @param to - The event to copy data into.
*/
copyData(from, to) {
to.isTrusted = from.isTrusted, to.srcElement = from.srcElement, to.timeStamp = performance.now(), to.type = from.type, to.detail = from.detail, to.view = from.view, to.which = from.which, to.layer.copyFrom(from.layer), to.page.copyFrom(from.page);
}
/**
* @param id - The pointer ID.
* @returns The tracking data stored for the given pointer. If no data exists, a blank
* state will be created.
*/
trackingData(id) {
return this.mappingState.trackingData[id] || (this.mappingState.trackingData[id] = {
pressTargetsByButton: {},
clicksByButton: {},
overTarget: null
}), this.mappingState.trackingData[id];
}
/**
* Allocate a specific type of event from {@link PIXI.EventBoundary#eventPool this.eventPool}.
*
* This allocation is constructor-agnostic, as long as it only takes one argument - this event
* boundary.
* @param constructor - The event's constructor.
*/
allocateEvent(constructor) {
this.eventPool.has(constructor) || this.eventPool.set(constructor, []);
const event = this.eventPool.get(constructor).pop() || new constructor(this);
return event.eventPhase = event.NONE, event.currentTarget = null, event.path = null, event.target = null, event;
}
/**
* Frees the event and puts it back into the event pool.
*
* It is illegal to reuse the event until it is allocated again, using `this.allocateEvent`.
*
* It is also advised that events not allocated from {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}
* not be freed. This is because of the possibility that the same event is freed twice, which can cause
* it to be allocated twice & result in overwriting.
* @param event - The event to be freed.
* @throws Error if the event is managed by another event boundary.
*/
freeEvent(event) {
if (event.manager !== this)
throw new Error("It is illegal to free an event not managed by this EventBoundary!");
const constructor = event.constructor;
this.eventPool.has(constructor) || this.eventPool.set(constructor, []), this.eventPool.get(constructor).push(event);
}
/**
* Similar to {@link PIXI.EventEmitter.emit}, except it stops if the `propagationImmediatelyStopped` flag
* is set on the event.
* @param e - The event to call each listener with.
* @param type - The event key.
*/
notifyListeners(e, type) {
const listeners = e.currentTarget._events[type];
if (listeners && e.currentTarget.isInteractive())
if ("fn" in listeners)
listeners.once && e.currentTarget.removeListener(type, listeners.fn, void 0, !0), listeners.fn.call(listeners.context, e);
else
for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++)
listeners[i].once && e.currentTarget.removeListener(type, listeners[i].fn, void 0, !0), listeners[i].fn.call(listeners[i].context, e);
}
}
exports.EventBoundary = EventBoundary;
//# sourceMappingURL=EventBoundary.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,615 @@
import { Point, utils } from "@pixi/core";
import { EventsTicker } from "./EventTicker.mjs";
import { FederatedMouseEvent } from "./FederatedMouseEvent.mjs";
import { FederatedPointerEvent } from "./FederatedPointerEvent.mjs";
import { FederatedWheelEvent } from "./FederatedWheelEvent.mjs";
const PROPAGATION_LIMIT = 2048, tempHitLocation = new Point(), tempLocalMapping = new Point();
class EventBoundary {
/**
* @param rootTarget - The holder of the event boundary.
*/
constructor(rootTarget) {
this.dispatch = new utils.EventEmitter(), this.moveOnAll = !1, this.enableGlobalMoveEvents = !0, this.mappingState = {
trackingData: {}
}, this.eventPool = /* @__PURE__ */ new Map(), this._allInteractiveElements = [], this._hitElements = [], this._isPointerMoveEvent = !1, this.rootTarget = rootTarget, 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);
}
/**
* Adds an event mapping for the event `type` handled by `fn`.
*
* Event mappings can be used to implement additional or custom events. They take an event
* coming from the upstream scene (or directly from the {@link PIXI.EventSystem}) and dispatch new downstream events
* generally trickling down and bubbling up to {@link PIXI.EventBoundary.rootTarget this.rootTarget}.
*
* To modify the semantics of existing events, the built-in mapping methods of EventBoundary should be overridden
* instead.
* @param type - The type of upstream event to map.
* @param fn - The mapping method. The context of this function must be bound manually, if desired.
*/
addEventMapping(type, fn) {
this.mappingTable[type] || (this.mappingTable[type] = []), this.mappingTable[type].push({
fn,
priority: 0
}), this.mappingTable[type].sort((a, b) => a.priority - b.priority);
}
/**
* Dispatches the given event
* @param e
* @param type
*/
dispatchEvent(e, type) {
e.propagationStopped = !1, e.propagationImmediatelyStopped = !1, this.propagate(e, type), this.dispatch.emit(type || e.type, e);
}
/**
* Maps the given upstream event through the event boundary and propagates it downstream.
* @param e
*/
mapEvent(e) {
if (!this.rootTarget)
return;
const mappers = this.mappingTable[e.type];
if (mappers)
for (let i = 0, j = mappers.length; i < j; i++)
mappers[i].fn(e);
else
console.warn(`[EventBoundary]: Event mapping not defined for ${e.type}`);
}
/**
* Finds the DisplayObject that is the target of a event at the given coordinates.
*
* The passed (x,y) coordinates are in the world space above this event boundary.
* @param x
* @param y
*/
hitTest(x, y) {
EventsTicker.pauseUpdate = !0;
const fn = this._isPointerMoveEvent && this.enableGlobalMoveEvents ? "hitTestMoveRecursive" : "hitTestRecursive", invertedPath = this[fn](
this.rootTarget,
this.rootTarget.eventMode,
tempHitLocation.set(x, y),
this.hitTestFn,
this.hitPruneFn
);
return invertedPath && invertedPath[0];
}
/**
* Propagate the passed event from from {@link PIXI.EventBoundary.rootTarget this.rootTarget} to its
* target {@code e.target}.
* @param e - The event to propagate.
* @param type
*/
propagate(e, type) {
if (!e.target)
return;
const composedPath = e.composedPath();
e.eventPhase = e.CAPTURING_PHASE;
for (let i = 0, j = composedPath.length - 1; i < j; i++)
if (e.currentTarget = composedPath[i], this.notifyTarget(e, type), e.propagationStopped || e.propagationImmediatelyStopped)
return;
if (e.eventPhase = e.AT_TARGET, e.currentTarget = e.target, this.notifyTarget(e, type), !(e.propagationStopped || e.propagationImmediatelyStopped)) {
e.eventPhase = e.BUBBLING_PHASE;
for (let i = composedPath.length - 2; i >= 0; i--)
if (e.currentTarget = composedPath[i], this.notifyTarget(e, type), e.propagationStopped || e.propagationImmediatelyStopped)
return;
}
}
/**
* Emits the event {@code e} to all interactive display objects. The event is propagated in the bubbling phase always.
*
* This is used in the `globalpointermove` event.
* @param e - The emitted event.
* @param type - The listeners to notify.
* @param targets - The targets to notify.
*/
all(e, type, targets = this._allInteractiveElements) {
if (targets.length === 0)
return;
e.eventPhase = e.BUBBLING_PHASE;
const events = Array.isArray(type) ? type : [type];
for (let i = targets.length - 1; i >= 0; i--)
events.forEach((event) => {
e.currentTarget = targets[i], this.notifyTarget(e, event);
});
}
/**
* Finds the propagation path from {@link PIXI.EventBoundary.rootTarget rootTarget} to the passed
* {@code target}. The last element in the path is {@code target}.
* @param target
*/
propagationPath(target) {
const propagationPath = [target];
for (let i = 0; i < PROPAGATION_LIMIT && target !== this.rootTarget; i++) {
if (!target.parent)
throw new Error("Cannot find propagation path to disconnected target");
propagationPath.push(target.parent), target = target.parent;
}
return propagationPath.reverse(), propagationPath;
}
hitTestMoveRecursive(currentTarget, eventMode, location, testFn, pruneFn, ignore = !1) {
let shouldReturn = !1;
if (this._interactivePrune(currentTarget))
return null;
if ((currentTarget.eventMode === "dynamic" || eventMode === "dynamic") && (EventsTicker.pauseUpdate = !1), currentTarget.interactiveChildren && currentTarget.children) {
const children = currentTarget.children;
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i], nestedHit = this.hitTestMoveRecursive(
child,
this._isInteractive(eventMode) ? eventMode : child.eventMode,
location,
testFn,
pruneFn,
ignore || pruneFn(currentTarget, location)
);
if (nestedHit) {
if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent)
continue;
const isInteractive = currentTarget.isInteractive();
(nestedHit.length > 0 || isInteractive) && (isInteractive && this._allInteractiveElements.push(currentTarget), nestedHit.push(currentTarget)), this._hitElements.length === 0 && (this._hitElements = nestedHit), shouldReturn = !0;
}
}
}
const isInteractiveMode = this._isInteractive(eventMode), isInteractiveTarget = currentTarget.isInteractive();
return isInteractiveMode && isInteractiveTarget && this._allInteractiveElements.push(currentTarget), ignore || this._hitElements.length > 0 ? null : shouldReturn ? this._hitElements : isInteractiveMode && !pruneFn(currentTarget, location) && testFn(currentTarget, location) ? isInteractiveTarget ? [currentTarget] : [] : null;
}
/**
* Recursive implementation for {@link PIXI.EventBoundary.hitTest hitTest}.
* @param currentTarget - The DisplayObject that is to be hit tested.
* @param eventMode - The event mode for the `currentTarget` or one of its parents.
* @param location - The location that is being tested for overlap.
* @param testFn - Callback that determines whether the target passes hit testing. This callback
* can assume that `pruneFn` failed to prune the display object.
* @param pruneFn - Callback that determiness whether the target and all of its children
* cannot pass the hit test. It is used as a preliminary optimization to prune entire subtrees
* of the scene graph.
* @returns An array holding the hit testing target and all its ancestors in order. The first element
* is the target itself and the last is {@link PIXI.EventBoundary.rootTarget rootTarget}. This is the opposite
* order w.r.t. the propagation path. If no hit testing target is found, null is returned.
*/
hitTestRecursive(currentTarget, eventMode, location, testFn, pruneFn) {
if (this._interactivePrune(currentTarget) || pruneFn(currentTarget, location))
return null;
if ((currentTarget.eventMode === "dynamic" || eventMode === "dynamic") && (EventsTicker.pauseUpdate = !1), currentTarget.interactiveChildren && currentTarget.children) {
const children = currentTarget.children;
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i], nestedHit = this.hitTestRecursive(
child,
this._isInteractive(eventMode) ? eventMode : child.eventMode,
location,
testFn,
pruneFn
);
if (nestedHit) {
if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent)
continue;
const isInteractive = currentTarget.isInteractive();
return (nestedHit.length > 0 || isInteractive) && nestedHit.push(currentTarget), nestedHit;
}
}
}
const isInteractiveMode = this._isInteractive(eventMode), isInteractiveTarget = currentTarget.isInteractive();
return isInteractiveMode && testFn(currentTarget, location) ? isInteractiveTarget ? [currentTarget] : [] : null;
}
_isInteractive(int) {
return int === "static" || int === "dynamic";
}
_interactivePrune(displayObject) {
return !!(!displayObject || displayObject.isMask || !displayObject.visible || !displayObject.renderable || displayObject.eventMode === "none" || displayObject.eventMode === "passive" && !displayObject.interactiveChildren || displayObject.isMask);
}
/**
* Checks whether the display object or any of its children cannot pass the hit test at all.
*
* {@link PIXI.EventBoundary}'s implementation uses the {@link PIXI.DisplayObject.hitArea hitArea}
* and {@link PIXI.DisplayObject._mask} for pruning.
* @param displayObject
* @param location
*/
hitPruneFn(displayObject, location) {
if (displayObject.hitArea && (displayObject.worldTransform.applyInverse(location, tempLocalMapping), !displayObject.hitArea.contains(tempLocalMapping.x, tempLocalMapping.y)))
return !0;
if (displayObject._mask) {
const maskObject = displayObject._mask.isMaskData ? displayObject._mask.maskObject : displayObject._mask;
if (maskObject && !maskObject.containsPoint?.(location))
return !0;
}
return !1;
}
/**
* Checks whether the display object passes hit testing for the given location.
* @param displayObject
* @param location
* @returns - Whether `displayObject` passes hit testing for `location`.
*/
hitTestFn(displayObject, location) {
return displayObject.eventMode === "passive" ? !1 : displayObject.hitArea ? !0 : displayObject.containsPoint ? displayObject.containsPoint(location) : !1;
}
/**
* Notify all the listeners to the event's `currentTarget`.
*
* If the `currentTarget` contains the property `on<type>`, then it is called here,
* simulating the behavior from version 6.x and prior.
* @param e - The event passed to the target.
* @param type
*/
notifyTarget(e, type) {
type = type ?? e.type;
const handlerKey = `on${type}`;
e.currentTarget[handlerKey]?.(e);
const key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${type}capture` : type;
this.notifyListeners(e, key), e.eventPhase === e.AT_TARGET && this.notifyListeners(e, type);
}
/**
* Maps the upstream `pointerdown` events to a downstream `pointerdown` event.
*
* `touchstart`, `rightdown`, `mousedown` events are also dispatched for specific pointer types.
* @param from
*/
mapPointerDown(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const e = this.createPointerEvent(from);
if (this.dispatchEvent(e, "pointerdown"), e.pointerType === "touch")
this.dispatchEvent(e, "touchstart");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.dispatchEvent(e, isRightButton ? "rightdown" : "mousedown");
}
const trackingData = this.trackingData(from.pointerId);
trackingData.pressTargetsByButton[from.button] = e.composedPath(), this.freeEvent(e);
}
/**
* Maps the upstream `pointermove` to downstream `pointerout`, `pointerover`, and `pointermove` events, in that order.
*
* The tracking data for the specific pointer has an updated `overTarget`. `mouseout`, `mouseover`,
* `mousemove`, and `touchmove` events are fired as well for specific pointer types.
* @param from - The upstream `pointermove` event.
*/
mapPointerMove(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
this._allInteractiveElements.length = 0, this._hitElements.length = 0, this._isPointerMoveEvent = !0;
const e = this.createPointerEvent(from);
this._isPointerMoveEvent = !1;
const isMouse = e.pointerType === "mouse" || e.pointerType === "pen", trackingData = this.trackingData(from.pointerId), outTarget = this.findMountedTarget(trackingData.overTargets);
if (trackingData.overTargets?.length > 0 && outTarget !== e.target) {
const outType = from.type === "mousemove" ? "mouseout" : "pointerout", outEvent = this.createPointerEvent(from, outType, outTarget);
if (this.dispatchEvent(outEvent, "pointerout"), isMouse && this.dispatchEvent(outEvent, "mouseout"), !e.composedPath().includes(outTarget)) {
const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; leaveEvent.target && !e.composedPath().includes(leaveEvent.target); )
leaveEvent.currentTarget = leaveEvent.target, this.notifyTarget(leaveEvent), isMouse && this.notifyTarget(leaveEvent, "mouseleave"), leaveEvent.target = leaveEvent.target.parent;
this.freeEvent(leaveEvent);
}
this.freeEvent(outEvent);
}
if (outTarget !== e.target) {
const overType = from.type === "mousemove" ? "mouseover" : "pointerover", overEvent = this.clonePointerEvent(e, overType);
this.dispatchEvent(overEvent, "pointerover"), isMouse && this.dispatchEvent(overEvent, "mouseover");
let overTargetAncestor = outTarget?.parent;
for (; overTargetAncestor && overTargetAncestor !== this.rootTarget.parent && overTargetAncestor !== e.target; )
overTargetAncestor = overTargetAncestor.parent;
if (!overTargetAncestor || overTargetAncestor === this.rootTarget.parent) {
const enterEvent = this.clonePointerEvent(e, "pointerenter");
for (enterEvent.eventPhase = enterEvent.AT_TARGET; enterEvent.target && enterEvent.target !== outTarget && enterEvent.target !== this.rootTarget.parent; )
enterEvent.currentTarget = enterEvent.target, this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter"), enterEvent.target = enterEvent.target.parent;
this.freeEvent(enterEvent);
}
this.freeEvent(overEvent);
}
const allMethods = [], allowGlobalPointerEvents = this.enableGlobalMoveEvents ?? !0;
this.moveOnAll ? allMethods.push("pointermove") : this.dispatchEvent(e, "pointermove"), allowGlobalPointerEvents && allMethods.push("globalpointermove"), e.pointerType === "touch" && (this.moveOnAll ? allMethods.splice(1, 0, "touchmove") : this.dispatchEvent(e, "touchmove"), allowGlobalPointerEvents && allMethods.push("globaltouchmove")), isMouse && (this.moveOnAll ? allMethods.splice(1, 0, "mousemove") : this.dispatchEvent(e, "mousemove"), allowGlobalPointerEvents && allMethods.push("globalmousemove"), this.cursor = e.target?.cursor), allMethods.length > 0 && this.all(e, allMethods), this._allInteractiveElements.length = 0, this._hitElements.length = 0, trackingData.overTargets = e.composedPath(), this.freeEvent(e);
}
/**
* Maps the upstream `pointerover` to downstream `pointerover` and `pointerenter` events, in that order.
*
* The tracking data for the specific pointer gets a new `overTarget`.
* @param from - The upstream `pointerover` event.
*/
mapPointerOver(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId), e = this.createPointerEvent(from), isMouse = e.pointerType === "mouse" || e.pointerType === "pen";
this.dispatchEvent(e, "pointerover"), isMouse && this.dispatchEvent(e, "mouseover"), e.pointerType === "mouse" && (this.cursor = e.target?.cursor);
const enterEvent = this.clonePointerEvent(e, "pointerenter");
for (enterEvent.eventPhase = enterEvent.AT_TARGET; enterEvent.target && enterEvent.target !== this.rootTarget.parent; )
enterEvent.currentTarget = enterEvent.target, this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter"), enterEvent.target = enterEvent.target.parent;
trackingData.overTargets = e.composedPath(), this.freeEvent(e), this.freeEvent(enterEvent);
}
/**
* Maps the upstream `pointerout` to downstream `pointerout`, `pointerleave` events, in that order.
*
* The tracking data for the specific pointer is cleared of a `overTarget`.
* @param from - The upstream `pointerout` event.
*/
mapPointerOut(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId);
if (trackingData.overTargets) {
const isMouse = from.pointerType === "mouse" || from.pointerType === "pen", outTarget = this.findMountedTarget(trackingData.overTargets), outEvent = this.createPointerEvent(from, "pointerout", outTarget);
this.dispatchEvent(outEvent), isMouse && this.dispatchEvent(outEvent, "mouseout");
const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget);
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; leaveEvent.target && leaveEvent.target !== this.rootTarget.parent; )
leaveEvent.currentTarget = leaveEvent.target, this.notifyTarget(leaveEvent), isMouse && this.notifyTarget(leaveEvent, "mouseleave"), leaveEvent.target = leaveEvent.target.parent;
trackingData.overTargets = null, this.freeEvent(outEvent), this.freeEvent(leaveEvent);
}
this.cursor = null;
}
/**
* Maps the upstream `pointerup` event to downstream `pointerup`, `pointerupoutside`,
* and `click`/`rightclick`/`pointertap` events, in that order.
*
* The `pointerupoutside` event bubbles from the original `pointerdown` target to the most specific
* ancestor of the `pointerdown` and `pointerup` targets, which is also the `click` event's target. `touchend`,
* `rightup`, `mouseup`, `touchendoutside`, `rightupoutside`, `mouseupoutside`, and `tap` are fired as well for
* specific pointer types.
* @param from - The upstream `pointerup` event.
*/
mapPointerUp(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const now = performance.now(), e = this.createPointerEvent(from);
if (this.dispatchEvent(e, "pointerup"), e.pointerType === "touch")
this.dispatchEvent(e, "touchend");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.dispatchEvent(e, isRightButton ? "rightup" : "mouseup");
}
const trackingData = this.trackingData(from.pointerId), pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);
let clickTarget = pressTarget;
if (pressTarget && !e.composedPath().includes(pressTarget)) {
let currentTarget = pressTarget;
for (; currentTarget && !e.composedPath().includes(currentTarget); ) {
if (e.currentTarget = currentTarget, this.notifyTarget(e, "pointerupoutside"), e.pointerType === "touch")
this.notifyTarget(e, "touchendoutside");
else if (e.pointerType === "mouse" || e.pointerType === "pen") {
const isRightButton = e.button === 2;
this.notifyTarget(e, isRightButton ? "rightupoutside" : "mouseupoutside");
}
currentTarget = currentTarget.parent;
}
delete trackingData.pressTargetsByButton[from.button], clickTarget = currentTarget;
}
if (clickTarget) {
const clickEvent = this.clonePointerEvent(e, "click");
clickEvent.target = clickTarget, clickEvent.path = null, trackingData.clicksByButton[from.button] || (trackingData.clicksByButton[from.button] = {
clickCount: 0,
target: clickEvent.target,
timeStamp: now
});
const clickHistory = trackingData.clicksByButton[from.button];
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < 200 ? ++clickHistory.clickCount : clickHistory.clickCount = 1, clickHistory.target = clickEvent.target, clickHistory.timeStamp = now, clickEvent.detail = clickHistory.clickCount, clickEvent.pointerType === "mouse") {
const isRightButton = clickEvent.button === 2;
this.dispatchEvent(clickEvent, isRightButton ? "rightclick" : "click");
} else
clickEvent.pointerType === "touch" && this.dispatchEvent(clickEvent, "tap");
this.dispatchEvent(clickEvent, "pointertap"), this.freeEvent(clickEvent);
}
this.freeEvent(e);
}
/**
* Maps the upstream `pointerupoutside` event to a downstream `pointerupoutside` event, bubbling from the original
* `pointerdown` target to `rootTarget`.
*
* (The most specific ancestor of the `pointerdown` event and the `pointerup` event must the
* `{@link PIXI.EventBoundary}'s root because the `pointerup` event occurred outside of the boundary.)
*
* `touchendoutside`, `mouseupoutside`, and `rightupoutside` events are fired as well for specific pointer
* types. The tracking data for the specific pointer is cleared of a `pressTarget`.
* @param from - The upstream `pointerupoutside` event.
*/
mapPointerUpOutside(from) {
if (!(from instanceof FederatedPointerEvent)) {
console.warn("EventBoundary cannot map a non-pointer event as a pointer event");
return;
}
const trackingData = this.trackingData(from.pointerId), pressTarget = this.findMountedTarget(trackingData.pressTargetsByButton[from.button]), e = this.createPointerEvent(from);
if (pressTarget) {
let currentTarget = pressTarget;
for (; currentTarget; )
e.currentTarget = currentTarget, this.notifyTarget(e, "pointerupoutside"), e.pointerType === "touch" ? this.notifyTarget(e, "touchendoutside") : (e.pointerType === "mouse" || e.pointerType === "pen") && this.notifyTarget(e, e.button === 2 ? "rightupoutside" : "mouseupoutside"), currentTarget = currentTarget.parent;
delete trackingData.pressTargetsByButton[from.button];
}
this.freeEvent(e);
}
/**
* Maps the upstream `wheel` event to a downstream `wheel` event.
* @param from - The upstream `wheel` event.
*/
mapWheel(from) {
if (!(from instanceof FederatedWheelEvent)) {
console.warn("EventBoundary cannot map a non-wheel event as a wheel event");
return;
}
const wheelEvent = this.createWheelEvent(from);
this.dispatchEvent(wheelEvent), this.freeEvent(wheelEvent);
}
/**
* Finds the most specific event-target in the given propagation path that is still mounted in the scene graph.
*
* This is used to find the correct `pointerup` and `pointerout` target in the case that the original `pointerdown`
* or `pointerover` target was unmounted from the scene graph.
* @param propagationPath - The propagation path was valid in the past.
* @returns - The most specific event-target still mounted at the same location in the scene graph.
*/
findMountedTarget(propagationPath) {
if (!propagationPath)
return null;
let currentTarget = propagationPath[0];
for (let i = 1; i < propagationPath.length && propagationPath[i].parent === currentTarget; i++)
currentTarget = propagationPath[i];
return currentTarget;
}
/**
* Creates an event whose {@code originalEvent} is {@code from}, with an optional `type` and `target` override.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The {@code originalEvent} for the returned event.
* @param [type=from.type] - The type of the returned event.
* @param target - The target of the returned event.
*/
createPointerEvent(from, type, target) {
const event = this.allocateEvent(FederatedPointerEvent);
return this.copyPointerData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = target ?? this.hitTest(event.global.x, event.global.y) ?? this._hitElements[0], typeof type == "string" && (event.type = type), event;
}
/**
* Creates a wheel event whose {@code originalEvent} is {@code from}.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The upstream wheel event.
*/
createWheelEvent(from) {
const event = this.allocateEvent(FederatedWheelEvent);
return this.copyWheelData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = this.hitTest(event.global.x, event.global.y), event;
}
/**
* Clones the event {@code from}, with an optional {@code type} override.
*
* The event is allocated using {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}.
* @param from - The event to clone.
* @param [type=from.type] - The type of the returned event.
*/
clonePointerEvent(from, type) {
const event = this.allocateEvent(FederatedPointerEvent);
return event.nativeEvent = from.nativeEvent, event.originalEvent = from.originalEvent, this.copyPointerData(from, event), this.copyMouseData(from, event), this.copyData(from, event), event.target = from.target, event.path = from.composedPath().slice(), event.type = type ?? event.type, event;
}
/**
* Copies wheel {@link PIXI.FederatedWheelEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + deltaMode
* + deltaX
* + deltaY
* + deltaZ
* @param from
* @param to
*/
copyWheelData(from, to) {
to.deltaMode = from.deltaMode, to.deltaX = from.deltaX, to.deltaY = from.deltaY, to.deltaZ = from.deltaZ;
}
/**
* Copies pointer {@link PIXI.FederatedPointerEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + pointerId
* + width
* + height
* + isPrimary
* + pointerType
* + pressure
* + tangentialPressure
* + tiltX
* + tiltY
* @param from
* @param to
*/
copyPointerData(from, to) {
from instanceof FederatedPointerEvent && to instanceof FederatedPointerEvent && (to.pointerId = from.pointerId, to.width = from.width, to.height = from.height, to.isPrimary = from.isPrimary, to.pointerType = from.pointerType, to.pressure = from.pressure, to.tangentialPressure = from.tangentialPressure, to.tiltX = from.tiltX, to.tiltY = from.tiltY, to.twist = from.twist);
}
/**
* Copies mouse {@link PIXI.FederatedMouseEvent} data from {@code from} to {@code to}.
*
* The following properties are copied:
* + altKey
* + button
* + buttons
* + clientX
* + clientY
* + metaKey
* + movementX
* + movementY
* + pageX
* + pageY
* + x
* + y
* + screen
* + shiftKey
* + global
* @param from
* @param to
*/
copyMouseData(from, to) {
from instanceof FederatedMouseEvent && to instanceof FederatedMouseEvent && (to.altKey = from.altKey, to.button = from.button, to.buttons = from.buttons, to.client.copyFrom(from.client), to.ctrlKey = from.ctrlKey, to.metaKey = from.metaKey, to.movement.copyFrom(from.movement), to.screen.copyFrom(from.screen), to.shiftKey = from.shiftKey, to.global.copyFrom(from.global));
}
/**
* Copies base {@link PIXI.FederatedEvent} data from {@code from} into {@code to}.
*
* The following properties are copied:
* + isTrusted
* + srcElement
* + timeStamp
* + type
* @param from - The event to copy data from.
* @param to - The event to copy data into.
*/
copyData(from, to) {
to.isTrusted = from.isTrusted, to.srcElement = from.srcElement, to.timeStamp = performance.now(), to.type = from.type, to.detail = from.detail, to.view = from.view, to.which = from.which, to.layer.copyFrom(from.layer), to.page.copyFrom(from.page);
}
/**
* @param id - The pointer ID.
* @returns The tracking data stored for the given pointer. If no data exists, a blank
* state will be created.
*/
trackingData(id) {
return this.mappingState.trackingData[id] || (this.mappingState.trackingData[id] = {
pressTargetsByButton: {},
clicksByButton: {},
overTarget: null
}), this.mappingState.trackingData[id];
}
/**
* Allocate a specific type of event from {@link PIXI.EventBoundary#eventPool this.eventPool}.
*
* This allocation is constructor-agnostic, as long as it only takes one argument - this event
* boundary.
* @param constructor - The event's constructor.
*/
allocateEvent(constructor) {
this.eventPool.has(constructor) || this.eventPool.set(constructor, []);
const event = this.eventPool.get(constructor).pop() || new constructor(this);
return event.eventPhase = event.NONE, event.currentTarget = null, event.path = null, event.target = null, event;
}
/**
* Frees the event and puts it back into the event pool.
*
* It is illegal to reuse the event until it is allocated again, using `this.allocateEvent`.
*
* It is also advised that events not allocated from {@link PIXI.EventBoundary#allocateEvent this.allocateEvent}
* not be freed. This is because of the possibility that the same event is freed twice, which can cause
* it to be allocated twice & result in overwriting.
* @param event - The event to be freed.
* @throws Error if the event is managed by another event boundary.
*/
freeEvent(event) {
if (event.manager !== this)
throw new Error("It is illegal to free an event not managed by this EventBoundary!");
const constructor = event.constructor;
this.eventPool.has(constructor) || this.eventPool.set(constructor, []), this.eventPool.get(constructor).push(event);
}
/**
* Similar to {@link PIXI.EventEmitter.emit}, except it stops if the `propagationImmediatelyStopped` flag
* is set on the event.
* @param e - The event to call each listener with.
* @param type - The event key.
*/
notifyListeners(e, type) {
const listeners = e.currentTarget._events[type];
if (listeners && e.currentTarget.isInteractive())
if ("fn" in listeners)
listeners.once && e.currentTarget.removeListener(type, listeners.fn, void 0, !0), listeners.fn.call(listeners.context, e);
else
for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++)
listeners[i].once && e.currentTarget.removeListener(type, listeners[i].fn, void 0, !0), listeners[i].fn.call(listeners[i].context, e);
}
}
export {
EventBoundary
};
//# sourceMappingURL=EventBoundary.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,274 @@
"use strict";
var core = require("@pixi/core"), EventBoundary = require("./EventBoundary.js"), EventTicker = require("./EventTicker.js"), FederatedPointerEvent = require("./FederatedPointerEvent.js"), FederatedWheelEvent = require("./FederatedWheelEvent.js");
const MOUSE_POINTER_ID = 1, TOUCH_TO_POINTER = {
touchstart: "pointerdown",
touchend: "pointerup",
touchendoutside: "pointerupoutside",
touchmove: "pointermove",
touchcancel: "pointercancel"
}, _EventSystem = class _EventSystem2 {
/**
* @param {PIXI.Renderer} renderer
*/
constructor(renderer) {
this.supportsTouchEvents = "ontouchstart" in globalThis, this.supportsPointerEvents = !!globalThis.PointerEvent, this.domElement = null, this.resolution = 1, this.renderer = renderer, this.rootBoundary = new EventBoundary.EventBoundary(null), EventTicker.EventsTicker.init(this), this.autoPreventDefault = !0, this.eventsAdded = !1, this.rootPointerEvent = new FederatedPointerEvent.FederatedPointerEvent(null), this.rootWheelEvent = new FederatedWheelEvent.FederatedWheelEvent(null), this.cursorStyles = {
default: "inherit",
pointer: "pointer"
}, this.features = new Proxy({ ..._EventSystem2.defaultEventFeatures }, {
set: (target, key, value) => (key === "globalMove" && (this.rootBoundary.enableGlobalMoveEvents = value), target[key] = value, !0)
}), 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);
}
/**
* The default interaction mode for all display objects.
* @see PIXI.DisplayObject.eventMode
* @type {PIXI.EventMode}
* @readonly
* @since 7.2.0
*/
static get defaultEventMode() {
return this._defaultEventMode;
}
/**
* Runner init called, view is available at this point.
* @ignore
*/
init(options) {
const { view, resolution } = this.renderer;
this.setTargetElement(view), this.resolution = resolution, _EventSystem2._defaultEventMode = options.eventMode ?? "auto", Object.assign(this.features, options.eventFeatures ?? {}), this.rootBoundary.enableGlobalMoveEvents = this.features.globalMove;
}
/**
* Handle changing resolution.
* @ignore
*/
resolutionChange(resolution) {
this.resolution = resolution;
}
/** Destroys all event listeners and detaches the renderer. */
destroy() {
this.setTargetElement(null), this.renderer = null;
}
/**
* Sets the current cursor mode, handling any callbacks or CSS style changes.
* @param mode - cursor mode, a key from the cursorStyles dictionary
*/
setCursor(mode) {
mode = mode || "default";
let applyStyles = !0;
if (globalThis.OffscreenCanvas && this.domElement instanceof OffscreenCanvas && (applyStyles = !1), this.currentCursor === mode)
return;
this.currentCursor = mode;
const style = this.cursorStyles[mode];
if (style)
switch (typeof style) {
case "string":
applyStyles && (this.domElement.style.cursor = style);
break;
case "function":
style(mode);
break;
case "object":
applyStyles && Object.assign(this.domElement.style, style);
break;
}
else
applyStyles && typeof mode == "string" && !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode) && (this.domElement.style.cursor = mode);
}
/**
* The global pointer event.
* Useful for getting the pointer position without listening to events.
* @since 7.2.0
*/
get pointer() {
return this.rootPointerEvent;
}
/**
* Event handler for pointer down events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerDown(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
const events = this.normalizeToPointerData(nativeEvent);
this.autoPreventDefault && events[0].isNormalized && (nativeEvent.cancelable || !("cancelable" in nativeEvent)) && nativeEvent.preventDefault();
for (let i = 0, j = events.length; i < j; i++) {
const nativeEvent2 = events[i], federatedEvent = this.bootstrapEvent(this.rootPointerEvent, nativeEvent2);
this.rootBoundary.mapEvent(federatedEvent);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer move events on on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch events.
*/
onPointerMove(nativeEvent) {
if (!this.features.move)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, EventTicker.EventsTicker.pointerMoved();
const normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer up events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerUp(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
let target = nativeEvent.target;
nativeEvent.composedPath && nativeEvent.composedPath().length > 0 && (target = nativeEvent.composedPath()[0]);
const outside = target !== this.domElement ? "outside" : "", normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
event.type += outside, this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer over & out events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerOverOut(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
const normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Passive handler for `wheel` events on {@link PIXI.EventSystem.domElement this.domElement}.
* @param nativeEvent - The native wheel event.
*/
onWheel(nativeEvent) {
if (!this.features.wheel)
return;
const wheelEvent = this.normalizeWheelEvent(nativeEvent);
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, this.rootBoundary.mapEvent(wheelEvent);
}
/**
* Sets the {@link PIXI.EventSystem#domElement domElement} and binds event listeners.
*
* To deregister the current DOM element without setting a new one, pass {@code null}.
* @param element - The new DOM element.
*/
setTargetElement(element) {
this.removeEvents(), this.domElement = element, EventTicker.EventsTicker.domElement = element, this.addEvents();
}
/** Register event listeners on {@link PIXI.Renderer#domElement this.domElement}. */
addEvents() {
if (this.eventsAdded || !this.domElement)
return;
EventTicker.EventsTicker.addTickerListener();
const style = this.domElement.style;
style && (globalThis.navigator.msPointerEnabled ? (style.msContentZooming = "none", style.msTouchAction = "none") : this.supportsPointerEvents && (style.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, {
passive: !0,
capture: !0
}), this.eventsAdded = !0;
}
/** Unregister event listeners on {@link PIXI.EventSystem#domElement this.domElement}. */
removeEvents() {
if (!this.eventsAdded || !this.domElement)
return;
EventTicker.EventsTicker.removeTickerListener();
const style = this.domElement.style;
globalThis.navigator.msPointerEnabled ? (style.msContentZooming = "", style.msTouchAction = "") : this.supportsPointerEvents && (style.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;
}
/**
* Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
* resulting value is stored in the point. This takes into account the fact that the DOM
* element could be scaled and positioned anywhere on the screen.
* @param {PIXI.IPointData} point - the point that the result will be stored in
* @param {number} x - the x coord of the position to map
* @param {number} y - the y coord of the position to map
*/
mapPositionToPoint(point, x, y) {
const rect = this.domElement.isConnected ? this.domElement.getBoundingClientRect() : {
x: 0,
y: 0,
width: this.domElement.width,
height: this.domElement.height,
left: 0,
top: 0
}, resolutionMultiplier = 1 / this.resolution;
point.x = (x - rect.left) * (this.domElement.width / rect.width) * resolutionMultiplier, point.y = (y - rect.top) * (this.domElement.height / rect.height) * resolutionMultiplier;
}
/**
* Ensures that the original event object contains all data that a regular pointer event would have
* @param event - The original event data from a touch or mouse event
* @returns An array containing a single normalized pointer event, in the case of a pointer
* or mouse event, or a multiple normalized pointer events if there are multiple changed touches
*/
normalizeToPointerData(event) {
const normalizedEvents = [];
if (this.supportsTouchEvents && event instanceof TouchEvent)
for (let i = 0, li = event.changedTouches.length; i < li; i++) {
const touch = event.changedTouches[i];
typeof touch.button > "u" && (touch.button = 0), typeof touch.buttons > "u" && (touch.buttons = 1), typeof touch.isPrimary > "u" && (touch.isPrimary = event.touches.length === 1 && event.type === "touchstart"), typeof touch.width > "u" && (touch.width = touch.radiusX || 1), typeof touch.height > "u" && (touch.height = touch.radiusY || 1), typeof touch.tiltX > "u" && (touch.tiltX = 0), typeof touch.tiltY > "u" && (touch.tiltY = 0), typeof touch.pointerType > "u" && (touch.pointerType = "touch"), typeof touch.pointerId > "u" && (touch.pointerId = touch.identifier || 0), typeof touch.pressure > "u" && (touch.pressure = touch.force || 0.5), typeof touch.twist > "u" && (touch.twist = 0), typeof touch.tangentialPressure > "u" && (touch.tangentialPressure = 0), typeof touch.layerX > "u" && (touch.layerX = touch.offsetX = touch.clientX), typeof touch.layerY > "u" && (touch.layerY = touch.offsetY = touch.clientY), touch.isNormalized = !0, touch.type = event.type, normalizedEvents.push(touch);
}
else if (!globalThis.MouseEvent || event instanceof MouseEvent && (!this.supportsPointerEvents || !(event instanceof globalThis.PointerEvent))) {
const tempEvent = event;
typeof tempEvent.isPrimary > "u" && (tempEvent.isPrimary = !0), typeof tempEvent.width > "u" && (tempEvent.width = 1), typeof tempEvent.height > "u" && (tempEvent.height = 1), typeof tempEvent.tiltX > "u" && (tempEvent.tiltX = 0), typeof tempEvent.tiltY > "u" && (tempEvent.tiltY = 0), typeof tempEvent.pointerType > "u" && (tempEvent.pointerType = "mouse"), typeof tempEvent.pointerId > "u" && (tempEvent.pointerId = MOUSE_POINTER_ID), typeof tempEvent.pressure > "u" && (tempEvent.pressure = 0.5), typeof tempEvent.twist > "u" && (tempEvent.twist = 0), typeof tempEvent.tangentialPressure > "u" && (tempEvent.tangentialPressure = 0), tempEvent.isNormalized = !0, normalizedEvents.push(tempEvent);
} else
normalizedEvents.push(event);
return normalizedEvents;
}
/**
* Normalizes the native {@link https://w3c.github.io/uievents/#interface-wheelevent WheelEvent}.
*
* The returned {@link PIXI.FederatedWheelEvent} is a shared instance. It will not persist across
* multiple native wheel events.
* @param nativeEvent - The native wheel event that occurred on the canvas.
* @returns A federated wheel event.
*/
normalizeWheelEvent(nativeEvent) {
const event = this.rootWheelEvent;
return this.transferMouseData(event, nativeEvent), event.deltaX = nativeEvent.deltaX, event.deltaY = nativeEvent.deltaY, event.deltaZ = nativeEvent.deltaZ, event.deltaMode = nativeEvent.deltaMode, this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY), event.global.copyFrom(event.screen), event.offset.copyFrom(event.screen), event.nativeEvent = nativeEvent, event.type = nativeEvent.type, event;
}
/**
* Normalizes the `nativeEvent` into a federateed {@link PIXI.FederatedPointerEvent}.
* @param event
* @param nativeEvent
*/
bootstrapEvent(event, nativeEvent) {
return event.originalEvent = null, event.nativeEvent = nativeEvent, event.pointerId = nativeEvent.pointerId, event.width = nativeEvent.width, event.height = nativeEvent.height, event.isPrimary = nativeEvent.isPrimary, event.pointerType = nativeEvent.pointerType, event.pressure = nativeEvent.pressure, event.tangentialPressure = nativeEvent.tangentialPressure, event.tiltX = nativeEvent.tiltX, event.tiltY = nativeEvent.tiltY, event.twist = nativeEvent.twist, this.transferMouseData(event, nativeEvent), this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY), event.global.copyFrom(event.screen), event.offset.copyFrom(event.screen), event.isTrusted = nativeEvent.isTrusted, event.type === "pointerleave" && (event.type = "pointerout"), event.type.startsWith("mouse") && (event.type = event.type.replace("mouse", "pointer")), event.type.startsWith("touch") && (event.type = TOUCH_TO_POINTER[event.type] || event.type), event;
}
/**
* Transfers base & mouse event data from the {@code nativeEvent} to the federated event.
* @param event
* @param nativeEvent
*/
transferMouseData(event, nativeEvent) {
event.isTrusted = nativeEvent.isTrusted, event.srcElement = nativeEvent.srcElement, event.timeStamp = performance.now(), event.type = nativeEvent.type, event.altKey = nativeEvent.altKey, event.button = nativeEvent.button, event.buttons = nativeEvent.buttons, event.client.x = nativeEvent.clientX, event.client.y = nativeEvent.clientY, event.ctrlKey = nativeEvent.ctrlKey, event.metaKey = nativeEvent.metaKey, event.movement.x = nativeEvent.movementX, event.movement.y = nativeEvent.movementY, event.page.x = nativeEvent.pageX, event.page.y = nativeEvent.pageY, event.relatedTarget = null, event.shiftKey = nativeEvent.shiftKey;
}
};
_EventSystem.extension = {
name: "events",
type: [
core.ExtensionType.RendererSystem,
core.ExtensionType.CanvasRendererSystem
]
}, /**
* The event features that are enabled by the EventSystem
* This option only is available when using **@pixi/events** package
* (included in the **pixi.js** and **pixi.js-legacy** bundle), otherwise it will be ignored.
* @since 7.2.0
*/
_EventSystem.defaultEventFeatures = {
move: !0,
globalMove: !0,
click: !0,
wheel: !0
};
let EventSystem = _EventSystem;
core.extensions.add(EventSystem);
exports.EventSystem = EventSystem;
//# sourceMappingURL=EventSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,279 @@
import { ExtensionType, extensions } from "@pixi/core";
import { EventBoundary } from "./EventBoundary.mjs";
import { EventsTicker } from "./EventTicker.mjs";
import { FederatedPointerEvent } from "./FederatedPointerEvent.mjs";
import { FederatedWheelEvent } from "./FederatedWheelEvent.mjs";
const MOUSE_POINTER_ID = 1, TOUCH_TO_POINTER = {
touchstart: "pointerdown",
touchend: "pointerup",
touchendoutside: "pointerupoutside",
touchmove: "pointermove",
touchcancel: "pointercancel"
}, _EventSystem = class _EventSystem2 {
/**
* @param {PIXI.Renderer} renderer
*/
constructor(renderer) {
this.supportsTouchEvents = "ontouchstart" in globalThis, this.supportsPointerEvents = !!globalThis.PointerEvent, this.domElement = null, this.resolution = 1, this.renderer = renderer, this.rootBoundary = new EventBoundary(null), EventsTicker.init(this), this.autoPreventDefault = !0, this.eventsAdded = !1, this.rootPointerEvent = new FederatedPointerEvent(null), this.rootWheelEvent = new FederatedWheelEvent(null), this.cursorStyles = {
default: "inherit",
pointer: "pointer"
}, this.features = new Proxy({ ..._EventSystem2.defaultEventFeatures }, {
set: (target, key, value) => (key === "globalMove" && (this.rootBoundary.enableGlobalMoveEvents = value), target[key] = value, !0)
}), 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);
}
/**
* The default interaction mode for all display objects.
* @see PIXI.DisplayObject.eventMode
* @type {PIXI.EventMode}
* @readonly
* @since 7.2.0
*/
static get defaultEventMode() {
return this._defaultEventMode;
}
/**
* Runner init called, view is available at this point.
* @ignore
*/
init(options) {
const { view, resolution } = this.renderer;
this.setTargetElement(view), this.resolution = resolution, _EventSystem2._defaultEventMode = options.eventMode ?? "auto", Object.assign(this.features, options.eventFeatures ?? {}), this.rootBoundary.enableGlobalMoveEvents = this.features.globalMove;
}
/**
* Handle changing resolution.
* @ignore
*/
resolutionChange(resolution) {
this.resolution = resolution;
}
/** Destroys all event listeners and detaches the renderer. */
destroy() {
this.setTargetElement(null), this.renderer = null;
}
/**
* Sets the current cursor mode, handling any callbacks or CSS style changes.
* @param mode - cursor mode, a key from the cursorStyles dictionary
*/
setCursor(mode) {
mode = mode || "default";
let applyStyles = !0;
if (globalThis.OffscreenCanvas && this.domElement instanceof OffscreenCanvas && (applyStyles = !1), this.currentCursor === mode)
return;
this.currentCursor = mode;
const style = this.cursorStyles[mode];
if (style)
switch (typeof style) {
case "string":
applyStyles && (this.domElement.style.cursor = style);
break;
case "function":
style(mode);
break;
case "object":
applyStyles && Object.assign(this.domElement.style, style);
break;
}
else
applyStyles && typeof mode == "string" && !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode) && (this.domElement.style.cursor = mode);
}
/**
* The global pointer event.
* Useful for getting the pointer position without listening to events.
* @since 7.2.0
*/
get pointer() {
return this.rootPointerEvent;
}
/**
* Event handler for pointer down events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerDown(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
const events = this.normalizeToPointerData(nativeEvent);
this.autoPreventDefault && events[0].isNormalized && (nativeEvent.cancelable || !("cancelable" in nativeEvent)) && nativeEvent.preventDefault();
for (let i = 0, j = events.length; i < j; i++) {
const nativeEvent2 = events[i], federatedEvent = this.bootstrapEvent(this.rootPointerEvent, nativeEvent2);
this.rootBoundary.mapEvent(federatedEvent);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer move events on on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch events.
*/
onPointerMove(nativeEvent) {
if (!this.features.move)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, EventsTicker.pointerMoved();
const normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer up events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerUp(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
let target = nativeEvent.target;
nativeEvent.composedPath && nativeEvent.composedPath().length > 0 && (target = nativeEvent.composedPath()[0]);
const outside = target !== this.domElement ? "outside" : "", normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
event.type += outside, this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Event handler for pointer over & out events on {@link PIXI.EventSystem#domElement this.domElement}.
* @param nativeEvent - The native mouse/pointer/touch event.
*/
onPointerOverOut(nativeEvent) {
if (!this.features.click)
return;
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered;
const normalizedEvents = this.normalizeToPointerData(nativeEvent);
for (let i = 0, j = normalizedEvents.length; i < j; i++) {
const event = this.bootstrapEvent(this.rootPointerEvent, normalizedEvents[i]);
this.rootBoundary.mapEvent(event);
}
this.setCursor(this.rootBoundary.cursor);
}
/**
* Passive handler for `wheel` events on {@link PIXI.EventSystem.domElement this.domElement}.
* @param nativeEvent - The native wheel event.
*/
onWheel(nativeEvent) {
if (!this.features.wheel)
return;
const wheelEvent = this.normalizeWheelEvent(nativeEvent);
this.rootBoundary.rootTarget = this.renderer.lastObjectRendered, this.rootBoundary.mapEvent(wheelEvent);
}
/**
* Sets the {@link PIXI.EventSystem#domElement domElement} and binds event listeners.
*
* To deregister the current DOM element without setting a new one, pass {@code null}.
* @param element - The new DOM element.
*/
setTargetElement(element) {
this.removeEvents(), this.domElement = element, EventsTicker.domElement = element, this.addEvents();
}
/** Register event listeners on {@link PIXI.Renderer#domElement this.domElement}. */
addEvents() {
if (this.eventsAdded || !this.domElement)
return;
EventsTicker.addTickerListener();
const style = this.domElement.style;
style && (globalThis.navigator.msPointerEnabled ? (style.msContentZooming = "none", style.msTouchAction = "none") : this.supportsPointerEvents && (style.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, {
passive: !0,
capture: !0
}), this.eventsAdded = !0;
}
/** Unregister event listeners on {@link PIXI.EventSystem#domElement this.domElement}. */
removeEvents() {
if (!this.eventsAdded || !this.domElement)
return;
EventsTicker.removeTickerListener();
const style = this.domElement.style;
globalThis.navigator.msPointerEnabled ? (style.msContentZooming = "", style.msTouchAction = "") : this.supportsPointerEvents && (style.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;
}
/**
* Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The
* resulting value is stored in the point. This takes into account the fact that the DOM
* element could be scaled and positioned anywhere on the screen.
* @param {PIXI.IPointData} point - the point that the result will be stored in
* @param {number} x - the x coord of the position to map
* @param {number} y - the y coord of the position to map
*/
mapPositionToPoint(point, x, y) {
const rect = this.domElement.isConnected ? this.domElement.getBoundingClientRect() : {
x: 0,
y: 0,
width: this.domElement.width,
height: this.domElement.height,
left: 0,
top: 0
}, resolutionMultiplier = 1 / this.resolution;
point.x = (x - rect.left) * (this.domElement.width / rect.width) * resolutionMultiplier, point.y = (y - rect.top) * (this.domElement.height / rect.height) * resolutionMultiplier;
}
/**
* Ensures that the original event object contains all data that a regular pointer event would have
* @param event - The original event data from a touch or mouse event
* @returns An array containing a single normalized pointer event, in the case of a pointer
* or mouse event, or a multiple normalized pointer events if there are multiple changed touches
*/
normalizeToPointerData(event) {
const normalizedEvents = [];
if (this.supportsTouchEvents && event instanceof TouchEvent)
for (let i = 0, li = event.changedTouches.length; i < li; i++) {
const touch = event.changedTouches[i];
typeof touch.button > "u" && (touch.button = 0), typeof touch.buttons > "u" && (touch.buttons = 1), typeof touch.isPrimary > "u" && (touch.isPrimary = event.touches.length === 1 && event.type === "touchstart"), typeof touch.width > "u" && (touch.width = touch.radiusX || 1), typeof touch.height > "u" && (touch.height = touch.radiusY || 1), typeof touch.tiltX > "u" && (touch.tiltX = 0), typeof touch.tiltY > "u" && (touch.tiltY = 0), typeof touch.pointerType > "u" && (touch.pointerType = "touch"), typeof touch.pointerId > "u" && (touch.pointerId = touch.identifier || 0), typeof touch.pressure > "u" && (touch.pressure = touch.force || 0.5), typeof touch.twist > "u" && (touch.twist = 0), typeof touch.tangentialPressure > "u" && (touch.tangentialPressure = 0), typeof touch.layerX > "u" && (touch.layerX = touch.offsetX = touch.clientX), typeof touch.layerY > "u" && (touch.layerY = touch.offsetY = touch.clientY), touch.isNormalized = !0, touch.type = event.type, normalizedEvents.push(touch);
}
else if (!globalThis.MouseEvent || event instanceof MouseEvent && (!this.supportsPointerEvents || !(event instanceof globalThis.PointerEvent))) {
const tempEvent = event;
typeof tempEvent.isPrimary > "u" && (tempEvent.isPrimary = !0), typeof tempEvent.width > "u" && (tempEvent.width = 1), typeof tempEvent.height > "u" && (tempEvent.height = 1), typeof tempEvent.tiltX > "u" && (tempEvent.tiltX = 0), typeof tempEvent.tiltY > "u" && (tempEvent.tiltY = 0), typeof tempEvent.pointerType > "u" && (tempEvent.pointerType = "mouse"), typeof tempEvent.pointerId > "u" && (tempEvent.pointerId = MOUSE_POINTER_ID), typeof tempEvent.pressure > "u" && (tempEvent.pressure = 0.5), typeof tempEvent.twist > "u" && (tempEvent.twist = 0), typeof tempEvent.tangentialPressure > "u" && (tempEvent.tangentialPressure = 0), tempEvent.isNormalized = !0, normalizedEvents.push(tempEvent);
} else
normalizedEvents.push(event);
return normalizedEvents;
}
/**
* Normalizes the native {@link https://w3c.github.io/uievents/#interface-wheelevent WheelEvent}.
*
* The returned {@link PIXI.FederatedWheelEvent} is a shared instance. It will not persist across
* multiple native wheel events.
* @param nativeEvent - The native wheel event that occurred on the canvas.
* @returns A federated wheel event.
*/
normalizeWheelEvent(nativeEvent) {
const event = this.rootWheelEvent;
return this.transferMouseData(event, nativeEvent), event.deltaX = nativeEvent.deltaX, event.deltaY = nativeEvent.deltaY, event.deltaZ = nativeEvent.deltaZ, event.deltaMode = nativeEvent.deltaMode, this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY), event.global.copyFrom(event.screen), event.offset.copyFrom(event.screen), event.nativeEvent = nativeEvent, event.type = nativeEvent.type, event;
}
/**
* Normalizes the `nativeEvent` into a federateed {@link PIXI.FederatedPointerEvent}.
* @param event
* @param nativeEvent
*/
bootstrapEvent(event, nativeEvent) {
return event.originalEvent = null, event.nativeEvent = nativeEvent, event.pointerId = nativeEvent.pointerId, event.width = nativeEvent.width, event.height = nativeEvent.height, event.isPrimary = nativeEvent.isPrimary, event.pointerType = nativeEvent.pointerType, event.pressure = nativeEvent.pressure, event.tangentialPressure = nativeEvent.tangentialPressure, event.tiltX = nativeEvent.tiltX, event.tiltY = nativeEvent.tiltY, event.twist = nativeEvent.twist, this.transferMouseData(event, nativeEvent), this.mapPositionToPoint(event.screen, nativeEvent.clientX, nativeEvent.clientY), event.global.copyFrom(event.screen), event.offset.copyFrom(event.screen), event.isTrusted = nativeEvent.isTrusted, event.type === "pointerleave" && (event.type = "pointerout"), event.type.startsWith("mouse") && (event.type = event.type.replace("mouse", "pointer")), event.type.startsWith("touch") && (event.type = TOUCH_TO_POINTER[event.type] || event.type), event;
}
/**
* Transfers base & mouse event data from the {@code nativeEvent} to the federated event.
* @param event
* @param nativeEvent
*/
transferMouseData(event, nativeEvent) {
event.isTrusted = nativeEvent.isTrusted, event.srcElement = nativeEvent.srcElement, event.timeStamp = performance.now(), event.type = nativeEvent.type, event.altKey = nativeEvent.altKey, event.button = nativeEvent.button, event.buttons = nativeEvent.buttons, event.client.x = nativeEvent.clientX, event.client.y = nativeEvent.clientY, event.ctrlKey = nativeEvent.ctrlKey, event.metaKey = nativeEvent.metaKey, event.movement.x = nativeEvent.movementX, event.movement.y = nativeEvent.movementY, event.page.x = nativeEvent.pageX, event.page.y = nativeEvent.pageY, event.relatedTarget = null, event.shiftKey = nativeEvent.shiftKey;
}
};
_EventSystem.extension = {
name: "events",
type: [
ExtensionType.RendererSystem,
ExtensionType.CanvasRendererSystem
]
}, /**
* The event features that are enabled by the EventSystem
* This option only is available when using **@pixi/events** package
* (included in the **pixi.js** and **pixi.js-legacy** bundle), otherwise it will be ignored.
* @since 7.2.0
*/
_EventSystem.defaultEventFeatures = {
move: !0,
globalMove: !0,
click: !0,
wheel: !0
};
let EventSystem = _EventSystem;
extensions.add(EventSystem);
export {
EventSystem
};
//# sourceMappingURL=EventSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,60 @@
"use strict";
var core = require("@pixi/core");
class EventsTickerClass {
constructor() {
this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this.tickerAdded = !1, this._pauseUpdate = !0;
}
/**
* Initializes the event ticker.
* @param events - The event system.
*/
init(events) {
this.removeTickerListener(), this.events = events, this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this.tickerAdded = !1, this._pauseUpdate = !0;
}
/** Whether to pause the update checks or not. */
get pauseUpdate() {
return this._pauseUpdate;
}
set pauseUpdate(paused) {
this._pauseUpdate = paused;
}
/** Adds the ticker listener. */
addTickerListener() {
this.tickerAdded || !this.domElement || (core.Ticker.system.add(this.tickerUpdate, this, core.UPDATE_PRIORITY.INTERACTION), this.tickerAdded = !0);
}
/** Removes the ticker listener. */
removeTickerListener() {
this.tickerAdded && (core.Ticker.system.remove(this.tickerUpdate, this), this.tickerAdded = !1);
}
/** Sets flag to not fire extra events when the user has already moved there mouse */
pointerMoved() {
this._didMove = !0;
}
/** Updates the state of interactive objects. */
update() {
if (!this.domElement || this._pauseUpdate)
return;
if (this._didMove) {
this._didMove = !1;
return;
}
const rootPointerEvent = this.events.rootPointerEvent;
this.events.supportsTouchEvents && rootPointerEvent.pointerType === "touch" || globalThis.document.dispatchEvent(new PointerEvent("pointermove", {
clientX: rootPointerEvent.clientX,
clientY: rootPointerEvent.clientY
}));
}
/**
* Updates the state of interactive objects if at least {@link PIXI.EventsTicker#interactionFrequency}
* milliseconds have passed since the last invocation.
*
* Invoked by a throttled ticker update from {@link PIXI.Ticker.system}.
* @param deltaTime - time delta since the last call
*/
tickerUpdate(deltaTime) {
this._deltaTime += deltaTime, !(this._deltaTime < this.interactionFrequency) && (this._deltaTime = 0, this.update());
}
}
const EventsTicker = new EventsTickerClass();
exports.EventsTicker = EventsTicker;
//# sourceMappingURL=EventTicker.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,61 @@
import { Ticker, UPDATE_PRIORITY } from "@pixi/core";
class EventsTickerClass {
constructor() {
this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this.tickerAdded = !1, this._pauseUpdate = !0;
}
/**
* Initializes the event ticker.
* @param events - The event system.
*/
init(events) {
this.removeTickerListener(), this.events = events, this.interactionFrequency = 10, this._deltaTime = 0, this._didMove = !1, this.tickerAdded = !1, this._pauseUpdate = !0;
}
/** Whether to pause the update checks or not. */
get pauseUpdate() {
return this._pauseUpdate;
}
set pauseUpdate(paused) {
this._pauseUpdate = paused;
}
/** Adds the ticker listener. */
addTickerListener() {
this.tickerAdded || !this.domElement || (Ticker.system.add(this.tickerUpdate, this, UPDATE_PRIORITY.INTERACTION), this.tickerAdded = !0);
}
/** Removes the ticker listener. */
removeTickerListener() {
this.tickerAdded && (Ticker.system.remove(this.tickerUpdate, this), this.tickerAdded = !1);
}
/** Sets flag to not fire extra events when the user has already moved there mouse */
pointerMoved() {
this._didMove = !0;
}
/** Updates the state of interactive objects. */
update() {
if (!this.domElement || this._pauseUpdate)
return;
if (this._didMove) {
this._didMove = !1;
return;
}
const rootPointerEvent = this.events.rootPointerEvent;
this.events.supportsTouchEvents && rootPointerEvent.pointerType === "touch" || globalThis.document.dispatchEvent(new PointerEvent("pointermove", {
clientX: rootPointerEvent.clientX,
clientY: rootPointerEvent.clientY
}));
}
/**
* Updates the state of interactive objects if at least {@link PIXI.EventsTicker#interactionFrequency}
* milliseconds have passed since the last invocation.
*
* Invoked by a throttled ticker update from {@link PIXI.Ticker.system}.
* @param deltaTime - time delta since the last call
*/
tickerUpdate(deltaTime) {
this._deltaTime += deltaTime, !(this._deltaTime < this.interactionFrequency) && (this._deltaTime = 0, this.update());
}
}
const EventsTicker = new EventsTickerClass();
export {
EventsTicker
};
//# sourceMappingURL=EventTicker.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,81 @@
"use strict";
var core = require("@pixi/core");
class FederatedEvent {
/**
* @param manager - The event boundary which manages this event. Propagation can only occur
* within the boundary's jurisdiction.
*/
constructor(manager) {
this.bubbles = !0, this.cancelBubble = !0, this.cancelable = !1, this.composed = !1, this.defaultPrevented = !1, this.eventPhase = FederatedEvent.prototype.NONE, this.propagationStopped = !1, this.propagationImmediatelyStopped = !1, this.layer = new core.Point(), this.page = new core.Point(), this.NONE = 0, this.CAPTURING_PHASE = 1, this.AT_TARGET = 2, this.BUBBLING_PHASE = 3, this.manager = manager;
}
/** @readonly */
get layerX() {
return this.layer.x;
}
/** @readonly */
get layerY() {
return this.layer.y;
}
/** @readonly */
get pageX() {
return this.page.x;
}
/** @readonly */
get pageY() {
return this.page.y;
}
/**
* Fallback for the deprecated @code{PIXI.InteractionEvent.data}.
* @deprecated since 7.0.0
*/
get data() {
return this;
}
/** The propagation path for this event. Alias for {@link PIXI.EventBoundary.propagationPath}. */
composedPath() {
return this.manager && (!this.path || this.path[this.path.length - 1] !== this.target) && (this.path = this.target ? this.manager.propagationPath(this.target) : []), this.path;
}
/**
* Unimplemented method included for implementing the DOM interface {@code Event}. It will throw an {@code Error}.
* @deprecated
* @param _type
* @param _bubbles
* @param _cancelable
*/
initEvent(_type, _bubbles, _cancelable) {
throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
}
/**
* Unimplemented method included for implementing the DOM interface {@code UIEvent}. It will throw an {@code Error}.
* @deprecated
* @param _typeArg
* @param _bubblesArg
* @param _cancelableArg
* @param _viewArg
* @param _detailArg
*/
initUIEvent(_typeArg, _bubblesArg, _cancelableArg, _viewArg, _detailArg) {
throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
}
/** Prevent default behavior of PixiJS and the user agent. */
preventDefault() {
this.nativeEvent instanceof Event && this.nativeEvent.cancelable && this.nativeEvent.preventDefault(), this.defaultPrevented = !0;
}
/**
* Stop this event from propagating to any addition listeners, including on the
* {@link PIXI.FederatedEventTarget.currentTarget currentTarget} and also the following
* event targets on the propagation path.
*/
stopImmediatePropagation() {
this.propagationImmediatelyStopped = !0;
}
/**
* Stop this event from propagating to the next {@link PIXI.FederatedEventTarget}. The rest of the listeners
* on the {@link PIXI.FederatedEventTarget.currentTarget currentTarget} will still be notified.
*/
stopPropagation() {
this.propagationStopped = !0;
}
}
exports.FederatedEvent = FederatedEvent;
//# sourceMappingURL=FederatedEvent.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,82 @@
import { Point } from "@pixi/core";
class FederatedEvent {
/**
* @param manager - The event boundary which manages this event. Propagation can only occur
* within the boundary's jurisdiction.
*/
constructor(manager) {
this.bubbles = !0, this.cancelBubble = !0, this.cancelable = !1, this.composed = !1, this.defaultPrevented = !1, this.eventPhase = FederatedEvent.prototype.NONE, this.propagationStopped = !1, this.propagationImmediatelyStopped = !1, this.layer = new Point(), this.page = new Point(), this.NONE = 0, this.CAPTURING_PHASE = 1, this.AT_TARGET = 2, this.BUBBLING_PHASE = 3, this.manager = manager;
}
/** @readonly */
get layerX() {
return this.layer.x;
}
/** @readonly */
get layerY() {
return this.layer.y;
}
/** @readonly */
get pageX() {
return this.page.x;
}
/** @readonly */
get pageY() {
return this.page.y;
}
/**
* Fallback for the deprecated @code{PIXI.InteractionEvent.data}.
* @deprecated since 7.0.0
*/
get data() {
return this;
}
/** The propagation path for this event. Alias for {@link PIXI.EventBoundary.propagationPath}. */
composedPath() {
return this.manager && (!this.path || this.path[this.path.length - 1] !== this.target) && (this.path = this.target ? this.manager.propagationPath(this.target) : []), this.path;
}
/**
* Unimplemented method included for implementing the DOM interface {@code Event}. It will throw an {@code Error}.
* @deprecated
* @param _type
* @param _bubbles
* @param _cancelable
*/
initEvent(_type, _bubbles, _cancelable) {
throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
}
/**
* Unimplemented method included for implementing the DOM interface {@code UIEvent}. It will throw an {@code Error}.
* @deprecated
* @param _typeArg
* @param _bubblesArg
* @param _cancelableArg
* @param _viewArg
* @param _detailArg
*/
initUIEvent(_typeArg, _bubblesArg, _cancelableArg, _viewArg, _detailArg) {
throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.");
}
/** Prevent default behavior of PixiJS and the user agent. */
preventDefault() {
this.nativeEvent instanceof Event && this.nativeEvent.cancelable && this.nativeEvent.preventDefault(), this.defaultPrevented = !0;
}
/**
* Stop this event from propagating to any addition listeners, including on the
* {@link PIXI.FederatedEventTarget.currentTarget currentTarget} and also the following
* event targets on the propagation path.
*/
stopImmediatePropagation() {
this.propagationImmediatelyStopped = !0;
}
/**
* Stop this event from propagating to the next {@link PIXI.FederatedEventTarget}. The rest of the listeners
* on the {@link PIXI.FederatedEventTarget.currentTarget currentTarget} will still be notified.
*/
stopPropagation() {
this.propagationStopped = !0;
}
}
export {
FederatedEvent
};
//# sourceMappingURL=FederatedEvent.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=FederatedEventMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedEventMap.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,2 @@
//# sourceMappingURL=FederatedEventMap.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedEventMap.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,507 @@
"use strict";
var core = require("@pixi/core"), display = require("@pixi/display"), EventSystem = require("./EventSystem.js"), FederatedEvent = require("./FederatedEvent.js");
function convertEventModeToInteractiveMode(mode) {
return mode === "dynamic" || mode === "static";
}
const FederatedDisplayObject = {
/**
* Property-based event handler for the `click` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onclick = (event) => {
* //some function here that happens on click
* }
*/
onclick: null,
/**
* Property-based event handler for the `mousedown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmousedown = (event) => {
* //some function here that happens on mousedown
* }
*/
onmousedown: null,
/**
* Property-based event handler for the `mouseenter` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseenter = (event) => {
* //some function here that happens on mouseenter
* }
*/
onmouseenter: null,
/**
* Property-based event handler for the `mouseleave` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseleave = (event) => {
* //some function here that happens on mouseleave
* }
*/
onmouseleave: null,
/**
* Property-based event handler for the `mousemove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmousemove = (event) => {
* //some function here that happens on mousemove
* }
*/
onmousemove: null,
/**
* Property-based event handler for the `globalmousemove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobalmousemove = (event) => {
* //some function here that happens on globalmousemove
* }
*/
onglobalmousemove: null,
/**
* Property-based event handler for the `mouseout` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseout = (event) => {
* //some function here that happens on mouseout
* }
*/
onmouseout: null,
/**
* Property-based event handler for the `mouseover` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseover = (event) => {
* //some function here that happens on mouseover
* }
*/
onmouseover: null,
/**
* Property-based event handler for the `mouseup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseup = (event) => {
* //some function here that happens on mouseup
* }
*/
onmouseup: null,
/**
* Property-based event handler for the `mouseupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseupoutside = (event) => {
* //some function here that happens on mouseupoutside
* }
*/
onmouseupoutside: null,
/**
* Property-based event handler for the `pointercancel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointercancel = (event) => {
* //some function here that happens on pointercancel
* }
*/
onpointercancel: null,
/**
* Property-based event handler for the `pointerdown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerdown = (event) => {
* //some function here that happens on pointerdown
* }
*/
onpointerdown: null,
/**
* Property-based event handler for the `pointerenter` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerenter = (event) => {
* //some function here that happens on pointerenter
* }
*/
onpointerenter: null,
/**
* Property-based event handler for the `pointerleave` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerleave = (event) => {
* //some function here that happens on pointerleave
* }
*/
onpointerleave: null,
/**
* Property-based event handler for the `pointermove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointermove = (event) => {
* //some function here that happens on pointermove
* }
*/
onpointermove: null,
/**
* Property-based event handler for the `globalpointermove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobalpointermove = (event) => {
* //some function here that happens on globalpointermove
* }
*/
onglobalpointermove: null,
/**
* Property-based event handler for the `pointerout` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerout = (event) => {
* //some function here that happens on pointerout
* }
*/
onpointerout: null,
/**
* Property-based event handler for the `pointerover` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerover = (event) => {
* //some function here that happens on pointerover
* }
*/
onpointerover: null,
/**
* Property-based event handler for the `pointertap` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointertap = (event) => {
* //some function here that happens on pointertap
* }
*/
onpointertap: null,
/**
* Property-based event handler for the `pointerup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerup = (event) => {
* //some function here that happens on pointerup
* }
*/
onpointerup: null,
/**
* Property-based event handler for the `pointerupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerupoutside = (event) => {
* //some function here that happens on pointerupoutside
* }
*/
onpointerupoutside: null,
/**
* Property-based event handler for the `rightclick` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightclick = (event) => {
* //some function here that happens on rightclick
* }
*/
onrightclick: null,
/**
* Property-based event handler for the `rightdown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightdown = (event) => {
* //some function here that happens on rightdown
* }
*/
onrightdown: null,
/**
* Property-based event handler for the `rightup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightup = (event) => {
* //some function here that happens on rightup
* }
*/
onrightup: null,
/**
* Property-based event handler for the `rightupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightupoutside = (event) => {
* //some function here that happens on rightupoutside
* }
*/
onrightupoutside: null,
/**
* Property-based event handler for the `tap` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontap = (event) => {
* //some function here that happens on tap
* }
*/
ontap: null,
/**
* Property-based event handler for the `touchcancel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchcancel = (event) => {
* //some function here that happens on touchcancel
* }
*/
ontouchcancel: null,
/**
* Property-based event handler for the `touchend` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchend = (event) => {
* //some function here that happens on touchend
* }
*/
ontouchend: null,
/**
* Property-based event handler for the `touchendoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchendoutside = (event) => {
* //some function here that happens on touchendoutside
* }
*/
ontouchendoutside: null,
/**
* Property-based event handler for the `touchmove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchmove = (event) => {
* //some function here that happens on touchmove
* }
*/
ontouchmove: null,
/**
* Property-based event handler for the `globaltouchmove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobaltouchmove = (event) => {
* //some function here that happens on globaltouchmove
* }
*/
onglobaltouchmove: null,
/**
* Property-based event handler for the `touchstart` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchstart = (event) => {
* //some function here that happens on touchstart
* }
*/
ontouchstart: null,
/**
* Property-based event handler for the `wheel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onwheel = (event) => {
* //some function here that happens on wheel
* }
*/
onwheel: null,
/**
* @ignore
*/
_internalInteractive: void 0,
/**
* Enable interaction events for the DisplayObject. Touch, pointer and mouse
* @memberof PIXI.DisplayObject#
*/
get interactive() {
return this._internalInteractive ?? convertEventModeToInteractiveMode(EventSystem.EventSystem.defaultEventMode);
},
set interactive(value) {
core.utils.deprecation(
"7.2.0",
// eslint-disable-next-line max-len
"Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."
), this._internalInteractive = value, this.eventMode = value ? "static" : "auto";
},
/**
* @ignore
*/
_internalEventMode: void 0,
/**
* Enable interaction events for the DisplayObject. Touch, pointer and mouse.
* This now replaces the `interactive` property.
* There are 5 types of interaction settings:
* - `'none'`: Ignores all interaction events, even on its children.
* - `'passive'`: Does not emit events and ignores all hit testing on itself and non-interactive children.
* Interactive children will still emit events.
* - `'auto'`: Does not emit events but is hit tested if parent is interactive. Same as `interactive = false` in v7
* - `'static'`: Emit events and is hit tested. Same as `interaction = true` in v7
* - `'dynamic'`: Emits events and is hit tested but will also receive mock interaction events fired from a ticker to
* allow for interaction when the mouse isn't moving
* @example
* import { Sprite } from 'pixi.js';
*
* const sprite = new Sprite(texture);
* sprite.eventMode = 'static';
* sprite.on('tap', (event) => {
* // Handle event
* });
* @memberof PIXI.DisplayObject#
* @since 7.2.0
*/
get eventMode() {
return this._internalEventMode ?? EventSystem.EventSystem.defaultEventMode;
},
set eventMode(value) {
this._internalInteractive = convertEventModeToInteractiveMode(value), this._internalEventMode = value;
},
/**
* Determines if the displayObject is interactive or not
* @returns {boolean} Whether the displayObject is interactive or not
* @memberof PIXI.DisplayObject#
* @since 7.2.0
* @example
* import { Sprite } from 'pixi.js';
* const sprite = new Sprite(texture);
* sprite.eventMode = 'static';
* sprite.isInteractive(); // true
*
* sprite.eventMode = 'dynamic';
* sprite.isInteractive(); // true
*
* sprite.eventMode = 'none';
* sprite.isInteractive(); // false
*
* sprite.eventMode = 'passive';
* sprite.isInteractive(); // false
*
* sprite.eventMode = 'auto';
* sprite.isInteractive(); // false
*/
isInteractive() {
return this.eventMode === "static" || this.eventMode === "dynamic";
},
/**
* Determines if the children to the displayObject can be clicked/touched
* Setting this to false allows PixiJS to bypass a recursive `hitTest` function
* @memberof PIXI.Container#
*/
interactiveChildren: !0,
/**
* Interaction shape. Children will be hit first, then this shape will be checked.
* Setting this will cause this shape to be checked in hit tests rather than the displayObject's bounds.
* @example
* import { Rectangle, Sprite } from 'pixi.js';
*
* const sprite = new Sprite(texture);
* sprite.interactive = true;
* sprite.hitArea = new Rectangle(0, 0, 100, 100);
* @member {PIXI.IHitArea}
* @memberof PIXI.DisplayObject#
*/
hitArea: null,
/**
* Unlike `on` or `addListener` which are methods from EventEmitter, `addEventListener`
* seeks to be compatible with the DOM's `addEventListener` with support for options.
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param type - The type of event to listen to.
* @param listener - The listener callback or object.
* @param options - Listener options, used for capture phase.
* @example
* // Tell the user whether they did a single, double, triple, or nth click.
* button.addEventListener('click', {
* handleEvent(e): {
* let prefix;
*
* switch (e.detail) {
* case 1: prefix = 'single'; break;
* case 2: prefix = 'double'; break;
* case 3: prefix = 'triple'; break;
* default: prefix = e.detail + 'th'; break;
* }
*
* console.log('That was a ' + prefix + 'click');
* }
* });
*
* // But skip the first click!
* button.parent.addEventListener('click', function blockClickOnce(e) {
* e.stopImmediatePropagation();
* button.parent.removeEventListener('click', blockClickOnce, true);
* }, {
* capture: true,
* });
*/
addEventListener(type, listener, options) {
const capture = typeof options == "boolean" && options || typeof options == "object" && options.capture, signal = typeof options == "object" ? options.signal : void 0, once = typeof options == "object" ? options.once === !0 : !1, context = typeof listener == "function" ? void 0 : listener;
type = capture ? `${type}capture` : type;
const listenerFn = typeof listener == "function" ? listener : listener.handleEvent, emitter = this;
signal && signal.addEventListener("abort", () => {
emitter.off(type, listenerFn, context);
}), once ? emitter.once(type, listenerFn, context) : emitter.on(type, listenerFn, context);
},
/**
* Unlike `off` or `removeListener` which are methods from EventEmitter, `removeEventListener`
* seeks to be compatible with the DOM's `removeEventListener` with support for options.
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param type - The type of event the listener is bound to.
* @param listener - The listener callback or object.
* @param options - The original listener options. This is required to deregister a capture phase listener.
*/
removeEventListener(type, listener, options) {
const capture = typeof options == "boolean" && options || typeof options == "object" && options.capture, context = typeof listener == "function" ? void 0 : listener;
type = capture ? `${type}capture` : type, listener = typeof listener == "function" ? listener : listener.handleEvent, this.off(type, listener, context);
},
/**
* Dispatch the event on this {@link PIXI.DisplayObject} using the event's {@link PIXI.EventBoundary}.
*
* The target of the event is set to `this` and the `defaultPrevented` flag is cleared before dispatch.
*
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param e - The event to dispatch.
* @returns Whether the {@link PIXI.FederatedEvent.preventDefault preventDefault}() method was not invoked.
* @example
* // Reuse a click event!
* button.dispatchEvent(clickEvent);
*/
dispatchEvent(e) {
if (!(e instanceof FederatedEvent.FederatedEvent))
throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");
return e.defaultPrevented = !1, e.path = null, e.target = this, e.manager.dispatchEvent(e), !e.defaultPrevented;
}
};
display.DisplayObject.mixin(FederatedDisplayObject);
exports.FederatedDisplayObject = FederatedDisplayObject;
//# sourceMappingURL=FederatedEventTarget.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,511 @@
import { utils } from "@pixi/core";
import { DisplayObject } from "@pixi/display";
import { EventSystem } from "./EventSystem.mjs";
import { FederatedEvent } from "./FederatedEvent.mjs";
function convertEventModeToInteractiveMode(mode) {
return mode === "dynamic" || mode === "static";
}
const FederatedDisplayObject = {
/**
* Property-based event handler for the `click` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onclick = (event) => {
* //some function here that happens on click
* }
*/
onclick: null,
/**
* Property-based event handler for the `mousedown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmousedown = (event) => {
* //some function here that happens on mousedown
* }
*/
onmousedown: null,
/**
* Property-based event handler for the `mouseenter` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseenter = (event) => {
* //some function here that happens on mouseenter
* }
*/
onmouseenter: null,
/**
* Property-based event handler for the `mouseleave` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseleave = (event) => {
* //some function here that happens on mouseleave
* }
*/
onmouseleave: null,
/**
* Property-based event handler for the `mousemove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmousemove = (event) => {
* //some function here that happens on mousemove
* }
*/
onmousemove: null,
/**
* Property-based event handler for the `globalmousemove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobalmousemove = (event) => {
* //some function here that happens on globalmousemove
* }
*/
onglobalmousemove: null,
/**
* Property-based event handler for the `mouseout` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseout = (event) => {
* //some function here that happens on mouseout
* }
*/
onmouseout: null,
/**
* Property-based event handler for the `mouseover` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseover = (event) => {
* //some function here that happens on mouseover
* }
*/
onmouseover: null,
/**
* Property-based event handler for the `mouseup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseup = (event) => {
* //some function here that happens on mouseup
* }
*/
onmouseup: null,
/**
* Property-based event handler for the `mouseupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onmouseupoutside = (event) => {
* //some function here that happens on mouseupoutside
* }
*/
onmouseupoutside: null,
/**
* Property-based event handler for the `pointercancel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointercancel = (event) => {
* //some function here that happens on pointercancel
* }
*/
onpointercancel: null,
/**
* Property-based event handler for the `pointerdown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerdown = (event) => {
* //some function here that happens on pointerdown
* }
*/
onpointerdown: null,
/**
* Property-based event handler for the `pointerenter` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerenter = (event) => {
* //some function here that happens on pointerenter
* }
*/
onpointerenter: null,
/**
* Property-based event handler for the `pointerleave` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerleave = (event) => {
* //some function here that happens on pointerleave
* }
*/
onpointerleave: null,
/**
* Property-based event handler for the `pointermove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointermove = (event) => {
* //some function here that happens on pointermove
* }
*/
onpointermove: null,
/**
* Property-based event handler for the `globalpointermove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobalpointermove = (event) => {
* //some function here that happens on globalpointermove
* }
*/
onglobalpointermove: null,
/**
* Property-based event handler for the `pointerout` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerout = (event) => {
* //some function here that happens on pointerout
* }
*/
onpointerout: null,
/**
* Property-based event handler for the `pointerover` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerover = (event) => {
* //some function here that happens on pointerover
* }
*/
onpointerover: null,
/**
* Property-based event handler for the `pointertap` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointertap = (event) => {
* //some function here that happens on pointertap
* }
*/
onpointertap: null,
/**
* Property-based event handler for the `pointerup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerup = (event) => {
* //some function here that happens on pointerup
* }
*/
onpointerup: null,
/**
* Property-based event handler for the `pointerupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onpointerupoutside = (event) => {
* //some function here that happens on pointerupoutside
* }
*/
onpointerupoutside: null,
/**
* Property-based event handler for the `rightclick` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightclick = (event) => {
* //some function here that happens on rightclick
* }
*/
onrightclick: null,
/**
* Property-based event handler for the `rightdown` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightdown = (event) => {
* //some function here that happens on rightdown
* }
*/
onrightdown: null,
/**
* Property-based event handler for the `rightup` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightup = (event) => {
* //some function here that happens on rightup
* }
*/
onrightup: null,
/**
* Property-based event handler for the `rightupoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onrightupoutside = (event) => {
* //some function here that happens on rightupoutside
* }
*/
onrightupoutside: null,
/**
* Property-based event handler for the `tap` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontap = (event) => {
* //some function here that happens on tap
* }
*/
ontap: null,
/**
* Property-based event handler for the `touchcancel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchcancel = (event) => {
* //some function here that happens on touchcancel
* }
*/
ontouchcancel: null,
/**
* Property-based event handler for the `touchend` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchend = (event) => {
* //some function here that happens on touchend
* }
*/
ontouchend: null,
/**
* Property-based event handler for the `touchendoutside` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchendoutside = (event) => {
* //some function here that happens on touchendoutside
* }
*/
ontouchendoutside: null,
/**
* Property-based event handler for the `touchmove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchmove = (event) => {
* //some function here that happens on touchmove
* }
*/
ontouchmove: null,
/**
* Property-based event handler for the `globaltouchmove` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onglobaltouchmove = (event) => {
* //some function here that happens on globaltouchmove
* }
*/
onglobaltouchmove: null,
/**
* Property-based event handler for the `touchstart` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.ontouchstart = (event) => {
* //some function here that happens on touchstart
* }
*/
ontouchstart: null,
/**
* Property-based event handler for the `wheel` event.
* @memberof PIXI.DisplayObject#
* @default null
* @example
* this.onwheel = (event) => {
* //some function here that happens on wheel
* }
*/
onwheel: null,
/**
* @ignore
*/
_internalInteractive: void 0,
/**
* Enable interaction events for the DisplayObject. Touch, pointer and mouse
* @memberof PIXI.DisplayObject#
*/
get interactive() {
return this._internalInteractive ?? convertEventModeToInteractiveMode(EventSystem.defaultEventMode);
},
set interactive(value) {
utils.deprecation(
"7.2.0",
// eslint-disable-next-line max-len
"Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."
), this._internalInteractive = value, this.eventMode = value ? "static" : "auto";
},
/**
* @ignore
*/
_internalEventMode: void 0,
/**
* Enable interaction events for the DisplayObject. Touch, pointer and mouse.
* This now replaces the `interactive` property.
* There are 5 types of interaction settings:
* - `'none'`: Ignores all interaction events, even on its children.
* - `'passive'`: Does not emit events and ignores all hit testing on itself and non-interactive children.
* Interactive children will still emit events.
* - `'auto'`: Does not emit events but is hit tested if parent is interactive. Same as `interactive = false` in v7
* - `'static'`: Emit events and is hit tested. Same as `interaction = true` in v7
* - `'dynamic'`: Emits events and is hit tested but will also receive mock interaction events fired from a ticker to
* allow for interaction when the mouse isn't moving
* @example
* import { Sprite } from 'pixi.js';
*
* const sprite = new Sprite(texture);
* sprite.eventMode = 'static';
* sprite.on('tap', (event) => {
* // Handle event
* });
* @memberof PIXI.DisplayObject#
* @since 7.2.0
*/
get eventMode() {
return this._internalEventMode ?? EventSystem.defaultEventMode;
},
set eventMode(value) {
this._internalInteractive = convertEventModeToInteractiveMode(value), this._internalEventMode = value;
},
/**
* Determines if the displayObject is interactive or not
* @returns {boolean} Whether the displayObject is interactive or not
* @memberof PIXI.DisplayObject#
* @since 7.2.0
* @example
* import { Sprite } from 'pixi.js';
* const sprite = new Sprite(texture);
* sprite.eventMode = 'static';
* sprite.isInteractive(); // true
*
* sprite.eventMode = 'dynamic';
* sprite.isInteractive(); // true
*
* sprite.eventMode = 'none';
* sprite.isInteractive(); // false
*
* sprite.eventMode = 'passive';
* sprite.isInteractive(); // false
*
* sprite.eventMode = 'auto';
* sprite.isInteractive(); // false
*/
isInteractive() {
return this.eventMode === "static" || this.eventMode === "dynamic";
},
/**
* Determines if the children to the displayObject can be clicked/touched
* Setting this to false allows PixiJS to bypass a recursive `hitTest` function
* @memberof PIXI.Container#
*/
interactiveChildren: !0,
/**
* Interaction shape. Children will be hit first, then this shape will be checked.
* Setting this will cause this shape to be checked in hit tests rather than the displayObject's bounds.
* @example
* import { Rectangle, Sprite } from 'pixi.js';
*
* const sprite = new Sprite(texture);
* sprite.interactive = true;
* sprite.hitArea = new Rectangle(0, 0, 100, 100);
* @member {PIXI.IHitArea}
* @memberof PIXI.DisplayObject#
*/
hitArea: null,
/**
* Unlike `on` or `addListener` which are methods from EventEmitter, `addEventListener`
* seeks to be compatible with the DOM's `addEventListener` with support for options.
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param type - The type of event to listen to.
* @param listener - The listener callback or object.
* @param options - Listener options, used for capture phase.
* @example
* // Tell the user whether they did a single, double, triple, or nth click.
* button.addEventListener('click', {
* handleEvent(e): {
* let prefix;
*
* switch (e.detail) {
* case 1: prefix = 'single'; break;
* case 2: prefix = 'double'; break;
* case 3: prefix = 'triple'; break;
* default: prefix = e.detail + 'th'; break;
* }
*
* console.log('That was a ' + prefix + 'click');
* }
* });
*
* // But skip the first click!
* button.parent.addEventListener('click', function blockClickOnce(e) {
* e.stopImmediatePropagation();
* button.parent.removeEventListener('click', blockClickOnce, true);
* }, {
* capture: true,
* });
*/
addEventListener(type, listener, options) {
const capture = typeof options == "boolean" && options || typeof options == "object" && options.capture, signal = typeof options == "object" ? options.signal : void 0, once = typeof options == "object" ? options.once === !0 : !1, context = typeof listener == "function" ? void 0 : listener;
type = capture ? `${type}capture` : type;
const listenerFn = typeof listener == "function" ? listener : listener.handleEvent, emitter = this;
signal && signal.addEventListener("abort", () => {
emitter.off(type, listenerFn, context);
}), once ? emitter.once(type, listenerFn, context) : emitter.on(type, listenerFn, context);
},
/**
* Unlike `off` or `removeListener` which are methods from EventEmitter, `removeEventListener`
* seeks to be compatible with the DOM's `removeEventListener` with support for options.
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param type - The type of event the listener is bound to.
* @param listener - The listener callback or object.
* @param options - The original listener options. This is required to deregister a capture phase listener.
*/
removeEventListener(type, listener, options) {
const capture = typeof options == "boolean" && options || typeof options == "object" && options.capture, context = typeof listener == "function" ? void 0 : listener;
type = capture ? `${type}capture` : type, listener = typeof listener == "function" ? listener : listener.handleEvent, this.off(type, listener, context);
},
/**
* Dispatch the event on this {@link PIXI.DisplayObject} using the event's {@link PIXI.EventBoundary}.
*
* The target of the event is set to `this` and the `defaultPrevented` flag is cleared before dispatch.
*
* **IMPORTANT:** _Only_ available if using the `@pixi/events` package.
* @memberof PIXI.DisplayObject
* @param e - The event to dispatch.
* @returns Whether the {@link PIXI.FederatedEvent.preventDefault preventDefault}() method was not invoked.
* @example
* // Reuse a click event!
* button.dispatchEvent(clickEvent);
*/
dispatchEvent(e) {
if (!(e instanceof FederatedEvent))
throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");
return e.defaultPrevented = !1, e.path = null, e.target = this, e.manager.dispatchEvent(e), !e.defaultPrevented;
}
};
DisplayObject.mixin(FederatedDisplayObject);
export {
FederatedDisplayObject
};
//# sourceMappingURL=FederatedEventTarget.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,113 @@
"use strict";
var core = require("@pixi/core"), FederatedEvent = require("./FederatedEvent.js");
class FederatedMouseEvent extends FederatedEvent.FederatedEvent {
constructor() {
super(...arguments), this.client = new core.Point(), this.movement = new core.Point(), this.offset = new core.Point(), this.global = new core.Point(), this.screen = new core.Point();
}
/** @readonly */
get clientX() {
return this.client.x;
}
/** @readonly */
get clientY() {
return this.client.y;
}
/**
* Alias for {@link PIXI.FederatedMouseEvent.clientX this.clientX}.
* @readonly
*/
get x() {
return this.clientX;
}
/**
* Alias for {@link PIXI.FederatedMouseEvent.clientY this.clientY}.
* @readonly
*/
get y() {
return this.clientY;
}
/** @readonly */
get movementX() {
return this.movement.x;
}
/** @readonly */
get movementY() {
return this.movement.y;
}
/** @readonly */
get offsetX() {
return this.offset.x;
}
/** @readonly */
get offsetY() {
return this.offset.y;
}
/** @readonly */
get globalX() {
return this.global.x;
}
/** @readonly */
get globalY() {
return this.global.y;
}
/**
* The pointer coordinates in the renderer's screen. Alias for {@code screen.x}.
* @readonly
*/
get screenX() {
return this.screen.x;
}
/**
* The pointer coordinates in the renderer's screen. Alias for {@code screen.y}.
* @readonly
*/
get screenY() {
return this.screen.y;
}
/**
* This will return the local coordinates of the specified displayObject for this InteractionData
* @param {PIXI.DisplayObject} displayObject - The DisplayObject that you would like the local
* coords off
* @param {PIXI.IPointData} point - A Point object in which to store the value, optional (otherwise
* will create a new point)
* @param {PIXI.IPointData} globalPos - A Point object containing your custom global coords, optional
* (otherwise will use the current global coords)
* @returns - A point containing the coordinates of the InteractionData position relative
* to the DisplayObject
*/
getLocalPosition(displayObject, point, globalPos) {
return displayObject.worldTransform.applyInverse(globalPos || this.global, point);
}
/**
* Whether the modifier key was pressed when this event natively occurred.
* @param key - The modifier key.
*/
getModifierState(key) {
return "getModifierState" in this.nativeEvent && this.nativeEvent.getModifierState(key);
}
/**
* Not supported.
* @param _typeArg
* @param _canBubbleArg
* @param _cancelableArg
* @param _viewArg
* @param _detailArg
* @param _screenXArg
* @param _screenYArg
* @param _clientXArg
* @param _clientYArg
* @param _ctrlKeyArg
* @param _altKeyArg
* @param _shiftKeyArg
* @param _metaKeyArg
* @param _buttonArg
* @param _relatedTargetArg
* @deprecated since 7.0.0
*/
// eslint-disable-next-line max-params
initMouseEvent(_typeArg, _canBubbleArg, _cancelableArg, _viewArg, _detailArg, _screenXArg, _screenYArg, _clientXArg, _clientYArg, _ctrlKeyArg, _altKeyArg, _shiftKeyArg, _metaKeyArg, _buttonArg, _relatedTargetArg) {
throw new Error("Method not implemented.");
}
}
exports.FederatedMouseEvent = FederatedMouseEvent;
//# sourceMappingURL=FederatedMouseEvent.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,115 @@
import { Point } from "@pixi/core";
import { FederatedEvent } from "./FederatedEvent.mjs";
class FederatedMouseEvent extends FederatedEvent {
constructor() {
super(...arguments), this.client = new Point(), this.movement = new Point(), this.offset = new Point(), this.global = new Point(), this.screen = new Point();
}
/** @readonly */
get clientX() {
return this.client.x;
}
/** @readonly */
get clientY() {
return this.client.y;
}
/**
* Alias for {@link PIXI.FederatedMouseEvent.clientX this.clientX}.
* @readonly
*/
get x() {
return this.clientX;
}
/**
* Alias for {@link PIXI.FederatedMouseEvent.clientY this.clientY}.
* @readonly
*/
get y() {
return this.clientY;
}
/** @readonly */
get movementX() {
return this.movement.x;
}
/** @readonly */
get movementY() {
return this.movement.y;
}
/** @readonly */
get offsetX() {
return this.offset.x;
}
/** @readonly */
get offsetY() {
return this.offset.y;
}
/** @readonly */
get globalX() {
return this.global.x;
}
/** @readonly */
get globalY() {
return this.global.y;
}
/**
* The pointer coordinates in the renderer's screen. Alias for {@code screen.x}.
* @readonly
*/
get screenX() {
return this.screen.x;
}
/**
* The pointer coordinates in the renderer's screen. Alias for {@code screen.y}.
* @readonly
*/
get screenY() {
return this.screen.y;
}
/**
* This will return the local coordinates of the specified displayObject for this InteractionData
* @param {PIXI.DisplayObject} displayObject - The DisplayObject that you would like the local
* coords off
* @param {PIXI.IPointData} point - A Point object in which to store the value, optional (otherwise
* will create a new point)
* @param {PIXI.IPointData} globalPos - A Point object containing your custom global coords, optional
* (otherwise will use the current global coords)
* @returns - A point containing the coordinates of the InteractionData position relative
* to the DisplayObject
*/
getLocalPosition(displayObject, point, globalPos) {
return displayObject.worldTransform.applyInverse(globalPos || this.global, point);
}
/**
* Whether the modifier key was pressed when this event natively occurred.
* @param key - The modifier key.
*/
getModifierState(key) {
return "getModifierState" in this.nativeEvent && this.nativeEvent.getModifierState(key);
}
/**
* Not supported.
* @param _typeArg
* @param _canBubbleArg
* @param _cancelableArg
* @param _viewArg
* @param _detailArg
* @param _screenXArg
* @param _screenYArg
* @param _clientXArg
* @param _clientYArg
* @param _ctrlKeyArg
* @param _altKeyArg
* @param _shiftKeyArg
* @param _metaKeyArg
* @param _buttonArg
* @param _relatedTargetArg
* @deprecated since 7.0.0
*/
// eslint-disable-next-line max-params
initMouseEvent(_typeArg, _canBubbleArg, _cancelableArg, _viewArg, _detailArg, _screenXArg, _screenYArg, _clientXArg, _clientYArg, _ctrlKeyArg, _altKeyArg, _shiftKeyArg, _metaKeyArg, _buttonArg, _relatedTargetArg) {
throw new Error("Method not implemented.");
}
}
export {
FederatedMouseEvent
};
//# sourceMappingURL=FederatedMouseEvent.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,17 @@
"use strict";
var FederatedMouseEvent = require("./FederatedMouseEvent.js");
class FederatedPointerEvent extends FederatedMouseEvent.FederatedMouseEvent {
constructor() {
super(...arguments), this.width = 0, this.height = 0, this.isPrimary = !1;
}
// Only included for completeness for now
getCoalescedEvents() {
return this.type === "pointermove" || this.type === "mousemove" || this.type === "touchmove" ? [this] : [];
}
// Only included for completeness for now
getPredictedEvents() {
throw new Error("getPredictedEvents is not supported!");
}
}
exports.FederatedPointerEvent = FederatedPointerEvent;
//# sourceMappingURL=FederatedPointerEvent.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedPointerEvent.js","sources":["../src/FederatedPointerEvent.ts"],"sourcesContent":["import { FederatedMouseEvent } from './FederatedMouseEvent';\n\n/**\n * A {@link PIXI.FederatedEvent} for pointer events.\n * @memberof PIXI\n */\nexport class FederatedPointerEvent extends FederatedMouseEvent implements PointerEvent\n{\n /**\n * The unique identifier of the pointer.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId}\n */\n public pointerId: number;\n\n /**\n * The width of the pointer's contact along the x-axis, measured in CSS pixels.\n * radiusX of TouchEvents will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width\n */\n public width = 0;\n\n /**\n * The height of the pointer's contact along the y-axis, measured in CSS pixels.\n * radiusY of TouchEvents will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height\n */\n public height = 0;\n\n /**\n * Indicates whether or not the pointer device that created the event is the primary pointer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary\n */\n public isPrimary = false;\n\n /**\n * The type of pointer that triggered the event.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType\n */\n public pointerType: string;\n\n /**\n * Pressure applied by the pointing device during the event.\n *s\n * A Touch's force property will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure\n */\n public pressure: number;\n\n /**\n * Barrel pressure on a stylus pointer.\n * @see https://w3c.github.io/pointerevents/#pointerevent-interface\n */\n public tangentialPressure: number;\n\n /**\n * The angle, in degrees, between the pointer device and the screen.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX\n */\n public tiltX: number;\n\n /**\n * The angle, in degrees, between the pointer device and the screen.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY\n */\n public tiltY: number;\n\n /**\n * Twist of a stylus pointer.\n * @see https://w3c.github.io/pointerevents/#pointerevent-interface\n */\n public twist: number;\n\n /** This is the number of clicks that occurs in 200ms/click of each other. */\n public detail: number;\n\n // Only included for completeness for now\n getCoalescedEvents(): PointerEvent[]\n {\n if (this.type === 'pointermove' || this.type === 'mousemove' || this.type === 'touchmove')\n {\n return [this];\n }\n\n return [];\n }\n\n // Only included for completeness for now\n getPredictedEvents(): PointerEvent[]\n {\n throw new Error('getPredictedEvents is not supported!');\n }\n}\n"],"names":["FederatedMouseEvent"],"mappings":";;AAMO,MAAM,8BAA8BA,oBAAAA,oBAC3C;AAAA,EADO,cAAA;AAAA,UAAA,GAAA,SAAA,GAaH,KAAO,QAAQ,GAOf,KAAO,SAAS,GAMhB,KAAO,YAAY;AAAA,EAAA;AAAA;AAAA,EA4CnB,qBACA;AACI,WAAI,KAAK,SAAS,iBAAiB,KAAK,SAAS,eAAe,KAAK,SAAS,cAEnE,CAAC,IAAI,IAGT,CAAA;AAAA,EACX;AAAA;AAAA,EAGA,qBACA;AACU,UAAA,IAAI,MAAM,sCAAsC;AAAA,EAC1D;AACJ;;"}

View File

@@ -0,0 +1,18 @@
import { FederatedMouseEvent } from "./FederatedMouseEvent.mjs";
class FederatedPointerEvent extends FederatedMouseEvent {
constructor() {
super(...arguments), this.width = 0, this.height = 0, this.isPrimary = !1;
}
// Only included for completeness for now
getCoalescedEvents() {
return this.type === "pointermove" || this.type === "mousemove" || this.type === "touchmove" ? [this] : [];
}
// Only included for completeness for now
getPredictedEvents() {
throw new Error("getPredictedEvents is not supported!");
}
}
export {
FederatedPointerEvent
};
//# sourceMappingURL=FederatedPointerEvent.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedPointerEvent.mjs","sources":["../src/FederatedPointerEvent.ts"],"sourcesContent":["import { FederatedMouseEvent } from './FederatedMouseEvent';\n\n/**\n * A {@link PIXI.FederatedEvent} for pointer events.\n * @memberof PIXI\n */\nexport class FederatedPointerEvent extends FederatedMouseEvent implements PointerEvent\n{\n /**\n * The unique identifier of the pointer.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId}\n */\n public pointerId: number;\n\n /**\n * The width of the pointer's contact along the x-axis, measured in CSS pixels.\n * radiusX of TouchEvents will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width\n */\n public width = 0;\n\n /**\n * The height of the pointer's contact along the y-axis, measured in CSS pixels.\n * radiusY of TouchEvents will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height\n */\n public height = 0;\n\n /**\n * Indicates whether or not the pointer device that created the event is the primary pointer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary\n */\n public isPrimary = false;\n\n /**\n * The type of pointer that triggered the event.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType\n */\n public pointerType: string;\n\n /**\n * Pressure applied by the pointing device during the event.\n *s\n * A Touch's force property will be represented by this value.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure\n */\n public pressure: number;\n\n /**\n * Barrel pressure on a stylus pointer.\n * @see https://w3c.github.io/pointerevents/#pointerevent-interface\n */\n public tangentialPressure: number;\n\n /**\n * The angle, in degrees, between the pointer device and the screen.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX\n */\n public tiltX: number;\n\n /**\n * The angle, in degrees, between the pointer device and the screen.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY\n */\n public tiltY: number;\n\n /**\n * Twist of a stylus pointer.\n * @see https://w3c.github.io/pointerevents/#pointerevent-interface\n */\n public twist: number;\n\n /** This is the number of clicks that occurs in 200ms/click of each other. */\n public detail: number;\n\n // Only included for completeness for now\n getCoalescedEvents(): PointerEvent[]\n {\n if (this.type === 'pointermove' || this.type === 'mousemove' || this.type === 'touchmove')\n {\n return [this];\n }\n\n return [];\n }\n\n // Only included for completeness for now\n getPredictedEvents(): PointerEvent[]\n {\n throw new Error('getPredictedEvents is not supported!');\n }\n}\n"],"names":[],"mappings":";AAMO,MAAM,8BAA8B,oBAC3C;AAAA,EADO,cAAA;AAAA,UAAA,GAAA,SAAA,GAaH,KAAO,QAAQ,GAOf,KAAO,SAAS,GAMhB,KAAO,YAAY;AAAA,EAAA;AAAA;AAAA,EA4CnB,qBACA;AACI,WAAI,KAAK,SAAS,iBAAiB,KAAK,SAAS,eAAe,KAAK,SAAS,cAEnE,CAAC,IAAI,IAGT,CAAA;AAAA,EACX;AAAA;AAAA,EAGA,qBACA;AACU,UAAA,IAAI,MAAM,sCAAsC;AAAA,EAC1D;AACJ;"}

View File

@@ -0,0 +1,12 @@
"use strict";
var FederatedMouseEvent = require("./FederatedMouseEvent.js");
class FederatedWheelEvent extends FederatedMouseEvent.FederatedMouseEvent {
constructor() {
super(...arguments), this.DOM_DELTA_PIXEL = 0, this.DOM_DELTA_LINE = 1, this.DOM_DELTA_PAGE = 2;
}
}
FederatedWheelEvent.DOM_DELTA_PIXEL = 0, /** Units specified in lines. */
FederatedWheelEvent.DOM_DELTA_LINE = 1, /** Units specified in pages. */
FederatedWheelEvent.DOM_DELTA_PAGE = 2;
exports.FederatedWheelEvent = FederatedWheelEvent;
//# sourceMappingURL=FederatedWheelEvent.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedWheelEvent.js","sources":["../src/FederatedWheelEvent.ts"],"sourcesContent":["import { FederatedMouseEvent } from './FederatedMouseEvent';\n\n/**\n * A {@link PIXI.FederatedEvent} for wheel events.\n * @memberof PIXI\n */\nexport class FederatedWheelEvent extends FederatedMouseEvent implements WheelEvent\n{\n /**\n * The units of `deltaX`, `deltaY`, and `deltaZ`. This is one of `DOM_DELTA_LINE`,\n * `DOM_DELTA_PAGE`, `DOM_DELTA_PIXEL`.\n */\n deltaMode: number;\n\n /** Horizontal scroll amount */\n deltaX: number;\n\n /** Vertical scroll amount */\n deltaY: number;\n\n /** z-axis scroll amount. */\n deltaZ: number;\n\n /** Units specified in pixels. */\n static readonly DOM_DELTA_PIXEL = 0;\n\n /** Units specified in pixels. */\n readonly DOM_DELTA_PIXEL = 0;\n\n /** Units specified in lines. */\n static readonly DOM_DELTA_LINE = 1;\n\n /** Units specified in lines. */\n readonly DOM_DELTA_LINE = 1;\n\n /** Units specified in pages. */\n static readonly DOM_DELTA_PAGE = 2;\n\n /** Units specified in pages. */\n readonly DOM_DELTA_PAGE = 2;\n}\n"],"names":["FederatedMouseEvent"],"mappings":";;AAMO,MAAM,4BAA4BA,oBAAAA,oBACzC;AAAA,EADO,cAAA;AAAA,UAAA,GAAA,SAAA,GAqBH,KAAS,kBAAkB,GAM3B,KAAS,iBAAiB,GAM1B,KAAS,iBAAiB;AAAA,EAAA;AAC9B;AAlCa,oBAkBO,kBAAkB;AAlBzB,oBAwBO,iBAAiB;AAxBxB,oBA8BO,iBAAiB;;"}

View File

@@ -0,0 +1,13 @@
import { FederatedMouseEvent } from "./FederatedMouseEvent.mjs";
class FederatedWheelEvent extends FederatedMouseEvent {
constructor() {
super(...arguments), this.DOM_DELTA_PIXEL = 0, this.DOM_DELTA_LINE = 1, this.DOM_DELTA_PAGE = 2;
}
}
FederatedWheelEvent.DOM_DELTA_PIXEL = 0, /** Units specified in lines. */
FederatedWheelEvent.DOM_DELTA_LINE = 1, /** Units specified in pages. */
FederatedWheelEvent.DOM_DELTA_PAGE = 2;
export {
FederatedWheelEvent
};
//# sourceMappingURL=FederatedWheelEvent.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FederatedWheelEvent.mjs","sources":["../src/FederatedWheelEvent.ts"],"sourcesContent":["import { FederatedMouseEvent } from './FederatedMouseEvent';\n\n/**\n * A {@link PIXI.FederatedEvent} for wheel events.\n * @memberof PIXI\n */\nexport class FederatedWheelEvent extends FederatedMouseEvent implements WheelEvent\n{\n /**\n * The units of `deltaX`, `deltaY`, and `deltaZ`. This is one of `DOM_DELTA_LINE`,\n * `DOM_DELTA_PAGE`, `DOM_DELTA_PIXEL`.\n */\n deltaMode: number;\n\n /** Horizontal scroll amount */\n deltaX: number;\n\n /** Vertical scroll amount */\n deltaY: number;\n\n /** z-axis scroll amount. */\n deltaZ: number;\n\n /** Units specified in pixels. */\n static readonly DOM_DELTA_PIXEL = 0;\n\n /** Units specified in pixels. */\n readonly DOM_DELTA_PIXEL = 0;\n\n /** Units specified in lines. */\n static readonly DOM_DELTA_LINE = 1;\n\n /** Units specified in lines. */\n readonly DOM_DELTA_LINE = 1;\n\n /** Units specified in pages. */\n static readonly DOM_DELTA_PAGE = 2;\n\n /** Units specified in pages. */\n readonly DOM_DELTA_PAGE = 2;\n}\n"],"names":[],"mappings":";AAMO,MAAM,4BAA4B,oBACzC;AAAA,EADO,cAAA;AAAA,UAAA,GAAA,SAAA,GAqBH,KAAS,kBAAkB,GAM3B,KAAS,iBAAiB,GAM1B,KAAS,iBAAiB;AAAA,EAAA;AAC9B;AAlCa,oBAkBO,kBAAkB;AAlBzB,oBAwBO,iBAAiB;AAxBxB,oBA8BO,iBAAiB;"}

12
resources/app/node_modules/@pixi/events/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
var EventBoundary = require("./EventBoundary.js"), EventSystem = require("./EventSystem.js"), FederatedEvent = require("./FederatedEvent.js");
require("./FederatedEventMap.js");
var FederatedEventTarget = require("./FederatedEventTarget.js"), FederatedMouseEvent = require("./FederatedMouseEvent.js"), FederatedPointerEvent = require("./FederatedPointerEvent.js"), FederatedWheelEvent = require("./FederatedWheelEvent.js");
exports.EventBoundary = EventBoundary.EventBoundary;
exports.EventSystem = EventSystem.EventSystem;
exports.FederatedEvent = FederatedEvent.FederatedEvent;
exports.FederatedDisplayObject = FederatedEventTarget.FederatedDisplayObject;
exports.FederatedMouseEvent = FederatedMouseEvent.FederatedMouseEvent;
exports.FederatedPointerEvent = FederatedPointerEvent.FederatedPointerEvent;
exports.FederatedWheelEvent = FederatedWheelEvent.FederatedWheelEvent;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}

18
resources/app/node_modules/@pixi/events/lib/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,18 @@
import { EventBoundary } from "./EventBoundary.mjs";
import { EventSystem } from "./EventSystem.mjs";
import { FederatedEvent } from "./FederatedEvent.mjs";
import "./FederatedEventMap.mjs";
import { FederatedDisplayObject } from "./FederatedEventTarget.mjs";
import { FederatedMouseEvent } from "./FederatedMouseEvent.mjs";
import { FederatedPointerEvent } from "./FederatedPointerEvent.mjs";
import { FederatedWheelEvent } from "./FederatedWheelEvent.mjs";
export {
EventBoundary,
EventSystem,
FederatedDisplayObject,
FederatedEvent,
FederatedMouseEvent,
FederatedPointerEvent,
FederatedWheelEvent
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

38
resources/app/node_modules/@pixi/events/package.json generated vendored Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "@pixi/events",
"version": "7.4.2",
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/index.d.ts",
"default": "./lib/index.mjs"
},
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
}
},
"description": "Federated Events API, the plumbing behind the propagation of UI events into the PixiJS scene graph.",
"author": "Shukant Pal <shukant@pixijs.io>",
"homepage": "https://github.com/pixijs/pixijs#readme",
"license": "MIT",
"files": [
"lib",
"*.d.ts"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pixijs/pixijs.git"
},
"peerDependencies": {
"@pixi/core": "7.4.2",
"@pixi/display": "7.4.2"
}
}