@paged-media/plugin-sdk 0.2.42-canary.0 → 0.2.43-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -273,6 +273,18 @@ interface DocumentsBackend {
273
273
  };
274
274
  }): Promise<OpenDocumentResult>;
275
275
  }
276
+ /**
277
+ * v70 — the backend the editor injects to back `host.viewport`'s page
278
+ * members. The editor owns the camera and the page layout, so it answers
279
+ * which page is active and moves the camera to one. No backend →
280
+ * `goToPage` answers false, `activePage` null, the event never fires and
281
+ * `supports("viewport.pages@1")` is false.
282
+ */
283
+ interface PagesBackend {
284
+ goToPage(pageId: string, fit: "page" | "width"): boolean | Promise<boolean>;
285
+ activePage(): string | null;
286
+ onDidChangeActivePage(listener: (pageId: string | null) => void): () => void;
287
+ }
276
288
  /** The SHARED cross-plugin data-provider registry (paged.data §7.1 / D-09). The
277
289
  * editor creates ONE (`createDataProviderRegistry`) and injects the SAME
278
290
  * instance into every plugin host, so a provider plugin and a consumer plugin
@@ -515,6 +527,10 @@ interface CreateBundleHostOptions {
515
527
  * `supports("documents.exportPaged@1")` / `supports("documents.open@1")`
516
528
  * answer true. When absent, both doors reject. */
517
529
  documents?: DocumentsBackend;
530
+ /** v70 — page navigation for `host.viewport` (`goToPage`,
531
+ * `activePage`, `onDidChangeActivePage`). When present,
532
+ * `supports("viewport.pages@1")` is true. */
533
+ pages?: PagesBackend;
518
534
  /** Host-provided WORKER backend (K-3 / S-07 / I-02). When present,
519
535
  * `host.workers.spawn` resolves a declared bundle-relative module +
520
536
  * constructs a host-owned `Worker` through it (capability-gated,
@@ -1021,4 +1037,4 @@ declare function contributeObjectType(host: BundleHost, contribution: ObjectType
1021
1037
  */
1022
1038
  declare function contributeBindingProvider(host: BundleHost, contextType: string, provider: BindingProvider): BindingProviderHandle;
1023
1039
 
1024
- export { API_VERSION, ASSET_BUDGETS, BLOB_BUDGETS, type BindingProviderBackend, type BlobStore, type BundleAssetProvider, type BundleAssetSource, type BundleHostHandle, type BundleTrust, CANVAS_WASM_PKG, CLICK_DRAG_THRESHOLD_PX, type ClipboardBackend, type ConsentBackend, type CreateBundleHostOptions, type DataProviderBackend, type DiagnosticsSink, DisposableStore, type DocumentsBackend, FALLBACK_WIDGETS, HOST_FEATURES, type HarnessOptions, type HeadlessCanvasWorker, type HeadlessHost, type HeadlessHostHandle, type JournalSink, type LoadBundleWasmOptions, type LoadHeadlessEngineOptions, type LoadedBundle, type LoadedBundleWasm, type LoadedEngine, type NativeDocumentBackend, type PageDrag, PluginApiNotImplemented, PluginCapabilityError, type RecordableAssetSource, type RecordedContribution, type RecordedFontFaceRequest, type RegisteredBindingProvider, type SecretStoreBackend, type SeededFace, type ShellBackend, type SpawnedWorker, type StorageBacking, type TextCaretBackend, type ToolSettingsBackend, WASM_BUDGETS, WORKER_BUDGETS, type WillSaveBackend, type WorkerBackend, beginPageDrag, commitAndSelect, contributeBindingProvider, contributeEditContext, contributeObjectType, contributePanel, contributeSchemaPanel, contributeTool, createBindingProviderRegistry, createBundleHost, createDataProviderRegistry, createHeadlessHost, createRecordableAssetSource, defineBundle, endLocalFor, inMemoryToolSettings, inMemoryWillSave, loadBundle, loadBundleWasm, loadHeadlessEngine, makeSchemaPanelComponent, protocolFromVersion, pxToPt, readVendoredWireVersion, resolveCanvasWasm, resolveGate, satisfiesApiVersion, toDisposable };
1040
+ export { API_VERSION, ASSET_BUDGETS, BLOB_BUDGETS, type BindingProviderBackend, type BlobStore, type BundleAssetProvider, type BundleAssetSource, type BundleHostHandle, type BundleTrust, CANVAS_WASM_PKG, CLICK_DRAG_THRESHOLD_PX, type ClipboardBackend, type ConsentBackend, type CreateBundleHostOptions, type DataProviderBackend, type DiagnosticsSink, DisposableStore, type DocumentsBackend, FALLBACK_WIDGETS, HOST_FEATURES, type HarnessOptions, type HeadlessCanvasWorker, type HeadlessHost, type HeadlessHostHandle, type JournalSink, type LoadBundleWasmOptions, type LoadHeadlessEngineOptions, type LoadedBundle, type LoadedBundleWasm, type LoadedEngine, type NativeDocumentBackend, type PageDrag, type PagesBackend, PluginApiNotImplemented, PluginCapabilityError, type RecordableAssetSource, type RecordedContribution, type RecordedFontFaceRequest, type RegisteredBindingProvider, type SecretStoreBackend, type SeededFace, type ShellBackend, type SpawnedWorker, type StorageBacking, type TextCaretBackend, type ToolSettingsBackend, WASM_BUDGETS, WORKER_BUDGETS, type WillSaveBackend, type WorkerBackend, beginPageDrag, commitAndSelect, contributeBindingProvider, contributeEditContext, contributeObjectType, contributePanel, contributeSchemaPanel, contributeTool, createBindingProviderRegistry, createBundleHost, createDataProviderRegistry, createHeadlessHost, createRecordableAssetSource, defineBundle, endLocalFor, inMemoryToolSettings, inMemoryWillSave, loadBundle, loadBundleWasm, loadHeadlessEngine, makeSchemaPanelComponent, protocolFromVersion, pxToPt, readVendoredWireVersion, resolveCanvasWasm, resolveGate, satisfiesApiVersion, toDisposable };
package/dist/index.js CHANGED
@@ -279,6 +279,10 @@ var HOST_FEATURES = [
279
279
  // door: the flag says this SDK forwards `snapPoint`; an engine older
280
280
  // than v67 answers the point unsnapped, never a throw.
281
281
  "document.snapPoint@1",
282
+ // v70 — page images from the engine's renderer (`requestSnapshot` with
283
+ // `hideItems`). Static like the snapper: the flag says this SDK
284
+ // forwards the query; an engine that refuses answers null.
285
+ "render.snapshot@1",
282
286
  // DOC-03 structured whole-story read (canvas-wasm v54). Static for the same
283
287
  // reason as storage.parts@1: the pinned engine is the server, and the worker
284
288
  // handshake refuses a protocol older than the pin — so a running bundle is
@@ -1520,6 +1524,7 @@ function createBundleHost(getEditor, manifest, options) {
1520
1524
  return store.add(toDisposable(off));
1521
1525
  }
1522
1526
  };
