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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/NOTICE +240 -0
  2. package/README.md +43 -47
  3. package/README.zh.md +35 -50
  4. package/assets/font-subset.json +70 -0
  5. package/assets/font-subset.wasm +0 -0
  6. package/lib/browser/assets.json +10 -0
  7. package/lib/browser/index.js +442 -0
  8. package/lib/browser/types/connection.d.ts +20 -0
  9. package/lib/browser/types/engine-rendering.d.ts +3 -0
  10. package/lib/browser/types/engine-types.d.ts +17 -0
  11. package/lib/browser/types/font-channel.d.ts +20 -0
  12. package/lib/browser/types/index.d.ts +13 -0
  13. package/lib/browser/types/office-engine.d.ts +46 -0
  14. package/lib/browser/types/office-types.d.ts +107 -0
  15. package/lib/browser/types/office.d.ts +4 -0
  16. package/lib/browser/types/protocol.d.ts +109 -0
  17. package/lib/browser/types/rendering.d.ts +4 -0
  18. package/lib/browser/types/types.d.ts +92 -0
  19. package/lib/browser/types/worker.d.ts +2 -0
  20. package/lib/browser/worker.js +3498 -0
  21. package/lib/browser-assets.js +119 -0
  22. package/lib/cli.js +1336 -0
  23. package/lib/document.js +178 -0
  24. package/lib/engine-rendering.js +120 -0
  25. package/lib/font-config.js +46 -0
  26. package/lib/font-source.js +377 -0
  27. package/lib/font-worker.js +1383 -0
  28. package/lib/index.js +408 -165
  29. package/lib/rendering.js +99 -0
  30. package/lib/sheet-geometry.js +111 -0
  31. package/lib/types/browser-assets.d.ts +15 -0
  32. package/lib/types/cli.d.ts +3 -0
  33. package/lib/types/default-fonts.d.ts +3 -0
  34. package/lib/types/document.d.ts +1 -1
  35. package/lib/types/engine-rendering.d.ts +15 -0
  36. package/lib/types/engine.d.ts +5 -5
  37. package/lib/types/font-config.d.ts +24 -0
  38. package/lib/types/font-full.d.ts +13 -0
  39. package/lib/types/font-loader.d.ts +1 -7
  40. package/lib/types/font-preferences-data.d.ts +16 -0
  41. package/lib/types/font-preferences.d.ts +29 -0
  42. package/lib/types/font-request.d.ts +12 -0
  43. package/lib/types/font-source-types.d.ts +84 -0
  44. package/lib/types/font-source.d.ts +10 -0
  45. package/lib/types/font-subsets.d.ts +35 -0
  46. package/lib/types/font-worker.d.ts +2 -0
  47. package/lib/types/fonts.d.ts +20 -37
  48. package/lib/types/harfbuzz-subset.d.ts +11 -0
  49. package/lib/types/image-operations.d.ts +58 -0
  50. package/lib/types/image-renderer.d.ts +6 -0
  51. package/lib/types/index.d.ts +25 -2
  52. package/lib/types/native.d.ts +4 -2
  53. package/lib/types/operations.d.ts +41 -0
  54. package/lib/types/options.d.ts +1 -1
  55. package/lib/types/png.d.ts +2 -0
  56. package/lib/types/profile.d.ts +8 -0
  57. package/lib/types/rendering.d.ts +41 -0
  58. package/lib/types/runtime.d.ts +14 -0
  59. package/lib/types/sheet-geometry.d.ts +38 -0
  60. package/lib/types/unicode-scripts.d.ts +18 -0
  61. package/lib/types/wasm.d.ts +76 -1
  62. package/lib/types/worker.d.ts +3 -0
  63. package/lib/worker.js +1716 -271
  64. package/licenses/font-subset/harfbuzz-COPYING +42 -0
  65. package/licenses/font-subset/harfbuzzjs-LICENSE +19 -0
  66. package/licenses/javascript/fflate-LICENSE +21 -0
  67. package/licenses/javascript/saxes-LICENSE +64 -0
  68. package/licenses/javascript/xmlchars-LICENSE +18 -0
  69. package/package.json +59 -12
  70. package/sources/browser/packages/browser/package.json +22 -0
  71. package/sources/browser/packages/browser/src/connection.ts +166 -0
  72. package/sources/browser/packages/browser/src/engine-rendering.ts +2 -0
  73. package/sources/browser/packages/browser/src/engine-types.ts +14 -0
  74. package/sources/browser/packages/browser/src/font-channel.ts +99 -0
  75. package/sources/browser/packages/browser/src/index.ts +39 -0
  76. package/sources/browser/packages/browser/src/office-engine.ts +299 -0
  77. package/sources/browser/packages/browser/src/office-types.ts +77 -0
  78. package/sources/browser/packages/browser/src/office.ts +62 -0
  79. package/sources/browser/packages/browser/src/protocol.ts +39 -0
  80. package/sources/browser/packages/browser/src/rendering.ts +3 -0
  81. package/sources/browser/packages/browser/src/types.ts +94 -0
  82. package/sources/browser/packages/browser/src/worker.ts +166 -0
  83. package/sources/browser/packages/browser/tsconfig.json +5 -0
  84. package/sources/browser/packages/browser/tsdown.config.ts +7 -0
  85. package/sources/browser/scripts/build-browser.mjs +82 -0
  86. package/sources/font-subset/engine/font-subset/README.md +23 -0
  87. package/sources/font-subset/engine/font-subset/README.zh.md +23 -0
  88. package/sources/font-subset/engine/font-subset/source.json +16 -0
  89. package/sources/font-subset/harfbuzzjs/config-override-subset.h +7 -0
  90. package/sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols +34 -0
  91. package/sources/font-subset/scripts/build-font-subset.mjs +64 -0
  92. package/sources/font-subset/scripts/pack-utils.mjs +69 -0
  93. package/sources/font-subset/scripts/platform-matrix.mjs +100 -0
  94. package/sources/font-subset/scripts/verify-artifacts.mjs +260 -0
