@aethervtt/shard-platform 0.0.1 → 0.1.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/index.d.ts CHANGED
@@ -17,6 +17,29 @@ export interface Platform {
17
17
  * first use. Absent on hosts without threads; `workersOf` falls back to running jobs inline.
18
18
  */
19
19
  readonly workers?: Workers;
20
+ /** The host's own performance instruments (long tasks, downloads), for 0062's metrics. */
21
+ readonly performance?: HostPerformance;
22
+ }
23
+ /**
24
+ * What the host itself can measure about a page or process (0062). Browsers report long tasks and
25
+ * resource timing; Node and Tauri report what they can, and leave out what they can't.
26
+ */
27
+ export interface HostPerformance {
28
+ /** The user agent, or the runtime's name and version. */
29
+ readonly userAgent: string;
30
+ /**
31
+ * Main-thread tasks of 50 ms or more, as the host reports them: start (on the `clock`'s timeline)
32
+ * and duration, in ms. Returns an unsubscribe function. Absent where the host can't see them.
33
+ */
34
+ onLongTask?(listener: (startMs: number, durationMs: number) => void): () => void;
35
+ /** Bytes fetched so far (scripts, WASM, assets), over the wire and decoded. Absent without resource timing. */
36
+ downloads?(): HostDownloads;
37
+ }
38
+ export interface HostDownloads {
39
+ /** Bytes over the wire, headers included. Cached responses add nothing. */
40
+ transferred: number;
41
+ /** Bytes after decoding (decompression). */
42
+ decoded: number;
20
43
  }
21
44
  export * from './workers.js';
22
45
  export type MouseButton = 'left' | 'middle' | 'right' | 'back' | 'forward';
@@ -39,10 +62,35 @@ export type RawInputEvent = {
39
62
  y: number;
40
63
  dx: number;
41
64
  dy: number;
42
- } | {
65
+ }
66
+ /**
67
+ * Wheel movement in pixels (line and page deltas already converted). `x`/`y` (CSS pixels, from
68
+ * the element's top left) and `modifiers` come from sources that know them; a ctrl wheel is a
69
+ * trackpad pinch.
70
+ */
71
+ | {
43
72
  type: 'wheel';
44
73
  dx: number;
45
74
  dy: number;
75
+ x?: number;
76
+ y?: number;
77
+ modifiers?: number;
78
+ }
79
+ /**
80
+ * One pointer (0060): mouse, pen or touch, in CSS pixels from the element's top left. Gestures
81
+ * read these; `mouse-*` and `touch` events still feed the device resources and action maps.
82
+ */
83
+ | {
84
+ type: 'pointer';
85
+ id: number;
86
+ phase: PointerPhase;
87
+ pointer: PointerKind;
88
+ /** The button that went down (`down`/`up`), or the one held since (`move`). */
89
+ button: MouseButton;
90
+ x: number;
91
+ y: number;
92
+ /** `MODIFIERS` bits held: shift, ctrl, alt, meta. */
93
+ modifiers: number;
46
94
  } | {
47
95
  type: 'touch';
48
96
  id: number;
@@ -69,10 +117,44 @@ export type RawInputEvent = {
69
117
  type: 'text';
70
118
  text: string;
71
119
  };
120
+ export type PointerPhase = 'down' | 'move' | 'up' | 'cancel';
121
+ export type PointerKind = 'mouse' | 'pen' | 'touch';
122
+ /** Bits of a pointer or wheel event's `modifiers`. */
123
+ export declare const MODIFIERS: {
124
+ readonly shift: 1;
125
+ readonly ctrl: 2;
126
+ readonly alt: 4;
127
+ readonly meta: 8;
128
+ };
129
+ /**
130
+ * What the scene takes from the pointer while a control is enabled (0060). A source stops the
131
+ * host's default handling (`preventDefault`) only for what's listed here and for claimed pointers;
132
+ * everything else passes through to the page.
133
+ */
134
+ export interface PointerPolicy {
135
+ /** Mouse buttons enabled controls drag with: presses with them, and the context menu for 'right'. */
136
+ buttons: readonly MouseButton[];
137
+ /** Wheel events zoom a control. */
138
+ wheel: boolean;
139
+ /** Touches drive a control: the element gets `touch-action: none`. */
140
+ touch: boolean;
141
+ }
72
142
  /** Where raw input comes from: DOM listeners in a browser or webview, nothing when headless. */
73
143
  export interface InputSource {
74
144
  /** Appends events since the last drain (and polls devices like gamepads). */
75
145
  drain(out: RawInputEvent[]): void;
146
+ /**
147
+ * Calls `listener` whenever an event arrives, so an on-demand app wakes to drain it (0052).
148
+ * Returns an unsubscribe function. Polled devices (gamepads) don't call it.
149
+ */
150
+ onInput?(listener: () => void): () => void;
151
+ /**
152
+ * A consumer took this pointer's gesture (0060): its later events are the scene's
153
+ * (`preventDefault`), and it keeps reporting outside the element (pointer capture) until it ends.
154
+ */
155
+ claimPointer?(id: number): void;
156
+ /** What enabled controls take; see `PointerPolicy`. Called when it changes. */
157
+ setPointerPolicy?(policy: PointerPolicy): void;
76
158
  dispose(): void;
77
159
  }
78
160
  export type FileChangeKind = 'create' | 'modify' | 'remove';
@@ -194,6 +276,11 @@ export interface AudioBackend {
194
276
  readonly state: AudioContextState;
195
277
  /** Returns an id for `update` and `stop`. */
196
278
  play(voice: AudioVoiceDesc): number;
279
+ /**
280
+ * Gets a clip ready to play (a browser decodes it), so its first play starts on time instead of
281
+ * starting late into the clip. Optional: backends with nothing to prepare leave it out.
282
+ */
283
+ preload?(clip: AudioClipSource): void;
197
284
  update(voice: number, params: AudioVoiceParams): void;
198
285
  /** Stops a voice, fading out over `fade` seconds (default: at once). */
199
286
  stop(voice: number, fade?: number): void;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./workers.js";
2
+ const MODIFIERS = { shift: 1, ctrl: 2, alt: 4, meta: 8 };
2
3
  function createMemoryStorage() {
3
4
  const data = /* @__PURE__ */ new Map();
4
5
  return {
@@ -12,5 +13,6 @@ function createMemoryStorage() {
12
13
  };
13
14
  }
14
15
  export {
16
+ MODIFIERS,
15
17
  createMemoryStorage
16
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aethervtt/shard-platform",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,7 +16,7 @@
16
16
  "README.md"
17
17
  ],
18
18
  "dependencies": {
19
- "@aethervtt/shard-core": "0.0.1"
19
+ "@aethervtt/shard-core": "0.1.0"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -28,6 +28,6 @@
28
28
  "provenance": true
29
29
  },
30
30
  "shard": {
31
- "buildSha": "d6c5c6aef4675575c878b02cf2c8f738b4190229"
31
+ "buildSha": "8e14c9896f82a3554b156f1ffdd68f2cc3e7d78a"
32
32
  }
33
33
  }