@yagejs/input 0.3.0 → 0.5.0
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/api-BaItBbSe.d.cts +685 -0
- package/dist/api-BaItBbSe.d.ts +685 -0
- package/dist/api.cjs +34 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +2 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.js +7 -0
- package/dist/api.js.map +1 -0
- package/dist/chunk-O2U7FZ7Q.js +12 -0
- package/dist/chunk-O2U7FZ7Q.js.map +1 -0
- package/dist/index.cjs +1322 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -164
- package/dist/index.d.ts +4 -164
- package/dist/index.js +1326 -62
- package/dist/index.js.map +1 -1
- package/package.json +13 -3
package/dist/api.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api.ts
|
|
21
|
+
var api_exports = {};
|
|
22
|
+
__export(api_exports, {
|
|
23
|
+
InputManagerKey: () => InputManagerKey
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(api_exports);
|
|
26
|
+
|
|
27
|
+
// src/types.ts
|
|
28
|
+
var import_core = require("@yagejs/core");
|
|
29
|
+
var InputManagerKey = new import_core.ServiceKey("inputManager");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
InputManagerKey
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=api.cjs.map
|
package/dist/api.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api.ts","../src/types.ts"],"sourcesContent":["export { InputManagerKey } from \"./types.js\";\nexport type {\n InputConfig,\n GamepadInfo,\n GamepadAxisKey,\n PointerInfo,\n PointerType,\n} from \"./types.js\";\n","import { ServiceKey } from \"@yagejs/core\";\nimport type { RendererAdapter, Vec2 } from \"@yagejs/core\";\nimport type { InputManager } from \"./InputManager.js\";\n\n/** Service key for the InputManager. */\nexport const InputManagerKey = new ServiceKey<InputManager>(\"inputManager\");\n\n/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */\nexport interface CameraLike {\n screenToWorld(screenX: number, screenY: number): { x: number; y: number };\n}\n\n/**\n * Minimal renderer surface needed by InputPlugin for canvas access and\n * coordinate mapping. Alias of the cross-package `RendererAdapter` contract.\n */\nexport type RendererLike = RendererAdapter;\n\n/** Configuration for the InputPlugin. */\nexport interface InputConfig {\n /** Target element for pointer events (default: canvas from renderer, or document). */\n target?: HTMLElement;\n /** Action map: action name -> array of physical key codes. */\n actions?: ActionMapDefinition;\n /** Input groups: group name -> array of action names belonging to it. */\n groups?: Record<string, string[]>;\n /** Key codes to call preventDefault() on (default: none). */\n preventDefaultKeys?: string[];\n /**\n * Optional override for the renderer service key. When omitted, InputPlugin\n * auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`\n * plugin registers itself under that key, so pointer events target its\n * canvas and coordinates route through `canvasToVirtual` out of the box.\n * Set this only if you ship a custom renderer registered under a different\n * key.\n */\n rendererKey?: ServiceKey<RendererAdapter>;\n /** Deadzone thresholds for analog inputs. */\n deadzones?: {\n /** Radial deadzone applied to stick magnitude (default 0.15). */\n stick?: number;\n /** Lower deadzone for trigger analog values (default 0.05). */\n trigger?: number;\n };\n /**\n * Trigger value at which `GamepadLT`/`GamepadRT` fire as button edges in the\n * action map (default 0.5). Below this, the trigger remains \"released\" for\n * `isPressed` purposes; the analog `getTrigger` value is unaffected.\n */\n triggerThreshold?: number;\n /**\n * Whether to poll `navigator.getGamepads()` each frame (default `true`).\n * Disable to use only synthetic input via `fireGamepadButton`/`fireGamepadAxis`\n * — useful for inspector probes that want deterministic state.\n */\n pollGamepads?: boolean;\n /**\n * Invert vertical scroll so positive `dy` means up (default `false`,\n * matching the W3C convention where positive `deltaY` is \"scroll content\n * down\"). Affects both `onWheel` callbacks and `WheelUp/Down` action edges.\n */\n wheelInvertY?: boolean;\n /**\n * Call `preventDefault()` on incoming wheel events so the page does not\n * scroll. Default `false` — opt in only if your game canvas should swallow\n * scroll. The listener is attached as `{ passive: false }` when this is\n * enabled so `preventDefault()` actually takes effect.\n */\n preventDefaultWheel?: boolean;\n}\n\n/** Information about a connected gamepad. */\nexport interface GamepadInfo {\n /** Index in `navigator.getGamepads()`. May change if pads are hot-swapped. */\n index: number;\n /** Browser-reported gamepad identifier (vendor + product). */\n id: string;\n}\n\n/**\n * Named gamepad analog axis. Sticks are exposed per axis (`leftX`/`leftY`,\n * etc.); triggers (`leftTrigger`/`rightTrigger`) carry the W3C\n * `GamepadButton.value` for buttons 6/7 under standard mapping.\n */\nexport type GamepadAxisKey =\n | \"leftX\"\n | \"leftY\"\n | \"rightX\"\n | \"rightY\"\n | \"leftTrigger\"\n | \"rightTrigger\";\n\n/**\n * Class of physical pointer device. Sourced from `PointerEvent.pointerType` on\n * real input; defaults to `\"mouse\"` for synthetic injection.\n */\nexport type PointerType = \"mouse\" | \"pen\" | \"touch\";\n\n/**\n * Read-only view of a tracked pointer. Returned from {@link InputManager.getPointers}\n * and the per-pointer event hooks. Treat as immutable — fields reflect the\n * pointer's state at query time and are not retained between frames.\n */\nexport interface PointerInfo {\n /** Browser-assigned `PointerEvent.pointerId`, or the synthetic id passed via `firePointer*`. */\n readonly id: number;\n /** Position in screen-space pixels (already routed through `canvasToVirtual` if available). */\n readonly screenPos: Vec2;\n /** Source device class. */\n readonly type: PointerType;\n /** Whether the browser flagged this as the primary pointer (`PointerEvent.isPrimary`). */\n readonly isPrimary: boolean;\n /** Currently-held button indices (0=left/primary, 1=middle, 2=right). */\n readonly buttons: ReadonlySet<number>;\n /** Convenience mirror of `buttons.size > 0`. */\n readonly isDown: boolean;\n}\n\n/**\n * Per-event payload assembled by {@link InputPlugin} from each `PointerEvent`\n * (or by `firePointer*` for synthetic injection) and forwarded to the manager's\n * internal pointer handlers.\n *\n * @internal\n */\nexport interface PointerEventInfo {\n id: number;\n screenX: number;\n screenY: number;\n type: PointerType;\n isPrimary: boolean;\n /**\n * The button whose state changed for this event. `-1` for events that don't\n * change button state (move-only). Down/up handlers ignore `-1`.\n */\n button: number;\n}\n\n/** Maps action names to arrays of physical key codes. */\nexport type ActionMapDefinition = Record<string, string[]>;\n\n/** How to handle a conflict when rebinding a key already used by another action in the same group. */\nexport type InputConflictPolicy = \"replace\" | \"keep-both\" | \"reject\";\n\n/** Options for {@link InputManager.rebind}. */\nexport interface RebindOptions {\n /** Index of the binding slot to replace. Appends if the slot does not exist. */\n slot?: number;\n /** How to resolve conflicts with other actions in the same group(s). Default: `\"reject\"`. */\n conflict?: InputConflictPolicy;\n}\n\n/** Result of a {@link InputManager.rebind} call. */\nexport interface RebindResult {\n /** Whether the rebind succeeded. */\n ok: boolean;\n /** Present when `ok` is false due to a conflict with `conflict: \"reject\"`. */\n conflict?: { action: string; key: string };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2B;AAKpB,IAAM,kBAAkB,IAAI,uBAAyB,cAAc;","names":[]}
|
package/dist/api.d.cts
ADDED
package/dist/api.d.ts
ADDED
package/dist/api.js
ADDED
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/types.ts
|
|
5
|
+
import { ServiceKey } from "@yagejs/core";
|
|
6
|
+
var InputManagerKey = new ServiceKey("inputManager");
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__name,
|
|
10
|
+
InputManagerKey
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-O2U7FZ7Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { ServiceKey } from \"@yagejs/core\";\nimport type { RendererAdapter, Vec2 } from \"@yagejs/core\";\nimport type { InputManager } from \"./InputManager.js\";\n\n/** Service key for the InputManager. */\nexport const InputManagerKey = new ServiceKey<InputManager>(\"inputManager\");\n\n/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */\nexport interface CameraLike {\n screenToWorld(screenX: number, screenY: number): { x: number; y: number };\n}\n\n/**\n * Minimal renderer surface needed by InputPlugin for canvas access and\n * coordinate mapping. Alias of the cross-package `RendererAdapter` contract.\n */\nexport type RendererLike = RendererAdapter;\n\n/** Configuration for the InputPlugin. */\nexport interface InputConfig {\n /** Target element for pointer events (default: canvas from renderer, or document). */\n target?: HTMLElement;\n /** Action map: action name -> array of physical key codes. */\n actions?: ActionMapDefinition;\n /** Input groups: group name -> array of action names belonging to it. */\n groups?: Record<string, string[]>;\n /** Key codes to call preventDefault() on (default: none). */\n preventDefaultKeys?: string[];\n /**\n * Optional override for the renderer service key. When omitted, InputPlugin\n * auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`\n * plugin registers itself under that key, so pointer events target its\n * canvas and coordinates route through `canvasToVirtual` out of the box.\n * Set this only if you ship a custom renderer registered under a different\n * key.\n */\n rendererKey?: ServiceKey<RendererAdapter>;\n /** Deadzone thresholds for analog inputs. */\n deadzones?: {\n /** Radial deadzone applied to stick magnitude (default 0.15). */\n stick?: number;\n /** Lower deadzone for trigger analog values (default 0.05). */\n trigger?: number;\n };\n /**\n * Trigger value at which `GamepadLT`/`GamepadRT` fire as button edges in the\n * action map (default 0.5). Below this, the trigger remains \"released\" for\n * `isPressed` purposes; the analog `getTrigger` value is unaffected.\n */\n triggerThreshold?: number;\n /**\n * Whether to poll `navigator.getGamepads()` each frame (default `true`).\n * Disable to use only synthetic input via `fireGamepadButton`/`fireGamepadAxis`\n * — useful for inspector probes that want deterministic state.\n */\n pollGamepads?: boolean;\n /**\n * Invert vertical scroll so positive `dy` means up (default `false`,\n * matching the W3C convention where positive `deltaY` is \"scroll content\n * down\"). Affects both `onWheel` callbacks and `WheelUp/Down` action edges.\n */\n wheelInvertY?: boolean;\n /**\n * Call `preventDefault()` on incoming wheel events so the page does not\n * scroll. Default `false` — opt in only if your game canvas should swallow\n * scroll. The listener is attached as `{ passive: false }` when this is\n * enabled so `preventDefault()` actually takes effect.\n */\n preventDefaultWheel?: boolean;\n}\n\n/** Information about a connected gamepad. */\nexport interface GamepadInfo {\n /** Index in `navigator.getGamepads()`. May change if pads are hot-swapped. */\n index: number;\n /** Browser-reported gamepad identifier (vendor + product). */\n id: string;\n}\n\n/**\n * Named gamepad analog axis. Sticks are exposed per axis (`leftX`/`leftY`,\n * etc.); triggers (`leftTrigger`/`rightTrigger`) carry the W3C\n * `GamepadButton.value` for buttons 6/7 under standard mapping.\n */\nexport type GamepadAxisKey =\n | \"leftX\"\n | \"leftY\"\n | \"rightX\"\n | \"rightY\"\n | \"leftTrigger\"\n | \"rightTrigger\";\n\n/**\n * Class of physical pointer device. Sourced from `PointerEvent.pointerType` on\n * real input; defaults to `\"mouse\"` for synthetic injection.\n */\nexport type PointerType = \"mouse\" | \"pen\" | \"touch\";\n\n/**\n * Read-only view of a tracked pointer. Returned from {@link InputManager.getPointers}\n * and the per-pointer event hooks. Treat as immutable — fields reflect the\n * pointer's state at query time and are not retained between frames.\n */\nexport interface PointerInfo {\n /** Browser-assigned `PointerEvent.pointerId`, or the synthetic id passed via `firePointer*`. */\n readonly id: number;\n /** Position in screen-space pixels (already routed through `canvasToVirtual` if available). */\n readonly screenPos: Vec2;\n /** Source device class. */\n readonly type: PointerType;\n /** Whether the browser flagged this as the primary pointer (`PointerEvent.isPrimary`). */\n readonly isPrimary: boolean;\n /** Currently-held button indices (0=left/primary, 1=middle, 2=right). */\n readonly buttons: ReadonlySet<number>;\n /** Convenience mirror of `buttons.size > 0`. */\n readonly isDown: boolean;\n}\n\n/**\n * Per-event payload assembled by {@link InputPlugin} from each `PointerEvent`\n * (or by `firePointer*` for synthetic injection) and forwarded to the manager's\n * internal pointer handlers.\n *\n * @internal\n */\nexport interface PointerEventInfo {\n id: number;\n screenX: number;\n screenY: number;\n type: PointerType;\n isPrimary: boolean;\n /**\n * The button whose state changed for this event. `-1` for events that don't\n * change button state (move-only). Down/up handlers ignore `-1`.\n */\n button: number;\n}\n\n/** Maps action names to arrays of physical key codes. */\nexport type ActionMapDefinition = Record<string, string[]>;\n\n/** How to handle a conflict when rebinding a key already used by another action in the same group. */\nexport type InputConflictPolicy = \"replace\" | \"keep-both\" | \"reject\";\n\n/** Options for {@link InputManager.rebind}. */\nexport interface RebindOptions {\n /** Index of the binding slot to replace. Appends if the slot does not exist. */\n slot?: number;\n /** How to resolve conflicts with other actions in the same group(s). Default: `\"reject\"`. */\n conflict?: InputConflictPolicy;\n}\n\n/** Result of a {@link InputManager.rebind} call. */\nexport interface RebindResult {\n /** Whether the rebind succeeded. */\n ok: boolean;\n /** Present when `ok` is false due to a conflict with `conflict: \"reject\"`. */\n conflict?: { action: string; key: string };\n}\n"],"mappings":";;;;AAAA,SAAS,kBAAkB;AAKpB,IAAM,kBAAkB,IAAI,WAAyB,cAAc;","names":[]}
|