@iyulab/declart-web 0.21.0 → 0.22.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/index.d.ts CHANGED
@@ -1,32 +1,44 @@
1
+ /** Options for the render functions. */
2
+ export interface RenderOptions {
3
+ /**
4
+ * Leave the backdrop unpainted so the page shows through. Colors are unchanged —
5
+ * on a dark page use the `dark` theme so text stays legible.
6
+ */
7
+ transparent?: boolean;
8
+ }
9
+
1
10
  /**
2
11
  * Renders a TOML or JSON diagram declaration to SVG.
3
12
  * @param input - TOML or JSON declaration string (format auto-detected)
4
- * @param theme - Theme name: 'default', 'monochrome', 'accessible', 'warm' (defaults to 'default')
13
+ * @param theme - Theme name: 'default', 'monochrome', 'accessible', 'warm', 'dark' (defaults to 'default')
5
14
  * @param width - Optional canvas width in pixels (height scales proportionally)
15
+ * @param options - `transparent: true` leaves the backdrop unpainted
6
16
  * @returns SVG string
7
17
  * @throws If the declaration is invalid
8
18
  */
9
- export function render(input: string, theme?: string, width?: number): string;
19
+ export function render(input: string, theme?: string, width?: number, options?: RenderOptions): string;
10
20
 
11
21
  /**
12
22
  * Renders a JSON diagram declaration to SVG.
13
23
  * @param input - JSON declaration string
14
24
  * @param theme - Theme name (defaults to 'default')
15
25
  * @param width - Optional canvas width in pixels
26
+ * @param options - `transparent: true` leaves the backdrop unpainted
16
27
  * @returns SVG string
17
28
  * @throws If the JSON declaration is invalid
18
29
  */
19
- export function renderJson(input: string, theme?: string, width?: number): string;
30
+ export function renderJson(input: string, theme?: string, width?: number, options?: RenderOptions): string;
20
31
 
21
32
  /**
22
33
  * Renders a TOML or JSON diagram declaration with a custom theme TOML.
23
34
  * @param input - TOML or JSON declaration string
24
35
  * @param themeToml - TOML theme definition string
25
36
  * @param width - Optional canvas width in pixels
37
+ * @param options - `transparent: true` leaves the backdrop unpainted
26
38
  * @returns SVG string
27
39
  * @throws If the declaration or theme is invalid
28
40
  */
29
- export function renderWithThemeToml(input: string, themeToml: string, width?: number): string;
41
+ export function renderWithThemeToml(input: string, themeToml: string, width?: number, options?: RenderOptions): string;
30
42
 
31
43
  /**
32
44
  * Validates a TOML or JSON diagram declaration without rendering.
@@ -35,6 +47,15 @@ export function renderWithThemeToml(input: string, themeToml: string, width?: nu
35
47
  */
36
48
  export function validate(input: string): void;
37
49
 
50
+ /**
51
+ * Returns a one-paragraph text equivalent of a TOML or JSON declaration — the text the
52
+ * rendered SVG carries as its `<desc>`. Use it as `alt` when the SVG is shown through `<img>`.
53
+ * @param input - TOML or JSON declaration string
54
+ * @returns Text equivalent, e.g. `"Process: Upload → Parse → Index."`
55
+ * @throws If the declaration is invalid
56
+ */
57
+ export function describe(input: string): string;
58
+
38
59
  /**
39
60
  * Returns the list of supported theme names.
40
61
  */
package/index.js CHANGED
@@ -3,22 +3,23 @@ import {
3
3
  render_json,
4
4
  render_with_theme_toml,
5
5
  validate,
6
+ describe,
6
7
  themes as wasmThemes,
7
8
  kinds as wasmKinds,
8
9
  } from './wasm/declart_wasm.js';
9
10
 
10
- export { validate };
11
+ export { validate, describe };
11
12
 