@@ -0,0 +1,99 @@
1
+ //#region lib/types/rendering.js
2
+ const TWIPS_PER_CSS_PIXEL = 15;
3
+ const MAX_TILE_PIXELS = 16777216;
4
+ /** Split a region on its output-pixel grid, bounding the plan before allocating it. */
5
+ function splitRasterRectangle(rectangle, scale, limits) {
6
+ const { x, y, width, height } = rectangle;
7
+ const { maxPixels, maxDimension, maxTiles } = limits;
8
+ if (![
9
+ x,
10
+ y,
11
+ width,
12
+ height,
13
+ scale
14
+ ].every(Number.isFinite) || x < 0 || y < 0 || width <= 0 || height <= 0 || scale <= 0 || !Number.isSafeInteger(maxPixels) || maxPixels < 1 || maxPixels > 16777216 || !Number.isSafeInteger(maxDimension) || maxDimension < 1 || maxDimension > 16777216 || !Number.isSafeInteger(maxTiles) || maxTiles < 0) throw new TypeError("Invalid raster splitting limits or rectangle.");
15
+ const pixelWidth = Math.ceil(width * scale - 1e-9), pixelHeight = Math.ceil(height * scale - 1e-9);
16
+ if (![pixelWidth, pixelHeight].every((value) => Number.isSafeInteger(value) && value > 0)) throw new RangeError("Raster dimensions exceed the coordinate range.");
17
+ let tileWidth = Math.min(pixelWidth, maxDimension), tileHeight = Math.min(pixelHeight, maxDimension);
18
+ if (tileWidth * tileHeight > maxPixels) {
19
+ const side = Math.floor(Math.sqrt(maxPixels));
20
+ if (tileWidth <= side) tileHeight = Math.floor(maxPixels / tileWidth);
21
+ else if (tileHeight <= side) tileWidth = Math.floor(maxPixels / tileHeight);
22
+ else {
23
+ tileWidth = side;
24
+ tileHeight = Math.min(tileHeight, Math.floor(maxPixels / tileWidth));
25
+ }
26
+ }
27
+ const columns = Math.ceil(pixelWidth / tileWidth), rows = Math.ceil(pixelHeight / tileHeight);
28
+ if (columns * rows > maxTiles) throw new RangeError("Raster batch exceeds maxPages after worksheet splitting.");
29
+ const result = [];
30
+ for (let row = 0; row < rows; row++) for (let column = 0; column < columns; column++) {
31
+ const left = column * tileWidth / scale, top = row * tileHeight / scale;
32
+ result.push({
33
+ x: x + left,
34
+ y: y + top,
35
+ width: Math.min(tileWidth / scale, width - left),
36
+ height: Math.min(tileHeight / scale, height - top)
37
+ });
38
+ }
39
+ return result;
40
+ }
41
+ /** Writer's zero-area parity placeholders have no visible page. Offsets stay in twips. */
42
+ function writerPages(rectangles) {
43
+ const pages = rectangles.split(";").filter((value) => value.trim()).flatMap((rectangle) => {
44
+ const fields = rectangle.split(",").map((value) => Number(value.trim()));
45
+ const [x, y, width, height] = fields;
46
+ if (fields.length !== 4 || x === void 0 || y === void 0 || width === void 0 || height === void 0 || fields.some((value) => !Number.isSafeInteger(value) || value < 0 || value > 2147483647) || width === 0 !== (height === 0) || x + width > 2147483647 || y + height > 2147483647) throw new Error("LibreOffice returned invalid page rectangles.");
47
+ return width === 0 ? [] : [{
48
+ x,
49
+ y,
50
+ width: width / 15,
51
+ height: height / 15,
52
+ part: -1
53
+ }];
54
+ });
55
+ if (pages.length === 0) throw new Error("LibreOffice returned no document pages.");
56
+ return pages;
57
+ }
58
+ /** Validate coordinates before allocation or wasm32 integer conversion. */
59
+ function tileDimensions(request, pages) {
60
+ const page = pages[request.pageIndex];
61
+ if (!Number.isSafeInteger(request.pageIndex) || !page || ![
62
+ request.x,
63
+ request.y,
64
+ request.width,
65
+ request.height,
66
+ request.scale
67
+ ].every(Number.isFinite) || request.x < 0 || request.y < 0 || request.width <= 0 || request.height <= 0 || request.scale <= 0 || request.x + request.width > page.width + .001 || request.y + request.height > page.height + .001) throw new Error("Tile rectangle lies outside its page.");
68
+ const width = Math.ceil(request.width * request.scale - 1e-9);
69
+ const height = Math.ceil(request.height * request.scale - 1e-9);
70
+ if (width <= 0 || height <= 0 || !Number.isSafeInteger(width * height) || width * height > 16777216) throw new Error("Tile exceeds the 16 megapixel allocation limit.");
71
+ const twips = [
72
+ page.x + Math.round(request.x * 15),
73
+ page.y + Math.round(request.y * 15),
74
+ Math.round(request.width * 15),
75
+ Math.round(request.height * 15)
76
+ ];
77
+ if (twips.some((value) => !Number.isSafeInteger(value) || value < 0 || value > 2147483647) || twips[0] + twips[2] > 2147483647 || twips[1] + twips[3] > 2147483647) throw new Error("Tile coordinates exceed the wasm32 range.");
78
+ return {
79
+ page,
80
+ width,
81
+ height
82
+ };
83
+ }
84
+ /** Cairo/LO channels are premultiplied; PNG and ImageData require straight RGBA. */
85
+ function rgbaPixels(source, tileMode) {
86
+ if (tileMode !== 0 && tileMode !== 1 || source.length % 4 !== 0) throw new Error("LibreOffice returned an unsupported tile pixel format.");
87
+ const result = new Uint8ClampedArray(source.length);
88
+ for (let index = 0; index < source.length; index += 4) {
89
+ const alpha = source[index + 3];
90
+ const multiplier = alpha === 0 ? 0 : 255 / alpha;
91
+ result[index] = source[index + (tileMode === 1 ? 2 : 0)] * multiplier;
92
+ result[index + 1] = source[index + 1] * multiplier;
93
+ result[index + 2] = source[index + (tileMode === 1 ? 0 : 2)] * multiplier;
94
+ result[index + 3] = alpha;
95
+ }
96
+ return result;
97
+ }
98
+ //#endregion
99
+ export { MAX_TILE_PIXELS, TWIPS_PER_CSS_PIXEL, rgbaPixels, splitRasterRectangle, tileDimensions, writerPages };
@@ -0,0 +1,111 @@
1
+ //#region lib/types/sheet-geometry.js
2
+ const MAX_COLUMN = 16383;
3
+ const MAX_ROW = 1048575;
4
+ function column(index) {
5
+ let name = "";
6
+ for (let value = index + 1; value > 0; value = Math.floor((value - 1) / 26)) name = String.fromCharCode(65 + (value - 1) % 26) + name;
7
+ return name;
8
+ }
9
+ function rangeName(range) {
10
+ return `${column(range.firstColumn)}${range.firstRow + 1}:${column(range.lastColumn)}${range.lastRow + 1}`;
11
+ }
12
+ function parseCellRange(value) {
13
+ const match = /^\$?([A-Z]{1,3})\$?([1-9]\d{0,6})(?::\$?([A-Z]{1,3})\$?([1-9]\d{0,6}))?$/i.exec(value);
14
+ if (!match) throw new TypeError("range must be an A1 cell or rectangle without a sheet prefix.");
15
+ const col = (name) => [...name.toUpperCase()].reduce((sum, c) => sum * 26 + c.charCodeAt(0) - 64, 0) - 1;
16
+ const firstColumn = col(match[1]);
17
+ const firstRow = Number(match[2]) - 1;
18
+ const lastColumn = col(match[3] ?? match[1]);
19
+ const lastRow = Number(match[4] ?? match[2]) - 1;
20
+ if (lastColumn < firstColumn || lastRow < firstRow || lastColumn > MAX_COLUMN || lastRow > MAX_ROW) throw new TypeError("range exceeds Calc worksheet bounds or has reversed endpoints.");
21
+ return {
22
+ firstColumn,
23
+ firstRow,
24
+ lastColumn,
25
+ lastRow
26
+ };
27
+ }
28
+ function sheetPartInfo(value) {
29
+ const info = JSON.parse(value);
30
+ if (!info || typeof info.name !== "string" || ![0, 1].includes(info.visible) || ![0, 1].includes(info.rtllayout) || !Number.isInteger(info.lastcolumn) || !Number.isInteger(info.lastrow) || info.lastcolumn < 0 || info.lastrow < 0 || info.lastcolumn > MAX_COLUMN || info.lastrow > MAX_ROW) throw new Error("LibreOffice returned invalid worksheet data-area metadata.");
31
+ return info;
32
+ }
33
+ /** Formatting-only cells and standalone drawings do not enlarge LibreOffice's data area. */
34
+ function dataArea(info) {
35
+ return {
36
+ firstColumn: 0,
37
+ firstRow: 0,
38
+ lastColumn: info.lastcolumn,
39
+ lastRow: info.lastrow
40
+ };
41
+ }
42
+ function spans(encoded, flags, maximum) {
43
+ if (typeof encoded !== "string" || encoded.length > 33554432) throw new Error("Invalid worksheet geometry span encoding.");
44
+ const tokens = encoded.trim().split(/\s+/);
45
+ let previous = -1;
46
+ let flag = 0;
47
+ const result = tokens.map((token, i) => {
48
+ const fields = token.split(":");
49
+ let value;
50
+ let end;
51
+ if (flags && i > 0) {
52
+ value = flag = 1 - flag;
53
+ end = Number(fields[0]);
54
+ if (fields.length !== 1) throw new Error("Invalid worksheet flag span.");
55
+ } else {
56
+ value = Number(fields[0]);
57
+ end = Number(fields[1]);
58
+ flag = value;
59
+ if (fields.length !== 2) throw new Error("Invalid worksheet size span.");
60
+ }
61
+ if (!Number.isSafeInteger(value) || value < 0 || (flags ? value > 1 : value > 65535) || !Number.isSafeInteger(end) || end <= previous || end > maximum) throw new Error("Invalid worksheet geometry span.");
62
+ previous = end;
63
+ return {
64
+ end,
65
+ value
66
+ };
67
+ });
68
+ if (previous !== maximum) throw new Error("Worksheet geometry does not cover the complete dimension.");
69
+ return result;
70
+ }
71
+ function dimension(data, first, last, maximum, scale) {
72
+ const sizes = spans(data?.sizes, false, maximum);
73
+ const hidden = spans(data?.hidden, true, maximum);
74
+ const filtered = spans(data?.filtered, true, maximum);
75
+ let position = 0, start = 0, index = 0, si = 0, hi = 0, fi = 0;
76
+ while (index <= last) {
77
+ const size = sizes[si], hide = hidden[hi], filter = filtered[fi];
78
+ const end = Math.min(size.end, hide.end, filter.end, last, index < first ? first - 1 : last);
79
+ const pixels = hide.value || filter.value || size.value === 0 ? 0 : Math.max(1, Math.floor(size.value * scale / 15));
80
+ if (index === first) start = position;
81
+ position += (end - index + 1) * pixels;
82
+ index = end + 1;
83
+ if (index > size.end) si++;
84
+ if (index > hide.end) hi++;
85
+ if (index > filter.end) fi++;
86
+ }
87
+ return [start / scale, (position - start) / scale];
88
+ }
89
+ /** Logical columns advance from A; LOK itself mirrors RTL sheet painting. No manual x inversion. */
90
+ function sheetRangeRectangle(geometry, range, scale) {
91
+ if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
92
+ const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
93
+ const [y, height] = dimension(geometry.rows, range.firstRow, range.lastRow, MAX_ROW, scale);
94
+ if (width <= 0 || height <= 0) throw new Error("The selected worksheet range is entirely hidden or filtered.");
95
+ if ([
96
+ x,
97
+ y,
98
+ width,
99
+ height,
100
+ x + width,
101
+ y + height
102
+ ].some((value) => !Number.isFinite(value) || value * 15 > 2147483647)) throw new Error("The selected worksheet range exceeds the supported coordinate range.");
103
+ return {
104
+ x,
105
+ y,
106
+ width,
107
+ height
108
+ };
109
+ }
110
+ //#endregion
111
+ export { dataArea, parseCellRange, rangeName, sheetPartInfo, sheetRangeRectangle };
@@ -0,0 +1,15 @@
1
+ /** A validated local resource. Servers should expose opaque URLs, not these filesystem paths. */
2
+ export interface BrowserAsset {
3
+ readonly path: string;
4
+ readonly bytes: number;
5
+ readonly sha256: string;
6
+ }
7
+ /** Exactly the resources consumed by the browser transport. */
8
+ export interface BrowserAssets {
9
+ readonly schemaVersion: 1;
10
+ readonly programDirectory: string;
11
+ readonly files: Readonly<Record<'worker' | 'loader' | 'wasm' | 'data' | 'metadata', BrowserAsset>>;
12
+ }
13
+ /** Validate package identity, resource paths, sizes, and hashes once for this immutable installation. */
14
+ export declare function resolveBrowserAssets(): Promise<BrowserAssets>;
15
+ //# sourceMappingURL=browser-assets.d.ts.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Ordered family groups used when the caller supplies none. */
2
+ export declare const DEFAULT_FONT_FALLBACKS: readonly (readonly string[])[];
3
+ //# sourceMappingURL=default-fonts.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import type { DocumentFontMetadata } from './ooxml.ts';
2
2
  import type { ResolvedOptions } from './options.ts';
