@deepseek-ai/libreoffice-kit 0.0.2-rc5 → 0.0.2-rc6

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
@@ -54,6 +54,8 @@ Node operations and the Host font service use bounded system-font discovery. Exa
54
54
 
55
55
  `createFontSource` from `@deepseek-ai/libreoffice-kit/fonts` provides an independent lazy Worker service. `resolve(attributes)` retains the Unicode-script subset behavior for interactive Office. `resolve({...attributes, mode:'full'})` returns opaque `full_…` identities, original family names and `format` (`ttf`, `otf`, `ttc`); `read(id)` returns complete original font bytes. Apple dfont resources are extracted as complete sfnt faces. Reads reject unknown or changed sources and do not expose host paths.
56
56
 
57
+ Full-mode selections from the same unchanged TTC share one file read and retained byte entry while keeping each selected family's name and alias. The existing cache budget counts unique full assets once; eviction may require a later read to regenerate them. Subsets and dfont resources remain specific to each physical face.
58
+
57
59
  PDFium is an experimental direct raster path, separate from PDF.js and Office reading sessions. Embedded PDF fonts remain PDFium-owned. A fixed, bounded set of regular faces selected from `initialFontFamilies` and fallback groups is mounted before PDFium's first font enumeration. This does not infer every arbitrary PDF font or repair custom encodings. Password-protected PDFs are rejected; forms are rasterized by the upstream PDFium wrapper, while ordinary annotations and advanced PDF features require further qualification.
58
60
 
59
61
  ## Browser and font entries
@@ -31,16 +31,16 @@
31
31
  "sha256": "3dbe51aba06e309bc9a8573462af1a8c93628cf325e88db7d32320fc2a9d54e8"
32
32
  },
33
33
  "sources/font-subset/scripts/platform-matrix.mjs": {
34
- "bytes": 4810,
35
- "sha256": "fb5656feafafa89e02d1217bea5e36e3fea7583f113dbda8ff50ba5c966c411b"
34
+ "bytes": 4819,
35
+ "sha256": "870716743136c2a79283910ed58b73aa88766a94f491ca171a59c7fb7512890d"
36
36
  },
37
37
  "sources/font-subset/scripts/pack-utils.mjs": {
38
38
  "bytes": 3327,
39
39
  "sha256": "aa5368e0dd38d90459f0ef14e1d4b27740aef2f4e46617aca6d6fafed0577a44"
40
40
  },
41
41
  "sources/font-subset/scripts/verify-artifacts.mjs": {
42
- "bytes": 15997,
43
- "sha256": "6e89c766a49aa5cb3859e25ae16cdf48e0355df53a5210061b475357709f0cec"
42
+ "bytes": 16017,
43
+ "sha256": "b69af5760f7ebfedece94f198dba765def2fd840a4d46bdb8c8b7729fb4884ea"
44
44
  },
45
45
  "sources/font-subset/engine/font-subset/README.md": {
46
46
  "bytes": 2130,
@@ -3,8 +3,8 @@
3
3
  "files": {
4
4
  "worker": {
5
5
  "path": "lib/browser/worker.js",
6
- "bytes": 114732,
7
- "sha256": "9e4d6b2a7d9598fbfcf14d1a359ba0c962f4c94772849224ac4ba68dd6c725e5"
6
+ "bytes": 116577,
7
+ "sha256": "81237217e64c708763b3e8c2128ed29c1d589ddd4753008c761396d69449eb43"
8
8
  }
9
9
  }
10
10
  }
@@ -21,16 +21,26 @@ function fontViews(channel) {
21
21
  bytes: new Uint8Array(channel, 8)
22
22
  };
23
23
  }
