@celestia-island/hikari 0.55.495 → 0.55.497

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.
@@ -47,6 +47,10 @@ export interface BoardNodeInput {
47
47
  kind?: string;
48
48
  /** Invisible junction node — routes edges, paints nothing. */
49
49
  hidden?: boolean;
50
+ /** Paint-only node: the shell renders but pointer gestures pass straight
51
+ * through to the board. Subgraph cluster frames need this — a frame covers
52
+ * its members' surroundings, and it must not swallow the pan drag. */
53
+ passthrough?: boolean;
50
54
  /** Opt in to pointer dragging (world-coord moves + `node-move` events). */
51
55
  draggable?: boolean;
52
56
  /** Page payload, handed back through the scoped slot. */
@@ -1,5 +1,31 @@
1
1
  import { type PropType } from "vue";
2
2
  import "./HkCornerText.scss";
3
+ /**
4
+ * Does a slot's returned tree paint NOTHING at all? The lane's dead-space
5
+ * rule must read the RENDERED nodes, not the slot's existence: Vue hands
6
+ * back a truthy value for every slot shape a host can write, so the
7
+ * original `!slotContent` test kept an invisible `.hk-corner-text` box
8
+ * (with the corner's flex margins) for a slot that renders `[]`, `[null]`,
9
+ * `false`, `""` or a whitespace-only string.
10
+ *
11
+ * The walk mirrors what Vue's own normalizer accepts:
12
+ * - `null` / `undefined` / booleans paint nothing (they normalize to a
13
+ * comment placeholder);
14
+ * - strings only paint when they carry a non-whitespace character — a
15
+ * blank string still mounts a text node, which occupies a flex row in
16
+ * the lane;
17
+ * - numbers always paint (`0` is real content);
18
+ * - a `Text` vnode paints when its children carry such a string;
19
+ * - `Fragment` vnodes (what a slot returning an array is wrapped in) and
20
+ * plain arrays recurse — they paint only what their children paint;
21
+ * - `Comment` vnodes never paint;
22
+ * - every other vnode (element, component, Teleport, Suspense) paints by
23
+ * definition.
24
+ *
25
+ * A function is NOT invoked here: Vue resolves slot functions, and calling
26
+ * a host's by hand could run it twice per render.
27
+ */
28
+ export declare function slotPaintsNothing(value: unknown): boolean;
3
29
  /** One entry of a corner text lane: plain text, or a link when `href`
4
30
  * is set (registry links open in a new tab with `noopener`, the same
5
31
  * contract as the beian filings). */
@@ -14,7 +14,7 @@
14
14
  * axis) so a doc can never collide two parts.
15
15
  */
16
16
  import type { MermaidDoc, MermaidGraphDoc } from "./types";
