@deepseek-ai/libreoffice-kit 0.0.2-rc9 → 0.0.3
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/NOTICE +0 -240
- package/README.md +53 -43
- package/README.zh.md +58 -35
- package/lib/cli.js +725 -132
- package/lib/index.js +757 -133
- package/lib/types/engine.d.ts +5 -5
- package/lib/types/font-loader.d.ts +18 -16
- package/lib/types/fonts.d.ts +38 -21
- package/lib/types/image-operations.d.ts +1 -1
- package/lib/types/index.d.ts +13 -7
- package/lib/types/native-image-renderer.d.ts +19 -0
- package/lib/types/native.d.ts +1 -1
- package/lib/types/options.d.ts +3 -1
- package/lib/types/wasm.d.ts +4 -1
- package/lib/types/worker.d.ts +2 -0
- package/lib/worker.js +420 -942
- package/package.json +13 -55
- package/assets/font-subset.json +0 -70
- package/assets/font-subset.wasm +0 -0
- package/lib/browser/assets.json +0 -10
- package/lib/browser/index.js +0 -626
- package/lib/browser/types/connection.d.ts +0 -42
- package/lib/browser/types/engine-rendering.d.ts +0 -3
- package/lib/browser/types/engine-types.d.ts +0 -17
- package/lib/browser/types/font-channel.d.ts +0 -36
- package/lib/browser/types/index.d.ts +0 -14
- package/lib/browser/types/office-engine.d.ts +0 -56
- package/lib/browser/types/office-types.d.ts +0 -166
- package/lib/browser/types/office.d.ts +0 -19
- package/lib/browser/types/preparation.d.ts +0 -13
- package/lib/browser/types/protocol.d.ts +0 -137
- package/lib/browser/types/rendering.d.ts +0 -4
- package/lib/browser/types/types.d.ts +0 -115
- package/lib/browser/types/worker.d.ts +0 -2
- package/lib/browser/worker.js +0 -3796
- package/lib/browser-assets.js +0 -119
- package/lib/document.js +0 -178
- package/lib/engine-rendering.js +0 -120
- package/lib/font-config.js +0 -46
- package/lib/font-source.js +0 -395
- package/lib/font-worker.js +0 -1481
- package/lib/rendering.js +0 -99
- package/lib/sheet-geometry.js +0 -111
- package/lib/types/browser-assets.d.ts +0 -15
- package/lib/types/default-fonts.d.ts +0 -3
- package/lib/types/font-config.d.ts +0 -24
- package/lib/types/font-preferences-data.d.ts +0 -16
- package/lib/types/font-preferences.d.ts +0 -29
- package/lib/types/font-request.d.ts +0 -12
- package/lib/types/font-source-types.d.ts +0 -95
- package/lib/types/font-source.d.ts +0 -10
- package/lib/types/font-subsets.d.ts +0 -39
- package/lib/types/font-worker.d.ts +0 -2
- package/lib/types/harfbuzz-subset.d.ts +0 -11
- package/lib/types/unicode-scripts.d.ts +0 -18
- package/licenses/font-subset/harfbuzz-COPYING +0 -42
- package/licenses/font-subset/harfbuzzjs-LICENSE +0 -19
- package/licenses/javascript/fflate-LICENSE +0 -21
- package/licenses/javascript/saxes-LICENSE +0 -64
- package/licenses/javascript/xmlchars-LICENSE +0 -18
- package/sources/browser/packages/browser/package.json +0 -22
- package/sources/browser/packages/browser/src/connection.ts +0 -237
- package/sources/browser/packages/browser/src/engine-rendering.ts +0 -2
- package/sources/browser/packages/browser/src/engine-types.ts +0 -14
- package/sources/browser/packages/browser/src/font-channel.ts +0 -169
- package/sources/browser/packages/browser/src/index.ts +0 -40
- package/sources/browser/packages/browser/src/office-engine.ts +0 -397
- package/sources/browser/packages/browser/src/office-types.ts +0 -128
- package/sources/browser/packages/browser/src/office.ts +0 -128
- package/sources/browser/packages/browser/src/preparation.ts +0 -41
- package/sources/browser/packages/browser/src/protocol.ts +0 -55
- package/sources/browser/packages/browser/src/rendering.ts +0 -3
- package/sources/browser/packages/browser/src/types.ts +0 -118
- package/sources/browser/packages/browser/src/worker.ts +0 -260
- package/sources/browser/packages/browser/tsconfig.json +0 -5
- package/sources/browser/packages/browser/tsdown.config.ts +0 -7
- package/sources/browser/scripts/build-browser.mjs +0 -86
- package/sources/font-subset/engine/font-subset/README.md +0 -23
- package/sources/font-subset/engine/font-subset/README.zh.md +0 -23
- package/sources/font-subset/engine/font-subset/source.json +0 -16
- package/sources/font-subset/harfbuzzjs/config-override-subset.h +0 -7
- package/sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols +0 -34
- package/sources/font-subset/scripts/build-font-subset.mjs +0 -64
- package/sources/font-subset/scripts/pack-utils.mjs +0 -69
- package/sources/font-subset/scripts/platform-matrix.mjs +0 -100
- package/sources/font-subset/scripts/verify-artifacts.mjs +0 -260
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/** Browser-side WASM compilation without creating an Office Worker or memory. */
|
|
2
|
-
import { BrowserRenderError } from './types.ts'
|
|
3
|
-
import type { BrowserEngineAssets, PreparedBrowserEngine } from './types.ts'
|
|
4
|
-
|
|
5
|
-
interface PreparedBrowserEngineRecord {
|
|
6
|
-
readonly wasmUrl: string
|
|
7
|
-
readonly module: WebAssembly.Module
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Compile the version-matched LibreOffice WASM module for later document Workers.
|
|
12
|
-
* @param assets - Browser resources whose WASM URL identifies the compiled module.
|
|
13
|
-
* @param signal - Cancels the resource request; compilation may finish before cancellation is observed.
|
|
14
|
-
* @returns an opaque, structured-cloneable engine handle that allocates no WASM memory.
|
|
15
|
-
*/
|
|
16
|
-
export async function prepareOfficeBrowser(assets: BrowserEngineAssets, signal?: AbortSignal): Promise<PreparedBrowserEngine> {
|
|
17
|
-
signal?.throwIfAborted()
|
|
18
|
-
if (typeof WebAssembly.compileStreaming !== 'function') throw new BrowserRenderError('unavailable', 'Streaming WebAssembly compilation is unavailable.')
|
|
19
|
-
const response = await fetch(assets.wasmUrl, { credentials: 'same-origin', ...(signal === undefined ? {} : { signal }) })
|
|
20
|
-
if (!response.ok) throw new BrowserRenderError('unavailable', `LibreOffice WASM request failed: ${response.status}`)
|
|
21
|
-
const module = await WebAssembly.compileStreaming(Promise.resolve(response))
|
|
22
|
-
signal?.throwIfAborted()
|
|
23
|
-
return Object.freeze({ wasmUrl: assets.wasmUrl, module }) as unknown as PreparedBrowserEngine
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Return the compiled module after validating the Worker-bound asset identity. */
|
|
27
|
-
export function preparedBrowserModule(prepared: PreparedBrowserEngine, assets: BrowserEngineAssets): WebAssembly.Module {
|
|
28
|
-
const record = prepared as unknown as PreparedBrowserEngineRecord
|
|
29
|
-
if (record.wasmUrl !== assets.wasmUrl || !(record.module instanceof WebAssembly.Module)) {
|
|
30
|
-
throw new TypeError('The prepared browser engine does not match the requested WASM asset.')
|
|
31
|
-
}
|
|
32
|
-
return record.module
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Instantiate precompiled code through Emscripten's synchronous override. */
|
|
36
|
-
export function instantiatePreparedModule(module: WebAssembly.Module, imports: WebAssembly.Imports,
|
|
37
|
-
receive: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void): WebAssembly.Exports {
|
|
38
|
-
const instance = new WebAssembly.Instance(module, imports)
|
|
39
|
-
receive(instance, module)
|
|
40
|
-
return instance.exports
|
|
41
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/** Private messages exchanged by the document owner and its single engine Worker. */
|
|
2
|
-
import type { BrowserDocumentOptions, BrowserFontIdentity, BrowserFontRequest, BrowserPage, BrowserRenderErrorCode, BrowserRuntimeOptions, BrowserTile, BrowserTileRequest } from './types.ts'
|
|
3
|
-
import type { OfficeDocumentEvent, OfficeDocumentNavigation, OfficeDocumentOptions, OfficeDocumentState, OfficeDocumentPointer, OfficeDocumentLayoutRequest, OfficeDocumentLayoutResult, OfficeDocumentTileRequest, OfficeDocumentRectangle, OfficeReadingState } from './office-types.ts'
|
|
4
|
-
|
|
5
|
-
export const FONT_CHUNK_BYTES = 1024 * 1024
|
|
6
|
-
export const FONT_HEADER_BYTES = 8
|
|
7
|
-
export const enum FontState { Waiting, Header, Bytes, Done, Error, Cancelled }
|
|
8
|
-
/** Engine resources a Worker holds for the lifetime of every document it opens. */
|
|
9
|
-
export type WorkerOptions = Omit<BrowserRuntimeOptions, 'resolveFonts' | 'onMissingFonts'>
|
|
10
|
-
/** Source bytes and reading position of one document opened inside a started Worker. */
|
|
11
|
-
export interface WorkerDocumentOptions {
|
|
12
|
-
readonly data: Uint8Array
|
|
13
|
-
readonly extension: BrowserDocumentOptions['extension'] | OfficeDocumentOptions['extension']
|
|
14
|
-
/** Reading position captured from an earlier open of the same bytes. */
|
|
15
|
-
readonly restore?: OfficeReadingState
|
|
16
|
-
}
|
|
17
|
-
export type OfficeOperation =
|
|
18
|
-
| { readonly type: 'pointer'; readonly event: OfficeDocumentPointer }
|
|
19
|
-
| { readonly type: 'navigate'; readonly event: OfficeDocumentNavigation }
|
|
20
|
-
| { readonly type: 'select-all' }
|
|
21
|
-
| { readonly type: 'cell'; readonly address: string }
|
|
22
|
-
| { readonly type: 'copy' }
|
|
23
|
-
| { readonly type: 'part'; readonly part: number }
|
|
24
|
-
| { readonly type: 'viewport'; readonly rectangle: OfficeDocumentRectangle; readonly scale: number }
|
|
25
|
-
| { readonly type: 'layout'; readonly request: OfficeDocumentLayoutRequest }
|
|
26
|
-
export type OwnerMessage =
|
|
27
|
-
| { readonly type: 'start'; readonly id: number; readonly options: WorkerOptions; readonly channel: SharedArrayBuffer }
|
|
28
|
-
| { readonly type: 'open'; readonly id: number; readonly options: WorkerDocumentOptions }
|
|
29
|
-
| { readonly type: 'close-document'; readonly id: number }
|
|
30
|
-
| { readonly type: 'reading-state'; readonly id: number }
|
|
31
|
-
| { readonly type: 'tile'; readonly id: number; readonly request: BrowserTileRequest }
|
|
32
|
-
| { readonly type: 'office-tile'; readonly id: number; readonly request: OfficeDocumentTileRequest }
|
|
33
|
-
| { readonly type: 'office-operation'; readonly id: number; readonly operation: OfficeOperation }
|
|
34
|
-
| { readonly type: 'dispose'; readonly id: number }
|
|
35
|
-
type WithoutId<T> = T extends unknown ? Omit<T, 'id'> : never
|
|
36
|
-
export type OwnerRequest = WithoutId<OwnerMessage>
|
|
37
|
-
export type WorkerMessage =
|
|
38
|
-
| { readonly type: 'started'; readonly id: number }
|
|
39
|
-
| { readonly type: 'opened'; readonly id: number; readonly pages: readonly BrowserPage[]; readonly office?: OfficeDocumentState }
|
|
40
|
-
| { readonly type: 'closed-document'; readonly id: number }
|
|
41
|
-
| { readonly type: 'reading-state'; readonly id: number; readonly state: OfficeReadingState }
|
|
42
|
-
| { readonly type: 'tile'; readonly id: number; readonly tile: BrowserTile }
|
|
43
|
-
| { readonly type: 'office-result'; readonly id: number; readonly text?: string; readonly layout?: OfficeDocumentLayoutResult }
|
|
44
|
-
| { readonly type: 'office-event'; readonly event: OfficeDocumentEvent }
|
|
45
|
-
| { readonly type: 'disposed'; readonly id: number }
|
|
46
|
-
| { readonly type: 'error'; readonly id: number; readonly code: BrowserRenderErrorCode; readonly message: string; readonly fatal: boolean }
|
|
47
|
-
| { readonly type: 'font'; readonly request: BrowserFontRequest; readonly known: readonly FontIdentity[] }
|
|
48
|
-
| { readonly type: 'font-next' }
|
|
49
|
-
| { readonly type: 'missing-fonts'; readonly families: readonly string[] }
|
|
50
|
-
/** Immutable bytes already installed in this document's MEMFS. */
|
|
51
|
-
export type FontIdentity = BrowserFontIdentity
|
|
52
|
-
export interface FontHeader {
|
|
53
|
-
readonly fonts: readonly (FontIdentity & { readonly family: string; readonly alias: string; readonly reference?: true })[]
|
|
54
|
-
readonly missingFamily?: string
|
|
55
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/** Geometry and RGBA conversion shared by every WASM consumer. */
|
|
2
|
-
export { writerPages, tileDimensions, rgbaPixels, TWIPS_PER_CSS_PIXEL } from '@deepseek-ai/libreoffice-kit/internal/rendering'
|
|
3
|
-
export type { EnginePage } from '@deepseek-ai/libreoffice-kit/internal/rendering'
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/** Browser-facing document rendering and host font interfaces. */
|
|
2
|
-
|
|
3
|
-
/** Independently served, version-matched engine resources. */
|
|
4
|
-
export interface BrowserEngineAssets {
|
|
5
|
-
readonly workerUrl: string
|
|
6
|
-
readonly loaderUrl: string
|
|
7
|
-
readonly wasmUrl: string
|
|
8
|
-
readonly dataUrl: string
|
|
9
|
-
readonly metadataUrl: string
|
|
10
|
-
readonly programDirectory: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare const preparedBrowserEngine: unique symbol
|
|
14
|
-
/** Compiled engine code bound to one WASM resource identity. */
|
|
15
|
-
export interface PreparedBrowserEngine { readonly [preparedBrowserEngine]: true }
|
|
16
|
-
|
|
17
|
-
/** VCL attributes passed unchanged to the Host's font matcher. */
|
|
18
|
-
export interface BrowserFontRequest {
|
|
19
|
-
readonly mode?: 'full'
|
|
20
|
-
readonly family: string
|
|
21
|
-
readonly style: string
|
|
22
|
-
readonly weight: number
|
|
23
|
-
readonly italic: number
|
|
24
|
-
readonly width: number
|
|
25
|
-
readonly pitch: number
|
|
26
|
-
readonly language: string
|
|
27
|
-
readonly codePoints: readonly number[]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Immutable font content already installed in one document Worker. */
|
|
31
|
-
export interface BrowserFontIdentity {
|
|
32
|
-
readonly id: string
|
|
33
|
-
readonly bytes: number
|
|
34
|
-
readonly format?: 'ttf' | 'otf' | 'ttc'
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** One new font body or a metadata-only reference to content already installed in the Worker. */
|
|
38
|
-
export type BrowserResolvedFont = {
|
|
39
|
-
readonly id: string
|
|
40
|
-
readonly family: string
|
|
41
|
-
readonly alias: string
|
|
42
|
-
readonly format?: 'ttf' | 'otf' | 'ttc'
|
|
43
|
-
} & ({ readonly data: Uint8Array; readonly bytes?: never } | { readonly data?: never; readonly bytes: number })
|
|
44
|
-
|
|
45
|
-
/** Immutable per-face font subsets; equal ids and aliases must identify equal bytes. */
|
|
46
|
-
export interface BrowserFontResult {
|
|
47
|
-
readonly fonts: readonly BrowserResolvedFont[]
|
|
48
|
-
readonly missingFamily?: string
|
|
49
|
-
/** Missing scalars reported by the Host, independently of a substituted family. */
|
|
50
|
-
readonly unresolvedCodePoints?: readonly number[]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** All sizes are CSS pixels at 96 pixels per inch. */
|
|
54
|
-
export interface BrowserPage { readonly width: number; readonly height: number }
|
|
55
|
-
|
|
56
|
-
/** Page-relative rectangle, rasterized at the requested pixel scale. */
|
|
57
|
-
export interface BrowserTileRequest {
|
|
58
|
-
readonly pageIndex: number
|
|
59
|
-
readonly x: number
|
|
60
|
-
readonly y: number
|
|
61
|
-
readonly width: number
|
|
62
|
-
readonly height: number
|
|
63
|
-
readonly scale: number
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Owned, non-premultiplied RGBA pixels accepted by ImageData. */
|
|
67
|
-
export interface BrowserTile {
|
|
68
|
-
readonly width: number
|
|
69
|
-
readonly height: number
|
|
70
|
-
readonly rgba: Uint8ClampedArray
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Caller-owned source bytes are copied before Worker transfer. */
|
|
74
|
-
export interface BrowserDocumentOptions {
|
|
75
|
-
readonly data: Uint8Array
|
|
76
|
-
readonly extension: 'pdf'
|
|
77
|
-
readonly assets: BrowserEngineAssets
|
|
78
|
-
/** Optional compiled WASM code created by prepareOfficeBrowser for these assets. */
|
|
79
|
-
readonly preparedEngine?: PreparedBrowserEngine
|
|
80
|
-
/** Maximum time for each load, render, font request, or teardown operation. */
|
|
81
|
-
readonly timeoutMs: number
|
|
82
|
-
/** Maximum ZIP entries inspected before LibreOffice loads OOXML. */
|
|
83
|
-
readonly maxArchiveEntries: number
|
|
84
|
-
/** Maximum total declared uncompressed OOXML bytes. */
|
|
85
|
-
readonly maxUncompressedBytes: number
|
|
86
|
-
/** Total distinct font bytes retained in this document's MEMFS. */
|
|
87
|
-
readonly maxLoadedFontBytes: number
|
|
88
|
-
/** The same ordered substitution groups used by the Host font matcher. */
|
|
89
|
-
readonly fontFallbacks: readonly (readonly string[])[]
|
|
90
|
-
/** Match fonts without blocking the browser's main thread. */
|
|
91
|
-
readonly resolveFonts: (request: BrowserFontRequest, known: readonly BrowserFontIdentity[], signal: AbortSignal) => Promise<BrowserFontResult>
|
|
92
|
-
/** Called with unavailable declared OOXML families; binary DOC/PPT have no font diagnostics. */
|
|
93
|
-
readonly onMissingFonts?: (families: readonly string[]) => void
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Engine resources and limits one Worker holds for every document it opens. */
|
|
97
|
-
export type BrowserRuntimeOptions = Omit<BrowserDocumentOptions, 'data' | 'extension' | 'resolveFonts' | 'onMissingFonts'>
|
|
98
|
-
|
|
99
|
-
/** One Worker-owned, read-only Office document. */
|
|
100
|
-
export interface BrowserDocument {
|
|
101
|
-
/** Visible pages; Writer omits zero-area automatic section parity placeholders. */
|
|
102
|
-
readonly pages: readonly BrowserPage[]
|
|
103
|
-
/** Render a page region; cancellation discards that region without closing the document. */
|
|
104
|
-
renderTile(request: BrowserTileRequest, signal?: AbortSignal): Promise<BrowserTile>
|
|
105
|
-
/** Await document, office and pthread disposal; repeated calls share completion. */
|
|
106
|
-
dispose(): Promise<void>
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Stable failures callers may map to their own localized product copy. */
|
|
110
|
-
export type BrowserRenderErrorCode = 'unavailable' | 'invalid-document' | 'timeout' | 'font-limit' | 'font-unavailable' | 'disposed' | 'render-failed' | 'stale-part'
|
|
111
|
-
|
|
112
|
-
/** A rendering failure with a stable machine-readable category. */
|
|
113
|
-
export class BrowserRenderError extends Error {
|
|
114
|
-
constructor(readonly code: BrowserRenderErrorCode, message: string) {
|
|
115
|
-
super(message)
|
|
116
|
-
this.name = 'BrowserRenderError'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/** Classic Worker entry: serializes one LibreOffice instance, its documents and its pthreads. */
|
|
2
|
-
import { inspectDocument } from '@deepseek-ai/libreoffice-kit/document-inspection'
|
|
3
|
-
import { memoryFontConfig } from '@deepseek-ai/libreoffice-kit/font-config'
|
|
4
|
-
import { createEngineFontCache, createFontReader, type EngineFontFace } from './font-channel.ts'
|
|
5
|
-
import { instantiatePreparedModule, preparedBrowserModule } from './preparation.ts'
|
|
6
|
-
import { BrowserRenderError } from './types.ts'
|
|
7
|
-
import type { BrowserFontRequest, BrowserRenderErrorCode, BrowserTileRequest } from './types.ts'
|
|
8
|
-
import type { OwnerMessage, WorkerDocumentOptions, WorkerMessage, WorkerOptions } from './protocol.ts'
|
|
9
|
-
import type { EnginePage } from './rendering.ts'
|
|
10
|
-
|
|
11
|
-
import type { EmscriptenModule } from './engine-types.ts'
|
|
12
|
-
import type { OfficeDocumentFormat } from './office-types.ts'
|
|
13
|
-
import { OfficeEngine } from './office-engine.ts'
|
|
14
|
-
import { pdfPages, renderRegion } from './engine-rendering.ts'
|
|
15
|
-
|
|
16
|
-
interface EngineGlobal extends DedicatedWorkerGlobalScope {
|
|
17
|
-
createLibreOfficeModule(overrides: Record<string, unknown>): Promise<EmscriptenModule>
|
|
18
|
-
}
|
|
19
|
-
const scope = globalThis as unknown as EngineGlobal
|
|
20
|
-
/** Host font request that installs a fallback face before LibreOffice resolves any family. */
|
|
21
|
-
const initialFont: BrowserFontRequest = { family: 'sans-serif', style: '', weight: 5, italic: 0, width: 5, pitch: 0, language: '', codePoints: [] }
|
|
22
|
-
let module: EmscriptenModule | undefined
|
|
23
|
-
let office = 0
|
|
24
|
-
let document = 0
|
|
25
|
-
let pdf = 0
|
|
26
|
-
let pages: EnginePage[] = []
|
|
27
|
-
let reader: OfficeEngine | undefined
|
|
28
|
-
let fatal = false
|
|
29
|
-
let fontFailure: unknown
|
|
30
|
-
let serial = Promise.resolve()
|
|
31
|
-
const lifetime = new AbortController()
|
|
32
|
-
let runtime: { options: WorkerOptions; channel: SharedArrayBuffer } | undefined
|
|
33
|
-
let resolveFonts: ((request: BrowserFontRequest) => EngineFontFace[]) | undefined
|
|
34
|
-
/** MEMFS path of the open document; removed when its model is released. */
|
|
35
|
-
let source: string | undefined
|
|
36
|
-
/** Font identities and files retained until this runtime is destroyed. */
|
|
37
|
-
const fontCache = createEngineFontCache()
|
|
38
|
-
|
|
39
|
-
function send(message: WorkerMessage, transfer: Transferable[] = []): void { scope.postMessage(message, transfer) }
|
|
40
|
-
function call(name: string, args: number[]): number { return module!.ccall(name, 'number', args.map(() => 'number'), args) }
|
|
41
|
-
function error(code: BrowserRenderErrorCode): BrowserRenderError {
|
|
42
|
-
if (fontFailure instanceof BrowserRenderError) return fontFailure
|
|
43
|
-
if (!module) return new BrowserRenderError(code, 'LibreOffice could not initialize.')
|
|
44
|
-
const pointer = call('dsh_lok_error', [office])
|
|
45
|
-
if (!pointer) return new BrowserRenderError(code, 'LibreOffice could not render the document.')
|
|
46
|
-
try { return new BrowserRenderError(code, module.UTF8ToString(pointer)) } finally { call('free', [pointer]) }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Bind one document's declared families to the runtime's font channel.
|
|
51
|
-
* The first synchronous read of a request consumes the Host response that was
|
|
52
|
-
* requested before the engine's filesystem was configured.
|
|
53
|
-
*/
|
|
54
|
-
function installFonts(loaded: EmscriptenModule, options: WorkerOptions, families: ReadonlyMap<string, string>,
|
|
55
|
-
codePoints: readonly number[], consumeInitial: { pending: boolean }): (request: BrowserFontRequest) => EngineFontFace[] {
|
|
56
|
-
loaded.FS.writeFile('/dsh/fonts.conf', new TextEncoder().encode(memoryFontConfig(options.fontFallbacks, families.values())))
|
|
57
|
-
return createFontReader(runtime!.channel, options.timeoutMs, options.maxLoadedFontBytes, families,
|
|
58
|
-
(request, known) => {
|
|
59
|
-
if (consumeInitial.pending) consumeInitial.pending = false
|
|
60
|
-
else send({ type: 'font', request, known })
|
|
61
|
-
}, () => send({ type: 'font-next' }),
|
|
62
|
-
(path, bytes) => { loaded.FS.writeFile(path, bytes) },
|
|
63
|
-
missing => send({ type: 'missing-fonts', families: missing }), codePoints, fontCache)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Create this runtime's WASM module, filesystem configuration and office instance once. */
|
|
67
|
-
async function createEngine(options: WorkerOptions, families: ReadonlyMap<string, string>,
|
|
68
|
-
codePoints: readonly number[], consumeInitial: { pending: boolean }, portableDocument: boolean): Promise<void> {
|
|
69
|
-
const { assets } = options
|
|
70
|
-
const prepared = options.preparedEngine === undefined ? undefined : preparedBrowserModule(options.preparedEngine, assets)
|
|
71
|
-
const response = await fetch(assets.dataUrl, { credentials: 'same-origin', signal: lifetime.signal })
|
|
72
|
-
if (!response.ok) throw new BrowserRenderError('unavailable', `LibreOffice data request failed: ${response.status}`)
|
|
73
|
-
const data = await response.arrayBuffer()
|
|
74
|
-
scope.importScripts(assets.loaderUrl)
|
|
75
|
-
const created = await scope.createLibreOfficeModule({
|
|
76
|
-
noInitialRun: true,
|
|
77
|
-
dshOnCallback(type: number, payload: string) { reader?.callback(type, payload) },
|
|
78
|
-
mainScriptUrlOrBlob: assets.loaderUrl,
|
|
79
|
-
locateFile(name: string) {
|
|
80
|
-
const basename = name.slice(name.lastIndexOf('/') + 1)
|
|
81
|
-
switch (basename) {
|
|
82
|
-
case 'soffice.js': case 'soffice.cjs': return assets.loaderUrl
|
|
83
|
-
case 'soffice.wasm': return assets.wasmUrl
|
|
84
|
-
case 'soffice.data': return assets.dataUrl
|
|
85
|
-
case 'soffice.data.js.metadata': return assets.metadataUrl
|
|
86
|
-
default: throw new BrowserRenderError('unavailable', `LibreOffice requested an undeclared resource: ${basename}`)
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
getPreloadedPackage: () => data,
|
|
90
|
-
...(prepared === undefined ? {} : { instantiateWasm(imports: WebAssembly.Imports,
|
|
91
|
-
receive: (instance: WebAssembly.Instance, compiled: WebAssembly.Module) => void) {
|
|
92
|
-
return instantiatePreparedModule(prepared, imports, receive)
|
|
93
|
-
} }),
|
|
94
|
-
dshResolveSystemFontFaces(request: BrowserFontRequest) {
|
|
95
|
-
if (!resolveFonts) throw new BrowserRenderError('font-unavailable', 'LibreOffice requested fonts before MEMFS initialization.')
|
|
96
|
-
try { return resolveFonts(request) } catch (failure) { fontFailure = failure; throw failure }
|
|
97
|
-
},
|
|
98
|
-
preRun: [(loaded: EmscriptenModule) => {
|
|
99
|
-
for (const path of ['/dsh/profile', '/dsh/font-cache', '/dsh-fonts', '/usr/share/fonts/dsh-pdfium']) loaded.FS.mkdirTree(path)
|
|
100
|
-
resolveFonts = installFonts(loaded, options, families, codePoints, consumeInitial)
|
|
101
|
-
if (portableDocument) for (const family of new Set(options.fontFallbacks.flat())) resolveFonts({ ...initialFont, family, mode: 'full' })
|
|
102
|
-
else resolveFonts(initialFont)
|
|
103
|
-
Object.assign(loaded.ENV, { HOME: '/dsh/profile', TMPDIR: '/tmp', FONTCONFIG_FILE: '/dsh/fonts.conf', LOK_HOST_ALLOWLIST: '^$' })
|
|
104
|
-
}],
|
|
105
|
-
onAbort() { fatal = true },
|
|
106
|
-
print() {}, printErr() {},
|
|
107
|
-
})
|
|
108
|
-
module = created
|
|
109
|
-
office = created.ccall('dsh_lok_initialize', 'number', ['string', 'string'], [assets.programDirectory, 'file:///dsh/profile'])
|
|
110
|
-
if (!office) throw error('unavailable')
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Load one document into the already initialized engine. */
|
|
114
|
-
async function openDocument(options: WorkerDocumentOptions): Promise<void> {
|
|
115
|
-
if (!runtime) throw new BrowserRenderError('disposed', 'LibreOffice Worker has not been started.')
|
|
116
|
-
const engine = runtime.options
|
|
117
|
-
const reading = options.extension !== 'pdf'
|
|
118
|
-
let metadata: ReturnType<typeof inspectDocument>
|
|
119
|
-
try {
|
|
120
|
-
metadata = reading
|
|
121
|
-
? inspectDocument(options.data, options.extension, engine)
|
|
122
|
-
: { families: new Map(), codePoints: [] }
|
|
123
|
-
} catch (failure) { throw new BrowserRenderError('invalid-document', failure instanceof Error ? failure.message : String(failure)) }
|
|
124
|
-
// Host font discovery runs while the engine downloads and compiles. The first
|
|
125
|
-
// synchronous font read consumes this response through the same bounded channel.
|
|
126
|
-
if (reading) send({ type: 'font', request: initialFont, known: [] })
|
|
127
|
-
const consumeInitial = { pending: reading }
|
|
128
|
-
if (!module) await createEngine(engine, metadata.families, metadata.codePoints, consumeInitial, !reading)
|
|
129
|
-
else {
|
|
130
|
-
resolveFonts = installFonts(module, engine, metadata.families, metadata.codePoints, consumeInitial)
|
|
131
|
-
if (reading) resolveFonts(initialFont)
|
|
132
|
-
}
|
|
133
|
-
const loaded = module as EmscriptenModule
|
|
134
|
-
if (!reading) {
|
|
135
|
-
const pointer = loaded.ccall('malloc', 'number', ['number'], [options.data.byteLength])
|
|
136
|
-
if (!pointer) throw error('invalid-document')
|
|
137
|
-
try {
|
|
138
|
-
new Uint8Array(loaded.HEAPU32.buffer, pointer, options.data.byteLength).set(options.data)
|
|
139
|
-
pdf = loaded.ccall('dsh_pdf_open', 'number', ['number', 'number', 'string'], [pointer, options.data.byteLength, ''])
|
|
140
|
-
} finally { call('free', [pointer]) }
|
|
141
|
-
if (!pdf) throw error('invalid-document')
|
|
142
|
-
pages = pdfPages(loaded, pdf, () => error('invalid-document'))
|
|
143
|
-
return
|
|
144
|
-
}
|
|
145
|
-
const input = `/dsh/document.${options.extension}`
|
|
146
|
-
loaded.FS.writeFile(input, options.data)
|
|
147
|
-
source = input
|
|
148
|
-
document = loaded.ccall('dsh_lok_document_load', 'number', ['number', 'string', 'string'],
|
|
149
|
-
[office, `file://${input}`, 'ReadOnly=true,EnableMacrosExecution=false'])
|
|
150
|
-
if (!document || !call('dsh_lok_document_initialize_rendering', [document])) throw error('invalid-document')
|
|
151
|
-
const type = call('dsh_lok_document_type', [document])
|
|
152
|
-
if (type !== (options.extension === 'docx' || options.extension === 'doc' ? 0 : options.extension === 'xlsx' || options.extension === 'xls' ? 1 : 2)) throw new BrowserRenderError('invalid-document', 'The document type does not match its extension.')
|
|
153
|
-
const engineReader = reader = new OfficeEngine(loaded, document, options.extension as OfficeDocumentFormat,
|
|
154
|
-
event => send({ type: 'office-event', event }), failure => {
|
|
155
|
-
fatal ||= failure instanceof WebAssembly.RuntimeError
|
|
156
|
-
send({ type: 'office-event', event: { type: 'error', code: 'render-failed', message: failure instanceof Error ? failure.message : String(failure) } })
|
|
157
|
-
})
|
|
158
|
-
await engineReader.start()
|
|
159
|
-
if (options.restore) await engineReader.restore(options.restore)
|
|
160
|
-
pages = engineReader.state.parts.map((part, index) => ({ ...part, x: 0, y: 0, part: type === 0 ? -1 : index }))
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Release the open document's model, MEMFS bytes and installed fonts; keep the engine. */
|
|
164
|
-
function closeDocument(): void {
|
|
165
|
-
reader?.stop()
|
|
166
|
-
reader = undefined
|
|
167
|
-
try {
|
|
168
|
-
if (module && !fatal) {
|
|
169
|
-
if (pdf) { const value = pdf; pdf = 0; if (!call('dsh_pdf_destroy', [value])) throw error('render-failed') }
|
|
170
|
-
if (document) { const value = document; document = 0; if (!call('dsh_lok_document_destroy', [value])) throw error('render-failed') }
|
|
171
|
-
if (source !== undefined) unlink(source)
|
|
172
|
-
}
|
|
173
|
-
} finally {
|
|
174
|
-
resolveFonts = undefined
|
|
175
|
-
pages = []
|
|
176
|
-
source = undefined
|
|
177
|
-
document = 0
|
|
178
|
-
pdf = 0
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** Remove one MEMFS path; a missing file means the engine already released it. */
|
|
183
|
-
function unlink(path: string): void {
|
|
184
|
-
try { module?.FS.unlink(path) } catch (failure: unknown) {
|
|
185
|
-
if (!(failure instanceof Error) || !/no such file|does not exist/i.test(failure.message)) throw failure
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function render(request: BrowserTileRequest): { width: number; height: number; rgba: Uint8ClampedArray } {
|
|
190
|
-
if (fatal) throw new BrowserRenderError('render-failed', 'LibreOffice Worker has aborted.')
|
|
191
|
-
if (!pdf || !module) throw new BrowserRenderError('disposed', 'The document is closed.')
|
|
192
|
-
return renderRegion(module, pdf, request, pages, () => error('render-failed'), true)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** Destroy the office instance and every pthread after the documents are closed. */
|
|
196
|
-
function dispose(): void {
|
|
197
|
-
closeDocument()
|
|
198
|
-
try {
|
|
199
|
-
if (module && !fatal && office) {
|
|
200
|
-
const value = office
|
|
201
|
-
office = 0
|
|
202
|
-
if (!call('dsh_lok_destroy', [value])) throw error('render-failed')
|
|
203
|
-
}
|
|
204
|
-
} finally {
|
|
205
|
-
module?.PThread.terminateAllThreads()
|
|
206
|
-
module = undefined
|
|
207
|
-
office = 0
|
|
208
|
-
pages = []
|
|
209
|
-
runtime = undefined
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
scope.onmessage = (event: MessageEvent<OwnerMessage>) => {
|
|
214
|
-
const message = event.data
|
|
215
|
-
if (message.type === 'dispose') { lifetime.abort(); reader?.stop() }
|
|
216
|
-
serial = serial.then(async () => {
|
|
217
|
-
try {
|
|
218
|
-
switch (message.type) {
|
|
219
|
-
case 'start': {
|
|
220
|
-
runtime = { options: message.options, channel: message.channel }
|
|
221
|
-
send({ type: 'started', id: message.id })
|
|
222
|
-
break
|
|
223
|
-
}
|
|
224
|
-
case 'open': {
|
|
225
|
-
// One document at a time: a caller that replaces its document without
|
|
226
|
-
// closing first still leaves the engine with a single loaded model.
|
|
227
|
-
if (document || pdf) closeDocument()
|
|
228
|
-
await openDocument(message.options)
|
|
229
|
-
send({ type: 'opened', id: message.id, pages: pages.map(({ width, height }) => ({ width, height })),
|
|
230
|
-
...(reader ? { office: reader.state } : {}) })
|
|
231
|
-
break
|
|
232
|
-
}
|
|
233
|
-
case 'close-document': closeDocument(); send({ type: 'closed-document', id: message.id }); break
|
|
234
|
-
case 'reading-state': {
|
|
235
|
-
if (!reader) throw new BrowserRenderError('disposed', 'Office document is closed.')
|
|
236
|
-
send({ type: 'reading-state', id: message.id, state: reader.capture() })
|
|
237
|
-
break
|
|
238
|
-
}
|
|
239
|
-
case 'tile': { const tile = render(message.request); send({ type: 'tile', id: message.id, tile }, [tile.rgba.buffer]); break }
|
|
240
|
-
case 'office-tile': {
|
|
241
|
-
if (!reader) throw new BrowserRenderError('disposed', 'Office reader is closed.')
|
|
242
|
-
const tile = reader.render(message.request)
|
|
243
|
-
send({ type: 'tile', id: message.id, tile }, [tile.rgba.buffer])
|
|
244
|
-
break
|
|
245
|
-
}
|
|
246
|
-
case 'office-operation': {
|
|
247
|
-
if (!reader) throw new BrowserRenderError('disposed', 'Office reader is closed.')
|
|
248
|
-
const result = await reader.operation(message.operation)
|
|
249
|
-
send({ type: 'office-result', id: message.id, ...result })
|
|
250
|
-
break
|
|
251
|
-
}
|
|
252
|
-
case 'dispose': dispose(); send({ type: 'disposed', id: message.id }); scope.close(); break
|
|
253
|
-
default: throw new BrowserRenderError('render-failed', 'Unsupported Office Worker request.')
|
|
254
|
-
}
|
|
255
|
-
} catch (failure) {
|
|
256
|
-
fatal ||= failure instanceof WebAssembly.RuntimeError
|
|
257
|
-
send({ type: 'error', id: message.id, code: failure instanceof BrowserRenderError ? failure.code : 'render-failed', message: failure instanceof Error ? failure.message : String(failure), fatal })
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsdown'
|
|
2
|
-
|
|
3
|
-
/** The classic worker bundles its protocol and renderer before loading Emscripten. */
|
|
4
|
-
export default defineConfig([
|
|
5
|
-
{ entry: ['lib/types/index.js'], outDir: 'lib', format: ['esm'], platform: 'browser', target: 'es2024', fixedExtension: false, dts: false, clean: false },
|
|
6
|
-
{ entry: ['lib/types/worker.js'], outDir: 'lib', format: ['iife'], noExternal: ['@deepseek-ai/libreoffice-kit/font-config', '@deepseek-ai/libreoffice-kit/internal/rendering', '@deepseek-ai/libreoffice-kit/internal/engine-rendering', '@deepseek-ai/libreoffice-kit/internal/sheet-geometry', '@deepseek-ai/libreoffice-kit/document-inspection', 'fflate', 'saxes', 'xmlchars'], outputOptions: { entryFileNames: '[name].js' }, platform: 'browser', target: 'es2024', fixedExtension: false, dts: false, clean: false },
|
|
7
|
-
])
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/** Build browser entries into the existing main package; the engine stays in the WASM dependency. */
|
|
3
|
-
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import { buildKitSources } from './build-kit.mjs';
|
|
7
|
-
import { root, isMain, readJson } from './platform-matrix.mjs';
|
|
8
|
-
import { pnpm } from './pack-utils.mjs';
|
|
9
|
-
import { assert, regularFile, sha256, verifyEnginePackage } from './verify-artifacts.mjs';
|
|
10
|
-
|
|
11
|
-
const source = join(root, 'packages/browser');
|
|
12
|
-
const directory = join(root, 'packages/entry');
|
|
13
|
-
const helpers = ['rendering', 'engine-rendering', 'sheet-geometry'];
|
|
14
|
-
|
|
15
|
-
/** Compile browser-only JavaScript without copying any engine bytes into the main package. */
|
|
16
|
-
export function buildBrowserSources(buildEntry = true) {
|
|
17
|
-
if (buildEntry) buildKitSources();
|
|
18
|
-
// TypeScript does not remove declarations for deleted source files.
|
|
19
|
-
rmSync(join(source, 'lib/types'), { recursive: true, force: true });
|
|
20
|
-
rmSync(join(source, 'lib/tsconfig.tsbuildinfo'), { force: true });
|
|
21
|
-
pnpm(['exec', 'tsc', '-b', 'packages/browser'], { cwd: root });
|
|
22
|
-
pnpm(['exec', 'tsdown'], { cwd: source });
|
|
23
|
-
const target = join(directory, 'lib/browser');
|
|
24
|
-
rmSync(target, { recursive: true, force: true });
|
|
25
|
-
mkdirSync(join(target, 'types'), { recursive: true });
|
|
26
|
-
for (const name of ['index.js', 'worker.js']) cpSync(regularFile(source, `lib/${name}`), join(target, name));
|
|
27
|
-
for (const name of readdirSync(join(source, 'lib/types')).filter(name => name.endsWith('.d.ts')))
|
|
28
|
-
cpSync(join(source, 'lib/types', name), join(target, 'types', name));
|
|
29
|
-
rmSync(join(directory, 'sources/browser'), { recursive: true, force: true });
|
|
30
|
-
for (const path of ['packages/browser/src', 'packages/browser/package.json', 'packages/browser/tsconfig.json', 'packages/browser/tsdown.config.ts', 'scripts/build-browser.mjs']) {
|
|
31
|
-
const dest = join(directory, 'sources/browser', path);
|
|
32
|
-
mkdirSync(dirname(dest), { recursive: true }); cpSync(join(root, path), dest, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
const entryRequire = createRequire(join(directory, 'package.json'));
|
|
35
|
-
const saxesRequire = createRequire(entryRequire.resolve('saxes'));
|
|
36
|
-
mkdirSync(join(directory, 'licenses/javascript'), { recursive: true });
|
|
37
|
-
for (const [name, resolver] of [['fflate', entryRequire], ['saxes', entryRequire], ['xmlchars', saxesRequire]]) {
|
|
38
|
-
let folder = dirname(resolver.resolve(name));
|
|
39
|
-
while (!existsSync(join(folder, 'package.json')) || readJson(join(folder, 'package.json')).name !== name) {
|
|
40
|
-
const parent = dirname(folder); assert(parent !== folder, `Missing bundled dependency: ${name}`); folder = parent;
|
|
41
|
-
}
|
|
42
|
-
const license = name === 'saxes' ? join(source, 'third-party/saxes-6.0.0-LICENSE') : join(folder, 'LICENSE');
|
|
43
|
-
cpSync(license, join(directory, 'licenses/javascript', `${name}-LICENSE`));
|
|
44
|
-
}
|
|
45
|
-
const path = 'lib/browser/worker.js';
|
|
46
|
-
writeFileSync(join(target, 'assets.json'), `${JSON.stringify({ schemaVersion: 1, files: { worker: { path, bytes: statSync(join(directory, path)).size, sha256: sha256(join(directory, path)) } } }, null, 2)}\n`);
|
|
47
|
-
return directory;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Require main-package browser entries and the direct-drawing ABI in the separately staged engine. */
|
|
51
|
-
export function verifyBrowserPackage(target = directory, engineDirectory = join(root, 'packages/wasm')) {
|
|
52
|
-
const manifest = readJson(regularFile(target, 'package.json'));
|
|
53
|
-
assert(manifest.name === '@deepseek-ai/libreoffice-kit' && manifest.version === readJson(join(root, 'package.json')).version,
|
|
54
|
-
'Browser entry must be in the matching main package');
|
|
55
|
-
for (const file of ['lib/browser/index.js', 'lib/browser/worker.js', 'lib/browser/types/index.d.ts', 'lib/browser-assets.js']) regularFile(target, file);
|
|
56
|
-
for (const helper of helpers) regularFile(target, `lib/${helper}.js`);
|
|
57
|
-
const declarations = join(target, 'lib/browser/types');
|
|
58
|
-
const declarationText = readdirSync(declarations).filter(name => name.endsWith('.d.ts')).map(name => readFileSync(join(declarations, name), 'utf8')).join('\n');
|
|
59
|
-
assert(declarationText.includes('openOfficeDocument') && declarationText.includes('openOfficeRuntime')
|
|
60
|
-
&& declarationText.includes('OfficeReadingState') && declarationText.includes('prepareOfficeBrowser') && !declarationText.includes('openEditor')
|
|
61
|
-
&& !readdirSync(declarations).some(name => name.startsWith('editor')), 'Browser package retains a removed editing SDK');
|
|
62
|
-
const receipt = readJson(regularFile(target, 'lib/browser/assets.json'));
|
|
63
|
-
const worker = receipt.files?.worker;
|
|
64
|
-
assert(receipt.schemaVersion === 1 && worker?.path === 'lib/browser/worker.js'
|
|
65
|
-
&& worker.bytes === statSync(join(target, worker.path)).size && worker.sha256 === sha256(join(target, worker.path)), 'Browser Worker receipt differs');
|
|
66
|
-
verifyEnginePackage(engineDirectory);
|
|
67
|
-
const engine = readJson(join(engineDirectory, 'prebuilds.json')).engine;
|
|
68
|
-
const module = new WebAssembly.Module(readFileSync(join(engineDirectory, engine.wasm)));
|
|
69
|
-
const exports = new Set(WebAssembly.Module.exports(module).map(entry => entry.name));
|
|
70
|
-
for (const name of ['dsh_lok_document_paint', 'dsh_lok_document_configure_view', 'dsh_lok_document_composition',
|
|
71
|
-
'dsh_lok_document_create_view', 'dsh_lok_document_part_info', 'dsh_lok_document_capture_reading_selection',
|
|
72
|
-
'dsh_lok_document_restore_reading_text_selection', 'dsh_lok_document_restore_reading_object_selection',
|
|
73
|
-
'dsh_pdf_open', 'dsh_pdf_paint'])
|
|
74
|
-
assert(exports.has(name) || exports.has(`_${name}`), `WASM has no browser export: ${name}`);
|
|
75
|
-
return receipt;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Compatibility build command; payload remains exclusively in the existing WASM package. */
|
|
79
|
-
export function stageBrowserAssets(engineDirectory = join(root, 'packages/wasm')) {
|
|
80
|
-
buildBrowserSources(); verifyBrowserPackage(directory, engineDirectory); return directory;
|
|
81
|
-
}
|
|
82
|
-
if (isMain(import.meta.url)) {
|
|
83
|
-
if (process.argv.includes('--verify')) verifyBrowserPackage();
|
|
84
|
-
else if (process.argv.includes('--stage')) stageBrowserAssets();
|
|
85
|
-
else buildBrowserSources();
|
|
86
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Host font subset runtime
|
|
2
|
-
|
|
3
|
-
[中文](README.zh.md)
|
|
4
|
-
|
|
5
|
-
The Node font source uses HarfBuzz to extract individual sfnt faces and preserve shaping while selecting reusable Unicode-script partitions. [source.json](source.json) pins harfbuzzjs, its HarfBuzz submodule, and Emscripten. The upstream subset module has a fixed 65 MiB heap; this recipe enables heap growth up to the WebAssembly build ceiling of 2 GiB. Input limits and the retained-subset cache budget do not bound all transient subsetting allocations.
|
|
6
|
-
|
|
7
|
-
Prepare an isolated checkout and SDK, then build:
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
git clone --depth 1 --branch v1.6.1 --recurse-submodules --shallow-submodules https://github.com/harfbuzz/harfbuzzjs.git .build/font-subset/harfbuzzjs
|
|
11
|
-
git clone https://github.com/emscripten-core/emsdk.git .build/font-subset/emsdk
|
|
12
|
-
git -C .build/font-subset/emsdk checkout --detach 5eb0bde7585670252e8ba05e9d361627bffd08b5
|
|
13
|
-
python3 .build/font-subset/emsdk/emsdk.py install 4.0.10
|
|
14
|
-
python3 .build/font-subset/emsdk/emsdk.py activate 4.0.10
|
|
15
|
-
node scripts/build-font-subset.mjs
|
|
16
|
-
node scripts/build-font-subset.mjs --verify
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
The build checks exact commits, clean tracked source files, and the compiler version. It changes only compiler/linker arguments: upstream source remains unmodified. `--source`, `--emsdk`, and `--target` accept existing checkout and staging directories; use a separate SDK cache when another build is active.
|
|
20
|
-
|
|
21
|
-
The generated `packages/entry/assets/font-subset.json` records the exact source pins, recipe hash, and checksums for the WASM module, source recipe, configuration, exports list, and license notices. Node API packing verifies this receipt. The runtime verifies its WASM bytes against the packaged receipt before initialization. Installation and font requests never build or fetch the module.
|
|
22
|
-
|
|
23
|
-
Build this runtime before running font subset tests. Portable fixtures compare Arabic, Indic, supplementary-script, and variable-font shaping and outlines, exercise TTC/dfont extraction, and force allocation beyond the upstream heap size. The tests also cover cache eviction, font-index refresh, worker teardown, and invalid module receipts.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Host 字体子集运行时
|
|
2
|
-
|
|
3
|
-
[English](README.md)
|
|
4
|
-
|
|
5
|
-
Node 字体源使用 HarfBuzz 提取单独的 sfnt 字面,并在选择可复用 Unicode 文字系统分区时保留字形塑形。[source.json](source.json) 固定 harfbuzzjs、其 HarfBuzz 子模块和 Emscripten。上游子集模块使用固定的 65 MiB 堆;本配方允许堆增长,WebAssembly 构建上限为 2 GiB。输入限制和保留子集缓存预算不能约束所有临时子集分配。
|
|
6
|
-
|
|
7
|
-
准备独立源码目录和 SDK,然后构建:
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
git clone --depth 1 --branch v1.6.1 --recurse-submodules --shallow-submodules https://github.com/harfbuzz/harfbuzzjs.git .build/font-subset/harfbuzzjs
|
|
11
|
-
git clone https://github.com/emscripten-core/emsdk.git .build/font-subset/emsdk
|
|
12
|
-
git -C .build/font-subset/emsdk checkout --detach 5eb0bde7585670252e8ba05e9d361627bffd08b5
|
|
13
|
-
python3 .build/font-subset/emsdk/emsdk.py install 4.0.10
|
|
14
|
-
python3 .build/font-subset/emsdk/emsdk.py activate 4.0.10
|
|
15
|
-
node scripts/build-font-subset.mjs
|
|
16
|
-
node scripts/build-font-subset.mjs --verify
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
构建检查精确提交、已跟踪源码无修改及编译器版本。它仅调整编译和链接参数,不修改上游源码。`--source`、`--emsdk` 和 `--target` 接受已有源码、SDK 和暂存目录;另一个构建运行时,应使用独立的 SDK 缓存。
|
|
20
|
-
|
|
21
|
-
生成的 `packages/entry/assets/font-subset.json` 记录精确源码固定信息、配方哈希,以及 WASM 模块、源码配方、配置、导出列表和许可声明的校验和。Node API 打包时验证该回执。运行时初始化前会核对 WASM 字节与随包回执。安装和字体请求不会构建或下载模块。
|
|
22
|
-
|
|
23
|
-
运行字体子集测试前需构建该运行时。可移植测试字体比较阿拉伯文、印度文字、补充平面文字及可变字体的塑形和轮廓,覆盖 TTC/dfont 提取,并强制分配超过上游堆大小的输入。测试还覆盖缓存淘汰、字体索引刷新、Worker 释放和无效模块回执。
|