@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
package/lib/index.js
CHANGED
|
@@ -138,7 +138,7 @@ function dimension(data, first, last, maximum, scale) {
|
|
|
138
138
|
}
|
|
139
139
|
return [start / scale, (position - start) / scale];
|
|
140
140
|
}
|
|
141
|
-
/** Logical columns advance from A;
|
|
141
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
142
142
|
function sheetRangeRectangle(geometry, range, scale) {
|
|
143
143
|
if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
|
|
144
144
|
const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
|
|
@@ -159,6 +159,17 @@ function sheetRangeRectangle(geometry, range, scale) {
|
|
|
159
159
|
height
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
163
|
+
function unmirrorRtlTile({ width, height, rgba }) {
|
|
164
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < Math.floor(width / 2); x++) {
|
|
165
|
+
const left = (y * width + x) * 4, right = (y * width + width - 1 - x) * 4;
|
|
166
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
167
|
+
const value = rgba[left + channel];
|
|
168
|
+
rgba[left + channel] = rgba[right + channel];
|
|
169
|
+
rgba[right + channel] = value;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
162
173
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
163
174
|
function splitRasterRectangle(rectangle, scale, limits) {
|
|
164
175
|
const { x, y, width, height } = rectangle;
|
|
@@ -319,18 +330,41 @@ function selectedPages(pages, count, limit) {
|
|
|
319
330
|
}
|
|
320
331
|
//#endregion
|
|
321
332
|
//#region lib/types/native-process.js
|
|
322
|
-
/** Native helper stdio; Windows
|
|
333
|
+
/** Native helper stdio; Windows pipe handles permit read/write access under restricted tokens. */
|
|
334
|
+
let pipeAttributes;
|
|
323
335
|
function windowsPipes() {
|
|
324
336
|
const koffi = createRequire(import.meta.url)("koffi");
|
|
325
|
-
const kernel = koffi.load("kernel32.dll"), node = koffi.load(null);
|
|
326
|
-
const
|
|
337
|
+
const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
|
|
338
|
+
const attributes = pipeAttributes ??= koffi.struct({
|
|
339
|
+
nLength: "uint32",
|
|
340
|
+
lpSecurityDescriptor: "void *",
|
|
341
|
+
bInheritHandle: "int"
|
|
342
|
+
});
|
|
343
|
+
const createPipe = kernel.func("__stdcall", "CreatePipe", "int", [
|
|
344
|
+
koffi.out(koffi.pointer("void *")),
|
|
345
|
+
koffi.out(koffi.pointer("void *")),
|
|
346
|
+
koffi.pointer(attributes),
|
|
347
|
+
"uint32"
|
|
348
|
+
]);
|
|
327
349
|
const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
350
|
+
const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
|
|
328
351
|
const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
|
|
329
352
|
const lastError = kernel.func("uint32 __stdcall GetLastError()");
|
|
353
|
+
const convertSecurityDescriptor = advapi.func("int __stdcall ConvertStringSecurityDescriptorToSecurityDescriptorW(void *sddl, uint32 revision, _Out_ void **descriptor, void *size)");
|
|
330
354
|
const openFd = node.func("int uv_open_osfhandle(void *handle)");
|
|
331
355
|
function pipe() {
|
|
332
356
|
const reads = [null], writes = [null];
|
|
333
|
-
|
|
357
|
+
const descriptor = [null];
|
|
358
|
+
if (!convertSecurityDescriptor(Buffer.from("D:(A;;GRGW;;;WD)\0", "utf16le"), 1, descriptor, null)) throw new Error(`Pipe security descriptor failed: ${lastError()}`);
|
|
359
|
+
try {
|
|
360
|
+
if (!createPipe(reads, writes, {
|
|
361
|
+
nLength: attributes.size,
|
|
362
|
+
lpSecurityDescriptor: descriptor[0],
|
|
363
|
+
bInheritHandle: 0
|
|
364
|
+
}, 0)) throw new Error(`CreatePipe failed: ${lastError()}`);
|
|
365
|
+
} finally {
|
|
366
|
+
localFree(descriptor[0]);
|
|
367
|
+
}
|
|
334
368
|
const read = openFd(reads[0]);
|
|
335
369
|
if (read < 0) {
|
|
336
370
|
closeHandle(reads[0]);
|
|
@@ -440,6 +474,9 @@ function spawnNative(executable, args, env) {
|
|
|
440
474
|
stdin = stdin;
|
|
441
475
|
stdout = output.readable;
|
|
442
476
|
stderr = error.readable;
|
|
477
|
+
get pid() {
|
|
478
|
+
return child.pid;
|
|
479
|
+
}
|
|
443
480
|
get exitCode() {
|
|
444
481
|
return child.exitCode;
|
|
445
482
|
}
|
|
@@ -468,6 +505,8 @@ function spawnNative(executable, args, env) {
|
|
|
468
505
|
});
|
|
469
506
|
child.once("close", (code, signal) => {
|
|
470
507
|
stdin.destroy();
|
|
508
|
+
output.readable.resume();
|
|
509
|
+
error.readable.resume();
|
|
471
510
|
drained.then(() => {
|
|
472
511
|
if (failure !== void 0) helper.emit("error", failure);
|
|
473
512
|
helper.emit("close", code, signal);
|
|
@@ -671,7 +710,9 @@ const NATIVE_ENVIRONMENT_KEYS = [
|
|
|
671
710
|
"PATHEXT",
|
|
672
711
|
"LANG",
|
|
673
712
|
"LC_ALL",
|
|
674
|
-
"TZ"
|
|
713
|
+
"TZ",
|
|
714
|
+
"OFFICE_GRAPHITE_DIAGNOSTICS",
|
|
715
|
+
"OFFICE_LOAD_DIAGNOSTICS"
|
|
675
716
|
];
|
|
676
717
|
function fontSearchName(value) {
|
|
677
718
|
const name = value.replaceAll(/[\uff00-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 65248)).replaceAll(/[A-Z]/g, (character) => character.toLowerCase()).replaceAll(/[^a-z0-9;()\u0080-\uffff]/g, "");
|
|
@@ -697,6 +738,7 @@ async function prepareNativeFontProfile(profile, substitutions) {
|
|
|
697
738
|
});
|
|
698
739
|
}
|
|
699
740
|
/**
|
|
741
|
+
* Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
|
|
700
742
|
* Linux searches the verified program directory; ambient loader overrides and credentials are excluded.
|
|
701
743
|
* @param profile - Conversion-owned profile directory the helper treats as home.
|
|
702
744
|
* @param programDirectory - Verified engine program directory.
|
|
@@ -716,38 +758,90 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
|
|
|
716
758
|
USERPROFILE: profile,
|
|
717
759
|
TMPDIR: profile,
|
|
718
760
|
TMP: profile,
|
|
719
|
-
TEMP: profile
|
|
761
|
+
TEMP: profile,
|
|
762
|
+
SAL_DISABLE_PRINTERLIST: "1",
|
|
763
|
+
SAL_DISABLE_DEFAULTPRINTER: "1"
|
|
720
764
|
});
|
|
721
765
|
}
|
|
722
766
|
/**
|
|
723
|
-
*
|
|
767
|
+
* Prepare short Windows engine paths owned by the caller's private profile.
|
|
724
768
|
* @param engine - Verified engine installation; its resources remain in place.
|
|
725
769
|
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
726
|
-
* @
|
|
727
|
-
* @returns The operation result after removing the resource junction.
|
|
770
|
+
* @returns Engine paths and a release function to call once, after the helper closes and before removing the profile.
|
|
728
771
|
*/
|
|
729
|
-
async function
|
|
730
|
-
if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return
|
|
772
|
+
async function prepareNativeEngine(engine, profile) {
|
|
773
|
+
if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return {
|
|
774
|
+
engine,
|
|
775
|
+
release: async () => {}
|
|
776
|
+
};
|
|
731
777
|
const root = join(profile, "engine");
|
|
732
778
|
await symlink(engine.root, root, "junction");
|
|
733
779
|
try {
|
|
734
780
|
const executable = join(profile, "libreoffice-kit.exe");
|
|
735
781
|
await copyFile(engine.executable, executable, constants.COPYFILE_EXCL);
|
|
736
|
-
return
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
782
|
+
return {
|
|
783
|
+
engine: {
|
|
784
|
+
...engine,
|
|
785
|
+
root,
|
|
786
|
+
executable,
|
|
787
|
+
programDirectory: join(root, relative(engine.root, engine.programDirectory))
|
|
788
|
+
},
|
|
789
|
+
release: () => unlink(root)
|
|
790
|
+
};
|
|
791
|
+
} catch (error) {
|
|
743
792
|
await unlink(root);
|
|
793
|
+
throw error;
|
|
744
794
|
}
|
|
745
795
|
}
|
|
746
796
|
/**
|
|
797
|
+
* Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
|
|
798
|
+
* @param engine - Verified engine installation; its resources remain in place.
|
|
799
|
+
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
800
|
+
* @param run - Operation that settles only after its helper closes.
|
|
801
|
+
* @returns The operation result after removing the resource junction.
|
|
802
|
+
*/
|
|
803
|
+
async function withNativeEngine(engine, profile, run) {
|
|
804
|
+
const prepared = await prepareNativeEngine(engine, profile);
|
|
805
|
+
try {
|
|
806
|
+
return await run(prepared.engine);
|
|
807
|
+
} finally {
|
|
808
|
+
await prepared.release();
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Prepare the document transport accepted by the pinned helper.
|
|
813
|
+
* @param engine - Resolved helper and input protocol.
|
|
814
|
+
* @param input - Owned document bytes and validated format.
|
|
815
|
+
* @param profile - Private directory retained until the helper exits and removed by the operation owner.
|
|
816
|
+
* @param signal - Cancellation of input preparation.
|
|
817
|
+
* @returns Helper arguments and an optional binary stdin prefix.
|
|
818
|
+
*/
|
|
819
|
+
async function prepareNativeInput(engine, input, profile, signal) {
|
|
820
|
+
signal.throwIfAborted();
|
|
821
|
+
if (engine.legacyInputPath) {
|
|
822
|
+
const path = join(profile, `source.${input.format}`);
|
|
823
|
+
await writeFile(path, input.bytes, {
|
|
824
|
+
flag: "wx",
|
|
825
|
+
mode: 384,
|
|
826
|
+
signal
|
|
827
|
+
});
|
|
828
|
+
return { args: ["--input-path", path] };
|
|
829
|
+
}
|
|
830
|
+
return {
|
|
831
|
+
args: [
|
|
832
|
+
"--input-bytes",
|
|
833
|
+
String(input.bytes.byteLength),
|
|
834
|
+
"--input-format",
|
|
835
|
+
input.format
|
|
836
|
+
],
|
|
837
|
+
bytes: input.bytes
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
747
841
|
* Run one native conversion and await bounded result transport.
|
|
748
842
|
* @param engine - Resolved native engine installation.
|
|
749
843
|
* @param options - Validated conversion limits.
|
|
750
|
-
* @param input -
|
|
844
|
+
* @param input - Owned source bytes and format; older pinned helpers receive a private input file.
|
|
751
845
|
* @param output - Private PDF path inside the conversion scratch directory.
|
|
752
846
|
* @param profile - Conversion-owned profile directory.
|
|
753
847
|
* @param fonts - Installed font files the helper may load.
|
|
@@ -766,11 +860,12 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
766
860
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
767
861
|
signal.throwIfAborted();
|
|
768
862
|
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
863
|
+
const transport = await prepareNativeInput(engine, input, profile, signal);
|
|
864
|
+
signal.throwIfAborted();
|
|
769
865
|
const child = spawnNative(engine.executable, [
|
|
770
866
|
"--program-directory",
|
|
771
867
|
engine.programDirectory,
|
|
772
|
-
|
|
773
|
-
input,
|
|
868
|
+
...transport.args,
|
|
774
869
|
"--output-path",
|
|
775
870
|
output,
|
|
776
871
|
"--profile-directory",
|
|
@@ -786,7 +881,6 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
786
881
|
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
787
882
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
788
883
|
], env);
|
|
789
|
-
child.stdin.end();
|
|
790
884
|
let stdout = "";
|
|
791
885
|
let stderr = "";
|
|
792
886
|
let failure;
|
|
@@ -807,6 +901,11 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
807
901
|
child.stderr.on("data", (chunk) => {
|
|
808
902
|
stderr = (stderr + chunk).slice(-65536);
|
|
809
903
|
});
|
|
904
|
+
child.stdin.on("error", (error) => {
|
|
905
|
+
failure ??= error;
|
|
906
|
+
child.kill("SIGKILL");
|
|
907
|
+
});
|
|
908
|
+
child.stdin.end(transport.bytes);
|
|
810
909
|
try {
|
|
811
910
|
const code = await new Promise((resolve, reject) => {
|
|
812
911
|
child.once("error", (error) => {
|
|
@@ -962,19 +1061,22 @@ function plan(ready, request) {
|
|
|
962
1061
|
}
|
|
963
1062
|
/** Run one native image batch and write final PNGs only after each bounded paint succeeds. */
|
|
964
1063
|
async function renderImagesWithNative(request) {
|
|
965
|
-
const { engine, options,
|
|
1064
|
+
const { engine, options, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
|
|
966
1065
|
signal.throwIfAborted();
|
|
967
1066
|
await mkdir(profile, { mode: 448 });
|
|
968
1067
|
await prepareNativeFontProfile(profile, substitutions);
|
|
969
1068
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
1069
|
+
const transport = await prepareNativeInput(engine, {
|
|
1070
|
+
bytes: source,
|
|
1071
|
+
format: operation.extension
|
|
1072
|
+
}, profile, signal);
|
|
970
1073
|
signal.throwIfAborted();
|
|
971
1074
|
const child = spawnNative(engine.executable, [
|
|
972
1075
|
"--operation",
|
|
973
1076
|
"render-images",
|
|
974
1077
|
"--program-directory",
|
|
975
1078
|
engine.programDirectory,
|
|
976
|
-
|
|
977
|
-
inputPath,
|
|
1079
|
+
...transport.args,
|
|
978
1080
|
"--scratch-directory",
|
|
979
1081
|
scratch,
|
|
980
1082
|
"--profile-directory",
|
|
@@ -1014,6 +1116,11 @@ async function renderImagesWithNative(request) {
|
|
|
1014
1116
|
child.kill("SIGKILL");
|
|
1015
1117
|
};
|
|
1016
1118
|
signal.addEventListener("abort", abort, { once: true });
|
|
1119
|
+
child.stdin.on("error", (error) => {
|
|
1120
|
+
stopped ??= error;
|
|
1121
|
+
child.kill("SIGKILL");
|
|
1122
|
+
});
|
|
1123
|
+
if (transport.bytes) child.stdin.write(transport.bytes);
|
|
1017
1124
|
const next = async () => {
|
|
1018
1125
|
signal.throwIfAborted();
|
|
1019
1126
|
if (lines.length > 0) return lines.shift();
|
|
@@ -1100,7 +1207,13 @@ async function renderImagesWithNative(request) {
|
|
|
1100
1207
|
if (resolve(painted.path) !== resolve(scratch, `tile-${index}.rgba`)) throw new Error("LibreOffice native renderer returned a tile outside its scratch directory.");
|
|
1101
1208
|
const raw = await readFile(painted.path);
|
|
1102
1209
|
if (raw.byteLength !== width * height * 4) throw new Error("LibreOffice native renderer returned incomplete pixels.");
|
|
1103
|
-
const
|
|
1210
|
+
const rgba = ready.documentType === "pdf" ? new Uint8ClampedArray(raw) : rgbaPixels(raw, ready.tileMode);
|
|
1211
|
+
if (region.rtl) unmirrorRtlTile({
|
|
1212
|
+
width,
|
|
1213
|
+
height,
|
|
1214
|
+
rgba
|
|
1215
|
+
});
|
|
1216
|
+
const png = encodePng(width, height, rgba);
|
|
1104
1217
|
total += png.byteLength;
|
|
1105
1218
|
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
1106
1219
|
const path = join(operation.outputDir, `page-${String(index).padStart(4, "0")}.png`);
|
|
@@ -1422,16 +1535,16 @@ function resolveOptions(input = {}) {
|
|
|
1422
1535
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1423
1536
|
const require = createRequire(import.meta.url);
|
|
1424
1537
|
/** Node API release version returned by runtime discovery. */
|
|
1425
|
-
const ENGINE_VERSION = "0.
|
|
1538
|
+
const ENGINE_VERSION = "0.2.0-alpha5";
|
|
1426
1539
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1427
1540
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1428
|
-
"darwin-arm64": "0.
|
|
1429
|
-
"darwin-x64": "0.
|
|
1541
|
+
"darwin-arm64": "0.2.0-alpha5",
|
|
1542
|
+
"darwin-x64": "0.2.0-alpha5",
|
|
1430
1543
|
"linux-arm64-glibc": "0.1.1",
|
|
1431
1544
|
"linux-x64-glibc": "0.1.1",
|
|
1432
|
-
"win32-arm64": "0.1.
|
|
1433
|
-
"win32-x64": "0.
|
|
1434
|
-
wasm: "0.
|
|
1545
|
+
"win32-arm64": "0.1.5",
|
|
1546
|
+
"win32-x64": "0.2.0-alpha5",
|
|
1547
|
+
wasm: "0.2.0-alpha5"
|
|
1435
1548
|
});
|
|
1436
1549
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1437
1550
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
|
@@ -1470,7 +1583,7 @@ function glibcVersion(value) {
|
|
|
1470
1583
|
return typeof value === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part))) ? value.split(".").map(Number) : void 0;
|
|
1471
1584
|
}
|
|
1472
1585
|
/**
|
|
1473
|
-
*
|
|
1586
|
+
* Prefer the installed compatible native engine; hosts without one use the shared WASM package.
|
|
1474
1587
|
* @param resolvePackage - Package manifest resolver; injectable for selection tests.
|
|
1475
1588
|
* @param packageExists - Installed-package probe; injectable for selection tests.
|
|
1476
1589
|
* @param host - Process identification and diagnostic report.
|
|
@@ -1488,7 +1601,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1488
1601
|
const failure = error;
|
|
1489
1602
|
if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
|
|
1490
1603
|
if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
|
|
1491
|
-
if (platform !== "linux") throw new Error(`Required LibreOfficeKit native package is missing: ${name}`, { cause: error });
|
|
1492
1604
|
}
|
|
1493
1605
|
if (packageFile !== void 0) {
|
|
1494
1606
|
const engine = await readEngine(packageFile, "native", target);
|
|
@@ -1497,7 +1609,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1497
1609
|
if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
|
|
1498
1610
|
}
|
|
1499
1611
|
}
|
|
1500
|
-
if (platform !== "linux") throw new Error(`Unsupported LibreOfficeKit host: ${platform}-${arch}`);
|
|
1501
1612
|
return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
|
|
1502
1613
|
}
|
|
1503
1614
|
async function engineAsset(root, value, name, kind) {
|
|
@@ -1522,6 +1633,7 @@ async function readEngine(packageFile, backend, target) {
|
|
|
1522
1633
|
root,
|
|
1523
1634
|
programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
|
|
1524
1635
|
executable,
|
|
1636
|
+
...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
|
|
1525
1637
|
...glibcFloor
|
|
1526
1638
|
};
|
|
1527
1639
|
}
|
|
@@ -1638,6 +1750,7 @@ async function discoverRuntime() {
|
|
|
1638
1750
|
return {
|
|
1639
1751
|
version: ENGINE_VERSION,
|
|
1640
1752
|
backend: engine.backend,
|
|
1753
|
+
nativePreview: engine.backend === "native" && !engine.legacyInputPath,
|
|
1641
1754
|
cliPath: fileURLToPath(new URL("./cli.js", import.meta.url)),
|
|
1642
1755
|
nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
|
|
1643
1756
|
};
|
|
@@ -1926,16 +2039,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1926
2039
|
output = await open(request.outputPath, "wx", 384);
|
|
1927
2040
|
const sourceBytes = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
1928
2041
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-"));
|
|
1929
|
-
const inputPath = join(scratch, `document.${extension}`);
|
|
1930
|
-
const input = await open(inputPath, "wx", 384);
|
|
1931
|
-
try {
|
|
1932
|
-
await input.writeFile(sourceBytes);
|
|
1933
|
-
} finally {
|
|
1934
|
-
await input.close();
|
|
1935
|
-
}
|
|
1936
2042
|
const fonts = await snapshot(stopped);
|
|
1937
2043
|
const result = await runWorker({
|
|
1938
|
-
|
|
2044
|
+
bytes: sourceBytes,
|
|
1939
2045
|
extension,
|
|
1940
2046
|
operation: request,
|
|
1941
2047
|
options: resolvedOptions,
|
|
@@ -1952,7 +2058,10 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1952
2058
|
const profile = join(scratch, "profile");
|
|
1953
2059
|
await mkdir(profile, { mode: 448 });
|
|
1954
2060
|
const path = join(scratch, `output.${format}`);
|
|
1955
|
-
await runNative(native, resolvedOptions,
|
|
2061
|
+
await runNative(native, resolvedOptions, {
|
|
2062
|
+
bytes: sourceBytes,
|
|
2063
|
+
format: extension
|
|
2064
|
+
}, path, profile, result.fonts, result.substitutions, stopped, request);
|
|
1956
2065
|
bytes = await readBounded(path, resolvedOptions.maxOutputBytes, stopped, "output");
|
|
1957
2066
|
}
|
|
1958
2067
|
validateOutput(bytes, format);
|
|
@@ -2003,14 +2112,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2003
2112
|
owned = true;
|
|
2004
2113
|
const source = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
2005
2114
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-images-"));
|
|
2006
|
-
const inputPath = join(scratch, `document.${request.extension}`);
|
|
2007
|
-
await writeFile(inputPath, source, {
|
|
2008
|
-
flag: "wx",
|
|
2009
|
-
mode: 384
|
|
2010
|
-
});
|
|
2011
2115
|
const fonts = await snapshot(stopped);
|
|
2012
2116
|
const result = await runWorker({
|
|
2013
|
-
|
|
2117
|
+
bytes: source,
|
|
2014
2118
|
extension: request.extension,
|
|
2015
2119
|
operation: request,
|
|
2016
2120
|
options: resolvedOptions,
|
|
@@ -2026,7 +2130,6 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2026
2130
|
images = await renderImagesWithNative({
|
|
2027
2131
|
engine,
|
|
2028
2132
|
options: resolvedOptions,
|
|
2029
|
-
inputPath,
|
|
2030
2133
|
source,
|
|
2031
2134
|
scratch,
|
|
2032
2135
|
profile,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EditorPixels } from './editor-types.ts';
|
|
2
|
+
/** Bounded binary records shared by the native editor's process reader and writer. */
|
|
3
|
+
export interface EditorFrame {
|
|
4
|
+
readonly control: Record<string, unknown>;
|
|
5
|
+
readonly pixels: Buffer;
|
|
6
|
+
}
|
|
7
|
+
/** Encode a control record; the native editor accepts no binary input. */
|
|
8
|
+
export declare function encodeEditorRequest(control: object): Buffer;
|
|
9
|
+
/** Parses fragmented records without repeatedly copying a partial pixel frame. */
|
|
10
|
+
export declare class EditorFrameReader {
|
|
11
|
+
private readonly maxPixelBytes;
|
|
12
|
+
private readonly receive;
|
|
13
|
+
private readonly maxControlBytes;
|
|
14
|
+
private readonly header;
|
|
15
|
+
private headerBytes;
|
|
16
|
+
private body;
|
|
17
|
+
private bodyBytes;
|
|
18
|
+
private jsonBytes;
|
|
19
|
+
constructor(maxPixelBytes: number, receive: (frame: EditorFrame) => void, maxControlBytes?: number);
|
|
20
|
+
/** Consume arbitrary process chunks; invalid sizes or JSON are fatal to the session. */
|
|
21
|
+
push(chunk: Buffer): void;
|
|
22
|
+
/** Reject truncated records when stdout closes. */
|
|
23
|
+
finish(): void;
|
|
24
|
+
}
|
|
25
|
+
/** Read an integer from the native process, rejecting invalid counters and dimensions. */
|
|
26
|
+
export declare function editorInteger(control: Record<string, unknown>, key: string, minimum?: number): number;
|
|
27
|
+
/** Validate straight RGBA and retain the reader-owned buffer without copying its pixels. */
|
|
28
|
+
export declare function decodeEditorPixels({ control: c, pixels }: EditorFrame): EditorPixels;
|
|
29
|
+
//# sourceMappingURL=editor-protocol.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Owns one isolated native process and settles every request on cancellation, timeout, or exit. */
|
|
2
|
+
import { type EditorFrame } from './editor-protocol.ts';
|
|
3
|
+
import type { EditorEvent } from './editor-types.ts';
|
|
4
|
+
/** Process-private request multiplexer; the public editor serializes operations before submitting. */
|
|
5
|
+
export declare class EditorTransport {
|
|
6
|
+
private readonly timeoutMs;
|
|
7
|
+
private readonly signal;
|
|
8
|
+
private readonly onProgress?;
|
|
9
|
+
private readonly child;
|
|
10
|
+
private readonly pending;
|
|
11
|
+
private readonly ready;
|
|
12
|
+
private readonly exited;
|
|
13
|
+
private readonly listeners;
|
|
14
|
+
private failure;
|
|
15
|
+
private sequence;
|
|
16
|
+
private stderr;
|
|
17
|
+
private closing;
|
|
18
|
+
private initialized;
|
|
19
|
+
private readonly abort;
|
|
20
|
+
private readonly startupTimer;
|
|
21
|
+
constructor(executable: string, args: string[], env: Record<string, string>, timeoutMs: number, maxPixelBytes: number, signal: AbortSignal, maxControlBytes?: number, source?: Uint8Array, onProgress?: ((stage: "document") => void) | undefined);
|
|
22
|
+
private fail;
|
|
23
|
+
private emit;
|
|
24
|
+
private receive;
|
|
25
|
+
/** Actual owned native process; never supplied by a renderer. */
|
|
26
|
+
get processId(): number;
|
|
27
|
+
/** Wait for document initialization; failure still requires close() to join cleanup. */
|
|
28
|
+
opened(): Promise<EditorFrame>;
|
|
29
|
+
/** Subscribe until disposed; observers must not throw. */
|
|
30
|
+
onEvent(listener: (event: EditorEvent) => void): () => void;
|
|
31
|
+
/** Submit a bounded operation; a timeout terminates the session because edit completion is then uncertain. */
|
|
32
|
+
request(control: object): Promise<EditorFrame>;
|
|
33
|
+
/** Graceful EOF or forced termination; resolves only after the OS closes the process streams. */
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=editor-transport.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** Native editor operations use document twips (1/1440 inch) and physical output pixels. */
|
|
2
|
+
export type OfficeFormat = 'docx' | 'xlsx' | 'pptx';
|
|
3
|
+
/** Direct commands never open LibreOffice dialogs. Values use the documented UNO argument names. */
|
|
4
|
+
export type EditorCommand = 'Undo' | 'Redo' | 'Bold' | 'Italic' | 'Underline' | 'CharFontName' | 'FontHeight' | 'LeftPara' | 'CenterPara' | 'RightPara' | 'JustifyPara' | 'DefaultBullet' | 'DefaultNumbering' | 'ULSpacing' | 'SelectAll' | 'GoToStartOfDoc' | 'GoToEndOfDoc' | 'GoToCell' | 'DuplicatePage' | 'InsertPage' | 'DeletePage' | 'Cut' | 'Copy' | 'Delete' | 'InsertRowsBefore' | 'InsertColumnsBefore' | 'DeleteRows' | 'DeleteColumns';
|
|
5
|
+
/** Typed UNO scalar arguments for commands that require a value. */
|
|
6
|
+
export type EditorArguments = Readonly<Record<string, {
|
|
7
|
+
readonly type: 'string' | 'boolean' | 'long' | 'short' | 'float';
|
|
8
|
+
readonly value: string | number | boolean;
|
|
9
|
+
}>>;
|
|
10
|
+
/** Input is ordered with edits and snapshots; key codes follow LibreOfficeKit's VCL key constants. */
|
|
11
|
+
export type EditorInput = {
|
|
12
|
+
readonly op: 'mouse';
|
|
13
|
+
readonly type: 0 | 1 | 2;
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
readonly count: number;
|
|
17
|
+
readonly buttons: number;
|
|
18
|
+
readonly modifiers: number;
|
|
19
|
+
} | {
|
|
20
|
+
readonly op: 'key';
|
|
21
|
+
readonly type: 0 | 1;
|
|
22
|
+
readonly character: number;
|
|
23
|
+
readonly key: number;
|
|
24
|
+
} | {
|
|
25
|
+
readonly op: 'composition';
|
|
26
|
+
readonly type: 0 | 2;
|
|
27
|
+
readonly text: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly op: 'paste';
|
|
30
|
+
readonly mime: 'text/plain;charset=utf-8' | 'text/html';
|
|
31
|
+
readonly text: string;
|
|
32
|
+
};
|
|
33
|
+
/** Document region in twips. */
|
|
34
|
+
export interface EditorRectangle {
|
|
35
|
+
readonly x: number;
|
|
36
|
+
readonly y: number;
|
|
37
|
+
readonly width: number;
|
|
38
|
+
readonly height: number;
|
|
39
|
+
}
|
|
40
|
+
/** A tile may target a slide without changing the active view or its selection. */
|
|
41
|
+
export interface EditorPaintRectangle extends EditorRectangle {
|
|
42
|
+
/** Zero-based presentation part; omitted for the active view or Writer page coordinates. */
|
|
43
|
+
readonly part?: number;
|
|
44
|
+
}
|
|
45
|
+
/** Pixel/twip scale and actual visible document area. */
|
|
46
|
+
export interface EditorViewport extends EditorRectangle {
|
|
47
|
+
readonly pixelSize: number;
|
|
48
|
+
readonly twipSize: number;
|
|
49
|
+
}
|
|
50
|
+
/** A fresh document geometry query, including sheets or slides. */
|
|
51
|
+
export interface EditorInfo {
|
|
52
|
+
readonly documentType: 'text' | 'spreadsheet' | 'presentation';
|
|
53
|
+
readonly width: number;
|
|
54
|
+
readonly height: number;
|
|
55
|
+
readonly part: number;
|
|
56
|
+
readonly rectangles: string;
|
|
57
|
+
readonly parts: readonly {
|
|
58
|
+
readonly index: number;
|
|
59
|
+
readonly name: string;
|
|
60
|
+
}[];
|
|
61
|
+
/** Backend the native engine is actually drawing with; `raster` is the explicit fallback. */
|
|
62
|
+
readonly renderBackend: 'raster' | 'ganesh' | 'graphite';
|
|
63
|
+
}
|
|
64
|
+
/** Tightly packed, non-premultiplied RGBA pixels. Each result owns a buffer that later renders never reuse. */
|
|
65
|
+
export interface EditorPixels {
|
|
66
|
+
readonly pixels: Uint8Array;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
readonly revision: number;
|
|
70
|
+
readonly part?: number;
|
|
71
|
+
readonly ended?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** Native callbacks remain transient and are never document contents or durable session events. */
|
|
74
|
+
export type EditorEvent = {
|
|
75
|
+
readonly kind: 'callback';
|
|
76
|
+
readonly type: number;
|
|
77
|
+
readonly payload: string;
|
|
78
|
+
} | {
|
|
79
|
+
readonly kind: 'revision';
|
|
80
|
+
readonly revision: number;
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: 'presentation';
|
|
83
|
+
readonly part: number;
|
|
84
|
+
readonly ended: boolean;
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: 'failure';
|
|
87
|
+
readonly error: Error;
|
|
88
|
+
};
|
|
89
|
+
/** Playback controls apply to the current in-memory document, while content input is suspended. */
|
|
90
|
+
export type PresentationControl = {
|
|
91
|
+
readonly action: 'start';
|
|
92
|
+
readonly pixelWidth: number;
|
|
93
|
+
readonly pixelHeight: number;
|
|
94
|
+
readonly part: number;
|
|
95
|
+
} | {
|
|
96
|
+
readonly action: 'resize';
|
|
97
|
+
readonly pixelWidth: number;
|
|
98
|
+
readonly pixelHeight: number;
|
|
99
|
+
} | {
|
|
100
|
+
readonly action: 'next' | 'previous' | 'stop';
|
|
101
|
+
} | {
|
|
102
|
+
readonly action: 'pause';
|
|
103
|
+
readonly paused: boolean;
|
|
104
|
+
} | {
|
|
105
|
+
readonly action: 'goto';
|
|
106
|
+
readonly part: number;
|
|
107
|
+
} | {
|
|
108
|
+
readonly action: 'stream';
|
|
109
|
+
readonly enabled: true;
|
|
110
|
+
readonly requestId: string;
|
|
111
|
+
readonly generation: number;
|
|
112
|
+
readonly frameRate: number;
|
|
113
|
+
} | {
|
|
114
|
+
readonly action: 'stream';
|
|
115
|
+
readonly enabled: false;
|
|
116
|
+
readonly requestId: string;
|
|
117
|
+
readonly generation: number;
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=editor-types.d.ts.map
|