@mica-js/widget 0.2.3 → 0.3.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
@@ -1,13 +1,12 @@
1
- import { CanvasBindingCatalog } from '@mica-js/core/canvas';
2
- import { CanvasCommand } from '@mica-js/core/canvas';
3
- import { CanvasDocument } from '@mica-js/core/canvas';
4
- import { DeliveryKind } from '@mica-js/core/canvas';
5
- import { DeviceSimulationHost } from '@mica-js/simulator';
1
+ import { CanvasBindingTarget } from '@mica-js/document/canvas';
2
+ import { DeliveryKind } from '@mica-js/document/canvas';
6
3
  import { Disposable } from '@mica-js/core/lifecycle';
7
4
  import { Event as Event_2 } from '@mica-js/core/lifecycle';
8
- import { PayloadType } from '@mica-js/core/canvas';
5
+ import { PayloadType } from '@mica-js/document/canvas';
6
+ import { RpcServiceId } from '@mica-js/core/rpc';
9
7
  import { SandboxWorker } from '@mica-js/sandbox';
10
8
  import { SandboxWorkerOptions } from '@mica-js/sandbox';
9
+ import { TimePs } from '@mica-js/core';
11
10
 
12
11
  /**
13
12
  * Loads every package up front and indexes its widgets under `<packageId>:<widgetId>`.
@@ -23,32 +22,28 @@ export declare function createStaticWidgetProvider(modules: Readonly<Record<stri
23
22
  /**
24
23
  * Loads the packaged processor into `context` and creates its node.
25
24
  *
26
- * Pass it as `getAudioWorklet` wherever a `WidgetHost` or `CanvasEditor` asks for one; hosts that
27
- * provide no loader of their own use the same processor internally.
25
+ * Pass it as `WidgetAudioOptions.getAudioWorklet`; runtimes that provide no loader of their
26
+ * own use the same processor internally.
28
27
  */
29
28
  export declare function createWidgetAudioWorklet(context: AudioContext): Promise<AudioWorkletNode>;
30
29
 
31
30
  /**
32
- * Creates the widget host.
31
+ * Creates the widget host guest worker.
33
32
  *
34
- * The document is the single source of truth: instances are mounted, resized, repropped and
35
- * reordered to match it. The sandbox starts lazily on the first instance and every concurrent mount
36
- * shares that one startup, so a host with no instances never pays for an iframe and a worker. After
37
- * a crash the next reconciliation starts a fresh sandbox instead of rebuilding instances
38
- * automatically.
33
+ * Hosts start the guest, then wire its RPC surface with `createWidgetSandboxFromWorker`.
39
34
  */
40
- export declare function createWidgetHost(options: WidgetHostOptions, createSandbox: WidgetSandboxFactory): WidgetHost;
35
+ export declare function createWidgetHostGuestSandbox(options?: SandboxWorkerOptions): SandboxWorker;
41
36
 
42
37
  /**
43
- * Creates the widget host guest worker.
38
+ * Creates the widget runtime over an existing sandbox.
44
39
  *
45
- * This is the guest `WidgetHost` talks to, and it is the same one `@mica-js/canvas-editor`'s
46
- * `SandboxHostProvider` starts by default. Hosts only start it; the RPC surface is wired by
47
- * `createWidgetSandboxFromWorker`.
40
+ * The runtime owns the sandbox: `dispose()` terminates it, so the caller must not keep using it
41
+ * afterwards. The runtime never reads documents or files, resolves widget modules, drives a clock
42
+ * or talks to a device runtime; those stay with the editor that calls it.
48
43
  */
49
- export declare function createWidgetHostGuestSandbox(options?: SandboxWorkerOptions): SandboxWorker;
44
+ export declare function createWidgetRuntime(sandbox: WidgetSandbox, options?: IWidgetRuntimeOptions): IWidgetRuntime;
50
45
 
51
- /** Adapts a provider-created widget worker to WidgetHost's RPC-facing surface. */
46
+ /** Adapts a provider-created widget worker to the runtime's RPC-facing surface. */
52
47
  export declare function createWidgetSandboxFromWorker(worker: SandboxWorker, options: WidgetSandboxHostOptions): Promise<WidgetSandbox>;
53
48
 
