@celestia-island/hikari 0.55.504 → 0.55.506
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/types/components/HkBoard.d.ts +6 -0
- package/dist/types/mermaid/layout.d.ts +4 -0
- package/dist/types/mermaid/types.d.ts +13 -0
- package/package.json +1 -1
- package/src/components/HkBoard.arrows.test.tsx +48 -0
- package/src/components/HkBoard.tsx +105 -24
- package/src/components/HkMermaidDiagram.test.tsx +24 -0
- package/src/components/HkMermaidDiagram.tsx +5 -0
- package/src/components/__tests__/hkMermaidParse.test.ts +56 -0
- package/src/errorLandingStandalone/error-landing.html +1 -1
- package/src/mermaid/layout.ts +8 -0
- package/src/mermaid/types.ts +14 -0
- package/src/mermaid/wasmEngine.ts +40 -13
- package/src/wasm/mermaid/hikari_wasm_mermaid.js +1 -1
|
@@ -73,6 +73,12 @@ export interface BoardEdgeInput {
|
|
|
73
73
|
/** Arrowhead at the `to` end: solid triangle, open chevron, or none
|
|
74
74
|
* (the default — plain path, current behavior). */
|
|
75
75
|
arrow?: "none" | "solid" | "open";
|
|
76
|
+
/** Non-arrow adornment at the `to` end — mermaid's `--o` ring / `--x`
|
|
77
|
+
* cross. Drawn INSTEAD of the plain arrowhead when set. */
|
|
78
|
+
headEnd?: "circle" | "cross";
|
|
79
|
+
/** Adornment at the `from` end. Only `"arrow"` today: mermaid's `<-->`
|
|
80
|
+
* draws an arrowhead at both ends. */
|
|
81
|
+
headStart?: "arrow";
|
|
76
82
|
/** Caption painted at the path midpoint (mermaid edge labels, sequence
|
|
77
83
|
* message text). Plain text — no markup, SVG <text> with a surface
|
|
78
84
|
* halo so it stays legible over the path it names. */
|
|
@@ -49,6 +49,10 @@ export interface LaidOutEdge {
|
|
|
49
49
|
anchorTo?: MermaidAnchorMode;
|
|
50
50
|
dashed: boolean;
|
|
51
51
|
arrow: "none" | "solid" | "open";
|
|
52
|
+
/** Non-arrow adornment at the target end (`--o` ring, `--x` cross). */
|
|
53
|
+
headEnd?: "circle" | "cross";
|
|
54
|
+
/** Non-arrow adornment at the SOURCE end (`<-->` draws an arrowhead). */
|
|
55
|
+
headStart?: "arrow";
|
|
52
56
|
label: string | null;
|
|
53
57
|
via?: string[];
|
|
54
58
|
}
|
|
@@ -30,11 +30,18 @@ export interface MermaidNode {
|
|
|
30
30
|
}
|
|
31
31
|
/** `-->` (arrow) or `---` (plain line). */
|
|
32
32
|
export type MermaidEdgeType = "arrow" | "line";
|
|
33
|
+
/** A link-end adornment that is not the plain arrowhead. Rust parity:
|
|
34
|
+
* `MermaidEdge::head_end` / `head_start` (`EdgeHead`), omitted when absent. */
|
|
35
|
+
export type MermaidEdgeHead = "circle" | "cross" | "arrow";
|
|
33
36
|
export interface MermaidEdge {
|
|
34
37
|
source: string;
|
|
35
38
|
target: string;
|
|
36
39
|
label: string | null;
|
|
37
40
|
edgeType: MermaidEdgeType;
|
|
41
|
+
/** `--o` (circle) or `--x` (cross) at the target end. */
|
|
42
|
+
headEnd?: MermaidEdgeHead;
|
|
43
|
+
/** `<-->` sets this to `arrow`: an arrowhead at the SOURCE end too. */
|
|
44
|
+
headStart?: MermaidEdgeHead;
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
40
47
|
* A `subgraph` cluster — the frame drawn around its members. The Rust
|
|
@@ -101,6 +108,12 @@ export interface ClassRelationship {
|
|
|
101
108
|
* `<|--`/`*--`/`o--`/`<--` put it at the FROM class, `-->`/`..|>`/`..>`
|
|
102
109
|
* at TO, plain `--`/`..` nowhere. */
|
|
103
110
|
arrowAt: "from" | "to" | "none";
|
|
111
|
+
/** Multiplicity at the FROM end (`Student "1" --> "*" School` carries
|
|
112
|
+
* `1` here). Rust parity: `ClassRelationship::from_cardinality`, omitted
|
|
113
|
+
* from the JSON when absent. */
|
|
114
|
+
fromCardinality?: string;
|
|
115
|
+
/** Multiplicity at the TO end. */
|
|
116
|
+
toCardinality?: string;
|
|
104
117
|
}
|
|
105
118
|
export interface MermaidClassDoc {
|
|
106
119
|
kind: "class";
|
package/package.json
CHANGED
|
@@ -308,4 +308,52 @@ describe("HkBoard — arrows arrive head-on", () => {
|
|
|
308
308
|
expect(c2x).toBeLessThan(ex);
|
|
309
309
|
board.unmount();
|
|
310
310
|
});
|
|
311
|
+
|
|
312
|
+
/// `--o` / `--x` / `<-->`: a ring or a cross is DRAWN at the named end, and
|
|
313
|
+
/// `<-->` puts an arrowhead at BOTH ends. The glyph must not become a node
|
|
314
|
+
/// name (the parser side pins that) and must not be silently dropped here
|
|
315
|
+
/// (this side).
|
|
316
|
+
///
|
|
317
|
+
/// MUT: removing the marker definitions or the `marker-start` binding
|
|
318
|
+
/// never passes — the corresponding assertion cannot find its marker.
|
|
319
|
+
it("draws a ring, a cross and a two-ended arrow", async () => {
|
|
320
|
+
const c = document.createElement("div");
|
|
321
|
+
document.body.appendChild(c);
|
|
322
|
+
createApp({
|
|
323
|
+
render: () => (
|
|
324
|
+
<HkBoard
|
|
325
|
+
nodes={[
|
|
326
|
+
{ id: "a", x: 0, y: 0, w: 80, h: 40, label: "A" },
|
|
327
|
+
{ id: "b", x: 0, y: 200, w: 80, h: 40, label: "B" },
|
|
328
|
+
{ id: "c", x: 0, y: 400, w: 80, h: 40, label: "C" },
|
|
329
|
+
]}
|
|
330
|
+
edges={[
|
|
331
|
+
{ id: "e1", from: "a", to: "b", headEnd: "circle" },
|
|
332
|
+
{ id: "e2", from: "b", to: "c", headEnd: "cross" },
|
|
333
|
+
{ id: "e3", from: "c", to: "a", arrow: "solid", headStart: "arrow" },
|
|
334
|
+
]}
|
|
335
|
+
/>
|
|
336
|
+
),
|
|
337
|
+
}).mount(c);
|
|
338
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
339
|
+
// A ring marker exists and is CIRCULAR (a marker whose child is a circle).
|
|
340
|
+
const markers = [...c.querySelectorAll("marker")];
|
|
341
|
+
const ring = markers.find((m) => m.querySelector("circle") !== null);
|
|
342
|
+
expect(ring, "a ring marker").toBeTruthy();
|
|
343
|
+
// A cross marker exists: two strokes crossing.
|
|
344
|
+
const cross = markers.find((m) => (m.querySelector("path")?.getAttribute("d") ?? "").includes("M1.5,1.5"));
|
|
345
|
+
expect(cross, "a cross marker").toBeTruthy();
|
|
346
|
+
// The ring is centred ON the line end (a trailing ring reads as a dot).
|
|
347
|
+
expect(ring!.getAttribute("refX")).toBe("5");
|
|
348
|
+
const paths = [...c.querySelectorAll<SVGPathElement>(".hk-board-edge")];
|
|
349
|
+
expect(paths.length).toBe(3);
|
|
350
|
+
// The two adornments landed on their edges…
|
|
351
|
+
expect(paths[0].getAttribute("marker-end")).toContain(ring!.id);
|
|
352
|
+
expect(paths[1].getAttribute("marker-end")).toContain(cross!.id);
|
|
353
|
+
// …and the bidirectional edge has a head at BOTH ends.
|
|
354
|
+
expect(paths[2].getAttribute("marker-end")).toBeTruthy();
|
|
355
|
+
expect(paths[2].getAttribute("marker-start")).toContain("hk-board-ah-");
|
|
356
|
+
expect(paths[0].getAttribute("marker-start")).toBeNull();
|
|
357
|
+
c.remove();
|
|
358
|
+
});
|
|
311
359
|
});
|
|
@@ -129,6 +129,12 @@ export interface BoardEdgeInput {
|
|
|
129
129
|
/** Arrowhead at the `to` end: solid triangle, open chevron, or none
|
|
130
130
|
* (the default — plain path, current behavior). */
|
|
131
131
|
arrow?: "none" | "solid" | "open";
|
|
132
|
+
/** Non-arrow adornment at the `to` end — mermaid's `--o` ring / `--x`
|
|
133
|
+
* cross. Drawn INSTEAD of the plain arrowhead when set. */
|
|
134
|
+
headEnd?: "circle" | "cross";
|
|
135
|
+
/** Adornment at the `from` end. Only `"arrow"` today: mermaid's `<-->`
|
|
136
|
+
* draws an arrowhead at both ends. */
|
|
137
|
+
headStart?: "arrow";
|
|
132
138
|
/** Caption painted at the path midpoint (mermaid edge labels, sequence
|
|
133
139
|
* message text). Plain text — no markup, SVG <text> with a surface
|
|
134
140
|
* halo so it stays legible over the path it names. */
|
|
@@ -213,6 +219,8 @@ export default defineComponent({
|
|
|
213
219
|
dashed: boolean;
|
|
214
220
|
width: number;
|
|
215
221
|
arrow: "none" | "solid" | "open";
|
|
222
|
+
headEnd?: "circle" | "cross";
|
|
223
|
+
headStart?: "arrow";
|
|
216
224
|
label: string | null;
|
|
217
225
|
labelAt: { x: number; y: number };
|
|
218
226
|
}[] = [];
|
|
@@ -260,6 +268,8 @@ export default defineComponent({
|
|
|
260
268
|
dashed: Boolean(e.dashed),
|
|
261
269
|
width: e.width ?? 1.5,
|
|
262
270
|
arrow: e.arrow ?? "none",
|
|
271
|
+
headEnd: e.headEnd,
|
|
272
|
+
headStart: e.headStart,
|
|
263
273
|
label: e.label && e.label !== "" ? e.label : null,
|
|
264
274
|
labelAt: mid,
|
|
265
275
|
});
|
|
@@ -274,25 +284,39 @@ export default defineComponent({
|
|
|
274
284
|
* sequence: `url(#id)` resolves document-wide, and two mounted boards
|
|
275
285
|
* minting `hk-board-ah-0` each would cross-wire their arrowheads. */
|
|
276
286
|
const boardSeq = boardInstanceSeq();
|
|
287
|
+
// Every adornment an edge can carry at an end: the two arrowheads plus
|
|
288
|
+
// mermaid's ring (`--o`) and cross (`--x`). They share one <defs> pool
|
|
289
|
+
// keyed by (kind, ink) so a diagram with many such edges emits each
|
|
290
|
+
// marker once.
|
|
291
|
+
type MarkerKind = "solid" | "open" | "circle" | "cross";
|
|
277
292
|
const edgeMarkers = computed(() => {
|
|
278
293
|
const index = new Map<string, number>();
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const key = `${e.arrow}\u0000${e.ink}`;
|
|
294
|
+
const add = (kind: MarkerKind, ink: string): void => {
|
|
295
|
+
const key = `${kind}\u0000${ink}`;
|
|
282
296
|
if (!index.has(key)) index.set(key, index.size);
|
|
297
|
+
};
|
|
298
|
+
for (const e of edgePaths.value) {
|
|
299
|
+
if (e.arrow !== "none") add(e.arrow, e.ink);
|
|
300
|
+
if (e.headEnd) add(e.headEnd, e.ink);
|
|
301
|
+
// `<-->` draws an ordinary arrow at the source end too.
|
|
302
|
+
if (e.headStart) add("solid", e.ink);
|
|
283
303
|
}
|
|
284
304
|
return [...index.entries()].map(([key, i]) => {
|
|
285
305
|
const [kind, ink] = key.split("\u0000");
|
|
286
|
-
return { id: `hk-board-ah-${boardSeq}-${i}`, kind: kind as
|
|
306
|
+
return { id: `hk-board-ah-${boardSeq}-${i}`, kind: kind as MarkerKind, ink };
|
|
287
307
|
});
|
|
288
308
|
});
|
|
289
309
|
|
|
290
|
-
const
|
|
291
|
-
if (kind === "none") return undefined;
|
|
310
|
+
const markerRef = (kind: MarkerKind, ink: string): string | undefined => {
|
|
292
311
|
const idx = edgeMarkers.value.findIndex((m) => m.kind === kind && m.ink === ink);
|
|
293
312
|
return idx >= 0 ? `url(#hk-board-ah-${boardSeq}-${idx})` : undefined;
|
|
294
313
|
};
|
|
295
314
|
|
|
315
|
+
const markerOf = (kind: "none" | "solid" | "open", ink: string): string | undefined => {
|
|
316
|
+
if (kind === "none") return undefined;
|
|
317
|
+
return markerRef(kind, ink);
|
|
318
|
+
};
|
|
319
|
+
|
|
296
320
|
const contentBounds = computed(() => content.value);
|
|
297
321
|
|
|
298
322
|
const worldStyle = computed(() => ({
|
|
@@ -579,23 +603,79 @@ export default defineComponent({
|
|
|
579
603
|
<div class="hk-board-world" style={worldStyle.value}>
|
|
580
604
|
<svg class="hk-board-edges" width={contentBounds.value.w} height={contentBounds.value.h}>
|
|
581
605
|
<defs>
|
|
582
|
-
{edgeMarkers.value.map((m) =>
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
606
|
+
{edgeMarkers.value.map((m) => {
|
|
607
|
+
// The arrowheads keep the family's 10×8 box pinned at the line
|
|
608
|
+
// end; the ring and the cross are centred ON that end (a ring
|
|
609
|
+
// that trailed the line would read as a separate dot).
|
|
610
|
+
if (m.kind === "circle") {
|
|
611
|
+
return (
|
|
612
|
+
<marker
|
|
613
|
+
key={m.id}
|
|
614
|
+
id={m.id}
|
|
615
|
+
viewBox="0 0 10 10"
|
|
616
|
+
refX={5}
|
|
617
|
+
refY={5}
|
|
618
|
+
markerWidth={10}
|
|
619
|
+
markerHeight={10}
|
|
620
|
+
markerUnits="userSpaceOnUse"
|
|
621
|
+
orient="auto"
|
|
622
|
+
>
|
|
623
|
+
<circle
|
|
624
|
+
cx={5}
|
|
625
|
+
cy={5}
|
|
626
|
+
r={3.6}
|
|
627
|
+
// `var()` in a PRESENTATION ATTRIBUTE is not
|
|
628
|
+
// substituted on every engine (the family rule this
|
|
629
|
+
// file's ink notes spell out) — the halo fill rides an
|
|
630
|
+
// inline style like every other token here.
|
|
631
|
+
style={{ fill: "rgb(var(--color-surface, 255 255 255))" }}
|
|
632
|
+
stroke={m.ink}
|
|
633
|
+
stroke-width={1.5}
|
|
634
|
+
/>
|
|
635
|
+
</marker>
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (m.kind === "cross") {
|
|
639
|
+
return (
|
|
640
|
+
<marker
|
|
641
|
+
key={m.id}
|
|
642
|
+
id={m.id}
|
|
643
|
+
viewBox="0 0 10 10"
|
|
644
|
+
refX={5}
|
|
645
|
+
refY={5}
|
|
646
|
+
markerWidth={10}
|
|
647
|
+
markerHeight={10}
|
|
648
|
+
markerUnits="userSpaceOnUse"
|
|
649
|
+
orient="auto"
|
|
650
|
+
>
|
|
651
|
+
<path
|
|
652
|
+
d="M1.5,1.5 L8.5,8.5 M8.5,1.5 L1.5,8.5"
|
|
653
|
+
fill="none"
|
|
654
|
+
stroke={m.ink}
|
|
655
|
+
stroke-width={1.5}
|
|
656
|
+
stroke-linecap="round"
|
|
657
|
+
/>
|
|
658
|
+
</marker>
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return (
|
|
662
|
+
<marker
|
|
663
|
+
key={m.id}
|
|
664
|
+
id={m.id}
|
|
665
|
+
viewBox="0 0 10 8"
|
|
666
|
+
refX={9}
|
|
667
|
+
refY={4}
|
|
668
|
+
markerWidth={10}
|
|
669
|
+
markerHeight={8}
|
|
670
|
+
markerUnits="userSpaceOnUse"
|
|
671
|
+
orient="auto"
|
|
672
|
+
>
|
|
673
|
+
{m.kind === "solid"
|
|
674
|
+
? <path d="M0,0 L10,4 L0,8 Z" fill={m.ink} />
|
|
675
|
+
: <path d="M0,0 L10,4 L0,8" fill="none" stroke={m.ink} stroke-width={1.5} stroke-linecap="round" />}
|
|
676
|
+
</marker>
|
|
677
|
+
);
|
|
678
|
+
})}
|
|
599
679
|
</defs>
|
|
600
680
|
{edgePaths.value.map((e) => (
|
|
601
681
|
<g key={e.id}>
|
|
@@ -608,7 +688,8 @@ export default defineComponent({
|
|
|
608
688
|
stroke-dasharray={e.dashed ? "6 5" : undefined}
|
|
609
689
|
fill="none"
|
|
610
690
|
stroke-linecap="round"
|
|
611
|
-
marker-end={markerOf(e.arrow, e.ink)}
|
|
691
|
+
marker-end={e.headEnd ? markerRef(e.headEnd, e.ink) : markerOf(e.arrow, e.ink)}
|
|
692
|
+
marker-start={e.headStart ? markerRef("solid", e.ink) : undefined}
|
|
612
693
|
/>
|
|
613
694
|
{e.label !== null && (
|
|
614
695
|
<text
|
|
@@ -224,6 +224,30 @@ describe("HkMermaidDiagram", () => {
|
|
|
224
224
|
for (const svg of outlines) expect(svg.children.length).toBeGreaterThan(0);
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
+
it("paints the ring/cross a link's head glyph asks for, end to end", async () => {
|
|
228
|
+
// The layout→board hand-off is what a component-level prop test cannot
|
|
229
|
+
// see: the parser puts `headEnd` on the edge, `buildBoardModel` must carry
|
|
230
|
+
// it into the board edge, and the board must draw it. Only the full
|
|
231
|
+
// mermaid render exercises all three.
|
|
232
|
+
// MUT: dropping `headEnd` from the layout's edge projection (or from the
|
|
233
|
+
// board's own projection) turns this red while a prop-level test stays
|
|
234
|
+
// green — which is exactly how this pin came to exist.
|
|
235
|
+
setMermaidEngineForTests(mermaidParser);
|
|
236
|
+
await mermaidReady;
|
|
237
|
+
const c = mount({ source: "flowchart LR\n A --o B\n B --x C\n C <--> D\n" });
|
|
238
|
+
await settle();
|
|
239
|
+
expect(c.querySelector(".hk-mermaid-fallback")).toBeNull();
|
|
240
|
+
const markers = [...c.querySelectorAll("marker")];
|
|
241
|
+
expect(markers.some((m) => m.querySelector("circle") !== null), "a ring marker").toBe(true);
|
|
242
|
+
expect(
|
|
243
|
+
markers.some((m) => (m.querySelector("path")?.getAttribute("d") ?? "").includes("M1.5,1.5")),
|
|
244
|
+
"a cross marker",
|
|
245
|
+
).toBe(true);
|
|
246
|
+
const paths = [...c.querySelectorAll<SVGPathElement>(".hk-board-edge")];
|
|
247
|
+
expect(paths.length, "three edges").toBe(3);
|
|
248
|
+
expect(paths.some((p) => p.getAttribute("marker-start")?.includes("hk-board-ah-")), "a two-ended arrow").toBe(true);
|
|
249
|
+
});
|
|
250
|
+
|
|
227
251
|
it("changing the source re-parses (computed pipeline, no stale board)", async () => {
|
|
228
252
|
setMermaidEngineForTests(mermaidParser);
|
|
229
253
|
await mermaidReady;
|
|
@@ -411,6 +411,11 @@ export default defineComponent({
|
|
|
411
411
|
anchorTo: e.anchorTo,
|
|
412
412
|
dashed: e.dashed,
|
|
413
413
|
arrow: e.arrow,
|
|
414
|
+
// The link's head glyph rides through every projection: parser →
|
|
415
|
+
// layout → this hand-off → board. Dropping it here is invisible to a
|
|
416
|
+
// board-level prop test and leaves the ring/cross unpainted.
|
|
417
|
+
headEnd: e.headEnd,
|
|
418
|
+
headStart: e.headStart,
|
|
414
419
|
ink: MERMAID_EDGE_INK,
|
|
415
420
|
label: e.label ?? undefined,
|
|
416
421
|
via: e.via,
|
|
@@ -108,6 +108,31 @@ describe("parseQuadrant", () => {
|
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
describe("link head adornments", () => {
|
|
112
|
+
/// `--o` / `--x` / `<-->` carry a head GLYPH. The grammar used to read the
|
|
113
|
+
/// letter as a node id (inventing a box and detaching the real target);
|
|
114
|
+
/// now the glyph rides the contract so the painter can draw it.
|
|
115
|
+
/// MUT: dropping the head fields leaves every assertion here undefined.
|
|
116
|
+
it("carries ring, cross and both-ends arrows through to the contract", async () => {
|
|
117
|
+
await mermaidReady;
|
|
118
|
+
const doc = wasmMermaidEngine.parse(
|
|
119
|
+
"flowchart LR\n A --o B\n B --x C\n C <--> D\n D --> E\n",
|
|
120
|
+
);
|
|
121
|
+
expect(doc).not.toBeNull();
|
|
122
|
+
const edges = (doc as unknown as {
|
|
123
|
+
edges: Array<{ source: string; target: string; headEnd?: string; headStart?: string }>;
|
|
124
|
+
}).edges;
|
|
125
|
+
const byFrom = (src: string) => edges.find((e) => e.source === src)!;
|
|
126
|
+
expect(byFrom("A").headEnd).toBe("circle");
|
|
127
|
+
expect(byFrom("A").target).toBe("B");
|
|
128
|
+
expect(byFrom("B").headEnd).toBe("cross");
|
|
129
|
+
expect(byFrom("C").headStart).toBe("arrow");
|
|
130
|
+
// An ordinary link carries neither.
|
|
131
|
+
expect(byFrom("D").headEnd).toBeUndefined();
|
|
132
|
+
expect(byFrom("D").headStart).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
111
136
|
describe("stateDiagram", () => {
|
|
112
137
|
it("parses state transitions as graph", async () => {
|
|
113
138
|
await mermaidReady;
|
|
@@ -121,6 +146,37 @@ describe("stateDiagram", () => {
|
|
|
121
146
|
/// single labelled box with every edge pointing at it.
|
|
122
147
|
/// MUT: collapsing either rewrite back to one id never passes — the two
|
|
123
148
|
/// circle assertions below catch it.
|
|
149
|
+
/// A composite state is a CLUSTER with its own initial/final markers: the
|
|
150
|
+
/// frame must exist, its members must be listed, and the nested `[*]` must
|
|
151
|
+
/// NOT merge with the top-level one (that merge is the defect the flat
|
|
152
|
+
/// rewrite removed, and a global id would reintroduce it one level down).
|
|
153
|
+
///
|
|
154
|
+
/// MUT: dropping the scope suffix from the pseudostate ids merges the four
|
|
155
|
+
/// circles into two — the distinct-id assertion catches it.
|
|
156
|
+
it("renders a composite state as a cluster with its own pseudostates", async () => {
|
|
157
|
+
await mermaidReady;
|
|
158
|
+
const doc = wasmMermaidEngine.parse(
|
|
159
|
+
"stateDiagram-v2\n [*] --> Idle\n state Working {\n [*] --> Busy\n Busy --> Done\n Done --> [*]\n }\n Idle --> Working\n Working --> [*]",
|
|
160
|
+
);
|
|
161
|
+
expect(doc).not.toBeNull();
|
|
162
|
+
const g = doc as unknown as {
|
|
163
|
+
nodes: Array<{ id: string; shape: string }>;
|
|
164
|
+
groups: Array<{ id: string; members: string[] }>;
|
|
165
|
+
edges: Array<{ source: string; target: string }>;
|
|
166
|
+
};
|
|
167
|
+
// The frame exists and holds the composite's own states.
|
|
168
|
+
expect(g.groups.map((x) => x.id)).toEqual(["Working"]);
|
|
169
|
+
expect(g.groups[0].members).toContain("Busy");
|
|
170
|
+
expect(g.groups[0].members).toContain("Done");
|
|
171
|
+
// Four DISTINCT circles: the outer pair and the composite's pair.
|
|
172
|
+
const circles = g.nodes.filter((n) => n.shape === "circle");
|
|
173
|
+
expect(circles.length).toBe(4);
|
|
174
|
+
expect(new Set(circles.map((n) => n.id)).size).toBe(4);
|
|
175
|
+
// The outer flow still runs Idle → Working, and the composite is a node
|
|
176
|
+
// edges can target (it is a container, not a plain box).
|
|
177
|
+
expect(g.edges.some((e) => e.source === "Idle" && e.target === "Working")).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
|
|
124
180
|
it("keeps the initial and final pseudostates apart, as circles", async () => {
|
|
125
181
|
await mermaidReady;
|
|
126
182
|
const doc = wasmMermaidEngine.parse("stateDiagram-v2\n [*] --> Idle\n Idle --> Running\n Running --> [*]");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<meta name="hk-error-landing" content="v1 0.55.
|
|
4
|
+
<meta name="hk-error-landing" content="v1 0.55.506 <dev>">
|
|
5
5
|
<meta charset="utf-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
<meta name="robots" content="noindex" />
|
package/src/mermaid/layout.ts
CHANGED
|
@@ -74,6 +74,10 @@ export interface LaidOutEdge {
|
|
|
74
74
|
anchorTo?: MermaidAnchorMode;
|
|
75
75
|
dashed: boolean;
|
|
76
76
|
arrow: "none" | "solid" | "open";
|
|
77
|
+
/** Non-arrow adornment at the target end (`--o` ring, `--x` cross). */
|
|
78
|
+
headEnd?: "circle" | "cross";
|
|
79
|
+
/** Non-arrow adornment at the SOURCE end (`<-->` draws an arrowhead). */
|
|
80
|
+
headStart?: "arrow";
|
|
77
81
|
label: string | null;
|
|
78
82
|
via?: string[];
|
|
79
83
|
}
|
|
@@ -851,6 +855,8 @@ function layoutGraphDoc(
|
|
|
851
855
|
...selfLoop(i, { x: loop.x, y: loop.y, w: loop.w, h: loop.h }),
|
|
852
856
|
dashed: false,
|
|
853
857
|
arrow: e.edgeType === "arrow" ? ("solid" as const) : ("none" as const),
|
|
858
|
+
headEnd: e.headEnd === "circle" || e.headEnd === "cross" ? e.headEnd : undefined,
|
|
859
|
+
headStart: e.headStart === "arrow" ? ("arrow" as const) : undefined,
|
|
854
860
|
label: e.label,
|
|
855
861
|
};
|
|
856
862
|
}
|
|
@@ -878,6 +884,8 @@ function layoutGraphDoc(
|
|
|
878
884
|
...(via && via.length > 0 ? { via } : {}),
|
|
879
885
|
dashed: false,
|
|
880
886
|
arrow: e.edgeType === "arrow" ? ("solid" as const) : ("none" as const),
|
|
887
|
+
headEnd: e.headEnd === "circle" || e.headEnd === "cross" ? e.headEnd : undefined,
|
|
888
|
+
headStart: e.headStart === "arrow" ? ("arrow" as const) : undefined,
|
|
881
889
|
label: e.label,
|
|
882
890
|
};
|
|
883
891
|
});
|
package/src/mermaid/types.ts
CHANGED
|
@@ -49,11 +49,19 @@ export interface MermaidNode {
|
|
|
49
49
|
/** `-->` (arrow) or `---` (plain line). */
|
|
50
50
|
export type MermaidEdgeType = "arrow" | "line";
|
|
51
51
|
|
|
52
|
+
/** A link-end adornment that is not the plain arrowhead. Rust parity:
|
|
53
|
+
* `MermaidEdge::head_end` / `head_start` (`EdgeHead`), omitted when absent. */
|
|
54
|
+
export type MermaidEdgeHead = "circle" | "cross" | "arrow";
|
|
55
|
+
|
|
52
56
|
export interface MermaidEdge {
|
|
53
57
|
source: string;
|
|
54
58
|
target: string;
|
|
55
59
|
label: string | null;
|
|
56
60
|
edgeType: MermaidEdgeType;
|
|
61
|
+
/** `--o` (circle) or `--x` (cross) at the target end. */
|
|
62
|
+
headEnd?: MermaidEdgeHead;
|
|
63
|
+
/** `<-->` sets this to `arrow`: an arrowhead at the SOURCE end too. */
|
|
64
|
+
headStart?: MermaidEdgeHead;
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
/**
|
|
@@ -143,6 +151,12 @@ export interface ClassRelationship {
|
|
|
143
151
|
* `<|--`/`*--`/`o--`/`<--` put it at the FROM class, `-->`/`..|>`/`..>`
|
|
144
152
|
* at TO, plain `--`/`..` nowhere. */
|
|
145
153
|
arrowAt: "from" | "to" | "none";
|
|
154
|
+
/** Multiplicity at the FROM end (`Student "1" --> "*" School` carries
|
|
155
|
+
* `1` here). Rust parity: `ClassRelationship::from_cardinality`, omitted
|
|
156
|
+
* from the JSON when absent. */
|
|
157
|
+
fromCardinality?: string;
|
|
158
|
+
/** Multiplicity at the TO end. */
|
|
159
|
+
toCardinality?: string;
|
|
146
160
|
}
|
|
147
161
|
|
|
148
162
|
export interface MermaidClassDoc {
|
|
@@ -121,19 +121,46 @@ mermaidReady.catch(() => {
|
|
|
121
121
|
* which is the only shape the grammar can carry.
|
|
122
122
|
*/
|
|
123
123
|
export function normalizeStateDiagram(source: string): string {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.replace(
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
|
|
124
|
+
const out: string[] = [];
|
|
125
|
+
// Scope depth is what gives each pseudostate its OWN node: `[*]` is the
|
|
126
|
+
// initial marker of ITS container, so a composite's `[*]` must not merge
|
|
127
|
+
// with the top-level one (merging is the defect this rewrite exists to
|
|
128
|
+
// remove, and it reappears one level down if the id is global).
|
|
129
|
+
let depth = 0;
|
|
130
|
+
for (const raw of source.split("\n")) {
|
|
131
|
+
const line = raw.replace(/^\s*stateDiagram(-v\d+)?/, "graph TD");
|
|
132
|
+
|
|
133
|
+
// Composite state header → a cluster: `state Working {` becomes
|
|
134
|
+
// `subgraph Working["Working"]`, so the frame is drawn and edges into the
|
|
135
|
+
// composite land on it.
|
|
136
|
+
const composite = /^(\s*)state\s+([A-Za-z0-9_]+)\s*\{\s*$/.exec(line);
|
|
137
|
+
if (composite) {
|
|
138
|
+
depth += 1;
|
|
139
|
+
out.push(`${composite[1]}subgraph ${composite[2]}["${composite[2]}"]`);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// A statement-level `}` closes the composite (or the diagram body).
|
|
143
|
+
if (/^\s*\}\s*$/.test(line)) {
|
|
144
|
+
depth = Math.max(0, depth - 1);
|
|
145
|
+
out.push(line.replace("}", "end"));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const scope = depth > 0 ? `_${depth}` : "";
|
|
150
|
+
const START = `__hk_state_start${scope}`;
|
|
151
|
+
const END = `__hk_state_end${scope}`;
|
|
152
|
+
const rewritten = line
|
|
153
|
+
// `[*] --> X` is the initial marker; `X --> [*]` is the final one.
|
|
154
|
+
// Both directions are handled before any leftover `[*]` so a line with
|
|
155
|
+
// one on each side still yields two distinct pseudostates.
|
|
156
|
+
.replace(/\[\*\](\s*(?:-->|--)\s*)/g, `${START}((""))$1`)
|
|
157
|
+
.replace(/((?:-->|--)\s*)\[\*\]/g, `$1${END}((""))`)
|
|
158
|
+
.replace(/\[\*\]/g, `${START}((""))`)
|
|
159
|
+
// State transition labels: `A --> B : label` → `A -->|label| B`
|
|
160
|
+
.replace(/^(\s*)(\S+)\s+(-->|--)\s+(\S+)\s*:\s*(.+)$/, "$1$2 $3|$5| $4");
|
|
161
|
+
out.push(rewritten);
|
|
162
|
+
}
|
|
163
|
+
return out.join("\n");
|
|
137
164
|
}
|
|
138
165
|
|
|
139
166
|
/** Check whether the wasm component handles this diagram type. */
|