@n3rdw1z4rd/core 0.18.5 → 0.19.1

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 (109) hide show
  1. package/README.md +72 -10
  2. package/dist/astar.d.ts +44 -0
  3. package/dist/astar.js +118 -0
  4. package/dist/canvas-renderer.d.ts +157 -0
  5. package/dist/canvas-renderer.js +207 -0
  6. package/dist/clock.d.ts +69 -0
  7. package/dist/clock.js +108 -0
  8. package/dist/color-palette.d.ts +25 -0
  9. package/dist/color-palette.js +112 -0
  10. package/dist/color.d.ts +90 -0
  11. package/dist/color.js +224 -0
  12. package/dist/css/main.css +1 -3
  13. package/dist/disposable.d.ts +27 -0
  14. package/dist/disposable.js +32 -0
  15. package/dist/dungeon-generator.d.ts +142 -0
  16. package/dist/dungeon-generator.js +288 -0
  17. package/dist/ecs.d.ts +87 -0
  18. package/dist/ecs.js +101 -0
  19. package/dist/emitter.d.ts +40 -0
  20. package/dist/emitter.js +54 -0
  21. package/dist/event-queue.d.ts +29 -0
  22. package/dist/event-queue.js +40 -0
  23. package/dist/index.cjs +3820 -0
  24. package/dist/index.d.cts +2657 -0
  25. package/dist/index.d.ts +35 -873
  26. package/dist/index.js +34 -3981
  27. package/dist/input/action-map.d.ts +79 -0
  28. package/dist/input/action-map.js +131 -0
  29. package/dist/input/bindings.d.ts +273 -0
  30. package/dist/input/bindings.js +250 -0
  31. package/dist/input/gestures.d.ts +108 -0
  32. package/dist/input/gestures.js +159 -0
  33. package/dist/input/index.d.ts +5 -0
  34. package/dist/input/index.js +5 -0
  35. package/dist/input/input.d.ts +297 -0
  36. package/dist/input/input.js +695 -0
  37. package/dist/log.d.ts +8 -0
  38. package/dist/log.js +9 -0
  39. package/dist/map2d.d.ts +83 -0
  40. package/dist/map2d.js +120 -0
  41. package/dist/map3d-CHDJiq5T.d.cts +236 -0
  42. package/dist/map3d.d.ts +94 -0
  43. package/dist/map3d.js +148 -0
  44. package/dist/math.d.ts +176 -0
  45. package/dist/math.js +206 -0
  46. package/dist/misc.d.ts +46 -0
  47. package/dist/misc.js +71 -0
  48. package/dist/observable.d.ts +43 -0
  49. package/dist/observable.js +53 -0
  50. package/dist/particle-renderer.d.ts +47 -0
  51. package/dist/particle-renderer.js +82 -0
  52. package/dist/particle-system-2d.d.ts +60 -0
  53. package/dist/particle-system-2d.js +147 -0
  54. package/dist/random.d.ts +46 -0
  55. package/dist/random.js +74 -0
  56. package/dist/rectangle.d.ts +44 -0
  57. package/dist/rectangle.js +69 -0
  58. package/dist/rng.d.ts +72 -0
  59. package/dist/rng.js +152 -0
  60. package/dist/signal.d.ts +34 -0
  61. package/dist/signal.js +41 -0
  62. package/dist/spatial-partition-2d.d.ts +42 -0
  63. package/dist/spatial-partition-2d.js +52 -0
  64. package/dist/spatial-partition-3d-Ba-VBveM.cjs +1324 -0
  65. package/dist/spatial-partition-3d.d.ts +44 -0
  66. package/dist/spatial-partition-3d.js +57 -0
  67. package/dist/three/asteroid-mesh.d.ts +41 -0
  68. package/dist/three/asteroid-mesh.js +44 -0
  69. package/dist/three/camera-rig.d.ts +140 -0
  70. package/dist/three/camera-rig.js +197 -0
  71. package/dist/three/cube-sphere-geometry.d.ts +55 -0
  72. package/dist/three/cube-sphere-geometry.js +239 -0
  73. package/dist/three/ecs.d.ts +75 -0
  74. package/dist/three/ecs.js +64 -0
  75. package/dist/three/index.d.ts +12 -0
  76. package/dist/three/index.js +12 -0
  77. package/dist/three/particle-system-3d.d.ts +53 -0
  78. package/dist/three/particle-system-3d.js +224 -0
  79. package/dist/three/renderer.d.ts +38 -0
  80. package/dist/three/renderer.js +57 -0
  81. package/dist/three/starfield.d.ts +23 -0
  82. package/dist/three/starfield.js +64 -0
  83. package/dist/three/texture-atlas.d.ts +76 -0
  84. package/dist/three/texture-atlas.js +84 -0
  85. package/dist/three/texture-utils.d.ts +31 -0
  86. package/dist/three/texture-utils.js +44 -0
  87. package/dist/three/voxel-geometry.d.ts +72 -0
  88. package/dist/three/voxel-geometry.js +231 -0
  89. package/dist/three/voxel-mesh.d.ts +67 -0
  90. package/dist/three/voxel-mesh.js +71 -0
  91. package/dist/three.cjs +1307 -0
  92. package/dist/three.d.cts +655 -0
  93. package/dist/tilemap.d.ts +17 -0
  94. package/dist/tilemap.js +26 -0
  95. package/dist/types.d.ts +34 -0
  96. package/dist/types.js +0 -0
  97. package/dist/vector.d.ts +78 -0
  98. package/dist/vector.js +169 -0
  99. package/dist/webgl-renderer.d.ts +89 -0
  100. package/dist/webgl-renderer.js +140 -0
  101. package/dist/webgl.d.ts +357 -0
  102. package/dist/webgl.js +628 -0
  103. package/dist/worker-interface.d.ts +30 -0
  104. package/dist/worker-interface.js +39 -0
  105. package/package.json +55 -13
  106. package/dist/css/index.ts +0 -1
  107. package/dist/index.css +0 -104
  108. package/dist/index.d.mts +0 -873
  109. package/dist/index.mjs +0 -3977