54
49
  /**
@@ -118,12 +113,190 @@ export declare interface HostFsErrorPayload {
118
113
  readonly message?: string;
119
114
  }
120
115
 
116
+ /**
117
+ * Everything the runtime needs to mount one instance.
118
+ *
119
+ * The editor already resolved the module through its own widget library and owns the placement:
120
+ * the runtime receives no document, rotation, drawing order or bindings at mount time.
121
+ */
122
+ export declare interface IPreparedWidgetInstance {
123
+ readonly instanceId: string;
124
+ /** Widget reference: `<packageId>:<widgetId>`. */
125
+ readonly widget: string;
126
+ /** Definition and implementation source, resolved by the caller. */
127
+ readonly module: WidgetModule;
128
+ readonly width: number;
129
+ readonly height: number;
130
+ readonly dpr: number;
131
+ readonly properties?: Readonly<Record<string, unknown>>;
132
+ /** Prefetched bytes keyed by `WidgetAssetRef.src`; the runtime never reads a file system. */
133
+ readonly assets?: Readonly<Record<string, Uint8Array>>;
134
+ }
135
+
121
136
  /** Whether `uri` carries a scheme, i.e. is absolute rather than a relative reference. */
122
137
  export declare function isAbsoluteHostUri(uri: string): boolean;
123
138
 
124
139
  /** Narrows an unknown rejection to a `HostFsError` created in this realm. */
125
140
  export declare function isHostFsError(value: unknown): value is HostFsError;
126
141
 
