@deepseek-ai/libreoffice-kit 0.2.0 → 0.2.2

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 (47) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +5 -5
  3. package/README.zh.md +5 -5
  4. package/frame-forwarding/CMakeLists.txt +3 -4
  5. package/frame-forwarding/README.md +18 -18
  6. package/frame-forwarding/README.zh.md +19 -19
  7. package/frame-forwarding/include/dsh_frame_forwarding.h +33 -9
  8. package/frame-forwarding/index.d.ts +58 -54
  9. package/frame-forwarding/index.mjs +14 -17
  10. package/frame-forwarding/prebuilds/darwin-arm64/frame-forwarding.node +0 -0
  11. package/frame-forwarding/prebuilds/darwin-arm64/libdsh_frame_forwarding_sdk.a +0 -0
  12. package/frame-forwarding/prebuilds/darwin-arm64/manifest.json +22 -21
  13. package/frame-forwarding/prebuilds/darwin-x64/frame-forwarding.node +0 -0
  14. package/frame-forwarding/prebuilds/darwin-x64/libdsh_frame_forwarding_sdk.a +0 -0
  15. package/frame-forwarding/prebuilds/darwin-x64/manifest.json +22 -21
  16. package/frame-forwarding/prebuilds/win32-arm64/dsh_frame_forwarding_sdk.lib +0 -0
  17. package/frame-forwarding/prebuilds/win32-arm64/frame-forwarding.node +0 -0
  18. package/frame-forwarding/prebuilds/win32-arm64/manifest.json +22 -21
  19. package/frame-forwarding/prebuilds/win32-x64/dsh_frame_forwarding_sdk.lib +0 -0
  20. package/frame-forwarding/prebuilds/win32-x64/frame-forwarding.node +0 -0
  21. package/frame-forwarding/prebuilds/win32-x64/manifest.json +22 -21
  22. package/frame-forwarding/receipt.json +15 -14
  23. package/frame-forwarding/scripts/build-webgpu.mjs +1 -0
  24. package/frame-forwarding/scripts/build.mjs +3 -3
  25. package/frame-forwarding/scripts/metadata.mjs +11 -8
  26. package/frame-forwarding/scripts/source-identity.mjs +3 -3
  27. package/frame-forwarding/sdk.json +6 -5
  28. package/frame-forwarding/{include/dsh_webgpu.h → src/graphite-interop-internal.hxx} +22 -22
  29. package/frame-forwarding/src/{webgpu.cc → graphite-interop.cc} +34 -24
  30. package/frame-forwarding/src/node-producer.cc +24 -154
  31. package/frame-forwarding/src/producer.cc +93 -26
  32. package/frame-forwarding/src/receiver.cc +416 -212
  33. package/frame-forwarding/src/relay-transport.inc +38 -10
  34. package/frame-forwarding/src/transport.cc +307 -141
  35. package/frame-forwarding/src/transport.h +60 -9
  36. package/frame-forwarding/verify.d.mts +1 -1
  37. package/frame-forwarding/verify.mjs +19 -17
  38. package/lib/cli.js +6 -6
  39. package/lib/editor.js +15 -10
  40. package/lib/index.js +6 -6
  41. package/lib/types/editor.d.ts +17 -4
  42. package/lib/types/engine.d.ts +1 -1
  43. package/lib/types/fonts.d.ts +1 -1
  44. package/lib/worker.js +3 -2
  45. package/package.json +8 -10
  46. package/frame-forwarding/include/dsh_frame_forwarding_engine.h +0 -66
  47. package/frame-forwarding/include/dsh_frame_forwarding_node.h +0 -27
@@ -13,43 +13,92 @@ constexpr uint32_t magic = 0x44535231;
13
13
  enum Kind : uint32_t { hello = 1, ready, frame, release, message, goodbye, allocate, allocated, deallocate };
14
14
  /** hello.max_frames carries optional capabilities; zero is the legacy producer. */
15
15
  constexpr uint32_t hello_keyed_mutex = 1;
16
+ /**
17
+ * The producer holds a transferable TX credential and requires the connection identifier in ready.token. Receivers
18
+ * refuse producers without it, so a producer that relied on PID binding never connects.
19
+ */
20
+ constexpr uint32_t hello_transferable = 2;
21
+ /**
22
+ * frame.max_frames carries per-frame flags; zero is an ordered frame. A replaceable frame may be dropped before
23
+ * presentation once a newer replaceable frame of the same view is ready; receivers that ignore the flag present it.
24
+ */
25
+ constexpr uint32_t frame_replaceable = 1;
26
+ /** goodbye.text of a candidate the receiver refuses before it receives a connection identifier. */
27
+ constexpr const char* reject_busy = "channel-busy";
28
+ constexpr const char* reject_capability = "transferable-tx-required";
29
+ constexpr const char* reject_credential = "invalid-credential";
30
+ constexpr const char* reject_closed = "channel-closed";
31
+ /** Prefix of a refusal that names the producer's and the receiver's protocol versions. */
32
+ constexpr const char* reject_protocol = "protocol-mismatch";
16
33
  struct Packet {
17
34
  uint32_t marker = magic, version = DSH_FRAME_FORWARDING_PROTOCOL_VERSION, kind = 0;
18
35
  uint32_t width = 0, height = 0, stride = 0, max_frames = 0;
19
36
  uint64_t frame_id = 0, allocation_id = 0, max_bytes = 0, resource = 0;
37
+ /** hello: the TX secret. After the handshake: the decimal connection identifier. */
20
38
  char token[65] = {};
21
39
  char text[DSH_FRAME_FORWARDING_TEXT_CAPACITY] = {};
22
40
  };
