@purpurds/slider 5.10.1 → 5.11.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/slider.cjs.js +2 -2
- package/dist/slider.cjs.js.map +1 -1
- package/dist/slider.d.ts +6 -1
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.es.js +46 -55
- package/dist/slider.es.js.map +1 -1
- package/package.json +13 -12
- package/src/slider.stories.tsx +37 -59
- package/src/slider.tsx +6 -2
package/dist/slider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../src/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAO/D,KAAK,WAAW,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../src/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAO/D,KAAK,WAAW,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,eAAO,MAAM,WAAW,qCAAsC,CAAC;AAE/D,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI;IAC/C,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC;IAEzB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEvB,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;MAGE;IACF,YAAY,CAAC,EAAE,CAAC,CAAC;IAEjB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,WAAW,CAAC,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;IAE3C,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV,aAAa,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAChC,CAAC;AA6CF,eAAO,MAAM,MAAM,oGAA8B,CAAC"}
|
package/dist/slider.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as Pe, jsx as G } from "react/jsx-runtime";
|
|
2
|
-
import D, { useCallback as ce, createContext as q, useMemo as
|
|
2
|
+
import D, { useCallback as ce, createContext as q, useMemo as N, createElement as v, useContext as ae, useRef as E, useEffect as k, useState as T, useLayoutEffect as Ee, forwardRef as P, Children as B, isValidElement as F, cloneElement as se, Fragment as De, useId as Me } from "react";
|
|
3
3
|
import "react-dom";
|
|
4
4
|
function y() {
|
|
5
5
|
return y = Object.assign ? Object.assign.bind() : function(e) {
|
|
@@ -14,10 +14,9 @@ function y() {
|
|
|
14
14
|
function le(e, [t, n]) {
|
|
15
15
|
return Math.min(n, Math.max(t, e));
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function O(e, t, { checkForDefaultPrevented: n = !0 } = {}) {
|
|
18
18
|
return function(i) {
|
|
19
|
-
if (e == null || e(i), n === !1 || !i.defaultPrevented)
|
|
20
|
-
return t == null ? void 0 : t(i);
|
|
19
|
+
if (e == null || e(i), n === !1 || !i.defaultPrevented) return t == null ? void 0 : t(i);
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
22
|
function Re(e, t) {
|
|
@@ -40,7 +39,7 @@ function de(e, t = []) {
|
|
|
40
39
|
a
|
|
41
40
|
];
|
|
42
41
|
function u(s) {
|
|
43
|
-
const { scope: d, children: S, ...f } = s, $ = (d == null ? void 0 : d[e][l]) || c, p =
|
|
42
|
+
const { scope: d, children: S, ...f } = s, $ = (d == null ? void 0 : d[e][l]) || c, p = N(
|
|
44
43
|
() => f,
|
|
45
44
|
Object.values(f)
|
|
46
45
|
);
|
|
@@ -50,10 +49,8 @@ function de(e, t = []) {
|
|
|
50
49
|
}
|
|
51
50
|
function m(s, d) {
|
|
52
51
|
const S = (d == null ? void 0 : d[e][l]) || c, f = ae(S);
|
|
53
|
-
if (f)
|
|
54
|
-
|
|
55
|
-
if (a !== void 0)
|
|
56
|
-
return a;
|
|
52
|
+
if (f) return f;
|
|
53
|
+
if (a !== void 0) return a;
|
|
57
54
|
throw new Error(`\`${s}\` must be used within \`${o}\``);
|
|
58
55
|
}
|
|
59
56
|
return u.displayName = o + "Provider", [
|
|
@@ -65,7 +62,7 @@ function de(e, t = []) {
|
|
|
65
62
|
const o = n.map((a) => /* @__PURE__ */ q(a));
|
|
66
63
|
return function(c) {
|
|
67
64
|
const l = (c == null ? void 0 : c[e]) || o;
|
|
68
|
-
return
|
|
65
|
+
return N(
|
|
69
66
|
() => ({
|
|
70
67
|
[`__scope${e}`]: {
|
|
71
68
|
...c,
|
|
@@ -86,8 +83,7 @@ function de(e, t = []) {
|
|
|
86
83
|
}
|
|
87
84
|
function Ae(...e) {
|
|
88
85
|
const t = e[0];
|
|
89
|
-
if (e.length === 1)
|
|
90
|
-
return t;
|
|
86
|
+
if (e.length === 1) return t;
|
|
91
87
|
const n = () => {
|
|
92
88
|
const r = e.map(
|
|
93
89
|
(i) => ({
|
|
@@ -103,7 +99,7 @@ function Ae(...e) {
|
|
|
103
99
|
...s
|
|
104
100
|
};
|
|
105
101
|
}, {});
|
|
106
|
-
return
|
|
102
|
+
return N(
|
|
107
103
|
() => ({
|
|
108
104
|
[`__scope${t.scopeName}`]: a
|
|
109
105
|
}),
|
|
@@ -119,7 +115,7 @@ function fe(e) {
|
|
|
119
115
|
const t = E(e);
|
|
120
116
|
return k(() => {
|
|
121
117
|
t.current = e;
|
|
122
|
-
}),
|
|
118
|
+
}), N(
|
|
123
119
|
() => (...n) => {
|
|
124
120
|
var r;
|
|
125
121
|
return (r = t.current) === null || r === void 0 ? void 0 : r.call(t, ...n);
|
|
@@ -129,15 +125,14 @@ function fe(e) {
|
|
|
129
125
|
}
|
|
130
126
|
function Ie({ prop: e, defaultProp: t, onChange: n = () => {
|
|
131
127
|
} }) {
|
|
132
|
-
const [r, i] =
|
|
128
|
+
const [r, i] = Oe({
|
|
133
129
|
defaultProp: t,
|
|
134
130
|
onChange: n
|
|
135
131
|
}), o = e !== void 0, a = o ? e : r, c = fe(n), l = ce((u) => {
|
|
136
132
|
if (o) {
|
|
137
133
|
const s = typeof u == "function" ? u(e) : u;
|
|
138
134
|
s !== e && c(s);
|
|
139
|
-
} else
|
|
140
|
-
i(u);
|
|
135
|
+
} else i(u);
|
|
141
136
|
}, [
|
|
142
137
|
o,
|
|
143
138
|
e,
|
|
@@ -149,8 +144,8 @@ function Ie({ prop: e, defaultProp: t, onChange: n = () => {
|
|
|
149
144
|
l
|
|
150
145
|
];
|
|
151
146
|
}
|
|
152
|
-
function
|
|
153
|
-
const n =
|
|
147
|
+
function Oe({ defaultProp: e, onChange: t }) {
|
|
148
|
+
const n = T(e), [r] = n, i = E(r), o = fe(t);
|
|
154
149
|
return k(() => {
|
|
155
150
|
i.current !== r && (o(r), i.current = r);
|
|
156
151
|
}, [
|
|
@@ -159,24 +154,24 @@ function Ke({ defaultProp: e, onChange: t }) {
|
|
|
159
154
|
o
|
|
160
155
|
]), n;
|
|
161
156
|
}
|
|
162
|
-
const
|
|
163
|
-
function
|
|
164
|
-
const t = ae(
|
|
157
|
+
const Ne = /* @__PURE__ */ q(void 0);
|
|
158
|
+
function Te(e) {
|
|
159
|
+
const t = ae(Ne);
|
|
165
160
|
return e || t || "ltr";
|
|
166
161
|
}
|
|
167
|
-
function
|
|
162
|
+
function Ke(e) {
|
|
168
163
|
const t = E({
|
|
169
164
|
value: e,
|
|
170
165
|
previous: e
|
|
171
166
|
});
|
|
172
|
-
return
|
|
167
|
+
return N(() => (t.current.value !== e && (t.current.previous = t.current.value, t.current.value = e), t.current.previous), [
|
|
173
168
|
e
|
|
174
169
|
]);
|
|
175
170
|
}
|
|
176
171
|
const Ve = globalThis != null && globalThis.document ? Ee : () => {
|
|
177
172
|
};
|
|
178
173
|
function Be(e) {
|
|
179
|
-
const [t, n] =
|
|
174
|
+
const [t, n] = T(void 0);
|
|
180
175
|
return Ve(() => {
|
|
181
176
|
if (e) {
|
|
182
177
|
n({
|
|
@@ -184,8 +179,7 @@ function Be(e) {
|
|
|
184
179
|
height: e.offsetHeight
|
|
185
180
|
});
|
|
186
181
|
const r = new ResizeObserver((i) => {
|
|
187
|
-
if (!Array.isArray(i) || !i.length)
|
|
188
|
-
return;
|
|
182
|
+
if (!Array.isArray(i) || !i.length) return;
|
|
189
183
|
const o = i[0];
|
|
190
184
|
let a, c;
|
|
191
185
|
if ("borderBoxSize" in o) {
|
|
@@ -316,8 +310,7 @@ function je(e) {
|
|
|
316
310
|
const f = o(e + "CollectionConsumer", S);
|
|
317
311
|
return D.useCallback(() => {
|
|
318
312
|
const p = f.collectionRef.current;
|
|
319
|
-
if (!p)
|
|
320
|
-
return [];
|
|
313
|
+
if (!p) return [];
|
|
321
314
|
const b = Array.from(p.querySelectorAll(`[${m}]`));
|
|
322
315
|
return Array.from(f.itemMap.values()).sort(
|
|
323
316
|
(g, R) => b.indexOf(g.ref.current) - b.indexOf(R.ref.current)
|
|
@@ -377,7 +370,7 @@ const pe = [
|
|
|
377
370
|
r
|
|
378
371
|
], value: m, onValueChange: s = () => {
|
|
379
372
|
}, onValueCommit: d = () => {
|
|
380
|
-
}, inverted: S = !1, ...f } = e, [$, p] =
|
|
373
|
+
}, inverted: S = !1, ...f } = e, [$, p] = T(null), b = M(
|
|
381
374
|
t,
|
|
382
375
|
(x) => p(x)
|
|
383
376
|
), _ = E(/* @__PURE__ */ new Set()), h = E(0), g = a === "horizontal", R = $ ? !!$.closest("form") : !0, ee = g ? Xe : Ge, [w = [], _e] = Ie({
|
|
@@ -392,16 +385,16 @@ const pe = [
|
|
|
392
385
|
}), te = E(w);
|
|
393
386
|
function ye(x) {
|
|
394
387
|
const C = rt(w, x);
|
|
395
|
-
|
|
388
|
+
K(x, C);
|
|
396
389
|
}
|
|
397
390
|
function we(x) {
|
|
398
|
-
|
|
391
|
+
K(x, h.current);
|
|
399
392
|
}
|
|
400
393
|
function Ce() {
|
|
401
394
|
const x = te.current[h.current];
|
|
402
395
|
w[h.current] !== x && d(w);
|
|
403
396
|
}
|
|
404
|
-
function
|
|
397
|
+
function K(x, C, { commit: L } = {
|
|
405
398
|
commit: !1
|
|
406
399
|
}) {
|
|
407
400
|
const ne = st(o), X = lt(Math.round((x - r) / o) * o + r, ne), V = le(X, [
|
|
@@ -414,8 +407,7 @@ const pe = [
|
|
|
414
407
|
h.current = A.indexOf(V);
|
|
415
408
|
const oe = String(A) !== String(I);
|
|
416
409
|
return oe && L && d(A), oe ? A : I;
|
|
417
|
-
} else
|
|
418
|
-
return I;
|
|
410
|
+
} else return I;
|
|
419
411
|
});
|
|
420
412
|
}
|
|
421
413
|
return /* @__PURE__ */ v(Ye, {
|
|
@@ -436,7 +428,7 @@ const pe = [
|
|
|
436
428
|
"data-disabled": c ? "" : void 0
|
|
437
429
|
}, f, {
|
|
438
430
|
ref: b,
|
|
439
|
-
onPointerDown:
|
|
431
|
+
onPointerDown: O(f.onPointerDown, () => {
|
|
440
432
|
c || (te.current = w);
|
|
441
433
|
}),
|
|
442
434
|
min: r,
|
|
@@ -445,16 +437,16 @@ const pe = [
|
|
|
445
437
|
onSlideStart: c ? void 0 : ye,
|
|
446
438
|
onSlideMove: c ? void 0 : we,
|
|
447
439
|
onSlideEnd: c ? void 0 : Ce,
|
|
448
|
-
onHomeKeyDown: () => !c &&
|
|
440
|
+
onHomeKeyDown: () => !c && K(r, 0, {
|
|
449
441
|
commit: !0
|
|
450
442
|
}),
|
|
451
|
-
onEndKeyDown: () => !c &&
|
|
443
|
+
onEndKeyDown: () => !c && K(i, w.length - 1, {
|
|
452
444
|
commit: !0
|
|
453
445
|
}),
|
|
454
446
|
onStepKeyDown: ({ event: x, direction: C }) => {
|
|
455
447
|
if (!c) {
|
|
456
448
|
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
|
-
|
|
449
|
+
K(I + A, V, {
|
|
458
450
|
commit: !0
|
|
459
451
|
});
|
|
460
452
|
}
|
|
@@ -472,10 +464,10 @@ const pe = [
|
|
|
472
464
|
size: "width",
|
|
473
465
|
direction: 1
|
|
474
466
|
}), 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] =
|
|
467
|
+
const { min: n, max: r, dir: i, inverted: o, onSlideStart: a, onSlideMove: c, onSlideEnd: l, onStepKeyDown: u, ...m } = e, [s, d] = T(null), S = M(
|
|
476
468
|
t,
|
|
477
469
|
(h) => d(h)
|
|
478
|
-
), f = E(), $ =
|
|
470
|
+
), f = E(), $ = Te(i), p = $ === "ltr", b = p && !o || !p && o;
|
|
479
471
|
function _(h) {
|
|
480
472
|
const g = f.current || s.getBoundingClientRect(), R = [
|
|
481
473
|
0,
|
|
@@ -575,17 +567,17 @@ const pe = [
|
|
|
575
567
|
const { __scopeSlider: n, onSlideStart: r, onSlideMove: i, onSlideEnd: o, onHomeKeyDown: a, onEndKeyDown: c, onStepKeyDown: l, ...u } = e, m = W(z, n);
|
|
576
568
|
return /* @__PURE__ */ v(Y.span, y({}, u, {
|
|
577
569
|
ref: t,
|
|
578
|
-
onKeyDown:
|
|
570
|
+
onKeyDown: O(e.onKeyDown, (s) => {
|
|
579
571
|
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
572
|
}),
|
|
581
|
-
onPointerDown:
|
|
573
|
+
onPointerDown: O(e.onPointerDown, (s) => {
|
|
582
574
|
const d = s.target;
|
|
583
575
|
d.setPointerCapture(s.pointerId), s.preventDefault(), m.thumbs.has(d) ? d.focus() : r(s);
|
|
584
576
|
}),
|
|
585
|
-
onPointerMove:
|
|
577
|
+
onPointerMove: O(e.onPointerMove, (s) => {
|
|
586
578
|
s.target.hasPointerCapture(s.pointerId) && i(s);
|
|
587
579
|
}),
|
|
588
|
-
onPointerUp:
|
|
580
|
+
onPointerUp: O(e.onPointerUp, (s) => {
|
|
589
581
|
const d = s.target;
|
|
590
582
|
d.hasPointerCapture(s.pointerId) && (d.releasePointerCapture(s.pointerId), o(s));
|
|
591
583
|
})
|
|
@@ -614,10 +606,10 @@ const pe = [
|
|
|
614
606
|
}
|
|
615
607
|
}));
|
|
616
608
|
}), ie = "SliderThumb", Qe = /* @__PURE__ */ P((e, t) => {
|
|
617
|
-
const n = Fe(e.__scopeSlider), [r, i] =
|
|
609
|
+
const n = Fe(e.__scopeSlider), [r, i] = T(null), o = M(
|
|
618
610
|
t,
|
|
619
611
|
(c) => i(c)
|
|
620
|
-
), a =
|
|
612
|
+
), a = N(
|
|
621
613
|
() => r ? n().findIndex(
|
|
622
614
|
(c) => c.ref.current === r
|
|
623
615
|
) : -1,
|
|
@@ -631,7 +623,7 @@ const pe = [
|
|
|
631
623
|
index: a
|
|
632
624
|
}));
|
|
633
625
|
}), et = /* @__PURE__ */ P((e, t) => {
|
|
634
|
-
const { __scopeSlider: n, index: r, ...i } = e, o = W(ie, n), a = ve(ie, n), [c, l] =
|
|
626
|
+
const { __scopeSlider: n, index: r, ...i } = e, o = W(ie, n), a = ve(ie, n), [c, l] = T(null), u = M(
|
|
635
627
|
t,
|
|
636
628
|
(p) => l(p)
|
|
637
629
|
), 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;
|
|
@@ -666,12 +658,12 @@ const pe = [
|
|
|
666
658
|
style: s === void 0 ? {
|
|
667
659
|
display: "none"
|
|
668
660
|
} : e.style,
|
|
669
|
-
onFocus:
|
|
661
|
+
onFocus: O(e.onFocus, () => {
|
|
670
662
|
o.valueIndexToChangeRef.current = r;
|
|
671
663
|
})
|
|
672
664
|
}))));
|
|
673
665
|
}), tt = (e) => {
|
|
674
|
-
const { value: t, ...n } = e, r = E(null), i =
|
|
666
|
+
const { value: t, ...n } = e, r = E(null), i = Ke(t);
|
|
675
667
|
return k(() => {
|
|
676
668
|
const o = r.current, a = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(a, "value").set;
|
|
677
669
|
if (i !== t && l) {
|
|
@@ -714,8 +706,7 @@ function ot(e, t) {
|
|
|
714
706
|
][e] : void 0;
|
|
715
707
|
}
|
|
716
708
|
function rt(e, t) {
|
|
717
|
-
if (e.length === 1)
|
|
718
|
-
return 0;
|
|
709
|
+
if (e.length === 1) return 0;
|
|
719
710
|
const n = e.map(
|
|
720
711
|
(i) => Math.abs(i - t)
|
|
721
712
|
), r = Math.min(...n);
|
|
@@ -745,8 +736,7 @@ function at(e, t) {
|
|
|
745
736
|
}
|
|
746
737
|
function Q(e, t) {
|
|
747
738
|
return (n) => {
|
|
748
|
-
if (e[0] === e[1] || t[0] === t[1])
|
|
749
|
-
return t[0];
|
|
739
|
+
if (e[0] === e[1] || t[0] === t[1]) return t[0];
|
|
750
740
|
const r = (t[1] - t[0]) / (e[1] - e[0]);
|
|
751
741
|
return t[0] + r * (n - e[0]);
|
|
752
742
|
};
|
|
@@ -804,7 +794,7 @@ const St = /* @__PURE__ */ $t(mt), ht = {
|
|
|
804
794
|
"purpur-slider__track": "_purpur-slider__track_14tuk_17",
|
|
805
795
|
"purpur-slider__range": "_purpur-slider__range_14tuk_17",
|
|
806
796
|
"purpur-slider__thumb": "_purpur-slider__thumb_14tuk_43"
|
|
807
|
-
}, H = St.bind(ht), j = "purpur-slider", vt = (e) => String(e), bt = ({
|
|
797
|
+
}, H = St.bind(ht), Ct = ["horizontal", "vertical"], j = "purpur-slider", vt = (e) => String(e), bt = ({
|
|
808
798
|
"aria-label": e,
|
|
809
799
|
"aria-valuetext": t,
|
|
810
800
|
className: n,
|
|
@@ -840,6 +830,7 @@ const St = /* @__PURE__ */ $t(mt), ht = {
|
|
|
840
830
|
}, xt = P(bt);
|
|
841
831
|
xt.displayName = "Slider";
|
|
842
832
|
export {
|
|
833
|
+
Ct as ORIENTATION,
|
|
843
834
|
xt as Slider
|
|
844
835
|
};
|
|
845
836
|
//# sourceMappingURL=slider.es.js.map
|