@celestia-island/hikari 0.55.507 → 0.55.509

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.
@@ -83,6 +83,11 @@ export interface BoardEdgeInput {
83
83
  * message text). Plain text — no markup, SVG <text> with a surface
84
84
  * halo so it stays legible over the path it names. */
85
85
  label?: string;
86
+ /** Small caption at the FROM end, just off the border (mermaid class
87
+ * multiplicities: `Student "1"` paints `1` near Student). */
88
+ labelFrom?: string;
89
+ /** Small caption at the TO end. */
90
+ labelTo?: string;
86
91
  }
87
92
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
88
93
  nodes: {
@@ -49,6 +49,10 @@ export interface LaidOutEdge {
49
49
  anchorTo?: MermaidAnchorMode;
50
50
  dashed: boolean;
51
51
  arrow: "none" | "solid" | "open";
52
+ /** Class-diagram multiplicity at the FROM end (`Student "1"` → `"1"`). */
53
+ labelFrom?: string;
54
+ /** Class-diagram multiplicity at the TO end. */
55
+ labelTo?: string;
52
56
  /** Non-arrow adornment at the target end (`--o` ring, `--x` cross). */
53
57
  headEnd?: "circle" | "cross";
54
58
  /** Non-arrow adornment at the SOURCE end (`<-->` draws an arrowhead). */
@@ -79,10 +79,19 @@ export interface SequenceMessage {
79
79
  text: string;
80
80
  arrowKind: SeqArrowKind;
81
81
  }
82
+ /** One block frame over a message span (inclusive indices). Rust parity:
83
+ * `SequenceBlock`, omitted from the JSON when there are none. */
84
+ export interface MermaidSequenceBlock {
85
+ kind: string;
86
+ label: string | null;
87
+ from: number;
88
+ to: number;
89
+ }
82
90
  export interface MermaidSequenceDoc {
83
91
  kind: "sequence";
84
92
  participants: string[];
85
93
  messages: SequenceMessage[];
94
+ blocks?: MermaidSequenceBlock[];
86
95
  }
87
96
  export type ClassVisibility = "public" | "private" | "protected" | "internal";
88
97
  export interface ClassMember {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.507",
3
+ "version": "0.55.509",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -139,6 +139,11 @@ export interface BoardEdgeInput {
139
139
  * message text). Plain text — no markup, SVG <text> with a surface
140
140
  * halo so it stays legible over the path it names. */
141
141
  label?: string;
142
+ /** Small caption at the FROM end, just off the border (mermaid class
143
+ * multiplicities: `Student "1"` paints `1` near Student). */
144
+ labelFrom?: string;
145
+ /** Small caption at the TO end. */
146
+ labelTo?: string;
142
147
  }
143
148
 
144
149
  // Ink colors ride INLINE STYLES beside the stroke presentation attribute:
@@ -210,6 +215,14 @@ export default defineComponent({
210
215
  /** Edges sharing a `from` node fan across its border (天女散花). */
211
216
  const fanOrdinal = computed(() => boardFanOrdinals(props.edges));
212
217
 
218
+ /** A point `dist` px from `from`, toward `to` (straight line). */
219
+ const offsetToward = (from: BoardPoint, to: BoardPoint, dist: number): { x: number; y: number } => {
220
+ const dx = to.x - from.x;
221
+ const dy = to.y - from.y;
222
+ const len = Math.hypot(dx, dy) || 1;
223
+ return { x: from.x + (dx / len) * dist, y: from.y + (dy / len) * dist };
224
+ };
225
+
213
226
  const edgePaths = computed(() => {
214
227
  const rects = rectOf.value;
215
228
  const out: {
@@ -223,6 +236,10 @@ export default defineComponent({
223
236
  headStart?: "arrow";
224
237
  label: string | null;
225
238
  labelAt: { x: number; y: number };
239
+ labelFrom: string | null;
240
+ labelFromAt: { x: number; y: number } | null;
241
+ labelTo: string | null;
242
+ labelToAt: { x: number; y: number } | null;
226
243
  }[] = [];
227
244
  for (const e of props.edges) {
228
245
  const from = rects.get(e.from);
@@ -272,6 +289,13 @@ export default defineComponent({
272
289
  headStart: e.headStart,
273
290
  label: e.label && e.label !== "" ? e.label : null,
274
291
  labelAt: mid,
292
+ // The end captions sit just OFF the border, a step toward the other
293
+ // end: on the border they collide with the node, any further they
294
+ // drift off their line.
295
+ labelFrom: e.labelFrom ?? null,
296
+ labelFromAt: e.labelFrom ? offsetToward(a, b, 14) : null,
297
+ labelTo: e.labelTo ?? null,
298
+ labelToAt: e.labelTo ? offsetToward(b, a, 14) : null,
275
299
  });
276
300
  }
277
301
  return out;
@@ -702,6 +726,28 @@ export default defineComponent({
702
726
  {e.label}
703
727
  </text>
704
728
  )}
729
+ {e.labelFrom !== null && e.labelFromAt !== null && (
730
+ <text
731
+ class="hk-board-edge-endlabel"
732
+ x={e.labelFromAt.x}
733
+ y={e.labelFromAt.y}
734
+ text-anchor="middle"
735
+ dominant-baseline="middle"
736
+ >
737
+ {e.labelFrom}
738
+ </text>
739
+ )}
740
+ {e.labelTo !== null && e.labelToAt !== null && (
741
+ <text
742
+ class="hk-board-edge-endlabel"
743
+ x={e.labelToAt.x}
744
+ y={e.labelToAt.y}
745
+ text-anchor="middle"
746
+ dominant-baseline="middle"
747
+ >
748
+ {e.labelTo}
749
+ </text>
750
+ )}
705
751
  </g>
706
752
  ))}
707
753
  </svg>
@@ -248,6 +248,60 @@ describe("HkMermaidDiagram", () => {
248
248
  expect(paths.some((p) => p.getAttribute("marker-start")?.includes("hk-board-ah-")), "a two-ended arrow").toBe(true);
249
249
  });
250
250
 
251
+ it("paints class multiplicities at the relation's ends, end to end", async () => {
252
+ // The full path under test: the parser lifts `Student "1"` /
253
+ // `"*" School` into the contract, the class layout forwards them (swapped
254
+ // when the adornment swaps the route), the board paints each near its
255
+ // class. MUT: dropping `labelFrom`/`labelTo` from ANY of the three
256
+ // projections (layout → diagram → board) or from the board's text render
257
+ // leaves this green-while-blank — that is why the pin is end-to-end.
258
+ setMermaidEngineForTests(mermaidParser);
259
+ await mermaidReady;
260
+ const c = mount({
261
+ source: 'classDiagram\n class Student\n class School\n Student "1" --> "*" School : attends\n',
262
+ });
263
+ await settle();
264
+ expect(c.querySelector(".hk-mermaid-fallback")).toBeNull();
265
+ const ends = [...c.querySelectorAll(".hk-board-edge-endlabel")].map((t) => t.textContent);
266
+ expect(ends, "both multiplicities painted").toEqual(expect.arrayContaining(["1", "*"]));
267
+ // The relation caption is still the midpoint label.
268
+ expect([...c.querySelectorAll(".hk-board-edge-label")].map((t) => t.textContent)).toEqual(["attends"]);
269
+ });
270
+
271
+ it("paints sequence block frames over their message rows", async () => {
272
+ // alt/else/opt open, section and close into frames spanning exactly their
273
+ // message rows. MUT: dropping the block parsing (frames vanish), the
274
+ // layout's frame nodes (frames vanish), or mis-scoping the span (wrong
275
+ // label/count) each never passes the assertions below.
276
+ setMermaidEngineForTests(mermaidParser);
277
+ await mermaidReady;
278
+ const c = mount({
279
+ source: [
280
+ "sequenceDiagram",
281
+ " Alice ->> Bob: a",
282
+ " alt success",
283
+ " Bob -->> Alice: b",
284
+ " else failure",
285
+ " Bob -->> Alice: c",
286
+ " end",
287
+ " opt maybe",
288
+ " Alice ->> Bob: d",
289
+ " end",
290
+ " Alice ->> Bob: e",
291
+ ].join("\n"),
292
+ });
293
+ await settle();
294
+ expect(c.querySelector(".hk-mermaid-fallback")).toBeNull();
295
+ const frames = [...c.querySelectorAll(".hk-mmd-group .hk-mmd-group__label")].map((el) => el.textContent);
296
+ expect(frames, "alt section, else section, opt frame").toEqual([
297
+ "alt: success",
298
+ "alt: failure",
299
+ "opt: maybe",
300
+ ]);
301
+ // The five messages still render as edges.
302
+ expect(c.querySelectorAll(".hk-board-edge").length).toBeGreaterThanOrEqual(5);
303
+ });
304
+
251
305
  it("changing the source re-parses (computed pipeline, no stale board)", async () => {
252
306
  setMermaidEngineForTests(mermaidParser);
253
307
  await mermaidReady;
@@ -418,6 +418,10 @@ export default defineComponent({
418
418
  headStart: e.headStart,
419
419
  ink: MERMAID_EDGE_INK,
420
420
  label: e.label ?? undefined,
421
+ // The class multiplicities ride the same four-projection path as the
422
+ // head glyphs — a drop in any layer is invisible to a props-level test.
423
+ labelFrom: e.labelFrom,
424
+ labelTo: e.labelTo,
421
425
  via: e.via,
422
426
  })),
423
427
  );
@@ -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.507 <dev>">
4
+ <meta name="hk-error-landing" content="v1 0.55.509 <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" />
@@ -22,6 +22,11 @@ exports[`mermaid golden snapshots (wasm is the reference) > mermaid: class-basic
22
22
  ],
23
23
  "name": "Animal",
24
24
  },
25
+ {
26
+ "attributes": [],
27
+ "methods": [],
28
+ "name": "Dog",
29
+ },
25
30
  ],
26
31
  "kind": "class",
27
32
  "relationships": [
@@ -74,6 +74,10 @@ export interface LaidOutEdge {
74
74
  anchorTo?: MermaidAnchorMode;
75
75
  dashed: boolean;
76
76
  arrow: "none" | "solid" | "open";
77
+ /** Class-diagram multiplicity at the FROM end (`Student "1"` → `"1"`). */
78
+ labelFrom?: string;
79
+ /** Class-diagram multiplicity at the TO end. */
80
+ labelTo?: string;
77
81
  /** Non-arrow adornment at the target end (`--o` ring, `--x` cross). */
78
82
  headEnd?: "circle" | "cross";
79
83
  /** Non-arrow adornment at the SOURCE end (`<-->` draws an arrowhead). */
@@ -938,6 +942,35 @@ function layoutSequence(
938
942
  edges.push({ id: `e:life:${p}`, from: `p:${p}`, to: `j:life:${p}`, style: "straight", dashed: true, arrow: "none", label: null });
939
943
  }
940
944
 
945
+ // Block frames (alt/opt/loop/…): one passthrough group node per frame,
946
+ // spanning the frame's message rows and the participants its messages
947
+ // actually touch (a two-party alt must not span every lane on the page).
948
+ doc.blocks?.forEach((blk, bi) => {
949
+ if (blk.to < blk.from) return;
950
+ const span = doc.messages.slice(blk.from, blk.to + 1);
951
+ if (span.length === 0) return;
952
+ const xs = span.flatMap((m) => {
953
+ const a = centerX.get(m.from);
954
+ const b = centerX.get(m.to);
955
+ return [a, b].filter((v): v is number => v !== undefined);
956
+ });
957
+ if (xs.length === 0) return;
958
+ const pad = 22;
959
+ const left = Math.min(...xs) - pad;
960
+ const right = Math.max(...xs) + pad;
961
+ const top = firstRowY + blk.from * SEQ_ROW_STEP - 22;
962
+ const height = (blk.to - blk.from) * SEQ_ROW_STEP + 44;
963
+ nodes.push({
964
+ id: `b:${bi}`,
965
+ x: left,
966
+ y: top,
967
+ w: Math.max(right - left, 120),
968
+ h: height,
969
+ kind: "group",
970
+ data: { label: `${blk.kind}${blk.label ? `: ${blk.label}` : ""}` },
971
+ });
972
+ });
973
+
941
974
  doc.messages.forEach((msg, i) => {
942
975
  const fromX = centerX.get(msg.from) ?? MARGIN;
943
976
  const toX = centerX.get(msg.to) ?? MARGIN;
@@ -1030,6 +1063,10 @@ function layoutClass(
1030
1063
  dashed: dashedRel.has(r.relType),
1031
1064
  arrow,
1032
1065
  label: r.label,
1066
+ // Multiplicity belongs to the CLASS end, not the routed end: when the
1067
+ // edge was swapped for the adornment, the cardinalities swap with it.
1068
+ labelFrom: (swap ? r.toCardinality : r.fromCardinality) ?? undefined,
1069
+ labelTo: (swap ? r.fromCardinality : r.toCardinality) ?? undefined,
1033
1070
  };
1034
1071
  });
1035
1072
 
@@ -108,10 +108,20 @@ export interface SequenceMessage {
108
108
  arrowKind: SeqArrowKind;
109
109
  }
110
110
 
111
+ /** One block frame over a message span (inclusive indices). Rust parity:
112
+ * `SequenceBlock`, omitted from the JSON when there are none. */
113
+ export interface MermaidSequenceBlock {
114
+ kind: string;
115
+ label: string | null;
116
+ from: number;
117
+ to: number;
118
+ }
119
+
111
120
  export interface MermaidSequenceDoc {
112
121
  kind: "sequence";
113
122
  participants: string[];
114
123
  messages: SequenceMessage[];
124
+ blocks?: MermaidSequenceBlock[];
115
125
  }
116
126
 
117
127
  // ── Class ────────────────────────────────────────────────────────────
@@ -64,8 +64,10 @@ describe("wasmMermaidEngine", () => {
64
64
  ) as MermaidClassDoc;
65
65
  expect(doc).not.toBeNull();
66
66
  expect(doc!.kind).toBe("class");
67
- expect(doc!.classes).toHaveLength(1);
68
- expect(doc!.classes[0]!.name).toBe("Animal");
67
+ // MUT:implied-classes — `Dog <|-- Animal` implies Dog (an endpoint is a
68
+ // class even without a `class` block); dropping the pass never passes
69
+ // this length assertion.
70
+ expect(doc!.classes.map((c) => c.name)).toEqual(["Animal", "Dog"]);
69
71
  // Members split: +name is an attribute, +speak() is a method.
70
72
  expect(doc!.classes[0]!.attributes).toHaveLength(1);
71
73
  expect(doc!.classes[0]!.methods).toHaveLength(1);