@paged-media/plugin-sdk 0.2.56-canary.0 → 0.2.57-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.
Files changed (2) hide show
  1. package/dist/index.js +79 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16486,7 +16486,9 @@ function createBundleHost(getEditor, manifest, options) {
16486
16486
  // like `getPlacedImage` (no injected provider): the document registry
16487
16487
  // is the engine's. Fill-only — the engine is asked first whether it
16488
16488
  // holds the face, and a held face is never sent again — so a bundle
16489
- // cannot change how text that already resolves is drawn.
16489
+ // cannot change how text that already resolves is drawn. ADR 330 — its
16490
+ // lifetime is the client's: one with `registerDocumentFont` scopes the
16491
+ // face to the open document (`@2`).
16490
16492
  async registerDocumentFont(bytes, family, style) {
16491
16493
  requireDeclared(
16492
16494
  hasAsset("fonts"),
@@ -16512,7 +16514,7 @@ function createBundleHost(getEditor, manifest, options) {
16512
16514
  container === "woff" ? "a WOFF or WOFF2 face \u2014 the canvas reads TrueType and OpenType only" : "the bytes are not a TrueType or OpenType face"
16513
16515
  );
16514
16516
  }
16515
- const face = Array.from(bytes);
16517
+ const face = bytes.slice();
16516
16518
  let client;
16517
16519
  try {
16518
16520
  client = getEditor().client;
@@ -16528,10 +16530,20 @@ function createBundleHost(getEditor, manifest, options) {
16528
16530
  if (held.kind === "fontFaceBytes" && held.payload.found && (style === void 0 || held.payload.style === style)) {
16529
16531
  return { status: "held" };
16530
16532
  }
16531
- const reply = await client.send({
16532
- kind: "registerFont",
16533
- payload: { family, style: style ?? null, bytes: face, scope: "document" }
16534
- });
16533
+ const scoped = client.registerDocumentFont;
16534
+ let reply;
16535
+ if (typeof scoped === "function") {
16536
+ try {
16537
+ reply = await scoped.call(client, family, face, style ?? null);
16538
+ } catch (err) {
16539
+ return refuse3(err instanceof Error ? err.message : String(err));
16540
+ }
16541
+ } else {
16542
+ reply = await client.send({
16543
+ kind: "registerFont",
16544
+ payload: { family, style: style ?? null, bytes: Array.from(face), scope: "document" }
16545
+ });
16546
+ }
16535
16547
  if (reply.kind !== "fontRegistered") {
16536
16548
  return refuse3(`the engine answered ${reply.kind}`);
16537
16549
  }
@@ -17158,6 +17170,9 @@ function createBundleHost(getEditor, manifest, options) {
17158
17170
  featureSet.add("rendering.sceneLayer.binary@1");
17159
17171
  }
17160
17172
  }
17173
+ if (typeof getEditor().client?.registerDocumentFont === "function") {
17174
+ featureSet.add("assets.documentFont@2");
17175
+ }
17161
17176
  if (typeof getEditor().mutateWithBytes === "function") {
17162
17177
  featureSet.add("document.mutateBinary@1");
17163
17178
  }
@@ -17651,6 +17666,46 @@ function makeEngineEditor(worker, recorder, onToolPreview, onToolPreviews, overl
17651
17666
  const raw = worker.handleMessage(envelope);
17652
17667
  return JSON.parse(raw);
17653
17668
  };
17669
+ const registry = [];
17670
+ let openDocId = null;
17671
+ const documentScope = (payload) => (payload?.scope ?? "document") === "document";
17672
+ const registerFace = (face) => {
17673
+ const reply = dispatch("registerFont", {
17674
+ family: face.family,
17675
+ style: face.style,
17676
+ bytes: face.bytes,
17677
+ scope: "document"
17678
+ });
17679
+ if (reply.kind !== "fontRegistered") return false;
17680
+ registry.push(face);
17681
+ return true;
17682
+ };
17683
+ const note = (kind, payload, reply) => {
17684
+ if (kind === "registerFont" && reply.kind === "fontRegistered" && documentScope(payload)) {
17685
+ const p = payload;
17686
+ registry.push({ family: p.family, style: p.style ?? null, bytes: p.bytes, owner: null });
17687
+ } else if (kind === "clearFontRegistry" && reply.kind === "fontRegistryCleared" && documentScope(payload)) {
17688
+ registry.length = 0;
17689
+ }
17690
+ };
17691
+ const loads = {
17692
+ begin() {
17693
+ const dropped = registry.filter((f) => f.owner !== null);
17694
+ if (dropped.length === 0) return dropped;
17695
+ const keep = registry.filter((f) => f.owner === null);
17696
+ registry.length = 0;
17697
+ dispatch("clearFontRegistry");
17698
+ for (const face of keep) registerFace(face);
17699
+ return dropped;
17700
+ },
17701
+ end(reply, dropped) {
17702
+ if (reply.kind === "documentLoaded") {
17703
+ openDocId = reply.payload.docId;
17704
+ return;
17705
+ }
17706
+ for (const face of dropped) registerFace(face);
17707
+ }
17708
+ };
17654
17709
  const recordingRegistry = (kind) => ({
17655
17710
  register(contribution) {
17656
17711
  const entry = {
@@ -17742,13 +17797,27 @@ function makeEngineEditor(worker, recorder, onToolPreview, onToolPreviews, overl
17742
17797
  },
17743
17798
  async send(message) {
17744
17799
  const m = message;
17800
+ if (m.kind === "loadDocument" || m.kind === "newBlankDocument") {
17801
+ const dropped = loads.begin();
17802
+ const loaded = dispatch(m.kind, m.payload);
17803
+ loads.end(loaded, dropped);
17804
+ return loaded;
17805
+ }
17745
17806
  const reply = dispatch(m.kind, m.payload);
17807
+ note(m.kind, m.payload, reply);
17746
17808
  if (documentChangeOf(reply) !== null) fanOut(reply);
17747
17809
  return reply;
17748
17810
  },
17749
17811
  subscribe(listener) {
17750
17812
  listeners.add(listener);
17751
17813
  return () => listeners.delete(listener);
17814
+ },
17815
+ async registerDocumentFont(family, bytes, style) {
17816
+ if (openDocId === null) throw new Error("no document is open to give the face to");
17817
+ const face = { family, style, bytes: Array.from(bytes), owner: openDocId };
17818
+ const reply = dispatch("registerFont", { family, style, bytes: face.bytes, scope: "document" });
17819
+ if (reply.kind === "fontRegistered") registry.push(face);
17820
+ return reply;
17752
17821
  }
17753
17822
  };
17754
17823
  const editor = {
@@ -17824,7 +17893,7 @@ function makeEngineEditor(worker, recorder, onToolPreview, onToolPreviews, overl
17824
17893
  }
17825
17894
  };
17826
17895
  }
17827
- return { editor, fanOut };
17896
+ return { editor, fanOut, loads };
17828
17897
  }
17829
17898
  async function createHeadlessHost(options = {}) {
17830
17899
  const engine = await loadHeadlessEngine(options);
@@ -17833,7 +17902,7 @@ async function createHeadlessHost(options = {}) {
17833
17902
  let lastPreview = null;
17834
17903
  let lastPreviews = null;
17835
17904
  const overlayLayerMap = /* @__PURE__ */ new Map();
17836
- const { editor, fanOut } = makeEngineEditor(
17905
+ const { editor, fanOut, loads } = makeEngineEditor(
17837
17906
  worker,
17838
17907
  contributions,
17839
17908
  (value) => {
@@ -17846,9 +17915,11 @@ async function createHeadlessHost(options = {}) {
17846
17915
  options.engineShaper === true
17847
17916
  );
17848
17917
  const loadDirect = (bytes) => {
17918
+ const dropped = loads.begin();
17849
17919
  const reply = JSON.parse(
17850
17920
  options.defaultFont ? worker.loadDocumentDirect(seqCounter++, bytes, options.defaultFont) : worker.loadDocumentDirect(seqCounter++, bytes)
17851
17921
  );
17922
+ loads.end(reply, dropped);
17852
17923
  if (reply.kind === "documentLoaded") {
17853
17924
  try {
17854
17925
  worker.runResolveJson();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paged-media/plugin-sdk",
3
- "version": "0.2.56-canary.0",
3
+ "version": "0.2.57-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.56-canary.0"
14
+ "@paged-media/plugin-api": "0.2.57-canary.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "^18.3.0"