@celestia-island/hikari 0.55.372 → 0.55.373
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/components/HkDebugFloat.scss +105 -15
- package/src/components/HkDebugFloat.test.tsx +428 -19
- package/src/components/HkDebugFloat.tsx +197 -36
- package/src/components/debugFloat.ts +24 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* from the `hoverOpacity` prop); data-hovered mirrors :hover for the
|
|
12
12
|
* runtime tests and for pen/touch engines where :hover is sticky.
|
|
13
13
|
*
|
|
14
|
+
* The fade lives on the `[data-el="fade"]` CARD, not the root: the hover
|
|
15
|
+
* chrome (`[data-el="overlay"]` — section chips, the headerless close) is
|
|
16
|
+
* a sibling of the card so the controls stay legible while the content
|
|
17
|
+
* dims — at a 0.15 hover dim a close button inside the fading subtree
|
|
18
|
+
* would fade out of reach together with the content it closes.
|
|
19
|
+
*
|
|
14
20
|
* Every ink hangs off hikari's theme tokens (no hardcoded colors); the
|
|
15
21
|
* body is compact mono with tabular figures so debug numbers line up.
|
|
16
22
|
*/
|
|
@@ -26,7 +32,22 @@
|
|
|
26
32
|
z-index: var(--hk-z-debug-float, 80000);
|
|
27
33
|
|
|
28
34
|
position: fixed;
|
|
29
|
-
|
|
35
|
+
/* The window catches pointers ONLY on itself — it is never an
|
|
36
|
+
* inset-0 overlay, so clicks outside its box land on the page. */
|
|
37
|
+
pointer-events: auto;
|
|
38
|
+
touch-action: none;
|
|
39
|
+
|
|
40
|
+
/* Content-sized seat (`width="auto"`): the window grows to its
|
|
41
|
+
* longest line (a `white-space: pre` mono dump) instead of clipping
|
|
42
|
+
* it, capped so a pathological line cannot span the viewport. */
|
|
43
|
+
&[data-auto-width] {
|
|
44
|
+
width: max-content;
|
|
45
|
+
max-width: calc(100vw - 2 * var(--hk-debug-float-offset, 16px));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* ---------- the card (visual chrome + the hover fade) ---------- */
|
|
50
|
+
.hk-debug-float [data-el="fade"] {
|
|
30
51
|
overflow: hidden;
|
|
31
52
|
border: 1px solid var(--border-faint);
|
|
32
53
|
border-radius: var(--radius-sm);
|
|
@@ -40,10 +61,6 @@
|
|
|
40
61
|
font-family: var(--font-mono);
|
|
41
62
|
font-variant-numeric: tabular-nums;
|
|
42
63
|
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
64
|
|
|
48
65
|
/* Hover → yield: the pointer over the HUD drops it to the translucent
|
|
49
66
|
* state so the measured content reads through it (~150ms, opacity only
|
|
@@ -51,17 +68,19 @@
|
|
|
51
68
|
* property; 0.45 is the wowsp-derived default. */
|
|
52
69
|
opacity: 1;
|
|
53
70
|
transition: opacity var(--duration-short) ease;
|
|
71
|
+
}
|
|
54
72
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
.hk-debug-float:hover [data-el="fade"],
|
|
74
|
+
.hk-debug-float[data-hovered] [data-el="fade"] {
|
|
75
|
+
opacity: var(--hk-debug-float-hover-opacity, 0.45);
|
|
76
|
+
}
|
|
59
77
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
/* Drag exception: while the user is GRABBING the window it must stay
|
|
79
|
+
* fully opaque — fading mid-grab hides what the hand holds. Equal
|
|
80
|
+
* specificity with the hover rule above: source order (this rule LAST)
|
|
81
|
+
* is the cascade. */
|
|
82
|
+
.hk-debug-float[data-dragging] [data-el="fade"] {
|
|
83
|
+
opacity: 1;
|
|
65
84
|
}
|
|
66
85
|
|
|
67
86
|
/* ---------- corner anchoring (pre-drag) ----------
|
|
@@ -90,7 +109,7 @@
|
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
/* ---------- header (drag handle) ---------- */
|
|
112
|
+
/* ---------- header (drag handle, headered chrome) ---------- */
|
|
94
113
|
.hk-debug-float [data-el="header"] {
|
|
95
114
|
display: flex;
|
|
96
115
|
align-items: center;
|
|
@@ -110,6 +129,16 @@
|
|
|
110
129
|
cursor: grabbing;
|
|
111
130
|
}
|
|
112
131
|
|
|
132
|
+
/* Headerless: the whole window is the handle. */
|
|
133
|
+
.hk-debug-float[data-chrome="none"] {
|
|
134
|
+
cursor: grab;
|
|
135
|
+
@include user-select(none);
|
|
136
|
+
|
|
137
|
+
&[data-dragging] {
|
|
138
|
+
cursor: grabbing;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
113
142
|
.hk-debug-float [data-el="title"] {
|
|
114
143
|
font-size: var(--text-2xs);
|
|
115
144
|
font-weight: 600;
|
|
@@ -137,6 +166,67 @@
|
|
|
137
166
|
}
|
|
138
167
|
}
|
|
139
168
|
|
|
169
|
+
/* ---------- hover chrome (section chips + headerless close) ----------
|
|
170
|
+
* Revealed ONLY while it is usable — hover, drag, or keyboard focus —
|
|
171
|
+
* and click-transparent otherwise (opacity alone would leave invisible
|
|
172
|
+
* buttons catching clicks). It never fades with the card: it is a
|
|
173
|
+
* sibling of [data-el="fade"], pinned INSIDE the window box (both
|
|
174
|
+
* insets + wrap): a chip row wider than the seat wraps instead of
|
|
175
|
+
* painting (and catching clicks) outside the window. */
|
|
176
|
+
.hk-debug-float [data-el="overlay"] {
|
|
177
|
+
position: absolute;
|
|
178
|
+
left: var(--space-4);
|
|
179
|
+
right: var(--space-4);
|
|
180
|
+
display: flex;
|
|
181
|
+
align-items: center;
|
|
182
|
+
justify-content: flex-end;
|
|
183
|
+
flex-wrap: wrap;
|
|
184
|
+
gap: var(--space-4);
|
|
185
|
+
opacity: 0;
|
|
186
|
+
pointer-events: none;
|
|
187
|
+
transition: opacity var(--duration-short) ease;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Headerless: no header bar, so the chrome owns the top edge... */
|
|
191
|
+
.hk-debug-float[data-chrome="none"] [data-el="overlay"] {
|
|
192
|
+
top: var(--space-4);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* ...headered: park it on the bottom edge — the header already has its
|
|
196
|
+
* own close button up top. */
|
|
197
|
+
.hk-debug-float[data-chrome="header"] [data-el="overlay"] {
|
|
198
|
+
bottom: var(--space-4);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.hk-debug-float:hover [data-el="overlay"],
|
|
202
|
+
.hk-debug-float[data-hovered] [data-el="overlay"],
|
|
203
|
+
.hk-debug-float[data-dragging] [data-el="overlay"],
|
|
204
|
+
.hk-debug-float:focus-within [data-el="overlay"] {
|
|
205
|
+
opacity: 1;
|
|
206
|
+
pointer-events: auto;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* Section toggle chip: a compact mono pill, on = section visible. */
|
|
210
|
+
.hk-debug-float [data-el="overlay"] .hk-debug-float-section {
|
|
211
|
+
flex-shrink: 0;
|
|
212
|
+
padding: var(--space-2) var(--space-6);
|
|
213
|
+
border: 1px solid var(--border-subtle);
|
|
214
|
+
border-radius: var(--radius-sm);
|
|
215
|
+
background: rgb(var(--color-surface) / 92%);
|
|
216
|
+
color: rgb(var(--color-muted));
|
|
217
|
+
font-family: var(--font-mono);
|
|
218
|
+
font-size: var(--text-2xs);
|
|
219
|
+
font-weight: 600;
|
|
220
|
+
letter-spacing: 0.04em;
|
|
221
|
+
cursor: pointer;
|
|
222
|
+
white-space: nowrap;
|
|
223
|
+
|
|
224
|
+
&[data-on] {
|
|
225
|
+
color: rgb(var(--color-text));
|
|
226
|
+
border-color: var(--border-input);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
140
230
|
/* ---------- close ---------- */
|
|
141
231
|
/* The close affordance rides the STANDARD icon button at the 24 rung
|
|
142
232
|
* (close-button family contract) with the seat class for this window. */
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
clampDebugFloatPosition,
|
|
13
13
|
debugFloatStorageKey,
|
|
14
14
|
HK_DEBUG_FLOAT_DOCUMENT_Z,
|
|
15
|
+
readDebugFloatPersisted,
|
|
15
16
|
} from "./debugFloat";
|
|
16
17
|
|
|
17
18
|
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
@@ -278,16 +279,21 @@ describe("HkDebugFloat drag", () => {
|
|
|
278
279
|
expect(win.getBoundingClientRect().bottom).toBeLessThanOrEqual(window.innerHeight);
|
|
279
280
|
});
|
|
280
281
|
|
|
281
|
-
it("ignores non-primary-button grabs and pointerdowns on the close button", () => {
|
|
282
|
+
it("ignores non-primary-button grabs and pointerdowns on the close button", async () => {
|
|
282
283
|
mount(() => h(HkDebugFloat));
|
|
283
284
|
const win = floatWindow()!;
|
|
284
285
|
const header = win.querySelector("[data-el='header']")!;
|
|
285
286
|
|
|
286
287
|
dispatchMouse("pointerdown", header, { clientX: 100, clientY: 100, button: 2, buttons: 2 });
|
|
288
|
+
// Vue patches the DOM on a microtask — without the tick the
|
|
289
|
+
// assertion reads the PRE-drag DOM and passes vacuously even when a
|
|
290
|
+
// drag started.
|
|
291
|
+
await nextTick();
|
|
287
292
|
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
288
293
|
|
|
289
294
|
const close = win.querySelector("button.hk-icon-button")!;
|
|
290
295
|
dispatchMouse("pointerdown", close, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
296
|
+
await nextTick();
|
|
291
297
|
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
292
298
|
// The close button also never starts a drag position.
|
|
293
299
|
expect(win.style.left).toBe("");
|
|
@@ -307,6 +313,39 @@ describe("HkDebugFloat drag", () => {
|
|
|
307
313
|
});
|
|
308
314
|
});
|
|
309
315
|
|
|
316
|
+
describe("readDebugFloatPersisted", () => {
|
|
317
|
+
it("parses a record that carries a hidden-section list", () => {
|
|
318
|
+
localStorage.setItem(
|
|
319
|
+
debugFloatStorageKey("unit-hidden"),
|
|
320
|
+
JSON.stringify({ open: true, x: 4, y: 5, hidden: ["gpu", "draws"] }),
|
|
321
|
+
);
|
|
322
|
+
expect(readDebugFloatPersisted("unit-hidden")).toEqual({
|
|
323
|
+
open: true,
|
|
324
|
+
x: 4,
|
|
325
|
+
y: 5,
|
|
326
|
+
hidden: ["gpu", "draws"],
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("rejects a non-array hidden list (corrupted payloads degrade to null)", () => {
|
|
331
|
+
localStorage.setItem(
|
|
332
|
+
debugFloatStorageKey("unit-bad-hidden"),
|
|
333
|
+
JSON.stringify({ open: true, hidden: "gpu" }),
|
|
334
|
+
);
|
|
335
|
+
expect(readDebugFloatPersisted("unit-bad-hidden")).toBeNull();
|
|
336
|
+
localStorage.setItem(
|
|
337
|
+
debugFloatStorageKey("unit-bad-hidden2"),
|
|
338
|
+
JSON.stringify({ open: true, hidden: ["gpu", 3] }),
|
|
339
|
+
);
|
|
340
|
+
expect(readDebugFloatPersisted("unit-bad-hidden2")).toBeNull();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("accepts a record with no hidden half (older writers)", () => {
|
|
344
|
+
localStorage.setItem(debugFloatStorageKey("unit-legacy"), JSON.stringify({ open: false }));
|
|
345
|
+
expect(readDebugFloatPersisted("unit-legacy")).toEqual({ open: false });
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
310
349
|
describe("clampDebugFloatPosition", () => {
|
|
311
350
|
const VW = 1024;
|
|
312
351
|
const VH = 768;
|
|
@@ -331,41 +370,357 @@ describe("clampDebugFloatPosition", () => {
|
|
|
331
370
|
});
|
|
332
371
|
});
|
|
333
372
|
|
|
373
|
+
describe("HkDebugFloat headerless chrome", () => {
|
|
374
|
+
function mountHeaderless(extra: Record<string, unknown> = {}) {
|
|
375
|
+
mount(() => h(HkDebugFloat, { chrome: "none", title: "PERF", ...extra }, () => "fps 60"));
|
|
376
|
+
return floatWindow()!;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
it("renders no title bar and carries the chrome marker", () => {
|
|
380
|
+
const win = mountHeaderless();
|
|
381
|
+
expect(win.getAttribute("data-chrome")).toBe("none");
|
|
382
|
+
expect(win.querySelector("[data-el='header']")).toBeNull();
|
|
383
|
+
expect(win.querySelector("[data-el='title']")).toBeNull();
|
|
384
|
+
// The slot content still lands in the body.
|
|
385
|
+
expect(win.querySelector("[data-el='body']")!.textContent).toContain("fps 60");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("keeps the title as the accessible name even without a header", () => {
|
|
389
|
+
const win = mountHeaderless();
|
|
390
|
+
expect(win.getAttribute("aria-label")).toBe("PERF");
|
|
391
|
+
expect(win.getAttribute("role")).toBe("group");
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("exposes the close button through the hover chrome overlay", () => {
|
|
395
|
+
const win = mountHeaderless();
|
|
396
|
+
const overlay = win.querySelector("[data-el='overlay']")!;
|
|
397
|
+
expect(overlay).toBeTruthy();
|
|
398
|
+
const close = overlay.querySelector("button.hk-debug-float-close")!;
|
|
399
|
+
expect(close).toBeTruthy();
|
|
400
|
+
expect(close.getAttribute("aria-label")).toBe("Close");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("close hides the window and emits update:open false", async () => {
|
|
404
|
+
const emitted: boolean[] = [];
|
|
405
|
+
mount(() =>
|
|
406
|
+
h(HkDebugFloat, { chrome: "none", "onUpdate:open": (v: boolean) => emitted.push(v) }),
|
|
407
|
+
);
|
|
408
|
+
const close = floatWindow()!.querySelector("[data-el='overlay'] button") as HTMLButtonElement;
|
|
409
|
+
close.click();
|
|
410
|
+
expect(emitted).toEqual([false]);
|
|
411
|
+
await nextTick();
|
|
412
|
+
expect(floatWindow()).toBeNull();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("drags from the whole window body — no header to grab", async () => {
|
|
416
|
+
mount(() => h(HkDebugFloat, { chrome: "none", width: "auto" }));
|
|
417
|
+
const win = floatWindow()!;
|
|
418
|
+
// A press on the window body itself (no [data-el='header'] exists).
|
|
419
|
+
dispatchMouse("pointerdown", win, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
420
|
+
await nextTick();
|
|
421
|
+
expect(win.hasAttribute("data-dragging")).toBe(true);
|
|
422
|
+
dispatchMouse("pointermove", win, { clientX: 140, clientY: 120, buttons: 1 });
|
|
423
|
+
await nextTick();
|
|
424
|
+
expect(win.style.left).toBe("40px");
|
|
425
|
+
expect(win.style.top).toBe("20px");
|
|
426
|
+
dispatchMouse("pointerup", win);
|
|
427
|
+
await nextTick();
|
|
428
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("a press on the overlay's close button never starts a body drag", async () => {
|
|
432
|
+
mount(() => h(HkDebugFloat, { chrome: "none" }));
|
|
433
|
+
const win = floatWindow()!;
|
|
434
|
+
const close = win.querySelector("[data-el='overlay'] button")!;
|
|
435
|
+
dispatchMouse("pointerdown", close, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
436
|
+
// Await the DOM flush so a (broken) drag start is actually visible.
|
|
437
|
+
await nextTick();
|
|
438
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
439
|
+
expect(win.style.left).toBe("");
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
describe("HkDebugFloat width", () => {
|
|
444
|
+
it("marks the auto seat and drops the inline px width", () => {
|
|
445
|
+
mount(() => h(HkDebugFloat, { width: "auto" }));
|
|
446
|
+
const win = floatWindow()!;
|
|
447
|
+
expect(win.getAttribute("data-auto-width")).toBe("");
|
|
448
|
+
expect(win.style.width).toBe("");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("keeps the numeric seat inline (no auto marker)", () => {
|
|
452
|
+
mount(() => h(HkDebugFloat, { width: 320 }));
|
|
453
|
+
const win = floatWindow()!;
|
|
454
|
+
expect(win.hasAttribute("data-auto-width")).toBe(false);
|
|
455
|
+
expect(win.style.width).toBe("320px");
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
describe("HkDebugFloat sections", () => {
|
|
460
|
+
const SECTIONS = [
|
|
461
|
+
{ key: "timing", label: "timing" },
|
|
462
|
+
{ key: "draws", label: "draws" },
|
|
463
|
+
{ key: "gpu", label: "gpu" },
|
|
464
|
+
];
|
|
465
|
+
|
|
466
|
+
function mountSections(
|
|
467
|
+
propsExtra: Record<string, unknown> = {},
|
|
468
|
+
slots?: Record<string, () => ReturnType<typeof h>>,
|
|
469
|
+
) {
|
|
470
|
+
mount(
|
|
471
|
+
() =>
|
|
472
|
+
h(
|
|
473
|
+
HkDebugFloat,
|
|
474
|
+
{ sections: SECTIONS, chrome: "none", ...propsExtra },
|
|
475
|
+
slots ?? {
|
|
476
|
+
timing: () => h("div", null, "render 60 fps"),
|
|
477
|
+
draws: () => h("div", null, "draws 325"),
|
|
478
|
+
gpu: () => h("div", null, "ANGLE (Intel)"),
|
|
479
|
+
},
|
|
480
|
+
),
|
|
481
|
+
);
|
|
482
|
+
return floatWindow()!;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function section(win: HTMLElement, key: string): HTMLElement | null {
|
|
486
|
+
return win.querySelector<HTMLElement>(`[data-el='section'][data-key='${key}']`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
it("renders each section through its same-named slot, in declared order", () => {
|
|
490
|
+
const win = mountSections();
|
|
491
|
+
const keys = [...win.querySelectorAll("[data-el='section']")].map(
|
|
492
|
+
(el) => el.getAttribute("data-key"),
|
|
493
|
+
);
|
|
494
|
+
expect(keys).toEqual(["timing", "draws", "gpu"]);
|
|
495
|
+
expect(section(win, "draws")!.textContent).toContain("draws 325");
|
|
496
|
+
// The plain default slot is not part of the sections contract.
|
|
497
|
+
expect(win.querySelector("[data-el='body']")!.textContent).not.toContain("unsectioned");
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("drops a section whose slot is missing instead of crashing", () => {
|
|
501
|
+
const win = mountSections(
|
|
502
|
+
{},
|
|
503
|
+
{ timing: () => h("div", null, "render 60 fps"), gpu: () => h("div", null, "ANGLE") },
|
|
504
|
+
);
|
|
505
|
+
expect(section(win, "timing")).toBeTruthy();
|
|
506
|
+
expect(section(win, "draws")).toBeNull();
|
|
507
|
+
expect(section(win, "gpu")).toBeTruthy();
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("every section gets a toggle chip, pressed = visible", () => {
|
|
511
|
+
const win = mountSections();
|
|
512
|
+
for (const s of SECTIONS) {
|
|
513
|
+
const chip = win.querySelector<HTMLButtonElement>(`.hk-debug-float-section[data-key='${s.key}']`);
|
|
514
|
+
expect(chip, `chip for ${s.key}`).toBeTruthy();
|
|
515
|
+
expect(chip!.textContent).toBe(s.label);
|
|
516
|
+
expect(chip!.getAttribute("aria-pressed")).toBe("true");
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it("toggling a chip hides that section (uncontrolled) and persists it", async () => {
|
|
521
|
+
const win = mountSections({ persistKey: "sections" });
|
|
522
|
+
const chip = win.querySelector<HTMLButtonElement>(
|
|
523
|
+
".hk-debug-float-section[data-key='draws']",
|
|
524
|
+
)!;
|
|
525
|
+
chip.click();
|
|
526
|
+
await nextTick();
|
|
527
|
+
expect(section(floatWindow()!, "draws")).toBeNull();
|
|
528
|
+
expect(section(floatWindow()!, "timing")).toBeTruthy();
|
|
529
|
+
const raw = localStorage.getItem(debugFloatStorageKey("sections"));
|
|
530
|
+
expect(JSON.parse(raw!)).toEqual({ open: true, hidden: ["draws"] });
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("a remount restores the hidden set from the persisted record", () => {
|
|
534
|
+
localStorage.setItem(debugFloatStorageKey("restore-hidden"), JSON.stringify({
|
|
535
|
+
open: true,
|
|
536
|
+
hidden: ["gpu", "timing"],
|
|
537
|
+
}));
|
|
538
|
+
const win = mountSections({ persistKey: "restore-hidden" });
|
|
539
|
+
expect(section(win, "gpu")).toBeNull();
|
|
540
|
+
expect(section(win, "timing")).toBeNull();
|
|
541
|
+
expect(section(win, "draws")).toBeTruthy();
|
|
542
|
+
// The chip mirrors the persisted state.
|
|
543
|
+
expect(
|
|
544
|
+
win.querySelector<HTMLButtonElement>(".hk-debug-float-section[data-key='gpu']")!
|
|
545
|
+
.getAttribute("aria-pressed"),
|
|
546
|
+
).toBe("false");
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("toggling back re-shows the section and clears the persisted list", async () => {
|
|
550
|
+
localStorage.setItem(
|
|
551
|
+
debugFloatStorageKey("toggle-back"),
|
|
552
|
+
JSON.stringify({ open: true, hidden: ["gpu"] }),
|
|
553
|
+
);
|
|
554
|
+
const win = mountSections({ persistKey: "toggle-back" });
|
|
555
|
+
const chip = win.querySelector<HTMLButtonElement>(".hk-debug-float-section[data-key='gpu']")!;
|
|
556
|
+
expect(chip.getAttribute("aria-pressed")).toBe("false");
|
|
557
|
+
chip.click();
|
|
558
|
+
await nextTick();
|
|
559
|
+
expect(section(floatWindow()!, "gpu")).toBeTruthy();
|
|
560
|
+
const raw = localStorage.getItem(debugFloatStorageKey("toggle-back"));
|
|
561
|
+
expect(JSON.parse(raw!)).toEqual({ open: true });
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it("corrupted hidden lists degrade to all-visible instead of crashing", () => {
|
|
565
|
+
localStorage.setItem(
|
|
566
|
+
debugFloatStorageKey("corrupt-hidden"),
|
|
567
|
+
JSON.stringify({ open: true, hidden: "draws" }),
|
|
568
|
+
);
|
|
569
|
+
const win = mountSections({ persistKey: "corrupt-hidden" });
|
|
570
|
+
expect(section(win, "draws")).toBeTruthy();
|
|
571
|
+
expect(section(win, "gpu")).toBeTruthy();
|
|
572
|
+
|
|
573
|
+
// A NON-ARRAY hidden that slipped past the reader would throw at
|
|
574
|
+
// mount time (new Set(3) on a number) — the mount itself succeeding
|
|
575
|
+
// is part of the contract, so pin the numeric shape on a fresh
|
|
576
|
+
// record too (the new window is the LAST in document order).
|
|
577
|
+
localStorage.setItem(
|
|
578
|
+
debugFloatStorageKey("corrupt-hidden-2"),
|
|
579
|
+
JSON.stringify({ open: true, hidden: 3 }),
|
|
580
|
+
);
|
|
581
|
+
mountSections({ persistKey: "corrupt-hidden-2" });
|
|
582
|
+
const windows = document.querySelectorAll<HTMLElement>(".hk-debug-float");
|
|
583
|
+
const win2 = windows[windows.length - 1];
|
|
584
|
+
expect(section(win2, "draws")).toBeTruthy();
|
|
585
|
+
expect(section(win2, "timing")).toBeTruthy();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it("controlled visibleSections wins over the internal state and emits the next list", async () => {
|
|
589
|
+
const emitted: string[][] = [];
|
|
590
|
+
const win = mountSections(
|
|
591
|
+
{
|
|
592
|
+
visibleSections: ["timing", "gpu"],
|
|
593
|
+
"onUpdate:visibleSections": (keys: string[]) => emitted.push(keys),
|
|
594
|
+
},
|
|
595
|
+
);
|
|
596
|
+
// The prop is the visible list: draws never renders.
|
|
597
|
+
expect(section(win, "draws")).toBeNull();
|
|
598
|
+
expect(section(win, "timing")).toBeTruthy();
|
|
599
|
+
// Toggling the hidden one emits its RETURN, in sections order…
|
|
600
|
+
const chip = win.querySelector<HTMLButtonElement>(".hk-debug-float-section[data-key='draws']")!;
|
|
601
|
+
chip.click();
|
|
602
|
+
await nextTick();
|
|
603
|
+
expect(emitted).toEqual([["timing", "draws", "gpu"]]);
|
|
604
|
+
// …and the uncontrolled state/persistence stay untouched (the prop
|
|
605
|
+
// remains authoritative until the parent round-trips).
|
|
606
|
+
expect(section(win, "draws")).toBeNull();
|
|
607
|
+
// Toggling a visible one removes it from the emitted list.
|
|
608
|
+
win.querySelector<HTMLButtonElement>(".hk-debug-float-section[data-key='timing']")!.click();
|
|
609
|
+
await nextTick();
|
|
610
|
+
expect(emitted[1]).toEqual(["gpu"]);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("a drag under controlled visibility persists the prop-derived set, not a stale internal one", async () => {
|
|
614
|
+
// A record from an uncontrolled era must not resurrect through a
|
|
615
|
+
// controlled mount: the visibleSections prop is authoritative, so
|
|
616
|
+
// the drag-drop persistence writes the DERIVED hidden set (empty
|
|
617
|
+
// here) — never the mount-time internal list.
|
|
618
|
+
localStorage.setItem(
|
|
619
|
+
debugFloatStorageKey("ctl-stale"),
|
|
620
|
+
JSON.stringify({ open: true, hidden: ["gpu"] }),
|
|
621
|
+
);
|
|
622
|
+
const win = mountSections({
|
|
623
|
+
persistKey: "ctl-stale",
|
|
624
|
+
visibleSections: ["timing", "draws", "gpu"],
|
|
625
|
+
});
|
|
626
|
+
expect(section(win, "gpu")).toBeTruthy();
|
|
627
|
+
dispatchMouse("pointerdown", win, { clientX: 10, clientY: 10, button: 0, buttons: 1 });
|
|
628
|
+
dispatchMouse("pointermove", win, { clientX: 30, clientY: 20, buttons: 1 });
|
|
629
|
+
dispatchMouse("pointerup", win);
|
|
630
|
+
await nextTick();
|
|
631
|
+
expect(JSON.parse(localStorage.getItem(debugFloatStorageKey("ctl-stale"))!)).toEqual({
|
|
632
|
+
open: true,
|
|
633
|
+
x: 20,
|
|
634
|
+
y: 10,
|
|
635
|
+
});
|
|
636
|
+
// The inverse direction: a controlled prop that HIDES a section
|
|
637
|
+
// persists that same set on drop (prop-derived, both ways). Two
|
|
638
|
+
// windows are mounted by now — the new one is the LAST in document
|
|
639
|
+
// order (floatWindow() would return the first).
|
|
640
|
+
localStorage.setItem(
|
|
641
|
+
debugFloatStorageKey("ctl-stale2"),
|
|
642
|
+
JSON.stringify({ open: true }),
|
|
643
|
+
);
|
|
644
|
+
mountSections({
|
|
645
|
+
persistKey: "ctl-stale2",
|
|
646
|
+
visibleSections: ["timing"],
|
|
647
|
+
});
|
|
648
|
+
const windows = document.querySelectorAll<HTMLElement>(".hk-debug-float");
|
|
649
|
+
const win2 = windows[windows.length - 1];
|
|
650
|
+
dispatchMouse("pointerdown", win2, { clientX: 10, clientY: 10, button: 0, buttons: 1 });
|
|
651
|
+
dispatchMouse("pointermove", win2, { clientX: 30, clientY: 20, buttons: 1 });
|
|
652
|
+
dispatchMouse("pointerup", win2);
|
|
653
|
+
await nextTick();
|
|
654
|
+
expect(JSON.parse(localStorage.getItem(debugFloatStorageKey("ctl-stale2"))!)).toEqual({
|
|
655
|
+
open: true,
|
|
656
|
+
x: 20,
|
|
657
|
+
y: 10,
|
|
658
|
+
hidden: ["draws", "gpu"],
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
it("keeps the default-slot contract when no sections are declared", () => {
|
|
663
|
+
mount(() => h(HkDebugFloat, null, () => "fps 60"));
|
|
664
|
+
const win = floatWindow()!;
|
|
665
|
+
expect(win.querySelector("[data-el='section']")).toBeNull();
|
|
666
|
+
expect(win.querySelector("[data-el='body']")!.textContent).toContain("fps 60");
|
|
667
|
+
expect(win.querySelector(".hk-debug-float-section")).toBeNull();
|
|
668
|
+
expect(win.querySelector("[data-el='overlay']")).toBeNull();
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it("headered mode parks the chips overlay but keeps the header close button", () => {
|
|
672
|
+
mount(() => h(HkDebugFloat, { sections: SECTIONS }, {
|
|
673
|
+
timing: () => h("div", null, "t"),
|
|
674
|
+
draws: () => h("div", null, "d"),
|
|
675
|
+
gpu: () => h("div", null, "g"),
|
|
676
|
+
}));
|
|
677
|
+
const win = floatWindow()!;
|
|
678
|
+
expect(win.getAttribute("data-chrome")).toBe("header");
|
|
679
|
+
expect(win.querySelector("[data-el='header'] .hk-debug-float-close")).toBeTruthy();
|
|
680
|
+
// Chips still exist — in the hover overlay, not the header.
|
|
681
|
+
expect(win.querySelectorAll(".hk-debug-float-section").length).toBe(3);
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
|
|
334
685
|
describe("HkDebugFloat stylesheet contract", () => {
|
|
335
686
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
336
687
|
const css = compile(resolve(here, "HkDebugFloat.scss"), { style: "expanded" }).css;
|
|
337
688
|
const scale = readFileSync(resolve(here, "..", "scale.scss"), "utf8");
|
|
338
689
|
|
|
339
|
-
it("fades to the prop-driven opacity on hover (the wowsp HUD idiom)", () => {
|
|
690
|
+
it("fades the CARD to the prop-driven opacity on hover (the wowsp HUD idiom)", () => {
|
|
691
|
+
// The fade lives on [data-el="fade"], never the root — the hover
|
|
692
|
+
// chrome is the card's sibling and must stay legible while the
|
|
693
|
+
// content dims (at a 0.15 dim an in-card close would fade too).
|
|
340
694
|
// Sass compiles quoted attribute selectors unquoted ([data-hovered]).
|
|
341
695
|
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\);/,
|
|
696
|
+
/\.hk-debug-float:hover \[data-el=fade\],\s*\.hk-debug-float\[data-hovered\] \[data-el=fade\]\s*\{\s*opacity:\s*var\(--hk-debug-float-hover-opacity,\s*0\.45\);/,
|
|
343
697
|
);
|
|
344
698
|
});
|
|
345
699
|
|
|
346
|
-
it("runs the fade as an opacity-only ~150ms transition on the
|
|
700
|
+
it("runs the fade as an opacity-only ~150ms transition on the card", () => {
|
|
347
701
|
expect(css).toMatch(
|
|
348
|
-
/\.hk-debug-float\s*\{[^}]*transition:\s*opacity\s+var\(--duration-short\)/,
|
|
702
|
+
/\.hk-debug-float \[data-el=fade\]\s*\{[^}]*transition:\s*opacity\s+var\(--duration-short\)/,
|
|
349
703
|
);
|
|
350
704
|
// Opacity-only: nothing about the fade may move layout.
|
|
351
|
-
expect(css).toMatch(/\.hk-debug-float\s*\{[^}]*transition:\s*opacity[^;]*;/);
|
|
705
|
+
expect(css).toMatch(/\.hk-debug-float \[data-el=fade\]\s*\{[^}]*transition:\s*opacity[^;]*;/);
|
|
352
706
|
});
|
|
353
707
|
|
|
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;/);
|
|
708
|
+
it("keeps the drag exception: a grabbed window's card stays opaque", () => {
|
|
709
|
+
expect(css).toMatch(/\.hk-debug-float\[data-dragging\] \[data-el=fade\]\s*\{\s*opacity:\s*1;/);
|
|
356
710
|
});
|
|
357
711
|
|
|
358
712
|
it("pins the drag exception AFTER the hover rule (equal specificity — order is the cascade)", () => {
|
|
359
|
-
// `.hk-debug-float:hover
|
|
360
|
-
// EQUAL specificity
|
|
361
|
-
// over the
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
//
|
|
713
|
+
// `.hk-debug-float:hover [data-el=fade]` and
|
|
714
|
+
// `[data-dragging] [data-el=fade]` have EQUAL specificity: mid-grab
|
|
715
|
+
// both match (the pointer is captured over the handle, so :hover
|
|
716
|
+
// holds and pointerleave cannot fire). Which rule wins is decided
|
|
717
|
+
// purely by source order — moving the drag exception above the hover
|
|
718
|
+
// rule fades the window mid-grab, and no runtime test exercises that
|
|
719
|
+
// co-occurrence (happy-dom has no real hover pipeline).
|
|
365
720
|
const hoverIdx = css.search(
|
|
366
|
-
/\.hk-debug-float:hover,\s*\.hk-debug-float\[data-hovered\]\s*\{/,
|
|
721
|
+
/\.hk-debug-float:hover \[data-el=fade\],\s*\.hk-debug-float\[data-hovered\] \[data-el=fade\]\s*\{/,
|
|
367
722
|
);
|
|
368
|
-
const dragIdx = css.search(/\.hk-debug-float\[data-dragging\]\s*\{/);
|
|
723
|
+
const dragIdx = css.search(/\.hk-debug-float\[data-dragging\] \[data-el=fade\]\s*\{/);
|
|
369
724
|
expect(hoverIdx).toBeGreaterThan(-1);
|
|
370
725
|
expect(dragIdx).toBeGreaterThan(hoverIdx);
|
|
371
726
|
});
|
|
@@ -400,14 +755,23 @@ describe("HkDebugFloat stylesheet contract", () => {
|
|
|
400
755
|
expect(css).not.toMatch(/\.hk-debug-float\s*\{[^}]*position:\s*absolute/);
|
|
401
756
|
});
|
|
402
757
|
|
|
403
|
-
it("gives the header the grab affordances and the
|
|
758
|
+
it("gives the header the grab affordances and the card the tabular mono face", () => {
|
|
404
759
|
expect(css).toMatch(/\.hk-debug-float \[data-el=header\]\s*\{[^}]*cursor:\s*grab;/);
|
|
405
760
|
expect(css).toMatch(/\.hk-debug-float \[data-el=header\]\s*\{[^}]*touch-action:\s*none;/);
|
|
406
761
|
expect(css).toMatch(
|
|
407
762
|
/\.hk-debug-float\[data-dragging\] \[data-el=header\]\s*\{[^}]*cursor:\s*grabbing;/,
|
|
408
763
|
);
|
|
409
|
-
expect(css).toMatch(/\.hk-debug-float\s*\{[^}]*font-family:\s*var\(--font-mono\);/);
|
|
410
|
-
expect(css).toMatch(
|
|
764
|
+
expect(css).toMatch(/\.hk-debug-float \[data-el=fade\]\s*\{[^}]*font-family:\s*var\(--font-mono\);/);
|
|
765
|
+
expect(css).toMatch(
|
|
766
|
+
/\.hk-debug-float \[data-el=fade\]\s*\{[^}]*font-variant-numeric:\s*tabular-nums;/,
|
|
767
|
+
);
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
it("makes the whole headerless window the drag handle", () => {
|
|
771
|
+
expect(css).toMatch(/\.hk-debug-float\[data-chrome=none\]\s*\{[^}]*cursor:\s*grab;/);
|
|
772
|
+
expect(css).toMatch(
|
|
773
|
+
/\.hk-debug-float\[data-chrome=none\]\[data-dragging\]\s*\{[^}]*cursor:\s*grabbing;/,
|
|
774
|
+
);
|
|
411
775
|
});
|
|
412
776
|
|
|
413
777
|
it("caps the body so a fat dump cannot cover the viewport", () => {
|
|
@@ -415,4 +779,49 @@ describe("HkDebugFloat stylesheet contract", () => {
|
|
|
415
779
|
/\.hk-debug-float \[data-el=body\]\s*\{[^}]*max-height:\s*40vh;[^}]*overflow:\s*auto;/,
|
|
416
780
|
);
|
|
417
781
|
});
|
|
782
|
+
|
|
783
|
+
it("sizes the auto seat to its content, guarded against the viewport", () => {
|
|
784
|
+
expect(css).toMatch(/\.hk-debug-float\[data-auto-width\]\s*\{[^}]*width:\s*max-content;/);
|
|
785
|
+
expect(css).toMatch(
|
|
786
|
+
/\.hk-debug-float\[data-auto-width\]\s*\{[^}]*max-width:\s*calc\(100vw - 2 \* var\(--hk-debug-float-offset,\s*16px\)\);/,
|
|
787
|
+
);
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
it("keeps the hover chrome out of the fading card and click-transparent until revealed", () => {
|
|
791
|
+
// Structure: the overlay is a sibling of the card, never inside it —
|
|
792
|
+
// a nested overlay would fade (and unclickable) with the content.
|
|
793
|
+
// dart-sass compiles the attribute selectors UNQUOTED, so search the
|
|
794
|
+
// compiled form — the quoted spelling only survives inside comments
|
|
795
|
+
// and would make this assertion vacuous.
|
|
796
|
+
const fadeIdx = css.indexOf("[data-el=fade]");
|
|
797
|
+
const overlayIdx = css.indexOf("[data-el=overlay]");
|
|
798
|
+
expect(fadeIdx).toBeGreaterThan(-1);
|
|
799
|
+
expect(overlayIdx).toBeGreaterThan(fadeIdx);
|
|
800
|
+
expect(css).not.toMatch(/\.hk-debug-float \[data-el=fade\][^{]*\[data-el=overlay\]/);
|
|
801
|
+
// Hidden until revealed, and reveal never happens inside the card.
|
|
802
|
+
expect(css).toMatch(
|
|
803
|
+
/\.hk-debug-float \[data-el=overlay\]\s*\{[^}]*opacity:\s*0;[^}]*pointer-events:\s*none;/,
|
|
804
|
+
);
|
|
805
|
+
expect(css).toMatch(
|
|
806
|
+
/\.hk-debug-float:hover \[data-el=overlay\],[\s\S]*?\.hk-debug-float\[data-dragging\] \[data-el=overlay\],[\s\S]*?\.hk-debug-float:focus-within \[data-el=overlay\]\s*\{\s*opacity:\s*1;\s*pointer-events:\s*auto;/,
|
|
807
|
+
);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
it("pins the hover chrome INSIDE the window box so wide chip rows cannot catch off-window clicks", () => {
|
|
811
|
+
// The overlay spans both insets and wraps: a chip row wider than a
|
|
812
|
+
// fixed seat stays inside the window instead of painting (and, while
|
|
813
|
+
// revealed, clicking) past its edge.
|
|
814
|
+
expect(css).toMatch(
|
|
815
|
+
/\.hk-debug-float \[data-el=overlay\]\s*\{[^}]*left:\s*var\(--space-4\);[^}]*right:\s*var\(--space-4\);[^}]*flex-wrap:\s*wrap;/,
|
|
816
|
+
);
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
it("parks the hover chrome on the top edge when headerless and the bottom edge when headered", () => {
|
|
820
|
+
expect(css).toMatch(
|
|
821
|
+
/\.hk-debug-float\[data-chrome=none\] \[data-el=overlay\]\s*\{[^}]*top:\s*var\(--space-4\);/,
|
|
822
|
+
);
|
|
823
|
+
expect(css).toMatch(
|
|
824
|
+
/\.hk-debug-float\[data-chrome=header\] \[data-el=overlay\]\s*\{[^}]*bottom:\s*var\(--space-4\);/,
|
|
825
|
+
);
|
|
826
|
+
});
|
|
418
827
|
});
|
|
@@ -22,12 +22,42 @@
|
|
|
22
22
|
* fades it to `hoverOpacity` (default 0.45, ~150ms opacity-only
|
|
23
23
|
* transition); leaving restores full opacity. While DRAGGING the
|
|
24
24
|
* window stays opaque — fading mid-grab hides what the hand holds.
|
|
25
|
-
*
|
|
25
|
+
* The fade lives on the `[data-el="fade"]` card, NOT on the root: the
|
|
26
|
+
* hover chrome (section chips, headerless close) sits outside that
|
|
27
|
+
* subtree so the controls stay legible while the content dims — at a
|
|
28
|
+
* 0.15 hover dim an in-card close button would fade out of reach.
|
|
29
|
+
* - **Drag anywhere on the handle.** Header chrome (`chrome="header"`,
|
|
30
|
+
* the default): the header bar is the handle. Headerless
|
|
31
|
+
* (`chrome="none"`): the whole window body is the handle — the HUD
|
|
32
|
+
* has no title bar to grab (the wowsp PERF seat), a pointer press on
|
|
33
|
+
* any of it starts the drag. Pointer-captured, clamped to the
|
|
26
34
|
* viewport (`clampDebugFloatPosition`); on drop the position persists.
|
|
35
|
+
* Presses on buttons/links/inputs never start a drag.
|
|
36
|
+
* - **Headerless chrome.** With `chrome="none"` there is no title bar —
|
|
37
|
+
* the close × and the section chips live in a hover-revealed overlay
|
|
38
|
+
* pinned inside the window corner (`[data-el="overlay"]`). It reveals
|
|
39
|
+
* on hover / while dragging / on keyboard focus-within and is
|
|
40
|
+
* click-transparent otherwise, so it never shadows the content or the
|
|
41
|
+
* page. Headered mode keeps the × in the header; chips (when
|
|
42
|
+
* `sections` is set) still come through the hover overlay, parked at
|
|
43
|
+
* the bottom edge so they cannot sit on the header's own ×.
|
|
44
|
+
* - **Sections (optional declarative content).** Pass `sections`
|
|
45
|
+
* (`{ key, label }[]`) and render each through a same-named slot:
|
|
46
|
+
* every section gets a toggle chip, so a dense debug HUD can be
|
|
47
|
+
* thinned to the lines that matter. Visibility is v-model-able via
|
|
48
|
+
* `visibleSections` / `update:visibleSections` (the prop is the list
|
|
49
|
+
* of VISIBLE keys); uncontrolled visibility persists in the
|
|
50
|
+
* persistKey record (`hidden` — keys toggled off). A section whose
|
|
51
|
+
* slot is missing renders nothing. Without `sections` the plain
|
|
52
|
+
* default-slot contract is unchanged.
|
|
53
|
+
* - **Width.** Numeric `width` pins the px width (default 280).
|
|
54
|
+
* `width="auto"` sizes the window to its content (`max-content`,
|
|
55
|
+
* viewport-guarded) so long mono lines — GPU adapter strings, full
|
|
56
|
+
* percentiles — are never clipped by the seat.
|
|
27
57
|
* - **Close (×)** emits `update:open` (v-model:open) and persists the
|
|
28
|
-
* closed state. With `persistKey` set, open-state
|
|
29
|
-
* round-trip via localStorage under
|
|
30
|
-
* restores
|
|
58
|
+
* closed state. With `persistKey` set, open-state, dragged position
|
|
59
|
+
* and hidden sections round-trip via localStorage under
|
|
60
|
+
* `hk-debug-float:<key>`; reopening restores them.
|
|
31
61
|
* - The window intercepts pointers ONLY on its own box (no backdrop,
|
|
32
62
|
* no inset-0 overlay) — clicks outside it always reach the page.
|
|
33
63
|
*/
|
|
@@ -52,6 +82,7 @@ import {
|
|
|
52
82
|
readDebugFloatPersisted,
|
|
53
83
|
writeDebugFloatPersisted,
|
|
54
84
|
type HkDebugFloatCorner,
|
|
85
|
+
type HkDebugFloatSection,
|
|
55
86
|
} from "./debugFloat";
|
|
56
87
|
import { useI18n } from "../i18n/context";
|
|
57
88
|
import "./HkDebugFloat.scss";
|
|
@@ -69,27 +100,43 @@ export default defineComponent({
|
|
|
69
100
|
/** v-model:open. Controlled when bound; leave undefined to let the
|
|
70
101
|
* window own the state (persisted value first, then defaultOpen). */
|
|
71
102
|
open: { type: Boolean, default: undefined },
|
|
72
|
-
/** Header text; falls back to the localized debug label ("DEBUG").
|
|
103
|
+
/** Header text; falls back to the localized debug label ("DEBUG").
|
|
104
|
+
* Headerless mode still uses it as the window's accessible name. */
|
|
73
105
|
title: { type: String, default: undefined },
|
|
106
|
+
/** Window chrome: `"header"` (default) renders the classic title
|
|
107
|
+
* bar (drag handle + close); `"none"` renders a bare HUD — drag
|
|
108
|
+
* on the body, close + section chips revealed on hover. */
|
|
109
|
+
chrome: {
|
|
110
|
+
type: String as PropType<"header" | "none">,
|
|
111
|
+
default: "header",
|
|
112
|
+
},
|
|
74
113
|
/** Viewport corner to anchor to until the window is dragged. */
|
|
75
114
|
position: { type: String as PropType<HkDebugFloatCorner>, default: "bottom-right" },
|
|
76
115
|
/** Distance from the anchored viewport edges, px. */
|
|
77
116
|
offset: { type: Number, default: 16 },
|
|
78
|
-
/** Window width, px. */
|
|
79
|
-
width: { type: Number, default: 280 },
|
|
117
|
+
/** Window width, px — or `"auto"` to size to the content. */
|
|
118
|
+
width: { type: [Number, String] as PropType<number | "auto">, default: 280 },
|
|
80
119
|
/** Opacity the window fades to while hovered, 0..1. */
|
|
81
120
|
hoverOpacity: { type: Number, default: 0.45 },
|
|
82
121
|
/** Uncontrolled initial open state (superseded by any persisted one). */
|
|
83
122
|
defaultOpen: { type: Boolean, default: true },
|
|
84
|
-
/** When set: open-state + position persist under
|
|
123
|
+
/** When set: open-state + position (+ hidden sections) persist under
|
|
85
124
|
* `hk-debug-float:<persistKey>` and restore on remount. */
|
|
86
125
|
persistKey: { type: String, default: undefined },
|
|
126
|
+
/** Declarative sections; each renders through the same-named slot
|
|
127
|
+
* and gets a toggle chip in the hover chrome. */
|
|
128
|
+
sections: { type: Array as PropType<HkDebugFloatSection[]>, default: undefined },
|
|
129
|
+
/** v-model:visibleSections — the list of VISIBLE section keys.
|
|
130
|
+
* Controlled when bound; otherwise visibility is owned here and
|
|
131
|
+
* persisted with the persistKey. */
|
|
132
|
+
visibleSections: { type: Array as PropType<string[]>, default: undefined },
|
|
87
133
|
/** Document-space z-index. The default band stays below every
|
|
88
134
|
* functional hikari popup (see debugFloat.ts). */
|
|
89
135
|
zIndex: { type: Number, default: HK_DEBUG_FLOAT_DOCUMENT_Z },
|
|
90
136
|
},
|
|
91
137
|
emits: {
|
|
92
138
|
"update:open": (_open: boolean) => true,
|
|
139
|
+
"update:visibleSections": (_keys: string[]) => true,
|
|
93
140
|
},
|
|
94
141
|
setup(props, { emit, slots }) {
|
|
95
142
|
const { t } = useI18n();
|
|
@@ -105,6 +152,20 @@ export default defineComponent({
|
|
|
105
152
|
const internalOpen = ref(initialPersisted ? initialPersisted.open : props.defaultOpen);
|
|
106
153
|
const isOpen = computed(() => props.open ?? internalOpen.value);
|
|
107
154
|
|
|
155
|
+
// -- section visibility: uncontrolled state tracks HIDDEN keys (the
|
|
156
|
+
// persisted shape); the controlled prop tracks VISIBLE keys --
|
|
157
|
+
const internalHidden = ref<string[]>(initialPersisted?.hidden ?? []);
|
|
158
|
+
const hiddenKeys = computed(() => {
|
|
159
|
+
if (props.visibleSections !== undefined) {
|
|
160
|
+
const visible = new Set(props.visibleSections);
|
|
161
|
+
return new Set((props.sections ?? []).map((s) => s.key).filter((k) => !visible.has(k)));
|
|
162
|
+
}
|
|
163
|
+
return new Set(internalHidden.value);
|
|
164
|
+
});
|
|
165
|
+
const visibleSections = computed(() =>
|
|
166
|
+
(props.sections ?? []).filter((s) => !hiddenKeys.value.has(s.key)),
|
|
167
|
+
);
|
|
168
|
+
|
|
108
169
|
// -- dragged position: null until the first grab; corner CSS anchors
|
|
109
170
|
// the window until then, and a persisted position short-circuits it --
|
|
110
171
|
const dragPos = ref<{ x: number; y: number } | null>(
|
|
@@ -118,13 +179,20 @@ export default defineComponent({
|
|
|
118
179
|
|
|
119
180
|
/** Best-effort persistence — the new open value is passed in because
|
|
120
181
|
* under a controlled v-model the prop (and thus isOpen) only flips
|
|
121
|
-
* after the parent round-trips the emitted update.
|
|
182
|
+
* after the parent round-trips the emitted update. The hidden half
|
|
183
|
+
* persists the DERIVED set (hiddenKeys, sections order) — under a
|
|
184
|
+
* controlled visibleSections the internal list stays at its
|
|
185
|
+
* mount-time value (the prop is authoritative), and persisting
|
|
186
|
+
* that stale internal list would clobber the record on the next
|
|
187
|
+
* drag/close. */
|
|
122
188
|
function persistState(open: boolean): void {
|
|
123
189
|
if (!props.persistKey) return;
|
|
124
190
|
const pos = dragPos.value;
|
|
191
|
+
const hidden = props.sections != null ? [...hiddenKeys.value] : [];
|
|
125
192
|
writeDebugFloatPersisted(props.persistKey, {
|
|
126
193
|
open,
|
|
127
194
|
...(pos ? { x: pos.x, y: pos.y } : {}),
|
|
195
|
+
...(hidden.length > 0 ? { hidden } : {}),
|
|
128
196
|
});
|
|
129
197
|
}
|
|
130
198
|
|
|
@@ -150,10 +218,31 @@ export default defineComponent({
|
|
|
150
218
|
persistState(open);
|
|
151
219
|
}
|
|
152
220
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
//
|
|
156
|
-
//
|
|
221
|
+
function toggleSection(key: string): void {
|
|
222
|
+
if (props.sections == null) return;
|
|
223
|
+
// Controlled visibility: derive the next visible list in sections
|
|
224
|
+
// order and hand it to the parent — the prop stays authoritative.
|
|
225
|
+
if (props.visibleSections !== undefined) {
|
|
226
|
+
const hidden = hiddenKeys.value;
|
|
227
|
+
emit(
|
|
228
|
+
"update:visibleSections",
|
|
229
|
+
props.sections.map((s) => s.key).filter((k) => (k === key ? hidden.has(k) : !hidden.has(k))),
|
|
230
|
+
);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const hidden = new Set(internalHidden.value);
|
|
234
|
+
if (hidden.has(key)) hidden.delete(key);
|
|
235
|
+
else hidden.add(key);
|
|
236
|
+
// Keep the persisted list in sections order (deterministic writes).
|
|
237
|
+
internalHidden.value = props.sections.map((s) => s.key).filter((k) => hidden.has(k));
|
|
238
|
+
persistState(isOpen.value);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// -- drag (the handle: header bar, or the whole window when
|
|
242
|
+
// headerless) --
|
|
243
|
+
function onDragPointerDown(e: PointerEvent): void {
|
|
244
|
+
// Primary button only; interactive chrome (close, section chips,
|
|
245
|
+
// producer content controls) keeps its own pointer semantics.
|
|
157
246
|
if (e.button !== 0) return;
|
|
158
247
|
if ((e.target as HTMLElement).closest("button, a, input, select, textarea")) return;
|
|
159
248
|
const el = windowEl.value;
|
|
@@ -166,18 +255,19 @@ export default defineComponent({
|
|
|
166
255
|
dragStart = { px: e.clientX, py: e.clientY, x: origin.x, y: origin.y };
|
|
167
256
|
dragging.value = true;
|
|
168
257
|
// Capture keeps live moves flowing while the pointer leaves the
|
|
169
|
-
// handle
|
|
258
|
+
// handle (the header bar, or the whole window when headerless).
|
|
259
|
+
// A synthetic pointer (tests, some engines) has no active
|
|
170
260
|
// pointer id and the capture call may reject per spec — a failed
|
|
171
261
|
// capture must never kill the grab: moves land on the handle
|
|
172
262
|
// anyway, which is the plain no-capture semantic.
|
|
173
263
|
try {
|
|
174
|
-
headerEl.value?.setPointerCapture?.(e.pointerId);
|
|
264
|
+
(headerEl.value ?? windowEl.value)?.setPointerCapture?.(e.pointerId);
|
|
175
265
|
} catch {
|
|
176
266
|
// No active pointer for the id — dragging continues un-captured.
|
|
177
267
|
}
|
|
178
268
|
}
|
|
179
269
|
|
|
180
|
-
function
|
|
270
|
+
function onDragPointerMove(e: PointerEvent): void {
|
|
181
271
|
if (!dragStart) return;
|
|
182
272
|
// Re-check the press: a hover with no button held (or a stale
|
|
183
273
|
// start after a mid-drag close) must never move the window.
|
|
@@ -225,6 +315,7 @@ export default defineComponent({
|
|
|
225
315
|
() => {
|
|
226
316
|
const persisted = readPersisted();
|
|
227
317
|
internalOpen.value = persisted ? persisted.open : props.defaultOpen;
|
|
318
|
+
internalHidden.value = persisted?.hidden ?? [];
|
|
228
319
|
dragPos.value = persisted ? debugFloatPersistedPosition(persisted) : null;
|
|
229
320
|
if (persisted) void nextTick(reclampToViewport);
|
|
230
321
|
},
|
|
@@ -232,12 +323,15 @@ export default defineComponent({
|
|
|
232
323
|
|
|
233
324
|
return () => {
|
|
234
325
|
if (!isOpen.value) return null;
|
|
326
|
+
const headered = props.chrome === "header";
|
|
235
327
|
const style: Record<string, string> = {
|
|
236
|
-
width: `${props.width}px`,
|
|
237
328
|
zIndex: String(props.zIndex),
|
|
238
329
|
"--hk-debug-float-hover-opacity": String(props.hoverOpacity),
|
|
239
330
|
"--hk-debug-float-offset": `${props.offset}px`,
|
|
240
331
|
};
|
|
332
|
+
// Numeric width pins the px seat inline; "auto" is class-driven
|
|
333
|
+
// (max-content, viewport-guarded) so the seat follows the content.
|
|
334
|
+
if (props.width !== "auto") style.width = `${props.width}px`;
|
|
241
335
|
// A dragged/persisted position pins the top-left corner in px;
|
|
242
336
|
// the corner insets must yield to it entirely.
|
|
243
337
|
if (dragPos.value) {
|
|
@@ -246,6 +340,25 @@ export default defineComponent({
|
|
|
246
340
|
style.right = "auto";
|
|
247
341
|
style.bottom = "auto";
|
|
248
342
|
}
|
|
343
|
+
// The drag handle: the header bar when headered, the whole window
|
|
344
|
+
// body when headerless (a HUD without a title bar to grab).
|
|
345
|
+
const handleProps = headered
|
|
346
|
+
? {
|
|
347
|
+
onPointerdown: onDragPointerDown,
|
|
348
|
+
onPointermove: onDragPointerMove,
|
|
349
|
+
onPointerup: endDrag,
|
|
350
|
+
onPointercancel: endDrag,
|
|
351
|
+
}
|
|
352
|
+
: {};
|
|
353
|
+
const bodyHandleProps = headered
|
|
354
|
+
? {}
|
|
355
|
+
: {
|
|
356
|
+
onPointerdown: onDragPointerDown,
|
|
357
|
+
onPointermove: onDragPointerMove,
|
|
358
|
+
onPointerup: endDrag,
|
|
359
|
+
onPointercancel: endDrag,
|
|
360
|
+
};
|
|
361
|
+
const showOverlay = props.sections != null || !headered;
|
|
249
362
|
return (
|
|
250
363
|
// Directly to <body> — NOT into #hk-overlay-root: this window
|
|
251
364
|
// is not a functional popup (no popup-manager band, no scroll
|
|
@@ -256,6 +369,8 @@ export default defineComponent({
|
|
|
256
369
|
ref={windowEl}
|
|
257
370
|
class="hk-debug-float"
|
|
258
371
|
data-corner={props.position}
|
|
372
|
+
data-chrome={props.chrome}
|
|
373
|
+
data-auto-width={props.width === "auto" ? "" : undefined}
|
|
259
374
|
data-hovered={hovered.value ? "" : undefined}
|
|
260
375
|
data-dragging={dragging.value ? "" : undefined}
|
|
261
376
|
role={titleText.value ? "group" : undefined}
|
|
@@ -263,27 +378,73 @@ export default defineComponent({
|
|
|
263
378
|
style={style as CSSProperties}
|
|
264
379
|
onPointerenter={onPointerEnter}
|
|
265
380
|
onPointerleave={onPointerLeave}
|
|
381
|
+
{...bodyHandleProps}
|
|
266
382
|
>
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
383
|
+
{/* The visible card: visuals + hover fade live here, so the
|
|
384
|
+
hover chrome below can stay legible while content dims. */}
|
|
385
|
+
<div data-el="fade">
|
|
386
|
+
{headered && (
|
|
387
|
+
<div ref={headerEl} data-el="header" {...handleProps}>
|
|
388
|
+
<span data-el="title">{slots.title ? slots.title() : titleText.value}</span>
|
|
389
|
+
<HIconButton
|
|
390
|
+
class="hk-debug-float-close"
|
|
391
|
+
size={24}
|
|
392
|
+
variant="ghost"
|
|
393
|
+
aria-label={t("hikari::alert.close", "Close")}
|
|
394
|
+
onClick={() => setOpen(false)}
|
|
395
|
+
>
|
|
396
|
+
{{ icon: () => <X aria-hidden="true" /> }}
|
|
397
|
+
</HIconButton>
|
|
398
|
+
</div>
|
|
399
|
+
)}
|
|
400
|
+
<div data-el="body">
|
|
401
|
+
{props.sections != null
|
|
402
|
+
? visibleSections.value
|
|
403
|
+
// A section with no slot renders nothing at all —
|
|
404
|
+
// not even an empty wrapper.
|
|
405
|
+
.filter((s) => slots[s.key] != null)
|
|
406
|
+
.map((s) => (
|
|
407
|
+
<div key={s.key} data-el="section" data-key={s.key}>
|
|
408
|
+
{slots[s.key]!()}
|
|
409
|
+
</div>
|
|
410
|
+
))
|
|
411
|
+
: slots.default?.()}
|
|
412
|
+
</div>
|
|
285
413
|
</div>
|
|
286
|
-
|
|
414
|
+
{/* Hover chrome: section chips + the headerless close. It is
|
|
415
|
+
a sibling of — never inside — the fading card, pinned to
|
|
416
|
+
the window corner, click-transparent until revealed. */}
|
|
417
|
+
{showOverlay && (
|
|
418
|
+
<div data-el="overlay">
|
|
419
|
+
{(props.sections ?? []).map((s) => {
|
|
420
|
+
const on = !hiddenKeys.value.has(s.key);
|
|
421
|
+
return (
|
|
422
|
+
<button
|
|
423
|
+
key={s.key}
|
|
424
|
+
type="button"
|
|
425
|
+
class="hk-debug-float-section"
|
|
426
|
+
data-key={s.key}
|
|
427
|
+
data-on={on ? "" : undefined}
|
|
428
|
+
aria-pressed={on}
|
|
429
|
+
onClick={() => toggleSection(s.key)}
|
|
430
|
+
>
|
|
431
|
+
{s.label}
|
|
432
|
+
</button>
|
|
433
|
+
);
|
|
434
|
+
})}
|
|
435
|
+
{!headered && (
|
|
436
|
+
<HIconButton
|
|
437
|
+
class="hk-debug-float-close"
|
|
438
|
+
size={24}
|
|
439
|
+
variant="ghost"
|
|
440
|
+
aria-label={t("hikari::alert.close", "Close")}
|
|
441
|
+
onClick={() => setOpen(false)}
|
|
442
|
+
>
|
|
443
|
+
{{ icon: () => <X aria-hidden="true" /> }}
|
|
444
|
+
</HIconButton>
|
|
445
|
+
)}
|
|
446
|
+
</div>
|
|
447
|
+
)}
|
|
287
448
|
</div>
|
|
288
449
|
</Teleport>
|
|
289
450
|
);
|
|
@@ -27,14 +27,30 @@ export const HK_DEBUG_FLOAT_DOCUMENT_Z = 80000;
|
|
|
27
27
|
/** localStorage namespace: `hk-debug-float:<persistKey>`. */
|
|
28
28
|
export const HK_DEBUG_FLOAT_STORAGE_PREFIX = "hk-debug-float:";
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* A declarative content section of the float (HkDebugFloat `sections`
|
|
32
|
+
* prop). The producer lists the sections it can render; the float renders
|
|
33
|
+
* each through a same-named slot and gives every one a toggle in the
|
|
34
|
+
* hover chrome, so a dense debug HUD can be thinned to just the lines
|
|
35
|
+
* that matter right now.
|
|
36
|
+
*/
|
|
37
|
+
export interface HkDebugFloatSection {
|
|
38
|
+
/** Slot name and persistence identity of the section. */
|
|
39
|
+
key: string;
|
|
40
|
+
/** Chip label in the hover chrome (verbatim producer text). */
|
|
41
|
+
label: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
/** Shape persisted under a persistKey. `x`/`y` are the window's
|
|
31
45
|
* top-left offset in viewport pixels (the dragged position); both are
|
|
32
46
|
* optional but PAIRED — a close before the first drag stores open-state
|
|
33
|
-
* only, and a drop always stores both.
|
|
47
|
+
* only, and a drop always stores both. `hidden` lists section keys the
|
|
48
|
+
* user toggled off (only written when non-empty; absent = all visible). */
|
|
34
49
|
export interface HkDebugFloatPersisted {
|
|
35
50
|
open: boolean;
|
|
36
51
|
x?: number;
|
|
37
52
|
y?: number;
|
|
53
|
+
hidden?: string[];
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
/**
|
|
@@ -102,9 +118,16 @@ export function readDebugFloatPersisted(persistKey: string): HkDebugFloatPersist
|
|
|
102
118
|
) {
|
|
103
119
|
return null;
|
|
104
120
|
}
|
|
121
|
+
if (
|
|
122
|
+
"hidden" in rec &&
|
|
123
|
+
(!Array.isArray(rec.hidden) || !rec.hidden.every((k) => typeof k === "string"))
|
|
124
|
+
) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
105
127
|
return {
|
|
106
128
|
open: rec.open,
|
|
107
129
|
...(hasPos ? { x: rec.x as number, y: rec.y as number } : {}),
|
|
130
|
+
...("hidden" in rec ? { hidden: rec.hidden as string[] } : {}),
|
|
108
131
|
};
|
|
109
132
|
} catch {
|
|
110
133
|
return null;
|
package/src/index.ts
CHANGED
|
@@ -774,6 +774,7 @@ export {
|
|
|
774
774
|
HK_DEBUG_FLOAT_STORAGE_PREFIX,
|
|
775
775
|
type HkDebugFloatCorner,
|
|
776
776
|
type HkDebugFloatPersisted,
|
|
777
|
+
type HkDebugFloatSection,
|
|
777
778
|
} from "./components/debugFloat";
|
|
778
779
|
export { default as HkTransitionContainer } from "./components/HkTransitionContainer";
|
|
779
780
|
export { default as HkPaneHolder } from "./components/HkPaneHolder";
|