@purpurds/toggle 8.11.0 → 8.12.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/toggle.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as g, jsxs as O } from "react/jsx-runtime";
2
2
  import * as s from "react";
3
- import { useState as C, useCallback as A, useEffect as P, cloneElement as ue, isValidElement as se, useRef as E, forwardRef as ce } from "react";
3
+ import { useState as C, useCallback as A, useEffect as E, cloneElement as ue, isValidElement as se, useRef as z, forwardRef as ce } from "react";
4
4
  import "react-dom";
5
5
  function le(e) {
6
6
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -47,16 +47,16 @@ const fe = /* @__PURE__ */ le(de), he = {
47
47
  "purpur-icon--md": "_purpur-icon--md_8u1lq_16",
48
48
  "purpur-icon--lg": "_purpur-icon--lg_8u1lq_20",
49
49
  "purpur-icon--xl": "_purpur-icon--xl_8u1lq_24"
50
- }, ge = fe.bind(he), B = "purpur-icon", _e = "md", me = (e) => e.filter((n) => Object.keys(n).length >= 1).map((n) => `${n.name}="${n.value}"`).join(" "), ve = ({ content: e = "", title: n } = {}) => {
50
+ }, ge = fe.bind(he), B = "purpur-icon", ve = "md", _e = (e) => e.filter((n) => Object.keys(n).length >= 1).map((n) => `${n.name}="${n.value}"`).join(" "), me = ({ content: e = "", title: n } = {}) => {
51
51
  const t = [
52
52
  { name: "xmlns", value: "http://www.w3.org/2000/svg" },
53
53
  { name: "fill", value: "currentColor" },
54
54
  { name: "viewBox", value: "0 0 24 24" },
55
55
  n ? { name: "role", value: "img" } : { name: "aria-hidden", value: "true" }
56
56
  ], a = n ? `<title>${n}</title>` : "";
57
- return `<svg ${me(t)}>${a}${e}</svg>`;
58
- }, be = (e) => e.replace(/<(\/?)svg([^>]*)>/g, "").trim(), J = ({ svg: e, allyTitle: n, className: t, size: a = _e, ...o }) => {
59
- const r = ve({
57
+ return `<svg ${_e(t)}>${a}${e}</svg>`;
58
+ }, be = (e) => e.replace(/<(\/?)svg([^>]*)>/g, "").trim(), J = ({ svg: e, allyTitle: n, className: t, size: a = ve, ...o }) => {
59
+ const r = me({
60
60
  content: be(e.svg),
61
61
  title: n
62
62
  }), i = ge(B, `${B}--${a}`, t);
@@ -90,7 +90,7 @@ function we(...e) {
90
90
  };
91
91
  };
92
92
  }
93
- var Se = Symbol.for("react.lazy"), k = s[" use ".trim().toString()];
93
+ var Se = Symbol.for("react.lazy"), P = s[" use ".trim().toString()];
94
94
  function xe(e) {
95
95
  return typeof e == "object" && e !== null && "then" in e;
96
96
  }
@@ -101,8 +101,8 @@ function K(e) {
101
101
  function Ce(e) {
102
102
  const n = /* @__PURE__ */ $e(e), t = s.forwardRef((a, o) => {
103
103
  let { children: r, ...i } = a;
104
- K(r) && typeof k == "function" && (r = k(r._payload));
105
- const u = s.Children.toArray(r), c = u.find(Ee);
104
+ K(r) && typeof P == "function" && (r = P(r._payload));
105
+ const u = s.Children.toArray(r), c = u.find(ze);
106
106
  if (c) {
107
107
  const l = c.props.children, d = u.map((p) => p === c ? s.Children.count(l) > 1 ? s.Children.only(null) : s.isValidElement(l) ? l.props.children : null : p);
108
108
  return /* @__PURE__ */ g(n, { ...i, ref: o, children: s.isValidElement(l) ? s.cloneElement(l, void 0, d) : null });
@@ -115,8 +115,8 @@ function Ce(e) {
115
115
  function $e(e) {
116
116
  const n = s.forwardRef((t, a) => {
117
117
  let { children: o, ...r } = t;
118
- if (K(o) && typeof k == "function" && (o = k(o._payload)), s.isValidElement(o)) {
119
- const i = ke(o), u = Pe(r, o.props);
118
+ if (K(o) && typeof P == "function" && (o = P(o._payload)), s.isValidElement(o)) {
119
+ const i = Pe(o), u = Ee(r, o.props);
120
120
  return o.type !== s.Fragment && (u.ref = a ? we(a, i) : i), s.cloneElement(o, u);
121
121
  }
122
122
  return s.Children.count(o) > 1 ? s.Children.only(null) : null;
@@ -124,10 +124,10 @@ function $e(e) {
124
124
  return n.displayName = `${e}.SlotClone`, n;
125
125
  }
126
126
  var Re = Symbol("radix.slottable");
127
- function Ee(e) {
127
+ function ze(e) {
128
128
  return s.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === Re;
129
129
  }
130
- function Pe(e, n) {
130
+ function Ee(e, n) {
131
131
  const t = { ...n };
132
132
  for (const a in n) {
133
133
  const o = e[a], r = n[a];
@@ -138,11 +138,11 @@ function Pe(e, n) {
138
138
  }
139
139
  return { ...e, ...t };
140
140
  }
141
- function ke(e) {
141
+ function Pe(e) {
142
142
  let n = Object.getOwnPropertyDescriptor(e.props, "ref")?.get, t = n && "isReactWarning" in n && n.isReactWarning;
143
143
  return t ? e.ref : (n = Object.getOwnPropertyDescriptor(e, "ref")?.get, t = n && "isReactWarning" in n && n.isReactWarning, t ? e.props.ref : e.props.ref || e.ref);
144
144
  }
145
- var De = [
145
+ var ke = [
146
146
  "a",
147
147
  "button",
148
148
  "div",
@@ -160,14 +160,14 @@ var De = [
160
160
  "span",
161
161
  "svg",
162
162
  "ul"
163
- ], Ne = De.reduce((e, n) => {
163
+ ], De = ke.reduce((e, n) => {
164
164
  const t = /* @__PURE__ */ Ce(`Primitive.${n}`), a = s.forwardRef((o, r) => {
165
165
  const { asChild: i, ...u } = o, c = i ? t : n;
166
166
  return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ g(c, { ...u, ref: r });
167
167
  });
168
168
  return a.displayName = `Primitive.${n}`, { ...e, [n]: a };
169
- }, {}), ze = "Label", Q = s.forwardRef((e, n) => /* @__PURE__ */ g(
170
- Ne.label,
169
+ }, {}), Ne = "Label", Q = s.forwardRef((e, n) => /* @__PURE__ */ g(
170
+ De.label,
171
171
  {
172
172
  ...e,
173
173
  ref: n,
@@ -176,7 +176,7 @@ var De = [
176
176
  }
177
177
  }
178
178
  ));
179
- Q.displayName = ze;
179
+ Q.displayName = Ne;
180
180
  var Oe = Q;
181
181
  function Ae(e) {
182
182
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -219,16 +219,16 @@ const qe = /* @__PURE__ */ Ae(je), Be = {
219
219
  "purpur-label": "_purpur-label_1x80u_1",
220
220
  "purpur-label--negative": "_purpur-label--negative_1x80u_8",
221
221
  "purpur-label--disabled": "_purpur-label--disabled_1x80u_11"
222
- }, Xe = qe.bind(Be), N = "purpur-label", He = ({
222
+ }, Xe = qe.bind(Be), D = "purpur-label", He = ({
223
223
  children: e,
224
224
  className: n,
225
225
  disabled: t,
226
226
  negative: a = !1,
227
227
  ...o
228
228
  }) => {
229
- const r = Xe(n, N, {
230
- [`${N}--disabled`]: t,
231
- [`${N}--negative`]: a
229
+ const r = Xe(n, D, {
230
+ [`${D}--disabled`]: t,
231
+ [`${D}--negative`]: a
232
232
  });
233
233
  return /* @__PURE__ */ g(Oe, { className: r, ...o, children: e });
234
234
  };
@@ -270,20 +270,21 @@ function We() {
270
270
  }
271
271
  var Ie = We();
272
272
  const Te = /* @__PURE__ */ Le(Ie), Ve = {
273
- "purpur-paragraph": "_purpur-paragraph_1rh57_1",
274
- "purpur-paragraph--disabled": "_purpur-paragraph--disabled_1rh57_7",
275
- "purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_1rh57_10",
276
- "purpur-paragraph--negative": "_purpur-paragraph--negative_1rh57_13",
277
- "purpur-paragraph--paragraph-100": "_purpur-paragraph--paragraph-100_1rh57_16",
278
- "purpur-paragraph--paragraph-100-medium": "_purpur-paragraph--paragraph-100-medium_1rh57_22",
279
- "purpur-paragraph--paragraph-100-bold": "_purpur-paragraph--paragraph-100-bold_1rh57_29",
280
- "purpur-paragraph--paragraph-200": "_purpur-paragraph--paragraph-200_1rh57_36",
281
- "purpur-paragraph--preamble-100": "_purpur-paragraph--preamble-100_1rh57_42",
282
- "purpur-paragraph--preamble-200": "_purpur-paragraph--preamble-200_1rh57_48",
283
- "purpur-paragraph--additional-100": "_purpur-paragraph--additional-100_1rh57_54",
284
- "purpur-paragraph--additional-100-medium": "_purpur-paragraph--additional-100-medium_1rh57_60",
285
- "purpur-paragraph--overline-100": "_purpur-paragraph--overline-100_1rh57_67",
286
- "purpur-paragraph--overline-200": "_purpur-paragraph--overline-200_1rh57_75"
273
+ "purpur-paragraph": "_purpur-paragraph_1vz75_1",
274
+ "purpur-paragraph--disabled": "_purpur-paragraph--disabled_1vz75_7",
275
+ "purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_1vz75_10",
276
+ "purpur-paragraph--negative": "_purpur-paragraph--negative_1vz75_13",
277
+ "purpur-paragraph--paragraph-100": "_purpur-paragraph--paragraph-100_1vz75_16",
278
+ "purpur-paragraph--paragraph-100-medium": "_purpur-paragraph--paragraph-100-medium_1vz75_22",
279
+ "purpur-paragraph--paragraph-100-bold": "_purpur-paragraph--paragraph-100-bold_1vz75_29",
280
+ "purpur-paragraph--paragraph-200": "_purpur-paragraph--paragraph-200_1vz75_36",
281
+ "purpur-paragraph--preamble-100": "_purpur-paragraph--preamble-100_1vz75_42",
282
+ "purpur-paragraph--preamble-200": "_purpur-paragraph--preamble-200_1vz75_48",
283
+ "purpur-paragraph--additional-100": "_purpur-paragraph--additional-100_1vz75_54",
284
+ "purpur-paragraph--additional-100-medium": "_purpur-paragraph--additional-100-medium_1vz75_60",
285
+ "purpur-paragraph--additional-100-bold": "_purpur-paragraph--additional-100-bold_1vz75_67",
286
+ "purpur-paragraph--overline-100": "_purpur-paragraph--overline-100_1vz75_74",
287
+ "purpur-paragraph--overline-200": "_purpur-paragraph--overline-200_1vz75_82"
287
288
  }, Fe = Te.bind(Ve), Ue = {
288
289
  PARAGRAPH100: "paragraph-100"
289
290
  }, R = "purpur-paragraph", Y = ({
@@ -339,12 +340,12 @@ function Je(e, n = []) {
339
340
  const u = s.createContext(i), c = t.length;
340
341
  t = [...t, i];
341
342
  const l = (p) => {
342
- const { scope: f, children: _, ...h } = p, m = f?.[e]?.[c] || u, v = s.useMemo(() => h, Object.values(h));
343
- return /* @__PURE__ */ g(m.Provider, { value: v, children: _ });
343
+ const { scope: f, children: v, ...h } = p, _ = f?.[e]?.[c] || u, m = s.useMemo(() => h, Object.values(h));
344
+ return /* @__PURE__ */ g(_.Provider, { value: m, children: v });
344
345
  };
345
346
  l.displayName = r + "Provider";
346
347
  function d(p, f) {
347
- const _ = f?.[e]?.[c] || u, h = s.useContext(_);
348
+ const v = f?.[e]?.[c] || u, h = s.useContext(v);
348
349
  if (h) return h;
349
350
  if (i !== void 0) return i;
350
351
  throw new Error(`\`${p}\` must be used within \`${r}\``);
@@ -520,7 +521,7 @@ var cr = [
520
521
  onCheckedChange: l,
521
522
  form: d,
522
523
  ...p
523
- } = e, [f, _] = s.useState(null), h = Ge(n, (y) => _(y)), m = s.useRef(!1), v = f ? d || !!f.closest("form") : !0, [b = !1, x] = Qe({
524
+ } = e, [f, v] = s.useState(null), h = Ge(n, (y) => v(y)), _ = s.useRef(!1), m = f ? d || !!f.closest("form") : !0, [b = !1, x] = Qe({
524
525
  prop: o,
525
526
  defaultProp: r,
526
527
  onChange: l
@@ -540,15 +541,15 @@ var cr = [
540
541
  ...p,
541
542
  ref: h,
542
543
  onClick: Ze(e.onClick, (y) => {
543
- x((w) => !w), v && (m.current = y.isPropagationStopped(), m.current || y.stopPropagation());
544
+ x((w) => !w), m && (_.current = y.isPropagationStopped(), _.current || y.stopPropagation());
544
545
  })
545
546
  }
546
547
  ),
547
- v && /* @__PURE__ */ g(
548
+ m && /* @__PURE__ */ g(
548
549
  fr,
549
550
  {
550
551
  control: f,
551
- bubbles: !m.current,
552
+ bubbles: !_.current,
552
553
  name: a,
553
554
  value: c,
554
555
  checked: b,
@@ -609,12 +610,12 @@ function ae(e) {
609
610
  return e ? "checked" : "unchecked";
610
611
  }
611
612
  var hr = ne, gr = ie;
612
- function _r(e) {
613
+ function vr(e) {
613
614
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
614
615
  }
615
- var z = { exports: {} };
616
+ var N = { exports: {} };
616
617
  var V;
617
- function mr() {
618
+ function _r() {
618
619
  return V || (V = 1, (function(e) {
619
620
  (function() {
620
621
  var n = {}.hasOwnProperty;
@@ -644,10 +645,10 @@ function mr() {
644
645
  }
645
646
  e.exports ? (t.default = t, e.exports = t) : window.classNames = t;
646
647
  })();
647
- })(z)), z.exports;
648
+ })(N)), N.exports;
648
649
  }
649
- var vr = mr();
650
- const br = /* @__PURE__ */ _r(vr), F = (e) => e && "touches" in e, yr = ({
650
+ var mr = _r();
651
+ const br = /* @__PURE__ */ vr(mr), F = (e) => e && "touches" in e, yr = ({
651
652
  children: e,
652
653
  disabled: n,
653
654
  onStart: t,
@@ -657,13 +658,13 @@ const br = /* @__PURE__ */ _r(vr), F = (e) => e && "touches" in e, yr = ({
657
658
  position: i,
658
659
  style: u
659
660
  }) => {
660
- const [c, l] = C(void 0), [d, p] = C(void 0), [f, _] = C(!1), h = (b) => {
661
+ const [c, l] = C(void 0), [d, p] = C(void 0), [f, v] = C(!1), h = (b) => {
661
662
  if (!n) {
662
663
  b.preventDefault();
663
664
  const x = F(b.nativeEvent) ? b.nativeEvent.touches[0].clientX : b.nativeEvent.clientX;
664
665
  p(x), t?.();
665
666
  }
666
- }, m = A(
667
+ }, _ = A(
667
668
  (b) => {
668
669
  if (typeof d != "number")
669
670
  return;
@@ -671,20 +672,20 @@ const br = /* @__PURE__ */ _r(vr), F = (e) => e && "touches" in e, yr = ({
671
672
  if (!y)
672
673
  return;
673
674
  const w = i + y;
674
- !f && Math.abs(w) && _(!0);
675
- const D = w > r.right ? r.right : w < r.left ? r.left : w;
676
- l(D), a?.({ x: D });
675
+ !f && Math.abs(w) && v(!0);
676
+ const k = w > r.right ? r.right : w < r.left ? r.left : w;
677
+ l(k), a?.({ x: k });
677
678
  },
678
679
  // eslint-disable-next-line react-hooks/exhaustive-deps
679
680
  [a, l, f, d]
680
- ), v = A(() => {
681
- p(void 0), l(void 0), _(!1), o?.();
681
+ ), m = A(() => {
682
+ p(void 0), l(void 0), v(!1), o?.();
682
683
  }, [o, p]);
683
- return P(() => (window.addEventListener("mousemove", m), window.addEventListener("touchmove", m), () => {
684
- window.removeEventListener("mousemove", m), window.removeEventListener("touchmove", m);
685
- }), [m]), P(() => (window.addEventListener("mouseup", v), window.addEventListener("touchend", v), () => {
686
- window.removeEventListener("mouseup", v), window.removeEventListener("touchend", v);
687
- }), [v]), se(e) ? ue(e, {
684
+ return E(() => (window.addEventListener("mousemove", _), window.addEventListener("touchmove", _), () => {
685
+ window.removeEventListener("mousemove", _), window.removeEventListener("touchmove", _);
686
+ }), [_]), E(() => (window.addEventListener("mouseup", m), window.addEventListener("touchend", m), () => {
687
+ window.removeEventListener("mouseup", m), window.removeEventListener("touchend", m);
688
+ }), [m]), se(e) ? ue(e, {
688
689
  onMouseDown: h,
689
690
  onTouchStart: h,
690
691
  style: { ...u, transform: `translateX(${f ? c : i}px)` }
@@ -694,18 +695,18 @@ const br = /* @__PURE__ */ _r(vr), F = (e) => e && "touches" in e, yr = ({
694
695
  height: void 0
695
696
  };
696
697
  function Z(e) {
697
- const { ref: n, box: t = "content-box", round: a } = e, [{ width: o, height: r }, i] = C(U), u = wr(), c = E({ ...U }), l = E(void 0);
698
- return l.current = e.onResize, P(() => {
698
+ const { ref: n, box: t = "content-box", round: a } = e, [{ width: o, height: r }, i] = C(U), u = wr(), c = z({ ...U }), l = z(void 0);
699
+ return l.current = e.onResize, E(() => {
699
700
  if (!n.current || typeof window > "u" || !("ResizeObserver" in window))
700
701
  return;
701
702
  const d = new ResizeObserver(([p]) => {
702
- const f = t === "border-box" ? "borderBoxSize" : t === "device-pixel-content-box" ? "devicePixelContentBoxSize" : "contentBoxSize", _ = G(p, f, "inlineSize"), h = G(p, f, "blockSize");
703
- if (c.current.width !== _ || c.current.height !== h) {
704
- const v = {
705
- width: _ && a ? Math.round(_) : _,
703
+ const f = t === "border-box" ? "borderBoxSize" : t === "device-pixel-content-box" ? "devicePixelContentBoxSize" : "contentBoxSize", v = G(p, f, "inlineSize"), h = G(p, f, "blockSize");
704
+ if (c.current.width !== v || c.current.height !== h) {
705
+ const m = {
706
+ width: v && a ? Math.round(v) : v,
706
707
  height: h && a ? Math.round(h) : h
707
708
  };
708
- c.current.width = _, c.current.height = h, l.current ? l.current(v) : u() && i(v);
709
+ c.current.width = v, c.current.height = h, l.current ? l.current(m) : u() && i(m);
709
710
  }
710
711
  });
711
712
  return d.observe(n.current, { box: t }), () => {
@@ -721,24 +722,24 @@ function G(e, n, t) {
721
722
  ) : n === "contentBoxSize" ? e.contentRect[t === "inlineSize" ? "width" : "height"] : void 0;
722
723
  }
723
724
  function wr() {
724
- const e = E(!1);
725
- return P(() => (e.current = !0, () => {
725
+ const e = z(!1);
726
+ return E(() => (e.current = !0, () => {
726
727
  e.current = !1;
727
728
  }), []), A(() => e.current, []);
728
729
  }
729
730
  const Sr = ({ checked: e, onChange: n }) => {
730
- const t = E(null), a = E(null), [o, r] = C(void 0), [i, u] = C(!1), [c, l] = C(0), { height: d = 0 } = Z({ ref: a, round: !0 }), { height: p = 0 } = Z({ ref: t, round: !0 }), f = (p || 0) - d, _ = d + f, h = f / 2, m = _ / 2, v = typeof o == "number" && (e ? o < m : o > m);
731
+ const t = z(null), a = z(null), [o, r] = C(void 0), [i, u] = C(!1), [c, l] = C(0), { height: d = 0 } = Z({ ref: a, round: !0 }), { height: p = 0 } = Z({ ref: t, round: !0 }), f = (p || 0) - d, v = d + f, h = f / 2, _ = v / 2, m = typeof o == "number" && (e ? o < _ : o > _);
731
732
  return {
732
733
  trackRef: t,
733
734
  thumbRef: a,
734
735
  isDragging: i,
735
- bounds: { left: h, right: _ },
736
- position: e ? _ : h,
736
+ bounds: { left: h, right: v },
737
+ position: e ? v : h,
737
738
  onDrag: ({ x: w }) => {
738
- r(w), Math.abs((e ? _ : h) - w) > 2 && u(!0);
739
+ r(w), Math.abs((e ? v : h) - w) > 2 && u(!0);
739
740
  },
740
741
  onStop: () => {
741
- u(!1), i && l(Date.now()), v && n?.(!e);
742
+ u(!1), i && l(Date.now()), m && n?.(!e);
742
743
  },
743
744
  onChangeWithDrag: () => {
744
745
  Date.now() - c > 50 && n?.(!e), r(void 0);
@@ -768,7 +769,7 @@ const Sr = ({ checked: e, onChange: n }) => {
768
769
  }, l) => {
769
770
  const [d, p] = C(
770
771
  typeof r == "boolean" ? r : !!u
771
- ), f = !!(typeof r == "boolean" ? r : d), { thumbRef: _, trackRef: h, isDragging: m, onChangeWithDrag: v, ...b } = Sr({
772
+ ), f = !!(typeof r == "boolean" ? r : d), { thumbRef: v, trackRef: h, isDragging: _, onChangeWithDrag: m, ...b } = Sr({
772
773
  checked: f,
773
774
  onChange: (y) => {
774
775
  c.disabled || (a?.(y), p(y));
@@ -793,17 +794,17 @@ const Sr = ({ checked: e, onChange: n }) => {
793
794
  id: c.id,
794
795
  "data-testid": e,
795
796
  className: $(S),
796
- onCheckedChange: v,
797
+ onCheckedChange: m,
797
798
  checked: f,
798
799
  children: /* @__PURE__ */ O("span", { ref: h, className: $(`${S}__track`), children: [
799
800
  /* @__PURE__ */ g("span", { className: $(`${S}__checkmark-container`), children: /* @__PURE__ */ g(J, { className: $(`${S}__checkmark`), svg: ye, size: "xxs" }) }),
800
801
  /* @__PURE__ */ g(yr, { disabled: i, ...b, children: /* @__PURE__ */ g(
801
802
  gr,
802
803
  {
803
- ref: _,
804
+ ref: v,
804
805
  "data-testid": e && `${e}-thumb`,
805
806
  className: $(`${S}__thumb`, {
806
- [`${S}__thumb--dragging`]: m
807
+ [`${S}__thumb--dragging`]: _
807
808
  })
808
809
  }
809
810
  ) })