@celestia-island/hikari 0.55.358 → 0.55.360

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/package.json +1 -1
  2. package/src/components/HkAboutModal.test.tsx +33 -1
  3. package/src/components/HkAboutModal.tsx +11 -0
  4. package/src/components/HkAdminHeader.test.tsx +23 -0
  5. package/src/components/HkAdminHeader.tsx +9 -1
  6. package/src/components/HkDrawer.scss +14 -4
  7. package/src/components/HkLoadingVeil.scss +6 -1
  8. package/src/components/HkMarkdownRenderer.tsx +32 -1
  9. package/src/components/HkPopover.scss +6 -1
  10. package/src/components/HkScrollContainer.dock.test.tsx +100 -2
  11. package/src/components/HkScrollContainer.scss +15 -10
  12. package/src/components/HkScrollContainer.tsx +9 -2
  13. package/src/components/HkSelect.scss +6 -2
  14. package/src/components/HkTitleBar.test.tsx +32 -0
  15. package/src/components/HkTitleBar.tsx +25 -1
  16. package/src/components/HkTooltip.tsx +11 -1
  17. package/src/components/__tests__/hkMarkdownLinks.test.ts +152 -0
  18. package/src/components/chromeBand.contract.test.ts +54 -1
  19. package/src/index.ts +25 -0
  20. package/src/plugins/boot-chrome.d.mts +10 -1
  21. package/src/plugins/boot-chrome.mjs +8 -0
  22. package/src/res/boot-chrome.js +97 -3
  23. package/src/res/bootChrome.test.ts +108 -1
  24. package/src/runtime/hyperlink.test.ts +231 -0
  25. package/src/runtime/hyperlink.ts +294 -0
  26. package/src/runtime/index.ts +6 -0
  27. package/src/runtime/popupBounds.test.ts +58 -1
  28. package/src/runtime/popupBounds.ts +45 -2
  29. package/src/runtime/tooltipBridge.test.ts +88 -0
  30. package/src/runtime/tooltipBridge.ts +21 -0
  31. package/src/runtime/tooltipPosition.ts +28 -4
  32. package/src/runtime/windowChrome.ts +59 -0
