@celestia-island/hikari 0.55.344 → 0.55.346
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/HkAddTile.barrel.test.ts +27 -0
- package/src/components/HkAddTile.contract.test.ts +7 -2
- package/src/components/HkAddTile.scss +1 -1
- package/src/components/HkAddTile.test.tsx +38 -5
- package/src/components/HkAddTile.tsx +15 -3
- package/src/components/HkMediaSlider.scss +26 -6
- package/src/components/HkMediaSlider.test.tsx +139 -0
- package/src/components/HkMediaSlider.tsx +43 -4
- package/src/components/HkThemeToggle.contract.test.ts +10 -0
- package/src/components/HkThemeToggle.scss +8 -0
- package/src/components/HkThemeToggle.test.ts +5 -4
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as barrel from "../index";
|
|
3
|
+
import { asIndexable } from "../utils/typing";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The public barrel guard for the dashed add/empty affordance tile
|
|
7
|
+
* (HkEdgeGlow.barrel.test.ts shape): deleting the export lines from
|
|
8
|
+
* index.ts kept the ENTIRE suite green while the component's own tests
|
|
9
|
+
* reach the module through "./HkAddTile" — only an external consumer
|
|
10
|
+
* would have noticed. Recorded as a residual in #1222's R4/R5; this
|
|
11
|
+
* file closes it.
|
|
12
|
+
*
|
|
13
|
+
* This file deliberately does NOT mock "@celestia-island/hikari": the
|
|
14
|
+
* package's self-reference resolves to the very same src/index.ts module
|
|
15
|
+
* as "../index", so a vi.mock here would replace the barrel under test
|
|
16
|
+
* with the mock's own namespace.
|
|
17
|
+
*/
|
|
18
|
+
describe("the public barrel", () => {
|
|
19
|
+
it("exports the add tile under both family names", () => {
|
|
20
|
+
const hk = asIndexable(barrel.HkAddTile);
|
|
21
|
+
expect(hk, "HkAddTile must be re-exported").toBeTruthy();
|
|
22
|
+
expect(hk.name).toBe("HkAddTile");
|
|
23
|
+
// The H- alias rides the HCard/HkCard family convention: consumers
|
|
24
|
+
// import either name, one component underneath.
|
|
25
|
+
expect(barrel.HAddTile).toBe(barrel.HkAddTile);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -60,8 +60,13 @@ describe("HkAddTile neutrality contract", () => {
|
|
|
60
60
|
const drag = fullRule(css, ".hk-add-tile--drag-over");
|
|
61
61
|
expect(drag).toContain("rgb(var(--color-primary) / 8%)");
|
|
62
62
|
// Whole-file sweep: exactly one top-level rule chunk paints the
|
|
63
|
-
// wash, and it is the drag-over rule.
|
|
64
|
-
|
|
63
|
+
// wash, and it is the drag-over rule. Comments are stripped first —
|
|
64
|
+
// a mere mention of the wash alpha in prose must not red this (the
|
|
65
|
+
// R3 comment-sensitivity residual).
|
|
66
|
+
const cssSansComments = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
67
|
+
const chunks = cssSansComments
|
|
68
|
+
.split(/(?=\.hk-add-tile)/g)
|
|
69
|
+
.filter((r) => r.includes("/ 8%)"));
|
|
65
70
|
expect(chunks.length).toBe(1);
|
|
66
71
|
expect(chunks[0].startsWith(".hk-add-tile--drag-over")).toBe(true);
|
|
67
72
|
});
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/* List-end form: a slim
|
|
44
|
+
/* List-end form: a slim start-aligned row ("+ add one more") that rides
|
|
45
45
|
* the end of a row list instead of floating under it as a button. */
|
|
46
46
|
.hk-add-tile--compact {
|
|
47
47
|
flex-direction: row;
|
|
@@ -39,6 +39,14 @@ function dropEvent(files: File[]): Event {
|
|
|
39
39
|
return ev;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** A dragleave carrying a relatedTarget — the containment contract the
|
|
43
|
+
handler keys on (undefined leaves it null = "left to nothing"). */
|
|
44
|
+
function leaveEvent(relatedTarget: Node | null): Event {
|
|
45
|
+
const ev = new Event("dragleave", { bubbles: true, cancelable: true });
|
|
46
|
+
Object.defineProperty(ev, "relatedTarget", { value: relatedTarget });
|
|
47
|
+
return ev;
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
function file(name: string): File {
|
|
43
51
|
return new File(["x"], name, { type: "text/plain" });
|
|
44
52
|
}
|
|
@@ -131,22 +139,47 @@ describe("HkAddTile", () => {
|
|
|
131
139
|
expect(onDropFiles).not.toHaveBeenCalled();
|
|
132
140
|
});
|
|
133
141
|
|
|
134
|
-
it("
|
|
142
|
+
it("keeps drag-over across child boundaries, clears on real exit", async () => {
|
|
135
143
|
const c = mount(h(HkAddTile, { droppable: true }, { default: () => "Drop" }));
|
|
136
144
|
const el = tileEl(c);
|
|
137
145
|
// The default slot text is a direct child; enter the tile, then its
|
|
138
|
-
//
|
|
146
|
+
// glyph boundary, then back into the label area only.
|
|
139
147
|
el.dispatchEvent(new Event("dragenter", { bubbles: true }));
|
|
140
148
|
await nextTick();
|
|
141
149
|
expect(el.classList.contains("hk-add-tile--drag-over")).toBe(true);
|
|
142
|
-
const inner = el.
|
|
150
|
+
const inner = el.firstElementChild as Element;
|
|
143
151
|
inner.dispatchEvent(new Event("dragenter", { bubbles: true })); // depth 2
|
|
144
|
-
|
|
152
|
+
// Internal move (leaving the glyph toward the label): contained, so
|
|
153
|
+
// the depth must not RESET — an always-reset leave with no
|
|
154
|
+
// containment check would clear the wash here. (The blind-decrement
|
|
155
|
+
// direction is the self-heal test's below.)
|
|
156
|
+
inner.dispatchEvent(leaveEvent(el));
|
|
145
157
|
await nextTick();
|
|
146
158
|
expect(el.classList.contains("hk-add-tile--drag-over")).toBe(true);
|
|
147
|
-
el.dispatchEvent(
|
|
159
|
+
el.dispatchEvent(leaveEvent(null)); // left to nothing — full reset
|
|
160
|
+
await nextTick();
|
|
161
|
+
expect(el.classList.contains("hk-add-tile--drag-over")).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("self-heals when a hovered child leaves the DOM mid-drag", async () => {
|
|
165
|
+
// The stuck-depth leak (residual sweep): a slot child removed
|
|
166
|
+
// mid-hover never fires its own leave, so the old decrement could
|
|
167
|
+
// strand the count above zero and keep the wash lit after the
|
|
168
|
+
// pointer had fully exited. The containment reset clears the wash on
|
|
169
|
+
// the first real exit regardless of how deep the count was stranded.
|
|
170
|
+
const c = mount(h(HkAddTile, { droppable: true }, { default: () => "Drop" }));
|
|
171
|
+
const el = tileEl(c);
|
|
172
|
+
el.dispatchEvent(new Event("dragenter", { bubbles: true }));
|
|
173
|
+
const inner = el.firstElementChild as Element;
|
|
174
|
+
inner.dispatchEvent(new Event("dragenter", { bubbles: true })); // depth 2
|
|
175
|
+
inner.remove(); // slot swap: the child's leave never fires
|
|
176
|
+
el.dispatchEvent(leaveEvent(null)); // pointer exits the tile for real
|
|
148
177
|
await nextTick();
|
|
149
178
|
expect(el.classList.contains("hk-add-tile--drag-over")).toBe(false);
|
|
179
|
+
// The next drag session starts from a clean slate.
|
|
180
|
+
el.dispatchEvent(new Event("dragenter", { bubbles: true }));
|
|
181
|
+
await nextTick();
|
|
182
|
+
expect(el.classList.contains("hk-add-tile--drag-over")).toBe(true);
|
|
150
183
|
});
|
|
151
184
|
|
|
152
185
|
it("cancels dragenter/dragover exactly when it accepts the drag", () => {
|
|
@@ -16,7 +16,7 @@ import "./HkAddTile.scss";
|
|
|
16
16
|
* the empty state of a list or panel ("no sources yet — add one to
|
|
17
17
|
* begin"). The whole tile is the click target; hosts no longer pair
|
|
18
18
|
* a passive dashed box with a separate button below it.
|
|
19
|
-
* - **compact** — a slim
|
|
19
|
+
* - **compact** — a slim start-aligned row ("+ Add node / repo"): the
|
|
20
20
|
* tile that rides the END of a list of rows and grows the list. It
|
|
21
21
|
* replaces the loose secondary button, so the add affordance reads
|
|
22
22
|
* as part of the list instead of floating under it.
|
|
@@ -60,6 +60,7 @@ export default defineComponent({
|
|
|
60
60
|
const dragOver = computed(
|
|
61
61
|
() => props.droppable && !props.disabled && dragDepth.value > 0,
|
|
62
62
|
);
|
|
63
|
+
const rootEl = ref<HTMLButtonElement | null>(null);
|
|
63
64
|
|
|
64
65
|
/** Whether this tile accepts the drag at all. Refusing means NEVER
|
|
65
66
|
* calling preventDefault: the browser only permits a drop onto a
|
|
@@ -83,8 +84,18 @@ export default defineComponent({
|
|
|
83
84
|
e.preventDefault();
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
function onDragleave() {
|
|
87
|
-
|
|
87
|
+
function onDragleave(e: DragEvent) {
|
|
88
|
+
// Containment check instead of a blind decrement: a child that
|
|
89
|
+
// leaves the DOM mid-hover (slot swap) never fires its own leave,
|
|
90
|
+
// so a plain `depth -= 1` could strand the count above zero and
|
|
91
|
+
// keep the drag-over wash lit after the pointer has fully exited
|
|
92
|
+
// (the R3 residual sweep). When the leave's relatedTarget is
|
|
93
|
+
// outside the tile — or null, i.e. left to nothing — the pointer
|
|
94
|
+
// has truly gone: reset fully.
|
|
95
|
+
const root = rootEl.value;
|
|
96
|
+
const rt = e.relatedTarget as Node | null;
|
|
97
|
+
if (root && rt && root.contains(rt)) return;
|
|
98
|
+
dragDepth.value = 0;
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
function onDrop(e: DragEvent) {
|
|
@@ -115,6 +126,7 @@ export default defineComponent({
|
|
|
115
126
|
return (
|
|
116
127
|
<button
|
|
117
128
|
type="button"
|
|
129
|
+
ref={rootEl}
|
|
118
130
|
class={[
|
|
119
131
|
"hk-add-tile",
|
|
120
132
|
props.compact && "hk-add-tile--compact",
|
|
@@ -3,11 +3,26 @@
|
|
|
3
3
|
.hk-media-slider {
|
|
4
4
|
position: relative;
|
|
5
5
|
height: 6px;
|
|
6
|
-
border-radius: var(--radius-sm);
|
|
7
|
-
background: rgb(var(--color-muted) / 22%);
|
|
8
6
|
cursor: pointer;
|
|
9
7
|
touch-action: none;
|
|
10
8
|
@include user-select(none);
|
|
9
|
+
// The drawable rail is inset by the thumb radius at each end (6px — the
|
|
10
|
+
// thumb is 12px at every size); the value comes inline from the component,
|
|
11
|
+
// this is only the no-inline fallback. A thumb parked on 0/1 then rests
|
|
12
|
+
// ON the rail instead of hanging off its cap (2026-11-11, the same shape
|
|
13
|
+
// HkSlider ships).
|
|
14
|
+
--hk-media-slider-rail-inset: 6px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The track paint moved off the element box onto ::before so it can start
|
|
18
|
+
// and end at the rail edges (the element itself stays the full-width hit
|
|
19
|
+
// area).
|
|
20
|
+
.hk-media-slider::before {
|
|
21
|
+
content: "";
|
|
22
|
+
position: absolute;
|
|
23
|
+
inset: 0 var(--hk-media-slider-rail-inset, 6px);
|
|
24
|
+
border-radius: var(--radius-full, 9999px);
|
|
25
|
+
background: rgb(var(--color-muted) / 22%);
|
|
11
26
|
}
|
|
12
27
|
|
|
13
28
|
.hk-media-slider[data-size="sm"] {
|
|
@@ -21,15 +36,20 @@
|
|
|
21
36
|
|
|
22
37
|
.hk-media-slider-buffered {
|
|
23
38
|
position: absolute;
|
|
24
|
-
inset: 0 auto 0
|
|
25
|
-
|
|
39
|
+
inset: 0 auto 0 var(--hk-media-slider-rail-inset, 6px);
|
|
40
|
+
// Flat start (hidden under the fill), rounded end cap: the buffered edge
|
|
41
|
+
// is visible past the fill at partial playback.
|
|
42
|
+
border-radius: 0 var(--radius-full, 9999px) var(--radius-full, 9999px) 0;
|
|
26
43
|
background: rgb(var(--color-muted) / 40%);
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
.hk-media-slider-fill {
|
|
30
47
|
position: absolute;
|
|
31
|
-
inset: 0 auto 0
|
|
32
|
-
|
|
48
|
+
inset: 0 auto 0 var(--hk-media-slider-rail-inset, 6px);
|
|
49
|
+
// The LEFT cap stays FLAT — a pill cap on a thin saturated bar reads as a
|
|
50
|
+
// pointed nib at the rail start (2026-11-11 user report) — while the end
|
|
51
|
+
// cap stays round and closes the rail off at 100%.
|
|
52
|
+
border-radius: 0 var(--radius-full, 9999px) var(--radius-full, 9999px) 0;
|
|
33
53
|
background: rgb(var(--color-primary));
|
|
34
54
|
}
|
|
35
55
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp, h, ref } from "vue";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
import HkMediaSlider from "./HkMediaSlider";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* HkMediaSlider contract (the seek/volume primitive): the 2026-11-11
|
|
11
|
+
* rail-inset geometry — thumb parked on 0/1 rests ON the rail, buffered and
|
|
12
|
+
* fill widths anchor at the rail start (flat cap), presses map into the
|
|
13
|
+
* inset rail. The nested precision editor this shares visual language with
|
|
14
|
+
* is pinned in hikari's HkSlider suite.
|
|
15
|
+
*
|
|
16
|
+
* Repo test convention: raw createApp + document queries.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
20
|
+
|
|
21
|
+
function mountSlider(ratio: number, buffered = 0) {
|
|
22
|
+
const container = document.createElement("div");
|
|
23
|
+
document.body.appendChild(container);
|
|
24
|
+
const seen: Array<number> = [];
|
|
25
|
+
const app = createApp({
|
|
26
|
+
setup: () => () =>
|
|
27
|
+
h(HkMediaSlider, {
|
|
28
|
+
ratio,
|
|
29
|
+
buffered,
|
|
30
|
+
ariaLabel: "Seek",
|
|
31
|
+
"onUpdate:ratio": (v: number) => seen.push(v),
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
app.mount(container);
|
|
35
|
+
mounts.push({ app, container });
|
|
36
|
+
const slider = container.querySelector(".hk-media-slider") as HTMLElement;
|
|
37
|
+
return { slider, seen };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function pinRect(slider: HTMLElement) {
|
|
41
|
+
Object.defineProperty(slider, "getBoundingClientRect", {
|
|
42
|
+
configurable: true,
|
|
43
|
+
value: () =>
|
|
44
|
+
({ left: 0, width: 200, height: 6, top: 0, right: 200, bottom: 6, x: 0, y: 0 }) as DOMRect,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function pointer(type: string, clientX: number) {
|
|
49
|
+
return new PointerEvent(type, { bubbles: true, clientX, pointerId: 1, pointerType: "mouse" });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
54
|
+
app.unmount();
|
|
55
|
+
container.remove();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("HkMediaSlider — the inset rail", () => {
|
|
60
|
+
it("keeps endpoint thumbs ON the rail with a flat-start fill", () => {
|
|
61
|
+
// Source contract: the pill cap on a thin saturated bar read as a
|
|
62
|
+
// pointed nib at the rail start (2026-11-11 user report).
|
|
63
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
64
|
+
const scss = readFileSync(join(here, "HkMediaSlider.scss"), "utf-8");
|
|
65
|
+
const fill = scss.match(/\.hk-media-slider-fill\s*{[^}]*}/)?.[0] ?? "";
|
|
66
|
+
expect(fill).toContain("border-radius: 0 var(--radius-full, 9999px)");
|
|
67
|
+
expect(fill).toContain("inset: 0 auto 0 var(--hk-media-slider-rail-inset, 6px)");
|
|
68
|
+
|
|
69
|
+
const atEnd = mountSlider(1);
|
|
70
|
+
expect(
|
|
71
|
+
(atEnd.slider.querySelector(".hk-media-slider-thumb") as HTMLElement).style.left,
|
|
72
|
+
).toBe("calc(100% - 6px)");
|
|
73
|
+
expect(
|
|
74
|
+
(atEnd.slider.querySelector(".hk-media-slider-fill") as HTMLElement).style.width,
|
|
75
|
+
).toBe("calc(100% - 12px)");
|
|
76
|
+
expect(atEnd.slider.style.getPropertyValue("--hk-media-slider-rail-inset")).toBe("6px");
|
|
77
|
+
|
|
78
|
+
const atStart = mountSlider(0);
|
|
79
|
+
expect(
|
|
80
|
+
(atStart.slider.querySelector(".hk-media-slider-thumb") as HTMLElement).style.left,
|
|
81
|
+
).toBe("calc(0% + 6px)");
|
|
82
|
+
expect(
|
|
83
|
+
(atStart.slider.querySelector(".hk-media-slider-fill") as HTMLElement).style.width,
|
|
84
|
+
).toBe("calc(0% - 0px)");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("anchors the buffered bar at the rail start ahead of the fill", () => {
|
|
88
|
+
const { slider } = mountSlider(0.25, 0.5);
|
|
89
|
+
expect(
|
|
90
|
+
(slider.querySelector(".hk-media-slider-buffered") as HTMLElement).style.width,
|
|
91
|
+
).toBe("calc(50% - 6px)");
|
|
92
|
+
expect(
|
|
93
|
+
(slider.querySelector(".hk-media-slider-fill") as HTMLElement).style.width,
|
|
94
|
+
).toBe("calc(25% - 3px)");
|
|
95
|
+
expect(
|
|
96
|
+
(slider.querySelector(".hk-media-slider-thumb") as HTMLElement).style.left,
|
|
97
|
+
).toBe("calc(25% + 3px)");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("omits the buffered bar when nothing is buffered", () => {
|
|
101
|
+
const { slider } = mountSlider(0.5);
|
|
102
|
+
expect(slider.querySelector(".hk-media-slider-buffered")).toBeNull();
|
|
103
|
+
expect(
|
|
104
|
+
(slider.querySelector(".hk-media-slider-fill") as HTMLElement).style.width,
|
|
105
|
+
).toBe("calc(50% - 6px)");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("maps presses into the inset rail and saturates outside", () => {
|
|
109
|
+
const { slider, seen } = mountSlider(0);
|
|
110
|
+
pinRect(slider);
|
|
111
|
+
// 200px rect, 6px insets → a 188px rail: the rail start/mid/end land on
|
|
112
|
+
// clientX 6/100/194; presses outside saturate.
|
|
113
|
+
slider.dispatchEvent(pointer("pointerdown", 6));
|
|
114
|
+
expect(seen).toEqual([0]);
|
|
115
|
+
slider.dispatchEvent(pointer("pointerdown", 100));
|
|
116
|
+
expect(seen).toEqual([0, 0.5]);
|
|
117
|
+
slider.dispatchEvent(pointer("pointerdown", 194));
|
|
118
|
+
expect(seen).toEqual([0, 0.5, 1]);
|
|
119
|
+
// Presses before the rail start clamp (the old full-width mapping would
|
|
120
|
+
// emit 3/200 instead of 0).
|
|
121
|
+
slider.dispatchEvent(pointer("pointerdown", 3));
|
|
122
|
+
expect(seen).toEqual([0, 0.5, 1, 0]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("degenerate rails re-assert the current value instead of dividing", () => {
|
|
126
|
+
const { slider, seen } = mountSlider(0.5);
|
|
127
|
+
// 10px rect is thinner than both insets (12px): the press re-emits the
|
|
128
|
+
// current ratio (the Rust mirror's None → no-emit parity), never a
|
|
129
|
+
// division blow-up.
|
|
130
|
+
pinRect(slider);
|
|
131
|
+
Object.defineProperty(slider, "getBoundingClientRect", {
|
|
132
|
+
configurable: true,
|
|
133
|
+
value: () =>
|
|
134
|
+
({ left: 0, width: 10, height: 6, top: 0, right: 10, bottom: 6, x: 0, y: 0 }) as DOMRect,
|
|
135
|
+
});
|
|
136
|
+
slider.dispatchEvent(pointer("pointerdown", 5));
|
|
137
|
+
expect(seen).toEqual([0.5]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -7,6 +7,16 @@ import "./HkMediaSlider.scss";
|
|
|
7
7
|
* volume slider are built on. Pointer-drag (with capture) emits the ratio
|
|
8
8
|
* continuously so consumers can scrub live. An optional secondary `buffered`
|
|
9
9
|
* fill renders behind the played fill.
|
|
10
|
+
*
|
|
11
|
+
* Rail geometry (2026-11-11, the same shape HkSlider ships): the drawable
|
|
12
|
+
* rail is inset by the thumb radius (6px — the thumb is 12px at every size)
|
|
13
|
+
* at each end via the inline `--hk-media-slider-rail-inset` var, so a thumb
|
|
14
|
+
* parked on 0/1 rests ON the rail instead of hanging off its cap, and the
|
|
15
|
+
* fill starts FLAT at the rail edge (a rounded cap on a thin saturated bar
|
|
16
|
+
* reads as a pointed nib). The emitted positions use the linear calc
|
|
17
|
+
* expansion `calc(F% ± Npx)` — identical geometry to
|
|
18
|
+
* `inset + (100% - 2·inset)·f`, and the form jsdom/cssstyle parses for the
|
|
19
|
+
* contract tests.
|
|
10
20
|
*/
|
|
11
21
|
export default defineComponent({
|
|
12
22
|
name: "HkMediaSlider",
|
|
@@ -24,11 +34,36 @@ export default defineComponent({
|
|
|
24
34
|
const trackRef = ref<HTMLElement | null>(null);
|
|
25
35
|
let dragging = false;
|
|
26
36
|
|
|
37
|
+
/** Thumb radius: the thumb is 12px at every size (scss). */
|
|
38
|
+
const railInset = 6;
|
|
39
|
+
|
|
40
|
+
function round4(n: number): number {
|
|
41
|
+
return Math.round(n * 1e4) / 1e4;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The fill/buffered width along the rail: `railLength·f` as
|
|
45
|
+
* `calc(F% - Npx)`. */
|
|
46
|
+
function railWidth(f: number): string {
|
|
47
|
+
return `calc(${round4(f * 100)}% - ${round4(railInset * 2 * f)}px)`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A position ON the rail (thumb center): `inset + railLength·f`. */
|
|
51
|
+
function railPos(f: number): string {
|
|
52
|
+
const px = round4(railInset * (1 - 2 * f));
|
|
53
|
+
const op = px < 0 ? " - " : " + ";
|
|
54
|
+
return `calc(${round4(f * 100)}%${op}${Math.abs(px)}px)`;
|
|
55
|
+
}
|
|
56
|
+
|
|
27
57
|
function ratioFrom(clientX: number): number {
|
|
28
58
|
const el = trackRef.value;
|
|
29
59
|
if (!el) return 0;
|
|
30
60
|
const rect = el.getBoundingClientRect();
|
|
31
|
-
|
|
61
|
+
const rail = rect.width - railInset * 2;
|
|
62
|
+
// Degenerate rail (hidden or thinner than both insets): re-assert the
|
|
63
|
+
// current value instead of inventing a position (the Rust mirror's
|
|
64
|
+
// None → no-emit parity).
|
|
65
|
+
if (rect.width <= 0 || rail <= 0) return props.ratio;
|
|
66
|
+
return Math.max(0, Math.min(1, (clientX - rect.left - railInset) / rail));
|
|
32
67
|
}
|
|
33
68
|
function onDown(e: PointerEvent) {
|
|
34
69
|
if (props.disabled) return;
|
|
@@ -62,6 +97,7 @@ export default defineComponent({
|
|
|
62
97
|
props.disabled && "is-disabled",
|
|
63
98
|
].filter(Boolean).join(" ")}
|
|
64
99
|
data-size={props.size}
|
|
100
|
+
style={{ "--hk-media-slider-rail-inset": `${railInset}px` }}
|
|
65
101
|
role="slider"
|
|
66
102
|
tabindex={-1}
|
|
67
103
|
aria-label={props.ariaLabel}
|
|
@@ -71,10 +107,13 @@ export default defineComponent({
|
|
|
71
107
|
onPointerdown={onDown}
|
|
72
108
|
>
|
|
73
109
|
{props.buffered > 0 && (
|
|
74
|
-
<div
|
|
110
|
+
<div
|
|
111
|
+
class="hk-media-slider-buffered"
|
|
112
|
+
style={{ width: railWidth(props.buffered) }}
|
|
113
|
+
/>
|
|
75
114
|
)}
|
|
76
|
-
<div class="hk-media-slider-fill" style={{ width:
|
|
77
|
-
<div class="hk-media-slider-thumb" style={{ left:
|
|
115
|
+
<div class="hk-media-slider-fill" style={{ width: railWidth(props.ratio) }} />
|
|
116
|
+
<div class="hk-media-slider-thumb" style={{ left: railPos(props.ratio) }} />
|
|
78
117
|
</div>
|
|
79
118
|
);
|
|
80
119
|
},
|
|
@@ -128,6 +128,16 @@ describe("HkThemeToggle row lead-cell contract", () => {
|
|
|
128
128
|
// rules anymore (the alignment contract retired with the row).
|
|
129
129
|
const css = read("HkThemeToggle.scss");
|
|
130
130
|
expect(css).not.toMatch(/\.s-theme-item-customize \.hk-menu-item-icon/);
|
|
131
|
+
// The entry's vertical rhythm is owned component-side (residual
|
|
132
|
+
// sweep: the margin rule previously had no vue-side pin at all).
|
|
133
|
+
expect(css).toMatch(/\.s-theme-item-customize\s*\{[^}]*margin-top/);
|
|
134
|
+
// And the mobile sheet rides the family's 44px touch contract. The
|
|
135
|
+
// `}\s*\}` fence pins media-block CONTAINMENT — a rule un-nested
|
|
136
|
+
// from the block but placed after it would fail the double close
|
|
137
|
+
// (residual sweep: `[\s\S]*?` alone bridges braces).
|
|
138
|
+
expect(css).toMatch(
|
|
139
|
+
/\(max-width: 767px\)[\s\S]*?\.s-theme-item-customize\s*\{[^}]*min-height[^}]*\}\s*\}/,
|
|
140
|
+
);
|
|
131
141
|
});
|
|
132
142
|
|
|
133
143
|
it("aligns mode-extra host rows to the lead column without rescaling their glyph", () => {
|
|
@@ -365,6 +365,14 @@
|
|
|
365
365
|
.s-theme-item-row[data-custom] .s-theme-item-name {
|
|
366
366
|
margin-inline-end: 2.75rem;
|
|
367
367
|
}
|
|
368
|
+
|
|
369
|
+
/* The customize tile rides the menu family's sheet touch geometry:
|
|
370
|
+
* its compact padding alone reads ~32px, under the 44px sheet-row
|
|
371
|
+
* contract every sibling row gets from the item-sheet tokens
|
|
372
|
+
* (2026-11-11 residual sweep). Desktop keeps the compact metrics. */
|
|
373
|
+
.s-theme-item-customize {
|
|
374
|
+
min-height: var(--hk-menu-item-min-h, 2.75rem);
|
|
375
|
+
}
|
|
368
376
|
}
|
|
369
377
|
|
|
370
378
|
/* ── Host-provided row anatomy (item-leading / item-trailing) ───────────
|
|
@@ -74,10 +74,11 @@ function triggerButton(container: HTMLElement): HTMLButtonElement {
|
|
|
74
74
|
return trigger!;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function
|
|
77
|
+
function customizeEntry(): HTMLButtonElement {
|
|
78
78
|
// The entry rides the standard HkAddTile (2026-11-11 family migration)
|
|
79
79
|
// and no longer carries s-theme-item-btn — the stable host hook class
|
|
80
|
-
// is the query surface.
|
|
80
|
+
// is the query surface. (The helper's old paletteButton name retired
|
|
81
|
+
// with the palette glyph: the tile's default is a Plus.)
|
|
81
82
|
const btn = document.body.querySelector<HTMLButtonElement>(
|
|
82
83
|
".s-theme-menu .s-theme-item-customize",
|
|
83
84
|
);
|
|
@@ -168,7 +169,7 @@ describe("HkThemeToggle external customization", () => {
|
|
|
168
169
|
openMenu(container);
|
|
169
170
|
await settle();
|
|
170
171
|
|
|
171
|
-
|
|
172
|
+
customizeEntry().click();
|
|
172
173
|
await settle();
|
|
173
174
|
|
|
174
175
|
expect(openCustomize()).toBe(1);
|
|
@@ -183,7 +184,7 @@ describe("HkThemeToggle external customization", () => {
|
|
|
183
184
|
openMenu(container);
|
|
184
185
|
await settle();
|
|
185
186
|
|
|
186
|
-
|
|
187
|
+
customizeEntry().click();
|
|
187
188
|
await settle();
|
|
188
189
|
|
|
189
190
|
expect(openCustomize()).toBe(0);
|