@celestia-island/hikari 0.55.97 → 0.55.99

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.
@@ -0,0 +1,80 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ /**
7
+ * Source contract: the error landing's raw-details pane is a STANDING
8
+ * frame — the larger of 9rem and ~20vh, fixed. The frame must never
9
+ * breathe with its content: the 2026-10-01 content-hugging experiment
10
+ * (max-height cap + inheriting body) shipped and was reverted the same
11
+ * day after mobile review — folding the tree shrank the whole error card
12
+ * and the jumping height read as broken. These pins keep BOTH regression
13
+ * classes out: the breathing class (max-height instead of height on the
14
+ * pane, an inheriting/max-capped body) and the late-re-declaration class
15
+ * (a later same-file override re-pinning either box).
16
+ */
17
+ const here = dirname(fileURLToPath(import.meta.url));
18
+ const scss = readFileSync(join(here, "HkErrorLanding.scss"), "utf-8");
19
+
20
+ describe("HkErrorLanding standing frame contract", () => {
21
+ const paneAt = scss.indexOf(".hk-error-landing__details-pane {");
22
+ const bodyAt = scss.indexOf(".hk-error-landing__details-body {");
23
+
24
+ it("declares the pane and body exactly once — no late re-declaration", () => {
25
+ // Whole-file site count: the slice-scoped sweeps below read only up
26
+ // to the nested tree rule, so a LATER `.hk-error-landing__details-
27
+ // body { height: ... }` in this file would cascade over the frame
28
+ // while every slice pin stays green (the R3-M4 mutation class).
29
+ // Pristine file has exactly two sites (pane + body); the descendant
30
+ // `.s-tool-json-tree` rule and the label/toggle selectors don't match.
31
+ // Keep this pin at strict equality — softening it to >= silently
32
+ // reopens the late-re-declaration class.
33
+ const sites = scss.match(/\.hk-error-landing__details-(?:pane|body)\s*[,{]/g) ?? [];
34
+ expect(sites.length, `details pane/body selector sites = ${sites.join(" | ")}`).toBe(2);
35
+ });
36
+
37
+ it("fixes the pane at the standing frame, never a content-driven cap", () => {
38
+ expect(paneAt, "pane rule present").toBeGreaterThanOrEqual(0);
39
+ const pane = scss.slice(paneAt, bodyAt);
40
+ // Both viewport lines: the vh fallback pairs with the dvh override,
41
+ // matching the family pattern.
42
+ expect(pane).toContain("height: max(9rem, 20vh)");
43
+ expect(pane).toContain("height: max(9rem, 20dvh)");
44
+ // Every height declaration must BE the frame pair — a later `height:
45
+ // auto` (or an extra one) would let the frame breathe again.
46
+ const heights = [...pane.matchAll(/^\s*height:.*$/gm)].map((m) => m[0].trim());
47
+ expect(heights.length, `pane height declarations = ${JSON.stringify(heights)}`).toBe(2);
48
+ for (const value of heights) expect(value).toMatch(/^height: max\(9rem, 20d?vh\);$/);
49
+ // A content-driven cap is EXACTLY the reverted breathing frame.
50
+ expect(pane).not.toContain("max-height:");
51
+ expect(pane).not.toContain("min-height:");
52
+ });
53
+
54
+ it("fills the fixed frame instead of hugging the payload", () => {
55
+ expect(bodyAt, "body rule present").toBeGreaterThanOrEqual(0);
56
+ const nextAt = scss.indexOf(".hk-error-landing__details-body .s-tool-json-tree");
57
+ // The slice boundary is load-bearing: the sweeps below must never
58
+ // silently extend to EOF (where unrelated rules would trip them).
59
+ expect(nextAt, "tree-neutering rule present").toBeGreaterThanOrEqual(0);
60
+ const body = scss.slice(bodyAt, nextAt);
61
+ // The body fills the fixed frame — its ONLY height declaration is
62
+ // the 100% fill; any other height (auto/inherit/max cap) is the
63
+ // reverted content-hugging regression (the R2-M-D mutation class).
64
+ const bodyHeights = [...body.matchAll(/^\s*height:.*$/gm)].map((m) => m[0].trim());
65
+ expect(bodyHeights, `body height declarations = ${JSON.stringify(bodyHeights)}`).toEqual(["height: 100%;"]);
66
+ expect(body).not.toContain("max-height:");
67
+ expect(body).not.toContain("min-height:");
68
+ // Long content still scrolls inside the frame.
69
+ expect(body).toContain("overflow: auto");
70
+ });
71
+
72
+ it("keeps the mobile dvh override after its vh fallback", () => {
73
+ // The pair is order-sensitive by convention (the later dvh line wins
74
+ // where dvh is supported); nothing may reorder or deduplicate it.
75
+ const vhAt = scss.indexOf("height: max(9rem, 20vh)");
76
+ const dvhAt = scss.indexOf("height: max(9rem, 20dvh)");
77
+ expect(vhAt, "vh fallback present").toBeGreaterThanOrEqual(0);
78
+ expect(dvhAt, "dvh override present").toBeGreaterThan(vhAt);
79
+ });
80
+ });
@@ -95,7 +95,8 @@ describe("HkErrorLanding", () => {
95
95
  const el = mountLanding({
96
96
  details: () => h("pre", { class: "s-tool-json-tree" }, "raw"),
97
97
  });
98
- // No collapse affordance anymore — the pane is a fixed region.
98
+ // No collapse affordance — the pane is a standing frame; folding
99
+ // changes only its content (standing-frame contract in scss).
99
100
  expect(el.querySelector(".hk-error-landing__details-toggle")).toBeNull();
100
101
  expect(el.querySelector(".hk-error-landing__details-label")!.textContent).toContain("Raw error details");
101
102
  expect(el.querySelector(".hk-error-landing__details-pane")).not.toBeNull();
@@ -44,12 +44,14 @@ function normalizeSlotNodes(nodes: VNode | VNode[] | undefined): VNode[] {
44
44
  * carrying a tone icon, a (pre-translated) title and description, the wire
45
45
  * error code / HTTP status as HkBadge chips above the headline, an
46
46
  * always-open raw-details pane (the default slot — hosts render HkJsonTree
47
- * there) with a FIXED ~20vh footprint carried by the family overlay
48
- * scrollbar, and an actions slot.
47
+ * there) with a STABLE standing frame — the larger of 9rem and ~20vh,
48
+ * carried by the family overlay scrollbar — and an actions slot.
49
49
  *
50
- * The details pane deliberately never collapses and never grows past its
51
- * frame: folding every JSON node still leaves the pane standing, and a
52
- * long stack trace scrolls inside it instead of stretching the card.
50
+ * The pane never breathes with its content: folding every JSON node only
51
+ * changes what renders INSIDE the standing frame, and a long stack trace
52
+ * scrolls inside it instead of stretching the card. (The 2026-10-01
53
+ * content-hugging frame was reverted the same day: on mobile the whole
54
+ * error card visibly jumped between fold states, which read as broken.)
53
55
  *
54
56
  * The component is presentation-only and route-agnostic: it never touches
55
57
  * the router and can be mounted by an SPA overlay, a modal, or a standalone
@@ -66,6 +66,34 @@ describe("HkJsonTree spacing contract", () => {
66
66
  expect(indent).toContain("flex-shrink: 0");
67
67
  });
68
68
 
69
+ it("clips collapsed summaries to one line instead of wrapping", () => {
70
+ const tsx = readFileSync(join(here, "HkJsonTree.tsx"), "utf-8");
71
+ const clampAt = scss.indexOf(".s-jt-preview,\n.s-jt-clamp {");
72
+ expect(clampAt, ".s-jt-clamp rule present").toBeGreaterThanOrEqual(0);
73
+ const clamp = scss.slice(clampAt);
74
+ // The container preview shares the clip block: dropping it from the
75
+ // selector group re-wraps the keyless root summary (the third-round
76
+ // screenshot complaint) while every other pin stays green.
77
+ expect(clamp).toContain("min-width: 0");
78
+ expect(clamp).toContain("overflow: hidden");
79
+ expect(clamp).toContain("white-space: nowrap");
80
+ expect(clamp).toContain("text-overflow: ellipsis");
81
+ // Exactly three selector sites: the color/size block plus the two
82
+ // entries of the clip group. A FOURTH (a later re-declaration in this
83
+ // file) would cascade over the clip — R2's B1 mutation proved a bare
84
+ // toContain pin lets `.s-jt-preview { white-space: normal; }` sail
85
+ // through green while re-wrapping the summary. Cross-file overrides
86
+ // are out of this file's reach by construction — the residual is
87
+ // covered by greps in review, not by a pin.
88
+ const selectorSites = scss.match(/\.s-jt-(?:preview|clamp)\s*[,{]/g) ?? [];
89
+ expect(selectorSites.length, `selector sites = ${selectorSites.join(" | ")}`).toBe(3);
90
+ // The clip hook rides exactly the collapsed long-string value (the
91
+ // container preview is covered by the selector group above); expanded
92
+ // leaf values keep their soft wrap.
93
+ expect(tsx.match(/class="[^"]*s-jt-clamp/g)?.length).toBe(1);
94
+ expect(tsx).toContain('class="s-jv-str s-jt-clamp"');
95
+ });
96
+
69
97
  it("keeps the key colon gap on one spacing unit", () => {
70
98
  const block = scss.slice(scss.indexOf(".s-jt-colon {"), scss.indexOf(".s-jv-null"));
71
99
  expect(block).toContain("margin-inline-end: var(--space-4");
@@ -197,3 +197,21 @@
197
197
  font-weight: 400;
198
198
  opacity: 0.7;
199
199
  }
200
+
201
+ /* Collapsed summaries live on ONE line: anything past the row's right
202
+ edge clips to an ellipsis instead of wrapping (a wrapped summary reads
203
+ as broken content, and the row is one click away from the full view —
204
+ expand, don't paginate). The box clip needs overflow != visible, which
205
+ per flexbox also zeroes the item's automatic minimum size, so the span
206
+ actually shrinks to the row instead of pushing it wide; min-width: 0
207
+ spells that out so the clip never depends on that spec side effect.
208
+ Applied to the container preview here and to the collapsed long-string
209
+ value via the .s-jt-clamp hook in the tsx — expanded leaf rows keep
210
+ their soft wrap. */
211
+ .s-jt-preview,
212
+ .s-jt-clamp {
213
+ min-width: 0;
214
+ overflow: hidden;
215
+ white-space: nowrap;
216
+ text-overflow: ellipsis;
217
+ }
@@ -88,6 +88,25 @@ describe("HkJsonTree component", () => {
88
88
  expect(el.querySelector(".s-jv-num")!.textContent).toBe("2");
89
89
  });
90
90
 
91
+ it("marks both collapsed summary shapes with the one-line clip hook", async () => {
92
+ // Container summary: the preview span is the stylesheet's clip target.
93
+ const folded = mountTree({ text: JSON.stringify({ a: 1, b: 2 }) });
94
+ (folded.querySelector('.s-jt-row[data-parent]')! as HTMLElement).click();
95
+ await nextTick();
96
+ expect(folded.querySelector(".s-jt-preview")).not.toBeNull();
97
+ // Long string summary: the collapsed value span carries the hook and
98
+ // keeps its string coloring (the clip must not mute it).
99
+ const long = Array.from({ length: 15 }, (_, i) => `line-${i}`).join("\n");
100
+ const el = mountTree({ text: JSON.stringify({ log: long }) });
101
+ const longRow = el.querySelectorAll(".s-jt-row[data-parent]")[1]!;
102
+ (longRow as HTMLElement).click();
103
+ await nextTick();
104
+ const clamp = el.querySelector(".s-jt-clamp");
105
+ expect(clamp).not.toBeNull();
106
+ expect(clamp!.classList.contains("s-jv-str")).toBe(true);
107
+ expect(clamp!.textContent).toContain("line-0");
108
+ });
109
+
91
110
  it("collapses and re-expands long strings via row clicks", async () => {
92
111
  const long = Array.from({ length: 15 }, (_, i) => `line-${i}`).join("\n");
93
112
  const el = mountTree({ text: JSON.stringify({ log: long }) });
@@ -148,6 +148,11 @@ function initialExpandedSet(root: HJsonNode): Set<number> {
148
148
  * align with the same left rhythm; `key:` gaps are one unit, type hints
149
149
  * two; the depth step is one toggle width (JT_INDENT = JT_TOGGLE,
150
150
  * pinned alongside the stylesheet contract).
151
+ *
152
+ * Collapse contract (same pin): a collapsed summary is ONE line — the
153
+ * container preview and the collapsed long-string value carry the
154
+ * one-line clip (`.s-jt-clamp` / `.s-jt-preview`) and ellipsize past the
155
+ * row edge instead of wrapping; expanding is the pager.
151
156
  */
152
157
  export const HkJsonTree = defineComponent({
153
158
  name: "HkJsonTree",
@@ -269,7 +274,7 @@ export const HkJsonTree = defineComponent({
269
274
  {node.key !== null && <span class="s-jt-key">{node.key}</span>}
270
275
  {node.key !== null && <span class="s-jt-colon">: </span>}
271
276
  <span class="s-jt-indent" />
272
- <span class="s-jv-str">"{truncateStr(node.stringValue, STR_PREVIEW_LEN)}"</span>
277
+ <span class="s-jv-str s-jt-clamp">"{truncateStr(node.stringValue, STR_PREVIEW_LEN)}"</span>
273
278
  <span class="s-jt-type">string ({node.stringValue.length})</span>
274
279
  </div>
275
280
  );
@@ -0,0 +1,13 @@
1
+ // HkMinimap3D — stereoscopic minimap. The card chrome (`.hk-minimap`),
2
+ // zoom bar and slider pop are shared verbatim with the 2D minimap (this
3
+ // component imports HkMinimap.scss; the module graph dedupes it) — only
4
+ // the 3D canvas itself is styled here.
5
+
6
+ .hk-minimap3d-canvas {
7
+ display: block;
8
+ width: 100%;
9
+ height: auto;
10
+ // Deep-space tint behind the additive markers; the card's blur and
11
+ // border come from the shared .hk-minimap shell.
12
+ background: rgb(var(--color-background) / 0.55);
13
+ }
@@ -0,0 +1,361 @@
1
+ /* HkMinimap3D behaviour: the fake WebGL surface captures which camera the
2
+ * map renders with; three's real scene/camera math sits underneath, so a
3
+ * drag must MOVE the map eye around the main camera and the zoom bar must
4
+ * scale the fit radius. */
5
+
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
+ import { createApp, defineComponent, h, nextTick } from "vue";
8
+ import * as THREE from "three";
9
+
10
+ const H = vi.hoisted(() => {
11
+ class FakeWebGLRenderer {
12
+ static instances: FakeWebGLRenderer[] = [];
13
+ renders: Array<{ scene: unknown; camera: THREE.PerspectiveCamera }> = [];
14
+ disposed = false;
15
+ constructor(_opts: { canvas: HTMLCanvasElement }) {
16
+ FakeWebGLRenderer.instances.push(this);
17
+ }
18
+ setPixelRatio(): void {}
19
+ setSize(): void {}
20
+ setClearColor(): void {}
21
+ render(scene: unknown, camera: THREE.PerspectiveCamera): void {
22
+ // A real renderer maintains world matrices every pass.
23
+ (scene as THREE.Scene).updateMatrixWorld(true);
24
+ camera.updateMatrixWorld();
25
+ this.renders.push({ scene, camera });
26
+ }
27
+ dispose(): void { this.disposed = true; }
28
+ }
29
+ return { FakeWebGLRenderer };
30
+ });
31
+
32
+ vi.mock("three", async (importOriginal) => {
33
+ const actual = await importOriginal<typeof import("three")>();
34
+ return { ...actual, WebGLRenderer: H.FakeWebGLRenderer };
35
+ });
36
+
37
+ import HkMinimap3D from "./HkMinimap3D";
38
+ import { BOARD3D_HELPERS_LAYER, type Board3DEngine } from "./HkBoard3D";
39
+ import { orbitDelta, sphericalPosition } from "../utils/scene3d";
40
+
41
+ const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
42
+
43
+ interface FakeEngineOpts {
44
+ objects?: Map<string, { object: THREE.Object3D; content?: boolean }>;
45
+ }
46
+
47
+ function fakeEngine(opts: FakeEngineOpts = {}): {
48
+ engine: Board3DEngine;
49
+ scene: THREE.Scene;
50
+ camera: THREE.PerspectiveCamera;
51
+ firePostRender: () => void;
52
+ } {
53
+ const scene = new THREE.Scene();
54
+ const camera = new THREE.PerspectiveCamera(45, 16 / 9, 0.1, 4000);
55
+ camera.position.set(20, 12, 24);
56
+ camera.lookAt(0, 0, 0);
57
+ const target = new THREE.Vector3(0, 0, 0);
58
+ let postRender: (() => void) | null = null;
59
+ const engine = {
60
+ scene,
61
+ camera,
62
+ controls: { target } as unknown as Board3DEngine["controls"],
63
+ renderer: {} as Board3DEngine["renderer"],
64
+ addTick: () => () => {},
65
+ addPostRender: (fn: () => void) => {
66
+ postRender = fn;
67
+ return () => { postRender = null; };
68
+ },
69
+ setObject: () => {},
70
+ objects: () => (opts.objects ?? new Map()) as never,
71
+ flyTo: () => {},
72
+ frameAll: () => {},
73
+ projectToScreen: () => ({ x: 0, y: 0, visible: true }),
74
+ onTheme: () => {},
75
+ };
76
+ return {
77
+ engine: engine as Board3DEngine,
78
+ scene,
79
+ camera,
80
+ firePostRender: () => postRender?.(),
81
+ };
82
+ }
83
+
84
+ function mountMap(engine: Board3DEngine) {
85
+ const container = document.createElement("div");
86
+ document.body.appendChild(container);
87
+ const app = createApp(
88
+ defineComponent({
89
+ setup() {
90
+ return () => h(HkMinimap3D, { engine });
91
+ },
92
+ }),
93
+ );
94
+ app.mount(container);
95
+ mounts.push({ app, container });
96
+ return { app, container };
97
+ }
98
+
99
+ beforeEach(() => {
100
+ H.FakeWebGLRenderer.instances = [];
101
+ });
102
+
103
+ afterEach(() => {
104
+ for (const m of mounts.splice(0)) {
105
+ m.app.unmount();
106
+ m.container.remove();
107
+ }
108
+ });
109
+
110
+ describe("HkMinimap3D", () => {
111
+ it("renders the same scene from its own camera, with helpers on the helpers layer", async () => {
112
+ const { engine, scene, firePostRender } = fakeEngine();
113
+ mountMap(engine);
114
+ await nextTick();
115
+ firePostRender();
116
+
117
+ const renderer = H.FakeWebGLRenderer.instances[0];
118
+ expect(renderer.renders.length).toBe(1);
119
+ expect(renderer.renders[0].scene).toBe(scene);
120
+ const mapCam = renderer.renders[0].camera;
121
+ expect(mapCam).not.toBe(engine.camera);
122
+ // The map camera sees the helper layer; the main camera does not.
123
+ expect(mapCam.layers.test(new THREE.Layers())).toBe(true);
124
+ const helpersMask = 1 << BOARD3D_HELPERS_LAYER;
125
+ expect(mapCam.layers.mask & helpersMask).toBe(helpersMask);
126
+ expect(engine.camera.layers.mask & helpersMask).toBe(0);
127
+ // Helpers actually joined the scene (glyph group + view-plane frame).
128
+ const helperChildren = scene.children.filter(
129
+ (c) => (c.layers.mask & helpersMask) !== 0,
130
+ );
131
+ expect(helperChildren.length).toBeGreaterThanOrEqual(2);
132
+ });
133
+
134
+ it("spawns markers for registered content and follows their world positions", async () => {
135
+ const body = new THREE.Mesh(new THREE.SphereGeometry(2, 8, 6), new THREE.MeshBasicMaterial());
136
+ body.position.set(7, 0, -4);
137
+ const objects = new Map([["node-1", { object: body }]]);
138
+ const { engine, scene, firePostRender } = fakeEngine({ objects: objects as never });
139
+ mountMap(engine);
140
+ await nextTick();
141
+ firePostRender();
142
+
143
+ const marker = scene.children.find((c) => c.userData.mm3dId === "node-1");
144
+ expect(marker).toBeDefined();
145
+ expect(marker!.position.x).toBeCloseTo(7, 5);
146
+ expect(marker!.position.z).toBeCloseTo(-4, 5);
147
+
148
+ body.position.set(-3, 1, 9);
149
+ firePostRender();
150
+ expect(marker!.position.x).toBeCloseTo(-3, 5);
151
+ expect(marker!.position.z).toBeCloseTo(9, 5);
152
+ });
153
+
154
+ it("dragging orbits the map eye on the sphere centred on the main camera", async () => {
155
+ const { engine, camera, firePostRender } = fakeEngine();
156
+ const { container } = mountMap(engine);
157
+ await nextTick();
158
+ firePostRender();
159
+ const renderer = H.FakeWebGLRenderer.instances[0];
160
+ const mapCam = renderer.renders[0].camera;
161
+ const before = mapCam.position.clone();
162
+
163
+ const root = container.querySelector(".hk-minimap3d")!;
164
+ root.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, clientX: 80, clientY: 55 }));
165
+ root.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientX: 120, clientY: 40 }));
166
+ firePostRender();
167
+
168
+ const after = mapCam.position.clone();
169
+ expect(after.equals(before)).toBe(false);
170
+ // Still on the sphere: distance to the main camera is the fit radius.
171
+ const dBefore = before.distanceTo(camera.position);
172
+ const dAfter = after.distanceTo(camera.position);
173
+ expect(dAfter).toBeCloseTo(dBefore, 3);
174
+
175
+ // And the eye keeps LOOKING AT the main camera: its forward axis
176
+ // points straight at it.
177
+ const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(mapCam.quaternion);
178
+ const toCam = camera.position.clone().sub(after).normalize();
179
+ expect(forward.dot(toCam)).toBeGreaterThan(0.999);
180
+
181
+ root.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 120, clientY: 40 }));
182
+ });
183
+
184
+ it("drag deltas follow the shared spherical math", async () => {
185
+ const { engine, camera, firePostRender } = fakeEngine();
186
+ const { container } = mountMap(engine);
187
+ await nextTick();
188
+ firePostRender();
189
+ const mapCam = H.FakeWebGLRenderer.instances[0].renders[0].camera;
190
+
191
+ const root = container.querySelector(".hk-minimap3d")!;
192
+ root.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, clientX: 80, clientY: 55 }));
193
+ root.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientX: 96, clientY: 55 }));
194
+ firePostRender();
195
+
196
+ // Recompute the expected pose: seed from the first render, drag +16px.
197
+ const radius = mapCam.position.distanceTo(camera.position);
198
+ // theta0 comes from the camera azimuth; the drag adds orbitDelta.
199
+ const off = camera.position.clone().sub(new THREE.Vector3(0, 0, 0));
200
+ const theta0 = Math.atan2(off.x, off.z);
201
+ const phi0 = Math.acos(Math.min(1, Math.max(-1, off.y / off.length())));
202
+ const next = orbitDelta(theta0, phi0, 16, 0);
203
+ const expected = sphericalPosition(
204
+ [camera.position.x, camera.position.y, camera.position.z],
205
+ next.theta,
206
+ next.phi,
207
+ radius,
208
+ );
209
+ expect(mapCam.position.x).toBeCloseTo(expected[0], 3);
210
+ expect(mapCam.position.y).toBeCloseTo(expected[1], 3);
211
+ expect(mapCam.position.z).toBeCloseTo(expected[2], 3);
212
+ root.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 96, clientY: 55 }));
213
+ });
214
+
215
+ it("the zoom bar steps 15% rungs clamped to [50, 250], reset reseeds to 100%", async () => {
216
+ const { engine } = fakeEngine();
217
+ const { container } = mountMap(engine);
218
+ await nextTick();
219
+
220
+ const label = () => container.querySelector(".hk-mm-zoom-label")!.textContent;
221
+ const btns = container.querySelectorAll<HTMLButtonElement>(".hk-mm-zoom-btn");
222
+ const [minus, plus] = [btns[0], btns[1]];
223
+ const reset = container.querySelector<HTMLButtonElement>(".hk-mm-zoom-reset-btn")!;
224
+
225
+ expect(label()).toBe("100%");
226
+ plus.click();
227
+ await nextTick();
228
+ expect(label()).toBe("115%");
229
+ minus.click();
230
+ minus.click();
231
+ await nextTick();
232
+ expect(label()).toBe("85%");
233
+ for (let i = 0; i < 20; i++) minus.click();
234
+ await nextTick();
235
+ expect(label()).toBe("50%");
236
+ expect(minus.disabled).toBe(true);
237
+ reset.click();
238
+ await nextTick();
239
+ expect(label()).toBe("100%");
240
+ });
241
+
242
+ it("wheel over the map steps the zoom too", async () => {
243
+ const { engine } = fakeEngine();
244
+ const { container } = mountMap(engine);
245
+ await nextTick();
246
+ const label = () => container.querySelector(".hk-mm-zoom-label")!.textContent;
247
+ const canvas = container.querySelector("canvas")!;
248
+ canvas.dispatchEvent(new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: -100 }));
249
+ await nextTick();
250
+ expect(label()).toBe("115%");
251
+ canvas.dispatchEvent(new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: 100 }));
252
+ await nextTick();
253
+ expect(label()).toBe("100%");
254
+ });
255
+
256
+ it("a higher zoom pulls the map eye closer to the main camera", async () => {
257
+ const { engine, camera, firePostRender } = fakeEngine();
258
+ const { container } = mountMap(engine);
259
+ await nextTick();
260
+ firePostRender();
261
+ const mapCam = H.FakeWebGLRenderer.instances[0].renders[0].camera;
262
+ const d100 = mapCam.position.distanceTo(camera.position);
263
+
264
+ const btns = container.querySelectorAll<HTMLButtonElement>(".hk-mm-zoom-btn");
265
+ btns[1].click(); // 115%
266
+ await nextTick();
267
+ firePostRender();
268
+ const d115 = mapCam.position.distanceTo(camera.position);
269
+ expect(d115).toBeLessThan(d100);
270
+ expect(d115 / d100).toBeCloseTo(100 / 115, 2);
271
+ });
272
+
273
+ it("throttles its auto-refit to the 300 ms window", async () => {
274
+ const { engine, camera, firePostRender } = fakeEngine();
275
+ mountMap(engine);
276
+ await nextTick();
277
+ // First frame refits (the window is open from mount).
278
+ firePostRender();
279
+ const mapCam = H.FakeWebGLRenderer.instances[0].renders[0].camera;
280
+ const r0 = mapCam.position.distanceTo(camera.position);
281
+
282
+ // Move the main camera OUT and fire again well inside the window:
283
+ // the map eye radius (a function of the fit radius while throttled)
284
+ // must not follow yet.
285
+ camera.position.set(400, 300, 500);
286
+ firePostRender();
287
+ expect(mapCam.position.distanceTo(camera.position)).toBeCloseTo(r0, 6);
288
+
289
+ // Past the window it does follow.
290
+ const realNow = performance.now();
291
+ const spy = vi.spyOn(performance, "now").mockReturnValue(realNow + 400);
292
+ try {
293
+ firePostRender();
294
+ } finally {
295
+ spy.mockRestore();
296
+ }
297
+ expect(mapCam.position.distanceTo(camera.position)).not.toBeCloseTo(r0, 6);
298
+ });
299
+
300
+ it("disposes its renderer and strips helpers on unmount", async () => {
301
+ // Registered content matters here: the marker meshes are a separate
302
+ // branch of the teardown and only exist once objects() is non-empty.
303
+ const objects = new Map([
304
+ ["a", { object: new THREE.Mesh(new THREE.SphereGeometry(1, 8, 6), new THREE.MeshBasicMaterial()) }],
305
+ ["b", { object: new THREE.Mesh(new THREE.SphereGeometry(1, 8, 6), new THREE.MeshBasicMaterial()) }],
306
+ ]);
307
+ const { engine, scene, firePostRender } = fakeEngine({ objects: objects as never });
308
+ mountMap(engine);
309
+ await nextTick();
310
+ // Markers are spawned during the post-render pass — fire it so the
311
+ // teardown actually has marker meshes to strip.
312
+ firePostRender();
313
+ expect(scene.children.length).toBeGreaterThan(0);
314
+ const helpersMask = 1 << BOARD3D_HELPERS_LAYER;
315
+ expect(scene.children.some((c) => (c.layers.mask & helpersMask) !== 0)).toBe(true);
316
+
317
+ const m = mounts.splice(0)[0];
318
+ m.app.unmount();
319
+ m.container.remove();
320
+ expect(H.FakeWebGLRenderer.instances[0].disposed).toBe(true);
321
+ expect(scene.children.some((c) => (c.layers.mask & helpersMask) !== 0)).toBe(false);
322
+ // No marker survivors: the map must leave the scene exactly as it
323
+ // found it (this is what a hide/show toggle would leak otherwise).
324
+ expect(scene.children.length).toBe(0);
325
+ });
326
+
327
+ it("disposes the camera glyph's own geometries and materials on unmount", async () => {
328
+ const { engine } = fakeEngine();
329
+ mountMap(engine);
330
+ await nextTick();
331
+ // The glyph is a group (cone + octahedron); count what the map built
332
+ // on the helpers layer and assert every one of them is disposed.
333
+ const helpersMask = 1 << BOARD3D_HELPERS_LAYER;
334
+ const built: Array<{ dispose: () => void }> = [];
335
+ const builtMats: Array<{ dispose: () => void }> = [];
336
+ const seenGeo = new Set<unknown>();
337
+ const seenMat = new Set<unknown>();
338
+ for (const child of engine.scene.children) {
339
+ if ((child.layers.mask & helpersMask) === 0) continue;
340
+ child.traverse((obj: THREE.Object3D) => {
341
+ const mesh = obj as THREE.Mesh;
342
+ if (mesh.geometry && !seenGeo.has(mesh.geometry)) {
343
+ seenGeo.add(mesh.geometry);
344
+ built.push(mesh.geometry as unknown as { dispose: () => void });
345
+ }
346
+ const mat = (mesh as unknown as { material?: { dispose: () => void } }).material;
347
+ if (mat && !seenMat.has(mat)) {
348
+ seenMat.add(mat);
349
+ builtMats.push(mat);
350
+ }
351
+ });
352
+ }
353
+ expect(built.length).toBeGreaterThan(1); // cone + octahedron + frame
354
+ const spies = [...built, ...builtMats].map((r) => vi.spyOn(r, "dispose"));
355
+
356
+ const m = mounts.splice(0)[0];
357
+ m.app.unmount();
358
+ m.container.remove();
359
+ for (const spy of spies) expect(spy).toHaveBeenCalled();
360
+ });
361
+ });