@simpludify/web 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # @simpludify/web
2
2
 
3
- Experimental v0.1.2 browser SDK for Simpludify, a code-first TypeScript 2D engine. APIs may change between 0.x releases. Includes Game, PixiJS rendering, browser input and Canvas/DOM UI adapters; re-exports the host-independent Core API. Core and PixiJS are installed as runtime dependencies, not bundled into this package.
3
+ Experimental v0.1.4 browser SDK for Simpludify, a code-first TypeScript 2D engine. APIs may change between 0.x releases. Includes Game, PixiJS rendering, browser input and Canvas/DOM UI adapters; re-exports the host-independent Core API. Core and PixiJS are installed as runtime dependencies, not bundled into this package.
4
4
 
5
- Registry installation (check availability with `npm view @simpludify/web@0.1.2 version`):
5
+ Registry installation (check availability with `npm view @simpludify/web@0.1.4 version`):
6
6
 
7
7
  ```sh
8
- npm install @simpludify/web@0.1.2
8
+ npm install @simpludify/web@0.1.4
9
9
  npm install --save-dev vite typescript
10
10
  ```
11
11
 
@@ -20,3 +20,5 @@ await game.run();
20
20
  Use a browser bundler such as Vite, with an HTML module entry and a parent with an explicit height. The entry automatically imports scoped CSS. It can also be imported explicitly with `import "@simpludify/web/style.css"`. Do not configure CSS as side-effect-free. No repository CLI, example assets or global stylesheet reset is included.
21
21
 
