@celestia-island/hikari 0.55.424 → 0.55.425
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/HkSlideConfirm.scss +137 -0
- package/src/components/HkSlideConfirm.test.tsx +418 -0
- package/src/components/HkSlideConfirm.tsx +439 -0
- package/src/components/slideConfirmPath.test.ts +179 -0
- package/src/components/slideConfirmPath.ts +192 -0
- package/src/i18n/locales/ar/components.json +3 -1
- package/src/i18n/locales/de/components.json +3 -1
- package/src/i18n/locales/en/components.json +3 -1
- package/src/i18n/locales/es/components.json +3 -1
- package/src/i18n/locales/fr/components.json +3 -1
- package/src/i18n/locales/ja/components.json +3 -1
- package/src/i18n/locales/ko/components.json +3 -1
- package/src/i18n/locales/pt/components.json +3 -1
- package/src/i18n/locales/ru/components.json +3 -1
- package/src/i18n/locales/zh-Hans/components.json +3 -1
- package/src/i18n/locales/zh-Hant/components.json +3 -1
- package/src/index.ts +12 -0
package/package.json
CHANGED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
@use "../styles/polyfill" as *;
|
|
2
|
+
|
|
3
|
+
// HkSlideConfirm (components/HkSlideConfirm.tsx) — the fat slide-to-
|
|
4
|
+
// confirm: a three-standard-row block whose orthogonal lane carries ≥3
|
|
5
|
+
// random right-angle turns; the knob is grabbed and TRACED from the left
|
|
6
|
+
// edge to the right edge; a premature release or a corridor exit snaps it
|
|
7
|
+
// back at once. Tokens follow the house scale (--space-*, --radius-*,
|
|
8
|
+
// rgb(var(--color-*)), --hi-color-*).
|
|
9
|
+
//
|
|
10
|
+
// GEOMETRY: the block's height is THREE standard control rows
|
|
11
|
+
// (calc(var(--space-40, 2.5rem) * 3)) — the 2026-11-19 user direction
|
|
12
|
+
// that makes the confirmation feel deliberate instead of reflexive. The
|
|
13
|
+
// lane svg is inset by the same TRACK_PAD the tsx maps coordinates with;
|
|
14
|
+
// the knob rides the lane's px frame (transform from the track corner,
|
|
15
|
+
// centered by the negative half-margin below).
|
|
16
|
+
|
|
17
|
+
.hk-slide-confirm {
|
|
18
|
+
position: relative;
|
|
19
|
+
height: calc(var(--space-40, 2.5rem) * 3);
|
|
20
|
+
border-radius: var(--radius-lg, 0.75rem);
|
|
21
|
+
background: var(--hi-color-surface, rgba(255, 255, 255, 0.95));
|
|
22
|
+
border: 1px solid rgb(var(--color-border) / 8%);
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
transition: border-color 0.2s ease, background 0.2s ease;
|
|
25
|
+
|
|
26
|
+
&:hover:not(.is-disabled) {
|
|
27
|
+
border-color: rgb(var(--color-border) / 20%);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&.is-done {
|
|
31
|
+
border-color: rgb(var(--color-primary) / 35%);
|
|
32
|
+
background: color-mix(in srgb, var(--hi-color-primary, #7aa2f7) 8%, transparent);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.is-disabled {
|
|
36
|
+
opacity: 0.55;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* The lane: an svg inset by TRACK_PAD (the tsx maps coordinates in the
|
|
42
|
+
* same frame). One polyline, thick round stroke — a corridor to trace,
|
|
43
|
+
* not a line to read. */
|
|
44
|
+
.hk-slide-confirm-lane {
|
|
45
|
+
position: absolute;
|
|
46
|
+
overflow: visible;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.hk-slide-confirm-lane-path {
|
|
51
|
+
fill: none;
|
|
52
|
+
stroke: rgb(var(--color-text) / 14%);
|
|
53
|
+
stroke-width: 1.25rem;
|
|
54
|
+
stroke-linecap: round;
|
|
55
|
+
stroke-linejoin: round;
|
|
56
|
+
|
|
57
|
+
&.is-done {
|
|
58
|
+
stroke: color-mix(in srgb, var(--hi-color-primary, #7aa2f7) 45%, transparent);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.hk-slide-confirm-label,
|
|
63
|
+
.hk-slide-confirm-done-label {
|
|
64
|
+
position: absolute;
|
|
65
|
+
inset: 0;
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
padding: 0 var(--space-32, 2rem);
|
|
70
|
+
font-size: 0.75rem;
|
|
71
|
+
color: rgb(var(--color-text) / 45%);
|
|
72
|
+
text-align: center;
|
|
73
|
+
pointer-events: none;
|
|
74
|
+
@include user-select(none);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.hk-slide-confirm-done-label {
|
|
78
|
+
color: var(--hi-color-primary, #7aa2f7);
|
|
79
|
+
font-weight: 600;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* The knob: a joystick-sized circle, centered on the lane point by the
|
|
83
|
+
* negative half-margin, riding the transform the tsx writes. While
|
|
84
|
+
* snapping it transitions back to the start (the "一下子回去" — the
|
|
85
|
+
* instant return reads as refusal, not as a reset). */
|
|
86
|
+
.hk-slide-confirm-knob {
|
|
87
|
+
position: absolute;
|
|
88
|
+
top: 0;
|
|
89
|
+
left: 0;
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
width: 2.4rem;
|
|
94
|
+
height: 2.4rem;
|
|
95
|
+
margin: -1.2rem; /* center the knob on the lane point */
|
|
96
|
+
border-radius: 50%;
|
|
97
|
+
background: var(--hi-color-surface, rgba(255, 255, 255, 0.98));
|
|
98
|
+
border: 1px solid rgb(var(--color-border) / 22%);
|
|
99
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / 22%);
|
|
100
|
+
cursor: grab;
|
|
101
|
+
touch-action: none;
|
|
102
|
+
transition: transform 0.24s cubic-bezier(0.3, 0, 0.5, 1), border-color 0.2s ease;
|
|
103
|
+
|
|
104
|
+
&.is-done {
|
|
105
|
+
cursor: default;
|
|
106
|
+
border-color: var(--hi-color-primary, #7aa2f7);
|
|
107
|
+
background: color-mix(in srgb, var(--hi-color-primary, #7aa2f7) 18%, var(--hi-color-surface, rgba(255, 255, 255, 0.95)));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.hk-slide-confirm.is-dragging .hk-slide-confirm-knob {
|
|
112
|
+
cursor: grabbing;
|
|
113
|
+
/* While tracing, the knob follows the pointer 1:1 — no transition (a
|
|
114
|
+
* transitioned follow would lag the hand). Only the snap-back transition
|
|
115
|
+
* above applies, and only once .is-dragging is gone. */
|
|
116
|
+
transition: border-color 0.2s ease;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* The grip: three horizontal pills — the joystick affordance. */
|
|
120
|
+
.hk-slide-confirm-knob-grip {
|
|
121
|
+
width: 0.9rem;
|
|
122
|
+
height: 0.55rem;
|
|
123
|
+
background:
|
|
124
|
+
linear-gradient(to bottom,
|
|
125
|
+
rgb(var(--color-text) / 45%) 0 2px, transparent 2px 4px,
|
|
126
|
+
rgb(var(--color-text) / 45%) 4px 6px, transparent 6px 8px,
|
|
127
|
+
rgb(var(--color-text) / 45%) 8px 10px, transparent 10px);
|
|
128
|
+
border-radius: 1px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Reduced motion: the snap-back must SNAP (the whole point of the refusal
|
|
132
|
+
* read), not glide — the transition is the only animated part. */
|
|
133
|
+
@media (prefers-reduced-motion: reduce) {
|
|
134
|
+
.hk-slide-confirm-knob {
|
|
135
|
+
transition: border-color 0.2s ease;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// HkSlideConfirm — the fat slide-to-confirm (a traced orthogonal lane
|
|
2
|
+
// with random right-angle turns, not a straight pull).
|
|
3
|
+
//
|
|
4
|
+
// The contract these tests pin (2026-11-19 user direction): arrows walk
|
|
5
|
+
// the lane and reaching the end emits confirm ONCE; a premature pointer
|
|
6
|
+
// release snaps the knob back to zero (no emit); dragging off the
|
|
7
|
+
// corridor snaps back too; a seeded mount reproduces the exact lane; a
|
|
8
|
+
// seed change regenerates and resets; the whole surface is operable from
|
|
9
|
+
// a keyboard alone. Pointer geometry works in jsdom through an injected
|
|
10
|
+
// track rect; drags TRACE along the seeded lane in small steps (a real
|
|
11
|
+
// drag never teleports — the walk refuses single-event corner jumps).
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
13
|
+
import { createApp, h, nextTick, ref } from "vue";
|
|
14
|
+
|
|
15
|
+
import HkSlideConfirm from "./HkSlideConfirm";
|
|
16
|
+
import {
|
|
17
|
+
generateSlidePath,
|
|
18
|
+
slidePixelPoints,
|
|
19
|
+
slidePointAtT,
|
|
20
|
+
} from "./slideConfirmPath";
|
|
21
|
+
|
|
22
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
23
|
+
|
|
24
|
+
function mount(renderNode: () => ReturnType<typeof h>) {
|
|
25
|
+
const container = document.createElement("div");
|
|
26
|
+
document.body.appendChild(container);
|
|
27
|
+
const app = createApp({ render: renderNode });
|
|
28
|
+
app.mount(container);
|
|
29
|
+
mounts.push({ app, container });
|
|
30
|
+
return container;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
35
|
+
app.unmount();
|
|
36
|
+
container.remove();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const root = () => document.body.querySelector<HTMLElement>(".hk-slide-confirm")!;
|
|
41
|
+
const knob = () => document.body.querySelector<HTMLElement>(".hk-slide-confirm-knob")!;
|
|
42
|
+
|
|
43
|
+
function injectRect(el: HTMLElement, width = 300, height = 120) {
|
|
44
|
+
el.getBoundingClientRect = () =>
|
|
45
|
+
({
|
|
46
|
+
width,
|
|
47
|
+
height,
|
|
48
|
+
top: 0,
|
|
49
|
+
left: 0,
|
|
50
|
+
right: width,
|
|
51
|
+
bottom: height,
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0,
|
|
54
|
+
toJSON: () => ({}),
|
|
55
|
+
}) as DOMRect;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Pointer event with real coordinates (jsdom dispatches to the handler).
|
|
59
|
+
* setPointerCapture is absent in jsdom — the component guards it. */
|
|
60
|
+
function pointer(el: HTMLElement, type: string, x: number, y: number) {
|
|
61
|
+
el.dispatchEvent(
|
|
62
|
+
new PointerEvent(type, { bubbles: true, cancelable: true, pointerId: 1, clientX: x, clientY: y }),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function key(el: HTMLElement, keyName: string) {
|
|
67
|
+
el.dispatchEvent(new KeyboardEvent("keydown", { key: keyName, bubbles: true, cancelable: true }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const now = () => Number(knob().getAttribute("aria-valuenow"));
|
|
71
|
+
|
|
72
|
+
/** The seeded lane in the component's REAL inner frame (300×120 track
|
|
73
|
+
* minus the 24px TRACK_PAD per side). */
|
|
74
|
+
const lane42 = () => slidePixelPoints(generateSlidePath(42).points, 252, 72);
|
|
75
|
+
|
|
76
|
+
/** Trace the lane from fromT to toT in small pointer steps (a real drag
|
|
77
|
+
* never teleports; the walk refuses single-event corner jumps). */
|
|
78
|
+
function trace(handle: HTMLElement, pixel: ReturnType<typeof lane42>, fromT: number, toT: number, steps: number) {
|
|
79
|
+
for (let i = 1; i <= steps; i++) {
|
|
80
|
+
const t = fromT + ((toT - fromT) * i) / steps;
|
|
81
|
+
const p = slidePointAtT(pixel, t);
|
|
82
|
+
pointer(handle, "pointermove", 24 + p.x, 24 + p.y);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe("HkSlideConfirm", () => {
|
|
87
|
+
it("renders the fat track, the lane svg and the slider knob", () => {
|
|
88
|
+
mount(() => h(HkSlideConfirm, { seed: 42 }));
|
|
89
|
+
expect(document.body.querySelector(".hk-slide-confirm")).not.toBeNull();
|
|
90
|
+
expect(document.body.querySelector(".hk-slide-confirm-lane-path")).not.toBeNull();
|
|
91
|
+
const handle = knob();
|
|
92
|
+
expect(handle.getAttribute("role")).toBe("slider");
|
|
93
|
+
expect(handle.getAttribute("aria-valuemin")).toBe("0");
|
|
94
|
+
expect(handle.getAttribute("aria-valuemax")).toBe("100");
|
|
95
|
+
expect(handle.getAttribute("aria-valuenow")).toBe("0");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("a seed reproduces the exact lane", () => {
|
|
99
|
+
mount(() => h(HkSlideConfirm, { seed: 20261119 }));
|
|
100
|
+
const laneA = document.body.querySelector(".hk-slide-confirm-lane-path")!.getAttribute("points");
|
|
101
|
+
mount(() => h(HkSlideConfirm, { seed: 20261119 }));
|
|
102
|
+
const laneB = document.body.querySelector(".hk-slide-confirm-lane-path")!.getAttribute("points");
|
|
103
|
+
expect(laneA).toBeTruthy();
|
|
104
|
+
expect(laneA).toBe(laneB);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("arrows walk the lane and the end fires confirm exactly once", async () => {
|
|
108
|
+
const onConfirm = vi.fn();
|
|
109
|
+
mount(() => h(HkSlideConfirm, { seed: 7, onConfirm }));
|
|
110
|
+
const handle = knob();
|
|
111
|
+
handle.focus();
|
|
112
|
+
// ~24 steps traverse the lane; walk a couple extra to prove once-only.
|
|
113
|
+
for (let i = 0; i < 30; i++) key(handle, "ArrowRight");
|
|
114
|
+
await nextTick();
|
|
115
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
116
|
+
expect(now()).toBe(100);
|
|
117
|
+
// The done state: the success label replaces the idle one.
|
|
118
|
+
expect(document.body.querySelector(".hk-slide-confirm-done-label")).not.toBeNull();
|
|
119
|
+
expect(document.body.querySelector(".hk-slide-confirm-label")).toBeNull();
|
|
120
|
+
// Post-confirm keys never re-fire.
|
|
121
|
+
for (let i = 0; i < 5; i++) key(handle, "ArrowRight");
|
|
122
|
+
await nextTick();
|
|
123
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("Home resets and Left/Down retreat without firing", async () => {
|
|
127
|
+
const onConfirm = vi.fn();
|
|
128
|
+
mount(() => h(HkSlideConfirm, { seed: 7, onConfirm }));
|
|
129
|
+
const handle = knob();
|
|
130
|
+
for (let i = 0; i < 10; i++) key(handle, "ArrowRight");
|
|
131
|
+
await nextTick();
|
|
132
|
+
expect(now()).toBeGreaterThan(0);
|
|
133
|
+
key(handle, "ArrowLeft");
|
|
134
|
+
await nextTick();
|
|
135
|
+
expect(now()).toBeLessThan(Math.round((10 / 24) * 100));
|
|
136
|
+
key(handle, "Home");
|
|
137
|
+
await nextTick();
|
|
138
|
+
expect(now()).toBe(0);
|
|
139
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("a premature pointer release snaps back to zero without emitting", async () => {
|
|
143
|
+
const onConfirm = vi.fn();
|
|
144
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
145
|
+
injectRect(root(), 300, 120);
|
|
146
|
+
const handle = knob();
|
|
147
|
+
const pixel = lane42();
|
|
148
|
+
// pointerdown lands ON the knob (the seeded start point) so the grab
|
|
149
|
+
// offset is zero — the traced point is the knob center.
|
|
150
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
151
|
+
// Trace halfway along the lane in real drag steps.
|
|
152
|
+
trace(handle, pixel, 0, 0.5, 40);
|
|
153
|
+
await nextTick();
|
|
154
|
+
expect(now()).toBeGreaterThan(0);
|
|
155
|
+
pointer(handle, "pointerup", 24, 24);
|
|
156
|
+
await nextTick();
|
|
157
|
+
// Snapped back: progress zeroed, no confirmation, idle returns.
|
|
158
|
+
expect(now()).toBe(0);
|
|
159
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("dragging off the corridor is a failed attempt (snap back)", async () => {
|
|
163
|
+
const onConfirm = vi.fn();
|
|
164
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
165
|
+
injectRect(root(), 300, 120);
|
|
166
|
+
const handle = knob();
|
|
167
|
+
const pixel = lane42();
|
|
168
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
169
|
+
// Trace the first quarter of the lane to arm progress.
|
|
170
|
+
trace(handle, pixel, 0, 0.25, 24);
|
|
171
|
+
await nextTick();
|
|
172
|
+
expect(now()).toBeGreaterThan(0);
|
|
173
|
+
// …then teleport far off the lane: the corridor is gone → snap.
|
|
174
|
+
pointer(handle, "pointermove", 60, 118);
|
|
175
|
+
await nextTick();
|
|
176
|
+
expect(now()).toBe(0);
|
|
177
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("a straight pull cannot cut the turns (trace is enforced)", async () => {
|
|
181
|
+
// The S1 corridor-slip probe: hold the pointer at ONE height and drag
|
|
182
|
+
// straight across the whole track — the walk must stop at the first
|
|
183
|
+
// lane change instead of chord-diagonaling through the turns.
|
|
184
|
+
const onConfirm = vi.fn();
|
|
185
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
186
|
+
injectRect(root(), 300, 120);
|
|
187
|
+
const handle = knob();
|
|
188
|
+
const pixel = lane42();
|
|
189
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
190
|
+
const y = 24 + pixel[0]!.y;
|
|
191
|
+
pointer(handle, "pointermove", 130, y);
|
|
192
|
+
pointer(handle, "pointermove", 276, y);
|
|
193
|
+
await nextTick();
|
|
194
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("a straight pull at the lane height never completes (small honest steps)", async () => {
|
|
198
|
+
// The R3 probe: an 8px-step straight pull ON the start lane rides the
|
|
199
|
+
// corridor through the first run, freezes at the first turn, and can
|
|
200
|
+
// never reach the end — no emit, progress visibly stuck below 100.
|
|
201
|
+
const onConfirm = vi.fn();
|
|
202
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
203
|
+
injectRect(root(), 300, 120);
|
|
204
|
+
const handle = knob();
|
|
205
|
+
const pixel = lane42();
|
|
206
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
207
|
+
const y = 24 + pixel[0]!.y;
|
|
208
|
+
for (let x = 25; x <= 276; x += 8) pointer(handle, "pointermove", x, y);
|
|
209
|
+
await nextTick();
|
|
210
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
211
|
+
expect(now()).toBeLessThan(100);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("a straight pull one lane off snaps back immediately", async () => {
|
|
215
|
+
// dy = ±12 (a full lane spacing) is OUTSIDE the 10px corridor: the
|
|
216
|
+
// first honest pointermove is already a refusal.
|
|
217
|
+
const onConfirm = vi.fn();
|
|
218
|
+
for (const dy of [-12, 12]) {
|
|
219
|
+
mounts.length = 0;
|
|
220
|
+
document.body.innerHTML = "";
|
|
221
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
222
|
+
injectRect(root(), 300, 120);
|
|
223
|
+
const handle = knob();
|
|
224
|
+
const pixel = lane42();
|
|
225
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
226
|
+
for (let x = 25; x <= 276; x += 8) pointer(handle, "pointermove", x, 24 + pixel[0]!.y + dy);
|
|
227
|
+
await nextTick();
|
|
228
|
+
expect(onConfirm, `dy=${dy}`).not.toHaveBeenCalled();
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("a fast first event (20px sweep) still advances — no speed cliff", async () => {
|
|
233
|
+
// The sweep-segment walk measures the segment the pointer SWEPT, so
|
|
234
|
+
// one coalesced 20px event along the lane advances honestly (the old
|
|
235
|
+
// point-anchored walk aborted on it — the S1 speed cliff).
|
|
236
|
+
const onConfirm = vi.fn();
|
|
237
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
238
|
+
injectRect(root(), 300, 120);
|
|
239
|
+
const handle = knob();
|
|
240
|
+
const pixel = lane42();
|
|
241
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
242
|
+
pointer(handle, "pointermove", 24 + pixel[0]!.x + 20, 24 + pixel[0]!.y);
|
|
243
|
+
await nextTick();
|
|
244
|
+
// Assert the ADVANCE, not survival: a 20px sweep along the lane is
|
|
245
|
+
// ~20px of honest progress (a 1-unit partial regression still passed
|
|
246
|
+
// the old form).
|
|
247
|
+
expect(now()).toBeGreaterThanOrEqual(4);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("completing the lane by pointer emits confirm once", async () => {
|
|
251
|
+
const onConfirm = vi.fn();
|
|
252
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
253
|
+
injectRect(root(), 300, 120);
|
|
254
|
+
const handle = knob();
|
|
255
|
+
const pixel = lane42();
|
|
256
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
257
|
+
// Trace the WHOLE lane densely (the pure module computes the same
|
|
258
|
+
// geometry the component maps).
|
|
259
|
+
trace(handle, pixel, 0, 1, 120);
|
|
260
|
+
await nextTick();
|
|
261
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
262
|
+
expect(now()).toBe(100);
|
|
263
|
+
// Done state short-circuits further pointer input.
|
|
264
|
+
trace(handle, pixel, 1, 1, 3);
|
|
265
|
+
await nextTick();
|
|
266
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("a seed change regenerates the lane and resets progress", async () => {
|
|
270
|
+
// The documented contract: a seed change lays a fresh route AND
|
|
271
|
+
// resets the gesture (a half-traced knob must not carry over).
|
|
272
|
+
const seed = ref(1);
|
|
273
|
+
const onConfirm = vi.fn();
|
|
274
|
+
mount(() => h(HkSlideConfirm, { seed: seed.value, onConfirm }));
|
|
275
|
+
const handle = knob();
|
|
276
|
+
handle.focus();
|
|
277
|
+
key(handle, "ArrowRight");
|
|
278
|
+
await nextTick();
|
|
279
|
+
expect(now()).toBeGreaterThan(0);
|
|
280
|
+
|
|
281
|
+
seed.value = 20261119;
|
|
282
|
+
await nextTick();
|
|
283
|
+
expect(now()).toBe(0);
|
|
284
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("coalesced sub-samples trace through a corner (regression: M4)", async () => {
|
|
288
|
+
// The R4 S1(b) fix: a single large event straddling a corner aborts
|
|
289
|
+
// (2√2·corridor ceiling), but the browser's coalesced sub-samples are
|
|
290
|
+
// traced INDIVIDUALLY — deleting the coalesced branch makes this red
|
|
291
|
+
// (the combined single event snaps back instead of crossing).
|
|
292
|
+
const onConfirm = vi.fn();
|
|
293
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
294
|
+
injectRect(root(), 300, 120);
|
|
295
|
+
const handle = knob();
|
|
296
|
+
const pixel = lane42();
|
|
297
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
298
|
+
// Arm progress up to just before the first turn (~t 0.18).
|
|
299
|
+
trace(handle, pixel, 0, 0.18, 16);
|
|
300
|
+
await nextTick();
|
|
301
|
+
// ONE real event whose coalesced sub-samples carry the pointer
|
|
302
|
+
// through the corner: base → top → beyond.
|
|
303
|
+
const cornerBase = slidePointAtT(pixel, 0.19);
|
|
304
|
+
const cornerTop = slidePointAtT(pixel, 0.24);
|
|
305
|
+
const beyond = slidePointAtT(pixel, 0.3);
|
|
306
|
+
const big = new PointerEvent("pointermove", {
|
|
307
|
+
bubbles: true,
|
|
308
|
+
cancelable: true,
|
|
309
|
+
pointerId: 1,
|
|
310
|
+
clientX: 24 + beyond.x,
|
|
311
|
+
clientY: 24 + beyond.y,
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(big, "getCoalescedEvents", {
|
|
314
|
+
value: () => [
|
|
315
|
+
{ clientX: 24 + cornerBase.x, clientY: 24 + cornerBase.y },
|
|
316
|
+
{ clientX: 24 + cornerTop.x, clientY: 24 + cornerTop.y },
|
|
317
|
+
{ clientX: 24 + beyond.x, clientY: 24 + beyond.y },
|
|
318
|
+
],
|
|
319
|
+
});
|
|
320
|
+
handle.dispatchEvent(big);
|
|
321
|
+
await nextTick();
|
|
322
|
+
// Crossed the corner: progress past it, no snap-back.
|
|
323
|
+
expect(now()).toBeGreaterThanOrEqual(28);
|
|
324
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("the 2x runaway bound tolerates ordinary aim error (regression: M5)", async () => {
|
|
328
|
+
// The R4 S1(a) fix: the runaway bound is 2× the corridor, so an
|
|
329
|
+
// honest trace with a ±3px lateral aim error completes. With a 1×
|
|
330
|
+
// bound the knob-lead + aim error crossed the bound and snapped
|
|
331
|
+
// mid-trace (progress froze well before the end / no emit).
|
|
332
|
+
const onConfirm = vi.fn();
|
|
333
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
334
|
+
injectRect(root(), 300, 120);
|
|
335
|
+
const handle = knob();
|
|
336
|
+
const pixel = lane42();
|
|
337
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
338
|
+
// Trace the whole lane with a ±3px vertical aim wobble in small steps.
|
|
339
|
+
const steps = 60;
|
|
340
|
+
for (let i = 1; i <= steps; i++) {
|
|
341
|
+
const t = i / steps;
|
|
342
|
+
const p = slidePointAtT(pixel, t);
|
|
343
|
+
const wobble = i % 2 === 0 ? 3 : -3;
|
|
344
|
+
pointer(handle, "pointermove", 24 + p.x, 24 + p.y + wobble);
|
|
345
|
+
}
|
|
346
|
+
await nextTick();
|
|
347
|
+
expect(onConfirm, "the wobbling honest trace completes").toHaveBeenCalledTimes(1);
|
|
348
|
+
expect(now()).toBe(100);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("a stale snap-back timer never tears the done state down", async () => {
|
|
352
|
+
// The complete() guard: a snap-back scheduled BEFORE completion must
|
|
353
|
+
// not fire after it (a teardown would resurrect the control and allow
|
|
354
|
+
// a second confirm — a destructive host action firing twice).
|
|
355
|
+
vi.useFakeTimers();
|
|
356
|
+
try {
|
|
357
|
+
const onConfirm = vi.fn();
|
|
358
|
+
mount(() => h(HkSlideConfirm, { seed: 42, onConfirm }));
|
|
359
|
+
injectRect(root(), 300, 120);
|
|
360
|
+
const handle = knob();
|
|
361
|
+
const pixel = lane42();
|
|
362
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
363
|
+
// Arm, release early → snap-back scheduled (260ms).
|
|
364
|
+
trace(handle, pixel, 0, 0.3, 20);
|
|
365
|
+
pointer(handle, "pointerup", 24, 24);
|
|
366
|
+
// Complete by keyboard BEFORE the timer fires.
|
|
367
|
+
for (let i = 0; i < 30; i++) key(handle, "ArrowRight");
|
|
368
|
+
await nextTick();
|
|
369
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
370
|
+
// Let the stale timer's deadline pass: the done state must survive.
|
|
371
|
+
vi.advanceTimersByTime(600);
|
|
372
|
+
await nextTick();
|
|
373
|
+
expect(now()).toBe(100);
|
|
374
|
+
expect(document.body.querySelector(".hk-slide-confirm-done-label")).not.toBeNull();
|
|
375
|
+
// And no second confirm can be produced for the same gesture.
|
|
376
|
+
for (let i = 0; i < 5; i++) key(handle, "ArrowRight");
|
|
377
|
+
await nextTick();
|
|
378
|
+
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
379
|
+
} finally {
|
|
380
|
+
vi.useRealTimers();
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("flipping disabled mid-gesture refuses instead of tracking", async () => {
|
|
385
|
+
// The traceEvent guard: a host gating on async state can disable the
|
|
386
|
+
// control mid-drag — the knob must stop (snap back), never emit.
|
|
387
|
+
const onConfirm = vi.fn();
|
|
388
|
+
const disabled = ref(false);
|
|
389
|
+
mount(() => h(HkSlideConfirm, { seed: 42, disabled: disabled.value, onConfirm }));
|
|
390
|
+
injectRect(root(), 300, 120);
|
|
391
|
+
const handle = knob();
|
|
392
|
+
const pixel = lane42();
|
|
393
|
+
pointer(handle, "pointerdown", 24 + pixel[0]!.x, 24 + pixel[0]!.y);
|
|
394
|
+
trace(handle, pixel, 0, 0.3, 20);
|
|
395
|
+
await nextTick();
|
|
396
|
+
expect(now()).toBeGreaterThan(0);
|
|
397
|
+
|
|
398
|
+
disabled.value = true;
|
|
399
|
+
await nextTick();
|
|
400
|
+
trace(handle, pixel, 0.3, 1, 60);
|
|
401
|
+
await nextTick();
|
|
402
|
+
expect(now()).toBe(0);
|
|
403
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("disabled blocks pointer and keyboard paths", () => {
|
|
407
|
+
const onConfirm = vi.fn();
|
|
408
|
+
mount(() => h(HkSlideConfirm, { seed: 42, disabled: true, onConfirm }));
|
|
409
|
+
const handle = knob();
|
|
410
|
+
expect(handle.getAttribute("aria-disabled")).toBe("true");
|
|
411
|
+
expect(handle.getAttribute("tabindex")).toBe("-1");
|
|
412
|
+
key(handle, "End");
|
|
413
|
+
pointer(handle, "pointerdown", 24, 24);
|
|
414
|
+
pointer(handle, "pointermove", 100, 24);
|
|
415
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
416
|
+
expect(now()).toBe(0);
|
|
417
|
+
});
|
|
418
|
+
});
|