@mermanjs/node-wasm 0.10.0 → 0.11.0

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.
@@ -15,19 +15,19 @@ license or notice files. This inventory is engineering evidence, not legal advic
15
15
 
16
16
  ASCII rendering source, copied fixtures, and behavior references.
17
17
 
18
- Components: `beautiful-mermaid`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`.
18
+ Components: `beautiful-mermaid`, `grok-build`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`.
19
19
 
20
20
  ### `cli-default`
21
21
 
22
22
  The source-default CLI feature closure including ELK without RaTeX math/font support.
23
23
 
24
- Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
24
+ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
25
25
 
26
26
  ### `cli-release`
27
27
 
28
28
  The published complete CLI release closure, including explicit ELK and RaTeX math/font support.
29
29
 
30
- Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
30
+ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
31
31
 
32
32
  ### `elk-render`
33
33
 
@@ -57,43 +57,43 @@ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent
57
57
 
58
58
  Embedding SDK full legal closure.
59
59
 
60
- Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
60
+ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
61
61
 
62
62
  ### `sdk-math`
63
63
 
64
64
  Embedding SDK math legal closure.
65
65
 
66
- Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
66
+ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
67
67
 
68
68
  ### `sdk-native-full`
69
69
 
70
70
  Native C full SDK, including its ASCII source notices.
71
71
 
72
- Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
72
+ Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `grok-build`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
73
73
 
74
74
  ### `sdk-native-math`
75
75
 
76
76
  Native C math SDK, including its ASCII source notices.
77
77
 
78
- Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
78
+ Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `grok-build`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
79
79
 
80
80
  ### `sdk-native-standard`
81
81
 
82
82
  Native C standard SDK, including its ASCII source notices.
83
83
 
84
- Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
84
+ Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `grok-build`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
85
85
 
86
86
  ### `sdk-standard`
87
87
 
88
88
  Embedding SDK standard legal closure.
89
89
 
