UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 15.2 kB
{"version":3,"file":"FederatedEvent.mjs","sources":["../../src/events/FederatedEvent.ts"],"sourcesContent":["import { Point } from '../maths/point/Point';\n\nimport type { Container } from '../scene/container/Container';\nimport type { EventBoundary } from './EventBoundary';\n\n/**\n * A PixiJS compatible touch event interface that extends the standard DOM Touch interface.\n * Provides additional properties to normalize touch input with mouse/pointer events.\n * @example\n * ```ts\n * // Access touch information\n * sprite.on('touchstart', (event) => {\n * // Standard touch properties\n * console.log('Touch position:', event.clientX, event.clientY);\n * console.log('Touch ID:', event.pointerId);\n *\n * // Additional PixiJS properties\n * console.log('Pressure:', event.pressure);\n * console.log('Size:', event.width, event.height);\n * console.log('Tilt:', event.tiltX, event.tiltY);\n * });\n * ```\n * @category events\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Touch} DOM Touch Interface\n * @standard\n */\nexport interface PixiTouch extends Touch\n{\n /** The button being pressed (0: left, 1: middle, 2: right) */\n button: number;\n\n /** Bitmap of currently pressed buttons */\n buttons: number;\n\n /** Whether this is the primary touch point */\n isPrimary: boolean;\n\n /** The width of the touch contact area */\n width: number;\n\n /** The height of the touch contact area */\n height: number;\n\n /** The angle of tilt along the x-axis (in degrees) */\n tiltX: number;\n\n /** The angle of tilt along the y-axis (in degrees) */\n tiltY: number;\n\n /** The type of pointer that triggered this event */\n pointerType: string;\n\n /** Unique identifier for this touch point */\n pointerId: number;\n\n /** The normalized pressure of the pointer (0 to 1) */\n pressure: number;\n\n /** The rotation angle of the pointer (e.g., pen) */\n twist: number;\n\n /** The normalized tangential pressure of the pointer */\n tangentialPressure: number;\n\n /** The x coordinate relative to the current layer */\n layerX: number;\n\n /** The y coordinate relative to the current layer */\n layerY: number;\n\n /** The x coordinate relative to the target's offset parent */\n offsetX: number;\n\n /** The y coordinate relative to the target's offset parent */\n offsetY: number;\n\n /** Whether the event was normalized by PixiJS */\n isNormalized: boolean;\n\n /** The type of touch event */\n type: string;\n}\n\n/**\n * A DOM-compatible synthetic event implementation for PixiJS's event system.\n * This class implements the standard DOM Event interface while providing additional\n * functionality specific to PixiJS events.\n * > [!NOTE] You wont receive an instance of this class directly, but rather a subclass\n * > of this class, such as {@link FederatedPointerEvent}, {@link FederatedMouseEvent}, or\n * > {@link FederatedWheelEvent}. This class is the base for all federated events.\n * @example\n * ```ts\n * // Basic event handling\n * sprite.on('pointerdown', (event: FederatedEvent) => {\n * // Access standard DOM event properties\n * console.log('Target:', event.target);\n * console.log('Phase:', event.eventPhase);\n * console.log('Type:', event.type);\n *\n * // Control propagation\n * event.stopPropagation();\n * });\n * ```\n * @typeParam N - The type of native event held. Can be either a UIEvent or PixiTouch.\n * @remarks\n * - Implements the standard DOM UIEvent interface\n * - Provides event bubbling and capturing phases\n * - Supports propagation control\n * - Manages event paths through display tree\n * - Normalizes native browser events\n * @see {@link https://dom.spec.whatwg.org/#event} DOM Event Specification\n * @see {@link FederatedPointerEvent} For pointer-specific events\n * @see {@link FederatedMouseEvent} For mouse-specific events\n * @see {@link FederatedWheelEvent} For wheel-specific events\n * @category events\n * @standard\n */\nexport class FederatedEvent<N extends UIEvent | PixiTouch = UIEvent | PixiTouch> implements UIEvent\n{\n /** Flags whether this event bubbles. This will take effect only if it is set before propagation. */\n public bubbles = true;\n\n /** @deprecated since 7.0.0 */\n public cancelBubble = true;\n\n /**\n * Flags whether this event can be canceled using {@link FederatedEvent.preventDefault}. This is always\n * false (for now).\n */\n public readonly cancelable = false;\n\n /**\n * Flag added for compatibility with DOM `Event`. It is not used in the Federated Events\n * API.\n * @see https://dom.spec.whatwg.org/#dom-event-composed\n * @ignore\n */\n public readonly composed = false;\n\n /** The listeners of the event target that are being notified. */\n public currentTarget: Container;\n\n /** Flags whether the default response of the user agent was prevent through this event. */\n public defaultPrevented = false;\n\n /**\n * The propagation phase.\n * @default {@link FederatedEvent.NONE}\n */\n public eventPhase = FederatedEvent.prototype.NONE;\n\n /** Flags whether this is a user-trusted event */\n public isTrusted: boolean;\n\n /** @deprecated since 7.0.0 */\n public returnValue: boolean;\n\n /** @deprecated since 7.0.0 */\n public srcElement: EventTarget;\n\n /** The event target that this will be dispatched to. */\n public target: Container;\n\n /** The timestamp of when the event was created. */\n public timeStamp: number;\n\n /** The type of event, e.g. `\"mouseup\"`. */\n public type: string;\n\n /** The native event that caused the foremost original event. */\n public nativeEvent: N;\n\n /** The original event that caused this event, if any. */\n public originalEvent: FederatedEvent<N>;\n\n /** Flags whether propagation was stopped. */\n public propagationStopped = false;\n\n /** Flags whether propagation was immediately stopped. */\n public propagationImmediatelyStopped = false;\n\n /** The composed path of the event's propagation. The `target` is at the end. */\n public path: Container[];\n\n /** The {@link EventBoundary} that manages this event. Null for root events. */\n public readonly manager: EventBoundary;\n\n /** Event-specific detail */\n public detail: number;\n\n /** The global Window object. */\n public view: WindowProxy;\n\n /**\n * Not supported.\n * @deprecated since 7.0.0\n * @ignore\n */\n public which: number;\n\n /** The coordinates of the event relative to the nearest DOM layer. This is a non-standard property. */\n public layer: Point = new Point();\n\n /** @readonly */\n get layerX(): number { return this.layer.x; }\n\n /** @readonly */\n get layerY(): number { return this.layer.y; }\n\n /** The coordinates of the event relative to the DOM document. This is a non-standard property. */\n public page: Point = new Point();\n\n /** @readonly */\n get pageX(): number { return this.page.x; }\n\n /** @readonly */\n get pageY(): number { return this.page.y; }\n\n /**\n * @param manager - The event boundary which manages this event. Propagation can only occur\n * within the boundary's jurisdiction.\n */\n constructor(manager: EventBoundary)\n {\n this.manager = manager;\n }\n\n /**\n * Fallback for the deprecated `InteractionEvent.data`.\n * @deprecated since 7.0.0\n */\n get data(): this\n {\n return this;\n }\n\n /**\n * The propagation path for this event. Alias for {@link EventBoundary.propagationPath}.\n * @advanced\n */\n public composedPath(): Container[]\n {\n // Find the propagation path if it isn't cached or if the target has changed since since\n // the last evaluation.\n if (this.manager && (!this.path || this.path[this.path.length - 1] !== this.target))\n {\n this.path = this.target ? this.manager.propagationPath(this.target) : [];\n }\n\n return this.path;\n }\n\n /**\n * Unimplemented method included for implementing the DOM interface `Event`. It will throw an `Error`.\n * @deprecated\n * @ignore\n * @param _type\n * @param _bubbles\n * @param _cancelable\n */\n public initEvent(_type: string, _bubbles?: boolean, _cancelable?: boolean): void\n {\n throw new Error('initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.');\n }\n\n /**\n * Unimplemented method included for implementing the DOM interface `UIEvent`. It will throw an `Error`.\n * @ignore\n * @deprecated\n * @param _typeArg\n * @param _bubblesArg\n * @param _cancelableArg\n * @param _viewArg\n * @param _detailArg\n */\n public initUIEvent(_typeArg: string, _bubblesArg?: boolean, _cancelableArg?: boolean, _viewArg?: Window | null,\n _detailArg?: number): void\n {\n throw new Error('initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.');\n }\n\n /**\n * Prevent default behavior of both PixiJS and the user agent.\n * @example\n * ```ts\n * sprite.on('click', (event) => {\n * // Prevent both browser's default click behavior\n * // and PixiJS's default handling\n * event.preventDefault();\n *\n * // Custom handling\n * customClickHandler();\n * });\n * ```\n * @remarks\n * - Only works if the native event is cancelable\n * - Does not stop event propagation\n */\n public preventDefault(): void\n {\n if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable)\n {\n this.nativeEvent.preventDefault();\n }\n\n this.defaultPrevented = true;\n }\n\n /**\n * Stop this event from propagating to any additional listeners, including those\n * on the current target and any following targets in the propagation path.\n * @example\n * ```ts\n * container.on('pointerdown', (event) => {\n * // Stop all further event handling\n * event.stopImmediatePropagation();\n *\n * // These handlers won't be called:\n * // - Other pointerdown listeners on this container\n * // - Any pointerdown listeners on parent containers\n * });\n * ```\n * @remarks\n * - Immediately stops all event propagation\n * - Prevents other listeners on same target from being called\n * - More aggressive than stopPropagation()\n */\n public stopImmediatePropagation(): void\n {\n this.propagationImmediatelyStopped = true;\n }\n\n /**\n * Stop this event from propagating to the next target in the propagation path.\n * The rest of the listeners on the current target will still be notified.\n * @example\n * ```ts\n * child.on('pointermove', (event) => {\n * // Handle event on child\n * updateChild();\n *\n * // Prevent parent handlers from being called\n * event.stopPropagation();\n * });\n *\n * // This won't be called if child handles the event\n * parent.on('pointermove', (event) => {\n * updateParent();\n * });\n * ```\n * @remarks\n * - Stops event bubbling to parent containers\n * - Does not prevent other listeners on same target\n * - Less aggressive than stopImmediatePropagation()\n */\n public stopPropagation(): void\n {\n this.propagationStopped = true;\n }\n\n /**\n * The event propagation phase NONE that indicates that the event is not in any phase.\n * @default 0\n * @advanced\n */\n public readonly NONE = 0;\n /**\n * The event propagation phase CAPTURING_PHASE that indicates that the event is in the capturing phase.\n * @default 1\n * @advanced\n */\n public readonly CAPTURING_PHASE = 1;\n /**\n * The event propagation phase AT_TARGET that indicates that the event is at the target.\n * @default 2\n * @advanced\n */\n public readonly AT_TARGET = 2;\n /**\n * The event propagation phase BUBBLING_PHASE that indicates that the event is in the bubbling phase.\n * @default 3\n * @advanced\n */\n public readonly BUBBLING_PHASE = 3;\n}\n"],"names":[],"mappings":";;;AAqHO,MAAM,cACb,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwGI,YAAY,OACZ,EAAA;AAvGA;AAAA,IAAA,IAAA,CAAO,OAAU,GAAA,IAAA,CAAA;AAGjB;AAAA,IAAA,IAAA,CAAO,YAAe,GAAA,IAAA,CAAA;AAMtB;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAgB,UAAa,GAAA,KAAA,CAAA;AAQ7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAgB,QAAW,GAAA,KAAA,CAAA;AAM3B;AAAA,IAAA,IAAA,CAAO,gBAAmB,GAAA,KAAA,CAAA;AAM1B;AAAA;AAAA;AAAA;AAAA,IAAO,IAAA,CAAA,UAAA,GAAa,eAAe,SAAU,CAAA,IAAA,CAAA;AA2B7C;A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