@@ -0,0 +1,152 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { createApp, defineComponent, h, nextTick, ref } from "vue";
3
+
4
+ import HkMarkdownRenderer from "../HkMarkdownRenderer";
5
+ import { provideHyperlinkCoordinator } from "../../runtime/hyperlink";
6
+
7
+ /**
8
+ * The markdown link activation contract (runtime/hyperlink.ts): every
9
+ * anchor a rendered body carries activates through the coordinator — the
10
+ * web face opens a hardened new tab, the native shell hands the URL to
11
+ * the opener bridge — and the anchor's default is ALWAYS taken over, so
12
+ * the webview itself never navigates (the 2026-11-12 protocol-modal 404:
13
+ * the chest login window followed a vendored relative href onto the app
14
+ * origin). The linkContext prop rides the activation for host resolvers.
15
+ *
16
+ * (Repo test convention: raw createApp + document queries, no
17
+ * @vue/test-utils dependency.)
18
+ */
19
+
20
+ const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
21
+
22
+ async function mountMarkdown(content: string, linkContext?: string): Promise<void> {
23
+ const container = document.createElement("div");
24
+ document.body.appendChild(container);
25
+ const Wrapper = defineComponent({
26
+ setup() {
27
+ return () =>
28
+ h(HkMarkdownRenderer, {
29
+ content,
30
+ ...(linkContext !== undefined ? { linkContext } : {}),
31
+ });
32
+ },
33
+ });
34
+ const app = createApp(Wrapper);
35
+ app.mount(container);
36
+ mounts.push({ app, container });
37
+ // The renderer lazy-imports marked + DOMPurify on the first non-plain
38
+ // parse — POLL for the rendered body (the chest suites learned this
39
+ // the same way: a fixed settle races the module transform).
40
+ for (let i = 0; i < 100; i += 1) {
41
+ await nextTick();
42
+ await new Promise((resolve) => setTimeout(resolve, 10));
43
+ if (document.body.querySelector(".hk-markdown-body a[href]")) return;
44
+ }
45
+ throw new Error(
46
+ "markdown body never rendered an anchor; body HTML: " +
47
+ (document.body.querySelector(".hk-markdown-body")?.innerHTML ?? "(no body)") +
48
+ " / rendered: " +
49
+ (document.body.querySelector(".hk-markdown")?.outerHTML.slice(0, 300) ?? "(none)"),
50
+ );
51
+ }
52
+
53
+ function bodyAnchor(href: string): HTMLAnchorElement {
54
+ const anchor = document.body.querySelector<HTMLAnchorElement>(
55
+ '.hk-markdown-body a[href="' + href + '"]',
56
+ );
57
+ expect(anchor, 'anchor "' + href + '" renders').toBeTruthy();
58
+ return anchor!;
59
+ }
60
+
61
+ afterEach(() => {
62
+ for (const { app, container } of mounts.splice(0)) {
63
+ app.unmount();
64
+ container.remove();
65
+ }
66
+ provideHyperlinkCoordinator(null);
67
+ vi.unstubAllGlobals();
68
+ vi.restoreAllMocks();
69
+ });
70
+
71
+ describe("markdown link activation", () => {
72
+ it("opens an external anchor in a hardened new tab on the web face", async () => {
73
+ const open = vi.fn(() => ({}));
74
+ vi.stubGlobal("open", open);
75
+
76
+ await mountMarkdown("[CLA](https://docs.celestia.world/meta/cla.html)");
77
+ const anchor = bodyAnchor("https://docs.celestia.world/meta/cla.html");
78
+ anchor.dispatchEvent(
79
+ new MouseEvent("click", { bubbles: true, cancelable: true }),
80
+ );
81
+ await new Promise((resolve) => setTimeout(resolve, 0));
82
+
83
+ expect(open).toHaveBeenCalledWith(
84
+ "https://docs.celestia.world/meta/cla.html",
85
+ "_blank",
86
+ "noopener,noreferrer",
87
+ );
88
+ });
89
+
90
+ it("never lets the anchor default through (the webview must not navigate)", async () => {
91
+ const open = vi.fn(() => ({}));
92
+ vi.stubGlobal("open", open);
93
+
94
+ const locationBefore = window.location.href;
95
+ await mountMarkdown("[guide](cla.md)", "protocol");
96
+ const anchor = bodyAnchor("cla.md");
97
+ const event = new MouseEvent("click", { bubbles: true, cancelable: true });
98
+ anchor.dispatchEvent(event);
99
+ await new Promise((resolve) => setTimeout(resolve, 0));
100
+
101
+ // The DEFAULT is taken over (the webview never follows the href); the
102
+ // web face instead opens the resolved tab — the open() call IS the
103
+ // designed routing here, the assertion is that no navigation happened.
104
+ expect(event.defaultPrevented).toBe(true);
105
+ expect(window.location.href).toBe(locationBefore);
106
+ expect(open).toHaveBeenCalledTimes(1);
107
+ const firstCall = open.mock.calls[0] as unknown as [string] | undefined;
108
+ expect(firstCall?.[0]).toBe(new URL("cla.md", document.baseURI).href);
109
+ });
110
+
111
+ it("carries the linkContext so the host resolver can canonicalize", async () => {
112
+ const open = vi.fn(() => ({}));
113
+ vi.stubGlobal("open", open);
114
+ const seen: Array<{ href: string; linkContext?: string; source: string }> = [];
115
+ provideHyperlinkCoordinator({
116
+ resolve: (info) => {
117
+ seen.push({ href: info.href, linkContext: info.linkContext, source: info.source });
118
+ return null; // swallow — this pin only observes the handoff
119
+ },
120
+ });
121
+
122
+ await mountMarkdown("[CLA](cla.md)", "protocol");
123
+ bodyAnchor("cla.md").dispatchEvent(
124
+ new MouseEvent("click", { bubbles: true, cancelable: true }),
125
+ );
126
+ await new Promise((resolve) => setTimeout(resolve, 0));
127
+
128
+ expect(seen).toEqual([
129
+ { href: "cla.md", linkContext: "protocol", source: "markdown" },
130
+ ]);
131
+ expect(open).not.toHaveBeenCalled();
132
+ });
133
+
134
+ it("activates through the opener IPC on the native shell", async () => {
135
+ const invoke = vi.fn(() => Promise.resolve());
136
+ vi.stubGlobal("__TAURI_INTERNALS__", { invoke });
137
+ const open = vi.fn();
138
+ vi.stubGlobal("open", open);
139
+
140
+ await mountMarkdown("[site](https://example.com)");
141
+ bodyAnchor("https://example.com").dispatchEvent(
142
+ new MouseEvent("click", { bubbles: true, cancelable: true }),
143
+ );
144
+ await new Promise((resolve) => setTimeout(resolve, 0));
145
+
146
+ expect(invoke).toHaveBeenCalledWith("plugin:opener|open_url", {
147
+ url: "https://example.com",
148
+ with: null,
149
+ });
150
+ expect(open).not.toHaveBeenCalled();
151
+ });
152
+ });
@@ -41,7 +41,13 @@ import { fileURLToPath } from "node:url";
41
41
  * the contract — keep the prose home in sync);
