@celestia-island/hikari 0.55.496 → 0.55.498

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.
Files changed (32) hide show
  1. package/dist/types/components/HkBoard.d.ts +4 -0
  2. package/dist/types/errorReporting/index.d.ts +11 -0
  3. package/dist/types/errorReporting/serverLanding.d.ts +103 -0
  4. package/dist/types/errorReporting/state.d.ts +10 -2
  5. package/dist/types/index.d.ts +1 -0
  6. package/dist/types/mermaid/layout.d.ts +15 -1
  7. package/dist/types/mermaid/types.d.ts +27 -2
  8. package/dist/types/utils/boardCamera.d.ts +9 -0
  9. package/package.json +1 -1
  10. package/src/components/HkBoard.scss +7 -0
  11. package/src/components/HkBoard.tsx +60 -7
  12. package/src/components/HkBoard.viewportRecovery.test.tsx +202 -0
  13. package/src/components/HkMermaidDiagram.scss +29 -0
  14. package/src/components/HkMermaidDiagram.styles.test.ts +52 -0
  15. package/src/components/HkMermaidDiagram.subgraph.test.tsx +153 -0
  16. package/src/components/HkMermaidDiagram.tsx +11 -0
  17. package/src/components/HkModal.test.tsx +15 -2
  18. package/src/components/__tests__/hkMermaidLayout.test.ts +175 -0
  19. package/src/errorReporting/HkErrorReportingOverlay.tsx +39 -3
  20. package/src/errorReporting/index.test.tsx +222 -0
  21. package/src/errorReporting/index.ts +27 -0
  22. package/src/errorReporting/serverLanding.test.ts +192 -0
  23. package/src/errorReporting/serverLanding.ts +187 -0
  24. package/src/errorReporting/state.ts +24 -2
  25. package/src/index.ts +10 -0
  26. package/src/mermaid/__golden.test.ts +4 -0
  27. package/src/mermaid/__snapshots__/__golden.test.ts.snap +43 -0
  28. package/src/mermaid/layout.ts +163 -7
  29. package/src/mermaid/types.ts +28 -2
  30. package/src/utils/boardCamera.test.ts +21 -0
  31. package/src/utils/boardCamera.ts +13 -2
  32. package/src/wasm/mermaid/hikari_wasm_mermaid.js +1 -1
@@ -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. */
@@ -2,6 +2,7 @@ import { type Plugin } from "vue";
2
2
  import { type HkErrorReportingOptions, type HkErrorSource } from "./state";
3
3
  export type { HkErrorReportingOptions, HkErrorSource, HkReportedError, } from "./state";
4
4
  export { HkErrorReportingOverlay } from "./HkErrorReportingOverlay";
5
+ export { HkServerErrorLandingError, parseServerErrorLanding, readServerErrorLanding, reportServerErrorLanding, serializeServerErrorLanding, SERVER_ERROR_LANDING_ID, SERVER_ERROR_LANDING_VERSION, type HkServerErrorLanding, } from "./serverLanding";
5
6
  /**
6
7
  * createErrorReporting — the install-and-forget global error reporting hook.
7
8
  *
@@ -26,6 +27,16 @@ export { HkErrorReportingOverlay } from "./HkErrorReportingOverlay";
26
27
  * Any pre-existing `app.config.errorHandler` is chained, not discarded.
27
28
  * All capture channels are optional; `shouldReport` filters, `onError` is
28
29
  * the telemetry hook.
30
+ *
31
+ * INSTALL ALSO SETTLES THE SERVER'S VERDICT ON THIS DOCUMENT: when the
32
+ * server answered the navigation with an error it hands it over through the
33
+ * `hk-server-error` JSON island in index.html (see `./serverLanding`), and
34
+ * install raises the landing for it right away — source `server`, the HTTP
35
+ * status and the raw response on the card. So `app.use(createErrorReporting())`
36
+ * is the one line that covers BOTH halves of "no bare error ever reaches a
37
+ * visitor": what crashes after boot, and what the server said before it.
38
+ * The island is read once and consumed; a host that wants to decide itself
39
+ * reads it with `readServerErrorLanding()` BEFORE installing.
29
40
  */
30
41
  export declare function createErrorReporting(options?: HkErrorReportingOptions): Plugin;