3
3
  /** Input suffixes accepted by the public converter. */
4
- export declare const DOCUMENT_EXTENSIONS: readonly ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
4
+ export declare const DOCUMENT_EXTENSIONS: readonly ["doc", "docx", "odt", "xls", "xlsx", "ods", "ppt", "pptx", "odp"];
5
5
  /**
6
6
  * Inspect the input container before invoking LibreOffice's document importer.
7
7
  * Compound-file streams and legacy font tables are interpreted by LibreOffice;
@@ -0,0 +1,15 @@
1
+ /** Shared bounded raster allocations for browser and Node engine owners. */
2
+ import { type EnginePage, type RasterTile, type TileRequest } from './rendering.ts';
3
+ export interface RasterModule {
4
+ readonly HEAPU32: Uint32Array;
5
+ ccall(name: string, returnType: string | null, argTypes: string[], args: unknown[]): number;
6
+ UTF8ToString(pointer: number): string;
7
+ }
8
+ export declare function numericCall(module: RasterModule, name: string, args: number[]): number;
9
+ /** Copy/free one engine-owned UTF-8 return value. */
10
+ export declare function engineString(module: RasterModule, name: string, types: string[], args: unknown[], failure: () => Error): string;
11
+ /** Paint into a temporary allocation; copy pixels before free or another engine call. */
12
+ export declare function renderRegion(module: RasterModule, document: number, request: TileRequest, pages: readonly EnginePage[], failure: () => Error, pdf?: boolean): RasterTile;
13
+ /** PDF page dimensions use the same twips ABI, with an immutable PDF page index as part. */
14
+ export declare function pdfPages(module: RasterModule, pdf: number, failure: () => Error): EnginePage[];
15
+ //# sourceMappingURL=engine-rendering.d.ts.map
@@ -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.1";
5
+ export declare const ENGINE_VERSION = "0.0.2-rc5";
6
6
  /** Host diagnostic fields used to identify the runtime glibc version. */
