@deepseek-ai/libreoffice-kit 0.1.5 → 0.2.0-alpha6
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 +44 -8
- package/README.zh.md +45 -9
- package/frame-forwarding/CMakeLists.txt +40 -0
- package/frame-forwarding/LICENSE +21 -0
- package/frame-forwarding/README.md +83 -0
- package/frame-forwarding/README.zh.md +83 -0
- package/frame-forwarding/include/dsh_frame_forwarding.h +101 -0
- package/frame-forwarding/include/dsh_frame_forwarding_engine.h +66 -0
- package/frame-forwarding/include/dsh_frame_forwarding_node.h +27 -0
- package/frame-forwarding/include/dsh_webgpu.h +52 -0
- package/frame-forwarding/index.d.ts +145 -0
- package/frame-forwarding/index.mjs +71 -0
- package/frame-forwarding/lib/browser/display.d.ts +46 -0
- package/frame-forwarding/lib/browser/display.js +128 -0
- package/frame-forwarding/lib/browser/index.d.ts +4 -0
- package/frame-forwarding/lib/browser/index.js +3 -0
- package/frame-forwarding/lib/browser/painters.d.ts +9 -0
- package/frame-forwarding/lib/browser/painters.js +180 -0
- package/frame-forwarding/lib/browser/types.d.ts +51 -0
- package/frame-forwarding/lib/browser/types.js +1 -0
- package/frame-forwarding/lib/electron/adapter.d.ts +9 -0
- package/frame-forwarding/lib/electron/adapter.js +118 -0
- package/frame-forwarding/lib/electron/index.d.ts +3 -0
- package/frame-forwarding/lib/electron/index.js +3 -0
- package/frame-forwarding/lib/electron/preload.d.ts +13 -0
- package/frame-forwarding/lib/electron/preload.js +47 -0
- package/frame-forwarding/lib/electron/transfer.d.ts +15 -0
- package/frame-forwarding/lib/electron/transfer.js +36 -0
- package/frame-forwarding/prebuilds/darwin-arm64/frame-forwarding.node +0 -0
- package/frame-forwarding/prebuilds/darwin-arm64/libdsh_frame_forwarding_sdk.a +0 -0
- package/frame-forwarding/prebuilds/darwin-arm64/manifest.json +34 -0
- package/frame-forwarding/prebuilds/darwin-x64/frame-forwarding.node +0 -0
- package/frame-forwarding/prebuilds/darwin-x64/libdsh_frame_forwarding_sdk.a +0 -0
- package/frame-forwarding/prebuilds/darwin-x64/manifest.json +34 -0
- package/frame-forwarding/prebuilds/win32-arm64/dsh_frame_forwarding_sdk.lib +0 -0
- package/frame-forwarding/prebuilds/win32-arm64/frame-forwarding.node +0 -0
- package/frame-forwarding/prebuilds/win32-arm64/manifest.json +34 -0
- package/frame-forwarding/prebuilds/win32-x64/dsh_frame_forwarding_sdk.lib +0 -0
- package/frame-forwarding/prebuilds/win32-x64/frame-forwarding.node +0 -0
- package/frame-forwarding/prebuilds/win32-x64/manifest.json +34 -0
- package/frame-forwarding/receipt.json +23 -0
- package/frame-forwarding/scripts/build-webgpu.mjs +197 -0
- package/frame-forwarding/scripts/build.mjs +43 -0
- package/frame-forwarding/scripts/metadata.mjs +47 -0
- package/frame-forwarding/scripts/source-identity.mjs +15 -0
- package/frame-forwarding/scripts/verify-prebuilds.mjs +14 -0
- package/frame-forwarding/sdk.json +45 -0
- package/frame-forwarding/src/node-producer.cc +595 -0
- package/frame-forwarding/src/producer-internal.h +8 -0
- package/frame-forwarding/src/producer.cc +306 -0
- package/frame-forwarding/src/receiver.cc +1050 -0
- package/frame-forwarding/src/relay-transport.inc +293 -0
- package/frame-forwarding/src/transport.cc +405 -0
- package/frame-forwarding/src/transport.h +80 -0
- package/frame-forwarding/src/webgpu.cc +214 -0
- package/frame-forwarding/src/win-delay-load.LICENSE +24 -0
- package/frame-forwarding/src/win-delay-load.cc +43 -0
- package/frame-forwarding/verify.d.mts +4 -0
- package/frame-forwarding/verify.mjs +101 -0
- package/frame-forwarding/webgpu-dependencies.json +51 -0
- package/lib/cli.js +109 -46
- package/lib/editor.js +2061 -0
- package/lib/index.js +109 -46
- 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 +30 -2
- package/lib/types/runtime.d.ts +2 -0
- package/lib/types/worker.d.ts +2 -2
- package/lib/worker.js +38 -31
- package/package.json +94 -9
package/lib/index.js
CHANGED
|
@@ -335,12 +335,17 @@ let pipeAttributes;
|
|
|
335
335
|
function windowsPipes() {
|
|
336
336
|
const koffi = createRequire(import.meta.url)("koffi");
|
|
337
337
|
const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
|
|
338
|
-
const attributes = pipeAttributes ??= koffi.struct(
|
|
338
|
+
const attributes = pipeAttributes ??= koffi.struct({
|
|
339
339
|
nLength: "uint32",
|
|
340
340
|
lpSecurityDescriptor: "void *",
|
|
341
341
|
bInheritHandle: "int"
|
|
342
342
|
});
|
|
343
|
-
const createPipe = kernel.func("
|
|
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
|
+
]);
|
|
344
349
|
const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
345
350
|
const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
|
|
346
351
|
const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
|
|
@@ -469,6 +474,9 @@ function spawnNative(executable, args, env) {
|
|
|
469
474
|
stdin = stdin;
|
|
470
475
|
stdout = output.readable;
|
|
471
476
|
stderr = error.readable;
|
|
477
|
+
get pid() {
|
|
478
|
+
return child.pid;
|
|
479
|
+
}
|
|
472
480
|
get exitCode() {
|
|
473
481
|
return child.exitCode;
|
|
474
482
|
}
|
|
@@ -702,7 +710,9 @@ const NATIVE_ENVIRONMENT_KEYS = [
|
|
|
702
710
|
"PATHEXT",
|
|
703
711
|
"LANG",
|
|
704
712
|
"LC_ALL",
|
|
705
|
-
"TZ"
|
|
713
|
+
"TZ",
|
|
714
|
+
"OFFICE_GRAPHITE_DIAGNOSTICS",
|
|
715
|
+
"OFFICE_LOAD_DIAGNOSTICS"
|
|
706
716
|
];
|
|
707
717
|
function fontSearchName(value) {
|
|
708
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, "");
|
|
@@ -754,34 +764,84 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
|
|
|
754
764
|
});
|
|
755
765
|
}
|
|
756
766
|
/**
|
|
757
|
-
*
|
|
767
|
+
* Prepare short Windows engine paths owned by the caller's private profile.
|
|
758
768
|
* @param engine - Verified engine installation; its resources remain in place.
|
|
759
769
|
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
760
|
-
* @
|
|
761
|
-
* @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.
|
|
762
771
|
*/
|
|
763
|
-
async function
|
|
764
|
-
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
|
+
};
|
|
765
777
|
const root = join(profile, "engine");
|
|
766
778
|
await symlink(engine.root, root, "junction");
|
|
767
779
|
try {
|
|
768
780
|
const executable = join(profile, "libreoffice-kit.exe");
|
|
769
781
|
await copyFile(engine.executable, executable, constants.COPYFILE_EXCL);
|
|
770
|
-
return
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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) {
|
|
777
792
|
await unlink(root);
|
|
793
|
+
throw error;
|
|
778
794
|
}
|
|
779
795
|
}
|
|
780
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
|
+
/**
|
|
781
841
|
* Run one native conversion and await bounded result transport.
|
|
782
842
|
* @param engine - Resolved native engine installation.
|
|
783
843
|
* @param options - Validated conversion limits.
|
|
784
|
-
* @param input -
|
|
844
|
+
* @param input - Owned source bytes and format; older pinned helpers receive a private input file.
|
|
785
845
|
* @param output - Private PDF path inside the conversion scratch directory.
|
|
786
846
|
* @param profile - Conversion-owned profile directory.
|
|
787
847
|
* @param fonts - Installed font files the helper may load.
|
|
@@ -800,11 +860,12 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
800
860
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
801
861
|
signal.throwIfAborted();
|
|
802
862
|
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
863
|
+
const transport = await prepareNativeInput(engine, input, profile, signal);
|
|
864
|
+
signal.throwIfAborted();
|
|
803
865
|
const child = spawnNative(engine.executable, [
|
|
804
866
|
"--program-directory",
|
|
805
867
|
engine.programDirectory,
|
|
806
|
-
|
|
807
|
-
input,
|
|
868
|
+
...transport.args,
|
|
808
869
|
"--output-path",
|
|
809
870
|
output,
|
|
810
871
|
"--profile-directory",
|
|
@@ -820,7 +881,6 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
820
881
|
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
821
882
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
822
883
|
], env);
|
|
823
|
-
child.stdin.end();
|
|
824
884
|
let stdout = "";
|
|
825
885
|
let stderr = "";
|
|
826
886
|
let failure;
|
|
@@ -841,6 +901,11 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
841
901
|
child.stderr.on("data", (chunk) => {
|
|
842
902
|
stderr = (stderr + chunk).slice(-65536);
|
|
843
903
|
});
|
|
904
|
+
child.stdin.on("error", (error) => {
|
|
905
|
+
failure ??= error;
|
|
906
|
+
child.kill("SIGKILL");
|
|
907
|
+
});
|
|
908
|
+
child.stdin.end(transport.bytes);
|
|
844
909
|
try {
|
|
845
910
|
const code = await new Promise((resolve, reject) => {
|
|
846
911
|
child.once("error", (error) => {
|
|
@@ -996,19 +1061,22 @@ function plan(ready, request) {
|
|
|
996
1061
|
}
|
|
997
1062
|
/** Run one native image batch and write final PNGs only after each bounded paint succeeds. */
|
|
998
1063
|
async function renderImagesWithNative(request) {
|
|
999
|
-
const { engine, options,
|
|
1064
|
+
const { engine, options, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
|
|
1000
1065
|
signal.throwIfAborted();
|
|
1001
1066
|
await mkdir(profile, { mode: 448 });
|
|
1002
1067
|
await prepareNativeFontProfile(profile, substitutions);
|
|
1003
1068
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
1069
|
+
const transport = await prepareNativeInput(engine, {
|
|
1070
|
+
bytes: source,
|
|
1071
|
+
format: operation.extension
|
|
1072
|
+
}, profile, signal);
|
|
1004
1073
|
signal.throwIfAborted();
|
|
1005
1074
|
const child = spawnNative(engine.executable, [
|
|
1006
1075
|
"--operation",
|
|
1007
1076
|
"render-images",
|
|
1008
1077
|
"--program-directory",
|
|
1009
1078
|
engine.programDirectory,
|
|
1010
|
-
|
|
1011
|
-
inputPath,
|
|
1079
|
+
...transport.args,
|
|
1012
1080
|
"--scratch-directory",
|
|
1013
1081
|
scratch,
|
|
1014
1082
|
"--profile-directory",
|
|
@@ -1048,6 +1116,11 @@ async function renderImagesWithNative(request) {
|
|
|
1048
1116
|
child.kill("SIGKILL");
|
|
1049
1117
|
};
|
|
1050
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);
|
|
1051
1124
|
const next = async () => {
|
|
1052
1125
|
signal.throwIfAborted();
|
|
1053
1126
|
if (lines.length > 0) return lines.shift();
|
|
@@ -1462,16 +1535,16 @@ function resolveOptions(input = {}) {
|
|
|
1462
1535
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1463
1536
|
const require = createRequire(import.meta.url);
|
|
1464
1537
|
/** Node API release version returned by runtime discovery. */
|
|
1465
|
-
const ENGINE_VERSION = "0.
|
|
1538
|
+
const ENGINE_VERSION = "0.2.0-alpha6";
|
|
1466
1539
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1467
1540
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1468
|
-
"darwin-arm64": "0.
|
|
1469
|
-
"darwin-x64": "0.
|
|
1541
|
+
"darwin-arm64": "0.2.0-alpha6",
|
|
1542
|
+
"darwin-x64": "0.2.0-alpha6",
|
|
1470
1543
|
"linux-arm64-glibc": "0.1.1",
|
|
1471
1544
|
"linux-x64-glibc": "0.1.1",
|
|
1472
1545
|
"win32-arm64": "0.1.5",
|
|
1473
|
-
"win32-x64": "0.
|
|
1474
|
-
wasm: "0.
|
|
1546
|
+
"win32-x64": "0.2.0-alpha6",
|
|
1547
|
+
wasm: "0.2.0-alpha5"
|
|
1475
1548
|
});
|
|
1476
1549
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1477
1550
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
|
@@ -1510,7 +1583,7 @@ function glibcVersion(value) {
|
|
|
1510
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;
|
|
1511
1584
|
}
|
|
1512
1585
|
/**
|
|
1513
|
-
*
|
|
1586
|
+
* Prefer the installed compatible native engine; hosts without one use the shared WASM package.
|
|
1514
1587
|
* @param resolvePackage - Package manifest resolver; injectable for selection tests.
|
|
1515
1588
|
* @param packageExists - Installed-package probe; injectable for selection tests.
|
|
1516
1589
|
* @param host - Process identification and diagnostic report.
|
|
@@ -1528,7 +1601,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1528
1601
|
const failure = error;
|
|
1529
1602
|
if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
|
|
1530
1603
|
if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
|
|
1531
|
-
if (platform !== "linux") throw new Error(`Required LibreOfficeKit native package is missing: ${name}`, { cause: error });
|
|
1532
1604
|
}
|
|
1533
1605
|
if (packageFile !== void 0) {
|
|
1534
1606
|
const engine = await readEngine(packageFile, "native", target);
|
|
@@ -1537,7 +1609,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1537
1609
|
if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
|
|
1538
1610
|
}
|
|
1539
1611
|
}
|
|
1540
|
-
if (platform !== "linux") throw new Error(`Unsupported LibreOfficeKit host: ${platform}-${arch}`);
|
|
1541
1612
|
return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
|
|
1542
1613
|
}
|
|
1543
1614
|
async function engineAsset(root, value, name, kind) {
|
|
@@ -1562,6 +1633,7 @@ async function readEngine(packageFile, backend, target) {
|
|
|
1562
1633
|
root,
|
|
1563
1634
|
programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
|
|
1564
1635
|
executable,
|
|
1636
|
+
...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
|
|
1565
1637
|
...glibcFloor
|
|
1566
1638
|
};
|
|
1567
1639
|
}
|
|
@@ -1678,6 +1750,7 @@ async function discoverRuntime() {
|
|
|
1678
1750
|
return {
|
|
1679
1751
|
version: ENGINE_VERSION,
|
|
1680
1752
|
backend: engine.backend,
|
|
1753
|
+
nativePreview: engine.backend === "native" && !engine.legacyInputPath,
|
|
1681
1754
|
cliPath: fileURLToPath(new URL("./cli.js", import.meta.url)),
|
|
1682
1755
|
nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
|
|
1683
1756
|
};
|
|
@@ -1966,16 +2039,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1966
2039
|
output = await open(request.outputPath, "wx", 384);
|
|
1967
2040
|
const sourceBytes = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
1968
2041
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-"));
|
|
1969
|
-
const inputPath = join(scratch, `document.${extension}`);
|
|
1970
|
-
const input = await open(inputPath, "wx", 384);
|
|
1971
|
-
try {
|
|
1972
|
-
await input.writeFile(sourceBytes);
|
|
1973
|
-
} finally {
|
|
1974
|
-
await input.close();
|
|
1975
|
-
}
|
|
1976
2042
|
const fonts = await snapshot(stopped);
|
|
1977
2043
|
const result = await runWorker({
|
|
1978
|
-
|
|
2044
|
+
bytes: sourceBytes,
|
|
1979
2045
|
extension,
|
|
1980
2046
|
operation: request,
|
|
1981
2047
|
options: resolvedOptions,
|
|
@@ -1992,7 +2058,10 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1992
2058
|
const profile = join(scratch, "profile");
|
|
1993
2059
|
await mkdir(profile, { mode: 448 });
|
|
1994
2060
|
const path = join(scratch, `output.${format}`);
|
|
1995
|
-
await runNative(native, resolvedOptions,
|
|
2061
|
+
await runNative(native, resolvedOptions, {
|
|
2062
|
+
bytes: sourceBytes,
|
|
2063
|
+
format: extension
|
|
2064
|
+
}, path, profile, result.fonts, result.substitutions, stopped, request);
|
|
1996
2065
|
bytes = await readBounded(path, resolvedOptions.maxOutputBytes, stopped, "output");
|
|
1997
2066
|
}
|
|
1998
2067
|
validateOutput(bytes, format);
|
|
@@ -2043,14 +2112,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2043
2112
|
owned = true;
|
|
2044
2113
|
const source = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
2045
2114
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-images-"));
|
|
2046
|
-
const inputPath = join(scratch, `document.${request.extension}`);
|
|
2047
|
-
await writeFile(inputPath, source, {
|
|
2048
|
-
flag: "wx",
|
|
2049
|
-
mode: 384
|
|
2050
|
-
});
|
|
2051
2115
|
const fonts = await snapshot(stopped);
|
|
2052
2116
|
const result = await runWorker({
|
|
2053
|
-
|
|
2117
|
+
bytes: source,
|
|
2054
2118
|
extension: request.extension,
|
|
2055
2119
|
operation: request,
|
|
2056
2120
|
options: resolvedOptions,
|
|
@@ -2066,7 +2130,6 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2066
2130
|
images = await renderImagesWithNative({
|
|
2067
2131
|
engine,
|
|
2068
2132
|
options: resolvedOptions,
|
|
2069
|
-
inputPath,
|
|
2070
2133
|
source,
|
|
2071
2134
|
scratch,
|
|
2072
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
|
|
@@ -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-alpha6";
|
|
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.
|