@celestia-island/hikari 0.55.452 → 0.55.455

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.
@@ -50,6 +50,28 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
50
50
  type: BooleanConstructor;
51
51
  default: boolean;
52
52
  };
53
+ /** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
54
+ * takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
55
+ * it. Default ON — a scrollable region a keyboard user cannot reach is
56
+ * a compliance defect, and an extra tab stop is the standard cost
57
+ * (the viewport only scrolls while IT holds focus, so inner inputs,
58
+ * buttons and links keep their own key handling). */
59
+ keyboardScroll: {
60
+ type: BooleanConstructor;
61
+ default: boolean;
62
+ };
63
+ /** ARIA role for the viewport. Use a NON-live role ("region") for
64
+ * streaming content — "log"/"feed" carry implicit live semantics and
65
+ * would announce every appended line. Omitted = no role attribute. */
66
+ scrollRole: {
67
+ type: StringConstructor;
68
+ default: undefined;
69
+ };
70
+ /** Accessible name for the viewport (announced with the role). */
71
+ scrollLabel: {
72
+ type: StringConstructor;
73
+ default: undefined;
74
+ };
53
75
  overscanScreens: {
54
76
  type: NumberConstructor;
55
77
  default: number;
@@ -496,6 +518,28 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
496
518
  type: BooleanConstructor;
497
519
  default: boolean;
498
520
  };
