@purpurds/toggle 5.7.0 → 5.8.0
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 +3 -3
- package/dist/toggle.cjs.js +3 -3
- package/dist/toggle.cjs.js.map +1 -1
- package/dist/toggle.es.js +43 -43
- package/dist/toggle.es.js.map +1 -1
- package/package.json +5 -5
package/dist/toggle.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as x, jsxs as J } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as w, Children as y, isValidElement as
|
|
2
|
+
import { forwardRef as w, Children as y, isValidElement as O, createElement as _, cloneElement as X, useEffect as A, Fragment as ee, useCallback as B, createContext as K, useMemo as R, useContext as fe, useRef as C, useState as $, useLayoutEffect as re } from "react";
|
|
3
3
|
import "react-dom";
|
|
4
4
|
function ge(e) {
|
|
5
5
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
@@ -108,7 +108,7 @@ function M() {
|
|
|
108
108
|
function Pe(e, n) {
|
|
109
109
|
typeof e == "function" ? e(n) : e != null && (e.current = n);
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function Oe(...e) {
|
|
112
112
|
return (n) => e.forEach(
|
|
113
113
|
(t) => Pe(t, n)
|
|
114
114
|
);
|
|
@@ -116,29 +116,29 @@ function ke(...e) {
|
|
|
116
116
|
const ne = /* @__PURE__ */ w((e, n) => {
|
|
117
117
|
const { children: t, ...o } = e, c = y.toArray(t), r = c.find(Ae);
|
|
118
118
|
if (r) {
|
|
119
|
-
const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */
|
|
120
|
-
return /* @__PURE__ */ _(
|
|
119
|
+
const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ O(a) ? a.props.children : null : i);
|
|
120
|
+
return /* @__PURE__ */ _(W, M({}, o, {
|
|
121
121
|
ref: n
|
|
122
|
-
}), /* @__PURE__ */
|
|
122
|
+
}), /* @__PURE__ */ O(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
|
|
123
123
|
}
|
|
124
|
-
return /* @__PURE__ */ _(
|
|
124
|
+
return /* @__PURE__ */ _(W, M({}, o, {
|
|
125
125
|
ref: n
|
|
126
126
|
}), t);
|
|
127
127
|
});
|
|
128
128
|
ne.displayName = "Slot";
|
|
129
|
-
const
|
|
129
|
+
const W = /* @__PURE__ */ w((e, n) => {
|
|
130
130
|
const { children: t, ...o } = e;
|
|
131
|
-
return /* @__PURE__ */
|
|
132
|
-
...
|
|
133
|
-
ref: n ?
|
|
131
|
+
return /* @__PURE__ */ O(t) ? /* @__PURE__ */ X(t, {
|
|
132
|
+
...Ce(o, t.props),
|
|
133
|
+
ref: n ? Oe(n, t.ref) : t.ref
|
|
134
134
|
}) : y.count(t) > 1 ? y.only(null) : null;
|
|
135
135
|
});
|
|
136
|
-
|
|
137
|
-
const
|
|
136
|
+
W.displayName = "SlotClone";
|
|
137
|
+
const ke = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
|
|
138
138
|
function Ae(e) {
|
|
139
|
-
return /* @__PURE__ */
|
|
139
|
+
return /* @__PURE__ */ O(e) && e.type === ke;
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function Ce(e, n) {
|
|
142
142
|
const t = {
|
|
143
143
|
...n
|
|
144
144
|
};
|
|
@@ -159,7 +159,7 @@ function De(e, n) {
|
|
|
159
159
|
...t
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
-
const
|
|
162
|
+
const De = [
|
|
163
163
|
"a",
|
|
164
164
|
"button",
|
|
165
165
|
"div",
|
|
@@ -176,7 +176,7 @@ const Ce = [
|
|
|
176
176
|
"span",
|
|
177
177
|
"svg",
|
|
178
178
|
"ul"
|
|
179
|
-
], Ee =
|
|
179
|
+
], Ee = De.reduce((e, n) => {
|
|
180
180
|
const t = /* @__PURE__ */ w((o, c) => {
|
|
181
181
|
const { asChild: r, ...a } = o, u = r ? ne : n;
|
|
182
182
|
return A(() => {
|
|
@@ -374,7 +374,7 @@ function ce(...e) {
|
|
|
374
374
|
function Ve(...e) {
|
|
375
375
|
return B(ce(...e), e);
|
|
376
376
|
}
|
|
377
|
-
function
|
|
377
|
+
function We(e, n = []) {
|
|
378
378
|
let t = [];
|
|
379
379
|
function o(r, a) {
|
|
380
380
|
const u = /* @__PURE__ */ K(a), i = t.length;
|
|
@@ -424,10 +424,10 @@ function Ue(e, n = []) {
|
|
|
424
424
|
};
|
|
425
425
|
return c.scopeName = e, [
|
|
426
426
|
o,
|
|
427
|
-
|
|
427
|
+
Ue(c, ...n)
|
|
428
428
|
];
|
|
429
429
|
}
|
|
430
|
-
function
|
|
430
|
+
function Ue(...e) {
|
|
431
431
|
const n = e[0];
|
|
432
432
|
if (e.length === 1)
|
|
433
433
|
return n;
|
|
@@ -459,7 +459,7 @@ function We(...e) {
|
|
|
459
459
|
return t.scopeName = n.scopeName, t;
|
|
460
460
|
}
|
|
461
461
|
function ue(e) {
|
|
462
|
-
const n =
|
|
462
|
+
const n = C(e);
|
|
463
463
|
return A(() => {
|
|
464
464
|
n.current = e;
|
|
465
465
|
}), R(
|
|
@@ -493,7 +493,7 @@ function Ge({ prop: e, defaultProp: n, onChange: t = () => {
|
|
|
493
493
|
];
|
|
494
494
|
}
|
|
495
495
|
function Ze({ defaultProp: e, onChange: n }) {
|
|
496
|
-
const t = $(e), [o] = t, c =
|
|
496
|
+
const t = $(e), [o] = t, c = C(o), r = ue(n);
|
|
497
497
|
return A(() => {
|
|
498
498
|
c.current !== o && (r(o), c.current = o);
|
|
499
499
|
}, [
|
|
@@ -503,7 +503,7 @@ function Ze({ defaultProp: e, onChange: n }) {
|
|
|
503
503
|
]), t;
|
|
504
504
|
}
|
|
505
505
|
function Je(e) {
|
|
506
|
-
const n =
|
|
506
|
+
const n = C({
|
|
507
507
|
value: e,
|
|
508
508
|
previous: e
|
|
509
509
|
});
|
|
@@ -558,27 +558,27 @@ function L() {
|
|
|
558
558
|
const ie = /* @__PURE__ */ w((e, n) => {
|
|
559
559
|
const { children: t, ...o } = e, c = y.toArray(t), r = c.find(er);
|
|
560
560
|
if (r) {
|
|
561
|
-
const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */
|
|
562
|
-
return /* @__PURE__ */ _(
|
|
561
|
+
const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ O(a) ? a.props.children : null : i);
|
|
562
|
+
return /* @__PURE__ */ _(U, L({}, o, {
|
|
563
563
|
ref: n
|
|
564
|
-
}), /* @__PURE__ */
|
|
564
|
+
}), /* @__PURE__ */ O(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
|
|
565
565
|
}
|
|
566
|
-
return /* @__PURE__ */ _(
|
|
566
|
+
return /* @__PURE__ */ _(U, L({}, o, {
|
|
567
567
|
ref: n
|
|
568
568
|
}), t);
|
|
569
569
|
});
|
|
570
570
|
ie.displayName = "Slot";
|
|
571
|
-
const
|
|
571
|
+
const U = /* @__PURE__ */ w((e, n) => {
|
|
572
572
|
const { children: t, ...o } = e;
|
|
573
|
-
return /* @__PURE__ */
|
|
573
|
+
return /* @__PURE__ */ O(t) ? /* @__PURE__ */ X(t, {
|
|
574
574
|
...rr(o, t.props),
|
|
575
575
|
ref: n ? ce(n, t.ref) : t.ref
|
|
576
576
|
}) : y.count(t) > 1 ? y.only(null) : null;
|
|
577
577
|
});
|
|
578
|
-
|
|
578
|
+
U.displayName = "SlotClone";
|
|
579
579
|
const Ye = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
|
|
580
580
|
function er(e) {
|
|
581
|
-
return /* @__PURE__ */
|
|
581
|
+
return /* @__PURE__ */ O(e) && e.type === Ye;
|
|
582
582
|
}
|
|
583
583
|
function rr(e, n) {
|
|
584
584
|
const t = {
|
|
@@ -631,11 +631,11 @@ const tr = [
|
|
|
631
631
|
...e,
|
|
632
632
|
[n]: t
|
|
633
633
|
};
|
|
634
|
-
}, {}), le = "Switch", [nr, yr] =
|
|
634
|
+
}, {}), le = "Switch", [nr, yr] = We(le), [or, ar] = nr(le), cr = /* @__PURE__ */ w((e, n) => {
|
|
635
635
|
const { __scopeSwitch: t, name: o, checked: c, defaultChecked: r, required: a, disabled: u, value: i = "on", onCheckedChange: s, ...h } = e, [l, p] = $(null), v = Ve(
|
|
636
636
|
n,
|
|
637
637
|
(m) => p(m)
|
|
638
|
-
), f =
|
|
638
|
+
), f = C(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ge({
|
|
639
639
|
prop: c,
|
|
640
640
|
defaultProp: r,
|
|
641
641
|
onChange: s
|
|
@@ -657,7 +657,7 @@ const tr = [
|
|
|
657
657
|
ref: v,
|
|
658
658
|
onClick: qe(e.onClick, (m) => {
|
|
659
659
|
b(
|
|
660
|
-
(
|
|
660
|
+
(k) => !k
|
|
661
661
|
), g && (f.current = m.isPropagationStopped(), f.current || m.stopPropagation());
|
|
662
662
|
})
|
|
663
663
|
})), g && /* @__PURE__ */ _(sr, {
|
|
@@ -681,7 +681,7 @@ const tr = [
|
|
|
681
681
|
ref: n
|
|
682
682
|
}));
|
|
683
683
|
}), sr = (e) => {
|
|
684
|
-
const { control: n, checked: t, bubbles: o = !0, ...c } = e, r =
|
|
684
|
+
const { control: n, checked: t, bubbles: o = !0, ...c } = e, r = C(null), a = Je(t), u = Qe(n);
|
|
685
685
|
return A(() => {
|
|
686
686
|
const i = r.current, s = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(s, "checked").set;
|
|
687
687
|
if (a !== t && l) {
|
|
@@ -785,12 +785,12 @@ const F = /* @__PURE__ */ dr(fr), S = {
|
|
|
785
785
|
(b) => {
|
|
786
786
|
if (typeof h != "number")
|
|
787
787
|
return;
|
|
788
|
-
const
|
|
789
|
-
if (!
|
|
788
|
+
const k = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
|
|
789
|
+
if (!k)
|
|
790
790
|
return;
|
|
791
|
-
const
|
|
792
|
-
!p && Math.abs(
|
|
793
|
-
const T =
|
|
791
|
+
const D = a + k;
|
|
792
|
+
!p && Math.abs(D) && v(!0);
|
|
793
|
+
const T = D > r.right ? r.right : D < r.left ? r.left : D;
|
|
794
794
|
s(T), o == null || o({ x: T });
|
|
795
795
|
},
|
|
796
796
|
[o, s, p, h]
|
|
@@ -801,14 +801,14 @@ const F = /* @__PURE__ */ dr(fr), S = {
|
|
|
801
801
|
window.removeEventListener("mousemove", g), window.removeEventListener("touchmove", g);
|
|
802
802
|
}), [g]), A(() => (window.addEventListener("mouseup", d), window.addEventListener("touchend", d), () => {
|
|
803
803
|
window.removeEventListener("mouseup", d), window.removeEventListener("touchend", d);
|
|
804
|
-
}), [d]),
|
|
804
|
+
}), [d]), O(e) ? X(y.only(e), {
|
|
805
805
|
onMouseDown: f,
|
|
806
806
|
onTouchStart: f,
|
|
807
807
|
style: { ...u, transform: `translateX(${p ? i : a}px)` }
|
|
808
808
|
}) : null;
|
|
809
809
|
}, hr = ({ checked: e, onChange: n }) => {
|
|
810
810
|
var G, Z;
|
|
811
|
-
const t =
|
|
811
|
+
const t = C(null), o = C(null), [c, r] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
|
|
812
812
|
re(() => {
|
|
813
813
|
var E, z;
|
|
814
814
|
l(((E = o.current) == null ? void 0 : E.clientHeight) || 0), v(((z = t.current) == null ? void 0 : z.clientHeight) || 0);
|
|
@@ -845,8 +845,8 @@ const F = /* @__PURE__ */ dr(fr), S = {
|
|
|
845
845
|
typeof r == "boolean" ? r : !!u
|
|
846
846
|
), p = !!(typeof r == "boolean" ? r : h), { thumbRef: v, trackRef: f, isDragging: g, onChangeWithDrag: d, ...b } = hr({
|
|
847
847
|
checked: p,
|
|
848
|
-
onChange: (
|
|
849
|
-
i.disabled || (o == null || o(
|
|
848
|
+
onChange: (k) => {
|
|
849
|
+
i.disabled || (o == null || o(k), l(k));
|
|
850
850
|
}
|
|
851
851
|
}), m = () => /* @__PURE__ */ x(
|
|
852
852
|
Le,
|