@pinkaphant/ecctrl 0.0.0-stage → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +10 -0
  4. package/dist/Color-V9u0UyNg.cjs +81 -0
  5. package/dist/Color-V9u0UyNg.cjs.map +1 -0
  6. package/dist/Color-rCfz0rNn.js +28 -0
  7. package/dist/Color-rCfz0rNn.js.map +1 -0
  8. package/dist/CurveLUT-BfMhx3LX.js +88 -0
  9. package/dist/CurveLUT-BfMhx3LX.js.map +1 -0
  10. package/dist/CurveLUT-Ck18ZlkK.cjs +99 -0
  11. package/dist/CurveLUT-Ck18ZlkK.cjs.map +1 -0
  12. package/dist/EcctrlAnimationStateController-41Cm1Tt1.cjs +111 -0
  13. package/dist/EcctrlAnimationStateController-41Cm1Tt1.cjs.map +1 -0
  14. package/dist/EcctrlAnimationStateController-Bb2fARWF.js +94 -0
  15. package/dist/EcctrlAnimationStateController-Bb2fARWF.js.map +1 -0
  16. package/dist/Math-BkrN2TZK.js +49 -0
  17. package/dist/Math-BkrN2TZK.js.map +1 -0
  18. package/dist/Math-ByyUpUHB.cjs +68 -0
  19. package/dist/Math-ByyUpUHB.cjs.map +1 -0
  20. package/dist/all.cjs +52 -0
  21. package/dist/all.cjs.map +1 -0
  22. package/dist/all.d.ts +16 -0
  23. package/dist/all.js +32 -0
  24. package/dist/all.js.map +1 -0
  25. package/dist/animation.cjs +23 -0
  26. package/dist/animation.cjs.map +1 -0
  27. package/dist/animation.d.ts +8 -0
  28. package/dist/animation.js +20 -0
  29. package/dist/animation.js.map +1 -0
  30. package/dist/camera-B_UgIm14.js +71 -0
  31. package/dist/camera-B_UgIm14.js.map +1 -0
  32. package/dist/camera-CzMKt9dI.cjs +79 -0
  33. package/dist/camera-CzMKt9dI.cjs.map +1 -0
  34. package/dist/camera.cjs +10 -0
  35. package/dist/camera.d.ts +9 -0
  36. package/dist/camera.js +9 -0
  37. package/dist/character/Ecctrl.d.ts +105 -0
  38. package/dist/character/animation/EcctrlAnimationStateController.d.ts +17 -0
  39. package/dist/character/animation/index.d.ts +13 -0
  40. package/dist/character/animation/resolveAnimationState.d.ts +9 -0
  41. package/dist/character/animation/types.d.ts +19 -0
  42. package/dist/character/animation/useEcctrlAnimationStore.d.ts +21 -0
  43. package/dist/character/types.d.ts +27 -0
  44. package/dist/chunk-D6vf50IK.cjs +35 -0
  45. package/dist/curves/CurveLUT.d.ts +27 -0
  46. package/dist/curves.cjs +22 -0
  47. package/dist/curves.cjs.map +1 -0
  48. package/dist/curves.d.ts +9 -0
  49. package/dist/curves.js +20 -0
  50. package/dist/curves.js.map +1 -0
  51. package/dist/gravity/EcctrlCameraControls.d.ts +28 -0
  52. package/dist/gravity/useCustomGravity.d.ts +23 -0
  53. package/dist/gravity.cjs +21 -0
  54. package/dist/gravity.cjs.map +1 -0
  55. package/dist/gravity.d.ts +9 -0
  56. package/dist/gravity.js +20 -0
  57. package/dist/gravity.js.map +1 -0
  58. package/dist/index.cjs +14 -0
  59. package/dist/index.d.ts +12 -0
  60. package/dist/index.js +10 -0
  61. package/dist/input/Joystick.d.ts +18 -0
  62. package/dist/input/VirtualButton.d.ts +17 -0
  63. package/dist/input/stores/useButtonStore.d.ts +21 -0
  64. package/dist/input/stores/useJoystickStore.d.ts +26 -0
  65. package/dist/input-CrNBMRxm.js +315 -0
  66. package/dist/input-CrNBMRxm.js.map +1 -0
  67. package/dist/input-DBhf3WZe.cjs +340 -0
  68. package/dist/input-DBhf3WZe.cjs.map +1 -0
  69. package/dist/input.cjs +13 -0
  70. package/dist/input.d.ts +15 -0
  71. package/dist/input.js +9 -0
  72. package/dist/leva--ZV58vPr.cjs +771 -0
  73. package/dist/leva--ZV58vPr.cjs.map +1 -0
  74. package/dist/leva-BjLuypTs.js +764 -0
  75. package/dist/leva-BjLuypTs.js.map +1 -0
  76. package/dist/leva.cjs +10 -0
  77. package/dist/leva.d.ts +9 -0
  78. package/dist/leva.js +9 -0
  79. package/dist/plugins/leva/CurveEditorPlugin.d.ts +72 -0
  80. package/dist/shared/Math.d.ts +11 -0
  81. package/dist/shared/constants/Color.d.ts +16 -0
  82. package/dist/shared/types.d.ts +16 -0
  83. package/dist/src-BTTVvwrl.cjs +1172 -0
  84. package/dist/src-BTTVvwrl.cjs.map +1 -0
  85. package/dist/src-XJOuoUi3.js +1164 -0
  86. package/dist/src-XJOuoUi3.js.map +1 -0
  87. package/dist/time/TimeControl.d.ts +16 -0
  88. package/dist/time-B4iUfe91.cjs +65 -0
  89. package/dist/time-B4iUfe91.cjs.map +1 -0
  90. package/dist/time-DTVzhzJ8.js +60 -0
  91. package/dist/time-DTVzhzJ8.js.map +1 -0
  92. package/dist/time.cjs +10 -0
  93. package/dist/time.d.ts +9 -0
  94. package/dist/time.js +9 -0
  95. package/dist/useCustomGravity-B35U0d4V.cjs +45 -0
  96. package/dist/useCustomGravity-B35U0d4V.cjs.map +1 -0
  97. package/dist/useCustomGravity-elzlTR6Y.js +38 -0
  98. package/dist/useCustomGravity-elzlTR6Y.js.map +1 -0
  99. package/dist/utils.cjs +23 -0
  100. package/dist/utils.cjs.map +1 -0
  101. package/dist/utils.d.ts +8 -0
  102. package/dist/utils.js +20 -0
  103. package/dist/utils.js.map +1 -0
  104. package/dist/vehicle-AEqO39Wm.js +2525 -0
  105. package/dist/vehicle-AEqO39Wm.js.map +1 -0
  106. package/dist/vehicle-DbaRBeDD.cjs +2545 -0
  107. package/dist/vehicle-DbaRBeDD.cjs.map +1 -0
  108. package/dist/vehicle.cjs +12 -0
  109. package/dist/vehicle.d.ts +14 -0
  110. package/dist/vehicle.js +9 -0
  111. package/dist/vehicles/EcctrlVehicle.d.ts +111 -0
  112. package/dist/vehicles/components/ShapeCastWheel.d.ts +114 -0
  113. package/dist/vehicles/components/ThrustPropeller.d.ts +51 -0
  114. package/dist/vehicles/types.d.ts +39 -0
  115. package/package.json +149 -4
  116. package/readme.md +739 -0
  117. package/README.md +0 -3
