@deepseek-ai/libreoffice-kit 0.0.2-rc6 → 0.0.2-rc9
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 +2 -2
- package/README.zh.md +1 -1
- package/assets/font-subset.json +2 -2
- package/lib/browser/assets.json +2 -2
- package/lib/browser/index.js +333 -162
- package/lib/browser/types/connection.d.ts +28 -6
- package/lib/browser/types/font-channel.d.ts +16 -1
- package/lib/browser/types/index.d.ts +3 -2
- package/lib/browser/types/office-engine.d.ts +10 -2
- package/lib/browser/types/office-types.d.ts +60 -1
- package/lib/browser/types/office.d.ts +18 -3
- package/lib/browser/types/preparation.d.ts +13 -0
- package/lib/browser/types/protocol.d.ts +33 -10
- package/lib/browser/types/types.d.ts +31 -8
- package/lib/browser/worker.js +360 -106
- 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 +126 -29
- 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 +6 -5
- package/package.json +2 -2
- package/sources/browser/packages/browser/package.json +1 -1
- package/sources/browser/packages/browser/src/connection.ts +105 -34
- package/sources/browser/packages/browser/src/font-channel.ts +69 -9
- package/sources/browser/packages/browser/src/index.ts +3 -2
- package/sources/browser/packages/browser/src/office-engine.ts +80 -6
- package/sources/browser/packages/browser/src/office-types.ts +52 -1
- package/sources/browser/packages/browser/src/office.ts +118 -52
- package/sources/browser/packages/browser/src/preparation.ts +41 -0
- package/sources/browser/packages/browser/src/protocol.ts +19 -5
- package/sources/browser/packages/browser/src/types.ts +26 -2
- package/sources/browser/packages/browser/src/worker.ts +138 -53
- package/sources/browser/scripts/build-browser.mjs +6 -2
- package/sources/font-subset/scripts/verify-artifacts.mjs +1 -1
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-rc9";
|
|
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-rc9" || 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 } from "node:path";
|
|
4
|
+
import { extname, join, posix, win32 } from "node:path";
|
|
5
5
|
import { create } from "fontkit";
|
|
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";
|
|
@@ -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",
|
|
@@ -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) {
|
|
@@ -1285,33 +1392,13 @@ var FontSubsetSource = class {
|
|
|
1285
1392
|
return asset;
|
|
1286
1393
|
}
|
|
1287
1394
|
/**
|
|
1288
|
-
*
|
|
1395
|
+
* Select whole Unicode-script subsets from the source lifetime's installed-font snapshot.
|
|
1289
1396
|
* @param request - Requested family/style attributes and Unicode scalars.
|
|
1290
1397
|
* @returns reusable subset identities; unavailable characters remain unresolved.
|
|
1291
1398
|
*/
|
|
1292
1399
|
async resolve(request) {
|
|
1293
1400
|
if (request.mode !== void 0 && request.mode !== "subset" && request.mode !== "full") throw new TypeError("Unknown font asset mode.");
|
|
1294
|
-
const
|
|
1295
|
-
if (this.catalog === void 0 || snapshot.length !== this.snapshot.length || snapshot.some((face, index) => face !== this.snapshot[index])) {
|
|
1296
|
-
const current = new Set(snapshot.map((face) => fileIdentity(face)));
|
|
1297
|
-
for (const [partition, selection] of this.partitions) {
|
|
1298
|
-
if (current.has(fileIdentity(selection.face))) continue;
|
|
1299
|
-
this.partitions.delete(partition);
|
|
1300
|
-
if (this.selected.get(selection.asset.id) === selection) this.selected.delete(selection.asset.id);
|
|
1301
|
-
const bytes = this.cached.get(selection.key);
|
|
1302
|
-
if (bytes !== void 0) {
|
|
1303
|
-
this.cached.delete(selection.key);
|
|
1304
|
-
this.cachedBytes -= bytes.byteLength;
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
this.snapshot = snapshot;
|
|
1308
|
-
this.catalog = new SystemFontCatalog({
|
|
1309
|
-
faces: snapshot,
|
|
1310
|
-
fallbackFamilies: this.options.fallbackFamilies,
|
|
1311
|
-
deduplicateBy: "face"
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
const matched = this.catalog.match(request, new AbortController().signal);
|
|
1401
|
+
const matched = this.prepare().match(request, new AbortController().signal);
|
|
1315
1402
|
const fonts = [];
|
|
1316
1403
|
for (const face of matched.fonts) {
|
|
1317
1404
|
if (request.mode === "full") {
|
|
@@ -1353,10 +1440,20 @@ const port = parentPort;
|
|
|
1353
1440
|
const source = new FontSubsetSource(workerData);
|
|
1354
1441
|
let queue = Promise.resolve();
|
|
1355
1442
|
port.on("message", (command) => {
|
|
1356
|
-
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.");
|
|
1357
1448
|
queue = queue.then(async () => {
|
|
1358
1449
|
try {
|
|
1359
|
-
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") {
|
|
1360
1457
|
const value = await source.resolve(command.request);
|
|
1361
1458
|
port.postMessage({
|
|
1362
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-rc9";
|
|
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-rc9" || 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-rc9";
|
|
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";
|
|
@@ -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-rc9",
|
|
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-rc9"
|
|
89
89
|
},
|
|
90
90
|
"bin": {
|
|
91
91
|
"libreoffice-kit": "./lib/cli.js"
|