@deepseek-ai/libreoffice-kit 0.0.2-rc5 → 0.0.2-rc7
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 +3 -1
- package/assets/font-subset.json +4 -4
- package/lib/browser/assets.json +2 -2
- package/lib/browser/index.js +65 -16
- package/lib/browser/types/font-channel.d.ts +5 -4
- package/lib/browser/types/index.d.ts +2 -1
- package/lib/browser/types/office-engine.d.ts +2 -0
- package/lib/browser/types/preparation.d.ts +13 -0
- package/lib/browser/types/protocol.d.ts +7 -6
- package/lib/browser/types/types.d.ts +29 -8
- package/lib/browser/worker.js +138 -21
- package/lib/browser-assets.js +1 -1
- package/lib/cli.js +2 -2
- package/lib/font-source.js +19 -1
- package/lib/font-worker.js +133 -35
- package/lib/index.js +2 -2
- package/lib/types/engine.d.ts +1 -1
- package/lib/types/font-source-types.d.ts +11 -0
- package/lib/types/font-subsets.d.ts +5 -1
- package/lib/types/fonts.d.ts +1 -0
- package/lib/types/office-fonts.d.ts +6 -0
- package/lib/worker.js +7 -6
- package/package.json +2 -2
- package/sources/browser/packages/browser/package.json +1 -1
- package/sources/browser/packages/browser/src/connection.ts +8 -3
- package/sources/browser/packages/browser/src/font-channel.ts +75 -14
- package/sources/browser/packages/browser/src/index.ts +2 -1
- package/sources/browser/packages/browser/src/office-engine.ts +26 -2
- package/sources/browser/packages/browser/src/preparation.ts +41 -0
- package/sources/browser/packages/browser/src/protocol.ts +5 -3
- package/sources/browser/packages/browser/src/types.ts +23 -2
- package/sources/browser/packages/browser/src/worker.ts +19 -4
- package/sources/browser/scripts/build-browser.mjs +1 -1
- package/sources/font-subset/scripts/platform-matrix.mjs +1 -1
- package/sources/font-subset/scripts/verify-artifacts.mjs +3 -3
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-
|
|
736
|
+
const ENGINE_VERSION = "0.0.2-rc7";
|
|
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-
|
|
777
|
+
if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc7" || 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",
|
package/lib/font-source.js
CHANGED
|
@@ -285,6 +285,7 @@ function createFontSource(options = {}) {
|
|
|
285
285
|
let nextId = 0;
|
|
286
286
|
let failure;
|
|
287
287
|
let closing;
|
|
288
|
+
let preparing;
|
|
288
289
|
const pending = /* @__PURE__ */ new Map();
|
|
289
290
|
const fail = (error) => {
|
|
290
291
|
failure ??= error;
|
|
@@ -301,11 +302,13 @@ function createFontSource(options = {}) {
|
|
|
301
302
|
fallbackFamilies: resolved.fontFallbacks,
|
|
302
303
|
maxFiles: resolved.maxFontFiles,
|
|
303
304
|
maxFileBytes: resolved.maxFontFileBytes,
|
|
304
|
-
maxCachedSubsetBytes
|
|
305
|
+
maxCachedSubsetBytes,
|
|
306
|
+
includeOfficeFonts: fontDirectories === void 0
|
|
305
307
|
}
|
|
306
308
|
});
|
|
307
309
|
worker.on("message", (value) => {
|
|
308
310
|
if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "number" || !("kind" in value) || ![
|
|
311
|
+
"prepared",
|
|
309
312
|
"resolved",
|
|
310
313
|
"bytes",
|
|
311
314
|
"failed"
|
|
@@ -347,6 +350,21 @@ function createFontSource(options = {}) {
|
|
|
347
350
|
}
|
|
348
351
|
return {
|
|
349
352
|
fontFallbacks: resolved.fontFallbacks,
|
|
353
|
+
async prepare(signal) {
|
|
354
|
+
signal?.throwIfAborted();
|
|
355
|
+
if (failure !== void 0) throw failure;
|
|
356
|
+
if (preparing === void 0) preparing = call({
|
|
357
|
+
id: ++nextId,
|
|
358
|
+
kind: "prepare"
|
|
359
|
+
}).then((reply) => {
|
|
360
|
+
if (reply.kind !== "prepared") throw new Error("The font Worker returned the wrong operation.");
|
|
361
|
+
}).catch((error) => {
|
|
362
|
+
preparing = void 0;
|
|
363
|
+
throw error;
|
|
364
|
+
});
|
|
365
|
+
await preparing;
|
|
366
|
+
signal?.throwIfAborted();
|
|
367
|
+
},
|
|
350
368
|
async resolve(request, signal) {
|
|
351
369
|
const reply = await call({
|
|
352
370
|
id: ++nextId,
|
package/lib/font-worker.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 { extname, join, posix, win32 } from "node:path";
|
|
4
5
|
import { create } from "fontkit";
|
|
5
|
-
import {
|
|
6
|
+
import { homedir } from "node:os";
|
|
6
7
|
import { readFile } from "node:fs/promises";
|
|
7
8
|
import * as publishedProperties from "@unicode/unicode-17.0.0";
|
|
8
9
|
import variationSelectors from "@unicode/unicode-17.0.0/Binary_Property/Variation_Selector/code-points.mjs";
|
|
@@ -670,7 +671,7 @@ function fontPreferences(request, groups, script, scripts, platform = process.pl
|
|
|
670
671
|
const region = script === "Hangul" ? "kr" : script === "Hiragana" || script === "Katakana" ? "jp" : script === "Bopomofo" ? "tc" : script === "Han" ? hanRegion(request, scripts) : void 0;
|
|
671
672
|
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
673
|
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]
|
|
674
|
+
const config = FONTCONFIG_FONTS[generic === "sansserif" ? "sans-serif" : generic];
|
|
674
675
|
const windows = WINDOWS_FONTS[scriptKey] ?? [];
|
|
675
676
|
const candidates = script === "Latin" || script === "Greek" || script === "Cyrillic" || script === "Common" ? [
|
|
676
677
|
...legacy,
|
|
@@ -704,7 +705,7 @@ function fontPreferences(request, groups, script, scripts, platform = process.pl
|
|
|
704
705
|
//#endregion
|
|
705
706
|
//#region lib/types/fonts.js
|
|
706
707
|
/** Host font metadata snapshots and conversion-local glyph matching over original files. */
|
|
707
|
-
const FONT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
708
|
+
const FONT_EXTENSIONS$1 = /* @__PURE__ */ new Set([
|
|
708
709
|
".ttf",
|
|
709
710
|
".otf",
|
|
710
711
|
".ttc",
|
|
@@ -778,7 +779,7 @@ function fontPaths(directories, maxFiles) {
|
|
|
778
779
|
throw error;
|
|
779
780
|
}
|
|
780
781
|
pending.push(...names.sort().reverse().map((name) => join(canonical, name)));
|
|
781
|
-
} else if (status.isFile() && FONT_EXTENSIONS.has(extname(canonical).toLowerCase())) {
|
|
782
|
+
} else if (status.isFile() && FONT_EXTENSIONS$1.has(extname(canonical).toLowerCase())) {
|
|
782
783
|
if (paths.length >= maxFiles) throw new Error("The system font catalog exceeds maxFontFiles.");
|
|
783
784
|
paths.push(canonical);
|
|
784
785
|
}
|
|
@@ -913,7 +914,7 @@ function indexSystemFonts(options, previous = []) {
|
|
|
913
914
|
if (group) group.push(face);
|
|
914
915
|
else reusable.set(face.path, [face]);
|
|
915
916
|
}
|
|
916
|
-
return fontPaths(options.directories, options.maxFiles).flatMap((path) => {
|
|
917
|
+
return fontPaths([...options.directories, ...options.files ?? []], options.maxFiles).flatMap((path) => {
|
|
917
918
|
const prior = reusable.get(path);
|
|
918
919
|
if (prior !== void 0) {
|
|
919
920
|
let current;
|
|
@@ -1023,6 +1024,89 @@ function readFont(face) {
|
|
|
1023
1024
|
}
|
|
1024
1025
|
}
|
|
1025
1026
|
//#endregion
|
|
1027
|
+
//#region lib/types/office-fonts.js
|
|
1028
|
+
/** Curated fonts discovered from a user's Microsoft Office installation. */
|
|
1029
|
+
const FONT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1030
|
+
".ttf",
|
|
1031
|
+
".otf",
|
|
1032
|
+
".ttc",
|
|
1033
|
+
".otc",
|
|
1034
|
+
".dfont"
|
|
1035
|
+
]);
|
|
1036
|
+
const OFFICE_FONT_FILE = /^(?:aptos(?:[- ].*)?|arial(?:bd|bi|i)?|calibri(?:b|i|z|l|li)?|cambria(?:b|i|z)?|cour(?:bd|bi|i)?|deng(?:b|l)?|fangsong|kaiti|msjh(?:bd)?|msyh(?:bd|l)?|segoeui(?:b|i|z|l|li|sb|sbi|sl|sli)?|simhei|simsunb?|symbol|times(?:bd|bi|i)?|wingdings(?: [23])?|wingdng[23])\.(?:ttf|otf|ttc|otc)$/iu;
|
|
1037
|
+
const FAMILIES = new Set([
|
|
1038
|
+
"aptos",
|
|
1039
|
+
"aptos display",
|
|
1040
|
+
"aptos narrow",
|
|
1041
|
+
"arial",
|
|
1042
|
+
"calibri",
|
|
1043
|
+
"calibri light",
|
|
1044
|
+
"cambria",
|
|
1045
|
+
"cambria math",
|
|
1046
|
+
"courier new",
|
|
1047
|
+
"dengxian",
|
|
1048
|
+
"fangsong",
|
|
1049
|
+
"kaiti",
|
|
1050
|
+
"microsoft jhenghei",
|
|
1051
|
+
"microsoft jhenghei ui",
|
|
1052
|
+
"microsoft yahei",
|
|
1053
|
+
"microsoft yahei ui",
|
|
1054
|
+
"nsimsun",
|
|
1055
|
+
"segoe ui",
|
|
1056
|
+
"simhei",
|
|
1057
|
+
"simsun",
|
|
1058
|
+
"symbol",
|
|
1059
|
+
"times new roman",
|
|
1060
|
+
"wingdings",
|
|
1061
|
+
"wingdings 2",
|
|
1062
|
+
"wingdings 3"
|
|
1063
|
+
].map(normalize));
|
|
1064
|
+
/** @returns whether parsed font names belong to the curated Office compatibility set. */
|
|
1065
|
+
function officeFontFace(face) {
|
|
1066
|
+
return face.aliases.some((alias) => FAMILIES.has(alias));
|
|
1067
|
+
}
|
|
1068
|
+
function directory(path) {
|
|
1069
|
+
try {
|
|
1070
|
+
return statSync(path).isDirectory();
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
if (absent(error)) return false;
|
|
1073
|
+
throw error;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function files(root, recursive, namesOnly = true) {
|
|
1077
|
+
const pending = [root], result = [];
|
|
1078
|
+
for (let current = pending.pop(); current !== void 0; current = pending.pop()) {
|
|
1079
|
+
let entries;
|
|
1080
|
+
try {
|
|
1081
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
if (absent(error)) continue;
|
|
1084
|
+
throw error;
|
|
1085
|
+
}
|
|
1086
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name, "en"))) if (entry.isDirectory()) {
|
|
1087
|
+
if (recursive && entry.name !== "PreviewFont") pending.push(join(current, entry.name));
|
|
1088
|
+
} else if (entry.isFile() && FONT_EXTENSIONS.has(extname(entry.name).toLowerCase()) && (!namesOnly || OFFICE_FONT_FILE.test(entry.name))) result.push(join(current, entry.name));
|
|
1089
|
+
}
|
|
1090
|
+
return result;
|
|
1091
|
+
}
|
|
1092
|
+
/** Find compatibility font files without exposing their paths outside the font Worker. */
|
|
1093
|
+
function officeFontFiles(platform = process.platform, home = homedir(), env = process.env, applicationRoots = ["/Applications", posix.join(home, "Applications")]) {
|
|
1094
|
+
const bundled = platform === "darwin" ? [
|
|
1095
|
+
"Microsoft Word",
|
|
1096
|
+
"Microsoft Excel",
|
|
1097
|
+
"Microsoft PowerPoint"
|
|
1098
|
+
].flatMap((app) => applicationRoots.map((root) => posix.join(root, `${app}.app/Contents/Resources/DFonts`))).find(directory) : platform === "win32" ? [env.ProgramFiles, env["ProgramFiles(x86)"]].filter((root) => Boolean(root)).map((root) => win32.join(root, "Microsoft Office", "root", "vfs", "Fonts", "private")).find(directory) : void 0;
|
|
1099
|
+
const cloud = platform === "darwin" ? posix.join(home, "Library/Group Containers/UBF8T346G9.Office/FontCache") : platform === "win32" ? win32.join(env.LOCALAPPDATA ?? win32.join(home, "AppData", "Local"), "Microsoft", "FontCache") : void 0;
|
|
1100
|
+
const ordered = [...bundled === void 0 ? [] : files(bundled, false).sort(), ...cloud === void 0 ? [] : files(cloud, true, false).sort((a, b) => b.localeCompare(a, "en", { numeric: true }))];
|
|
1101
|
+
const unique = /* @__PURE__ */ new Map();
|
|
1102
|
+
for (const file of ordered) {
|
|
1103
|
+
const portable = file.replaceAll("\\", "/");
|
|
1104
|
+
const name = portable.slice(portable.lastIndexOf("/") + 1).toLowerCase();
|
|
1105
|
+
if (!unique.has(name)) unique.set(name, file);
|
|
1106
|
+
}
|
|
1107
|
+
return [...unique.values()];
|
|
1108
|
+
}
|
|
1109
|
+
//#endregion
|
|
1026
1110
|
//#region lib/types/font-full.js
|
|
1027
1111
|
/** Whole fonts for engines such as PDFium that perform their own glyph mapping. */
|
|
1028
1112
|
function fontFileFormat(bytes) {
|
|
@@ -1175,7 +1259,7 @@ async function fontScriptCodePoints(points, script) {
|
|
|
1175
1259
|
}
|
|
1176
1260
|
//#endregion
|
|
1177
1261
|
//#region lib/types/font-subsets.js
|
|
1178
|
-
/**
|
|
1262
|
+
/** Lifetime-scoped installed-font matching with deterministic, memory-bounded sfnt subsets. */
|
|
1179
1263
|
const ALGORITHM = `${FONT_SUBSET_VERSION}/${FONT_PARTITION_VERSION}`;
|
|
1180
1264
|
const STAT_KEYS = [
|
|
1181
1265
|
"dev",
|
|
@@ -1191,11 +1275,11 @@ function unchanged(face) {
|
|
|
1191
1275
|
const status = statSync(face.path);
|
|
1192
1276
|
if (!status.isFile() || STAT_KEYS.some((key) => status[key] !== face[key])) throw new Error("The selected font changed; resolve it again.");
|
|
1193
1277
|
}
|
|
1194
|
-
function fileIdentity(face) {
|
|
1278
|
+
function fileIdentity(face, wholeFile = false) {
|
|
1195
1279
|
return JSON.stringify([
|
|
1196
1280
|
face.path,
|
|
1197
1281
|
...STAT_KEYS.map((key) => face[key]),
|
|
1198
|
-
face.faceIndex
|
|
1282
|
+
...wholeFile ? [] : [face.faceIndex]
|
|
1199
1283
|
]);
|
|
1200
1284
|
}
|
|
1201
1285
|
/** One Worker-owned font index and LRU whose byte budget excludes transient subsetting input/output. */
|
|
@@ -1211,6 +1295,29 @@ var FontSubsetSource = class {
|
|
|
1211
1295
|
constructor(options) {
|
|
1212
1296
|
this.options = options;
|
|
1213
1297
|
}
|
|
1298
|
+
/** Build the immutable lifetime catalog, adding only Office families absent from normal system roots. */
|
|
1299
|
+
prepare() {
|
|
1300
|
+
if (this.catalog === void 0) {
|
|
1301
|
+
const primary = indexSystemFonts(this.options);
|
|
1302
|
+
const primaryFiles = new Set(primary.map((face) => face.path));
|
|
1303
|
+
const remaining = Math.max(0, this.options.maxFiles - primaryFiles.size);
|
|
1304
|
+
const supplementalFiles = this.options.includeOfficeFonts ? officeFontFiles() : [];
|
|
1305
|
+
const supplemental = remaining === 0 ? [] : indexSystemFonts({
|
|
1306
|
+
directories: [],
|
|
1307
|
+
files: supplementalFiles.slice(0, remaining),
|
|
1308
|
+
maxFiles: remaining,
|
|
1309
|
+
maxFileBytes: this.options.maxFileBytes
|
|
1310
|
+
});
|
|
1311
|
+
const aliases = new Set(primary.flatMap((face) => face.aliases));
|
|
1312
|
+
this.snapshot = [...primary, ...supplemental.filter((face) => officeFontFace(face) && !face.aliases.some((alias) => aliases.has(alias)))];
|
|
1313
|
+
this.catalog = new SystemFontCatalog({
|
|
1314
|
+
faces: this.snapshot,
|
|
1315
|
+
fallbackFamilies: this.options.fallbackFamilies,
|
|
1316
|
+
deduplicateBy: "face"
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
return this.catalog;
|
|
1320
|
+
}
|
|
1214
1321
|
retain(key, bytes) {
|
|
1215
1322
|
const existing = this.cached.get(key);
|
|
1216
1323
|
if (existing !== void 0) {
|
|
@@ -1249,18 +1356,19 @@ var FontSubsetSource = class {
|
|
|
1249
1356
|
}
|
|
1250
1357
|
async describe(face, script) {
|
|
1251
1358
|
unchanged(face);
|
|
1252
|
-
const partition = `${fileIdentity(face)}/${script}`;
|
|
1359
|
+
const partition = `${fileIdentity(face, script === "full" && extname(face.path).toLowerCase() !== ".dfont")}/${script}`;
|
|
1253
1360
|
const previous = this.partitions.get(partition);
|
|
1254
1361
|
if (previous !== void 0) {
|
|
1255
1362
|
this.selected.set(previous.asset.id, previous);
|
|
1256
1363
|
return {
|
|
1257
1364
|
...previous.asset,
|
|
1258
|
-
family: face.family
|
|
1365
|
+
family: face.family,
|
|
1366
|
+
alias: script === "full" ? face.family : previous.asset.alias
|
|
1259
1367
|
};
|
|
1260
1368
|
}
|
|
1261
1369
|
const { bytes, sourceHash } = await this.generate(face, script);
|
|
1262
1370
|
const id = `${script === "full" ? "full_" : ""}${hash(bytes)}`;
|
|
1263
|
-
const key = `${sourceHash}/${face.faceIndex}/${ALGORITHM}/${script}`;
|
|
1371
|
+
const key = script === "full" ? id : `${sourceHash}/${face.faceIndex}/${ALGORITHM}/${script}`;
|
|
1264
1372
|
const asset = {
|
|
1265
1373
|
id,
|
|
1266
1374
|
bytes: bytes.byteLength,
|
|
@@ -1284,33 +1392,13 @@ var FontSubsetSource = class {
|
|
|
1284
1392
|
return asset;
|
|
1285
1393
|
}
|
|
1286
1394
|
/**
|
|
1287
|
-
*
|
|
1395
|
+
* Select whole Unicode-script subsets from the source lifetime's installed-font snapshot.
|
|
1288
1396
|
* @param request - Requested family/style attributes and Unicode scalars.
|
|
1289
1397
|
* @returns reusable subset identities; unavailable characters remain unresolved.
|
|
1290
1398
|
*/
|
|
1291
1399
|
async resolve(request) {
|
|
1292
1400
|
if (request.mode !== void 0 && request.mode !== "subset" && request.mode !== "full") throw new TypeError("Unknown font asset mode.");
|
|
1293
|
-
const
|
|
1294
|
-
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
|
-
for (const [partition, selection] of this.partitions) {
|
|
1297
|
-
if (current.has(fileIdentity(selection.face))) continue;
|
|
1298
|
-
this.partitions.delete(partition);
|
|
1299
|
-
if (this.selected.get(selection.asset.id) === selection) this.selected.delete(selection.asset.id);
|
|
1300
|
-
const bytes = this.cached.get(selection.key);
|
|
1301
|
-
if (bytes !== void 0) {
|
|
1302
|
-
this.cached.delete(selection.key);
|
|
1303
|
-
this.cachedBytes -= bytes.byteLength;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
this.snapshot = snapshot;
|
|
1307
|
-
this.catalog = new SystemFontCatalog({
|
|
1308
|
-
faces: snapshot,
|
|
1309
|
-
fallbackFamilies: this.options.fallbackFamilies,
|
|
1310
|
-
deduplicateBy: "face"
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
const matched = this.catalog.match(request, new AbortController().signal);
|
|
1401
|
+
const matched = this.prepare().match(request, new AbortController().signal);
|
|
1314
1402
|
const fonts = [];
|
|
1315
1403
|
for (const face of matched.fonts) {
|
|
1316
1404
|
if (request.mode === "full") {
|
|
@@ -1352,10 +1440,20 @@ const port = parentPort;
|
|
|
1352
1440
|
const source = new FontSubsetSource(workerData);
|
|
1353
1441
|
let queue = Promise.resolve();
|
|
1354
1442
|
port.on("message", (command) => {
|
|
1355
|
-
if (!Number.isSafeInteger(command?.id) ||
|
|
1443
|
+
if (!Number.isSafeInteger(command?.id) || ![
|
|
1444
|
+
"prepare",
|
|
1445
|
+
"resolve",
|
|
1446
|
+
"read"
|
|
1447
|
+
].includes(command.kind)) throw new Error("The font Worker received an invalid operation.");
|
|
1356
1448
|
queue = queue.then(async () => {
|
|
1357
1449
|
try {
|
|
1358
|
-
if (command.kind === "
|
|
1450
|
+
if (command.kind === "prepare") {
|
|
1451
|
+
source.prepare();
|
|
1452
|
+
port.postMessage({
|
|
1453
|
+
id: command.id,
|
|
1454
|
+
kind: "prepared"
|
|
1455
|
+
});
|
|
1456
|
+
} else if (command.kind === "resolve") {
|
|
1359
1457
|
const value = await source.resolve(command.request);
|
|
1360
1458
|
port.postMessage({
|
|
1361
1459
|
id: command.id,
|
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-
|
|
734
|
+
const ENGINE_VERSION = "0.0.2-rc7";
|
|
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-
|
|
775
|
+
if (pkg.name !== `${ENGINE_PREFIX}-wasm` || pkg.version !== "0.0.2-rc7" || 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",
|
package/lib/types/engine.d.ts
CHANGED
|
@@ -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-
|
|
5
|
+
export declare const ENGINE_VERSION = "0.0.2-rc7";
|
|
6
6
|
/** Host diagnostic fields used to identify the runtime glibc version. */
|
|
7
7
|
export interface EngineHostReport {
|
|
8
8
|
readonly header?: {
|
|
@@ -40,6 +40,11 @@ export interface FontSourceOptions {
|
|
|
40
40
|
export interface FontSource {
|
|
41
41
|
/** Resolved ordered font family preferences shared with browser Fontconfig. */
|
|
42
42
|
readonly fontFallbacks: readonly (readonly string[])[];
|
|
43
|
+
/**
|
|
44
|
+
* Start the lifetime font snapshot without matching a document request.
|
|
45
|
+
* @param signal - Checked before dispatch and after the shared preparation settles.
|
|
46
|
+
*/
|
|
47
|
+
prepare(signal?: AbortSignal): Promise<void>;
|
|
43
48
|
/**
|
|
44
49
|
* Select deterministic Unicode-script subsets using LibreOffice's requested attributes.
|
|
45
50
|
* @param request - Family, style, language, and required Unicode scalars.
|
|
@@ -59,6 +64,9 @@ export interface FontSource {
|
|
|
59
64
|
}
|
|
60
65
|
/** Parent-to-worker operations; neither message contains a caller-selected file path. */
|
|
61
66
|
export type FontCommand = {
|
|
67
|
+
readonly id: number;
|
|
68
|
+
readonly kind: 'prepare';
|
|
69
|
+
} | {
|
|
62
70
|
readonly id: number;
|
|
63
71
|
readonly kind: 'resolve';
|
|
64
72
|
readonly request: FontResolveRequest;
|
|
@@ -69,6 +77,9 @@ export type FontCommand = {
|
|
|
69
77
|
};
|
|
70
78
|
/** Worker replies retain their operation discriminator across structured cloning. */
|
|
71
79
|
export type FontReply = {
|
|
80
|
+
readonly id: number;
|
|
81
|
+
readonly kind: 'prepared';
|
|
82
|
+
} | {
|
|
72
83
|
readonly id: number;
|
|
73
84
|
readonly kind: 'resolved';
|
|
74
85
|
readonly value: FontResolution;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { SystemFontCatalog } from './fonts.ts';
|
|
1
2
|
import type { FontIndexOptions } from './fonts.ts';
|
|
2
3
|
import type { FontAssetId, FontResolution, FontResolveRequest } from './font-source-types.ts';
|
|
3
4
|
/** Source limits and resolved family preferences passed to the private font Worker. */
|
|
4
5
|
export interface FontSubsetOptions extends FontIndexOptions {
|
|
5
6
|
readonly fallbackFamilies: readonly (readonly string[])[];
|
|
6
7
|
readonly maxCachedSubsetBytes: number;
|
|
8
|
+
readonly includeOfficeFonts?: boolean;
|
|
7
9
|
}
|
|
8
10
|
/** One Worker-owned font index and LRU whose byte budget excludes transient subsetting input/output. */
|
|
9
11
|
export declare class FontSubsetSource {
|
|
@@ -16,11 +18,13 @@ export declare class FontSubsetSource {
|
|
|
16
18
|
private cachedBytes;
|
|
17
19
|
/** @param options - Resolved discovery, fallback, and retained subset limits. */
|
|
18
20
|
constructor(options: FontSubsetOptions);
|
|
21
|
+
/** Build the immutable lifetime catalog, adding only Office families absent from normal system roots. */
|
|
22
|
+
prepare(): SystemFontCatalog;
|
|
19
23
|
private retain;
|
|
20
24
|
private generate;
|
|
21
25
|
private describe;
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* Select whole Unicode-script subsets from the source lifetime's installed-font snapshot.
|
|
24
28
|
* @param request - Requested family/style attributes and Unicode scalars.
|
|
25
29
|
* @returns reusable subset identities; unavailable characters remain unresolved.
|
|
26
30
|
*/
|
package/lib/types/fonts.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export interface SystemFontCatalogOptions {
|
|
|
45
45
|
/** Host font roots and physical file limits. */
|
|
46
46
|
export interface FontIndexOptions {
|
|
47
47
|
readonly directories: readonly string[];
|
|
48
|
+
readonly files?: readonly string[];
|
|
48
49
|
readonly maxFiles: number;
|
|
49
50
|
readonly maxFileBytes: number;
|
|
50
51
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FontFace } from './fonts.ts';
|
|
2
|
+
/** @returns whether parsed font names belong to the curated Office compatibility set. */
|
|
3
|
+
export declare function officeFontFace(face: Pick<FontFace, 'aliases'>): boolean;
|
|
4
|
+
/** Find compatibility font files without exposing their paths outside the font Worker. */
|
|
5
|
+
export declare function officeFontFiles(platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv, applicationRoots?: readonly string[]): string[];
|
|
6
|
+
//# sourceMappingURL=office-fonts.d.ts.map
|
package/lib/worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { parentPort, workerData } from "node:worker_threads";
|
|
3
3
|
import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { basename,
|
|
4
|
+
import { basename, extname, join } from "node:path";
|
|
5
5
|
import { strFromU8, unzipSync, zlibSync } from "fflate";
|
|
6
6
|
import { SaxesParser } from "saxes";
|
|
7
7
|
import { create } from "fontkit";
|
|
@@ -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,
|
|
@@ -1110,7 +1110,7 @@ function indexSystemFonts(options, previous = []) {
|
|
|
1110
1110
|
if (group) group.push(face);
|
|
1111
1111
|
else reusable.set(face.path, [face]);
|
|
1112
1112
|
}
|
|
1113
|
-
return fontPaths(options.directories, options.maxFiles).flatMap((path) => {
|
|
1113
|
+
return fontPaths([...options.directories, ...options.files ?? []], options.maxFiles).flatMap((path) => {
|
|
1114
1114
|
const prior = reusable.get(path);
|
|
1115
1115
|
if (prior !== void 0) {
|
|
1116
1116
|
let current;
|
|
@@ -1430,13 +1430,14 @@ async function withWasmSession(request, use) {
|
|
|
1430
1430
|
mainScriptUrlOrBlob: engine.loader,
|
|
1431
1431
|
locateFile(name) {
|
|
1432
1432
|
const file = basename(name);
|
|
1433
|
-
if (
|
|
1433
|
+
if (file === "soffice.wasm") return engine.wasm;
|
|
1434
|
+
for (const asset of [
|
|
1434
1435
|
engine.loader,
|
|
1435
1436
|
engine.data,
|
|
1436
1437
|
engine.wasm,
|
|
1437
1438
|
engine.metadata
|
|
1438
|
-
]
|
|
1439
|
-
|
|
1439
|
+
]) if (basename(asset) === file) return asset;
|
|
1440
|
+
throw new Error(`LibreOffice requested an unlisted asset: ${file}`);
|
|
1440
1441
|
},
|
|
1441
1442
|
getPreloadedPackage: () => data,
|
|
1442
1443
|
dshResolveSystemFonts(request) {
|
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-
|
|
4
|
+
"version": "0.0.2-rc7",
|
|
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-
|
|
88
|
+
"@deepseek-ai/libreoffice-kit-wasm": "0.0.2-rc7"
|
|
89
89
|
},
|
|
90
90
|
"bin": {
|
|
91
91
|
"libreoffice-kit": "./lib/cli.js"
|
|
@@ -3,6 +3,7 @@ import { FONT_CHUNK_BYTES, FONT_HEADER_BYTES, FontState } from './protocol.ts'
|
|
|
3
3
|
import type { OwnerMessage, OwnerRequest, WorkerMessage, WorkerOptions } from './protocol.ts'
|
|
4
4
|
import { fontFrames, fontViews } from './font-channel.ts'
|
|
5
5
|
import { BrowserRenderError } from './types.ts'
|
|
6
|
+
import { preparedBrowserModule } from './preparation.ts'
|
|
6
7
|
import type { BrowserDocumentOptions } from './types.ts'
|
|
7
8
|
import type { OfficeDocumentEvent, OfficeDocumentOptions } from './office-types.ts'
|
|
8
9
|
|
|
@@ -23,6 +24,7 @@ export async function openBrowserConnection(options: BrowserDocumentOptions | Of
|
|
|
23
24
|
if (!globalThis.crossOriginIsolated || typeof SharedArrayBuffer === 'undefined' || typeof Worker === 'undefined') throw new BrowserRenderError('unavailable', 'LibreOffice requires an isolated secure browser context with Worker and SharedArrayBuffer support.')
|
|
24
25
|
if (![options.timeoutMs, options.maxLoadedFontBytes, options.maxArchiveEntries, options.maxUncompressedBytes].every(value => Number.isSafeInteger(value) && value > 0) || options.timeoutMs > 0x7fffffff) throw new TypeError('Document limits must be positive integers and timeoutMs must fit a browser timer.')
|
|
25
26
|
if (!(office ? ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'] : ['pdf']).includes(options.extension) || options.data.byteLength === 0) throw new BrowserRenderError('invalid-document', 'The document is empty or has an unsupported extension.')
|
|
27
|
+
if (options.preparedEngine !== undefined) preparedBrowserModule(options.preparedEngine, options.assets)
|
|
26
28
|
const worker = new Worker(options.assets.workerUrl, { name: 'libreoffice-document' })
|
|
27
29
|
const channel = new SharedArrayBuffer(FONT_HEADER_BYTES + FONT_CHUNK_BYTES)
|
|
28
30
|
const { control, bytes } = fontViews(channel)
|
|
@@ -64,9 +66,9 @@ export async function openBrowserConnection(options: BrowserDocumentOptions | Of
|
|
|
64
66
|
case 'office-event': if (!closed) { onEvent?.(message.event); if (message.event.type === 'error') void dispose() }; return
|
|
65
67
|
case 'font':
|
|
66
68
|
if (closed) return
|
|
67
|
-
void Promise.resolve().then(() => options.resolveFonts(message.request, lifetime.signal)).then(result => {
|
|
69
|
+
void Promise.resolve().then(() => options.resolveFonts(message.request, message.known, lifetime.signal)).then(result => {
|
|
68
70
|
if (closed) return
|
|
69
|
-
frames = fontFrames(result)
|
|
71
|
+
frames = fontFrames(result, message.known)
|
|
70
72
|
pumpFonts()
|
|
71
73
|
}, sendFontError)
|
|
72
74
|
return
|
|
@@ -136,7 +138,10 @@ export async function openBrowserConnection(options: BrowserDocumentOptions | Of
|
|
|
136
138
|
|
|
137
139
|
try {
|
|
138
140
|
const data = new Uint8Array(options.data)
|
|
139
|
-
const engineOptions: WorkerOptions = { data, extension: options.extension, assets: options.assets,
|
|
141
|
+
const engineOptions: WorkerOptions = { data, extension: options.extension, assets: options.assets,
|
|
142
|
+
...(options.preparedEngine === undefined ? {} : { preparedEngine: options.preparedEngine }),
|
|
143
|
+
timeoutMs: options.timeoutMs, maxLoadedFontBytes: options.maxLoadedFontBytes, fontFallbacks: options.fontFallbacks,
|
|
144
|
+
maxArchiveEntries: options.maxArchiveEntries, maxUncompressedBytes: options.maxUncompressedBytes }
|
|
140
145
|
const result = await post({ type: 'open', id: ++sequence, options: engineOptions, channel, ...(office ? { office: true } : {}) }, [data.buffer])
|
|
141
146
|
if (result.type !== 'opened') throw new BrowserRenderError('invalid-document', 'LibreOffice returned an unexpected load response.')
|
|
142
147
|
opened = result
|