@mica-js/editor 0.3.3 → 0.4.1

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.
@@ -0,0 +1,849 @@
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 { Geometry2D } from '@mica-js/document/fused';
5
+ import { HtmlViewDefinition } from '@mica-js/document/fused';
6
+ import { ModelEvent } from '@mica-js/sdk/fused';
7
+ import { Point2D } from '@mica-js/document/fused';
8
+ import { ProgramFile } from '@mica-js/sdk/fused';
9
+ import { RpcProxy } from '@mica-js/core/rpc';
10
+ import { RpcServiceId } from '@mica-js/core/rpc';
11
+ import { RuntimeDiagnostic } from '@mica-js/sdk/fused';
12
+ import { TimePs } from '@mica-js/core';
13
+ import { UnifiedDeviceManifest } from '@mica-js/document/fused';
14
+ import { Value } from '@mica-js/document/fused';
15
+ import { WidgetAudioControls } from '@mica-js/widget/audio-host';
16
+
17
+ /** Mirrors every theme token onto the root element of one document, in place. */
18
+ export declare function applyHtmlViewTheme(root: HTMLElement, theme: IHtmlViewTheme): void;
19
+
20
+ /** Rejects a path that is not a normalized package-root relative file path. */
21
+ export declare function assertAssetPath(path: string): void;
22
+
23
+ /** Directory under the environment base URL that serves the package files. */
24
+ export declare const ASSET_ROOT_DIRECTORY = "__mica_package__/";
25
+
26
+ /** Absolute URL prefix that serves the verified package files of one environment. */
27
+ export declare function assetRootUrl(baseUrl: URL): URL;
28
+
29
+ /**
30
+ * Base URL the author document resolves relative references against.
31
+ *
32
+ * The asset root mirrors the package root, so the document base is the directory of the view entry
33
+ * and `./main.js` of `views/serial/index.html` resolves to the package file `views/serial/main.js`.
34
+ */
35
+ export declare function authorBaseUrl(assetRoot: URL, entry: string): string;
36
+
37
+ /** Builds the author-facing bridge over an established host channel. */
38
+ export declare function createDeviceViewSession(options: IDeviceViewSessionOptions): IDeviceViewSession;
39
+
40
+ /** Creates the HTML view manager of one workbench. */
41
+ export declare function createHtmlViewHost(options: IHtmlViewHostOptions): IHtmlViewHost;
42
+
43
+ /** Builds the manager callbacks of one runtime. */
44
+ export declare function createHtmlViewRuntimeSource(options: IHtmlViewSourceOptions): IHtmlViewRuntimeSource;
45
+
46
+ /** Decodes package bytes as UTF-8 text, tolerating a byte order mark. */
47
+ export declare function decodeDocument(bytes: Uint8Array): string;
48
+
49
+ /** Theme of an environment whose editor forwarded no colors yet. */
50
+ export declare const DEFAULT_HTML_VIEW_THEME: IHtmlViewTheme;
51
+
52
+ /** Bundled bootstrap module loaded by {@link ENVIRONMENT_DOCUMENT_FILE}. */
53
+ export declare const ENVIRONMENT_BOOTSTRAP_FILE = "environment.js";
54
+
55
+ /** Document the environment loads in the inner sandbox frame; a real same-origin URL. */
56
+ export declare const ENVIRONMENT_CONTENT_DOCUMENT_FILE = "content.html";
57
+
58
+ /** Bundled bootstrap module {@link ENVIRONMENT_CONTENT_DOCUMENT_FILE} loads. */
59
+ export declare const ENVIRONMENT_CONTENT_FILE = "content.js";
60
+
61
+ /** Bootstrap document the editor loads in the environment iframe. */
62
+ export declare const ENVIRONMENT_DOCUMENT_FILE = "index.html";
63
+
64
+ /** Bundled service worker that serves the package files of one environment. */
65
+ export declare const ENVIRONMENT_WORKER_FILE = "environment-sw.js";
66
+
67
+ /** Presentation mode of one workbench (RFC 0025). */
68
+ declare type FusedDisplayMode = 'edit' | 'run';
69
+
70
+ /** Typed package lane between the editor and one environment's asset worker. */
71
+ export declare const fusedHtmlAssetService: RpcServiceId<IFusedHtmlAssetService>;
72
+
73
+ /** Typed view identity lane of one inner frame; it shares the author lane port. */
74
+ export declare const fusedHtmlContentViewService: RpcServiceId<IFusedHtmlContentViewService>;
75
+
76
+ /** Typed control lane between the editor and one trusted environment page. */
77
+ export declare const fusedHtmlHostControlService: RpcServiceId<IFusedHtmlHostControlService>;
78
+
79
+ /** Typed author lane between the editor and one inner frame. */
80
+ export declare const fusedHtmlHostService: RpcServiceId<IFusedHtmlHostService>;
81
+
82
+ /** Declared event outlets of one model client. */
83
+ declare type FusedModelEvents = Readonly<Record<string, Event_2<ModelEvent<Value>>>>;
84
+
85
+ /** Dynamic methods of one display-side model client; only declared names resolve. */
86
+ declare type FusedModelMethods = Readonly<Record<string, (params: Value) => Promise<Value>>>;
87
+
88
+ /** Read-only plain property snapshot handed to a 2D presentation. */
89
+ declare type FusedPresentationProps = Readonly<Record<string, FusedPresentationValue>>;
90
+
91
+ /**
92
+ * One resolved property value a presentation may read.
93
+ *
94
+ * Scalars stay plain; `image` and `binary` properties are their resolved bytes; `firmware`
95
+ * properties are the loaded, segment-addressable snapshot. Resolution happens in the simulation
96
+ * worker, so an unresolved property rejects the presentation instead of shrinking its props.
97
+ */
98
+ declare type FusedPresentationValue = string | number | boolean | null | Uint8Array | IFusedFirmwareSnapshot | IFusedProgramFilesSnapshot;
99
+
100
+ /** Session status the host mirrors; `idle` means no models are mounted (edit mode). */
101
+ declare type FusedSessionStatus = 'idle' | 'paused' | 'running' | 'faulted' | 'disposed';
102
+
103
+ declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
104
+
105
+ /** Acknowledgement the environment posts back once it owns the transferred port. */
106
+ export declare const HTML_VIEW_ACK = "mica:view:ack";
107
+
108
+ /** Control message that grants the environment's asset worker its package channel. */
109
+ export declare const HTML_VIEW_ASSETS = "mica:view:assets";
110
+
111
+ /** Acknowledgement of {@link HTML_VIEW_ASSETS}: the worker owns the package port. */
112
+ export declare const HTML_VIEW_ASSETS_ACK = "mica:view:assets-ack";
113
+
114
+ /** Control message the inner frame posts into the asset worker to authorize its own requests. */
115
+ export declare const HTML_VIEW_ATTACH = "mica:view:attach";
116
+
117
+ /** Acknowledgement of {@link HTML_VIEW_ATTACH}; only then may the author document load. */
118
+ export declare const HTML_VIEW_ATTACH_ACK = "mica:view:attach-ack";
119
+
120
+ /** Control message the environment answers with the bridge port of the inner frame. */
121
+ export declare const HTML_VIEW_CHILD_CONNECT = "mica:view:child-connect";
122
+
123
+ /** Control message the inner frame posts to the environment once its bootstrap runs. */
124
+ export declare const HTML_VIEW_CHILD_HELLO = "mica:view:child-hello";
125
+
126
+ /** Control message the inner frame posts once its API and its package grant are in place. */
127
+ export declare const HTML_VIEW_CHILD_PREPARED = "mica:view:child-prepared";
128
+
129
+ /** Control message the editor posts into a freshly loaded environment. */
130
+ export declare const HTML_VIEW_CONNECT = "mica:view:connect";
131
+
132
+ /**
133
+ * Content security policy of the author document and of the inner content document.
134
+ *
135
+ * Package scripts, styles, fonts and images are same-origin because the asset worker serves them;
136
+ * opaque `blob:` URLs are the `assets.getUrl` results of the view itself. Nothing else is reachable:
137
+ * the author page has no network, no frames and no form targets. The inner document is served with
138
+ * this policy so an author document can never nest another frame, whatever the trusted environment
139
+ * allows itself.
140
+ */
141
+ export declare const HTML_VIEW_CONTENT_POLICY: string;
142
+
143
+ /**
144
+ * Policy of the trusted environment document.
145
+ *
146
+ * It only differs from the author policy where the environment itself needs more: exactly one inner
147
+ * frame of its own deployment directory, and the asset worker registration. The inner document is
148
+ * served with {@link HTML_VIEW_CONTENT_POLICY}, so the author document still cannot nest frames,
149
+ * reach another origin or post a form.
150
+ */
151
+ export declare const HTML_VIEW_ENVIRONMENT_POLICY: string;
152
+
153
+ /**
154
+ * Query parameter that carries the one-time token of one inner frame.
155
+ *
156
+ * The inner document is a real same-origin URL, so both frames derive the environment origin from
157
+ * their own location; only the frame token travels in the URL, and it never grants host access.
158
+ */
159
+ export declare const HTML_VIEW_FRAME_PARAM = "view";
160
+
161
+ /**
162
+ * Environment URL of one validated base and environment id.
163
+ *
164
+ * @throws {TypeError} when `id` is not a DNS label; ids come from {@link newHtmlEnvironmentId}.
165
+ */
166
+ export declare function htmlEnvironmentUrl(base: IHtmlViewBase, id: string): URL;
167
+
168
+ export declare type HtmlViewChangeType = 'opened' | 'ready' | 'failed' | 'closed' | 'moved';
169
+
170
+ /** Reads the declaration of one device manifest. */
171
+ export declare function htmlViewDeviceDeclaration(manifest: Pick<UnifiedDeviceManifest, 'view' | 'model'>): IHtmlViewDeviceDeclaration;
172
+
173
+ /** Diagnostic codes the HTML view contract reports (RFC 0023 "校验"). */
174
+ export declare type HtmlViewDiagnosticCode = 'view/invalid-base-url-template' | 'view/unknown-entry' | 'view/unavailable-mode' | 'view/load-failed' | 'view/bridge-failed' | 'view/execution-failed';
175
+
176
+ /** Local contract failure of the HTML view host or of one environment. */
177
+ export declare class HtmlViewError extends Error {
178
+ readonly code: HtmlViewDiagnosticCode;
179
+ readonly instanceId: string | undefined;
180
+ readonly viewId: string | undefined;
181
+ constructor(code: HtmlViewDiagnosticCode, message: string, options?: {
182
+ readonly instanceId?: string;
183
+ readonly viewId?: string;
184
+ });
185
+ }
186
+
187
+ /** Key of one view instance: the same device view in two places is still one environment. */
188
+ export declare function htmlViewKey(instanceId: string, viewId: string): string;
189
+
190
+ /** Container an environment occupies; switching never reloads its page. */
191
+ export declare type HtmlViewLocation = 'sidebar' | 'floating';
192
+
193
+ /** Lifecycle of one environment. */
194
+ export declare type HtmlViewState = 'loading' | 'ready' | 'failed' | 'closed';
195
+
196
+ /** Theme declarations injected into the author document head before any author script. */
197
+ export declare function htmlViewThemeCss(theme: IHtmlViewTheme): string;
198
+
199
+ /** Whether two themes resolve to the same appearance and colors. */
200
+ export declare function htmlViewThemeEquals(left: IHtmlViewTheme, right: IHtmlViewTheme): boolean;
201
+
202
+ /** RFC 0023 `DeviceViewApi`. */
203
+ export declare interface IDeviceViewApi {
204
+ readonly props: FusedPresentationProps;
205
+ readonly model: IDeviceViewModel | undefined;
206
+ readonly assets: IHtmlAssets;
207
+ readonly onDidClose: Event_2<void>;
208
+ }
209
+
210
+ /** RFC 0023 `DeviceViewApi.model`: the declared surface of the owning model. */
211
+ export declare interface IDeviceViewModel {
212
+ /** Declared methods; only declared names resolve. */
213
+ readonly methods: Readonly<Record<string, (params: Value) => Promise<Value>>>;
214
+ /** Declared event outlets; a subscription is created on the wire when it is first observed. */
215
+ readonly events: Readonly<Record<string, Event_2<ModelEvent<Value>>>>;
216
+ }
217
+
218
+ /** Live bridge of one environment. */
219
+ export declare interface IDeviceViewSession {
220
+ readonly api: IDeviceViewApi;
221
+ readonly closed: boolean;
222
+ /** Delivers one model event the host pushed into this environment. */
223
+ deliver(event: IFusedHtmlModelEventWire): void;
224
+ /** Announces the host released this view; fires `onDidClose` once. */
225
+ close(): void;
226
+ dispose(): void;
227
+ }
228
+
229
+ export declare interface IDeviceViewSessionOptions {
230
+ readonly host: RpcProxy<IFusedHtmlHostService>;
231
+ readonly target: IHtmlViewTarget;
232
+ /** Reports an author failure once; the editor faults the view afterwards (RFC 0023). */
233
+ readonly reportFailure: (code: string, message: string) => void;
234
+ /** Object URL seam; defaults to the environment realm `URL`. */
235
+ readonly createObjectUrl?: (blob: Blob) => string;
236
+ readonly revokeObjectUrl?: (url: string) => void;
237
+ }
238
+
239
+ /** 2D presentation surface the editor drives (RFC 0022). */
240
+ declare interface IFusedDisplay {
241
+ /** Mode of the current presentation; `undefined` before the first preparation. */
242
+ readonly mode: FusedDisplayMode | undefined;
243
+ readonly instances: readonly IFusedInstancePresentation[];
244
+ /** A presentation asked for a repaint. */
245
+ readonly onDidInvalidate: Event_2<IFusedInvalidateEvent>;
246
+ /**
247
+ * Requests one overlay frame.
248
+ *
249
+ * `layout` defaults to {@link IFusedRuntimeOptions.measure} or the instance bounds at one device
250
+ * pixel per local unit. A frame of a superseded request is discarded and its bitmap released.
251
+ */
252
+ render(instanceId: string, layout?: IFusedDisplayLayout): Promise<IFusedOverlayFrame | undefined>;
253
+ /** Delivers local pointer input; coordinates are the inverse transform of the overlay. */
254
+ input(instanceId: string, event: IFusedViewInput): void;
255
+ /** Marks instances stale; the default auto render repaints them. */
256
+ invalidate(instanceId?: string): void;
257
+ dispose(): Promise<void>;
258
+ }
259
+
260
+ /** Pixels per local unit and the overlay extent the host reserves for one instance. */
261
+ declare interface IFusedDisplayLayout {
262
+ /** Overlay width in device pixels. */
263
+ readonly width: number;
264
+ /** Overlay height in device pixels. */
265
+ readonly height: number;
266
+ /** Device pixels per local unit. */
267
+ readonly scale: number;
268
+ }
269
+
270
+ /** Request that mounts presentation for one mode. */
271
+ declare interface IFusedDisplayPrepareInput {
272
+ /**
273
+ * `run` mounts models first and hands every presentation its model client; `edit` releases the
274
+ * models and prepares the same instances without a model.
275
+ */
276
+ readonly mode: FusedDisplayMode;
277
+ }
278
+
279
+ /** One loaded firmware segment of a presentation snapshot (RFC 0026). */
280
+ declare interface IFusedFirmwareSegment {
281
+ readonly addressSpace: string;
282
+ readonly address: number;
283
+ /** Segment bytes; an independent copy owned by the presentation snapshot. */
284
+ readonly bytes: Uint8Array;
285
+ }
286
+
287
+ /** Read-only firmware snapshot a presentation may read (RFC 0026). */
288
+ declare interface IFusedFirmwareSnapshot {
289
+ readonly kind: 'firmware';
290
+ readonly segments: readonly IFusedFirmwareSegment[];
291
+ }
292
+
293
+ /** Package bytes the editor answers one asset request with. */
294
+ export declare interface IFusedHtmlAssetService {
295
+ /** Reads one package file for an asset request; every failure answers `404`. */
296
+ read(path: string): Promise<Uint8Array>;
297
+ }
298
+
299
+ /**
300
+ * View identity the inner frame reads from the editor before the author document exists.
301
+ *
302
+ * It shares the author lane port with {@link IFusedHtmlHostService}, so props, declared methods and
303
+ * events arrive from the same lease and never travel through the outer frame.
304
+ */
305
+ export declare interface IFusedHtmlContentViewService {
306
+ /** Reads the identity of the view; the inner frame calls this exactly once. */
307
+ view(): Promise<IHtmlViewContent>;
308
+ }
309
+
310
+ /**
311
+ * Lifecycle capabilities of the trusted outer frame, served directly by the editor.
312
+ *
313
+ * This lane carries no model call and no author resource read: the outer loads the view, relays the
314
+ * theme, reports failures and hands the two dedicated ports on.
315
+ */
316
+ export declare interface IFusedHtmlHostControlService {
317
+ /** Reads one declared package file of this view; the outer reads its author document with it. */
318
+ readAsset(path: string): Promise<Uint8Array>;
319
+ /** Computed theme of the workbench at this moment. */
320
+ getTheme(): Promise<IHtmlViewTheme>;
321
+ /** Announces every later theme of the workbench, including appearance changes. */
322
+ onDidThemeChange(listener: (theme: IHtmlViewTheme) => void): () => void;
323
+ /** Announces that the author document is written; the view leaves the loading state. */
324
+ ready(): Promise<void>;
325
+ /** Reports an author failure; the editor faults the view (RFC 0023). */
326
+ reportFailure(code: string, message: string): Promise<void>;
327
+ /** Announces that the environment goes away without an editor request. */
328
+ closed(): void;
329
+ /**
330
+ * Grants the dedicated package lane of this view's asset worker, once.
331
+ *
332
+ * The port is transferred into the worker straight from the outer frame, so no author document
333
+ * and no editor page ever holds it; the grant token decides which clients it serves.
334
+ */
335
+ assetPort(): Promise<MessagePort>;
336
+ /**
337
+ * Grants the dedicated author lane of this view's inner frame, once.
338
+ *
339
+ * The port is transferred into the sandboxed frame straight from the outer frame, after that
340
+ * frame announced its own hello with the token of this environment.
341
+ */
342
+ contentPort(): Promise<MessagePort>;
343
+ }
344
+
345
+ /**
346
+ * Author-facing capabilities of one inner frame, served directly by the editor.
347
+ *
348
+ * Every member is bound to the lease of one view: the declared methods and events of that instance,
349
+ * the verified package of that lock and the live proxy of that model.
350
+ */
351
+ export declare interface IFusedHtmlHostService {
352
+ /** Reads one declared package file; `path` is package-root relative and verified. */
353
+ readAsset(path: string): Promise<Uint8Array>;
354
+ /** Invokes one declared model method through the live model proxy of the instance. */
355
+ callModel(method: string, params: Value): Promise<Value>;
356
+ /** Starts receiving one declared model event. */
357
+ subscribe(event: string): Promise<void>;
358
+ /** Stops receiving one declared model event. */
359
+ unsubscribe(event: string): Promise<void>;
360
+ /** Every subscribed model event of this environment, in production order. */
361
+ onDidModelEvent(listener: (event: IFusedHtmlModelEventWire) => void): () => void;
362
+ /** Announces that the editor released this environment. */
363
+ onDidClose(listener: () => void): () => void;
364
+ /** Reports an author failure; the editor faults the view (RFC 0023). */
365
+ reportFailure(code: string, message: string): Promise<void>;
366
+ }
367
+
368
+ /** One model event pushed into an environment, for an event it subscribed to. */
369
+ export declare interface IFusedHtmlModelEventWire {
370
+ readonly name: string;
371
+ readonly payload: ModelEvent<Value>;
372
+ }
373
+
374
+ /**
375
+ * Everything the display worker needs to prepare one instance.
376
+ *
377
+ * Geometry and the property projection are resolved inside the simulation worker, so the host never
378
+ * parses a manifest or evaluates an author module.
379
+ */
380
+ declare interface IFusedInstancePresentation {
381
+ readonly instanceId: string;
382
+ /** Full `publisher:name` device id the instance locks. */
383
+ readonly device: string;
384
+ readonly lock: DeviceLock;
385
+ readonly geometry: Geometry2D;
386
+ /** Package-root relative `.js` overlay entry; `undefined` for a geometry-only device. */
387
+ readonly view: string | undefined;
388
+ /**
389
+ * Resolved property snapshot, identical to the one the model receives: manifest default and
390
+ * document override through the SDK, with resource bytes and the loaded firmware image. An
391
+ * instance whose props cannot be projected has no presentation at all, so this is never partial.
392
+ */
393
+ readonly props: FusedPresentationProps;
394
+ /** Declared model method names; empty for a device without a model. */
395
+ readonly methods: readonly string[];
396
+ /** Declared model event names; empty for a device without a model. */
397
+ readonly events: readonly string[];
398
+ }
399
+
400
+ /** A presentation asked for a repaint. */
401
+ declare interface IFusedInvalidateEvent {
402
+ readonly instanceId: string;
403
+ }
404
+
405
+ /**
406
+ * Model client handed to a presentation or to the editor.
407
+ *
408
+ * Structurally the RFC 0021 `ModelClient` of a dynamically declared interface: methods are
409
+ * asynchronous and every event is a core `Event` of a `ModelEvent` payload.
410
+ */
411
+ declare interface IFusedModelClient {
412
+ readonly methods: FusedModelMethods;
413
+ readonly events: FusedModelEvents;
414
+ }
415
+
416
+ /** Rendered overlay of one instance; the bitmap lives in the host after the transfer. */
417
+ declare interface IFusedOverlayFrame extends IFusedDisplayLayout {
418
+ readonly instanceId: string;
419
+ readonly generation: number;
420
+ readonly bitmap: ImageBitmap;
421
+ }
422
+
423
+ declare interface IFusedProgramFilesSnapshot {
424
+ readonly kind: 'filesystem';
425
+ readonly files: readonly ProgramFile[];
426
+ }
427
+
428
+ /**
429
+ * Fused editor runtime bridge of one workbench.
430
+ *
431
+ * The document, the packages and every model live in the simulation worker; the presentations live
432
+ * in the display worker. This surface only schedules, mirrors state and hands bitmaps back.
433
+ */
434
+ declare interface IFusedRuntime {
435
+ readonly audio: WidgetAudioControls;
436
+ getState(): IFusedSessionState;
437
+ readonly onDidChangeState: Event_2<IFusedSessionState>;
438
+ readonly onDidReportDiagnostic: Event_2<RuntimeDiagnostic>;
439
+ /** Fires for every overlay the presentation worker produced and the host adopted. */
440
+ readonly onDidRenderOverlay: Event_2<IFusedOverlayFrame>;
441
+ /** Proxy of one mounted model; rejects with `model/disconnected` outside a run session. */
442
+ getModel(instanceId: string): IFusedModelClient;
443
+ readonly display: IFusedDisplay;
444
+ /** Prepares or replaces the presentation of one mode and resolves with its descriptors. */
445
+ prepareDisplay(input: IFusedDisplayPrepareInput): Promise<readonly IFusedInstancePresentation[]>;
446
+ /** Restarts continuous fixed-step advancement after pause; requires a run session. */
447
+ resume(): Promise<void>;
448
+ /** Stops advancement, keeping models, listeners and presentation state. */
449
+ pause(): void;
450
+ /** Advances exactly one fixed step; requires a paused run session. */
451
+ step(): Promise<void>;
452
+ /** Rebuilds models and presentation of the run session from the same captured bytes, then advances. */
453
+ reset(): Promise<void>;
454
+ /** Releases both guests and their workers; safe to call more than once. */
455
+ dispose(): Promise<void>;
456
+ }
457
+
458
+ /** State of the simulation session as the host sees it. */
459
+ declare interface IFusedSessionState {
460
+ readonly status: FusedSessionStatus;
461
+ readonly simTime: TimePs;
462
+ }
463
+
464
+ /** Local pointer input delivered to one presentation (RFC 0022). */
465
+ declare interface IFusedViewInput {
466
+ readonly type: FusedViewInputType;
467
+ /** Position in the device's local coordinates. */
468
+ readonly position: Point2D;
469
+ /** DOM button number of the event. */
470
+ readonly button: number;
471
+ /** DOM button bit mask of the buttons currently held. */
472
+ readonly buttons: number;
473
+ }
474
+
475
+ /** RFC 0023 `HtmlAssets`: verified package reads and view-scoped resource URLs. */
476
+ export declare interface IHtmlAssets {
477
+ /** Reads one declared package file; `path` is package-root relative. */
478
+ read(path: string): Promise<Uint8Array>;
479
+ /** Resolves one package file to an opaque URL that dies with this view. */
480
+ getUrl(path: string): Promise<string>;
481
+ }
482
+
483
+ /** Preamble injected into the author document before any of its own markup. */
484
+ export declare interface IHtmlDocumentPreamble {
485
+ /** Absolute base URL the author document resolves relative references against. */
486
+ readonly base: string;
487
+ /** Content security policy of the author document. */
488
+ readonly policy: string;
489
+ /** Theme declarations of the environment, applied before any author script runs. */
490
+ readonly style: string;
491
+ }
492
+
493
+ export declare interface IHtmlViewAckMessage {
494
+ readonly type: typeof HTML_VIEW_ACK;
495
+ readonly token: string;
496
+ }
497
+
498
+ export declare interface IHtmlViewAssetAckMessage {
499
+ readonly type: typeof HTML_VIEW_ASSETS_ACK;
500
+ readonly token: string;
501
+ }
502
+
503
+ /**
504
+ * Grant of the package asset worker: the prefix it serves plus two ports.
505
+ *
506
+ * The first port is the dedicated package lane of the editor, the second one is where the worker
507
+ * acknowledges the grant. The environment page that installs the grant is the only client the
508
+ * registry admits, and it never answers a package read itself.
509
+ */
510
+ export declare interface IHtmlViewAssetGrantMessage {
511
+ readonly type: typeof HTML_VIEW_ASSETS;
512
+ readonly token: string;
513
+ /** URL pathname of the package asset root this worker serves. */
514
+ readonly root: string;
515
+ }
516
+
517
+ export declare interface IHtmlViewAttachAckMessage {
518
+ readonly type: typeof HTML_VIEW_ATTACH_ACK;
519
+ readonly token: string;
520
+ }
521
+
522
+ /** Authorization of one inner frame in the package asset worker. */
523
+ export declare interface IHtmlViewAttachMessage {
524
+ readonly type: typeof HTML_VIEW_ATTACH;
525
+ /** Grant token the frame read from its own view identity, never from the author document. */
526
+ readonly token: string;
527
+ }
528
+
529
+ /** Validated base URL of the HTML environment deployment. */
530
+ export declare interface IHtmlViewBase {
531
+ /** Configured template, with its single `${id}` label retained. */
532
+ readonly template: string;
533
+ /** Minimum suffix shared by every environment URL, used for diagnostics only. */
534
+ readonly deployment: string;
535
+ }
536
+
537
+ export declare interface IHtmlViewChange {
538
+ readonly type: HtmlViewChangeType;
539
+ readonly handle: IHtmlViewHandle;
540
+ }
541
+
542
+ /** Answer of the environment, carrying the one author port of the inner frame. */
543
+ export declare interface IHtmlViewChildConnectMessage {
544
+ readonly type: typeof HTML_VIEW_CHILD_CONNECT;
545
+ readonly token: string;
546
+ }
547
+
548
+ /** Handshake of the inner bootstrap, posted before any author script exists. */
549
+ export declare interface IHtmlViewChildHelloMessage {
550
+ readonly type: typeof HTML_VIEW_CHILD_HELLO;
551
+ readonly token: string;
552
+ }
553
+
554
+ /** Announcement of the inner frame that its API and its package grant are in place. */
555
+ export declare interface IHtmlViewChildPreparedMessage {
556
+ readonly type: typeof HTML_VIEW_CHILD_PREPARED;
557
+ readonly token: string;
558
+ }
559
+
560
+ export declare interface IHtmlViewConnectMessage {
561
+ readonly type: typeof HTML_VIEW_CONNECT;
562
+ /** One-time value of this environment; messages of stale pages never match it. */
563
+ readonly token: string;
564
+ /** Origin the environment must use for every message back to the editor. */
565
+ readonly parentOrigin: string;
566
+ readonly target: IHtmlViewTarget;
567
+ }
568
+
569
+ /** Identity of one view, as the inner frame receives it before the author document exists. */
570
+ export declare interface IHtmlViewContent {
571
+ /**
572
+ * Package grant token of this environment.
573
+ *
574
+ * It never appears in the author document; the inner frame presents it to the asset worker so
575
+ * only this frame may read the package files of the view.
576
+ */
577
+ readonly token: string;
578
+ readonly target: IHtmlViewTarget;
579
+ }
580
+
581
+ /** Declared HTML views and model presence of one device, normally read from its manifest. */
582
+ export declare interface IHtmlViewDeviceDeclaration {
583
+ /** Declared HTML views of the device; `manifest.view ?? {}`. */
584
+ readonly views: Readonly<Record<string, HtmlViewDefinition>>;
585
+ /** Whether the device declares a model (`manifest.model !== undefined`; RFC 0021). */
586
+ readonly hasModel: boolean;
587
+ }
588
+
589
+ /** Failure of one HTML view; the container shows device, title and reason. */
590
+ export declare interface IHtmlViewFailure {
591
+ readonly code: HtmlViewDiagnosticCode;
592
+ readonly message: string;
593
+ readonly instanceId: string;
594
+ readonly viewId: string;
595
+ readonly title: string;
596
+ readonly device: string;
597
+ }
598
+
599
+ /** One stable environment of one view. */
600
+ export declare interface IHtmlViewHandle {
601
+ /** Stable key of `(instanceId, viewId)`. */
602
+ readonly key: string;
603
+ readonly instanceId: string;
604
+ readonly viewId: string;
605
+ readonly title: string;
606
+ readonly device: string;
607
+ /** Package-root relative `.html` entry the environment loaded. */
608
+ readonly entry: string;
609
+ readonly location: HtmlViewLocation;
610
+ readonly state: HtmlViewState;
611
+ readonly failure: IHtmlViewFailure | undefined;
612
+ /** Owner of the iframe; it stays in the environment layer for the life of the environment. */
613
+ readonly element: HTMLElement;
614
+ /**
615
+ * Positions the owner over `slot`; `null` keeps the page alive but hides it.
616
+ *
617
+ * The owner keeps the slot box and is clipped to the visible part of every scrolling ancestor,
618
+ * the editor container and the viewport, so a partially scrolled sidebar never lets the frame
619
+ * paint over the rest of the editor. A slot that scrolled out completely stops painting.
620
+ */
621
+ attach(slot: HTMLElement | null): void;
622
+ /** Hides the page without unloading it; used when the container collapses. */
623
+ setVisible(visible: boolean): void;
624
+ setLocation(location: HtmlViewLocation): void;
625
+ focus(): void;
626
+ close(): void;
627
+ }
628
+
629
+ /** Manager of every device HTML environment of one workbench. */
630
+ export declare interface IHtmlViewHost {
631
+ readonly onDidChange: Event_2<IHtmlViewChange>;
632
+ /** Announces every resolved theme the environments must mirror. */
633
+ readonly onDidThemeChange: Event_2<IHtmlViewTheme>;
634
+ /** Theme the environments mirror at this moment; dark unless the workbench sets one. */
635
+ readonly theme: IHtmlViewTheme;
636
+ /**
637
+ * Sets the theme every environment mirrors, in place.
638
+ *
639
+ * The workbench forwards its *computed* colors, so a `var(...)` of the host page is already
640
+ * resolved. An equal theme is ignored and a change never reloads a frame, so author input, model
641
+ * session and document history survive it.
642
+ */
643
+ setTheme(theme: IHtmlViewTheme): void;
644
+ readonly views: readonly IHtmlViewHandle[];
645
+ get(instanceId: string, viewId: string): IHtmlViewHandle | undefined;
646
+ /**
647
+ * Opens or focuses the single environment of one view; it never creates a second one.
648
+ *
649
+ * Rejects with `view/unavailable-mode` when {@link close}, {@link closeAll} or
650
+ * {@link dispose} release the view while its verified package read is still in flight, so a
651
+ * cancelled open can never create a stale environment later.
652
+ */
653
+ open(request: IHtmlViewOpenRequest): Promise<IHtmlViewHandle>;
654
+ /** Releases the environment or cancels its pending open; `true` when either existed. */
655
+ close(instanceId: string, viewId: string): boolean;
656
+ /**
657
+ * Releases every environment and cancels every pending open, keeping the manager usable.
658
+ *
659
+ * The manager caches the model proxy of each environment for its lifetime, so a runtime reset
660
+ * must call this before the replacement runtime is prepared and then reopen the views: they bind
661
+ * the new model on their next {@link open}.
662
+ */
663
+ closeAll(): void;
664
+ focus(instanceId: string, viewId: string): boolean;
665
+ /** Re-measures every attached environment; call after a layout-only change. */
666
+ refresh(): void;
667
+ /** Releases every environment and cancels every pending open. */
668
+ dispose(): Promise<void>;
669
+ }
670
+
671
+ export declare interface IHtmlViewHostOptions {
672
+ /** Absolute HTTP(S) deployment directory with one `${id}` hostname label (RFC 0023). */
673
+ readonly viewBaseUrlTemplate: string;
674
+ /**
675
+ * Element the fixed environment layer is appended to.
676
+ *
677
+ * It is the editor host element, so its box also bounds every environment: an attached slot is
678
+ * clipped to it as well as to its own scrolling ancestors and the viewport.
679
+ */
680
+ readonly container: HTMLElement;
681
+ /** Resolves one live instance; `undefined` when it is not mounted (edit mode, no selection). */
682
+ readonly describe: (instanceId: string) => IHtmlViewInstance | undefined;
683
+ /** Registry that owns the locked packages every view resource is read from. */
684
+ readonly registry: DeviceRegistry;
685
+ /**
686
+ * Proxy of the mounted model of one instance.
687
+ *
688
+ * Called only for instances whose declaration has a model; it must resolve one, and a throw (for
689
+ * example `model/disconnected` outside a run session) fails the open with `view/unavailable-mode`
690
+ * instead of handing the author an API without a model.
691
+ */
692
+ readonly model?: (instanceId: string) => IFusedModelClient | undefined;
693
+ readonly onDiagnostic?: (failure: IHtmlViewFailure) => void;
694
+ /** Theme the environments mirror before the workbench forwards its own; defaults to dark. */
695
+ readonly theme?: IHtmlViewTheme;
696
+ /** Budget of one bridge handshake; defaults to 15 s, `0` disables it. */
697
+ readonly handshakeTimeoutMs?: number;
698
+ /**
699
+ * Origin of the editor page; a template resolving to it is rejected.
700
+ *
701
+ * Defaults to `globalThis.location.origin`; hosts without a browser location must pass it. The
702
+ * environment refuses a non-HTTP(S) answer origin, so there is no wildcard fallback.
703
+ */
704
+ readonly origin?: string;
705
+ /** DOM seams; default to the globals of the editor realm. */
706
+ readonly document?: Document;
707
+ readonly window?: Window;
708
+ readonly createEnvironmentId?: () => string;
709
+ }
710
+
711
+ /** One live instance an HTML view may attach to. */
712
+ export declare interface IHtmlViewInstance {
713
+ readonly device: string;
714
+ readonly lock: DeviceLock;
715
+ readonly props: FusedPresentationProps;
716
+ readonly methods: readonly string[];
717
+ readonly events: readonly string[];
718
+ /**
719
+ * Whether the instance device declares a model (RFC 0021).
720
+ *
721
+ * Authoritative: a model with an empty public surface still counts as present, and a device
722
+ * without a model keeps `api.model` undefined whatever its declared methods and events say.
723
+ */
724
+ readonly hasModel: boolean;
725
+ /** Declared HTML views of the instance device, normally `manifest.view`. */
726
+ readonly views: Readonly<Record<string, HtmlViewDefinition>>;
727
+ }
728
+
729
+ export declare interface IHtmlViewOpenRequest {
730
+ readonly instanceId: string;
731
+ readonly viewId: string;
732
+ readonly location: HtmlViewLocation;
733
+ }
734
+
735
+ /** Inputs of {@link createHtmlViewHost} backed by one runtime. */
736
+ export declare interface IHtmlViewRuntimeSource {
737
+ /** Describes one prepared instance; `undefined` when it is not mounted. */
738
+ describe(instanceId: string): IHtmlViewInstance | undefined;
739
+ /** Proxy of the mounted model; runtime failures propagate. */
740
+ model(instanceId: string): IFusedModelClient;
741
+ }
742
+
743
+ export declare interface IHtmlViewSourceOptions {
744
+ readonly runtime: IFusedRuntime;
745
+ /**
746
+ * Declaration of one device id.
747
+ *
748
+ * Return `undefined` only when the workbench does not know the device at all; an instance whose
749
+ * declaration is missing is reported as `view/unavailable-mode` instead of a view without views.
750
+ */
751
+ readonly device: (deviceId: string) => IHtmlViewDeviceDeclaration | undefined;
752
+ }
753
+
754
+ /** Everything one environment needs before the author document exists. */
755
+ export declare interface IHtmlViewTarget {
756
+ readonly instanceId: string;
757
+ readonly viewId: string;
758
+ readonly device: string;
759
+ readonly title: string;
760
+ /** Package-root relative `.html` entry of the view. */
761
+ readonly entry: string;
762
+ /** Absolute URL prefix that serves the verified package files of this view. */
763
+ readonly assetRoot: string;
764
+ /** Resolved property snapshot, identical to the one the model received. */
765
+ readonly props: FusedPresentationProps;
766
+ /** Declared model methods; empty for a device without a model. */
767
+ readonly methods: readonly string[];
768
+ /** Declared model events; empty for a device without a model. */
769
+ readonly events: readonly string[];
770
+ /** Whether the device declares a model; an absent model leaves `api.model` undefined. */
771
+ readonly hasModel: boolean;
772
+ }
773
+
774
+ /** Resolved workbench theme one environment mirrors into its author document. */
775
+ export declare interface IHtmlViewTheme {
776
+ readonly appearance: 'dark' | 'light';
777
+ /** Computed CSS colors of the workbench tokens; every token is present. */
778
+ readonly colors: WorkbenchThemeColors;
779
+ }
780
+
781
+ export declare function isHtmlViewError(value: unknown): value is HtmlViewError;
782
+
783
+ /** Response content type of one package file. */
784
+ export declare function mimeTypeOf(path: string): string;
785
+
786
+ /** Fresh environment id; distinct ids give every environment its own origin. */
787
+ export declare function newHtmlEnvironmentId(): string;
788
+
789
+ /**
790
+ * Validates one theme crossing the bridge and completes missing tokens.
791
+ *
792
+ * @throws {TypeError} when the appearance is unknown, a token is undeclared or a color cannot be
793
+ * placed in a style declaration.
794
+ */
795
+ export declare function normalizeHtmlViewTheme(value: unknown): IHtmlViewTheme;
796
+
797
+ /**
798
+ * Validates one `viewBaseUrlTemplate`.
799
+ *
800
+ * @throws {HtmlViewError} `view/invalid-base-url-template` when the template is not an absolute
801
+ * HTTP(S) directory URL with one standalone `${id}` hostname label on an independent origin.
802
+ */
803
+ export declare function parseHtmlViewBase(template: string, hostOrigin?: string): IHtmlViewBase;
804
+
805
+ /**
806
+ * Package path of one asset request, or `undefined` when the request leaves the package.
807
+ *
808
+ * `root` is the pathname of {@link assetRootUrl}; requests outside it, encoded separators and empty
809
+ * segments are rejected, so a view cannot read the environment bootstrap or another package.
810
+ */
811
+ export declare function resolveAssetRequest(pathname: string, root: string): string | undefined;
812
+
813
+ /** Placeholder of the environment id inside the template's hostname. */
814
+ export declare const VIEW_ENV_LABEL = "${id}";
815
+
816
+ /**
817
+ * Injects the document preamble of one view.
818
+ *
819
+ * The `<base>` must be the first base element, the policy travels with the document because it is
820
+ * written into a document of its own, and the theme declarations come before every author script so
821
+ * the author never paints a frame with missing tokens.
822
+ */
823
+ export declare function withHtmlDocumentPreamble(html: string, preamble: IHtmlDocumentPreamble): string;
824
+
825
+ declare const WORKBENCH_THEME_CSS_VARIABLES: Readonly<{
826
+ readonly 'workbench.background': "--mica-bg";
827
+ readonly 'workbench.foreground': "--mica-text";
828
+ readonly 'workbench.mutedForeground': "--mica-muted";
829
+ readonly 'panel.background': "--mica-panel";
830
+ readonly border: "--mica-border";
831
+ readonly accent: "--mica-accent";
832
+ readonly 'accent.foreground': "--mica-accent-foreground";
833
+ readonly 'selection.background': "--mica-active";
834
+ readonly 'focus.border': "--mica-focus";
835
+ readonly 'canvas.background': "--mica-canvas-background";
836
+ readonly 'canvas.grid': "--mica-canvas-grid";
837
+ readonly 'canvas.foreground': "--mica-canvas-foreground";
838
+ readonly 'canvas.wire': "--mica-canvas-wire";
839
+ readonly 'canvas.pin': "--mica-canvas-pin";
840
+ readonly 'canvas.selection': "--mica-canvas-selection";
841
+ readonly 'error.foreground': "--mica-error";
842
+ readonly shadow: "--mica-shadow";
843
+ }>;
844
+
845
+ declare type WorkbenchColorToken = keyof typeof WORKBENCH_THEME_CSS_VARIABLES;
846
+
847
+ declare type WorkbenchThemeColors = Readonly<Record<WorkbenchColorToken, string>>;
848
+
849
+ export { }