{"version":3,"file":"EventTicker.mjs","sources":["../src/EventTicker.ts"],"sourcesContent":["import { Ticker, UPDATE_PRIORITY } from '@pixi/core';\n\nimport type { EventSystem } from './EventSystem';\n\n/**\n * This class handles automatic firing of PointerEvents\n * in the case where the pointer is stationary for too long.\n * This is to ensure that hit-tests are still run on moving objects.\n * @memberof PIXI\n * @since 7.2.0\n * @see PIXI.EventsTicker\n */\nclass EventsTickerClass\n{\n    /** The event system. */\n    public events: EventSystem;\n    /** The DOM element to listen to events on. */\n    public domElement: HTMLElement;\n    /** The frequency that fake events will be fired. */\n    public interactionFrequency = 10;\n\n    private _deltaTime = 0;\n    private _didMove = false;\n    private tickerAdded = false;\n    private _pauseUpdate = true;\n\n    /**\n     * Initializes the event ticker.\n     * @param events - The event system.\n     */\n    public init(events: EventSystem): void\n    {\n        this.removeTickerListener();\n        this.events = events;\n        this.interactionFrequency = 10;\n        this._deltaTime = 0;\n        this._didMove = false;\n        this.tickerAdded = false;\n        this._pauseUpdate = true;\n    }\n\n    /** Whether to pause the update checks or not. */\n    get pauseUpdate(): boolean\n    {\n        return this._pauseUpdate;\n    }\n\n    set pauseUpdate(paused: boolean)\n    {\n        this._pauseUpdate = paused;\n    }\n\n    /** Adds the ticker listener. */\n    public addTickerListener(): void\n    {\n        if (this.tickerAdded || !this.domElement)\n        {\n            return;\n        }\n\n        Ticker.system.add(this.tickerUpdate, this, UPDATE_PRIORITY.INTERACTION);\n\n        this.tickerAdded = true;\n    }\n\n    /** Removes the ticker listener. */\n    public removeTickerListener(): void\n    {\n        if (!this.tickerAdded)\n        {\n            return;\n        }\n\n        Ticker.system.remove(this.tickerUpdate, this);\n\n        this.tickerAdded = false;\n    }\n\n    /** Sets flag to not fire extra events when the user has already moved there mouse */\n    public pointerMoved(): void\n    {\n        this._didMove = true;\n    }\n\n    /** Updates the state of interactive objects. */\n    private update(): void\n    {\n        if (!this.domElement || this._pauseUpdate)\n        {\n            return;\n        }\n\n        // if the user move the mouse this check has already been done using the mouse move!\n        if (this._didMove)\n        {\n            this._didMove = false;\n\n            return;\n        }\n\n        // eslint-disable-next-line dot-notation\n        const rootPointerEvent = this.events['rootPointerEvent'];\n\n        if (this.events.supportsTouchEvents && (rootPointerEvent as PointerEvent).pointerType === 'touch')\n        {\n            return;\n        }\n\n        globalThis.document.dispatchEvent(new PointerEvent('pointermove', {\n            clientX: rootPointerEvent.clientX,\n            clientY: rootPointerEvent.clientY,\n        }));\n    }\n\n    /**\n     * Updates the state of interactive objects if at least {@link PIXI.EventsTicker#interactionFrequency}\n     * milliseconds have passed since the last invocation.\n     *\n     * Invoked by a throttled ticker update from {@link PIXI.Ticker.system}.\n     * @param deltaTime - time delta since the last call\n     */\n    private tickerUpdate(deltaTime: number): void\n    {\n        this._deltaTime += deltaTime;\n\n        if (this._deltaTime < this.interactionFrequency)\n        {\n            return;\n        }\n\n        this._deltaTime = 0;\n\n        this.update();\n    }\n}\n\n/**\n * This class handles automatic firing of PointerEvents\n * in the case where the pointer is stationary for too long.\n * This is to ensure that hit-tests are still run on moving objects.\n * @memberof PIXI\n * @type {PIXI.EventsTickerClass}\n * @since 7.2.0\n */\nexport const EventsTicker = new EventsTickerClass();\n"],"names":[],"mappings":";AAYA,MAAM,kBACN;AAAA,EADA,cAAA;AAOI,SAAO,uBAAuB,IAE9B,KAAQ,aAAa,GACrB,KAAQ,WAAW,IACnB,KAAQ,cAAc,IACtB,KAAQ,eAAe;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhB,KAAK,QACZ;AACI,SAAK,wBACL,KAAK,SAAS,QACd,KAAK,uBAAuB,IAC5B,KAAK,aAAa,GAClB,KAAK,WAAW,IAChB,KAAK,cAAc,IACnB,KAAK,eAAe;AAAA,EACxB;AAAA;AAAA,EAGA,IAAI,cACJ;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,YAAY,QAChB;AACI,SAAK,eAAe;AAAA,EACxB;AAAA;AAAA,EAGO,oBACP;AACQ,SAAK,eAAe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