@mica-js/editor 0.13.0 → 0.14.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 CHANGED
@@ -35,6 +35,8 @@ await workbench.dispose();
35
35
 
36
36
  宿主直接传入 `FusedDocument`,自行维护项目身份和存储。`getDocument()` / `onDidChangeContent` 提供当前快照;可选的 `saveDocument(snapshot)` 完成后标记对应版本已保存,缺失时 `save()` 明确拒绝。器件 Provider 返回锁定发布版本的 `PackageFiles`,工作台校验文件清单和摘要。
37
37
 
38
+ `deviceStateProvider` 可持久化指定器件的二进制运行状态。`bindings` 按器件 ID 和锁定版本选择启动属性、查询方法与变化事件。启动时优先装载 `read` 返回的映像,缺失时使用电路配置。宿主用文档作用域与状态槽键定位 `read` / `write`,写入确认后运行时才视为已保存。工作台在停止、重启和关闭时等待保存,失败后可重试。预热不访问此存储。
39
+
38
40
  `assetProvider.select({ kind, formats, signal })` 打开宿主资产库 UI,返回 `{ id, name }` 或以 `undefined` 取消;`name` 包含文件扩展名。`read(id, signal)` 返回二进制,编辑器不枚举资产。普通资源仅支持 `asset` / `package`;`program` 另支持 `project`,使用 `programs.projects.select({ ...target, templateIds }, signal)` 选择项目、`resolve(id, target, signal?)` 取得程序产物。项目选择能力可省略,已有引用仍可解析;程序文件集资产使用 ZIP,校验解包后交给模型只读访问。
39
41
 
40
42
  属性字段以单行显示来源图标、引用名称和默认标记,通过同行图标打开来源菜单或内存装载设置浮层;新内容读取校验成功后才提交,取消和失败保留原值。项目选择的请求包含 `templateIds`,按属性的 `templates` 顺序传递,未声明时为空数组;宿主负责模板展示与项目创建,编辑器只保存返回的项目引用。内置资源从当前器件包选择,项目可独立打开。宿主接口合同见 [RFC 0028](../../docs/rfc/0028-workbench-host-resources.md)。
@@ -1 +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";
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-CyZiE7kS.js";
@@ -138,6 +138,32 @@ export declare type FusedView2DFactory = (context: IFusedView2DContext) => IFuse
138
138
 
139
139
  export declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
140
140
 
141
+ declare interface IDeviceStateBinding {
142
+ readonly device: string;
143
+ readonly version: string;
144
+ readonly slot: string;
145
+ readonly formatVersion: number;
146
+ readonly byteLength: number;
147
+ readonly property: string;
148
+ readonly method: string;
149
+ readonly event: string;
150
+ }
151
+
152
+ /** The caller scopes these keys to its account/workspace and stable document ID. */
153
+ declare interface IDeviceStateKey {
154
+ readonly instanceId: string;
155
+ readonly device: string;
156
+ readonly slot: string;
157
+ readonly formatVersion: number;
158
+ }
159
+
160
+ declare interface IDeviceStateProvider {
161
+ readonly bindings: readonly IDeviceStateBinding[];
162
+ read(key: IDeviceStateKey, signal: AbortSignal): Promise<Uint8Array | undefined>;
163
+ /** Atomically replace the slot. Resolve only after the write has committed. */
164
+ write(key: IDeviceStateKey, image: Uint8Array, signal: AbortSignal): Promise<void>;
165
+ }
166
+
141
167
  /** Audio handles belong to one instance generation, including while its body is hidden. */