42
42
  * 7. the GEOMETRY leg exists: both HkModal fixed plates read
43
43
  * --hk-chrome-band-inset on their top edge (the stacking-proof
44
- * fallback for hosts whose wrappers trap the band).
44
+ * fallback for hosts whose wrappers trap the band), and so does
45
+ * every OTHER windowed veil the library ships — the drawer's
46
+ * overlay and its left/right/top panels, the loading veil, and the
47
+ * mobile sheet scrims of the popover and the select panel (2026-11-12
48
+ * extension: the modal got the leg first; a drawer or a blocking
49
+ * veil covering the caption row again would be the same field
50
+ * report with a different component).
45
51
  */
46
52
 
47
53
  const here = dirname(fileURLToPath(import.meta.url));
@@ -52,6 +58,13 @@ const adminHeader = readFileSync(join(here, "HkAdminHeader.tsx"), "utf8");
52
58
  const titleBarScss = readFileSync(join(here, "HkTitleBar.scss"), "utf8");
53
59
  const windowControls = readFileSync(join(here, "HkWindowControls.tsx"), "utf8");
54
60
  const modalScss = readFileSync(join(here, "HkModal.scss"), "utf8");
61
+ const drawerScss = readFileSync(join(here, "HkDrawer.scss"), "utf8");
62
+ const veilScss = readFileSync(join(here, "HkLoadingVeil.scss"), "utf8");
63
+ const selectScss = readFileSync(join(here, "HkSelect.scss"), "utf8");
64
+ const popoverScss = readFileSync(join(here, "HkPopover.scss"), "utf8");
65
+ const titleBarTsx = readFileSync(join(here, "HkTitleBar.tsx"), "utf8");
66
+ const tooltipBridge = readFileSync(join(here, "..", "runtime", "tooltipBridge.ts"), "utf8");
67
+ const popupBounds = readFileSync(join(here, "..", "runtime", "popupBounds.ts"), "utf8");
55
68
 
56
69
  /** The numeric value a root z-token declaration carries, or null. */