24
- /** Frames are produced lazily so the transfer channel never duplicates a whole font set. */
25
- function* fontFrames(result) {
24
+ /** Only uninstalled content crosses the channel; each family retains its own alias. */
25
+ function* fontFrames(result, known = []) {
26
+ const identities = new Map(known.map((font) => [font.id, font]));
26
27
  const header = {
27
- fonts: result.fonts.map((font) => ({
28
- id: font.id,
29
- bytes: font.data.byteLength,
30
- family: font.family,
31
- alias: font.alias,
32
- ...font.format ? { format: font.format } : {}
33
- })),
28
+ fonts: result.fonts.map((font) => {
29
+ const identity = {
30
+ id: font.id,
31
+ bytes: font.data.byteLength,
32
+ ...font.format ? { format: font.format } : {}
33
+ };
34
+ const prior = identities.get(font.id);
35
+ if (prior && (prior.bytes !== identity.bytes || prior.format !== identity.format)) throw new BrowserRenderError("font-unavailable", "Font identity has conflicting bytes or formats.");
36
+ identities.set(font.id, identity);
37
+ return {
38
+ ...identity,
39
+ family: font.family,
40
+ alias: font.alias,
41
+ ...prior ? { reference: true } : {}
42
+ };
43
+ }),
34
44
  ...result.missingFamily === void 0 ? {} : { missingFamily: result.missingFamily }
35
45
  };
36
46
  const encoded = new TextEncoder().encode(JSON.stringify(header));
@@ -39,10 +49,13 @@ function* fontFrames(result) {
39
49
  state: 1,
40
50
  bytes: encoded
41
51
  };
42
- for (const font of result.fonts) for (let offset = 0; offset < font.data.byteLength; offset += FONT_CHUNK_BYTES) yield {
43
- state: 2,
44
- bytes: font.data.subarray(offset, offset + FONT_CHUNK_BYTES)
45
- };
52
+ for (const [index, font] of result.fonts.entries()) {
53
+ if (header.fonts[index].reference) continue;
54
+ for (let offset = 0; offset < font.data.byteLength; offset += FONT_CHUNK_BYTES) yield {
55
+ state: 2,
56
+ bytes: font.data.subarray(offset, offset + FONT_CHUNK_BYTES)
57
+ };
58
+ }
46
59
  yield {
47
60
  state: 3,
48
61
  bytes: /* @__PURE__ */ new Uint8Array()
@@ -126,7 +139,7 @@ async function openBrowserConnection(options, signal, office = false, onEvent) {
126
139
  if (closed) return;
127
140
  Promise.resolve().then(() => options.resolveFonts(message.request, lifetime.signal)).then((result) => {
128
141
  if (closed) return;
129
- frames = fontFrames(result);
142
+ frames = fontFrames(result, message.known);
130
143
  pumpFonts();
131
144
  }, sendFontError);
132
145
  return;
@@ -1,12 +1,13 @@
1
1
  import { FontState } from './protocol.ts';
2
+ import type { FontIdentity } from './protocol.ts';
2
3
  import type { BrowserFontRequest, BrowserFontResult } from './types.ts';
3
4
  /** Views shared by the owner and engine; only the engine uses Atomics.wait. */
4
5
  export declare function fontViews(channel: SharedArrayBuffer): {
5
6
  control: Int32Array;
6
7
  bytes: Uint8Array;
7
8
  };
8
- /** Frames are produced lazily so the transfer channel never duplicates a whole font set. */
9
- export declare function fontFrames(result: BrowserFontResult): Generator<{
9
+ /** Only uninstalled content crosses the channel; each family retains its own alias. */
10
+ export declare function fontFrames(result: BrowserFontResult, known?: readonly FontIdentity[]): Generator<{
10
11
  state: FontState;
11
12
  bytes: Uint8Array;
12
13
  }>;
@@ -15,6 +16,6 @@ export interface EngineFontFace {
15
16
  readonly path: string;
16
17
  readonly family: string;
17
18
  }
18
- /** The synchronous reader installs immutable subsets before returning their MEMFS paths and aliases. */
19
- export declare function createFontReader(channel: SharedArrayBuffer, timeoutMs: number, maxLoadedFontBytes: number, declaredFamilies: ReadonlyMap<string, string>, request: (request: BrowserFontRequest) => void, next: () => void, install: (path: string, bytes: Uint8Array) => void, missing: (families: readonly string[]) => void): (request: BrowserFontRequest) => EngineFontFace[];
19
+ /** The synchronous reader installs immutable font assets before returning their MEMFS paths and aliases. */
20
+ export declare function createFontReader(channel: SharedArrayBuffer, timeoutMs: number, maxLoadedFontBytes: number, declaredFamilies: ReadonlyMap<string, string>, request: (request: BrowserFontRequest, known: readonly FontIdentity[]) => void, next: () => void, install: (path: string, bytes: Uint8Array) => void, missing: (families: readonly string[]) => void): (request: BrowserFontRequest) => EngineFontFace[];
20
21
  //# sourceMappingURL=font-channel.d.ts.map
@@ -15,6 +15,8 @@ export declare class OfficeEngine {
15
15
  private stopped;
16
16
  private layoutWidth;
17
17
  private viewport;
18
+ private captureView;
19
+ private readingView;
18
20
  private commandResult;
19
21
  constructor(module: EmscriptenModule, document: number, format: OfficeDocumentFormat, emit: (event: OfficeDocumentEvent) => void, failure: (error: unknown) => void);
20
22
  private call;
@@ -89,20 +89,25 @@ export type WorkerMessage = {
89
89
  } | {
90
90
  readonly type: 'font';
91
91
  readonly request: BrowserFontRequest;
92
+ readonly known: readonly FontIdentity[];
92
93
  } | {
93
94
  readonly type: 'font-next';
94
95
  } | {
95
96
  readonly type: 'missing-fonts';
96
97
  readonly families: readonly string[];
97
98
  };
99
+ /** Immutable bytes already installed in this document's MEMFS. */
100
+ export interface FontIdentity {
101
+ readonly id: string;
102
+ readonly bytes: number;
103
+ readonly format?: 'ttf' | 'otf' | 'ttc';
104
+ }
98
105
  export interface FontHeader {
99
- readonly fonts: readonly {
100
- readonly id: string;
101
- readonly bytes: number;
106
+ readonly fonts: readonly (FontIdentity & {
102
107
  readonly family: string;
103
108
  readonly alias: string;
104
- readonly format?: 'ttf' | 'otf' | 'ttc';
105
- }[];
109
+ readonly reference?: true;
110
+ })[];
106
111
  readonly missingFamily?: string;
107
112
  }
108
113
  export {};
@@ -2457,7 +2457,7 @@ ${XMLNS_NAMESPACE}.`);
2457
2457
  bytes: new Uint8Array(channel, 8)
2458
2458
  };
2459
2459
  }
2460
- /** The synchronous reader installs immutable subsets before returning their MEMFS paths and aliases. */
2460
+ /** The synchronous reader installs immutable font assets before returning their MEMFS paths and aliases. */
2461
2461
  function createFontReader(channel, timeoutMs, maxLoadedFontBytes, declaredFamilies, request, next, install, missing) {
2462
2462
  const { control, bytes } = fontViews(channel);
2463
2463
  const installed = /* @__PURE__ */ new Map();
@@ -2493,7 +2493,11 @@ ${XMLNS_NAMESPACE}.`);
2493
2493
  const key = JSON.stringify(original);
2494
2494
  const cached = requests.get(key);
2495
2495
  if (cached) return cached;
2496
- request(original);
2496
+ request(original, [...installed].map(([id, font]) => ({
2497
+ id,
2498
+ bytes: font.bytes,
2499
+ ...font.format ? { format: font.format } : {}
2500
+ })));
2497
2501
  const first = read();
2498
2502
  if (first.state !== 1) throw new BrowserRenderError("font-unavailable", "Expected font transfer metadata.");
2499
2503
  let header;
@@ -2511,15 +2515,17 @@ ${XMLNS_NAMESPACE}.`);
2511
2515
  "otf",
2512
2516
  "ttc"
2513
2517
  ].includes(font.format)) throw new BrowserRenderError("font-unavailable", "Invalid full font format.");
2518
+ if (font.reference !== void 0 && font.reference !== true) throw new BrowserRenderError("font-unavailable", "Invalid font reference descriptor.");
2514
2519
  const prior = installed.get(font.id);
2515
- if (prior && (prior.format !== font.format || font.format === void 0 && prior.face.family !== font.alias)) throw new BrowserRenderError("font-unavailable", "Font identity has conflicting aliases or formats.");
2520
+ if (font.reference && !prior) throw new BrowserRenderError("font-unavailable", "Font reference has not been installed.");
2521
+ if (prior && (prior.bytes !== font.bytes || prior.format !== font.format || font.format === void 0 && prior.face.family !== font.alias)) throw new BrowserRenderError("font-unavailable", "Font identity has conflicting bytes, aliases or formats.");
2516
2522
  const alias = normalize(font.alias);
2517
2523
  const previousAlias = aliases.get(alias);
2518
2524
  if (previousAlias && (previousAlias.family !== font.family || font.format === void 0 && previousAlias.id !== font.id)) throw new BrowserRenderError("font-unavailable", "Font alias identifies conflicting subsets.");
2519
2525
  if (!prior && loadedBytes + font.bytes > maxLoadedFontBytes) throw new BrowserRenderError("font-limit", "Imported fonts exceed maxLoadedFontBytes.");
2520
2526
  const buffer = prior ? void 0 : new Uint8Array(font.bytes);
2521
2527
  let received = 0;
2522
- while (received < font.bytes) {
2528
+ while (!font.reference && received < font.bytes) {
2523
2529
  const frame = read();
2524
2530
  if (frame.state !== 2 || frame.data.length === 0 || received + frame.data.length > font.bytes) throw new BrowserRenderError("font-unavailable", "Incomplete font file transfer.");
2525
2531
  buffer?.set(frame.data, received);
@@ -2533,6 +2539,7 @@ ${XMLNS_NAMESPACE}.`);
2533
2539
  install(face.path, buffer);
2534
2540
  installed.set(font.id, {
2535
2541
  face,
2542
+ bytes: buffer.length,
2536
2543
  format: font.format
2537
2544
  });
2538
2545
  loadedBytes += buffer.length;
@@ -2751,6 +2758,8 @@ ${XMLNS_NAMESPACE}.`);
2751
2758
  stopped = false;
2752
2759
  layoutWidth = 0;
2753
2760
  viewport = "";
2761
+ captureView;
2762
+ readingView;
2754
2763
  commandResult;
2755
2764
  constructor(module, document, format, emit, failure) {
2756
2765
  this.module = module;
@@ -2800,6 +2809,20 @@ ${XMLNS_NAMESPACE}.`);
2800
2809
  /** Enforce the native read-only view before accepting any input. */
2801
2810
  async start() {
2802
2811
  this.requireOpen();
2812
+ if (this.state.documentType === "presentation") {
2813
+ const view = this.call("dsh_lok_document_get_view", [this.document]);
2814
+ try {
2815
+ const created = this.call("dsh_lok_document_create_view", [this.document]);
2816
+ if (created < 0) throw new BrowserRenderError("render-failed", "LibreOffice could not create a slide capture view.");
2817
+ this.captureView = created;
2818
+ this.invoke("initialize_rendering");
2819
+ this.configure({ mode: "paginated" });
2820
+ this.pump();
2821
+ } finally {
2822
+ this.invoke("set_view", [view]);
2823
+ }
2824
+ this.readingView = view;
2825
+ }
2803
2826
  this.configure({ mode: "paginated" });
2804
2827
  this.invoke("listen");
2805
2828
  this.refreshGeometry();
@@ -2879,12 +2902,14 @@ ${XMLNS_NAMESPACE}.`);
2879
2902
  }
2880
2903
  }
2881
2904
  pump() {
2905
+ if (this.readingView !== void 0) this.invoke("set_view", [this.readingView]);
2882
2906
  const deadline = performance.now() + 8;
2883
2907
  for (let pass = 0; pass < 8; pass++) {
2884
2908
  const result = this.call("dsh_lok_pump");
2885
2909
  if (result < 0) throw new BrowserRenderError("render-failed", "LibreOffice event processing failed.");
2886
2910
  if (!result || performance.now() >= deadline) break;
2887
2911
  }
2912
+ if (this.readingView !== void 0) this.invoke("set_view", [this.readingView]);
2888
2913
  this.flush();
2889
2914
  }
2890
2915
  flush() {
@@ -2993,6 +3018,7 @@ ${XMLNS_NAMESPACE}.`);
2993
3018
  /** The Worker permits only these typed reading operations, including at runtime. */
2994
3019
  async operation(operation) {
2995
3020
  this.requireOpen();
3021
+ if (this.readingView !== void 0) this.invoke("set_view", [this.readingView]);
2996
3022
  if (!operation || typeof operation !== "object") throw new BrowserRenderError("render-failed", "Invalid Office reading operation.");
2997
3023
  switch (operation.type) {
2998
3024
  case "pointer": {
@@ -3189,10 +3215,13 @@ ${XMLNS_NAMESPACE}.`);
3189
3215
  /** Direct tiles preserve the active view, navigation state and selection. */
3190
3216
  render(request) {
3191
3217
  this.requireOpen();
3218
+ if (this.readingView !== void 0) this.invoke("set_view", [this.readingView]);
3192
3219
  this.flush();
3193
3220
  const part = this.state.parts[integer(request.part, this.state.parts.length - 1)];
3194
- if (request.part !== this.state.part) throw new BrowserRenderError("stale-part", "The Office tile belongs to an inactive worksheet or slide.");
3221
+ const capture = request.part !== this.state.part;
3222
+ if (capture && this.state.documentType !== "presentation") throw new BrowserRenderError("stale-part", "The Office tile belongs to an inactive worksheet.");
3195
3223
  try {
3224
+ if (capture) this.invoke("set_view", [this.captureView]);
3196
3225
  return renderRegion(this.module, this.document, {
3197
3226
  ...request,
3198
3227
  pageIndex: 0
@@ -3203,6 +3232,7 @@ ${XMLNS_NAMESPACE}.`);
3203
3232
  part: this.state.documentType === "text" ? -1 : request.part
3204
3233
  }], () => new BrowserRenderError("render-failed", "Office tile rendering failed."));
3205
3234
  } finally {
3235
+ if (this.readingView !== void 0) this.invoke("set_view", [this.readingView]);
3206
3236
  this.flush();
3207
3237
  }
3208
3238
  }
