@draftably/markdown 0.0.0-stage → 0.2.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 +24 -2
- package/dist/LICENSE +21 -0
- package/dist/chunks/core-D4HpamVq.js +323 -0
- package/dist/chunks/mermaid-facade-BoLWBerE.js +289 -0
- package/dist/chunks/mermaid-importer-IVovOQE9.js +3753 -0
- package/dist/chunks/metadata-Dx6T_2Zy.js +53 -0
- package/dist/client.js +153 -0
- package/dist/files.js +103 -0
- package/dist/index.js +8 -0
- package/dist/markdown-it.js +156 -0
- package/dist/mermaid.js +93 -0
- package/dist/remark.js +86 -0
- package/dist/types/packages/markdown/src/client-validation.d.ts +5 -0
- package/dist/types/packages/markdown/src/client.d.ts +12 -0
- package/dist/types/packages/markdown/src/core.d.ts +110 -0
- package/dist/types/packages/markdown/src/files.d.ts +12 -0
- package/dist/types/packages/markdown/src/index.d.ts +3 -0
- package/dist/types/packages/markdown/src/markdown-it-helpers.d.ts +9 -0
- package/dist/types/packages/markdown/src/markdown-it.d.ts +30 -0
- package/dist/types/packages/markdown/src/mermaid.d.ts +8 -0
- package/dist/types/packages/markdown/src/metadata.d.ts +9 -0
- package/dist/types/packages/markdown/src/remark.d.ts +21 -0
- package/dist/types/packages/markdown/src/source.d.ts +4 -0
- package/dist/types/src/dsl/cells.d.ts +91 -0
- package/dist/types/src/dsl/channels.d.ts +53 -0
- package/dist/types/src/dsl/compile.d.ts +162 -0
- package/dist/types/src/dsl/frame.d.ts +38 -0
- package/dist/types/src/dsl/lanes.d.ts +23 -0
- package/dist/types/src/dsl/legend-notes.d.ts +3 -0
- package/dist/types/src/dsl/project.d.ts +39 -0
- package/dist/types/src/dsl/syntax.d.ts +317 -0
- package/dist/types/src/import/import-core.d.ts +105 -0
- package/dist/types/src/import/mermaid-facade.d.ts +120 -0
- package/dist/types/src/import/mermaid-importer.d.ts +4 -0
- package/dist/types/src/import/mermaid-sequence.d.ts +8 -0
- package/dist/types/src/model/appearance.d.ts +209 -0
- package/dist/types/src/model/bounds.d.ts +19 -0
- package/dist/types/src/model/document.d.ts +24 -0
- package/dist/types/src/model/font-faces.d.ts +24 -0
- package/dist/types/src/model/fonts.d.ts +47 -0
- package/dist/types/src/model/footnote.d.ts +34 -0
- package/dist/types/src/model/geometry.d.ts +29 -0
- package/dist/types/src/model/graph.d.ts +53 -0
- package/dist/types/src/model/heading.d.ts +38 -0
- package/dist/types/src/model/icons.d.ts +2 -0
- package/dist/types/src/model/labels.d.ts +88 -0
- package/dist/types/src/model/link.d.ts +63 -0
- package/dist/types/src/model/markers.d.ts +47 -0
- package/dist/types/src/model/note.d.ts +75 -0
- package/dist/types/src/model/rich-text.d.ts +24 -0
- package/dist/types/src/model/routes.d.ts +170 -0
- package/dist/types/src/model/status.d.ts +84 -0
- package/dist/types/src/model/styles.d.ts +13 -0
- package/dist/types/src/model/types.d.ts +277 -0
- package/package.json +53 -3
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@draftably/markdown`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn `draft` code fences, and optionally `mermaid` fences, into static SVG images when your site
|
|
4
|
+
builds. It has a remark plugin (Unified, MDX, Astro, Docusaurus) and a markdown-it plugin. Readers
|
|
5
|
+
load no Draftably JavaScript.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @draftably/markdown
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import remarkDraft from '@draftably/markdown/remark';
|
|
13
|
+
import { createFileAssets } from '@draftably/markdown/files';
|
|
14
|
+
|
|
15
|
+
const assets = createFileAssets({ directory: '.cache/diagrams', publicPath: '/diagrams/' });
|
|
16
|
+
processor.use(remarkDraft, { emitAsset: assets.emitAsset });
|
|
17
|
+
// After the build: await assets.copyTo('dist/diagrams');
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Docs
|
|
21
|
+
|
|
22
|
+
- [Markdown](https://draftably.dev/docs/markdown): a first build, fence options, includes,
|
|
23
|
+
Mermaid fences and interactive mode
|
|
24
|
+
- [Documentation sites](https://draftably.dev/docs/documentation-sites): Astro Starlight,
|
|
25
|
+
Docusaurus and VitePress recipes
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Byron Wall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { createHash as J } from "node:crypto";
|
|
2
|
+
import { runtimeVersion as W, fontMetricsVersion as Z, renderSvg as H } from "@draftably/runtime";
|
|
3
|
+
import { realpath as D, stat as K, readFile as V } from "node:fs/promises";
|
|
4
|
+
import { resolve as k, relative as q, sep as G, isAbsolute as Y } from "node:path";
|
|
5
|
+
function N(e, t) {
|
|
6
|
+
const r = q(e, t);
|
|
7
|
+
return r === "" || r !== ".." && !r.startsWith(`..${G}`) && !Y(r);
|
|
8
|
+
}
|
|
9
|
+
async function Q(e, t, r) {
|
|
10
|
+
if (!e || e.includes("\0") || e.startsWith("/") || e.startsWith("\\") || /^[A-Za-z][A-Za-z\d+.-]*:/.test(e) || /^[A-Za-z]:/.test(e))
|
|
11
|
+
throw new Error("src must be a relative local path.");
|
|
12
|
+
const s = await D(r), g = k(t, "..", e);
|
|
13
|
+
if (!N(k(r), g))
|
|
14
|
+
throw new Error("src is outside the configured content root.");
|
|
15
|
+
let n;
|
|
16
|
+
try {
|
|
17
|
+
n = await D(g);
|
|
18
|
+
} catch (m) {
|
|
19
|
+
let f = g, y;
|
|
20
|
+
for (; f !== k(f, ".."); )
|
|
21
|
+
try {
|
|
22
|
+
const l = await D(f);
|
|
23
|
+
if (!N(s, l))
|
|
24
|
+
throw new Error("src resolves outside the configured content root.", { cause: m });
|
|
25
|
+
y = l;
|
|
26
|
+
break;
|
|
27
|
+
} catch (l) {
|
|
28
|
+
if (l instanceof Error && l.message.includes("outside"))
|
|
29
|
+
throw l;
|
|
30
|
+
f = k(f, "..");
|
|
31
|
+
}
|
|
32
|
+
throw Object.assign(new Error("Included .draft file does not exist.", { cause: m }), {
|
|
33
|
+
missingPath: g,
|
|
34
|
+
watchPath: y
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (!N(s, n))
|
|
38
|
+
throw new Error("src resolves outside the configured content root.");
|
|
39
|
+
if (!n.endsWith(".draft")) throw new Error("src must name a .draft file.");
|
|
40
|
+
const p = await K(n);
|
|
41
|
+
if (!p.isFile()) throw new Error("src must name a regular file.");
|
|
42
|
+
if (p.size > 1e6) throw new Error("Included .draft file exceeds 1 MB.");
|
|
43
|
+
const h = await V(n);
|
|
44
|
+
if (h.byteLength > 1e6) throw new Error("Included .draft file exceeds 1 MB.");
|
|
45
|
+
return { source: new TextDecoder("utf-8", { fatal: !0 }).decode(h), path: n };
|
|
46
|
+
}
|
|
47
|
+
async function se(e, t, r) {
|
|
48
|
+
if (r.mermaid !== "convert") return { source: null, diagnostics: [] };
|
|
49
|
+
const { convertMermaid: s } = await import("../mermaid.js");
|
|
50
|
+
return s(e, t);
|
|
51
|
+
}
|
|
52
|
+
function z(e, t, r, s) {
|
|
53
|
+
return {
|
|
54
|
+
code: e,
|
|
55
|
+
severity: "error",
|
|
56
|
+
message: t,
|
|
57
|
+
location: r,
|
|
58
|
+
itemIds: [],
|
|
59
|
+
...s ? { related: s } : {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function M(e) {
|
|
63
|
+
return J("sha256").update(e).digest("hex");
|
|
64
|
+
}
|
|
65
|
+
function x(e) {
|
|
66
|
+
for (const t of e) {
|
|
67
|
+
const r = t.charCodeAt(0);
|
|
68
|
+
if (r < 32 || r === 127) return !0;
|
|
69
|
+
}
|
|
70
|
+
return !1;
|
|
71
|
+
}
|
|
72
|
+
function c(e, t = "Markdown host operation failed.") {
|
|
73
|
+
return X(e) ? e : Object.assign(new Error(t, { cause: e }), { hostFailure: !0 });
|
|
74
|
+
}
|
|
75
|
+
function X(e) {
|
|
76
|
+
return !!e && typeof e == "object" && "hostFailure" in e;
|
|
77
|
+
}
|
|
78
|
+
function P(e, t, r) {
|
|
79
|
+
return Object.assign(new Error(t), { diagnostic: z(e, t, r) });
|
|
80
|
+
}
|
|
81
|
+
function ce(e) {
|
|
82
|
+
return !!e && typeof e == "object" && "noPlaceholder" in e;
|
|
83
|
+
}
|
|
84
|
+
function F(e) {
|
|
85
|
+
if (e?.aborted)
|
|
86
|
+
throw Object.assign(new Error("Markdown diagram preparation was aborted."), {
|
|
87
|
+
noPlaceholder: !0,
|
|
88
|
+
cause: e.reason
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const v = /* @__PURE__ */ new Map(), ee = 128;
|
|
92
|
+
function te(e, t) {
|
|
93
|
+
const r = e.render ?? {};
|
|
94
|
+
if (!(r.links?.mode === "safe" && r.links.resolve && !r.links.cacheKey))
|
|
95
|
+
return JSON.stringify({
|
|
96
|
+
includeSource: r.includeSource ?? !1,
|
|
97
|
+
links: r.links ?? { mode: "none" },
|
|
98
|
+
limits: r.limits ?? {},
|
|
99
|
+
state: t ?? null,
|
|
100
|
+
target: "image",
|
|
101
|
+
fonts: "embed"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async function le(e, t, r, s, g, n) {
|
|
105
|
+
const p = [];
|
|
106
|
+
F(n.render?.signal);
|
|
107
|
+
let h = e, m = s.path, f, y = !1;
|
|
108
|
+
if (t.src) {
|
|
109
|
+
if (e.trim())
|
|
110
|
+
throw P(
|
|
111
|
+
"DRAFT_INCLUDE",
|
|
112
|
+
"src cannot be combined with a non-empty fence body.",
|
|
113
|
+
r
|
|
114
|
+
);
|
|
115
|
+
if (!s.path || !n.sources)
|
|
116
|
+
throw P(
|
|
117
|
+
"DRAFT_INCLUDE",
|
|
118
|
+
"src requires a document path and configured sources.rootDir.",
|
|
119
|
+
r
|
|
120
|
+
);
|
|
121
|
+
let i;
|
|
122
|
+
try {
|
|
123
|
+
i = await Q(t.src, s.path, n.sources.rootDir);
|
|
124
|
+
} catch (a) {
|
|
125
|
+
const { missingPath: u, watchPath: I } = a;
|
|
126
|
+
if (u)
|
|
127
|
+
try {
|
|
128
|
+
n.sources.onDependency?.({
|
|
129
|
+
documentPath: s.path,
|
|
130
|
+
dependencyPath: u,
|
|
131
|
+
missing: !0,
|
|
132
|
+
watchPath: I
|
|
133
|
+
});
|
|
134
|
+
} catch (A) {
|
|
135
|
+
throw c(A, "Markdown dependency callback failed.");
|
|
136
|
+
}
|
|
137
|
+
const o = a instanceof Error ? a.message : "Could not read included diagram.";
|
|
138
|
+
throw Object.assign(new Error(o), {
|
|
139
|
+
diagnostic: z(
|
|
140
|
+
"DRAFT_INCLUDE",
|
|
141
|
+
o,
|
|
142
|
+
r,
|
|
143
|
+
u ? [{ message: "Included here.", location: r }] : void 0
|
|
144
|
+
)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
h = i.source, m = i.path, y = !0, f = i.path;
|
|
148
|
+
try {
|
|
149
|
+
n.sources.onDependency?.({
|
|
150
|
+
documentPath: s.path,
|
|
151
|
+
dependencyPath: i.path,
|
|
152
|
+
missing: !1
|
|
153
|
+
});
|
|
154
|
+
} catch (a) {
|
|
155
|
+
throw c(a, "Markdown dependency callback failed.");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (t.mode === "interactive" && !n.interactive) {
|
|
159
|
+
const i = P(
|
|
160
|
+
"DRAFT_CAPABILITY",
|
|
161
|
+
"Interactive diagrams require a configured enhancement bridge.",
|
|
162
|
+
r
|
|
163
|
+
);
|
|
164
|
+
throw Object.assign(i, { noPlaceholder: !0 }), i;
|
|
165
|
+
}
|
|
166
|
+
const l = te(n, t.state), b = l === void 0 ? void 0 : M(
|
|
167
|
+
JSON.stringify([
|
|
168
|
+
h,
|
|
169
|
+
m ?? "",
|
|
170
|
+
W,
|
|
171
|
+
Z,
|
|
172
|
+
l
|
|
173
|
+
])
|
|
174
|
+
);
|
|
175
|
+
let w = b ? v.get(b) : void 0;
|
|
176
|
+
const L = (i) => i.map((a) => ({
|
|
177
|
+
...a,
|
|
178
|
+
location: a.location ? {
|
|
179
|
+
...a.location,
|
|
180
|
+
line: a.location.line + (y ? 0 : r?.line ?? 1),
|
|
181
|
+
...y ? {} : { column: void 0 }
|
|
182
|
+
} : r,
|
|
183
|
+
...y && r ? { related: [...a.related ?? [], { message: "Included here.", location: r }] } : {}
|
|
184
|
+
}));
|
|
185
|
+
if (!w) {
|
|
186
|
+
let i;
|
|
187
|
+
try {
|
|
188
|
+
i = await H(h, {
|
|
189
|
+
...n.render ?? {},
|
|
190
|
+
target: "image",
|
|
191
|
+
fonts: "embed",
|
|
192
|
+
includeSource: n.render?.includeSource ?? !1,
|
|
193
|
+
links: n.render?.links ?? { mode: "none" },
|
|
194
|
+
sourceId: m,
|
|
195
|
+
state: t.state ?? null
|
|
196
|
+
});
|
|
197
|
+
} catch (a) {
|
|
198
|
+
throw Object.assign(new Error("Draftably renderer failed."), {
|
|
199
|
+
noPlaceholder: !0,
|
|
200
|
+
cause: a
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (!i.ok) {
|
|
204
|
+
const a = L(i.diagnostics);
|
|
205
|
+
p.push(...a);
|
|
206
|
+
const u = Object.assign(new Error("Draftably could not render this diagram."), {
|
|
207
|
+
diagnostics: a
|
|
208
|
+
});
|
|
209
|
+
if ((n.errors ?? "fail") === "fail" || !["input", "limit"].includes(i.reason))
|
|
210
|
+
throw Object.assign(u, { noPlaceholder: !0 }), u;
|
|
211
|
+
return {
|
|
212
|
+
node: { type: "paragraph", children: [{ type: "text", value: "Diagram unavailable." }] },
|
|
213
|
+
diagnostics: p
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
w = {
|
|
217
|
+
svg: i.value.svg,
|
|
218
|
+
width: i.value.width,
|
|
219
|
+
height: i.value.height,
|
|
220
|
+
title: i.value.title,
|
|
221
|
+
diagnostics: i.diagnostics
|
|
222
|
+
}, b && (v.set(b, w), v.size > ee && v.delete(v.keys().next().value));
|
|
223
|
+
}
|
|
224
|
+
p.push(...L(w.diagnostics)), F(n.render?.signal);
|
|
225
|
+
const S = new TextEncoder().encode(w.svg), T = `draft-${M(S)}.svg`;
|
|
226
|
+
let d;
|
|
227
|
+
try {
|
|
228
|
+
d = await n.emitAsset(
|
|
229
|
+
{ fileName: T, mediaType: "image/svg+xml", bytes: S },
|
|
230
|
+
{ document: s, fenceIndex: g }
|
|
231
|
+
);
|
|
232
|
+
} catch (i) {
|
|
233
|
+
throw c(i, "SVG asset emitter failed.");
|
|
234
|
+
}
|
|
235
|
+
if (!d || typeof d.url != "string")
|
|
236
|
+
throw c(new TypeError("Asset emitter must return a URL string."));
|
|
237
|
+
let O;
|
|
238
|
+
try {
|
|
239
|
+
O = new URL(d.url, "https://draftably.invalid");
|
|
240
|
+
} catch {
|
|
241
|
+
throw c(new Error("Asset emitter returned an invalid URL."));
|
|
242
|
+
}
|
|
243
|
+
if (!d.url || d.url.charCodeAt(0) <= 32 || x(d.url) || !["https:", "http:"].includes(O.protocol))
|
|
244
|
+
throw c(new Error("Asset emitter returned an unsafe URL."));
|
|
245
|
+
const U = t.alt?.trim() || w.title, _ = {
|
|
246
|
+
type: "image",
|
|
247
|
+
url: d.url,
|
|
248
|
+
alt: U,
|
|
249
|
+
data: { hProperties: { width: Math.ceil(w.width), height: Math.ceil(w.height) } }
|
|
250
|
+
}, B = { fileName: T, url: d.url }, R = [];
|
|
251
|
+
let j;
|
|
252
|
+
const E = [_];
|
|
253
|
+
if (t.mode === "interactive") {
|
|
254
|
+
const i = n.interactive;
|
|
255
|
+
if (!/^[A-Za-z0-9._-]{1,64}$/.test(i.policyId))
|
|
256
|
+
throw c(new TypeError("Interactive policyId must be a short ASCII token."));
|
|
257
|
+
const a = `draft-${M(JSON.stringify([h, t.state ?? null, t.id ?? null, g])).slice(0, 24)}`, u = {
|
|
258
|
+
version: 1,
|
|
259
|
+
key: a,
|
|
260
|
+
source: h,
|
|
261
|
+
state: t.state ?? null,
|
|
262
|
+
label: U,
|
|
263
|
+
policyId: i.policyId
|
|
264
|
+
}, I = new TextEncoder().encode(JSON.stringify(u));
|
|
265
|
+
if (I.byteLength > 1e6)
|
|
266
|
+
throw P("DRAFT_LIMIT", "Interactive initialization data exceeds 1 MB.", r);
|
|
267
|
+
let o;
|
|
268
|
+
try {
|
|
269
|
+
o = await i.emitInit(u);
|
|
270
|
+
} catch ($) {
|
|
271
|
+
throw c($, "Interactive initialization emitter failed.");
|
|
272
|
+
}
|
|
273
|
+
if (!o || typeof o.fileName != "string" || typeof o.url != "string")
|
|
274
|
+
throw c(new TypeError("Initialization emitter must return a filename and URL."));
|
|
275
|
+
let A, C;
|
|
276
|
+
try {
|
|
277
|
+
A = new URL(o.url, "https://draftably.invalid"), C = new URL(i.clientModuleUrl, "https://draftably.invalid");
|
|
278
|
+
} catch {
|
|
279
|
+
throw c(new Error("Interactive bridge returned an invalid URL."));
|
|
280
|
+
}
|
|
281
|
+
if (o.fileName !== `draft-${M(I)}.json` || !o.url || o.url.charCodeAt(0) <= 32 || x(o.url) || !["https:", "http:"].includes(A.protocol))
|
|
282
|
+
throw c(new Error("Initialization emitter returned an invalid asset."));
|
|
283
|
+
if (!i.clientModuleUrl || i.clientModuleUrl.charCodeAt(0) <= 32 || x(i.clientModuleUrl) || !["https:", "http:"].includes(C.protocol))
|
|
284
|
+
throw c(new Error("clientModuleUrl is unsafe."));
|
|
285
|
+
R.push({ fileName: o.fileName, url: o.url }), j = i.clientModuleUrl, E.push({
|
|
286
|
+
type: "div",
|
|
287
|
+
data: {
|
|
288
|
+
hName: "div",
|
|
289
|
+
hProperties: {
|
|
290
|
+
className: ["draftably-viewer-region"],
|
|
291
|
+
"data-draftably-region": "",
|
|
292
|
+
"data-draftably-init": o.url,
|
|
293
|
+
"data-draftably-policy": i.policyId,
|
|
294
|
+
"data-draftably-key": a,
|
|
295
|
+
role: "region",
|
|
296
|
+
"aria-label": U
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
children: []
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return t.caption && E.push({
|
|
303
|
+
type: "figcaption",
|
|
304
|
+
data: { hName: "figcaption" },
|
|
305
|
+
children: [{ type: "text", value: t.caption }]
|
|
306
|
+
}), { node: t.mode === "interactive" || t.caption ? {
|
|
307
|
+
type: "figure",
|
|
308
|
+
data: { hName: "figure", ...t.id ? { hProperties: { id: t.id } } : {} },
|
|
309
|
+
children: E
|
|
310
|
+
} : {
|
|
311
|
+
type: "paragraph",
|
|
312
|
+
...t.id ? { data: { hProperties: { id: t.id } } } : {},
|
|
313
|
+
children: E
|
|
314
|
+
}, asset: B, extraAssets: R, clientModule: j, diagnostics: p, dependency: f };
|
|
315
|
+
}
|
|
316
|
+
export {
|
|
317
|
+
z as a,
|
|
318
|
+
ce as b,
|
|
319
|
+
c as h,
|
|
320
|
+
X as i,
|
|
321
|
+
se as m,
|
|
322
|
+
le as p
|
|
323
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
const E = "12.2.0";
|
|
2
|
+
const l = (t) => {
|
|
3
|
+
if (!t || typeof t != "object" || Array.isArray(t))
|
|
4
|
+
throw new Error("Expected a Mermaid data object.");
|
|
5
|
+
return t;
|
|
6
|
+
}, a = (t, s) => {
|
|
7
|
+
if (typeof t == "string") return t;
|
|
8
|
+
if (t == null && s !== void 0) return s;
|
|
9
|
+
throw new Error("Expected a Mermaid string.");
|
|
10
|
+
}, m = (t) => {
|
|
11
|
+
if (t == null) return [];
|
|
12
|
+
if (!Array.isArray(t) || t.some((s) => typeof s != "string"))
|
|
13
|
+
throw new Error("Expected a Mermaid string array.");
|
|
14
|
+
return [...t];
|
|
15
|
+
}, i = (t) => t == null ? void 0 : a(t), y = (t) => {
|
|
16
|
+
if (!Array.isArray(t)) throw new Error("Expected a Mermaid array.");
|
|
17
|
+
return t;
|
|
18
|
+
}, x = (t) => {
|
|
19
|
+
if (!(t instanceof Map)) throw new Error("Expected a Mermaid Map.");
|
|
20
|
+
return [...t.values()];
|
|
21
|
+
}, b = (t) => {
|
|
22
|
+
if (t != null) {
|
|
23
|
+
if (typeof t != "number" || !Number.isFinite(t))
|
|
24
|
+
throw new Error("Expected finite number.");
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function w(t) {
|
|
29
|
+
return t.replace(/fl°°(\d+)¶ß/g, "&#$1;").replace(/fl°([A-Za-z]\w*)¶ß/g, "&$1;");
|
|
30
|
+
}
|
|
31
|
+
function P(t) {
|
|
32
|
+
return (s) => {
|
|
33
|
+
const g = t.createElement("template");
|
|
34
|
+
return g.innerHTML = w(s).replace(/<br\s*\/?>/gi, `
|
|
35
|
+
`), g.content.textContent ?? "";
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function R(t) {
|
|
39
|
+
if (new TextEncoder().encode(t).length > 1e5)
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
code: "IMPORT_INPUT_LIMIT",
|
|
43
|
+
severity: "error",
|
|
44
|
+
message: "Mermaid input exceeds 100000 UTF-8 bytes."
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
const s = t.replace(/^\uFEFF/, "").replace(/\r\n?/g, `
|
|
48
|
+
`);
|
|
49
|
+
if (/^\s*---(?:\n|$)/.test(s) || /%%\s*\{/.test(s))
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
code: "MERMAID_CONFIGURATION_UNSUPPORTED",
|
|
53
|
+
severity: "error",
|
|
54
|
+
message: "This importer does not apply Mermaid frontmatter or directives. Remove the configuration block and import the diagram text."
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
if ([...s].some((o) => {
|
|
58
|
+
const d = o.charCodeAt(0);
|
|
59
|
+
return d < 32 && ![9, 10, 13].includes(d);
|
|
60
|
+
}))
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
code: "IMPORT_CONTROL_CHARACTER",
|
|
64
|
+
severity: "error",
|
|
65
|
+
message: "Input contains unsupported control characters."
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
const g = s.split(`
|
|
69
|
+
`).find((o) => o.trim() && !o.trimStart().startsWith("%%")) ?? "";
|
|
70
|
+
if (!/^\s*(?:flowchart|graph|sequenceDiagram)\b/.test(g))
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
code: "MERMAID_FAMILY_UNSUPPORTED",
|
|
74
|
+
severity: "error",
|
|
75
|
+
message: "This adapter supports Mermaid flowcharts and sequence diagrams only. Class, ER, state, chart and other families require separate semantic adapters."
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
const f = [];
|
|
79
|
+
for (const [o, d] of s.split(`
|
|
80
|
+
`).entries())
|
|
81
|
+
/(?:^|;)\s*click\s/.test(d) && f.push({
|
|
82
|
+
code: "MERMAID_INTERACTION_IGNORED",
|
|
83
|
+
severity: "warning",
|
|
84
|
+
message: "Mermaid click links and callbacks are data only; no interactions are installed.",
|
|
85
|
+
line: o + 1,
|
|
86
|
+
locationKind: "source"
|
|
87
|
+
});
|
|
88
|
+
return f;
|
|
89
|
+
}
|
|
90
|
+
function S(t, s) {
|
|
91
|
+
const g = new Map(
|
|
92
|
+
Object.entries(l(t.LINETYPE)).map(([n, r]) => [r, n])
|
|
93
|
+
), f = new Map(
|
|
94
|
+
Object.entries(l(t.PLACEMENT)).map(([n, r]) => [r, n])
|
|
95
|
+
), o = y(s("getBoxes")), d = s("getActors");
|
|
96
|
+
if (!(d instanceof Map)) throw new Error("Expected a Mermaid Map.");
|
|
97
|
+
const p = (n) => new Set(s(n) instanceof Map ? s(n).keys() : []);
|
|
98
|
+
return {
|
|
99
|
+
format: "mermaid",
|
|
100
|
+
family: "sequence",
|
|
101
|
+
parserVersion: E,
|
|
102
|
+
title: i(s("getDiagramTitle")) || void 0,
|
|
103
|
+
actors: m(s("getActorKeys")).map((n) => {
|
|
104
|
+
const r = l(d.get(n));
|
|
105
|
+
return {
|
|
106
|
+
id: n,
|
|
107
|
+
name: a(r.description, a(r.name, n)),
|
|
108
|
+
type: a(r.type, "participant"),
|
|
109
|
+
box: r.box ? o.indexOf(r.box) : void 0,
|
|
110
|
+
links: Object.keys(l(r.links ?? {}))
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
boxes: o.map((n) => {
|
|
114
|
+
const r = l(n);
|
|
115
|
+
return { name: i(r.name), fill: i(r.fill) };
|
|
116
|
+
}),
|
|
117
|
+
events: y(s("getMessages")).map((n) => {
|
|
118
|
+
const r = l(n), u = f.get(r.placement);
|
|
119
|
+
return {
|
|
120
|
+
kind: g.get(r.type) ?? "UNKNOWN",
|
|
121
|
+
from: i(r.from),
|
|
122
|
+
to: i(r.to),
|
|
123
|
+
// `autonumber` stores its numbering object here.
|
|
124
|
+
text: typeof r.message == "string" ? r.message : "",
|
|
125
|
+
...r.placement == null ? {} : {
|
|
126
|
+
placement: u === "LEFTOF" ? "left" : u === "RIGHTOF" ? "right" : "over"
|
|
127
|
+
},
|
|
128
|
+
central: !!r.centralConnection
|
|
129
|
+
};
|
|
130
|
+
}),
|
|
131
|
+
created: [...p("getCreatedActors")].map(String),
|
|
132
|
+
destroyed: [...p("getDestroyedActors")].map(String)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function D(t) {
|
|
136
|
+
let s = Promise.resolve();
|
|
137
|
+
return (g) => {
|
|
138
|
+
const f = s.then(async () => {
|
|
139
|
+
const o = R(g);
|
|
140
|
+
if (o.some((p) => p.severity === "error")) return { ok: !1, diagnostics: o };
|
|
141
|
+
let d = "load";
|
|
142
|
+
try {
|
|
143
|
+
const p = await t();
|
|
144
|
+
p.initialize({
|
|
145
|
+
startOnLoad: !1,
|
|
146
|
+
securityLevel: "strict",
|
|
147
|
+
htmlLabels: !1,
|
|
148
|
+
maxTextSize: 1e5,
|
|
149
|
+
maxEdges: 3e3,
|
|
150
|
+
suppressErrorRendering: !0
|
|
151
|
+
}), d = "parse";
|
|
152
|
+
const n = await p.mermaidAPI.getDiagramFromText(g.replace(/^\uFEFF/, ""));
|
|
153
|
+
if (!["flowchart", "flowchart-v2", "sequence"].includes(n.type))
|
|
154
|
+
return {
|
|
155
|
+
ok: !1,
|
|
156
|
+
diagnostics: [
|
|
157
|
+
...o,
|
|
158
|
+
{
|
|
159
|
+
code: "MERMAID_FAMILY_UNSUPPORTED",
|
|
160
|
+
severity: "error",
|
|
161
|
+
message: `Parser selected unsupported diagram family ${n.type}.`
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
d = "snapshot";
|
|
166
|
+
const r = l(n.db), u = (c) => {
|
|
167
|
+
if (typeof r[c] != "function")
|
|
168
|
+
throw new Error(`Mermaid ${E} boundary missing ${c}().`);
|
|
169
|
+
return r[c].call(r);
|
|
170
|
+
};
|
|
171
|
+
if (n.type === "sequence") {
|
|
172
|
+
const c = S(r, u);
|
|
173
|
+
return c.actors.length > 1e3 || c.events.length > 3e3 ? {
|
|
174
|
+
ok: !1,
|
|
175
|
+
diagnostics: [
|
|
176
|
+
...o,
|
|
177
|
+
{
|
|
178
|
+
code: "IMPORT_GRAPH_LIMIT",
|
|
179
|
+
severity: "error",
|
|
180
|
+
message: "Parsed sequence exceeds the import entity or event limit."
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
} : { ok: !0, diagnostics: o, snapshot: c };
|
|
184
|
+
}
|
|
185
|
+
const M = u("getEdges"), h = x(u("getVertices")).map((c) => {
|
|
186
|
+
const e = l(c);
|
|
187
|
+
return {
|
|
188
|
+
id: a(e.id),
|
|
189
|
+
text: a(e.text, a(e.id)),
|
|
190
|
+
type: i(e.type),
|
|
191
|
+
labelType: a(e.labelType, "text"),
|
|
192
|
+
classes: m(e.classes),
|
|
193
|
+
styles: m(e.styles),
|
|
194
|
+
link: i(e.link),
|
|
195
|
+
icon: i(e.icon),
|
|
196
|
+
img: i(e.img),
|
|
197
|
+
props: e.props == null ? void 0 : structuredClone(l(e.props))
|
|
198
|
+
};
|
|
199
|
+
}), T = y(M).map((c) => {
|
|
200
|
+
const e = l(c);
|
|
201
|
+
return {
|
|
202
|
+
start: a(e.start),
|
|
203
|
+
end: a(e.end),
|
|
204
|
+
text: a(e.text, ""),
|
|
205
|
+
type: i(e.type),
|
|
206
|
+
stroke: i(e.stroke),
|
|
207
|
+
id: i(e.id),
|
|
208
|
+
isUserDefinedId: e.isUserDefinedId === !0,
|
|
209
|
+
labelType: a(e.labelType, "text"),
|
|
210
|
+
classes: m(e.classes),
|
|
211
|
+
style: m(e.style),
|
|
212
|
+
length: b(e.length),
|
|
213
|
+
interpolate: i(e.interpolate),
|
|
214
|
+
animate: e.animate === !0,
|
|
215
|
+
animation: i(e.animation)
|
|
216
|
+
};
|
|
217
|
+
}), A = y(u("getSubGraphs")).map((c) => {
|
|
218
|
+
const e = l(c);
|
|
219
|
+
return {
|
|
220
|
+
id: a(e.id),
|
|
221
|
+
title: a(e.title, ""),
|
|
222
|
+
nodes: m(e.nodes),
|
|
223
|
+
dir: i(e.dir),
|
|
224
|
+
labelType: a(e.labelType, "text"),
|
|
225
|
+
classes: m(e.classes),
|
|
226
|
+
metadata: e.metadata == null ? void 0 : structuredClone(l(e.metadata))
|
|
227
|
+
};
|
|
228
|
+
}), _ = x(u("getClasses")).map((c) => {
|
|
229
|
+
const e = l(c);
|
|
230
|
+
return { id: a(e.id), styles: m(e.styles), textStyles: m(e.textStyles) };
|
|
231
|
+
});
|
|
232
|
+
if (h.length + A.length > 1e3 || T.length > 3e3)
|
|
233
|
+
return {
|
|
234
|
+
ok: !1,
|
|
235
|
+
diagnostics: [
|
|
236
|
+
...o,
|
|
237
|
+
{
|
|
238
|
+
code: "IMPORT_GRAPH_LIMIT",
|
|
239
|
+
severity: "error",
|
|
240
|
+
message: "Parsed graph exceeds the import entity or edge limit."
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
};
|
|
244
|
+
const I = M;
|
|
245
|
+
return {
|
|
246
|
+
ok: !0,
|
|
247
|
+
diagnostics: o,
|
|
248
|
+
snapshot: {
|
|
249
|
+
format: "mermaid",
|
|
250
|
+
family: "flowchart",
|
|
251
|
+
parserVersion: E,
|
|
252
|
+
direction: a(u("getDirection"), "TB"),
|
|
253
|
+
vertices: h,
|
|
254
|
+
edges: T,
|
|
255
|
+
groups: A,
|
|
256
|
+
classes: _,
|
|
257
|
+
defaultEdgeStyle: m(I.defaultStyle),
|
|
258
|
+
defaultEdgeInterpolate: i(I.defaultInterpolate)
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
} catch (p) {
|
|
262
|
+
const n = p, r = n.hash?.loc;
|
|
263
|
+
return {
|
|
264
|
+
ok: !1,
|
|
265
|
+
diagnostics: [
|
|
266
|
+
...o,
|
|
267
|
+
{
|
|
268
|
+
code: d === "parse" ? "MERMAID_PARSE_ERROR" : "MERMAID_ADAPTER_MISMATCH",
|
|
269
|
+
severity: "error",
|
|
270
|
+
message: n.message ?? String(p),
|
|
271
|
+
line: r?.first_line,
|
|
272
|
+
column: r?.first_column == null ? void 0 : r.first_column + 1,
|
|
273
|
+
locationKind: r ? "parser-relative" : void 0
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return s = f.catch(() => {
|
|
280
|
+
}), f;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
export {
|
|
284
|
+
E as MERMAID_VERSION,
|
|
285
|
+
D as createMermaidFlowParser,
|
|
286
|
+
P as makePlainLabel,
|
|
287
|
+
R as preflightMermaidFlow,
|
|
288
|
+
w as restoreEntitySpelling
|
|
289
|
+
};
|