7
7
  export interface EngineHostReport {
8
8
  readonly header?: {
@@ -56,12 +56,12 @@ export declare function installedPackageExists(name: string): boolean;
56
56
  */
57
57
  export declare function platformTarget(platform?: string, arch?: string, report?: () => EngineHostReport): string | undefined;
58
58
  /**
59
- * macOS and Windows require their native engine. Linux uses WASM when no compatible development native engine is installed.
59
+ * Resolve the shared WASM engine on every supported operating system.
60
60
  * @param resolvePackage - Package manifest resolver; injectable for selection tests.
61
- * @param packageExists - Installed-package probe; injectable for selection tests.
61
+ * @param _packageExists - Retained positional compatibility with earlier resolvers.
62
62
  * @param host - Process identification and diagnostic report.
63
- * @returns the installed native engine, or the installed WASM engine.
63
+ * @returns the installed WASM engine; native packages never change selection.
64
64
  */
65
- export declare function resolveEngine(resolvePackage?: (name: string) => string, packageExists?: (name: string) => boolean, { platform, arch, report }?: EngineResolutionHost): Promise<Engine>;
65
+ export declare function resolveEngine(resolvePackage?: (name: string) => string, _packageExists?: (name: string) => boolean, { platform, arch }?: EngineResolutionHost): Promise<Engine>;
66
66
  export {};
67
67
  //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1,24 @@
1
+ /** Browser-safe family ordering and Fontconfig XML shared by both WASM adapters. */
2
+ /**
3
+ * Case- and separator-insensitive family key used to compare names across sources.
4
+ * @param value - Family, style, or postscript name as recorded by a document or font.
5
+ * @returns The normalized key.
6
+ */
7
+ export declare function normalize(value: string): string;
8
+ /**
9
+ * Order named substitutions and their generic text family without excluding unlisted fonts.
10
+ * @param requested - Original family names, in document order.
11
+ * @param groups - Ordered family groups shared with Fontconfig aliases.
12
+ * @param pitch - VCL pitch; one requests a monospaced fallback.
13
+ * @param symbols - Whether symbol alternatives precede the generic fallback.
14
+ * @returns distinct family names, with original requests first.
15
+ */
16
+ export declare function fontFamilyPriority(requested: readonly string[], groups: readonly (readonly string[])[], pitch?: number, symbols?: boolean): string[];
17
+ /**
18
+ * Fontconfig XML restricts WASM discovery to imported originals in MEMFS.
19
+ * @param families - Ordered family groups; the first name of each group is its canonical spelling.
20
+ * @param requested - Additional family names the document declared.
21
+ * @returns the fontconfig document written into the module's memory filesystem.
22
+ */
23
+ export declare function memoryFontConfig(families: readonly (readonly string[])[], requested?: Iterable<string>): string;
24
+ //# sourceMappingURL=font-config.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { type FontFace } from './fonts.ts';
2
+ import type { ResolvedOptions } from './options.ts';
3
+ export type FontFileFormat = 'ttf' | 'otf' | 'ttc';
4
+ export declare function fontFileFormat(bytes: Uint8Array): FontFileFormat;
5
+ /** Keep full names, encoding tables and glyphs. Apple dfont containers expose one complete sfnt resource. */
6
+ export declare function fullFontFile(face: FontFace): {
7
+ bytes: Uint8Array;
8
+ sourceHash: string;
9
+ format: FontFileFormat;
10
+ };
11
+ /** Mount a fixed bounded set before PDFium performs its first installed-font enumeration. */
12
+ export declare function preloadPdfFonts(options: ResolvedOptions, faces: readonly FontFace[], install: (name: string, bytes: Uint8Array) => void): void;
13
+ //# sourceMappingURL=font-full.d.ts.map
@@ -32,11 +32,5 @@ export type FontInstaller = (name: string, bytes: Buffer) => string;
32
32
  export declare function createFontLoader(options: ResolvedOptions, document: DocumentFontMetadata, install: FontInstaller, faces: readonly FontFace[]): FontLoader;
33
33
  /** Supply native imports and seed WASM's first usable default font. */
34
34
  export declare function preloadFonts(loader: FontLoader, options: ResolvedOptions, document: DocumentFontMetadata, native?: boolean): void;
35
- /**
36
- * Fontconfig XML restricts WASM discovery to imported originals in MEMFS.
37
- * @param families - Ordered family groups; the first name of each group is its canonical spelling.
38
- * @param requested - Additional family names the document declared.
39
- * @returns the fontconfig document written into the module's memory filesystem.
40
- */
41
- export declare function memoryFontConfig(families: readonly (readonly string[])[], requested?: Iterable<string>): string;
35
+ export { memoryFontConfig } from './font-config.ts';
42
36
  //# sourceMappingURL=font-loader.d.ts.map
@@ -0,0 +1,16 @@
1
+ /** Generated by scripts/generate-font-preferences.mjs; do not edit.
2
+ + * Chromium: https://raw.githubusercontent.com/chromium/chromium/ffaf825e8c2e27fccc089b425f9f114d275804ae/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
3
+ + * Fontconfig: https://raw.githubusercontent.com/fontconfig/fontconfig/84ae86bc21c94d4aedbc02e32c9dc18b8750193c/conf.d/65-nonlatin.conf
4
+ + * Unicode: @unicode/unicode-17.0.0 2.0.7. Licenses: packages/entry/NOTICE.
5
+ + */
6
+ /** Pinned windows fonts. */
7
+ export declare const WINDOWS_FONTS: Readonly<Record<string, readonly string[]>>;
8
+ /** Pinned fontconfig fonts. */
9
+ export declare const FONTCONFIG_FONTS: Readonly<Record<string, readonly string[]>>;
10
+ /** Pinned script names. */
11
+ export declare const SCRIPT_NAMES: readonly string[];
12
+ /** Pinned script ranges. */
13
+ export declare const SCRIPT_RANGES: readonly (readonly [number, number, number])[];
14
+ /** Pinned script extensions. */
15
+ export declare const SCRIPT_EXTENSIONS: readonly (readonly [number, number, number])[];
16
+ //# sourceMappingURL=font-preferences-data.d.ts.map
@@ -0,0 +1,29 @@
1
+ import type { FontMatchRequest } from './font-request.ts';
2
+ /**
3
+ * Partition missing scalars by Unicode 17; shared marks follow a compatible script when present.
4
+ * @param points - Missing scalars, in engine order.
5
+ * @returns stable script groups without splitting Script_Extensions marks from their base.
6
+ */
7
+ export declare function fontScriptGroups(points: readonly number[]): Map<string, number[]>;
8
+ /**
9
+ * Recognize CJK regional font names, including platform families without a region suffix.
10
+ * @param family - Family or alias.
11
+ * @returns Noto region key, when the family identifies a regional design.
12
+ */
13
+ export declare function fontRegion(family: string): string | undefined;
14
+ /**
15
+ * Separate explicit aliases from generic fallback so script preferences cannot override user intent.
16
+ * @param request - VCL request.
17
+ * @param groups - Configured named and generic aliases.
18
+ * @param script - Current Unicode script.
19
+ * @param scripts - Other scripts in this same request.
20
+ * @param platform - Host OS owning the font catalog.
21
+ * @returns explicit names, ordered body candidates, regional preference and decorative policy.
22
+ */
23
+ export declare function fontPreferences(request: FontMatchRequest, groups: readonly (readonly string[])[], script: string, scripts: Iterable<string>, platform?: string): {
24
+ explicit: string[];
25
+ candidates: string[];
26
+ region: string | undefined;
27
+ penalizeDecorative: boolean;
28
+ };
29
+ //# sourceMappingURL=font-preferences.d.ts.map
@@ -0,0 +1,12 @@
1
+ /** VCL attributes LibreOffice requests one family for. */
2
+ export interface FontMatchRequest {
3
+ readonly family: string;
4
+ readonly style: string;
5
+ readonly weight: number;
6
+ readonly italic: number;
7
+ readonly width: number;
8
+ readonly pitch: number;
9
+ readonly language: string;
10
+ readonly codePoints: readonly number[];
11
+ }
12
+ //# sourceMappingURL=font-request.d.ts.map
@@ -0,0 +1,84 @@
1
+ /** Installed font files exposed without disclosing Host filesystem paths. */
2
+ import type { FontMatchRequest } from './font-request.ts';
3
+ export type { FontMatchRequest } from './font-request.ts';
4
+ /** Full mode preserves font names, encoding and all glyphs for PDFium. */
5
+ export interface FontResolveRequest extends FontMatchRequest {
6
+ readonly mode?: 'subset' | 'full';
7
+ }
8
+ /** Content identity of one deterministic physical-face Unicode-script subset. */
9
+ export type FontAssetId = string & {
10
+ readonly __fontAssetId: unique symbol;
11
+ };
12
+ /** A matched file available through the same font source lifetime. */
13
+ export interface FontAsset {
14
+ readonly id: FontAssetId;
15
+ readonly bytes: number;
16
+ readonly family: string;
17
+ /** Browser-only VCL identity distinguishing subsets with the same original family/style. */
18
+ readonly alias: string;
19
+ /** Full assets preserve original names; subset remains the default. */
20
+ readonly mode?: 'full';
21
+ readonly format?: 'ttf' | 'otf' | 'ttc';
22
+ }
23
+ /** Matched font subsets and an unavailable requested family, when applicable. */
24
+ export interface FontResolution {
25
+ readonly fonts: readonly FontAsset[];
26
+ readonly missingFamily?: string;
27
+ /** Scalars no installed font covers; distinct from a successfully substituted family. */
28
+ readonly unresolvedCodePoints?: readonly number[];
29
+ }
30
+ /** Font discovery limits; omitted values use the Node converter's font defaults. */
31
+ export interface FontSourceOptions {
32
+ readonly fontDirectories?: readonly string[];
33
+ readonly fontFallbacks?: readonly (readonly string[])[];
34
+ readonly maxFontFiles?: number;
35
+ readonly maxFontFileBytes?: number;
36
+ /** Retained subset bytes in the font Worker; defaults to 128 MiB. */
37
+ readonly maxCachedSubsetBytes?: number;
38
+ }
39
+ /** One lazily indexed Host font catalog with all CPU and file work in its Worker. */
40
+ export interface FontSource {
41
+ /** Resolved ordered font family preferences shared with browser Fontconfig. */
42
+ readonly fontFallbacks: readonly (readonly string[])[];
43
+ /**
44
+ * Select deterministic Unicode-script subsets using LibreOffice's requested attributes.
45
+ * @param request - Family, style, language, and required Unicode scalars.
46
+ * @param signal - Checked before dispatch and before publishing the result.
47
+ * @returns subset content identities with no Host paths.
48
+ */
49
+ resolve(request: FontResolveRequest, signal?: AbortSignal): Promise<FontResolution>;
50
+ /**
51
+ * Read or regenerate a selected subset while its original font remains unchanged.
52
+ * @param id - Identity returned by resolve in this source lifetime.
53
+ * @param signal - Checked before dispatch and before publishing the result.
54
+ * @returns caller-owned subset sfnt bytes; changed or unknown files reject.
55
+ */
56
+ read(id: FontAssetId, signal?: AbortSignal): Promise<Uint8Array>;
57
+ /** Stop pending work, terminate the Worker, and await its exit. */
58
+ dispose(): Promise<void>;
59
+ }
60
+ /** Parent-to-worker operations; neither message contains a caller-selected file path. */
61
+ export type FontCommand = {
62
+ readonly id: number;
63
+ readonly kind: 'resolve';
64
+ readonly request: FontResolveRequest;
65
+ } | {
66
+ readonly id: number;
67
+ readonly kind: 'read';
68
+ readonly asset: FontAssetId;
69
+ };
70
+ /** Worker replies retain their operation discriminator across structured cloning. */
71
+ export type FontReply = {
72
+ readonly id: number;
73
+ readonly kind: 'resolved';
74
+ readonly value: FontResolution;
75
+ } | {
76
+ readonly id: number;
77
+ readonly kind: 'bytes';
78
+ readonly value: Uint8Array;
79
+ } | {
80
+ readonly id: number;
81
+ readonly kind: 'failed';
82
+ readonly message: string;
83
+ };
84
+ //# sourceMappingURL=font-source-types.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { FontSource, FontSourceOptions } from './font-source-types.ts';
2
+ export type { FontAsset, FontAssetId, FontMatchRequest, FontResolveRequest, FontResolution, FontSource, FontSourceOptions } from './font-source-types.ts';
3
+ /**
4
+ * Create a font catalog without loading a LibreOffice engine or reading fonts yet.
5
+ * @param options - Font directories, fallback groups, and discovery limits.
6
+ * @returns a source whose first operation starts its private Worker. Cancellation
7
+ * discards a result after dispatched work settles; dispose terminates all work.
8
+ */
9
+ export declare function createFontSource(options?: FontSourceOptions): FontSource;
10
+ //# sourceMappingURL=font-source.d.ts.map
@@ -0,0 +1,35 @@
1
+ import type { FontIndexOptions } from './fonts.ts';
2
+ import type { FontAssetId, FontResolution, FontResolveRequest } from './font-source-types.ts';
3
+ /** Source limits and resolved family preferences passed to the private font Worker. */
4
+ export interface FontSubsetOptions extends FontIndexOptions {
5
+ readonly fallbackFamilies: readonly (readonly string[])[];
6
+ readonly maxCachedSubsetBytes: number;
7
+ }
8
+ /** One Worker-owned font index and LRU whose byte budget excludes transient subsetting input/output. */
9
+ export declare class FontSubsetSource {
10
+ private readonly options;
11
+ private snapshot;
12
+ private catalog;
13
+ private readonly selected;
14
+ private readonly partitions;
15
+ private readonly cached;
16
+ private cachedBytes;
17
+ /** @param options - Resolved discovery, fallback, and retained subset limits. */
18
+ constructor(options: FontSubsetOptions);
19
+ private retain;
20
+ private generate;
21
+ private describe;
22
+ /**
23
+ * Refresh installed files and select whole Unicode-script subsets for matching physical faces.
24
+ * @param request - Requested family/style attributes and Unicode scalars.
25
+ * @returns reusable subset identities; unavailable characters remain unresolved.
26
+ */
27
+ resolve(request: FontResolveRequest): Promise<FontResolution>;
28
+ /**
29
+ * Return caller-owned bytes, regenerating an evicted subset from its unchanged original.
30
+ * @param id - Subset identity previously returned by this source.
31
+ * @returns sfnt bytes copied so a Worker transfer cannot detach the retained cache entry.
32
+ */
33
+ read(id: FontAssetId): Promise<Uint8Array<ArrayBuffer>>;
34
+ }
35
+ //# sourceMappingURL=font-subsets.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=font-worker.d.ts.map