@@ -0,0 +1,35 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ //#region \0rolldown/runtime.js
9
+ var __create = Object.create;
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
+ key = keys[i];
18
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: ((k) => from[k]).bind(null, key),
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ //#endregion
30
+ Object.defineProperty(exports, "__toESM", {
31
+ enumerable: true,
32
+ get: function() {
33
+ return __toESM;
34
+ }
35
+ });
@@ -0,0 +1,27 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export type CurvePoint = {
9
+ x: number;
10
+ y: number;
11
+ r_in?: number;
12
+ r_out?: number;
13
+ w_in?: number;
14
+ w_out?: number;
15
+ };
16
+ export type CurveLUT = {
17
+ lut: Float32Array;
18
+ xMin: number;
19
+ xMax: number;
20
+ samples: number;
21
+ };
22
+ export type CurveData = {
23
+ points: CurvePoint[];
24
+ samples?: number;
25
+ };
26
+ export declare function bakeCurveLUT(points: CurvePoint[], samples?: number): CurveLUT;
27
+ export declare function evaluateCurveLUT(x: number, curve: CurveLUT): number;
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
+ const require_CurveLUT = require("./CurveLUT-Ck18ZlkK.cjs");
10
+ //#region src/curves.ts
11
+ /*!
12
+ * Ecctrl
13
+ * https://github.com/pmndrs/ecctrl
14
+ *
15
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
16
+ * SPDX-License-Identifier: MIT
17
+ */
18
+ //#endregion
19
+ exports.bakeCurveLUT = require_CurveLUT.bakeCurveLUT;
20
+ exports.evaluateCurveLUT = require_CurveLUT.evaluateCurveLUT;
21
+
22
+ //# sourceMappingURL=curves.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curves.cjs","names":[],"sources":["../src/curves.ts"],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export { bakeCurveLUT, evaluateCurveLUT } from "./curves/CurveLUT";
9
+ export type { CurveData, CurveLUT, CurvePoint } from "./curves/CurveLUT";
package/dist/curves.js ADDED
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import { n as evaluateCurveLUT, t as bakeCurveLUT } from "./CurveLUT-BfMhx3LX.js";
9
+ //#region src/curves.ts
10
+ /*!
11
+ * Ecctrl
12
+ * https://github.com/pmndrs/ecctrl
13
+ *
14
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+ //#endregion
18
+ export { bakeCurveLUT, evaluateCurveLUT };
19
+
20
+ //# sourceMappingURL=curves.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curves.js","names":[],"sources":["../src/curves.ts"],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import * as THREE from "three";
9
+ import { CameraControlsImpl } from "@react-three/drei";
10
+ /**
11
+ * Custom CameraControls class to allow dynamic up axis change
12
+ */
13
+ declare class EcctrlCameraControlsImpl extends CameraControlsImpl {
14
+ private _oldUp;
15
+ private _newUp;
16
+ private _pivotXAxis;
17
+ private _pivotYAxis;
18
+ private _pivotZAxis;
19
+ private _rotZ;
20
+ private _rotX;
21
+ constructor(camera: THREE.PerspectiveCamera | THREE.OrthographicCamera, domElement?: HTMLElement);
22
+ setUp(newUp: THREE.Vector3): void;
23
+ }
24
+ import { type CameraControlsProps } from "@react-three/drei";
25
+ import type { ForwardRefComponent } from "../shared/types";
26
+ export declare const EcctrlCameraControls: ForwardRefComponent<CameraControlsProps, EcctrlCameraControlsImpl>;
27
+ export type EcctrlCameraControls = EcctrlCameraControlsImpl;
28
+ export {};
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import * as THREE from "three";
9
+ import type { RapierRigidBody } from "@react-three/rapier";
10
+ export interface CustomGravityState {
11
+ gravityField: (pos: THREE.Vector3) => THREE.Vector3;
12
+ setGravityField: (fn: (pos: THREE.Vector3) => THREE.Vector3) => void;
13
+ applyGravityField: (body: RapierRigidBody, timeStep: number) => void;
14
+ }
15
+ export declare const useCustomGravity: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<CustomGravityState>, "subscribe"> & {
16
+ subscribe: {
17
+ (listener: (selectedState: CustomGravityState, previousSelectedState: CustomGravityState) => void): () => void;
18
+ <U>(selector: (state: CustomGravityState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
19
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
20
+ fireImmediately?: boolean;
21
+ } | undefined): () => void;
22
+ };
23
+ }>;
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
+ const require_useCustomGravity = require("./useCustomGravity-B35U0d4V.cjs");
10
+ //#region src/gravity.ts
11
+ /*!
12
+ * Ecctrl
13
+ * https://github.com/pmndrs/ecctrl
14
+ *
15
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
16
+ * SPDX-License-Identifier: MIT
17
+ */
18
+ //#endregion
19
+ exports.useCustomGravity = require_useCustomGravity.useCustomGravity;
20
+
21
+ //# sourceMappingURL=gravity.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gravity.cjs","names":[],"sources":["../src/gravity.ts"],"mappings":""}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export { useCustomGravity } from "./gravity/useCustomGravity";
9
+ export type { CustomGravityState } from "./gravity/useCustomGravity";
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import { t as useCustomGravity } from "./useCustomGravity-elzlTR6Y.js";
9
+ //#region src/gravity.ts
10
+ /*!
11
+ * Ecctrl
12
+ * https://github.com/pmndrs/ecctrl
13
+ *
14
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+ //#endregion
18
+ export { useCustomGravity };
19
+
20
+ //# sourceMappingURL=gravity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gravity.js","names":[],"sources":["../src/gravity.ts"],"mappings":""}
package/dist/index.cjs ADDED
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
+ const require_src = require("./src-BTTVvwrl.cjs");
10
+ const require_EcctrlAnimationStateController = require("./EcctrlAnimationStateController-41Cm1Tt1.cjs");
11
+ exports.Ecctrl = require_src.Ecctrl_default;
12
+ exports.EcctrlAnimationStateController = require_EcctrlAnimationStateController.EcctrlAnimationStateController;
13
+ exports.resolveEcctrlAnimationState = require_EcctrlAnimationStateController.resolveEcctrlAnimationState;
14
+ exports.useEcctrlAnimationStore = require_EcctrlAnimationStateController.useEcctrlAnimationStore;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export { default as Ecctrl } from "./character/Ecctrl";
9
+ export type { EcctrlProps, EcctrlHandle } from "./character/Ecctrl";
10
+ export * from "./character/animation";
11
+ export type { MovementInput, ReadonlyMovementInput } from "./character/types";
12
+ export type { EcctrlUserDataType } from "./shared/types";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import { t as Ecctrl_default } from "./src-XJOuoUi3.js";
9
+ import { n as useEcctrlAnimationStore, r as resolveEcctrlAnimationState, t as EcctrlAnimationStateController } from "./EcctrlAnimationStateController-Bb2fARWF.js";
10
+ export { Ecctrl_default as Ecctrl, EcctrlAnimationStateController, resolveEcctrlAnimationState, useEcctrlAnimationStore };
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import React from "react";
9
+ declare const _default: React.MemoExoticComponent<(props: JoystickProps) => React.JSX.Element>;
10
+ export default _default;
11
+ export interface JoystickProps extends React.HTMLAttributes<HTMLDivElement> {
12
+ id?: string;
13
+ joystickMaxRadius?: number;
14
+ joystickWrapperStyle?: React.CSSProperties;
15
+ joystickBaseStyle?: React.CSSProperties;
16
+ joystickKnobStyle?: React.CSSProperties;
17
+ props?: React.HTMLAttributes<HTMLDivElement>;
18
+ }
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import React from "react";
9
+ declare const _default: React.MemoExoticComponent<(props: VirtualButtonProps) => React.JSX.Element>;
10
+ export default _default;
11
+ export interface VirtualButtonProps extends React.HTMLAttributes<HTMLDivElement> {
12
+ id: string;
13
+ label?: string;
14
+ buttonWrapperStyle?: React.CSSProperties;
15
+ buttonCapStyle?: React.CSSProperties;
16
+ props?: React.HTMLAttributes<HTMLDivElement>;
17
+ }
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export interface ButtonStoreState {
9
+ buttons: Record<string, boolean>;
10
+ setButtonActive: (id: string, active: boolean) => void;
11
+ resetAllButtons: () => void;
12
+ }
13
+ export declare const useButtonStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ButtonStoreState>, "subscribe"> & {
14
+ subscribe: {
15
+ (listener: (selectedState: ButtonStoreState, previousSelectedState: ButtonStoreState) => void): () => void;
16
+ <U>(selector: (state: ButtonStoreState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
17
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
18
+ fireImmediately?: boolean;
19
+ } | undefined): () => void;
20
+ };
21
+ }>;
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ export interface JoystickState {
9
+ active: boolean;
10
+ x: number;
11
+ y: number;
12
+ }
13
+ export interface JoystickStoreState {
14
+ joysticks: Record<string, JoystickState>;
15
+ setJoystick: (x: number, y: number, id?: string) => void;
16
+ resetJoystick: (id?: string) => void;
17
+ }
18
+ export declare const useJoystickStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<JoystickStoreState>, "subscribe"> & {
19
+ subscribe: {
20
+ (listener: (selectedState: JoystickStoreState, previousSelectedState: JoystickStoreState) => void): () => void;
21
+ <U>(selector: (state: JoystickStoreState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
22
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
23
+ fireImmediately?: boolean;
24
+ } | undefined): () => void;
25
+ };
26
+ }>;
@@ -0,0 +1,315 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ import React, { useCallback, useEffect, useRef } from "react";
9
+ import { create } from "zustand";
10
+ import { subscribeWithSelector } from "zustand/middleware";
11
+ //#region src/input/stores/useJoystickStore.ts
12
+ /*!
13
+ * Ecctrl
14
+ * https://github.com/pmndrs/ecctrl
15
+ *
16
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
17
+ * SPDX-License-Identifier: MIT
18
+ */
19
+ var DEFAULT_ID = "default";
20
+ var EMPTY = {
21
+ active: false,
22
+ x: 0,
23
+ y: 0
24
+ };
25
+ var useJoystickStore = /* @__PURE__ */ create(/* @__PURE__ */ subscribeWithSelector((set) => ({
26
+ joysticks: { [DEFAULT_ID]: { ...EMPTY } },
27
+ setJoystick: (x, y, id) => set((state) => ({ joysticks: {
28
+ ...state.joysticks,
29
+ [id !== null && id !== void 0 ? id : DEFAULT_ID]: {
30
+ active: !(x === 0 && y === 0),
31
+ x,
32
+ y
33
+ }
34
+ } })),
35
+ resetJoystick: (id) => set((state) => ({ joysticks: {
36
+ ...state.joysticks,
37
+ [id !== null && id !== void 0 ? id : DEFAULT_ID]: { ...EMPTY }
38
+ } }))
39
+ })));
40
+ //#endregion
41
+ //#region src/input/Joystick.tsx
42
+ /*!
43
+ * Ecctrl
44
+ * https://github.com/pmndrs/ecctrl
45
+ *
46
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
47
+ * SPDX-License-Identifier: MIT
48
+ */
49
+ var defaultJoystickWrapperStyle = {
50
+ userSelect: "none",
51
+ MozUserSelect: "none",
52
+ WebkitUserSelect: "none",
53
+ msUserSelect: "none",
54
+ touchAction: "none",
55
+ overscrollBehavior: "none",
56
+ position: "fixed",
57
+ zIndex: "10",
58
+ height: "200px",
59
+ width: "200px",
60
+ borderRadius: "50%"
61
+ };
62
+ var defaultJoystickBaseStyle = {
63
+ width: "100px",
64
+ height: "100px",
65
+ background: "rgba(0, 0, 0, 0.1)",
66
+ border: "2px solid white",
67
+ borderRadius: "50%",
68
+ position: "absolute",
69
+ top: "50%",
70
+ left: "50%",
71
+ transform: "translate(-50%, -50%)",
72
+ touchAction: "none"
73
+ };
74
+ var defaultJoystickKnobStyle = {
75
+ width: "70px",
76
+ height: "70px",
77
+ background: "rgba(255, 255, 255, 0.8)",
78
+ borderRadius: "50%",
79
+ position: "absolute",
80
+ top: "50%",
81
+ left: "50%",
82
+ transform: "translate(-50%, -50%)",
83
+ transition: "transform 0.2s cubic-bezier(0.25, 1.5, 0.5, 1)",
84
+ willChange: "transform",
85
+ pointerEvents: "none"
86
+ };
87
+ var Joystick = (props) => {
88
+ var _props$joystickMaxRad;
89
+ const joystickMaxRadius = (_props$joystickMaxRad = props.joystickMaxRadius) !== null && _props$joystickMaxRad !== void 0 ? _props$joystickMaxRad : 50;
90
+ const baseRef = useRef(null);
91
+ const knobRef = useRef(null);
92
+ const activePointerIdRef = useRef(null);
93
+ const centerRef = useRef(null);
94
+ const releaseTransitionRef = useRef("");
95
+ const setJoystick = useJoystickStore((state) => state.setJoystick);
96
+ const resetJoystick = useJoystickStore((state) => state.resetJoystick);
97
+ const joystickWrapperStyle = {
98
+ ...defaultJoystickWrapperStyle,
99
+ ...props.joystickWrapperStyle
100
+ };
101
+ const joystickBaseStyle = {
102
+ ...defaultJoystickBaseStyle,
103
+ ...props.joystickBaseStyle
104
+ };
105
+ const joystickKnobStyle = {
106
+ ...defaultJoystickKnobStyle,
107
+ ...props.joystickKnobStyle
108
+ };
109
+ /**
110
+ * Function to handle joystick movement
111
+ */
112
+ const moveFunction = useCallback((x, y) => {
113
+ if (!knobRef.current || !centerRef.current) return;
114
+ let dx = x - centerRef.current.x;
115
+ let dy = y - centerRef.current.y;
116
+ const distance = Math.hypot(dx, dy);
117
+ if (distance > joystickMaxRadius) {
118
+ dx *= joystickMaxRadius / distance;
119
+ dy *= joystickMaxRadius / distance;
120
+ }
121
+ knobRef.current.style.transform = `translate(calc(-50% + ${dx}px), calc(-50% + ${dy}px))`;
122
+ setJoystick(dx / joystickMaxRadius, -dy / joystickMaxRadius, props.id);
123
+ }, [
124
+ setJoystick,
125
+ props.id,
126
+ joystickMaxRadius
127
+ ]);
128
+ /**
129
+ * Function to reset the joystick state
130
+ */
131
+ const resetFunction = useCallback((pointerId) => {
132
+ if (activePointerIdRef.current !== pointerId) return;
133
+ activePointerIdRef.current = null;
134
+ centerRef.current = null;
135
+ if (knobRef.current) {
136
+ knobRef.current.style.transition = releaseTransitionRef.current;
137
+ knobRef.current.style.transform = "translate(-50%, -50%)";
138
+ }
139
+ resetJoystick(props.id);
140
+ }, [resetJoystick, props.id]);
141
+ useEffect(() => () => resetJoystick(props.id), [resetJoystick, props.id]);
142
+ return /* @__PURE__ */ React.createElement("div", {
143
+ id: "ecctrl-joystick",
144
+ style: joystickWrapperStyle,
145
+ onContextMenu: (e) => e.preventDefault(),
146
+ onPointerDown: (e) => {
147
+ var _baseRef$current;
148
+ e.preventDefault();
149
+ e.stopPropagation();
150
+ if (activePointerIdRef.current !== null) return;
151
+ const rect = (_baseRef$current = baseRef.current) === null || _baseRef$current === void 0 ? void 0 : _baseRef$current.getBoundingClientRect();
152
+ if (!rect || !knobRef.current) return;
153
+ activePointerIdRef.current = e.pointerId;
154
+ centerRef.current = {
155
+ x: rect.left + rect.width / 2,
156
+ y: rect.top + rect.height / 2
157
+ };
158
+ releaseTransitionRef.current = knobRef.current.style.transition;
159
+ knobRef.current.style.transition = "none";
160
+ e.currentTarget.setPointerCapture(e.pointerId);
161
+ moveFunction(e.clientX, e.clientY);
162
+ },
163
+ onPointerMove: (e) => {
164
+ if (activePointerIdRef.current === e.pointerId) moveFunction(e.clientX, e.clientY);
165
+ },
166
+ onPointerUp: (e) => resetFunction(e.pointerId),
167
+ onPointerCancel: (e) => resetFunction(e.pointerId),
168
+ onLostPointerCapture: (e) => resetFunction(e.pointerId)
169
+ }, /* @__PURE__ */ React.createElement("div", {
170
+ id: "joystick-base",
171
+ style: joystickBaseStyle,
172
+ ref: baseRef
173
+ }, /* @__PURE__ */ React.createElement("div", {
174
+ id: "joystick-knob",
175
+ style: joystickKnobStyle,
176
+ ref: knobRef
177
+ })));
178
+ };
179
+ var Joystick_default = React.memo(Joystick);
180
+ //#endregion
181
+ //#region src/input/stores/useButtonStore.ts
182
+ /*!
183
+ * Ecctrl
184
+ * https://github.com/pmndrs/ecctrl
185
+ *
186
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
187
+ * SPDX-License-Identifier: MIT
188
+ */
189
+ var useButtonStore = /* @__PURE__ */ create(/* @__PURE__ */ subscribeWithSelector((set) => ({
190
+ buttons: {},
191
+ setButtonActive: (id, active) => set((state) => Boolean(state.buttons[id]) === active ? state : { buttons: {
192
+ ...state.buttons,
193
+ [id]: active
194
+ } }),
195
+ resetAllButtons: () => set((state) => Object.keys(state.buttons).length === 0 ? state : { buttons: {} })
196
+ })));
197
+ //#endregion
198
+ //#region src/input/VirtualButton.tsx
199
+ /*!
200
+ * Ecctrl
201
+ * https://github.com/pmndrs/ecctrl
202
+ *
203
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
204
+ * SPDX-License-Identifier: MIT
205
+ */
206
+ var defaultButtonWrapperStyle = {
207
+ userSelect: "none",
208
+ MozUserSelect: "none",
209
+ WebkitUserSelect: "none",
210
+ msUserSelect: "none",
211
+ touchAction: "none",
212
+ overscrollBehavior: "none",
213
+ position: "fixed",
214
+ zIndex: "10",
215
+ height: "60px",
216
+ width: "60px",
217
+ background: "rgba(0, 0, 0, 0.1)",
218
+ borderRadius: "50%"
219
+ };
220
+ var defaultButtonCapStyle = {
221
+ width: "45px",
222
+ height: "45px",
223
+ background: "rgba(255, 255, 255, 0.8)",
224
+ borderRadius: "50%",
225
+ position: "absolute",
226
+ top: "50%",
227
+ left: "50%",
228
+ transform: "translate(-50%, -50%)",
229
+ transition: "transform 0.2s cubic-bezier(0.25, 1.5, 0.5, 1)",
230
+ willChange: "transform",
231
+ display: "flex",
232
+ justifyContent: "center",
233
+ alignItems: "center",
234
+ fontSize: "12px",
235
+ fontWeight: "bold",
236
+ fontFamily: "Arial, sans-serif",
237
+ color: "LightGray",
238
+ userSelect: "none",
239
+ pointerEvents: "none"
240
+ };
241
+ var VirtualButton = (props) => {
242
+ const capRef = useRef(null);
243
+ const activePointerIdRef = useRef(null);
244
+ const setButtonActive = useButtonStore((state) => state.setButtonActive);
245
+ const buttonWrapperStyle = {
246
+ ...defaultButtonWrapperStyle,
247
+ ...props.buttonWrapperStyle
248
+ };
249
+ const buttonCapStyle = {
250
+ ...defaultButtonCapStyle,
251
+ ...props.buttonCapStyle
252
+ };
253
+ /**
254
+ * Function to handle button press, setting the button active state
255
+ */
256
+ const pressFunction = useCallback((e) => {
257
+ e.preventDefault();
258
+ e.stopPropagation();
259
+ if (activePointerIdRef.current !== null) return;
260
+ activePointerIdRef.current = e.pointerId;
261
+ e.currentTarget.setPointerCapture(e.pointerId);
262
+ setButtonActive(props.id, true);
263
+ if (capRef.current) {
264
+ capRef.current.style.transform = "translate(-50%, -50%) scale(1.3)";
265
+ capRef.current.style.opacity = "0.5";
266
+ }
267
+ }, [setButtonActive, props.id]);
268
+ /**
269
+ * Function to reset the button state for the active pointer
270
+ */
271
+ const resetFunction = useCallback((pointerId) => {
272
+ if (activePointerIdRef.current !== pointerId) return;
273
+ activePointerIdRef.current = null;
274
+ setButtonActive(props.id, false);
275
+ if (capRef.current) {
276
+ capRef.current.style.transform = "translate(-50%, -50%) scale(1)";
277
+ capRef.current.style.opacity = "1";
278
+ }
279
+ }, [setButtonActive, props.id]);
280
+ useEffect(() => () => {
281
+ activePointerIdRef.current = null;
282
+ setButtonActive(props.id, false);
283
+ if (capRef.current) {
284
+ capRef.current.style.transform = "translate(-50%, -50%) scale(1)";
285
+ capRef.current.style.opacity = "1";
286
+ }
287
+ }, [setButtonActive, props.id]);
288
+ return /* @__PURE__ */ React.createElement("div", {
289
+ id: "ecctrl-virtual-button",
290
+ style: buttonWrapperStyle,
291
+ onContextMenu: (e) => e.preventDefault(),
292
+ onPointerDown: pressFunction,
293
+ onPointerUp: (e) => resetFunction(e.pointerId),
294
+ onPointerCancel: (e) => resetFunction(e.pointerId),
295
+ onLostPointerCapture: (e) => resetFunction(e.pointerId)
296
+ }, /* @__PURE__ */ React.createElement("div", {
297
+ id: "virtual-button-cap",
298
+ style: buttonCapStyle,
299
+ ref: capRef
300
+ }, props.label));
301
+ };
302
+ var VirtualButton_default = React.memo(VirtualButton);
303
+ //#endregion
304
+ //#region src/input.ts
305
+ /*!
306
+ * Ecctrl
307
+ * https://github.com/pmndrs/ecctrl
308
+ *
309
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
310
+ * SPDX-License-Identifier: MIT
311
+ */
312
+ //#endregion
313
+ export { useJoystickStore as i, useButtonStore as n, Joystick_default as r, VirtualButton_default as t };
314
+
315
+ //# sourceMappingURL=input-CrNBMRxm.js.map