@purpurds/slider 0.0.1
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/dist/LICENSE.txt +193 -0
- package/dist/slider.cjs.js +6 -0
- package/dist/slider.cjs.js.map +1 -0
- package/dist/slider.d.ts +21 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.es.js +836 -0
- package/dist/slider.es.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +60 -0
- package/readme.mdx +81 -0
- package/src/global.d.ts +4 -0
- package/src/slider.module.scss +82 -0
- package/src/slider.stories.tsx +177 -0
- package/src/slider.test.tsx +63 -0
- package/src/slider.tsx +73 -0
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
import { jsxs as Pe, jsx as G } from "react/jsx-runtime";
|
|
2
|
+
import D, { useCallback as ce, createContext as q, useMemo as O, createElement as v, useContext as ae, useRef as E, useEffect as k, useState as N, useLayoutEffect as Ee, forwardRef as P, Children as B, isValidElement as F, cloneElement as se, Fragment as De, useId as Me } from "react";
|
|
3
|
+
import "react-dom";
|
|
4
|
+
function y() {
|
|
5
|
+
return y = Object.assign ? Object.assign.bind() : function(e) {
|
|
6
|
+
for (var t = 1; t < arguments.length; t++) {
|
|
7
|
+
var n = arguments[t];
|
|
8
|
+
for (var r in n)
|
|
9
|
+
Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
|
|
10
|
+
}
|
|
11
|
+
return e;
|
|
12
|
+
}, y.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
function le(e, [t, n]) {
|
|
15
|
+
return Math.min(n, Math.max(t, e));
|
|
16
|
+
}
|
|
17
|
+
function K(e, t, { checkForDefaultPrevented: n = !0 } = {}) {
|
|
18
|
+
return function(i) {
|
|
19
|
+
if (e == null || e(i), n === !1 || !i.defaultPrevented)
|
|
20
|
+
return t == null ? void 0 : t(i);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function Re(e, t) {
|
|
24
|
+
typeof e == "function" ? e(t) : e != null && (e.current = t);
|
|
25
|
+
}
|
|
26
|
+
function ue(...e) {
|
|
27
|
+
return (t) => e.forEach(
|
|
28
|
+
(n) => Re(n, t)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function M(...e) {
|
|
32
|
+
return ce(ue(...e), e);
|
|
33
|
+
}
|
|
34
|
+
function de(e, t = []) {
|
|
35
|
+
let n = [];
|
|
36
|
+
function r(o, a) {
|
|
37
|
+
const c = /* @__PURE__ */ q(a), l = n.length;
|
|
38
|
+
n = [
|
|
39
|
+
...n,
|
|
40
|
+
a
|
|
41
|
+
];
|
|
42
|
+
function u(s) {
|
|
43
|
+
const { scope: d, children: S, ...f } = s, $ = (d == null ? void 0 : d[e][l]) || c, p = O(
|
|
44
|
+
() => f,
|
|
45
|
+
Object.values(f)
|
|
46
|
+
);
|
|
47
|
+
return /* @__PURE__ */ v($.Provider, {
|
|
48
|
+
value: p
|
|
49
|
+
}, S);
|
|
50
|
+
}
|
|
51
|
+
function m(s, d) {
|
|
52
|
+
const S = (d == null ? void 0 : d[e][l]) || c, f = ae(S);
|
|
53
|
+
if (f)
|
|
54
|
+
return f;
|
|
55
|
+
if (a !== void 0)
|
|
56
|
+
return a;
|
|
57
|
+
throw new Error(`\`${s}\` must be used within \`${o}\``);
|
|
58
|
+
}
|
|
59
|
+
return u.displayName = o + "Provider", [
|
|
60
|
+
u,
|
|
61
|
+
m
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
const i = () => {
|
|
65
|
+
const o = n.map((a) => /* @__PURE__ */ q(a));
|
|
66
|
+
return function(c) {
|
|
67
|
+
const l = (c == null ? void 0 : c[e]) || o;
|
|
68
|
+
return O(
|
|
69
|
+
() => ({
|
|
70
|
+
[`__scope${e}`]: {
|
|
71
|
+
...c,
|
|
72
|
+
[e]: l
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
[
|
|
76
|
+
c,
|
|
77
|
+
l
|
|
78
|
+
]
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
return i.scopeName = e, [
|
|
83
|
+
r,
|
|
84
|
+
Ae(i, ...t)
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
function Ae(...e) {
|
|
88
|
+
const t = e[0];
|
|
89
|
+
if (e.length === 1)
|
|
90
|
+
return t;
|
|
91
|
+
const n = () => {
|
|
92
|
+
const r = e.map(
|
|
93
|
+
(i) => ({
|
|
94
|
+
useScope: i(),
|
|
95
|
+
scopeName: i.scopeName
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
return function(o) {
|
|
99
|
+
const a = r.reduce((c, { useScope: l, scopeName: u }) => {
|
|
100
|
+
const s = l(o)[`__scope${u}`];
|
|
101
|
+
return {
|
|
102
|
+
...c,
|
|
103
|
+
...s
|
|
104
|
+
};
|
|
105
|
+
}, {});
|
|
106
|
+
return O(
|
|
107
|
+
() => ({
|
|
108
|
+
[`__scope${t.scopeName}`]: a
|
|
109
|
+
}),
|
|
110
|
+
[
|
|
111
|
+
a
|
|
112
|
+
]
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
return n.scopeName = t.scopeName, n;
|
|
117
|
+
}
|
|
118
|
+
function fe(e) {
|
|
119
|
+
const t = E(e);
|
|
120
|
+
return k(() => {
|
|
121
|
+
t.current = e;
|
|
122
|
+
}), O(
|
|
123
|
+
() => (...n) => {
|
|
124
|
+
var r;
|
|
125
|
+
return (r = t.current) === null || r === void 0 ? void 0 : r.call(t, ...n);
|
|
126
|
+
},
|
|
127
|
+
[]
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function Ie({ prop: e, defaultProp: t, onChange: n = () => {
|
|
131
|
+
} }) {
|
|
132
|
+
const [r, i] = Ke({
|
|
133
|
+
defaultProp: t,
|
|
134
|
+
onChange: n
|
|
135
|
+
}), o = e !== void 0, a = o ? e : r, c = fe(n), l = ce((u) => {
|
|
136
|
+
if (o) {
|
|
137
|
+
const s = typeof u == "function" ? u(e) : u;
|
|
138
|
+
s !== e && c(s);
|
|
139
|
+
} else
|
|
140
|
+
i(u);
|
|
141
|
+
}, [
|
|
142
|
+
o,
|
|
143
|
+
e,
|
|
144
|
+
i,
|
|
145
|
+
c
|
|
146
|
+
]);
|
|
147
|
+
return [
|
|
148
|
+
a,
|
|
149
|
+
l
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
function Ke({ defaultProp: e, onChange: t }) {
|
|
153
|
+
const n = N(e), [r] = n, i = E(r), o = fe(t);
|
|
154
|
+
return k(() => {
|
|
155
|
+
i.current !== r && (o(r), i.current = r);
|
|
156
|
+
}, [
|
|
157
|
+
r,
|
|
158
|
+
i,
|
|
159
|
+
o
|
|
160
|
+
]), n;
|
|
161
|
+
}
|
|
162
|
+
const Oe = /* @__PURE__ */ q(void 0);
|
|
163
|
+
function Ne(e) {
|
|
164
|
+
const t = ae(Oe);
|
|
165
|
+
return e || t || "ltr";
|
|
166
|
+
}
|
|
167
|
+
function Te(e) {
|
|
168
|
+
const t = E({
|
|
169
|
+
value: e,
|
|
170
|
+
previous: e
|
|
171
|
+
});
|
|
172
|
+
return O(() => (t.current.value !== e && (t.current.previous = t.current.value, t.current.value = e), t.current.previous), [
|
|
173
|
+
e
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
const Ve = globalThis != null && globalThis.document ? Ee : () => {
|
|
177
|
+
};
|
|
178
|
+
function Be(e) {
|
|
179
|
+
const [t, n] = N(void 0);
|
|
180
|
+
return Ve(() => {
|
|
181
|
+
if (e) {
|
|
182
|
+
n({
|
|
183
|
+
width: e.offsetWidth,
|
|
184
|
+
height: e.offsetHeight
|
|
185
|
+
});
|
|
186
|
+
const r = new ResizeObserver((i) => {
|
|
187
|
+
if (!Array.isArray(i) || !i.length)
|
|
188
|
+
return;
|
|
189
|
+
const o = i[0];
|
|
190
|
+
let a, c;
|
|
191
|
+
if ("borderBoxSize" in o) {
|
|
192
|
+
const l = o.borderBoxSize, u = Array.isArray(l) ? l[0] : l;
|
|
193
|
+
a = u.inlineSize, c = u.blockSize;
|
|
194
|
+
} else
|
|
195
|
+
a = e.offsetWidth, c = e.offsetHeight;
|
|
196
|
+
n({
|
|
197
|
+
width: a,
|
|
198
|
+
height: c
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return r.observe(e, {
|
|
202
|
+
box: "border-box"
|
|
203
|
+
}), () => r.unobserve(e);
|
|
204
|
+
} else
|
|
205
|
+
n(void 0);
|
|
206
|
+
}, [
|
|
207
|
+
e
|
|
208
|
+
]), t;
|
|
209
|
+
}
|
|
210
|
+
const U = /* @__PURE__ */ P((e, t) => {
|
|
211
|
+
const { children: n, ...r } = e, i = B.toArray(n), o = i.find(ze);
|
|
212
|
+
if (o) {
|
|
213
|
+
const a = o.props.children, c = i.map((l) => l === o ? B.count(a) > 1 ? B.only(null) : /* @__PURE__ */ F(a) ? a.props.children : null : l);
|
|
214
|
+
return /* @__PURE__ */ v(Z, y({}, r, {
|
|
215
|
+
ref: t
|
|
216
|
+
}), /* @__PURE__ */ F(a) ? /* @__PURE__ */ se(a, void 0, c) : null);
|
|
217
|
+
}
|
|
218
|
+
return /* @__PURE__ */ v(Z, y({}, r, {
|
|
219
|
+
ref: t
|
|
220
|
+
}), n);
|
|
221
|
+
});
|
|
222
|
+
U.displayName = "Slot";
|
|
223
|
+
const Z = /* @__PURE__ */ P((e, t) => {
|
|
224
|
+
const { children: n, ...r } = e;
|
|
225
|
+
return /* @__PURE__ */ F(n) ? /* @__PURE__ */ se(n, {
|
|
226
|
+
...Le(r, n.props),
|
|
227
|
+
ref: t ? ue(t, n.ref) : n.ref
|
|
228
|
+
}) : B.count(n) > 1 ? B.only(null) : null;
|
|
229
|
+
});
|
|
230
|
+
Z.displayName = "SlotClone";
|
|
231
|
+
const ke = ({ children: e }) => /* @__PURE__ */ v(De, null, e);
|
|
232
|
+
function ze(e) {
|
|
233
|
+
return /* @__PURE__ */ F(e) && e.type === ke;
|
|
234
|
+
}
|
|
235
|
+
function Le(e, t) {
|
|
236
|
+
const n = {
|
|
237
|
+
...t
|
|
238
|
+
};
|
|
239
|
+
for (const r in t) {
|
|
240
|
+
const i = e[r], o = t[r];
|
|
241
|
+
/^on[A-Z]/.test(r) ? i && o ? n[r] = (...c) => {
|
|
242
|
+
o(...c), i(...c);
|
|
243
|
+
} : i && (n[r] = i) : r === "style" ? n[r] = {
|
|
244
|
+
...i,
|
|
245
|
+
...o
|
|
246
|
+
} : r === "className" && (n[r] = [
|
|
247
|
+
i,
|
|
248
|
+
o
|
|
249
|
+
].filter(Boolean).join(" "));
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
...e,
|
|
253
|
+
...n
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const He = [
|
|
257
|
+
"a",
|
|
258
|
+
"button",
|
|
259
|
+
"div",
|
|
260
|
+
"form",
|
|
261
|
+
"h2",
|
|
262
|
+
"h3",
|
|
263
|
+
"img",
|
|
264
|
+
"input",
|
|
265
|
+
"label",
|
|
266
|
+
"li",
|
|
267
|
+
"nav",
|
|
268
|
+
"ol",
|
|
269
|
+
"p",
|
|
270
|
+
"span",
|
|
271
|
+
"svg",
|
|
272
|
+
"ul"
|
|
273
|
+
], Y = He.reduce((e, t) => {
|
|
274
|
+
const n = /* @__PURE__ */ P((r, i) => {
|
|
275
|
+
const { asChild: o, ...a } = r, c = o ? U : t;
|
|
276
|
+
return k(() => {
|
|
277
|
+
window[Symbol.for("radix-ui")] = !0;
|
|
278
|
+
}, []), /* @__PURE__ */ v(c, y({}, a, {
|
|
279
|
+
ref: i
|
|
280
|
+
}));
|
|
281
|
+
});
|
|
282
|
+
return n.displayName = `Primitive.${t}`, {
|
|
283
|
+
...e,
|
|
284
|
+
[t]: n
|
|
285
|
+
};
|
|
286
|
+
}, {});
|
|
287
|
+
function je(e) {
|
|
288
|
+
const t = e + "CollectionProvider", [n, r] = de(t), [i, o] = n(t, {
|
|
289
|
+
collectionRef: {
|
|
290
|
+
current: null
|
|
291
|
+
},
|
|
292
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
293
|
+
}), a = (S) => {
|
|
294
|
+
const { scope: f, children: $ } = S, p = D.useRef(null), b = D.useRef(/* @__PURE__ */ new Map()).current;
|
|
295
|
+
return /* @__PURE__ */ D.createElement(i, {
|
|
296
|
+
scope: f,
|
|
297
|
+
itemMap: b,
|
|
298
|
+
collectionRef: p
|
|
299
|
+
}, $);
|
|
300
|
+
}, c = e + "CollectionSlot", l = /* @__PURE__ */ D.forwardRef((S, f) => {
|
|
301
|
+
const { scope: $, children: p } = S, b = o(c, $), _ = M(f, b.collectionRef);
|
|
302
|
+
return /* @__PURE__ */ D.createElement(U, {
|
|
303
|
+
ref: _
|
|
304
|
+
}, p);
|
|
305
|
+
}), u = e + "CollectionItemSlot", m = "data-radix-collection-item", s = /* @__PURE__ */ D.forwardRef((S, f) => {
|
|
306
|
+
const { scope: $, children: p, ...b } = S, _ = D.useRef(null), h = M(f, _), g = o(u, $);
|
|
307
|
+
return D.useEffect(() => (g.itemMap.set(_, {
|
|
308
|
+
ref: _,
|
|
309
|
+
...b
|
|
310
|
+
}), () => void g.itemMap.delete(_))), /* @__PURE__ */ D.createElement(U, {
|
|
311
|
+
[m]: "",
|
|
312
|
+
ref: h
|
|
313
|
+
}, p);
|
|
314
|
+
});
|
|
315
|
+
function d(S) {
|
|
316
|
+
const f = o(e + "CollectionConsumer", S);
|
|
317
|
+
return D.useCallback(() => {
|
|
318
|
+
const p = f.collectionRef.current;
|
|
319
|
+
if (!p)
|
|
320
|
+
return [];
|
|
321
|
+
const b = Array.from(p.querySelectorAll(`[${m}]`));
|
|
322
|
+
return Array.from(f.itemMap.values()).sort(
|
|
323
|
+
(g, R) => b.indexOf(g.ref.current) - b.indexOf(R.ref.current)
|
|
324
|
+
);
|
|
325
|
+
}, [
|
|
326
|
+
f.collectionRef,
|
|
327
|
+
f.itemMap
|
|
328
|
+
]);
|
|
329
|
+
}
|
|
330
|
+
return [
|
|
331
|
+
{
|
|
332
|
+
Provider: a,
|
|
333
|
+
Slot: l,
|
|
334
|
+
ItemSlot: s
|
|
335
|
+
},
|
|
336
|
+
d,
|
|
337
|
+
r
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
const pe = [
|
|
341
|
+
"PageUp",
|
|
342
|
+
"PageDown"
|
|
343
|
+
], $e = [
|
|
344
|
+
"ArrowUp",
|
|
345
|
+
"ArrowDown",
|
|
346
|
+
"ArrowLeft",
|
|
347
|
+
"ArrowRight"
|
|
348
|
+
], me = {
|
|
349
|
+
"from-left": [
|
|
350
|
+
"Home",
|
|
351
|
+
"PageDown",
|
|
352
|
+
"ArrowDown",
|
|
353
|
+
"ArrowLeft"
|
|
354
|
+
],
|
|
355
|
+
"from-right": [
|
|
356
|
+
"Home",
|
|
357
|
+
"PageDown",
|
|
358
|
+
"ArrowDown",
|
|
359
|
+
"ArrowRight"
|
|
360
|
+
],
|
|
361
|
+
"from-bottom": [
|
|
362
|
+
"Home",
|
|
363
|
+
"PageDown",
|
|
364
|
+
"ArrowDown",
|
|
365
|
+
"ArrowLeft"
|
|
366
|
+
],
|
|
367
|
+
"from-top": [
|
|
368
|
+
"Home",
|
|
369
|
+
"PageDown",
|
|
370
|
+
"ArrowUp",
|
|
371
|
+
"ArrowLeft"
|
|
372
|
+
]
|
|
373
|
+
}, z = "Slider", [J, Fe, Ue] = je(z), [Se, wt] = de(z, [
|
|
374
|
+
Ue
|
|
375
|
+
]), [Ye, W] = Se(z), We = /* @__PURE__ */ P((e, t) => {
|
|
376
|
+
const { name: n, min: r = 0, max: i = 100, step: o = 1, orientation: a = "horizontal", disabled: c = !1, minStepsBetweenThumbs: l = 0, defaultValue: u = [
|
|
377
|
+
r
|
|
378
|
+
], value: m, onValueChange: s = () => {
|
|
379
|
+
}, onValueCommit: d = () => {
|
|
380
|
+
}, inverted: S = !1, ...f } = e, [$, p] = N(null), b = M(
|
|
381
|
+
t,
|
|
382
|
+
(x) => p(x)
|
|
383
|
+
), _ = E(/* @__PURE__ */ new Set()), h = E(0), g = a === "horizontal", R = $ ? !!$.closest("form") : !0, ee = g ? Xe : Ge, [w = [], _e] = Ie({
|
|
384
|
+
prop: m,
|
|
385
|
+
defaultProp: u,
|
|
386
|
+
onChange: (x) => {
|
|
387
|
+
var C;
|
|
388
|
+
(C = [
|
|
389
|
+
..._.current
|
|
390
|
+
][h.current]) === null || C === void 0 || C.focus(), s(x);
|
|
391
|
+
}
|
|
392
|
+
}), te = E(w);
|
|
393
|
+
function ye(x) {
|
|
394
|
+
const C = rt(w, x);
|
|
395
|
+
T(x, C);
|
|
396
|
+
}
|
|
397
|
+
function we(x) {
|
|
398
|
+
T(x, h.current);
|
|
399
|
+
}
|
|
400
|
+
function Ce() {
|
|
401
|
+
const x = te.current[h.current];
|
|
402
|
+
w[h.current] !== x && d(w);
|
|
403
|
+
}
|
|
404
|
+
function T(x, C, { commit: L } = {
|
|
405
|
+
commit: !1
|
|
406
|
+
}) {
|
|
407
|
+
const ne = st(o), X = lt(Math.round((x - r) / o) * o + r, ne), V = le(X, [
|
|
408
|
+
r,
|
|
409
|
+
i
|
|
410
|
+
]);
|
|
411
|
+
_e((I = []) => {
|
|
412
|
+
const A = nt(I, V, C);
|
|
413
|
+
if (at(A, l * o)) {
|
|
414
|
+
h.current = A.indexOf(V);
|
|
415
|
+
const oe = String(A) !== String(I);
|
|
416
|
+
return oe && L && d(A), oe ? A : I;
|
|
417
|
+
} else
|
|
418
|
+
return I;
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return /* @__PURE__ */ v(Ye, {
|
|
422
|
+
scope: e.__scopeSlider,
|
|
423
|
+
disabled: c,
|
|
424
|
+
min: r,
|
|
425
|
+
max: i,
|
|
426
|
+
valueIndexToChangeRef: h,
|
|
427
|
+
thumbs: _.current,
|
|
428
|
+
values: w,
|
|
429
|
+
orientation: a
|
|
430
|
+
}, /* @__PURE__ */ v(J.Provider, {
|
|
431
|
+
scope: e.__scopeSlider
|
|
432
|
+
}, /* @__PURE__ */ v(J.Slot, {
|
|
433
|
+
scope: e.__scopeSlider
|
|
434
|
+
}, /* @__PURE__ */ v(ee, y({
|
|
435
|
+
"aria-disabled": c,
|
|
436
|
+
"data-disabled": c ? "" : void 0
|
|
437
|
+
}, f, {
|
|
438
|
+
ref: b,
|
|
439
|
+
onPointerDown: K(f.onPointerDown, () => {
|
|
440
|
+
c || (te.current = w);
|
|
441
|
+
}),
|
|
442
|
+
min: r,
|
|
443
|
+
max: i,
|
|
444
|
+
inverted: S,
|
|
445
|
+
onSlideStart: c ? void 0 : ye,
|
|
446
|
+
onSlideMove: c ? void 0 : we,
|
|
447
|
+
onSlideEnd: c ? void 0 : Ce,
|
|
448
|
+
onHomeKeyDown: () => !c && T(r, 0, {
|
|
449
|
+
commit: !0
|
|
450
|
+
}),
|
|
451
|
+
onEndKeyDown: () => !c && T(i, w.length - 1, {
|
|
452
|
+
commit: !0
|
|
453
|
+
}),
|
|
454
|
+
onStepKeyDown: ({ event: x, direction: C }) => {
|
|
455
|
+
if (!c) {
|
|
456
|
+
const X = pe.includes(x.key) || x.shiftKey && $e.includes(x.key) ? 10 : 1, V = h.current, I = w[V], A = o * X * C;
|
|
457
|
+
T(I + A, V, {
|
|
458
|
+
commit: !0
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
})))), R && w.map(
|
|
463
|
+
(x, C) => /* @__PURE__ */ v(tt, {
|
|
464
|
+
key: C,
|
|
465
|
+
name: n ? n + (w.length > 1 ? "[]" : "") : void 0,
|
|
466
|
+
value: x
|
|
467
|
+
})
|
|
468
|
+
));
|
|
469
|
+
}), [he, ve] = Se(z, {
|
|
470
|
+
startEdge: "left",
|
|
471
|
+
endEdge: "right",
|
|
472
|
+
size: "width",
|
|
473
|
+
direction: 1
|
|
474
|
+
}), Xe = /* @__PURE__ */ P((e, t) => {
|
|
475
|
+
const { min: n, max: r, dir: i, inverted: o, onSlideStart: a, onSlideMove: c, onSlideEnd: l, onStepKeyDown: u, ...m } = e, [s, d] = N(null), S = M(
|
|
476
|
+
t,
|
|
477
|
+
(h) => d(h)
|
|
478
|
+
), f = E(), $ = Ne(i), p = $ === "ltr", b = p && !o || !p && o;
|
|
479
|
+
function _(h) {
|
|
480
|
+
const g = f.current || s.getBoundingClientRect(), R = [
|
|
481
|
+
0,
|
|
482
|
+
g.width
|
|
483
|
+
], w = Q(R, b ? [
|
|
484
|
+
n,
|
|
485
|
+
r
|
|
486
|
+
] : [
|
|
487
|
+
r,
|
|
488
|
+
n
|
|
489
|
+
]);
|
|
490
|
+
return f.current = g, w(h - g.left);
|
|
491
|
+
}
|
|
492
|
+
return /* @__PURE__ */ v(he, {
|
|
493
|
+
scope: e.__scopeSlider,
|
|
494
|
+
startEdge: b ? "left" : "right",
|
|
495
|
+
endEdge: b ? "right" : "left",
|
|
496
|
+
direction: b ? 1 : -1,
|
|
497
|
+
size: "width"
|
|
498
|
+
}, /* @__PURE__ */ v(be, y({
|
|
499
|
+
dir: $,
|
|
500
|
+
"data-orientation": "horizontal"
|
|
501
|
+
}, m, {
|
|
502
|
+
ref: S,
|
|
503
|
+
style: {
|
|
504
|
+
...m.style,
|
|
505
|
+
"--radix-slider-thumb-transform": "translateX(-50%)"
|
|
506
|
+
},
|
|
507
|
+
onSlideStart: (h) => {
|
|
508
|
+
const g = _(h.clientX);
|
|
509
|
+
a == null || a(g);
|
|
510
|
+
},
|
|
511
|
+
onSlideMove: (h) => {
|
|
512
|
+
const g = _(h.clientX);
|
|
513
|
+
c == null || c(g);
|
|
514
|
+
},
|
|
515
|
+
onSlideEnd: () => {
|
|
516
|
+
f.current = void 0, l == null || l();
|
|
517
|
+
},
|
|
518
|
+
onStepKeyDown: (h) => {
|
|
519
|
+
const R = me[b ? "from-left" : "from-right"].includes(h.key);
|
|
520
|
+
u == null || u({
|
|
521
|
+
event: h,
|
|
522
|
+
direction: R ? -1 : 1
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
})));
|
|
526
|
+
}), Ge = /* @__PURE__ */ P((e, t) => {
|
|
527
|
+
const { min: n, max: r, inverted: i, onSlideStart: o, onSlideMove: a, onSlideEnd: c, onStepKeyDown: l, ...u } = e, m = E(null), s = M(t, m), d = E(), S = !i;
|
|
528
|
+
function f($) {
|
|
529
|
+
const p = d.current || m.current.getBoundingClientRect(), b = [
|
|
530
|
+
0,
|
|
531
|
+
p.height
|
|
532
|
+
], h = Q(b, S ? [
|
|
533
|
+
r,
|
|
534
|
+
n
|
|
535
|
+
] : [
|
|
536
|
+
n,
|
|
537
|
+
r
|
|
538
|
+
]);
|
|
539
|
+
return d.current = p, h($ - p.top);
|
|
540
|
+
}
|
|
541
|
+
return /* @__PURE__ */ v(he, {
|
|
542
|
+
scope: e.__scopeSlider,
|
|
543
|
+
startEdge: S ? "bottom" : "top",
|
|
544
|
+
endEdge: S ? "top" : "bottom",
|
|
545
|
+
size: "height",
|
|
546
|
+
direction: S ? 1 : -1
|
|
547
|
+
}, /* @__PURE__ */ v(be, y({
|
|
548
|
+
"data-orientation": "vertical"
|
|
549
|
+
}, u, {
|
|
550
|
+
ref: s,
|
|
551
|
+
style: {
|
|
552
|
+
...u.style,
|
|
553
|
+
"--radix-slider-thumb-transform": "translateY(50%)"
|
|
554
|
+
},
|
|
555
|
+
onSlideStart: ($) => {
|
|
556
|
+
const p = f($.clientY);
|
|
557
|
+
o == null || o(p);
|
|
558
|
+
},
|
|
559
|
+
onSlideMove: ($) => {
|
|
560
|
+
const p = f($.clientY);
|
|
561
|
+
a == null || a(p);
|
|
562
|
+
},
|
|
563
|
+
onSlideEnd: () => {
|
|
564
|
+
d.current = void 0, c == null || c();
|
|
565
|
+
},
|
|
566
|
+
onStepKeyDown: ($) => {
|
|
567
|
+
const b = me[S ? "from-bottom" : "from-top"].includes($.key);
|
|
568
|
+
l == null || l({
|
|
569
|
+
event: $,
|
|
570
|
+
direction: b ? -1 : 1
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
})));
|
|
574
|
+
}), be = /* @__PURE__ */ P((e, t) => {
|
|
575
|
+
const { __scopeSlider: n, onSlideStart: r, onSlideMove: i, onSlideEnd: o, onHomeKeyDown: a, onEndKeyDown: c, onStepKeyDown: l, ...u } = e, m = W(z, n);
|
|
576
|
+
return /* @__PURE__ */ v(Y.span, y({}, u, {
|
|
577
|
+
ref: t,
|
|
578
|
+
onKeyDown: K(e.onKeyDown, (s) => {
|
|
579
|
+
s.key === "Home" ? (a(s), s.preventDefault()) : s.key === "End" ? (c(s), s.preventDefault()) : pe.concat($e).includes(s.key) && (l(s), s.preventDefault());
|
|
580
|
+
}),
|
|
581
|
+
onPointerDown: K(e.onPointerDown, (s) => {
|
|
582
|
+
const d = s.target;
|
|
583
|
+
d.setPointerCapture(s.pointerId), s.preventDefault(), m.thumbs.has(d) ? d.focus() : r(s);
|
|
584
|
+
}),
|
|
585
|
+
onPointerMove: K(e.onPointerMove, (s) => {
|
|
586
|
+
s.target.hasPointerCapture(s.pointerId) && i(s);
|
|
587
|
+
}),
|
|
588
|
+
onPointerUp: K(e.onPointerUp, (s) => {
|
|
589
|
+
const d = s.target;
|
|
590
|
+
d.hasPointerCapture(s.pointerId) && (d.releasePointerCapture(s.pointerId), o(s));
|
|
591
|
+
})
|
|
592
|
+
}));
|
|
593
|
+
}), qe = "SliderTrack", Ze = /* @__PURE__ */ P((e, t) => {
|
|
594
|
+
const { __scopeSlider: n, ...r } = e, i = W(qe, n);
|
|
595
|
+
return /* @__PURE__ */ v(Y.span, y({
|
|
596
|
+
"data-disabled": i.disabled ? "" : void 0,
|
|
597
|
+
"data-orientation": i.orientation
|
|
598
|
+
}, r, {
|
|
599
|
+
ref: t
|
|
600
|
+
}));
|
|
601
|
+
}), re = "SliderRange", Je = /* @__PURE__ */ P((e, t) => {
|
|
602
|
+
const { __scopeSlider: n, ...r } = e, i = W(re, n), o = ve(re, n), a = E(null), c = M(t, a), l = i.values.length, u = i.values.map(
|
|
603
|
+
(d) => xe(d, i.min, i.max)
|
|
604
|
+
), m = l > 1 ? Math.min(...u) : 0, s = 100 - Math.max(...u);
|
|
605
|
+
return /* @__PURE__ */ v(Y.span, y({
|
|
606
|
+
"data-orientation": i.orientation,
|
|
607
|
+
"data-disabled": i.disabled ? "" : void 0
|
|
608
|
+
}, r, {
|
|
609
|
+
ref: c,
|
|
610
|
+
style: {
|
|
611
|
+
...e.style,
|
|
612
|
+
[o.startEdge]: m + "%",
|
|
613
|
+
[o.endEdge]: s + "%"
|
|
614
|
+
}
|
|
615
|
+
}));
|
|
616
|
+
}), ie = "SliderThumb", Qe = /* @__PURE__ */ P((e, t) => {
|
|
617
|
+
const n = Fe(e.__scopeSlider), [r, i] = N(null), o = M(
|
|
618
|
+
t,
|
|
619
|
+
(c) => i(c)
|
|
620
|
+
), a = O(
|
|
621
|
+
() => r ? n().findIndex(
|
|
622
|
+
(c) => c.ref.current === r
|
|
623
|
+
) : -1,
|
|
624
|
+
[
|
|
625
|
+
n,
|
|
626
|
+
r
|
|
627
|
+
]
|
|
628
|
+
);
|
|
629
|
+
return /* @__PURE__ */ v(et, y({}, e, {
|
|
630
|
+
ref: o,
|
|
631
|
+
index: a
|
|
632
|
+
}));
|
|
633
|
+
}), et = /* @__PURE__ */ P((e, t) => {
|
|
634
|
+
const { __scopeSlider: n, index: r, ...i } = e, o = W(ie, n), a = ve(ie, n), [c, l] = N(null), u = M(
|
|
635
|
+
t,
|
|
636
|
+
(p) => l(p)
|
|
637
|
+
), m = Be(c), s = o.values[r], d = s === void 0 ? 0 : xe(s, o.min, o.max), S = ot(r, o.values.length), f = m == null ? void 0 : m[a.size], $ = f ? it(f, d, a.direction) : 0;
|
|
638
|
+
return k(() => {
|
|
639
|
+
if (c)
|
|
640
|
+
return o.thumbs.add(c), () => {
|
|
641
|
+
o.thumbs.delete(c);
|
|
642
|
+
};
|
|
643
|
+
}, [
|
|
644
|
+
c,
|
|
645
|
+
o.thumbs
|
|
646
|
+
]), /* @__PURE__ */ v("span", {
|
|
647
|
+
style: {
|
|
648
|
+
transform: "var(--radix-slider-thumb-transform)",
|
|
649
|
+
position: "absolute",
|
|
650
|
+
[a.startEdge]: `calc(${d}% + ${$}px)`
|
|
651
|
+
}
|
|
652
|
+
}, /* @__PURE__ */ v(J.ItemSlot, {
|
|
653
|
+
scope: e.__scopeSlider
|
|
654
|
+
}, /* @__PURE__ */ v(Y.span, y({
|
|
655
|
+
role: "slider",
|
|
656
|
+
"aria-label": e["aria-label"] || S,
|
|
657
|
+
"aria-valuemin": o.min,
|
|
658
|
+
"aria-valuenow": s,
|
|
659
|
+
"aria-valuemax": o.max,
|
|
660
|
+
"aria-orientation": o.orientation,
|
|
661
|
+
"data-orientation": o.orientation,
|
|
662
|
+
"data-disabled": o.disabled ? "" : void 0,
|
|
663
|
+
tabIndex: o.disabled ? void 0 : 0
|
|
664
|
+
}, i, {
|
|
665
|
+
ref: u,
|
|
666
|
+
style: s === void 0 ? {
|
|
667
|
+
display: "none"
|
|
668
|
+
} : e.style,
|
|
669
|
+
onFocus: K(e.onFocus, () => {
|
|
670
|
+
o.valueIndexToChangeRef.current = r;
|
|
671
|
+
})
|
|
672
|
+
}))));
|
|
673
|
+
}), tt = (e) => {
|
|
674
|
+
const { value: t, ...n } = e, r = E(null), i = Te(t);
|
|
675
|
+
return k(() => {
|
|
676
|
+
const o = r.current, a = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(a, "value").set;
|
|
677
|
+
if (i !== t && l) {
|
|
678
|
+
const u = new Event("input", {
|
|
679
|
+
bubbles: !0
|
|
680
|
+
});
|
|
681
|
+
l.call(o, t), o.dispatchEvent(u);
|
|
682
|
+
}
|
|
683
|
+
}, [
|
|
684
|
+
i,
|
|
685
|
+
t
|
|
686
|
+
]), /* @__PURE__ */ v("input", y({
|
|
687
|
+
style: {
|
|
688
|
+
display: "none"
|
|
689
|
+
}
|
|
690
|
+
}, n, {
|
|
691
|
+
ref: r,
|
|
692
|
+
defaultValue: t
|
|
693
|
+
}));
|
|
694
|
+
};
|
|
695
|
+
function nt(e = [], t, n) {
|
|
696
|
+
const r = [
|
|
697
|
+
...e
|
|
698
|
+
];
|
|
699
|
+
return r[n] = t, r.sort(
|
|
700
|
+
(i, o) => i - o
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
function xe(e, t, n) {
|
|
704
|
+
const o = 100 / (n - t) * (e - t);
|
|
705
|
+
return le(o, [
|
|
706
|
+
0,
|
|
707
|
+
100
|
|
708
|
+
]);
|
|
709
|
+
}
|
|
710
|
+
function ot(e, t) {
|
|
711
|
+
return t > 2 ? `Value ${e + 1} of ${t}` : t === 2 ? [
|
|
712
|
+
"Minimum",
|
|
713
|
+
"Maximum"
|
|
714
|
+
][e] : void 0;
|
|
715
|
+
}
|
|
716
|
+
function rt(e, t) {
|
|
717
|
+
if (e.length === 1)
|
|
718
|
+
return 0;
|
|
719
|
+
const n = e.map(
|
|
720
|
+
(i) => Math.abs(i - t)
|
|
721
|
+
), r = Math.min(...n);
|
|
722
|
+
return n.indexOf(r);
|
|
723
|
+
}
|
|
724
|
+
function it(e, t, n) {
|
|
725
|
+
const r = e / 2, o = Q([
|
|
726
|
+
0,
|
|
727
|
+
50
|
|
728
|
+
], [
|
|
729
|
+
0,
|
|
730
|
+
r
|
|
731
|
+
]);
|
|
732
|
+
return (r - o(t) * n) * n;
|
|
733
|
+
}
|
|
734
|
+
function ct(e) {
|
|
735
|
+
return e.slice(0, -1).map(
|
|
736
|
+
(t, n) => e[n + 1] - t
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
function at(e, t) {
|
|
740
|
+
if (t > 0) {
|
|
741
|
+
const n = ct(e);
|
|
742
|
+
return Math.min(...n) >= t;
|
|
743
|
+
}
|
|
744
|
+
return !0;
|
|
745
|
+
}
|
|
746
|
+
function Q(e, t) {
|
|
747
|
+
return (n) => {
|
|
748
|
+
if (e[0] === e[1] || t[0] === t[1])
|
|
749
|
+
return t[0];
|
|
750
|
+
const r = (t[1] - t[0]) / (e[1] - e[0]);
|
|
751
|
+
return t[0] + r * (n - e[0]);
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function st(e) {
|
|
755
|
+
return (String(e).split(".")[1] || "").length;
|
|
756
|
+
}
|
|
757
|
+
function lt(e, t) {
|
|
758
|
+
const n = Math.pow(10, t);
|
|
759
|
+
return Math.round(e * n) / n;
|
|
760
|
+
}
|
|
761
|
+
const ut = We, dt = Ze, ft = Je, pt = Qe;
|
|
762
|
+
function $t(e) {
|
|
763
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
764
|
+
}
|
|
765
|
+
var ge = { exports: {} };
|
|
766
|
+
/*!
|
|
767
|
+
Copyright (c) 2018 Jed Watson.
|
|
768
|
+
Licensed under the MIT License (MIT), see
|
|
769
|
+
http://jedwatson.github.io/classnames
|
|
770
|
+
*/
|
|
771
|
+
(function(e) {
|
|
772
|
+
(function() {
|
|
773
|
+
var t = {}.hasOwnProperty;
|
|
774
|
+
function n() {
|
|
775
|
+
for (var o = "", a = 0; a < arguments.length; a++) {
|
|
776
|
+
var c = arguments[a];
|
|
777
|
+
c && (o = i(o, r.call(this, c)));
|
|
778
|
+
}
|
|
779
|
+
return o;
|
|
780
|
+
}
|
|
781
|
+
function r(o) {
|
|
782
|
+
if (typeof o == "string" || typeof o == "number")
|
|
783
|
+
return this && this[o] || o;
|
|
784
|
+
if (typeof o != "object")
|
|
785
|
+
return "";
|
|
786
|
+
if (Array.isArray(o))
|
|
787
|
+
return n.apply(this, o);
|
|
788
|
+
if (o.toString !== Object.prototype.toString && !o.toString.toString().includes("[native code]"))
|
|
789
|
+
return o.toString();
|
|
790
|
+
var a = "";
|
|
791
|
+
for (var c in o)
|
|
792
|
+
t.call(o, c) && o[c] && (a = i(a, this && this[c] || c));
|
|
793
|
+
return a;
|
|
794
|
+
}
|
|
795
|
+
function i(o, a) {
|
|
796
|
+
return a ? o ? o + " " + a : o + a : o;
|
|
797
|
+
}
|
|
798
|
+
e.exports ? (n.default = n, e.exports = n) : window.classNames = n;
|
|
799
|
+
})();
|
|
800
|
+
})(ge);
|
|
801
|
+
var mt = ge.exports;
|
|
802
|
+
const St = /* @__PURE__ */ $t(mt), ht = {
|
|
803
|
+
"purpur-slider": "_purpur-slider_14tuk_1",
|
|
804
|
+
"purpur-slider__track": "_purpur-slider__track_14tuk_17",
|
|
805
|
+
"purpur-slider__range": "_purpur-slider__range_14tuk_17",
|
|
806
|
+
"purpur-slider__thumb": "_purpur-slider__thumb_14tuk_43"
|
|
807
|
+
}, H = St.bind(ht), j = "purpur-slider", vt = (e) => String(e), bt = ({ "aria-label": e, className: t, defaultValue: n, id: r, value: i, ...o }, a) => {
|
|
808
|
+
const c = Me(), l = i || n;
|
|
809
|
+
return /* @__PURE__ */ Pe(
|
|
810
|
+
ut,
|
|
811
|
+
{
|
|
812
|
+
...o,
|
|
813
|
+
id: r || c,
|
|
814
|
+
ref: a,
|
|
815
|
+
className: H(j, t),
|
|
816
|
+
value: i,
|
|
817
|
+
defaultValue: n,
|
|
818
|
+
children: [
|
|
819
|
+
/* @__PURE__ */ G(dt, { className: H(`${j}__track`), children: /* @__PURE__ */ G(ft, { className: H(`${j}__range`) }) }),
|
|
820
|
+
l == null ? void 0 : l.map((u, m) => /* @__PURE__ */ G(
|
|
821
|
+
pt,
|
|
822
|
+
{
|
|
823
|
+
className: H(`${j}__thumb`),
|
|
824
|
+
"aria-label": e
|
|
825
|
+
},
|
|
826
|
+
vt(m)
|
|
827
|
+
))
|
|
828
|
+
]
|
|
829
|
+
}
|
|
830
|
+
);
|
|
831
|
+
}, xt = P(bt);
|
|
832
|
+
xt.displayName = "Slider";
|
|
833
|
+
export {
|
|
834
|
+
xt as Slider
|
|
835
|
+
};
|
|
836
|
+
//# sourceMappingURL=slider.es.js.map
|