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ystick-controller.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/joystick-controller@1.1.0/dist/lib/joystick-controller.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\";\n\nexports.__esModule = true;\nexports.default = exports.MOUSE_CLICK_BUTTONS = void 0;\n// Joystick window identifier\nvar JOYSTICK_WINDOW_IDENTIFIER = \"__joysticks_identifiers__\";\n// Active joystick window\nvar JOYSTICK_WINDOW_ACTIVE = \"__active_joysticks__\";\n// Mouse click buttons constants\nvar MOUSE_CLICK_BUTTONS = {\n  ALL: -1,\n  LEFT: 0,\n  MIDDLE: 1,\n  RIGHT: 2\n};\n/**\n * A JavaScript library for creating a virtual joystick.\n * @author Cyrus Mobini\n * @version 1.1.0\n * @docs https://github.com/cyrus2281/joystick-controller#readme\n */\nexports.MOUSE_CLICK_BUTTONS = MOUSE_CLICK_BUTTONS;\nvar JoystickController = /** @class */function () {\n  /**\n   * Constructor for the joystick controller\n   * @param options Joystick options\n   * @param onMove Callback function when the joystick moves\n   */\n  function JoystickController(options, onMove) {\n    var _this = this;\n    /**\n     * Default transition for the joystick\n     */\n    this.JOYSTICK_TRANSITION = \"border-radius 0.2s ease-in-out\";\n    /**\n     * Default options for the joystick\n     */\n    this.options = {\n      maxRange: 100,\n      level: 10,\n      radius: 50,\n      joystickRadius: 30,\n      opacity: 0.8,\n      leftToRight: true,\n      bottomToUp: true,\n      containerClass: \"\",\n      controllerClass: \"\",\n      joystickClass: \"\",\n      x: \"50%\",\n      y: \"50%\",\n      distortion: false,\n      dynamicPosition: false,\n      dynamicPositionTarget: null,\n      mouseClickButton: -1,\n      hideContextMenu: false\n    };\n    /**\n     * x position of the joystick.\n     */\n    this.x = 0;\n    /**\n     * y position of the joystick.\n     */\n    this.y = 0;\n    /**\n     * x position of the joystick scaled to be between -level and +level.\n     */\n    this.leveledX = 0;\n    /**\n     * y position of the joystick scaled to be between -level and +level.\n     */\n    this.leveledY = 0;\n    /**\n     * Angle of the joystick in radians.\n     */\n    this.angle = 0;\n    /**\n     * Distance of the joystick dot from the center.\n     */\n    this.distance = 0;\n    /**\n     * Indicates if the joystick movement has started.\n     */\n    this.started = false;\n    /**\n     * Identifier for the joystick for dynamic positioning.\n     */\n    this.identifier = null;\n    /**\n     * Mouse button to listen on.\n     */\n    this.mouseButton = -1;\n    /**\n     * Adds necessary event listeners for the joystick.\n     */\n    this.addEventListeners = function () {\n      var mcb = _this.options.mouseClickButton;\n      if (typeof mcb === \"string\" && Object.keys(MOUSE_CLICK_BUTTONS).includes(mcb) || typeof mcb === \"number\" && mcb < 6 && mcb > -2) {\n        _this.mouseButton = typeof mcb === \"string\" ? MOUSE_CLICK_BUTTONS[mcb] : mcb;\n      }\n      if (_this.options.dynamicPosition) {\n        var target = _this.options.dynamicPositionTarget || document;\n        // mouse events Listeners\n        target.addEventListener(\"mousedown\", _this.dynamicPositioningMouse);\n        document.addEventListener(\"mouseup\", _this.removeDynamicPositioning);\n        // touch events Listeners\n        target.addEventListener(\"touchstart\", _this.dynamicPositioningTouch);\n        document.addEventListener(\"touchmove\", _this.onTouchEvent, {\n          passive: false\n        });\n        document.addEventListener(\"touchend\", _this.removeDynamicPositioning);\n        if (_this.options.hideContextMenu) {\n          target.addEventListener(\"contextmenu\", function (e) {\n            return e.preventDefault();\n          });\n          _this.joystick.addEventListener(\"contextmenu\", function (e) {\n            return e.preventDefault();\n          });\n        }\n      } else {\n        // touch events Listeners\n        _this.joystick.addEventListener(\"touchstart\", _this.onStartEvent);\n        _this.joystick.addEventListener(\"touchmove\", _this.onTouchEvent);\n        _this.joystick.addEventListener(\"touchend\", _this.onStopEvent);\n        // mouse events Listeners\n        _this.joystick.addEventListener(\"mousedown\", _this.onStartEvent);\n        if (_this.options.hideContextMenu) {\n          _this.container.addEventListener(\"contextmenu\", function (e) {\n            return e.preventDefault();\n          });\n          _this.joystick.addEventListener(\"contextmenu\", function (e) {\n            return e.preventDefault();\n          });\n        }\n      }\n      // window resize listener\n      window.addEventListener(\"resize\", _this.recenterJoystick);\n    };\n    /**\n     * Fetch the coordinates of the joystick container\n     * base on user click, and adds it to document\n     * @param e MouseEvent\n     */\n    this.dynamicPositioningMouse = function (e) {\n      if (_this.identifier !== null) return;\n      if (_this.mouseButton !== -1 && e.button !== _this.mouseButton) return;\n      var identifier = e.x + \"-\" + e.y;\n      if (window[JOYSTICK_WINDOW_IDENTIFIER].has(identifier)) return;\n      _this.identifier = identifier;\n      window[JOYSTICK_WINDOW_IDENTIFIER].add(_this.identifier);\n      var x = e.clientX;\n      var y = e.clientY;\n      _this.container.style.left = x + \"px\";\n      _this.container.style.top = y + \"px\";\n      _this.container.style.bottom = \"unset\";\n      _this.container.style.right = \"unset\";\n      document.body.appendChild(_this.container);\n      _this.recenterJoystick();\n      _this.onStartEvent(e, false);\n    };\n    /**\n     * Fetch the coordinates of the joystick container\n     * base on user touch, and adds it to document\n     * @param event touchstart event\n     */\n    this.dynamicPositioningTouch = function (event) {\n      if (_this.identifier !== null) return;\n      var identifier = event.changedTouches[0].identifier;\n      if (window[JOYSTICK_WINDOW_IDENTIFIER].has(identifier)) return;\n      _this.identifier = identifier;\n      window[JOYSTICK_WINDOW_IDENTIFIER].add(identifier);\n      // Current touch (for multi-touch)\n      var touch;\n      for (var i = 0; i < event.touches.length; i++) {\n        var tc = event.touches.item(i);\n        if (_this.identifier === (tc === null || tc === void 0 ? void 0 : tc.identifier)) {\n          touch = tc;\n          break;\n        }\n      }\n      if (!touch) return;\n      var x = touch.clientX;\n      var y = touch.clientY;\n      _this.container.style.left = x + \"px\";\n      _this.container.style.top = y + \"px\";\n      _this.container.style.bottom = \"unset\";\n      _this.container.style.right = \"unset\";\n      document.body.appendChild(_this.container);\n      _this.recenterJoystick();\n      _this.onStartEvent(event, false);\n    };\n    /**\n     * Stop the dynamic positioning of the joystick\n     * @param  e mousedown/touchend event\n     */\n    this.removeDynamicPositioning = function (e) {\n      if (_this.identifier === null) return;\n      if (e.type === \"touchend\") {\n        var identifier = e.changedTouches[0].identifier;\n        if (_this.identifier !== identifier) return;\n      } else if (_this.mouseButton !== -1 && e.button !== _this.mouseButton) return;\n      window[JOYSTICK_WINDOW_IDENTIFIER].delete(_this.identifier);\n      _this.identifier = null;\n      _this.onStopEvent(e);\n      _this.container.remove();\n    };\n    /**\n     * Updating the x,y, distance,angle, and joystick position base on the x and y\n     * @param x x coordinate\n     * @param y y coordinate\n     */\n    this.updateCoordinates = function (x, y) {\n      // distance from center\n      _this.distance = +Math.sqrt(Math.pow(x - _this.centerX, 2) + Math.pow(y - _this.centerY, 2)).toFixed(4);\n      // angle from center in Radians\n      _this.angle = +Math.atan2(y - _this.centerY, x - _this.centerX).toFixed(4);\n      // considering max range\n      var adjustedDistance = _this.distance > _this.options.maxRange ? _this.options.maxRange : _this.distance;\n      // x offset from center\n      _this.x = Math.round(Math.cos(_this.angle) * adjustedDistance);\n      // y offset from center\n      _this.y = -Math.round(Math.sin(_this.angle) * adjustedDistance);\n      // Scaling x and y to be between -level and +level\n      _this.leveledX = Math.round(_this.x / _this.options.maxRange * _this.options.level);\n      _this.leveledY = Math.round(_this.y / _this.options.maxRange * _this.options.level);\n      // setting position of stick\n      _this.joystick.style.left = _this.options.radius + _this.x + \"px\";\n      _this.joystick.style.bottom = _this.options.radius + _this.y + \"px\";\n      // distort joystick\n      _this.options.distortion && _this.distortJoystick();\n      // Triggering Event\n      _this.onMove && _this.onMove({\n        x: _this.x,\n        y: _this.y,\n        leveledX: _this.leveledX,\n        leveledY: _this.leveledY,\n        distance: _this.distance,\n        angle: _this.angle\n      });\n    };\n    /**\n     * Resting Coordinates\n     */\n    this.resetCoordinates = function () {\n      _this.x = 0;\n      _this.y = 0;\n      _this.leveledX = 0;\n      _this.leveledY = 0;\n      _this.angle = 0;\n      _this.distance = 0;\n      // reset position of stick\n      _this.joystick.style.left = _this.options.radius + \"px\";\n      _this.joystick.style.bottom = _this.options.radius + \"px\";\n      // reset joystick distortion\n      _this.options.distortion && _this.distortJoystick();\n      // Triggering Event\n      _this.onMove && _this.onMove({\n        x: _this.x,\n        y: _this.y,\n        leveledX: _this.leveledX,\n        leveledY: _this.leveledY,\n        distance: _this.distance,\n        angle: _this.angle\n      });\n    };\n    /**\n     * Distort joystick based on distance if further than 70% of maxRange\n     */\n    this.distortJoystick = function () {\n      if (_this.distance > _this.options.maxRange * 0.7) {\n        // distorting joystick\n        _this.joystick.style.borderRadius = \"70% 80% 70% 15%\";\n        _this.joystick.style.transform = \"translate(-50%, 50%) rotate(\".concat(+_this.angle + Math.PI / 4, \"rad)\");\n      } else {\n        // resting to default\n        _this.joystick.style.borderRadius = \"50%\";\n        _this.joystick.style.transform = \"translate(-50%, 50%) rotate(\".concat(Math.PI / 4, \"rad})\");\n      }\n    };\n    /**\n     * on grab joystick event\n     * @param event\n     */\n    this.onStartEvent = function (event, addIdentifier) {\n      if (addIdentifier === void 0) {\n        addIdentifier = true;\n      }\n      if (event.type === \"mousedown\") {\n        if (_this.mouseButton !== -1 && event.button !== _this.mouseButton) return;\n        window.addEventListener(\"mousemove\", _this.onMouseEvent);\n        window.addEventListener(\"mouseup\", _this.onStopEvent);\n      } else if (addIdentifier) {\n        var identifier = event.changedTouches[0].identifier;\n        _this.identifier = identifier;\n      }\n      _this.started = true;\n      // style adjustment\n      _this.joystick.style.transition = _this.JOYSTICK_TRANSITION;\n      _this.joystick.style.cursor = \"grabbing\";\n    };\n    /**\n     * On leave joystick event\n     * @param event leave joystick event\n     */\n    this.onStopEvent = function (event) {\n      if (event.type === \"mouseup\") {\n        if (_this.mouseButton !== -1 && event.button !== _this.mouseButton) return;\n        window.removeEventListener(\"mousemove\", _this.onMouseEvent);\n        window.removeEventListener(\"mouseup\", _this.onStopEvent);\n      } else {\n        _this.identifier = null;\n      }\n      _this.started = false;\n      // style adjustment\n      _this.joystick.style.transition = \"all 0.2s ease-in-out\";\n      _this.joystick.style.cursor = \"grab\";\n      // reset values\n      _this.resetCoordinates();\n    };\n    /**\n     * Update the coordinates of the joystick on touch move\n     * @param event touch move event\n     */\n    this.onTouchEvent = function (event) {\n      // Current touch (for multi-touch)\n      var touch;\n      for (var i = 0; i < event.touches.length; i++) {\n        var tc = event.touches.item(i);\n        if (_this.identifier === (tc === null || tc === void 0 ? void 0 : tc.identifier)) {\n          touch = tc;\n          break;\n        }\n      }\n      if (!touch) return;\n      event.preventDefault();\n      // position of touch\n      var x = touch.clientX;\n      var y = touch.clientY;\n      // update coordinates\n      _this.updateCoordinates(x, y);\n    };\n    /**\n     * Update the coordinates of the joystick on mouse move\n     * @param event mouse move event\n     */\n    this.onMouseEvent = function (event) {\n      if (!_this.started) return;\n      event.preventDefault();\n      // position of mouse\n      var x = event.clientX;\n      var y = event.clientY;\n      // distance from center\n      _this.updateCoordinates(x, y);\n    };\n    /**\n     * Update the center coordinates of the joystick on window resize\n     */\n    this.recenterJoystick = function () {\n      // update the center coordinates\n      _this.centerX = _this.controller.getBoundingClientRect().left + _this.options.radius;\n      _this.centerY = _this.controller.getBoundingClientRect().top + _this.options.radius;\n    };\n    this.options = Object.assign(this.options, options);\n    this.onMove = onMove;\n    this.validate();\n    this.init();\n  }\n  /**\n   * Validates if there are any conflicting dynamicPosition options among active joysticks.\n   */\n  JoystickController.prototype.validate = function () {\n    var _this = this;\n    if (window[JOYSTICK_WINDOW_ACTIVE] && window[JOYSTICK_WINDOW_ACTIVE].length > 0 && window[JOYSTICK_WINDOW_ACTIVE].some(function (j) {\n      return j.options.dynamicPosition && (j.options.dynamicPositionTarget || document) === (_this.options.dynamicPositionTarget || document);\n    })) {\n      console.error(\"Multiple dynamicPosition should be used with different target elements (dynamicPositionTarget) to prevent event collision.\");\n    }\n  };\n  /**\n   * Initializes the joystick controller.\n   */\n  JoystickController.prototype.init = function () {\n    // Adding identifier array to window\n    if (!window[JOYSTICK_WINDOW_IDENTIFIER]) {\n      window[JOYSTICK_WINDOW_IDENTIFIER] = new Set();\n    }\n    // Generate a unique ID for the joystick\n    this.id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);\n    // Adding to active joysticks\n    window[JOYSTICK_WINDOW_ACTIVE] = Object.assign(window[JOYSTICK_WINDOW_ACTIVE] || [], [this]);\n    // Styles for the joystick\n    this.style = document.createElement(\"style\");\n    this.style.setAttribute(\"id\", \"style-\" + this.id);\n    this.style.innerHTML = \"\\n        .joystick-container-\".concat(this.id, \" {\\n            box-sizing: border-box;\\n            position: fixed;\\n            outline: none;\\n            \").concat(this.options.leftToRight ? \"left\" : \"right\", \": \").concat(this.options.x, \";\\n            \").concat(this.options.bottomToUp ? \"bottom\" : \"top\", \": \").concat(this.options.y, \";\\n            transform: translate(\").concat(this.options.dynamicPosition || this.options.leftToRight ? \"-50%\" : \"50%\", \", \").concat(this.options.dynamicPosition || !this.options.bottomToUp ? \"-50%\" : \"50%\", \");\\n        }\\n    \\n        .joystick-controller-\").concat(this.id, \" {\\n            box-sizing: border-box;\\n            outline: none;\\n            opacity: \").concat(this.options.opacity, \";\\n            width: \").concat(this.options.radius * 2, \"px;\\n            height: \").concat(this.options.radius * 2, \"px;\\n            border-radius: 50%;\\n            position: relative;\\n            outline: 2px solid #4c4c4c77;\\n            background: radial-gradient(circle,#ebebeb55, #5c5c5c55);\\n        }\\n    \\n        .joystick-\").concat(this.id, \" {\\n            box-sizing: border-box;\\n            outline: none;\\n            position: absolute;\\n            cursor: grab;\\n            width: \").concat(this.options.joystickRadius * 2, \"px;\\n            height: \").concat(this.options.joystickRadius * 2, \"px;\\n            z-index: 1;\\n            border-radius: 50%;\\n            left: 50%;\\n            bottom: 50%;\\n            transform: translate(-50%, 50%);\\n            background: radial-gradient(#000c, #3e3f46aa);\\n            transition: \").concat(this.JOYSTICK_TRANSITION, \";\\n        }\\n        \");\n    // Container for the joystick\n    this.container = document.createElement(\"div\");\n    this.container.setAttribute(\"id\", \"joystick-container-\" + this.id);\n    this.container.setAttribute(\"class\", \"joystick-container-\" + this.id + \" \" + this.options.containerClass);\n    // Controller for the joystick\n    this.controller = document.createElement(\"div\");\n    this.controller.setAttribute(\"id\", \"joystick-controller-\" + this.id);\n    this.controller.setAttribute(\"class\", \"joystick-controller-\" + this.id + \" \" + this.options.controllerClass);\n    // Actual joystick element\n    this.joystick = document.createElement(\"div\");\n    this.joystick.setAttribute(\"id\", \"joystick-\" + this.id);\n    this.joystick.setAttribute(\"class\", \"joystick-\" + this.id + \" \" + this.options.joystickClass);\n    // Append the joystick elements to the DOM\n    this.controller.appendChild(this.joystick);\n    this.container.appendChild(this.controller);\n    document.head.appendChild(this.style);\n    if (!this.options.dynamicPosition) {\n      document.body.appendChild(this.container);\n    }\n    // Add event listeners for interaction\n    this.addEventListeners();\n    // Center of the joystick\n    this.recenterJoystick();\n    // Resting coordinates\n    this.resetCoordinates();\n  };\n  /**\n   * To remove the joystick from the DOM and clear all the listeners\n   */\n  JoystickController.prototype.destroy = function () {\n    var _this = this;\n    // removing event listeners\n    if (this.options.dynamicPosition) {\n      var target = this.options.dynamicPositionTarget || document;\n      // mouse events Listeners\n      target.removeEventListener(\"mousedown\", this.dynamicPositioningMouse);\n      document.removeEventListener(\"mouseup\", this.removeDynamicPositioning);\n      // touch events Listeners\n      target.removeEventListener(\"touchstart\", this.dynamicPositioningTouch);\n      document.removeEventListener(\"touchmove\", this.onTouchEvent);\n      document.removeEventListener(\"touchend\", this.removeDynamicPositioning);\n    } else {\n      // touch events Listeners\n      this.joystick.removeEventListener(\"touchstart\", this.onStartEvent);\n      this.joystick.removeEventListener(\"touchmove\", this.onTouchEvent);\n      this.joystick.removeEventListener(\"touchend\", this.onStopEvent);\n      // mouse events Listeners\n      this.joystick.removeEventListener(\"mousedown\", this.onStartEvent);\n    }\n    window.removeEventListener(\"resize\", this.recenterJoystick);\n    // removing elements\n    this.style.remove();\n    this.container.remove();\n    // removing from active joysticks\n    if (Array.isArray(window[JOYSTICK_WINDOW_ACTIVE])) window[JOYSTICK_WINDOW_ACTIVE] = window[JOYSTICK_WINDOW_ACTIVE].filter(function (joystick) {\n      return joystick !== _this;\n    });\n  };\n  return JoystickController;\n}();\nvar _default = JoystickController;\nexports.default = _default;"]}