57
70
  function rootTokenZ(source: string, token: string): number | null {
@@ -179,4 +192,44 @@ describe("chrome-band layer contract (the host caption stayed under the veil)",
179
192
  it("names .hk-chrome-band on HkWindowControls (the prose home)", () => {
180
193
  expect(windowControls).toContain(".hk-chrome-band");
181
194
  });
195
+
196
+ it("yields the other windowed veils' top edge to --hk-chrome-band-inset", () => {
197
+ // The geometry leg across the windowed family: every fixed dim/blur
198
+ // curtain (and every panel that would physically cover the band row)
199
+ // starts BELOW the host caption band. A missing leg on any of these
200
+ // re-dims — or re-covers — the caption row on native shells.
201
+ const expectInset = (source: string, selector: string, file: string) => {
202
+ const rules = allRuleDeclarations(source, selector).filter((r) => !r.nested);
203
+ expect(rules.length, selector + " in " + file + " must exist at top level").toBe(1);
204
+ expect(rules[0].decls).toContainEqual(["top", "var(--hk-chrome-band-inset, 0px)"]);
205
+ };
206
+ expectInset(drawerScss, ".hk-drawer-overlay", "HkDrawer.scss");
207
+ expectInset(drawerScss, ".hk-drawer-left", "HkDrawer.scss");
208
+ expectInset(drawerScss, ".hk-drawer-right", "HkDrawer.scss");
209
+ expectInset(drawerScss, ".hk-drawer-top", "HkDrawer.scss");
210
+ expectInset(veilScss, ".hk-loading-veil", "HkLoadingVeil.scss");
211
+ expectInset(selectScss, ".hk-select-sheet-scrim", "HkSelect.scss");
212
+ expectInset(popoverScss, ".hk-popover-scrim", "HkPopover.scss");
213
+ // A BOTTOM-docked drawer still owns its bottom edge — the inset is a
214
+ // top-edge contract only.
215
+ const bottom = allRuleDeclarations(drawerScss, ".hk-drawer-bottom").filter((r) => !r.nested);
216
+ expect(bottom[0].decls).not.toContainEqual(["top", "var(--hk-chrome-band-inset, 0px)"]);
217
+ });
218
+
219
+ it("keeps tooltips off the band by default with an explicit exemption", () => {
220
+ // The tooltip leg of the contract (2026-11-12 user direction): the
221
+ // popup frame floors at the band inset + POPUP_BAND_GAP_PX (4) —
222
+ // default NO cover; pinning over the strip is an explicit per-trigger
223
+ // marker or install option, which the caption's OWN buttons carry.
224
+ // Three pins: the floor exists, the bridge reads the marker, and the
225
+ // title bar's buttons carry it.
226
+ expect(popupBounds).toMatch(/bandInset > 0 \? bandInset \+ POPUP_BAND_GAP_PX : 0/);
227
+ expect(popupBounds).toContain("POPUP_BAND_GAP_PX = 4");
228
+ expect(tooltipBridge).toContain('data-hk-tooltip-band-overlap');
229
+ expect(tooltipBridge).toMatch(/el\.hasAttribute\(\"data-hk-tooltip-band-overlap\"\)/);
230
+ // Every caption-row button of the reference title bar opts in —
231
+ // custom actions, minimize, maximize/restore, close.
232
+ const markers = (titleBarTsx.match(/data-hk-tooltip-band-overlap="true"/g) ?? []).length;
233
+ expect(markers, "all four caption buttons must carry the exemption").toBe(4);
234
+ });
182
235
  });
package/src/index.ts CHANGED
@@ -1070,8 +1070,33 @@ export {
1070
1070
  WINDOW_IPC,
1071
1071
  RESIZE_POLL_MS,
1072
1072
  RESIZE_FALLBACK_TICKS,
1073
+ // Caption-band contracts (2026-11-12): hosts bind their band's
1074
+ // data-tauri-drag-region to CHROME_BAND_DRAG_REGION ("deep" — the bare value
1075
+ // only matches the exact event target, so a band of wrappers never dragged or
1076
+ // double-click-maximized) and publish their band height under
1077
+ // CHROME_BAND_HEIGHT_VAR so hikari's pre-boot bar wears the same height as the
1078
+ // app's caption band instead of a thin default it then replaces.
1079
+ CHROME_BAND_DRAG_REGION,
1080
+ CHROME_BAND_HEIGHT_VAR,
1073
1081
  type WindowApiLike,
1074
1082
  } from "./runtime/windowChrome";
1083
+ // THE hyperlink coordination context (runtime/hyperlink.ts): every link
1084
+ // activation — markdown anchors, About-dialog rows, host surfaces — goes
1085
+ // through openHyperlink so the environment picks the destination (new tab
1086
+ // on the web, the system browser in the native shell) and the webview
1087
+ // itself never navigates. Hosts register resolve/open overrides once at
1088
+ // bootstrap with provideHyperlinkCoordinator.
1089
+ export {
1090
+ classifyHyperlink,
1091
+ openExternalHyperlink,
1092
+ openHyperlink,
1093
+ provideHyperlinkCoordinator,
1094
+ useHyperlinkCoordinator,
1095
+ type HyperlinkCoordinator,
1096
+ type HyperlinkInfo,
1097
+ type HyperlinkKind,
1098
+ type HyperlinkSource,
1099
+ } from "./runtime/hyperlink";
1075
1100
  // Pre-boot caption bar (`bootChromePlugin`) is NOT exported here. It ships from
1076
1101
  // its own published subpath — `@celestia-island/hikari/plugins/boot-chrome` —
1077
1102
  // resolved to a self-contained ESM module, and that is what a host imports in
@@ -20,7 +20,16 @@ export declare const BOOT_CHROME_URL: string;
20
20
  export interface BootChromePluginOptions {
21
21
  /** Application name on the left of the bar (default: `document.title`). */
22
22
  title?: string;
23
- /** Bar height in px; `boot-chrome.js` clamps it to 20..64 (default 32). */
23
+ /**
24
+ * Bar height in px; `boot-chrome.js` clamps it to 20..64 (default 32).
25
+ *
26
+ * PINNING this option is the exception, not the rule: a shell whose caption
27
+ * band has a real height should publish that height to `root` as
28
+ * `--hk-chrome-band-h` (hikari's `CHROME_BAND_HEIGHT_VAR`, exported from
29
+ * `runtime/windowChrome`) instead — the bar then wears the app's own band
30
+ * height from the first frame and the host never restates a number. An
31
+ * explicit `height` wins over that contract (it means "pin the bar").
32
+ */
24
33
  height?: number;
25
34
  /** Watchdog delay in ms before the reload affordance appears (default 20000). */
26
35
  hangMs?: number;
@@ -50,6 +50,14 @@ import { fileURLToPath } from "node:url";
50
50
  * in dev (Vite only serves `public/` files otherwise, and the script ships
51
51
  * inside the package instead).
52
52
  *
53
+ * HEIGHT CONTRACT (2026-11-12): the bar also follows a host-published custom
54
+ * property — `--hk-chrome-band-h` on :root (hikari's CHROME_BAND_HEIGHT_VAR,
55
+ * runtime/windowChrome.ts) — so a shell whose caption band has a real height
56
+ * draws the SAME band from the first frame instead of a thin default the band
57
+ * then replaces. Declare it from the host's pre-paint skeleton as a length or a
58
+ * var() chain (`var(--s-header-height, 3rem)`); the bar applies the resolved
59
+ * length. The `height` option still wins when a host wants the bar pinned.
60
+ *
53
61
  * KNOWN PRECONDITIONS (host-side, documented rather than enforced):
54
62
  * - `boot-chrome.js` injects its own `<style>` element, so the host CSP needs
55
63
  * `style-src 'unsafe-inline'` (the Tauri shells in the family allow it).
@@ -27,7 +27,17 @@
27
27
  * data-hk-title application name shown on the left (default: document.title)
28
28
  * data-hk-hang-ms watchdog delay in ms before the reload affordance appears
29
29
  * (default 20000; a non-positive/invalid value = default)
30
- * data-hk-height bar height in px (default 32, clamped to 20..64)
30
+ * data-hk-height bar height in px (default 32, clamped to 20..64). An
31
+ * explicit value PINNS the bar: it wins over the height
32
+ * contract below.
33
+ * height contract the host may publish its caption band height to :root as
34
+ * `--hk-chrome-band-h` (hikari's CHROME_BAND_HEIGHT_VAR,
35
+ * runtime/windowChrome.ts) — a length or a var() chain.
36
+ * The bar wears it verbatim, so the strip matches the
37
+ * app's caption band from the first frame and keeps
38
+ * tracking the app token once its stylesheet lands
39
+ * (2026-11-12: chest's wide 3rem band booted behind a
40
+ * thin 32px strip). Absent → the 32px default, as before.
31
41
  *
32
42
  * HOST API — `window.HkBootChrome`:
33
43
  * setStatus(text) replace the status text (e.g. "connecting…")
@@ -110,13 +120,24 @@
110
120
  var HEIGHT_DEFAULT = 32;
111
121
  var HEIGHT_MIN = 20;
112
122
  var HEIGHT_MAX = 64;
123
+ // hikari's caption-height contract (runtime/windowChrome.ts — a classic
124
+ // script cannot import it, so the name is mirrored here and the parity
125
+ // test in src/res/bootChrome.test.ts pins both spellings).
126
+ var CAPTION_HEIGHT_VAR = "--hk-chrome-band-h";
113
127
  var RETRY_EVERY_MS = 100;
114
128
  var RETRY_BUDGET_MS = 5000;
115
129
  var FADE_MS = 160; // < 200ms: the claim handoff must not delay the app.
116
130
 
117
131
  var currentScript = doc.currentScript;
118
132
  var cfg = (currentScript && currentScript.dataset) || {};
119
- var barHeight = intOption(cfg.hkHeight, HEIGHT_MIN, HEIGHT_MAX) || HEIGHT_DEFAULT;
133
+ // Height precedence: an explicit data-hk-height PIN beats the caption band
134
+ // contract (a host that asked for a fixed bar meant it); the contract beats
135
+ // the thin default. `barHeight` stays the numeric fallback the stylesheet
136
+ // rule carries; `bandHeight` (when set) is the resolved length applied as an
137
+ // inline height and published through `--hk-boot-chrome-h`.
138
+ var pinnedHeight = intOption(cfg.hkHeight, HEIGHT_MIN, HEIGHT_MAX);
139
+ var bandHeight = pinnedHeight === null ? captionBandHeight() : "";
140
+ var barHeight = pinnedHeight || HEIGHT_DEFAULT;
120
141
  var hangMs = intOption(cfg.hkHangMs, 1, 3600000) || HANG_MS_DEFAULT;
121
142
  var appTitle =
122
143
  typeof cfg.hkTitle === "string" && cfg.hkTitle
@@ -142,6 +163,67 @@
142
163
  }
143
164
  }
144
165
 
166
+ /** A plain CSS length (or a bare 0) — the only shape the bar can apply. */
167
+ function isPlainLength(value) {
168
+ return /^\s*(-?\d*\.?\d+(px|rem|em|ex|ch|vh|dvh|svh|lvh|vw|dvw|%)|0)\s*$/i.test(
169
+ value
170
+ );
171
+ }
172
+
173
+ /**
174
+ * Resolve a host's caption-height declaration to one plain length.
175
+ *
176
+ * The contract accepts a length OR a var() chain, but the bar needs a value it
177
+ * can actually apply: a declaration parser may reject var() inside a style
178
+ * property (happy-dom's does; some WebViews did too). Resolution therefore
179
+ * lands on a length, in this order:
180
+ *
181
+ * 1. a plain length is taken as-is;
182
+ * 2. a `var(--name, fallback)` chain resolves to its OWN fallback when the
183
+ * referenced property is not in the cascade yet — which is the normal
184
+ * boot case: the bar exists BEFORE any stylesheet has loaded, so the
185
+ * fallback IS the app's declared height at that instant;
186
+ * 3. anything else (junk, a chain without a fallback) yields "" and the
187
+ * numeric default stays.
188
+ *
189
+ * Tarbar tracking: the applied length is a snapshot, not a live chain. That is
190
+ * deliberate — the bar only lives until the app claims the chrome, and a boot
191
+ * strip that changes height mid-load is worse than one that matches the
192
+ * pre-CSS contract exactly.
193
+ */
194
+ function resolveBandHeight(raw) {
195
+ var value = (raw || "").trim();
196
+ if (!value) return "";
197
+ if (isPlainLength(value)) return value;
198
+ var chain = /^var\(\s*--[A-Za-z0-9_-]+\s*,\s*([^()]+?)\s*\)$/i.exec(value);
199
+ if (chain && isPlainLength(chain[1])) return chain[1].trim();
200
+ return "";
201
+ }
202
+
203
+ /**
204
+ * The host's caption band height, when the contract var is published.
205
+ *
206
+ * Computed first — a real webview substitutes custom properties, so a chain
207
+ * arrives already resolved — then the declared value (the pre-paint skeleton
208
+ * writes it as an inline :root style), which covers engines that do not
209
+ * substitute in getComputedStyle. Both go through resolveBandHeight.
210
+ */
211
+ function captionBandHeight() {
212
+ var computed = safe(function () {
213
+ var cs =
214
+ typeof window.getComputedStyle === "function"
215
+ ? window.getComputedStyle(root)
216
+ : null;
217
+ return cs ? cs.getPropertyValue(CAPTION_HEIGHT_VAR) || "" : "";
218
+ }, "");
219
+ var resolved = resolveBandHeight(computed);
220
+ if (resolved) return resolved;
221
+ var declared = safe(function () {
222
+ return root.style.getPropertyValue(CAPTION_HEIGHT_VAR) || "";
223
+ }, "");
224
+ return resolveBandHeight(declared);
225
+ }
226
+
145
227
  function noop() {}
146
228
 
147
229
  // --------------------------------------------------------------------- copy
@@ -407,8 +489,20 @@
407
489
  }, undefined);
