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sB,EAAS,GAClC,cAAc,WAAa,QAAQ,IAAI,WAAW,aAAmB,WACrE,SAAS,cAAc,IAAI,YAAY,kBAAmB,CACtD,OAAQ,CAAE,UAAS,YAE3B,EAEJ,QAAQ,cAAgB","file":"/npm/gamepad-helper@1.2.3/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gamepad-helper@1.2.3/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.GamepadHelper = void 0;\nclass GamepadHelper {\n    static gamepads = {};\n    static gamepadsLastUpdate;\n    static logOutput = false;\n    /** Return the state of the specified button */\n    static getButtonValue(gamepad, button) {\n        return GamepadHelper.gamepads[gamepad]?.buttons[button]?.value;\n    }\n    /** Return the state of the specified axis */\n    static getAxisValue(gamepad, axis) {\n        return GamepadHelper.gamepads[gamepad]?.axes[axis];\n    }\n    /**\tMain method intended to be called from within a game loop.\n     *\tQueries the state of each button on each connected gamepad and dispatches an event to the document if there is change in state.\n     */\n    static update() {\n        GamepadHelper.checkForNewGamepads();\n        // skip if there are no gamepads connected\n        if (!GamepadHelper.gamepads || Object.keys(GamepadHelper.gamepads).length < 1)\n            return;\n        if (GamepadHelper.gamepadsLastUpdate &&\n            Object.keys(GamepadHelper.gamepadsLastUpdate).length > 0) {\n            Object.values(GamepadHelper.gamepads).forEach((gamepad) => {\n                // check for changes in button state\n                for (let i = 0; i < gamepad.buttons.length; i++) {\n                    const buttonLastUpdate = GamepadHelper.gamepadsLastUpdate[gamepad.index]?.buttons[i];\n                    const button = gamepad.buttons[i];\n                    if (button?.value == 1 && buttonLastUpdate?.value == 0) {\n                        GamepadHelper.dispatchButtonDownEvent(gamepad.index, i);\n                    }\n                    else if (button?.value == 0 && buttonLastUpdate?.value == 1) {\n                        GamepadHelper.dispatchButtonUpEvent(gamepad.index, i);\n                    }\n                }\n            });\n        }\n        // copy to a separate object in order to compare fields next update\n        GamepadHelper.gamepadsLastUpdate = Object.assign({}, GamepadHelper.gamepads);\n    }\n    static checkForNewGamepads() {\n        // @ts-ignore\n        const gamepads = navigator.getGamepads();\n        for (const gamepad of gamepads) {\n            if (gamepad) {\n                if (!GamepadHelper.gamepads[gamepad.index]) {\n                    GamepadHelper.logOutput &&\n                        console.log(\"gamepad \" + gamepad.index + \" connected\");\n                }\n                GamepadHelper.gamepads[gamepad.index] = gamepad;\n            }\n        }\n    }\n    static dispatchButtonDownEvent(gamepad, button) {\n        GamepadHelper.logOutput && console.log(`gamepad ${gamepad}: button ${button} is down`);\n        document.dispatchEvent(new CustomEvent(\"gamepadbuttondown\", {\n            detail: { gamepad, button }\n        }));\n    }\n    static dispatchButtonUpEvent(gamepad, button) {\n        GamepadHelper.logOutput && console.log(`gamepad ${gamepad}: button ${button} is up`);\n        document.dispatchEvent(new CustomEvent(\"gamepadbuttonup\", {\n            detail: { gamepad, button }\n        }));\n    }\n}\nexports.GamepadHelper = GamepadHelper;\n"]}