1527
+ const pagesBackend = options?.pages;
1523
1528
  const viewport = {
1524
1529
  camera() {
1525
1530
  const cam = getEditor().camera.camera;
@@ -1528,6 +1533,53 @@ function createBundleHost(getEditor, manifest, options) {
1528
1533
  pxToPt(px) {
1529
1534
  const scale = getEditor().camera.camera.scale;
1530
1535
  return px / (scale > 0 ? scale : 1);
1536
+ },
1537
+ async goToPage(pageId, opts) {
1538
+ if (!pagesBackend || typeof pageId !== "string" || pageId === "") {
1539
+ return false;
1540
+ }
1541
+ const fit = opts?.fit === "width" ? "width" : "page";
1542
+ return await pagesBackend.goToPage(pageId, fit) === true;
1543
+ },
1544
+ activePage() {
1545
+ return pagesBackend ? pagesBackend.activePage() : null;
1546
+ },
1547
+ onDidChangeActivePage(listener) {
1548
+ if (!pagesBackend) {
1549
+ return toDisposable(() => {
1550
+ });
1551
+ }
1552
+ return store.add(toDisposable(pagesBackend.onDidChangeActivePage(listener)));
1553
+ }
1554
+ };
1555
+ const render = {
1556
+ async snapshot(pageId, opts) {
1557
+ requireDocRead("render.snapshot");
1558
+ const widthPx = Math.round(opts?.widthPx ?? 0);
1559
+ if (!(widthPx >= 1 && widthPx <= 8192)) {
1560
+ throw new Error("host.render.snapshot: widthPx must be 1 to 8192");
1561
+ }
1562
+ const hideItems = Array.isArray(opts?.hideItems) ? opts.hideItems : [];
1563
+ let reply;
1564
+ try {
1565
+ reply = await getEditor().client.send({
1566
+ kind: "requestSnapshot",
1567
+ payload: { pageId, targetWidthPx: widthPx, hideItems }
1568
+ });
1569
+ } catch {
1570
+ return null;
1571
+ }
1572
+ if (reply.kind !== "snapshotReady") {
1573
+ return null;
1574
+ }
1575
+ const p = reply.payload;
1576
+ return {
1577
+ pageId: p.pageId,
1578
+ widthPx: p.widthPx,
1579
+ heightPx: p.heightPx,
1580
+ png: Uint8Array.from(p.pngBytes),
1581
+ layoutGeneration: p.layoutGeneration
1582
+ };
1531
1583
  }
1532
1584
  };
1533
1585
  const text = {
@@ -2577,6 +2629,9 @@ function createBundleHost(getEditor, manifest, options) {
2577
2629
  featureSet.add("document.readNative@1");
2578
2630
  featureSet.add("document.openNative@1");
2579
2631
  }
2632
+ if (options?.pages) {
2633
+ featureSet.add("viewport.pages@1");
2634
+ }
2580
2635
  if (options?.documents) {
2581
2636
  featureSet.add("documents.exportPaged@1");
2582
2637
  featureSet.add("documents.open@1");
@@ -2597,6 +2652,7 @@ function createBundleHost(getEditor, manifest, options) {
2597
2652
  document,
2598
2653
  selection,
2599
2654
  viewport,
2655
+ render,
2600
2656
  text,
2601
2657
  overlay,
2602
2658
  shell,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paged-media/plugin-sdk",
3
- "version": "0.2.42-canary.0",
3
+ "version": "0.2.43-canary.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@paged-media/plugin-api": "0.2.42-canary.0"
14
+ "@paged-media/plugin-api": "0.2.43-canary.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "^18.3.0"