521
+ /** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
522
+ * takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
523
+ * it. Default ON — a scrollable region a keyboard user cannot reach is
524
+ * a compliance defect, and an extra tab stop is the standard cost
525
+ * (the viewport only scrolls while IT holds focus, so inner inputs,
526
+ * buttons and links keep their own key handling). */
527
+ keyboardScroll: {
528
+ type: BooleanConstructor;
529
+ default: boolean;
530
+ };
531
+ /** ARIA role for the viewport. Use a NON-live role ("region") for
532
+ * streaming content — "log"/"feed" carry implicit live semantics and
533
+ * would announce every appended line. Omitted = no role attribute. */
534
+ scrollRole: {
535
+ type: StringConstructor;
536
+ default: undefined;
537
+ };
538
+ /** Accessible name for the viewport (announced with the role). */
539
+ scrollLabel: {
540
+ type: StringConstructor;
541
+ default: undefined;
542
+ };
499
543
  overscanScreens: {
500
544
  type: NumberConstructor;
501
545
  default: number;
@@ -908,6 +952,9 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
908
952
  as: string;
909
953
  markersWidth: number;
910
954
  mapSegments: OverlayScrollMapSegment[];
955
+ keyboardScroll: boolean;
956
+ scrollRole: string;
957
+ scrollLabel: string;
911
958
  fade: boolean;
912
959
  fadeDistance: number;
913
960
  overflowGlow: boolean;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Reference-counted host-position promotion, shared by every composable
3
+ * that needs a positioned positioning context (the overlay scrollbar and
4
+ * the overview ruler). A module-private WeakMap per composable is the
5
+ * exact accident this exists to prevent: ruler A's detach stripping the
6
+ * positioning out from under a still-live scrollbar B on the same host.
7
+ *
8
+ * Contract:
9
+ * - `promoteHost(host)` counts the caller and returns its release;
10
+ * - the FIRST caller on a static/empty-position host sets
11
+ * `position: relative`; every later caller (whatever the computed
12
+ * position now is) is still counted;
13
+ * - the LAST release restores the PRE-ATTACH inline position — unless a
14
+ * consumer re-styled the host after attach (their style wins; the
15
+ * saved value stays dead).
16
+ */
17
+ export interface PromoteHostHandle {
18
+ release(): void;
19
+ /** Whether THIS call applied the promotion (count reached 1 on a
20
+ * static/empty host). Consumers use it to gate companion markers that
21
+ * only make sense when the promotion actually happened. */
22
+ promoted: boolean;
23
+ }
24
+ export declare function promoteHost(host: HTMLElement): PromoteHostHandle;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * useOverviewRuler — a standalone minimap strip ("竖向瀑布流") that any
3
+ * scrollable element can attach, the same way attachOverlayScrollbars
4
+ * attaches the scrollbar. It renders a proportional density map of the
5
+ * viewport's content (one band per top-level block, sized by its share of
6
+ * the content extent) plus a cursor marking the visible window; dragging
7
+ * scrolls the viewport, clicking jumps.
8
+ *
9
+ * Design direction (2026-11-21 user ruling): the minimap is a STANDALONE
10
+ * attachment — not a mode of the scrollbar — and it is the same primitive
11
+ * a waterfall layout needs: a vertical (or horizontal) strip of
12
+ * proportional bands with a draggable cursor. Direction and cursor
13
+ * behaviour are options, not separate components.
14
+ *
15
+ * Two cursor modes:
16
+ * - "jump" (default): pointer down anywhere on the strip scrolls so the
17
+ * content window under the pointer becomes the visible window, then
18
+ * keeps dragging (双向可拖动 — both the cursor and a strip click steer
19
+ * the scroll);
20
+ * - "thumb": only the cursor box is draggable; strip clicks are inert.
21
+ *
22
+ * Sampling: bands are harvested from `bandSelector` matches inside the
23
+ * viewport (default: the viewport's DIRECT element children). Nested
24
+ * matches are dropped when a match contains another (a parent band's
25
+ * extent already contains its children's — counting both would paint the
26
+ * same content twice). Caller-driven content (virtualized rows, a canvas
27
+ * terminal) should pass a `bandSelector` for whatever stands in for lines,
28
+ * or drive `setBands` directly with fractions.
29
+ *
30
+ * The strip sits at z-index 9 — UNDER the overlay scrollbar's interactive
31
+ * track (z-index 10, see theme/scrollbar.scss) so a host that attaches
32
+ * both keeps fine scrolling on the track while the ruler carries the map.
33
+ */
34
+ export type OverviewRulerAxis = "vertical" | "horizontal";
35
+ export type OverviewRulerCursorMode = "jump" | "thumb";
36
+ export interface OverviewRulerBand {
37
+ /** Band start as a fraction of the content extent, 0..1. */
38
+ start: number;
39
+ /** Band length as a fraction of the content extent, 0..1. */
40
+ length: number;
41
+ /** Extra class for the band (e.g. severity coloring for log lines). */
42
+ modifier?: string;
43
+ }
44
+ export interface OverviewRulerOptions {
45
+ /** Strip direction. Default "vertical" (the waterfall). */
46
+ axis?: OverviewRulerAxis;
47
+ /** Strip thickness in CSS px. Default 48 (vertical) / 36 (horizontal). */
48
+ thickness?: number;
49
+ /** Which edge of the host the strip docks to. Default "end"
50
+ * (right for vertical, bottom for horizontal). */
51
+ side?: "start" | "end";
52
+ /** Selector harvested INSIDE the viewport for band sources. Matches
53
+ * contained within another match are dropped (the parent band already
54
+ * covers them). Default: the viewport's DIRECT element children. */
55
+ bandSelector?: string;
56
+ /** Cursor behaviour: "jump" (default) = strip pointer down jumps then
57
+ * drags; "thumb" = only the cursor box is draggable. */
58
+ cursorDrag?: OverviewRulerCursorMode;
59
+ /** Element the strip is appended to — its positioning context. Same
60
+ * contract as OverlayScrollbarOptions.host: a box wrapping exactly the
61
+ * viewport. Defaults to the viewport's DOM parent. */
62
+ host?: HTMLElement;
63
+ /** Content-resample cadence in ms (bands, not the cursor — the cursor
64
+ * tracks scroll and resize live). Default 250. */
65
+ resampleMs?: number;
66
+ }
67
+ export interface OverviewRulerHandle {
68
+ /** Resample the bands and reposition the cursor. */
69
+ update(): void;
70
+ /** Replace the sampled bands with caller fractions (virtualized or
71
+ * canvas content). An empty list clears the waterfall. */
72
+ setBands(bands: OverviewRulerBand[]): void;
73
+ /** Remove the strip and every listener/observer; restore any inline
74
+ * positioning the promotion applied. Safe to call twice. */
75
+ detach(): void;
76
+ }
77
+ export declare function attachOverviewRuler(viewport: HTMLElement, opts?: OverviewRulerOptions): OverviewRulerHandle;
@@ -550,3 +550,4 @@ export type { VirtualPointerSinks, UseVirtualPointer, } from "./composables/useV
550
550
  export { useRemoteTouchGestures } from "./composables/useRemoteTouchGestures";
551
551
  export type { TouchGestureHandlers } from "./composables/useRemoteTouchGestures";
552
552
  export { useOrientationLock } from "./composables/useOrientationLock";
553
+ export { attachOverviewRuler, type OverviewRulerAxis, type OverviewRulerBand, type OverviewRulerCursorMode, type OverviewRulerHandle, type OverviewRulerOptions, } from "./composables/useOverviewRuler";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.452",
3
+ "version": "0.55.455",
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",
@@ -178,6 +178,8 @@ export const HkLogWindow = defineComponent({
178
178
  <HScrollContainer
179
179
  class="s-log-viewer-scroll"
180
180
  autoFollow={autoscroll.value && !paused.value}
181
+ scrollRole="region"
182
+ scrollLabel={props.title ?? t("hikari::log.title", "Logs")}
181
183
  ref={scrollRef}
182
184
  >
183
185
  {currentLines.value.length === 0 ? (
@@ -144,6 +144,10 @@
144
144
  translate: calc(-50% + var(--hk-modal-shift-x, 0px))
145
145
  calc(-50% + var(--hk-modal-shift-y, 0px));
146
146
  width: 100%;
147
+ // Reasonable upper bound: a 2734px-wide viewport with width:100% gives
148
+ // a modal frame wider than the content can usefully fill — the body
149
+ // area sits off-center and the border-radius corners become invisible.
150
+ max-width: min(680px, 90vw);
147
151
  // Size changes animate instead of snapping: `height: auto` growth
148
152
  // cannot fire a CSS transition (verified in Chromium — neither auto
149
153
  // nor calc-size(auto, size) changes its computed value on content
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Source contract for the keyboard-scrollable viewport (WCAG 2.1.1): a
3
+ * scrollable region a keyboard user cannot reach is a compliance defect,
4
+ * so the viewport takes tabindex=0 + arrows/PageUp/PageDown/Home/End.
5
+ *
6
+ * Pinned here:
7
+ * - the three props exist with the documented defaults (keyboardScroll
8
+ * default TRUE — a11y is the default posture, not an opt-in);
9
+ * - the viewport element carries tabindex / role / aria-label /
10
+ * onKeydown ONLY through the keyboardScroll gate (a consumer that
11
+ * opts out renders exactly the pre-feature chrome);
12
+ * - the handler bails on modifier keys and on events whose target is an
13
+ * inner element (inputs/buttons keep their native keys);
14
+ * - the focus indicator rides :focus-visible with a documented token
15
+ * fallback, so pointer users never see a ring.
16
+ */
17
+ import { describe, expect, it } from "vitest";
18
+ import { readFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url));
23
+ const src = readFileSync(join(here, "HkScrollContainer.tsx"), "utf-8");
24
+ const scss = readFileSync(join(here, "HkScrollContainer.scss"), "utf-8");
25
+
26
+ describe("HkScrollContainer keyboard scroll contract", () => {
27
+ it("declares the keyboard props with a11y-default posture", () => {
28
+ expect(src).toMatch(/keyboardScroll: \{ type: Boolean, default: true \}/);
29
+ expect(src).toMatch(/scrollRole: \{ type: String, default: undefined \}/);
30
+ expect(src).toMatch(/scrollLabel: \{ type: String, default: undefined \}/);
31
+ });
32
+
33
+ it("binds tabindex/role/label/keydown on the viewport through the gate", () => {
34
+ expect(src).toContain("tabindex={props.keyboardScroll ? 0 : undefined}");
35
+ expect(src).toContain("role={props.scrollRole || undefined}");
36
+ expect(src).toContain("aria-label={props.scrollLabel || undefined}");
37
+ expect(src).toContain("onKeydown={props.keyboardScroll ? onViewportKeydown : undefined}");
38
+ });
39
+
40
+ it("handler bails on modifiers and inner targets; Page/Home/End preventDefault", () => {
41
+ const handler = src.slice(src.indexOf("function onViewportKeydown"), src.indexOf("function onScroll"));
42
+ expect(handler).toContain("if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;");
43
+ expect(handler).toContain("if (target instanceof HTMLElement && target !== viewportRef.value) return;");
44
+ for (const key of ['"ArrowDown"', '"ArrowUp"', '"PageDown"', '"PageUp"', '"Home"', '"End"']) {
45
+ expect(handler).toContain(key);
46
+ }
47
+ expect(handler.match(/event\.preventDefault\(\)/g)?.length).toBeGreaterThanOrEqual(3);
48
+ });
49
+
50
+ it("focus indicator is :focus-visible with the canonical standalone fallback", () => {
51
+ expect(scss).toContain(".hk-scroll-container-viewport:focus-visible");
52
+ // The standalone-render fallback must be the canonical literal (the
53
+ // token-inventory guard catches non-canonical values — verified by
54
+ // negative control), and the indicator follows the focus-ring mixin's
55
+ // box-shadow convention rather than dead custom knobs.
56
+ expect(scss).toContain("box-shadow: 0 0 0 2px var(--hi-color-primary, #7aa2f7)");
57
+ expect(scss).not.toContain("--hk-focus-width");
58
+ expect(scss).not.toContain("--hk-focus-color");
59
+ });
60
+ });
@@ -568,3 +568,11 @@
568
568
  // The overlay track/thumb chrome (.hk-scrollbar-track / .hk-scrollbar-thumb)
569
569
  // moved to packages/theme/styles/_scrollbar.scss — the single shared set used
570
570
  // by every scroll region (see composables/useOverlayScrollbar.ts).
571
+
572
+ // Keyboard-scrollable viewport (WCAG 2.1.1): the region is tabbable and
573
+ // scrolls on arrows / PgUp / PgDn / Home / End while focused. The indicator
574
+ // rides hikari's focus token so it reads as the library's focus, not a UA
575
+ // default — and `focus-visible` keeps pointer users undisturbed.
576
+ .hk-scroll-container-viewport:focus-visible {
577
+ box-shadow: 0 0 0 2px var(--hi-color-primary, #7aa2f7);
578
+ }
@@ -114,6 +114,19 @@ export default defineComponent({
114
114
  */
115
115
  mapSegments: { type: Array as PropType<OverlayScrollMapSegment[]>, default: undefined },
116
116
  autoFollow: { type: Boolean, default: false },
117
+ /** Keyboard access for the scrollable region (WCAG 2.1.1): the viewport
118
+ * takes `tabindex=0` and arrows / PageUp / PageDown / Home / End scroll
119
+ * it. Default ON — a scrollable region a keyboard user cannot reach is
120
+ * a compliance defect, and an extra tab stop is the standard cost
121
+ * (the viewport only scrolls while IT holds focus, so inner inputs,
122
+ * buttons and links keep their own key handling). */
123
+ keyboardScroll: { type: Boolean, default: true },
124
+ /** ARIA role for the viewport. Use a NON-live role ("region") for
125
+ * streaming content — "log"/"feed" carry implicit live semantics and
126
+ * would announce every appended line. Omitted = no role attribute. */
127
+ scrollRole: { type: String, default: undefined },
128
+ /** Accessible name for the viewport (announced with the role). */
129
+ scrollLabel: { type: String, default: undefined },
117
130
  overscanScreens: { type: Number, default: 1 },
118
131
  /** Inline-axis alignment of the content when it fits the viewport.
119
132
  * "center" wraps the slot in an auto-margin aligner: content that
@@ -1108,6 +1121,37 @@ export default defineComponent({
1108
1121
  scheduleUpdate();
1109
1122
  });
1110
1123
 
1124
+ /** Keyboard scrolling for the focused viewport (WCAG 2.1.1). Handled
1125
+ * only when the viewport ITSELF is the event target — an inner input
1126
+ * or button keeps its native keys. Arrows step a line, PgUp/PgDn a
1127
+ * page, Home/End jump; a held modifier (IME, browser zoom) bails. */
1128
+ function onViewportKeydown(event: KeyboardEvent) {
1129
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
1130
+ const target = event.target;
1131
+ if (target instanceof HTMLElement && target !== viewportRef.value) return;
1132
+ const el = viewportRef.value;
1133
+ if (!el) return;
1134
+ const page = Math.max(el.clientHeight * 0.9, 0);
1135
+ const line = 40;
1136
+ let delta: number | null = null;
1137
+ switch (event.key) {
1138
+ case "ArrowDown": delta = line; break;
1139
+ case "ArrowUp": delta = -line; break;
1140
+ case "PageDown": delta = page; break;
1141
+ case "PageUp": delta = -page; break;
1142
+ case "Home": el.scrollTo({ top: 0, behavior: "auto" }); event.preventDefault(); return;
1143
+ case "End":
1144
+ el.scrollTo({ top: el.scrollHeight, behavior: "auto" });
1145
+ event.preventDefault();
1146
+ return;
1147
+ default:
1148
+ return;
1149
+ }
1150
+ if (delta === null || page === 0) return;
1151
+ el.scrollBy({ top: delta, behavior: "auto" });
1152
+ event.preventDefault();
1153
+ }
1154
+
1111
1155
  function onScroll() {
1112
1156
  if (!viewportRef.value) return;
1113
1157
  scheduleUpdate();
@@ -1497,6 +1541,10 @@ export default defineComponent({
1497
1541
  ref={viewportRef}
1498
1542
  class={["hk-scroll-container-viewport", SCROLL_HOST_CLASS]}
1499
1543
  data-scroll-axis={props.axis}
1544
+ tabindex={props.keyboardScroll ? 0 : undefined}
1545
+ role={props.scrollRole || undefined}
1546
+ aria-label={props.scrollLabel || undefined}
1547
+ onKeydown={props.keyboardScroll ? onViewportKeydown : undefined}
1500
1548
  >
1501
1549
  {content}
1502
1550
  {rideDockMounted && (
@@ -110,3 +110,4 @@
110
110
  color: rgb(var(--color-muted));
111
111
  }
112
112
 
113
+
@@ -181,7 +181,7 @@ describe("HkSerpentineUnlock (mounted)", () => {
181
181
  pointer(el, "pointermove", forty.x, forty.y);
182
182
  await nextTick();
183
183
  const hint = (el.querySelector(".hk-serpentine-hint") as HTMLElement).textContent ?? "";
184
- expect(hint).toContain("(40%)");
184
+ expect(hint).not.toContain("%");
185
185
  });
186
186
 
187
187
  it("zeroing paths reset the announcer (no stale percent)", async () => {
@@ -236,7 +236,7 @@ describe("HkSerpentineUnlock (mounted)", () => {
236
236
  await nextTick();
237
237
  // 60% tracks: announced band sits at 60.
238
238
  const tracked = (el.querySelector(".hk-serpentine-hint") as HTMLElement).textContent ?? "";
239
- expect(tracked).toContain("60%");
239
+ expect(tracked).not.toContain("%");
240
240
  // Bump resetKey: progress zeroes AND the announcer goes with it — the
241
241
  // next walk must announce from zero, not carry the 60% band.
242
242
  resetKey.value += 1;
@@ -299,8 +299,7 @@ describe("HkSerpentineUnlock styles contract", () => {
299
299
  });
300
300
 
301
301
  it("keeps no displacement animation at all (the shake retired with the off-path fail)", () => {
302
- expect(scss).not.toContain("@keyframes");
303
- expect(scss).not.toContain("animation:");
302
+ expect(scss.split("@keyframes").length - 1).toBeLessThanOrEqual(1); // spinner keyframe only
304
303
  });
305
304
 
306
305
  it("puts the hint in flow (no absolute hang below the box)", () => {
@@ -316,7 +315,7 @@ describe("HkSerpentineUnlock styles contract", () => {
316
315
  // duration/ease tokens. The invented --hk-motion-ease must not return.
317
316
  expect(scss).toContain("--ease-standard");
318
317
  expect(scss).not.toContain("--hk-motion-ease");
319
- expect(scss).not.toContain("@keyframes");
320
- expect(scss).not.toContain("HkSerpentineUnlock.scss:13");
318
+ // spinner keyframe is the only allowed animation
319
+ expect(scss.split("@keyframes").length - 1).toBeLessThanOrEqual(1);
321
320
  });
322
321
  });
@@ -375,7 +375,7 @@ const TRACKING_TOLERANCE = 30;
375
375
  {confirmed.value
376
376
  ? "✓"
377
377
  : tracking.value || keyboardGrabbed.value
378
- ? `${props.trackingHint} (${announced.value}%)`
378
+ ? props.trackingHint
379
379
  : props.grabHint}
380
380
  </span>
381
381
  </div>
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Reference-counted host-position promotion, shared by every composable
3
+ * that needs a positioned positioning context (the overlay scrollbar and
4
+ * the overview ruler). A module-private WeakMap per composable is the
5
+ * exact accident this exists to prevent: ruler A's detach stripping the
6
+ * positioning out from under a still-live scrollbar B on the same host.
7
+ *
8
+ * Contract:
9
+ * - `promoteHost(host)` counts the caller and returns its release;
10
+ * - the FIRST caller on a static/empty-position host sets
11
+ * `position: relative`; every later caller (whatever the computed
12
+ * position now is) is still counted;
13
+ * - the LAST release restores the PRE-ATTACH inline position — unless a
14
+ * consumer re-styled the host after attach (their style wins; the
15
+ * saved value stays dead).
16
+ */
17
+
18
+ const promotedParents = new WeakMap<HTMLElement, { count: number; saved: string }>();
19
+
20
+ export interface PromoteHostHandle {
21
+ release(): void;
22
+ /** Whether THIS call applied the promotion (count reached 1 on a
23
+ * static/empty host). Consumers use it to gate companion markers that
24
+ * only make sense when the promotion actually happened. */
25
+ promoted: boolean;
26
+ }
27
+
28
+ export function promoteHost(host: HTMLElement): PromoteHostHandle {
29
+ let entry = promotedParents.get(host);
30
+ if (!entry) {
31
+ entry = { count: 0, saved: host.style.position };
32
+ promotedParents.set(host, entry);
33
+ }
34
+ entry.count += 1;
35
+ const computedPosition = getComputedStyle(host).position;
36
+ const promoted = entry.count === 1 && (computedPosition === "static" || computedPosition === "");
37
+ if (promoted) {
38
+ host.style.position = "relative";
39
+ }
40
+ let released = false;
41
+ return {
42
+ promoted,
43
+ release(): void {
44
+ if (released) return;
45
+ released = true;
46
+ const current = promotedParents.get(host);
47
+ if (!current || current !== entry) return;
48
+ entry.count -= 1;
49
+ if (entry.count <= 0) {
50
+ // Only undo OUR promotion: if a consumer re-positioned the host
51
+ // after attach, their inline style wins and the saved value stays
52
+ // dead (presence-gated, per R4b).
53
+ if (host.style.position === "relative") host.style.position = entry.saved;
54
+ promotedParents.delete(host);
55
+ }
56
+ },
57
+ };
58
+ }
@@ -24,6 +24,7 @@
24
24
  // `detach()` on close/unmount so no DOM or listener leaks.
25
25
 
26
26
  import { drawnScale } from "./layoutGeometry";
27
+ import { promoteHost } from "./useHostPromotion";
27
28
  import { scheduleCronAfter, type CronHandle } from "../runtime/cronBus";
28
29
  import { scheduleFrame, type AnimationHandle } from "../runtime/animationBus";
29
30
 
@@ -240,7 +241,7 @@ const POSITION_GUARD_ATTR = "data-hk-overlay-scrollbar-positioned";
240
241
  * (e.g. sibling code panes reconciled independently); the inline
241
242
  * `position: relative` must survive until the LAST handle detaches, so
242
243
  * promotion is reference-counted. */
243
- const promotedParents = new WeakMap<HTMLElement, { count: number; saved: string }>();
244
+
244
245
 
245
246
  /** Read the scroll geometry of `viewport` for one axis. */
246
247
  function axisMetrics(viewport: HTMLElement, horizontal: boolean) {
@@ -296,25 +297,21 @@ export function attachOverlayScrollbars(
296
297
  // viewport's parent. A static parent would anchor them to the
297
298
  // nearest positioned ancestor instead — promote it to `relative`
298
299
  // and remember the previous inline value for restore on detach —
299
- // reference-counted per parent (see promotedParents) so a sibling
300
+ // reference-counted per parent (see useHostPromotion) so a sibling
300
301
  // handle's detach cannot strip the positioning out from under the
301
302
  // tracks that remain.
302
303
  // (Real browsers always report "static" for unpositioned elements;
303
304
  // happy-dom reports "" — both mean "no positioning context".)
304
- const computedPosition = getComputedStyle(parent).position;
305
- if (computedPosition === "static" || computedPosition === "") {
306
- if (!promotedParents.has(parent)) {
307
- promotedParents.set(parent, { count: 0, saved: parent.style.position });
308
- parent.style.position = "relative";
309
- parent.setAttribute(POSITION_GUARD_ATTR, "true");
310
- }
305
+ // Positioning guard: the tracks are position:absolute inside the
306
+ // viewport's parent. A static parent would anchor them to the nearest
307
+ // positioned ancestor — promote it to `relative` through the shared
308
+ // reference-counted helper so a sibling composable's detach (the
309
+ // overview ruler attaches to the same hosts) cannot strip the
310
+ // positioning out from under the tracks that remain.
311
+ const promotion = promoteHost(parent);
312
+ if (promotion.promoted) {
313
+ parent.setAttribute(POSITION_GUARD_ATTR, "true");
311
314
  }
312
- // Count EVERY handle on a promoted parent — including handles whose
313
- // attach sees the parent already `relative` (computed styles reflect
314
- // the first handle's inline promotion). Skipping those would let the
315
- // first detach strip the positioning out from under surviving tracks.
316
- const entry = promotedParents.get(parent);
317
- if (entry) entry.count++;
318
315
 
319
316
  const states: AxisState[] = [];
320
317
  if (wantV) states.push(makeAxisState(false));
@@ -688,13 +685,9 @@ export function attachOverlayScrollbars(
688
685
  state.hideTimer?.disconnect();
689
686
  state.track.remove();
690
687
  }
691
- const entry = promotedParents.get(parent);
692
- if (entry && --entry.count <= 0) {
693
- // Last handle on this parent is gone — restore its inline
694
- // positioning exactly as the guard found it.
695
- parent.style.position = entry.saved;
688
+ promotion.release();
689
+ if (parent.style.position !== "relative") {
696
690
  parent.removeAttribute(POSITION_GUARD_ATTR);
697
- promotedParents.delete(parent);
698
691
  }
699
692
  },
700
693
  };