@rse/gradia 0.9.9 → 1.0.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/README.md +73 -12
- package/dst/gradia-api-config.d.ts +1 -0
- package/dst/gradia-api-config.js +10 -4
- package/dst/gradia-api-parser.js +8 -5
- package/dst/gradia-api-render-base.js +5 -3
- package/dst/gradia-api-render-edge.js +3 -2
- package/dst/gradia-api-render-group.js +1 -1
- package/dst/gradia-api-render-node.js +5 -4
- package/dst/gradia-api-render-svg.d.ts +1 -1
- package/dst/gradia-api-render-svg.js +70 -54
- package/dst/gradia-api-type-graph.js +20 -10
- package/dst/gradia-api-type-grid.js +7 -4
- package/dst/gradia-api-type-hub.js +7 -9
- package/dst/gradia-api.js +20 -4
- package/dst/gradia-api.umd.js +2 -2
- package/dst/gradia-cli.js +5 -3
- package/dst/gradia-mcp.js +82 -13
- package/package.json +2 -2
package/dst/gradia-api.js
CHANGED
|
@@ -39,7 +39,7 @@ export const diagramFormatDefault = "svg:standalone";
|
|
|
39
39
|
export class Gradia {
|
|
40
40
|
/* the rendering configuration options and their default values
|
|
41
41
|
(exposed so consumers can discover and validate the options) */
|
|
42
|
-
static config = configDefaults;
|
|
42
|
+
static config = Object.freeze({ ...configDefaults });
|
|
43
43
|
/* parse a graph description into the graph model */
|
|
44
44
|
static parse(spec) {
|
|
45
45
|
return parse(spec);
|
|
@@ -67,15 +67,31 @@ export class Gradia {
|
|
|
67
67
|
const layout = parts === null ?
|
|
68
68
|
await renderers[type](graph, config) :
|
|
69
69
|
composeGroups(parts, await Promise.all(parts.map((part) => renderers[type](part.graph, config))), config);
|
|
70
|
+
/* derive the identifier seed of the SVG document from everything
|
|
71
|
+
which determines the rendered output, so that regenerating an
|
|
72
|
+
unchanged diagram yields a byte-identical SVG (the explicitly
|
|
73
|
+
configured options enter as their sorted key list only, as
|
|
74
|
+
their values are already part of the layered configuration and
|
|
75
|
+
merely their presence decides between a hard-coded CSS value
|
|
76
|
+
and a CSS custom property lookup) */
|
|
77
|
+
const seed = JSON.stringify({
|
|
78
|
+
type,
|
|
79
|
+
config,
|
|
80
|
+
explicit: Object.keys(explicit).sort(),
|
|
81
|
+
nodes: Array.from(graph.nodes.values()),
|
|
82
|
+
edges: graph.edges
|
|
83
|
+
});
|
|
70
84
|
/* render the laid out graph into an SVG document */
|
|
71
|
-
const svg = renderSVG(layout, config, explicit);
|
|
72
|
-
/* convert the SVG document into the requested output format
|
|
85
|
+
const svg = renderSVG(layout, config, explicit, seed);
|
|
86
|
+
/* convert the SVG document into the requested output format
|
|
87
|
+
(the Base64 encoding uses the platform-neutral "btoa", as the
|
|
88
|
+
API is also shipped as a browser bundle without "Buffer") */
|
|
73
89
|
if (format === "svg:embedded")
|
|
74
90
|
return svg.replace(/^<\?xml[^?]*\?>\n/, "");
|
|
75
91
|
else if (format === "url:xml")
|
|
76
92
|
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
77
93
|
else if (format === "url:base64")
|
|
78
|
-
return `data:image/svg+xml;base64,${
|
|
94
|
+
return `data:image/svg+xml;base64,${btoa(Array.from(new TextEncoder().encode(svg), (byte) => String.fromCharCode(byte)).join(""))}`;
|
|
79
95
|
else
|
|
80
96
|
return svg;
|
|
81
97
|
}
|