408
490
 
409
491
  // Publish the bar height so the host can keep its own content below it.
492
+ // The contract value goes out VERBATIM (never re-measured) so the host's
493
+ // offset tracks the same token chain the bar itself wears.
494
+ safe(function () {
495
+ root.style.setProperty(
496
+ "--hk-boot-chrome-h",
497
+ bandHeight || barHeight + "px"
498
+ );
499
+ }, undefined);
500
+
501
+ // Wear the caption band height when the contract delivered one: an inline
502
+ // height beats the stylesheet rule's numeric default, so the strip and the
503
+ // app's caption band read as one band from the very first frame.
410
504
  safe(function () {
411
- root.style.setProperty("--hk-boot-chrome-h", barHeight + "px");
505
+ if (bandHeight) bar.style.height = bandHeight;
412
506
  }, undefined);
413
507
  root.setAttribute("data-hk-boot-chrome", "active");
414
508
 
@@ -4,7 +4,11 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
6
 
7
- import { WINDOW_IPC } from "../runtime/windowChrome";
7
+ import {
8
+ CHROME_BAND_DRAG_REGION,
9
+ CHROME_BAND_HEIGHT_VAR,
10
+ WINDOW_IPC,
11
+ } from "../runtime/windowChrome";
8
12
  import { asIndexable } from "../utils/typing";
