@celestia-island/hikari 0.55.344 → 0.55.345
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
CHANGED
|
@@ -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
|
},
|