142
168
  export declare interface IFusedAudio extends Omit<WidgetAudioApi, 'onStateChange' | 'createStream'> {
143
169
  readonly onDidChangeState: Event_2<FusedAudioState>;
@@ -189,6 +215,16 @@ export declare interface IFusedConnectionOptions {
189
215
  readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
190
216
  }
191
217
 
218
+ /** A configured slot and, if available, its persisted startup bytes. */
219
+ declare interface IFusedDeviceStateImage {
220
+ readonly instanceId: string;
221
+ readonly property: string;
222
+ readonly method: string;
223
+ readonly event: string;
224
+ readonly byteLength: number;
225
+ readonly image?: Uint8Array;
226
+ }
227
+
192
228
  /** 2D presentation surface the editor drives (RFC 0022). */
193
229
  export declare interface IFusedDisplay {
194
230
  /** Mode of the current presentation; `undefined` before the first preparation. */
@@ -382,6 +418,8 @@ export declare interface IFusedLoadRequest {
382
418
  readonly simulationPacing?: FusedSimulationPacing;
383
419
  /** Explicit simulator batch-execution switch; omitted uses the board default. */
384
420
  readonly batchExecution?: boolean;
421
+ readonly deviceState?: readonly IFusedDeviceStateImage[];
422
+ readonly stateGeneration?: number;
385
423
  }
386
424
 
387
425
  /** Model lane served by the simulation guest to the display guest over the direct port. */
@@ -427,6 +465,7 @@ export declare interface IFusedModelEventWire {
427
465
  readonly instanceId: string;
428
466
  readonly event: string;
429
467
  readonly payload: ModelEvent<Value>;
468
+ readonly stateGeneration?: number;
430
469
  }
431
470
 
432
471
  /** Model event lane served by the display guest to the simulation guest. */
@@ -459,10 +498,15 @@ export declare interface IFusedPackageFilesWire {
459
498
  export declare interface IFusedPrepareRequest {
460
499
  readonly document: FusedDocument;
461
500
  readonly mode: FusedDisplayMode;
501
+ readonly deviceState?: readonly IFusedDeviceStateImage[];
462
502
  }
463
503
 
464
504
  export declare interface IFusedPrepareResult {
465
505
  readonly instances: readonly IFusedInstancePresentation[];
506
+ readonly deviceState?: readonly {
507
+ readonly instanceId: string;
508
+ readonly image: Uint8Array;
509
+ }[];
466
510
  }
467
511
 
468
512
  declare interface IFusedProgramFilesSnapshot {
@@ -516,6 +560,7 @@ export declare interface IFusedRuntime {
516
560
  }
517
561
 
518
562
  export declare interface IFusedRuntimeOptions {
563
+ readonly deviceStateProvider?: IDeviceStateProvider;
519
564
  /** Caller-owned browser context; resume it directly within a user gesture for autoplay. */
520
565
  readonly audio?: IFusedAudioOptions;
521
566
  /** Fused `.sch` version 2 document; the simulation guest snapshots it. */
@@ -1,3 +1,3 @@
1
- import { c as toWireFailure, i as isFusedBridgeError, n as FusedBridgeError, o as mapWireFailure, r as fromWireFailure, t as FUSED_WIRE_FAILURE } from "./wire-BDHL5Aj9.js";
2
- import { _ as fusedModelSinkService, a as createFusedRuntime, c as createModelEventRouter, d as createHostPackageGateway, f as packageLockKey, g as fusedModelChannelService, h as fusedHostResourceService, i as startFusedSimulationGuest, l as createFusedDisplay, m as fusedHostPackageService, n as startFusedDisplayGuest, o as createHostModelRouter, p as fusedDisplayService, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedSimulationService } from "./runtime-hyeAcSP7.js";
1
+ import { c as toWireFailure, i as isFusedBridgeError, n as FusedBridgeError, o as mapWireFailure, r as fromWireFailure, t as FUSED_WIRE_FAILURE } from "./wire-Di4FVpnu.js";
2
+ import { _ as fusedModelSinkService, a as createFusedRuntime, c as createModelEventRouter, d as createHostPackageGateway, f as packageLockKey, g as fusedModelChannelService, h as fusedHostResourceService, i as startFusedSimulationGuest, l as createFusedDisplay, m as fusedHostPackageService, n as startFusedDisplayGuest, o as createHostModelRouter, p as fusedDisplayService, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedSimulationService } from "./runtime-_9IqvWDa.js";
3
3
  export { FUSED_WIRE_FAILURE, FusedBridgeError, channelKey, connectFusedWorkbench, createFusedDisplay, createFusedRuntime, createHostModelRouter, createHostPackageGateway, createModelEventRouter, createViewSession, fromWireFailure, fusedDisplayService, fusedHostPackageService, fusedHostResourceService, fusedModelChannelService, fusedModelSinkService, fusedSimulationService, isFusedBridgeError, loadFusedWorkerFactories, mapWireFailure, packageLockKey, startFusedDisplayGuest, startFusedSimulationGuest, toWireFailure };
package/dist/fused.d.ts CHANGED
@@ -261,6 +261,32 @@ export declare interface IDeviceAdditionContext extends IDocumentAccessContext {
261
261
 
262
262
  export { IDeviceProvider }
263
263
 
264
+ export declare interface IDeviceStateBinding {
265
+ readonly device: string;
266
+ readonly version: string;
267
+ readonly slot: string;
268
+ readonly formatVersion: number;
269
+ readonly byteLength: number;
270
+ readonly property: string;
271
+ readonly method: string;
272
+ readonly event: string;
273
+ }
274
+
275
+ /** The caller scopes these keys to its account/workspace and stable document ID. */
276
+ export declare interface IDeviceStateKey {
277
+ readonly instanceId: string;
278
+ readonly device: string;
279
+ readonly slot: string;
280
+ readonly formatVersion: number;
281
+ }
282
+
283
+ export declare interface IDeviceStateProvider {
284
+ readonly bindings: readonly IDeviceStateBinding[];
285
+ read(key: IDeviceStateKey, signal: AbortSignal): Promise<Uint8Array | undefined>;
286
+ /** Atomically replace the slot. Resolve only after the write has committed. */
287
+ write(key: IDeviceStateKey, image: Uint8Array, signal: AbortSignal): Promise<void>;
288
+ }
289
+
264
290
  export declare interface IDocumentAccess {
265
291
  readonly edit: AccessDecision;
266
292
  readonly run: AccessDecision;
@@ -528,6 +554,7 @@ export declare interface IWorkbenchExtensionContext {
528
554
  }
529
555
 
530
556
  export declare interface IWorkbenchOptions {
557
+ readonly deviceStateProvider?: IDeviceStateProvider;
531
558
  /** Caller-owned browser context, automatically resumed on document-wide user gestures. */
532
559
  readonly audio?: IFusedAudioOptions;
533
560
  readonly container: HTMLElement;
package/dist/fused.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { c as planPolylineSegmentDrag, n as orthogonalWaypoints, t as extendWirePath } from "./wire-JZIiIOI0.js";
2
- import { Q as isHtmlViewError, _ as resolveTheme, a as createHtmlViewHost, f as WORKBENCH_DARK_COLORS, g as readCanvasTheme, h as normalizeTheme, m as WORKBENCH_THEME_CSS_VARIABLES, p as WORKBENCH_LIGHT_COLORS, v as themeStyle } from "./html-HXwZq1my.js";
3
- import { a as createFusedRuntime } from "./runtime-hyeAcSP7.js";
2
+ import { Q as isHtmlViewError, _ as resolveTheme, a as createHtmlViewHost, f as WORKBENCH_DARK_COLORS, g as readCanvasTheme, h as normalizeTheme, m as WORKBENCH_THEME_CSS_VARIABLES, p as WORKBENCH_LIGHT_COLORS, v as themeStyle } from "./html-CyZiE7kS.js";
3
+ import { a as createFusedRuntime } from "./runtime-_9IqvWDa.js";
4
4
  import { DisposableStore, Emitter } from "@mica-js/core/lifecycle";
5
5
  import { projectOnSegment } from "@mica-js/document/schematic";
6
6
  import { timePs } from "@mica-js/core";
@@ -6772,6 +6772,7 @@ async function createWorkbench(options) {
6772
6772
  })) return void 0;
6773
6773
  const result = await createFusedRuntime({
6774
6774
  ...options.audio === void 0 ? {} : { audio: options.audio },
6775
+ ...options.deviceStateProvider === void 0 ? {} : { deviceStateProvider: options.deviceStateProvider },
6775
6776
  document,
6776
6777
  registry: options.deviceProvider,
6777
6778
  step,
@@ -6887,6 +6888,7 @@ async function createWorkbench(options) {
6887
6888
  if (!permission.allowed) throw new Error(permission.message);
6888
6889
  mode = "run";
6889
6890
  } else try {
6891
+ if (options.deviceStateProvider !== void 0) await runtime?.pause();
6890
6892
  await documentSession.setRunning(false);
6891
6893
  mode = "edit";
6892
6894
  if (runtime === void 0) presentationSignature = "";
@@ -7209,9 +7211,13 @@ async function createWorkbench(options) {
7209
7211
  },
7210
7212
  dispose() {
7211
7213
  if (disposal !== void 0) return disposal;
7212
- disposed = true;
7213
- abort.abort();
7214
7214
  disposal = (async () => {
7215
+ if (options.deviceStateProvider !== void 0) {
7216
+ await transition;
7217
+ await runtime?.pause();
7218
+ }
7219
+ disposed = true;
7220
+ abort.abort();
7215
7221
  const errors = [];
7216
7222
  const release = async (action) => {
7217
7223
  try {
@@ -7235,7 +7241,10 @@ async function createWorkbench(options) {
7235
7241
  mount.remove();
7236
7242
  environment.remove();
7237
7243
  if (errors.length) throw new AggregateError(errors, "Failed to release workbench resources");
7238
- })();
7244
+ })().catch((reason) => {
7245
+ if (!disposed) disposal = void 0;
7246
+ throw reason;
7247
+ });
7239
7248
  return disposal;
7240
7249
  }
7241
7250
  };