23
41
  struct Received { Packet packet; uint32_t pid = 0; uintptr_t resource = 0; };
24
- /** A private single-peer channel. receive returns 1 data, 0 timeout, -1 closed/error. */
42
+ /**
43
+ * One physical producer connection. receive returns 1 data, 0 timeout, -1 closed/error. After bind_connection, every
44
+ * sent packet carries the connection identifier and a received packet without it closes the channel.
45
+ */
25
46
  class Channel {
26
47
  public:
27
48
  virtual ~Channel() = default;
28
- virtual int receive(Received&, uint32_t timeout_ms) = 0;
29
- virtual bool send(const Packet&, uintptr_t resource = 0) = 0;
49
+ int receive(Received& out, uint32_t timeout_ms);
50
+ bool send(const Packet& packet, uintptr_t resource = 0);
51
+ void bind_connection(uint64_t id);
52
+ uint64_t connection() const { return connection_; }
53
+ /** The last receive closed because a packet named another connection. */
54
+ bool foreign_packet() const { return foreign_; }
30
55
  virtual void interrupt() = 0;
31
56
  virtual uint32_t peer_pid() const = 0;
57
+ protected:
58
+ virtual int receive_packet(Received&, uint32_t timeout_ms) = 0;
59
+ virtual bool send_packet(const Packet&, uintptr_t resource) = 0;
60
+ private:
61
+ uint64_t connection_ = 0;
62
+ char connection_text_[65] = {};
63
+ bool foreign_ = false;
64
+ };
65
+ /** A producer whose hello reached the listener; its channel answers it before acceptance or refusal. */
66
+ struct Candidate { Received hello; std::unique_ptr<Channel> channel; };
67
+ /** The stable endpoint of one logical channel. Each producer connection gets a channel of its own. */
68
+ class Listener {
69
+ public:
70
+ virtual ~Listener() = default;
71
+ /** 1 candidate, 0 timeout, -1 stopped or failed. Malformed or silent connections are dropped without affecting others. */
72
+ virtual int accept(Candidate& candidate, uint32_t timeout_ms) = 0;
73
+ virtual void interrupt() = 0;
32
74
  };
33
75
  struct Endpoint { uint32_t pid; std::string token, name; };
34
76
  Endpoint parse_endpoint(const std::string& value);
35
- std::unique_ptr<Channel> listen_channel(Endpoint& endpoint);
77
+ /** Publish the endpoint name. handshake_ms bounds how long a connected client may withhold its hello. */
78
+ std::unique_ptr<Listener> listen(Endpoint& endpoint, uint32_t handshake_ms);
36
79
  std::unique_ptr<Channel> connect_channel(const Endpoint& endpoint, const std::function<bool()>& cancelled = {});
80
+ /** Parse a decimal connection identifier from a token; 0 when it is not one. */
81
+ uint64_t parse_connection(const char (&token)[65]);
37
82
  uint32_t process_id();
38
83
  uintptr_t receive_resource(Received& received);
39
84
  void release_resource(uintptr_t resource);
40
85
  void clear_validation_device();
41
86
  uint64_t resource_bytes(uintptr_t resource);
42
- bool resource_dimensions(uintptr_t resource, uint32_t width, uint32_t height, uint32_t stride, std::string& diagnostic, std::string& adapter, bool* keyed_mutex = nullptr);
87
+ /**
88
+ * Validate a producer frame's format and dimensions and report its adapter. On Windows a keyed-mutex texture is also
89
+ * made ready: key 0 is acquired within the deadline and released, before Chromium's unbounded key-0 acquisition.
90
+ */
91
+ bool resource_dimensions(uintptr_t resource, uint32_t width, uint32_t height, uint32_t stride,
92
+ std::chrono::steady_clock::time_point deadline, std::string& diagnostic, std::string& adapter, bool* keyed_mutex = nullptr);
43
93
  /** Adapter owning a shared resource, or an empty string when it cannot be identified. */
44
94
  std::string resource_adapter(uintptr_t resource);
45
95
  /** Adapter owning the producer's graphics device. */
46
96
  std::string device_adapter(void* device);