22
22
  ESM only, ES2022. Tooling requires Node >=22.12; Chromium/WebGL is the automated rendering target. This browser package is not a Node/SSR entry; use `@simpludify/core` for headless execution. Source maps embed original sources. [Complete Vite setup](https://github.oz-coden.com/Simpludify/guides/npm.html) · [Repository/API](https://github.com/oz-coden/Simpludify). MIT.
23
+
24
+ Registry availability is recorded in the repository release report; a source version alone does not establish publication.
@@ -18,6 +18,7 @@ export declare class CanvasVisual implements CanvasPresentation {
18
18
  private dirty;
19
19
  private dead;
20
20
  private active;
21
+ private cacheResolution;
21
22
  private mirroredFocus;
22
23
  private readonly subscriptions;
23
24
  private syncs;
@@ -25,14 +26,17 @@ export declare class CanvasVisual implements CanvasPresentation {
25
26
  graphics(graphics: Graphics, context: number | undefined): void;
26
27
  text(text: Text, key: string | undefined): void;
27
28
  changedText(key: string): void;
29
+ cacheResolution(): number | undefined;
28
30
  });
29
31
  get diagnostics(): {
30
32
  nodes: number;
33
+ visibleNodes: number;
31
34
  buttons: number;
32
35
  syncs: number;
33
36
  textMetrics: number;
34
37
  };
35
38
  private measure;
39
+ private clearCache;
36
40
  beforeResolutionChange(): void;
37
41
  focus(node: CanvasNode): void;
38
42
  private native;
package/dist/game.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { CanvasNode } from "@simpludify/core";
2
2
  import { type ActionBindings, ActionController, type ActionSet, type Actor, Aspect, Camera, CanvasUI, type CanvasUIOptions, Engine, type FixedStepOptions, type FrameDriver, type JsonValue, type LogicalResolution, type RendererPort, type ReplayControllers, ReplayPlayer, Scene, ScenePointer, type ScreenPoint, type TweenScheduler, type Viewport, type ViewTransform, type WorldPoint } from "@simpludify/core";
3
+ import { GamepadInput } from "./gamepads.js";
3
4
  import { Theme, type ThemeTokens, type UINode } from "./ui.js";
4
5
  export interface SceneContext {
5
6
  readonly scene: Scene;
@@ -37,6 +38,7 @@ export declare class Game<SceneId extends string = string> {
37
38
  readonly engine: Engine;
38
39
  readonly element: HTMLDivElement;
39
40
  readonly camera: Camera;
41
+ readonly gamepads: GamepadInput;
40
42
  private readonly renderer;
41
43
  private readonly keyboard;
42
44
  private readonly pointers;
@@ -0,0 +1,100 @@
1
+ import { type ActionKind, type ActionSet, type ActionToken } from "@simpludify/core";
2
+ /** Standard mapping physical positions, not product-specific printed labels. */
3
+ export declare const GamepadButton: Readonly<{
4
+ South: 0;
5
+ East: 1;
6
+ West: 2;
7
+ North: 3;
8
+ LeftShoulder: 4;
9
+ RightShoulder: 5;
10
+ LeftTrigger: 6;
11
+ RightTrigger: 7;
12
+ Select: 8;
13
+ Start: 9;
14
+ LeftStick: 10;
15
+ RightStick: 11;
16
+ DPadUp: 12;
17
+ DPadDown: 13;
18
+ DPadLeft: 14;
19
+ DPadRight: 15;
20
+ Home: 16;
21
+ }>;
22
+ export type GamepadButton = (typeof GamepadButton)[keyof typeof GamepadButton];
23
+ export declare const GamepadAxis: Readonly<{
24
+ LeftX: 0;
25
+ LeftY: 1;
26
+ RightX: 2;
27
+ RightY: 3;
28
+ }>;
29
+ export type GamepadAxis = (typeof GamepadAxis)[keyof typeof GamepadAxis];
30
+ export interface GamepadButtonBinding {
31
+ readonly buttons?: readonly (number | {
32
+ readonly button: number;
33
+ readonly threshold?: number;
34
+ })[];
35
+ }
36
+ export interface GamepadAxisBinding {
37
+ readonly axis?: number;
38
+ readonly invert?: boolean;
39
+ readonly negative?: readonly number[];
40
+ readonly positive?: readonly number[];
41
+ readonly deadZone?: number;
42
+ }
43
+ export interface GamepadVectorBinding {
44
+ readonly x?: GamepadAxisBinding;
45
+ readonly y?: GamepadAxisBinding;
46
+ }
47
+ export interface GamepadVector3Binding extends GamepadVectorBinding {
48
+ readonly z?: GamepadAxisBinding;
49
+ }
50
+ export type GamepadBinding<K extends ActionKind> = K extends "button" ? GamepadButtonBinding : K extends "axis1d" ? GamepadAxisBinding : K extends "axis2d" ? GamepadVectorBinding : GamepadVector3Binding;
51
+ export type GamepadBindings<A extends ActionSet> = {
52
+ readonly [N in keyof A]?: GamepadBinding<A[N]["kind"]>;
53
+ };
54
+ /** Ready-to-use data; game Actions retain application-defined names. */
55
+ export declare const GamepadBindings: Readonly<{
56
+ LeftStick: Readonly<{
57
+ x: Readonly<{
58
+ axis: number;
59
+ }>;
60
+ y: Readonly<{
61
+ axis: number;
62
+ }>;
63
+ }>;
64
+ RightStick: Readonly<{
65
+ x: Readonly<{
66
+ axis: number;
67
+ }>;
68
+ y: Readonly<{
69
+ axis: number;
70
+ }>;
71
+ }>;
72
+ DPad: Readonly<{
73
+ x: Readonly<{
74
+ negative: readonly number[];
75
+ positive: readonly number[];
76
+ }>;
77
+ y: Readonly<{
78
+ negative: readonly number[];
79
+ positive: readonly number[];
80
+ }>;
81
+ }>;
82
+ Move: Readonly<{
83
+ x: Readonly<{
84
+ axis: 0;
85
+ negative: readonly number[];
86
+ positive: readonly number[];
87
+ }>;
88
+ y: Readonly<{
89
+ axis: 1;
90
+ negative: readonly number[];
91
+ positive: readonly number[];
92
+ }>;
93
+ }>;
94
+ }>;
95
+ type Binding = GamepadButtonBinding | GamepadAxisBinding | GamepadVector3Binding;
96
+ export type CheckedGamepadBinding = readonly [ActionToken, Binding];
97
+ export declare function gamepadIndex(value: unknown): number;
98
+ export declare function gamepadDeadZone(value: unknown): number;
99
+ export declare function checkedGamepadBindings(actions: ActionSet, value: unknown): readonly CheckedGamepadBinding[];
100
+ export {};
@@ -0,0 +1,18 @@
1
+ export type GamepadLayout = "generic" | "xbox" | "playstation" | "nintendo";
2
+ export interface GamepadInfo {
3
+ /** Unmodified browser string; never a persistent individual-device identifier. */
4
+ readonly id: string;
5
+ readonly index: number;
6
+ readonly connected: boolean;
7
+ readonly mapping: string;
8
+ readonly standardMapping: boolean;
9
+ readonly buttonCount: number;
10
+ readonly axisCount: number;
11
+ /** Heuristic ID hint, not a browser fact or guaranteed product detection. */
12
+ readonly inferredLayout: GamepadLayout;
13
+ }
14
+ export declare function gamepadButtonLabel(button: number, options?: {
15
+ readonly layout?: GamepadLayout;
16
+ readonly overrides?: Readonly<Record<number, string>>;
17
+ }): string;
18
+ export declare function inferredGamepadLayout(id: string): GamepadLayout;
@@ -0,0 +1,79 @@
1
+ import { type ActionController, type ActionSet, type InputAdapter, type InputSystem, type LifetimeOwner } from "@simpludify/core";
2
+ import { type GamepadBindings } from "./gamepad-bindings.js";
3
+ import { type GamepadInfo } from "./gamepad-layout.js";
4
+ /** Structural polling boundary also usable by deterministic tests/custom Web hosts. */
5
+ export interface GamepadState {
6
+ readonly id: string;
7
+ readonly index: number;
8
+ readonly connected: boolean;
9
+ readonly mapping: string;
10
+ readonly axes: readonly number[];
11
+ readonly buttons: readonly {
12
+ readonly value: number;
13
+ readonly pressed: boolean;
14
+ }[];
15
+ }
16
+ export type GamepadPoll = () => readonly (GamepadState | null)[];
17
+ export interface GamepadOptions<A extends ActionSet> {
18
+ readonly index: number;
19
+ readonly bindings: GamepadBindings<A>;
20
+ readonly deadZone?: number;
21
+ /** Positional constants require standard mapping; raw is an explicit opt-in. */
22
+ readonly mapping?: "standard" | "raw";
23
+ }
24
+ /** A controller-owned device contribution. Reassignment does not replace its readers/Actors. */
25
+ export declare class GamepadSource<A extends ActionSet> {
26
+ private readonly input;
27
+ private readonly controller;
28
+ private readonly life;
29
+ private readonly source;
30
+ private bindings;
31
+ private assigned;
32
+ private armed;
33
+ private signature;
34
+ private readonly zone;
35
+ private readonly mapping;
36
+ constructor(input: GamepadInput, controller: ActionController<A>, options: GamepadOptions<A>);
37
+ get disposed(): boolean;
38
+ get enabled(): boolean;
39
+ set enabled(value: boolean);
40
+ get index(): number;
41
+ get info(): GamepadInfo | undefined;
42
+ get connected(): boolean;
43
+ get usable(): boolean;
44
+ assign(index: number): void;
45
+ rebind(bindings: GamepadBindings<A>): void;
46
+ clear(): void;
47
+ private alive;
48
+ /** @internal */ sample(pad: GamepadState | undefined, allowed: boolean): void;
49
+ /** @internal */ onDispose(callback: () => void): () => void;
50
+ dispose(): void;
51
+ }
52
+ /** One Web host adapter; multiple sources share a single snapshot per Engine input boundary. */
53
+ export declare class GamepadInput implements InputAdapter {
54
+ private readonly input;
55
+ private readonly life;
56
+ private readonly changes;
57
+ private readonly sources;
58
+ private readonly disconnected;
59
+ private listed;
60
+ private readable;
61
+ private readonly poll;
62
+ private readonly active;
63
+ constructor(input: InputSystem, options?: {
64
+ readonly poll?: GamepadPoll;
65
+ readonly active?: () => boolean;
66
+ readonly events?: EventTarget;
67
+ });
68
+ get disposed(): boolean;
69
+ /** Whether the most recent polling attempt completed; an empty list may still need a user gesture. */
70
+ get available(): boolean;
71
+ get devices(): readonly GamepadInfo[];
72
+ onChange(handler: () => void, owner?: LifetimeOwner): () => void;
73
+ private publish;
74
+ /** @internal */ assertController(controller: object): void;
75
+ bind<A extends ActionSet>(controller: ActionController<A>, options: GamepadOptions<A>): GamepadSource<A>;
76
+ sample(): void;
77
+ reset(): void;
78
+ dispose(): void;
79
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,12 @@ export * from "@simpludify/core";
3
3
  export { browserAbortSignal, CanvasButton } from "./canvas-node.js";
4
4
  export type { CanvasPresentation } from "./canvas-visual.js";
5
5
  export * from "./game.js";
6
+ export type { GamepadAxisBinding, GamepadBinding, GamepadButtonBinding, GamepadVector3Binding, GamepadVectorBinding, } from "./gamepad-bindings.js";
7
+ export { GamepadAxis, GamepadBindings, GamepadButton, } from "./gamepad-bindings.js";
8
+ export type { GamepadInfo, GamepadLayout } from "./gamepad-layout.js";
9
+ export { gamepadButtonLabel } from "./gamepad-layout.js";
10
+ export type { GamepadOptions, GamepadPoll, GamepadState } from "./gamepads.js";
11
+ export { GamepadInput, GamepadSource } from "./gamepads.js";
6
12
  export { BrowserInput } from "./input.js";
7
13
  export { PixiRenderer } from "./renderer.js";
8
14
  export * from "./ui.js";