12
- export function render(input, theme = 'default', width) {
13
- return wasmRender(input, theme, width ?? undefined);
13
+ export function render(input, theme = 'default', width, options) {
14
+ return wasmRender(input, theme, width ?? undefined, options?.transparent ?? undefined);
14
15
  }
15
16
 
16
- export function renderJson(input, theme = 'default', width) {
17
- return render_json(input, theme, width ?? undefined);
17
+ export function renderJson(input, theme = 'default', width, options) {
18
+ return render_json(input, theme, width ?? undefined, options?.transparent ?? undefined);
18
19
  }
19
20
 
20
- export function renderWithThemeToml(input, themeToml, width) {
21
- return render_with_theme_toml(input, themeToml, width ?? undefined);
21
+ export function renderWithThemeToml(input, themeToml, width, options) {
22
+ return render_with_theme_toml(input, themeToml, width ?? undefined, options?.transparent ?? undefined);
22
23
  }
23
24
 
24
25
  export function themes() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyulab/declart-web",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Declarative diagram engine for browsers and bundlers (Vite, webpack, Rollup) — declare what to show, the engine renders SVG",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,14 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * Returns a one-paragraph text equivalent of a TOML or JSON declaration — the same text the
6
+ * rendered SVG carries as `<desc>`. Use it as `alt` when the SVG is shown through `<img>`.
7
+ *
8
+ * Returns a `JsError` with the parse/validation error message when the declaration is invalid.
9
+ */
10
+ export function describe(input: string): string;
11
+
4
12
  /**
5
13
  * Returns a comma-separated list of supported diagram kind names.
6
14
  */
@@ -12,10 +20,11 @@ export function kinds(): string;
12
20
  * - `input`: TOML or JSON declaration string (auto-detected by leading `{`)
13
21
  * - `theme`: `"default"`, `"monochrome"`, `"accessible"`, or `"warm"` (unknown values fall back to `"default"`)
14
22
  * - `width`: optional canvas width in pixels (height scales proportionally)
23
+ * - `transparent`: `Some(true)` leaves the backdrop unpainted so the page shows through
15
24
  *
16
25
  * Returns the SVG string on success, or a `JsError` with a descriptive message on failure.
17
26
  */
18
- export function render(input: string, theme: string, width?: number | null): string;
27
+ export function render(input: string, theme: string, width?: number | null, transparent?: boolean | null): string;
19
28
 
20
29
  /**
21
30
  * Renders a JSON diagram declaration to SVG with a named theme.
@@ -26,7 +35,7 @@ export function render(input: string, theme: string, width?: number | null): str
26
35
  *
27
36
  * Returns the SVG string on success, or a `JsError` on failure.
28
37
  */
29
- export function render_json(input: string, theme: string, width?: number | null): string;
38
+ export function render_json(input: string, theme: string, width?: number | null, transparent?: boolean | null): string;
30
39
 
31
40
  /**
32
41
  * Renders a TOML or JSON diagram declaration with a custom theme defined as a TOML string.
@@ -37,7 +46,7 @@ export function render_json(input: string, theme: string, width?: number | null)
37
46
  *
38
47
  * Returns the SVG string on success, or a `JsError` on parse/validation failure.
39
48
  */
40
- export function render_with_theme_toml(input: string, theme_toml: string, width?: number | null): string;
49
+ export function render_with_theme_toml(input: string, theme_toml: string, width?: number | null, transparent?: boolean | null): string;
41
50
 
42
51
  /**
43
52
  * Returns a comma-separated list of supported theme names.
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./declart_wasm_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- kinds, render, render_json, render_with_theme_toml, themes, validate
8
+ describe, kinds, render, render_json, render_with_theme_toml, themes, validate
9
9
  } from "./declart_wasm_bg.js";
@@ -1,3 +1,32 @@
1
+ /**
2
+ * Returns a one-paragraph text equivalent of a TOML or JSON declaration — the same text the
3
+ * rendered SVG carries as `<desc>`. Use it as `alt` when the SVG is shown through `<img>`.
4
+ *
5
+ * Returns a `JsError` with the parse/validation error message when the declaration is invalid.
6
+ * @param {string} input
7
+ * @returns {string}
8
+ */
9
+ export function describe(input) {
10
+ let deferred3_0;
11
+ let deferred3_1;
12
+ try {
13
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
14
+ const len0 = WASM_VECTOR_LEN;
15
+ const ret = wasm.describe(ptr0, len0);
16
+ var ptr2 = ret[0];
17
+ var len2 = ret[1];
18
+ if (ret[3]) {
19
+ ptr2 = 0; len2 = 0;
20
+ throw takeFromExternrefTable0(ret[2]);
21
+ }
22
+ deferred3_0 = ptr2;
23
+ deferred3_1 = len2;
24
+ return getStringFromWasm0(ptr2, len2);
25
+ } finally {
26
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
27
+ }
28
+ }
29
+
1
30
  /**
2
31
  * Returns a comma-separated list of supported diagram kind names.
3
32
  * @returns {string}
@@ -21,14 +50,16 @@ export function kinds() {
21
50
  * - `input`: TOML or JSON declaration string (auto-detected by leading `{`)
22
51
  * - `theme`: `"default"`, `"monochrome"`, `"accessible"`, or `"warm"` (unknown values fall back to `"default"`)
23
52
  * - `width`: optional canvas width in pixels (height scales proportionally)
53
+ * - `transparent`: `Some(true)` leaves the backdrop unpainted so the page shows through
24
54
  *
25
55
  * Returns the SVG string on success, or a `JsError` with a descriptive message on failure.
26
56
  * @param {string} input
27
57
  * @param {string} theme
28
58
  * @param {number | null} [width]
59
+ * @param {boolean | null} [transparent]
29
60
  * @returns {string}
30
61
  */
31
- export function render(input, theme, width) {
62
+ export function render(input, theme, width, transparent) {
32
63
  let deferred4_0;
33
64
  let deferred4_1;
34
65
  try {
@@ -36,7 +67,7 @@ export function render(input, theme, width) {
36
67
  const len0 = WASM_VECTOR_LEN;
37
68
  const ptr1 = passStringToWasm0(theme, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
38
69
  const len1 = WASM_VECTOR_LEN;
39
- const ret = wasm.render(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);
70
+ const ret = wasm.render(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0, isLikeNone(transparent) ? 0xFFFFFF : transparent ? 1 : 0);
40
71
  var ptr3 = ret[0];
41
72
  var len3 = ret[1];
42
73
  if (ret[3]) {
@@ -62,9 +93,10 @@ export function render(input, theme, width) {
62
93
  * @param {string} input
63
94
  * @param {string} theme
64
95
  * @param {number | null} [width]
96
+ * @param {boolean | null} [transparent]
65
97
  * @returns {string}
66
98
  */
67
- export function render_json(input, theme, width) {
99
+ export function render_json(input, theme, width, transparent) {
68
100
  let deferred4_0;
69
101
  let deferred4_1;
70
102
  try {
@@ -72,7 +104,7 @@ export function render_json(input, theme, width) {
72
104
  const len0 = WASM_VECTOR_LEN;
73
105
  const ptr1 = passStringToWasm0(theme, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
74
106
  const len1 = WASM_VECTOR_LEN;
75
- const ret = wasm.render_json(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);
107
+ const ret = wasm.render_json(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0, isLikeNone(transparent) ? 0xFFFFFF : transparent ? 1 : 0);
76
108
  var ptr3 = ret[0];
77
109
  var len3 = ret[1];
78
110
  if (ret[3]) {
@@ -98,9 +130,10 @@ export function render_json(input, theme, width) {
98
130
  * @param {string} input
99
131
  * @param {string} theme_toml
100
132
  * @param {number | null} [width]
133
+ * @param {boolean | null} [transparent]
101
134
  * @returns {string}
102
135
  */
103
- export function render_with_theme_toml(input, theme_toml, width) {
136
+ export function render_with_theme_toml(input, theme_toml, width, transparent) {
104
137
  let deferred4_0;
105
138
  let deferred4_1;
106
139
  try {
@@ -108,7 +141,7 @@ export function render_with_theme_toml(input, theme_toml, width) {
108
141
  const len0 = WASM_VECTOR_LEN;
109
142
  const ptr1 = passStringToWasm0(theme_toml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
110
143
  const len1 = WASM_VECTOR_LEN;
111
- const ret = wasm.render_with_theme_toml(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);
144
+ const ret = wasm.render_with_theme_toml(ptr0, len0, ptr1, len1, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0, isLikeNone(transparent) ? 0xFFFFFF : transparent ? 1 : 0);
112
145
  var ptr3 = ret[0];
113
146
  var len3 = ret[1];
114
147
  if (ret[3]) {
Binary file
@@ -1,15 +1,16 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const describe: (a: number, b: number) => [number, number, number, number];
4
5
  export const kinds: () => [number, number];
5
- export const render: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
6
- export const render_json: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
7
- export const render_with_theme_toml: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
6
+ export const render: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
7
+ export const render_json: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
8
+ export const render_with_theme_toml: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
8
9
  export const themes: () => [number, number];
9
10
  export const validate: (a: number, b: number) => [number, number];
10
11
  export const __wbindgen_externrefs: WebAssembly.Table;
11
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
12
12
  export const __wbindgen_malloc: (a: number, b: number) => number;
13
13
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
14
14
  export const __externref_table_dealloc: (a: number) => void;
15
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
15
16
  export const __wbindgen_start: () => void;