@mermanjs/node-wasm 0.10.0-alpha.2 → 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.
package/dist/index.d.ts CHANGED
@@ -4,9 +4,36 @@ export type MermanResourceProfile =
4
4
  | "trusted-native"
5
5
  | "unbounded-for-trusted-input";
6
6
 
7
+ export type MermanAsciiGraphPresentation = "strict" | "adaptive";
8
+
9
+ /** Options for the canonical `ascii` operation, also accepted through optionsJson. */
10
+ export interface MermanAsciiRenderOptions {
11
+ /** Defaults to strict. Adaptive is Plain-only for Flowchart, Swimlane, and State. */
12
+ graph_presentation?: MermanAsciiGraphPresentation;
13
+ graphPresentation?: MermanAsciiGraphPresentation;
14
+ /** State supports Canonical only; Auto requires a maximum width. */
15
+ layout_profile?: "canonical" | "compact" | "auto";
16
+ layoutProfile?: "canonical" | "compact" | "auto";
17
+ charset?: "ascii" | "unicode";
18
+ max_width?: number;
19
+ maxWidth?: number;
20
+ overflow?: "allow" | "fallback" | "error";
21
+ color_mode?:
22
+ | "plain" | "none"
23
+ | "ansi16" | "ansi-16" | "ansi_16"
24
+ | "ansi256" | "ansi-256" | "ansi_256"
25
+ | "truecolor" | "true-color" | "true_color" | "html";
26
+ colorMode?: MermanAsciiRenderOptions["color_mode"];
27
+ [key: string]: unknown;
28
+ }
29
+
7
30
  export interface MermanBindingOptions {
8
31
  version?: 3;
9
32
  runtime_policy?: "deterministic";
33
+ fixed_today?: string | null;
34
+ /** Exact host-supplied Unix milliseconds; mutually exclusive with a non-null fixed_today. */
35
+ fixed_unix_millis?: number | null;
36
+ fixed_local_offset_minutes?: number | null;
10
37
  environment?: {
11
38
  theme_portability?: "best-effort" | "require-portable";
12
39
  text_measurement?: "deterministic" | null;
@@ -16,9 +43,126 @@ export interface MermanBindingOptions {
16
43
  profile?: MermanResourceProfile;
17
44
  limits?: Record<string, number>;
18
45
  };
46
+ /** A supplied selection replaces the complete constructor theme; null clears it. */
47
+ theme?: DiagramThemeSelection | null;
48
+ ascii?: MermanAsciiRenderOptions;
19
49
  [key: string]: unknown;
20
50
  }
21
51
 
52
+ export type ThemeAppearance = "light" | "dark";
53
+ export type ThemeJsonValue =
54
+ | string | number | boolean | null
55
+ | ThemeJsonValue[]
56
+ | { [key: string]: ThemeJsonValue };
57
+ export type ThemeJsonObject = { [key: string]: ThemeJsonValue };
58
+
59
+ /** Editable JSON sections are validated by the shared Rust theme compiler. */
60
+ export interface ThemeDesignV1 {
61
+ tokens?: Record<string, ThemeJsonValue>;
62
+ styles?: Record<string, ThemeJsonValue>;
63
+ rules?: ThemeJsonObject[];
64
+ palettes?: Record<string, ThemeJsonValue>;
65
+ canvas?: ThemeJsonObject;
66
+ typography?: ThemeJsonObject;
67
+ mermaid?: ThemeJsonObject;
68
+ assets?: ThemeJsonObject;
69
+ requirements?: ThemeJsonObject;
70
+ appearances?: Partial<Record<ThemeAppearance, ThemeAppearanceOverridesV1>>;
71
+ default_appearance?: ThemeAppearance;
72
+ }
73
+
74
+ export type ThemeAppearanceOverridesV1 =
75
+ Omit<ThemeDesignV1, "appearances" | "default_appearance" | "assets" | "requirements">;
76
+
77
+ export type ThemeRecipeV1 = {
78
+ schema_version: 1;
79
+ preset?: never;
80
+ spec?: never;
81
+ recipe?: never;
82
+ appearance?: never;
83
+ } & (
84
+ | { kind: "design"; design: ThemeDesignV1; complete_spec?: never }
85
+ | { kind: "complete_spec"; complete_spec: ThemeJsonObject; design?: never }
86
+ );
87
+
88
+ export type DiagramThemeSelection =
89
+ | ThemeRecipeV1
90
+ | ({ kind?: never; schema_version?: never; design?: never; complete_spec?: never } & (
91
+ | { preset: string; appearance?: ThemeAppearance; recipe?: never; spec?: never }
92
+ | { recipe: ThemeRecipeV1; appearance?: ThemeAppearance; preset?: never; spec?: never }
93
+ | { spec: ThemeJsonObject; preset?: never; recipe?: never; appearance?: never }
94
+ ));
95
+
96
+ export type ThemeAuthoringRequestV1 =
97
+ | { schema_version: 1; action: "inspect"; recipe: ThemeRecipeV1; appearance?: never }
98
+ | { schema_version: 1; action: "materialize"; recipe: ThemeRecipeV1; appearance?: ThemeAppearance };
99
+ export type ThemeAuthoringInput = ThemeDesignV1 | ThemeAuthoringRequestV1 | string;
100
+
101
+ export interface ThemeDesignReferenceUse {
102
+ token: string;
103
+ path: string;
104
+ domain: ThemeJsonObject;
105
+ }
106
+
107
+ export interface ThemeRecipeReferenceUseV1 extends ThemeDesignReferenceUse {
108
+ token_path: string;
109
+ }
110
+
111
+ export interface MaterializedThemeWireV1 {
112
+ schema_version: 1;
113
+ authoring_schema_version: 1;
114
+ expansion_version: 1;
115
+ spec_schema_version: 1;
116
+ spec: ThemeJsonObject;
117
+ references?: ThemeDesignReferenceUse[];
118
+ }
119
+
120
+ export interface ThemeRecipeInspectionV1 {
121
+ schema_version: 1;
122
+ recipe_schema_version: 1;
123
+ supported_appearances: ThemeAppearance[];
124
+ default_appearance: ThemeAppearance | null;
125
+ appearances: {
126
+ appearance: ThemeAppearance | null;
127
+ references: ThemeRecipeReferenceUseV1[];
128
+ }[];
129
+ }
130
+
131
+ export interface MaterializedThemeRecipeV1 {
132
+ schema_version: 1;
133
+ recipe_schema_version: 1;
134
+ supported_appearances: ThemeAppearance[];
135
+ default_appearance: ThemeAppearance | null;
136
+ effective_appearance: ThemeAppearance | null;
137
+ spec: ThemeJsonObject;
138
+ references: ThemeRecipeReferenceUseV1[];
139
+ }
140
+
141
+ export type ThemeAuthoringResult =
142
+ | MaterializedThemeWireV1 | ThemeRecipeInspectionV1 | MaterializedThemeRecipeV1;
143
+ export type ThemeAuthoringResultFor<Input extends ThemeAuthoringInput> =
144
+ Input extends { action: "inspect" } ? ThemeRecipeInspectionV1
145
+ : Input extends { action: "materialize" } ? MaterializedThemeRecipeV1
146
+ : Input extends string ? ThemeAuthoringResult : MaterializedThemeWireV1;
147
+
148
+ export interface ThemeSupportQueryV1 {
149
+ schema_version: 1;
150
+ family: string;
151
+ output: string;
152
+ subject:
153
+ | { kind: "rule"; target: string; facet: string }
154
+ | { kind: "ordinal-palette"; target: string }
155
+ | { kind: "base-typography"; property: string };
156
+ }
157
+
158
+ export interface ThemeCapabilityDescriptorV1 {
159
+ schema_version: 1;
160
+ claim_revision: number;
161
+ query: ThemeSupportQueryV1;
162
+ state: "unconditional" | "conditional" | "not-applicable" | "unsupported" | "unverified" | (string & {});
163
+ reason_ids: string[];
164
+ }
165
+
22
166
  /** One host-loaded Iconify pack, admitted once into an immutable engine-local registry. */
23
167
  export interface MermanIconPack {
24
168
  json: string;
@@ -53,7 +197,11 @@ export interface MermanOperationRequest {
53
197
  operationId: string;
54
198
  source: string;
55
199
  uri?: string | null;
56
- /** Raw per-request options JSON merged over the reusable engine baseline. */
200
+ /**
201
+ * Raw per-request options JSON merged over the reusable engine baseline.
202
+ * For ASCII, use operationId "ascii" and JSON.stringify({ ascii: { graph_presentation: "adaptive" } }
203
+ * satisfies MermanBindingOptions). Admission is advertised by metadataJson("ascii-capabilities").
204
+ */
57
205
  optionsJson?: string;
58
206
  }
59
207
 
@@ -61,6 +209,7 @@ export interface MermanOperationResult {
61
209
  operation_id: string;
62
210
  media_type: string;
63
211
  data: string;
212
+ /** Canonical metadata JSON; ASCII output_plan uses report schema 4 within metadata version 1. */
64
213
  metadata_json: string;
65
214
  }
66
215
 
@@ -149,7 +298,7 @@ export interface MermanRuntimeConstructorServiceContract {
149
298
 
150
299
  export interface MermanRuntimeCatalog {
151
300
  schema_version: 1;
152
- transport_api_version: 1;
301
+ transport_api_version: 2;
153
302
  package_version: string;
154
303
  options_schema_versions: number[];
155
304
  payload_schemas: MermanRuntimePayloadSchema[];
@@ -201,6 +350,17 @@ export declare class MermanEngine {
201
350
  source: string,
202
351
  options?: Omit<RenderSvgOptions, "signal">,
203
352
  ): string;
353
+ /** Raw strings preserve duplicate-field admission and source paths in Rust. */
354
+ materializeTheme<Input extends ThemeAuthoringInput>(
355
+ input: Input,
356
+ options?: RenderSvgOptions,
357
+ ): Promise<ThemeAuthoringResultFor<Input>>;
358
+ describeThemeSupport(
359
+ query: ThemeSupportQueryV1 | string,
360
+ options?: RenderSvgOptions,
361
+ ): Promise<ThemeCapabilityDescriptorV1>;
362
+ /** Exports the complete editable design, including every declared appearance. */
363
+ exportThemePreset(presetId: string, options?: RenderSvgOptions): Promise<ThemeRecipeV1>;
204
364
  metadataJson(id: string): string;
205
365
  executeOperation(
206
366
  request: MermanOperationRequest,
@@ -5,8 +5,11 @@ import {
5
5
  MermanMissingPlatformPackageError,
6
6
  MermanNativeLoadError,
7
7
  MermanUnsupportedTargetError,
8
+ decodeWireCreationError,
8
9
  parseRuntimeCatalogJsonText,
10
+ validateTransportIdentityExport,
9
11
  } from "./errors.mjs";
12
+ import { wrapCandidateEngine } from "./candidates/wrap-engine.mjs";
10
13
 
11
14
  const TARGET_PACKAGES = Object.freeze({
12
15
  "darwin-arm64": "@mermanjs/node-darwin-arm64",
@@ -19,6 +22,8 @@ const TARGET_PACKAGES = Object.freeze({
19
22
  });
20
23
 
21
24
  const requireFromPackage = createRequire(import.meta.url);
25
+ // Only installed native addons can use the direct SVG input and result contract.
26
+ const directSvgTransports = new WeakSet();
22
27
  const loaderPackageManifest = requireFromPackage("../package.json");
23
28
  const loaderPackageVersion = loaderPackageManifest?.version;
24
29
 
@@ -89,6 +94,76 @@ export function loadNativeBinding({
89
94
  }
90
95
  }
91
96
 
97
+ export async function loadInstalledNativeTransport(optionsJson, iconPacksJson) {
98
+ let nativeAddon = false;
99
+ const binding = loadNativeBinding({
100
+ loadPackage(packageName) {
101
+ const entrypoint = requireFromPackage.resolve(packageName);
102
+ // The platform manifest loads the addon directly. JavaScript shims stay on the wire path.
103
+ nativeAddon = entrypoint.endsWith(".node");
104
+ return requireFromPackage(entrypoint);
105
+ },
106
+ });
107
+ const transport = await wrapNativeBinding(binding, optionsJson, iconPacksJson, {
108
+ directSvgAddon: nativeAddon,
109
+ });
110
+ if (nativeAddon) {
111
+ directSvgTransports.add(transport);
112
+ }
113
+ return transport;
114
+ }
115
+
116
+ export function supportsDirectNativeSvg(transport) {
117
+ return directSvgTransports.has(transport);
118
+ }
119
+
120
+ export async function wrapNativeBinding(
121
+ binding,
122
+ optionsJson,
123
+ iconPacksJson,
124
+ { directSvgAddon = false } = {},
125
+ ) {
126
+ const label = "The target-specific Merman addon";
127
+ const NativeEngine = binding?.NativeEngine ?? binding?.default?.NativeEngine;
128
+ if (typeof NativeEngine !== "function") {
129
+ throw new MermanInvalidTransportError(
130
+ "The target-specific Merman package does not export NativeEngine.",
131
+ );
132
+ }
133
+ validateTransportIdentityExport(binding?.transportIdentityJson, {
134
+ expectedPackageVersion: nodeLoaderPackageVersion(),
135
+ expectedTransport: "napi",
136
+ label: "The target-specific Merman package",
137
+ });
138
+ let transport;
139
+ try {
140
+ transport = wrapCandidateEngine(
141
+ iconPacksJson === undefined
142
+ ? new NativeEngine(optionsJson)
143
+ : new NativeEngine(optionsJson, iconPacksJson),
144
+ label,
145
+ { forwardsAbortSignal: true, directSvgAddon },
146
+ );
147
+ } catch (cause) {
148
+ throw decodeWireCreationError(cause, label);
149
+ }
150
+ try {
151
+ const runtimeCatalogJson = assertRuntimePackageVersion(transport.runtimeCatalogJson());
152
+ const wrapped = {
153
+ ...transport,
154
+ runtimeCatalogJson: () => runtimeCatalogJson,
155
+ };
156
+ return typeof wrapped.executeSvg === "function" ? Object.freeze(wrapped) : wrapped;
157
+ } catch (cause) {
158
+ try {
159
+ await transport.dispose();
160
+ } catch {
161
+ // Preserve the package-version failure that made the transport unusable.
162
+ }
163
+ throw cause;
164
+ }
165
+ }
166
+
92
167
  function linuxLibc(report, arch) {
93
168
  if (report?.header?.glibcVersionRuntime) return "gnu";
94
169
  if (
@@ -15,7 +15,7 @@ function validateContract(value) {
15
15
  value.schema_version !== 1 ||
16
16
  value.package_id !== "@mermanjs/node" ||
17
17
  value.artifact_id !== "merman-node-static-svg" ||
18
- value.transport_api_version !== 1 ||
18
+ value.transport_api_version !== 2 ||
19
19
  value.binding_result_payload_version !== 1 ||
20
20
  !value.artifact ||
21
21
  !value.documents ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mermanjs/node-wasm",
3
- "version": "0.10.0-alpha.2",
3
+ "version": "0.11.0",
4
4
  "description": "Explicit Node-targeted WebAssembly rendering package for Merman.",
5
5
  "type": "module",
6
6
  "engines": {