31
42
  /**
@@ -0,0 +1,103 @@
1
+ import { type HkReportedError } from "./state";
2
+ /**
3
+ * Server error landing handoff — the contract between a family SERVER and
4
+ * the SPA it serves, for the errors a browser reaches by NAVIGATION.
5
+ *
6
+ * `createErrorReporting` catches what happens after the app is running. It
7
+ * cannot catch the failure that never lets the app start: a server that
8
+ * answers a top-level navigation with a bare `{"error": …}` body (an OAuth
9
+ * callback whose token exchange failed, a revoked share link, a 502 from a
10
+ * restart window) shows the visitor raw JSON in the tab — no landing, no
11
+ * way back, nothing to copy but what the viewport holds (the 2026-11-26
12
+ * res.celestia.world report).
13
+ *
14
+ * The handoff closes that gap with the page itself as the carrier. The
15
+ * server answers with the SPA's own `index.html` at the REAL status code,
16
+ * with one JSON data island injected:
17
+ *
18
+ * ```html
19
+ * <script type="application/json" id="hk-server-error">
20
+ * {"v":1,"status":502,"code":"identity_provider_unreachable",
21
+ * "message":"identity provider unreachable: …","raw":{"error":"…"}}
22
+ * </script>
23
+ * ```
24
+ *
25
+ * `createErrorReporting().install` reads the island (once — the element is
26
+ * consumed) and raises the same takeover a runtime error gets, with the
27
+ * HTTP status and the server's raw payload on the card. A data block is
28
+ * never executed, so it passes a `script-src 'self'` policy untouched, and
29
+ * {@link serializeServerErrorLanding} escapes the few characters that could
30
+ * let the payload close the island or read as markup.
31
+ *
32
+ * The island is the WHOLE contract: nothing here knows a URL scheme, a
33
+ * header name or a service, so any server facing a browser can produce it
34
+ * (the Rust side lives in plana's `plana-error-landing`).
35
+ */
36
+ /** Element id of the JSON island a server injects into its index.html. */
37
+ export declare const SERVER_ERROR_LANDING_ID = "hk-server-error";
38
+ /** The only island shape this build understands (`v` in the payload). */
39
+ export declare const SERVER_ERROR_LANDING_VERSION = 1;
40
+ /** A validated server handoff: what the card shows, plus the raw body. */
41
+ export interface HkServerErrorLanding {
42
+ /** The HTTP status the server ANSWERED with — shown as the `HTTP <n>` chip. */
43
+ readonly status: number;
44
+ /** Wire error code shown as the code chip (`unknown_provider`). Empty
45
+ * falls back to `http_<status>`. */
46
+ readonly code: string;
47
+ /** The server's human-readable explanation — the card's description. */
48
+ readonly message: string;
49
+ /** The response body the server would have sent as JSON (an object, an
50
+ * array, a string …). Rendered in the raw-details pane; absent when the
51
+ * server had nothing to hand over. */
52
+ readonly raw?: unknown;
53
+ }
54
+ /**
55
+ * The error object a server handoff is reported through — the counterpart
56
+ * of the runtime errors the window hooks catch. `name` is the code chip, so
57
+ * it reads as the wire code when the server sent one and as `http_<status>`
58
+ * when it did not; `status` and `details` ride the report onto the card.
59
+ * `reportError` copies both off ANY object reported with the `server`
60
+ * source (duck-typed), so a host's own subclass can carry them without
61
+ * importing this one; a runtime error is never inspected for them.
62
+ */
63
+ export declare class HkServerErrorLandingError extends Error {
64
+ readonly status: number;
65
+ readonly code: string;
66
+ readonly raw: unknown;
67
+ readonly landing: HkServerErrorLanding;
68
+ constructor(landing: HkServerErrorLanding);
69
+ /** The wire field under the name the report carries (`reportError` reads
70
+ * `details`, whatever class the error is). Same value as `raw`. */
71
+ get details(): unknown;
72
+ }
73
+ /**
74
+ * Validate an island's text into a handoff, or `null` for anything this
75
+ * build must not render: a JSON syntax error, a non-object, another
76
+ * `v` (a future shape — ignored rather than half-rendered), a status
77
+ * outside the error classes. Unknown keys are ignored, so a newer server
78
+ * can add fields without breaking an older SPA.
79
+ */
80
+ export declare function parseServerErrorLanding(text: string): HkServerErrorLanding | null;
81
+ /**
82
+ * Serialize a handoff as island text. Besides `v`, the output differs from
83
+ * plain `JSON.stringify` in one way that matters: `<`, `>` and `&` leave as
84
+ * `\u003c`-style escapes, so no payload — however hostile — can close the
85
+ * `<script>` element or be read as markup by a parser that never sees the
86
+ * island as a data block (`JSON.parse` turns the escapes back).
87
+ */
88
+ export declare function serializeServerErrorLanding(landing: HkServerErrorLanding): string;
89
+ /**
90
+ * Read the handoff out of the document — once. The island is REMOVED on the
91
+ * first read, valid or not: a reinstall (HMR, a second app instance on the
92
+ * same document) must not re-raise a landing the visitor already saw or
93
+ * dismissed, and a malformed island must not be retried on every install.
94
+ * `null` when the document carries no island or the island is unusable.
95
+ */
96
+ export declare function readServerErrorLanding(root?: ParentNode): HkServerErrorLanding | null;
97
+ /**
98
+ * Raise the global error landing for a server handoff — the navigation-time
99
+ * counterpart of `reportGlobalError`. Goes through the same acceptance
100
+ * (`shouldReport`, first-error-wins, `onError`) as every other source, so
101
+ * a host filters or logs it exactly like a runtime error.
102
+ */
103
+ export declare function reportServerErrorLanding(landing: HkServerErrorLanding): HkReportedError | null;
@@ -1,6 +1,7 @@
1
1
  import { type Ref, type VNodeChild } from "vue";
