@celestia-island/hikari 0.55.508 → 0.55.510

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.508",
3
+ "version": "0.55.510",
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",
@@ -51,6 +51,17 @@
51
51
  stroke-linejoin: round;
52
52
  }
53
53
 
54
+ .hk-board-edge-endlabel {
55
+ // One step smaller than the midpoint caption: the multiplicities are
56
+ // metadata, the caption is the message.
57
+ font-size: 10px;
58
+ fill: rgb(var(--color-text) / 85%);
59
+ paint-order: stroke;
60
+ stroke: rgb(var(--color-surface));
61
+ stroke-width: 4px;
62
+ stroke-linejoin: round;
63
+ }
64
+
54
65
  // Edge ink (fill/stroke/linecap) is set as presentation attributes on every
55
66
  // emitted path (HkBoard.tsx) — no CSS declaration here, only per-edge attrs.
56
67
 
@@ -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,28 @@ 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
+
226
+ /** An end caption's anchor: `dist` px along the line from its border and
227
+ * `side` px OFF the shaft (perpendicular). On the shaft the caption
228
+ * crosses the arrow and is illegible (audit screenshot, 2026-11-28);
229
+ * off to one side it reads like mermaid's own placement. The two ends
230
+ * naturally land on opposite sides because their directions invert. */
231
+ const offsetEnd = (from: BoardPoint, to: BoardPoint, dist: number, side: number): { x: number; y: number } => {
232
+ const dx = to.x - from.x;
233
+ const dy = to.y - from.y;
234
+ const len = Math.hypot(dx, dy) || 1;
235
+ const ux = dx / len;
236
+ const uy = dy / len;
237
+ return { x: from.x + ux * dist - uy * side, y: from.y + uy * dist + ux * side };
238
+ };
239
+
213
240
  const edgePaths = computed(() => {
214
241
  const rects = rectOf.value;
215
242
  const out: {
@@ -223,6 +250,10 @@ export default defineComponent({
223
250
  headStart?: "arrow";
224
251
  label: string | null;
225
252
  labelAt: { x: number; y: number };
253
+ labelFrom: string | null;
254
+ labelFromAt: { x: number; y: number } | null;
255
+ labelTo: string | null;
256
+ labelToAt: { x: number; y: number } | null;
226
257
  }[] = [];
227
258
  for (const e of props.edges) {
228
259
  const from = rects.get(e.from);
@@ -231,6 +262,7 @@ export default defineComponent({
231
262
  const toCenter = { x: to.x + to.w / 2, y: to.y + to.h / 2 };
232
263
  const fromCenter = { x: from.x + from.w / 2, y: from.y + from.h / 2 };
233
264
  const fan = fanOrdinal.value.get(e.id) ?? { index: 0, count: 1 };
265
+ const edgeLen = Math.hypot(toCenter.x - fromCenter.x, toCenter.y - fromCenter.y);
234
266
  const a = boardAnchor(from, e.anchorFrom ?? "center", toCenter, fan.index, fan.count);
235
267
  const b = boardAnchor(to, e.anchorTo ?? "center", fromCenter, fan.index, fan.count);
236
268
  const viaCenters = (e.via ?? [])
@@ -272,6 +304,19 @@ export default defineComponent({
272
304
  headStart: e.headStart,
273
305
  label: e.label && e.label !== "" ? e.label : null,
274
306
  labelAt: mid,
307
+ // End captions sit OFF the shaft (perpendicular to the line): on it
308
+ // they cross the arrow and are illegible (audit screenshot,
309
+ // 2026-11-28). Short edges (adjacent classes) would stack them onto
310
+ // the midpoint caption, so they step closer to the border and
311
+ // further off the shaft as the edge shrinks.
312
+ labelFrom: e.labelFrom ?? null,
313
+ labelFromAt: e.labelFrom
314
+ ? offsetEnd(a, b, edgeLen > 90 ? 14 : 8, edgeLen > 90 ? 12 : 16)
315
+ : null,
316
+ labelTo: e.labelTo ?? null,
317
+ labelToAt: e.labelTo
318
+ ? offsetEnd(b, a, edgeLen > 90 ? 14 : 8, edgeLen > 90 ? 12 : 16)
319
+ : null,
275
320
  });
276
321
  }
277
322
  return out;
@@ -702,6 +747,28 @@ export default defineComponent({
702
747
  {e.label}
703
748
  </text>
704
749
  )}
750
+ {e.labelFrom !== null && e.labelFromAt !== null && (
751
+ <text
752
+ class="hk-board-edge-endlabel"
753
+ x={e.labelFromAt.x}
754
+ y={e.labelFromAt.y}
755
+ text-anchor="middle"
756
+ dominant-baseline="middle"
757
+ >
758
+ {e.labelFrom}
759
+ </text>
760
+ )}
761
+ {e.labelTo !== null && e.labelToAt !== null && (
762
+ <text
763
+ class="hk-board-edge-endlabel"
764
+ x={e.labelToAt.x}
765
+ y={e.labelToAt.y}
766
+ text-anchor="middle"
767
+ dominant-baseline="middle"
768
+ >
769
+ {e.labelTo}
770
+ </text>
771
+ )}
705
772
  </g>
706
773
  ))}
707
774
  </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.508 <dev>">
4
+ <meta name="hk-error-landing" content="v1 0.55.510 <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" />
@@ -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 ────────────────────────────────────────────────────────────