142
+ /** One committed frame of one instance. */
143
+ export declare interface IWidgetFrame {
144
+ readonly instanceId: string;
145
+ readonly width: number;
146
+ readonly height: number;
147
+ readonly dpr: number;
148
+ /**
149
+ * The bitmap belongs to the runtime: it stays valid until the next frame of the same instance,
150
+ * its unmount or runtime disposal. A consumer that needs it longer has to copy it.
151
+ */
152
+ readonly bitmap: ImageBitmap;
153
+ /** Increments with every frame, so a consumer can tell a repaint from a cached frame. */
154
+ readonly sequence: number;
155
+ }
156
+
157
+ /** Clock context the caller hands to {@link IWidgetRuntime.step}. */
158
+ export declare interface IWidgetFrameContext {
159
+ /** Simulation time after the step, in picoseconds. */
160
+ readonly simTime: TimePs;
161
+ /** Length of the step, in picoseconds. */
162
+ readonly dt: TimePs;
163
+ readonly mode: WidgetRuntimeMode;
164
+ }
165
+
166
+ /** One-time guest configuration applied before the first mount. */
167
+ export declare interface IWidgetGuestRuntimeConfig {
168
+ /**
169
+ * Removes the guest's automatic repaint scheduling: an `invalidate()` only marks the instance
170
+ * dirty, and the next {@link IWidgetGuestStep} paints it.
171
+ */
172
+ readonly explicitStepping?: boolean;
173
+ /** Contract behind the direct port; defaults to `simulation-runtime` at first use. */
174
+ readonly directTopicService?: WidgetDirectTopicService;
175
+ }
176
+
177
+ /** Caller-supplied time of one widget step. */
178
+ export declare interface IWidgetGuestStep {
179
+ /** Simulation time after the step, in picoseconds. */
180
+ readonly simTime: TimePs;
181
+ /** Length of the step, in picoseconds. */
182
+ readonly dt: TimePs;
183
+ /** Editor mode; widgets keep running in both, the caller decides what advances. */
184
+ readonly mode: 'edit' | 'simulation';
185
+ }
186
+
187
+ /** Fields `update` may change after mount; omitted fields stay as they are. */
188
+ export declare interface IWidgetInstanceUpdate {
189
+ readonly properties?: Readonly<Record<string, unknown>>;
190
+ readonly width?: number;
191
+ readonly height?: number;
192
+ readonly dpr?: number;
193
+ readonly assets?: Readonly<Record<string, Uint8Array>>;
194
+ }
195
+
196
+ /** One payload crossing the instance boundary in either direction. */
197
+ export declare interface IWidgetMessage {
198
+ readonly instanceId: string;
199
+ readonly port: string;
200
+ readonly payload: unknown;
201
+ /** Simulation time in picoseconds. */
202
+ readonly simTime: TimePs;
203
+ /**
204
+ * Set when the guest already handed the publish to the simulation runtime over the direct port.
205
+ * Observers of `onDidPublish` must not route such a message a second time.
206
+ */
207
+ readonly direct?: true;
208
+ }
209
+
210
+ /**
211
+ * Instance execution without document, library, file system, clock or device ownership.
212
+ *
213
+ * The caller mounts prepared instances, advances time with {@link step}, and decides how publishes
214
+ * reach the simulation. The runtime owns its sandbox: {@link dispose} terminates it.
215
+ */
216
+ export declare interface IWidgetRuntime extends IWidgetRuntimeRouting {
217
+ /** Fire-and-observe publish lane; `direct` says the simulation already received the message. */
218
+ readonly onDidPublish: Event_2<IWidgetMessage>;
219
+ readonly onDidRender: Event_2<IWidgetFrame>;
220
+ /** Isolated widget, audio and sandbox failures; they never reject another instance's work. */
221
+ readonly onDidDiagnostic: Event_2<IWidgetRuntimeDiagnostic>;
222
+ mount(instance: IPreparedWidgetInstance): Promise<void>;
223
+ update(instanceId: string, update: IWidgetInstanceUpdate): Promise<void>;
224
+ unmount(instanceId: string): Promise<void>;
225
+ /**
226
+ * Queues one payload for an input port until the next {@link step}.
227
+ *
228
+ * Rejects immediately when the instance is not mounted, the port is unknown, its direction is not
229
+ * `input`, or the payload does not match the declared type. Accepted messages resolve once queued.
230
+ */
231
+ deliver(message: IWidgetMessage): Promise<void>;
232
+ /** Queues one pointer or keyboard event until the next {@link step}. */
233
+ dispatch(instanceId: string, event: WidgetInputEvent): Promise<void>;
234
+ /**
235
+ * Flushes queued input, then advances the guest to the supplied time.
236
+ *
237
+ * Paints deferred by explicit stepping are committed before this resolves, and direct
238
+ * widget → simulation deliveries started by the step settle before it resolves.
239
+ */
240
+ step(context: IWidgetFrameContext): Promise<void>;
241
+ /** Audio controls for every instance; the no-op surface when no options were supplied. */
242
+ readonly audio: WidgetAudioControls;
243
+ /** Clears bitmaps, audio sessions, queued traffic and terminates the owned sandbox. */
244
+ dispose(): Promise<void>;
245
+ }
246
+
247
+ /** A failure contained to one instance, one publish or the sandbox as a whole. */
248
+ export declare interface IWidgetRuntimeDiagnostic {
249
+ readonly code: IWidgetRuntimeDiagnosticCode;
250
+ readonly message: string;
251
+ readonly phase: IWidgetRuntimeDiagnosticPhase;
252
+ readonly instanceId?: string;
253
+ readonly widget?: string;
254
+ readonly port?: string;
255
+ }
256
+
257
+ export declare type IWidgetRuntimeDiagnosticCode = 'widget/runtime-failed' | 'widget/mount-failed' | 'widget/update-failed' | 'widget/unmount-failed' | 'widget/render-failed' | 'widget/deliver-failed' | 'widget/publish-rejected' | 'widget/asset-failed' | 'widget/audio-failed' | 'widget/audio-limit' | 'widget/step-failed';
258
+
259
+ export declare type IWidgetRuntimeDiagnosticPhase = 'runtime' | 'mount' | 'update' | 'unmount' | 'render' | 'deliver' | 'publish' | 'asset' | 'audio' | 'step';
260
+
261
+ export declare interface IWidgetRuntimeOptions {
262
+ /** Enables `api.audio`; the caller keeps ownership of the `AudioContext`. */
263
+ readonly audio?: WidgetAudioOptions;
264
+ }
265
+
266
+ /**
267
+ * Narrow configuration of the routes the editor produced.
268
+ *
269
+ * The runtime does not validate bindings against a document: the editor owns the binding model and
270
+ * hands over the endpoint map it already checked.
271
+ */
272
+ export declare interface IWidgetRuntimeRouting {
273
+ setBindings(instanceId: string, bindings: Readonly<Record<string, CanvasBindingTarget>>): Promise<void>;
274
+ }
275
+
276
+ /** One publish the editor simulation runtime sends over the direct port. */
277
+ export declare interface IWidgetSimulationPublish {
278
+ readonly target: CanvasBindingTarget;
279
+ readonly payload: unknown;
280
+ /** Simulation time the publish belongs to, in picoseconds. */
281
+ readonly simTime: TimePs;
282
+ }
283
+
284
+ /**
285
+ * The slice of the editor simulation runtime the guest reaches over the direct port.
286
+ *
287
+ * The editor registers this service on the device worker (or an in-process simulation) under the
288
+ * `simulation-runtime` id and transfers the other end of the port to this guest. The contract is
289
+ * declared locally on purpose: the widget package must not depend on the simulator implementation
290
+ * to state the wire shape. `deliver` takes the same `{ target, payload, simTime }` message that
291
+ * `onDidPublish` reports.
292
+ */
293
+ export declare interface IWidgetSimulationRuntimeChannel {
294
+ /** Queues one message for a device endpoint; consumed by the simulation's next step. */
295
+ deliver(message: IWidgetSimulationPublish): Promise<void>;
296
+ /** Subscribes to simulation publishes; the guest fans them out to its bound instances. */
297
+ onDidPublish(listener: (publish: IWidgetSimulationPublish) => void): () => void;
298
+ }
299
+
127
300
  /**
128
301
  * Reads a package manifest, every declared widget definition and its paired implementation.
129
302
  * Only the three declared path kinds are read; the package is never enumerated.
@@ -258,7 +431,7 @@ export declare interface WidgetAudioApi {
258
431
  createStream(options: WidgetAudioStreamOptions): WidgetAudioStream;
259
432
  }
260
433
 
261
- /** `WidgetHost.audio` — controls every instance of one widget host. */
434
+ /** `IWidgetRuntime.audio` controls every instance owned by the runtime. */
262
435
  export declare interface WidgetAudioControls {
263
436
  /** Mirror of the state the guest reads from `api.audio.state`. */
264
437
  readonly state: WidgetAudioState;
@@ -298,7 +471,7 @@ export declare interface WidgetAudioLimits {
298
471
  }
299
472
 
300
473
  /**
301
- * Host audio configuration for `createWidgetHost` (RFC 0016).
474
+ * Audio configuration for `createWidgetRuntime` (RFC 0016).
302
475
  *
303
476
  * Omit it and `api.audio.state` is `unavailable`: every method still returns a usable handle, but
304
477
  * nothing is ever played.
@@ -307,7 +480,7 @@ export declare interface WidgetAudioLimits {
307
480
  readonly context: AudioContext;
308
481
  /** Where the host's master gain ends up; defaults to `context.destination`. */
309
482
  readonly destination?: AudioNode;
310
- /** Creates the worklet node after the host has created the context. */
483
+ /** Creates the worklet node using the caller-owned context. */
311
484
  readonly getAudioWorklet?: (context: AudioContext) => Promise<AudioWorkletNode>;
312
485
  /** Tightens the defaults (8 voices, 4 PCM streams per instance). */
313
486
  readonly limits?: Partial<WidgetAudioLimits>;
@@ -431,6 +604,12 @@ export declare interface WidgetBinding {
431
604
  readonly port: string;
432
605
  }
433
606
 
607
+ /**
608
+ * Configures explicit stepping and connects the direct simulation-runtime port before mounting.
609
+ * Without explicit stepping the standalone guest retains automatic repaint scheduling.
610
+ */
611
+ export declare const widgetConfigureMethod = "configure";
612
+
434
613
  export declare interface WidgetDefinition {
435
614
  readonly properties: Readonly<Record<string, PropertyDefinition_2>>;
436
615
  readonly ports: Readonly<Record<string, PortDefinition>>;
@@ -455,6 +634,9 @@ export declare interface WidgetDiagnostic {
455
634
 
456
635
  export declare type WidgetDiagnosticCode = 'widget/runtime-failed' | 'widget/unknown-widget' | 'widget/instance-exists' | 'widget/instance-not-found' | 'widget/mount-failed' | 'widget/binding-failed' | 'widget/render-failed' | 'widget/deliver-failed' | 'widget/asset-failed' | 'widget/audio-failed' | 'widget/audio-limit';
457
636
 
637
+ /** Service the guest reaches over the transferred direct port. */
638
+ export declare type WidgetDirectTopicService = 'simulation-runtime';
639
+
458
640
  /** Default export of a widget implementation module. */
459
641
  export declare type WidgetFactory = (api: WidgetInstanceApi) => WidgetImplementation | void;
460
642
 
@@ -467,183 +649,6 @@ export declare type WidgetFactory = (api: WidgetInstanceApi) => WidgetImplementa
467
649
  */
468
650
  export declare const widgetGuestScript: string;
469
651
 
470
- export declare interface WidgetHost {
471
- /**
472
- * Snapshot the host currently coordinates: the last document accepted by `loadDocument` or
473
- * `applyCommand`. Starts as the empty document `{ version: 1, widgets: [] }`.
474
- *
475
- * Every call returns the current value, so a long-lived reference stays live.
476
- */
477
- getDocument(): CanvasDocument;
478
- /**
479
- * Commits a document and mounts the instances it lists.
480
- *
481
- * Accepts an already parsed `CanvasDocument`, or the absolute URI of a `.cnv` resource. The URI
482
- * form reads the bytes through `WidgetHostOptions.fs` (a `data:` URI is decoded locally),
483
- * decodes them as UTF-8 text, parses with `parseCanvas`, and then runs the same validation and
484
- * mount flow as the parsed form.
485
- *
486
- * The document's `schematic` is resolved against the document URI and loaded through
487
- * `deviceHost` before any instance mounts (RFC 0018 step 2), regardless of the current host mode.
488
- *
489
- * Resolves once the instances of this first pass finished mounting. A widget that fails to mount
490
- * is reported through `onDiagnostic` and left out of `getLayers()` instead of rejecting this
491
- * promise.
492
- *
493
- * Binding endpoint and type diagnostics skip only the affected instances and are reported through
494
- * `onDiagnostic`; valid instances still mount. Schema, schematic-loading, and other document-level
495
- * errors reject the call and leave the previous document and instances unchanged.
496
- * @throws {HostFsError} when reading the URI fails, or when no `fs` is configured for a
497
- * non-`data:` URI.
498
- * @throws {TypeError} when the URI is relative or a `data:` URI is malformed.
499
- * @throws whatever `DeviceSimulationHost.loadSchematic` rejects with when a device host is configured;
500
- * the document and the instances keep the state they had before the call.
501
- */
502
- loadDocument(document: CanvasDocument): Promise<void>;
503
- loadDocument(uri: string): Promise<void>;
504
- /**
505
- * Applies one command to the current document.
506
- *
507
- * The new snapshot and the `onDocumentChange` notification happen synchronously; coordinating
508
- * instances runs in the background and never rolls the document back. A rejected command leaves
509
- * both the document and the instances untouched.
510
- *
511
- * Binding endpoint and type diagnostics skip only affected instances and are reported through
512
- * `onDiagnostic`; other invalid commands and document-level diagnostics still throw.
513
- */
514
- applyCommand(command: CanvasCommand): void;
515
- /** Current widget runtime mode; only `simulation` advances the device host. */
516
- getMode(): WidgetHostMode;
517
- /** Switches widget runtime modes and resets the device and widget state. */
518
- setMode(mode: WidgetHostMode): Promise<void>;
519
- /** Subscribes to committed snapshots; returns the unsubscribe function. */
520
- onDocumentChange(listener: (document: CanvasDocument) => void): () => void;
521
- /**
522
- * Drops every instance and mounts the current document again, so widgets restart from their
523
- * initial state. Layers are emptied and repopulated.
524
- *
525
- * With a URI-loaded document this re-executes `loadDocument`: the bytes are read and parsed
526
- * again, and the document's schematic is handed to the device host once more, so the simulation
527
- * does not keep the state of a killed widget.
528
- *
529
- * Each mount runs the widget factory again (fresh closure, canvas and subscriptions, initial
530
- * props), but the guest keeps its module cache: a widget module is evaluated once per session.
531
- * Module-level state is therefore not reset — the contract puts instance state in the factory.
532
- *
533
- * Resolves once every instance of the current document has mounted again. Failures are reported
534
- * through `onDiagnostic` instead of rejecting, like every other coordination step.
535
- */
536
- reset(): Promise<void>;
537
- deliver(instanceId: string, port: string, payload: unknown, simTime: number): void;
538
- /**
539
- * Hands one input event to an instance.
540
- *
541
- * The event is queued and dispatched at the start of the next step (RFC 0018).
542
- */
543
- dispatch(instanceId: string, event: WidgetInputEvent): void;
544
- /** Bulk instance projection in drawing order; carries no bitmaps. */
545
- listInstances(): readonly WidgetInstance[];
546
- /** Fires once the instance is mounted, with its complete state. */
547
- readonly onDidAddWidget: Event_2<Widget>;
548
- /** Fires when geometry, properties, bindings, the pixel ratio or the bitmap changed. */
549
- readonly onDidChangeWidget: Event_2<Widget>;
550
- /** Fires when an instance is unloaded; the payload is the `instanceId`. */
551
- readonly onDidRemoveWidget: Event_2<string>;
552
- /** Fires with the new drawing order; the elements are `instanceId`s. */
553
- readonly onDidReorderWidgets: Event_2<readonly string[]>;
554
- /** Requests a full sync: every instance is reported as removed and then added, in current order. */
555
- invalidate(): void;
556
- /** Bitmaps in document order; the same store for the lifetime of the host. */
557
- getLayers(): WidgetLayers;
558
- /** Changes the device pixel ratio of every layer and repaints all instances. */
559
- resize(dpr: number): void;
560
- /** Freezes the frame clock; the document and the instances stay untouched. */
561
- pause(): void;
562
- /** Resumes the frame clock and re-times it from now. */
563
- resume(): void;
564
- /**
565
- * Audio controls for every instance (RFC 0016). Without `WidgetHostOptions.audio` the state stays
566
- * `unavailable` and the controls are no-ops.
567
- */
568
- readonly audio: WidgetAudioControls;
569
- /** Terminates the sandbox and closes every bitmap. */
570
- dispose(): Promise<void>;
571
- }
572
-
573
- /**
574
- * Frame clock policy. The host decides how much one frame advances; the backlog of a stalled frame
575
- * is dropped instead of being simulated later.
576
- */
577
- export declare interface WidgetHostFrameOptions {
578
- /** Length of one fixed step, in milliseconds. Defaults to 25 ms. */
579
- readonly stepMs?: number;
580
- /** Frame scheduler; the default uses `setTimeout` with the configured step duration. */
581
- readonly requestFrame?: (callback: () => void) => () => void;
582
- }
583
-
584
- export declare type WidgetHostMode = 'edit' | 'simulation';
585
-
586
- export declare interface WidgetHostOptions {
587
- /** Widget definitions and implementations (RFC 0014). Required together with {@link provider}. */
588
- readonly widgetProvider?: WidgetProvider;
589
- /** @deprecated Use {@link widgetProvider}. */
590
- readonly provider?: WidgetProvider;
591
- /**
592
- * Simulation runtime kept loaded by the widget host in both edit and simulation modes.
593
- */
594
- readonly deviceHost: DeviceSimulationHost;
595
- /** Initial runtime mode. Defaults to `simulation`. */
596
- readonly mode?: WidgetHostMode;
597
- /**
598
- * Reads the bytes of a document URI for `loadDocument(uri)`. `data:` URIs are decoded locally
599
- * and never reach `fs`; without this option only `data:` URIs and the parsed-document form work.
600
- */
601
- readonly fs?: HostFs;
602
- readonly container?: HTMLElement;
603
- /** Device pixel ratio for new layers. Defaults to `devicePixelRatio`, or 1 outside a browser. */
604
- readonly dpr?: number;
605
- /** Receives failures that must not interrupt the caller. */
606
- readonly onDidReportDiagnostic?: (diagnostic: WidgetDiagnostic) => void;
607
- /** @deprecated Use {@link onDidReportDiagnostic}. */
608
- readonly onDiagnostic?: (diagnostic: WidgetDiagnostic) => void;
609
- /** Receives port payloads published by widgets outside every binding. */
610
- readonly onDidPublish?: (publish: WidgetPublish) => void;
611
- /** @deprecated Use {@link onDidPublish}. */
612
- readonly onPublish?: (publish: WidgetPublish) => void;
613
- /** Frame clock policy. */
614
- readonly frame?: WidgetHostFrameOptions;
615
- /**
616
- * Prefetches image / binary property values when an instance mounts. Without it nothing is
617
- * prefetched and `api.assets.readBinary` rejects.
618
- */
619
- readonly assets?: WidgetAssetProvider;
620
- /**
621
- * Overrides the binding catalog the host assembles itself (RFC 0018).
622
- *
623
- * By default the host validates every `loadDocument` / `applyCommand` against the definitions
624
- * resolved through `widgetProvider`, the endpoints `deviceHost.getTopics()` reports when a device
625
- * host is configured, and the schematic the device host loaded.
626
- *
627
- * Pass a catalog to validate against a different registry — for example a static list of
628
- * endpoints before a simulation exists.
629
- */
630
- readonly catalog?: CanvasBindingCatalog;
631
- /**
632
- * One end of the direct device channel between the widget guest and the device guest (RFC 0018).
633
- *
634
- * Handed to the first sandbox the host starts and never reused: a guest restarted after a crash
635
- * runs without it, and the host relays topic traffic as before.
636
- */
637
- readonly devicePort?: MessagePort;
638
- /**
639
- * Enables `api.audio`. Without it every widget sees `api.audio.state === 'unavailable'`.
640
- *
641
- * The host never closes the `AudioContext`: the caller keeps ownership, including the user
642
- * gesture that unlocks it.
643
- */
644
- readonly audio?: WidgetAudioOptions;
645
- }
646
-
647
652
  /**
648
653
  * Object a widget factory may return. Every hook is optional, so a pure-logic widget can return
649
654
  * nothing at all; an instance without `render` still produces one blank frame per repaint.
@@ -797,6 +802,23 @@ export declare interface WidgetPublish {
797
802
  readonly simTime: number;
798
803
  }
799
804
 
805
+ /**
806
+ * Typed rejection of one runtime call.
807
+ *
808
+ * Widget boundary failures (render, input, publish) become diagnostics instead; errors with this
809
+ * type mean the caller asked for something the runtime cannot do.
810
+ */
811
+ export declare class WidgetRuntimeError extends Error {
812
+ readonly code: WidgetRuntimeErrorCode;
813
+ constructor(code: WidgetRuntimeErrorCode, message: string, options?: ErrorOptions);
814
+ }
815
+
816
+ /** Rejections the widget runtime produces before or around the guest boundary. */
817
+ export declare type WidgetRuntimeErrorCode = 'widget/disposed' | 'widget/instance-exists' | 'widget/unknown-instance' | 'widget/unknown-port' | 'widget/invalid-instance' | 'widget/invalid-update' | 'widget/invalid-payload' | 'widget/invalid-direction' | 'widget/invalid-time' | 'widget/invalid-step' | 'widget/sandbox-failed';
818
+
819
+ /** Mode the editor is in when it asks for a step. */
820
+ export declare type WidgetRuntimeMode = 'edit' | 'simulation';
821
+
800
822
  /**
801
823
  * Minimal sandbox surface the host depends on. The default implementation wraps
802
824
  * `@mica-js/sandbox` through `SandboxWorker` plus a typed RPC adapter; tests inject a fake with the same shape.
@@ -810,9 +832,8 @@ export declare interface WidgetSandbox {
810
832
  /** Host → guest audio lane; without it `api.audio` stays `unavailable`. */
811
833
  readonly audio?: WidgetSandboxAudio;
812
834
  /**
813
- * The guest holds the direct device channel (RFC 0018), so it delivers widget publishes to the
814
- * device guest and fans device publishes out to its instances itself. The host then keeps the
815
- * binding map, the level cache and the diagnostics, and stops relaying topic traffic.
835
+ * The guest holds a direct simulation-runtime channel and routes bound topic traffic itself.
836
+ * Observers must not relay publishes marked as direct a second time.
816
837
  */
817
838
  readonly directDevice?: boolean;
818
839
  terminate(reason?: string): Promise<void>;
@@ -839,10 +860,24 @@ export declare interface WidgetSandboxHostOptions {
839
860
  /**
840
861
  * One end of the direct device channel, transferred to the guest with its first message.
841
862
  *
842
- * A port can be transferred once, so the host hands it to the first sandbox it starts; a sandbox
843
- * started after a crash runs without one and the host relays topic traffic again.
863
+ * A port can be transferred once. A replacement sandbox needs a fresh port; without one the
864
+ * caller routes topic traffic through the runtime events.
844
865
  */
845
866
  readonly devicePort?: MessagePort;
846
867
  }
847
868
 
869
+ /** Replaces the prefetched bytes of one mounted instance without remounting it. */
870
+ export declare const widgetSetAssetsMethod = "set-assets";
871
+
872
+ /** Wire name of {@link IWidgetSimulationRuntimeChannel}. */
873
+ export declare const widgetSimulationRuntimeService: RpcServiceId<IWidgetSimulationRuntimeChannel>;
874
+
875
+ /**
876
+ * Advances the guest to a caller-supplied time.
877
+ *
878
+ * The editor owns the clock: it delivers the same step to widgets and devices, so the guest must
879
+ * not schedule time-bound work on its own.
880
+ */
881
+ export declare const widgetStepMethod = "step";
882
+
848
883
  export { }