@mica-js/editor 0.3.3 → 0.4.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/README.md +96 -1
- package/dist/fused-html.d.ts +849 -0
- package/dist/fused-html.js +1 -0
- package/dist/fused-runtime.d.ts +685 -0
- package/dist/fused-runtime.js +3 -0
- package/dist/fused.d.ts +537 -0
- package/dist/fused.js +6725 -0
- package/dist/fused.js.map +1 -0
- package/dist/html-HXwZq1my.js +1618 -0
- package/dist/html-HXwZq1my.js.map +1 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +174 -280
- package/dist/index.js.map +1 -1
- package/dist/runtime-CXYJzbbj.js +1739 -0
- package/dist/runtime-CXYJzbbj.js.map +1 -0
- package/dist/style.css +1486 -0
- package/dist/view-environment/content.html +36 -0
- package/dist/view-environment/content.js +666 -0
- package/dist/view-environment/environment-sw.js +632 -0
- package/dist/view-environment/environment.js +783 -0
- package/dist/view-environment/index.html +32 -0
- package/dist/wire-BDHL5Aj9.js +183 -0
- package/dist/wire-BDHL5Aj9.js.map +1 -0
- package/dist/wire-JZIiIOI0.js +260 -0
- package/dist/wire-JZIiIOI0.js.map +1 -0
- package/dist/workers-BsocIPUc.js +34 -0
- package/dist/workers-BsocIPUc.js.map +1 -0
- package/package.json +41 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { y as ASSET_ROOT_DIRECTORY, s as DEFAULT_HTML_VIEW_THEME, b as ENVIRONMENT_BOOTSTRAP_FILE, x as ENVIRONMENT_CONTENT_DOCUMENT_FILE, S as ENVIRONMENT_CONTENT_FILE, C as ENVIRONMENT_DOCUMENT_FILE, w as ENVIRONMENT_WORKER_FILE, L as HTML_VIEW_ACK, R as HTML_VIEW_ASSETS, z as HTML_VIEW_ASSETS_ACK, B as HTML_VIEW_ATTACH, V as HTML_VIEW_ATTACH_ACK, H as HTML_VIEW_CHILD_CONNECT, U as HTML_VIEW_CHILD_HELLO, W as HTML_VIEW_CHILD_PREPARED, G as HTML_VIEW_CONNECT, T as HTML_VIEW_CONTENT_POLICY, E as HTML_VIEW_ENVIRONMENT_POLICY, K as HTML_VIEW_FRAME_PARAM, q as HtmlViewError, N as VIEW_ENV_LABEL, c as applyHtmlViewTheme, t as assertAssetPath, D as assetRootUrl, O as authorBaseUrl, n as createDeviceViewSession, a as createHtmlViewHost, r as createHtmlViewRuntimeSource, k as decodeDocument, J as fusedHtmlAssetService, Y as fusedHtmlContentViewService, X as fusedHtmlHostControlService, Z as fusedHtmlHostService, P as htmlEnvironmentUrl, i as htmlViewDeviceDeclaration, o as htmlViewKey, l as htmlViewThemeCss, u as htmlViewThemeEquals, Q as isHtmlViewError, A as mimeTypeOf, F as newHtmlEnvironmentId, d as normalizeHtmlViewTheme, I as parseHtmlViewBase, j as resolveAssetRequest, M as withHtmlDocumentPreamble } from "./html-HXwZq1my.js";
|
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
import { DeviceLock } from '@mica-js/document/fused';
|
|
2
|
+
import { DeviceRegistry } from '@mica-js/document/fused';
|
|
3
|
+
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
4
|
+
import { WidgetAudioState as FusedAudioState } from '@mica-js/widget/audio-guest';
|
|
5
|
+
import { FusedDocument } from '@mica-js/document/fused';
|
|
6
|
+
import { Geometry2D } from '@mica-js/document/fused';
|
|
7
|
+
import { WidgetAudioControls as IFusedAudioControls } from '@mica-js/widget/audio-host';
|
|
8
|
+
import { WidgetAudioOptions as IFusedAudioOptions } from '@mica-js/widget/audio-host';
|
|
9
|
+
import { WidgetAudioStreamOptions as IFusedAudioStreamOptions } from '@mica-js/widget/audio-guest';
|
|
10
|
+
import { WidgetAudioTone as IFusedAudioTone } from '@mica-js/widget/audio-guest';
|
|
11
|
+
import { WidgetAudioToneOptions as IFusedAudioToneOptions } from '@mica-js/widget/audio-guest';
|
|
12
|
+
import { MemoryProgram } from '@mica-js/sdk/fused';
|
|
13
|
+
import { ModelEvent } from '@mica-js/sdk/fused';
|
|
14
|
+
import { PackageFile } from '@mica-js/document/fused';
|
|
15
|
+
import { Point2D } from '@mica-js/document/fused';
|
|
16
|
+
import { ProgramArtifact } from '@mica-js/sdk/fused';
|
|
17
|
+
import { ProgramFile } from '@mica-js/sdk/fused';
|
|
18
|
+
import { ProgramFiles } from '@mica-js/sdk/fused';
|
|
19
|
+
import { ProgramSources } from '@mica-js/sdk/fused';
|
|
20
|
+
import { ProgramTarget } from '@mica-js/sdk/fused';
|
|
21
|
+
import { ResourceRequest } from '@mica-js/sdk/fused';
|
|
22
|
+
import { ResourceResolver } from '@mica-js/sdk/fused';
|
|
23
|
+
import { RpcEndpoint } from '@mica-js/core/rpc';
|
|
24
|
+
import { RpcProxy } from '@mica-js/core/rpc';
|
|
25
|
+
import { RpcServiceId } from '@mica-js/core/rpc';
|
|
26
|
+
import { RuntimeDiagnostic } from '@mica-js/sdk/fused';
|
|
27
|
+
import { TimePs } from '@mica-js/core';
|
|
28
|
+
import { Value } from '@mica-js/document/fused';
|
|
29
|
+
import { WidgetAudioApi } from '@mica-js/widget/audio-guest';
|
|
30
|
+
import { WidgetAudioStream } from '@mica-js/widget/audio-guest';
|
|
31
|
+
import { WidgetAudioStreamStatus } from '@mica-js/widget/audio-guest';
|
|
32
|
+
|
|
33
|
+
export declare function channelKey(instanceId: string, event: string): string;
|
|
34
|
+
|
|
35
|
+
/** Browser-owned audio engine; the guest only receives session tokens and a worklet port. */
|
|
36
|
+
declare function connectFusedAudio(rpc: RpcEndpoint, display: Pick<RpcProxy<IFusedDisplayService>, 'attachAudio' | 'setAudioState'>, options: IFusedAudioOptions | undefined, report: (diagnostic: RuntimeDiagnostic) => void): IFusedAudioControls & {
|
|
37
|
+
clear(): void;
|
|
38
|
+
dispose(): void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Boots both guests of one workbench and wires their RPC surfaces. */
|
|
42
|
+
export declare function connectFusedWorkbench(options: IFusedConnectionOptions): Promise<IFusedConnection>;
|
|
43
|
+
|
|
44
|
+
export declare function createFusedDisplay(options: IFusedDisplayHostOptions): IFusedDisplayHost;
|
|
45
|
+
|
|
46
|
+
/** Creates the runtime bridge of one workbench from a document, a registry and a fixed step. */
|
|
47
|
+
export declare function createFusedRuntime(options: IFusedRuntimeOptions): Promise<IFusedRuntime>;
|
|
48
|
+
|
|
49
|
+
export declare function createHostModelRouter(proxy: RpcProxy<IFusedSimulationService>): IFusedHostModelRouter;
|
|
50
|
+
|
|
51
|
+
/** Registry implementation served by the host over `endpoint`. */
|
|
52
|
+
export declare function createHostPackageGateway(endpoint: RpcEndpoint): DeviceRegistry;
|
|
53
|
+
|
|
54
|
+
export declare function createModelEventRouter(channel: IFusedModelEventChannel): IFusedModelEventRouter;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Evaluates the presentation entry of one instance and initializes it.
|
|
58
|
+
*
|
|
59
|
+
* @throws {FusedBridgeError} when the module has no factory or `initialize` fails.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createViewSession(options: IFusedViewSessionOptions): Promise<IFusedViewSession>;
|
|
62
|
+
|
|
63
|
+
/** Rebuilds the failure of a rejected guest call; other errors pass through. */
|
|
64
|
+
export declare function fromWireFailure(cause: unknown): Error;
|
|
65
|
+
|
|
66
|
+
/** `name` of a failure whose message carries a {@link IFusedFailurePayload}. */
|
|
67
|
+
export declare const FUSED_WIRE_FAILURE = "FusedSandboxFailure";
|
|
68
|
+
|
|
69
|
+
/** Adapt the shared audio implementation's subscriptions to the editor lifecycle convention. */
|
|
70
|
+
export declare function fusedAudio(api: WidgetAudioApi): IFusedAudio;
|
|
71
|
+
|
|
72
|
+
export { FusedAudioState }
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Host-side failure of the fused sandbox bridge.
|
|
76
|
+
*
|
|
77
|
+
* Mirrors `FusedRuntimeError` (`code`, optional `instanceId`) and keeps the business payload of a
|
|
78
|
+
* model `MethodError` rejection. Guest code uses the same class to build the failure it throws.
|
|
79
|
+
*/
|
|
80
|
+
export declare class FusedBridgeError extends Error {
|
|
81
|
+
readonly code: string;
|
|
82
|
+
readonly instanceId: string | undefined;
|
|
83
|
+
readonly details: Value | undefined;
|
|
84
|
+
constructor(code: string, message: string, options?: IFusedBridgeErrorOptions);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Presentation mode of one workbench (RFC 0025). */
|
|
88
|
+
export declare type FusedDisplayMode = 'edit' | 'run';
|
|
89
|
+
|
|
90
|
+
/** Wire name of the 2D presentation guest. */
|
|
91
|
+
export declare const fusedDisplayService: RpcServiceId<IFusedDisplayService>;
|
|
92
|
+
|
|
93
|
+
/** Wire name of the host package access both guests use. */
|
|
94
|
+
export declare const fusedHostPackageService: RpcServiceId<IFusedHostPackageService>;
|
|
95
|
+
|
|
96
|
+
/** Wire name of the host resource access of the simulation guest. */
|
|
97
|
+
export declare const fusedHostResourceService: RpcServiceId<IFusedHostResourceService>;
|
|
98
|
+
|
|
99
|
+
/** Wire name of the model lane the simulation guest serves. */
|
|
100
|
+
export declare const fusedModelChannelService: RpcServiceId<IFusedModelChannelService>;
|
|
101
|
+
|
|
102
|
+
/** Declared event outlets of one model client. */
|
|
103
|
+
export declare type FusedModelEvents = Readonly<Record<string, Event_2<ModelEvent<Value>>>>;
|
|
104
|
+
|
|
105
|
+
/** Dynamic methods of one display-side model client; only declared names resolve. */
|
|
106
|
+
export declare type FusedModelMethods = Readonly<Record<string, (params: Value) => Promise<Value>>>;
|
|
107
|
+
|
|
108
|
+
/** Wire name of the model sink the display guest serves. */
|
|
109
|
+
export declare const fusedModelSinkService: RpcServiceId<IFusedModelSinkService>;
|
|
110
|
+
|
|
111
|
+
/** Read-only plain property snapshot handed to a 2D presentation. */
|
|
112
|
+
export declare type FusedPresentationProps = Readonly<Record<string, FusedPresentationValue>>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* One resolved property value a presentation may read.
|
|
116
|
+
*
|
|
117
|
+
* Scalars stay plain; `image` and `binary` properties are their resolved bytes; `firmware`
|
|
118
|
+
* properties are the loaded, segment-addressable snapshot. Resolution happens in the simulation
|
|
119
|
+
* worker, so an unresolved property rejects the presentation instead of shrinking its props.
|
|
120
|
+
*/
|
|
121
|
+
export declare type FusedPresentationValue = string | number | boolean | null | Uint8Array | IFusedFirmwareSnapshot | IFusedProgramFilesSnapshot;
|
|
122
|
+
|
|
123
|
+
declare type FusedResolvedPresentationProps = Readonly<Record<string, string | number | boolean | null | Uint8Array | MemoryProgram | ProgramFiles>>;
|
|
124
|
+
|
|
125
|
+
/** Session status the host mirrors; `idle` means no models are mounted (edit mode). */
|
|
126
|
+
export declare type FusedSessionStatus = 'idle' | 'paused' | 'running' | 'faulted' | 'disposed';
|
|
127
|
+
|
|
128
|
+
/** Wire name of the simulation guest. */
|
|
129
|
+
export declare const fusedSimulationService: RpcServiceId<IFusedSimulationService>;
|
|
130
|
+
|
|
131
|
+
export declare type FusedSurfaceFactory = (width: number, height: number) => IFusedOverlaySurface;
|
|
132
|
+
|
|
133
|
+
/** Default export of a `view2d.entry` module. */
|
|
134
|
+
export declare type FusedView2DFactory = (context: IFusedView2DContext) => IFusedView2D;
|
|
135
|
+
|
|
136
|
+
export declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
|
|
137
|
+
|
|
138
|
+
/** Audio handles belong to one instance generation, including while its body is hidden. */
|
|
139
|
+
export declare interface IFusedAudio extends Omit<WidgetAudioApi, 'onStateChange' | 'createStream'> {
|
|
140
|
+
readonly onDidChangeState: Event_2<FusedAudioState>;
|
|
141
|
+
createStream(options: Parameters<WidgetAudioApi['createStream']>[0]): IFusedAudioStream;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { IFusedAudioControls }
|
|
145
|
+
|
|
146
|
+
export { IFusedAudioOptions }
|
|
147
|
+
|
|
148
|
+
export declare interface IFusedAudioStream extends Omit<WidgetAudioStream, 'onDrain' | 'onStatus'> {
|
|
149
|
+
readonly onDidDrain: Event_2<void>;
|
|
150
|
+
readonly onDidChangeStatus: Event_2<WidgetAudioStreamStatus>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { IFusedAudioStreamOptions }
|
|
154
|
+
|
|
155
|
+
export { IFusedAudioTone }
|
|
156
|
+
|
|
157
|
+
export { IFusedAudioToneOptions }
|
|
158
|
+
|
|
159
|
+
export declare interface IFusedBridgeErrorOptions {
|
|
160
|
+
readonly instanceId?: string;
|
|
161
|
+
readonly details?: Value;
|
|
162
|
+
/**
|
|
163
|
+
* Error name. A method rejection keeps `MethodError`, so the SDK predicate of the consumer still
|
|
164
|
+
* recognizes it; every other failure keeps the default name.
|
|
165
|
+
*/
|
|
166
|
+
readonly name?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Two guests of one workbench plus the endpoints that reach them. */
|
|
170
|
+
export declare interface IFusedConnection {
|
|
171
|
+
readonly audio: ReturnType<typeof connectFusedAudio>;
|
|
172
|
+
readonly simulation: RpcProxy<IFusedSimulationService>;
|
|
173
|
+
readonly display: RpcProxy<IFusedDisplayService>;
|
|
174
|
+
dispose(): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export declare interface IFusedConnectionOptions {
|
|
178
|
+
readonly audio?: IFusedAudioOptions;
|
|
179
|
+
readonly workers: IFusedWorkerFactories;
|
|
180
|
+
/** Host package access both guests share. */
|
|
181
|
+
readonly registry: DeviceRegistry;
|
|
182
|
+
/** Element that hosts the two hidden sandbox iframes. */
|
|
183
|
+
readonly container?: HTMLElement;
|
|
184
|
+
readonly resolveResource?: ResourceResolver;
|
|
185
|
+
readonly programs?: ProgramSources;
|
|
186
|
+
readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 2D presentation surface the editor drives (RFC 0022). */
|
|
190
|
+
export declare interface IFusedDisplay {
|
|
191
|
+
/** Mode of the current presentation; `undefined` before the first preparation. */
|
|
192
|
+
readonly mode: FusedDisplayMode | undefined;
|
|
193
|
+
readonly instances: readonly IFusedInstancePresentation[];
|
|
194
|
+
/** A presentation asked for a repaint. */
|
|
195
|
+
readonly onDidInvalidate: Event_2<IFusedInvalidateEvent>;
|
|
196
|
+
/**
|
|
197
|
+
* Requests one overlay frame.
|
|
198
|
+
*
|
|
199
|
+
* `layout` defaults to {@link IFusedRuntimeOptions.measure} or the instance bounds at one device
|
|
200
|
+
* pixel per local unit. A frame of a superseded request is discarded and its bitmap released.
|
|
201
|
+
*/
|
|
202
|
+
render(instanceId: string, layout?: IFusedDisplayLayout): Promise<IFusedOverlayFrame | undefined>;
|
|
203
|
+
/** Delivers local pointer input; coordinates are the inverse transform of the overlay. */
|
|
204
|
+
input(instanceId: string, event: IFusedViewInput): void;
|
|
205
|
+
/** Marks instances stale; the default auto render repaints them. */
|
|
206
|
+
invalidate(instanceId?: string): void;
|
|
207
|
+
dispose(): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export declare interface IFusedDisplayGuest {
|
|
211
|
+
readonly rpc: RpcEndpoint;
|
|
212
|
+
dispose(): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Replaceable guest dependencies, so the presentation runs off-browser in tests. */
|
|
216
|
+
export declare interface IFusedDisplayGuestOptions {
|
|
217
|
+
readonly createEndpoint?: (port: MessagePort) => RpcEndpoint;
|
|
218
|
+
/** Startup ports after the RPC port; the first one is the model lane (RFC 0025). */
|
|
219
|
+
readonly ports?: readonly MessagePort[];
|
|
220
|
+
/** Evaluates one verified view module; defaults to a blob URL plus dynamic `import()`. */
|
|
221
|
+
readonly importModule?: (code: string) => Promise<unknown>;
|
|
222
|
+
/** Creates the overlay canvas; defaults to `OffscreenCanvas`. */
|
|
223
|
+
readonly createSurface?: FusedSurfaceFactory;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Display surface plus the preparation the runtime drives. */
|
|
227
|
+
export declare interface IFusedDisplayHost {
|
|
228
|
+
readonly display: IFusedDisplay;
|
|
229
|
+
/** Replaces the presentation of one mode; drops every pending frame of the previous one. */
|
|
230
|
+
prepare(input: IFusedDisplayPrepareInput, instances: readonly IFusedInstancePresentation[]): Promise<void>;
|
|
231
|
+
/** Runs the author `initialize` hooks once the models of the mode exist. */
|
|
232
|
+
activate(): Promise<void>;
|
|
233
|
+
dispose(): Promise<void>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export declare interface IFusedDisplayHostOptions {
|
|
237
|
+
readonly proxy: RpcProxy<IFusedDisplayService>;
|
|
238
|
+
readonly onOverlay?: (frame: IFusedOverlayFrame) => void;
|
|
239
|
+
readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
|
|
240
|
+
/** Overlay extent of one instance; defaults to its bounds at one device pixel per local unit. */
|
|
241
|
+
readonly measure?: (instance: IFusedInstancePresentation) => IFusedDisplayLayout;
|
|
242
|
+
/** Repaints when a presentation asks for it; defaults to `true`. */
|
|
243
|
+
readonly autoRender?: boolean;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Pixels per local unit and the overlay extent the host reserves for one instance. */
|
|
247
|
+
export declare interface IFusedDisplayLayout {
|
|
248
|
+
/** Overlay width in device pixels. */
|
|
249
|
+
readonly width: number;
|
|
250
|
+
/** Overlay height in device pixels. */
|
|
251
|
+
readonly height: number;
|
|
252
|
+
/** Device pixels per local unit. */
|
|
253
|
+
readonly scale: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Request that mounts presentation for one mode. */
|
|
257
|
+
export declare interface IFusedDisplayPrepareInput {
|
|
258
|
+
/**
|
|
259
|
+
* `run` mounts models first and hands every presentation its model client; `edit` releases the
|
|
260
|
+
* models and prepares the same instances without a model.
|
|
261
|
+
*/
|
|
262
|
+
readonly mode: FusedDisplayMode;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Preparation of the display guest: one mode and the instances of the current session. */
|
|
266
|
+
export declare interface IFusedDisplayPrepareRequest {
|
|
267
|
+
readonly mode: FusedDisplayMode;
|
|
268
|
+
readonly instances: readonly IFusedInstancePresentation[];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Display guest, reached through {@link fusedDisplayService}. */
|
|
272
|
+
export declare interface IFusedDisplayService {
|
|
273
|
+
/** Direct display guest to audio worklet lane, transferred by the host. */
|
|
274
|
+
attachAudio(port: MessagePort): void;
|
|
275
|
+
setAudioState(state: FusedAudioState): void;
|
|
276
|
+
/**
|
|
277
|
+
* Creates the presentation factories of one mode; nothing is initialized yet.
|
|
278
|
+
*
|
|
279
|
+
* It runs before the models exist, so a factory can subscribe to model events and still observe
|
|
280
|
+
* the events the model produces while it initializes.
|
|
281
|
+
*/
|
|
282
|
+
prepare(request: IFusedDisplayPrepareRequest): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Runs `initialize` of every prepared presentation, after the models are mounted and their initial
|
|
285
|
+
* events were delivered (RFC 0025 startup barrier).
|
|
286
|
+
*/
|
|
287
|
+
activate(): Promise<void>;
|
|
288
|
+
/** Renders one overlay; `undefined` when the instance has no dynamic overlay. */
|
|
289
|
+
render(request: IFusedRenderRequest): Promise<IFusedOverlayFrame | undefined>;
|
|
290
|
+
/** Delivers local pointer input; the guest reports a failing handler as `view2d/input-failed`. */
|
|
291
|
+
input(instanceId: string, event: IFusedViewInput): void;
|
|
292
|
+
release(instanceId: string): void;
|
|
293
|
+
dispose(): Promise<void>;
|
|
294
|
+
onDidInvalidate(listener: (change: IFusedInvalidateEvent) => void): () => void;
|
|
295
|
+
onDidReportDiagnostic(listener: (diagnostic: RuntimeDiagnostic) => void): () => void;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** One failure of a guest call, flattened for the wire. */
|
|
299
|
+
export declare interface IFusedFailurePayload {
|
|
300
|
+
/** `method` keeps a business rejection, `runtime` a contract error, `failure` anything else. */
|
|
301
|
+
readonly kind: 'method' | 'runtime' | 'failure';
|
|
302
|
+
readonly code: string;
|
|
303
|
+
readonly message: string;
|
|
304
|
+
readonly instanceId?: string;
|
|
305
|
+
/** JSON-safe snapshot of a `MethodError` payload. */
|
|
306
|
+
readonly details?: unknown;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** One loaded firmware segment of a presentation snapshot (RFC 0026). */
|
|
310
|
+
declare interface IFusedFirmwareSegment {
|
|
311
|
+
readonly addressSpace: string;
|
|
312
|
+
readonly address: number;
|
|
313
|
+
/** Segment bytes; an independent copy owned by the presentation snapshot. */
|
|
314
|
+
readonly bytes: Uint8Array;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Read-only firmware snapshot a presentation may read (RFC 0026). */
|
|
318
|
+
declare interface IFusedFirmwareSnapshot {
|
|
319
|
+
readonly kind: 'firmware';
|
|
320
|
+
readonly segments: readonly IFusedFirmwareSegment[];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Model clients of one runtime, keyed by the instance they belong to. */
|
|
324
|
+
export declare interface IFusedHostModelRouter {
|
|
325
|
+
client(instance: IFusedInstancePresentation): IFusedModelClient;
|
|
326
|
+
release(instanceId: string): void;
|
|
327
|
+
dispose(): void;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Host package access both guests share; the host owns the bytes and verifies nothing twice. */
|
|
331
|
+
export declare interface IFusedHostPackageService {
|
|
332
|
+
open(lock: DeviceLock): Promise<IFusedPackageFilesWire>;
|
|
333
|
+
/** Returns a copy the guest may keep; the reply transfers its buffer. */
|
|
334
|
+
read(lock: DeviceLock, path: string): Promise<Uint8Array>;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Host resources the simulation guest reaches during preparation (RFC 0020 / RFC 0026). */
|
|
338
|
+
export declare interface IFusedHostResourceService {
|
|
339
|
+
readResource(request: ResourceRequest): Promise<Uint8Array>;
|
|
340
|
+
resolveProgramProject(projectId: string, target: ProgramTarget): Promise<ProgramArtifact>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Everything the display worker needs to prepare one instance.
|
|
345
|
+
*
|
|
346
|
+
* Geometry and the property projection are resolved inside the simulation worker, so the host never
|
|
347
|
+
* parses a manifest or evaluates an author module.
|
|
348
|
+
*/
|
|
349
|
+
export declare interface IFusedInstancePresentation {
|
|
350
|
+
readonly instanceId: string;
|
|
351
|
+
/** Full `publisher:name` device id the instance locks. */
|
|
352
|
+
readonly device: string;
|
|
353
|
+
readonly lock: DeviceLock;
|
|
354
|
+
readonly geometry: Geometry2D;
|
|
355
|
+
/** Package-root relative `.js` overlay entry; `undefined` for a geometry-only device. */
|
|
356
|
+
readonly view: string | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* Resolved property snapshot, identical to the one the model receives: manifest default and
|
|
359
|
+
* document override through the SDK, with resource bytes and the loaded firmware image. An
|
|
360
|
+
* instance whose props cannot be projected has no presentation at all, so this is never partial.
|
|
361
|
+
*/
|
|
362
|
+
readonly props: FusedPresentationProps;
|
|
363
|
+
/** Declared model method names; empty for a device without a model. */
|
|
364
|
+
readonly methods: readonly string[];
|
|
365
|
+
/** Declared model event names; empty for a device without a model. */
|
|
366
|
+
readonly events: readonly string[];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** A presentation asked for a repaint. */
|
|
370
|
+
export declare interface IFusedInvalidateEvent {
|
|
371
|
+
readonly instanceId: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Request that creates the models of one run session. */
|
|
375
|
+
export declare interface IFusedLoadRequest {
|
|
376
|
+
readonly document: FusedDocument;
|
|
377
|
+
/** Fixed positive step of every advance, in picoseconds. */
|
|
378
|
+
readonly step: TimePs;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Model lane served by the simulation guest to the display guest over the direct port. */
|
|
382
|
+
export declare interface IFusedModelChannelService {
|
|
383
|
+
call(instanceId: string, method: string, params: Value): Promise<Value>;
|
|
384
|
+
subscribe(instanceId: string, event: string): void;
|
|
385
|
+
unsubscribe(instanceId: string, event: string): void;
|
|
386
|
+
/** Replies on the model lane after every event already sent on that lane. */
|
|
387
|
+
settle(): void;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Model client handed to a presentation or to the editor.
|
|
392
|
+
*
|
|
393
|
+
* Structurally the RFC 0021 `ModelClient` of a dynamically declared interface: methods are
|
|
394
|
+
* asynchronous and every event is a core `Event` of a `ModelEvent` payload.
|
|
395
|
+
*/
|
|
396
|
+
export declare interface IFusedModelClient {
|
|
397
|
+
readonly methods: FusedModelMethods;
|
|
398
|
+
readonly events: FusedModelEvents;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Wire subscriptions the router needs from its owner. */
|
|
402
|
+
export declare interface IFusedModelEventChannel {
|
|
403
|
+
subscribe(instanceId: string, event: string): void;
|
|
404
|
+
unsubscribe(instanceId: string, event: string): void;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export declare interface IFusedModelEventRouter {
|
|
408
|
+
/** Declared event outlet of one instance; only listeners create a wire subscription. */
|
|
409
|
+
event(instanceId: string, event: string): Event_2<ModelEvent<Value>>;
|
|
410
|
+
/** Delivers one event to the listeners active at this moment. */
|
|
411
|
+
deliver(instanceId: string, event: string, payload: ModelEvent<Value>): void;
|
|
412
|
+
/** Drops every listener of one instance. */
|
|
413
|
+
release(instanceId: string): void;
|
|
414
|
+
dispose(): void;
|
|
415
|
+
/** Number of live wire subscriptions; used to keep the wire silent without listeners. */
|
|
416
|
+
readonly activeSubscriptions: number;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** One model event as it crosses the sandbox boundary. */
|
|
420
|
+
export declare interface IFusedModelEventWire {
|
|
421
|
+
readonly instanceId: string;
|
|
422
|
+
readonly event: string;
|
|
423
|
+
readonly payload: ModelEvent<Value>;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Model event lane served by the display guest to the simulation guest. */
|
|
427
|
+
export declare interface IFusedModelSinkService {
|
|
428
|
+
deliver(event: IFusedModelEventWire): void;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** Rendered overlay of one instance; the bitmap lives in the host after the transfer. */
|
|
432
|
+
export declare interface IFusedOverlayFrame extends IFusedDisplayLayout {
|
|
433
|
+
readonly instanceId: string;
|
|
434
|
+
readonly generation: number;
|
|
435
|
+
readonly bitmap: ImageBitmap;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** Canvas one overlay is painted into; injectable so the guest runs off-browser in tests. */
|
|
439
|
+
export declare interface IFusedOverlaySurface {
|
|
440
|
+
readonly width: number;
|
|
441
|
+
readonly height: number;
|
|
442
|
+
getContext(type: '2d'): OffscreenCanvasRenderingContext2D | null;
|
|
443
|
+
transferToImageBitmap(): ImageBitmap;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Paths of one locked package, resolved by the host (RFC 0020). */
|
|
447
|
+
export declare interface IFusedPackageFilesWire {
|
|
448
|
+
readonly lock: DeviceLock;
|
|
449
|
+
readonly files: Readonly<Record<string, PackageFile>>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Preparation request of the simulation guest: verify packages and describe the scene. */
|
|
453
|
+
export declare interface IFusedPrepareRequest {
|
|
454
|
+
readonly document: FusedDocument;
|
|
455
|
+
readonly mode: FusedDisplayMode;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export declare interface IFusedPrepareResult {
|
|
459
|
+
readonly instances: readonly IFusedInstancePresentation[];
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
declare interface IFusedProgramFilesSnapshot {
|
|
463
|
+
readonly kind: 'filesystem';
|
|
464
|
+
readonly files: readonly ProgramFile[];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** One overlay render request. */
|
|
468
|
+
export declare interface IFusedRenderRequest extends IFusedDisplayLayout {
|
|
469
|
+
readonly instanceId: string;
|
|
470
|
+
/** Monotonic request number the frame echoes back, so stale results are dropped. */
|
|
471
|
+
readonly generation: number;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Fused editor runtime bridge of one workbench.
|
|
476
|
+
*
|
|
477
|
+
* The document, the packages and every model live in the simulation worker; the presentations live
|
|
478
|
+
* in the display worker. This surface only schedules, mirrors state and hands bitmaps back.
|
|
479
|
+
*/
|
|
480
|
+
export declare interface IFusedRuntime {
|
|
481
|
+
readonly audio: IFusedAudioControls;
|
|
482
|
+
getState(): IFusedSessionState;
|
|
483
|
+
readonly onDidChangeState: Event_2<IFusedSessionState>;
|
|
484
|
+
readonly onDidReportDiagnostic: Event_2<RuntimeDiagnostic>;
|
|
485
|
+
/** Fires for every overlay the presentation worker produced and the host adopted. */
|
|
486
|
+
readonly onDidRenderOverlay: Event_2<IFusedOverlayFrame>;
|
|
487
|
+
/** Proxy of one mounted model; rejects with `model/disconnected` outside a run session. */
|
|
488
|
+
getModel(instanceId: string): IFusedModelClient;
|
|
489
|
+
readonly display: IFusedDisplay;
|
|
490
|
+
/** Prepares or replaces the presentation of one mode and resolves with its descriptors. */
|
|
491
|
+
prepareDisplay(input: IFusedDisplayPrepareInput): Promise<readonly IFusedInstancePresentation[]>;
|
|
492
|
+
/** Restarts continuous fixed-step advancement after pause; requires a run session. */
|
|
493
|
+
resume(): Promise<void>;
|
|
494
|
+
/** Stops advancement, keeping models, listeners and presentation state. */
|
|
495
|
+
pause(): void;
|
|
496
|
+
/** Advances exactly one fixed step; requires a paused run session. */
|
|
497
|
+
step(): Promise<void>;
|
|
498
|
+
/** Rebuilds models and presentation of the run session from the same captured bytes, then advances. */
|
|
499
|
+
reset(): Promise<void>;
|
|
500
|
+
/** Releases both guests and their workers; safe to call more than once. */
|
|
501
|
+
dispose(): Promise<void>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export declare interface IFusedRuntimeOptions {
|
|
505
|
+
/** Caller-owned browser context; resume it directly within a user gesture for autoplay. */
|
|
506
|
+
readonly audio?: IFusedAudioOptions;
|
|
507
|
+
/** Fused `.sch` version 2 document; the simulation guest snapshots it. */
|
|
508
|
+
readonly document: FusedDocument;
|
|
509
|
+
/** Resolves the locked packages of the document in the editor. */
|
|
510
|
+
readonly registry: DeviceRegistry;
|
|
511
|
+
/** Fixed positive step of every advance, in picoseconds. */
|
|
512
|
+
readonly step: TimePs;
|
|
513
|
+
/** Presentation mode prepared on creation; defaults to `edit`. */
|
|
514
|
+
readonly mode?: FusedDisplayMode;
|
|
515
|
+
/** Explicit resolver of `file` and `store` property resources (RFC 0020). */
|
|
516
|
+
readonly resolveResource?: ResourceResolver;
|
|
517
|
+
/** Firmware project service of the editor (RFC 0026). */
|
|
518
|
+
readonly programs?: ProgramSources;
|
|
519
|
+
/** Receives every freshly rendered overlay, already keyed by instance. */
|
|
520
|
+
readonly onOverlay?: (frame: IFusedOverlayFrame) => void;
|
|
521
|
+
/** Receives preparation and runtime diagnostics of both guests. */
|
|
522
|
+
readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
|
|
523
|
+
/** Element that hosts the two hidden sandbox iframes. */
|
|
524
|
+
readonly container?: HTMLElement;
|
|
525
|
+
/** Overrides of the generated workers; tests inject plain fakes. */
|
|
526
|
+
readonly workers?: IFusedWorkerFactories;
|
|
527
|
+
/** Overlay extent of one instance; defaults to its bounds at one device pixel per local unit. */
|
|
528
|
+
readonly measure?: (instance: IFusedInstancePresentation) => IFusedDisplayLayout;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** State of the simulation session as the host sees it. */
|
|
532
|
+
export declare interface IFusedSessionState {
|
|
533
|
+
readonly status: FusedSessionStatus;
|
|
534
|
+
readonly simTime: TimePs;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Guest runtime plus the RPC endpoint that serves it. */
|
|
538
|
+
export declare interface IFusedSimulationGuest {
|
|
539
|
+
readonly rpc: RpcEndpoint;
|
|
540
|
+
dispose(): Promise<void>;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Replaceable guest dependencies, so the runtime can be exercised outside a browser worker. */
|
|
544
|
+
export declare interface IFusedSimulationGuestOptions {
|
|
545
|
+
/** Creates the endpoint over the startup port; tests inject a fake. */
|
|
546
|
+
readonly createEndpoint?: (port: MessagePort) => RpcEndpoint;
|
|
547
|
+
/**
|
|
548
|
+
* Startup ports after the RPC port. The first one is the model lane (RFC 0025), the display guest
|
|
549
|
+
* holds the other end of the same channel.
|
|
550
|
+
*/
|
|
551
|
+
readonly ports?: readonly MessagePort[];
|
|
552
|
+
/** Evaluates one verified package module; defaults to a blob URL plus dynamic `import()`. */
|
|
553
|
+
readonly importModule?: (code: string) => Promise<unknown>;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Simulation guest, reached through {@link fusedSimulationService}. */
|
|
557
|
+
export declare interface IFusedSimulationService {
|
|
558
|
+
prepare(request: IFusedPrepareRequest): Promise<IFusedPrepareResult>;
|
|
559
|
+
load(request: IFusedLoadRequest): Promise<IFusedSessionState>;
|
|
560
|
+
step(): Promise<IFusedSessionState>;
|
|
561
|
+
resume(): Promise<void>;
|
|
562
|
+
pause(): void;
|
|
563
|
+
reset(): Promise<void>;
|
|
564
|
+
/** Releases the models and keeps the captured package bytes for the next load. */
|
|
565
|
+
dispose(): Promise<void>;
|
|
566
|
+
call(instanceId: string, method: string, params: Value): Promise<Value>;
|
|
567
|
+
getState(): IFusedSessionState;
|
|
568
|
+
onDidChangeState(listener: (state: IFusedSessionState) => void): () => void;
|
|
569
|
+
onDidReportDiagnostic(listener: (diagnostic: RuntimeDiagnostic) => void): () => void;
|
|
570
|
+
/** Every model event of the session, in production order. */
|
|
571
|
+
onDidModelEvent(listener: (event: IFusedModelEventWire) => void): () => void;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Object a `view2d.entry` default factory returns (RFC 0022). */
|
|
575
|
+
export declare interface IFusedView2D {
|
|
576
|
+
initialize?(): void | Promise<void>;
|
|
577
|
+
renderOverlay?(context: OffscreenCanvasRenderingContext2D): void;
|
|
578
|
+
input?(event: IFusedViewInput): void | Promise<void>;
|
|
579
|
+
dispose?(): void;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Context a `view2d.entry` factory receives (RFC 0022). */
|
|
583
|
+
export declare interface IFusedView2DContext {
|
|
584
|
+
readonly mode: FusedDisplayMode;
|
|
585
|
+
readonly props: FusedResolvedPresentationProps;
|
|
586
|
+
readonly geometry: Geometry2D;
|
|
587
|
+
/** Proxy of the owning instance; `undefined` in edit mode and for devices without a model. */
|
|
588
|
+
readonly model: IFusedModelClient | undefined;
|
|
589
|
+
readonly assets: IFusedViewAssets;
|
|
590
|
+
/** Instance audio, independent of overlay rendering and HTML panels. */
|
|
591
|
+
readonly audio: IFusedAudio;
|
|
592
|
+
/** Marks the overlay stale; the host decides when to repaint. */
|
|
593
|
+
invalidate(): void;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** Package resources one presentation may read (RFC 0022 `ViewAssets`). */
|
|
597
|
+
export declare interface IFusedViewAssets {
|
|
598
|
+
/** Reads one declared package file; bytes are copied into the caller. */
|
|
599
|
+
read(path: string): Promise<Uint8Array>;
|
|
600
|
+
/** Decodes one image; the caller owns the bitmap and must `close()` it. */
|
|
601
|
+
loadImage(path: string): Promise<ImageBitmap>;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** Local pointer input delivered to one presentation (RFC 0022). */
|
|
605
|
+
export declare interface IFusedViewInput {
|
|
606
|
+
readonly type: FusedViewInputType;
|
|
607
|
+
/** Position in the device's local coordinates. */
|
|
608
|
+
readonly position: Point2D;
|
|
609
|
+
/** DOM button number of the event. */
|
|
610
|
+
readonly button: number;
|
|
611
|
+
/** DOM button bit mask of the buttons currently held. */
|
|
612
|
+
readonly buttons: number;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export declare interface IFusedViewSession {
|
|
616
|
+
readonly instanceId: string;
|
|
617
|
+
readonly geometry: Geometry2D;
|
|
618
|
+
/** Runs the author `initialize` hook once; safe to call again. */
|
|
619
|
+
activate(): Promise<void>;
|
|
620
|
+
/** Paints one overlay frame; the caller owns the returned bitmap. */
|
|
621
|
+
render(request: IFusedRenderRequest): ImageBitmap | undefined;
|
|
622
|
+
input(event: IFusedViewInput): void;
|
|
623
|
+
dispose(): void;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Requests the display guest performs on behalf of one session. */
|
|
627
|
+
export declare interface IFusedViewSessionOptions {
|
|
628
|
+
readonly instance: IFusedInstancePresentation;
|
|
629
|
+
readonly mode: FusedDisplayMode;
|
|
630
|
+
readonly model: IFusedModelClient | undefined;
|
|
631
|
+
readonly audio?: IFusedAudio;
|
|
632
|
+
readonly readAsset: (path: string) => Promise<Uint8Array>;
|
|
633
|
+
readonly importModule: (code: string) => Promise<unknown>;
|
|
634
|
+
readonly createSurface: FusedSurfaceFactory;
|
|
635
|
+
readonly invalidate: () => void;
|
|
636
|
+
readonly report: (code: string, message: string) => void;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** Sandbox worker the runtime drives; `@mica-js/sandbox`'s `SandboxWorker` satisfies it. */
|
|
640
|
+
export declare interface IFusedWorker {
|
|
641
|
+
readonly state: 'ready' | 'terminated';
|
|
642
|
+
readonly ready: Promise<void>;
|
|
643
|
+
postMessage(message: unknown, options?: readonly Transferable[]): void;
|
|
644
|
+
terminate(reason?: string): Promise<void>;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** One simulation worker and one presentation worker per workbench. */
|
|
648
|
+
export declare interface IFusedWorkerFactories {
|
|
649
|
+
createSimulationWorker(options?: IFusedWorkerOptions): IFusedWorker;
|
|
650
|
+
createDisplayWorker(options?: IFusedWorkerOptions): IFusedWorker;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** Worker construction options the runtime forwards to the generated sandbox class. */
|
|
654
|
+
export declare interface IFusedWorkerOptions {
|
|
655
|
+
/** Element that hosts the hidden sandbox iframe. */
|
|
656
|
+
readonly container?: HTMLElement;
|
|
657
|
+
readonly name?: string;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export declare function isFusedBridgeError(value: unknown): value is FusedBridgeError;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Loads the generated worker factories on demand.
|
|
664
|
+
*
|
|
665
|
+
* `createFusedRuntime` does this itself; call it to preload both guest bundles, or to pass the
|
|
666
|
+
* same factories to several runtimes.
|
|
667
|
+
*/
|
|
668
|
+
export declare function loadFusedWorkerFactories(): Promise<IFusedWorkerFactories>;
|
|
669
|
+
|
|
670
|
+
/** Runs one guest call and rebuilds a wire failure of its rejection. */
|
|
671
|
+
export declare function mapWireFailure<T>(run: () => Promise<T>): Promise<T>;
|
|
672
|
+
|
|
673
|
+
/** Wire key of one locked package. */
|
|
674
|
+
export declare function packageLockKey(lock: DeviceLock): string;
|
|
675
|
+
|
|
676
|
+
/** Starts the 2D presentation guest on the startup port of a sandbox worker. */
|
|
677
|
+
export declare function startFusedDisplayGuest(port: MessagePort, options?: IFusedDisplayGuestOptions): IFusedDisplayGuest;
|
|
678
|
+
|
|
679
|
+
/** Starts the simulation guest on the startup port of a sandbox worker. */
|
|
680
|
+
export declare function startFusedSimulationGuest(port: MessagePort, options?: IFusedSimulationGuestOptions): IFusedSimulationGuest;
|
|
681
|
+
|
|
682
|
+
/** Encodes one failure as an `Error` the RPC layer can carry. */
|
|
683
|
+
export declare function toWireFailure(cause: unknown): Error;
|
|
684
|
+
|
|
685
|
+
export { }
|