47
97
  #if defined(_WIN32)
48
- /** Bounded source readiness check before Chromium's unbounded key-0 acquisition. */
49
- bool resource_ready(uintptr_t resource, std::chrono::steady_clock::time_point deadline, std::string& diagnostic);
50
98
  struct RelayDevice;
51
99
  struct RelayTexture;
52
100
  struct RelayReadback;
101
+ struct RelaySource;
53
102
  uintptr_t relay_handle(const std::shared_ptr<RelayTexture>& texture);
54
103
  bool relay_begin(uintptr_t resource, uint32_t width, uint32_t height,
55
104
  const std::string& adapter, std::chrono::steady_clock::time_point deadline, const std::atomic<bool>& stopped,
@@ -59,8 +108,10 @@ int relay_advance(const std::shared_ptr<RelayTexture>& slot, const std::atomic<b
59
108
  uintptr_t relay_completion_event(const std::shared_ptr<RelayTexture>& slot);
60
109
  /** True only after every submitted copy completes or its device is removed. */
61
110
  bool relay_gpu_idle(const std::shared_ptr<RelayTexture>& slot, std::string& diagnostic);
62
- bool relay_readback_begin(uintptr_t resource, uint32_t width, uint32_t height,
63
- std::shared_ptr<RelayReadback>& slot, std::string& diagnostic,
111
+ /** Validate each frame and copy under key 0; reuse the allocation's import only for the same NT object and dimensions. */
112
+ bool relay_readback_begin(uintptr_t resource, uint32_t width, uint32_t height, uint32_t stride,
113
+ std::shared_ptr<RelayReadback>& slot, std::shared_ptr<RelaySource>& imported,
114
+ std::string& diagnostic, std::string& adapter, bool* keyed_mutex,
64
115
  std::chrono::steady_clock::time_point deadline);
65
116
  int relay_readback_ready(const std::shared_ptr<RelayReadback>& slot, bool retiring, std::string& diagnostic);
66
117
  uintptr_t relay_readback_event(const std::shared_ptr<RelayReadback>& slot);
@@ -1,4 +1,4 @@
1
1
  /** Validate one complete target's addon, static library, sources, hashes, and architecture. */
2
2
  export declare function verifyFrameForwardingPackage(directory: string, target: { platform: string; arch: string }): Promise<void>;
3
3
  /** Validate all four payloads against one Kit version and source commit. */
4
- export declare function verifyFrameForwardingPrebuilds(directory: string, expected?: { version?: string; sourceCommit?: string }): Promise<{ version: string; protocolVersion: number; sourceCommit: string }>;
4
+ export declare function verifyFrameForwardingPrebuilds(directory: string, expected?: { version?: string; sourceCommit?: string }): Promise<{ version: string; protocolVersion: number; capabilities: string[]; sourceCommit: string }>;
@@ -2,9 +2,10 @@
2
2
  import { createHash } from 'node:crypto';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
- import { buildSources, targets } from './scripts/metadata.mjs';
5
+ import { buildSources, capabilities, targets } from './scripts/metadata.mjs';
6
6
 
7
7
  const digest = bytes => createHash('sha256').update(bytes).digest('hex');
8
+ const sameCapabilities = value => JSON.stringify(value) === JSON.stringify(capabilities);
8
9
  function verifyObject(bytes, target, subject, archive = false) {
9
10
  if (target.platform === 'win32') {
10
11
  let machine;
@@ -49,53 +50,54 @@ function verifyArchive(bytes, target, subject) {
49
50
 
50
51
  /**
51
52
  * Check one target's addon, static SDK, and source files against its build receipt.
52
- * @param {string} directory Native-render SDK directory.
53
+ * @param {string} directory Frame-forwarding SDK directory.
53
54
  * @param {{platform:string,arch:string}} target Operating system and CPU architecture.
54
55
  * @returns {Promise<void>} Resolves only for a complete matching SDK target.
55
56
  */
56
57
  export async function verifyFrameForwardingPackage(directory, target) {
57
58
  const name = `${target.platform}-${target.arch}`;
58
- if (!targets.includes(name)) throw new Error(`Native rendering has no packaged backend for ${name}`);
59
+ if (!targets.includes(name)) throw new Error(`Frame forwarding has no packaged backend for ${name}`);
59
60
  const root = join(directory, 'prebuilds', name);
60
61
  const manifest = JSON.parse(await readFile(join(root, 'manifest.json'), 'utf8'));
61
62
  const sdk = JSON.parse(await readFile(join(directory, 'sdk.json'), 'utf8'));
62
63
  if (typeof sdk.version !== 'string' || !sdk.version || sdk.protocolVersion !== 1
64
+ || !sameCapabilities(sdk.capabilities) || !sameCapabilities(manifest.capabilities)
63
65
  || JSON.stringify(sdk.platforms) !== JSON.stringify(targets)
64
66
  || JSON.stringify(sdk.buildSources) !== JSON.stringify(buildSources)
65
67
  || manifest.platform !== name || manifest.protocolVersion !== sdk.protocolVersion || manifest.version !== sdk.version
66
- || !/^[a-f0-9]{40}$/.test(manifest.sourceCommit) || typeof manifest.sourceDirty !== 'boolean') throw new Error(`Native rendering build receipt does not match ${name}`);
68
+ || !/^[a-f0-9]{40}$/.test(manifest.sourceCommit) || typeof manifest.sourceDirty !== 'boolean') throw new Error(`Frame-forwarding build receipt does not match ${name}`);
67
69
  const library = target.platform === 'win32' ? 'dsh_frame_forwarding_sdk.lib' : 'libdsh_frame_forwarding_sdk.a';
68
- if (sdk.staticLibraries?.[name] !== `prebuilds/${name}/${library}`) throw new Error(`Native rendering library metadata differs: ${name}`);
69
- if (Object.keys(manifest.files ?? {}).sort().join(',') !== [library, 'frame-forwarding.node'].sort().join(',')) throw new Error(`Native rendering artifact inventory differs: ${name}`);
70
+ if (sdk.staticLibraries?.[name] !== `prebuilds/${name}/${library}`) throw new Error(`Frame-forwarding library metadata differs: ${name}`);
71
+ if (Object.keys(manifest.files ?? {}).sort().join(',') !== [library, 'frame-forwarding.node'].sort().join(',')) throw new Error(`Frame-forwarding artifact inventory differs: ${name}`);
70
72
  for (const filename of ['frame-forwarding.node', library]) {
71
73
  const bytes = await readFile(join(root, filename));
72
- if (digest(bytes) !== manifest.files[filename]) throw new Error(`Native rendering artifact hash mismatch: ${name}/${filename}`);
73
- if (filename === 'frame-forwarding.node') verifyObject(bytes, target, 'Native renderer');
74
- else verifyArchive(bytes, target, 'Native producer SDK');
74
+ if (digest(bytes) !== manifest.files[filename]) throw new Error(`Frame-forwarding artifact hash mismatch: ${name}/${filename}`);
75
+ if (filename === 'frame-forwarding.node') verifyObject(bytes, target, 'Frame-forwarding addon');
76
+ else verifyArchive(bytes, target, 'Frame-forwarding producer SDK');
75
77
  }
76
- if (Object.keys(manifest.sources ?? {}).sort().join(',') !== [...buildSources].sort().join(',')) throw new Error(`Native rendering source inventory differs: ${name}`);
78
+ if (Object.keys(manifest.sources ?? {}).sort().join(',') !== [...buildSources].sort().join(',')) throw new Error(`Frame-forwarding source inventory differs: ${name}`);
77
79
  for (const source of buildSources) {
78
- if (digest(await readFile(join(directory, source))) !== manifest.sources[source]) throw new Error(`Native source receipt differs: ${name}/${source}`);
80
+ if (digest(await readFile(join(directory, source))) !== manifest.sources[source]) throw new Error(`Frame-forwarding source receipt differs: ${name}/${source}`);
79
81
  }
80
82
  }
81
83
 
82
84
  /**
83
85
  * Require all four payloads to share the expected package version and source commit.
84
- * @param {string} directory Native-render SDK directory.
86
+ * @param {string} directory Frame-forwarding SDK directory.
85
87
  * @param {{version?:string,sourceCommit?:string}} expected Release identity, when known by the caller.
86
- * @returns {Promise<{version:string,protocolVersion:number,sourceCommit:string}>} Shared build identity.
88
+ * @returns {Promise<{version:string,protocolVersion:number,capabilities:string[],sourceCommit:string}>} Shared build identity.
87
89
  */
88
90
  export async function verifyFrameForwardingPrebuilds(directory, expected = {}) {
89
91
  const sdk = JSON.parse(await readFile(join(directory, 'sdk.json'), 'utf8'));
90
- if (expected.version !== undefined && sdk.version !== expected.version) throw new Error('Native render version differs from the Kit package');
92
+ if (expected.version !== undefined && sdk.version !== expected.version) throw new Error('Frame-forwarding version differs from the Kit package');
91
93
  let sourceCommit = expected.sourceCommit;
92
94
  for (const name of targets) {
93
95
  const [platform, arch] = name.split('-');
94
96
  await verifyFrameForwardingPackage(directory, { platform, arch });
95
97
  const manifest = JSON.parse(await readFile(join(directory, 'prebuilds', name, 'manifest.json'), 'utf8'));
96
- if (manifest.sourceDirty) throw new Error(`Native render artifact was built from dirty SDK sources: ${name}`);
98
+ if (manifest.sourceDirty) throw new Error(`Frame-forwarding artifact was built from dirty SDK sources: ${name}`);
97
99
  sourceCommit ??= manifest.sourceCommit;
98
- if (sourceCommit !== manifest.sourceCommit) throw new Error(`Native render source commit differs: ${name}`);
100
+ if (sourceCommit !== manifest.sourceCommit) throw new Error(`Frame-forwarding source commit differs: ${name}`);
99
101
  }
100
- return { version: sdk.version, protocolVersion: sdk.protocolVersion, sourceCommit };
102
+ return { version: sdk.version, protocolVersion: sdk.protocolVersion, capabilities: sdk.capabilities, sourceCommit };
101
103
  }
package/lib/cli.js CHANGED
@@ -1537,16 +1537,16 @@ function resolveOptions(input = {}) {
1537
1537
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1538
1538
  const require = createRequire(import.meta.url);
1539
1539
  /** Node API release version returned by runtime discovery. */
1540
- const ENGINE_VERSION = "0.2.0";
1540
+ const ENGINE_VERSION = "0.2.2";
1541
1541
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1542
1542
  const ENGINE_VERSIONS = Object.freeze({
1543
- "darwin-arm64": "0.2.0",
1544
- "darwin-x64": "0.2.0",
1543
+ "darwin-arm64": "0.2.2",
1544
+ "darwin-x64": "0.2.2",
1545
1545
  "linux-arm64-glibc": "0.1.1",
1546
1546
  "linux-x64-glibc": "0.1.1",
1547
- "win32-arm64": "0.2.0",
1548
- "win32-x64": "0.2.0",
1549
- wasm: "0.2.0"
1547
+ "win32-arm64": "0.2.2",
1548
+ "win32-x64": "0.2.2",
1549
+ wasm: "0.2.2"
1550
1550
  });
1551
1551
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1552
1552
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
package/lib/editor.js CHANGED
@@ -176,7 +176,7 @@ var SystemFontCatalog = class {
176
176
  }
177
177
  /**
178
178
  * Find installed faces covering the requested family or missing characters.
179
- * Exact families precede configured alternatives, symbol families for missing symbols,
179
+ * Exact families precede configured alternatives, symbol families for requests without letters or numbers,
180
180
  * generic families, then other glyph-covering faces.
181
181
  * @param request - VCL family/style attributes and Unicode scalars missing from its current font.
182
182
  * @param signal - cancellation checked between synchronous font reads.
@@ -189,7 +189,8 @@ var SystemFontCatalog = class {
189
189
  const primary = requested[0];
190
190
  let missingFamily;
191
191
  if (primary !== void 0 && !GENERIC_FAMILIES.has(normalize(primary)) && !this.faces.some((face) => face.aliases.includes(normalize(primary)))) missingFamily = primary;
192
- const priority = fontFamilyPriority(requested, this.options.fallbackFamilies, request.pitch, request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point)))).map(normalize);
192
+ const symbols = request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point))) && !request.codePoints.some((point) => /[\p{Letter}\p{Number}]/u.test(String.fromCodePoint(point)));
193
+ const priority = fontFamilyPriority(requested, this.options.fallbackFamilies, request.pitch, symbols).map(normalize);
193
194
  const missing = new Set(request.codePoints);
194
195
  const ranked = this.faces.map((face) => {
195
196
  const rank = priority.findIndex((family) => face.aliases.includes(family));
@@ -474,13 +475,13 @@ function resolveOptions(input = {}) {
474
475
  const require = createRequire(import.meta.url);
475
476
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
476
477
  const ENGINE_VERSIONS = Object.freeze({
477
- "darwin-arm64": "0.2.0",
478
- "darwin-x64": "0.2.0",
478
+ "darwin-arm64": "0.2.2",
479
+ "darwin-x64": "0.2.2",
479
480
  "linux-arm64-glibc": "0.1.1",
480
481
  "linux-x64-glibc": "0.1.1",
481
- "win32-arm64": "0.2.0",
482
- "win32-x64": "0.2.0",
483
- wasm: "0.2.0"
482
+ "win32-arm64": "0.2.2",
483
+ "win32-x64": "0.2.2",
484
+ wasm: "0.2.2"
484
485
  });
485
486
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
486
487
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -1647,7 +1648,8 @@ var EditorTransport = class {
1647
1648
  return;
1648
1649
  }
1649
1650
  if (c.kind === "ready") {
1650
- if (c.protocol !== 4 || c.nativeRenderProtocol !== 1 || frame.pixels.length !== 0) throw new Error("Native editor requires editor protocol 4 and native render protocol 1.");
1651
+ if (c.protocol !== 4 || c.frameForwardingProtocol !== 1 || frame.pixels.length !== 0) throw new Error("Native editor requires editor protocol 4 and frame-forwarding protocol 1.");
1652
+ if (c.frameForwardingTransferable !== true) throw new Error("Native editor predates transferable frame-forwarding channels; install the matching engine.");
1651
1653
  this.initialized = true;
1652
1654
  clearTimeout(this.startupTimer);
1653
1655
  this.ready.resolve(frame);
@@ -1881,10 +1883,13 @@ async function openDocument(request) {
1881
1883
  missingFonts: fonts.missingFonts,
1882
1884
  writable,
1883
1885
  processId: process.processId,
1884
- async attachSurfaceTransport(endpoint) {
1886
+ async attachSurfaceTransport(tx, { timeoutMs }) {
1887
+ if (typeof tx !== "string" || tx.length === 0) throw new TypeError("A frame-forwarding TX credential is required.");
1888
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs >= options.timeoutMs) throw new RangeError("Surface transport timeoutMs must be a positive integer below the operation timeout.");
1885
1889
  await execute({
1886
1890
  op: "attachSurfaceTransport",
1887
- endpoint
1891
+ tx,
1892
+ timeoutMs
1888
1893
  });
1889
1894
  },
1890
1895
  async detachSurfaceTransport() {
package/lib/index.js CHANGED
@@ -1535,16 +1535,16 @@ function resolveOptions(input = {}) {
1535
1535
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1536
1536
  const require = createRequire(import.meta.url);
1537
1537
  /** Node API release version returned by runtime discovery. */
1538
- const ENGINE_VERSION = "0.2.0";
1538
+ const ENGINE_VERSION = "0.2.2";
1539
1539
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1540
1540
  const ENGINE_VERSIONS = Object.freeze({
1541
- "darwin-arm64": "0.2.0",
1542
- "darwin-x64": "0.2.0",
1541
+ "darwin-arm64": "0.2.2",
1542
+ "darwin-x64": "0.2.2",
1543
1543
  "linux-arm64-glibc": "0.1.1",
1544
1544
  "linux-x64-glibc": "0.1.1",
1545
- "win32-arm64": "0.2.0",
1546
- "win32-x64": "0.2.0",
1547
- wasm: "0.2.0"
1545
+ "win32-arm64": "0.2.2",
1546
+ "win32-x64": "0.2.2",
1547
+ wasm: "0.2.2"
1548
1548
  });
1549
1549
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1550
1550
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -47,9 +47,14 @@ export interface EditorSurfaceResult {
47
47
  readonly part?: number;
48
48
  readonly ended?: boolean;
49
49
  }
50
+ /** Deadline for connecting a document to a frame-forwarding channel. */
51
+ export interface EditorSurfaceTransportOptions {
52
+ /** Positive milliseconds, shorter than the document's operation timeout. */
53
+ readonly timeoutMs: number;
54
+ }
50
55
  /** One in-memory document with ordered operations and explicit process ownership. Native views hide comments while original-format snapshots retain their data. */
51
56
  export interface EditorDocument {
52
- /** Owned native PID, usable only by a trusted local transport broker. */
57
+ /** Owned native PID for process supervision; frame-forwarding channels do not authorize by process. */
53
58
  readonly processId: number;
54
59
  readonly initialInfo: EditorInfo;
55
60
  readonly missingFonts: readonly string[];
@@ -58,9 +63,17 @@ export interface EditorDocument {
58
63
  readonly revision: number;
59
64
  /** Subscribe to transient engine callbacks and process failure; returns an unsubscribe function. */
60
65
  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. */
66
+ /**
67
+ * Connect shared rendering and input to a frame-forwarding channel with its TX credential. While another producer of
68
+ * the channel is connected the attach rejects with a message starting "channel-busy"; after that producer
69
+ * disconnects, it waits until the receiver released the previous connection's frames. The wait is bounded by
70
+ * `timeoutMs`, which must be shorter than the document's operation timeout because an operation timeout ends the
71
+ * session.
72
+ * @param tx - TX credential issued by the channel's receiver.
73
+ * @param options - Connection deadline in milliseconds.
74
+ */
75
+ attachSurfaceTransport(tx: string, options: EditorSurfaceTransportOptions): Promise<void>;
76
+ /** Close this document's producer connection; the channel and its TX credential stay valid for a successor. The editable document is retained. */
64
77
  detachSurfaceTransport(): Promise<void>;
65
78
  /** Wait for the canonical direct-input sequence before the next business operation. */
66
79
  waitForInput(sequence: number): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  /** Node API release version returned by runtime discovery. */
2
- export declare const ENGINE_VERSION = "0.2.0";
2
+ export declare const ENGINE_VERSION = "0.2.2";
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. */
@@ -125,7 +125,7 @@ export declare class SystemFontCatalog {
125
125
  constructor(options: SystemFontCatalogOptions);
126
126
  /**
127
127
  * Find installed faces covering the requested family or missing characters.
128
- * Exact families precede configured alternatives, symbol families for missing symbols,
128
+ * Exact families precede configured alternatives, symbol families for requests without letters or numbers,
129
129
  * generic families, then other glyph-covering faces.
130
130
  * @param request - VCL family/style attributes and Unicode scalars missing from its current font.
131
131
  * @param signal - cancellation checked between synchronous font reads.
package/lib/worker.js CHANGED
@@ -157,7 +157,7 @@ var SystemFontCatalog = class {
157
157
  }
158
158
  /**
159
159
  * Find installed faces covering the requested family or missing characters.
160
- * Exact families precede configured alternatives, symbol families for missing symbols,
160
+ * Exact families precede configured alternatives, symbol families for requests without letters or numbers,
161
161
  * generic families, then other glyph-covering faces.
162
162
  * @param request - VCL family/style attributes and Unicode scalars missing from its current font.
163
163
  * @param signal - cancellation checked between synchronous font reads.
@@ -170,7 +170,8 @@ var SystemFontCatalog = class {
170
170
  const primary = requested[0];
171
171
  let missingFamily;
172
172
  if (primary !== void 0 && !GENERIC_FAMILIES.has(normalize(primary)) && !this.faces.some((face) => face.aliases.includes(normalize(primary)))) missingFamily = primary;
173
- const priority = fontFamilyPriority(requested, this.options.fallbackFamilies, request.pitch, request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point)))).map(normalize);
173
+ const symbols = request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point))) && !request.codePoints.some((point) => /[\p{Letter}\p{Number}]/u.test(String.fromCodePoint(point)));
174
+ const priority = fontFamilyPriority(requested, this.options.fallbackFamilies, request.pitch, symbols).map(normalize);
174
175
  const missing = new Set(request.codePoints);
175
176
  const ranked = this.faces.map((face) => {
176
177
  const rank = priority.findIndex((family) => face.aliases.includes(family));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/libreoffice-kit",
3
3
  "description": "Convert, recalculate, and render Office documents with prebuilt LibreOffice",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -69,9 +69,7 @@
69
69
  "frame-forwarding/README.md",
70
70
  "frame-forwarding/README.zh.md",
71
71
  "frame-forwarding/include/dsh_frame_forwarding.h",
72
- "frame-forwarding/include/dsh_frame_forwarding_engine.h",
73
- "frame-forwarding/include/dsh_frame_forwarding_node.h",
74
- "frame-forwarding/include/dsh_webgpu.h",
72
+ "frame-forwarding/src/graphite-interop-internal.hxx",
75
73
  "frame-forwarding/src/node-producer.cc",
76
74
  "frame-forwarding/src/producer-internal.h",
77
75
  "frame-forwarding/src/transport.h",
@@ -81,7 +79,7 @@
81
79
  "frame-forwarding/src/receiver.cc",
82
80
  "frame-forwarding/src/win-delay-load.cc",
83
81
  "frame-forwarding/src/win-delay-load.LICENSE",
84
- "frame-forwarding/src/webgpu.cc",
82
+ "frame-forwarding/src/graphite-interop.cc",
85
83
  "frame-forwarding/CMakeLists.txt",
86
84
  "frame-forwarding/sdk.json",
87
85
  "frame-forwarding/scripts/build.mjs",
@@ -126,11 +124,11 @@
126
124
  },
127
125
  "optionalDependencies": {
128
126
  "koffi": "3.1.1",
129
- "@deepseek-ai/libreoffice-kit-darwin-x64": "0.2.0",
130
- "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.2.0",
131
- "@deepseek-ai/libreoffice-kit-wasm": "0.2.0",
132
- "@deepseek-ai/libreoffice-kit-win32-x64": "0.2.0",
133
- "@deepseek-ai/libreoffice-kit-win32-arm64": "0.2.0"
127
+ "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.2.2",
128
+ "@deepseek-ai/libreoffice-kit-darwin-x64": "0.2.2",
129
+ "@deepseek-ai/libreoffice-kit-win32-arm64": "0.2.2",
130
+ "@deepseek-ai/libreoffice-kit-wasm": "0.2.2",
131
+ "@deepseek-ai/libreoffice-kit-win32-x64": "0.2.2"
134
132
  },
135
133
  "bin": {
136
134
  "dsoffice": "./lib/cli.js"
@@ -1,66 +0,0 @@
1
- #ifndef DSH_FRAME_FORWARDING_ENGINE_H
2
- #define DSH_FRAME_FORWARDING_ENGINE_H
3
- #include <stddef.h>
4
- #include <stdint.h>
5
- #ifdef __cplusplus
6
- extern "C" {
7
- #endif
8
- /** A borrowed GPU target valid only during render(). Native objects never enter JS. */
9
- typedef struct dsh_frame_forwarding_target {
10
- void* texture; /* IOSurfaceRef on macOS; ID3D11Texture2D* on Windows. */
11
- void* shared_handle; /* Borrowed Windows NT handle; NULL on macOS. */
12
- void* device; /* Borrowed ID3D11Device*; NULL on macOS. */
13
- uint32_t width, height;
14
- uint64_t frame_id, input_sequence;
15
- double time_seconds; /* Monotonic time since this producer was created. */
16
- void* cancellation_context;
17
- int (*cancelled)(void*); /* Close or operation deadline; callable from this worker. */
18
- } dsh_frame_forwarding_target;
19
- /** Native engine adapter ABI v1. The factory and its configuration outlive the
20
- * producer. Every callback runs serially on that producer's native worker.
21
- * create/destroy own one engine instance; device returns its borrowed D3D11
22
- * device (or NULL for default/macOS). update receives bounded application JSON.
23
- * On Windows the SDK owns key 0 around render: queue commands on target.device's
24
- * immediate context without acquiring the mutex again. Release imported views
25
- * before returning 1; no completion wait is required. On macOS GPU writes must
26
- * be complete on return. External devices/import APIs that acquire their own lock
27
- * use the C surface API instead of this callback. Return 0 with diagnostic text on failure; the producer closes
28
- * instead of reusing a target whose completion is uncertain. Long-running work
29
- * must observe target.cancelled. No callback may throw across this C ABI.
30
- */
31
- typedef struct dsh_frame_forwarding_engine_v1 {
32
- uint32_t version, size;
33
- void* configuration;
34
- void* (*create)(void* configuration, char* error, size_t error_size);
35
- void (*destroy)(void* engine);
36
- void* (*device)(void* engine);
37
- int (*update)(void* engine, const char* json, char* error, size_t error_size);
38
- int (*render)(void* engine, const dsh_frame_forwarding_target* target, char* error, size_t error_size);
39
- } dsh_frame_forwarding_engine_v1;
40
- /** Surface-free frame information borrowed during prepare(). */
41
- typedef struct dsh_frame_forwarding_frame_info {
42
- uint32_t width, height;
43
- uint64_t input_sequence;
44
- double time_seconds;
45
- void* cancellation_context;
46
- int (*cancelled)(void*);
47
- } dsh_frame_forwarding_frame_info;
48
- /** Engine ABI v2: base.version is 2 and base.size is sizeof(dsh_frame_forwarding_engine_v2).
49
- * The v1 callbacks and ownership rules are unchanged. prepare runs on the same
50
- * worker before acquiring a surface: 1 declares a changed frame, 0 declares no
51
- * change, and -1 reports failure with diagnostic text. It must honor cancelled
52
- * and must not acquire or access a transport surface. A declared change remains
53
- * pending across credit waits; update may replace that pending application state
54
- * before render. prepare continues at the stream cadence while credit is held.
55
- * A successful render consumes the prepared state. Starting or
56
- * resizing a stream forces one render even when prepare reports no change.
57
- * Manual surface.render() invokes base.render directly, without prepare.
58
- */
59
- typedef struct dsh_frame_forwarding_engine_v2 {
60
- dsh_frame_forwarding_engine_v1 base;
61
- int (*prepare)(void* engine, const dsh_frame_forwarding_frame_info* frame, char* error, size_t error_size);
62
- } dsh_frame_forwarding_engine_v2;
63
- #ifdef __cplusplus
64
- }
65
- #endif
66
- #endif
@@ -1,27 +0,0 @@
1
- #ifndef DSH_FRAME_FORWARDING_NODE_H
2
- #define DSH_FRAME_FORWARDING_NODE_H
3
- #include <node_api.h>
4
- #include "dsh_frame_forwarding_engine.h"
5
- /** Shared type tag for engine objects produced by cooperating native addons. */
6
- static const napi_type_tag dsh_frame_forwarding_engine_tag = {0xe1910c31bb654d4aULL, 0x9c30d42b2c88ee15ULL};
7
- /** Export a native engine factory as an opaque JS object. The descriptor and its
8
- * configuration must remain alive until finalize runs. The producer retains the
9
- * object through native teardown. The addon supplying callbacks must remain
10
- * loaded for the object's lifetime. No graphics work runs in this helper.
11
- */
12
- static inline napi_status dsh_frame_forwarding_export_engine(napi_env env, dsh_frame_forwarding_engine_v1* factory,
13
- napi_finalize finalize, void* hint, napi_value* result) {
14
- napi_status status = napi_create_object(env, result);
15
- if (status == napi_ok) status = napi_wrap(env, *result, factory, finalize, hint, NULL);
16
- if (status == napi_ok) {
17
- status = napi_type_tag_object(env, *result, &dsh_frame_forwarding_engine_tag);
18
- if (status != napi_ok) { void* removed = NULL; napi_remove_wrap(env, *result, &removed); }
19
- }
20
- return status;
21
- }
22
- /** Export v2 with the same descriptor, configuration, and addon lifetime as v1. */
23
- static inline napi_status dsh_frame_forwarding_export_engine_v2(napi_env env, dsh_frame_forwarding_engine_v2* factory,
24
- napi_finalize finalize, void* hint, napi_value* result) {
25
- return dsh_frame_forwarding_export_engine(env, &factory->base, finalize, hint, result);
26
- }
27
- #endif