@celestia-island/hikari 0.55.368 → 0.55.370
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.
- package/package.json +1 -1
- package/src/animation/registerAnimations.ts +6 -0
- package/src/components/HkDebugFloat.scss +145 -0
- package/src/components/HkDebugFloat.test.tsx +418 -0
- package/src/components/HkDebugFloat.tsx +292 -0
- package/src/components/HkEmergencyAlert.layering.contract.test.ts +99 -0
- package/src/components/HkEmergencyAlert.scss +279 -0
- package/src/components/HkEmergencyAlert.test.tsx +249 -0
- package/src/components/HkEmergencyAlert.tsx +232 -0
- package/src/components/debugFloat.ts +128 -0
- package/src/i18n/locales/ar/components.json +6 -1
- package/src/i18n/locales/de/components.json +6 -1
- package/src/i18n/locales/en/components.json +6 -1
- package/src/i18n/locales/es/components.json +6 -1
- package/src/i18n/locales/fr/components.json +6 -1
- package/src/i18n/locales/ja/components.json +6 -1
- package/src/i18n/locales/ko/components.json +6 -1
- package/src/i18n/locales/pt/components.json +6 -1
- package/src/i18n/locales/ru/components.json +6 -1
- package/src/i18n/locales/zh-Hans/components.json +6 -1
- package/src/i18n/locales/zh-Hant/components.json +6 -1
- package/src/i18n/usageSurface.test.ts +6 -0
- package/src/index.ts +21 -0
- package/src/overlay/hudRoot.ts +1 -0
- package/src/overlay/overlayRoot.styles.test.ts +19 -0
- package/src/overlay/overlayRoot.ts +1 -1
- package/src/plugins/boot-recovery.details.test.ts +1 -1
- package/src/plugins/boot-recovery.diagnostics.test.ts +1 -1
- package/src/plugins/boot-recovery.locales.test.ts +1 -1
- package/src/plugins/bootLandingCss.js +1 -1
- package/src/runtime/index.ts +1 -0
- package/src/runtime/useEmergencyAlert.test.ts +121 -0
- package/src/runtime/useEmergencyAlert.ts +219 -0
- package/src/scale.scss +12 -1
- package/src/styles/theme/scale.scss +12 -1
package/package.json
CHANGED
|
@@ -151,3 +151,9 @@ registerCssAnimation("hk-badge-dot-pulse", { infinite: true });
|
|
|
151
151
|
// Reduced motion keeps the band and drops the loop (house pattern, see
|
|
152
152
|
// HkSkeleton); the global CSS-animation switch pauses it as usual.
|
|
153
153
|
registerCssAnimation("hk-edge-glow-breathe", { infinite: true });
|
|
154
|
+
// components/HkEmergencyAlert.scss — the takeover band's steady-state
|
|
155
|
+
// life signs: the tone badge breathe and the hairline edge signal pulse
|
|
156
|
+
// (both loop forever while the alert stands). Reduced motion keeps the
|
|
157
|
+
// band and drops the loops (house pattern, see HkSkeleton).
|
|
158
|
+
registerCssAnimation("hk-emergency-breathe", { infinite: true });
|
|
159
|
+
registerCssAnimation("hk-emergency-signal", { infinite: true });
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* HkDebugFloat — generic debug floating window (HUD grammar).
|
|
5
|
+
*
|
|
6
|
+
* The wowsp idiom this window ports: a HUD card that turns SEMI-TRANSPARENT
|
|
7
|
+
* while the pointer is over it (`&:hover { opacity: 0.8 }` on the
|
|
8
|
+
* HoloScorebar/HoloShipCard family), so it stops competing with the
|
|
9
|
+
* content it measures and yields the visual field back to the page. The
|
|
10
|
+
* hovered opacity is prop-tunable (--hk-debug-float-hover-opacity, inline
|
|
11
|
+
* from the `hoverOpacity` prop); data-hovered mirrors :hover for the
|
|
12
|
+
* runtime tests and for pen/touch engines where :hover is sticky.
|
|
13
|
+
*
|
|
14
|
+
* Every ink hangs off hikari's theme tokens (no hardcoded colors); the
|
|
15
|
+
* body is compact mono with tabular figures so debug numbers line up.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
@use "../styles/polyfill" as *;
|
|
19
|
+
|
|
20
|
+
.hk-debug-float {
|
|
21
|
+
/* Document-space debug band: above every content-chrome rung, strictly
|
|
22
|
+
* below #hk-overlay-root (--hk-z-overlay-root, 90000) so every
|
|
23
|
+
* functional popup — modal, drawer, toast, tooltip — paints above the
|
|
24
|
+
* debug window. The band lives in scale.scss; the constant behind the
|
|
25
|
+
* fallback is HK_DEBUG_FLOAT_DOCUMENT_Z (kept honest by the test). */
|
|
26
|
+
z-index: var(--hk-z-debug-float, 80000);
|
|
27
|
+
|
|
28
|
+
position: fixed;
|
|
29
|
+
min-width: 0;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
border: 1px solid var(--border-faint);
|
|
32
|
+
border-radius: var(--radius-sm);
|
|
33
|
+
background: rgb(var(--color-surface) / 0.82);
|
|
34
|
+
box-shadow: var(--shadow-dropdown);
|
|
35
|
+
color: rgb(var(--color-text));
|
|
36
|
+
font-size: var(--text-xs);
|
|
37
|
+
/* A debug HUD is a numbers surface: mono face, tabular figures, so
|
|
38
|
+
* FPS/counters keep their columns while values tick (the wowsp
|
|
39
|
+
* scorebar's font-variant-numeric contract). */
|
|
40
|
+
font-family: var(--font-mono);
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
line-height: 1.45;
|
|
43
|
+
/* The window catches pointers ONLY on itself — it is never an
|
|
44
|
+
* inset-0 overlay, so clicks outside its box land on the page. */
|
|
45
|
+
pointer-events: auto;
|
|
46
|
+
touch-action: none;
|
|
47
|
+
|
|
48
|
+
/* Hover → yield: the pointer over the HUD drops it to the translucent
|
|
49
|
+
* state so the measured content reads through it (~150ms, opacity only
|
|
50
|
+
* — nothing moves). hoverOpacity flows in as an inline custom
|
|
51
|
+
* property; 0.45 is the wowsp-derived default. */
|
|
52
|
+
opacity: 1;
|
|
53
|
+
transition: opacity var(--duration-short) ease;
|
|
54
|
+
|
|
55
|
+
&:hover,
|
|
56
|
+
&[data-hovered] {
|
|
57
|
+
opacity: var(--hk-debug-float-hover-opacity, 0.45);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Drag exception: while the user is GRABBING the window it must stay
|
|
61
|
+
* fully opaque — fading mid-grab hides what the hand is holding. */
|
|
62
|
+
&[data-dragging] {
|
|
63
|
+
opacity: 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* ---------- corner anchoring (pre-drag) ----------
|
|
68
|
+
* Physical corners on purpose: the `position` prop is named physically
|
|
69
|
+
* and the window is a viewport HUD, not in-flow content (HkFloatingLayer's
|
|
70
|
+
* precedent). Safe-area-aware like the HkFab/HkFloatingLayer insets. */
|
|
71
|
+
.hk-debug-float {
|
|
72
|
+
&[data-corner="top-left"] {
|
|
73
|
+
top: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-top, 0px));
|
|
74
|
+
left: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-left, 0px));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&[data-corner="top-right"] {
|
|
78
|
+
top: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-top, 0px));
|
|
79
|
+
right: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-right, 0px));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&[data-corner="bottom-left"] {
|
|
83
|
+
bottom: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-bottom, 0px));
|
|
84
|
+
left: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-left, 0px));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&[data-corner="bottom-right"] {
|
|
88
|
+
bottom: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-bottom, 0px));
|
|
89
|
+
right: max(var(--hk-debug-float-offset, 16px), env(safe-area-inset-right, 0px));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ---------- header (drag handle) ---------- */
|
|
94
|
+
.hk-debug-float [data-el="header"] {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: space-between;
|
|
98
|
+
gap: var(--space-8);
|
|
99
|
+
padding: var(--space-4) var(--space-8) var(--space-4) var(--space-10);
|
|
100
|
+
border-bottom: 1px solid var(--border-faint);
|
|
101
|
+
background: rgb(var(--color-muted) / 8%);
|
|
102
|
+
cursor: grab;
|
|
103
|
+
/* The handle owns the drag gesture — mobile browsers must not fire
|
|
104
|
+
* pointercancel and scroll the page instead (HkMinimap precedent). */
|
|
105
|
+
touch-action: none;
|
|
106
|
+
@include user-select(none);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.hk-debug-float[data-dragging] [data-el="header"] {
|
|
110
|
+
cursor: grabbing;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.hk-debug-float [data-el="title"] {
|
|
114
|
+
font-size: var(--text-2xs);
|
|
115
|
+
font-weight: 600;
|
|
116
|
+
letter-spacing: 0.04em;
|
|
117
|
+
text-transform: uppercase;
|
|
118
|
+
color: rgb(var(--color-muted));
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
text-overflow: ellipsis;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* ---------- body (slot content) ---------- */
|
|
125
|
+
.hk-debug-float [data-el="body"] {
|
|
126
|
+
padding: var(--space-8);
|
|
127
|
+
/* A fat debug dump must never cover the viewport: cap and scroll.
|
|
128
|
+
* Bar-less HUD scroller (nativeScrollbar contract): the bar stays
|
|
129
|
+
* hidden, wheel/touch/keyboard still scroll. */
|
|
130
|
+
max-height: 40vh;
|
|
131
|
+
overflow: auto;
|
|
132
|
+
overscroll-behavior: contain;
|
|
133
|
+
scrollbar-width: none;
|
|
134
|
+
|
|
135
|
+
&::-webkit-scrollbar {
|
|
136
|
+
display: none;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* ---------- close ---------- */
|
|
141
|
+
/* The close affordance rides the STANDARD icon button at the 24 rung
|
|
142
|
+
* (close-button family contract) with the seat class for this window. */
|
|
143
|
+
.hk-debug-float-close {
|
|
144
|
+
flex-shrink: 0;
|
|
145
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { compile } from "sass";
|
|
7
|
+
import { dirname, resolve } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
import HkDebugFloat from "./HkDebugFloat";
|
|
11
|
+
import {
|
|
12
|
+
clampDebugFloatPosition,
|
|
13
|
+
debugFloatStorageKey,
|
|
14
|
+
HK_DEBUG_FLOAT_DOCUMENT_Z,
|
|
15
|
+
} from "./debugFloat";
|
|
16
|
+
|
|
17
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
18
|
+
|
|
19
|
+
function mount(renderNode: () => ReturnType<typeof h>) {
|
|
20
|
+
const container = document.createElement("div");
|
|
21
|
+
document.body.appendChild(container);
|
|
22
|
+
const app = createApp({ render: renderNode });
|
|
23
|
+
app.mount(container);
|
|
24
|
+
mounts.push({ app, container });
|
|
25
|
+
return container;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The live teleported window (HkDebugFloat renders INTO document.body,
|
|
29
|
+
* never into the mount container). */
|
|
30
|
+
function floatWindow(): HTMLElement | null {
|
|
31
|
+
return document.body.querySelector<HTMLElement>(".hk-debug-float");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function dispatchMouse(type: string, target: EventTarget, init: MouseEventInit = {}): void {
|
|
35
|
+
target.dispatchEvent(new MouseEvent(type, { bubbles: true, ...init }));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
40
|
+
app.unmount();
|
|
41
|
+
container.remove();
|
|
42
|
+
}
|
|
43
|
+
localStorage.clear();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Vitest stubs CSS, so the runtime suite can never catch a lost rule —
|
|
47
|
+
// the hover-fade and band contracts are additionally pinned by the
|
|
48
|
+
// compiled stylesheet guard at the bottom of this file (HkBadge pulse
|
|
49
|
+
// pattern).
|
|
50
|
+
describe("HkDebugFloat", () => {
|
|
51
|
+
it("teleports the window to body — never inside the mount container", () => {
|
|
52
|
+
const c = mount(() => h(HkDebugFloat, null, () => "fps 60"));
|
|
53
|
+
expect(document.body.querySelector(".hk-debug-float")).toBeTruthy();
|
|
54
|
+
expect(c.querySelector(".hk-debug-float")).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("renders the slot content", () => {
|
|
58
|
+
mount(() => h(HkDebugFloat, null, () => "fps 60"));
|
|
59
|
+
expect(document.body.querySelector(".hk-debug-float [data-el='body']")!.textContent).toContain(
|
|
60
|
+
"fps 60",
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("defaults the header to the localized DEBUG label", () => {
|
|
65
|
+
// The en bundle loads eagerly, so the two-arg t() fallback doubles as
|
|
66
|
+
// the assertion's expected string — no i18n test setup (HkLoadMore).
|
|
67
|
+
mount(() => h(HkDebugFloat));
|
|
68
|
+
expect(document.body.querySelector("[data-el='title']")!.textContent).toBe("DEBUG");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("lets the title prop override the default", () => {
|
|
72
|
+
mount(() => h(HkDebugFloat, { title: "CACHE" }));
|
|
73
|
+
expect(document.body.querySelector("[data-el='title']")!.textContent).toBe("CACHE");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("lets the title slot override everything", () => {
|
|
77
|
+
mount(() => h(HkDebugFloat, { title: "CACHE" }, { title: () => "SLOT" }));
|
|
78
|
+
expect(document.body.querySelector("[data-el='title']")!.textContent).toBe("SLOT");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("labels the window group with the title and the close button with Close", () => {
|
|
82
|
+
mount(() => h(HkDebugFloat));
|
|
83
|
+
const win = floatWindow()!;
|
|
84
|
+
expect(win.getAttribute("aria-label")).toBe("DEBUG");
|
|
85
|
+
const close = win.querySelector("button.hk-icon-button")!;
|
|
86
|
+
expect(close.getAttribute("aria-label")).toBe("Close");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("reflects the position prop as the corner anchor", () => {
|
|
90
|
+
mount(() => h(HkDebugFloat, { position: "top-left" }));
|
|
91
|
+
expect(floatWindow()!.getAttribute("data-corner")).toBe("top-left");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("anchors to bottom-right by default", () => {
|
|
95
|
+
mount(() => h(HkDebugFloat));
|
|
96
|
+
expect(floatWindow()!.getAttribute("data-corner")).toBe("bottom-right");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("wires width, offset and hover opacity as inline custom properties", () => {
|
|
100
|
+
mount(() => h(HkDebugFloat, { width: 320, offset: 8, hoverOpacity: 0.2 }));
|
|
101
|
+
const win = floatWindow()!;
|
|
102
|
+
expect(win.style.width).toBe("320px");
|
|
103
|
+
expect(win.style.getPropertyValue("--hk-debug-float-offset")).toBe("8px");
|
|
104
|
+
expect(win.style.getPropertyValue("--hk-debug-float-hover-opacity")).toBe("0.2");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("defaults the z-index to the debug band (below every functional popup)", () => {
|
|
108
|
+
mount(() => h(HkDebugFloat));
|
|
109
|
+
expect(floatWindow()!.style.zIndex).toBe(String(HK_DEBUG_FLOAT_DOCUMENT_Z));
|
|
110
|
+
expect(floatWindow()!.style.zIndex).toBe("80000");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("honors an explicit zIndex override", () => {
|
|
114
|
+
mount(() => h(HkDebugFloat, { zIndex: 42 }));
|
|
115
|
+
expect(floatWindow()!.style.zIndex).toBe("42");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("flips the hovered state on pointerenter and back on pointerleave", async () => {
|
|
119
|
+
mount(() => h(HkDebugFloat));
|
|
120
|
+
const win = floatWindow()!;
|
|
121
|
+
expect(win.hasAttribute("data-hovered")).toBe(false);
|
|
122
|
+
win.dispatchEvent(new Event("pointerenter"));
|
|
123
|
+
await nextTick();
|
|
124
|
+
expect(win.hasAttribute("data-hovered")).toBe(true);
|
|
125
|
+
win.dispatchEvent(new Event("pointerleave"));
|
|
126
|
+
await nextTick();
|
|
127
|
+
expect(win.hasAttribute("data-hovered")).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("close hides the window and emits update:open false (uncontrolled)", async () => {
|
|
131
|
+
const emitted: boolean[] = [];
|
|
132
|
+
mount(() =>
|
|
133
|
+
h(HkDebugFloat, {
|
|
134
|
+
"onUpdate:open": (v: boolean) => emitted.push(v),
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
const close = floatWindow()!.querySelector("button.hk-icon-button") as HTMLButtonElement;
|
|
138
|
+
close.click();
|
|
139
|
+
// The emit is synchronous; the unmount lands on the next tick.
|
|
140
|
+
expect(emitted).toEqual([false]);
|
|
141
|
+
await nextTick();
|
|
142
|
+
expect(floatWindow()).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("stays hidden on remount when a persistKey persisted the closed state", async () => {
|
|
146
|
+
mount(() => h(HkDebugFloat, { persistKey: "roundtrip" }));
|
|
147
|
+
(floatWindow()!.querySelector("button.hk-icon-button") as HTMLButtonElement).click();
|
|
148
|
+
await nextTick();
|
|
149
|
+
const raw = localStorage.getItem(debugFloatStorageKey("roundtrip"));
|
|
150
|
+
expect(raw).not.toBeNull();
|
|
151
|
+
expect(JSON.parse(raw!)).toMatchObject({ open: false });
|
|
152
|
+
|
|
153
|
+
// A fresh mount reads the same record and stays closed.
|
|
154
|
+
mount(() => h(HkDebugFloat, { persistKey: "roundtrip" }));
|
|
155
|
+
expect(floatWindow()).toBeNull();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("restores a persisted open state on remount", () => {
|
|
159
|
+
localStorage.setItem(debugFloatStorageKey("reopen"), JSON.stringify({ open: true }));
|
|
160
|
+
mount(() => h(HkDebugFloat, { persistKey: "reopen", defaultOpen: false }));
|
|
161
|
+
expect(floatWindow()).not.toBeNull();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("falls back to defaultOpen when nothing was persisted", () => {
|
|
165
|
+
mount(() => h(HkDebugFloat, { persistKey: "fresh", defaultOpen: false }));
|
|
166
|
+
expect(floatWindow()).toBeNull();
|
|
167
|
+
mount(() => h(HkDebugFloat, { persistKey: "fresh", defaultOpen: true }));
|
|
168
|
+
expect(floatWindow()).not.toBeNull();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("ignores corrupted persisted payloads instead of crashing", () => {
|
|
172
|
+
localStorage.setItem(debugFloatStorageKey("corrupt"), "{not json");
|
|
173
|
+
mount(() => h(HkDebugFloat, { persistKey: "corrupt" }));
|
|
174
|
+
expect(floatWindow()).not.toBeNull();
|
|
175
|
+
expect(floatWindow()!.style.left).toBe("");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("honors the controlled open prop over the internal state", () => {
|
|
179
|
+
mount(() => h(HkDebugFloat, { open: false }));
|
|
180
|
+
expect(floatWindow()).toBeNull();
|
|
181
|
+
mount(() => h(HkDebugFloat, { open: true }));
|
|
182
|
+
expect(floatWindow()).not.toBeNull();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("v-model round-trips: clicking close emits and a flipped prop hides", async () => {
|
|
186
|
+
const Host = defineComponent({
|
|
187
|
+
setup() {
|
|
188
|
+
const open = ref(true);
|
|
189
|
+
return () =>
|
|
190
|
+
h(HkDebugFloat, {
|
|
191
|
+
open: open.value,
|
|
192
|
+
"onUpdate:open": (v: boolean) => {
|
|
193
|
+
open.value = v;
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
mount(() => h(Host));
|
|
199
|
+
expect(floatWindow()).not.toBeNull();
|
|
200
|
+
(floatWindow()!.querySelector("button.hk-icon-button") as HTMLButtonElement).click();
|
|
201
|
+
await nextTick();
|
|
202
|
+
expect(floatWindow()).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("HkDebugFloat drag", () => {
|
|
207
|
+
it("moves the window with the header pointer sequence and clamps to the viewport", async () => {
|
|
208
|
+
mount(() => h(HkDebugFloat, { width: 280 }));
|
|
209
|
+
const win = floatWindow()!;
|
|
210
|
+
const header = win.querySelector("[data-el='header']")!;
|
|
211
|
+
|
|
212
|
+
dispatchMouse("pointerdown", header, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
213
|
+
await nextTick();
|
|
214
|
+
expect(win.hasAttribute("data-dragging")).toBe(true);
|
|
215
|
+
|
|
216
|
+
// happy-dom has no layout engine: rects read zero, so the first
|
|
217
|
+
// grab adopts origin (0,0) here — real browsers adopt the
|
|
218
|
+
// CSS-resolved corner spot (the component contract, exercised via
|
|
219
|
+
// the pure clamp helper below).
|
|
220
|
+
dispatchMouse("pointermove", header, { clientX: 140, clientY: 120, buttons: 1 });
|
|
221
|
+
await nextTick();
|
|
222
|
+
// A dragged position pins the top-left in px and kills the insets.
|
|
223
|
+
expect(win.style.left).toBe("40px");
|
|
224
|
+
expect(win.style.top).toBe("20px");
|
|
225
|
+
expect(win.style.right).toBe("auto");
|
|
226
|
+
expect(win.style.bottom).toBe("auto");
|
|
227
|
+
|
|
228
|
+
// Clamp: drag past the right/bottom edge of the 1024x768 viewport —
|
|
229
|
+
// the top-left never goes past the viewport box.
|
|
230
|
+
dispatchMouse("pointermove", header, { clientX: 5000, clientY: 5000, buttons: 1 });
|
|
231
|
+
await nextTick();
|
|
232
|
+
expect(Number.parseFloat(win.style.left)).toBeLessThanOrEqual(window.innerWidth);
|
|
233
|
+
expect(Number.parseFloat(win.style.top)).toBeLessThanOrEqual(window.innerHeight);
|
|
234
|
+
|
|
235
|
+
dispatchMouse("pointerup", header);
|
|
236
|
+
await nextTick();
|
|
237
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("persists the dropped position when a persistKey is set", async () => {
|
|
241
|
+
mount(() => h(HkDebugFloat, { persistKey: "dragpos", width: 280 }));
|
|
242
|
+
const win = floatWindow()!;
|
|
243
|
+
const header = win.querySelector("[data-el='header']")!;
|
|
244
|
+
dispatchMouse("pointerdown", header, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
245
|
+
dispatchMouse("pointermove", header, { clientX: 150, clientY: 120, buttons: 1 });
|
|
246
|
+
dispatchMouse("pointerup", header);
|
|
247
|
+
await nextTick();
|
|
248
|
+
|
|
249
|
+
const raw = localStorage.getItem(debugFloatStorageKey("dragpos"));
|
|
250
|
+
expect(raw).not.toBeNull();
|
|
251
|
+
// origin (0,0) + pointer delta (50, 20) from the (100,100) grab.
|
|
252
|
+
expect(JSON.parse(raw!)).toEqual({ open: true, x: 50, y: 20 });
|
|
253
|
+
expect(win.style.left).toBe("50px");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("restores a persisted position as an explicit top-left pin", () => {
|
|
257
|
+
localStorage.setItem(
|
|
258
|
+
debugFloatStorageKey("restore"),
|
|
259
|
+
JSON.stringify({ open: true, x: 40, y: 60 }),
|
|
260
|
+
);
|
|
261
|
+
mount(() => h(HkDebugFloat, { persistKey: "restore" }));
|
|
262
|
+
const win = floatWindow()!;
|
|
263
|
+
expect(win.style.left).toBe("40px");
|
|
264
|
+
expect(win.style.top).toBe("60px");
|
|
265
|
+
expect(win.style.right).toBe("auto");
|
|
266
|
+
expect(win.style.bottom).toBe("auto");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("clamps a restored position that no longer fits the viewport", () => {
|
|
270
|
+
localStorage.setItem(
|
|
271
|
+
debugFloatStorageKey("offscreen"),
|
|
272
|
+
JSON.stringify({ open: true, x: 9999, y: 9999 }),
|
|
273
|
+
);
|
|
274
|
+
mount(() => h(HkDebugFloat, { persistKey: "offscreen", width: 280 }));
|
|
275
|
+
const win = floatWindow()!;
|
|
276
|
+
// onMounted re-clamps against the rendered box and the viewport.
|
|
277
|
+
expect(win.getBoundingClientRect().right).toBeLessThanOrEqual(window.innerWidth);
|
|
278
|
+
expect(win.getBoundingClientRect().bottom).toBeLessThanOrEqual(window.innerHeight);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("ignores non-primary-button grabs and pointerdowns on the close button", () => {
|
|
282
|
+
mount(() => h(HkDebugFloat));
|
|
283
|
+
const win = floatWindow()!;
|
|
284
|
+
const header = win.querySelector("[data-el='header']")!;
|
|
285
|
+
|
|
286
|
+
dispatchMouse("pointerdown", header, { clientX: 100, clientY: 100, button: 2, buttons: 2 });
|
|
287
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
288
|
+
|
|
289
|
+
const close = win.querySelector("button.hk-icon-button")!;
|
|
290
|
+
dispatchMouse("pointerdown", close, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
291
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
292
|
+
// The close button also never starts a drag position.
|
|
293
|
+
expect(win.style.left).toBe("");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("a hover with no button held never moves the window", () => {
|
|
297
|
+
mount(() => h(HkDebugFloat));
|
|
298
|
+
const win = floatWindow()!;
|
|
299
|
+
const header = win.querySelector("[data-el='header']")!;
|
|
300
|
+
// moves with dragStart unset (no pointerdown) are no-ops…
|
|
301
|
+
dispatchMouse("pointermove", header, { clientX: 500, clientY: 500, buttons: 1 });
|
|
302
|
+
expect(win.style.left).toBe("");
|
|
303
|
+
// …and a stale start releases when the button is no longer held.
|
|
304
|
+
dispatchMouse("pointerdown", header, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
305
|
+
dispatchMouse("pointermove", header, { clientX: 140, clientY: 120, buttons: 0 });
|
|
306
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe("clampDebugFloatPosition", () => {
|
|
311
|
+
const VW = 1024;
|
|
312
|
+
const VH = 768;
|
|
313
|
+
|
|
314
|
+
it("keeps an in-range position untouched", () => {
|
|
315
|
+
expect(clampDebugFloatPosition(10, 20, 280, 200, VW, VH)).toEqual({ x: 10, y: 20 });
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("clamps negative offsets to the viewport origin", () => {
|
|
319
|
+
expect(clampDebugFloatPosition(-50, -1, 280, 200, VW, VH)).toEqual({ x: 0, y: 0 });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("clamps past-edge drags to the fully-visible box", () => {
|
|
323
|
+
expect(clampDebugFloatPosition(5000, 5000, 280, 200, VW, VH)).toEqual({
|
|
324
|
+
x: VW - 280,
|
|
325
|
+
y: VH - 200,
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("pins a degenerate oversized window to the origin instead of going negative", () => {
|
|
330
|
+
expect(clampDebugFloatPosition(30, 30, 2000, 2000, VW, VH)).toEqual({ x: 0, y: 0 });
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe("HkDebugFloat stylesheet contract", () => {
|
|
335
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
336
|
+
const css = compile(resolve(here, "HkDebugFloat.scss"), { style: "expanded" }).css;
|
|
337
|
+
const scale = readFileSync(resolve(here, "..", "scale.scss"), "utf8");
|
|
338
|
+
|
|
339
|
+
it("fades to the prop-driven opacity on hover (the wowsp HUD idiom)", () => {
|
|
340
|
+
// Sass compiles quoted attribute selectors unquoted ([data-hovered]).
|
|
341
|
+
expect(css).toMatch(
|
|
342
|
+
/\.hk-debug-float:hover,\s*\.hk-debug-float\[data-hovered\]\s*\{\s*opacity:\s*var\(--hk-debug-float-hover-opacity,\s*0\.45\);/,
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("runs the fade as an opacity-only ~150ms transition on the root", () => {
|
|
347
|
+
expect(css).toMatch(
|
|
348
|
+
/\.hk-debug-float\s*\{[^}]*transition:\s*opacity\s+var\(--duration-short\)/,
|
|
349
|
+
);
|
|
350
|
+
// Opacity-only: nothing about the fade may move layout.
|
|
351
|
+
expect(css).toMatch(/\.hk-debug-float\s*\{[^}]*transition:\s*opacity[^;]*;/);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("keeps the drag exception: a grabbed window stays opaque", () => {
|
|
355
|
+
expect(css).toMatch(/\.hk-debug-float\[data-dragging\]\s*\{\s*opacity:\s*1;/);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("pins the drag exception AFTER the hover rule (equal specificity — order is the cascade)", () => {
|
|
359
|
+
// `.hk-debug-float:hover`/`[data-hovered]` and `[data-dragging]` have
|
|
360
|
+
// EQUAL specificity (0,2,0): mid-grab both match (the pointer is captured
|
|
361
|
+
// over the header, so :hover holds and pointerleave cannot fire). Which
|
|
362
|
+
// rule wins is decided purely by source order — moving the drag exception
|
|
363
|
+
// above the hover rule fades the window mid-grab, and no runtime test
|
|
364
|
+
// exercises that co-occurrence (happy-dom has no real hover pipeline).
|
|
365
|
+
const hoverIdx = css.search(
|
|
366
|
+
/\.hk-debug-float:hover,\s*\.hk-debug-float\[data-hovered\]\s*\{/,
|
|
367
|
+
);
|
|
368
|
+
const dragIdx = css.search(/\.hk-debug-float\[data-dragging\]\s*\{/);
|
|
369
|
+
expect(hoverIdx).toBeGreaterThan(-1);
|
|
370
|
+
expect(dragIdx).toBeGreaterThan(hoverIdx);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("keeps scale.scss, the sheet fallback and the TS constant on one band", () => {
|
|
374
|
+
const band = scale.match(/--hk-z-debug-float:\s*(\d+)/);
|
|
375
|
+
// A missing match is a broken contract, not an empty pass.
|
|
376
|
+
expect(band).not.toBeNull();
|
|
377
|
+
expect(Number(band![1])).toBe(HK_DEBUG_FLOAT_DOCUMENT_Z);
|
|
378
|
+
expect(css).toContain(`z-index: var(--hk-z-debug-float, ${HK_DEBUG_FLOAT_DOCUMENT_Z});`);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("parks the band above content chrome and below every functional popup", () => {
|
|
382
|
+
const value = (name: string) => {
|
|
383
|
+
const m = scale.match(new RegExp(`--hk-z-${name}:\\s*(\\d+)`));
|
|
384
|
+
expect(m, `--hk-z-${name} must stay defined in scale.scss`).not.toBeNull();
|
|
385
|
+
return Number(m![1]);
|
|
386
|
+
};
|
|
387
|
+
const band = value("debug-float");
|
|
388
|
+
// Above every content-chrome rung (tooltip is the highest).
|
|
389
|
+
expect(band).toBeGreaterThan(value("tooltip"));
|
|
390
|
+
// Strictly below the fenced popup root: modals, drawers, toasts and
|
|
391
|
+
// tooltips all live inside #hk-overlay-root and must win over the
|
|
392
|
+
// debug window.
|
|
393
|
+
expect(band).toBeLessThan(value("overlay-root"));
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("never spans the viewport — pointers outside the window land on the page", () => {
|
|
397
|
+
const root = css.match(/\.hk-debug-float\s*\{[^}]*\}/)![0];
|
|
398
|
+
expect(root).not.toMatch(/inset\s*:/);
|
|
399
|
+
expect(root).toMatch(/pointer-events:\s*auto;/);
|
|
400
|
+
expect(css).not.toMatch(/\.hk-debug-float\s*\{[^}]*position:\s*absolute/);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("gives the header the grab affordances and the body the tabular mono face", () => {
|
|
404
|
+
expect(css).toMatch(/\.hk-debug-float \[data-el=header\]\s*\{[^}]*cursor:\s*grab;/);
|
|
405
|
+
expect(css).toMatch(/\.hk-debug-float \[data-el=header\]\s*\{[^}]*touch-action:\s*none;/);
|
|
406
|
+
expect(css).toMatch(
|
|
407
|
+
/\.hk-debug-float\[data-dragging\] \[data-el=header\]\s*\{[^}]*cursor:\s*grabbing;/,
|
|
408
|
+
);
|
|
409
|
+
expect(css).toMatch(/\.hk-debug-float\s*\{[^}]*font-family:\s*var\(--font-mono\);/);
|
|
410
|
+
expect(css).toMatch(/\.hk-debug-float\s*\{[^}]*font-variant-numeric:\s*tabular-nums;/);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("caps the body so a fat dump cannot cover the viewport", () => {
|
|
414
|
+
expect(css).toMatch(
|
|
415
|
+
/\.hk-debug-float \[data-el=body\]\s*\{[^}]*max-height:\s*40vh;[^}]*overflow:\s*auto;/,
|
|
416
|
+
);
|
|
417
|
+
});
|
|
418
|
+
});
|