2
- /** Where a reported error came from. */
3
- export type HkErrorSource = "vue" | "window" | "rejection" | "manual";
2
+ /** Where a reported error came from. `server` = a handoff the server
3
+ * injected into this document (see `./serverLanding`), not a runtime error. */
4
+ export type HkErrorSource = "vue" | "window" | "rejection" | "manual" | "server";
4
5
  /** A normalized error record carried by the global error landing. */
5
6
  export interface HkReportedError {
6
7
  source: HkErrorSource;
@@ -10,6 +11,13 @@ export interface HkReportedError {
10
11
  stack: string;
11
12
  /** Vue's `info` string for errors surfaced through `app.config.errorHandler`. */
12
13
  info?: string;
14
+ /** The HTTP status a SERVER handoff answered with — the `HTTP <n>` chip.
15
+ * Absent for runtime errors (nothing to show). */
16
+ status?: number;
17
+ /** A structured payload the reporter attached to the error, shown in the
18
+ * raw-details pane in place of the stack record: a server handoff's raw
19
+ * response body. Absent for runtime errors. */
20
+ details?: unknown;
13
21
  }
14
22
  export interface HkErrorReportingOptions {
15
23
  /** Headline override; defaults to `hikari::errors.defaultTitle`.
@@ -143,6 +143,7 @@ export { default as HErrorBoundary } from "./components/HkErrorBoundary";
143
143
  export { HkErrorLanding as HErrorLanding, type HErrorTone, type HErrorLandingVariant, } from "./components/HkErrorLanding";
144
144
  export { HkErrorReportingOverlay as HErrorReportingOverlay } from "./errorReporting";
145
145
  export { createErrorReporting, reportGlobalError, clearGlobalError, type HkErrorReportingOptions, type HkErrorSource, type HkReportedError, } from "./errorReporting";
146
+ export { HkServerErrorLandingError as HServerErrorLandingError, parseServerErrorLanding, readServerErrorLanding, reportServerErrorLanding, serializeServerErrorLanding, SERVER_ERROR_LANDING_ID, SERVER_ERROR_LANDING_VERSION, type HkServerErrorLanding as HServerErrorLanding, } from "./errorReporting";
146
147
  export { default as HDraggableList } from "./components/HkDraggableList";
147
148
  export { default as HDraggableGrid } from "./components/HkDraggableGrid";
148
149
  export { default as HSelectionGrid } from "./components/HkSelectionGrid";
@@ -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.496",
3
+ "version": "0.55.498",
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",
@@ -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
+ });
@@ -31,6 +31,35 @@
31
31
  }
32
32
  }
33
33
 
34
+ // ── Subgraph cluster frame ───────────────────────────────────────────
35
+ // Paint-only shell behind a subgraph's members: dashed outline + wash fill,
36
+ // caption pinned to the top-left inside the reserved header band. The fill
37
+ // stays translucent because the board paints edges UNDER nodes — an opaque
38
+ // frame would black out every edge inside the cluster.
39
+ .hk-mmd-group {
40
+ position: relative;
41
+ width: 100%;
42
+ height: 100%;
43
+ box-sizing: border-box;
44
+ border: 1px dashed rgb(var(--color-primary) / 45%);
45
+ border-radius: var(--radius-md, 8px);
46
+ background: rgb(var(--color-primary) / 4%);
47
+ pointer-events: none;
48
+
49
+ &__label {
50
+ position: absolute;
51
+ top: 5px;
52
+ inset-inline-start: 10px;
53
+ max-width: calc(100% - 20px);
54
+ overflow: hidden;
55
+ text-overflow: ellipsis;
56
+ white-space: nowrap;
57
+ font-size: 12px;
58
+ font-weight: 600;
59
+ color: rgb(var(--color-text) / 78%);
60
+ }
61
+ }
62
+
34
63
  // ── Graph node shells (shape kinds) ──────────────────────────────────
35
64
 
36
65
  .hk-mmd-node {