@celestia-island/hikari 0.55.293 → 0.55.294
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.test.ts +1 -0
- package/src/animation/registerAnimations.ts +5 -0
- package/src/components/HkRangeRibbon.barrel.test.ts +46 -0
- package/src/components/HkRangeRibbon.scss +401 -0
- package/src/components/HkRangeRibbon.test.tsx +1335 -0
- package/src/components/HkRangeRibbon.tsx +736 -0
- package/src/components/HkScrollPin.scrollcontract.test.ts +77 -1
- package/src/components/HkScrollPin.scss +24 -4
- package/src/components/HkStepFlow.scss +10 -4
- package/src/i18n/locales/ar/components.json +8 -1
- package/src/i18n/locales/de/components.json +8 -1
- package/src/i18n/locales/en/components.json +8 -1
- package/src/i18n/locales/es/components.json +8 -1
- package/src/i18n/locales/fr/components.json +8 -1
- package/src/i18n/locales/ja/components.json +8 -1
- package/src/i18n/locales/ko/components.json +8 -1
- package/src/i18n/locales/pt/components.json +8 -1
- package/src/i18n/locales/ru/components.json +8 -1
- package/src/i18n/locales/zh-Hans/components.json +8 -1
- package/src/i18n/locales/zh-Hant/components.json +8 -1
- package/src/index.ts +8 -0
|
@@ -0,0 +1,1335 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { compile } from "sass";
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { createApp, defineComponent, h, nextTick, ref, type Ref } from "vue";
|
|
8
|
+
|
|
9
|
+
import HkRangeRibbon, { type RibbonLane, type RibbonSegment } from "./HkRangeRibbon";
|
|
10
|
+
import { setLocale } from "../i18n/context";
|
|
11
|
+
import jaBundle from "../i18n/locales/ja/components.json";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* HkRangeRibbon anatomy + behaviour.
|
|
15
|
+
*
|
|
16
|
+
* The component's whole reason to exist is the window contract, so the
|
|
17
|
+
* cases below pin it from both sides:
|
|
18
|
+
* · windowed lanes are the ONLY clipping site (full domain → positions
|
|
19
|
+
* untouched; clipped → re-normalized; wholly-outside → absent), while
|
|
20
|
+
* the overview keeps painting the full domain;
|
|
21
|
+
* · the emitted window is ALWAYS in full-domain absolute fractions —
|
|
22
|
+
* never relative to the currently zoomed sub-domain (the chest row
|
|
23
|
+
* filter depends on exactly that);
|
|
24
|
+
* · every reset path (button / dblclick / Escape / Home) lands null and
|
|
25
|
+
* restores the full view;
|
|
26
|
+
* · sub-minimum brushes, edge drags and keyboard nudges clamp instead of
|
|
27
|
+
* crossing.
|
|
28
|
+
* A stylesheet contract at the bottom compiles the sheet and pins the
|
|
29
|
+
* classes, geometry and the one animation (repo convention: vitest stubs
|
|
30
|
+
* CSS, so the runtime cases can never catch a dead rule).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const LANES: RibbonLane[] = [
|
|
34
|
+
{ key: "cpu", label: "CPU" },
|
|
35
|
+
{ key: "io", label: "IO" },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const SEGMENTS: RibbonSegment[] = [
|
|
39
|
+
{ id: "boot", lane: "cpu", start: 0.05, end: 0.2, label: "boot", tone: "success" },
|
|
40
|
+
{ id: "parse", lane: "cpu", start: 0.3, end: 0.45, label: "parse", tone: "secondary" },
|
|
41
|
+
{ id: "write", lane: "io", start: 0.5, end: 0.9, label: "write", tone: "warning" },
|
|
42
|
+
{
|
|
43
|
+
id: "flush",
|
|
44
|
+
lane: "io",
|
|
45
|
+
start: 0.95,
|
|
46
|
+
end: 1,
|
|
47
|
+
label: "flush",
|
|
48
|
+
status: "error",
|
|
49
|
+
tip: { title: "Flush stall", lines: ["waited 12ms", "retried once"] },
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
54
|
+
|
|
55
|
+
afterEach(async () => {
|
|
56
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
57
|
+
app.unmount();
|
|
58
|
+
container.remove();
|
|
59
|
+
}
|
|
60
|
+
// setLocale mutates module-global i18n state — restore the default after
|
|
61
|
+
// every case (HkDateTag / HkSolarLocationSetting idiom).
|
|
62
|
+
await setLocale("en");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ── Mount helpers ───────────────────────────────────────────────────────
|
|
66
|
+
function mountRibbon(props: Record<string, unknown> = {}): HTMLElement {
|
|
67
|
+
const container = document.createElement("div");
|
|
68
|
+
document.body.appendChild(container);
|
|
69
|
+
const Wrapper = defineComponent({
|
|
70
|
+
setup() {
|
|
71
|
+
return () => h(HkRangeRibbon, { lanes: LANES, segments: SEGMENTS, ...props });
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
const app = createApp(Wrapper);
|
|
75
|
+
app.mount(container);
|
|
76
|
+
mounts.push({ app, container });
|
|
77
|
+
const root = container.querySelector<HTMLElement>(".hk-range-ribbon");
|
|
78
|
+
expect(root, ".hk-range-ribbon renders").toBeTruthy();
|
|
79
|
+
return root!;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface Host {
|
|
83
|
+
root: HTMLElement;
|
|
84
|
+
window: Ref<[number, number] | null>;
|
|
85
|
+
windowChange: ReturnType<typeof vi.fn>;
|
|
86
|
+
select: ReturnType<typeof vi.fn>;
|
|
87
|
+
setWindow: (next: [number, number] | null) => Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The controlled-consumer harness: the host owns `window`, applies every
|
|
92
|
+
* emitted value back into its own ref and records it. That is the contract
|
|
93
|
+
* chest uses (fractions in, window out, host filters its rows).
|
|
94
|
+
*/
|
|
95
|
+
function mountHost(
|
|
96
|
+
initial: [number, number] | null = null,
|
|
97
|
+
extra: Record<string, unknown> = {},
|
|
98
|
+
): Host {
|
|
99
|
+
const container = document.createElement("div");
|
|
100
|
+
document.body.appendChild(container);
|
|
101
|
+
const win = ref<[number, number] | null>(initial);
|
|
102
|
+
const windowChange = vi.fn();
|
|
103
|
+
const select = vi.fn();
|
|
104
|
+
const base = { lanes: LANES, segments: SEGMENTS, ...extra };
|
|
105
|
+
const Wrapper = defineComponent({
|
|
106
|
+
setup() {
|
|
107
|
+
return () =>
|
|
108
|
+
h(HkRangeRibbon, {
|
|
109
|
+
...base,
|
|
110
|
+
window: win.value,
|
|
111
|
+
onWindowChange: (next: [number, number] | null) => {
|
|
112
|
+
windowChange(next);
|
|
113
|
+
win.value = next;
|
|
114
|
+
},
|
|
115
|
+
onSelect: (id: string) => select(id),
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const app = createApp(Wrapper);
|
|
120
|
+
app.mount(container);
|
|
121
|
+
mounts.push({ app, container });
|
|
122
|
+
const root = container.querySelector<HTMLElement>(".hk-range-ribbon");
|
|
123
|
+
expect(root, ".hk-range-ribbon renders").toBeTruthy();
|
|
124
|
+
return {
|
|
125
|
+
root: root!,
|
|
126
|
+
window: win,
|
|
127
|
+
windowChange,
|
|
128
|
+
select,
|
|
129
|
+
setWindow: async (next) => {
|
|
130
|
+
win.value = next;
|
|
131
|
+
await nextTick();
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ── DOM queries / geometry ──────────────────────────────────────────────
|
|
137
|
+
function laneSegments(root: HTMLElement, lane?: string): HTMLElement[] {
|
|
138
|
+
const scope = lane
|
|
139
|
+
? root.querySelector<HTMLElement>(`.hk-range-ribbon-lane[data-lane="${lane}"]`)
|
|
140
|
+
: root;
|
|
141
|
+
if (!scope) return [];
|
|
142
|
+
return Array.from(
|
|
143
|
+
scope.querySelectorAll<HTMLElement>(".hk-range-ribbon-lane-track .hk-range-ribbon-segment"),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function segmentById(root: HTMLElement, id: string): HTMLElement | null {
|
|
148
|
+
return root.querySelector<HTMLElement>(
|
|
149
|
+
`.hk-range-ribbon-lane-track .hk-range-ribbon-segment[data-segment-id="${id}"]`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function boxOf(element: HTMLElement): { left: number; width: number } {
|
|
154
|
+
return { left: parseFloat(element.style.left), width: parseFloat(element.style.width) };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function lastWindow(mock: ReturnType<typeof vi.fn>): [number, number] | null {
|
|
158
|
+
const calls = mock.mock.calls;
|
|
159
|
+
expect(calls.length, "windowChange was emitted").toBeGreaterThan(0);
|
|
160
|
+
return calls[calls.length - 1]?.[0] as [number, number] | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function expectWindow(
|
|
164
|
+
actual: [number, number] | null,
|
|
165
|
+
lo: number,
|
|
166
|
+
hi: number,
|
|
167
|
+
): void {
|
|
168
|
+
expect(actual, "windowChange payload").not.toBeNull();
|
|
169
|
+
const [start, end] = actual!;
|
|
170
|
+
expect(start, "window start").toBeCloseTo(lo, 10);
|
|
171
|
+
expect(end, "window end").toBeCloseTo(hi, 10);
|
|
172
|
+
expect(start, "start < end").toBeLessThan(end);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const STRIP_LEFT = 100;
|
|
176
|
+
const STRIP_WIDTH = 200;
|
|
177
|
+
|
|
178
|
+
/** happy-dom has no layout: pin the strip's rect and derive clientX from a
|
|
179
|
+
* full-domain fraction. */
|
|
180
|
+
function stubStrip(
|
|
181
|
+
root: HTMLElement,
|
|
182
|
+
): { strip: HTMLElement; x: (fraction: number) => number } {
|
|
183
|
+
const strip = root.querySelector<HTMLElement>(".hk-range-ribbon-strip");
|
|
184
|
+
expect(strip, "the overview strip renders").toBeTruthy();
|
|
185
|
+
const rect = {
|
|
186
|
+
x: STRIP_LEFT,
|
|
187
|
+
y: 0,
|
|
188
|
+
left: STRIP_LEFT,
|
|
189
|
+
top: 0,
|
|
190
|
+
width: STRIP_WIDTH,
|
|
191
|
+
height: 32,
|
|
192
|
+
right: STRIP_LEFT + STRIP_WIDTH,
|
|
193
|
+
bottom: 32,
|
|
194
|
+
toJSON: () => ({}),
|
|
195
|
+
} as DOMRect;
|
|
196
|
+
strip!.getBoundingClientRect = () => rect;
|
|
197
|
+
return {
|
|
198
|
+
strip: strip!,
|
|
199
|
+
x: (fraction: number) => STRIP_LEFT + fraction * STRIP_WIDTH,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
interface PointerOptions {
|
|
204
|
+
pointerId?: number;
|
|
205
|
+
pointerType?: string;
|
|
206
|
+
button?: number;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function pointer(
|
|
210
|
+
type: string,
|
|
211
|
+
clientX: number,
|
|
212
|
+
target: EventTarget,
|
|
213
|
+
options: PointerOptions = {},
|
|
214
|
+
): void {
|
|
215
|
+
target.dispatchEvent(
|
|
216
|
+
new PointerEvent(type, {
|
|
217
|
+
bubbles: true,
|
|
218
|
+
cancelable: true,
|
|
219
|
+
pointerId: options.pointerId ?? 1,
|
|
220
|
+
pointerType: options.pointerType ?? "mouse",
|
|
221
|
+
clientX,
|
|
222
|
+
clientY: 10,
|
|
223
|
+
button: options.button ?? 0,
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function keydown(
|
|
229
|
+
target: EventTarget,
|
|
230
|
+
key: string,
|
|
231
|
+
init: KeyboardEventInit = {},
|
|
232
|
+
): KeyboardEvent {
|
|
233
|
+
const event = new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...init });
|
|
234
|
+
target.dispatchEvent(event);
|
|
235
|
+
return event;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function drag(
|
|
239
|
+
target: EventTarget,
|
|
240
|
+
from: number,
|
|
241
|
+
to: number,
|
|
242
|
+
x: (fraction: number) => number,
|
|
243
|
+
): Promise<void> {
|
|
244
|
+
pointer("pointerdown", x(from), target);
|
|
245
|
+
pointer("pointermove", x(to), target);
|
|
246
|
+
pointer("pointerup", x(to), target);
|
|
247
|
+
await nextTick();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ── Full domain ─────────────────────────────────────────────────────────
|
|
251
|
+
describe("HkRangeRibbon full domain", () => {
|
|
252
|
+
it("renders every segment at its full-domain fraction and no window chrome", () => {
|
|
253
|
+
const root = mountRibbon({ window: null });
|
|
254
|
+
const expected: Record<string, { left: number; width: number; lane: string }> = {
|
|
255
|
+
boot: { left: 5, width: 15, lane: "cpu" },
|
|
256
|
+
parse: { left: 30, width: 15, lane: "cpu" },
|
|
257
|
+
write: { left: 50, width: 40, lane: "io" },
|
|
258
|
+
flush: { left: 95, width: 5, lane: "io" },
|
|
259
|
+
};
|
|
260
|
+
expect(laneSegments(root), "all four segments render").toHaveLength(4);
|
|
261
|
+
for (const [id, box] of Object.entries(expected)) {
|
|
262
|
+
const element = segmentById(root, id);
|
|
263
|
+
expect(element, `${id} renders`).toBeTruthy();
|
|
264
|
+
expect(element!.closest(".hk-range-ribbon-lane")?.getAttribute("data-lane")).toBe(box.lane);
|
|
265
|
+
expect(boxOf(element!).left, `${id} left`).toBeCloseTo(box.left, 4);
|
|
266
|
+
expect(boxOf(element!).width, `${id} width`).toBeCloseTo(box.width, 4);
|
|
267
|
+
}
|
|
268
|
+
// No window ⇒ no highlight, no scrims, no handles, no reset button.
|
|
269
|
+
expect(root.querySelector(".hk-range-ribbon-window")).toBeNull();
|
|
270
|
+
expect(root.querySelector(".hk-range-ribbon-scrim")).toBeNull();
|
|
271
|
+
expect(root.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
272
|
+
expect(root.querySelector(".hk-range-ribbon-reset")).toBeNull();
|
|
273
|
+
expect(root.hasAttribute("data-windowed")).toBe(false);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("clamps inverted and out-of-domain segments and drops NaN ones", () => {
|
|
277
|
+
const segments: RibbonSegment[] = [
|
|
278
|
+
{ id: "inverted", lane: "cpu", start: 0.7, end: 0.3, label: "inverted" },
|
|
279
|
+
{ id: "point", lane: "cpu", start: 0.5, end: 0.5, label: "point" },
|
|
280
|
+
{ id: "far", lane: "cpu", start: -0.5, end: 0.25, label: "far" },
|
|
281
|
+
{ id: "nan", lane: "cpu", start: Number.NaN, end: 0.4, label: "nan" },
|
|
282
|
+
{ id: "orphan", lane: "gpu", start: 0.1, end: 0.2, label: "orphan" },
|
|
283
|
+
];
|
|
284
|
+
const root = mountRibbon({ window: null, segments });
|
|
285
|
+
// Inverted → swapped, out-of-domain → clamped, zero-length kept as a tick.
|
|
286
|
+
expect(boxOf(segmentById(root, "inverted")!).left).toBeCloseTo(30, 4);
|
|
287
|
+
expect(boxOf(segmentById(root, "inverted")!).width).toBeCloseTo(40, 4);
|
|
288
|
+
expect(boxOf(segmentById(root, "point")!).left).toBeCloseTo(50, 4);
|
|
289
|
+
expect(boxOf(segmentById(root, "point")!).width).toBeCloseTo(0, 4);
|
|
290
|
+
expect(boxOf(segmentById(root, "far")!).left).toBeCloseTo(0, 4);
|
|
291
|
+
expect(boxOf(segmentById(root, "far")!).width).toBeCloseTo(25, 4);
|
|
292
|
+
// NaN is ignored…
|
|
293
|
+
expect(segmentById(root, "nan")).toBeNull();
|
|
294
|
+
// …and a segment can never invent an undeclared lane.
|
|
295
|
+
expect(segmentById(root, "orphan")).toBeNull();
|
|
296
|
+
expect(root.querySelector('[data-segment-id="orphan"]')).toBeNull();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("shares the label column with the lanes so both axes agree", () => {
|
|
300
|
+
const root = mountRibbon({ window: [0.2, 0.6] });
|
|
301
|
+
const overview = root.querySelector<HTMLElement>(".hk-range-ribbon-overview")!;
|
|
302
|
+
const gutter = overview.querySelector<HTMLElement>(".hk-range-ribbon-overview-gutter");
|
|
303
|
+
const field = overview.querySelector<HTMLElement>(".hk-range-ribbon-overview-field");
|
|
304
|
+
expect(gutter, "the overview keeps an empty label gutter").toBeTruthy();
|
|
305
|
+
expect(field, "the strip lives in the lane-matching column").toBeTruthy();
|
|
306
|
+
expect(field!.firstElementChild?.classList.contains("hk-range-ribbon-strip")).toBe(true);
|
|
307
|
+
// Handle percentages resolve against the strip's own box (the field),
|
|
308
|
+
// never against the gutter — a window edge lines up with the bar it clips.
|
|
309
|
+
expect(root.querySelector<HTMLElement>('[data-edge="start"]')!.parentElement).toBe(field);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// ── Windowed view: clipping ─────────────────────────────────────────────
|
|
314
|
+
describe("HkRangeRibbon windowed view", () => {
|
|
315
|
+
it("clips and re-normalizes only intersecting segments — the only clipping site", () => {
|
|
316
|
+
const root = mountRibbon({ window: [0.4, 0.6] });
|
|
317
|
+
|
|
318
|
+
// boot (0.05–0.2) and flush (0.95–1) are wholly outside: absent.
|
|
319
|
+
expect(segmentById(root, "boot")).toBeNull();
|
|
320
|
+
expect(segmentById(root, "flush")).toBeNull();
|
|
321
|
+
expect(laneSegments(root), "only the two intersecting segments render").toHaveLength(2);
|
|
322
|
+
|
|
323
|
+
// parse 0.3–0.45 → clipped to 0.4–0.45 → re-normalized to 0–25%.
|
|
324
|
+
// A "rebuild the bar from raw fractions" regression leaves 30%/15%.
|
|
325
|
+
const parse = segmentById(root, "parse")!;
|
|
326
|
+
expect(boxOf(parse).left, "parse re-normalized left").toBeCloseTo(0, 4);
|
|
327
|
+
expect(boxOf(parse).width, "parse re-normalized width").toBeCloseTo(25, 4);
|
|
328
|
+
|
|
329
|
+
// write 0.5–0.9 → clipped to 0.5–0.6 → 50%–100%.
|
|
330
|
+
const write = segmentById(root, "write")!;
|
|
331
|
+
expect(boxOf(write).left).toBeCloseTo(50, 4);
|
|
332
|
+
expect(boxOf(write).width).toBeCloseTo(50, 4);
|
|
333
|
+
|
|
334
|
+
// The overview still highlights exactly the window.
|
|
335
|
+
const highlight = root.querySelector<HTMLElement>(".hk-range-ribbon-window")!;
|
|
336
|
+
expect(boxOf(highlight).left).toBeCloseTo(40, 4);
|
|
337
|
+
expect(boxOf(highlight).width).toBeCloseTo(20, 4);
|
|
338
|
+
const before = root.querySelector<HTMLElement>('.hk-range-ribbon-scrim[data-side="before"]')!;
|
|
339
|
+
const after = root.querySelector<HTMLElement>('.hk-range-ribbon-scrim[data-side="after"]')!;
|
|
340
|
+
expect(boxOf(before).width, "before scrim dims 0–40%").toBeCloseTo(40, 4);
|
|
341
|
+
expect(boxOf(after).left, "after scrim starts at 60%").toBeCloseTo(60, 4);
|
|
342
|
+
expect(boxOf(after).width).toBeCloseTo(40, 4);
|
|
343
|
+
expect(root.getAttribute("data-windowed")).toBe("true");
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("keeps painting the FULL domain in the overview while the lanes are clipped", () => {
|
|
347
|
+
const root = mountRibbon({ window: [0.4, 0.6] });
|
|
348
|
+
// Negative pin for "clipping only happens in windowed lanes": the
|
|
349
|
+
// wholly-outside boot must still be painted on the overview at its
|
|
350
|
+
// FULL-domain position. If the overview reused the clipped placement
|
|
351
|
+
// (or the window were applied to both surfaces) this goes red.
|
|
352
|
+
const overview = root.querySelector<HTMLElement>(
|
|
353
|
+
'.hk-range-ribbon-overview-segment[data-segment-id="boot"]',
|
|
354
|
+
);
|
|
355
|
+
expect(overview, "the overview keeps the outside segment").toBeTruthy();
|
|
356
|
+
expect(boxOf(overview!).left, "overview left is full-domain").toBeCloseTo(5, 4);
|
|
357
|
+
expect(boxOf(overview!).width, "overview width is full-domain").toBeCloseTo(15, 4);
|
|
358
|
+
expect(root.querySelectorAll(".hk-range-ribbon-overview-segment")).toHaveLength(4);
|
|
359
|
+
// …while the lane copy of the same segment is gone.
|
|
360
|
+
expect(segmentById(root, "boot")).toBeNull();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("clips a domain-edge sliver without rescaling it against the full domain", () => {
|
|
364
|
+
const root = mountRibbon({ window: [0.9, 1] });
|
|
365
|
+
// write ends exactly at the window start (a strict-intersection test).
|
|
366
|
+
expect(segmentById(root, "write")).toBeNull();
|
|
367
|
+
const flush = segmentById(root, "flush")!;
|
|
368
|
+
expect(boxOf(flush).left).toBeCloseTo(50, 4);
|
|
369
|
+
expect(boxOf(flush).width).toBeCloseTo(50, 4);
|
|
370
|
+
expect(laneSegments(root)).toHaveLength(1);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("normalizes inverted, out-of-domain and degenerate windows; NaN means full", () => {
|
|
374
|
+
// Inverted [0.8, 0.2] → [0.2, 0.8].
|
|
375
|
+
const inverted = mountRibbon({ window: [0.8, 0.2] as unknown as [number, number] });
|
|
376
|
+
expect(boxOf(inverted.querySelector<HTMLElement>(".hk-range-ribbon-window")!).left).toBeCloseTo(
|
|
377
|
+
20,
|
|
378
|
+
4,
|
|
379
|
+
);
|
|
380
|
+
expect(
|
|
381
|
+
boxOf(inverted.querySelector<HTMLElement>(".hk-range-ribbon-window")!).width,
|
|
382
|
+
).toBeCloseTo(60, 4);
|
|
383
|
+
|
|
384
|
+
// Out-of-domain [-0.5, 0.5] → [0, 0.5]: boot 5–20% of the domain → 10–40% of the window.
|
|
385
|
+
const clamped = mountRibbon({ window: [-0.5, 0.5] as [number, number] });
|
|
386
|
+
expect(boxOf(segmentById(clamped, "boot")!).left).toBeCloseTo(10, 4);
|
|
387
|
+
expect(boxOf(segmentById(clamped, "boot")!).width).toBeCloseTo(30, 4);
|
|
388
|
+
|
|
389
|
+
// Degenerate [0.5, 0.5] expands around the point to minWindow (0.02).
|
|
390
|
+
const degenerate = mountRibbon({ window: [0.5, 0.5] });
|
|
391
|
+
const highlight = degenerate.querySelector<HTMLElement>(".hk-range-ribbon-window")!;
|
|
392
|
+
expect(boxOf(highlight).left).toBeCloseTo(49, 4);
|
|
393
|
+
expect(boxOf(highlight).width).toBeCloseTo(2, 4);
|
|
394
|
+
|
|
395
|
+
// NaN is not a window: the full domain renders with no chrome.
|
|
396
|
+
const nan = mountRibbon({ window: [Number.NaN, 0.5] as [number, number] });
|
|
397
|
+
expect(nan.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
398
|
+
expect(laneSegments(nan)).toHaveLength(4);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("clamps a minWindow above half the domain around the point and treats malformed windows as full", () => {
|
|
402
|
+
// minWindow 0.7 around 0.5 → [0.15, 0.85].
|
|
403
|
+
const wide = mountRibbon({ window: [0.5, 0.5], minWindow: 0.7 });
|
|
404
|
+
const highlight = wide.querySelector<HTMLElement>(".hk-range-ribbon-window")!;
|
|
405
|
+
expect(boxOf(highlight).left).toBeCloseTo(15, 4);
|
|
406
|
+
expect(boxOf(highlight).width).toBeCloseTo(70, 4);
|
|
407
|
+
|
|
408
|
+
// Malformed values mean "no window" (full domain), never a crash: a
|
|
409
|
+
// one-member array, an infinity and an all-NaN pair all fall back.
|
|
410
|
+
const malformed: number[][] = [
|
|
411
|
+
[0.2],
|
|
412
|
+
[0.2, Number.POSITIVE_INFINITY],
|
|
413
|
+
[Number.NaN, Number.NaN],
|
|
414
|
+
];
|
|
415
|
+
for (const window of malformed) {
|
|
416
|
+
const root = mountRibbon({ window });
|
|
417
|
+
expect(root.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
418
|
+
expect(laneSegments(root)).toHaveLength(4);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// ── Brushing ────────────────────────────────────────────────────────────
|
|
424
|
+
describe("HkRangeRibbon brush", () => {
|
|
425
|
+
it("brushes a window from a strip drag in full-domain fractions", async () => {
|
|
426
|
+
const host = mountHost(null);
|
|
427
|
+
const { strip, x } = stubStrip(host.root);
|
|
428
|
+
await drag(strip, 0.2, 0.4, x);
|
|
429
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.4);
|
|
430
|
+
expect(host.window.value).not.toBeNull();
|
|
431
|
+
expect(host.window.value![0]).toBeCloseTo(0.2, 10);
|
|
432
|
+
expect(host.window.value![1]).toBeCloseTo(0.4, 10);
|
|
433
|
+
// The host-fed window drives the lanes: only parse survives [0.2, 0.4].
|
|
434
|
+
expect(laneSegments(host.root)).toHaveLength(1);
|
|
435
|
+
expect(segmentById(host.root, "parse")).toBeTruthy();
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("clamps a sub-minimum brush to minWindow", async () => {
|
|
439
|
+
const host = mountHost(null, { minWindow: 0.1 });
|
|
440
|
+
const { strip, x } = stubStrip(host.root);
|
|
441
|
+
await drag(strip, 0.5, 0.52, x);
|
|
442
|
+
expectWindow(lastWindow(host.windowChange), 0.5, 0.6);
|
|
443
|
+
const [start, end] = lastWindow(host.windowChange)!;
|
|
444
|
+
expect(end - start, "never narrower than minWindow").toBeGreaterThanOrEqual(0.1 - 1e-9);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("shifts a min-width brush inward at the domain edge", async () => {
|
|
448
|
+
const host = mountHost(null, { minWindow: 0.1 });
|
|
449
|
+
const { strip, x } = stubStrip(host.root);
|
|
450
|
+
await drag(strip, 0.95, 0.99, x);
|
|
451
|
+
expectWindow(lastWindow(host.windowChange), 0.9, 1);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("keeps start < end for a right-to-left drag", async () => {
|
|
455
|
+
const host = mountHost(null);
|
|
456
|
+
const { strip, x } = stubStrip(host.root);
|
|
457
|
+
await drag(strip, 0.6, 0.2, x);
|
|
458
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.6);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("clamps a brush that runs past the strip to the domain", async () => {
|
|
462
|
+
const host = mountHost(null);
|
|
463
|
+
const { strip, x } = stubStrip(host.root);
|
|
464
|
+
await drag(strip, 0.1, 1.4, x);
|
|
465
|
+
expectWindow(lastWindow(host.windowChange), 0.1, 1);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("does not brush on a click without movement (negative)", async () => {
|
|
469
|
+
const host = mountHost(null);
|
|
470
|
+
const { strip, x } = stubStrip(host.root);
|
|
471
|
+
pointer("pointerdown", x(0.55), strip);
|
|
472
|
+
pointer("pointerup", x(0.55), strip);
|
|
473
|
+
await nextTick();
|
|
474
|
+
expect(host.windowChange).not.toHaveBeenCalled();
|
|
475
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(false);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("keeps its own window when no window prop or listener is supplied (uncontrolled fallback)", async () => {
|
|
479
|
+
const root = mountRibbon({});
|
|
480
|
+
const { strip, x } = stubStrip(root);
|
|
481
|
+
pointer("pointerdown", x(0.25), strip);
|
|
482
|
+
pointer("pointermove", x(0.5), strip);
|
|
483
|
+
pointer("pointerup", x(0.5), strip);
|
|
484
|
+
await nextTick();
|
|
485
|
+
expect(root.hasAttribute("data-windowed")).toBe(true);
|
|
486
|
+
const parse = segmentById(root, "parse")!;
|
|
487
|
+
expect(boxOf(parse).left).toBeCloseTo(20, 4);
|
|
488
|
+
expect(boxOf(parse).width).toBeCloseTo(60, 4);
|
|
489
|
+
expect(root.querySelector(".hk-range-ribbon-reset")).toBeTruthy();
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
// ── Pointer plumbing (capture / multi-touch / release) ──────────────────
|
|
494
|
+
describe("HkRangeRibbon pointer plumbing", () => {
|
|
495
|
+
it("captures the pointer on strip and handle pointerdown", () => {
|
|
496
|
+
const host = mountHost([0.2, 0.6]);
|
|
497
|
+
const { strip, x } = stubStrip(host.root);
|
|
498
|
+
const stripCapture = vi.fn();
|
|
499
|
+
strip.setPointerCapture = stripCapture;
|
|
500
|
+
pointer("pointerdown", x(0.5), strip);
|
|
501
|
+
expect(stripCapture, "strip captures the brush pointer").toHaveBeenCalledWith(1);
|
|
502
|
+
pointer("pointerup", x(0.5), strip);
|
|
503
|
+
|
|
504
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
505
|
+
const handleCapture = vi.fn();
|
|
506
|
+
handle.setPointerCapture = handleCapture;
|
|
507
|
+
pointer("pointerdown", x(0.6), handle);
|
|
508
|
+
expect(handleCapture, "handle captures the resize pointer").toHaveBeenCalledWith(1);
|
|
509
|
+
pointer("pointerup", x(0.6), handle);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it("ignores a second pointer while a brush is in flight", async () => {
|
|
513
|
+
const host = mountHost(null);
|
|
514
|
+
const { strip, x } = stubStrip(host.root);
|
|
515
|
+
pointer("pointerdown", x(0.2), strip, { pointerId: 1 });
|
|
516
|
+
pointer("pointerdown", x(0.8), strip, { pointerId: 2 }); // second finger
|
|
517
|
+
pointer("pointermove", x(0.4), strip, { pointerId: 1 });
|
|
518
|
+
await nextTick();
|
|
519
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.4);
|
|
520
|
+
|
|
521
|
+
// The other pointer's release must not end the first drag…
|
|
522
|
+
const calls = host.windowChange.mock.calls.length;
|
|
523
|
+
pointer("pointerup", x(0.4), strip, { pointerId: 2 });
|
|
524
|
+
pointer("pointermove", x(0.5), strip, { pointerId: 1 });
|
|
525
|
+
await nextTick();
|
|
526
|
+
expect(host.windowChange.mock.calls.length).toBe(calls + 1);
|
|
527
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.5);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("ends the gesture when the pointer is released outside the ribbon", async () => {
|
|
531
|
+
const host = mountHost(null);
|
|
532
|
+
const { strip, x } = stubStrip(host.root);
|
|
533
|
+
pointer("pointerdown", x(0.2), strip);
|
|
534
|
+
pointer("pointermove", x(0.3), strip);
|
|
535
|
+
await nextTick();
|
|
536
|
+
let calls = host.windowChange.mock.calls.length;
|
|
537
|
+
|
|
538
|
+
document.body.dispatchEvent(
|
|
539
|
+
new PointerEvent("pointerup", {
|
|
540
|
+
bubbles: true,
|
|
541
|
+
pointerId: 1,
|
|
542
|
+
pointerType: "mouse",
|
|
543
|
+
clientX: x(0.9),
|
|
544
|
+
clientY: 10,
|
|
545
|
+
button: 0,
|
|
546
|
+
}),
|
|
547
|
+
);
|
|
548
|
+
document.body.dispatchEvent(
|
|
549
|
+
new PointerEvent("pointermove", {
|
|
550
|
+
bubbles: true,
|
|
551
|
+
pointerId: 1,
|
|
552
|
+
pointerType: "mouse",
|
|
553
|
+
clientX: x(0.9),
|
|
554
|
+
clientY: 10,
|
|
555
|
+
}),
|
|
556
|
+
);
|
|
557
|
+
await nextTick();
|
|
558
|
+
expect(host.windowChange.mock.calls.length, "released drag stops tracking").toBe(calls);
|
|
559
|
+
|
|
560
|
+
// pointercancel ends it too.
|
|
561
|
+
pointer("pointerdown", x(0.1), strip);
|
|
562
|
+
pointer("pointermove", x(0.2), strip);
|
|
563
|
+
await nextTick();
|
|
564
|
+
calls = host.windowChange.mock.calls.length;
|
|
565
|
+
document.body.dispatchEvent(
|
|
566
|
+
new PointerEvent("pointercancel", {
|
|
567
|
+
bubbles: true,
|
|
568
|
+
pointerId: 1,
|
|
569
|
+
pointerType: "mouse",
|
|
570
|
+
clientX: x(0.2),
|
|
571
|
+
clientY: 10,
|
|
572
|
+
}),
|
|
573
|
+
);
|
|
574
|
+
document.body.dispatchEvent(
|
|
575
|
+
new PointerEvent("pointermove", {
|
|
576
|
+
bubbles: true,
|
|
577
|
+
pointerId: 1,
|
|
578
|
+
pointerType: "mouse",
|
|
579
|
+
clientX: x(0.6),
|
|
580
|
+
clientY: 10,
|
|
581
|
+
}),
|
|
582
|
+
);
|
|
583
|
+
await nextTick();
|
|
584
|
+
expect(host.windowChange.mock.calls.length, "cancelled drag stops tracking").toBe(calls);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it("brushes with touch pointers", async () => {
|
|
588
|
+
const host = mountHost(null);
|
|
589
|
+
const { strip, x } = stubStrip(host.root);
|
|
590
|
+
pointer("pointerdown", x(0.25), strip, { pointerType: "touch", pointerId: 3 });
|
|
591
|
+
pointer("pointermove", x(0.5), strip, { pointerType: "touch", pointerId: 3 });
|
|
592
|
+
pointer("pointerup", x(0.5), strip, { pointerType: "touch", pointerId: 3 });
|
|
593
|
+
await nextTick();
|
|
594
|
+
expectWindow(lastWindow(host.windowChange), 0.25, 0.5);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it("ignores sub-pixel jitter on a click (3px brush slop)", async () => {
|
|
598
|
+
const host = mountHost(null);
|
|
599
|
+
const { strip, x } = stubStrip(host.root);
|
|
600
|
+
|
|
601
|
+
pointer("pointerdown", x(0.5), strip);
|
|
602
|
+
pointer("pointermove", x(0.5) + 2, strip); // 2px: under the slop
|
|
603
|
+
pointer("pointerup", x(0.5) + 2, strip);
|
|
604
|
+
await nextTick();
|
|
605
|
+
expect(host.windowChange, "a jittery click must not zoom").not.toHaveBeenCalled();
|
|
606
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(false);
|
|
607
|
+
|
|
608
|
+
// 4px clears the slop: this is a real brush.
|
|
609
|
+
pointer("pointerdown", x(0.5), strip);
|
|
610
|
+
pointer("pointermove", x(0.5) + 4, strip);
|
|
611
|
+
pointer("pointerup", x(0.5) + 4, strip);
|
|
612
|
+
await nextTick();
|
|
613
|
+
expect(host.windowChange).toHaveBeenCalled();
|
|
614
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(true);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it("gives touch pointers a wider brush slop", async () => {
|
|
618
|
+
const host = mountHost(null);
|
|
619
|
+
const { strip, x } = stubStrip(host.root);
|
|
620
|
+
|
|
621
|
+
// A touch tap drifts 4-6px in practice: 6px must still be a tap.
|
|
622
|
+
pointer("pointerdown", x(0.5), strip, { pointerType: "touch", pointerId: 4 });
|
|
623
|
+
pointer("pointermove", x(0.5) + 6, strip, { pointerType: "touch", pointerId: 4 });
|
|
624
|
+
pointer("pointerup", x(0.5) + 6, strip, { pointerType: "touch", pointerId: 4 });
|
|
625
|
+
await nextTick();
|
|
626
|
+
expect(host.windowChange, "a 6px touch tap must not zoom").not.toHaveBeenCalled();
|
|
627
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(false);
|
|
628
|
+
|
|
629
|
+
// 12px clears the touch slop: this is a real brush.
|
|
630
|
+
pointer("pointerdown", x(0.5), strip, { pointerType: "touch", pointerId: 4 });
|
|
631
|
+
pointer("pointermove", x(0.5) + 12, strip, { pointerType: "touch", pointerId: 4 });
|
|
632
|
+
pointer("pointerup", x(0.5) + 12, strip, { pointerType: "touch", pointerId: 4 });
|
|
633
|
+
await nextTick();
|
|
634
|
+
expect(host.windowChange).toHaveBeenCalled();
|
|
635
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(true);
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// ── Handles ─────────────────────────────────────────────────────────────
|
|
640
|
+
describe("HkRangeRibbon handles", () => {
|
|
641
|
+
it("moves exactly one edge when the start handle is dragged", async () => {
|
|
642
|
+
const host = mountHost([0.2, 0.6], { minWindow: 0.1 });
|
|
643
|
+
const { x } = stubStrip(host.root);
|
|
644
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="start"]')!;
|
|
645
|
+
pointer("pointerdown", x(0.2), handle);
|
|
646
|
+
pointer("pointermove", x(0.35), handle);
|
|
647
|
+
pointer("pointerup", x(0.35), handle);
|
|
648
|
+
await nextTick();
|
|
649
|
+
expectWindow(lastWindow(host.windowChange), 0.35, 0.6);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it("moves exactly one edge when the end handle is dragged", async () => {
|
|
653
|
+
const host = mountHost([0.2, 0.6], { minWindow: 0.1 });
|
|
654
|
+
const { x } = stubStrip(host.root);
|
|
655
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
656
|
+
pointer("pointerdown", x(0.6), handle);
|
|
657
|
+
pointer("pointermove", x(0.75), handle);
|
|
658
|
+
pointer("pointerup", x(0.75), handle);
|
|
659
|
+
await nextTick();
|
|
660
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.75);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("stops the end handle at minWindow and never crosses the start edge", async () => {
|
|
664
|
+
const host = mountHost([0.2, 0.6], { minWindow: 0.1 });
|
|
665
|
+
const { x } = stubStrip(host.root);
|
|
666
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
667
|
+
pointer("pointerdown", x(0.6), handle);
|
|
668
|
+
pointer("pointermove", x(0.05), handle);
|
|
669
|
+
pointer("pointerup", x(0.05), handle);
|
|
670
|
+
await nextTick();
|
|
671
|
+
expectWindow(lastWindow(host.windowChange), 0.2, 0.3);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it("stops the start handle at minWindow and never crosses the end edge", async () => {
|
|
675
|
+
const host = mountHost([0.2, 0.6], { minWindow: 0.1 });
|
|
676
|
+
const { x } = stubStrip(host.root);
|
|
677
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="start"]')!;
|
|
678
|
+
pointer("pointerdown", x(0.2), handle);
|
|
679
|
+
pointer("pointermove", x(0.95), handle);
|
|
680
|
+
pointer("pointerup", x(0.95), handle);
|
|
681
|
+
await nextTick();
|
|
682
|
+
expectWindow(lastWindow(host.windowChange), 0.5, 0.6);
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it("emits FULL-DOMAIN absolute fractions when dragging a handle inside an active window", async () => {
|
|
686
|
+
// The chest row filter consumes this value: a drag on the right handle
|
|
687
|
+
// of [0.2, 0.4] to the middle of the ZOOMED strip must answer
|
|
688
|
+
// [0.2, 0.5] in full-domain fractions — a window-relative bug would
|
|
689
|
+
// answer [0.2, 0.7] (or renormalize the start to 0).
|
|
690
|
+
const host = mountHost([0.2, 0.4], { minWindow: 0.02 });
|
|
691
|
+
const { x } = stubStrip(host.root);
|
|
692
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
693
|
+
pointer("pointerdown", x(0.4), handle);
|
|
694
|
+
pointer("pointermove", x(0.5), handle);
|
|
695
|
+
pointer("pointerup", x(0.5), handle);
|
|
696
|
+
await nextTick();
|
|
697
|
+
const emitted = lastWindow(host.windowChange);
|
|
698
|
+
expectWindow(emitted, 0.2, 0.5);
|
|
699
|
+
// The start edge must be untouched, in absolute domain terms.
|
|
700
|
+
expect(emitted![0], "start stays 0.2 absolute, not window-relative").toBeCloseTo(0.2, 10);
|
|
701
|
+
// …and the rendered chrome agrees: start handle at 20%, end at 50%.
|
|
702
|
+
const startHandle = host.root.querySelector<HTMLElement>('[data-edge="start"]')!;
|
|
703
|
+
const endHandle = host.root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
704
|
+
expect(parseFloat(startHandle.style.left)).toBeCloseTo(20, 4);
|
|
705
|
+
expect(parseFloat(endHandle.style.left)).toBeCloseTo(50, 4);
|
|
706
|
+
const highlight = host.root.querySelector<HTMLElement>(".hk-range-ribbon-window")!;
|
|
707
|
+
expect(boxOf(highlight).left, "highlight left is 20% of the full domain").toBeCloseTo(20, 4);
|
|
708
|
+
expect(boxOf(highlight).width).toBeCloseTo(30, 4);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
it("nudges only its own edge from the keyboard", async () => {
|
|
712
|
+
const host = mountHost([0.4, 0.6], { minWindow: 0.02 });
|
|
713
|
+
const handle = host.root.querySelector<HTMLElement>('[data-edge="start"]')!;
|
|
714
|
+
keydown(handle, "ArrowRight");
|
|
715
|
+
await nextTick();
|
|
716
|
+
expectWindow(lastWindow(host.windowChange), 0.45, 0.6);
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// ── Reset paths ─────────────────────────────────────────────────────────
|
|
721
|
+
describe("HkRangeRibbon reset", () => {
|
|
722
|
+
it("resets through the button and restores the full view", async () => {
|
|
723
|
+
const host = mountHost([0.2, 0.6]);
|
|
724
|
+
const button = host.root.querySelector<HTMLElement>(".hk-range-ribbon-reset");
|
|
725
|
+
expect(button, "reset button is shown while a window exists").toBeTruthy();
|
|
726
|
+
button!.click();
|
|
727
|
+
await nextTick();
|
|
728
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
729
|
+
expect(host.window.value).toBeNull();
|
|
730
|
+
expect(host.root.querySelector(".hk-range-ribbon-reset")).toBeNull();
|
|
731
|
+
expect(host.root.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
732
|
+
// Full view restored — not just the highlight removed.
|
|
733
|
+
expect(laneSegments(host.root)).toHaveLength(4);
|
|
734
|
+
expect(boxOf(segmentById(host.root, "boot")!).left).toBeCloseTo(5, 4);
|
|
735
|
+
expect(boxOf(segmentById(host.root, "flush")!).left).toBeCloseTo(95, 4);
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
it("resets on a double-click on the strip", async () => {
|
|
739
|
+
const host = mountHost([0.2, 0.6]);
|
|
740
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
741
|
+
strip.dispatchEvent(new MouseEvent("dblclick", { bubbles: true, cancelable: true }));
|
|
742
|
+
await nextTick();
|
|
743
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
744
|
+
expect(laneSegments(host.root)).toHaveLength(4);
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
it("only consumes a double-click when it actually resets", async () => {
|
|
748
|
+
const idle = mountHost(null);
|
|
749
|
+
const idleEvent = new MouseEvent("dblclick", { bubbles: true, cancelable: true });
|
|
750
|
+
idle.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!.dispatchEvent(idleEvent);
|
|
751
|
+
await nextTick();
|
|
752
|
+
expect(idle.windowChange).not.toHaveBeenCalled();
|
|
753
|
+
expect(idleEvent.defaultPrevented, "nothing to reset: the host keeps the event").toBe(false);
|
|
754
|
+
|
|
755
|
+
const host = mountHost([0.2, 0.6]);
|
|
756
|
+
const event = new MouseEvent("dblclick", { bubbles: true, cancelable: true });
|
|
757
|
+
host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!.dispatchEvent(event);
|
|
758
|
+
await nextTick();
|
|
759
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
760
|
+
expect(event.defaultPrevented).toBe(true);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it("resets on Escape", async () => {
|
|
764
|
+
const host = mountHost([0.2, 0.6]);
|
|
765
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
766
|
+
const event = keydown(strip, "Escape");
|
|
767
|
+
await nextTick();
|
|
768
|
+
expect(event.defaultPrevented).toBe(true);
|
|
769
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it("resets on Home", async () => {
|
|
773
|
+
const host = mountHost([0.2, 0.6]);
|
|
774
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
775
|
+
keydown(strip, "Home");
|
|
776
|
+
await nextTick();
|
|
777
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it("resets on Home from the reset button too", async () => {
|
|
781
|
+
const host = mountHost([0.2, 0.6]);
|
|
782
|
+
const button = host.root.querySelector<HTMLElement>(".hk-range-ribbon-reset")!;
|
|
783
|
+
const event = keydown(button, "Home");
|
|
784
|
+
await nextTick();
|
|
785
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
786
|
+
expect(event.defaultPrevented).toBe(true);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
it("leaves Escape to the host when there is nothing to reset", async () => {
|
|
790
|
+
const host = mountHost(null);
|
|
791
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
792
|
+
const event = keydown(strip, "Escape");
|
|
793
|
+
await nextTick();
|
|
794
|
+
expect(host.windowChange, "no window: nothing resets").not.toHaveBeenCalled();
|
|
795
|
+
expect(event.defaultPrevented, "a host dialog must still see Escape").toBe(false);
|
|
796
|
+
|
|
797
|
+
// With a window the reset really happens, so Escape is consumed.
|
|
798
|
+
await host.setWindow([0.2, 0.6]);
|
|
799
|
+
const second = keydown(host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!, "Escape");
|
|
800
|
+
await nextTick();
|
|
801
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
802
|
+
expect(second.defaultPrevented).toBe(true);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("drops an in-flight brush when a reset interrupts it", async () => {
|
|
806
|
+
const host = mountHost(null);
|
|
807
|
+
const { strip, x } = stubStrip(host.root);
|
|
808
|
+
pointer("pointerdown", x(0.2), strip);
|
|
809
|
+
pointer("pointermove", x(0.4), strip);
|
|
810
|
+
await nextTick();
|
|
811
|
+
const afterBrush = host.windowChange.mock.calls.length;
|
|
812
|
+
expect(afterBrush, "the brush emitted").toBeGreaterThan(0);
|
|
813
|
+
|
|
814
|
+
keydown(strip, "Escape");
|
|
815
|
+
await nextTick();
|
|
816
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
817
|
+
const afterReset = host.windowChange.mock.calls.length;
|
|
818
|
+
|
|
819
|
+
// The pointer is still down, but the reset cleared the gesture: the
|
|
820
|
+
// next move must not re-brush from the stale anchor.
|
|
821
|
+
pointer("pointermove", x(0.8), strip);
|
|
822
|
+
await nextTick();
|
|
823
|
+
expect(host.windowChange.mock.calls.length, "no brush after the reset").toBe(afterReset);
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it("hides the reset button when no window exists (negative)", () => {
|
|
827
|
+
const root = mountRibbon({ window: null });
|
|
828
|
+
expect(root.querySelector(".hk-range-ribbon-reset")).toBeNull();
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
// ── Keyboard ────────────────────────────────────────────────────────────
|
|
833
|
+
describe("HkRangeRibbon keyboard", () => {
|
|
834
|
+
it("slides the window with the arrow keys, clamped to the domain", async () => {
|
|
835
|
+
const host = mountHost([0.4, 0.6]);
|
|
836
|
+
let strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
837
|
+
keydown(strip, "ArrowRight");
|
|
838
|
+
await nextTick();
|
|
839
|
+
expectWindow(lastWindow(host.windowChange), 0.45, 0.65);
|
|
840
|
+
|
|
841
|
+
// At the right edge the width is preserved and the end clamps to 1.
|
|
842
|
+
await host.setWindow([0.9, 0.98]);
|
|
843
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
844
|
+
keydown(strip, "ArrowRight");
|
|
845
|
+
await nextTick();
|
|
846
|
+
expectWindow(lastWindow(host.windowChange), 0.92, 1);
|
|
847
|
+
|
|
848
|
+
// …and symmetrically at the left edge.
|
|
849
|
+
await host.setWindow([0.02, 0.1]);
|
|
850
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
851
|
+
keydown(strip, "ArrowLeft");
|
|
852
|
+
await nextTick();
|
|
853
|
+
expectWindow(lastWindow(host.windowChange), 0, 0.08);
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
it("resizes from the trailing edge with Shift+Arrow, clamped to minWindow", async () => {
|
|
857
|
+
const host = mountHost([0.4, 0.6], { minWindow: 0.02 });
|
|
858
|
+
let strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
859
|
+
keydown(strip, "ArrowRight", { shiftKey: true });
|
|
860
|
+
await nextTick();
|
|
861
|
+
expectWindow(lastWindow(host.windowChange), 0.4, 0.65);
|
|
862
|
+
|
|
863
|
+
await host.setWindow([0.4, 0.45]);
|
|
864
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
865
|
+
keydown(strip, "ArrowLeft", { shiftKey: true });
|
|
866
|
+
await nextTick();
|
|
867
|
+
expectWindow(lastWindow(host.windowChange), 0.4, 0.42);
|
|
868
|
+
|
|
869
|
+
await host.setWindow([0.94, 0.99]);
|
|
870
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
871
|
+
keydown(strip, "ArrowRight", { shiftKey: true });
|
|
872
|
+
await nextTick();
|
|
873
|
+
expectWindow(lastWindow(host.windowChange), 0.94, 1);
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
it("contracts the full domain into a window with Shift+Arrow; plain arrows stay inert (negative)", async () => {
|
|
877
|
+
const host = mountHost(null);
|
|
878
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
879
|
+
|
|
880
|
+
// A bare arrow cannot brush without a brush: no window, no emission —
|
|
881
|
+
// and the arrow is left un-prevented for the host.
|
|
882
|
+
const bareArrow = keydown(strip, "ArrowRight");
|
|
883
|
+
await nextTick();
|
|
884
|
+
expect(host.windowChange).not.toHaveBeenCalled();
|
|
885
|
+
expect(bareArrow.defaultPrevented, "an inert arrow is not swallowed").toBe(false);
|
|
886
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(false);
|
|
887
|
+
|
|
888
|
+
// Shift+Arrow is the keyboard entry point into windowed mode.
|
|
889
|
+
keydown(strip, "ArrowLeft", { shiftKey: true });
|
|
890
|
+
await nextTick();
|
|
891
|
+
expectWindow(lastWindow(host.windowChange), 0, 0.95);
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
it("does not emit an identical window at a domain edge", async () => {
|
|
895
|
+
const host = mountHost([0.9, 1]);
|
|
896
|
+
let strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
897
|
+
let event = keydown(strip, "ArrowRight");
|
|
898
|
+
await nextTick();
|
|
899
|
+
expect(host.windowChange, "sliding past the right edge is a no-op").not.toHaveBeenCalled();
|
|
900
|
+
expect(event.defaultPrevented).toBe(false);
|
|
901
|
+
|
|
902
|
+
await host.setWindow([0, 0.1]);
|
|
903
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
904
|
+
event = keydown(strip, "ArrowLeft");
|
|
905
|
+
await nextTick();
|
|
906
|
+
expect(host.windowChange, "sliding past the left edge is a no-op").not.toHaveBeenCalled();
|
|
907
|
+
expect(event.defaultPrevented).toBe(false);
|
|
908
|
+
|
|
909
|
+
await host.setWindow([0.4, 1]);
|
|
910
|
+
strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
911
|
+
event = keydown(strip, "ArrowRight", { shiftKey: true });
|
|
912
|
+
await nextTick();
|
|
913
|
+
expect(host.windowChange, "growing past the right edge is a no-op").not.toHaveBeenCalled();
|
|
914
|
+
expect(event.defaultPrevented).toBe(false);
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
it("keeps Home for the range surface and Escape for the whole ribbon", async () => {
|
|
918
|
+
const host = mountHost([0.2, 0.6]);
|
|
919
|
+
const segment = segmentById(host.root, "write")!;
|
|
920
|
+
|
|
921
|
+
// A focused segment keeps its native Home (caret/scroll) behaviour.
|
|
922
|
+
const homeOnSegment = keydown(segment, "Home");
|
|
923
|
+
await nextTick();
|
|
924
|
+
expect(host.windowChange, "Home on a segment does not reset").not.toHaveBeenCalled();
|
|
925
|
+
expect(homeOnSegment.defaultPrevented).toBe(false);
|
|
926
|
+
|
|
927
|
+
// Escape still resets from anywhere inside the ribbon.
|
|
928
|
+
keydown(segment, "Escape");
|
|
929
|
+
await nextTick();
|
|
930
|
+
expect(host.windowChange).toHaveBeenLastCalledWith(null);
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
// ── Selection ───────────────────────────────────────────────────────────
|
|
935
|
+
describe("HkRangeRibbon selection", () => {
|
|
936
|
+
it("selects on click and paints selectedId as data-selected", async () => {
|
|
937
|
+
const host = mountHost([0.2, 0.6]);
|
|
938
|
+
segmentById(host.root, "write")!.click();
|
|
939
|
+
await nextTick();
|
|
940
|
+
expect(host.select).toHaveBeenCalledWith("write");
|
|
941
|
+
|
|
942
|
+
const root = mountRibbon({ window: null, selectedId: "parse" });
|
|
943
|
+
expect(segmentById(root, "parse")!.getAttribute("data-selected")).toBe("true");
|
|
944
|
+
expect(segmentById(root, "boot")!.hasAttribute("data-selected")).toBe(false);
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("selects with Enter and Space from the keyboard", async () => {
|
|
948
|
+
const host = mountHost(null);
|
|
949
|
+
const parse = segmentById(host.root, "parse")!;
|
|
950
|
+
const enter = keydown(parse, "Enter");
|
|
951
|
+
await nextTick();
|
|
952
|
+
expect(enter.defaultPrevented).toBe(true);
|
|
953
|
+
expect(host.select).toHaveBeenCalledWith("parse");
|
|
954
|
+
keydown(parse, " ");
|
|
955
|
+
await nextTick();
|
|
956
|
+
expect(host.select).toHaveBeenCalledTimes(2);
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
it("paints tone, kind and status onto the lane bars", () => {
|
|
960
|
+
const segments: RibbonSegment[] = [
|
|
961
|
+
{
|
|
962
|
+
id: "tinted",
|
|
963
|
+
lane: "cpu",
|
|
964
|
+
start: 0.1,
|
|
965
|
+
end: 0.3,
|
|
966
|
+
label: "tinted",
|
|
967
|
+
tone: "warning",
|
|
968
|
+
kind: "wave",
|
|
969
|
+
},
|
|
970
|
+
{ id: "queued", lane: "cpu", start: 0.4, end: 0.6, label: "queued", status: "pending" },
|
|
971
|
+
{ id: "failed", lane: "cpu", start: 0.7, end: 0.9, label: "failed", status: "error" },
|
|
972
|
+
{ id: "plain", lane: "cpu", start: 0.92, end: 0.98, label: "plain" },
|
|
973
|
+
];
|
|
974
|
+
const root = mountRibbon({ window: null, segments });
|
|
975
|
+
const tinted = segmentById(root, "tinted")!;
|
|
976
|
+
expect(tinted.getAttribute("data-tone")).toBe("warning");
|
|
977
|
+
expect(tinted.getAttribute("data-kind")).toBe("wave");
|
|
978
|
+
expect(segmentById(root, "queued")!.getAttribute("data-status")).toBe("pending");
|
|
979
|
+
expect(segmentById(root, "failed")!.getAttribute("data-status")).toBe("error");
|
|
980
|
+
// A plain row carries none of the optional markers (no "undefined" text).
|
|
981
|
+
const plain = segmentById(root, "plain")!;
|
|
982
|
+
expect(plain.hasAttribute("data-tone")).toBe(false);
|
|
983
|
+
expect(plain.hasAttribute("data-kind")).toBe(false);
|
|
984
|
+
expect(plain.hasAttribute("data-status")).toBe(false);
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
// ── Tip card ────────────────────────────────────────────────────────────
|
|
989
|
+
describe("HkRangeRibbon tip card", () => {
|
|
990
|
+
it("floats the title and lines on hover and leaves on mouseleave", async () => {
|
|
991
|
+
const root = mountRibbon({ window: null });
|
|
992
|
+
const flush = segmentById(root, "flush")!;
|
|
993
|
+
flush.dispatchEvent(new MouseEvent("mouseenter"));
|
|
994
|
+
await nextTick();
|
|
995
|
+
const tip = flush.querySelector<HTMLElement>(".hk-range-ribbon-tip");
|
|
996
|
+
expect(tip, "tip card renders on hover").toBeTruthy();
|
|
997
|
+
expect(tip!.getAttribute("role")).toBe("tooltip");
|
|
998
|
+
expect(tip!.querySelector(".hk-range-ribbon-tip-title")?.textContent).toBe("Flush stall");
|
|
999
|
+
expect(
|
|
1000
|
+
Array.from(tip!.querySelectorAll(".hk-range-ribbon-tip-line")).map((line) => line.textContent),
|
|
1001
|
+
).toEqual(["waited 12ms", "retried once"]);
|
|
1002
|
+
|
|
1003
|
+
flush.dispatchEvent(new MouseEvent("mouseleave"));
|
|
1004
|
+
await nextTick();
|
|
1005
|
+
expect(flush.querySelector(".hk-range-ribbon-tip")).toBeNull();
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
it("floats on focus and hides on blur", async () => {
|
|
1009
|
+
const root = mountRibbon({ window: null });
|
|
1010
|
+
const flush = segmentById(root, "flush")!;
|
|
1011
|
+
flush.dispatchEvent(new FocusEvent("focus"));
|
|
1012
|
+
await nextTick();
|
|
1013
|
+
expect(flush.querySelector(".hk-range-ribbon-tip")).toBeTruthy();
|
|
1014
|
+
flush.dispatchEvent(new FocusEvent("blur"));
|
|
1015
|
+
await nextTick();
|
|
1016
|
+
expect(flush.querySelector(".hk-range-ribbon-tip")).toBeNull();
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
it("floats nothing for a segment without a tip (negative)", async () => {
|
|
1020
|
+
const root = mountRibbon({ window: null });
|
|
1021
|
+
const parse = segmentById(root, "parse")!;
|
|
1022
|
+
parse.dispatchEvent(new MouseEvent("mouseenter"));
|
|
1023
|
+
await nextTick();
|
|
1024
|
+
expect(parse.querySelector(".hk-range-ribbon-tip")).toBeNull();
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
it("does not resurrect a tip for a segment that left the window", async () => {
|
|
1028
|
+
const host = mountHost(null);
|
|
1029
|
+
const flush = segmentById(host.root, "flush")!;
|
|
1030
|
+
flush.dispatchEvent(new MouseEvent("mouseenter"));
|
|
1031
|
+
await nextTick();
|
|
1032
|
+
expect(flush.querySelector(".hk-range-ribbon-tip"), "tip floats on hover").toBeTruthy();
|
|
1033
|
+
|
|
1034
|
+
// Narrow the window until the hovered segment is clipped out: its bar
|
|
1035
|
+
// unmounts without a mouseleave, and the tip id must not survive it.
|
|
1036
|
+
await host.setWindow([0.2, 0.6]);
|
|
1037
|
+
expect(segmentById(host.root, "flush")).toBeNull();
|
|
1038
|
+
expect(host.root.querySelector(".hk-range-ribbon-tip")).toBeNull();
|
|
1039
|
+
|
|
1040
|
+
// Restoring the full domain re-renders the bar — with NO tip, because
|
|
1041
|
+
// nothing is hovering or focusing it any more.
|
|
1042
|
+
await host.setWindow(null);
|
|
1043
|
+
expect(segmentById(host.root, "flush")).toBeTruthy();
|
|
1044
|
+
expect(host.root.querySelector(".hk-range-ribbon-tip")).toBeNull();
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
it("anchors the tip inward at the track edges", async () => {
|
|
1048
|
+
const segments: RibbonSegment[] = [
|
|
1049
|
+
{ id: "left", lane: "cpu", start: 0.02, end: 0.12, label: "left", tip: { title: "Left" } },
|
|
1050
|
+
{ id: "mid", lane: "cpu", start: 0.45, end: 0.55, label: "mid", tip: { title: "Mid" } },
|
|
1051
|
+
{ id: "right", lane: "cpu", start: 0.9, end: 0.99, label: "right", tip: { title: "Right" } },
|
|
1052
|
+
{ id: "quarter", lane: "cpu", start: 0.2, end: 0.3, label: "quarter", tip: { title: "Q" } },
|
|
1053
|
+
{ id: "threequarter", lane: "cpu", start: 0.7, end: 0.8, label: "threequarter", tip: { title: "TQ" } },
|
|
1054
|
+
];
|
|
1055
|
+
const root = mountRibbon({ window: null, segments });
|
|
1056
|
+
const anchorOf = async (id: string): Promise<string | null> => {
|
|
1057
|
+
const bar = segmentById(root, id)!;
|
|
1058
|
+
bar.dispatchEvent(new MouseEvent("mouseenter"));
|
|
1059
|
+
await nextTick();
|
|
1060
|
+
return bar.querySelector<HTMLElement>(".hk-range-ribbon-tip")!.getAttribute("data-anchor");
|
|
1061
|
+
};
|
|
1062
|
+
// The card grows away from the edge it would otherwise overflow.
|
|
1063
|
+
expect(await anchorOf("left"), "near the track start").toBe("start"); // center 7%
|
|
1064
|
+
expect(await anchorOf("mid"), "mid-track").toBe("middle"); // center 50%
|
|
1065
|
+
expect(await anchorOf("right"), "near the track end").toBe("end"); // center 94.5%
|
|
1066
|
+
// The thresholds are exclusive: exactly 25% / 75% still centres.
|
|
1067
|
+
expect(await anchorOf("quarter"), "exactly 25%").toBe("middle");
|
|
1068
|
+
expect(await anchorOf("threequarter"), "exactly 75%").toBe("middle");
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
// ── A11y + i18n ─────────────────────────────────────────────────────────
|
|
1073
|
+
describe("HkRangeRibbon a11y and i18n", () => {
|
|
1074
|
+
it("wires the strip and both handles as sliders with min/max/now", () => {
|
|
1075
|
+
const root = mountRibbon({ window: [0.2, 0.6] });
|
|
1076
|
+
const strip = root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
1077
|
+
expect(strip.getAttribute("role")).toBe("slider");
|
|
1078
|
+
expect(strip.getAttribute("aria-orientation")).toBe("horizontal");
|
|
1079
|
+
expect(strip.getAttribute("aria-valuemin")).toBe("0");
|
|
1080
|
+
expect(strip.getAttribute("aria-valuemax")).toBe("100");
|
|
1081
|
+
expect(strip.getAttribute("aria-valuenow"), "strip value = window start").toBe("20");
|
|
1082
|
+
expect(strip.getAttribute("aria-valuetext")).toBe("20% – 60%");
|
|
1083
|
+
expect(strip.getAttribute("aria-label")).toBe("Observation range");
|
|
1084
|
+
|
|
1085
|
+
const start = root.querySelector<HTMLElement>('[data-edge="start"]')!;
|
|
1086
|
+
expect(start.getAttribute("role")).toBe("slider");
|
|
1087
|
+
expect(start.getAttribute("aria-orientation")).toBe("horizontal");
|
|
1088
|
+
expect(start.getAttribute("aria-valuemin")).toBe("0");
|
|
1089
|
+
expect(start.getAttribute("aria-valuemax")).toBe("58");
|
|
1090
|
+
expect(start.getAttribute("aria-valuenow")).toBe("20");
|
|
1091
|
+
expect(start.getAttribute("aria-label")).toBe("Window start");
|
|
1092
|
+
|
|
1093
|
+
const end = root.querySelector<HTMLElement>('[data-edge="end"]')!;
|
|
1094
|
+
expect(end.getAttribute("role")).toBe("slider");
|
|
1095
|
+
expect(end.getAttribute("aria-orientation")).toBe("horizontal");
|
|
1096
|
+
expect(end.getAttribute("aria-valuemin")).toBe("22");
|
|
1097
|
+
expect(end.getAttribute("aria-valuemax")).toBe("100");
|
|
1098
|
+
expect(end.getAttribute("aria-valuenow")).toBe("60");
|
|
1099
|
+
expect(end.getAttribute("aria-label")).toBe("Window end");
|
|
1100
|
+
|
|
1101
|
+
// The hint described by the strip labels the keyboard contract.
|
|
1102
|
+
const describedBy = strip.getAttribute("aria-describedby");
|
|
1103
|
+
expect(describedBy, "strip points at its keyboard hint").toBeTruthy();
|
|
1104
|
+
const hint = document.getElementById(describedBy!);
|
|
1105
|
+
expect(hint, "hint element exists").toBeTruthy();
|
|
1106
|
+
expect(hint!.textContent).toContain("Move window");
|
|
1107
|
+
expect(hint!.textContent).toContain("Resize window");
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
it("localizes the labels and hint from the active locale bundle", async () => {
|
|
1111
|
+
await setLocale("ja");
|
|
1112
|
+
const root = mountRibbon({ window: [0.2, 0.6] });
|
|
1113
|
+
const strip = root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
1114
|
+
expect(strip.getAttribute("aria-label")).toBe(jaBundle["hikari::ribbon.rangeAria"]);
|
|
1115
|
+
expect(root.querySelector<HTMLElement>('[data-edge="start"]')!.getAttribute("aria-label")).toBe(
|
|
1116
|
+
jaBundle["hikari::ribbon.windowStart"],
|
|
1117
|
+
);
|
|
1118
|
+
expect(root.querySelector<HTMLElement>('[data-edge="end"]')!.getAttribute("aria-label")).toBe(
|
|
1119
|
+
jaBundle["hikari::ribbon.windowEnd"],
|
|
1120
|
+
);
|
|
1121
|
+
expect(
|
|
1122
|
+
root.querySelector<HTMLElement>(".hk-range-ribbon-reset")!.getAttribute("aria-label"),
|
|
1123
|
+
).toBe(jaBundle["hikari::ribbon.reset"]);
|
|
1124
|
+
const hint = document.getElementById(strip.getAttribute("aria-describedby")!);
|
|
1125
|
+
expect(hint!.textContent).toContain(jaBundle["hikari::ribbon.moveWindow"]);
|
|
1126
|
+
expect(hint!.textContent).toContain(jaBundle["hikari::ribbon.resizeWindow"]);
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
it("windowEnabled=false renders a static full-domain view and ignores the window", async () => {
|
|
1130
|
+
const host = mountHost([0.4, 0.6], { windowEnabled: false });
|
|
1131
|
+
expect(host.root.getAttribute("data-window-enabled")).toBe("false");
|
|
1132
|
+
expect(host.root.hasAttribute("data-windowed")).toBe(false);
|
|
1133
|
+
// A supplied window is ignored: the full domain renders, chrome gone.
|
|
1134
|
+
expect(laneSegments(host.root)).toHaveLength(4);
|
|
1135
|
+
expect(host.root.querySelector(".hk-range-ribbon-window")).toBeNull();
|
|
1136
|
+
expect(host.root.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
1137
|
+
expect(host.root.querySelector(".hk-range-ribbon-reset")).toBeNull();
|
|
1138
|
+
const strip = host.root.querySelector<HTMLElement>(".hk-range-ribbon-strip")!;
|
|
1139
|
+
expect(strip.getAttribute("tabindex")).toBe("-1");
|
|
1140
|
+
expect(strip.getAttribute("aria-disabled")).toBe("true");
|
|
1141
|
+
|
|
1142
|
+
// Drag and Escape stay inert.
|
|
1143
|
+
const { x } = stubStrip(host.root);
|
|
1144
|
+
pointer("pointerdown", x(0.1), strip);
|
|
1145
|
+
pointer("pointermove", x(0.3), strip);
|
|
1146
|
+
pointer("pointerup", x(0.3), strip);
|
|
1147
|
+
keydown(strip, "Escape");
|
|
1148
|
+
await nextTick();
|
|
1149
|
+
expect(host.windowChange).not.toHaveBeenCalled();
|
|
1150
|
+
expect(laneSegments(host.root)).toHaveLength(4);
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
// ── Controlled / uncontrolled switch ────────────────────────────────────
|
|
1155
|
+
describe("HkRangeRibbon controlled contract", () => {
|
|
1156
|
+
it("keeps the host's window while controlled and falls back to full when the prop is dropped", async () => {
|
|
1157
|
+
const container = document.createElement("div");
|
|
1158
|
+
document.body.appendChild(container);
|
|
1159
|
+
const control = ref<"controlled" | "uncontrolled">("controlled");
|
|
1160
|
+
const win = ref<[number, number] | null>([0.2, 0.6]);
|
|
1161
|
+
const emitted = vi.fn();
|
|
1162
|
+
const Wrapper = defineComponent({
|
|
1163
|
+
setup() {
|
|
1164
|
+
return () =>
|
|
1165
|
+
h(HkRangeRibbon, {
|
|
1166
|
+
lanes: LANES,
|
|
1167
|
+
segments: SEGMENTS,
|
|
1168
|
+
...(control.value === "controlled"
|
|
1169
|
+
? { window: win.value, onWindowChange: emitted }
|
|
1170
|
+
: {}),
|
|
1171
|
+
});
|
|
1172
|
+
},
|
|
1173
|
+
});
|
|
1174
|
+
const app = createApp(Wrapper);
|
|
1175
|
+
app.mount(container);
|
|
1176
|
+
mounts.push({ app, container });
|
|
1177
|
+
const root = container.querySelector<HTMLElement>(".hk-range-ribbon")!;
|
|
1178
|
+
const { strip, x } = stubStrip(root);
|
|
1179
|
+
|
|
1180
|
+
pointer("pointerdown", x(0.55), strip);
|
|
1181
|
+
pointer("pointermove", x(0.7), strip);
|
|
1182
|
+
pointer("pointerup", x(0.7), strip);
|
|
1183
|
+
await nextTick();
|
|
1184
|
+
expect(emitted, "the drag still reports").toHaveBeenCalled();
|
|
1185
|
+
|
|
1186
|
+
// The host ignored the emission: its window stays authoritative.
|
|
1187
|
+
const highlight = root.querySelector<HTMLElement>(".hk-range-ribbon-window")!;
|
|
1188
|
+
expect(parseFloat(highlight.style.left), "start still 20%").toBeCloseTo(20, 4);
|
|
1189
|
+
expect(parseFloat(highlight.style.width), "width still 40%").toBeCloseTo(40, 4);
|
|
1190
|
+
|
|
1191
|
+
// Dropping the prop hands control to the ribbon's own state, which never
|
|
1192
|
+
// mirrored the ignored controlled value: the full domain shows.
|
|
1193
|
+
control.value = "uncontrolled";
|
|
1194
|
+
await nextTick();
|
|
1195
|
+
expect(root.hasAttribute("data-windowed")).toBe(false);
|
|
1196
|
+
expect(root.querySelector(".hk-range-ribbon-handle")).toBeNull();
|
|
1197
|
+
expect(laneSegments(root)).toHaveLength(4);
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
// ── Stylesheet contract ─────────────────────────────────────────────────
|
|
1202
|
+
const componentDir = dirname(fileURLToPath(import.meta.url));
|
|
1203
|
+
|
|
1204
|
+
/** Body of one compiled rule, by exact selector (Sass drops quotes around
|
|
1205
|
+
* attribute values: `[data-status=pending]`). */
|
|
1206
|
+
function ruleBody(sheet: string, selector: string): string {
|
|
1207
|
+
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1208
|
+
const matches = [
|
|
1209
|
+
...sheet.matchAll(
|
|
1210
|
+
new RegExp(`(?:(?<=^)|(?<=[}{])|(?<=\\*/))\\s*${escaped}\\s*\\{([^}]*)\\}`, "g"),
|
|
1211
|
+
),
|
|
1212
|
+
];
|
|
1213
|
+
expect(matches, `${selector} compiles exactly once`).toHaveLength(1);
|
|
1214
|
+
return matches[0]?.[1] ?? "";
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
function declaration(body: string, property: string): string {
|
|
1218
|
+
const values = [...body.matchAll(new RegExp(`(?:^|;)\\s*${property}\\s*:([^;]*)`, "g"))].map(
|
|
1219
|
+
(match) => match[1]!.trim(),
|
|
1220
|
+
);
|
|
1221
|
+
expect(values.length, `${property} is declared at most once`).toBeLessThanOrEqual(1);
|
|
1222
|
+
return values[0] ?? "";
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
describe("HkRangeRibbon stylesheet contract", () => {
|
|
1226
|
+
const tsx = readFileSync(resolve(componentDir, "HkRangeRibbon.tsx"), "utf8");
|
|
1227
|
+
const scss = readFileSync(resolve(componentDir, "HkRangeRibbon.scss"), "utf8");
|
|
1228
|
+
const css = compile(resolve(componentDir, "HkRangeRibbon.scss"), { style: "expanded" }).css;
|
|
1229
|
+
|
|
1230
|
+
it("compiles without dangling rules", () => {
|
|
1231
|
+
expect(css).toContain(".hk-range-ribbon-strip");
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
it("gives every class the component emits a rule, and carries no dead class", () => {
|
|
1235
|
+
const inTsx = new Set<string>();
|
|
1236
|
+
for (const match of tsx.matchAll(/class="([^"]*)"/g)) {
|
|
1237
|
+
for (const token of match[1].split(/\s+/)) {
|
|
1238
|
+
if (token) inTsx.add(token);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
const inCss = new Set(
|
|
1242
|
+
Array.from(css.matchAll(/\.(hk-range-ribbon[\w-]*)/g)).map((match) => match[1]!),
|
|
1243
|
+
);
|
|
1244
|
+
expect([...inTsx].sort(), "every emitted class is styled").toEqual([...inCss].sort());
|
|
1245
|
+
// The scan must not go vacuous.
|
|
1246
|
+
expect(inTsx.size).toBeGreaterThan(15);
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
it("speaks hikari's own class namespace only (no host utility dialect)", () => {
|
|
1250
|
+
for (const match of tsx.matchAll(/class="([^"]*)"/g)) {
|
|
1251
|
+
for (const token of match[1].split(/\s+/)) {
|
|
1252
|
+
if (!token) continue;
|
|
1253
|
+
expect(token, `class token "${token}" must be hikari-owned`).toMatch(/^hk-/);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
it("styles from hikari theme tokens instead of hard-coded values", () => {
|
|
1259
|
+
expect(scss).toContain("var(--color-");
|
|
1260
|
+
expect(scss).toContain("var(--space-");
|
|
1261
|
+
expect(scss).toContain("var(--text-");
|
|
1262
|
+
expect(scss).toContain("var(--radius-");
|
|
1263
|
+
expect(scss, "no raw hex colours").not.toMatch(/#[0-9a-fA-F]{3,8}\b/);
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
it("pins the overview strip, handle and segment geometry", () => {
|
|
1267
|
+
const strip = ruleBody(css, ".hk-range-ribbon-strip");
|
|
1268
|
+
expect(declaration(strip, "height"), "overview strip height").toBe("32px");
|
|
1269
|
+
expect(strip).toContain("touch-action: none");
|
|
1270
|
+
expect(declaration(strip, "cursor")).toBe("crosshair");
|
|
1271
|
+
|
|
1272
|
+
const handle = ruleBody(css, ".hk-range-ribbon-handle");
|
|
1273
|
+
expect(declaration(handle, "width"), "handle grip width").toBe("8px");
|
|
1274
|
+
expect(declaration(handle, "transform"), "handle centers on its edge").toBe(
|
|
1275
|
+
"translateX(-50%)",
|
|
1276
|
+
);
|
|
1277
|
+
expect(declaration(handle, "cursor")).toBe("ew-resize");
|
|
1278
|
+
expect(handle).toContain("touch-action: none");
|
|
1279
|
+
expect(handle, "a handle drag cannot start a text selection").toMatch(
|
|
1280
|
+
/user-select:\s*none/,
|
|
1281
|
+
);
|
|
1282
|
+
|
|
1283
|
+
// A clipped 2px sliver must still be visible.
|
|
1284
|
+
expect(declaration(ruleBody(css, ".hk-range-ribbon-segment"), "min-width")).toBe("2px");
|
|
1285
|
+
expect(declaration(ruleBody(css, ".hk-range-ribbon-lane-track"), "height")).toBe("20px");
|
|
1286
|
+
// The reset chip clears the edge handle (half its 8px width).
|
|
1287
|
+
expect(declaration(ruleBody(css, ".hk-range-ribbon-reset"), "right")).toBe("4px");
|
|
1288
|
+
expect(ruleBody(css, ".hk-range-ribbon-window")).toContain("var(--color-primary)");
|
|
1289
|
+
expect(ruleBody(css, ".hk-range-ribbon-scrim")).toContain("var(--color-background)");
|
|
1290
|
+
});
|
|
1291
|
+
|
|
1292
|
+
it("pins the pending pulse and its reduced-motion off-switch", () => {
|
|
1293
|
+
expect(css).toContain("@keyframes hk-range-ribbon-pulse");
|
|
1294
|
+
// The ground rule (the reduced-motion override legitimately repeats the
|
|
1295
|
+
// same selector, so this is matched by shape rather than by uniqueness).
|
|
1296
|
+
expect(css).toMatch(
|
|
1297
|
+
/\.hk-range-ribbon-segment\[data-status=pending\]\s*\{[^}]*border-style: dashed[^}]*animation: hk-range-ribbon-pulse[^}]*\}/,
|
|
1298
|
+
);
|
|
1299
|
+
expect(css).toMatch(
|
|
1300
|
+
/@media \(prefers-reduced-motion: reduce\)[\s\S]*?\.hk-range-ribbon-segment\[data-status=pending\][\s\S]*?animation: none/,
|
|
1301
|
+
);
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
it("shares one label column between the overview and the lanes", () => {
|
|
1305
|
+
expect(
|
|
1306
|
+
declaration(ruleBody(css, ".hk-range-ribbon"), "--hk-range-ribbon-label-col"),
|
|
1307
|
+
"the root declares the shared label column",
|
|
1308
|
+
).toBe("minmax(48px, 84px)");
|
|
1309
|
+
const overviewColumns = declaration(
|
|
1310
|
+
ruleBody(css, ".hk-range-ribbon-overview"),
|
|
1311
|
+
"grid-template-columns",
|
|
1312
|
+
);
|
|
1313
|
+
const laneColumns = declaration(ruleBody(css, ".hk-range-ribbon-lane"), "grid-template-columns");
|
|
1314
|
+
expect(overviewColumns, "the overview opts into the shared column").toContain(
|
|
1315
|
+
"var(--hk-range-ribbon-label-col)",
|
|
1316
|
+
);
|
|
1317
|
+
expect(overviewColumns, "both surfaces use the same tracks").toBe(laneColumns);
|
|
1318
|
+
// The strip's own box is the coordinate space for handle percentages.
|
|
1319
|
+
expect(ruleBody(css, ".hk-range-ribbon-overview-field")).toContain("position: relative");
|
|
1320
|
+
expect(css).toContain(".hk-range-ribbon-overview-gutter");
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
it("anchors the tip inward at the track edges", () => {
|
|
1324
|
+
const tip = ruleBody(css, ".hk-range-ribbon-tip");
|
|
1325
|
+
expect(declaration(tip, "text-align")).toBe("start");
|
|
1326
|
+
expect(declaration(tip, "transform"), "centered by default").toBe("translateX(-50%)");
|
|
1327
|
+
const startAnchor = ruleBody(css, ".hk-range-ribbon-tip[data-anchor=start]");
|
|
1328
|
+
expect(declaration(startAnchor, "left")).toBe("0");
|
|
1329
|
+
expect(declaration(startAnchor, "transform")).toBe("none");
|
|
1330
|
+
const endAnchor = ruleBody(css, ".hk-range-ribbon-tip[data-anchor=end]");
|
|
1331
|
+
expect(declaration(endAnchor, "left")).toBe("auto");
|
|
1332
|
+
expect(declaration(endAnchor, "right")).toBe("0");
|
|
1333
|
+
expect(declaration(endAnchor, "transform")).toBe("none");
|
|
1334
|
+
});
|
|
1335
|
+
});
|