@flare-engine/input 0.4.10 → 0.4.12

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.
package/dist/index.d.mts CHANGED
@@ -158,13 +158,13 @@ export declare class GestureDetector {
158
158
  private longPressMinDuration;
159
159
  private swipeMinDistance;
160
160
  private swipeMaxDuration;
161
- private _startPos;
161
+ private readonly _startPos;
162
162
  /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */
163
163
  private _elapsed;
164
164
  private _isTracking;
165
165
  private _longPressFired;
166
166
  private _pinchStartDistance;
167
- private _pinchTouches;
167
+ private _pinchActive;
168
168
  constructor(config?: GestureConfig);
169
169
  /** Feed a pointer-down event. */
170
170
  pointerDown(x: number, y: number): void;
@@ -318,6 +318,13 @@ interface RemapTable {
318
318
  export declare function createIdentityRemap(buttonCount?: number, axisCount?: number): RemapTable;
319
319
  /** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */
320
320
  export declare function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot;
321
+ /**
322
+ * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into
323
+ * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so
324
+ * a scratch already at the table's size allocates nothing; growing allocates
325
+ * the missing button records once. `out` must not be `snapshot`.
326
+ */
327
+ export declare function applyRemapInto(snapshot: GamepadSnapshot, table: RemapTable, out: GamepadSnapshot): GamepadSnapshot;
321
328
  /**
322
329
  * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,
323
330
  * but declared locally so this package does not take a hard dep on storage.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-button.ts","../src/virtual-joystick.ts"],"mappings":";;;;;;;;;;qBAsBa;;;;;;;;;;;;;;;;;;;KAmBD,0BAA0B,4BAA4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}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-button.ts","../src/virtual-joystick.ts"],"mappings":";;;;;;;;;;qBAsBa;;;;;;;;;;;;;;;;;;;KAmBD,0BAA0B,4BAA4B;;qBAGrD;;;;;;KAMD,wBAAwB,0BAA0B;UAE7C;EACf;EACA;;EAEA;;EAEA;;UAGe;EACf;EACA;EACA;EACA,SAAS;EACT;;EAEA;;;UAIe;EACf;EACA;EACA;IAAW;IAAkB;;EAC7B;EACA;;wBAGc,mBAAmB,gBAAW,sBAAkB,qBAAgB;;;;;;;;wBAwChE,0BACd,OAAO,cACP,UAAU,wBACV;;wBAyDc,kBAAkB,OAAO;wBAoBzB,aAAa,OAAO,cAAc;wBAIlC,iBAAiB,OAAO,cAAc;wBAItC,kBAAkB,OAAO,cAAc;wBAIvC,QAAQ,OAAO,cAAc;;;;;;;;;;;;;;;;UCnM5B;EACf,SAAS;;UAGM;EACf,qBAAqB;;UAGN;EACf;EACA;EACA;EACA;EACA;IAAoB;IAAkB;;EACtC;;;;;;wBAOc,uBAAuB,MAAM,gBAAgB;;KClCjD;;UAGK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,WAAW;EACX;EACA;;;UAIe;;EAEf;;EAEA,QAAQ;;;;;;qBAaG;WACF,OAAK,OAAA;WACL,aAAW,OAAA;WACX,SAAO,OAAA;WACP,SAAO,OAAA;UAER;UACA;UACA;UACA;UACA;mBAGS;;UAET;UACA;UACA;UAGA;UACA;EAEI,YAAA,SAAS;;EASrB,YAAY,WAAW;;;;;;;;;;;;EAmBvB,UAAU,WAAW,WAAW;;;;;;;EAsChC,OAAO,YAAY,kBAAkB;;;;;;EAqBrC,YAAY,IAAI,MAAM,IAAI;;EAuB1B;;;UCzKe;WACN;WACA;;EAET;;;UAIe;EACf,iBAAiB,cAAc,UAA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f;;EAEA;;EAEA;;;wBAIc,qBAAqB;;wBASrB,iBAAiB,OAAO;;wBAMxB,YAAY,OAAO;;wBAQnB,cAAc,OAAO;;UCnBpB;;EAEf;;EAEA;;;UAIe;;EAEf;;EAEA,WAAW;;EAEX;;EAEA,QAAQ;;;wBAOM,uBAAuB;;;;;;;;;;;wBAmBvB,eACd,OAAO,sBACP,iBACA,iBACA,gBACA,gBACA,SAAS;;wBA8DK,gBAAgB,OAAO"}
package/dist/index.d.ts CHANGED
@@ -158,13 +158,13 @@ export declare class GestureDetector {
158
158
  private longPressMinDuration;
159
159
  private swipeMinDistance;
160
160
  private swipeMaxDuration;
161
- private _startPos;
161
+ private readonly _startPos;
162
162
  /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */
163
163
  private _elapsed;
164
164
  private _isTracking;
165
165
  private _longPressFired;
166
166
  private _pinchStartDistance;
167
- private _pinchTouches;
167
+ private _pinchActive;
168
168
  constructor(config?: GestureConfig);
169
169
  /** Feed a pointer-down event. */
170
170
  pointerDown(x: number, y: number): void;
@@ -318,6 +318,13 @@ interface RemapTable {
318
318
  export declare function createIdentityRemap(buttonCount?: number, axisCount?: number): RemapTable;
319
319
  /** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */
320
320
  export declare function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot;
321
+ /**
322
+ * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into
323
+ * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so
324
+ * a scratch already at the table's size allocates nothing; growing allocates
325
+ * the missing button records once. `out` must not be `snapshot`.
326
+ */
327
+ export declare function applyRemapInto(snapshot: GamepadSnapshot, table: RemapTable, out: GamepadSnapshot): GamepadSnapshot;
321
328
  /**
322
329
  * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,
323
330
  * but declared locally so this package does not take a hard dep on storage.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-button.ts","../src/virtual-joystick.ts"],"mappings":";;;;;;;;;;qBAsBa;;;;;;;;;;;;;;;;;;;KAmBD,0BAA0B,4BAA4B;;qBAGrD;;;;;;KAMD,wBAAwB,0BAA0B;UAE7C;EACf;EACA;;EAEA;;EAEA;;UAGe;EACf;EACA;EACA;EACA,SAAS;EACT;;EAEA;;;UAIe;EACf;EACA;EACA;IAAW;IAAkB;;EAC7B;EACA;;wBAGc,mBAAmB,gBAAW,sBAAkB,qBAAgB;;;;;;;;wBAwChE,0BACd,OAAO,cACP,UAAU,wBACV;;wBAyDc,kBAAkB,OAAO;wBAoBzB,aAAa,OAAO,cAAc;wBAIlC,iBAAiB,OAAO,cAAc;wBAItC,kBAAkB,OAAO,cAAc;wBAIvC,QAAQ,OAAO,cAAc;;;;;;;;;;;;;;;;UCnM5B;EACf,SAAS;;UAGM;EACf,qBAAqB;;UAGN;EACf;EACA;EACA;EACA;EACA;IAAoB;IAAkB;;EACtC;;;;;;wBAOc,uBAAuB,MAAM,gBAAgB;;KClCjD;;UAGK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,WAAW;EACX;EACA;;;UAIe;;EAEf;;EAEA,QAAQ;;;;;;qBAaG;WACF,OAAK,OAAA;WACL,aAAW,OAAA;WACX,SAAO,OAAA;WACP,SAAO,OAAA;UAER;UACA;UACA;UACA;UACA;UAGA;;UAEA;UACA;UACA;UAGA;UACA;EAEI,YAAA,SAAS;;EASrB,YAAY,WAAW;;;;;;;;;;;;EAkBvB,UAAU,WAAW,WAAW;;;;;;;EAsChC,OAAO,YAAY,kBAAkB;;;;;;EAqBrC,YAAY,IAAI,MAAM,IAAI;;EAuB1B;;;UCxKe;WACN;WACA;;EAET;;;UAIe;EACf,iBAAiB,cAAc,UAAU,IAAI;EAC7C,oBAAoB,cAAc,UAAU,IAAI;;;;;;;;;;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B;;EAEf;;EAEA;;;UAIe;;EAEf;;EAEA,WAAW;;EAEX;;EAEA,QAAQ;;;wBAOM,uBAAuB;;;;;;;;;;;wBAmBvB,eACd,OAAO,sBACP,iBACA,iBACA,gBACA,gBACA,SAAS;;wBA8DK,gBAAgB,OAAO"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-button.ts","../src/virtual-joystick.ts"],"mappings":";;;;;;;;;;qBAsBa;;;;;;;;;;;;;;;;;;;KAmBD,0BAA0B,4BAA4B;;qBAGrD;;;;;;KAMD,wBAAwB,0BAA0B;UAE7C;EACf;EACA;;EAEA;;EAEA;;UAGe;EACf;EACA;EACA;EACA,SAAS;EACT;;EAEA;;;UAIe;EACf;EACA;EACA;IAAW;IAAkB;;EAC7B;EACA;;wBAGc,mBAAmB,gBAAW,sBAAkB,qBAAgB;;;;;;;;wBAwChE,0BACd,OAAO,cACP,UAAU,wBACV;;wBAyDc,kBAAkB,OAAO;wBAoBzB,aAAa,OAAO,cAAc;wBAIlC,iBAAiB,OAAO,cAAc;wBAItC,kBAAkB,OAAO,cAAc;wBAIvC,QAAQ,OAAO,cAAc;;;;;;;;;;;;;;;;UCnM5B;EACf,SAAS;;UAGM;EACf,qBAAqB;;UAGN;EACf;EACA;EACA;EACA;EACA;IAAoB;IAAkB;;EACtC;;;;;;wBAOc,uBAAuB,MAAM,gBAAgB;;KClCjD;;UAGK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,WAAW;EACX;EACA;;;UAIe;;EAEf;;EAEA,QAAQ;;;;;;qBAaG;WACF,OAAK,OAAA;WACL,aAAW,OAAA;WACX,SAAO,OAAA;WACP,SAAO,OAAA;UAER;UACA;UACA;UACA;UACA;mBAGS;;UAET;UACA;UACA;UAGA;UACA;EAEI,YAAA,SAAS;;EASrB,YAAY,WAAW;;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;;;;;;;EAkBrC,cAAc,YAAY,WAAW;;EAYrC,YAAY,YAAY,WAAW;;EASnC,QAAQ,gBAAgB;;EAUxB,mBAAmB;;EAKnB,gBAAgB,eAAe,OAAO;;EAgBtC,aAAa,QAAQ;UAYb;UAaA;;;UClLO;;EAEf;;EAEA;;EAEA;;;wBAIc,qBAAqB;;wBASrB,iBAAiB,OAAO;;wBAMxB,YAAY,OAAO;;wBAQnB,cAAc,OAAO;;UCnBpB;;EAEf;;EAEA;;;UAIe;;EAEf;;EAEA,WAAW;;EAEX;;EAEA,QAAQ;;;wBAOM,uBAAuB;;;;;;;;;;;wBAmBvB,eACd,OAAO,sBACP,iBACA,iBACA,gBACA,gBACA,SAAS;;wBA8DK,gBAAgB,OAAO"}
package/dist/index.js CHANGED
@@ -227,7 +227,7 @@ var GestureDetector = class {
227
227
  _isTracking = false;
228
228
  _longPressFired = false;
229
229
  _pinchStartDistance = 0;
230
- _pinchTouches = null;
230
+ _pinchActive = false;
231
231
  constructor(config) {
232
232
  this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;
233
233
  this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;
@@ -237,10 +237,8 @@ var GestureDetector = class {
237
237
  }
238
238
  /** Feed a pointer-down event. */
239
239
  pointerDown(x, y) {
240
- this._startPos = {
241
- x,
242
- y
243
- };
240
+ this._startPos.x = x;
241
+ this._startPos.y = y;
244
242
  this._elapsed = 0;
245
243
  this._isTracking = true;
246
244
  this._longPressFired = false;
@@ -316,9 +314,9 @@ var GestureDetector = class {
316
314
  const dx = t2.x - t1.x;
317
315
  const dy = t2.y - t1.y;
318
316
  const dist = Math.sqrt(dx * dx + dy * dy);
319
- if (this._pinchTouches === null) {
317
+ if (!this._pinchActive) {
320
318
  this._pinchStartDistance = dist;
321
- this._pinchTouches = [{ ...t1 }, { ...t2 }];
319
+ this._pinchActive = true;
322
320
  return;
323
321
  }
324
322
  if (this._pinchStartDistance > 0) {
@@ -335,7 +333,7 @@ var GestureDetector = class {
335
333
  }
336
334
  /** Call when pinch ends (fewer than 2 touches). */
337
335
  pinchEnd() {
338
- this._pinchTouches = null;
336
+ this._pinchActive = false;
339
337
  this._pinchStartDistance = 0;
340
338
  }
341
339
  };
@@ -539,32 +537,49 @@ function createIdentityRemap(buttonCount = 17, axisCount = 4) {
539
537
  }
540
538
  /** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */
541
539
  function applyRemap(snapshot, table) {
542
- const buttons = new Array(table.buttons.length);
543
- for (let logical = 0; logical < table.buttons.length; logical++) {
544
- const physical = table.buttons[logical] ?? logical;
545
- const src = snapshot.buttons[physical];
546
- buttons[logical] = {
547
- pressed: src?.pressed ?? false,
548
- value: src?.value ?? 0
540
+ return applyRemapInto(snapshot, table, {
541
+ id: "",
542
+ index: 0,
543
+ timestamp: 0,
544
+ buttons: [],
545
+ axes: []
546
+ });
547
+ }
548
+ /**
549
+ * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into
550
+ * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so
551
+ * a scratch already at the table's size allocates nothing; growing allocates
552
+ * the missing button records once. `out` must not be `snapshot`.
553
+ */
554
+ function applyRemapInto(snapshot, table, out) {
555
+ const buttonCount = table.buttons.length;
556
+ const buttons = out.buttons;
557
+ if (buttons.length > buttonCount) buttons.length = buttonCount;
558
+ for (let logical = 0; logical < buttonCount; logical++) {
559
+ const src = snapshot.buttons[table.buttons[logical] ?? logical];
560
+ const pressed = src?.pressed ?? false;
561
+ const value = src?.value ?? 0;
562
+ const dst = buttons[logical];
563
+ if (dst) {
564
+ dst.pressed = pressed;
565
+ dst.value = value;
566
+ } else buttons[logical] = {
567
+ pressed,
568
+ value
549
569
  };
550
570
  }
551
- const axes = new Array(table.axes.length);
552
- for (let logical = 0; logical < table.axes.length; logical++) {
553
- const map = table.axes[logical] ?? {
554
- index: logical,
555
- invert: false,
556
- scale: 1
557
- };
558
- const raw = snapshot.axes[map.index] ?? 0;
559
- axes[logical] = raw * map.scale * (map.invert ? -1 : 1);
571
+ const axisCount = table.axes.length;
572
+ const axes = out.axes;
573
+ if (axes.length > axisCount) axes.length = axisCount;
574
+ for (let logical = 0; logical < axisCount; logical++) {
575
+ const map = table.axes[logical];
576
+ const raw = snapshot.axes[map ? map.index : logical] ?? 0;
577
+ axes[logical] = map ? raw * map.scale * (map.invert ? -1 : 1) : raw;
560
578
  }
561
- return {
562
- id: snapshot.id,
563
- index: snapshot.index,
564
- timestamp: snapshot.timestamp,
565
- buttons,
566
- axes
567
- };
579
+ out.id = snapshot.id;
580
+ out.index = snapshot.index;
581
+ out.timestamp = snapshot.timestamp;
582
+ return out;
568
583
  }
569
584
  /** Persist a remap table under the given key. Throws on invalid table shape. */
570
585
  async function saveRemap(store, key, table) {
@@ -595,6 +610,18 @@ function isRemapTable(value) {
595
610
  return true;
596
611
  }
597
612
  // src/input-manager.ts
613
+ /** Size `scratch` to `table` so the per-poll remap finds every record in place. */
614
+ function sizeRemapScratch(scratch, table) {
615
+ const buttons = scratch.buttons;
616
+ buttons.length = Math.min(buttons.length, table.buttons.length);
617
+ for (let i = buttons.length; i < table.buttons.length; i++) buttons[i] = {
618
+ pressed: false,
619
+ value: 0
620
+ };
621
+ const axes = scratch.axes;
622
+ axes.length = Math.min(axes.length, table.axes.length);
623
+ for (let i = axes.length; i < table.axes.length; i++) axes[i] = 0;
624
+ }
598
625
  /**
599
626
  * InputManager provides a polling-based input model.
600
627
  *
@@ -679,8 +706,26 @@ var InputManager = class {
679
706
  }
680
707
  /** Install a remap table for a specific gamepad index. Pass `null` to clear. */
681
708
  setGamepadRemap(index, table) {
682
- if (table === null) this._gamepadRemaps.delete(index);
683
- else this._gamepadRemaps.set(index, table);
709
+ if (table === null) {
710
+ this._gamepadRemaps.delete(index);
711
+ return;
712
+ }
713
+ let slot = this._gamepadRemaps.get(index);
714
+ if (slot) slot.table = table;
715
+ else {
716
+ slot = {
717
+ table,
718
+ scratch: {
719
+ id: "",
720
+ index,
721
+ timestamp: 0,
722
+ buttons: [],
723
+ axes: []
724
+ }
725
+ };
726
+ this._gamepadRemaps.set(index, slot);
727
+ }
728
+ sizeRemapScratch(slot.scratch, table);
684
729
  }
685
730
  /** Poll all gamepads from the given source, applying remap + dead zones. */
686
731
  pollGamepads(source) {
@@ -688,7 +733,8 @@ var InputManager = class {
688
733
  for (let i = 0; i < snapshots.length; i++) {
689
734
  const pad = this.gamepad(i);
690
735
  const snap = snapshots[i] ?? null;
691
- updateGamepadFromSnapshot(pad, snap !== null ? this._gamepadRemaps.get(i) ? applyRemap(snap, this._gamepadRemaps.get(i)) : snap : null, this._gamepadDeadZone);
736
+ const slot = snap !== null ? this._gamepadRemaps.get(i) : void 0;
737
+ updateGamepadFromSnapshot(pad, snap !== null && slot ? applyRemapInto(snap, slot.table, slot.scratch) : snap, this._gamepadDeadZone);
692
738
  }
693
739
  }
694
740
  _addOrUpdateTouch(id, x, y, isDown) {
@@ -804,6 +850,7 @@ exports.GamepadButton = GamepadButton;
804
850
  exports.GestureDetector = GestureDetector;
805
851
  exports.InputManager = InputManager;
806
852
  exports.applyRemap = applyRemap;
853
+ exports.applyRemapInto = applyRemapInto;
807
854
  exports.attachKeyboardListeners = attachKeyboardListeners;
808
855
  exports.createButtonState = createButtonState;
809
856
  exports.createGamepadState = createGamepadState;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["G","Signal"],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/virtual-button.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-joystick.ts"],"sourcesContent":["/**\n * Gamepad — poll-based state for a single connected controller.\n *\n * Buttons and axes are indexed against the W3C \"Standard Gamepad\" mapping by\n * default. Callers can translate raw indices via `remap.ts` before feeding\n * snapshots into `updateGamepadFromSnapshot`.\n */\n\n/**\n * Dev-flag access for the dead-zone guard, which runs per axis per frame. Read\n * as a `globalThis` property rather than a bare `__DEV__` identifier for the\n * reason measured in PERF-10 (~0.46 ns vs ~270 ns on JSC).\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad dead zone repeats every frame. */\nlet _warnedDeadZone = false;\n\n/** Largest dead zone that still leaves the rescale well-defined. */\nconst MAX_DEAD_ZONE = 0.99;\n\n/** W3C Standard Gamepad button indices. */\nexport const GamepadButton = {\n A: 0,\n B: 1,\n X: 2,\n Y: 3,\n LB: 4,\n RB: 5,\n LT: 6,\n RT: 7,\n Back: 8,\n Start: 9,\n LS: 10,\n RS: 11,\n DpadUp: 12,\n DpadDown: 13,\n DpadLeft: 14,\n DpadRight: 15,\n Home: 16,\n} as const;\nexport type GamepadButtonId = (typeof GamepadButton)[keyof typeof GamepadButton];\n\n/** W3C Standard Gamepad axes. */\nexport const GamepadAxis = {\n LeftX: 0,\n LeftY: 1,\n RightX: 2,\n RightY: 3,\n} as const;\nexport type GamepadAxisId = (typeof GamepadAxis)[keyof typeof GamepadAxis];\n\nexport interface GamepadButtonState {\n pressed: boolean;\n value: number;\n /** True for exactly one frame after a press. */\n justPressed: boolean;\n /** True for exactly one frame after a release. */\n justReleased: boolean;\n}\n\nexport interface GamepadState {\n connected: boolean;\n id: string;\n index: number;\n buttons: GamepadButtonState[];\n axes: number[];\n /** Monotonically increasing timestamp from the source (ms). */\n timestamp: number;\n}\n\n/** Raw snapshot from a `GamepadSource` — values only, no derived state. */\nexport interface GamepadSnapshot {\n id: string;\n index: number;\n buttons: { pressed: boolean; value: number }[];\n axes: number[];\n timestamp: number;\n}\n\nexport function createGamepadState(index = 0, buttonCount = 17, axisCount = 4): GamepadState {\n const buttons: GamepadButtonState[] = new Array(buttonCount);\n for (let i = 0; i < buttonCount; i++) {\n buttons[i] = { pressed: false, value: 0, justPressed: false, justReleased: false };\n }\n const axes = new Array<number>(axisCount).fill(0);\n return { connected: false, id: '', index, buttons, axes, timestamp: 0 };\n}\n\nfunction applyDeadZone(value: number, deadZone: number): number {\n // The documented contract is [0, 1). At exactly 1 the rescale below divides by\n // zero and returns ±Infinity for any out-of-range axis, which then propagates\n // into every consumer reading the stick. Correct rather than propagate.\n let dz = deadZone;\n if (!(dz >= 0 && dz < 1)) {\n if (G.__DEV__ && !_warnedDeadZone) {\n _warnedDeadZone = true;\n console.warn(\n `[flare-engine/input] deadZone=${deadZone} is outside [0, 1); clamping. ` +\n 'Values at or above 1 would suppress the axis entirely.',\n );\n }\n dz = dz >= 1 ? MAX_DEAD_ZONE : 0;\n }\n const abs = Math.abs(value);\n // `!(abs > dz)` rather than `abs <= dz` so a non-finite axis returns 0 instead\n // of falling through to produce NaN.\n if (!(abs > dz)) return 0;\n const sign = value < 0 ? -1 : 1;\n // Rescale [deadZone, 1] -> [0, 1] so inputs remain smooth past the dead zone.\n return sign * ((abs - dz) / (1 - dz));\n}\n\n/**\n * Apply a fresh snapshot to an existing `GamepadState` in place. Derived\n * `justPressed` / `justReleased` flags are recomputed from the\n * previous `pressed` value.\n *\n * `deadZone` in [0, 1). Values at or below are treated as 0.\n */\nexport function updateGamepadFromSnapshot(\n state: GamepadState,\n snapshot: GamepadSnapshot | null,\n deadZone = 0,\n): void {\n if (snapshot === null) {\n if (!state.connected && !anyButtonDown(state)) {\n clearFrameFlags(state);\n return;\n }\n // Disconnect: clear edge flags, keep sticky pressed=false for released-edge.\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n for (let i = 0; i < state.axes.length; i++) state.axes[i] = 0;\n state.connected = false;\n state.id = '';\n return;\n }\n\n state.connected = true;\n state.id = snapshot.id;\n state.index = snapshot.index;\n state.timestamp = snapshot.timestamp;\n\n const srcButtons = snapshot.buttons;\n const bLen = Math.min(state.buttons.length, srcButtons.length);\n for (let i = 0; i < bLen; i++) {\n const prev = state.buttons[i];\n const src = srcButtons[i];\n if (!prev || !src) continue;\n const wasDown = prev.pressed;\n prev.pressed = src.pressed;\n prev.value = src.value;\n prev.justPressed = src.pressed && !wasDown;\n prev.justReleased = !src.pressed && wasDown;\n }\n // Buttons beyond the snapshot length: clear edges, keep prior pressed false.\n for (let i = bLen; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n\n const aLen = Math.min(state.axes.length, snapshot.axes.length);\n for (let i = 0; i < aLen; i++) {\n state.axes[i] = applyDeadZone(snapshot.axes[i] ?? 0, deadZone);\n }\n for (let i = aLen; i < state.axes.length; i++) state.axes[i] = 0;\n}\n\n/** Reset just the per-frame edge flags. Call when advancing a frame without a fresh snapshot. */\nexport function resetGamepadFrame(state: GamepadState): void {\n clearFrameFlags(state);\n}\n\nfunction clearFrameFlags(state: GamepadState): void {\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = false;\n }\n}\n\nfunction anyButtonDown(state: GamepadState): boolean {\n for (let i = 0; i < state.buttons.length; i++) {\n if (state.buttons[i]?.pressed) return true;\n }\n return false;\n}\n\nexport function isButtonDown(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.pressed ?? false;\n}\n\nexport function wasButtonPressed(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justPressed ?? false;\n}\n\nexport function wasButtonReleased(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justReleased ?? false;\n}\n\nexport function getAxis(state: GamepadState, axis: number): number {\n return state.axes[axis] ?? 0;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Platform abstraction for sampling connected gamepads.\n *\n * `poll()` returns one snapshot per slot (typically up to 4). Unconnected\n * slots return `null`. Implementations:\n *\n * - `createWebGamepadSource()` wraps the W3C `navigator.getGamepads` API.\n * - Native implementations (e.g., `react-native-gamepad`) inject their own\n * via the `GamepadSource` interface — the package itself ships no native deps.\n *\n * **Freshness contract:** each call returns fresh objects. An implementation\n * must not reuse or mutate a snapshot (or its `buttons`/`axes` arrays) that a\n * previous `poll()` call returned. A caller may therefore retain a returned\n * snapshot across frames without it changing out from under them.\n */\nexport interface GamepadSource {\n poll(): (GamepadSnapshot | null)[];\n}\n\nexport interface NavigatorLike {\n getGamepads?: () => (WebGamepad | null)[];\n}\n\nexport interface WebGamepad {\n id: string;\n index: number;\n connected: boolean;\n timestamp: number;\n buttons: readonly { pressed: boolean; value: number }[];\n axes: readonly number[];\n}\n\n/**\n * Wrap `navigator.getGamepads()` (W3C Gamepad API). If `nav` is not supplied,\n * uses `globalThis.navigator`. Returns an empty array when the API is absent.\n */\nexport function createWebGamepadSource(nav?: NavigatorLike): GamepadSource {\n const source: NavigatorLike | undefined =\n nav ??\n (typeof globalThis === 'undefined'\n ? undefined\n : (globalThis as { navigator?: NavigatorLike }).navigator);\n\n return {\n poll(): (GamepadSnapshot | null)[] {\n if (!source?.getGamepads) return [];\n const pads = source.getGamepads();\n const out: (GamepadSnapshot | null)[] = new Array(pads.length);\n for (let i = 0; i < pads.length; i++) {\n const p = pads[i];\n if (!p?.connected) {\n out[i] = null;\n continue;\n }\n out[i] = webGamepadToSnapshot(p);\n }\n return out;\n },\n };\n}\n\nfunction webGamepadToSnapshot(p: WebGamepad): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(p.buttons.length);\n for (let i = 0; i < p.buttons.length; i++) {\n const b = p.buttons[i];\n buttons[i] = { pressed: b?.pressed ?? false, value: b?.value ?? 0 };\n }\n const axes = new Array<number>(p.axes.length);\n for (let i = 0; i < p.axes.length; i++) axes[i] = p.axes[i] ?? 0;\n return { id: p.id, index: p.index, timestamp: p.timestamp, buttons, axes };\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Vec2 } from '@flare-engine/math';\n\n/** Swipe direction. */\nexport type SwipeDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Gesture detection configuration. */\nexport interface GestureConfig {\n /** Max time (seconds) for a tap (default 0.3). */\n tapMaxDuration?: number;\n /** Max distance (px) for a tap (default 20). */\n tapMaxDistance?: number;\n /** Min time (seconds) for a long press (default 0.5). */\n longPressMinDuration?: number;\n /** Min distance (px) for a swipe (default 50). */\n swipeMinDistance?: number;\n /** Max time (seconds) for a swipe (default 0.4). */\n swipeMaxDuration?: number;\n}\n\n/** Swipe event data. */\nexport interface SwipeEvent {\n direction: SwipeDirection;\n distance: number;\n duration: number;\n}\n\n/** Pinch event data. */\nexport interface PinchEvent {\n /** Scale factor (>1 = spread, <1 = pinch). */\n scale: number;\n /** Center point between the two touches. */\n center: Vec2;\n}\n\nconst DEFAULT_TAP_MAX_DURATION = 0.3;\nconst DEFAULT_TAP_MAX_DISTANCE = 20;\nconst DEFAULT_LONG_PRESS_MIN_DURATION = 0.5;\nconst DEFAULT_SWIPE_MIN_DISTANCE = 50;\nconst DEFAULT_SWIPE_MAX_DURATION = 0.4;\n\n/**\n * GestureDetector recognizes tap, long press, swipe, and pinch gestures\n * from raw pointer events.\n */\nexport class GestureDetector {\n readonly onTap = new Signal<Vec2>();\n readonly onLongPress = new Signal<Vec2>();\n readonly onSwipe = new Signal<SwipeEvent>();\n readonly onPinch = new Signal<PinchEvent>();\n\n private tapMaxDuration: number;\n private tapMaxDistance: number;\n private longPressMinDuration: number;\n private swipeMinDistance: number;\n private swipeMaxDuration: number;\n\n // Single-touch tracking\n private _startPos: Vec2 = { x: 0, y: 0 };\n /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */\n private _elapsed = 0;\n private _isTracking = false;\n private _longPressFired = false;\n\n // Pinch tracking\n private _pinchStartDistance = 0;\n private _pinchTouches: [Vec2, Vec2] | null = null;\n\n constructor(config?: GestureConfig) {\n this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;\n this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;\n this.longPressMinDuration = config?.longPressMinDuration ?? DEFAULT_LONG_PRESS_MIN_DURATION;\n this.swipeMinDistance = config?.swipeMinDistance ?? DEFAULT_SWIPE_MIN_DISTANCE;\n this.swipeMaxDuration = config?.swipeMaxDuration ?? DEFAULT_SWIPE_MAX_DURATION;\n }\n\n /** Feed a pointer-down event. */\n pointerDown(x: number, y: number): void {\n this._startPos = { x, y };\n this._elapsed = 0;\n this._isTracking = true;\n this._longPressFired = false;\n }\n\n /**\n * Feed a pointer-up event.\n *\n * `elapsedSinceDown` is optional: pass it when the host tracks its own\n * timestamps (e.g. event-driven, no per-frame `update()` calls); omit it\n * to use the elapsed time already accumulated via `update(dt, ...)`. Either\n * way there is one clock per press — passing it here re-syncs the same\n * accumulator `update()` advances, rather than racing it. If a long press\n * already fired for this press, tap/swipe are suppressed so one press\n * yields exactly one gesture.\n */\n pointerUp(x: number, y: number, elapsedSinceDown?: number): void {\n if (!this._isTracking) return;\n this._isTracking = false;\n if (elapsedSinceDown !== undefined) this._elapsed = elapsedSinceDown;\n if (this._longPressFired) return;\n\n const dx = x - this._startPos.x;\n const dy = y - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n const duration = this._elapsed;\n\n // Check swipe first (requires min distance)\n if (dist >= this.swipeMinDistance && duration <= this.swipeMaxDuration) {\n const absDx = Math.abs(dx);\n const absDy = Math.abs(dy);\n let direction: SwipeDirection;\n if (absDx > absDy) {\n direction = dx > 0 ? 'right' : 'left';\n } else {\n direction = dy > 0 ? 'down' : 'up';\n }\n this.onSwipe.emit({ direction, distance: dist, duration });\n return;\n }\n\n // Check tap (short press, small movement)\n if (dist <= this.tapMaxDistance && duration <= this.tapMaxDuration) {\n this.onTap.emit({ x, y });\n return;\n }\n }\n\n /**\n * Update gesture tracking. Call each frame with dt.\n * @param dt Delta time in seconds.\n * @param currentX Current pointer X.\n * @param currentY Current pointer Y.\n */\n update(dt: number, currentX: number, currentY: number): void {\n if (!this._isTracking) return;\n this._elapsed += dt;\n\n // Long press detection\n if (!this._longPressFired && this._elapsed >= this.longPressMinDuration) {\n const dx = currentX - this._startPos.x;\n const dy = currentY - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n if (dist <= this.tapMaxDistance) {\n this._longPressFired = true;\n this.onLongPress.emit({ x: currentX, y: currentY });\n }\n }\n }\n\n /**\n * Feed a two-finger pinch update. Call when two touches are active.\n * @param t1 First touch position.\n * @param t2 Second touch position.\n */\n pinchUpdate(t1: Vec2, t2: Vec2): void {\n const dx = t2.x - t1.x;\n const dy = t2.y - t1.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (this._pinchTouches === null) {\n // Start pinch\n this._pinchStartDistance = dist;\n this._pinchTouches = [{ ...t1 }, { ...t2 }];\n return;\n }\n\n if (this._pinchStartDistance > 0) {\n const scale = dist / this._pinchStartDistance;\n const center: Vec2 = {\n x: (t1.x + t2.x) / 2,\n y: (t1.y + t2.y) / 2,\n };\n this.onPinch.emit({ scale, center });\n }\n }\n\n /** Call when pinch ends (fewer than 2 touches). */\n pinchEnd(): void {\n this._pinchTouches = null;\n this._pinchStartDistance = 0;\n }\n}\n","/** Virtual button state — pure data, no UI. */\nexport interface VirtualButtonState {\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n /** Whether the button was just pressed this frame. */\n justPressed: boolean;\n /** Whether the button was just released this frame. */\n justReleased: boolean;\n}\n\n/** Create a default button state. */\nexport function createButtonState(): VirtualButtonState {\n return {\n isPressed: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/** Call at the start of each frame to reset per-frame flags. */\nexport function resetButtonFrame(state: VirtualButtonState): void {\n state.justPressed = false;\n state.justReleased = false;\n}\n\n/** Call when the button is pressed. */\nexport function pressButton(state: VirtualButtonState): void {\n if (!state.isPressed) {\n state.isPressed = true;\n state.justPressed = true;\n }\n}\n\n/** Call when the button is released. */\nexport function releaseButton(state: VirtualButtonState): void {\n if (state.isPressed) {\n state.isPressed = false;\n state.justReleased = true;\n }\n}\n","import {\n createButtonState,\n pressButton,\n releaseButton,\n resetButtonFrame,\n type VirtualButtonState,\n} from './virtual-button.js';\n\n/** Minimal keyboard event shape — no DOM type dep. */\nexport interface KeyboardEventLike {\n readonly code: string;\n readonly type: string;\n /** Optional — real DOM events have it; synthetic feeds may not. */\n preventDefault?(): void;\n}\n\n/** Minimal event target shape for attaching keyboard listeners. */\nexport interface KeyboardEventTargetLike {\n addEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n removeEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n}\n\n/**\n * Buffered per-frame keyboard state.\n *\n * Edge flags (`wasPressed`, `wasReleased`) clear each frame via `reset()`.\n * `keyDown` / `keyUp` are the platform-neutral injection points: web feeds\n * them via `attachKeyboardListeners`; mobile/RN feeds them from a\n * hardware-keyboard native module or an on-screen source.\n */\nexport interface KeyboardState {\n /** True while the key is physically held. */\n isDown(code: string): boolean;\n /** True only on the frame the key was pressed. */\n wasPressed(code: string): boolean;\n /** True only on the frame the key was released. */\n wasReleased(code: string): boolean;\n /** Platform-neutral injection. OS auto-repeat is de-edged by the pressButton guard. */\n keyDown(code: string): void;\n /** Platform-neutral injection. */\n keyUp(code: string): void;\n /** Frame-start edge clear. Zero-alloc. */\n reset(): void;\n /** Blur/stuck-key guard: emits a release edge for every held code, then drops held. */\n clear(): void;\n}\n\n/** Create a fresh keyboard state. */\nexport function createKeyboard(): KeyboardState {\n const states: VirtualButtonState[] = [];\n const codeIndex = new Map<string, number>();\n\n return {\n isDown(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.isPressed ?? false;\n },\n\n wasPressed(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justPressed ?? false;\n },\n\n wasReleased(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justReleased ?? false;\n },\n\n keyDown(code: string): void {\n let i = codeIndex.get(code);\n if (i === undefined) {\n i = states.length;\n states.push(createButtonState());\n codeIndex.set(code, i);\n }\n pressButton(states[i]!);\n },\n\n keyUp(code: string): void {\n const i = codeIndex.get(code);\n if (i === undefined) return;\n releaseButton(states[i]!);\n },\n\n reset(): void {\n for (let i = 0; i < states.length; i++) {\n resetButtonFrame(states[i]!);\n }\n },\n\n clear(): void {\n for (let i = 0; i < states.length; i++) {\n releaseButton(states[i]!);\n }\n },\n };\n}\n\n/**\n * Web turnkey adapter: registers `keydown`, `keyup`, and `blur` listeners on\n * `target`. `blur` calls `kb.clear()` (stuck-key guard). Returns a detach fn.\n *\n * `target` is structural `{ addEventListener, removeEventListener }` — no DOM\n * types dep. On web, pass `window`; for mobile/RN, feed `keyDown`/`keyUp`\n * directly from a hardware-keyboard native module or an on-screen source.\n *\n * Does NOT call `preventDefault` — bare use lets Space/arrows scroll and Tab\n * move DOM focus. For game-mode input, attach your own listener that calls\n * `preventDefault` for game keys and forwards `kb.keyDown(ev.code)`.\n */\nexport function attachKeyboardListeners(\n kb: KeyboardState,\n target: KeyboardEventTargetLike,\n): () => void {\n const onKeyDown = (ev: KeyboardEventLike): void => {\n kb.keyDown(ev.code);\n };\n const onKeyUp = (ev: KeyboardEventLike): void => {\n kb.keyUp(ev.code);\n };\n const onBlur = (_ev: KeyboardEventLike): void => {\n kb.clear();\n };\n\n target.addEventListener('keydown', onKeyDown);\n target.addEventListener('keyup', onKeyUp);\n target.addEventListener('blur', onBlur);\n\n return (): void => {\n target.removeEventListener('keydown', onKeyDown);\n target.removeEventListener('keyup', onKeyUp);\n target.removeEventListener('blur', onBlur);\n };\n}\n\n/**\n * Action → code binding map. Keys are action names; values are arrays of\n * `KeyboardEvent.code` strings. Multiple codes OR-reduce (any bound key\n * triggers the action).\n */\nexport type KeyBindings = Readonly<Record<string, readonly string[]>>;\n\n/** True if any bound code for `action` is currently held. */\nexport function isActionDown(kb: KeyboardState, bindings: KeyBindings, action: string): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return true;\n }\n return false;\n}\n\n/** True if any bound code for `action` was pressed this frame. */\nexport function wasActionPressed(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.wasPressed(codes[i]!)) return true;\n }\n return false;\n}\n\n/**\n * True if any bound code for `action` was released this frame AND no bound\n * code is still held. Release fires only when the last held bound key lifts.\n */\nexport function wasActionReleased(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n let anyReleased = false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return false;\n if (kb.wasReleased(codes[i]!)) anyReleased = true;\n }\n return anyReleased;\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/** State of a single pointer (primary touch or mouse). */\nexport interface Pointer {\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Position delta since last frame. */\n delta: Vec2;\n /** Whether the pointer is currently held down. */\n isDown: boolean;\n /** True only on the frame the pointer was pressed. */\n justPressed: boolean;\n /** True only on the frame the pointer was released. */\n justReleased: boolean;\n}\n\n/** State of a single touch point in a multitouch scenario. */\nexport interface TouchPoint {\n /** Unique touch identifier. */\n id: number;\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Whether this touch is currently active. */\n isDown: boolean;\n}\n\n/** Create a default pointer state. */\nexport function createPointer(): Pointer {\n return {\n position: { x: 0, y: 0 },\n delta: { x: 0, y: 0 },\n isDown: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/**\n * Update pointer state for a new frame.\n * Call this at the start of each frame to clear per-frame flags.\n */\nexport function resetPointerFrame(pointer: Pointer): void {\n pointer.delta.x = 0;\n pointer.delta.y = 0;\n pointer.justPressed = false;\n pointer.justReleased = false;\n}\n\n/** Feed a pointer-down event into the pointer state. */\nexport function pointerDown(pointer: Pointer, x: number, y: number): void {\n const wasDown = pointer.isDown;\n pointer.isDown = true;\n if (!wasDown) {\n pointer.justPressed = true;\n }\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-move event into the pointer state. */\nexport function pointerMove(pointer: Pointer, x: number, y: number): void {\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-up event into the pointer state. */\nexport function pointerUp(pointer: Pointer, x: number, y: number): void {\n pointer.isDown = false;\n pointer.justReleased = true;\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Button / axis remap table.\n *\n * `buttons[logicalId] = physicalIndex` — to poll A, read\n * `snapshot.buttons[table.buttons[GamepadButton.A]]`.\n *\n * `axes` maps logical axis id → `{ index, invert, scale }`. Most games invert\n * Y on some controllers; `scale` supports half-range triggers.\n */\nexport interface AxisMap {\n index: number;\n invert: boolean;\n scale: number;\n}\n\nexport interface RemapTable {\n buttons: number[];\n axes: AxisMap[];\n}\n\nexport function createIdentityRemap(buttonCount = 17, axisCount = 4): RemapTable {\n const buttons = new Array<number>(buttonCount);\n for (let i = 0; i < buttonCount; i++) buttons[i] = i;\n const axes = new Array<AxisMap>(axisCount);\n for (let i = 0; i < axisCount; i++) axes[i] = { index: i, invert: false, scale: 1 };\n return { buttons, axes };\n}\n\n/** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */\nexport function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(table.buttons.length);\n for (let logical = 0; logical < table.buttons.length; logical++) {\n const physical = table.buttons[logical] ?? logical;\n const src = snapshot.buttons[physical];\n buttons[logical] = { pressed: src?.pressed ?? false, value: src?.value ?? 0 };\n }\n const axes = new Array<number>(table.axes.length);\n for (let logical = 0; logical < table.axes.length; logical++) {\n const map = table.axes[logical] ?? { index: logical, invert: false, scale: 1 };\n const raw = snapshot.axes[map.index] ?? 0;\n axes[logical] = raw * map.scale * (map.invert ? -1 : 1);\n }\n return { id: snapshot.id, index: snapshot.index, timestamp: snapshot.timestamp, buttons, axes };\n}\n\n/**\n * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,\n * but declared locally so this package does not take a hard dep on storage.\n */\nexport interface RemapStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n}\n\n/** Persist a remap table under the given key. Throws on invalid table shape. */\nexport async function saveRemap(store: RemapStore, key: string, table: RemapTable): Promise<void> {\n await store.set(key, JSON.stringify(table));\n}\n\n/** Load a remap table. Returns `null` if absent or malformed. */\nexport async function loadRemap(store: RemapStore, key: string): Promise<RemapTable | null> {\n const raw = await store.get(key);\n if (raw === null) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (!isRemapTable(parsed)) return null;\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isRemapTable(value: unknown): value is RemapTable {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as { buttons?: unknown; axes?: unknown };\n if (!Array.isArray(obj.buttons) || !Array.isArray(obj.axes)) return false;\n for (const b of obj.buttons) if (typeof b !== 'number') return false;\n for (const a of obj.axes) {\n if (typeof a !== 'object' || a === null) return false;\n const ax = a as { index?: unknown; invert?: unknown; scale?: unknown };\n if (\n typeof ax.index !== 'number' ||\n typeof ax.invert !== 'boolean' ||\n typeof ax.scale !== 'number'\n ) {\n return false;\n }\n }\n return true;\n}\n","import {\n createGamepadState,\n type GamepadState,\n resetGamepadFrame,\n updateGamepadFromSnapshot,\n} from './gamepad.js';\nimport type { GamepadSource } from './gamepad-source.js';\nimport { createKeyboard, type KeyboardState } from './keyboard.js';\nimport {\n createPointer,\n type Pointer,\n pointerDown,\n pointerMove,\n pointerUp,\n resetPointerFrame,\n type TouchPoint,\n} from './pointer.js';\nimport type { RemapTable } from './remap.js';\nimport { applyRemap } from './remap.js';\n\n/**\n * InputManager provides a polling-based input model.\n *\n * Call `update()` once per frame (before game logic) to snapshot input state.\n * Feed events from the platform (RN touch/gesture handlers) via the on* methods.\n */\nexport class InputManager {\n /**\n * Primary pointer — the touch that started the current gesture (first\n * `onPointerDown` while no touch was active), or the mouse.\n *\n * Once assigned, the primary id stays fixed to that touch until it lifts;\n * it does NOT transfer to a remaining finger. While a second finger is\n * down, its events reach only `touches` — `pointer` neither moves nor\n * releases because of it. When the primary lifts, `pointer.isDown` goes\n * false even if other fingers remain down, and a new primary is assigned\n * only once every touch has lifted and a fresh `onPointerDown` arrives.\n * This keeps `pointer` a single continuous stream with no mid-gesture\n * teleport; read `touches` for anything beyond one finger.\n */\n readonly pointer: Pointer = createPointer();\n\n /** Buffered keyboard state. Feed via `attachKeyboardListeners` (web) or `keyboard.keyDown`/`keyUp` (mobile/RN). */\n readonly keyboard: KeyboardState = createKeyboard();\n\n /** All active touch points. */\n readonly touches: TouchPoint[] = [];\n\n private _touchMap = new Map<number, TouchPoint>();\n private _primaryTouchId: number | null = null;\n private _gamepads: GamepadState[] = [];\n private _gamepadDeadZone = 0.15;\n private _gamepadRemaps = new Map<number, RemapTable>();\n\n /** Call once per frame to reset per-frame flags. */\n update(): void {\n resetPointerFrame(this.pointer);\n this.keyboard.reset();\n for (let i = 0; i < this._gamepads.length; i++) {\n const pad = this._gamepads[i];\n if (pad) resetGamepadFrame(pad);\n }\n }\n\n /** Feed a touch/pointer begin event. */\n onPointerDown(id: number, x: number, y: number): void {\n if (this._touchMap.size === 0) {\n this._primaryTouchId = id;\n }\n if (id === this._primaryTouchId) {\n pointerDown(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /**\n * Feed a touch/pointer move event.\n *\n * A move for an id that was never pressed, while no primary is active, is a\n * hover (a mouse with no button held): `pointer.position` and `delta`\n * follow it, but `isDown` / `justPressed` stay untouched and no `TouchPoint`\n * is recorded.\n */\n onPointerMove(id: number, x: number, y: number): void {\n if (this._primaryTouchId === null && !this._touchMap.has(id)) {\n pointerMove(this.pointer, x, y);\n return;\n }\n if (id === this._primaryTouchId) {\n pointerMove(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /** Feed a touch/pointer end event. */\n onPointerUp(id: number, x: number, y: number): void {\n if (id === this._primaryTouchId) {\n pointerUp(this.pointer, x, y);\n this._primaryTouchId = null;\n }\n this._removeTouch(id);\n }\n\n /** Access the gamepad state at `index`. Allocates on first access. */\n gamepad(index: number): GamepadState {\n let pad = this._gamepads[index];\n if (!pad) {\n pad = createGamepadState(index);\n this._gamepads[index] = pad;\n }\n return pad;\n }\n\n /** Dead zone in [0, 1). Axes at or below this magnitude read as 0. */\n setGamepadDeadZone(deadZone: number): void {\n this._gamepadDeadZone = Math.max(0, Math.min(0.95, deadZone));\n }\n\n /** Install a remap table for a specific gamepad index. Pass `null` to clear. */\n setGamepadRemap(index: number, table: RemapTable | null): void {\n if (table === null) this._gamepadRemaps.delete(index);\n else this._gamepadRemaps.set(index, table);\n }\n\n /** Poll all gamepads from the given source, applying remap + dead zones. */\n pollGamepads(source: GamepadSource): void {\n const snapshots = source.poll();\n for (let i = 0; i < snapshots.length; i++) {\n const pad = this.gamepad(i);\n const snap = snapshots[i] ?? null;\n const remapped =\n snap !== null\n ? this._gamepadRemaps.get(i)\n ? applyRemap(snap, this._gamepadRemaps.get(i) as RemapTable)\n : snap\n : null;\n updateGamepadFromSnapshot(pad, remapped, this._gamepadDeadZone);\n }\n }\n\n private _addOrUpdateTouch(id: number, x: number, y: number, isDown: boolean): void {\n let touch = this._touchMap.get(id);\n if (!touch) {\n touch = { id, position: { x, y }, isDown };\n this._touchMap.set(id, touch);\n this.touches.push(touch);\n } else {\n touch.position.x = x;\n touch.position.y = y;\n touch.isDown = isDown;\n }\n }\n\n private _removeTouch(id: number): void {\n const touch = this._touchMap.get(id);\n if (!touch) return;\n this._touchMap.delete(id);\n const idx = this.touches.indexOf(touch);\n if (idx !== -1) {\n this.touches.splice(idx, 1);\n }\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Dev-flag access for the config guard in `updateJoystick`, which runs once per\n * frame while a stick is held. Read as a `globalThis` property, not as a bare\n * `__DEV__` identifier: on JSC an unresolvable global costs ~270 ns per\n * evaluation where a property miss is inline-cached at ~0.46 ns. Same reasoning\n * as `@flare-engine/core`'s `Pool` — see PERF-10.\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad config repeats every frame. */\nlet _warnedConfig = false;\n\n/** Virtual joystick configuration. */\nexport interface VirtualJoystickConfig {\n /** Dead zone radius in pixels (default 10). */\n deadZone?: number;\n /** Maximum radius in pixels (default 50). */\n maxRadius?: number;\n}\n\n/** Virtual joystick state — pure data, no UI. */\nexport interface VirtualJoystickState {\n /** Whether the joystick is currently being touched. */\n active: boolean;\n /** Normalized direction vector (-1 to 1 per axis). */\n direction: Vec2;\n /** Magnitude 0-1 (0 = center/dead zone, 1 = max radius). */\n magnitude: number;\n /** Raw offset from center in pixels. */\n offset: Vec2;\n}\n\nconst DEFAULT_DEAD_ZONE = 10;\nconst DEFAULT_MAX_RADIUS = 50;\n\n/** Create a default joystick state. */\nexport function createJoystickState(): VirtualJoystickState {\n return {\n active: false,\n direction: { x: 0, y: 0 },\n magnitude: 0,\n offset: { x: 0, y: 0 },\n };\n}\n\n/**\n * Update joystick state from a touch event.\n *\n * @param state The joystick state to update.\n * @param centerX The joystick center X in screen pixels.\n * @param centerY The joystick center Y in screen pixels.\n * @param touchX The current touch X in screen pixels.\n * @param touchY The current touch Y in screen pixels.\n * @param config Joystick configuration.\n */\nexport function updateJoystick(\n state: VirtualJoystickState,\n centerX: number,\n centerY: number,\n touchX: number,\n touchY: number,\n config?: VirtualJoystickConfig,\n): void {\n let deadZone = config?.deadZone ?? DEFAULT_DEAD_ZONE;\n let maxRadius = config?.maxRadius ?? DEFAULT_MAX_RADIUS;\n\n // Out-of-contract config is corrected rather than propagated. Left alone, a\n // NaN deadZone defeats the early return below and a maxRadius equal to\n // deadZone divides by zero at `normalizedDist` — either way `state.direction`\n // becomes NaN and, because the state is reused across frames, the stick never\n // recovers. The whole check sits behind one comparison on the healthy path.\n if (!(deadZone >= 0 && maxRadius > deadZone)) {\n if (G.__DEV__ && !_warnedConfig) {\n _warnedConfig = true;\n console.warn(\n `[flare-engine/input] updateJoystick: invalid config (deadZone=${deadZone}, maxRadius=${maxRadius}); ` +\n 'expected 0 <= deadZone < maxRadius. Falling back to defaults for this call.',\n );\n }\n if (!(deadZone >= 0)) deadZone = DEFAULT_DEAD_ZONE;\n if (!(maxRadius > deadZone)) maxRadius = deadZone + DEFAULT_MAX_RADIUS;\n }\n\n const dx = touchX - centerX;\n const dy = touchY - centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n state.active = true;\n\n // `!(dist >= deadZone)` rather than `dist < deadZone` so a non-finite touch\n // coordinate takes the centred branch instead of falling through to the maths.\n if (!(dist >= deadZone)) {\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n // dist is non-finite only when a touch coordinate was, in which case dx/dy\n // are too — report a centred offset rather than writing NaN into the state.\n const centred = dist === 0 || !Number.isFinite(dist);\n state.offset.x = centred ? 0 : dx;\n state.offset.y = centred ? 0 : dy;\n return;\n }\n\n // Clamp to max radius\n const clampedDist = Math.min(dist, maxRadius);\n const normalizedDist = (clampedDist - deadZone) / (maxRadius - deadZone);\n\n // Direction is always the full normalized direction. `dist` is > 0 here —\n // a zero distance cannot pass the guard above once deadZone >= 0 — but the\n // reciprocal is guarded anyway, because `deadZone: 0` makes `dist === 0`\n // reachable and `1 / 0` would put Infinity into direction.\n const invDist = dist > 0 ? 1 / dist : 0;\n state.direction.x = dx * invDist;\n state.direction.y = dy * invDist;\n state.magnitude = Math.min(normalizedDist, 1);\n\n // Offset clamped to max radius\n const scale = dist > 0 ? clampedDist / dist : 0;\n state.offset.x = dx * scale;\n state.offset.y = dy * scale;\n}\n\n/** Reset joystick state when touch is released. */\nexport function releaseJoystick(state: VirtualJoystickState): void {\n state.active = false;\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n state.offset.x = 0;\n state.offset.y = 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,MAAMA,MAAI;;AAGV,IAAI,kBAAkB;;AAGtB,MAAM,gBAAgB;;AAGtB,MAAa,gBAAgB;CAC3B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,OAAO;CACP,IAAI;CACJ,IAAI;CACJ,QAAQ;CACR,UAAU;CACV,UAAU;CACV,WAAW;CACX,MAAM;AACR;;AAIA,MAAa,cAAc;CACzB,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AA+BA,SAAgB,mBAAmB,QAAQ,GAAG,cAAc,IAAI,YAAY,GAAiB;CAC3F,MAAM,UAAgC,IAAI,MAAM,WAAW;CAC3D,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAC/B,QAAQ,KAAK;EAAE,SAAS;EAAO,OAAO;EAAG,aAAa;EAAO,cAAc;CAAM;CAGnF,OAAO;EAAE,WAAW;EAAO,IAAI;EAAI;EAAO;EAAS,MADtC,IAAI,MAAc,SAAS,CAAC,CAAC,KAAK,CACO;EAAG,WAAW;CAAE;AACxE;AAEA,SAAS,cAAc,OAAe,UAA0B;CAI9D,IAAI,KAAK;CACT,IAAI,EAAE,MAAM,KAAK,KAAK,IAAI;EACxB,IAAIA,IAAE,WAAW,CAAC,iBAAiB;GACjC,kBAAkB;GAClB,QAAQ,KACN,iCAAiC,SAAS,qFAE5C;EACF;EACA,KAAK,MAAM,IAAI,gBAAgB;CACjC;CACA,MAAM,MAAM,KAAK,IAAI,KAAK;CAG1B,IAAI,EAAE,MAAM,KAAK,OAAO;CAGxB,QAFa,QAAQ,IAAI,KAAK,OAEd,MAAM,OAAO,IAAI;AACnC;;;;;;;;A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AAY,WAAW;EAC5C,IAAI,EAAE,WAAW,CAAC,eAAe;GAC/B,gBAAgB;GAChB,QAAQ,KACN,iEAAiE,SAAS,cAAc,UAAU,+EAEpG;EACF;EACA,IAAI,EAAE,YAAY,IAAI,WAAW;EACjC,IAAI,EAAE,YAAY,WAAW,YAAY,WAAW;CACtD;CAEA,MAAM,KAAK,SAAS;CACpB,MAAM,KAAK,SAAS;CACpB,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;CAExC,MAAM,SAAS;CAIf,IAAI,EAAE,QAAQ,WAAW;EACvB,MAAM,UAAU,IAAI;EACpB,MAAM,UAAU,IAAI;EACpB,MAAM,YAAY;EAGlB,MAAM,UAAU,SAAS,KAAK,CAAC,OAAO,SAAS,IAAI;EACnD,MAAM,OAAO,IAAI,UAAU,IAAI;EAC/B,MAAM,OAAO,IAAI,UAAU,IAAI;EAC/B;CACF;CAGA,MAAM,cAAc,KAAK,IAAI,MAAM,SAAS;CAC5C,MAAM,kBAAkB,cAAc,aAAa,YAAY;CAM/D,MAAM,UAAU,OAAO,IAAI,IAAI,OAAO;CACtC,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,YAAY,KAAK,IAAI,gBAAgB,CAAC;CAG5C,MAAM,QAAQ,OAAO,IAAI,cAAc,OAAO;CAC9C,MAAM,OAAO,IAAI,KAAK;CACtB,MAAM,OAAO,IAAI,KAAK;AACxB;;AAGA,SAAgB,gBAAgB,OAAmC;CACjE,MAAM,SAAS;CACf,MAAM,UAAU,IAAI;CACpB,MAAM,UAAU,IAAI;CACpB,MAAM,YAAY;CAClB,MAAM,OAAO,IAAI;CACjB,MAAM,OAAO,IAAI;AACnB"}
1
+ {"version":3,"file":"index.js","names":["G","Signal"],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/virtual-button.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-joystick.ts"],"sourcesContent":["/**\n * Gamepad — poll-based state for a single connected controller.\n *\n * Buttons and axes are indexed against the W3C \"Standard Gamepad\" mapping by\n * default. Callers can translate raw indices via `remap.ts` before feeding\n * snapshots into `updateGamepadFromSnapshot`.\n */\n\n/**\n * Dev-flag access for the dead-zone guard, which runs per axis per frame. Read\n * as a `globalThis` property rather than a bare `__DEV__` identifier for the\n * reason measured in PERF-10 (~0.46 ns vs ~270 ns on JSC).\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad dead zone repeats every frame. */\nlet _warnedDeadZone = false;\n\n/** Largest dead zone that still leaves the rescale well-defined. */\nconst MAX_DEAD_ZONE = 0.99;\n\n/** W3C Standard Gamepad button indices. */\nexport const GamepadButton = {\n A: 0,\n B: 1,\n X: 2,\n Y: 3,\n LB: 4,\n RB: 5,\n LT: 6,\n RT: 7,\n Back: 8,\n Start: 9,\n LS: 10,\n RS: 11,\n DpadUp: 12,\n DpadDown: 13,\n DpadLeft: 14,\n DpadRight: 15,\n Home: 16,\n} as const;\nexport type GamepadButtonId = (typeof GamepadButton)[keyof typeof GamepadButton];\n\n/** W3C Standard Gamepad axes. */\nexport const GamepadAxis = {\n LeftX: 0,\n LeftY: 1,\n RightX: 2,\n RightY: 3,\n} as const;\nexport type GamepadAxisId = (typeof GamepadAxis)[keyof typeof GamepadAxis];\n\nexport interface GamepadButtonState {\n pressed: boolean;\n value: number;\n /** True for exactly one frame after a press. */\n justPressed: boolean;\n /** True for exactly one frame after a release. */\n justReleased: boolean;\n}\n\nexport interface GamepadState {\n connected: boolean;\n id: string;\n index: number;\n buttons: GamepadButtonState[];\n axes: number[];\n /** Monotonically increasing timestamp from the source (ms). */\n timestamp: number;\n}\n\n/** Raw snapshot from a `GamepadSource` — values only, no derived state. */\nexport interface GamepadSnapshot {\n id: string;\n index: number;\n buttons: { pressed: boolean; value: number }[];\n axes: number[];\n timestamp: number;\n}\n\nexport function createGamepadState(index = 0, buttonCount = 17, axisCount = 4): GamepadState {\n const buttons: GamepadButtonState[] = new Array(buttonCount);\n for (let i = 0; i < buttonCount; i++) {\n buttons[i] = { pressed: false, value: 0, justPressed: false, justReleased: false };\n }\n const axes = new Array<number>(axisCount).fill(0);\n return { connected: false, id: '', index, buttons, axes, timestamp: 0 };\n}\n\nfunction applyDeadZone(value: number, deadZone: number): number {\n // The documented contract is [0, 1). At exactly 1 the rescale below divides by\n // zero and returns ±Infinity for any out-of-range axis, which then propagates\n // into every consumer reading the stick. Correct rather than propagate.\n let dz = deadZone;\n if (!(dz >= 0 && dz < 1)) {\n if (G.__DEV__ && !_warnedDeadZone) {\n _warnedDeadZone = true;\n console.warn(\n `[flare-engine/input] deadZone=${deadZone} is outside [0, 1); clamping. ` +\n 'Values at or above 1 would suppress the axis entirely.',\n );\n }\n dz = dz >= 1 ? MAX_DEAD_ZONE : 0;\n }\n const abs = Math.abs(value);\n // `!(abs > dz)` rather than `abs <= dz` so a non-finite axis returns 0 instead\n // of falling through to produce NaN.\n if (!(abs > dz)) return 0;\n const sign = value < 0 ? -1 : 1;\n // Rescale [deadZone, 1] -> [0, 1] so inputs remain smooth past the dead zone.\n return sign * ((abs - dz) / (1 - dz));\n}\n\n/**\n * Apply a fresh snapshot to an existing `GamepadState` in place. Derived\n * `justPressed` / `justReleased` flags are recomputed from the\n * previous `pressed` value.\n *\n * `deadZone` in [0, 1). Values at or below are treated as 0.\n */\nexport function updateGamepadFromSnapshot(\n state: GamepadState,\n snapshot: GamepadSnapshot | null,\n deadZone = 0,\n): void {\n if (snapshot === null) {\n if (!state.connected && !anyButtonDown(state)) {\n clearFrameFlags(state);\n return;\n }\n // Disconnect: clear edge flags, keep sticky pressed=false for released-edge.\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n for (let i = 0; i < state.axes.length; i++) state.axes[i] = 0;\n state.connected = false;\n state.id = '';\n return;\n }\n\n state.connected = true;\n state.id = snapshot.id;\n state.index = snapshot.index;\n state.timestamp = snapshot.timestamp;\n\n const srcButtons = snapshot.buttons;\n const bLen = Math.min(state.buttons.length, srcButtons.length);\n for (let i = 0; i < bLen; i++) {\n const prev = state.buttons[i];\n const src = srcButtons[i];\n if (!prev || !src) continue;\n const wasDown = prev.pressed;\n prev.pressed = src.pressed;\n prev.value = src.value;\n prev.justPressed = src.pressed && !wasDown;\n prev.justReleased = !src.pressed && wasDown;\n }\n // Buttons beyond the snapshot length: clear edges, keep prior pressed false.\n for (let i = bLen; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n\n const aLen = Math.min(state.axes.length, snapshot.axes.length);\n for (let i = 0; i < aLen; i++) {\n state.axes[i] = applyDeadZone(snapshot.axes[i] ?? 0, deadZone);\n }\n for (let i = aLen; i < state.axes.length; i++) state.axes[i] = 0;\n}\n\n/** Reset just the per-frame edge flags. Call when advancing a frame without a fresh snapshot. */\nexport function resetGamepadFrame(state: GamepadState): void {\n clearFrameFlags(state);\n}\n\nfunction clearFrameFlags(state: GamepadState): void {\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = false;\n }\n}\n\nfunction anyButtonDown(state: GamepadState): boolean {\n for (let i = 0; i < state.buttons.length; i++) {\n if (state.buttons[i]?.pressed) return true;\n }\n return false;\n}\n\nexport function isButtonDown(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.pressed ?? false;\n}\n\nexport function wasButtonPressed(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justPressed ?? false;\n}\n\nexport function wasButtonReleased(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justReleased ?? false;\n}\n\nexport function getAxis(state: GamepadState, axis: number): number {\n return state.axes[axis] ?? 0;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Platform abstraction for sampling connected gamepads.\n *\n * `poll()` returns one snapshot per slot (typically up to 4). Unconnected\n * slots return `null`. Implementations:\n *\n * - `createWebGamepadSource()` wraps the W3C `navigator.getGamepads` API.\n * - Native implementations (e.g., `react-native-gamepad`) inject their own\n * via the `GamepadSource` interface — the package itself ships no native deps.\n *\n * **Freshness contract:** each call returns fresh objects. An implementation\n * must not reuse or mutate a snapshot (or its `buttons`/`axes` arrays) that a\n * previous `poll()` call returned. A caller may therefore retain a returned\n * snapshot across frames without it changing out from under them.\n */\nexport interface GamepadSource {\n poll(): (GamepadSnapshot | null)[];\n}\n\nexport interface NavigatorLike {\n getGamepads?: () => (WebGamepad | null)[];\n}\n\nexport interface WebGamepad {\n id: string;\n index: number;\n connected: boolean;\n timestamp: number;\n buttons: readonly { pressed: boolean; value: number }[];\n axes: readonly number[];\n}\n\n/**\n * Wrap `navigator.getGamepads()` (W3C Gamepad API). If `nav` is not supplied,\n * uses `globalThis.navigator`. Returns an empty array when the API is absent.\n */\nexport function createWebGamepadSource(nav?: NavigatorLike): GamepadSource {\n const source: NavigatorLike | undefined =\n nav ??\n (typeof globalThis === 'undefined'\n ? undefined\n : (globalThis as { navigator?: NavigatorLike }).navigator);\n\n return {\n poll(): (GamepadSnapshot | null)[] {\n if (!source?.getGamepads) return [];\n const pads = source.getGamepads();\n const out: (GamepadSnapshot | null)[] = new Array(pads.length);\n for (let i = 0; i < pads.length; i++) {\n const p = pads[i];\n if (!p?.connected) {\n out[i] = null;\n continue;\n }\n out[i] = webGamepadToSnapshot(p);\n }\n return out;\n },\n };\n}\n\nfunction webGamepadToSnapshot(p: WebGamepad): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(p.buttons.length);\n for (let i = 0; i < p.buttons.length; i++) {\n const b = p.buttons[i];\n buttons[i] = { pressed: b?.pressed ?? false, value: b?.value ?? 0 };\n }\n const axes = new Array<number>(p.axes.length);\n for (let i = 0; i < p.axes.length; i++) axes[i] = p.axes[i] ?? 0;\n return { id: p.id, index: p.index, timestamp: p.timestamp, buttons, axes };\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Vec2 } from '@flare-engine/math';\n\n/** Swipe direction. */\nexport type SwipeDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Gesture detection configuration. */\nexport interface GestureConfig {\n /** Max time (seconds) for a tap (default 0.3). */\n tapMaxDuration?: number;\n /** Max distance (px) for a tap (default 20). */\n tapMaxDistance?: number;\n /** Min time (seconds) for a long press (default 0.5). */\n longPressMinDuration?: number;\n /** Min distance (px) for a swipe (default 50). */\n swipeMinDistance?: number;\n /** Max time (seconds) for a swipe (default 0.4). */\n swipeMaxDuration?: number;\n}\n\n/** Swipe event data. */\nexport interface SwipeEvent {\n direction: SwipeDirection;\n distance: number;\n duration: number;\n}\n\n/** Pinch event data. */\nexport interface PinchEvent {\n /** Scale factor (>1 = spread, <1 = pinch). */\n scale: number;\n /** Center point between the two touches. */\n center: Vec2;\n}\n\nconst DEFAULT_TAP_MAX_DURATION = 0.3;\nconst DEFAULT_TAP_MAX_DISTANCE = 20;\nconst DEFAULT_LONG_PRESS_MIN_DURATION = 0.5;\nconst DEFAULT_SWIPE_MIN_DISTANCE = 50;\nconst DEFAULT_SWIPE_MAX_DURATION = 0.4;\n\n/**\n * GestureDetector recognizes tap, long press, swipe, and pinch gestures\n * from raw pointer events.\n */\nexport class GestureDetector {\n readonly onTap = new Signal<Vec2>();\n readonly onLongPress = new Signal<Vec2>();\n readonly onSwipe = new Signal<SwipeEvent>();\n readonly onPinch = new Signal<PinchEvent>();\n\n private tapMaxDuration: number;\n private tapMaxDistance: number;\n private longPressMinDuration: number;\n private swipeMinDistance: number;\n private swipeMaxDuration: number;\n\n // Single-touch tracking\n private readonly _startPos: Vec2 = { x: 0, y: 0 };\n /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */\n private _elapsed = 0;\n private _isTracking = false;\n private _longPressFired = false;\n\n // Pinch tracking\n private _pinchStartDistance = 0;\n private _pinchActive = false;\n\n constructor(config?: GestureConfig) {\n this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;\n this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;\n this.longPressMinDuration = config?.longPressMinDuration ?? DEFAULT_LONG_PRESS_MIN_DURATION;\n this.swipeMinDistance = config?.swipeMinDistance ?? DEFAULT_SWIPE_MIN_DISTANCE;\n this.swipeMaxDuration = config?.swipeMaxDuration ?? DEFAULT_SWIPE_MAX_DURATION;\n }\n\n /** Feed a pointer-down event. */\n pointerDown(x: number, y: number): void {\n this._startPos.x = x;\n this._startPos.y = y;\n this._elapsed = 0;\n this._isTracking = true;\n this._longPressFired = false;\n }\n\n /**\n * Feed a pointer-up event.\n *\n * `elapsedSinceDown` is optional: pass it when the host tracks its own\n * timestamps (e.g. event-driven, no per-frame `update()` calls); omit it\n * to use the elapsed time already accumulated via `update(dt, ...)`. Either\n * way there is one clock per press — passing it here re-syncs the same\n * accumulator `update()` advances, rather than racing it. If a long press\n * already fired for this press, tap/swipe are suppressed so one press\n * yields exactly one gesture.\n */\n pointerUp(x: number, y: number, elapsedSinceDown?: number): void {\n if (!this._isTracking) return;\n this._isTracking = false;\n if (elapsedSinceDown !== undefined) this._elapsed = elapsedSinceDown;\n if (this._longPressFired) return;\n\n const dx = x - this._startPos.x;\n const dy = y - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n const duration = this._elapsed;\n\n // Check swipe first (requires min distance)\n if (dist >= this.swipeMinDistance && duration <= this.swipeMaxDuration) {\n const absDx = Math.abs(dx);\n const absDy = Math.abs(dy);\n let direction: SwipeDirection;\n if (absDx > absDy) {\n direction = dx > 0 ? 'right' : 'left';\n } else {\n direction = dy > 0 ? 'down' : 'up';\n }\n this.onSwipe.emit({ direction, distance: dist, duration });\n return;\n }\n\n // Check tap (short press, small movement)\n if (dist <= this.tapMaxDistance && duration <= this.tapMaxDuration) {\n this.onTap.emit({ x, y });\n return;\n }\n }\n\n /**\n * Update gesture tracking. Call each frame with dt.\n * @param dt Delta time in seconds.\n * @param currentX Current pointer X.\n * @param currentY Current pointer Y.\n */\n update(dt: number, currentX: number, currentY: number): void {\n if (!this._isTracking) return;\n this._elapsed += dt;\n\n // Long press detection\n if (!this._longPressFired && this._elapsed >= this.longPressMinDuration) {\n const dx = currentX - this._startPos.x;\n const dy = currentY - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n if (dist <= this.tapMaxDistance) {\n this._longPressFired = true;\n this.onLongPress.emit({ x: currentX, y: currentY });\n }\n }\n }\n\n /**\n * Feed a two-finger pinch update. Call when two touches are active.\n * @param t1 First touch position.\n * @param t2 Second touch position.\n */\n pinchUpdate(t1: Vec2, t2: Vec2): void {\n const dx = t2.x - t1.x;\n const dy = t2.y - t1.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (!this._pinchActive) {\n // Start pinch\n this._pinchStartDistance = dist;\n this._pinchActive = true;\n return;\n }\n\n if (this._pinchStartDistance > 0) {\n const scale = dist / this._pinchStartDistance;\n const center: Vec2 = {\n x: (t1.x + t2.x) / 2,\n y: (t1.y + t2.y) / 2,\n };\n this.onPinch.emit({ scale, center });\n }\n }\n\n /** Call when pinch ends (fewer than 2 touches). */\n pinchEnd(): void {\n this._pinchActive = false;\n this._pinchStartDistance = 0;\n }\n}\n","/** Virtual button state — pure data, no UI. */\nexport interface VirtualButtonState {\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n /** Whether the button was just pressed this frame. */\n justPressed: boolean;\n /** Whether the button was just released this frame. */\n justReleased: boolean;\n}\n\n/** Create a default button state. */\nexport function createButtonState(): VirtualButtonState {\n return {\n isPressed: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/** Call at the start of each frame to reset per-frame flags. */\nexport function resetButtonFrame(state: VirtualButtonState): void {\n state.justPressed = false;\n state.justReleased = false;\n}\n\n/** Call when the button is pressed. */\nexport function pressButton(state: VirtualButtonState): void {\n if (!state.isPressed) {\n state.isPressed = true;\n state.justPressed = true;\n }\n}\n\n/** Call when the button is released. */\nexport function releaseButton(state: VirtualButtonState): void {\n if (state.isPressed) {\n state.isPressed = false;\n state.justReleased = true;\n }\n}\n","import {\n createButtonState,\n pressButton,\n releaseButton,\n resetButtonFrame,\n type VirtualButtonState,\n} from './virtual-button.js';\n\n/** Minimal keyboard event shape — no DOM type dep. */\nexport interface KeyboardEventLike {\n readonly code: string;\n readonly type: string;\n /** Optional — real DOM events have it; synthetic feeds may not. */\n preventDefault?(): void;\n}\n\n/** Minimal event target shape for attaching keyboard listeners. */\nexport interface KeyboardEventTargetLike {\n addEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n removeEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n}\n\n/**\n * Buffered per-frame keyboard state.\n *\n * Edge flags (`wasPressed`, `wasReleased`) clear each frame via `reset()`.\n * `keyDown` / `keyUp` are the platform-neutral injection points: web feeds\n * them via `attachKeyboardListeners`; mobile/RN feeds them from a\n * hardware-keyboard native module or an on-screen source.\n */\nexport interface KeyboardState {\n /** True while the key is physically held. */\n isDown(code: string): boolean;\n /** True only on the frame the key was pressed. */\n wasPressed(code: string): boolean;\n /** True only on the frame the key was released. */\n wasReleased(code: string): boolean;\n /** Platform-neutral injection. OS auto-repeat is de-edged by the pressButton guard. */\n keyDown(code: string): void;\n /** Platform-neutral injection. */\n keyUp(code: string): void;\n /** Frame-start edge clear. Zero-alloc. */\n reset(): void;\n /** Blur/stuck-key guard: emits a release edge for every held code, then drops held. */\n clear(): void;\n}\n\n/** Create a fresh keyboard state. */\nexport function createKeyboard(): KeyboardState {\n const states: VirtualButtonState[] = [];\n const codeIndex = new Map<string, number>();\n\n return {\n isDown(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.isPressed ?? false;\n },\n\n wasPressed(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justPressed ?? false;\n },\n\n wasReleased(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justReleased ?? false;\n },\n\n keyDown(code: string): void {\n let i = codeIndex.get(code);\n if (i === undefined) {\n i = states.length;\n states.push(createButtonState());\n codeIndex.set(code, i);\n }\n pressButton(states[i]!);\n },\n\n keyUp(code: string): void {\n const i = codeIndex.get(code);\n if (i === undefined) return;\n releaseButton(states[i]!);\n },\n\n reset(): void {\n for (let i = 0; i < states.length; i++) {\n resetButtonFrame(states[i]!);\n }\n },\n\n clear(): void {\n for (let i = 0; i < states.length; i++) {\n releaseButton(states[i]!);\n }\n },\n };\n}\n\n/**\n * Web turnkey adapter: registers `keydown`, `keyup`, and `blur` listeners on\n * `target`. `blur` calls `kb.clear()` (stuck-key guard). Returns a detach fn.\n *\n * `target` is structural `{ addEventListener, removeEventListener }` — no DOM\n * types dep. On web, pass `window`; for mobile/RN, feed `keyDown`/`keyUp`\n * directly from a hardware-keyboard native module or an on-screen source.\n *\n * Does NOT call `preventDefault` — bare use lets Space/arrows scroll and Tab\n * move DOM focus. For game-mode input, attach your own listener that calls\n * `preventDefault` for game keys and forwards `kb.keyDown(ev.code)`.\n */\nexport function attachKeyboardListeners(\n kb: KeyboardState,\n target: KeyboardEventTargetLike,\n): () => void {\n const onKeyDown = (ev: KeyboardEventLike): void => {\n kb.keyDown(ev.code);\n };\n const onKeyUp = (ev: KeyboardEventLike): void => {\n kb.keyUp(ev.code);\n };\n const onBlur = (_ev: KeyboardEventLike): void => {\n kb.clear();\n };\n\n target.addEventListener('keydown', onKeyDown);\n target.addEventListener('keyup', onKeyUp);\n target.addEventListener('blur', onBlur);\n\n return (): void => {\n target.removeEventListener('keydown', onKeyDown);\n target.removeEventListener('keyup', onKeyUp);\n target.removeEventListener('blur', onBlur);\n };\n}\n\n/**\n * Action → code binding map. Keys are action names; values are arrays of\n * `KeyboardEvent.code` strings. Multiple codes OR-reduce (any bound key\n * triggers the action).\n */\nexport type KeyBindings = Readonly<Record<string, readonly string[]>>;\n\n/** True if any bound code for `action` is currently held. */\nexport function isActionDown(kb: KeyboardState, bindings: KeyBindings, action: string): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return true;\n }\n return false;\n}\n\n/** True if any bound code for `action` was pressed this frame. */\nexport function wasActionPressed(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.wasPressed(codes[i]!)) return true;\n }\n return false;\n}\n\n/**\n * True if any bound code for `action` was released this frame AND no bound\n * code is still held. Release fires only when the last held bound key lifts.\n */\nexport function wasActionReleased(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n let anyReleased = false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return false;\n if (kb.wasReleased(codes[i]!)) anyReleased = true;\n }\n return anyReleased;\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/** State of a single pointer (primary touch or mouse). */\nexport interface Pointer {\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Position delta since last frame. */\n delta: Vec2;\n /** Whether the pointer is currently held down. */\n isDown: boolean;\n /** True only on the frame the pointer was pressed. */\n justPressed: boolean;\n /** True only on the frame the pointer was released. */\n justReleased: boolean;\n}\n\n/** State of a single touch point in a multitouch scenario. */\nexport interface TouchPoint {\n /** Unique touch identifier. */\n id: number;\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Whether this touch is currently active. */\n isDown: boolean;\n}\n\n/** Create a default pointer state. */\nexport function createPointer(): Pointer {\n return {\n position: { x: 0, y: 0 },\n delta: { x: 0, y: 0 },\n isDown: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/**\n * Update pointer state for a new frame.\n * Call this at the start of each frame to clear per-frame flags.\n */\nexport function resetPointerFrame(pointer: Pointer): void {\n pointer.delta.x = 0;\n pointer.delta.y = 0;\n pointer.justPressed = false;\n pointer.justReleased = false;\n}\n\n/** Feed a pointer-down event into the pointer state. */\nexport function pointerDown(pointer: Pointer, x: number, y: number): void {\n const wasDown = pointer.isDown;\n pointer.isDown = true;\n if (!wasDown) {\n pointer.justPressed = true;\n }\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-move event into the pointer state. */\nexport function pointerMove(pointer: Pointer, x: number, y: number): void {\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-up event into the pointer state. */\nexport function pointerUp(pointer: Pointer, x: number, y: number): void {\n pointer.isDown = false;\n pointer.justReleased = true;\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Button / axis remap table.\n *\n * `buttons[logicalId] = physicalIndex` — to poll A, read\n * `snapshot.buttons[table.buttons[GamepadButton.A]]`.\n *\n * `axes` maps logical axis id → `{ index, invert, scale }`. Most games invert\n * Y on some controllers; `scale` supports half-range triggers.\n */\nexport interface AxisMap {\n index: number;\n invert: boolean;\n scale: number;\n}\n\nexport interface RemapTable {\n buttons: number[];\n axes: AxisMap[];\n}\n\nexport function createIdentityRemap(buttonCount = 17, axisCount = 4): RemapTable {\n const buttons = new Array<number>(buttonCount);\n for (let i = 0; i < buttonCount; i++) buttons[i] = i;\n const axes = new Array<AxisMap>(axisCount);\n for (let i = 0; i < axisCount; i++) axes[i] = { index: i, invert: false, scale: 1 };\n return { buttons, axes };\n}\n\n/** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */\nexport function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot {\n return applyRemapInto(snapshot, table, { id: '', index: 0, timestamp: 0, buttons: [], axes: [] });\n}\n\n/**\n * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into\n * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so\n * a scratch already at the table's size allocates nothing; growing allocates\n * the missing button records once. `out` must not be `snapshot`.\n */\nexport function applyRemapInto(\n snapshot: GamepadSnapshot,\n table: RemapTable,\n out: GamepadSnapshot,\n): GamepadSnapshot {\n const buttonCount = table.buttons.length;\n const buttons = out.buttons;\n if (buttons.length > buttonCount) buttons.length = buttonCount;\n for (let logical = 0; logical < buttonCount; logical++) {\n const src = snapshot.buttons[table.buttons[logical] ?? logical];\n const pressed = src?.pressed ?? false;\n const value = src?.value ?? 0;\n const dst = buttons[logical];\n if (dst) {\n dst.pressed = pressed;\n dst.value = value;\n } else {\n buttons[logical] = { pressed, value };\n }\n }\n const axisCount = table.axes.length;\n const axes = out.axes;\n if (axes.length > axisCount) axes.length = axisCount;\n for (let logical = 0; logical < axisCount; logical++) {\n const map = table.axes[logical];\n const raw = snapshot.axes[map ? map.index : logical] ?? 0;\n axes[logical] = map ? raw * map.scale * (map.invert ? -1 : 1) : raw;\n }\n out.id = snapshot.id;\n out.index = snapshot.index;\n out.timestamp = snapshot.timestamp;\n return out;\n}\n\n/**\n * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,\n * but declared locally so this package does not take a hard dep on storage.\n */\nexport interface RemapStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n}\n\n/** Persist a remap table under the given key. Throws on invalid table shape. */\nexport async function saveRemap(store: RemapStore, key: string, table: RemapTable): Promise<void> {\n await store.set(key, JSON.stringify(table));\n}\n\n/** Load a remap table. Returns `null` if absent or malformed. */\nexport async function loadRemap(store: RemapStore, key: string): Promise<RemapTable | null> {\n const raw = await store.get(key);\n if (raw === null) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (!isRemapTable(parsed)) return null;\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isRemapTable(value: unknown): value is RemapTable {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as { buttons?: unknown; axes?: unknown };\n if (!Array.isArray(obj.buttons) || !Array.isArray(obj.axes)) return false;\n for (const b of obj.buttons) if (typeof b !== 'number') return false;\n for (const a of obj.axes) {\n if (typeof a !== 'object' || a === null) return false;\n const ax = a as { index?: unknown; invert?: unknown; scale?: unknown };\n if (\n typeof ax.index !== 'number' ||\n typeof ax.invert !== 'boolean' ||\n typeof ax.scale !== 'number'\n ) {\n return false;\n }\n }\n return true;\n}\n","import {\n createGamepadState,\n type GamepadSnapshot,\n type GamepadState,\n resetGamepadFrame,\n updateGamepadFromSnapshot,\n} from './gamepad.js';\nimport type { GamepadSource } from './gamepad-source.js';\nimport { createKeyboard, type KeyboardState } from './keyboard.js';\nimport {\n createPointer,\n type Pointer,\n pointerDown,\n pointerMove,\n pointerUp,\n resetPointerFrame,\n type TouchPoint,\n} from './pointer.js';\nimport type { RemapTable } from './remap.js';\nimport { applyRemapInto } from './remap.js';\n\n/** A pad's remap table plus the manager-owned snapshot it is applied into. */\ninterface RemapSlot {\n table: RemapTable;\n scratch: GamepadSnapshot;\n}\n\n/** Size `scratch` to `table` so the per-poll remap finds every record in place. */\nfunction sizeRemapScratch(scratch: GamepadSnapshot, table: RemapTable): void {\n const buttons = scratch.buttons;\n buttons.length = Math.min(buttons.length, table.buttons.length);\n for (let i = buttons.length; i < table.buttons.length; i++) {\n buttons[i] = { pressed: false, value: 0 };\n }\n const axes = scratch.axes;\n axes.length = Math.min(axes.length, table.axes.length);\n for (let i = axes.length; i < table.axes.length; i++) axes[i] = 0;\n}\n\n/**\n * InputManager provides a polling-based input model.\n *\n * Call `update()` once per frame (before game logic) to snapshot input state.\n * Feed events from the platform (RN touch/gesture handlers) via the on* methods.\n */\nexport class InputManager {\n /**\n * Primary pointer — the touch that started the current gesture (first\n * `onPointerDown` while no touch was active), or the mouse.\n *\n * Once assigned, the primary id stays fixed to that touch until it lifts;\n * it does NOT transfer to a remaining finger. While a second finger is\n * down, its events reach only `touches` — `pointer` neither moves nor\n * releases because of it. When the primary lifts, `pointer.isDown` goes\n * false even if other fingers remain down, and a new primary is assigned\n * only once every touch has lifted and a fresh `onPointerDown` arrives.\n * This keeps `pointer` a single continuous stream with no mid-gesture\n * teleport; read `touches` for anything beyond one finger.\n */\n readonly pointer: Pointer = createPointer();\n\n /** Buffered keyboard state. Feed via `attachKeyboardListeners` (web) or `keyboard.keyDown`/`keyUp` (mobile/RN). */\n readonly keyboard: KeyboardState = createKeyboard();\n\n /** All active touch points. */\n readonly touches: TouchPoint[] = [];\n\n private _touchMap = new Map<number, TouchPoint>();\n private _primaryTouchId: number | null = null;\n private _gamepads: GamepadState[] = [];\n private _gamepadDeadZone = 0.15;\n private _gamepadRemaps = new Map<number, RemapSlot>();\n\n /** Call once per frame to reset per-frame flags. */\n update(): void {\n resetPointerFrame(this.pointer);\n this.keyboard.reset();\n for (let i = 0; i < this._gamepads.length; i++) {\n const pad = this._gamepads[i];\n if (pad) resetGamepadFrame(pad);\n }\n }\n\n /** Feed a touch/pointer begin event. */\n onPointerDown(id: number, x: number, y: number): void {\n if (this._touchMap.size === 0) {\n this._primaryTouchId = id;\n }\n if (id === this._primaryTouchId) {\n pointerDown(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /**\n * Feed a touch/pointer move event.\n *\n * A move for an id that was never pressed, while no primary is active, is a\n * hover (a mouse with no button held): `pointer.position` and `delta`\n * follow it, but `isDown` / `justPressed` stay untouched and no `TouchPoint`\n * is recorded.\n */\n onPointerMove(id: number, x: number, y: number): void {\n if (this._primaryTouchId === null && !this._touchMap.has(id)) {\n pointerMove(this.pointer, x, y);\n return;\n }\n if (id === this._primaryTouchId) {\n pointerMove(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /** Feed a touch/pointer end event. */\n onPointerUp(id: number, x: number, y: number): void {\n if (id === this._primaryTouchId) {\n pointerUp(this.pointer, x, y);\n this._primaryTouchId = null;\n }\n this._removeTouch(id);\n }\n\n /** Access the gamepad state at `index`. Allocates on first access. */\n gamepad(index: number): GamepadState {\n let pad = this._gamepads[index];\n if (!pad) {\n pad = createGamepadState(index);\n this._gamepads[index] = pad;\n }\n return pad;\n }\n\n /** Dead zone in [0, 1). Axes at or below this magnitude read as 0. */\n setGamepadDeadZone(deadZone: number): void {\n this._gamepadDeadZone = Math.max(0, Math.min(0.95, deadZone));\n }\n\n /** Install a remap table for a specific gamepad index. Pass `null` to clear. */\n setGamepadRemap(index: number, table: RemapTable | null): void {\n if (table === null) {\n this._gamepadRemaps.delete(index);\n return;\n }\n let slot = this._gamepadRemaps.get(index);\n if (slot) {\n slot.table = table;\n } else {\n slot = { table, scratch: { id: '', index, timestamp: 0, buttons: [], axes: [] } };\n this._gamepadRemaps.set(index, slot);\n }\n sizeRemapScratch(slot.scratch, table);\n }\n\n /** Poll all gamepads from the given source, applying remap + dead zones. */\n pollGamepads(source: GamepadSource): void {\n const snapshots = source.poll();\n for (let i = 0; i < snapshots.length; i++) {\n const pad = this.gamepad(i);\n const snap = snapshots[i] ?? null;\n const slot = snap !== null ? this._gamepadRemaps.get(i) : undefined;\n const remapped =\n snap !== null && slot ? applyRemapInto(snap, slot.table, slot.scratch) : snap;\n updateGamepadFromSnapshot(pad, remapped, this._gamepadDeadZone);\n }\n }\n\n private _addOrUpdateTouch(id: number, x: number, y: number, isDown: boolean): void {\n let touch = this._touchMap.get(id);\n if (!touch) {\n touch = { id, position: { x, y }, isDown };\n this._touchMap.set(id, touch);\n this.touches.push(touch);\n } else {\n touch.position.x = x;\n touch.position.y = y;\n touch.isDown = isDown;\n }\n }\n\n private _removeTouch(id: number): void {\n const touch = this._touchMap.get(id);\n if (!touch) return;\n this._touchMap.delete(id);\n const idx = this.touches.indexOf(touch);\n if (idx !== -1) {\n this.touches.splice(idx, 1);\n }\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Dev-flag access for the config guard in `updateJoystick`, which runs once per\n * frame while a stick is held. Read as a `globalThis` property, not as a bare\n * `__DEV__` identifier: on JSC an unresolvable global costs ~270 ns per\n * evaluation where a property miss is inline-cached at ~0.46 ns. Same reasoning\n * as `@flare-engine/core`'s `Pool` — see PERF-10.\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad config repeats every frame. */\nlet _warnedConfig = false;\n\n/** Virtual joystick configuration. */\nexport interface VirtualJoystickConfig {\n /** Dead zone radius in pixels (default 10). */\n deadZone?: number;\n /** Maximum radius in pixels (default 50). */\n maxRadius?: number;\n}\n\n/** Virtual joystick state — pure data, no UI. */\nexport interface VirtualJoystickState {\n /** Whether the joystick is currently being touched. */\n active: boolean;\n /** Normalized direction vector (-1 to 1 per axis). */\n direction: Vec2;\n /** Magnitude 0-1 (0 = center/dead zone, 1 = max radius). */\n magnitude: number;\n /** Raw offset from center in pixels. */\n offset: Vec2;\n}\n\nconst DEFAULT_DEAD_ZONE = 10;\nconst DEFAULT_MAX_RADIUS = 50;\n\n/** Create a default joystick state. */\nexport function createJoystickState(): VirtualJoystickState {\n return {\n active: false,\n direction: { x: 0, y: 0 },\n magnitude: 0,\n offset: { x: 0, y: 0 },\n };\n}\n\n/**\n * Update joystick state from a touch event.\n *\n * @param state The joystick state to update.\n * @param centerX The joystick center X in screen pixels.\n * @param centerY The joystick center Y in screen pixels.\n * @param touchX The current touch X in screen pixels.\n * @param touchY The current touch Y in screen pixels.\n * @param config Joystick configuration.\n */\nexport function updateJoystick(\n state: VirtualJoystickState,\n centerX: number,\n centerY: number,\n touchX: number,\n touchY: number,\n config?: VirtualJoystickConfig,\n): void {\n let deadZone = config?.deadZone ?? DEFAULT_DEAD_ZONE;\n let maxRadius = config?.maxRadius ?? DEFAULT_MAX_RADIUS;\n\n // Out-of-contract config is corrected rather than propagated. Left alone, a\n // NaN deadZone defeats the early return below and a maxRadius equal to\n // deadZone divides by zero at `normalizedDist` — either way `state.direction`\n // becomes NaN and, because the state is reused across frames, the stick never\n // recovers. The whole check sits behind one comparison on the healthy path.\n if (!(deadZone >= 0 && maxRadius > deadZone)) {\n if (G.__DEV__ && !_warnedConfig) {\n _warnedConfig = true;\n console.warn(\n `[flare-engine/input] updateJoystick: invalid config (deadZone=${deadZone}, maxRadius=${maxRadius}); ` +\n 'expected 0 <= deadZone < maxRadius. Falling back to defaults for this call.',\n );\n }\n if (!(deadZone >= 0)) deadZone = DEFAULT_DEAD_ZONE;\n if (!(maxRadius > deadZone)) maxRadius = deadZone + DEFAULT_MAX_RADIUS;\n }\n\n const dx = touchX - centerX;\n const dy = touchY - centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n state.active = true;\n\n // `!(dist >= deadZone)` rather than `dist < deadZone` so a non-finite touch\n // coordinate takes the centred branch instead of falling through to the maths.\n if (!(dist >= deadZone)) {\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n // dist is non-finite only when a touch coordinate was, in which case dx/dy\n // are too — report a centred offset rather than writing NaN into the state.\n const centred = dist === 0 || !Number.isFinite(dist);\n state.offset.x = centred ? 0 : dx;\n state.offset.y = centred ? 0 : dy;\n return;\n }\n\n // Clamp to max radius\n const clampedDist = Math.min(dist, maxRadius);\n const normalizedDist = (clampedDist - deadZone) / (maxRadius - deadZone);\n\n // Direction is always the full normalized direction. `dist` is > 0 here —\n // a zero distance cannot pass the guard above once deadZone >= 0 — but the\n // reciprocal is guarded anyway, because `deadZone: 0` makes `dist === 0`\n // reachable and `1 / 0` would put Infinity into direction.\n const invDist = dist > 0 ? 1 / dist : 0;\n state.direction.x = dx * invDist;\n state.direction.y = dy * invDist;\n state.magnitude = Math.min(normalizedDist, 1);\n\n // Offset clamped to max radius\n const scale = dist > 0 ? clampedDist / dist : 0;\n state.offset.x = dx * scale;\n state.offset.y = dy * scale;\n}\n\n/** Reset joystick state when touch is released. */\nexport function releaseJoystick(state: VirtualJoystickState): void {\n state.active = false;\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n state.offset.x = 0;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,YAAY;EAGlB,MAAM,UAAU,SAAS,KAAK,CAAC,OAAO,SAAS,IAAI;EACnD,MAAM,OAAO,IAAI,UAAU,IAAI;EAC/B,MAAM,OAAO,IAAI,UAAU,IAAI;EAC/B;CACF;CAGA,MAAM,cAAc,KAAK,IAAI,MAAM,SAAS;CAC5C,MAAM,kBAAkB,cAAc,aAAa,YAAY;CAM/D,MAAM,UAAU,OAAO,IAAI,IAAI,OAAO;CACtC,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,YAAY,KAAK,IAAI,gBAAgB,CAAC;CAG5C,MAAM,QAAQ,OAAO,IAAI,cAAc,OAAO;CAC9C,MAAM,OAAO,IAAI,KAAK;CACtB,MAAM,OAAO,IAAI,KAAK;AACxB;;AAGA,SAAgB,gBAAgB,OAAmC;CACjE,MAAM,SAAS;CACf,MAAM,UAAU,IAAI;CACpB,MAAM,UAAU,IAAI;CACpB,MAAM,YAAY;CAClB,MAAM,OAAO,IAAI;CACjB,MAAM,OAAO,IAAI;AACnB"}
package/dist/index.mjs CHANGED
@@ -226,7 +226,7 @@ var GestureDetector = class {
226
226
  _isTracking = false;
227
227
  _longPressFired = false;
228
228
  _pinchStartDistance = 0;
229
- _pinchTouches = null;
229
+ _pinchActive = false;
230
230
  constructor(config) {
231
231
  this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;
232
232
  this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;
@@ -236,10 +236,8 @@ var GestureDetector = class {
236
236
  }
237
237
  /** Feed a pointer-down event. */
238
238
  pointerDown(x, y) {
239
- this._startPos = {
240
- x,
241
- y
242
- };
239
+ this._startPos.x = x;
240
+ this._startPos.y = y;
243
241
  this._elapsed = 0;
244
242
  this._isTracking = true;
245
243
  this._longPressFired = false;
@@ -315,9 +313,9 @@ var GestureDetector = class {
315
313
  const dx = t2.x - t1.x;
316
314
  const dy = t2.y - t1.y;
317
315
  const dist = Math.sqrt(dx * dx + dy * dy);
318
- if (this._pinchTouches === null) {
316
+ if (!this._pinchActive) {
319
317
  this._pinchStartDistance = dist;
320
- this._pinchTouches = [{ ...t1 }, { ...t2 }];
318
+ this._pinchActive = true;
321
319
  return;
322
320
  }
323
321
  if (this._pinchStartDistance > 0) {
@@ -334,7 +332,7 @@ var GestureDetector = class {
334
332
  }
335
333
  /** Call when pinch ends (fewer than 2 touches). */
336
334
  pinchEnd() {
337
- this._pinchTouches = null;
335
+ this._pinchActive = false;
338
336
  this._pinchStartDistance = 0;
339
337
  }
340
338
  };
@@ -538,32 +536,49 @@ function createIdentityRemap(buttonCount = 17, axisCount = 4) {
538
536
  }
539
537
  /** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */
540
538
  function applyRemap(snapshot, table) {
541
- const buttons = new Array(table.buttons.length);
542
- for (let logical = 0; logical < table.buttons.length; logical++) {
543
- const physical = table.buttons[logical] ?? logical;
544
- const src = snapshot.buttons[physical];
545
- buttons[logical] = {
546
- pressed: src?.pressed ?? false,
547
- value: src?.value ?? 0
539
+ return applyRemapInto(snapshot, table, {
540
+ id: "",
541
+ index: 0,
542
+ timestamp: 0,
543
+ buttons: [],
544
+ axes: []
545
+ });
546
+ }
547
+ /**
548
+ * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into
549
+ * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so
550
+ * a scratch already at the table's size allocates nothing; growing allocates
551
+ * the missing button records once. `out` must not be `snapshot`.
552
+ */
553
+ function applyRemapInto(snapshot, table, out) {
554
+ const buttonCount = table.buttons.length;
555
+ const buttons = out.buttons;
556
+ if (buttons.length > buttonCount) buttons.length = buttonCount;
557
+ for (let logical = 0; logical < buttonCount; logical++) {
558
+ const src = snapshot.buttons[table.buttons[logical] ?? logical];
559
+ const pressed = src?.pressed ?? false;
560
+ const value = src?.value ?? 0;
561
+ const dst = buttons[logical];
562
+ if (dst) {
563
+ dst.pressed = pressed;
564
+ dst.value = value;
565
+ } else buttons[logical] = {
566
+ pressed,
567
+ value
548
568
  };
549
569
  }
550
- const axes = new Array(table.axes.length);
551
- for (let logical = 0; logical < table.axes.length; logical++) {
552
- const map = table.axes[logical] ?? {
553
- index: logical,
554
- invert: false,
555
- scale: 1
556
- };
557
- const raw = snapshot.axes[map.index] ?? 0;
558
- axes[logical] = raw * map.scale * (map.invert ? -1 : 1);
570
+ const axisCount = table.axes.length;
571
+ const axes = out.axes;
572
+ if (axes.length > axisCount) axes.length = axisCount;
573
+ for (let logical = 0; logical < axisCount; logical++) {
574
+ const map = table.axes[logical];
575
+ const raw = snapshot.axes[map ? map.index : logical] ?? 0;
576
+ axes[logical] = map ? raw * map.scale * (map.invert ? -1 : 1) : raw;
559
577
  }
560
- return {
561
- id: snapshot.id,
562
- index: snapshot.index,
563
- timestamp: snapshot.timestamp,
564
- buttons,
565
- axes
566
- };
578
+ out.id = snapshot.id;
579
+ out.index = snapshot.index;
580
+ out.timestamp = snapshot.timestamp;
581
+ return out;
567
582
  }
568
583
  /** Persist a remap table under the given key. Throws on invalid table shape. */
569
584
  async function saveRemap(store, key, table) {
@@ -594,6 +609,18 @@ function isRemapTable(value) {
594
609
  return true;
595
610
  }
596
611
  // src/input-manager.ts
612
+ /** Size `scratch` to `table` so the per-poll remap finds every record in place. */
613
+ function sizeRemapScratch(scratch, table) {
614
+ const buttons = scratch.buttons;
615
+ buttons.length = Math.min(buttons.length, table.buttons.length);
616
+ for (let i = buttons.length; i < table.buttons.length; i++) buttons[i] = {
617
+ pressed: false,
618
+ value: 0
619
+ };
620
+ const axes = scratch.axes;
621
+ axes.length = Math.min(axes.length, table.axes.length);
622
+ for (let i = axes.length; i < table.axes.length; i++) axes[i] = 0;
623
+ }
597
624
  /**
598
625
  * InputManager provides a polling-based input model.
599
626
  *
@@ -678,8 +705,26 @@ var InputManager = class {
678
705
  }
679
706
  /** Install a remap table for a specific gamepad index. Pass `null` to clear. */
680
707
  setGamepadRemap(index, table) {
681
- if (table === null) this._gamepadRemaps.delete(index);
682
- else this._gamepadRemaps.set(index, table);
708
+ if (table === null) {
709
+ this._gamepadRemaps.delete(index);
710
+ return;
711
+ }
712
+ let slot = this._gamepadRemaps.get(index);
713
+ if (slot) slot.table = table;
714
+ else {
715
+ slot = {
716
+ table,
717
+ scratch: {
718
+ id: "",
719
+ index,
720
+ timestamp: 0,
721
+ buttons: [],
722
+ axes: []
723
+ }
724
+ };
725
+ this._gamepadRemaps.set(index, slot);
726
+ }
727
+ sizeRemapScratch(slot.scratch, table);
683
728
  }
684
729
  /** Poll all gamepads from the given source, applying remap + dead zones. */
685
730
  pollGamepads(source) {
@@ -687,7 +732,8 @@ var InputManager = class {
687
732
  for (let i = 0; i < snapshots.length; i++) {
688
733
  const pad = this.gamepad(i);
689
734
  const snap = snapshots[i] ?? null;
690
- updateGamepadFromSnapshot(pad, snap !== null ? this._gamepadRemaps.get(i) ? applyRemap(snap, this._gamepadRemaps.get(i)) : snap : null, this._gamepadDeadZone);
735
+ const slot = snap !== null ? this._gamepadRemaps.get(i) : void 0;
736
+ updateGamepadFromSnapshot(pad, snap !== null && slot ? applyRemapInto(snap, slot.table, slot.scratch) : snap, this._gamepadDeadZone);
691
737
  }
692
738
  }
693
739
  _addOrUpdateTouch(id, x, y, isDown) {
@@ -798,6 +844,6 @@ function releaseJoystick(state) {
798
844
  state.offset.x = 0;
799
845
  state.offset.y = 0;
800
846
  }
801
- export { GamepadAxis, GamepadButton, GestureDetector, InputManager, applyRemap, attachKeyboardListeners, createButtonState, createGamepadState, createIdentityRemap, createJoystickState, createKeyboard, createPointer, createWebGamepadSource, getAxis, isActionDown, isButtonDown, loadRemap, pointerDown, pointerMove, pointerUp, pressButton, releaseButton, releaseJoystick, resetButtonFrame, resetGamepadFrame, resetPointerFrame, saveRemap, updateGamepadFromSnapshot, updateJoystick, wasActionPressed, wasActionReleased, wasButtonPressed, wasButtonReleased };
847
+ export { GamepadAxis, GamepadButton, GestureDetector, InputManager, applyRemap, applyRemapInto, attachKeyboardListeners, createButtonState, createGamepadState, createIdentityRemap, createJoystickState, createKeyboard, createPointer, createWebGamepadSource, getAxis, isActionDown, isButtonDown, loadRemap, pointerDown, pointerMove, pointerUp, pressButton, releaseButton, releaseJoystick, resetButtonFrame, resetGamepadFrame, resetPointerFrame, saveRemap, updateGamepadFromSnapshot, updateJoystick, wasActionPressed, wasActionReleased, wasButtonPressed, wasButtonReleased };
802
848
 
803
849
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["G"],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/virtual-button.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-joystick.ts"],"sourcesContent":["/**\n * Gamepad — poll-based state for a single connected controller.\n *\n * Buttons and axes are indexed against the W3C \"Standard Gamepad\" mapping by\n * default. Callers can translate raw indices via `remap.ts` before feeding\n * snapshots into `updateGamepadFromSnapshot`.\n */\n\n/**\n * Dev-flag access for the dead-zone guard, which runs per axis per frame. Read\n * as a `globalThis` property rather than a bare `__DEV__` identifier for the\n * reason measured in PERF-10 (~0.46 ns vs ~270 ns on JSC).\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad dead zone repeats every frame. */\nlet _warnedDeadZone = false;\n\n/** Largest dead zone that still leaves the rescale well-defined. */\nconst MAX_DEAD_ZONE = 0.99;\n\n/** W3C Standard Gamepad button indices. */\nexport const GamepadButton = {\n A: 0,\n B: 1,\n X: 2,\n Y: 3,\n LB: 4,\n RB: 5,\n LT: 6,\n RT: 7,\n Back: 8,\n Start: 9,\n LS: 10,\n RS: 11,\n DpadUp: 12,\n DpadDown: 13,\n DpadLeft: 14,\n DpadRight: 15,\n Home: 16,\n} as const;\nexport type GamepadButtonId = (typeof GamepadButton)[keyof typeof GamepadButton];\n\n/** W3C Standard Gamepad axes. */\nexport const GamepadAxis = {\n LeftX: 0,\n LeftY: 1,\n RightX: 2,\n RightY: 3,\n} as const;\nexport type GamepadAxisId = (typeof GamepadAxis)[keyof typeof GamepadAxis];\n\nexport interface GamepadButtonState {\n pressed: boolean;\n value: number;\n /** True for exactly one frame after a press. */\n justPressed: boolean;\n /** True for exactly one frame after a release. */\n justReleased: boolean;\n}\n\nexport interface GamepadState {\n connected: boolean;\n id: string;\n index: number;\n buttons: GamepadButtonState[];\n axes: number[];\n /** Monotonically increasing timestamp from the source (ms). */\n timestamp: number;\n}\n\n/** Raw snapshot from a `GamepadSource` — values only, no derived state. */\nexport interface GamepadSnapshot {\n id: string;\n index: number;\n buttons: { pressed: boolean; value: number }[];\n axes: number[];\n timestamp: number;\n}\n\nexport function createGamepadState(index = 0, buttonCount = 17, axisCount = 4): GamepadState {\n const buttons: GamepadButtonState[] = new Array(buttonCount);\n for (let i = 0; i < buttonCount; i++) {\n buttons[i] = { pressed: false, value: 0, justPressed: false, justReleased: false };\n }\n const axes = new Array<number>(axisCount).fill(0);\n return { connected: false, id: '', index, buttons, axes, timestamp: 0 };\n}\n\nfunction applyDeadZone(value: number, deadZone: number): number {\n // The documented contract is [0, 1). At exactly 1 the rescale below divides by\n // zero and returns ±Infinity for any out-of-range axis, which then propagates\n // into every consumer reading the stick. Correct rather than propagate.\n let dz = deadZone;\n if (!(dz >= 0 && dz < 1)) {\n if (G.__DEV__ && !_warnedDeadZone) {\n _warnedDeadZone = true;\n console.warn(\n `[flare-engine/input] deadZone=${deadZone} is outside [0, 1); clamping. ` +\n 'Values at or above 1 would suppress the axis entirely.',\n );\n }\n dz = dz >= 1 ? MAX_DEAD_ZONE : 0;\n }\n const abs = Math.abs(value);\n // `!(abs > dz)` rather than `abs <= dz` so a non-finite axis returns 0 instead\n // of falling through to produce NaN.\n if (!(abs > dz)) return 0;\n const sign = value < 0 ? -1 : 1;\n // Rescale [deadZone, 1] -> [0, 1] so inputs remain smooth past the dead zone.\n return sign * ((abs - dz) / (1 - dz));\n}\n\n/**\n * Apply a fresh snapshot to an existing `GamepadState` in place. Derived\n * `justPressed` / `justReleased` flags are recomputed from the\n * previous `pressed` value.\n *\n * `deadZone` in [0, 1). Values at or below are treated as 0.\n */\nexport function updateGamepadFromSnapshot(\n state: GamepadState,\n snapshot: GamepadSnapshot | null,\n deadZone = 0,\n): void {\n if (snapshot === null) {\n if (!state.connected && !anyButtonDown(state)) {\n clearFrameFlags(state);\n return;\n }\n // Disconnect: clear edge flags, keep sticky pressed=false for released-edge.\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n for (let i = 0; i < state.axes.length; i++) state.axes[i] = 0;\n state.connected = false;\n state.id = '';\n return;\n }\n\n state.connected = true;\n state.id = snapshot.id;\n state.index = snapshot.index;\n state.timestamp = snapshot.timestamp;\n\n const srcButtons = snapshot.buttons;\n const bLen = Math.min(state.buttons.length, srcButtons.length);\n for (let i = 0; i < bLen; i++) {\n const prev = state.buttons[i];\n const src = srcButtons[i];\n if (!prev || !src) continue;\n const wasDown = prev.pressed;\n prev.pressed = src.pressed;\n prev.value = src.value;\n prev.justPressed = src.pressed && !wasDown;\n prev.justReleased = !src.pressed && wasDown;\n }\n // Buttons beyond the snapshot length: clear edges, keep prior pressed false.\n for (let i = bLen; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n\n const aLen = Math.min(state.axes.length, snapshot.axes.length);\n for (let i = 0; i < aLen; i++) {\n state.axes[i] = applyDeadZone(snapshot.axes[i] ?? 0, deadZone);\n }\n for (let i = aLen; i < state.axes.length; i++) state.axes[i] = 0;\n}\n\n/** Reset just the per-frame edge flags. Call when advancing a frame without a fresh snapshot. */\nexport function resetGamepadFrame(state: GamepadState): void {\n clearFrameFlags(state);\n}\n\nfunction clearFrameFlags(state: GamepadState): void {\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = false;\n }\n}\n\nfunction anyButtonDown(state: GamepadState): boolean {\n for (let i = 0; i < state.buttons.length; i++) {\n if (state.buttons[i]?.pressed) return true;\n }\n return false;\n}\n\nexport function isButtonDown(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.pressed ?? false;\n}\n\nexport function wasButtonPressed(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justPressed ?? false;\n}\n\nexport function wasButtonReleased(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justReleased ?? false;\n}\n\nexport function getAxis(state: GamepadState, axis: number): number {\n return state.axes[axis] ?? 0;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Platform abstraction for sampling connected gamepads.\n *\n * `poll()` returns one snapshot per slot (typically up to 4). Unconnected\n * slots return `null`. Implementations:\n *\n * - `createWebGamepadSource()` wraps the W3C `navigator.getGamepads` API.\n * - Native implementations (e.g., `react-native-gamepad`) inject their own\n * via the `GamepadSource` interface — the package itself ships no native deps.\n *\n * **Freshness contract:** each call returns fresh objects. An implementation\n * must not reuse or mutate a snapshot (or its `buttons`/`axes` arrays) that a\n * previous `poll()` call returned. A caller may therefore retain a returned\n * snapshot across frames without it changing out from under them.\n */\nexport interface GamepadSource {\n poll(): (GamepadSnapshot | null)[];\n}\n\nexport interface NavigatorLike {\n getGamepads?: () => (WebGamepad | null)[];\n}\n\nexport interface WebGamepad {\n id: string;\n index: number;\n connected: boolean;\n timestamp: number;\n buttons: readonly { pressed: boolean; value: number }[];\n axes: readonly number[];\n}\n\n/**\n * Wrap `navigator.getGamepads()` (W3C Gamepad API). If `nav` is not supplied,\n * uses `globalThis.navigator`. Returns an empty array when the API is absent.\n */\nexport function createWebGamepadSource(nav?: NavigatorLike): GamepadSource {\n const source: NavigatorLike | undefined =\n nav ??\n (typeof globalThis === 'undefined'\n ? undefined\n : (globalThis as { navigator?: NavigatorLike }).navigator);\n\n return {\n poll(): (GamepadSnapshot | null)[] {\n if (!source?.getGamepads) return [];\n const pads = source.getGamepads();\n const out: (GamepadSnapshot | null)[] = new Array(pads.length);\n for (let i = 0; i < pads.length; i++) {\n const p = pads[i];\n if (!p?.connected) {\n out[i] = null;\n continue;\n }\n out[i] = webGamepadToSnapshot(p);\n }\n return out;\n },\n };\n}\n\nfunction webGamepadToSnapshot(p: WebGamepad): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(p.buttons.length);\n for (let i = 0; i < p.buttons.length; i++) {\n const b = p.buttons[i];\n buttons[i] = { pressed: b?.pressed ?? false, value: b?.value ?? 0 };\n }\n const axes = new Array<number>(p.axes.length);\n for (let i = 0; i < p.axes.length; i++) axes[i] = p.axes[i] ?? 0;\n return { id: p.id, index: p.index, timestamp: p.timestamp, buttons, axes };\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Vec2 } from '@flare-engine/math';\n\n/** Swipe direction. */\nexport type SwipeDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Gesture detection configuration. */\nexport interface GestureConfig {\n /** Max time (seconds) for a tap (default 0.3). */\n tapMaxDuration?: number;\n /** Max distance (px) for a tap (default 20). */\n tapMaxDistance?: number;\n /** Min time (seconds) for a long press (default 0.5). */\n longPressMinDuration?: number;\n /** Min distance (px) for a swipe (default 50). */\n swipeMinDistance?: number;\n /** Max time (seconds) for a swipe (default 0.4). */\n swipeMaxDuration?: number;\n}\n\n/** Swipe event data. */\nexport interface SwipeEvent {\n direction: SwipeDirection;\n distance: number;\n duration: number;\n}\n\n/** Pinch event data. */\nexport interface PinchEvent {\n /** Scale factor (>1 = spread, <1 = pinch). */\n scale: number;\n /** Center point between the two touches. */\n center: Vec2;\n}\n\nconst DEFAULT_TAP_MAX_DURATION = 0.3;\nconst DEFAULT_TAP_MAX_DISTANCE = 20;\nconst DEFAULT_LONG_PRESS_MIN_DURATION = 0.5;\nconst DEFAULT_SWIPE_MIN_DISTANCE = 50;\nconst DEFAULT_SWIPE_MAX_DURATION = 0.4;\n\n/**\n * GestureDetector recognizes tap, long press, swipe, and pinch gestures\n * from raw pointer events.\n */\nexport class GestureDetector {\n readonly onTap = new Signal<Vec2>();\n readonly onLongPress = new Signal<Vec2>();\n readonly onSwipe = new Signal<SwipeEvent>();\n readonly onPinch = new Signal<PinchEvent>();\n\n private tapMaxDuration: number;\n private tapMaxDistance: number;\n private longPressMinDuration: number;\n private swipeMinDistance: number;\n private swipeMaxDuration: number;\n\n // Single-touch tracking\n private _startPos: Vec2 = { x: 0, y: 0 };\n /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */\n private _elapsed = 0;\n private _isTracking = false;\n private _longPressFired = false;\n\n // Pinch tracking\n private _pinchStartDistance = 0;\n private _pinchTouches: [Vec2, Vec2] | null = null;\n\n constructor(config?: GestureConfig) {\n this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;\n this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;\n this.longPressMinDuration = config?.longPressMinDuration ?? DEFAULT_LONG_PRESS_MIN_DURATION;\n this.swipeMinDistance = config?.swipeMinDistance ?? DEFAULT_SWIPE_MIN_DISTANCE;\n this.swipeMaxDuration = config?.swipeMaxDuration ?? DEFAULT_SWIPE_MAX_DURATION;\n }\n\n /** Feed a pointer-down event. */\n pointerDown(x: number, y: number): void {\n this._startPos = { x, y };\n this._elapsed = 0;\n this._isTracking = true;\n this._longPressFired = false;\n }\n\n /**\n * Feed a pointer-up event.\n *\n * `elapsedSinceDown` is optional: pass it when the host tracks its own\n * timestamps (e.g. event-driven, no per-frame `update()` calls); omit it\n * to use the elapsed time already accumulated via `update(dt, ...)`. Either\n * way there is one clock per press — passing it here re-syncs the same\n * accumulator `update()` advances, rather than racing it. If a long press\n * already fired for this press, tap/swipe are suppressed so one press\n * yields exactly one gesture.\n */\n pointerUp(x: number, y: number, elapsedSinceDown?: number): void {\n if (!this._isTracking) return;\n this._isTracking = false;\n if (elapsedSinceDown !== undefined) this._elapsed = elapsedSinceDown;\n if (this._longPressFired) return;\n\n const dx = x - this._startPos.x;\n const dy = y - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n const duration = this._elapsed;\n\n // Check swipe first (requires min distance)\n if (dist >= this.swipeMinDistance && duration <= this.swipeMaxDuration) {\n const absDx = Math.abs(dx);\n const absDy = Math.abs(dy);\n let direction: SwipeDirection;\n if (absDx > absDy) {\n direction = dx > 0 ? 'right' : 'left';\n } else {\n direction = dy > 0 ? 'down' : 'up';\n }\n this.onSwipe.emit({ direction, distance: dist, duration });\n return;\n }\n\n // Check tap (short press, small movement)\n if (dist <= this.tapMaxDistance && duration <= this.tapMaxDuration) {\n this.onTap.emit({ x, y });\n return;\n }\n }\n\n /**\n * Update gesture tracking. Call each frame with dt.\n * @param dt Delta time in seconds.\n * @param currentX Current pointer X.\n * @param currentY Current pointer Y.\n */\n update(dt: number, currentX: number, currentY: number): void {\n if (!this._isTracking) return;\n this._elapsed += dt;\n\n // Long press detection\n if (!this._longPressFired && this._elapsed >= this.longPressMinDuration) {\n const dx = currentX - this._startPos.x;\n const dy = currentY - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n if (dist <= this.tapMaxDistance) {\n this._longPressFired = true;\n this.onLongPress.emit({ x: currentX, y: currentY });\n }\n }\n }\n\n /**\n * Feed a two-finger pinch update. Call when two touches are active.\n * @param t1 First touch position.\n * @param t2 Second touch position.\n */\n pinchUpdate(t1: Vec2, t2: Vec2): void {\n const dx = t2.x - t1.x;\n const dy = t2.y - t1.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (this._pinchTouches === null) {\n // Start pinch\n this._pinchStartDistance = dist;\n this._pinchTouches = [{ ...t1 }, { ...t2 }];\n return;\n }\n\n if (this._pinchStartDistance > 0) {\n const scale = dist / this._pinchStartDistance;\n const center: Vec2 = {\n x: (t1.x + t2.x) / 2,\n y: (t1.y + t2.y) / 2,\n };\n this.onPinch.emit({ scale, center });\n }\n }\n\n /** Call when pinch ends (fewer than 2 touches). */\n pinchEnd(): void {\n this._pinchTouches = null;\n this._pinchStartDistance = 0;\n }\n}\n","/** Virtual button state — pure data, no UI. */\nexport interface VirtualButtonState {\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n /** Whether the button was just pressed this frame. */\n justPressed: boolean;\n /** Whether the button was just released this frame. */\n justReleased: boolean;\n}\n\n/** Create a default button state. */\nexport function createButtonState(): VirtualButtonState {\n return {\n isPressed: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/** Call at the start of each frame to reset per-frame flags. */\nexport function resetButtonFrame(state: VirtualButtonState): void {\n state.justPressed = false;\n state.justReleased = false;\n}\n\n/** Call when the button is pressed. */\nexport function pressButton(state: VirtualButtonState): void {\n if (!state.isPressed) {\n state.isPressed = true;\n state.justPressed = true;\n }\n}\n\n/** Call when the button is released. */\nexport function releaseButton(state: VirtualButtonState): void {\n if (state.isPressed) {\n state.isPressed = false;\n state.justReleased = true;\n }\n}\n","import {\n createButtonState,\n pressButton,\n releaseButton,\n resetButtonFrame,\n type VirtualButtonState,\n} from './virtual-button.js';\n\n/** Minimal keyboard event shape — no DOM type dep. */\nexport interface KeyboardEventLike {\n readonly code: string;\n readonly type: string;\n /** Optional — real DOM events have it; synthetic feeds may not. */\n preventDefault?(): void;\n}\n\n/** Minimal event target shape for attaching keyboard listeners. */\nexport interface KeyboardEventTargetLike {\n addEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n removeEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n}\n\n/**\n * Buffered per-frame keyboard state.\n *\n * Edge flags (`wasPressed`, `wasReleased`) clear each frame via `reset()`.\n * `keyDown` / `keyUp` are the platform-neutral injection points: web feeds\n * them via `attachKeyboardListeners`; mobile/RN feeds them from a\n * hardware-keyboard native module or an on-screen source.\n */\nexport interface KeyboardState {\n /** True while the key is physically held. */\n isDown(code: string): boolean;\n /** True only on the frame the key was pressed. */\n wasPressed(code: string): boolean;\n /** True only on the frame the key was released. */\n wasReleased(code: string): boolean;\n /** Platform-neutral injection. OS auto-repeat is de-edged by the pressButton guard. */\n keyDown(code: string): void;\n /** Platform-neutral injection. */\n keyUp(code: string): void;\n /** Frame-start edge clear. Zero-alloc. */\n reset(): void;\n /** Blur/stuck-key guard: emits a release edge for every held code, then drops held. */\n clear(): void;\n}\n\n/** Create a fresh keyboard state. */\nexport function createKeyboard(): KeyboardState {\n const states: VirtualButtonState[] = [];\n const codeIndex = new Map<string, number>();\n\n return {\n isDown(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.isPressed ?? false;\n },\n\n wasPressed(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justPressed ?? false;\n },\n\n wasReleased(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justReleased ?? false;\n },\n\n keyDown(code: string): void {\n let i = codeIndex.get(code);\n if (i === undefined) {\n i = states.length;\n states.push(createButtonState());\n codeIndex.set(code, i);\n }\n pressButton(states[i]!);\n },\n\n keyUp(code: string): void {\n const i = codeIndex.get(code);\n if (i === undefined) return;\n releaseButton(states[i]!);\n },\n\n reset(): void {\n for (let i = 0; i < states.length; i++) {\n resetButtonFrame(states[i]!);\n }\n },\n\n clear(): void {\n for (let i = 0; i < states.length; i++) {\n releaseButton(states[i]!);\n }\n },\n };\n}\n\n/**\n * Web turnkey adapter: registers `keydown`, `keyup`, and `blur` listeners on\n * `target`. `blur` calls `kb.clear()` (stuck-key guard). Returns a detach fn.\n *\n * `target` is structural `{ addEventListener, removeEventListener }` — no DOM\n * types dep. On web, pass `window`; for mobile/RN, feed `keyDown`/`keyUp`\n * directly from a hardware-keyboard native module or an on-screen source.\n *\n * Does NOT call `preventDefault` — bare use lets Space/arrows scroll and Tab\n * move DOM focus. For game-mode input, attach your own listener that calls\n * `preventDefault` for game keys and forwards `kb.keyDown(ev.code)`.\n */\nexport function attachKeyboardListeners(\n kb: KeyboardState,\n target: KeyboardEventTargetLike,\n): () => void {\n const onKeyDown = (ev: KeyboardEventLike): void => {\n kb.keyDown(ev.code);\n };\n const onKeyUp = (ev: KeyboardEventLike): void => {\n kb.keyUp(ev.code);\n };\n const onBlur = (_ev: KeyboardEventLike): void => {\n kb.clear();\n };\n\n target.addEventListener('keydown', onKeyDown);\n target.addEventListener('keyup', onKeyUp);\n target.addEventListener('blur', onBlur);\n\n return (): void => {\n target.removeEventListener('keydown', onKeyDown);\n target.removeEventListener('keyup', onKeyUp);\n target.removeEventListener('blur', onBlur);\n };\n}\n\n/**\n * Action → code binding map. Keys are action names; values are arrays of\n * `KeyboardEvent.code` strings. Multiple codes OR-reduce (any bound key\n * triggers the action).\n */\nexport type KeyBindings = Readonly<Record<string, readonly string[]>>;\n\n/** True if any bound code for `action` is currently held. */\nexport function isActionDown(kb: KeyboardState, bindings: KeyBindings, action: string): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return true;\n }\n return false;\n}\n\n/** True if any bound code for `action` was pressed this frame. */\nexport function wasActionPressed(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.wasPressed(codes[i]!)) return true;\n }\n return false;\n}\n\n/**\n * True if any bound code for `action` was released this frame AND no bound\n * code is still held. Release fires only when the last held bound key lifts.\n */\nexport function wasActionReleased(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n let anyReleased = false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return false;\n if (kb.wasReleased(codes[i]!)) anyReleased = true;\n }\n return anyReleased;\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/** State of a single pointer (primary touch or mouse). */\nexport interface Pointer {\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Position delta since last frame. */\n delta: Vec2;\n /** Whether the pointer is currently held down. */\n isDown: boolean;\n /** True only on the frame the pointer was pressed. */\n justPressed: boolean;\n /** True only on the frame the pointer was released. */\n justReleased: boolean;\n}\n\n/** State of a single touch point in a multitouch scenario. */\nexport interface TouchPoint {\n /** Unique touch identifier. */\n id: number;\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Whether this touch is currently active. */\n isDown: boolean;\n}\n\n/** Create a default pointer state. */\nexport function createPointer(): Pointer {\n return {\n position: { x: 0, y: 0 },\n delta: { x: 0, y: 0 },\n isDown: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/**\n * Update pointer state for a new frame.\n * Call this at the start of each frame to clear per-frame flags.\n */\nexport function resetPointerFrame(pointer: Pointer): void {\n pointer.delta.x = 0;\n pointer.delta.y = 0;\n pointer.justPressed = false;\n pointer.justReleased = false;\n}\n\n/** Feed a pointer-down event into the pointer state. */\nexport function pointerDown(pointer: Pointer, x: number, y: number): void {\n const wasDown = pointer.isDown;\n pointer.isDown = true;\n if (!wasDown) {\n pointer.justPressed = true;\n }\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-move event into the pointer state. */\nexport function pointerMove(pointer: Pointer, x: number, y: number): void {\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-up event into the pointer state. */\nexport function pointerUp(pointer: Pointer, x: number, y: number): void {\n pointer.isDown = false;\n pointer.justReleased = true;\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Button / axis remap table.\n *\n * `buttons[logicalId] = physicalIndex` — to poll A, read\n * `snapshot.buttons[table.buttons[GamepadButton.A]]`.\n *\n * `axes` maps logical axis id → `{ index, invert, scale }`. Most games invert\n * Y on some controllers; `scale` supports half-range triggers.\n */\nexport interface AxisMap {\n index: number;\n invert: boolean;\n scale: number;\n}\n\nexport interface RemapTable {\n buttons: number[];\n axes: AxisMap[];\n}\n\nexport function createIdentityRemap(buttonCount = 17, axisCount = 4): RemapTable {\n const buttons = new Array<number>(buttonCount);\n for (let i = 0; i < buttonCount; i++) buttons[i] = i;\n const axes = new Array<AxisMap>(axisCount);\n for (let i = 0; i < axisCount; i++) axes[i] = { index: i, invert: false, scale: 1 };\n return { buttons, axes };\n}\n\n/** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */\nexport function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(table.buttons.length);\n for (let logical = 0; logical < table.buttons.length; logical++) {\n const physical = table.buttons[logical] ?? logical;\n const src = snapshot.buttons[physical];\n buttons[logical] = { pressed: src?.pressed ?? false, value: src?.value ?? 0 };\n }\n const axes = new Array<number>(table.axes.length);\n for (let logical = 0; logical < table.axes.length; logical++) {\n const map = table.axes[logical] ?? { index: logical, invert: false, scale: 1 };\n const raw = snapshot.axes[map.index] ?? 0;\n axes[logical] = raw * map.scale * (map.invert ? -1 : 1);\n }\n return { id: snapshot.id, index: snapshot.index, timestamp: snapshot.timestamp, buttons, axes };\n}\n\n/**\n * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,\n * but declared locally so this package does not take a hard dep on storage.\n */\nexport interface RemapStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n}\n\n/** Persist a remap table under the given key. Throws on invalid table shape. */\nexport async function saveRemap(store: RemapStore, key: string, table: RemapTable): Promise<void> {\n await store.set(key, JSON.stringify(table));\n}\n\n/** Load a remap table. Returns `null` if absent or malformed. */\nexport async function loadRemap(store: RemapStore, key: string): Promise<RemapTable | null> {\n const raw = await store.get(key);\n if (raw === null) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (!isRemapTable(parsed)) return null;\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isRemapTable(value: unknown): value is RemapTable {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as { buttons?: unknown; axes?: unknown };\n if (!Array.isArray(obj.buttons) || !Array.isArray(obj.axes)) return false;\n for (const b of obj.buttons) if (typeof b !== 'number') return false;\n for (const a of obj.axes) {\n if (typeof a !== 'object' || a === null) return false;\n const ax = a as { index?: unknown; invert?: unknown; scale?: unknown };\n if (\n typeof ax.index !== 'number' ||\n typeof ax.invert !== 'boolean' ||\n typeof ax.scale !== 'number'\n ) {\n return false;\n }\n }\n return true;\n}\n","import {\n createGamepadState,\n type GamepadState,\n resetGamepadFrame,\n updateGamepadFromSnapshot,\n} from './gamepad.js';\nimport type { GamepadSource } from './gamepad-source.js';\nimport { createKeyboard, type KeyboardState } from './keyboard.js';\nimport {\n createPointer,\n type Pointer,\n pointerDown,\n pointerMove,\n pointerUp,\n resetPointerFrame,\n type TouchPoint,\n} from './pointer.js';\nimport type { RemapTable } from './remap.js';\nimport { applyRemap } from './remap.js';\n\n/**\n * InputManager provides a polling-based input model.\n *\n * Call `update()` once per frame (before game logic) to snapshot input state.\n * Feed events from the platform (RN touch/gesture handlers) via the on* methods.\n */\nexport class InputManager {\n /**\n * Primary pointer — the touch that started the current gesture (first\n * `onPointerDown` while no touch was active), or the mouse.\n *\n * Once assigned, the primary id stays fixed to that touch until it lifts;\n * it does NOT transfer to a remaining finger. While a second finger is\n * down, its events reach only `touches` — `pointer` neither moves nor\n * releases because of it. When the primary lifts, `pointer.isDown` goes\n * false even if other fingers remain down, and a new primary is assigned\n * only once every touch has lifted and a fresh `onPointerDown` arrives.\n * This keeps `pointer` a single continuous stream with no mid-gesture\n * teleport; read `touches` for anything beyond one finger.\n */\n readonly pointer: Pointer = createPointer();\n\n /** Buffered keyboard state. Feed via `attachKeyboardListeners` (web) or `keyboard.keyDown`/`keyUp` (mobile/RN). */\n readonly keyboard: KeyboardState = createKeyboard();\n\n /** All active touch points. */\n readonly touches: TouchPoint[] = [];\n\n private _touchMap = new Map<number, TouchPoint>();\n private _primaryTouchId: number | null = null;\n private _gamepads: GamepadState[] = [];\n private _gamepadDeadZone = 0.15;\n private _gamepadRemaps = new Map<number, RemapTable>();\n\n /** Call once per frame to reset per-frame flags. */\n update(): void {\n resetPointerFrame(this.pointer);\n this.keyboard.reset();\n for (let i = 0; i < this._gamepads.length; i++) {\n const pad = this._gamepads[i];\n if (pad) resetGamepadFrame(pad);\n }\n }\n\n /** Feed a touch/pointer begin event. */\n onPointerDown(id: number, x: number, y: number): void {\n if (this._touchMap.size === 0) {\n this._primaryTouchId = id;\n }\n if (id === this._primaryTouchId) {\n pointerDown(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /**\n * Feed a touch/pointer move event.\n *\n * A move for an id that was never pressed, while no primary is active, is a\n * hover (a mouse with no button held): `pointer.position` and `delta`\n * follow it, but `isDown` / `justPressed` stay untouched and no `TouchPoint`\n * is recorded.\n */\n onPointerMove(id: number, x: number, y: number): void {\n if (this._primaryTouchId === null && !this._touchMap.has(id)) {\n pointerMove(this.pointer, x, y);\n return;\n }\n if (id === this._primaryTouchId) {\n pointerMove(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /** Feed a touch/pointer end event. */\n onPointerUp(id: number, x: number, y: number): void {\n if (id === this._primaryTouchId) {\n pointerUp(this.pointer, x, y);\n this._primaryTouchId = null;\n }\n this._removeTouch(id);\n }\n\n /** Access the gamepad state at `index`. Allocates on first access. */\n gamepad(index: number): GamepadState {\n let pad = this._gamepads[index];\n if (!pad) {\n pad = createGamepadState(index);\n this._gamepads[index] = pad;\n }\n return pad;\n }\n\n /** Dead zone in [0, 1). Axes at or below this magnitude read as 0. */\n setGamepadDeadZone(deadZone: number): void {\n this._gamepadDeadZone = Math.max(0, Math.min(0.95, deadZone));\n }\n\n /** Install a remap table for a specific gamepad index. Pass `null` to clear. */\n setGamepadRemap(index: number, table: RemapTable | null): void {\n if (table === null) this._gamepadRemaps.delete(index);\n else this._gamepadRemaps.set(index, table);\n }\n\n /** Poll all gamepads from the given source, applying remap + dead zones. */\n pollGamepads(source: GamepadSource): void {\n const snapshots = source.poll();\n for (let i = 0; i < snapshots.length; i++) {\n const pad = this.gamepad(i);\n const snap = snapshots[i] ?? null;\n const remapped =\n snap !== null\n ? this._gamepadRemaps.get(i)\n ? applyRemap(snap, this._gamepadRemaps.get(i) as RemapTable)\n : snap\n : null;\n updateGamepadFromSnapshot(pad, remapped, this._gamepadDeadZone);\n }\n }\n\n private _addOrUpdateTouch(id: number, x: number, y: number, isDown: boolean): void {\n let touch = this._touchMap.get(id);\n if (!touch) {\n touch = { id, position: { x, y }, isDown };\n this._touchMap.set(id, touch);\n this.touches.push(touch);\n } else {\n touch.position.x = x;\n touch.position.y = y;\n touch.isDown = isDown;\n }\n }\n\n private _removeTouch(id: number): void {\n const touch = this._touchMap.get(id);\n if (!touch) return;\n this._touchMap.delete(id);\n const idx = this.touches.indexOf(touch);\n if (idx !== -1) {\n this.touches.splice(idx, 1);\n }\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Dev-flag access for the config guard in `updateJoystick`, which runs once per\n * frame while a stick is held. Read as a `globalThis` property, not as a bare\n * `__DEV__` identifier: on JSC an unresolvable global costs ~270 ns per\n * evaluation where a property miss is inline-cached at ~0.46 ns. Same reasoning\n * as `@flare-engine/core`'s `Pool` — see PERF-10.\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad config repeats every frame. */\nlet _warnedConfig = false;\n\n/** Virtual joystick configuration. */\nexport interface VirtualJoystickConfig {\n /** Dead zone radius in pixels (default 10). */\n deadZone?: number;\n /** Maximum radius in pixels (default 50). */\n maxRadius?: number;\n}\n\n/** Virtual joystick state — pure data, no UI. */\nexport interface VirtualJoystickState {\n /** Whether the joystick is currently being touched. */\n active: boolean;\n /** Normalized direction vector (-1 to 1 per axis). */\n direction: Vec2;\n /** Magnitude 0-1 (0 = center/dead zone, 1 = max radius). */\n magnitude: number;\n /** Raw offset from center in pixels. */\n offset: Vec2;\n}\n\nconst DEFAULT_DEAD_ZONE = 10;\nconst DEFAULT_MAX_RADIUS = 50;\n\n/** Create a default joystick state. */\nexport function createJoystickState(): VirtualJoystickState {\n return {\n active: false,\n direction: { x: 0, y: 0 },\n magnitude: 0,\n offset: { x: 0, y: 0 },\n };\n}\n\n/**\n * Update joystick state from a touch event.\n *\n * @param state The joystick state to update.\n * @param centerX The joystick center X in screen pixels.\n * @param centerY The joystick center Y in screen pixels.\n * @param touchX The current touch X in screen pixels.\n * @param touchY The current touch Y in screen pixels.\n * @param config Joystick configuration.\n */\nexport function updateJoystick(\n state: VirtualJoystickState,\n centerX: number,\n centerY: number,\n touchX: number,\n touchY: number,\n config?: VirtualJoystickConfig,\n): void {\n let deadZone = config?.deadZone ?? DEFAULT_DEAD_ZONE;\n let maxRadius = config?.maxRadius ?? DEFAULT_MAX_RADIUS;\n\n // Out-of-contract config is corrected rather than propagated. Left alone, a\n // NaN deadZone defeats the early return below and a maxRadius equal to\n // deadZone divides by zero at `normalizedDist` — either way `state.direction`\n // becomes NaN and, because the state is reused across frames, the stick never\n // recovers. The whole check sits behind one comparison on the healthy path.\n if (!(deadZone >= 0 && maxRadius > deadZone)) {\n if (G.__DEV__ && !_warnedConfig) {\n _warnedConfig = true;\n console.warn(\n `[flare-engine/input] updateJoystick: invalid config (deadZone=${deadZone}, maxRadius=${maxRadius}); ` +\n 'expected 0 <= deadZone < maxRadius. Falling back to defaults for this call.',\n );\n }\n if (!(deadZone >= 0)) deadZone = DEFAULT_DEAD_ZONE;\n if (!(maxRadius > deadZone)) maxRadius = deadZone + DEFAULT_MAX_RADIUS;\n }\n\n const dx = touchX - centerX;\n const dy = touchY - centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n state.active = true;\n\n // `!(dist >= deadZone)` rather than `dist < deadZone` so a non-finite touch\n // coordinate takes the centred branch instead of falling through to the maths.\n if (!(dist >= deadZone)) {\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n // dist is non-finite only when a touch coordinate was, in which case dx/dy\n // are too — report a centred offset rather than writing NaN into the state.\n const centred = dist === 0 || !Number.isFinite(dist);\n state.offset.x = centred ? 0 : dx;\n state.offset.y = centred ? 0 : dy;\n return;\n }\n\n // Clamp to max radius\n const clampedDist = Math.min(dist, maxRadius);\n const normalizedDist = (clampedDist - deadZone) / (maxRadius - deadZone);\n\n // Direction is always the full normalized direction. `dist` is > 0 here —\n // a zero distance cannot pass the guard above once deadZone >= 0 — but the\n // reciprocal is guarded anyway, because `deadZone: 0` makes `dist === 0`\n // reachable and `1 / 0` would put Infinity into direction.\n const invDist = dist > 0 ? 1 / dist : 0;\n state.direction.x = dx * invDist;\n state.direction.y = dy * invDist;\n state.magnitude = Math.min(normalizedDist, 1);\n\n // Offset clamped to max radius\n const scale = dist > 0 ? clampedDist / dist : 0;\n state.offset.x = dx * scale;\n state.offset.y = dy * scale;\n}\n\n/** Reset joystick state when touch is released. */\nexport function releaseJoystick(state: VirtualJoystickState): void {\n state.active = false;\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n state.offset.x = 0;\n state.offset.y = 0;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAMA,MAAI;;AAGV,IAAI,kBAAkB;;AAGtB,MAAM,gBAAgB;;AAGtB,MAAa,gBAAgB;CAC3B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,OAAO;CACP,IAAI;CACJ,IAAI;CACJ,QAAQ;CACR,UAAU;CACV,UAAU;CACV,WAAW;CACX,MAAM;AACR;;AAIA,MAAa,cAAc;CACzB,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AA+BA,SAAgB,mBAAmB,QAAQ,GAAG,cAAc,IAAI,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AS;CAC5C,MAAM,kBAAkB,cAAc,aAAa,YAAY;CAM/D,MAAM,UAAU,OAAO,IAAI,IAAI,OAAO;CACtC,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,YAAY,KAAK,IAAI,gBAAgB,CAAC;CAG5C,MAAM,QAAQ,OAAO,IAAI,cAAc,OAAO;CAC9C,MAAM,OAAO,IAAI,KAAK;CACtB,MAAM,OAAO,IAAI,KAAK;AACxB;;AAGA,SAAgB,gBAAgB,OAAmC;CACjE,MAAM,SAAS;CACf,MAAM,UAAU,IAAI;CACpB,MAAM,UAAU,IAAI;CACpB,MAAM,YAAY;CAClB,MAAM,OAAO,IAAI;CACjB,MAAM,OAAO,IAAI;AACnB"}
1
+ {"version":3,"file":"index.mjs","names":["G"],"sources":["../src/gamepad.ts","../src/gamepad-source.ts","../src/gestures.ts","../src/virtual-button.ts","../src/keyboard.ts","../src/pointer.ts","../src/remap.ts","../src/input-manager.ts","../src/virtual-joystick.ts"],"sourcesContent":["/**\n * Gamepad — poll-based state for a single connected controller.\n *\n * Buttons and axes are indexed against the W3C \"Standard Gamepad\" mapping by\n * default. Callers can translate raw indices via `remap.ts` before feeding\n * snapshots into `updateGamepadFromSnapshot`.\n */\n\n/**\n * Dev-flag access for the dead-zone guard, which runs per axis per frame. Read\n * as a `globalThis` property rather than a bare `__DEV__` identifier for the\n * reason measured in PERF-10 (~0.46 ns vs ~270 ns on JSC).\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad dead zone repeats every frame. */\nlet _warnedDeadZone = false;\n\n/** Largest dead zone that still leaves the rescale well-defined. */\nconst MAX_DEAD_ZONE = 0.99;\n\n/** W3C Standard Gamepad button indices. */\nexport const GamepadButton = {\n A: 0,\n B: 1,\n X: 2,\n Y: 3,\n LB: 4,\n RB: 5,\n LT: 6,\n RT: 7,\n Back: 8,\n Start: 9,\n LS: 10,\n RS: 11,\n DpadUp: 12,\n DpadDown: 13,\n DpadLeft: 14,\n DpadRight: 15,\n Home: 16,\n} as const;\nexport type GamepadButtonId = (typeof GamepadButton)[keyof typeof GamepadButton];\n\n/** W3C Standard Gamepad axes. */\nexport const GamepadAxis = {\n LeftX: 0,\n LeftY: 1,\n RightX: 2,\n RightY: 3,\n} as const;\nexport type GamepadAxisId = (typeof GamepadAxis)[keyof typeof GamepadAxis];\n\nexport interface GamepadButtonState {\n pressed: boolean;\n value: number;\n /** True for exactly one frame after a press. */\n justPressed: boolean;\n /** True for exactly one frame after a release. */\n justReleased: boolean;\n}\n\nexport interface GamepadState {\n connected: boolean;\n id: string;\n index: number;\n buttons: GamepadButtonState[];\n axes: number[];\n /** Monotonically increasing timestamp from the source (ms). */\n timestamp: number;\n}\n\n/** Raw snapshot from a `GamepadSource` — values only, no derived state. */\nexport interface GamepadSnapshot {\n id: string;\n index: number;\n buttons: { pressed: boolean; value: number }[];\n axes: number[];\n timestamp: number;\n}\n\nexport function createGamepadState(index = 0, buttonCount = 17, axisCount = 4): GamepadState {\n const buttons: GamepadButtonState[] = new Array(buttonCount);\n for (let i = 0; i < buttonCount; i++) {\n buttons[i] = { pressed: false, value: 0, justPressed: false, justReleased: false };\n }\n const axes = new Array<number>(axisCount).fill(0);\n return { connected: false, id: '', index, buttons, axes, timestamp: 0 };\n}\n\nfunction applyDeadZone(value: number, deadZone: number): number {\n // The documented contract is [0, 1). At exactly 1 the rescale below divides by\n // zero and returns ±Infinity for any out-of-range axis, which then propagates\n // into every consumer reading the stick. Correct rather than propagate.\n let dz = deadZone;\n if (!(dz >= 0 && dz < 1)) {\n if (G.__DEV__ && !_warnedDeadZone) {\n _warnedDeadZone = true;\n console.warn(\n `[flare-engine/input] deadZone=${deadZone} is outside [0, 1); clamping. ` +\n 'Values at or above 1 would suppress the axis entirely.',\n );\n }\n dz = dz >= 1 ? MAX_DEAD_ZONE : 0;\n }\n const abs = Math.abs(value);\n // `!(abs > dz)` rather than `abs <= dz` so a non-finite axis returns 0 instead\n // of falling through to produce NaN.\n if (!(abs > dz)) return 0;\n const sign = value < 0 ? -1 : 1;\n // Rescale [deadZone, 1] -> [0, 1] so inputs remain smooth past the dead zone.\n return sign * ((abs - dz) / (1 - dz));\n}\n\n/**\n * Apply a fresh snapshot to an existing `GamepadState` in place. Derived\n * `justPressed` / `justReleased` flags are recomputed from the\n * previous `pressed` value.\n *\n * `deadZone` in [0, 1). Values at or below are treated as 0.\n */\nexport function updateGamepadFromSnapshot(\n state: GamepadState,\n snapshot: GamepadSnapshot | null,\n deadZone = 0,\n): void {\n if (snapshot === null) {\n if (!state.connected && !anyButtonDown(state)) {\n clearFrameFlags(state);\n return;\n }\n // Disconnect: clear edge flags, keep sticky pressed=false for released-edge.\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n for (let i = 0; i < state.axes.length; i++) state.axes[i] = 0;\n state.connected = false;\n state.id = '';\n return;\n }\n\n state.connected = true;\n state.id = snapshot.id;\n state.index = snapshot.index;\n state.timestamp = snapshot.timestamp;\n\n const srcButtons = snapshot.buttons;\n const bLen = Math.min(state.buttons.length, srcButtons.length);\n for (let i = 0; i < bLen; i++) {\n const prev = state.buttons[i];\n const src = srcButtons[i];\n if (!prev || !src) continue;\n const wasDown = prev.pressed;\n prev.pressed = src.pressed;\n prev.value = src.value;\n prev.justPressed = src.pressed && !wasDown;\n prev.justReleased = !src.pressed && wasDown;\n }\n // Buttons beyond the snapshot length: clear edges, keep prior pressed false.\n for (let i = bLen; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = b.pressed;\n b.pressed = false;\n b.value = 0;\n }\n\n const aLen = Math.min(state.axes.length, snapshot.axes.length);\n for (let i = 0; i < aLen; i++) {\n state.axes[i] = applyDeadZone(snapshot.axes[i] ?? 0, deadZone);\n }\n for (let i = aLen; i < state.axes.length; i++) state.axes[i] = 0;\n}\n\n/** Reset just the per-frame edge flags. Call when advancing a frame without a fresh snapshot. */\nexport function resetGamepadFrame(state: GamepadState): void {\n clearFrameFlags(state);\n}\n\nfunction clearFrameFlags(state: GamepadState): void {\n for (let i = 0; i < state.buttons.length; i++) {\n const b = state.buttons[i];\n if (!b) continue;\n b.justPressed = false;\n b.justReleased = false;\n }\n}\n\nfunction anyButtonDown(state: GamepadState): boolean {\n for (let i = 0; i < state.buttons.length; i++) {\n if (state.buttons[i]?.pressed) return true;\n }\n return false;\n}\n\nexport function isButtonDown(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.pressed ?? false;\n}\n\nexport function wasButtonPressed(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justPressed ?? false;\n}\n\nexport function wasButtonReleased(state: GamepadState, button: number): boolean {\n return state.buttons[button]?.justReleased ?? false;\n}\n\nexport function getAxis(state: GamepadState, axis: number): number {\n return state.axes[axis] ?? 0;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Platform abstraction for sampling connected gamepads.\n *\n * `poll()` returns one snapshot per slot (typically up to 4). Unconnected\n * slots return `null`. Implementations:\n *\n * - `createWebGamepadSource()` wraps the W3C `navigator.getGamepads` API.\n * - Native implementations (e.g., `react-native-gamepad`) inject their own\n * via the `GamepadSource` interface — the package itself ships no native deps.\n *\n * **Freshness contract:** each call returns fresh objects. An implementation\n * must not reuse or mutate a snapshot (or its `buttons`/`axes` arrays) that a\n * previous `poll()` call returned. A caller may therefore retain a returned\n * snapshot across frames without it changing out from under them.\n */\nexport interface GamepadSource {\n poll(): (GamepadSnapshot | null)[];\n}\n\nexport interface NavigatorLike {\n getGamepads?: () => (WebGamepad | null)[];\n}\n\nexport interface WebGamepad {\n id: string;\n index: number;\n connected: boolean;\n timestamp: number;\n buttons: readonly { pressed: boolean; value: number }[];\n axes: readonly number[];\n}\n\n/**\n * Wrap `navigator.getGamepads()` (W3C Gamepad API). If `nav` is not supplied,\n * uses `globalThis.navigator`. Returns an empty array when the API is absent.\n */\nexport function createWebGamepadSource(nav?: NavigatorLike): GamepadSource {\n const source: NavigatorLike | undefined =\n nav ??\n (typeof globalThis === 'undefined'\n ? undefined\n : (globalThis as { navigator?: NavigatorLike }).navigator);\n\n return {\n poll(): (GamepadSnapshot | null)[] {\n if (!source?.getGamepads) return [];\n const pads = source.getGamepads();\n const out: (GamepadSnapshot | null)[] = new Array(pads.length);\n for (let i = 0; i < pads.length; i++) {\n const p = pads[i];\n if (!p?.connected) {\n out[i] = null;\n continue;\n }\n out[i] = webGamepadToSnapshot(p);\n }\n return out;\n },\n };\n}\n\nfunction webGamepadToSnapshot(p: WebGamepad): GamepadSnapshot {\n const buttons = new Array<{ pressed: boolean; value: number }>(p.buttons.length);\n for (let i = 0; i < p.buttons.length; i++) {\n const b = p.buttons[i];\n buttons[i] = { pressed: b?.pressed ?? false, value: b?.value ?? 0 };\n }\n const axes = new Array<number>(p.axes.length);\n for (let i = 0; i < p.axes.length; i++) axes[i] = p.axes[i] ?? 0;\n return { id: p.id, index: p.index, timestamp: p.timestamp, buttons, axes };\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Vec2 } from '@flare-engine/math';\n\n/** Swipe direction. */\nexport type SwipeDirection = 'left' | 'right' | 'up' | 'down';\n\n/** Gesture detection configuration. */\nexport interface GestureConfig {\n /** Max time (seconds) for a tap (default 0.3). */\n tapMaxDuration?: number;\n /** Max distance (px) for a tap (default 20). */\n tapMaxDistance?: number;\n /** Min time (seconds) for a long press (default 0.5). */\n longPressMinDuration?: number;\n /** Min distance (px) for a swipe (default 50). */\n swipeMinDistance?: number;\n /** Max time (seconds) for a swipe (default 0.4). */\n swipeMaxDuration?: number;\n}\n\n/** Swipe event data. */\nexport interface SwipeEvent {\n direction: SwipeDirection;\n distance: number;\n duration: number;\n}\n\n/** Pinch event data. */\nexport interface PinchEvent {\n /** Scale factor (>1 = spread, <1 = pinch). */\n scale: number;\n /** Center point between the two touches. */\n center: Vec2;\n}\n\nconst DEFAULT_TAP_MAX_DURATION = 0.3;\nconst DEFAULT_TAP_MAX_DISTANCE = 20;\nconst DEFAULT_LONG_PRESS_MIN_DURATION = 0.5;\nconst DEFAULT_SWIPE_MIN_DISTANCE = 50;\nconst DEFAULT_SWIPE_MAX_DURATION = 0.4;\n\n/**\n * GestureDetector recognizes tap, long press, swipe, and pinch gestures\n * from raw pointer events.\n */\nexport class GestureDetector {\n readonly onTap = new Signal<Vec2>();\n readonly onLongPress = new Signal<Vec2>();\n readonly onSwipe = new Signal<SwipeEvent>();\n readonly onPinch = new Signal<PinchEvent>();\n\n private tapMaxDuration: number;\n private tapMaxDistance: number;\n private longPressMinDuration: number;\n private swipeMinDistance: number;\n private swipeMaxDuration: number;\n\n // Single-touch tracking\n private readonly _startPos: Vec2 = { x: 0, y: 0 };\n /** Elapsed time (seconds) since `pointerDown` for the in-progress press. */\n private _elapsed = 0;\n private _isTracking = false;\n private _longPressFired = false;\n\n // Pinch tracking\n private _pinchStartDistance = 0;\n private _pinchActive = false;\n\n constructor(config?: GestureConfig) {\n this.tapMaxDuration = config?.tapMaxDuration ?? DEFAULT_TAP_MAX_DURATION;\n this.tapMaxDistance = config?.tapMaxDistance ?? DEFAULT_TAP_MAX_DISTANCE;\n this.longPressMinDuration = config?.longPressMinDuration ?? DEFAULT_LONG_PRESS_MIN_DURATION;\n this.swipeMinDistance = config?.swipeMinDistance ?? DEFAULT_SWIPE_MIN_DISTANCE;\n this.swipeMaxDuration = config?.swipeMaxDuration ?? DEFAULT_SWIPE_MAX_DURATION;\n }\n\n /** Feed a pointer-down event. */\n pointerDown(x: number, y: number): void {\n this._startPos.x = x;\n this._startPos.y = y;\n this._elapsed = 0;\n this._isTracking = true;\n this._longPressFired = false;\n }\n\n /**\n * Feed a pointer-up event.\n *\n * `elapsedSinceDown` is optional: pass it when the host tracks its own\n * timestamps (e.g. event-driven, no per-frame `update()` calls); omit it\n * to use the elapsed time already accumulated via `update(dt, ...)`. Either\n * way there is one clock per press — passing it here re-syncs the same\n * accumulator `update()` advances, rather than racing it. If a long press\n * already fired for this press, tap/swipe are suppressed so one press\n * yields exactly one gesture.\n */\n pointerUp(x: number, y: number, elapsedSinceDown?: number): void {\n if (!this._isTracking) return;\n this._isTracking = false;\n if (elapsedSinceDown !== undefined) this._elapsed = elapsedSinceDown;\n if (this._longPressFired) return;\n\n const dx = x - this._startPos.x;\n const dy = y - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n const duration = this._elapsed;\n\n // Check swipe first (requires min distance)\n if (dist >= this.swipeMinDistance && duration <= this.swipeMaxDuration) {\n const absDx = Math.abs(dx);\n const absDy = Math.abs(dy);\n let direction: SwipeDirection;\n if (absDx > absDy) {\n direction = dx > 0 ? 'right' : 'left';\n } else {\n direction = dy > 0 ? 'down' : 'up';\n }\n this.onSwipe.emit({ direction, distance: dist, duration });\n return;\n }\n\n // Check tap (short press, small movement)\n if (dist <= this.tapMaxDistance && duration <= this.tapMaxDuration) {\n this.onTap.emit({ x, y });\n return;\n }\n }\n\n /**\n * Update gesture tracking. Call each frame with dt.\n * @param dt Delta time in seconds.\n * @param currentX Current pointer X.\n * @param currentY Current pointer Y.\n */\n update(dt: number, currentX: number, currentY: number): void {\n if (!this._isTracking) return;\n this._elapsed += dt;\n\n // Long press detection\n if (!this._longPressFired && this._elapsed >= this.longPressMinDuration) {\n const dx = currentX - this._startPos.x;\n const dy = currentY - this._startPos.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n if (dist <= this.tapMaxDistance) {\n this._longPressFired = true;\n this.onLongPress.emit({ x: currentX, y: currentY });\n }\n }\n }\n\n /**\n * Feed a two-finger pinch update. Call when two touches are active.\n * @param t1 First touch position.\n * @param t2 Second touch position.\n */\n pinchUpdate(t1: Vec2, t2: Vec2): void {\n const dx = t2.x - t1.x;\n const dy = t2.y - t1.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n if (!this._pinchActive) {\n // Start pinch\n this._pinchStartDistance = dist;\n this._pinchActive = true;\n return;\n }\n\n if (this._pinchStartDistance > 0) {\n const scale = dist / this._pinchStartDistance;\n const center: Vec2 = {\n x: (t1.x + t2.x) / 2,\n y: (t1.y + t2.y) / 2,\n };\n this.onPinch.emit({ scale, center });\n }\n }\n\n /** Call when pinch ends (fewer than 2 touches). */\n pinchEnd(): void {\n this._pinchActive = false;\n this._pinchStartDistance = 0;\n }\n}\n","/** Virtual button state — pure data, no UI. */\nexport interface VirtualButtonState {\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n /** Whether the button was just pressed this frame. */\n justPressed: boolean;\n /** Whether the button was just released this frame. */\n justReleased: boolean;\n}\n\n/** Create a default button state. */\nexport function createButtonState(): VirtualButtonState {\n return {\n isPressed: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/** Call at the start of each frame to reset per-frame flags. */\nexport function resetButtonFrame(state: VirtualButtonState): void {\n state.justPressed = false;\n state.justReleased = false;\n}\n\n/** Call when the button is pressed. */\nexport function pressButton(state: VirtualButtonState): void {\n if (!state.isPressed) {\n state.isPressed = true;\n state.justPressed = true;\n }\n}\n\n/** Call when the button is released. */\nexport function releaseButton(state: VirtualButtonState): void {\n if (state.isPressed) {\n state.isPressed = false;\n state.justReleased = true;\n }\n}\n","import {\n createButtonState,\n pressButton,\n releaseButton,\n resetButtonFrame,\n type VirtualButtonState,\n} from './virtual-button.js';\n\n/** Minimal keyboard event shape — no DOM type dep. */\nexport interface KeyboardEventLike {\n readonly code: string;\n readonly type: string;\n /** Optional — real DOM events have it; synthetic feeds may not. */\n preventDefault?(): void;\n}\n\n/** Minimal event target shape for attaching keyboard listeners. */\nexport interface KeyboardEventTargetLike {\n addEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n removeEventListener(type: string, handler: (ev: KeyboardEventLike) => void): void;\n}\n\n/**\n * Buffered per-frame keyboard state.\n *\n * Edge flags (`wasPressed`, `wasReleased`) clear each frame via `reset()`.\n * `keyDown` / `keyUp` are the platform-neutral injection points: web feeds\n * them via `attachKeyboardListeners`; mobile/RN feeds them from a\n * hardware-keyboard native module or an on-screen source.\n */\nexport interface KeyboardState {\n /** True while the key is physically held. */\n isDown(code: string): boolean;\n /** True only on the frame the key was pressed. */\n wasPressed(code: string): boolean;\n /** True only on the frame the key was released. */\n wasReleased(code: string): boolean;\n /** Platform-neutral injection. OS auto-repeat is de-edged by the pressButton guard. */\n keyDown(code: string): void;\n /** Platform-neutral injection. */\n keyUp(code: string): void;\n /** Frame-start edge clear. Zero-alloc. */\n reset(): void;\n /** Blur/stuck-key guard: emits a release edge for every held code, then drops held. */\n clear(): void;\n}\n\n/** Create a fresh keyboard state. */\nexport function createKeyboard(): KeyboardState {\n const states: VirtualButtonState[] = [];\n const codeIndex = new Map<string, number>();\n\n return {\n isDown(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.isPressed ?? false;\n },\n\n wasPressed(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justPressed ?? false;\n },\n\n wasReleased(code: string): boolean {\n const i = codeIndex.get(code);\n if (i === undefined) return false;\n return states[i]?.justReleased ?? false;\n },\n\n keyDown(code: string): void {\n let i = codeIndex.get(code);\n if (i === undefined) {\n i = states.length;\n states.push(createButtonState());\n codeIndex.set(code, i);\n }\n pressButton(states[i]!);\n },\n\n keyUp(code: string): void {\n const i = codeIndex.get(code);\n if (i === undefined) return;\n releaseButton(states[i]!);\n },\n\n reset(): void {\n for (let i = 0; i < states.length; i++) {\n resetButtonFrame(states[i]!);\n }\n },\n\n clear(): void {\n for (let i = 0; i < states.length; i++) {\n releaseButton(states[i]!);\n }\n },\n };\n}\n\n/**\n * Web turnkey adapter: registers `keydown`, `keyup`, and `blur` listeners on\n * `target`. `blur` calls `kb.clear()` (stuck-key guard). Returns a detach fn.\n *\n * `target` is structural `{ addEventListener, removeEventListener }` — no DOM\n * types dep. On web, pass `window`; for mobile/RN, feed `keyDown`/`keyUp`\n * directly from a hardware-keyboard native module or an on-screen source.\n *\n * Does NOT call `preventDefault` — bare use lets Space/arrows scroll and Tab\n * move DOM focus. For game-mode input, attach your own listener that calls\n * `preventDefault` for game keys and forwards `kb.keyDown(ev.code)`.\n */\nexport function attachKeyboardListeners(\n kb: KeyboardState,\n target: KeyboardEventTargetLike,\n): () => void {\n const onKeyDown = (ev: KeyboardEventLike): void => {\n kb.keyDown(ev.code);\n };\n const onKeyUp = (ev: KeyboardEventLike): void => {\n kb.keyUp(ev.code);\n };\n const onBlur = (_ev: KeyboardEventLike): void => {\n kb.clear();\n };\n\n target.addEventListener('keydown', onKeyDown);\n target.addEventListener('keyup', onKeyUp);\n target.addEventListener('blur', onBlur);\n\n return (): void => {\n target.removeEventListener('keydown', onKeyDown);\n target.removeEventListener('keyup', onKeyUp);\n target.removeEventListener('blur', onBlur);\n };\n}\n\n/**\n * Action → code binding map. Keys are action names; values are arrays of\n * `KeyboardEvent.code` strings. Multiple codes OR-reduce (any bound key\n * triggers the action).\n */\nexport type KeyBindings = Readonly<Record<string, readonly string[]>>;\n\n/** True if any bound code for `action` is currently held. */\nexport function isActionDown(kb: KeyboardState, bindings: KeyBindings, action: string): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return true;\n }\n return false;\n}\n\n/** True if any bound code for `action` was pressed this frame. */\nexport function wasActionPressed(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.wasPressed(codes[i]!)) return true;\n }\n return false;\n}\n\n/**\n * True if any bound code for `action` was released this frame AND no bound\n * code is still held. Release fires only when the last held bound key lifts.\n */\nexport function wasActionReleased(\n kb: KeyboardState,\n bindings: KeyBindings,\n action: string,\n): boolean {\n const codes = bindings[action];\n if (!codes) return false;\n let anyReleased = false;\n for (let i = 0; i < codes.length; i++) {\n if (kb.isDown(codes[i]!)) return false;\n if (kb.wasReleased(codes[i]!)) anyReleased = true;\n }\n return anyReleased;\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/** State of a single pointer (primary touch or mouse). */\nexport interface Pointer {\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Position delta since last frame. */\n delta: Vec2;\n /** Whether the pointer is currently held down. */\n isDown: boolean;\n /** True only on the frame the pointer was pressed. */\n justPressed: boolean;\n /** True only on the frame the pointer was released. */\n justReleased: boolean;\n}\n\n/** State of a single touch point in a multitouch scenario. */\nexport interface TouchPoint {\n /** Unique touch identifier. */\n id: number;\n /** Current position in screen coordinates. */\n position: Vec2;\n /** Whether this touch is currently active. */\n isDown: boolean;\n}\n\n/** Create a default pointer state. */\nexport function createPointer(): Pointer {\n return {\n position: { x: 0, y: 0 },\n delta: { x: 0, y: 0 },\n isDown: false,\n justPressed: false,\n justReleased: false,\n };\n}\n\n/**\n * Update pointer state for a new frame.\n * Call this at the start of each frame to clear per-frame flags.\n */\nexport function resetPointerFrame(pointer: Pointer): void {\n pointer.delta.x = 0;\n pointer.delta.y = 0;\n pointer.justPressed = false;\n pointer.justReleased = false;\n}\n\n/** Feed a pointer-down event into the pointer state. */\nexport function pointerDown(pointer: Pointer, x: number, y: number): void {\n const wasDown = pointer.isDown;\n pointer.isDown = true;\n if (!wasDown) {\n pointer.justPressed = true;\n }\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-move event into the pointer state. */\nexport function pointerMove(pointer: Pointer, x: number, y: number): void {\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n\n/** Feed a pointer-up event into the pointer state. */\nexport function pointerUp(pointer: Pointer, x: number, y: number): void {\n pointer.isDown = false;\n pointer.justReleased = true;\n pointer.delta.x += x - pointer.position.x;\n pointer.delta.y += y - pointer.position.y;\n pointer.position.x = x;\n pointer.position.y = y;\n}\n","import type { GamepadSnapshot } from './gamepad.js';\n\n/**\n * Button / axis remap table.\n *\n * `buttons[logicalId] = physicalIndex` — to poll A, read\n * `snapshot.buttons[table.buttons[GamepadButton.A]]`.\n *\n * `axes` maps logical axis id → `{ index, invert, scale }`. Most games invert\n * Y on some controllers; `scale` supports half-range triggers.\n */\nexport interface AxisMap {\n index: number;\n invert: boolean;\n scale: number;\n}\n\nexport interface RemapTable {\n buttons: number[];\n axes: AxisMap[];\n}\n\nexport function createIdentityRemap(buttonCount = 17, axisCount = 4): RemapTable {\n const buttons = new Array<number>(buttonCount);\n for (let i = 0; i < buttonCount; i++) buttons[i] = i;\n const axes = new Array<AxisMap>(axisCount);\n for (let i = 0; i < axisCount; i++) axes[i] = { index: i, invert: false, scale: 1 };\n return { buttons, axes };\n}\n\n/** Apply a remap table to a raw snapshot, returning a new snapshot with logical ordering. */\nexport function applyRemap(snapshot: GamepadSnapshot, table: RemapTable): GamepadSnapshot {\n return applyRemapInto(snapshot, table, { id: '', index: 0, timestamp: 0, buttons: [], axes: [] });\n}\n\n/**\n * Zero-alloc form of `applyRemap`: writes the logical-ordered snapshot into\n * `out` and returns it. `out.buttons` / `out.axes` are resized to the table, so\n * a scratch already at the table's size allocates nothing; growing allocates\n * the missing button records once. `out` must not be `snapshot`.\n */\nexport function applyRemapInto(\n snapshot: GamepadSnapshot,\n table: RemapTable,\n out: GamepadSnapshot,\n): GamepadSnapshot {\n const buttonCount = table.buttons.length;\n const buttons = out.buttons;\n if (buttons.length > buttonCount) buttons.length = buttonCount;\n for (let logical = 0; logical < buttonCount; logical++) {\n const src = snapshot.buttons[table.buttons[logical] ?? logical];\n const pressed = src?.pressed ?? false;\n const value = src?.value ?? 0;\n const dst = buttons[logical];\n if (dst) {\n dst.pressed = pressed;\n dst.value = value;\n } else {\n buttons[logical] = { pressed, value };\n }\n }\n const axisCount = table.axes.length;\n const axes = out.axes;\n if (axes.length > axisCount) axes.length = axisCount;\n for (let logical = 0; logical < axisCount; logical++) {\n const map = table.axes[logical];\n const raw = snapshot.axes[map ? map.index : logical] ?? 0;\n axes[logical] = map ? raw * map.scale * (map.invert ? -1 : 1) : raw;\n }\n out.id = snapshot.id;\n out.index = snapshot.index;\n out.timestamp = snapshot.timestamp;\n return out;\n}\n\n/**\n * Minimal storage contract — matches `@flare-engine/storage` `StorageAdapter`,\n * but declared locally so this package does not take a hard dep on storage.\n */\nexport interface RemapStore {\n get(key: string): Promise<string | null>;\n set(key: string, value: string): Promise<void>;\n}\n\n/** Persist a remap table under the given key. Throws on invalid table shape. */\nexport async function saveRemap(store: RemapStore, key: string, table: RemapTable): Promise<void> {\n await store.set(key, JSON.stringify(table));\n}\n\n/** Load a remap table. Returns `null` if absent or malformed. */\nexport async function loadRemap(store: RemapStore, key: string): Promise<RemapTable | null> {\n const raw = await store.get(key);\n if (raw === null) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (!isRemapTable(parsed)) return null;\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isRemapTable(value: unknown): value is RemapTable {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as { buttons?: unknown; axes?: unknown };\n if (!Array.isArray(obj.buttons) || !Array.isArray(obj.axes)) return false;\n for (const b of obj.buttons) if (typeof b !== 'number') return false;\n for (const a of obj.axes) {\n if (typeof a !== 'object' || a === null) return false;\n const ax = a as { index?: unknown; invert?: unknown; scale?: unknown };\n if (\n typeof ax.index !== 'number' ||\n typeof ax.invert !== 'boolean' ||\n typeof ax.scale !== 'number'\n ) {\n return false;\n }\n }\n return true;\n}\n","import {\n createGamepadState,\n type GamepadSnapshot,\n type GamepadState,\n resetGamepadFrame,\n updateGamepadFromSnapshot,\n} from './gamepad.js';\nimport type { GamepadSource } from './gamepad-source.js';\nimport { createKeyboard, type KeyboardState } from './keyboard.js';\nimport {\n createPointer,\n type Pointer,\n pointerDown,\n pointerMove,\n pointerUp,\n resetPointerFrame,\n type TouchPoint,\n} from './pointer.js';\nimport type { RemapTable } from './remap.js';\nimport { applyRemapInto } from './remap.js';\n\n/** A pad's remap table plus the manager-owned snapshot it is applied into. */\ninterface RemapSlot {\n table: RemapTable;\n scratch: GamepadSnapshot;\n}\n\n/** Size `scratch` to `table` so the per-poll remap finds every record in place. */\nfunction sizeRemapScratch(scratch: GamepadSnapshot, table: RemapTable): void {\n const buttons = scratch.buttons;\n buttons.length = Math.min(buttons.length, table.buttons.length);\n for (let i = buttons.length; i < table.buttons.length; i++) {\n buttons[i] = { pressed: false, value: 0 };\n }\n const axes = scratch.axes;\n axes.length = Math.min(axes.length, table.axes.length);\n for (let i = axes.length; i < table.axes.length; i++) axes[i] = 0;\n}\n\n/**\n * InputManager provides a polling-based input model.\n *\n * Call `update()` once per frame (before game logic) to snapshot input state.\n * Feed events from the platform (RN touch/gesture handlers) via the on* methods.\n */\nexport class InputManager {\n /**\n * Primary pointer — the touch that started the current gesture (first\n * `onPointerDown` while no touch was active), or the mouse.\n *\n * Once assigned, the primary id stays fixed to that touch until it lifts;\n * it does NOT transfer to a remaining finger. While a second finger is\n * down, its events reach only `touches` — `pointer` neither moves nor\n * releases because of it. When the primary lifts, `pointer.isDown` goes\n * false even if other fingers remain down, and a new primary is assigned\n * only once every touch has lifted and a fresh `onPointerDown` arrives.\n * This keeps `pointer` a single continuous stream with no mid-gesture\n * teleport; read `touches` for anything beyond one finger.\n */\n readonly pointer: Pointer = createPointer();\n\n /** Buffered keyboard state. Feed via `attachKeyboardListeners` (web) or `keyboard.keyDown`/`keyUp` (mobile/RN). */\n readonly keyboard: KeyboardState = createKeyboard();\n\n /** All active touch points. */\n readonly touches: TouchPoint[] = [];\n\n private _touchMap = new Map<number, TouchPoint>();\n private _primaryTouchId: number | null = null;\n private _gamepads: GamepadState[] = [];\n private _gamepadDeadZone = 0.15;\n private _gamepadRemaps = new Map<number, RemapSlot>();\n\n /** Call once per frame to reset per-frame flags. */\n update(): void {\n resetPointerFrame(this.pointer);\n this.keyboard.reset();\n for (let i = 0; i < this._gamepads.length; i++) {\n const pad = this._gamepads[i];\n if (pad) resetGamepadFrame(pad);\n }\n }\n\n /** Feed a touch/pointer begin event. */\n onPointerDown(id: number, x: number, y: number): void {\n if (this._touchMap.size === 0) {\n this._primaryTouchId = id;\n }\n if (id === this._primaryTouchId) {\n pointerDown(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /**\n * Feed a touch/pointer move event.\n *\n * A move for an id that was never pressed, while no primary is active, is a\n * hover (a mouse with no button held): `pointer.position` and `delta`\n * follow it, but `isDown` / `justPressed` stay untouched and no `TouchPoint`\n * is recorded.\n */\n onPointerMove(id: number, x: number, y: number): void {\n if (this._primaryTouchId === null && !this._touchMap.has(id)) {\n pointerMove(this.pointer, x, y);\n return;\n }\n if (id === this._primaryTouchId) {\n pointerMove(this.pointer, x, y);\n }\n this._addOrUpdateTouch(id, x, y, true);\n }\n\n /** Feed a touch/pointer end event. */\n onPointerUp(id: number, x: number, y: number): void {\n if (id === this._primaryTouchId) {\n pointerUp(this.pointer, x, y);\n this._primaryTouchId = null;\n }\n this._removeTouch(id);\n }\n\n /** Access the gamepad state at `index`. Allocates on first access. */\n gamepad(index: number): GamepadState {\n let pad = this._gamepads[index];\n if (!pad) {\n pad = createGamepadState(index);\n this._gamepads[index] = pad;\n }\n return pad;\n }\n\n /** Dead zone in [0, 1). Axes at or below this magnitude read as 0. */\n setGamepadDeadZone(deadZone: number): void {\n this._gamepadDeadZone = Math.max(0, Math.min(0.95, deadZone));\n }\n\n /** Install a remap table for a specific gamepad index. Pass `null` to clear. */\n setGamepadRemap(index: number, table: RemapTable | null): void {\n if (table === null) {\n this._gamepadRemaps.delete(index);\n return;\n }\n let slot = this._gamepadRemaps.get(index);\n if (slot) {\n slot.table = table;\n } else {\n slot = { table, scratch: { id: '', index, timestamp: 0, buttons: [], axes: [] } };\n this._gamepadRemaps.set(index, slot);\n }\n sizeRemapScratch(slot.scratch, table);\n }\n\n /** Poll all gamepads from the given source, applying remap + dead zones. */\n pollGamepads(source: GamepadSource): void {\n const snapshots = source.poll();\n for (let i = 0; i < snapshots.length; i++) {\n const pad = this.gamepad(i);\n const snap = snapshots[i] ?? null;\n const slot = snap !== null ? this._gamepadRemaps.get(i) : undefined;\n const remapped =\n snap !== null && slot ? applyRemapInto(snap, slot.table, slot.scratch) : snap;\n updateGamepadFromSnapshot(pad, remapped, this._gamepadDeadZone);\n }\n }\n\n private _addOrUpdateTouch(id: number, x: number, y: number, isDown: boolean): void {\n let touch = this._touchMap.get(id);\n if (!touch) {\n touch = { id, position: { x, y }, isDown };\n this._touchMap.set(id, touch);\n this.touches.push(touch);\n } else {\n touch.position.x = x;\n touch.position.y = y;\n touch.isDown = isDown;\n }\n }\n\n private _removeTouch(id: number): void {\n const touch = this._touchMap.get(id);\n if (!touch) return;\n this._touchMap.delete(id);\n const idx = this.touches.indexOf(touch);\n if (idx !== -1) {\n this.touches.splice(idx, 1);\n }\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Dev-flag access for the config guard in `updateJoystick`, which runs once per\n * frame while a stick is held. Read as a `globalThis` property, not as a bare\n * `__DEV__` identifier: on JSC an unresolvable global costs ~270 ns per\n * evaluation where a property miss is inline-cached at ~0.46 ns. Same reasoning\n * as `@flare-engine/core`'s `Pool` — see PERF-10.\n */\nconst G = globalThis as { __DEV__?: boolean };\n\n/** Warn at most once per process; a bad config repeats every frame. */\nlet _warnedConfig = false;\n\n/** Virtual joystick configuration. */\nexport interface VirtualJoystickConfig {\n /** Dead zone radius in pixels (default 10). */\n deadZone?: number;\n /** Maximum radius in pixels (default 50). */\n maxRadius?: number;\n}\n\n/** Virtual joystick state — pure data, no UI. */\nexport interface VirtualJoystickState {\n /** Whether the joystick is currently being touched. */\n active: boolean;\n /** Normalized direction vector (-1 to 1 per axis). */\n direction: Vec2;\n /** Magnitude 0-1 (0 = center/dead zone, 1 = max radius). */\n magnitude: number;\n /** Raw offset from center in pixels. */\n offset: Vec2;\n}\n\nconst DEFAULT_DEAD_ZONE = 10;\nconst DEFAULT_MAX_RADIUS = 50;\n\n/** Create a default joystick state. */\nexport function createJoystickState(): VirtualJoystickState {\n return {\n active: false,\n direction: { x: 0, y: 0 },\n magnitude: 0,\n offset: { x: 0, y: 0 },\n };\n}\n\n/**\n * Update joystick state from a touch event.\n *\n * @param state The joystick state to update.\n * @param centerX The joystick center X in screen pixels.\n * @param centerY The joystick center Y in screen pixels.\n * @param touchX The current touch X in screen pixels.\n * @param touchY The current touch Y in screen pixels.\n * @param config Joystick configuration.\n */\nexport function updateJoystick(\n state: VirtualJoystickState,\n centerX: number,\n centerY: number,\n touchX: number,\n touchY: number,\n config?: VirtualJoystickConfig,\n): void {\n let deadZone = config?.deadZone ?? DEFAULT_DEAD_ZONE;\n let maxRadius = config?.maxRadius ?? DEFAULT_MAX_RADIUS;\n\n // Out-of-contract config is corrected rather than propagated. Left alone, a\n // NaN deadZone defeats the early return below and a maxRadius equal to\n // deadZone divides by zero at `normalizedDist` — either way `state.direction`\n // becomes NaN and, because the state is reused across frames, the stick never\n // recovers. The whole check sits behind one comparison on the healthy path.\n if (!(deadZone >= 0 && maxRadius > deadZone)) {\n if (G.__DEV__ && !_warnedConfig) {\n _warnedConfig = true;\n console.warn(\n `[flare-engine/input] updateJoystick: invalid config (deadZone=${deadZone}, maxRadius=${maxRadius}); ` +\n 'expected 0 <= deadZone < maxRadius. Falling back to defaults for this call.',\n );\n }\n if (!(deadZone >= 0)) deadZone = DEFAULT_DEAD_ZONE;\n if (!(maxRadius > deadZone)) maxRadius = deadZone + DEFAULT_MAX_RADIUS;\n }\n\n const dx = touchX - centerX;\n const dy = touchY - centerY;\n const dist = Math.sqrt(dx * dx + dy * dy);\n\n state.active = true;\n\n // `!(dist >= deadZone)` rather than `dist < deadZone` so a non-finite touch\n // coordinate takes the centred branch instead of falling through to the maths.\n if (!(dist >= deadZone)) {\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n // dist is non-finite only when a touch coordinate was, in which case dx/dy\n // are too — report a centred offset rather than writing NaN into the state.\n const centred = dist === 0 || !Number.isFinite(dist);\n state.offset.x = centred ? 0 : dx;\n state.offset.y = centred ? 0 : dy;\n return;\n }\n\n // Clamp to max radius\n const clampedDist = Math.min(dist, maxRadius);\n const normalizedDist = (clampedDist - deadZone) / (maxRadius - deadZone);\n\n // Direction is always the full normalized direction. `dist` is > 0 here —\n // a zero distance cannot pass the guard above once deadZone >= 0 — but the\n // reciprocal is guarded anyway, because `deadZone: 0` makes `dist === 0`\n // reachable and `1 / 0` would put Infinity into direction.\n const invDist = dist > 0 ? 1 / dist : 0;\n state.direction.x = dx * invDist;\n state.direction.y = dy * invDist;\n state.magnitude = Math.min(normalizedDist, 1);\n\n // Offset clamped to max radius\n const scale = dist > 0 ? clampedDist / dist : 0;\n state.offset.x = dx * scale;\n state.offset.y = dy * scale;\n}\n\n/** Reset joystick state when touch is released. */\nexport function releaseJoystick(state: VirtualJoystickState): void {\n state.active = false;\n state.direction.x = 0;\n state.direction.y = 0;\n state.magnitude = 0;\n state.offset.x = 0;\n state.offset.y = 0;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAMA,MAAI;;AAGV,IAAI,kBAAkB;;AAGtB,MAAM,gBAAgB;;AAGtB,MAAa,gBAAgB;CAC3B,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,OAAO;CACP,IAAI;CACJ,IAAI;CACJ,QAAQ;CACR,UAAU;CACV,UAAU;CACV,WAAW;CACX,MAAM;AACR;;AAIA,MAAa,cAAc;CACzB,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AA+BA,SAAgB,mBAAmB,QAAQ,GAAG,cAAc,IAAI,YAAY,GAAiB;CAC3F,MAAM,UAAgC,IAAI,MAAM,WAAW;CAC3D,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAC/B,QAAQ,KAAK;EAAE,SAAS;EAAO,OAAO;EAAG,aAAa;E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,IAAI;AACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/input",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "InputManager, VirtualJoystick, gesture handling",
5
5
  "keywords": ["flare-engine", "input", "joystick", "gestures", "react-native", "typescript"],
6
6
  "license": "Apache-2.0",
@@ -37,8 +37,8 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@flare-engine/events": "^0.4.10",
41
- "@flare-engine/math": "^0.4.10"
40
+ "@flare-engine/events": "^0.4.12",
41
+ "@flare-engine/math": "^0.4.12"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=20"