@deepseek-ai/libreoffice-kit 0.0.3 → 0.0.4
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 +21 -4
- package/README.zh.md +21 -4
- package/lib/cli.js +149 -20
- package/lib/font-snapshot-worker.js +454 -0
- package/lib/index.js +153 -22
- package/lib/types/engine.d.ts +1 -1
- package/lib/types/font-metadata-cache.d.ts +11 -0
- package/lib/types/font-snapshot-state.d.ts +15 -0
- package/lib/types/font-snapshot-validation.d.ts +4 -0
- package/lib/types/font-snapshot-worker.d.ts +9 -0
- package/lib/types/font-snapshot.d.ts +11 -0
- package/lib/types/fonts.d.ts +9 -3
- package/lib/types/index.d.ts +4 -0
- package/lib/types/options.d.ts +2 -0
- package/lib/types/worker.d.ts +3 -3
- package/lib/worker.js +7 -248
- package/package.json +7 -6
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { constants, lstatSync, readdirSync } from "node:fs";
|
|
3
|
-
import { mkdir, mkdtemp, open, readFile, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { lstat, mkdir, mkdtemp, open, readFile, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
6
6
|
import { Worker } from "node:worker_threads";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
8
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
10
10
|
import { zlibSync } from "fflate";
|
|
11
11
|
import "fontkit";
|
|
@@ -1012,6 +1012,14 @@ function mobileAssetFontDirectories(assets) {
|
|
|
1012
1012
|
return entries.filter((name) => /^com_apple_MobileAsset_Font\d*$/.test(name)).sort().map((name) => join(assets, name));
|
|
1013
1013
|
}
|
|
1014
1014
|
//#endregion
|
|
1015
|
+
//#region lib/types/font-metadata-cache.js
|
|
1016
|
+
/** Resolve the platform's user-local cache, independently of font discovery. */
|
|
1017
|
+
function defaultFontMetadataCacheDirectory(platform = process.platform, home = homedir(), env = process.env) {
|
|
1018
|
+
if (platform === "darwin") return posix.join(home, "Library/Caches/libreoffice-kit");
|
|
1019
|
+
if (platform === "win32") return win32.join(env.LOCALAPPDATA ?? win32.join(home, "AppData/Local"), "libreoffice-kit/Cache");
|
|
1020
|
+
return posix.join(env.XDG_CACHE_HOME && posix.isAbsolute(env.XDG_CACHE_HOME) ? env.XDG_CACHE_HOME : posix.join(home, ".cache"), "libreoffice-kit");
|
|
1021
|
+
}
|
|
1022
|
+
//#endregion
|
|
1015
1023
|
//#region lib/types/options.js
|
|
1016
1024
|
const SANS_CJK_FAMILIES = [
|
|
1017
1025
|
"Microsoft YaHei",
|
|
@@ -1136,7 +1144,8 @@ const DEFAULT_LIMITS = {
|
|
|
1136
1144
|
maxFontFiles: 2e4,
|
|
1137
1145
|
maxFontFileBytes: 268435456,
|
|
1138
1146
|
maxLoadedFontBytes: 536870912,
|
|
1139
|
-
maxFontResolutionEntries: 4096
|
|
1147
|
+
maxFontResolutionEntries: 4096,
|
|
1148
|
+
maxFontMetadataCacheBytes: 33554432
|
|
1140
1149
|
};
|
|
1141
1150
|
const FONT_COLLECTION_NAMES = ["fontDirectories", "initialFontFamilies"];
|
|
1142
1151
|
function positiveSafeInteger(value, name) {
|
|
@@ -1174,8 +1183,12 @@ function resolveOptions(input = {}) {
|
|
|
1174
1183
|
initialFontFamilies: [],
|
|
1175
1184
|
...input
|
|
1176
1185
|
};
|
|
1177
|
-
for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks") throw new TypeError(`Unknown converter option: ${key}`);
|
|
1186
|
+
for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory") throw new TypeError(`Unknown converter option: ${key}`);
|
|
1187
|
+
const cacheDirectory = input.fontMetadataCacheDirectory === void 0 ? defaultFontMetadataCacheDirectory() : input.fontMetadataCacheDirectory;
|
|
1188
|
+
if (cacheDirectory !== false && (typeof cacheDirectory !== "string" || !isAbsolute(cacheDirectory) || cacheDirectory.includes("\0"))) throw new TypeError("fontMetadataCacheDirectory must be an absolute path or false.");
|
|
1178
1189
|
return {
|
|
1190
|
+
fontMetadataCacheDirectory: cacheDirectory,
|
|
1191
|
+
maxFontMetadataCacheBytes: positiveSafeInteger(merged.maxFontMetadataCacheBytes, "maxFontMetadataCacheBytes"),
|
|
1179
1192
|
timeoutMs: positiveSafeInteger(merged.timeoutMs, "timeoutMs"),
|
|
1180
1193
|
maxInputBytes: positiveSafeInteger(merged.maxInputBytes, "maxInputBytes"),
|
|
1181
1194
|
maxOutputBytes: positiveSafeInteger(merged.maxOutputBytes, "maxOutputBytes"),
|
|
@@ -1200,7 +1213,7 @@ const require = createRequire(import.meta.url);
|
|
|
1200
1213
|
* Engine-family version every installed engine package must carry. The engine
|
|
1201
1214
|
* family shares its release version with this Node API.
|
|
1202
1215
|
*/
|
|
1203
|
-
const ENGINE_VERSION = "0.0.
|
|
1216
|
+
const ENGINE_VERSION = "0.0.4";
|
|
1204
1217
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1205
1218
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
|
1206
1219
|
/**
|
|
@@ -1279,7 +1292,7 @@ async function readEngine(packageFile, backend, target) {
|
|
|
1279
1292
|
const root = dirname(packageFile);
|
|
1280
1293
|
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))]);
|
|
1281
1294
|
const engine = manifest.engine;
|
|
1282
|
-
if (pkg.name !== `${ENGINE_PREFIX}-${target}` || pkg.version !== "0.0.
|
|
1295
|
+
if (pkg.name !== `${ENGINE_PREFIX}-${target}` || pkg.version !== "0.0.4" || manifest.version !== pkg.version || manifest.schemaVersion !== 1 || manifest.status !== "built" || engine === void 0 || engine.kind !== backend || manifest.platform !== target) throw new Error(`Installed LibreOfficeKit ${backend} package has an incompatible or incomplete manifest.`);
|
|
1283
1296
|
const minimum = engine.glibcMinimum;
|
|
1284
1297
|
if (minimum !== void 0 && (!target.endsWith("-glibc") || !glibcVersion(minimum))) throw new Error("Installed LibreOfficeKit engine has an invalid glibcMinimum.");
|
|
1285
1298
|
const glibcFloor = minimum === void 0 ? {} : { glibcMinimum: minimum };
|
|
@@ -1414,6 +1427,111 @@ async function discoverRuntime() {
|
|
|
1414
1427
|
}
|
|
1415
1428
|
}
|
|
1416
1429
|
//#endregion
|
|
1430
|
+
//#region lib/types/font-snapshot-state.js
|
|
1431
|
+
/** Shared in-flight metadata work with independent cancellation and joined Worker cleanup. */
|
|
1432
|
+
/** Run one scan outside the event loop and join it before returning or cleaning its temporary file. */
|
|
1433
|
+
async function runFontSnapshot(options, previous, signal) {
|
|
1434
|
+
signal.throwIfAborted();
|
|
1435
|
+
const temporaryPath = options.fontMetadataCacheDirectory === false ? void 0 : join(options.fontMetadataCacheDirectory, `.font-metadata-${randomUUID()}.tmp`);
|
|
1436
|
+
const data = {
|
|
1437
|
+
options,
|
|
1438
|
+
previous,
|
|
1439
|
+
...temporaryPath === void 0 ? {} : { temporaryPath }
|
|
1440
|
+
};
|
|
1441
|
+
const worker = new Worker(new URL("./font-snapshot-worker.js", import.meta.url), {
|
|
1442
|
+
workerData: data,
|
|
1443
|
+
execArgv: [],
|
|
1444
|
+
name: "libreoffice-font-metadata",
|
|
1445
|
+
stdout: true,
|
|
1446
|
+
stderr: true
|
|
1447
|
+
});
|
|
1448
|
+
worker.stdout.resume();
|
|
1449
|
+
worker.stderr.resume();
|
|
1450
|
+
const result = Promise.withResolvers();
|
|
1451
|
+
const abort = () => result.reject(signal.reason);
|
|
1452
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1453
|
+
worker.once("error", result.reject);
|
|
1454
|
+
worker.once("exit", (code) => result.reject(new ConversionError("failed", `Font metadata worker exited before returning a snapshot (${code}).`)));
|
|
1455
|
+
worker.once("message", (message) => {
|
|
1456
|
+
if (message.ok) result.resolve(message.snapshot);
|
|
1457
|
+
else result.reject(new ConversionError(failureCode(message), message.error));
|
|
1458
|
+
});
|
|
1459
|
+
try {
|
|
1460
|
+
return await result.promise;
|
|
1461
|
+
} finally {
|
|
1462
|
+
signal.removeEventListener("abort", abort);
|
|
1463
|
+
await worker.terminate();
|
|
1464
|
+
if (temporaryPath !== void 0) try {
|
|
1465
|
+
await rm(temporaryPath, { force: true });
|
|
1466
|
+
} catch {}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
/** Each acquisition refreshes inventory; overlapping acquisitions share only the active scan. */
|
|
1470
|
+
var FontSnapshotState = class {
|
|
1471
|
+
previous = [];
|
|
1472
|
+
scan;
|
|
1473
|
+
/** Revalidate files for an operation without coupling its cancellation to other waiters. */
|
|
1474
|
+
async acquire(options, signal) {
|
|
1475
|
+
signal.throwIfAborted();
|
|
1476
|
+
while (this.scan?.controller.signal.aborted) {
|
|
1477
|
+
await this.scan.promise.catch(() => {});
|
|
1478
|
+
signal.throwIfAborted();
|
|
1479
|
+
}
|
|
1480
|
+
if (this.scan === void 0) {
|
|
1481
|
+
const controller = new AbortController();
|
|
1482
|
+
const promise = runFontSnapshot(options, this.previous, controller.signal).then((snapshot) => {
|
|
1483
|
+
this.previous = Buffer.byteLength(JSON.stringify(snapshot.records)) <= options.maxFontMetadataCacheBytes ? snapshot.records : [];
|
|
1484
|
+
return snapshot;
|
|
1485
|
+
}).finally(() => {
|
|
1486
|
+
this.scan = void 0;
|
|
1487
|
+
});
|
|
1488
|
+
this.scan = {
|
|
1489
|
+
controller,
|
|
1490
|
+
promise,
|
|
1491
|
+
waiters: 0
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
const scan = this.scan;
|
|
1495
|
+
scan.waiters++;
|
|
1496
|
+
const cancelled = Promise.withResolvers();
|
|
1497
|
+
const abort = () => cancelled.reject(signal.reason);
|
|
1498
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1499
|
+
try {
|
|
1500
|
+
return await Promise.race([scan.promise, cancelled.promise]);
|
|
1501
|
+
} finally {
|
|
1502
|
+
signal.removeEventListener("abort", abort);
|
|
1503
|
+
scan.waiters--;
|
|
1504
|
+
if (scan.waiters === 0 && this.scan === scan) {
|
|
1505
|
+
scan.controller.abort(/* @__PURE__ */ new Error("All font scan waiters stopped."));
|
|
1506
|
+
await scan.promise.catch(() => {});
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
/** Release completed metadata after the owning factory has joined its operations. */
|
|
1511
|
+
clear() {
|
|
1512
|
+
this.previous = [];
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
//#endregion
|
|
1516
|
+
//#region lib/types/font-snapshot-validation.js
|
|
1517
|
+
/** Verify the operation's source versions before publishing its output. */
|
|
1518
|
+
/** Reject changed, removed, or replaced sources without exposing local font paths. */
|
|
1519
|
+
async function validateFontSnapshot(snapshot) {
|
|
1520
|
+
await Promise.all(snapshot.records.map(async (record) => {
|
|
1521
|
+
try {
|
|
1522
|
+
const current = await lstat(record.path);
|
|
1523
|
+
if (current.isFile() && [
|
|
1524
|
+
"dev",
|
|
1525
|
+
"ino",
|
|
1526
|
+
"size",
|
|
1527
|
+
"mtimeMs",
|
|
1528
|
+
"ctimeMs"
|
|
1529
|
+
].every((key) => current[key] === record[key])) return;
|
|
1530
|
+
} catch {}
|
|
1531
|
+
throw new ConversionError("failed", "A system font changed during conversion; retry the operation.");
|
|
1532
|
+
}));
|
|
1533
|
+
}
|
|
1534
|
+
//#endregion
|
|
1417
1535
|
//#region lib/types/index.js
|
|
1418
1536
|
/** Convert caller-authorized disk documents with installed native or Node WASM engines. */
|
|
1419
1537
|
/** File identity that must match across a bounded read. */
|
|
@@ -1444,7 +1562,7 @@ async function readBounded(path, limit, signal, role) {
|
|
|
1444
1562
|
await file.close();
|
|
1445
1563
|
}
|
|
1446
1564
|
}
|
|
1447
|
-
async function runWorker(data, signal,
|
|
1565
|
+
async function runWorker(data, signal, onFontCache) {
|
|
1448
1566
|
signal.throwIfAborted();
|
|
1449
1567
|
const worker = new Worker(new URL("./worker.js", import.meta.url), {
|
|
1450
1568
|
workerData: data,
|
|
@@ -1465,8 +1583,7 @@ async function runWorker(data, signal, onFonts, onFontCache) {
|
|
|
1465
1583
|
settled.reject(new ConversionError("failed", `LibreOffice worker exited before returning a result (${code}).`));
|
|
1466
1584
|
});
|
|
1467
1585
|
worker.on("message", (message) => {
|
|
1468
|
-
if (message.kind === "
|
|
1469
|
-
else if (message.kind === "font-cache") onFontCache(message.entries);
|
|
1586
|
+
if (message.kind === "font-cache") onFontCache(message.entries);
|
|
1470
1587
|
else if (message.ok) settled.resolve(message);
|
|
1471
1588
|
else settled.reject(new ConversionError(failureCode(message), message.error));
|
|
1472
1589
|
});
|
|
@@ -1489,7 +1606,9 @@ function sharedStateKey(options, engine) {
|
|
|
1489
1606
|
maxFontFiles: options.maxFontFiles,
|
|
1490
1607
|
maxFontFileBytes: options.maxFontFileBytes,
|
|
1491
1608
|
maxLoadedFontBytes: options.maxLoadedFontBytes,
|
|
1492
|
-
maxFontResolutionEntries: options.maxFontResolutionEntries
|
|
1609
|
+
maxFontResolutionEntries: options.maxFontResolutionEntries,
|
|
1610
|
+
fontMetadataCacheDirectory: options.fontMetadataCacheDirectory,
|
|
1611
|
+
maxFontMetadataCacheBytes: options.maxFontMetadataCacheBytes
|
|
1493
1612
|
});
|
|
1494
1613
|
}
|
|
1495
1614
|
function defaultSharedState(options, engine) {
|
|
@@ -1501,7 +1620,8 @@ function defaultSharedState(options, engine) {
|
|
|
1501
1620
|
return existing;
|
|
1502
1621
|
}
|
|
1503
1622
|
const state = {
|
|
1504
|
-
|
|
1623
|
+
snapshots: new FontSnapshotState(),
|
|
1624
|
+
generation: void 0,
|
|
1505
1625
|
fontCache: /* @__PURE__ */ new Map()
|
|
1506
1626
|
};
|
|
1507
1627
|
defaultSharedStates.set(key, state);
|
|
@@ -1527,7 +1647,8 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1527
1647
|
const waiting = /* @__PURE__ */ new Set();
|
|
1528
1648
|
let running = false;
|
|
1529
1649
|
let disposal;
|
|
1530
|
-
const mergeCache = (entries) => {
|
|
1650
|
+
const mergeCache = (generation, entries) => {
|
|
1651
|
+
if (shared.generation !== generation) return;
|
|
1531
1652
|
for (const entry of entries) {
|
|
1532
1653
|
const prior = shared.fontCache.get(entry.key);
|
|
1533
1654
|
const faces = new Map((prior?.faces ?? []).map((face) => [`${face.path}\0${face.faceIndex}`, face]));
|
|
@@ -1544,6 +1665,14 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1544
1665
|
}
|
|
1545
1666
|
while (shared.fontCache.size > resolvedOptions.maxFontResolutionEntries) shared.fontCache.delete(shared.fontCache.keys().next().value);
|
|
1546
1667
|
};
|
|
1668
|
+
async function snapshot(signal) {
|
|
1669
|
+
const current = await shared.snapshots.acquire(resolvedOptions, signal);
|
|
1670
|
+
if (shared.generation !== current.generation) {
|
|
1671
|
+
shared.generation = current.generation;
|
|
1672
|
+
shared.fontCache.clear();
|
|
1673
|
+
}
|
|
1674
|
+
return current;
|
|
1675
|
+
}
|
|
1547
1676
|
async function acquire(signal) {
|
|
1548
1677
|
while (running) {
|
|
1549
1678
|
signal.throwIfAborted();
|
|
@@ -1591,6 +1720,7 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1591
1720
|
} finally {
|
|
1592
1721
|
await input.close();
|
|
1593
1722
|
}
|
|
1723
|
+
const fonts = await snapshot(stopped);
|
|
1594
1724
|
const result = await runWorker({
|
|
1595
1725
|
inputPath,
|
|
1596
1726
|
extension,
|
|
@@ -1598,11 +1728,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1598
1728
|
options: resolvedOptions,
|
|
1599
1729
|
engine,
|
|
1600
1730
|
scratch,
|
|
1601
|
-
fontFaces:
|
|
1731
|
+
fontFaces: fonts.faces,
|
|
1602
1732
|
fontCache: [...shared.fontCache.values()]
|
|
1603
|
-
}, stopped, (
|
|
1604
|
-
shared.fontFaces ??= faces;
|
|
1605
|
-
}, mergeCache);
|
|
1733
|
+
}, stopped, (entries) => mergeCache(fonts.generation, entries));
|
|
1606
1734
|
if ("images" in result) throw new ConversionError("failed", "Conversion worker returned an image batch for an export request.");
|
|
1607
1735
|
let bytes;
|
|
1608
1736
|
if ("output" in result) bytes = result.output;
|
|
@@ -1615,6 +1743,7 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1615
1743
|
bytes = await readBounded(path, resolvedOptions.maxOutputBytes, stopped, "output");
|
|
1616
1744
|
}
|
|
1617
1745
|
validateOutput(bytes, format);
|
|
1746
|
+
await validateFontSnapshot(fonts);
|
|
1618
1747
|
stopped.throwIfAborted();
|
|
1619
1748
|
await output.writeFile(bytes);
|
|
1620
1749
|
stopped.throwIfAborted();
|
|
@@ -1666,6 +1795,7 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1666
1795
|
flag: "wx",
|
|
1667
1796
|
mode: 384
|
|
1668
1797
|
});
|
|
1798
|
+
const fonts = await snapshot(stopped);
|
|
1669
1799
|
const result = await runWorker({
|
|
1670
1800
|
inputPath,
|
|
1671
1801
|
extension: request.extension,
|
|
@@ -1673,11 +1803,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1673
1803
|
options: resolvedOptions,
|
|
1674
1804
|
engine,
|
|
1675
1805
|
scratch,
|
|
1676
|
-
fontFaces:
|
|
1806
|
+
fontFaces: fonts.faces,
|
|
1677
1807
|
fontCache: [...shared.fontCache.values()]
|
|
1678
|
-
}, stopped, (
|
|
1679
|
-
shared.fontFaces ??= faces;
|
|
1680
|
-
}, mergeCache);
|
|
1808
|
+
}, stopped, (entries) => mergeCache(fonts.generation, entries));
|
|
1681
1809
|
let images;
|
|
1682
1810
|
if ("images" in result) images = result.images;
|
|
1683
1811
|
else if ("fonts" in result) {
|
|
@@ -1696,6 +1824,7 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1696
1824
|
signal: stopped
|
|
1697
1825
|
});
|
|
1698
1826
|
} else throw new ConversionError("failed", "Image worker did not return its manifest.");
|
|
1827
|
+
await validateFontSnapshot(fonts);
|
|
1699
1828
|
stopped.throwIfAborted();
|
|
1700
1829
|
await writeFile(join(request.outputDir, "manifest.json"), `${JSON.stringify(images, null, 2)}\n`, {
|
|
1701
1830
|
flag: "wx",
|
|
@@ -1755,7 +1884,8 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1755
1884
|
async function createConverterFactory(options) {
|
|
1756
1885
|
const { options: resolvedOptions, engine } = await resolveConverter(options);
|
|
1757
1886
|
const shared = {
|
|
1758
|
-
|
|
1887
|
+
snapshots: new FontSnapshotState(),
|
|
1888
|
+
generation: void 0,
|
|
1759
1889
|
fontCache: /* @__PURE__ */ new Map()
|
|
1760
1890
|
};
|
|
1761
1891
|
const converters = /* @__PURE__ */ new Set();
|
|
@@ -1774,7 +1904,8 @@ async function createConverterFactory(options) {
|
|
|
1774
1904
|
converters.clear();
|
|
1775
1905
|
const results = await Promise.allSettled(active.map((converter) => converter.dispose()));
|
|
1776
1906
|
shared.fontCache.clear();
|
|
1777
|
-
shared.
|
|
1907
|
+
shared.snapshots.clear();
|
|
1908
|
+
shared.generation = void 0;
|
|
1778
1909
|
const failures = results.filter((result) => result.status === "rejected");
|
|
1779
1910
|
if (failures.length) throw new AggregateError(failures.map((result) => result.reason), "LibreOffice converter factory disposal failed.");
|
|
1780
1911
|
})();
|
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.
|
|
5
|
+
export declare const ENGINE_VERSION = "0.0.4";
|
|
6
6
|
/** Host diagnostic fields used to identify the runtime glibc version. */
|
|
7
7
|
export interface EngineHostReport {
|
|
8
8
|
readonly header?: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FontFileMetadata } from './fonts.ts';
|
|
2
|
+
import type { ResolvedOptions } from './options.ts';
|
|
3
|
+
type CacheOptions = Pick<ResolvedOptions, 'fontMetadataCacheDirectory' | 'maxFontMetadataCacheBytes'>;
|
|
4
|
+
/** Resolve the platform's user-local cache, independently of font discovery. */
|
|
5
|
+
export declare function defaultFontMetadataCacheDirectory(platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): string;
|
|
6
|
+
/** Read validated records within the configured byte limit; unusable derived data is a cache miss. */
|
|
7
|
+
export declare function readFontMetadataCache(options: CacheOptions): FontFileMetadata[];
|
|
8
|
+
/** Atomically publish a bounded snapshot through a caller-owned unique temporary path. */
|
|
9
|
+
export declare function writeFontMetadataCache(options: CacheOptions, records: readonly FontFileMetadata[], temporaryPath: string): void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=font-metadata-cache.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FontSnapshot } from './font-snapshot.ts';
|
|
2
|
+
import type { FontFileMetadata } from './fonts.ts';
|
|
3
|
+
import type { ResolvedOptions } from './options.ts';
|
|
4
|
+
/** Run one scan outside the event loop and join it before returning or cleaning its temporary file. */
|
|
5
|
+
export declare function runFontSnapshot(options: ResolvedOptions, previous: readonly FontFileMetadata[], signal: AbortSignal): Promise<FontSnapshot>;
|
|
6
|
+
/** Each acquisition refreshes inventory; overlapping acquisitions share only the active scan. */
|
|
7
|
+
export declare class FontSnapshotState {
|
|
8
|
+
private previous;
|
|
9
|
+
private scan;
|
|
10
|
+
/** Revalidate files for an operation without coupling its cancellation to other waiters. */
|
|
11
|
+
acquire(options: ResolvedOptions, signal: AbortSignal): Promise<FontSnapshot>;
|
|
12
|
+
/** Release completed metadata after the owning factory has joined its operations. */
|
|
13
|
+
clear(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=font-snapshot-state.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FontSnapshot } from './font-snapshot.ts';
|
|
2
|
+
/** Reject changed, removed, or replaced sources without exposing local font paths. */
|
|
3
|
+
export declare function validateFontSnapshot(snapshot: FontSnapshot): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=font-snapshot-validation.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FontFileMetadata } from './fonts.ts';
|
|
2
|
+
import type { ResolvedOptions } from './options.ts';
|
|
3
|
+
/** Private input supplied by the shared scan owner. */
|
|
4
|
+
export interface FontSnapshotRequest {
|
|
5
|
+
readonly options: ResolvedOptions;
|
|
6
|
+
readonly previous: readonly FontFileMetadata[];
|
|
7
|
+
readonly temporaryPath?: string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=font-snapshot-worker.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FontFace, FontFileMetadata } from './fonts.ts';
|
|
2
|
+
import type { ResolvedOptions } from './options.ts';
|
|
3
|
+
/** Immutable metadata handed to one operation; generation excludes document-specific matches. */
|
|
4
|
+
export interface FontSnapshot {
|
|
5
|
+
readonly faces: FontFace[];
|
|
6
|
+
readonly records: FontFileMetadata[];
|
|
7
|
+
readonly generation: string;
|
|
8
|
+
}
|
|
9
|
+
/** Re-enumerate all configured sources; only unchanged physical files skip inspection. */
|
|
10
|
+
export declare function scanFontSnapshot(options: ResolvedOptions, previous?: readonly FontFileMetadata[]): FontSnapshot;
|
|
11
|
+
//# sourceMappingURL=font-snapshot.d.ts.map
|
package/lib/types/fonts.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export interface FontFace {
|
|
|
21
21
|
/** Decoded glyph ranges; absent until a match reads this face's coverage. */
|
|
22
22
|
coverage?: GlyphRange[];
|
|
23
23
|
}
|
|
24
|
+
/** All faces decoded from one unchanged physical file, including an empty parse result. */
|
|
25
|
+
export interface FontFileMetadata extends Pick<FontFace, 'path' | 'dev' | 'ino' | 'size' | 'mtimeMs' | 'ctimeMs'> {
|
|
26
|
+
readonly faces: FontFace[];
|
|
27
|
+
}
|
|
24
28
|
/** VCL attributes LibreOffice requests one family for. */
|
|
25
29
|
export interface FontMatchRequest {
|
|
26
30
|
readonly family: string;
|
|
@@ -110,10 +114,12 @@ export declare function faceMetrics(font: Pick<Font, 'OS/2' | 'post'>): {
|
|
|
110
114
|
/**
|
|
111
115
|
* Snapshot eligible local font metadata without retaining font bytes or decoding glyph coverage.
|
|
112
116
|
* @param options - Host font roots and physical file limits.
|
|
113
|
-
* @
|
|
117
|
+
* @param previous - Prior per-file records, reused only after opening and checking the current file.
|
|
118
|
+
* @param observed - Receives successfully read records for this scan, including damaged-font parse results.
|
|
119
|
+
* @returns metadata in discovery order for the current font inventory.
|
|
114
120
|
*/
|
|
115
|
-
export declare function indexSystemFonts(options: FontIndexOptions): FontFace[];
|
|
116
|
-
/** Conversion-local glyph coverage over
|
|
121
|
+
export declare function indexSystemFonts(options: FontIndexOptions, previous?: ReadonlyMap<string, FontFileMetadata>, observed?: Map<string, FontFileMetadata>): FontFace[];
|
|
122
|
+
/** Conversion-local glyph coverage over one operation's metadata snapshot. */
|
|
117
123
|
export declare class SystemFontCatalog {
|
|
118
124
|
private readonly options;
|
|
119
125
|
private readonly faces;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export type { ConversionErrorCode } from './errors.ts';
|
|
|
11
11
|
export { ENGINE_VERSION } from './engine.ts';
|
|
12
12
|
/** Host limits used by both native and Node WASM conversions. All byte limits are positive safe integers. */
|
|
13
13
|
export interface ConverterOptions {
|
|
14
|
+
/** User-local font metadata cache directory. Defaults to the platform cache directory; false disables disk reuse. */
|
|
15
|
+
fontMetadataCacheDirectory?: string | false;
|
|
16
|
+
/** Maximum persisted and reusable per-file metadata bytes. Default: 32 MiB. */
|
|
17
|
+
maxFontMetadataCacheBytes?: number;
|
|
14
18
|
/** Deadline after a queued conversion starts, including font work and output. Default: 120000 ms. */
|
|
15
19
|
timeoutMs?: number;
|
|
16
20
|
/** Maximum source bytes. Default: 64 MiB. */
|
package/lib/types/options.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { ConverterOptions } from './index.ts';
|
|
|
4
4
|
export declare const FONT_FALLBACKS: readonly (readonly string[])[];
|
|
5
5
|
/** Resolved limits and font settings used by every conversion of one converter. */
|
|
6
6
|
export interface ResolvedOptions {
|
|
7
|
+
readonly fontMetadataCacheDirectory: string | false;
|
|
8
|
+
readonly maxFontMetadataCacheBytes: number;
|
|
7
9
|
readonly timeoutMs: number;
|
|
8
10
|
readonly maxInputBytes: number;
|
|
9
11
|
readonly maxOutputBytes: number;
|
package/lib/types/worker.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ConversionSpec } from './operations.ts';
|
|
|
4
4
|
import type { Engine } from './engine.ts';
|
|
5
5
|
import type { FontFace } from './fonts.ts';
|
|
6
6
|
import type { ResolvedOptions } from './options.ts';
|
|
7
|
-
/** Worker input: inspected paths, validated limits, the resolved engine, and
|
|
7
|
+
/** Worker input: inspected paths, validated limits, the resolved engine, and the current font snapshot. */
|
|
8
8
|
export interface WorkerRequest {
|
|
9
9
|
readonly inputPath: string;
|
|
10
10
|
readonly extension: string;
|
|
@@ -12,8 +12,8 @@ export interface WorkerRequest {
|
|
|
12
12
|
readonly options: ResolvedOptions;
|
|
13
13
|
readonly engine: Engine;
|
|
14
14
|
readonly scratch: string;
|
|
15
|
-
/** Faces the
|
|
16
|
-
readonly fontFaces
|
|
15
|
+
/** Faces the caller's font snapshot revalidated for this conversion. */
|
|
16
|
+
readonly fontFaces: FontFace[];
|
|
17
17
|
readonly fontCache?: FontResolutionCacheEntry[] | undefined;
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=worker.d.ts.map
|