@deepseek-ai/libreoffice-kit 0.0.2-rc8 → 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 -491
- package/lib/browser/types/connection.d.ts +0 -20
- 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 -21
- package/lib/browser/types/index.d.ts +0 -14
- package/lib/browser/types/office-engine.d.ts +0 -48
- package/lib/browser/types/office-types.d.ts +0 -107
- package/lib/browser/types/office.d.ts +0 -4
- package/lib/browser/types/preparation.d.ts +0 -13
- package/lib/browser/types/protocol.d.ts +0 -110
- package/lib/browser/types/rendering.d.ts +0 -4
- package/lib/browser/types/types.d.ts +0 -113
- package/lib/browser/types/worker.d.ts +0 -2
- package/lib/browser/worker.js +0 -3615
- 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 -171
- 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 -160
- package/sources/browser/packages/browser/src/index.ts +0 -40
- package/sources/browser/packages/browser/src/office-engine.ts +0 -323
- package/sources/browser/packages/browser/src/office-types.ts +0 -77
- package/sources/browser/packages/browser/src/office.ts +0 -62
- package/sources/browser/packages/browser/src/preparation.ts +0 -41
- package/sources/browser/packages/browser/src/protocol.ts +0 -41
- package/sources/browser/packages/browser/src/rendering.ts +0 -3
- package/sources/browser/packages/browser/src/types.ts +0 -115
- package/sources/browser/packages/browser/src/worker.ts +0 -181
- 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 -82
- 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,115 +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
|
-
/** One Worker-owned, read-only Office document. */
|
|
97
|
-
export interface BrowserDocument {
|
|
98
|
-
/** Visible pages; Writer omits zero-area automatic section parity placeholders. */
|
|
99
|
-
readonly pages: readonly BrowserPage[]
|
|
100
|
-
/** Render a page region; cancellation discards that region without closing the document. */
|
|
101
|
-
renderTile(request: BrowserTileRequest, signal?: AbortSignal): Promise<BrowserTile>
|
|
102
|
-
/** Await document, office and pthread disposal; repeated calls share completion. */
|
|
103
|
-
dispose(): Promise<void>
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Stable failures callers may map to their own localized product copy. */
|
|
107
|
-
export type BrowserRenderErrorCode = 'unavailable' | 'invalid-document' | 'timeout' | 'font-limit' | 'font-unavailable' | 'disposed' | 'render-failed' | 'stale-part'
|
|
108
|
-
|
|
109
|
-
/** A rendering failure with a stable machine-readable category. */
|
|
110
|
-
export class BrowserRenderError extends Error {
|
|
111
|
-
constructor(readonly code: BrowserRenderErrorCode, message: string) {
|
|
112
|
-
super(message)
|
|
113
|
-
this.name = 'BrowserRenderError'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/** Classic Worker entry: serializes one LibreOffice instance and owns its pthreads. */
|
|
2
|
-
import { inspectDocument } from '@deepseek-ai/libreoffice-kit/document-inspection'
|
|
3
|
-
import { memoryFontConfig } from '@deepseek-ai/libreoffice-kit/font-config'
|
|
4
|
-
import { createFontReader } from './font-channel.ts'
|
|
5
|
-
import { instantiatePreparedModule, preparedBrowserModule } from './preparation.ts'
|
|
6
|
-
import { BrowserRenderError } from './types.ts'
|
|
7
|
-
import type { BrowserRenderErrorCode, BrowserTileRequest } from './types.ts'
|
|
8
|
-
import type { OwnerMessage, 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
|
-
let module: EmscriptenModule | undefined
|
|
21
|
-
let office = 0
|
|
22
|
-
let document = 0
|
|
23
|
-
let pdf = 0
|
|
24
|
-
let pages: EnginePage[] = []
|
|
25
|
-
let reader: OfficeEngine | undefined
|
|
26
|
-
let fatal = false
|
|
27
|
-
let fontFailure: unknown
|
|
28
|
-
let serial = Promise.resolve()
|
|
29
|
-
const lifetime = new AbortController()
|
|
30
|
-
|
|
31
|
-
function send(message: WorkerMessage, transfer: Transferable[] = []): void { scope.postMessage(message, transfer) }
|
|
32
|
-
function call(name: string, args: number[]): number { return module!.ccall(name, 'number', args.map(() => 'number'), args) }
|
|
33
|
-
function error(code: BrowserRenderErrorCode): BrowserRenderError {
|
|
34
|
-
if (fontFailure instanceof BrowserRenderError) return fontFailure
|
|
35
|
-
if (!module) return new BrowserRenderError(code, 'LibreOffice could not initialize.')
|
|
36
|
-
const pointer = call('dsh_lok_error', [office])
|
|
37
|
-
if (!pointer) return new BrowserRenderError(code, 'LibreOffice could not render the document.')
|
|
38
|
-
try { return new BrowserRenderError(code, module.UTF8ToString(pointer)) } finally { call('free', [pointer]) }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function open(options: WorkerOptions, channel: SharedArrayBuffer, reading = false): Promise<void> {
|
|
42
|
-
const { assets } = options
|
|
43
|
-
const prepared = options.preparedEngine === undefined ? undefined : preparedBrowserModule(options.preparedEngine, assets)
|
|
44
|
-
let metadata: ReturnType<typeof inspectDocument>
|
|
45
|
-
try { metadata = options.extension === 'pdf' ? { families: new Map(), codePoints: [] } : inspectDocument(options.data, options.extension, options) } catch (failure) { throw new BrowserRenderError('invalid-document', failure instanceof Error ? failure.message : String(failure)) }
|
|
46
|
-
const initialFont = { family: 'sans-serif', style: '', weight: 5, italic: 0, width: 5, pitch: 0, language: '', codePoints: [] }
|
|
47
|
-
let initialFontPending = options.extension !== 'pdf'
|
|
48
|
-
// Host font discovery runs while the engine downloads and compiles. The first
|
|
49
|
-
// synchronous font read consumes this response through the same bounded channel.
|
|
50
|
-
if (initialFontPending) send({ type: 'font', request: initialFont, known: [] })
|
|
51
|
-
const response = await fetch(assets.dataUrl, { credentials: 'same-origin', signal: lifetime.signal })
|
|
52
|
-
if (!response.ok) throw new BrowserRenderError('unavailable', `LibreOffice data request failed: ${response.status}`)
|
|
53
|
-
const data = await response.arrayBuffer()
|
|
54
|
-
scope.importScripts(assets.loaderUrl)
|
|
55
|
-
let resolveFonts: ReturnType<typeof createFontReader> | undefined
|
|
56
|
-
module = await scope.createLibreOfficeModule({
|
|
57
|
-
noInitialRun: true,
|
|
58
|
-
dshOnCallback(type: number, payload: string) { reader?.callback(type, payload) },
|
|
59
|
-
mainScriptUrlOrBlob: assets.loaderUrl,
|
|
60
|
-
locateFile(name: string) {
|
|
61
|
-
const basename = name.slice(name.lastIndexOf('/') + 1)
|
|
62
|
-
switch (basename) {
|
|
63
|
-
case 'soffice.js': case 'soffice.cjs': return assets.loaderUrl
|
|
64
|
-
case 'soffice.wasm': return assets.wasmUrl
|
|
65
|
-
case 'soffice.data': return assets.dataUrl
|
|
66
|
-
case 'soffice.data.js.metadata': return assets.metadataUrl
|
|
67
|
-
default: throw new BrowserRenderError('unavailable', `LibreOffice requested an undeclared resource: ${basename}`)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
getPreloadedPackage: () => data,
|
|
71
|
-
...(prepared === undefined ? {} : { instantiateWasm(imports: WebAssembly.Imports,
|
|
72
|
-
receive: (instance: WebAssembly.Instance, compiled: WebAssembly.Module) => void) {
|
|
73
|
-
return instantiatePreparedModule(prepared, imports, receive)
|
|
74
|
-
} }),
|
|
75
|
-
dshResolveSystemFontFaces(request: Parameters<NonNullable<typeof resolveFonts>>[0]) {
|
|
76
|
-
if (!resolveFonts) throw new BrowserRenderError('font-unavailable', 'LibreOffice requested fonts before MEMFS initialization.')
|
|
77
|
-
try { return resolveFonts(request) } catch (failure) { fontFailure = failure; throw failure }
|
|
78
|
-
},
|
|
79
|
-
preRun: [(loaded: EmscriptenModule) => {
|
|
80
|
-
for (const path of ['/dsh/profile', '/dsh/font-cache', '/dsh-fonts', '/usr/share/fonts/dsh-pdfium']) loaded.FS.mkdirTree(path)
|
|
81
|
-
loaded.FS.writeFile('/dsh/fonts.conf', new TextEncoder().encode(memoryFontConfig(options.fontFallbacks, metadata.families.values())))
|
|
82
|
-
Object.assign(loaded.ENV, { HOME: '/dsh/profile', TMPDIR: '/tmp', FONTCONFIG_FILE: '/dsh/fonts.conf', LOK_HOST_ALLOWLIST: '^$' })
|
|
83
|
-
resolveFonts = createFontReader(channel, options.timeoutMs, options.maxLoadedFontBytes, metadata.families,
|
|
84
|
-
(request, known) => {
|
|
85
|
-
if (initialFontPending) initialFontPending = false
|
|
86
|
-
else send({ type: 'font', request, known })
|
|
87
|
-
}, () => send({ type: 'font-next' }),
|
|
88
|
-
(path, bytes) => loaded.FS.writeFile(path, bytes), families => send({ type: 'missing-fonts', families }), metadata.codePoints)
|
|
89
|
-
if (options.extension === 'pdf') {
|
|
90
|
-
for (const family of new Set(options.fontFallbacks.flat())) resolveFonts({ ...initialFont, family, mode: 'full' })
|
|
91
|
-
} else resolveFonts(initialFont)
|
|
92
|
-
}],
|
|
93
|
-
onAbort() { fatal = true },
|
|
94
|
-
print() {}, printErr() {},
|
|
95
|
-
})
|
|
96
|
-
if (options.extension === 'pdf') {
|
|
97
|
-
const pointer = call('malloc', [options.data.byteLength])
|
|
98
|
-
if (!pointer) throw error('invalid-document')
|
|
99
|
-
try {
|
|
100
|
-
new Uint8Array(module.HEAPU32.buffer, pointer, options.data.byteLength).set(options.data)
|
|
101
|
-
pdf = module.ccall('dsh_pdf_open', 'number', ['number', 'number', 'string'], [pointer, options.data.byteLength, ''])
|
|
102
|
-
} finally { call('free', [pointer]) }
|
|
103
|
-
if (!pdf) throw error('invalid-document')
|
|
104
|
-
pages = pdfPages(module, pdf, () => error('invalid-document'))
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
const input = `/dsh/document.${options.extension}`
|
|
108
|
-
module.FS.writeFile(input, options.data)
|
|
109
|
-
office = module.ccall('dsh_lok_initialize', 'number', ['string', 'string'], [assets.programDirectory, 'file:///dsh/profile'])
|
|
110
|
-
if (!office) throw error('invalid-document')
|
|
111
|
-
document = module.ccall('dsh_lok_document_load', 'number', ['number', 'string', 'string'], [office, `file://${input}`, 'ReadOnly=true,EnableMacrosExecution=false'])
|
|
112
|
-
if (!document || !call('dsh_lok_document_initialize_rendering', [document])) throw error('invalid-document')
|
|
113
|
-
const type = call('dsh_lok_document_type', [document])
|
|
114
|
-
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.')
|
|
115
|
-
if (reading) {
|
|
116
|
-
reader = new OfficeEngine(module, document, options.extension as OfficeDocumentFormat,
|
|
117
|
-
event => send({ type: 'office-event', event }), failure => {
|
|
118
|
-
fatal ||= failure instanceof WebAssembly.RuntimeError
|
|
119
|
-
send({ type: 'office-event', event: { type: 'error', code: 'render-failed', message: failure instanceof Error ? failure.message : String(failure) } })
|
|
120
|
-
})
|
|
121
|
-
await reader.start()
|
|
122
|
-
pages = reader.state.parts.map((part, index) => ({ ...part, x: 0, y: 0, part: type === 0 ? -1 : index }))
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
throw new BrowserRenderError('invalid-document', 'Office documents require a retained session.')
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function render(request: BrowserTileRequest): { width: number; height: number; rgba: Uint8ClampedArray } {
|
|
129
|
-
if (fatal) throw new BrowserRenderError('render-failed', 'LibreOffice Worker has aborted.')
|
|
130
|
-
if (!pdf || !module) throw new BrowserRenderError('disposed', 'The document is closed.')
|
|
131
|
-
return renderRegion(module, pdf, request, pages, () => error('render-failed'), true)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function dispose(): void {
|
|
135
|
-
reader?.stop()
|
|
136
|
-
reader = undefined
|
|
137
|
-
try {
|
|
138
|
-
if (module && !fatal) {
|
|
139
|
-
if (pdf) { const value = pdf; pdf = 0; if (!call('dsh_pdf_destroy', [value])) throw error('render-failed') }
|
|
140
|
-
if (document) { const value = document; document = 0; if (!call('dsh_lok_document_destroy', [value])) throw error('render-failed') }
|
|
141
|
-
if (office) { const value = office; office = 0; if (!call('dsh_lok_destroy', [value])) throw error('render-failed') }
|
|
142
|
-
}
|
|
143
|
-
} finally {
|
|
144
|
-
module?.PThread.terminateAllThreads()
|
|
145
|
-
module = undefined
|
|
146
|
-
document = 0
|
|
147
|
-
pdf = 0
|
|
148
|
-
office = 0
|
|
149
|
-
pages = []
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
scope.onmessage = (event: MessageEvent<OwnerMessage>) => {
|
|
154
|
-
const message = event.data
|
|
155
|
-
if (message.type === 'dispose') { lifetime.abort(); reader?.stop() }
|
|
156
|
-
serial = serial.then(async () => {
|
|
157
|
-
try {
|
|
158
|
-
switch (message.type) {
|
|
159
|
-
case 'open': await open(message.options, message.channel, message.office); send({ type: 'opened', id: message.id, pages: pages.map(({ width, height }) => ({ width, height })), ...(reader ? { office: reader.state } : {}) }); break
|
|
160
|
-
case 'tile': { const tile = render(message.request); send({ type: 'tile', id: message.id, tile }, [tile.rgba.buffer]); break }
|
|
161
|
-
case 'office-tile': {
|
|
162
|
-
if (!reader) throw new BrowserRenderError('disposed', 'Office reader is closed.')
|
|
163
|
-
const tile = reader.render(message.request)
|
|
164
|
-
send({ type: 'tile', id: message.id, tile }, [tile.rgba.buffer])
|
|
165
|
-
break
|
|
166
|
-
}
|
|
167
|
-
case 'office-operation': {
|
|
168
|
-
if (!reader) throw new BrowserRenderError('disposed', 'Office reader is closed.')
|
|
169
|
-
const result = await reader.operation(message.operation)
|
|
170
|
-
send({ type: 'office-result', id: message.id, ...result })
|
|
171
|
-
break
|
|
172
|
-
}
|
|
173
|
-
case 'dispose': dispose(); send({ type: 'disposed', id: message.id }); scope.close(); break
|
|
174
|
-
default: throw new BrowserRenderError('render-failed', 'Unsupported Office Worker request.')
|
|
175
|
-
}
|
|
176
|
-
} catch (failure) {
|
|
177
|
-
fatal ||= failure instanceof WebAssembly.RuntimeError
|
|
178
|
-
send({ type: 'error', id: message.id, code: failure instanceof BrowserRenderError ? failure.code : 'render-failed', message: failure instanceof Error ? failure.message : String(failure), fatal })
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
}
|
|
@@ -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,82 +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('prepareOfficeBrowser') && !declarationText.includes('openEditor')
|
|
60
|
-
&& !readdirSync(declarations).some(name => name.startsWith('editor')), 'Browser package retains a removed editing SDK');
|
|
61
|
-
const receipt = readJson(regularFile(target, 'lib/browser/assets.json'));
|
|
62
|
-
const worker = receipt.files?.worker;
|
|
63
|
-
assert(receipt.schemaVersion === 1 && worker?.path === 'lib/browser/worker.js'
|
|
64
|
-
&& worker.bytes === statSync(join(target, worker.path)).size && worker.sha256 === sha256(join(target, worker.path)), 'Browser Worker receipt differs');
|
|
65
|
-
verifyEnginePackage(engineDirectory);
|
|
66
|
-
const engine = readJson(join(engineDirectory, 'prebuilds.json')).engine;
|
|
67
|
-
const module = new WebAssembly.Module(readFileSync(join(engineDirectory, engine.wasm)));
|
|
68
|
-
const exports = new Set(WebAssembly.Module.exports(module).map(entry => entry.name));
|
|
69
|
-
for (const name of ['dsh_lok_document_paint', 'dsh_lok_document_configure_view', 'dsh_lok_document_composition', 'dsh_lok_document_create_view', 'dsh_lok_document_part_info', 'dsh_pdf_open', 'dsh_pdf_paint'])
|
|
70
|
-
assert(exports.has(name) || exports.has(`_${name}`), `WASM has no browser export: ${name}`);
|
|
71
|
-
return receipt;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Compatibility build command; payload remains exclusively in the existing WASM package. */
|
|
75
|
-
export function stageBrowserAssets(engineDirectory = join(root, 'packages/wasm')) {
|
|
76
|
-
buildBrowserSources(); verifyBrowserPackage(directory, engineDirectory); return directory;
|
|
77
|
-
}
|
|
78
|
-
if (isMain(import.meta.url)) {
|
|
79
|
-
if (process.argv.includes('--verify')) verifyBrowserPackage();
|
|
80
|
-
else if (process.argv.includes('--stage')) stageBrowserAssets();
|
|
81
|
-
else buildBrowserSources();
|
|
82
|
-
}
|
|
@@ -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 释放和无效模块回执。
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schemaVersion": 1,
|
|
3
|
-
"algorithm": "harfbuzzjs-1.6.1-hb-36cb489-growth-v1",
|
|
4
|
-
"harfbuzzjs": {
|
|
5
|
-
"repository": "https://github.com/harfbuzz/harfbuzzjs.git",
|
|
6
|
-
"commit": "8aa047b90387790b255b118cf45ad11691a38910"
|
|
7
|
-
},
|
|
8
|
-
"harfbuzz": {
|
|
9
|
-
"repository": "https://github.com/harfbuzz/harfbuzz.git",
|
|
10
|
-
"commit": "36cb489cb02ce4b92099669ba9f9bea348eff93f"
|
|
11
|
-
},
|
|
12
|
-
"emsdk": {
|
|
13
|
-
"commit": "5eb0bde7585670252e8ba05e9d361627bffd08b5",
|
|
14
|
-
"version": "4.0.10"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
_hb_blob_create
|
|
2
|
-
_hb_blob_destroy
|
|
3
|
-
_hb_blob_get_data
|
|
4
|
-
_hb_blob_get_length
|
|
5
|
-
_hb_face_create
|
|
6
|
-
_hb_face_destroy
|
|
7
|
-
_hb_face_get_empty
|
|
8
|
-
_hb_face_reference_blob
|
|
9
|
-
_hb_set_add
|
|
10
|
-
_hb_set_clear
|
|
11
|
-
_hb_set_create
|
|
12
|
-
_hb_set_del
|
|
13
|
-
_hb_set_destroy
|
|
14
|
-
_hb_set_invert
|
|
15
|
-
_hb_set_union
|
|
16
|
-
_hb_subset_input_create_or_fail
|
|
17
|
-
_hb_subset_input_destroy
|
|
18
|
-
_hb_subset_input_get_flags
|
|
19
|
-
_hb_subset_input_get_user_data
|
|
20
|
-
_hb_subset_input_glyph_set
|
|
21
|
-
_hb_subset_input_pin_all_axes_to_default
|
|
22
|
-
_hb_subset_input_pin_axis_location
|
|
23
|
-
_hb_subset_input_pin_axis_to_default
|
|
24
|
-
_hb_subset_input_reference
|
|
25
|
-
_hb_subset_input_set
|
|
26
|
-
_hb_subset_input_set_axis_range
|
|
27
|
-
_hb_subset_input_set_flags
|
|
28
|
-
_hb_subset_input_set_user_data
|
|
29
|
-
_hb_subset_input_unicode_set
|
|
30
|
-
_hb_subset_input_keep_everything
|
|
31
|
-
_hb_subset_or_fail
|
|
32
|
-
_hb_subset_preprocess
|
|
33
|
-
_malloc
|
|
34
|
-
_free
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/** Build a pinned HarfBuzz subset module with a growing heap and stage its redistribution receipt. */
|
|
3
|
-
import { cpSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { join, resolve } from 'node:path';
|
|
5
|
-
import { parseArgs } from 'node:util';
|
|
6
|
-
import { isMain, readJson, root } from './platform-matrix.mjs';
|
|
7
|
-
import { run } from './pack-utils.mjs';
|
|
8
|
-
import { assert, regularFile, sha256 } from './verify-artifacts.mjs';
|
|
9
|
-
|
|
10
|
-
const specPath = 'engine/font-subset/source.json';
|
|
11
|
-
const spec = readJson(join(root, specPath));
|
|
12
|
-
const wasmPath = 'assets/font-subset.wasm';
|
|
13
|
-
const receiptPath = 'assets/font-subset.json';
|
|
14
|
-
const recipePath = 'scripts/build-font-subset.mjs';
|
|
15
|
-
const recipeFiles = [specPath, recipePath, 'scripts/platform-matrix.mjs', 'scripts/pack-utils.mjs', 'scripts/verify-artifacts.mjs', 'engine/font-subset/README.md', 'engine/font-subset/README.zh.md'];
|
|
16
|
-
const required = [wasmPath, ...recipeFiles.map(path => `sources/font-subset/${path}`),
|
|
17
|
-
'sources/font-subset/harfbuzzjs/config-override-subset.h', 'sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols',
|
|
18
|
-
'licenses/font-subset/harfbuzzjs-LICENSE', 'licenses/font-subset/harfbuzz-COPYING'];
|
|
19
|
-
|
|
20
|
-
/** Verify a staged subset module, recipe, exact source pins, and redistribution notices. */
|
|
21
|
-
export function verifyFontSubset(target = join(root, 'packages/entry')) {
|
|
22
|
-
const receipt = readJson(regularFile(target, receiptPath));
|
|
23
|
-
assert(receipt.schemaVersion === 1 && JSON.stringify(receipt.source) === JSON.stringify(spec), 'Font subset source receipt differs');
|
|
24
|
-
assert(receipt.recipe === sha256(join(root, recipePath)), 'Font subset build recipe changed; rebuild the module');
|
|
25
|
-
assert(JSON.stringify(Object.keys(receipt.files).sort()) === JSON.stringify(required.slice().sort()), 'Font subset receipt has an incomplete payload');
|
|
26
|
-
for (const path of required) {
|
|
27
|
-
const file = regularFile(target, path);
|
|
28
|
-
assert(receipt.files[path].bytes === statSync(file).size && receipt.files[path].sha256 === sha256(file), `Font subset payload checksum differs: ${path}`);
|
|
29
|
-
}
|
|
30
|
-
const module = new WebAssembly.Module(readFileSync(join(target, wasmPath)));
|
|
31
|
-
const names = new Set(WebAssembly.Module.exports(module).map(entry => entry.name));
|
|
32
|
-
for (const name of ['memory', '_initialize', 'malloc', 'hb_subset_or_fail', 'hb_subset_input_set']) assert(names.has(name), `Missing font subset export: ${name}`);
|
|
33
|
-
return receipt;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Compile explicit checked-out commits; this command never fetches or modifies upstream sources. */
|
|
37
|
-
export function buildFontSubset({ source = join(root, '.build/font-subset/harfbuzzjs'), emsdk = join(root, '.build/font-subset/emsdk'), target = join(root, 'packages/entry') } = {}) {
|
|
38
|
-
for (const [path, expected] of [[source, spec.harfbuzzjs.commit], [join(source, 'harfbuzz'), spec.harfbuzz.commit], [emsdk, spec.emsdk.commit]]) {
|
|
39
|
-
assert(run('git', ['rev-parse', 'HEAD'], { cwd: path }).trim() === expected, `Font subset checkout has the wrong commit: ${path}`);
|
|
40
|
-
assert(run('git', ['status', '--porcelain', '--untracked-files=no'], { cwd: path }).trim() === '', `Font subset checkout has tracked changes: ${path}`);
|
|
41
|
-
}
|
|
42
|
-
const invoke = (args) => run('bash', ['-c', 'set -e\nsource "$1" >/dev/null\nshift\nexec em++ "$@"', 'font-subset-build', join(emsdk, 'emsdk_env.sh'), ...args], { cwd: source });
|
|
43
|
-
assert(invoke(['--version']).split('\n')[0].includes(` ${spec.emsdk.version} `), 'Font subset Emscripten version differs');
|
|
44
|
-
mkdirSync(join(target, 'assets'), { recursive: true });
|
|
45
|
-
invoke(['-std=c++11', '-fno-exceptions', '-fno-rtti', '-fno-threadsafe-statics', '-fvisibility-inlines-hidden', '-Oz', '-I.',
|
|
46
|
-
'-DHB_TINY', '-DHB_USE_INTERNAL_QSORT', '-DHB_EXPERIMENTAL_API', '-DHB_CONFIG_OVERRIDE_H="config-override-subset.h"',
|
|
47
|
-
'--no-entry', '-sEXPORTED_FUNCTIONS=@harfbuzz-subset.symbols', '-sINITIAL_MEMORY=68157440',
|
|
48
|
-
'-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=2147483648', '-sABORTING_MALLOC=0',
|
|
49
|
-
'-o', join(target, wasmPath), 'harfbuzz/src/harfbuzz-subset.cc']);
|
|
50
|
-
const copies = [...recipeFiles.map(path => [join(root, path), `sources/font-subset/${path}`]),
|
|
51
|
-
[join(source, 'config-override-subset.h'), 'sources/font-subset/harfbuzzjs/config-override-subset.h'],
|
|
52
|
-
[join(source, 'harfbuzz-subset.symbols'), 'sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols'],
|
|
53
|
-
[join(source, 'LICENSE'), 'licenses/font-subset/harfbuzzjs-LICENSE'], [join(source, 'harfbuzz/COPYING'), 'licenses/font-subset/harfbuzz-COPYING']];
|
|
54
|
-
for (const [from, path] of copies) { mkdirSync(join(target, path, '..'), { recursive: true }); cpSync(from, join(target, path)); }
|
|
55
|
-
const files = Object.fromEntries(required.map(path => [path, { bytes: statSync(join(target, path)).size, sha256: sha256(join(target, path)) }]));
|
|
56
|
-
writeFileSync(join(target, receiptPath), `${JSON.stringify({ schemaVersion: 1, source: spec, recipe: sha256(join(root, recipePath)), files }, null, 2)}\n`);
|
|
57
|
-
return verifyFontSubset(target);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (isMain(import.meta.url)) {
|
|
61
|
-
const { values } = parseArgs({ options: { verify: { type: 'boolean' }, source: { type: 'string' }, emsdk: { type: 'string' }, target: { type: 'string' } } });
|
|
62
|
-
const options = Object.fromEntries(['source', 'emsdk', 'target'].filter(key => values[key]).map(key => [key, resolve(values[key])]));
|
|
63
|
-
console.log(JSON.stringify(values.verify ? verifyFontSubset(options.target) : buildFontSubset(options)));
|
|
64
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/** Local-only npm helpers shared by packaging and offline-install rehearsals. */
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, realpathSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { delimiter, dirname, join, resolve } from 'node:path';
|
|
4
|
-
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { root } from './platform-matrix.mjs';
|
|
6
|
-
|
|
7
|
-
export function scratch(prefix = 'packaging-') {
|
|
8
|
-
const parent = join(root, '.cache');
|
|
9
|
-
mkdirSync(parent, { recursive: true });
|
|
10
|
-
return mkdtempSync(join(parent, prefix));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function run(command, args, options = {}) {
|
|
14
|
-
const result = spawnSync(command, args, { encoding: 'utf8', timeout: 180_000, maxBuffer: 16 * 1024 * 1024, ...options });
|
|
15
|
-
if (result.error) throw result.error;
|
|
16
|
-
if (result.status !== 0) throw new Error(`${command} exited ${result.status} (${result.signal ?? 'no signal'}):\n${result.stderr}\n${result.stdout}`);
|
|
17
|
-
return result.stdout;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Invoke npm's JS CLI directly, including on Windows; no command shell is used. */
|
|
21
|
-
export function npmCli() {
|
|
22
|
-
const directories = [dirname(process.execPath), dirname(realpathSync(process.execPath)), ...(process.env.PATH ?? '').split(delimiter)];
|
|
23
|
-
const candidates = [process.env.npm_execpath];
|
|
24
|
-
for (const directory of directories) {
|
|
25
|
-
candidates.push(join(directory, 'node_modules/npm/bin/npm-cli.js'), resolve(directory, '../lib/node_modules/npm/bin/npm-cli.js'));
|
|
26
|
-
const link = join(directory, 'npm');
|
|
27
|
-
if (existsSync(link)) candidates.push(realpathSync(link));
|
|
28
|
-
}
|
|
29
|
-
const found = candidates.find((file) => file && /(?:^|[\\/])npm-cli\.js$/.test(file) && existsSync(file));
|
|
30
|
-
if (!found) throw new Error('npm-cli.js was not found next to Node or on PATH');
|
|
31
|
-
return found;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function npmEnvironment(work) {
|
|
35
|
-
const config = join(work, 'empty.npmrc');
|
|
36
|
-
const globalConfig = join(work, 'empty-global.npmrc');
|
|
37
|
-
writeFileSync(config, '');
|
|
38
|
-
writeFileSync(globalConfig, '');
|
|
39
|
-
return {
|
|
40
|
-
...Object.fromEntries(Object.entries(process.env).filter(([key]) => !/KEY|TOKEN|SECRET|PASSWORD|^NODE_OPTIONS$|^NODE_PATH$|^NPM_CONFIG_/i.test(key))),
|
|
41
|
-
npm_config_cache: join(work, 'npm-cache'),
|
|
42
|
-
npm_config_userconfig: config,
|
|
43
|
-
npm_config_globalconfig: globalConfig,
|
|
44
|
-
npm_config_audit: 'false',
|
|
45
|
-
npm_config_fund: 'false',
|
|
46
|
-
npm_config_update_notifier: 'false',
|
|
47
|
-
npm_config_registry: 'http://127.0.0.1:9',
|
|
48
|
-
npm_config_offline: 'true',
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function npm(args, cwd, work) {
|
|
53
|
-
return run(process.execPath, [npmCli(), ...args], { cwd, env: npmEnvironment(work) });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Resolve pnpm without invoking a Windows command shim through a shell. */
|
|
57
|
-
export function pnpmInvocation(args, environment = process.env, platform = process.platform) {
|
|
58
|
-
const entry = environment.npm_execpath;
|
|
59
|
-
if (entry && /(?:^|[\\/])pnpm\.[cm]?js$/i.test(entry)) return { command: process.execPath, args: [entry, ...args] };
|
|
60
|
-
if (entry && /(?:^|[\\/])pnpm(?:\.exe)?$/i.test(entry)) return { command: entry, args };
|
|
61
|
-
if (platform === 'win32') throw new Error('Invoke adapter builds and local packs through pnpm run on Windows.');
|
|
62
|
-
return { command: 'pnpm', args };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Run the pnpm lifecycle executable, retaining each argument without shell parsing. */
|
|
66
|
-
export function pnpm(args, options = {}) {
|
|
67
|
-
const invocation = pnpmInvocation(args);
|
|
68
|
-
return run(invocation.command, invocation.args, options);
|
|
69
|
-
}
|