@deepseek-ai/libreoffice-kit 0.1.5 → 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.
Files changed (77) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +44 -8
  3. package/README.zh.md +45 -9
  4. package/lib/cli.js +109 -46
  5. package/lib/editor.js +2061 -0
  6. package/lib/index.js +109 -46
  7. package/lib/types/editor-protocol.d.ts +29 -0
  8. package/lib/types/editor-transport.d.ts +36 -0
  9. package/lib/types/editor-types.d.ts +119 -0
  10. package/lib/types/editor.d.ts +105 -0
  11. package/lib/types/engine.d.ts +4 -2
  12. package/lib/types/fonts.d.ts +4 -8
  13. package/lib/types/native-image-renderer.d.ts +0 -1
  14. package/lib/types/native-process.d.ts +1 -0
  15. package/lib/types/native.d.ts +30 -2
  16. package/lib/types/runtime.d.ts +2 -0
  17. package/lib/types/worker.d.ts +2 -2
  18. package/lib/worker.js +38 -31
  19. package/native-render/CMakeLists.txt +40 -0
  20. package/native-render/LICENSE +21 -0
  21. package/native-render/README.md +83 -0
  22. package/native-render/README.zh.md +83 -0
  23. package/native-render/include/dsh_render.h +101 -0
  24. package/native-render/include/dsh_render_engine.h +66 -0
  25. package/native-render/include/dsh_render_node.h +27 -0
  26. package/native-render/include/dsh_webgpu.h +52 -0
  27. package/native-render/index.d.ts +145 -0
  28. package/native-render/index.mjs +71 -0
  29. package/native-render/lib/browser/display.d.ts +46 -0
  30. package/native-render/lib/browser/display.js +128 -0
  31. package/native-render/lib/browser/index.d.ts +4 -0
  32. package/native-render/lib/browser/index.js +3 -0
  33. package/native-render/lib/browser/painters.d.ts +9 -0
  34. package/native-render/lib/browser/painters.js +180 -0
  35. package/native-render/lib/browser/types.d.ts +51 -0
  36. package/native-render/lib/browser/types.js +1 -0
  37. package/native-render/lib/electron/adapter.d.ts +9 -0
  38. package/native-render/lib/electron/adapter.js +118 -0
  39. package/native-render/lib/electron/index.d.ts +3 -0
  40. package/native-render/lib/electron/index.js +3 -0
  41. package/native-render/lib/electron/preload.d.ts +13 -0
  42. package/native-render/lib/electron/preload.js +47 -0
  43. package/native-render/lib/electron/transfer.d.ts +15 -0
  44. package/native-render/lib/electron/transfer.js +36 -0
  45. package/native-render/prebuilds/darwin-arm64/libdsh_render_sdk.a +0 -0
  46. package/native-render/prebuilds/darwin-arm64/manifest.json +34 -0
  47. package/native-render/prebuilds/darwin-arm64/render.node +0 -0
  48. package/native-render/prebuilds/darwin-x64/libdsh_render_sdk.a +0 -0
  49. package/native-render/prebuilds/darwin-x64/manifest.json +34 -0
  50. package/native-render/prebuilds/darwin-x64/render.node +0 -0
  51. package/native-render/prebuilds/win32-arm64/dsh_render_sdk.lib +0 -0
  52. package/native-render/prebuilds/win32-arm64/manifest.json +34 -0
  53. package/native-render/prebuilds/win32-arm64/render.node +0 -0
  54. package/native-render/prebuilds/win32-x64/dsh_render_sdk.lib +0 -0
  55. package/native-render/prebuilds/win32-x64/manifest.json +34 -0
  56. package/native-render/prebuilds/win32-x64/render.node +0 -0
  57. package/native-render/receipt.json +23 -0
  58. package/native-render/scripts/build-webgpu.mjs +197 -0
  59. package/native-render/scripts/build.mjs +43 -0
  60. package/native-render/scripts/metadata.mjs +47 -0
  61. package/native-render/scripts/source-identity.mjs +15 -0
  62. package/native-render/scripts/verify-prebuilds.mjs +14 -0
  63. package/native-render/sdk.json +45 -0
  64. package/native-render/src/node-producer.cc +595 -0
  65. package/native-render/src/producer-internal.h +8 -0
  66. package/native-render/src/producer.cc +306 -0
  67. package/native-render/src/receiver.cc +1050 -0
  68. package/native-render/src/relay-transport.inc +293 -0
  69. package/native-render/src/transport.cc +405 -0
  70. package/native-render/src/transport.h +80 -0
  71. package/native-render/src/webgpu.cc +214 -0
  72. package/native-render/src/win-delay-load.LICENSE +24 -0
  73. package/native-render/src/win-delay-load.cc +43 -0
  74. package/native-render/verify.d.mts +4 -0
  75. package/native-render/verify.mjs +101 -0
  76. package/native-render/webgpu-dependencies.json +51 -0
  77. package/package.json +95 -10
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("KIT_SECURITY_ATTRIBUTES", {
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("int __stdcall CreatePipe(_Out_ void **read, _Out_ void **write, KIT_SECURITY_ATTRIBUTES *attributes, uint32 size)");
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
- * Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
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
- * @param run - Operation that settles only after its helper closes.
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 withNativeEngine(engine, profile, run) {
764
- if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return run(engine);
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 await run({
771
- ...engine,
772
- root,
773
- executable,
774
- programDirectory: join(root, relative(engine.root, engine.programDirectory))
775
- });
776
- } finally {
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 - Private source path inside the conversion scratch directory.
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
- "--input-path",
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, inputPath, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
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
- "--input-path",
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.1.5";
1538
+ const ENGINE_VERSION = "0.2.0-alpha5";
1466
1539
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1467
1540
  const ENGINE_VERSIONS = Object.freeze({
1468
- "darwin-arm64": "0.1.5",
1469
- "darwin-x64": "0.1.5",
1541
+ "darwin-arm64": "0.2.0-alpha5",
1542
+ "darwin-x64": "0.2.0-alpha5",
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.1.5",
1474
- wasm: "0.1.5"
1546
+ "win32-x64": "0.2.0-alpha5",
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
- * macOS and Windows require their native engine. Linux uses WASM when no compatible development native engine is installed.
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
- inputPath,
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, inputPath, path, profile, result.fonts, result.substitutions, stopped, request);
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
- inputPath,
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
@@ -1,5 +1,5 @@
1
1
  /** Node API release version returned by runtime discovery. */
2
- export declare const ENGINE_VERSION = "0.1.5";
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
- * macOS and Windows require their native engine. Linux uses WASM when no compatible development native engine is installed.
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.