@deepseek-ai/libreoffice-kit 0.1.4 → 0.2.0-alpha5
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 +4 -0
- package/README.md +49 -9
- package/README.zh.md +50 -10
- package/lib/cli.js +155 -52
- package/lib/editor.js +2061 -0
- package/lib/index.js +155 -52
- package/lib/types/editor-protocol.d.ts +29 -0
- package/lib/types/editor-transport.d.ts +36 -0
- package/lib/types/editor-types.d.ts +119 -0
- package/lib/types/editor.d.ts +105 -0
- package/lib/types/engine.d.ts +4 -2
- package/lib/types/fonts.d.ts +4 -8
- package/lib/types/native-image-renderer.d.ts +0 -1
- package/lib/types/native-process.d.ts +1 -0
- package/lib/types/native.d.ts +31 -2
- package/lib/types/rendering.d.ts +2 -0
- package/lib/types/runtime.d.ts +2 -0
- package/lib/types/sheet-geometry.d.ts +1 -1
- package/lib/types/worker.d.ts +2 -2
- package/lib/worker.js +51 -32
- package/native-render/CMakeLists.txt +40 -0
- package/native-render/LICENSE +21 -0
- package/native-render/README.md +83 -0
- package/native-render/README.zh.md +83 -0
- package/native-render/include/dsh_render.h +101 -0
- package/native-render/include/dsh_render_engine.h +66 -0
- package/native-render/include/dsh_render_node.h +27 -0
- package/native-render/include/dsh_webgpu.h +52 -0
- package/native-render/index.d.ts +145 -0
- package/native-render/index.mjs +71 -0
- package/native-render/lib/browser/display.d.ts +46 -0
- package/native-render/lib/browser/display.js +128 -0
- package/native-render/lib/browser/index.d.ts +4 -0
- package/native-render/lib/browser/index.js +3 -0
- package/native-render/lib/browser/painters.d.ts +9 -0
- package/native-render/lib/browser/painters.js +180 -0
- package/native-render/lib/browser/types.d.ts +51 -0
- package/native-render/lib/browser/types.js +1 -0
- package/native-render/lib/electron/adapter.d.ts +9 -0
- package/native-render/lib/electron/adapter.js +118 -0
- package/native-render/lib/electron/index.d.ts +3 -0
- package/native-render/lib/electron/index.js +3 -0
- package/native-render/lib/electron/preload.d.ts +13 -0
- package/native-render/lib/electron/preload.js +47 -0
- package/native-render/lib/electron/transfer.d.ts +15 -0
- package/native-render/lib/electron/transfer.js +36 -0
- package/native-render/prebuilds/darwin-arm64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-arm64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-arm64/render.node +0 -0
- package/native-render/prebuilds/darwin-x64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-x64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-x64/render.node +0 -0
- package/native-render/prebuilds/win32-arm64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-arm64/manifest.json +34 -0
- package/native-render/prebuilds/win32-arm64/render.node +0 -0
- package/native-render/prebuilds/win32-x64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-x64/manifest.json +34 -0
- package/native-render/prebuilds/win32-x64/render.node +0 -0
- package/native-render/receipt.json +23 -0
- package/native-render/scripts/build-webgpu.mjs +197 -0
- package/native-render/scripts/build.mjs +43 -0
- package/native-render/scripts/metadata.mjs +47 -0
- package/native-render/scripts/source-identity.mjs +15 -0
- package/native-render/scripts/verify-prebuilds.mjs +14 -0
- package/native-render/sdk.json +45 -0
- package/native-render/src/node-producer.cc +595 -0
- package/native-render/src/producer-internal.h +8 -0
- package/native-render/src/producer.cc +306 -0
- package/native-render/src/receiver.cc +1050 -0
- package/native-render/src/relay-transport.inc +293 -0
- package/native-render/src/transport.cc +405 -0
- package/native-render/src/transport.h +80 -0
- package/native-render/src/webgpu.cc +214 -0
- package/native-render/src/win-delay-load.LICENSE +24 -0
- package/native-render/src/win-delay-load.cc +43 -0
- package/native-render/verify.d.mts +4 -0
- package/native-render/verify.mjs +101 -0
- package/native-render/webgpu-dependencies.json +51 -0
- package/package.json +97 -11
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ConverterOptions } from './index.ts';
|
|
2
|
+
import type { EditorArguments, EditorCommand, EditorEvent, EditorInfo, EditorInput, EditorPixels, EditorRectangle, EditorPaintRectangle, EditorViewport, OfficeFormat, PresentationControl } from './editor-types.ts';
|
|
3
|
+
export type { EditorArguments, EditorCommand, EditorEvent, EditorInfo, EditorInput, EditorPixels, EditorRectangle, EditorPaintRectangle, EditorViewport, OfficeFormat, PresentationControl } from './editor-types.ts';
|
|
4
|
+
/** Native loading phases before the document becomes available for rendering. */
|
|
5
|
+
export type EditorLoadingStage = 'fonts' | 'engine' | 'document';
|
|
6
|
+
/** Caller-owned bytes are copied before opening; native export never overwrites the caller's source. */
|
|
7
|
+
export interface OpenDocumentOptions {
|
|
8
|
+
readonly bytes: Uint8Array;
|
|
9
|
+
readonly format: OfficeFormat;
|
|
10
|
+
/**
|
|
11
|
+
* Select before native document initialization. `auto` prefers LibreOffice's Skia Ganesh GPU
|
|
12
|
+
* backend (Vulkan on Windows, Metal on macOS) and keeps rendering on the CPU when the driver is
|
|
13
|
+
* denylisted or the GPU context is unavailable; `ganesh` requires that backend, `graphite`
|
|
14
|
+
* selects the experimental Dawn recorder, and `raster` forces CPU drawing for diagnostics.
|
|
15
|
+
*/
|
|
16
|
+
readonly renderBackend?: 'auto' | 'ganesh' | 'graphite' | 'raster';
|
|
17
|
+
/** Combined Graphite context/recorder cache budget; excludes live GPU resources and display textures. Default 128 MiB. */
|
|
18
|
+
readonly graphiteCacheBytes?: number;
|
|
19
|
+
/** Only literal true permits input, content commands, and snapshots. Default is read-only. */
|
|
20
|
+
readonly writable?: boolean;
|
|
21
|
+
/** Cancels the whole document lifetime; call close() to await filesystem cleanup. */
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
/** Reports actual loading phases; observer failures are warnings and do not abort loading. */
|
|
24
|
+
readonly onProgress?: (stage: EditorLoadingStage) => void;
|
|
25
|
+
/** The converter's font/size settings and per-operation timeout also govern editing. */
|
|
26
|
+
readonly options?: ConverterOptions;
|
|
27
|
+
}
|
|
28
|
+
/** A snapshot identifies exactly the serialized document revision; later input remains unsaved. */
|
|
29
|
+
export interface EditorSnapshot {
|
|
30
|
+
readonly bytes: Uint8Array;
|
|
31
|
+
readonly format: OfficeFormat;
|
|
32
|
+
readonly revision: number;
|
|
33
|
+
}
|
|
34
|
+
/** Correlation fields for a shared image delivered through the DSH native SDK. */
|
|
35
|
+
export interface EditorSurfaceRequest {
|
|
36
|
+
readonly requestId: string;
|
|
37
|
+
readonly generation: number;
|
|
38
|
+
readonly tileKey?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Shared rendering reply contains no pixel bytes; the SDK delivers the matching image. */
|
|
41
|
+
export interface EditorSurfaceResult {
|
|
42
|
+
readonly shared: true;
|
|
43
|
+
readonly requestId: string;
|
|
44
|
+
readonly width: number;
|
|
45
|
+
readonly height: number;
|
|
46
|
+
readonly revision: number;
|
|
47
|
+
readonly part?: number;
|
|
48
|
+
readonly ended?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** One in-memory document with ordered operations and explicit process ownership. */
|
|
51
|
+
export interface EditorDocument {
|
|
52
|
+
/** Owned native PID, usable only by a trusted local transport broker. */
|
|
53
|
+
readonly processId: number;
|
|
54
|
+
readonly initialInfo: EditorInfo;
|
|
55
|
+
readonly missingFonts: readonly string[];
|
|
56
|
+
readonly writable: boolean;
|
|
57
|
+
/** Current observed content revision, monotonically increasing within this document. */
|
|
58
|
+
readonly revision: number;
|
|
59
|
+
/** Subscribe to transient engine callbacks and process failure; returns an unsubscribe function. */
|
|
60
|
+
onEvent(listener: (event: EditorEvent) => void): () => void;
|
|
61
|
+
/** Connect to a private SDK receiver already bound to processId. */
|
|
62
|
+
attachSurfaceTransport(endpoint: string): Promise<void>;
|
|
63
|
+
/** Disconnect shared rendering and input while retaining the editable document. */
|
|
64
|
+
detachSurfaceTransport(): Promise<void>;
|
|
65
|
+
/** Wait for the canonical direct-input sequence before the next business operation. */
|
|
66
|
+
waitForInput(sequence: number): Promise<void>;
|
|
67
|
+
/** Render a document tile into a shared BGRA surface; no pixel bytes cross stdout. */
|
|
68
|
+
renderSurface(rectangle: EditorPaintRectangle, pixelWidth: number, pixelHeight: number, surface: EditorSurfaceRequest): Promise<EditorSurfaceResult>;
|
|
69
|
+
/** Submit one animated presentation image through the shared SDK transport. */
|
|
70
|
+
presentationSurface(surface: EditorSurfaceRequest): Promise<EditorSurfaceResult>;
|
|
71
|
+
/** Read current dimensions, parts, and page rectangles after queued operations. */
|
|
72
|
+
getInfo(): Promise<EditorInfo>;
|
|
73
|
+
/** Dispatch a whitelisted command, waiting for layout and command completion. */
|
|
74
|
+
dispatch(command: EditorCommand, arguments_?: EditorArguments): Promise<void>;
|
|
75
|
+
/** Deliver one ordered input event, including native composition updates or committed paste. */
|
|
76
|
+
input(event: EditorInput): Promise<void>;
|
|
77
|
+
/** Set client scale and the visible document rectangle without changing page layout. */
|
|
78
|
+
setViewport(viewport: EditorViewport): Promise<void>;
|
|
79
|
+
/** Change the current sheet or slide and return its dimensions. */
|
|
80
|
+
setPart(part: number): Promise<EditorInfo>;
|
|
81
|
+
/** Render one document rectangle at the requested physical pixel dimensions. */
|
|
82
|
+
render(rectangle: EditorPaintRectangle, pixelWidth: number, pixelHeight: number): Promise<EditorPixels>;
|
|
83
|
+
/** Read the native selection as text or HTML without changing the document. */
|
|
84
|
+
getSelection(mime: 'text/plain;charset=utf-8' | 'text/html'): Promise<string>;
|
|
85
|
+
/** Query Calc geometry or font names; the returned JSON follows LibreOfficeKit's documented command. */
|
|
86
|
+
getValues(command: 'SheetGeometryData' | 'CharFontName'): Promise<string>;
|
|
87
|
+
/** Query Calc row/column boundaries for a required document area in twips; sizes in the returned JSON are pixels. */
|
|
88
|
+
getValues(command: 'ViewRowColumnHeaders', area: EditorRectangle): Promise<string>;
|
|
89
|
+
/** Control native Impress playback; stop it before sending content input. */
|
|
90
|
+
presentation(control: PresentationControl): Promise<void>;
|
|
91
|
+
/** Advance playback to the native clock and return the current complete frame. */
|
|
92
|
+
presentationFrame(): Promise<EditorPixels>;
|
|
93
|
+
/** Export and validate a fresh original-format snapshot after all previously accepted edits. */
|
|
94
|
+
exportSnapshot(): Promise<EditorSnapshot>;
|
|
95
|
+
/** Stop accepting requests, join queued work/process exit, then remove the private directory. Idempotent. */
|
|
96
|
+
close(): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Open an isolated native document from an owned, seekable memory stream, preparing its fonts.
|
|
100
|
+
* @param request - Validated-format bytes and explicit editing permission.
|
|
101
|
+
* @returns A live document; the caller must close it even after process failure.
|
|
102
|
+
* @throws If the matching native engine is missing, the input is invalid, or opening times out.
|
|
103
|
+
*/
|
|
104
|
+
export declare function openDocument(request: OpenDocumentOptions): Promise<EditorDocument>;
|
|
105
|
+
//# sourceMappingURL=editor.d.ts.map
|
package/lib/types/engine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Node API release version returned by runtime discovery. */
|
|
2
|
-
export declare const ENGINE_VERSION = "0.
|
|
2
|
+
export declare const ENGINE_VERSION = "0.2.0-alpha5";
|
|
3
3
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
4
4
|
export declare const ENGINE_VERSIONS: Readonly<Record<string, string>>;
|
|
5
5
|
/** Host diagnostic fields used to identify the runtime glibc version. */
|
|
@@ -27,6 +27,8 @@ interface EngineInstallation {
|
|
|
27
27
|
export interface NativeEngine extends EngineInstallation {
|
|
28
28
|
readonly backend: 'native';
|
|
29
29
|
readonly executable: string;
|
|
30
|
+
/** Older pinned helpers load private files and do not implement the native preview protocol. */
|
|
31
|
+
readonly legacyInputPath?: true;
|
|
30
32
|
}
|
|
31
33
|
/** A resolved shared Node WebAssembly engine. */
|
|
32
34
|
export interface WasmEngine extends EngineInstallation {
|
|
@@ -55,7 +57,7 @@ export declare function installedPackageExists(name: string): boolean;
|
|
|
55
57
|
*/
|
|
56
58
|
export declare function platformTarget(platform?: string, arch?: string, report?: () => EngineHostReport): string | undefined;
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
60
|
+
* Prefer the installed compatible native engine; hosts without one use the shared WASM package.
|
|
59
61
|
* @param resolvePackage - Package manifest resolver; injectable for selection tests.
|
|
60
62
|
* @param packageExists - Installed-package probe; injectable for selection tests.
|
|
61
63
|
* @param host - Process identification and diagnostic report.
|
package/lib/types/fonts.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface FontFace {
|
|
|
18
18
|
readonly italic: boolean;
|
|
19
19
|
readonly fixed: boolean;
|
|
20
20
|
readonly postscriptName: string | null;
|
|
21
|
-
/**
|
|
21
|
+
/** Optional complete glyph ranges supplied by the metadata owner. */
|
|
22
22
|
coverage?: GlyphRange[];
|
|
23
23
|
}
|
|
24
24
|
/** All faces decoded from one unchanged physical file, including an empty parse result. */
|
|
@@ -88,19 +88,13 @@ export declare function systemFontDirectories(platform?: NodeJS.Platform, home?:
|
|
|
88
88
|
* @throws when the root exists but cannot be read for a reason other than its absence or protection.
|
|
89
89
|
*/
|
|
90
90
|
export declare function mobileAssetFontDirectories(assets: string): string[];
|
|
91
|
-
/**
|
|
92
|
-
* Decode glyph coverage for one parsed face.
|
|
93
|
-
* @param font - The parsed physical face.
|
|
94
|
-
* @returns the inclusive ranges the face renders, or none when its glyph tables reject decoding.
|
|
95
|
-
*/
|
|
96
|
-
export declare function faceCoverage(font: Font): GlyphRange[];
|
|
97
91
|
/**
|
|
98
92
|
* @param parsed - Parsed font file: one face, or a collection of faces.
|
|
99
93
|
* @param face - Indexed metadata naming the face inside that file.
|
|
100
94
|
* @returns the physical face the index names.
|
|
101
95
|
* @throws when the file no longer provides the indexed face.
|
|
102
96
|
*/
|
|
103
|
-
export declare function indexedFace(parsed: Font | FontCollection, face: Pick<FontFace, 'faceIndex' | 'postscriptName'>): Font;
|
|
97
|
+
export declare function indexedFace(parsed: Font | Pick<FontCollection, 'fonts'>, face: Pick<FontFace, 'faceIndex' | 'postscriptName'>): Font;
|
|
104
98
|
/**
|
|
105
99
|
* VCL weight, width, and fixed-pitch values for one parsed face.
|
|
106
100
|
* @param font - The parsed physical face, whose `OS/2` and `post` tables may be absent.
|
|
@@ -123,6 +117,8 @@ export declare function indexSystemFonts(options: FontIndexOptions, previous?: R
|
|
|
123
117
|
export declare class SystemFontCatalog {
|
|
124
118
|
private readonly options;
|
|
125
119
|
private readonly faces;
|
|
120
|
+
private readonly queried;
|
|
121
|
+
private readonly byFile;
|
|
126
122
|
/**
|
|
127
123
|
* @param options - Host metadata snapshot and fallback families.
|
|
128
124
|
*/
|
|
@@ -6,7 +6,6 @@ import type { ResolvedOptions } from './options.ts';
|
|
|
6
6
|
export declare function renderImagesWithNative(request: {
|
|
7
7
|
readonly engine: NativeEngine;
|
|
8
8
|
readonly options: ResolvedOptions;
|
|
9
|
-
readonly inputPath: string;
|
|
10
9
|
readonly source: Uint8Array;
|
|
11
10
|
readonly scratch: string;
|
|
12
11
|
readonly profile: string;
|
|
@@ -5,6 +5,7 @@ export interface NativeChild extends EventEmitter {
|
|
|
5
5
|
stdin: Writable;
|
|
6
6
|
stdout: Readable;
|
|
7
7
|
stderr: Readable;
|
|
8
|
+
readonly pid?: number | undefined;
|
|
8
9
|
readonly exitCode: number | null;
|
|
9
10
|
readonly signalCode: NodeJS.Signals | null;
|
|
10
11
|
kill(signal: NodeJS.Signals): boolean;
|
package/lib/types/native.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { ResolvedOptions } from './options.ts';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function prepareNativeFontProfile(profile: string, substitutions: readonly FontSubstitution[]): Promise<void>;
|
|
13
13
|
/**
|
|
14
|
+
* Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
|
|
14
15
|
* Linux searches the verified program directory; ambient loader overrides and credentials are excluded.
|
|
15
16
|
* @param profile - Conversion-owned profile directory the helper treats as home.
|
|
16
17
|
* @param programDirectory - Verified engine program directory.
|
|
@@ -19,6 +20,16 @@ export declare function prepareNativeFontProfile(profile: string, substitutions:
|
|
|
19
20
|
* @returns the environment the helper starts with.
|
|
20
21
|
*/
|
|
21
22
|
export declare function nativeEnvironment(profile: string, programDirectory: string, source?: NodeJS.ProcessEnv, platform?: string): Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Prepare short Windows engine paths owned by the caller's private profile.
|
|
25
|
+
* @param engine - Verified engine installation; its resources remain in place.
|
|
26
|
+
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
27
|
+
* @returns Engine paths and a release function to call once, after the helper closes and before removing the profile.
|
|
28
|
+
*/
|
|
29
|
+
export declare function prepareNativeEngine(engine: NativeEngine, profile: string): Promise<{
|
|
30
|
+
engine: NativeEngine;
|
|
31
|
+
release(): Promise<void>;
|
|
32
|
+
}>;
|
|
22
33
|
/**
|
|
23
34
|
* Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
|
|
24
35
|
* @param engine - Verified engine installation; its resources remain in place.
|
|
@@ -27,11 +38,26 @@ export declare function nativeEnvironment(profile: string, programDirectory: str
|
|
|
27
38
|
* @returns The operation result after removing the resource junction.
|
|
28
39
|
*/
|
|
29
40
|
export declare function withNativeEngine<T>(engine: NativeEngine, profile: string, run: (engine: NativeEngine) => Promise<T>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Prepare the document transport accepted by the pinned helper.
|
|
43
|
+
* @param engine - Resolved helper and input protocol.
|
|
44
|
+
* @param input - Owned document bytes and validated format.
|
|
45
|
+
* @param profile - Private directory retained until the helper exits and removed by the operation owner.
|
|
46
|
+
* @param signal - Cancellation of input preparation.
|
|
47
|
+
* @returns Helper arguments and an optional binary stdin prefix.
|
|
48
|
+
*/
|
|
49
|
+
export declare function prepareNativeInput(engine: NativeEngine, input: {
|
|
50
|
+
bytes: Uint8Array;
|
|
51
|
+
format: string;
|
|
52
|
+
}, profile: string, signal: AbortSignal): Promise<{
|
|
53
|
+
args: string[];
|
|
54
|
+
bytes?: Uint8Array;
|
|
55
|
+
}>;
|
|
30
56
|
/**
|
|
31
57
|
* Run one native conversion and await bounded result transport.
|
|
32
58
|
* @param engine - Resolved native engine installation.
|
|
33
59
|
* @param options - Validated conversion limits.
|
|
34
|
-
* @param input -
|
|
60
|
+
* @param input - Owned source bytes and format; older pinned helpers receive a private input file.
|
|
35
61
|
* @param output - Private PDF path inside the conversion scratch directory.
|
|
36
62
|
* @param profile - Conversion-owned profile directory.
|
|
37
63
|
* @param fonts - Installed font files the helper may load.
|
|
@@ -40,5 +66,8 @@ export declare function withNativeEngine<T>(engine: NativeEngine, profile: strin
|
|
|
40
66
|
* @param operation - Validated output format, recalculation, and worksheet selection.
|
|
41
67
|
* @throws ConversionError for a reported conversion failure, and the abort reason for cancellation.
|
|
42
68
|
*/
|
|
43
|
-
export declare function runNative(engine: NativeEngine, options: ResolvedOptions, input:
|
|
69
|
+
export declare function runNative(engine: NativeEngine, options: ResolvedOptions, input: {
|
|
70
|
+
bytes: Uint8Array;
|
|
71
|
+
format: string;
|
|
72
|
+
}, output: string, profile: string, fonts: readonly string[], substitutions: readonly FontSubstitution[], signal: AbortSignal, operation?: Pick<ConversionSpec, 'format' | 'recalculate' | 'sheet'>): Promise<void>;
|
|
44
73
|
//# sourceMappingURL=native.d.ts.map
|
package/lib/types/rendering.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface RasterTile {
|
|
|
22
22
|
readonly height: number;
|
|
23
23
|
readonly rgba: Uint8ClampedArray;
|
|
24
24
|
}
|
|
25
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
26
|
+
export declare function unmirrorRtlTile({ width, height, rgba }: RasterTile): void;
|
|
25
27
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
26
28
|
export declare function splitRasterRectangle(rectangle: Rectangle, scale: number, limits: {
|
|
27
29
|
readonly maxPixels: number;
|
package/lib/types/runtime.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export interface RuntimeInfo {
|
|
3
3
|
readonly version: string;
|
|
4
4
|
readonly backend: 'native' | 'wasm';
|
|
5
|
+
/** Whether the selected engine implements the native preview protocol; independent of GPU availability. */
|
|
6
|
+
readonly nativePreview: boolean;
|
|
5
7
|
readonly cliPath: string;
|
|
6
8
|
readonly nodeApiPath: string;
|
|
7
9
|
}
|
|
@@ -32,7 +32,7 @@ export declare function parseCellRange(value: string): CellRange;
|
|
|
32
32
|
export declare function sheetPartInfo(value: string): SheetPartInfo;
|
|
33
33
|
/** Formatting-only cells and standalone drawings do not enlarge LibreOffice's data area. */
|
|
34
34
|
export declare function dataArea(info: SheetPartInfo): CellRange;
|
|
35
|
-
/** Logical columns advance from A;
|
|
35
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
36
36
|
export declare function sheetRangeRectangle(geometry: SheetGeometry, range: CellRange, scale: number): Rectangle;
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=sheet-geometry.d.ts.map
|
package/lib/types/worker.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { ConversionSpec } from './operations.ts';
|
|
|
4
4
|
import type { Engine } from './engine.ts';
|
|
5
5
|
import type { FontFace } from './fonts.ts';
|
|
6
6
|
import type { ResolvedOptions } from './options.ts';
|
|
7
|
-
/** Worker input:
|
|
7
|
+
/** Worker input: owned source bytes, validated limits, the resolved engine, and the current font snapshot. */
|
|
8
8
|
export interface WorkerRequest {
|
|
9
|
-
readonly
|
|
9
|
+
readonly bytes: Uint8Array;
|
|
10
10
|
readonly extension: string;
|
|
11
11
|
readonly operation: ConversionSpec | ImageRenderSpec;
|
|
12
12
|
readonly options: ResolvedOptions;
|
package/lib/worker.js
CHANGED
|
@@ -119,28 +119,6 @@ function fontFamilyPriority(requested, groups, pitch = 0, symbols = false) {
|
|
|
119
119
|
}
|
|
120
120
|
return [...priority.values()];
|
|
121
121
|
}
|
|
122
|
-
function ranges(font) {
|
|
123
|
-
const points = font.characterSet.filter((point) => font.hasGlyphForCodePoint(point)).sort((left, right) => left - right);
|
|
124
|
-
const result = [];
|
|
125
|
-
for (const point of points) {
|
|
126
|
-
const last = result.at(-1);
|
|
127
|
-
if (last !== void 0 && point <= last[1] + 1) last[1] = Math.max(last[1], point);
|
|
128
|
-
else result.push([point, point]);
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Decode glyph coverage for one parsed face.
|
|
134
|
-
* @param font - The parsed physical face.
|
|
135
|
-
* @returns the inclusive ranges the face renders, or none when its glyph tables reject decoding.
|
|
136
|
-
*/
|
|
137
|
-
function faceCoverage(font) {
|
|
138
|
-
try {
|
|
139
|
-
return ranges(font);
|
|
140
|
-
} catch {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
122
|
/**
|
|
145
123
|
* @param parsed - Parsed font file: one face, or a collection of faces.
|
|
146
124
|
* @param face - Indexed metadata naming the face inside that file.
|
|
@@ -152,12 +130,6 @@ function indexedFace(parsed, face) {
|
|
|
152
130
|
if (font === void 0 || font.postscriptName !== face.postscriptName) throw new Error("The indexed font face is no longer available; recreate the converter.");
|
|
153
131
|
return font;
|
|
154
132
|
}
|
|
155
|
-
function covers(face, points) {
|
|
156
|
-
if (points.length === 0) return [];
|
|
157
|
-
if (face.coverage === void 0) face.coverage = faceCoverage(indexedFace(create(readFont(face)), face));
|
|
158
|
-
const coverage = face.coverage;
|
|
159
|
-
return points.filter((point) => coverage.some(([first, last]) => point >= first && point <= last));
|
|
160
|
-
}
|
|
161
133
|
function regionalPriority(face, language) {
|
|
162
134
|
const locale = language.toLowerCase();
|
|
163
135
|
const preferred = locale.startsWith("ja") ? ["jp"] : locale.startsWith("ko") ? ["kr"] : locale.startsWith("zh") ? /hant|tw|hk|mo/.test(locale) ? ["tc", "hk"] : ["sc"] : [];
|
|
@@ -169,12 +141,19 @@ function regionalPriority(face, language) {
|
|
|
169
141
|
var SystemFontCatalog = class {
|
|
170
142
|
options;
|
|
171
143
|
faces;
|
|
144
|
+
queried = /* @__PURE__ */ new Map();
|
|
145
|
+
byFile = /* @__PURE__ */ new Map();
|
|
172
146
|
/**
|
|
173
147
|
* @param options - Host metadata snapshot and fallback families.
|
|
174
148
|
*/
|
|
175
149
|
constructor(options) {
|
|
176
150
|
this.options = options;
|
|
177
151
|
this.faces = options.faces.map((face) => ({ ...face }));
|
|
152
|
+
for (const face of this.faces) {
|
|
153
|
+
const members = this.byFile.get(face.path) ?? [];
|
|
154
|
+
members.push(face);
|
|
155
|
+
this.byFile.set(face.path, members);
|
|
156
|
+
}
|
|
178
157
|
}
|
|
179
158
|
/**
|
|
180
159
|
* Find installed faces covering the requested family or missing characters.
|
|
@@ -208,7 +187,36 @@ var SystemFontCatalog = class {
|
|
|
208
187
|
const files = /* @__PURE__ */ new Set();
|
|
209
188
|
for (const { face } of ranked) {
|
|
210
189
|
signal.throwIfAborted();
|
|
211
|
-
|
|
190
|
+
let covered;
|
|
191
|
+
if (face.coverage !== void 0) {
|
|
192
|
+
const coverage = face.coverage;
|
|
193
|
+
covered = [...missing].filter((point) => coverage.some(([first, last]) => point >= first && point <= last));
|
|
194
|
+
} else {
|
|
195
|
+
let known = this.queried.get(face);
|
|
196
|
+
if (known === void 0) {
|
|
197
|
+
known = /* @__PURE__ */ new Map();
|
|
198
|
+
this.queried.set(face, known);
|
|
199
|
+
}
|
|
200
|
+
const unknown = [...missing].filter((point) => !known.has(point));
|
|
201
|
+
if (unknown.length > 0) {
|
|
202
|
+
const parsed = create(readFont(face));
|
|
203
|
+
const collection = "fonts" in parsed ? { fonts: parsed.fonts } : parsed;
|
|
204
|
+
for (const member of this.byFile.get(face.path)) {
|
|
205
|
+
let answers = this.queried.get(member);
|
|
206
|
+
if (answers === void 0) {
|
|
207
|
+
answers = /* @__PURE__ */ new Map();
|
|
208
|
+
this.queried.set(member, answers);
|
|
209
|
+
}
|
|
210
|
+
const font = indexedFace(collection, member);
|
|
211
|
+
try {
|
|
212
|
+
for (const point of unknown) answers.set(point, font.hasGlyphForCodePoint(point));
|
|
213
|
+
} catch {
|
|
214
|
+
for (const point of unknown) answers.set(point, false);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
covered = [...missing].filter((point) => known.get(point));
|
|
219
|
+
}
|
|
212
220
|
if (missing.size > 0 && covered.length === 0) continue;
|
|
213
221
|
if (!files.has(face.path)) {
|
|
214
222
|
selected.push(face);
|
|
@@ -860,6 +868,17 @@ async function convertWithWasm(request) {
|
|
|
860
868
|
};
|
|
861
869
|
});
|
|
862
870
|
}
|
|
871
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
872
|
+
function unmirrorRtlTile({ width, height, rgba }) {
|
|
873
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < Math.floor(width / 2); x++) {
|
|
874
|
+
const left = (y * width + x) * 4, right = (y * width + width - 1 - x) * 4;
|
|
875
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
876
|
+
const value = rgba[left + channel];
|
|
877
|
+
rgba[left + channel] = rgba[right + channel];
|
|
878
|
+
rgba[right + channel] = value;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
863
882
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
864
883
|
function splitRasterRectangle(rectangle, scale, limits) {
|
|
865
884
|
const { x, y, width, height } = rectangle;
|
|
@@ -1121,7 +1140,7 @@ function dimension(data, first, last, maximum, scale) {
|
|
|
1121
1140
|
}
|
|
1122
1141
|
return [start / scale, (position - start) / scale];
|
|
1123
1142
|
}
|
|
1124
|
-
/** Logical columns advance from A;
|
|
1143
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
1125
1144
|
function sheetRangeRectangle(geometry, range, scale) {
|
|
1126
1145
|
if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
|
|
1127
1146
|
const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
|
|
@@ -1357,6 +1376,7 @@ async function renderImagesWithWasm(request) {
|
|
|
1357
1376
|
...region.rectangle,
|
|
1358
1377
|
scale
|
|
1359
1378
|
}, [region.page], () => engineError(session.module, session.office), session.pdf);
|
|
1379
|
+
if (region.rtl) unmirrorRtlTile(tile);
|
|
1360
1380
|
const png = encodePng(tile.width, tile.height, tile.rgba);
|
|
1361
1381
|
total += png.length;
|
|
1362
1382
|
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
@@ -1409,8 +1429,7 @@ function requireParentPort(port) {
|
|
|
1409
1429
|
}
|
|
1410
1430
|
const port = requireParentPort(parentPort);
|
|
1411
1431
|
try {
|
|
1412
|
-
const {
|
|
1413
|
-
const bytes = readFileSync(inputPath);
|
|
1432
|
+
const { bytes, extension, operation, options, engine, scratch, fontFaces, fontCache } = workerData;
|
|
1414
1433
|
const images = "kind" in operation && operation.kind === "images";
|
|
1415
1434
|
if (images && extension === "pdf" && new TextDecoder().decode(bytes.subarray(0, 5)) !== "%PDF-") throw new ConversionError("invalid-document", "Input does not contain a PDF header.");
|
|
1416
1435
|
const document = images && extension === "pdf" ? {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/sdk.json" DSH_RENDER_METADATA)
|
|
3
|
+
string(JSON DSH_RENDER_VERSION GET "${DSH_RENDER_METADATA}" version)
|
|
4
|
+
string(REGEX REPLACE "-.*$" "" DSH_RENDER_CMAKE_VERSION "${DSH_RENDER_VERSION}")
|
|
5
|
+
project(dsh_render VERSION ${DSH_RENDER_CMAKE_VERSION} LANGUAGES CXX)
|
|
6
|
+
add_library(dsh_render_sdk STATIC src/producer.cc src/transport.cc)
|
|
7
|
+
target_compile_features(dsh_render_sdk PUBLIC cxx_std_17)
|
|
8
|
+
target_include_directories(dsh_render_sdk PUBLIC include PRIVATE src)
|
|
9
|
+
set_target_properties(dsh_render_sdk PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
10
|
+
target_compile_options(dsh_render_sdk PRIVATE $<$<PLATFORM_ID:Windows>:/EHsc>)
|
|
11
|
+
if(APPLE)
|
|
12
|
+
target_link_libraries(dsh_render_sdk PUBLIC "-framework IOSurface" "-framework CoreFoundation" bsm)
|
|
13
|
+
elseif(WIN32)
|
|
14
|
+
target_compile_definitions(dsh_render_sdk PUBLIC _WIN32_WINNT=0x0602)
|
|
15
|
+
target_link_libraries(dsh_render_sdk PUBLIC d3d11 dxgi advapi32)
|
|
16
|
+
else()
|
|
17
|
+
message(FATAL_ERROR "DSH native render requires macOS or Windows")
|
|
18
|
+
endif()
|
|
19
|
+
install(TARGETS dsh_render_sdk ARCHIVE DESTINATION lib)
|
|
20
|
+
install(FILES include/dsh_render.h include/dsh_render_engine.h include/dsh_render_node.h DESTINATION include)
|
|
21
|
+
|
|
22
|
+
option(DSH_RENDER_WEBGPU "Build the native WebGPU producer adapter" OFF)
|
|
23
|
+
if(DSH_RENDER_WEBGPU)
|
|
24
|
+
if(NOT DSH_DAWN_SOURCE_DIR)
|
|
25
|
+
message(FATAL_ERROR "Use scripts/build-webgpu.mjs to prepare the pinned Dawn sources")
|
|
26
|
+
endif()
|
|
27
|
+
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
|
28
|
+
set(DAWN_BUILD_MONOLITHIC_LIBRARY STATIC CACHE STRING "" FORCE)
|
|
29
|
+
set(DAWN_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
|
30
|
+
add_subdirectory("${DSH_DAWN_SOURCE_DIR}" dawn)
|
|
31
|
+
set_target_properties(webgpu_dawn PROPERTIES OUTPUT_NAME dawn)
|
|
32
|
+
add_library(dsh_webgpu STATIC src/webgpu.cc)
|
|
33
|
+
target_compile_features(dsh_webgpu PUBLIC cxx_std_20)
|
|
34
|
+
target_include_directories(dsh_webgpu PUBLIC include)
|
|
35
|
+
target_link_libraries(dsh_webgpu PUBLIC dsh_render_sdk dawn::webgpu_dawn)
|
|
36
|
+
set_target_properties(dsh_webgpu PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
37
|
+
target_compile_options(dsh_webgpu PRIVATE $<$<PLATFORM_ID:Windows>:/EHsc>)
|
|
38
|
+
install(TARGETS dsh_webgpu ARCHIVE DESTINATION lib)
|
|
39
|
+
install(FILES include/dsh_webgpu.h DESTINATION include)
|
|
40
|
+
endif()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Native rendering SDK
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
The `@deepseek-ai/libreoffice-kit/native-render` package connects an authorized native producer to Electron Main without routing pixels through DSH Host. This public Kit subpath contains Node/TypeScript producer and receiver APIs backed by the same Electron-independent C/C++ SDK. Its payload includes explicitly listed C/C++ build sources; source globs and source maps are excluded. macOS uses IOSurface with Mach port transfer; Windows uses D3D11 shared NT handles and an owner-only named pipe. Separate browser and Electron subpaths provide presentation and texture ownership; consumers own authorization and application commands.
|
|
6
|
+
|
|
7
|
+
Installing Kit with `--omit=optional` provides the SDK without Office engines or the Windows Office pipe dependency Koffi. Normal installation retains both optional dependency selections. Neither SDK installation nor SDK communication compiles or downloads binaries.
|
|
8
|
+
|
|
9
|
+
## Receiver
|
|
10
|
+
|
|
11
|
+
Create one `createBudget(maxBytes)` per window and pass it to every `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`. Start the owned producer through its normal application lifecycle, bind its PID once with `bindProducer(pid)`, and pass the private `endpoint` directly to that producer. The endpoint contains authentication credentials and must never reach the Renderer or logs.
|
|
12
|
+
|
|
13
|
+
Frame events carry `transport: "shared-texture"`, an eight-byte native handle, the producer's `frameId`, and a receiver-owned `deliveryId`. Call `release(deliveryId)` only after Electron reports `allReferencesReleased`; queue submission and frame timeout do not release consumer ownership. Delivery IDs remain distinct when a producer reuses a released frame ID. Duplicate releases return false. `close()` asynchronously drains submitted GPU work and joins the owned workers; delivered resources remain retained until release or receiver destruction. A stalled GPU can keep close pending; cancellation never frees resources still used by that GPU.
|
|
14
|
+
|
|
15
|
+
Windows shared-texture receivers require the compositor’s actual adapter LUID in `displayAdapter`; creating one without it fails. The producer reports its device LUID during authentication, and the receiver verifies it against each texture. For matching adapters, keyed producer textures are imported directly; legacy textures are copied into a receiver-owned shared target. `sourceKeyedMutex` reports the actual source descriptor, independent of the handshake declaration. For different adapters, a native worker reads back the entire source texture and uploads its premultiplied BGRA pixels into a shared texture on the compositor’s adapter. JavaScript receives only its handle. `adapterId` identifies the source; `presentationAdapterId` identifies the exported texture’s adapter and is null for macOS IOSurface.
|
|
16
|
+
|
|
17
|
+
The receiver’s Windows target uses a keyed mutex recognized by Chromium to order GPU access; Electron’s reference-release callback controls lifetime but does not replace this synchronization. Cross-adapter copies preserve row pitch and return source credit as soon as the readback GPU copy completes; the independent target remains held until Electron releases its delivery. Same-adapter copying and macOS IOSurface retain source credit through delivery release. GPU completion uses reusable fence events when supported and bounded query polling otherwise. `readbackTimeoutMs` bounds native frame preparation and delivery; timeout or cancellation stops new work while retaining submitted copies until GPU completion or device removal. Worker termination and receiver garbage collection use the same asynchronous cleanup.
|
|
18
|
+
|
|
19
|
+
[Chromium 152 acquires key 0 with `INFINITE`](https://github.com/chromium/chromium/blob/24072c1aa400ec4a89dc738b6b6acd12a8589b6f/gpu/command_buffer/service/dxgi_shared_handle_manager.cc#L129). Before direct handoff, the receiver worker performs a bounded acquire/release readiness check. This moves a possible CPU wait to that worker without copying pixels; it does not impose a timeout on Chromium. A producer must release before submitting and must not access the surface until credit returns. A producer that violates this after the check can still stall Chromium or trigger its GPU watchdog.
|
|
20
|
+
|
|
21
|
+
Shared-texture `framePolicy` defaults to `ordered`, preserving independent request/reply frames such as Office tiles. Continuous streams may select `latest`: a completed relay readback replaces the frame whose upload has not begun, with at most one pending frame and one upload in progress. Two staging slots allow source copying while a prepared frame waits for a target. Held targets stop further uploads; ordered delivery also stops readback when both staging slots are occupied.
|
|
22
|
+
|
|
23
|
+
The byte budget reserves one surface per macOS allocation or declared Windows same-adapter keyed allocation. A legacy same-adapter allocation reserves a source plus target. The optional hello capability permits the smaller reservation; a declared keyed producer that supplies a non-keyed texture is rejected. An undeclared keyed source can still be imported directly, with the conservative legacy reservation. Relay reserves up to `N = maxFrames` source textures, `N` independent targets, and two staging textures. Target and staging capacity tracks the connection's largest requested frame; source and pool growth receive one atomic budget grant. Relay limits each frame to `maxBytes / (2N + 2)` bytes and advertises `N` times that allowance to the producer. With three frames and 256 MiB, three 4K BGRA sources plus the five receiver textures reserve 253.125 MiB. Idle storage retains its reservation; closing frees independent pool slots while each held target retains its own budget until release. Renderer queues and canvas storage have separate limits; this budget is not a process-memory ceiling.
|
|
24
|
+
|
|
25
|
+
`send(json)` queues a bounded control message without blocking Main on native I/O. Producer messages arrive as `message` events. OS peer identity is checked in addition to the endpoint credential. A receiver accepts one producer connection and cannot be rebound. Errors require the consumer to terminate or replace that connection. Frames discarded before delivery release their native resources; delivered frames still require explicit release after closure.
|
|
26
|
+
|
|
27
|
+
## Node/TypeScript producer
|
|
28
|
+
|
|
29
|
+
Import `createProducer` from `@deepseek-ai/libreoffice-kit/native-render` inside the owning Node process. Bind the receiver to that Node process's PID; an in-process plugin uses `process.pid`. Pass the private endpoint, `maxPendingOperations`, `operationTimeoutMs`, and an optional native engine descriptor. Await `ready`, and register explicit `close()` with the owning plugin's disposal. The [TypeScript API](index.d.ts) defines operations and resource ownership.
|
|
30
|
+
|
|
31
|
+
A dedicated native worker serializes connection, uploads, engine callbacks, mutex waits and submission. A separate polling thread wakes it on credit and control events; acquisition does not poll on a timer. Accepted operations may queue before readiness; excess ordinary operations reject, including control messages. Discard has one reserved queue slot per owned lease so a full queue cannot prevent release. Pending acquisitions wait for credits without blocking worker execution. Acquisition timeout rejects that request without closing the producer. Transport or uncertain GPU completion failures close the connection. `closed` resolves after queued operations settle and the worker, client and engine are destroyed. Event-listener exceptions are contained; listeners remain responsible for their own diagnostics. Worker termination uses asynchronous native cleanup. Set `DSH_RENDER_DIAGNOSTICS=1` to report contained producer callback exceptions to stderr.
|
|
32
|
+
|
|
33
|
+
`acquire(width, height)` returns an explicit surface lease. Await `writeBgra(buffer, stride)` or `render()`, then `submit(frameId, metadata)` or `discard()`; surface `close()` is a discard alias. Busy or consumed surfaces reject reuse. Garbage collection never grants frame credit. Submission consumes the lease, but the underlying texture remains unavailable until the receiver releases its frame.
|
|
34
|
+
|
|
35
|
+
CPU uploads borrow a non-shared Node Buffer until the returned promise settles. During that time callers must not modify it, detach it or transfer its backing ArrayBuffer. Row stride may exceed the packed row width. The binding retains the Buffer and avoids an intermediate binding copy; the C SDK still copies or uploads those bytes. CPU upload is not GPU zero-copy.
|
|
36
|
+
|
|
37
|
+
For continuous GPU rendering, supply an engine exported by another Node addon using [dsh_render_node.h](include/dsh_render_node.h). Its [engine callbacks](include/dsh_render_engine.h) run serially on the producer worker. The descriptor stays alive through engine destruction. `render` borrows the acquired native texture and releases imports before returning. Windows callbacks queue work on the supplied device's immediate context while the SDK owns key 0; they must not acquire that lock themselves. macOS callbacks complete GPU work before returning. Both observe cancellation. Third-party callbacks must return promptly; the SDK cannot preempt arbitrary engine code. Engine creation, update and destruction must not call JavaScript.
|
|
38
|
+
|
|
39
|
+
`start({ width, height, generation, frameIntervalMs })` renders continuously in native code; `update(json, inputSequence)` applies batched engine state, and `stop()` stops new frames. The interval includes rendering time and accepts fractions such as `1000 / 60`; elapsed deadlines are skipped without catch-up bursts. Manual leases must be released before starting. Frame metadata contains request ID, viewport generation, revision and the latest applied input sequence.
|
|
40
|
+
|
|
41
|
+
Engine ABI v2 adds `prepare` before surface acquisition: return 1 for a changed frame, 0 for no change, or -1 for failure. An unchanged frame makes no acquisition or submission and consumes no credit. A declared change remains pending through credit waits; preparation continues at the stream cadence, and newer updates may replace the state rendered when credit arrives. Start and resize force one frame, and updates make the next change check immediately eligible. ABI v1 keeps continuous rendering; manual Node callers skip a frame by not acquiring or submitting it. Manual `surface.render()` does not call `prepare`.
|
|
42
|
+
|
|
43
|
+
The display path can match the C producer's native path without per-frame JavaScript or pixel readback on the same adapter. End-to-end performance still depends on engine work, callbacks, pacing, GPU choice and CPU copying. Displayed-frame intervals, skipped revisions, input-to-observed-frame latency and memory require separate measurement; arrival throughput alone is not displayed FPS. Both languages use the same automatic receiver transport.
|
|
44
|
+
|
|
45
|
+
## C/C++ producer
|
|
46
|
+
|
|
47
|
+
Include `include/dsh_render.h` and link the matching `libdsh_render_sdk.a` or `dsh_render_sdk.lib`, or build the sources listed in `sdk.json`. The API has no Node or Electron dependency. Poll on one thread; acquisition, writing, submission and discard may run on another. Callers must serialize use of the same graphics context. Interrupt polling, join that thread, and close the client after all its API calls return.
|
|
48
|
+
|
|
49
|
+
On Windows, `dsh_render_connect_with_device` accepts the application’s `ID3D11Device` and retains it until close. Passing null, or using `dsh_render_connect`, creates a default device. `dsh_render_connect_with_options` additionally bounds connection/handshake time and accepts a cancellation callback on the connecting thread. Applications choose their own GPU; DSH selects the transport. Serialize the adopted device’s immediate context with SDK writes. macOS requires a null device.
|
|
50
|
+
|
|
51
|
+
Acquisition initially returns null while the receiver grants allocation credit. Poll and retry when the owning application is ready; do not spin. Allocation requests enter a shared FIFO budget queue. Grants cover idle pool allocations as well as displayed frames. A null acquisition otherwise indicates exhausted credits; terminal allocation errors are reported by polling with `kind = -1` and explanatory text. Stop processing on a negative poll result and preserve its diagnostic before closing. A consumer must bound its overall operation lifetime and disconnect on timeout.
|
|
52
|
+
|
|
53
|
+
Textures use top-left BGRA8 premultiplied pixels in sRGB. Windows surfaces have a keyed mutex using key 0. Acquisition grants a lease without locking: SDK CPU uploads and engine callbacks own the write lock; external GPU writers own it themselves through `dsh_render_surface_keyed_mutex` or their import API. Writers release key 0 after queueing commands and release imported objects/views before submit or discard. CPU uploads copy the input before returning and do not wait for GPU completion; `dsh_render_write_bgra_with_timeout` bounds mutex acquisition. `AcquireSync` can block the CPU. macOS writers must complete GPU work before submit or discard. Reusing a surface requires both a new acquisition and the write lock on Windows. If GPU access release fails, close the connection without reusing the surface.
|
|
54
|
+
|
|
55
|
+
Frame IDs must be integers from 1 through 9007199254740991 and unique among outstanding submissions. `dsh_render_submit` returns 1 when submitted and 0 on failure. A failed submission leaves a valid acquisition with the caller for retry or discard under the same GPU completion requirements.
|
|
56
|
+
|
|
57
|
+
Windows Vulkan and D3D12 consumers borrow the NT handle through `dsh_render_surface_shared_handle` while the surface is acquired. They must use the SDK's GPU adapter and enable keyed-mutex synchronization in their import API, following the ownership rules above. The SDK owns the handle; callers must not close it. The function returns null on macOS. Receiver copies acquire the source mutex with a bounded timeout when the actual texture descriptor declares one; legacy textures retain the completed-write requirement.
|
|
58
|
+
|
|
59
|
+
Application JSON, frame correlation, input semantics, viewport generations and input acknowledgements are defined by the consuming application protocol. Control messages are limited to 16383 UTF-8 bytes. The SDK does not expose arbitrary process launching or native handles to webpages. The SDK has no LibreOffice runtime dependency; applications may install Kit with `--omit=optional` when only native rendering is needed.
|
|
60
|
+
|
|
61
|
+
## Build and validation
|
|
62
|
+
|
|
63
|
+
Run `node scripts/build.mjs` on the target platform with complete matching Node headers available. The SDK version comes from the public Kit package metadata. Set `DSH_NODE_INCLUDE` explicitly when necessary; Windows additionally requires a developer toolchain environment and `DSH_NODE_LIB`. Builds produce precompiled Node-API and static SDK artifacts with SHA-256 receipts. Installation never invokes a compiler. Public Kit packing requires all four supported targets from one source commit. Partial payloads cannot be packed. The verifier checks addon and static-library architectures, artifact hashes, source hashes, versions and protocol before signing. Desktop runtime packaging retains only the selected target’s native-render prebuilds, along with the package license.
|
|
64
|
+
|
|
65
|
+
Run `pnpm test` in this directory after building. `DSH_NATIVE_RENDER_PACKAGE_ROOT` selects an installed SDK payload for transport and lifecycle tests; diagnostics may be retained outside the package with `DSH_NATIVE_RENDER_DIAGNOSTICS`. Fixture setup gives each complete compile/link group 120 seconds within a 180-second setup hook; protocol and runner deadlines are separate. Compiler receipts preserve the resolved executable, arguments, working directory, elapsed time, direct-child outcome and stdout/stderr. Compiler descendant exit is not observed. Parent fixtures prepare GPU inspectors and pass their paths only to owned runners, retaining the temporary files until those runners exit. The native CI lane runs C transport and Node producer integration tests serially before packing, including asynchronous shutdown and Worker termination. Performance and Electron shared-texture import require separate actual GPU validation; a successful native transport test alone does not establish those results.
|
|
66
|
+
|
|
67
|
+
## Browser and Electron presentation
|
|
68
|
+
|
|
69
|
+
`@deepseek-ai/libreoffice-kit/native-render/browser` exports `NativeFrameDisplay`, `createNativeFramePainter`, and their types. Importing this entry does not load Electron, Office or native addons and allocates no graphics resources. The generic view identifier preserves application-specific string types. Applications own view creation, authorization, producer control and input arbitration.
|
|
70
|
+
|
|
71
|
+
`NativeFrameDisplay.present()` takes ownership of a frame lease and releases it after painting or rejection. Hidden documents wait for visibility; a generation change or disposal cancels the wait. The owner separately updates producer visibility. Dispose the display before removing its canvas.
|
|
72
|
+
|
|
73
|
+
`@deepseek-ai/libreoffice-kit/native-render/electron` exports `detectNativeRenderAdapter` and `sendNativeFrame` for Electron Main. Adapter detection waits for complete Chromium GPU information and observes its exported Direct3D11 texture within one supplied deadline. Unsupported backends or software compositing return `null` without creating an offscreen window. Cancellation also covers GPU initialization and window construction. After the application validates the recipient and frame metadata, `sendNativeFrame` owns the delivery credit through submission failure or Electron's final GPU-reference release. Its completion does not imply GPU release. The required failure callback synchronously stops producer I/O before Main releases its import or returns the delivery credit; the submission promise then rejects.
|
|
74
|
+
|
|
75
|
+
`@deepseek-ai/libreoffice-kit/native-render/electron/preload` exports `createNativeTextureReceiver` for a sandboxed preload. Bundle this entry with Electron external, and install its single document-wide receiver before starting production. Register at most one listener per view. Unsubscribe and revocation stop future deliveries; consumers retain delivered leases until explicit release. Missing consumers, frame extraction failures and throwing listeners release the imported texture. IPC authorization and application lifecycle remain with the caller.
|
|
76
|
+
|
|
77
|
+
## Distribution
|
|
78
|
+
|
|
79
|
+
The public Kit package exports the Node SDK, SDK metadata, verifier, browser and Electron entries independently. Resolve the SDK JSON file and read its `header`, `sources`, and `staticLibraries[target]` paths relative to that directory. Normal installation and runtime use the bundled addon without compiling or downloading native binaries.
|
|
80
|
+
|
|
81
|
+
The browser painters/display, Electron adapter probe and generic texture ownership tests originate from DeepSeek Harness commit `21261bee8b9a820c62c9e42cade3ff644b747a29`, under `packages/client/native-render` and `apps/desktop`. Their unit tests are maintained with these implementations; DSH retains application integration tests.
|
|
82
|
+
|
|
83
|
+
The MIT SDK originated in DeepSeek Harness commit `4438b67c13d529c9882d89893ed5cd610ace11cc`. Its WebGPU adapter retains the Office fixes from LibreOffice Kit commit `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df`. The Node binding and standalone C SDK share the source tree used by the Kit engine build. Protocol version 1 and engine ABI versions 1 and 2 are unchanged.
|