@@ -3249,6 +3279,22 @@ ${XMLNS_NAMESPACE}.`);
3249
3279
  } catch (failure) {
3250
3280
  throw new BrowserRenderError("invalid-document", failure instanceof Error ? failure.message : String(failure));
3251
3281
  }
3282
+ const initialFont = {
3283
+ family: "sans-serif",
3284
+ style: "",
3285
+ weight: 5,
3286
+ italic: 0,
3287
+ width: 5,
3288
+ pitch: 0,
3289
+ language: "",
3290
+ codePoints: []
3291
+ };
3292
+ let initialFontPending = options.extension !== "pdf";
3293
+ if (initialFontPending) send({
3294
+ type: "font",
3295
+ request: initialFont,
3296
+ known: []
3297
+ });
3252
3298
  const response = await fetch(assets.dataUrl, {
3253
3299
  credentials: "same-origin",
3254
3300
  signal: lifetime.signal
@@ -3298,25 +3344,23 @@ ${XMLNS_NAMESPACE}.`);
3298
3344
  FONTCONFIG_FILE: "/dsh/fonts.conf",
3299
3345
  LOK_HOST_ALLOWLIST: "^$"
3300
3346
  });
3301
- resolveFonts = createFontReader(channel, options.timeoutMs, options.maxLoadedFontBytes, metadata.families, (request) => send({
3302
- type: "font",
3303
- request
3304
- }), () => send({ type: "font-next" }), (path, bytes) => loaded.FS.writeFile(path, bytes), (families) => send({
3347
+ resolveFonts = createFontReader(channel, options.timeoutMs, options.maxLoadedFontBytes, metadata.families, (request, known) => {
3348
+ if (initialFontPending) initialFontPending = false;
3349
+ else send({
3350
+ type: "font",
3351
+ request,
3352
+ known
3353
+ });
3354
+ }, () => send({ type: "font-next" }), (path, bytes) => loaded.FS.writeFile(path, bytes), (families) => send({
3305
3355
  type: "missing-fonts",
3306
3356
  families
3307
3357
  }));
3308
- const initialFamilies = options.extension === "pdf" ? new Set(options.fontFallbacks.flat()) : /* @__PURE__ */ new Set(["sans-serif"]);
3309
- for (const family of initialFamilies) resolveFonts({
3358
+ if (options.extension === "pdf") for (const family of new Set(options.fontFallbacks.flat())) resolveFonts({
3359
+ ...initialFont,
3310
3360
  family,
3311
- style: "",
3312
- weight: 5,
3313
- italic: 0,
3314
- width: 5,
3315
- pitch: 0,
3316
- language: "",
3317
- codePoints: [],
3318
- ...options.extension === "pdf" ? { mode: "full" } : {}
3361
+ mode: "full"
3319
3362
  });
3363
+ else resolveFonts(initialFont);
3320
3364
  }],
3321
3365
  onAbort() {
3322
3366
  fatal = true;
@@ -47,7 +47,7 @@ async function readEngine(packageFile) {
47
47
  const root = dirname(packageFile);
48
48
  const [pkg, manifest] = await Promise.all([readFile(packageFile, "utf8").then((text) => JSON.parse(text)), readFile(resolve(root, "prebuilds.json"), "utf8").then((text) => JSON.parse(text))]);
49
49
  const engine = manifest.engine;
50
- if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc5" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
50
+ if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc6" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
51
51
  if (engine.glibcMinimum !== void 0) throw new Error("Installed LibreOfficeKit engine has an invalid glibcMinimum.");
52
52
  return {
53
53
  backend: "wasm",
package/lib/cli.js CHANGED
@@ -733,7 +733,7 @@ const require = createRequire(import.meta.url);
733
733
  * Engine-family version every installed engine package must carry. The engine
734
734
  * family shares its release version with this Node API.
735
735
  */
736
- const ENGINE_VERSION = "0.0.2-rc5";
736
+ const ENGINE_VERSION = "0.0.2-rc6";
737
737
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
738
738
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
739
739
  /**
@@ -774,7 +774,7 @@ async function readEngine(packageFile) {
774
774
  const root = dirname(packageFile);
775
775
  const [pkg, manifest] = await Promise.all([readFile(packageFile, "utf8").then((text) => JSON.parse(text)), readFile(resolve(root, "prebuilds.json"), "utf8").then((text) => JSON.parse(text))]);
776
776
  const engine = manifest.engine;
777
- if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc5" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
777
+ if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc6" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
778
778
  if (engine.glibcMinimum !== void 0) throw new Error("Installed LibreOfficeKit engine has an invalid glibcMinimum.");
779
779
  return {
780
780
  backend: "wasm",
@@ -1,8 +1,8 @@
1
1
  import { parentPort, workerData } from "node:worker_threads";
2
2
  import { createHash } from "node:crypto";
3
3
  import { closeSync, constants, fstatSync, openSync, readSync, readdirSync, realpathSync, statSync } from "node:fs";
4
- import { create } from "fontkit";
5
4
  import { extname, join } from "node:path";
5
+ import { create } from "fontkit";
6
6
  import { readFile } from "node:fs/promises";
7
7
  import * as publishedProperties from "@unicode/unicode-17.0.0";
8
8
  import variationSelectors from "@unicode/unicode-17.0.0/Binary_Property/Variation_Selector/code-points.mjs";
@@ -670,7 +670,7 @@ function fontPreferences(request, groups, script, scripts, platform = process.pl
670
670
  const region = script === "Hangul" ? "kr" : script === "Hiragana" || script === "Katakana" ? "jp" : script === "Bopomofo" ? "tc" : script === "Han" ? hanRegion(request, scripts) : void 0;
671
671
  const scriptKey = script === "Han" ? region === "sc" ? "simplified_han" : region === "tc" || region === "hk" ? "traditional_han" : region === "jp" ? "hiragana" : region === "kr" ? "hangul" : "han" : script === "Old_Turkic" ? "orkhon" : script.toLowerCase();
672
672
  const legacy = fontFamilyPriority(requested, groups, request.pitch, script === "Common" && request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point))));
673
- const config = FONTCONFIG_FONTS[generic === "sansserif" ? "sans-serif" : generic] ?? [];
673
+ const config = FONTCONFIG_FONTS[generic === "sansserif" ? "sans-serif" : generic];
674
674
  const windows = WINDOWS_FONTS[scriptKey] ?? [];
675
675
  const candidates = script === "Latin" || script === "Greek" || script === "Cyrillic" || script === "Common" ? [
676
676
  ...legacy,
@@ -1191,11 +1191,11 @@ function unchanged(face) {
1191
1191
  const status = statSync(face.path);
1192
1192
  if (!status.isFile() || STAT_KEYS.some((key) => status[key] !== face[key])) throw new Error("The selected font changed; resolve it again.");
1193
1193
  }
1194
- function fileIdentity(face) {
1194
+ function fileIdentity(face, wholeFile = false) {
1195
1195
  return JSON.stringify([
1196
1196
  face.path,
1197
1197
  ...STAT_KEYS.map((key) => face[key]),
1198
- face.faceIndex
1198
+ ...wholeFile ? [] : [face.faceIndex]
1199
1199
  ]);
1200
1200
  }
1201
1201
  /** One Worker-owned font index and LRU whose byte budget excludes transient subsetting input/output. */
@@ -1249,18 +1249,19 @@ var FontSubsetSource = class {
1249
1249
  }
1250
1250
  async describe(face, script) {
1251
1251
  unchanged(face);
1252
- const partition = `${fileIdentity(face)}/${script}`;
1252
+ const partition = `${fileIdentity(face, script === "full" && extname(face.path).toLowerCase() !== ".dfont")}/${script}`;
1253
1253
  const previous = this.partitions.get(partition);
1254
1254
  if (previous !== void 0) {
1255
1255
  this.selected.set(previous.asset.id, previous);
1256
1256
  return {
1257
1257
  ...previous.asset,
1258
- family: face.family
1258
+ family: face.family,
1259
+ alias: script === "full" ? face.family : previous.asset.alias
1259
1260
  };
1260
1261
  }
1261
1262
  const { bytes, sourceHash } = await this.generate(face, script);
1262
1263
  const id = `${script === "full" ? "full_" : ""}${hash(bytes)}`;
1263
- const key = `${sourceHash}/${face.faceIndex}/${ALGORITHM}/${script}`;
1264
+ const key = script === "full" ? id : `${sourceHash}/${face.faceIndex}/${ALGORITHM}/${script}`;
1264
1265
  const asset = {
1265
1266
  id,
1266
1267
  bytes: bytes.byteLength,
@@ -1292,7 +1293,7 @@ var FontSubsetSource = class {
1292
1293
  if (request.mode !== void 0 && request.mode !== "subset" && request.mode !== "full") throw new TypeError("Unknown font asset mode.");
1293
1294
  const snapshot = indexSystemFonts(this.options, this.snapshot);
1294
1295
  if (this.catalog === void 0 || snapshot.length !== this.snapshot.length || snapshot.some((face, index) => face !== this.snapshot[index])) {
1295
- const current = new Set(snapshot.map(fileIdentity));
1296
+ const current = new Set(snapshot.map((face) => fileIdentity(face)));
1296
1297
  for (const [partition, selection] of this.partitions) {
1297
1298
  if (current.has(fileIdentity(selection.face))) continue;
1298
1299
  this.partitions.delete(partition);
package/lib/index.js CHANGED
@@ -731,7 +731,7 @@ const require = createRequire(import.meta.url);
731
731
  * Engine-family version every installed engine package must carry. The engine
732
732
  * family shares its release version with this Node API.
733
733
  */
734
- const ENGINE_VERSION = "0.0.2-rc5";
734
+ const ENGINE_VERSION = "0.0.2-rc6";
735
735
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
736
736
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
737
737
  /**
@@ -772,7 +772,7 @@ async function readEngine(packageFile) {
772
772
  const root = dirname(packageFile);
773
773
  const [pkg, manifest] = await Promise.all([readFile(packageFile, "utf8").then((text) => JSON.parse(text)), readFile(resolve(root, "prebuilds.json"), "utf8").then((text) => JSON.parse(text))]);
774
774
  const engine = manifest.engine;
775
- if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc5" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
775
+ if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc6" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== "wasm" || manifest.platform !== "wasm") throw new Error("Installed LibreOfficeKit wasm package has an incompatible or incomplete manifest.");
776
776
  if (engine.glibcMinimum !== void 0) throw new Error("Installed LibreOfficeKit engine has an invalid glibcMinimum.");
777
777
  return {
778
778
  backend: "wasm",
@@ -2,7 +2,7 @@
2
2
  * Engine-family version every installed engine package must carry. The engine
3
3
  * family shares its release version with this Node API.
4
4
  */
5
- export declare const ENGINE_VERSION = "0.0.2-rc5";
5
+ export declare const ENGINE_VERSION = "0.0.2-rc6";
6
6
  /** Host diagnostic fields used to identify the runtime glibc version. */
7
7
  export interface EngineHostReport {
8
8
  readonly header?: {
package/lib/worker.js CHANGED
@@ -867,7 +867,7 @@ function fontPreferences(request, groups, script, scripts, platform = process.pl
867
867
  const region = script === "Hangul" ? "kr" : script === "Hiragana" || script === "Katakana" ? "jp" : script === "Bopomofo" ? "tc" : script === "Han" ? hanRegion(request, scripts) : void 0;
868
868
  const scriptKey = script === "Han" ? region === "sc" ? "simplified_han" : region === "tc" || region === "hk" ? "traditional_han" : region === "jp" ? "hiragana" : region === "kr" ? "hangul" : "han" : script === "Old_Turkic" ? "orkhon" : script.toLowerCase();
869
869
  const legacy = fontFamilyPriority(requested, groups, request.pitch, script === "Common" && request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point))));
870
- const config = FONTCONFIG_FONTS[generic === "sansserif" ? "sans-serif" : generic] ?? [];
870
+ const config = FONTCONFIG_FONTS[generic === "sansserif" ? "sans-serif" : generic];
871
871
  const windows = WINDOWS_FONTS[scriptKey] ?? [];
872
872
  const candidates = script === "Latin" || script === "Greek" || script === "Cyrillic" || script === "Common" ? [
873
873
  ...legacy,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/libreoffice-kit",
3
3
  "description": "WASM Office previews, document images, and conversion for Node and browsers",
4
- "version": "0.0.2-rc5",
4
+ "version": "0.0.2-rc6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -85,7 +85,7 @@
85
85
  "fflate": "0.8.2",
86
86
  "fontkit": "2.0.4",
87
87
  "saxes": "6.0.0",
88
- "@deepseek-ai/libreoffice-kit-wasm": "0.0.2-rc5"
88
+ "@deepseek-ai/libreoffice-kit-wasm": "0.0.2-rc6"
89
89
  },
90
90
  "bin": {
91
91
  "libreoffice-kit": "./lib/cli.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepseek-ai/libreoffice-kit-browser-internal",
3
- "version": "0.0.2-rc5",
3
+ "version": "0.0.2-rc6",
4
4
  "type": "module",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Browser Worker LibreOffice reading sessions and PDF rendering",
@@ -66,7 +66,7 @@ export async function openBrowserConnection(options: BrowserDocumentOptions | Of
66
66
  if (closed) return
67
67
  void Promise.resolve().then(() => options.resolveFonts(message.request, lifetime.signal)).then(result => {
68
68
  if (closed) return
69
- frames = fontFrames(result)
69
+ frames = fontFrames(result, message.known)
70
70
  pumpFonts()
71
71
  }, sendFontError)
72
72
  return
@@ -1,7 +1,7 @@
1
1
  /** Bounded frames bridge asynchronous Host font reads and synchronous VCL callbacks. */
2
2
  import { normalize } from '@deepseek-ai/libreoffice-kit/font-config'
3
3
  import { FONT_CHUNK_BYTES, FONT_HEADER_BYTES, FontState } from './protocol.ts'
4
- import type { FontHeader } from './protocol.ts'
4
+ import type { FontHeader, FontIdentity } from './protocol.ts'
5
5
  import { BrowserRenderError } from './types.ts'
6
6
  import type { BrowserFontRequest, BrowserFontResult } from './types.ts'
7
7
 
@@ -10,13 +10,21 @@ export function fontViews(channel: SharedArrayBuffer): { control: Int32Array; by
10
10
  return { control: new Int32Array(channel, 0, 2), bytes: new Uint8Array(channel, FONT_HEADER_BYTES) }
11
11
  }
12
12
 
13
- /** Frames are produced lazily so the transfer channel never duplicates a whole font set. */
14
- export function* fontFrames(result: BrowserFontResult): Generator<{ state: FontState; bytes: Uint8Array }> {
15
- const header: FontHeader = { fonts: result.fonts.map(font => ({ id: font.id, bytes: font.data.byteLength, family: font.family, alias: font.alias, ...(font.format ? { format: font.format } : {}) })), ...(result.missingFamily === undefined ? {} : { missingFamily: result.missingFamily }) }
13
+ /** Only uninstalled content crosses the channel; each family retains its own alias. */
14
+ export function* fontFrames(result: BrowserFontResult, known: readonly FontIdentity[] = []): Generator<{ state: FontState; bytes: Uint8Array }> {
15
+ const identities = new Map(known.map(font => [font.id, font]))
16
+ const header: FontHeader = { fonts: result.fonts.map(font => {
17
+ const identity: FontIdentity = { id: font.id, bytes: font.data.byteLength, ...(font.format ? { format: font.format } : {}) }
18
+ const prior = identities.get(font.id)
19
+ if (prior && (prior.bytes !== identity.bytes || prior.format !== identity.format)) throw new BrowserRenderError('font-unavailable', 'Font identity has conflicting bytes or formats.')
20
+ identities.set(font.id, identity)
21
+ return { ...identity, family: font.family, alias: font.alias, ...(prior ? { reference: true as const } : {}) }
22
+ }), ...(result.missingFamily === undefined ? {} : { missingFamily: result.missingFamily }) }
16
23
  const encoded = new TextEncoder().encode(JSON.stringify(header))
17
24
  if (encoded.length > FONT_CHUNK_BYTES) throw new BrowserRenderError('font-limit', 'Font response metadata exceeds the transfer limit.')
18
25
  yield { state: FontState.Header, bytes: encoded }
19
- for (const font of result.fonts) {
26
+ for (const [index, font] of result.fonts.entries()) {
27
+ if (header.fonts[index]!.reference) continue
20
28
  for (let offset = 0; offset < font.data.byteLength; offset += FONT_CHUNK_BYTES) {
21
29
  yield { state: FontState.Bytes, bytes: font.data.subarray(offset, offset + FONT_CHUNK_BYTES) }
22
30
  }
@@ -27,12 +35,12 @@ export function* fontFrames(result: BrowserFontResult): Generator<{ state: FontS
27
35
  /** One MEMFS font face registered under a document-local family alias. */
28
36
  export interface EngineFontFace { readonly path: string; readonly family: string }
29
37
 
30
- /** The synchronous reader installs immutable subsets before returning their MEMFS paths and aliases. */
38
+ /** The synchronous reader installs immutable font assets before returning their MEMFS paths and aliases. */
31
39
  export function createFontReader(channel: SharedArrayBuffer, timeoutMs: number, maxLoadedFontBytes: number,
32
- declaredFamilies: ReadonlyMap<string, string>, request: (request: BrowserFontRequest) => void, next: () => void,
40
+ declaredFamilies: ReadonlyMap<string, string>, request: (request: BrowserFontRequest, known: readonly FontIdentity[]) => void, next: () => void,
33
41
  install: (path: string, bytes: Uint8Array) => void, missing: (families: readonly string[]) => void): (request: BrowserFontRequest) => EngineFontFace[] {
34
42
  const { control, bytes } = fontViews(channel)
35
- const installed = new Map<string, { face: EngineFontFace; format: FontHeader['fonts'][number]['format'] }>()
43
+ const installed = new Map<string, { face: EngineFontFace; bytes: number; format: FontIdentity['format'] }>()
36
44
  const aliases = new Map<string, { id: string; family: string }>()
37
45
  const requests = new Map<string, EngineFontFace[]>()
38
46
  const families = new Set<string>()
@@ -59,7 +67,7 @@ export function createFontReader(channel: SharedArrayBuffer, timeoutMs: number,
59
67
  const key = JSON.stringify(original)
60
68
  const cached = requests.get(key)
61
69
  if (cached) return cached
62
- request(original)
70
+ request(original, [...installed].map(([id, font]) => ({ id, bytes: font.bytes, ...(font.format ? { format: font.format } : {}) })))
63
71
  const first = read()
64
72
  if (first.state !== FontState.Header) throw new BrowserRenderError('font-unavailable', 'Expected font transfer metadata.')
65
73
  let header: FontHeader
@@ -69,15 +77,17 @@ export function createFontReader(channel: SharedArrayBuffer, timeoutMs: number,
69
77
  for (const font of header.fonts) {
70
78
  if (typeof font.id !== 'string' || typeof font.family !== 'string' || font.family.length === 0 || typeof font.alias !== 'string' || font.alias.length === 0 || /[\x00\t\r\n]/.test(font.alias) || !Number.isSafeInteger(font.bytes) || font.bytes <= 0) throw new BrowserRenderError('font-unavailable', 'Invalid font file descriptor.')
71
79
  if (font.format !== undefined && !['ttf', 'otf', 'ttc'].includes(font.format)) throw new BrowserRenderError('font-unavailable', 'Invalid full font format.')
80
+ if (font.reference !== undefined && font.reference !== true) throw new BrowserRenderError('font-unavailable', 'Invalid font reference descriptor.')
72
81
  const prior = installed.get(font.id)
73
- if (prior && (prior.format !== font.format || (font.format === undefined && prior.face.family !== font.alias))) throw new BrowserRenderError('font-unavailable', 'Font identity has conflicting aliases or formats.')
82
+ if (font.reference && !prior) throw new BrowserRenderError('font-unavailable', 'Font reference has not been installed.')
83
+ if (prior && (prior.bytes !== font.bytes || prior.format !== font.format || (font.format === undefined && prior.face.family !== font.alias))) throw new BrowserRenderError('font-unavailable', 'Font identity has conflicting bytes, aliases or formats.')
74
84
  const alias = normalize(font.alias)
75
85
  const previousAlias = aliases.get(alias)
76
86
  if (previousAlias && (previousAlias.family !== font.family || (font.format === undefined && previousAlias.id !== font.id))) throw new BrowserRenderError('font-unavailable', 'Font alias identifies conflicting subsets.')
77
87
  if (!prior && loadedBytes + font.bytes > maxLoadedFontBytes) throw new BrowserRenderError('font-limit', 'Imported fonts exceed maxLoadedFontBytes.')
78
88
  const buffer = prior ? undefined : new Uint8Array(font.bytes)
79
89
  let received = 0
80
- while (received < font.bytes) {
90
+ while (!font.reference && received < font.bytes) {
81
91
  const frame = read()
82
92
  if (frame.state !== FontState.Bytes || frame.data.length === 0 || received + frame.data.length > font.bytes) throw new BrowserRenderError('font-unavailable', 'Incomplete font file transfer.')
83
93
  buffer?.set(frame.data, received)
@@ -86,7 +96,7 @@ export function createFontReader(channel: SharedArrayBuffer, timeoutMs: number,
86
96
  // A full TTC asset can expose multiple families from the same installed bytes.
87
97
  // Its requested family must not inherit the first family's alias.
88
98
  const face = { path: prior?.face.path ?? (font.format === undefined ? `/dsh-fonts/${installed.size}.font` : `/usr/share/fonts/dsh-pdfium/${installed.size}.${font.format}`), family: font.alias }
89
- if (buffer) { install(face.path, buffer); installed.set(font.id, { face, format: font.format }); loadedBytes += buffer.length }
99
+ if (buffer) { install(face.path, buffer); installed.set(font.id, { face, bytes: buffer.length, format: font.format }); loadedBytes += buffer.length }
90
100
  aliases.set(alias, { id: font.id, family: font.family })
91
101
  faces.push(face)
92
102
  }
@@ -42,6 +42,8 @@ export class OfficeEngine {
42
42
  private stopped = false
43
43
  private layoutWidth = 0
44
44
  private viewport = ''
45
+ private captureView: number | undefined
46
+ private readingView: number | undefined
45
47
  private commandResult: { name: string; resolve: () => void; reject: (error: unknown) => void } | undefined
46
48
 
47
49
  constructor(private readonly module: EmscriptenModule, private readonly document: number,
@@ -71,6 +73,18 @@ export class OfficeEngine {
71
73
  /** Enforce the native read-only view before accepting any input. */
72
74
  async start(): Promise<void> {
73
75
  this.requireOpen()
76
+ if (this.state.documentType === 'presentation') {
77
+ const view = this.call('dsh_lok_document_get_view', [this.document])
78
+ try {
79
+ const created = this.call('dsh_lok_document_create_view', [this.document])
80
+ if (created < 0) throw new BrowserRenderError('render-failed', 'LibreOffice could not create a slide capture view.')
81
+ this.captureView = created
82
+ this.invoke('initialize_rendering')
83
+ this.configure({ mode: 'paginated' })
84
+ this.pump()
85
+ } finally { this.invoke('set_view', [view]) }
86
+ this.readingView = view
87
+ }
74
88
  this.configure({ mode: 'paginated' })
75
89
  this.invoke('listen')
76
90
  this.refreshGeometry()
@@ -126,12 +140,15 @@ export class OfficeEngine {
126
140
  } finally { this.call('free', [pointer]) }
127
141
  }
128
142
  private pump(): void {
143
+ if (this.readingView !== undefined) this.invoke('set_view', [this.readingView])
129
144
  const deadline = performance.now() + 8
130
145
  for (let pass = 0; pass < 8; pass++) {
131
146
  const result = this.call('dsh_lok_pump')
132
147
  if (result < 0) throw new BrowserRenderError('render-failed', 'LibreOffice event processing failed.')
133
148
  if (!result || performance.now() >= deadline) break
134
149
  }
150
+ // Deferred native focus events can activate the capture view while pumping.
151
+ if (this.readingView !== undefined) this.invoke('set_view', [this.readingView])
135
152
  this.flush()
136
153
  }
137
154
  private flush(): void {
@@ -189,6 +206,7 @@ export class OfficeEngine {
189
206
  /** The Worker permits only these typed reading operations, including at runtime. */
190
207
  async operation(operation: OfficeOperation): Promise<{ text?: string; layout?: OfficeDocumentLayoutResult }> {
191
208
  this.requireOpen()
209
+ if (this.readingView !== undefined) this.invoke('set_view', [this.readingView])
192
210
  if (!operation || typeof operation !== 'object') throw new BrowserRenderError('render-failed', 'Invalid Office reading operation.')
193
211
  switch (operation.type) {
194
212
  case 'pointer': {
@@ -288,12 +306,18 @@ export class OfficeEngine {
288
306
  /** Direct tiles preserve the active view, navigation state and selection. */
289
307
  render(request: OfficeDocumentTileRequest): BrowserTile {
290
308
  this.requireOpen()
309
+ if (this.readingView !== undefined) this.invoke('set_view', [this.readingView])
291
310
  this.flush()
292
311
  const part = this.state.parts[integer(request.part, this.state.parts.length - 1)]!
293
- if (request.part !== this.state.part) throw new BrowserRenderError('stale-part', 'The Office tile belongs to an inactive worksheet or slide.')
312
+ const capture = request.part !== this.state.part
313
+ if (capture && this.state.documentType !== 'presentation') throw new BrowserRenderError('stale-part', 'The Office tile belongs to an inactive worksheet.')
294
314
  try {
315
+ if (capture) this.invoke('set_view', [this.captureView!])
295
316
  return renderRegion(this.module, this.document, { ...request, pageIndex: 0 }, [{ ...part, x: 0, y: 0,
296
317
  part: this.state.documentType === 'text' ? -1 : request.part }], () => new BrowserRenderError('render-failed', 'Office tile rendering failed.'))
297
- } finally { this.flush() }
318
+ } finally {
319
+ if (this.readingView !== undefined) this.invoke('set_view', [this.readingView])
320
+ this.flush()
321
+ }
298
322
  }
299
323
  }
@@ -30,10 +30,12 @@ export type WorkerMessage =
30
30
  | { readonly type: 'office-event'; readonly event: OfficeDocumentEvent }
31
31
  | { readonly type: 'disposed'; readonly id: number }
32
32
  | { readonly type: 'error'; readonly id: number; readonly code: BrowserRenderErrorCode; readonly message: string; readonly fatal: boolean }
33
- | { readonly type: 'font'; readonly request: BrowserFontRequest }
33
+ | { readonly type: 'font'; readonly request: BrowserFontRequest; readonly known: readonly FontIdentity[] }
34
34
  | { readonly type: 'font-next' }
35
35
  | { readonly type: 'missing-fonts'; readonly families: readonly string[] }
36
+ /** Immutable bytes already installed in this document's MEMFS. */
37
+ export interface FontIdentity { readonly id: string; readonly bytes: number; readonly format?: 'ttf' | 'otf' | 'ttc' }
36
38
  export interface FontHeader {
37
- readonly fonts: readonly { readonly id: string; readonly bytes: number; readonly family: string; readonly alias: string; readonly format?: 'ttf' | 'otf' | 'ttc' }[]
39
+ readonly fonts: readonly (FontIdentity & { readonly family: string; readonly alias: string; readonly reference?: true })[]
38
40
  readonly missingFamily?: string
39
41
  }
@@ -41,6 +41,11 @@ async function open(options: WorkerOptions, channel: SharedArrayBuffer, reading
41
41
  const { assets } = options
42
42
  let metadata: ReturnType<typeof inspectDocument>
43
43
  try { metadata = options.extension === 'pdf' ? { families: new Map(), codePoints: [] } : inspectDocument(options.data, options.extension, options) } catch (failure) { throw new BrowserRenderError('invalid-document', failure instanceof Error ? failure.message : String(failure)) }
44
+ const initialFont = { family: 'sans-serif', style: '', weight: 5, italic: 0, width: 5, pitch: 0, language: '', codePoints: [] }
45
+ let initialFontPending = options.extension !== 'pdf'
46
+ // Host font discovery runs while the engine downloads and compiles. The first
47
+ // synchronous font read consumes this response through the same bounded channel.
48
+ if (initialFontPending) send({ type: 'font', request: initialFont, known: [] })
44
49
  const response = await fetch(assets.dataUrl, { credentials: 'same-origin', signal: lifetime.signal })
45
50
  if (!response.ok) throw new BrowserRenderError('unavailable', `LibreOffice data request failed: ${response.status}`)
46
51
  const data = await response.arrayBuffer()
@@ -70,10 +75,14 @@ async function open(options: WorkerOptions, channel: SharedArrayBuffer, reading
70
75
  loaded.FS.writeFile('/dsh/fonts.conf', new TextEncoder().encode(memoryFontConfig(options.fontFallbacks, metadata.families.values())))
71
76
  Object.assign(loaded.ENV, { HOME: '/dsh/profile', TMPDIR: '/tmp', FONTCONFIG_FILE: '/dsh/fonts.conf', LOK_HOST_ALLOWLIST: '^$' })
72
77
  resolveFonts = createFontReader(channel, options.timeoutMs, options.maxLoadedFontBytes, metadata.families,
73
- request => send({ type: 'font', request }), () => send({ type: 'font-next' }),
78
+ (request, known) => {
79
+ if (initialFontPending) initialFontPending = false
80
+ else send({ type: 'font', request, known })
81
+ }, () => send({ type: 'font-next' }),
74
82
  (path, bytes) => loaded.FS.writeFile(path, bytes), families => send({ type: 'missing-fonts', families }))
75
- const initialFamilies = options.extension === 'pdf' ? new Set(options.fontFallbacks.flat()) : new Set(['sans-serif'])
76
- for (const family of initialFamilies) resolveFonts({ family, style: '', weight: 5, italic: 0, width: 5, pitch: 0, language: '', codePoints: [], ...(options.extension === 'pdf' ? { mode: 'full' as const } : {}) })
83
+ if (options.extension === 'pdf') {
84
+ for (const family of new Set(options.fontFallbacks.flat())) resolveFonts({ ...initialFont, family, mode: 'full' })
85
+ } else resolveFonts(initialFont)
77
86
  }],
78
87
  onAbort() { fatal = true },
79
88
  print() {}, printErr() {},
@@ -53,7 +53,7 @@ export function releaseAssetUrl(version, file) {
53
53
  /** Return the complete declared matrix, including targets without built assets. */
54
54
  export function packageMatrix(repo = root) {
55
55
  return readdirSync(join(repo, 'packages'), { withFileTypes: true })
56
- .filter((entry) => entry.isDirectory() && !['entry', 'browser'].includes(entry.name))
56
+ .filter((entry) => entry.isDirectory() && !['entry', 'browser', 'fonts'].includes(entry.name))
57
57
  .sort((a, b) => a.name.localeCompare(b.name))
58
58
  .map((entry) => {
59
59
  const dir = join(repo, 'packages', entry.name);
@@ -88,7 +88,7 @@ export function verifyEngineMetadata(manifest, prebuild) {
88
88
  }
89
89
  const exact = (actual, expected) => JSON.stringify(actual) === JSON.stringify(expected);
90
90
  if (prebuild.platform === 'wasm') {
91
- assert(JSON.stringify(manifest.os) === '["linux"]' && manifest.cpu === undefined && manifest.libc === undefined, 'WASM package must install only on Linux, for every CPU and libc');
91
+ assert(manifest.os === undefined && manifest.cpu === undefined && manifest.libc === undefined, 'WASM package must install across operating systems, CPUs and libc variants');
92
92
  assert(engine?.kind === 'wasm' && engine.loader === 'assets/soffice.cjs' && engine.wasm === 'assets/soffice.wasm'
93
93
  && engine.data === 'assets/soffice.data' && engine.metadata === 'assets/soffice.data.js.metadata'
94
94
  && engine.programDirectory === '/instdir/program', 'Unsupported WASM engine paths');
@@ -230,7 +230,7 @@ export function verifyEnginePackage(dir) {
230
230
  for (const key of ['loader', 'wasm', 'data', 'metadata']) regularFile(dir, engine[key]);
231
231
  const module = new WebAssembly.Module(readFileSync(join(dir, engine.wasm)));
232
232
  const exports = new Set(WebAssembly.Module.exports(module).filter((entry) => entry.kind === 'function').map((entry) => entry.name.replace(/^_/, '')));
233
- for (const name of ['dsh_lok_initialize', 'dsh_lok_document_load', 'dsh_lok_document_save_pdf', 'dsh_lok_document_destroy', 'dsh_lok_destroy', 'dsh_lok_error', 'malloc', 'free']) {
233
+ for (const name of ['dsh_lok_initialize', 'dsh_lok_document_load', 'dsh_lok_document_save_pdf', 'dsh_lok_document_export', 'dsh_lok_document_destroy', 'dsh_lok_destroy', 'dsh_lok_error', 'malloc', 'free']) {
234
234
  assert(exports.has(name), `WASM engine missing conversion export: ${name}`);
235
235
  }
236
236
  const dataSize = statSync(join(dir, engine.data)).size;