9
13
 
10
14
  /**
@@ -124,6 +128,7 @@ beforeEach(() => {
124
128
  document.documentElement.removeAttribute("data-mode");
125
129
  document.documentElement.removeAttribute("data-hk-boot-chrome");
126
130
  document.documentElement.style.removeProperty("--hk-boot-chrome-h");
131
+ document.documentElement.style.removeProperty(CHROME_BAND_HEIGHT_VAR);
127
132
  clearGlobal("HkBootChrome");
128
133
  clearGlobal("__TAURI__");
129
134
  clearGlobal("__TAURI_INTERNALS__");
@@ -619,6 +624,108 @@ describe("boot-chrome.js teardown (S3-1)", () => {
619
624
  });
620
625
  });
621
626
 
627
+ describe("boot-chrome.js caption band height contract (2026-11-12)", () => {
628
+ // WHY: the app's caption band is a real band (chest's 3rem-class header), and
629
+ // the pre-boot bar used to draw a thin 32px strip the band then replaced —
630
+ // two different heights inside one window, user-visible on every start. The
631
+ // host publishes its band height to :root; the bar wears it verbatim so the
632
+ // strip matches from the first frame AND keeps tracking the app token.
633
+
634
+ function published(): string {
635
+ return document.documentElement.style.getPropertyValue("--hk-boot-chrome-h");
636
+ }
637
+
638
+ /** The height the bar actually wears (inline, beats the rule's default). */
639
+ function worn(): string {
640
+ return (bar() as HTMLElement).style.height;
641
+ }
642
+
643
+ function declareBandHeight(value: string): void {
644
+ document.documentElement.style.setProperty(CHROME_BAND_HEIGHT_VAR, value);
645
+ }
646
+
647
+ it("resolves a var() chain to its fallback — the boot strip's real height", () => {
648
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
649
+ // The pre-paint skeleton (chest's theme-loader.js) publishes a CHAIN, not a
650
+ // resolved number. The bar exists BEFORE any stylesheet loads, so the
651
+ // referenced token is not in the cascade yet and the chain's own fallback
652
+ // IS the app's declared band height at that instant.
653
+ declareBandHeight("var(--s-header-height, 3rem)");
654
+ runBootChrome();
655
+
656
+ expect(worn()).toBe("3rem");
657
+ expect(published()).toBe("3rem");
658
+ });
659
+
660
+ it("prefers a resolvable chain over the numeric default", () => {
661
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
662
+ declareBandHeight("var(--chest-caption-height, 40px)");
663
+ runBootChrome();
664
+
665
+ expect(worn()).toBe("40px");
666
+ expect(published()).toBe("40px");
667
+ });
668
+
669
+ it("falls back to the numeric default for a chain with no resolvable length", () => {
670
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
671
+ // No fallback: nothing the boot strip can wear before the cascade exists.
672
+ declareBandHeight("var(--s-header-height)");
673
+ runBootChrome();
674
+
675
+ expect(worn()).toBe("");
676
+ expect(published()).toBe("32px");
677
+ });
678
+
679
+ it("accepts a plain length and clamps nothing away (host owns its band)", () => {
680
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
681
+ declareBandHeight("56px");
682
+ runBootChrome();
683
+
684
+ expect(worn()).toBe("56px");
685
+ expect(published()).toBe("56px");
686
+ });
687
+
688
+ it("lets an explicit data-hk-height pin beat the band contract", () => {
689
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
690
+ declareBandHeight("56px");
691
+ runBootChrome({ height: 36 });
692
+
693
+ expect(published()).toBe("36px");
694
+ expect(styleSheet()).toContain("height:36px");
695
+ // A pinned bar must not be overwritten by the contract.
696
+ expect(worn()).toBe("");
697
+ });
698
+
699
+ it("ignores a junk contract value instead of shipping a broken height", () => {
700
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
701
+ declareBandHeight("banana");
702
+ runBootChrome();
703
+
704
+ // No local height, and the published offset stays the numeric default —
705
+ // a junk value must not reach either (host offset consumers read this).
706
+ expect(worn()).toBe("");
707
+ expect(published()).toBe("32px");
708
+ });
709
+
710
+ it("ignores an empty contract value", () => {
711
+ setGlobal("__TAURI_INTERNALS__", { invoke: vi.fn(() => Promise.resolve(false)) });
712
+ declareBandHeight(" ");
713
+ runBootChrome();
714
+
715
+ expect(published()).toBe("32px");
716
+ });
717
+
718
+ it("pins the contract name on both sides of the classic-script boundary", () => {
719
+ // boot-chrome.js cannot import the TS constant; this is the anti-drift gate.
720
+ expect(CHROME_BAND_HEIGHT_VAR).toBe("--hk-chrome-band-h");
721
+ expect(SOURCE).toContain(`"${CHROME_BAND_HEIGHT_VAR}"`);
722
+ });
723
+
724
+ it("pins the deep drag-region value the caption bands carry", () => {
725
+ expect(CHROME_BAND_DRAG_REGION).toBe("deep");
726
+ });
727
+ });
728
+
622
729
  describe("boot-chrome.js ↔ runtime/windowChrome parity", () => {
623
730
  // The boot bar (classic script) and the Vue components (TS) must wire the
624
731
  // SAME shell commands in the SAME order. The components import WINDOW_IPC;