@@ -0,0 +1,297 @@
1
+ import { Binding, MouseButton } from "./bindings.js";
2
+ import { ActionMap } from "./action-map.js";
3
+ import { GestureFrame, GestureRecognizer, TouchPoint } from "./gestures.js";
4
+ import { Observable } from "../observable.js";
5
+ //#region src/input/input.d.ts
6
+ /**
7
+ * 0 = keyboard, mouse, pen, touch and VR; 1, 2, ... = gamepads.
8
+ *
9
+ * @category Input
10
+ */
11
+ export type InputDevice = number;
12
+ /**
13
+ * The kind of device the player last used, see {@link Input.lastDevice}.
14
+ *
15
+ * @category Input
16
+ */
17
+ export type InputDeviceType = 'keyboard' | 'mouse' | 'pen' | 'touch' | 'gamepad' | 'xr';
18
+ /**
19
+ * When an {@link Input.onAction} callback fires: as the action becomes pressed, or released.
20
+ *
21
+ * @category Input
22
+ */
23
+ export type ActionPhase = 'pressed' | 'released';
24
+ /**
25
+ * Options for the {@link Input} constructor.
26
+ *
27
+ * @category Input
28
+ */
29
+ export interface InputOptions {
30
+ /** where key events are read; default: window */
31
+ keyboardTarget?: EventTarget;
32
+ /** add the ui_* actions. Default true. */
33
+ defaults?: boolean;
34
+ /** stop bound keys / the wheel from scrolling the page. Default true. */
35
+ preventDefault?: boolean;
36
+ /** no right-click menu on the target. Default true. */
37
+ preventContextMenu?: boolean;
38
+ }
39
+ /**
40
+ * Restricts an action query to one {@link InputDevice}; without it, any device counts.
41
+ *
42
+ * @category Input
43
+ */
44
+ export interface DeviceQuery {
45
+ /** only this device; default: any */
46
+ device?: InputDevice;
47
+ }
48
+ /**
49
+ * A connected gamepad, see {@link Input.gamepads}.
50
+ *
51
+ * @category Input
52
+ */
53
+ export interface GamepadInfo {
54
+ /** gamepad.index + 1 */
55
+ device: InputDevice;
56
+ /** the browser's description of the controller */
57
+ id: string;
58
+ /** uses the standard mapping (button names are reliable); others map by index */
59
+ standard: boolean;
60
+ }
61
+ /**
62
+ * The parts of a WebXR XRSession that Input reads (structural, so no WebXR typings are required).
63
+ *
64
+ * @category Input
65
+ */
66
+ export interface XRSessionLike extends EventTarget {
67
+ /** the session's controllers */
68
+ readonly inputSources: Iterable<{
69
+ /** `'left'` or `'right'`; other values are ignored */
70
+ readonly handedness: string;
71
+ /** buttons in {@link XR_BUTTONS} order (value 0..1) and axes in {@link XR_AXES} order (-1..1) */
72
+ readonly gamepad?: {
73
+ /** in {@link XR_BUTTONS} order */
74
+ readonly buttons: readonly {
75
+ /** held down */
76
+ pressed: boolean;
77
+ /** 0..1 (analog for triggers and squeeze) */
78
+ value: number;
79
+ }[];
80
+ /** in {@link XR_AXES} order, -1..1 */
81
+ readonly axes: readonly number[];
82
+ } | null;
83
+ }>;
84
+ }
85
+ /**
86
+ * Mouse or pen state, see {@link Input.pointer}. Positions update on pointer events; deltas and
87
+ * wheel totals on each {@link Input.update}.
88
+ *
89
+ * @property y pixels, relative to the target's top-left, y down
90
+ * @property ndcY -1..1, y up
91
+ * @property deltaY movement during the last frame, pixels
92
+ * @property wheelY wheel movement during the last frame, in pixels (positive = down)
93
+ * @property tiltY pen: degrees
94
+ *
95
+ * @category Input
96
+ */
97
+ export interface PointerState {
98
+ /** the kind of pointer that last moved or pressed */
99
+ type: 'mouse' | 'pen';
100
+ /** pixels, relative to the target's top-left */
101
+ x: number;
102
+ y: number;
103
+ /** -1..1, y up (for raycasting) */
104
+ ndcX: number;
105
+ ndcY: number;
106
+ /** movement during the last frame, pixels (works under pointer lock) */
107
+ deltaX: number;
108
+ deltaY: number;
109
+ /** wheel movement during the last frame, in pixels */
110
+ wheelX: number;
111
+ wheelY: number;
112
+ /** pen: 0..1 */
113
+ pressure: number;
114
+ /** pen: degrees */
115
+ tiltX: number;
116
+ tiltY: number;
117
+ }
118
+ /**
119
+ * Options for {@link Input.captureBinding}.
120
+ *
121
+ * @category Input
122
+ */
123
+ export interface CaptureOptions {
124
+ /** KeyboardEvent.code that cancels (resolves null); `null` for none. Default 'Escape'. */
125
+ cancelKey?: string | null;
126
+ /** only accept these kinds of input; others are ignored and still reach actions */
127
+ types?: Binding['type'][];
128
+ }
129
+ /**
130
+ * Game input with a Godot-style action map: bind keys, buttons, sticks, gestures and VR controls
131
+ * to named actions, then query actions instead of devices.
132
+ *
133
+ * const input = new Input(canvas);
134
+ * input.actions.add('jump', [key('Space'), pad('A')]);
135
+ *
136
+ * // every frame, before game logic:
137
+ * input.update();
138
+ * if (input.isActionJustPressed('jump')) player.jump();
139
+ *
140
+ * Call `dispose()` to remove all listeners.
141
+ *
142
+ * @category Input
143
+ */
144
+ export declare class Input {
145
+ /** the actions to query; holds the `ui_*` defaults unless {@link InputOptions.defaults} is false */
146
+ readonly actions: ActionMap;
147
+ /** Thresholds for taps, swipes etc. can be tuned via `gestureRecognizer.thresholds`. */
148
+ readonly gestureRecognizer: GestureRecognizer;
149
+ /** Two-finger gesture values for the last frame (pinch 1 / pan 0 / rotate 0 when not gesturing). */
150
+ readonly gestures: Omit<GestureFrame, 'gestures'>;
151
+ /** Fingers currently on the target. */
152
+ get touches(): TouchPoint[];
153
+ /** the mouse or pen; not updated by touch */
154
+ readonly pointer: PointerState;
155
+ /** notified when {@link Input.lastDevice} changes, e.g. to switch on-screen button prompts */
156
+ readonly onDeviceChange: Observable<InputDeviceType>;
157
+ /** notified from update() when a gamepad is first seen */
158
+ readonly onGamepadConnected: Observable<GamepadInfo>;
159
+ /** notified from update() when a gamepad goes away; its held controls are released */
160
+ readonly onGamepadDisconnected: Observable<GamepadInfo>;
161
+ private readonly _gamepads;
162
+ /** Connected gamepads, as found by the last update(). */
163
+ get gamepads(): GamepadInfo[];
164
+ private _lastDevice;
165
+ private _keyLabels?;
166
+ private readonly _target?;
167
+ private readonly _options;
168
+ private readonly _listeners;
169
+ private readonly _controls;
170
+ private readonly _actionStates;
171
+ private readonly _actionListeners;
172
+ private readonly _warned;
173
+ private readonly _pending;
174
+ private _capture?;
175
+ /** The kind of device that produced the most recent input (initially `'keyboard'`). */
176
+ get lastDevice(): InputDeviceType;
177
+ /** Whether the pointer is locked to the target, see {@link Input.lockPointer}. */
178
+ get isPointerLocked(): boolean;
179
+ /**
180
+ * @param target element that receives pointer, wheel and touch input (usually the canvas)
181
+ */
182
+ constructor(target?: EventTarget, options?: InputOptions);
183
+ /**
184
+ * Call once per frame, before reading input: polls devices and advances "just pressed" /
185
+ * "just released" by one frame. Action callbacks fire from here.
186
+ */
187
+ update(): void;
188
+ /** Whether the action is held past its deadzone. Unknown actions return false (and warn once). */
189
+ isActionPressed(action: string, query?: DeviceQuery): boolean;
190
+ /** Whether the action became pressed in the last update(). */
191
+ isActionJustPressed(action: string, query?: DeviceQuery): boolean;
192
+ /** Whether the action was released in the last update(). */
193
+ isActionJustReleased(action: string, query?: DeviceQuery): boolean;
194
+ /** 0..1, rescaled past the action's deadzone (analog triggers and sticks give values in between). */
195
+ getActionStrength(action: string, query?: DeviceQuery): number;
196
+ /** 0..1 before the deadzone is applied. */
197
+ getActionRawStrength(action: string, query?: DeviceQuery): number;
198
+ /** -1..1: `positive` minus `negative`. */
199
+ getAxis(negative: string, positive: string, query?: DeviceQuery): number;
200
+ /**
201
+ * A 2D direction from four actions, with a circular deadzone and length at most 1 (diagonals
202
+ * aren't faster). Y is positive towards `positiveY`, as in Godot's get_vector("left", "right", "up", "down").
203
+ *
204
+ * @param options.deadzone default: the average of the four actions' deadzones
205
+ * @returns `x` and `y` in -1..1; `{ x: 0, y: 0 }` inside the deadzone
206
+ */
207
+ getVector(negativeX: string, positiveX: string, negativeY: string, positiveY: string, options?: DeviceQuery & {
208
+ deadzone?: number;
209
+ }): {
210
+ /** -1..1, positive towards `positiveX` */
211
+ x: number;
212
+ /** -1..1, positive towards `positiveY` */
213
+ y: number;
214
+ };
215
+ /** Calls `callback` when the action is pressed or released (during update()). Returns an unsubscribe function. */
216
+ onAction(action: string, phase: ActionPhase, callback: () => void, query?: DeviceQuery): () => void;
217
+ /** Whether a key (by `KeyboardEvent.code`) is held right now, regardless of actions. */
218
+ isKeyPressed(code: string): boolean;
219
+ /** Whether a mouse or pen button is held right now, regardless of actions. */
220
+ isMouseButtonPressed(button: MouseButton): boolean;
221
+ /**
222
+ * Releases every held key and button, on one device or all. Keyboard, mouse and touch (device 0)
223
+ * are released automatically when the window loses focus, since their release events get lost.
224
+ */
225
+ releaseAll(device?: InputDevice): void;
226
+ /** Requests pointer lock on the target (browsers only allow it from a user gesture, e.g. a click). */
227
+ lockPointer(): void;
228
+ /** Exits pointer lock if the target holds it. */
229
+ unlockPointer(): void;
230
+ /**
231
+ * Waits for the player's next input and resolves with a binding for it, for rebinding menus.
232
+ * Resolves `null` if the cancel key is pressed or another capture starts. The captured press
233
+ * doesn't trigger any actions.
234
+ */
235
+ captureBinding(options?: CaptureOptions): Promise<Binding | null>;
236
+ /** Ends a pending {@link Input.captureBinding}, resolving it with `null`. */
237
+ cancelCapture(): void;
238
+ /**
239
+ * Loads the keyboard layout (where supported, e.g. Chromium) so {@link bindingLabel} names keys
240
+ * as printed on the player's keyboard: KeyW is "Z" on AZERTY.
241
+ */
242
+ loadKeyboardLayout(): Promise<ReadonlyMap<string, string> | undefined>;
243
+ /** The layout loaded by {@link Input.loadKeyboardLayout}, if any: `KeyboardEvent.code` to printed key. */
244
+ get keyLabels(): ReadonlyMap<string, string> | undefined;
245
+ /** Removes all event listeners and action callbacks, cancels any capture and detaches XR. */
246
+ dispose(): void;
247
+ private _listen;
248
+ private _state;
249
+ private _advance;
250
+ private _controlValue;
251
+ private _bindingValue;
252
+ private _control;
253
+ /** Updates a held control (key, button, axis direction: 0..1); `binding` describes it for captureBinding(). */
254
+ protected _setControl(device: InputDevice, binding: Binding, value: number): void;
255
+ /** A one-frame press with no held state: wheel steps, gestures. */
256
+ protected _pulse(device: InputDevice, binding: Binding): void;
257
+ private _tryCapture;
258
+ private _setLastDevice;
259
+ /**
260
+ * Vibrates a gamepad (where supported). Magnitudes are 0..1; `strong` defaults to 1, `weak` to
261
+ * `strong`, `duration` to 200 ms.
262
+ */
263
+ rumble(device: InputDevice, options?: {
264
+ strong?: number;
265
+ weak?: number;
266
+ duration?: number;
267
+ }): void;
268
+ private _pollGamepads;
269
+ private _updateGestures;
270
+ private _xrSession?;
271
+ private _xrEnd?;
272
+ private readonly _xrHeld;
273
+ /** The session set by {@link Input.attachXR}, until detached or ended. */
274
+ get xrSession(): XRSessionLike | undefined;
275
+ /**
276
+ * Reads VR controller buttons and sticks from a WebXR session (e.g. `renderer.xr.getSession()`)
277
+ * into the action map. Controller poses stay with three.js (`renderer.xr.getController(i)`).
278
+ * XR controller state only updates during XR frames, so call update() from the XR animation
279
+ * loop (`renderer.setAnimationLoop`). Detaches automatically when the session ends.
280
+ */
281
+ attachXR(session: XRSessionLike): void;
282
+ /** Stops reading the XR session and releases its controls. */
283
+ detachXR(): void;
284
+ private _pollXR;
285
+ private _releaseXR;
286
+ private _isBound;
287
+ private _onKeyDown;
288
+ private _onKeyUp;
289
+ private _updatePointer;
290
+ private _local;
291
+ private _onPointerDown;
292
+ private _onPointerUp;
293
+ private _onPointerCancel;
294
+ private _onPointerMove;
295
+ private _onWheel;
296
+ }
297
+ //#endregion