90
- Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
90
+ Components: `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `non-layered-tidy-tree-layout`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `sdk-cousine`, `unicode-linebreak`, `usvg`, `venn-js`, `zenuml-core`.
91
91
 
92
92
  ### `source-archive`
93
93
 
94
94
  Conservative repository source archive inventory covering every translated, copied, linked, embedded, fixture, and behavior-reference component recorded here.
95
95
 
96
- Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `monaqa-tree-sitter-mermaid`, `non-layered-tidy-tree-layout`, `pappasam-tree-sitter-mermaid`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `singularity-tree-sitter-mermaid`, `tree-sitter-generator`, `tree-sitter-mermaid-mermaid-12-new-families`, `tree-sitter-mermaid-mermaid-baseline`, `tree-sitter-mermaid-zenuml-baseline`, `tree-sitter-templates`, `unicode-linebreak`, `venn-js`, `wasm-minimal-protocol`, `zenuml-core`.
96
+ Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `grok-build`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `monaqa-tree-sitter-mermaid`, `non-layered-tidy-tree-layout`, `pappasam-tree-sitter-mermaid`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `singularity-tree-sitter-mermaid`, `tree-sitter-generator`, `tree-sitter-mermaid-mermaid-12-new-families`, `tree-sitter-mermaid-mermaid-baseline`, `tree-sitter-mermaid-zenuml-baseline`, `tree-sitter-templates`, `unicode-linebreak`, `usvg`, `venn-js`, `wasm-minimal-protocol`, `zenuml-core`.
97
97
 
98
98
  ### `tree-sitter-mermaid-source`
99
99
 
@@ -117,7 +117,7 @@ Components: `dompurify`, `mermaid`, `sanitize-url`, `zenuml-core`.
117
117
 
118
118
  Browser ASCII artifacts combining the core parser legal closure with the ASCII renderer's copied fixtures and behavior references.
119
119
 
120
- Components: `beautiful-mermaid`, `dompurify`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `sanitize-url`, `zenuml-core`.
120
+ Components: `beautiful-mermaid`, `dompurify`, `grok-build`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `sanitize-url`, `zenuml-core`.
121
121
 
122
122
  ### `web-editor`
123
123
 
@@ -129,7 +129,7 @@ Components: `dompurify`, `mermaid`, `sanitize-url`, `zenuml-core`.
129
129
 
130
130
  Browser SDK including ASCII, Cytoscape, ELK and RaTeX math/font support.
131
131
 
132
- Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
132
+ Components: `beautiful-mermaid`, `cose-base-v1`, `cose-base-v2`, `cytoscape`, `cytoscape-cose-bilkent`, `cytoscape-fcose`, `d3-path`, `d3-shape`, `dagre`, `dompurify`, `eclipse-elk`, `elkjs`, `fmin`, `graphlib`, `grok-build`, `katex-fonts`, `layout-base-v1`, `layout-base-v2`, `mermaid`, `mermaid-ascii`, `mermaid-rs-renderer`, `non-layered-tidy-tree-layout`, `ratex`, `rough-rs`, `roughjs`, `roxmltree-dom`, `sanitize-url`, `unicode-linebreak`, `venn-js`, `zenuml-core`.
133
133
 
134
134
  ### `web-render`
135
135
 
@@ -366,6 +366,22 @@ dugong-graphlib is a modified Rust translation of the graph model used by Dagre.
366
366
  - Legal files:
367
367
  - [`THIRD_PARTY_LICENSES/graphlib/LICENSE`](THIRD_PARTY_LICENSES/graphlib/LICENSE) (license, SHA-256 `6a349742a6cb219d5a2fc8d0844f6d89a6efc62e20c664450d884fc7ff2d6015`)
368
368
 
369
+ ### Grok terminal Mermaid (xai-grok-markdown) (`grok-build`)
370
+
371
+ Grok's Apache-2.0 terminal Mermaid module is a behavior and presentation reference for terminal graph rendering. No Grok renderer, parser, test, or fixture implementation is included in distributed Merman artifacts. The separate MIT-licensed third_party/mermaid-to-svg component does not license this terminal module.
372
+
373
+ - Version: `0.1.0`
374
+ - Source: <https://github.com/xai-org/grok-build>
375
+ - Source ref: `2bdd1d6a6369de0e8c68132ea4539e9abd9e14a8`
376
+ - Source commit: `2bdd1d6a6369de0e8c68132ea4539e9abd9e14a8`
377
+ - Source path: `crates/codegen/xai-grok-markdown/src/mermaid.rs`
378
+ - Relationship: `behavior-reference`
379
+ - License expression: `Apache-2.0`
380
+ - Artifact scopes: `ascii-render`, `sdk-native-full`, `sdk-native-math`, `sdk-native-standard`, `source-archive`, `web-ascii`, `web-full`
381
+ - Local evidence: `crates/merman-ascii`
382
+ - Legal files:
383
+ - [`THIRD_PARTY_LICENSES/grok-build/LICENSE`](THIRD_PARTY_LICENSES/grok-build/LICENSE) (license, SHA-256 `116f7778b9802e569b7fa3a532b17bd80eb13c67837def01eed093d4ea472f28`)
384
+
369
385
  ### KaTeX fonts bundled by ratex-katex-fonts (`katex-fonts`)
370
386
 
371
387
  The RaTeX SVG backend embeds twenty KaTeX TrueType fonts; those font bytes are licensed under OFL-1.1 rather than RaTeX's MIT code license.
@@ -722,6 +738,24 @@ merman-unicode-linebreak is an Apache-2.0 fork of unicode-linebreak 0.1.5, prese
722
738
  - Legal files:
723
739
  - [`THIRD_PARTY_LICENSES/unicode-linebreak/LICENSE`](THIRD_PARTY_LICENSES/unicode-linebreak/LICENSE) (license, SHA-256 `c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`)
724
740
 
741
+ ### usvg (`usvg`)
742
+
743
+ Source-tree builds of the native font and image export pipeline link usvg 0.47.0 with a local font fallback backport. This source component carries the two upstream license texts.
744
+
745
+ - Version: `0.47.0 with font fallback backport`
746
+ - Source: <https://github.com/linebender/resvg>
747
+ - Source ref: `v0.47.0`
748
+ - Source commit: `3a0fdba53ccf2d346b54cc53ba7adf0ee60d0707`
749
+ - Source path: `crates/usvg`
750
+ - Relationship: `copied`, `linked`, `modified`
751
+ - License expression: `Apache-2.0 OR MIT`
752
+ - Selected license path: `MIT`
753
+ - Artifact scopes: `cli-default`, `cli-release`, `sdk-full`, `sdk-math`, `sdk-native-full`, `sdk-native-math`, `sdk-native-standard`, `sdk-standard`, `source-archive`
754
+ - Local evidence: `vendor/usvg`
755
+ - Legal files:
756
+ - [`THIRD_PARTY_LICENSES/usvg/LICENSE-APACHE`](THIRD_PARTY_LICENSES/usvg/LICENSE-APACHE) (license, SHA-256 `a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9`)
757
+ - [`THIRD_PARTY_LICENSES/usvg/LICENSE-MIT`](THIRD_PARTY_LICENSES/usvg/LICENSE-MIT) (license, SHA-256 `f5d934dc281b44e0003ee461ac740b18b6629a454decd872c774d34e4ee0b21d`)
758
+
725
759
  ### @upsetjs/venn.js (`venn-js`)
726
760
 
727
761
  The Venn family uses a modified Rust translation of the venn.js geometry and layout kernel.
Binary file
@@ -98,14 +98,13 @@ export class BoundedExecutor {
98
98
  this.#removeAbortListener(job);
99
99
  this.#active += 1;
100
100
  const operation = Promise.resolve().then(job.run);
101
- const observed = job.resolve || job.reject
102
- ? operation.then(job.resolve, job.reject)
103
- : operation;
104
- return observed.finally(() => {
101
+ // Release capacity and admit FIFO successors before callers observe either outcome.
102
+ const finished = operation.finally(() => {
105
103
  this.#active -= 1;
106
104
  this.#pump();
107
105
  this.#completeDisposeIfIdle();
108
106
  });
107
+ return job.resolve || job.reject ? finished.then(job.resolve, job.reject) : finished;
109
108
  }
110
109
 
111
110
  #pump() {
@@ -3,7 +3,7 @@ import { MermanDisposedError, MermanInvalidTransportError } from "../errors.mjs"
3
3
  export function wrapCandidateEngine(
4
4
  engine,
5
5
  label,
6
- { forwardsAbortSignal = false } = {},
6
+ { forwardsAbortSignal = false, directSvgAddon = false } = {},
7
7
  ) {
8
8
  if (
9
9
  typeof engine?.execute !== "function" ||
@@ -18,7 +18,12 @@ export function wrapCandidateEngine(
18
18
  if (!ownedEngine) throw new MermanDisposedError();
19
19
  return ownedEngine;
20
20
  };
21
- return {
21
+ const executeSvg = directSvgAddon ? engine.executeSvg : undefined;
22
+ const executeSvgSync = directSvgAddon ? engine.executeSvgSync : undefined;
23
+ if (directSvgAddon && (typeof executeSvg !== "function" || typeof executeSvgSync !== "function")) {
24
+ throw new MermanInvalidTransportError(`${label} does not implement the direct SVG contract.`);
25
+ }
26
+ const transport = {
22
27
  execute: (requestJson, signal, timeoutMs) =>
23
28
  forwardsAbortSignal
24
29
  ? currentEngine().execute(requestJson, signal, timeoutMs)
@@ -33,4 +38,11 @@ export function wrapCandidateEngine(
33
38
  return disposing?.dispose?.();
34
39
  },
35
40
  };
41
+ if (directSvgAddon) {
42
+ transport.executeSvg = (source, optionsJson, signal, timeoutMs) =>
43
+ executeSvg.call(currentEngine(), source, optionsJson, signal, timeoutMs);
44
+ transport.executeSvgSync = (source, optionsJson, timeoutMs) =>
45
+ executeSvgSync.call(currentEngine(), source, optionsJson, timeoutMs);
46
+ }
47
+ return transport;
36
48
  }
package/dist/engine.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BoundedExecutor } from "./bounded-executor.mjs";
2
+ import { supportsDirectNativeSvg } from "./native-loader.mjs";
2
3
  import {
3
4
  MermanInvalidTransportError,
4
5
  NODE_TRANSPORT_FIELD_LIMITS,
@@ -9,6 +10,7 @@ import {
9
10
  decodeWireInvocationError,
10
11
  decodeWireResponse,
11
12
  encodeTransportJson,
13
+ jsonStringFieldBytes,
12
14
  parseRuntimeCatalogJsonText,
13
15
  parseTransportJsonText,
14
16
  sameJsonValue,
@@ -99,6 +101,9 @@ const THEME_AUTHORING_RESULT_LIMITS = Object.freeze({
99
101
  max_string_utf8_bytes: NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes,
100
102
  });
101
103
  const MAX_OPERATION_TIMEOUT_MS = 0xffff_ffff;
104
+ const SVG_REQUEST_FRAME_BYTES = '{"operation_id":"svg","source":"","uri":null,"include_metadata":false}'.length;
105
+ const SVG_OPTIONS_FRAME_BYTES = ',"options_json":""'.length;
106
+ const SVG_TIMEOUT_FRAME_BYTES = ',"operation_control":{"timeout_ms":}'.length;
102
107
  const MERMAN_ENGINE_CONSTRUCTION_TOKEN = Symbol("MermanEngine construction");
103
108
 
104
109
  export async function createNodeEngine(
@@ -124,11 +129,14 @@ export async function createNodeEngine(
124
129
  try {
125
130
  assertTransport(transport);
126
131
  const runtimeCatalog = validateRuntimeCatalog(await transport.runtimeCatalogJson());
132
+ const directSvg = supportsDirectNativeSvg(transport) &&
133
+ runtimeCatalog.capabilities.operation_ids.includes("svg");
127
134
  return new MermanEngine(
128
135
  MERMAN_ENGINE_CONSTRUCTION_TOKEN,
129
136
  transport,
130
137
  runtimeCatalog,
131
138
  { concurrency, maxQueue },
139
+ directSvg,
132
140
  );
133
141
  } catch (error) {
134
142
  await disposeUnusableTransport(transport);
@@ -207,6 +215,7 @@ export function normalizeBindingOptions(value = {}) {
207
215
  }
208
216
 
209
217
  export class MermanEngine {
218
+ #directSvg;
210
219
  #disposePromise = null;
211
220
  #executor;
212
221
  #metadataIds;
@@ -214,13 +223,14 @@ export class MermanEngine {
214
223
  #runtimeCatalog;
215
224
  #transport;
216
225
 
217
- constructor(constructionToken, transport, runtimeCatalog, queueOptions) {
226
+ constructor(constructionToken, transport, runtimeCatalog, queueOptions, directSvg) {
218
227
  if (constructionToken !== MERMAN_ENGINE_CONSTRUCTION_TOKEN) {
219
228
  throw new MermanInvalidTransportError(
220
229
  "MermanEngine instances must be created with createNodeEngine().",
221
230
  );
222
231
  }
223
232
  this.#transport = transport;
233
+ this.#directSvg = directSvg;
224
234
  this.#runtimeCatalog = runtimeCatalog;
225
235
  this.#metadataIds = new Set(
226
236
  runtimeCatalog.metadata_ids.filter((id) => METADATA_SPEC_BY_ID.has(id)),
@@ -330,30 +340,35 @@ export class MermanEngine {
330
340
  } catch (error) {
331
341
  return Promise.reject(error);
332
342
  }
333
- const prepared = prepareOperationRequest(request, { timeoutMs });
343
+ const directSvg = this.#usesDirectSvg(request, includeMetadata);
344
+ const prepared = prepareOperationRequest(request, { timeoutMs, directSvg });
345
+ const { expectation } = prepared;
334
346
  if (signal?.aborted) return Promise.reject(abortError());
335
- const encoded = operationRequestJson(prepared, includeMetadata);
347
+ let execute;
348
+ if (directSvg) {
349
+ const optionsJson = prepareDirectSvgOptions(prepared, timeoutMs);
350
+ const { source } = prepared.request;
351
+ execute = (forwarded) => this.#transport.executeSvg(source, optionsJson, forwarded, timeoutMs);
352
+ } else {
353
+ const requestJson = operationRequestJson(prepared, includeMetadata);
354
+ execute = (forwarded) => this.#transport.execute(requestJson, forwarded, timeoutMs);
355
+ }
336
356
  return this.#executor.submit(
337
357
  async () => {
338
358
  // A signal can flip after queue admission but before this start microtask runs. That work
339
359
  // has not crossed the transport boundary, so preserve the established AbortError result.
340
360
  if (signal?.aborted) throw abortError();
341
- let responseJson;
361
+ let response;
342
362
  try {
343
- responseJson = await executeTransportOperation(
344
- this.#transport,
345
- encoded.json,
346
- signal,
347
- timeoutMs,
348
- );
363
+ response = await executeTransportOperation(execute, signal);
349
364
  } catch (cause) {
350
365
  throw decodeWireInvocationError(cause, "Merman operation");
351
366
  }
352
- return decodeWireResponse(responseJson, encoded.expectation, {
367
+ return this.#decodeOperationResponse(response, expectation, {
353
368
  includeMetadata,
354
- allowedCancellationReasons: invocationCancellationReasons(signal, timeoutMs),
355
- requireUnavailable: !this.#operationIds.has(encoded.expectation.operation_id),
356
- availableCapabilityIds: this.#runtimeCatalog.capabilities.capability_ids,
369
+ directSvg,
370
+ signal,
371
+ timeoutMs,
357
372
  });
358
373
  },
359
374
  { signal },
@@ -366,20 +381,43 @@ export class MermanEngine {
366
381
 
367
382
  #executeSync(request, { timeoutMs } = {}, includeMetadata) {
368
383
  this.#executor.assertSyncAvailable();
369
- const encoded = operationRequestJson(
370
- prepareOperationRequest(request, { timeoutMs }),
371
- includeMetadata,
372
- );
373
- let responseJson;
384
+ const directSvg = this.#usesDirectSvg(request, includeMetadata);
385
+ const prepared = prepareOperationRequest(request, { timeoutMs, directSvg });
386
+ const payload = directSvg
387
+ ? prepareDirectSvgOptions(prepared, timeoutMs)
388
+ : operationRequestJson(prepared, includeMetadata);
389
+ let response;
374
390
  try {
375
- responseJson = this.#transport.executeSync(encoded.json, timeoutMs);
391
+ response = directSvg
392
+ ? this.#transport.executeSvgSync(prepared.request.source, payload, timeoutMs)
393
+ : this.#transport.executeSync(payload, timeoutMs);
376
394
  } catch (cause) {
377
395
  throw decodeWireInvocationError(cause, "Merman operation");
378
396
  }
379
- return decodeWireResponse(responseJson, encoded.expectation, {
397
+ return this.#decodeOperationResponse(response, prepared.expectation, {
398
+ includeMetadata,
399
+ directSvg,
400
+ timeoutMs,
401
+ });
402
+ }
403
+
404
+ #usesDirectSvg(request, includeMetadata) {
405
+ return this.#directSvg && !includeMetadata && request.operationId === "svg";
406
+ }
407
+
408
+ #decodeOperationResponse(response, expectation, { includeMetadata, directSvg, signal, timeoutMs }) {
409
+ if (directSvg) {
410
+ if (typeof response === "string") return response;
411
+ if (response === null || typeof response !== "object" || !Object.hasOwn(response, "errorJson")) {
412
+ throw new MermanInvalidTransportError("The native SVG operation returned an invalid result.");
413
+ }
414
+ response = response.errorJson;
415
+ }
416
+ return decodeWireResponse(response, expectation, {
380
417
  includeMetadata,
381
- allowedCancellationReasons: invocationCancellationReasons(undefined, timeoutMs),
382
- requireUnavailable: !this.#operationIds.has(encoded.expectation.operation_id),
418
+ requireError: directSvg,
419
+ allowedCancellationReasons: invocationCancellationReasons(signal, timeoutMs),
420
+ requireUnavailable: !this.#operationIds.has(expectation.operation_id),
383
421
  availableCapabilityIds: this.#runtimeCatalog.capabilities.capability_ids,
384
422
  });
385
423
  }
@@ -400,7 +438,7 @@ function invocationCancellationReasons(signal, timeoutMs) {
400
438
  return reasons;
401
439
  }
402
440
 
403
- function prepareOperationRequest(value, { timeoutMs } = {}) {
441
+ function prepareOperationRequest(value, { timeoutMs, directSvg }) {
404
442
  if (!isPlainObject(value)) throw new TypeError("operation request must be a plain object.");
405
443
  const knownFields = new Set(["operationId", "source", "uri", "optionsJson"]);
406
444
  for (const field of Object.keys(value)) {
@@ -434,7 +472,7 @@ function prepareOperationRequest(value, { timeoutMs } = {}) {
434
472
  "operation request operationId",
435
473
  NODE_TRANSPORT_FIELD_LIMITS.operation_id_utf8_bytes,
436
474
  );
437
- assertUtf8Field(
475
+ const sourceBytes = (directSvg ? jsonStringFieldBytes : assertUtf8Field)(
438
476
  source,
439
477
  "operation request source",
440
478
  NODE_TRANSPORT_FIELD_LIMITS.source_utf8_bytes,
@@ -463,36 +501,51 @@ function prepareOperationRequest(value, { timeoutMs } = {}) {
463
501
  }
464
502
  request.operation_control = { timeout_ms: timeoutMs };
465
503
  }
466
- return { expectation, request, value };
504
+ return { expectation, request, value, sourceBytes };
467
505
  }
468
506
 
469
- function operationRequestJson({ expectation, request, value }, includeMetadata) {
507
+ function operationRequestJson({ request, value }, includeMetadata) {
470
508
  if (!includeMetadata) request.include_metadata = false;
471
509
  const optionsJson = value.optionsJson;
472
510
  if (optionsJson !== undefined) {
473
- if (typeof optionsJson !== "string") {
474
- throw new TypeError("optionsJson must be a JSON string when provided.");
475
- }
476
- assertUtf8Field(
477
- optionsJson,
478
- "operation request optionsJson",
479
- NODE_TRANSPORT_FIELD_LIMITS.options_json_utf8_bytes,
480
- );
481
- parseTransportJsonText(
482
- optionsJson,
483
- "operation request optionsJson",
484
- NODE_TRANSPORT_LIMITS.binding_options,
485
- );
511
+ validateOperationOptionsJson(optionsJson, assertUtf8Field);
486
512
  request.options_json = optionsJson;
487
513
  }
488
- return {
489
- expectation,
490
- json: encodeTransportJson(request, "operation request", NODE_TRANSPORT_LIMITS.request),
491
- };
514
+ return encodeTransportJson(request, "operation request", NODE_TRANSPORT_LIMITS.request);
515
+ }
516
+
517
+ function prepareDirectSvgOptions({ value, sourceBytes }, timeoutMs) {
518
+ // Match the former fixed request's byte budget without building or scanning the document.
519
+ let requestBytes = SVG_REQUEST_FRAME_BYTES + sourceBytes;
520
+ if (timeoutMs !== undefined) {
521
+ requestBytes += SVG_TIMEOUT_FRAME_BYTES + String(timeoutMs).length;
522
+ }
523
+ const optionsJson = value.optionsJson;
524
+ if (optionsJson !== undefined) {
525
+ requestBytes +=
526
+ SVG_OPTIONS_FRAME_BYTES + validateOperationOptionsJson(optionsJson, jsonStringFieldBytes);
527
+ }
528
+ const max = NODE_TRANSPORT_LIMITS.request.max_utf8_bytes;
529
+ if (requestBytes > max) {
530
+ throw new MermanInvalidTransportError(
531
+ `Merman transport operation request exceeds the ${max}-byte wire limit.`,
532
+ );
533
+ }
534
+ return optionsJson;
535
+ }
536
+
537
+ function validateOperationOptionsJson(optionsJson, measureField) {
538
+ if (typeof optionsJson !== "string") {
539
+ throw new TypeError("optionsJson must be a JSON string when provided.");
540
+ }
541
+ const label = "operation request optionsJson";
542
+ const bytes = measureField(optionsJson, label, NODE_TRANSPORT_FIELD_LIMITS.options_json_utf8_bytes);
543
+ parseTransportJsonText(optionsJson, label, NODE_TRANSPORT_LIMITS.binding_options);
544
+ return bytes;
492
545
  }
493
546
 
494
- async function executeTransportOperation(transport, requestJson, signal, timeoutMs) {
495
- if (!signal) return transport.execute(requestJson, undefined, timeoutMs);
547
+ async function executeTransportOperation(execute, signal) {
548
+ if (!signal) return execute(undefined);
496
549
 
497
550
  // Forward into a private signal so the N-API bridge cannot replace a caller-owned `onabort`
498
551
  // handler while it installs its cooperative cancellation callback.
@@ -508,7 +561,7 @@ async function executeTransportOperation(transport, requestJson, signal, timeout
508
561
  };
509
562
  signal.addEventListener("abort", forwardAbort, { once: true });
510
563
  try {
511
- const operation = transport.execute(requestJson, transportAbort.signal, timeoutMs);
564
+ const operation = execute(transportAbort.signal);
512
565
  transportReady = true;
513
566
  if (pendingAbort || signal.aborted) transportAbort.abort(signal.reason);
514
567
  return await operation;
@@ -551,7 +604,7 @@ export function validateRuntimeCatalog(value) {
551
604
  }
552
605
  if (
553
606
  catalog.schema_version !== RUNTIME_CATALOG_SCHEMA_VERSION ||
554
- catalog.transport_api_version !== 1
607
+ catalog.transport_api_version !== NODE_WIRE_CONTRACT.transport_api_version
555
608
  ) {
556
609
  throw new MermanInvalidTransportError("Merman transport returned an unsupported runtime catalog version.");
557
610
  }
package/dist/errors.mjs CHANGED
@@ -385,18 +385,8 @@ function addJsonStringWireBytes(value, label, limits, budget) {
385
385
  const codeUnit = value.charCodeAt(index);
386
386
  let characterBytes = utf8LengthOfCodeUnit(codeUnit);
387
387
  let wireBytes = characterBytes;
388
- if (codeUnit === 0x22 || codeUnit === 0x5c) {
389
- wireBytes = 2;
390
- } else if (
391
- codeUnit === 0x08 ||
392
- codeUnit === 0x09 ||
393
- codeUnit === 0x0a ||
394
- codeUnit === 0x0c ||
395
- codeUnit === 0x0d
396
- ) {
397
- wireBytes = 2;
398
- } else if (codeUnit <= 0x1f) {
399
- wireBytes = 6;
388
+ if (codeUnit <= 0x7f) {
389
+ wireBytes = jsonAsciiByteLength(codeUnit);
400
390
  } else if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
401
391
  const low = value.charCodeAt(index + 1);
402
392
  if (!(low >= 0xdc00 && low <= 0xdfff)) {
@@ -433,13 +423,12 @@ function addJsonWireBytes(budget, bytes) {
433
423
  }
434
424
 
435
425
  export function assertUtf8Field(value, label, maxUtf8Bytes) {
436
- const bytes = strictUtf8ByteLength(value, label);
437
- if (bytes > maxUtf8Bytes) {
438
- throw new MermanInvalidTransportError(
439
- `Merman transport ${label} exceeds the ${maxUtf8Bytes}-byte field limit.`,
440
- );
441
- }
442
- return bytes;
426
+ return measureUtf8Field(value, label, maxUtf8Bytes, false);
427
+ }
428
+
429
+ // Counts an escaped JSON string's contents without allocating it or including its quotes.
430
+ export function jsonStringFieldBytes(value, label, maxUtf8Bytes) {
431
+ return measureUtf8Field(value, label, maxUtf8Bytes, true);
443
432
  }
444
433
 
445
434
  export function parseRuntimeCatalogJsonText(value, label = "runtime catalog") {
@@ -520,11 +509,17 @@ export function validateTransportIdentityExport(
520
509
  }
521
510
 
522
511
  export function strictUtf8ByteLength(value, label = "text") {
512
+ return measureUtf8Field(value, label, Infinity, false);
513
+ }
514
+
515
+ function measureUtf8Field(value, label, maxUtf8Bytes, countJsonEscapes) {
523
516
  let bytes = 0;
517
+ let escapeBytes = 0;
524
518
  for (let index = 0; index < value.length; index += 1) {
525
519
  const codeUnit = value.charCodeAt(index);
526
520
  if (codeUnit <= 0x7f) {
527
521
  bytes += 1;
522
+ if (countJsonEscapes) escapeBytes += jsonAsciiByteLength(codeUnit) - 1;
528
523
  } else if (codeUnit <= 0x7ff) {
529
524
  bytes += 2;
530
525
  } else if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
@@ -544,7 +539,27 @@ export function strictUtf8ByteLength(value, label = "text") {
544
539
  bytes += 3;
545
540
  }
546
541
  }
547
- return bytes;
542
+ if (bytes > maxUtf8Bytes) {
543
+ throw new MermanInvalidTransportError(
544
+ `Merman transport ${label} exceeds the ${maxUtf8Bytes}-byte field limit.`,
545
+ );
546
+ }
547
+ return bytes + escapeBytes;
548
+ }
549
+
550
+ function jsonAsciiByteLength(codeUnit) {
551
+ switch (codeUnit) {
552
+ case 0x08:
553
+ case 0x09:
554
+ case 0x0a:
555
+ case 0x0c:
556
+ case 0x0d:
557
+ case 0x22:
558
+ case 0x5c:
559
+ return 2;
560
+ default:
561
+ return codeUnit <= 0x1f ? 6 : 1;
562
+ }
548
563
  }
549
564
 
550
565
  function scanBoundedJsonText(source, label, limits) {
@@ -904,6 +919,7 @@ export function decodeWireResponse(
904
919
  expectation,
905
920
  {
906
921
  includeMetadata = true,
922
+ requireError = false,
907
923
  allowedCancellationReasons = [],
908
924
  requireUnavailable = false,
909
925
  availableCapabilityIds = [],
@@ -937,6 +953,9 @@ export function decodeWireResponse(
937
953
  );
938
954
  throw new MermanOperationError(error);
939
955
  }
956
+ if (requireError) {
957
+ throw new MermanInvalidTransportError("The native SVG failure must contain an error envelope.");
958
+ }
940
959
  if (envelope.ok !== true || Object.hasOwn(envelope, "error")) {
941
960
  throw new MermanInvalidTransportError(
942
961
  "Merman transport success envelopes must contain result only.",
@@ -947,7 +966,12 @@ export function decodeWireResponse(
947
966
  "Merman transport executed an operation that its runtime catalog does not advertise.",
948
967
  );
949
968
  }
950
- return validateSuccessResult(envelope.result, expectation, includeMetadata);
969
+ return validateSuccessResult(
970
+ envelope.result,
971
+ expectation,
972
+ includeMetadata,
973
+ Object.hasOwn(envelope, "result"),
974
+ );
951
975
  }
952
976
 
953
977
  function validateAllowedCancellationReasons(reasons) {
@@ -1003,7 +1027,7 @@ function validateEnvelopeHeader(envelope, label) {
1003
1027
  }
1004
1028
  }
1005
1029
 
1006
- function validateSuccessResult(result, expectation, includeMetadata) {
1030
+ function validateSuccessResult(result, expectation, includeMetadata, hasOwnResult) {
1007
1031
  if (
1008
1032
  !isPlainJsonObject(result) ||
1009
1033
  typeof result.operation_id !== "string" ||
@@ -1025,11 +1049,22 @@ function validateSuccessResult(result, expectation, includeMetadata) {
1025
1049
  "response media_type",
1026
1050
  NODE_TRANSPORT_FIELD_LIMITS.media_type_utf8_bytes,
1027
1051
  );
1028
- const dataBytes = assertUtf8Field(
1029
- result.data,
1030
- "response data",
1031
- NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes,
1032
- );
1052
+ // Own parsed data already passed the response scanner's decoded-string bound.
1053
+ // Metadata and unscanned inherited values still need the exact field check.
1054
+ let dataBytes;
1055
+ if (
1056
+ includeMetadata ||
1057
+ !hasOwnResult ||
1058
+ !Object.hasOwn(result, "data") ||
1059
+ NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes <
1060
+ NODE_TRANSPORT_LIMITS.response.max_string_utf8_bytes
1061
+ ) {
1062
+ dataBytes = assertUtf8Field(
1063
+ result.data,
1064
+ "response data",
1065
+ NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes,
1066
+ );
1067
+ }
1033
1068
  if (
1034
1069
  !expectation ||
1035
1070
  result.operation_id !== expectation.operation_id ||