17
- export type MermaidNodeKind = "shape" | "participant" | "class" | "section" | "task" | "axis" | "pie" | "quadrant";
17
+ export type MermaidNodeKind = "shape" | "group" | "participant" | "class" | "section" | "task" | "axis" | "pie" | "quadrant";
18
18
  export interface LaidOutNode {
19
19
  id: string;
20
20
  x: number;
@@ -24,6 +24,9 @@ export interface LaidOutNode {
24
24
  kind: MermaidNodeKind;
25
25
  /** Invisible junction — routes edges, paints nothing, no minimap box. */
26
26
  hidden?: boolean;
27
+ /** Paint-only node: pointer gestures pass through to the board (cluster
28
+ * frames must not eat the pan drag). */
29
+ passthrough?: boolean;
27
30
  data: Record<string, unknown>;
28
31
  }
29
32
  export interface LaidOutEdge {
@@ -32,6 +35,11 @@ export interface LaidOutEdge {
32
35
  to: string;
33
36
  /** Board route style; bezier = mermaid flowchart feel. */
34
37
  style: "straight" | "bezier" | "orthogonal";
38
+ /** Border anchor overrides. An edge into a subgraph cluster lands on the
39
+ * frame's border (mermaid attaches there), not on its center — the center
40
+ * sits behind the frame's own members. */
41
+ anchorFrom?: "center" | "nearest" | "top" | "top-left" | "fan";
42
+ anchorTo?: "center" | "nearest" | "top" | "top-left" | "fan";
35
43
  dashed: boolean;
36
44
  arrow: "none" | "solid" | "open";
37
45
  label: string | null;
@@ -71,6 +79,12 @@ export interface GraphLayoutInput {
71
79
  to: string;
72
80
  }>;
73
81
  direction: MermaidGraphDoc["direction"];
82
+ /** Cross-axis gap between same-rank siblings, world px. Cluster frames pad
83
+ * their members on both sides (and reserve a caption band on the stacked
84
+ * axis), so a grouped graph widens this budget — `GROUP_CROSS_GAP_H` for
85
+ * TD/BT, `GROUP_CROSS_GAP_V` for LR/RL — or neighbouring frames would
86
+ * touch and overlap. */
87
+ crossGap?: number;
74
88
  }
75
89
  export interface GraphLayoutOutput {
76
90
  positions: Map<string, {
@@ -5,8 +5,13 @@
5
5
  * This is a faithful TS mirror of `ratatui-markdown`'s `mermaid/types.rs`
6
6
  * (the family's pest-driven Rust parser, v0.3.6). The Rust side stays the
7
7
  * semantic reference: when a syntax question arises, ratatui-markdown's
8
- * grammar wins, and the golden fixtures in `__tests__/hkMermaidParse.test.ts`
9
- * exist to keep the two implementations honest.
8
+ * grammar wins, and the golden fixtures in `__golden.test.ts` exist to keep
9
+ * the two implementations honest.
10
+ *
11
+ * Two fields are hikari-line EXTENSIONS over that vendor shape (see
12
+ * `packages/wasm/mermaid/src/mermaid/mod.rs`): `MermaidGroup`/`groups` for
13
+ * `subgraph … end` clusters, and the quote-stripped labels the shipped
14
+ * renderers paint.
10
15
  *
11
16
  * Framework-free on purpose: no Vue imports, safe in pure computation
12
17
  * modules (same rule as components/nodeCanvasTypes.ts).
@@ -28,6 +33,23 @@ export interface MermaidEdge {
28
33
  label: string | null;
29
34
  edgeType: MermaidEdgeType;
30
35
  }
36
+ /**
37
+ * A `subgraph` cluster — the frame drawn around its members. The Rust
38
+ * component omits the field entirely for a plain graph, so pre-cluster
39
+ * documents keep their exact JSON.
40
+ */
41
+ export interface MermaidGroup {
42
+ /** Subgraph id — the head's identifier, or a generated `_sg<N>`. Edges may
43
+ * point at it exactly like a node id. */
44
+ id: string;
45
+ /** Caption painted on the frame. */
46
+ label: string;
47
+ /** Node ids inside the cluster, parse order. A nested cluster's nodes also
48
+ * appear here, so the outer frame encloses the inner one. */
49
+ members: string[];
50
+ /** Enclosing cluster id for a nested subgraph. */
51
+ parent?: string | null;
52
+ }
31
53
  export interface MermaidGraphDoc {
32
54
  kind: "graph";
33
55
  /** `state` diagrams parse into the same shape; the flag only tunes
@@ -36,6 +58,9 @@ export interface MermaidGraphDoc {
36
58
  direction: MermaidDirection;
37
59
  nodes: MermaidNode[];
38
60
  edges: MermaidEdge[];
61
+ /** `subgraph` clusters, outer-first in parse order (absent for a plain
62
+ * graph — the Rust serializer omits an empty list). */
63
+ groups?: MermaidGroup[];
39
64
  }
40
65
  export type SeqArrowKind = "solid" | "dotted" | "solid-open" | "dotted-open";
41
66
  export interface SequenceMessage {
@@ -94,6 +94,15 @@ export declare function boardClampPan(cam: BoardCamera, content: BoardRect, view
94
94
  * boards shrink as far as needed to show everything — fit is allowed
95
95
  * below the interaction minimum (the ladder is for gestures, not for
96
96
  * the initial framing); tiny boards never blow up past the cap.
97
+ *
98
+ * The usable span is floored at zero, so k is never NEGATIVE. A viewport
99
+ * narrower than the padding is degenerate (a board mounted inside a
100
+ * hidden tab / collapsed panel / an unlaid-out flex item measures 0), and
101
+ * an unfloored `(0 - 80) / 1538 = -0.052` makes the whole world render
102
+ * mirrored and shrunken instead of merely unplaced — measured on the docs
103
+ * site, where the mermaid card's canvas collapsed and every diagram
104
+ * vanished. Zero is the honest answer for "no room"; the host re-fits
105
+ * once a real viewport exists (HkBoard's ResizeObserver path).
97
106
  */
98
107
  export declare function boardFit(content: BoardRect, viewport: BoardViewport, opts?: {
99
108
  pad?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.495",
3
+ "version": "0.55.497",
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",
@@ -287,12 +287,30 @@ describe("HkAuthCard SCSS spacing contract", () => {
287
287
  expect(scss).not.toMatch(/\.s-auth-form:has\(\+ \.s-auth-methods\)/);
288
288
  });
289
289
 
290
- it("keeps the form's collapsed bottom padding feeding the footer band", () => {
290
+ it("keeps the form's collapsed bottom padding feeding the footer band (sibling pin)", () => {
291
291
  // The form→footer distance is composed (8px form padding-bottom via
292
292
  // :has + the footer's own margin); losing the collapse would swap in
293
- // the form's default 24px bottom padding instead.
294
- const rule = scss.match(/\.s-auth-form:has\(\.s-auth-footer\)\s*{[^}]*}/)?.[0] ?? "";
295
- expect(rule, ":has collapse rule must exist").toBeTruthy();
293
+ // the form's default 32px bottom padding instead.
294
+ const rule = scss.match(/\.s-auth-form:has\(\+ \.s-auth-footer\)\s*{[^}]*}/)?.[0] ?? "";
295
+ expect(rule, ":has(+ …) sibling collapse rule must exist").toBeTruthy();
296
296
  expect(rule).toContain("padding-bottom: var(--space-8, 0.5rem)");
297
+
298
+ // The DOM half — the card's footer IS a direct sibling of the form, so
299
+ // this is the arm that fires for every card-shaped surface (HkLoginFlow's
300
+ // swapped body needs the DESCENDANT arm; see HkLoginFlow.test.tsx).
301
+ // MUT:authcard-footer-shape-drift (nesting the footer inside the form,
302
+ // or emitting it before it, flips both assertions below).
303
+ const c = mount(
304
+ h(HkAuthCard, { title: "T" }, {
305
+ default: () => h("input", { class: "probe-field" }),
306
+ footer: () => h("div", { class: "probe-footer" }, "row"),
307
+ }),
308
+ );
309
+ const form = c.querySelector(".s-auth-form");
310
+ const footer = c.querySelector(".s-auth-footer");
311
+ expect(form).not.toBeNull();
312
+ expect(footer).not.toBeNull();
313
+ expect(footer!.previousElementSibling).toBe(form);
314
+ expect(form!.contains(footer)).toBe(false);
297
315
  });
298
316
  });
@@ -138,3 +138,10 @@
138
138
  .hk-board-minimap > .hk-minimap {
139
139
  position: static;
140
140
  }
141
+
142
+ /* Paint-only nodes (subgraph cluster frames, decoration layers): visible, but
143
+ never the target of a pointer — a pan drag or a node tap must reach what is
144
+ underneath. */
145
+ .hk-board-node--passthrough {
146
+ pointer-events: none;
147
+ }
@@ -43,6 +43,7 @@ import {
43
43
  import { useBoardCamera } from "../composables/useBoardCamera";
44
44
  import HkMinimap, { type MinimapBox } from "./HkMinimap";
45
45
  import {
46
+ BOARD_FIT_PAD,
46
47
  boardBBox,
47
48
  boardStepRung,
48
49
  quantizeBoardK,
@@ -78,12 +79,20 @@ export interface BoardNodeInput {
78
79
  kind?: string;
79
80
  /** Invisible junction node — routes edges, paints nothing. */
80
81
  hidden?: boolean;
82
+ /** Paint-only node: the shell renders but pointer gestures pass straight
83
+ * through to the board. Subgraph cluster frames need this — a frame covers
84
+ * its members' surroundings, and it must not swallow the pan drag. */
85
+ passthrough?: boolean;
81
86
  /** Opt in to pointer dragging (world-coord moves + `node-move` events). */
82
87
  draggable?: boolean;
83
88
  /** Page payload, handed back through the scoped slot. */
84
89
  data?: Record<string, unknown>;
85
90
  }
86
91
 
92
+ /** Below twice the fit padding, `boardFit` has no room left after its own
93
+ * padding: the board is unplaced (k = 0) until its container grows past it. */
94
+ const FIT_FLOOR_PX = BOARD_FIT_PAD * 2;
95
+
87
96
  /** Per-instance sequence for document-unique marker ids (url(#id)
88
97
  * resolves document-wide — two boards must never mint the same id). */
89
98
  let boardInstanceCounter = 0;
@@ -309,10 +318,36 @@ export default defineComponent({
309
318
  cam.zoomByFactor(factor, localPoint(e));
310
319
  }
311
320
 
321
+ /** One-way latch: set by the first call the HOST makes into the camera
322
+ * through `expose` (`fit`, `reset`, `zoomIn`, `zoomOut`, `zoomToPercent`).
323
+ * Any such call — a single zoom included — means the framing is the
324
+ * host's, so the late recovery fit below must not take it back. The
325
+ * board's own chrome (the minimap reset) does not trip it: that is the
326
+ * component's UI, not a host decision. */
327
+ let hostOwnsCamera = false;
328
+
312
329
  function refreshSize(): void {
313
330
  const el = viewportRef.value;
314
331
  if (!el) return;
315
- viewportSize.value = { w: el.clientWidth, h: el.clientHeight };
332
+ const next = { w: el.clientWidth, h: el.clientHeight };
333
+ // "Unplaced" is the fit's own notion of no room: below twice the fit
334
+ // padding there is nothing left to frame into, so a fit on that box
335
+ // yields k = 0 and paints nothing. That covers a 0×0 hidden container
336
+ // AND the collapsed flex item measured on the docs hub (2px, its
337
+ // borders only) — a `w > 0` test would have missed the real case.
338
+ const unplaced = (s: BoardViewport): boolean => s.w <= FIT_FLOOR_PX || s.h <= FIT_FLOOR_PX;
339
+ const wasUnplaced = unplaced(viewportSize.value);
340
+ viewportSize.value = next;
341
+ // A board can mount before its container has a box: a hidden tab, a
342
+ // collapsed panel, a card whose own parent is still unmounted. The
343
+ // mount fit then frames against nothing and the camera stayed there
344
+ // forever — the diagram/chart only appeared after a manual reset.
345
+ // Re-fit on the FIRST size that follows an unplaced one; ordinary
346
+ // resizes keep the reader's camera, and a host that drives the camera
347
+ // itself keeps it too.
348
+ if (wasUnplaced && props.fitOnMount && !hostOwnsCamera) {
349
+ cam.fit();
350
+ }
316
351
  }
317
352
 
318
353
  let resizeObs: ResizeObserver | null = null;
@@ -470,11 +505,26 @@ export default defineComponent({
470
505
  });
471
506
 
472
507
  expose({
473
- fit: () => cam.fit(),
474
- zoomIn: () => cam.zoomIn(),
475
- zoomOut: () => cam.zoomOut(),
476
- zoomToPercent: (p: number, anchor?: BoardPoint) => cam.zoomToPercent(p, anchor),
477
- reset: () => cam.fit(),
508
+ fit: () => {
509
+ hostOwnsCamera = true;
510
+ cam.fit();
511
+ },
512
+ zoomIn: () => {
513
+ hostOwnsCamera = true;
514
+ cam.zoomIn();
515
+ },
516
+ zoomOut: () => {
517
+ hostOwnsCamera = true;
518
+ cam.zoomOut();
519
+ },
520
+ zoomToPercent: (p: number, anchor?: BoardPoint) => {
521
+ hostOwnsCamera = true;
522
+ cam.zoomToPercent(p, anchor);
523
+ },
524
+ reset: () => {
525
+ hostOwnsCamera = true;
526
+ cam.fit();
527
+ },
478
528
  camera,
479
529
  });
480
530
 
@@ -541,7 +591,10 @@ export default defineComponent({
541
591
  key={n.id}
542
592
  class={[
543
593
  "hk-board-node",
544
- { "hk-board-node--draggable": Boolean(n.draggable) },
594
+ {
595
+ "hk-board-node--draggable": Boolean(n.draggable),
596
+ "hk-board-node--passthrough": Boolean(n.passthrough),
597
+ },
545
598
  n.kind ? `hk-board-node--${n.kind}` : undefined,
546
599
  ]}
547
600
  style={{ left: `${n.x}px`, top: `${n.y}px`, width: `${n.w}px`, height: `${n.h}px` }}
@@ -0,0 +1,202 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+ import { createApp, defineComponent, h, nextTick, ref } from "vue";
3
+
4
+ import HkBoard, { type BoardNodeInput } from "./HkBoard";
5
+
6
+ /**
7
+ * A board must come back by itself when its container goes from "no box"
8
+ * to a real one.
9
+ *
10
+ * Measured on the docs site (2026-11-26): the mermaid card's canvas
11
+ * collapsed to 2px inside a flex row, HkBoard mounted against a 0-width
12
+ * viewport, and the camera stayed at that degenerate fit — the diagram was
13
+ * invisible until the reader pressed the minimap's reset. The fix has two
14
+ * halves: `boardFit` no longer returns a NEGATIVE scale, and the
15
+ * ResizeObserver path re-fits on the first real size after a degenerate
16
+ * one. This pins the second half.
17
+ */
18
+ const nodes: BoardNodeInput[] = [
19
+ { id: "a", x: 0, y: 0, w: 120, h: 80, label: "A" },
20
+ { id: "b", x: 400, y: 0, w: 120, h: 80, label: "B" },
21
+ ];
22
+
23
+ const VIEW_W = 800;
24
+ const VIEW_H = 600;
25
+
26
+ /** happy-dom lays nothing out; the box is whatever these getters say. */
27
+ const box = { w: 0, h: 0 };
28
+
29
+ let observers: Array<() => void> = [];
30
+
31
+ class FakeResizeObserver {
32
+ constructor(private readonly cb: () => void) {}
33
+ observe(): void {
34
+ // Browsers deliver one notification as soon as observation starts, not
35
+ // only on a later change; mirror that so a mount-time refresh is
36
+ // exercised the same way it is in Chrome.
37
+ observers.push(this.cb);
38
+ this.cb();
39
+ }
40
+ disconnect(): void {
41
+ observers = observers.filter((cb) => cb !== this.cb);
42
+ }
43
+ unobserve(): void {}
44
+ }
45
+
46
+ /** Fire every live observer once, as a browser would after a layout change. */
47
+ function triggerResize(): void {
48
+ for (const cb of [...observers]) cb();
49
+ }
50
+
51
+ function scaleOf(transform: string): number {
52
+ return Number(/scale\((-?[\d.]+)\)/.exec(transform)?.[1] ?? 0);
53
+ }
54
+
55
+ function mountBoard(props: Record<string, unknown> = {}): { transform: () => string; unmount: () => void } {
56
+ const host = document.createElement("div");
57
+ document.body.appendChild(host);
58
+ const app = createApp(defineComponent({
59
+ setup: () => () => h(HkBoard, { nodes, ...props }),
60
+ }));
61
+ app.mount(host);
62
+ return {
63
+ transform: () => document.body.querySelector<HTMLElement>(".hk-board-world")!.style.transform,
64
+ unmount: () => app.unmount(),
65
+ };
66
+ }
67
+
68
+ describe("HkBoard viewport recovery", () => {
69
+ // happy-dom defines neither of these as own prototype properties worth
70
+ // keeping, but the repo's convention is to snapshot + restore (see
71
+ // HkBoard.scale.test.ts) so a non-isolated runner cannot inherit the stubs.
72
+ let savedWidth: PropertyDescriptor | undefined;
73
+ let savedHeight: PropertyDescriptor | undefined;
74
+
75
+ beforeEach(() => {
76
+ savedWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "clientWidth");
77
+ savedHeight = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "clientHeight");
78
+ (globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = FakeResizeObserver;
79
+ Object.defineProperty(HTMLElement.prototype, "clientWidth", {
80
+ configurable: true,
81
+ get: () => box.w,
82
+ });
83
+ Object.defineProperty(HTMLElement.prototype, "clientHeight", {
84
+ configurable: true,
85
+ get: () => box.h,
86
+ });
87
+ observers = [];
88
+ box.w = 0;
89
+ box.h = 0;
90
+ });
91
+
92
+ afterEach(() => {
93
+ document.body.innerHTML = "";
94
+ observers = [];
95
+ if (savedWidth) Object.defineProperty(HTMLElement.prototype, "clientWidth", savedWidth);
96
+ else delete (HTMLElement.prototype as unknown as Record<string, unknown>).clientWidth;
97
+ if (savedHeight) Object.defineProperty(HTMLElement.prototype, "clientHeight", savedHeight);
98
+ else delete (HTMLElement.prototype as unknown as Record<string, unknown>).clientHeight;
99
+ delete (globalThis as unknown as Record<string, unknown>).ResizeObserver;
100
+ });
101
+
102
+ it("re-fits once the container grows from a degenerate box to a real one", async () => {
103
+ // The measured docs-hub shape: a 2px-wide canvas (its border only) with a
104
+ // real height, i.e. narrower than the fit padding.
105
+ box.w = 2;
106
+ box.h = 304;
107
+ const { transform, unmount } = mountBoard();
108
+ await nextTick();
109
+ await new Promise((r) => setTimeout(r, 30));
110
+ // No negative (mirrored) framing is allowed to survive the mount.
111
+ expect(scaleOf(transform())).toBeGreaterThanOrEqual(0);
112
+
113
+ box.w = VIEW_W;
114
+ box.h = VIEW_H;
115
+ triggerResize();
116
+ await nextTick();
117
+ await new Promise((r) => setTimeout(r, 260)); // fit tween is ~170ms
118
+
119
+ const k = scaleOf(transform());
120
+ // (800 - 80) / (620 content width incl. the 20px bbox margin) ≈ 1.16,
121
+ // capped at 1.25 — the point is that a real, positive fit happened
122
+ // without the reader pressing reset.
123
+ expect(k).toBeGreaterThan(0.5);
124
+ expect(k).toBeLessThanOrEqual(1.25 + 1e-6);
125
+ unmount();
126
+ });
127
+
128
+ it("does not overrule a host that drives its own camera", async () => {
129
+ box.w = VIEW_W;
130
+ box.h = VIEW_H;
131
+ const host = document.createElement("div");
132
+ document.body.appendChild(host);
133
+ const board = ref<{ zoomToPercent: (p: number) => void } | null>(null);
134
+ const app = createApp(defineComponent({
135
+ setup: () => () => h(HkBoard, { nodes, ref: board }),
136
+ }));
137
+ app.mount(host);
138
+ await nextTick();
139
+ await new Promise((r) => setTimeout(r, 260));
140
+
141
+ // The host picks its own framing (a 2× zoom, not the fit).
142
+ board.value?.zoomToPercent(200);
143
+ await nextTick();
144
+ await new Promise((r) => setTimeout(r, 260));
145
+ const hostChoice = scaleOf(document.body.querySelector<HTMLElement>(".hk-board-world")!.style.transform);
146
+ expect(hostChoice).toBeGreaterThan(1.5);
147
+
148
+ // Collapse to the docs-hub shape, then come back: the recovery path
149
+ // must NOT re-frame over the host's own choice.
150
+ box.w = 2;
151
+ box.h = 304;
152
+ triggerResize();
153
+ await nextTick();
154
+ box.w = VIEW_W;
155
+ box.h = VIEW_H;
156
+ triggerResize();
157
+ await nextTick();
158
+ await new Promise((r) => setTimeout(r, 260));
159
+ const after = scaleOf(document.body.querySelector<HTMLElement>(".hk-board-world")!.style.transform);
160
+ expect(after).toBeCloseTo(hostChoice, 6);
161
+ app.unmount();
162
+ });
163
+
164
+ it("leaves the camera alone when the host opted out of the mount fit", async () => {
165
+ // `fitOnMount: false` means "the host frames this board". A late recovery
166
+ // fit would overrule that opt-out even when the host never touched the
167
+ // camera itself, so the degenerate→real transition must not re-fit.
168
+ box.w = 2;
169
+ box.h = 304;
170
+ const { transform, unmount } = mountBoard({ fitOnMount: false });
171
+ await nextTick();
172
+ await new Promise((r) => setTimeout(r, 30));
173
+ const atMount = transform();
174
+
175
+ box.w = VIEW_W;
176
+ box.h = VIEW_H;
177
+ triggerResize();
178
+ await nextTick();
179
+ await new Promise((r) => setTimeout(r, 260));
180
+ expect(transform()).toBe(atMount);
181
+ unmount();
182
+ });
183
+
184
+ it("keeps a real mount fit untouched when the first size is already real", async () => {
185
+ box.w = VIEW_W;
186
+ box.h = VIEW_H;
187
+ const { transform, unmount } = mountBoard();
188
+ await nextTick();
189
+ await new Promise((r) => setTimeout(r, 260));
190
+ const mounted = scaleOf(transform());
191
+ expect(mounted).toBeGreaterThan(0.5);
192
+
193
+ // An ordinary resize (no degenerate predecessor) must not re-frame the
194
+ // camera — the reader owns it after mount.
195
+ box.w = 1000;
196
+ triggerResize();
197
+ await nextTick();
198
+ await new Promise((r) => setTimeout(r, 40));
199
+ expect(scaleOf(transform())).toBeCloseTo(mounted, 6);
200
+ unmount();
201
+ });
202
+ });
@@ -93,6 +93,39 @@ describe("HkCornerText", () => {
93
93
  expect(c.querySelector(".hk-corner-text")).toBeNull();
94
94
  });
95
95
 
96
+ it("treats a slot that PAINTS nothing as empty (the dead-space rule reads children, not the slot)", () => {
97
+ // A declared slot is always truthy, so `!slotContent` kept an
98
+ // invisible `.hk-corner-text` box (and the corner's flex margins with
99
+ // it) for every one of these shapes. The rule now walks the rendered
100
+ // nodes; each arm below is a shape a host writes by accident.
101
+ // MUT:corner-dead-space-slot-truthiness (restoring `!slotContent`
102
+ // renders the box for all of these and this goes red).
103
+ const emptyShapes: Array<[string, () => unknown]> = [
104
+ ["empty array", () => []],
105
+ ["nulls only", () => [null, null]],
106
+ ["false", () => false],
107
+ ["empty string", () => ""],
108
+ ["whitespace only", () => " "],
109
+ ["nested null array", () => [null]],
110
+ ];
111
+ for (const [label, slot] of emptyShapes) {
112
+ const c = mount(h(HkCornerText, { items: [] }, { default: slot as never }));
113
+ expect(c.querySelector(".hk-corner-text"), `slot shape "${label}" must not paint a lane`).toBeNull();
114
+ }
115
+ });
116
+
117
+ it("keeps the lane for slot children that DO paint (zero and text are content)", () => {
118
+ // The counterpart arm: the new check must not swallow real content.
119
+ // MUT:corner-dead-space-overreach (treating numbers as empty or
120
+ // dropping text nodes hides these lanes).
121
+ const zero = mount(h(HkCornerText, { items: [] }, { default: () => 0 }));
122
+ expect(zero.querySelector(".hk-corner-text")?.textContent).toBe("0");
123
+ const text = mount(h(HkCornerText, { items: [] }, { default: () => "苏ICP备" }));
124
+ expect(text.querySelector(".hk-corner-text")?.textContent).toBe("苏ICP备");
125
+ const nested = mount(h(HkCornerText, { items: [] }, { default: () => [[h("i", { class: "deep" }, "x")]] }));
126
+ expect(nested.querySelector(".hk-corner-text .deep")).not.toBeNull();
127
+ });
128
+
96
129
  it("as=nav marks a link lane as a labeled landmark; div stays unlabeled", () => {
97
130
  const c = mount(h(HkCornerText, { items, as: "nav", ariaLabel: "备案" }));
98
131
  const nav = c.querySelector("nav.hk-corner-text")!;
@@ -1,7 +1,50 @@
1
- import { defineComponent, type PropType } from "vue";
1
+ import { Comment, Fragment, Text, defineComponent, type PropType } from "vue";
2
2
 
3
3
  import "./HkCornerText.scss";
4
4
 
5
+ /**
6
+ * Does a slot's returned tree paint NOTHING at all? The lane's dead-space
7
+ * rule must read the RENDERED nodes, not the slot's existence: Vue hands
8
+ * back a truthy value for every slot shape a host can write, so the
9
+ * original `!slotContent` test kept an invisible `.hk-corner-text` box
10
+ * (with the corner's flex margins) for a slot that renders `[]`, `[null]`,
11
+ * `false`, `""` or a whitespace-only string.
12
+ *
13
+ * The walk mirrors what Vue's own normalizer accepts:
14
+ * - `null` / `undefined` / booleans paint nothing (they normalize to a
15
+ * comment placeholder);
16
+ * - strings only paint when they carry a non-whitespace character — a
17
+ * blank string still mounts a text node, which occupies a flex row in
18
+ * the lane;
19
+ * - numbers always paint (`0` is real content);
20
+ * - a `Text` vnode paints when its children carry such a string;
21
+ * - `Fragment` vnodes (what a slot returning an array is wrapped in) and
22
+ * plain arrays recurse — they paint only what their children paint;
23
+ * - `Comment` vnodes never paint;
24
+ * - every other vnode (element, component, Teleport, Suspense) paints by
25
+ * definition.
26
+ *
27
+ * A function is NOT invoked here: Vue resolves slot functions, and calling
28
+ * a host's by hand could run it twice per render.
29
+ */
30
+ export function slotPaintsNothing(value: unknown): boolean {
31
+ if (value === null || value === undefined || typeof value === "boolean") return true;
32
+ if (typeof value === "string") return value.trim().length === 0;
33
+ if (typeof value === "number") return false;
34
+ if (Array.isArray(value)) return value.every(slotPaintsNothing);
35
+ if (typeof value === "object") {
36
+ const vnode = value as { type?: unknown; children?: unknown };
37
+ if (vnode.type === Comment) return true;
38
+ if (vnode.type === Text) return slotPaintsNothing(vnode.children);
39
+ if (vnode.type === Fragment || Array.isArray(vnode.children)) {
40
+ return slotPaintsNothing(vnode.children);
41
+ }
42
+ return false;
43
+ }
44
+ // Symbol / bigint / function — nothing renders as a structural node.
45
+ return true;
46
+ }
47
+
5
48
  /** One entry of a corner text lane: plain text, or a link when `href`
6
49
  * is set (registry links open in a new tab with `noopener`, the same
7
50
  * contract as the beian filings). */
@@ -102,7 +145,7 @@ export const HkCornerText = defineComponent({
102
145
  ),
103
146
  );
104
147
  const slotContent = slots.default?.();
105
- const empty = entries.length === 0 && !slotContent;
148
+ const empty = entries.length === 0 && slotPaintsNothing(slotContent);
106
149
  if (empty) return null;
107
150
  const Tag = props.as;
108
151
  return (