@purpurds/toggle 5.10.1 → 5.11.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,5 +1,5 @@
1
- import { jsx as x, jsxs as J } from "react/jsx-runtime";
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";
1
+ import { jsx as x, jsxs as K } from "react/jsx-runtime";
2
+ import { forwardRef as w, Children as y, isValidElement as k, createElement as _, cloneElement as X, useEffect as A, Fragment as ee, useCallback as B, createContext as J, useMemo as R, useContext as fe, useRef as D, 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;
@@ -85,15 +85,15 @@ const be = /* @__PURE__ */ ge(he), _e = {
85
85
  }
86
86
  );
87
87
  };
88
- function V() {
89
- return V = Object.assign ? Object.assign.bind() : function(e) {
88
+ function W() {
89
+ return W = Object.assign ? Object.assign.bind() : function(e) {
90
90
  for (var n = 1; n < arguments.length; n++) {
91
91
  var t = arguments[n];
92
92
  for (var o in t)
93
93
  Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);
94
94
  }
95
95
  return e;
96
- }, V.apply(this, arguments);
96
+ }, W.apply(this, arguments);
97
97
  }
98
98
  function M() {
99
99
  return M = Object.assign ? Object.assign.bind() : function(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 Oe(...e) {
111
+ function ke(...e) {
112
112
  return (n) => e.forEach(
113
113
  (t) => Pe(t, n)
114
114
  );
@@ -116,29 +116,29 @@ function Oe(...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__ */ O(a) ? a.props.children : null : i);
120
- return /* @__PURE__ */ _(W, M({}, o, {
119
+ const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ k(a) ? a.props.children : null : i);
120
+ return /* @__PURE__ */ _(G, M({}, o, {
121
121
  ref: n
122
- }), /* @__PURE__ */ O(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
122
+ }), /* @__PURE__ */ k(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
123
123
  }
124
- return /* @__PURE__ */ _(W, M({}, o, {
124
+ return /* @__PURE__ */ _(G, M({}, o, {
125
125
  ref: n
126
126
  }), t);
127
127
  });
128
128
  ne.displayName = "Slot";
129
- const W = /* @__PURE__ */ w((e, n) => {
129
+ const G = /* @__PURE__ */ w((e, n) => {
130
130
  const { children: t, ...o } = e;
131
- return /* @__PURE__ */ O(t) ? /* @__PURE__ */ X(t, {
132
- ...Ce(o, t.props),
133
- ref: n ? Oe(n, t.ref) : t.ref
131
+ return /* @__PURE__ */ k(t) ? /* @__PURE__ */ X(t, {
132
+ ...De(o, t.props),
133
+ ref: n ? ke(n, t.ref) : t.ref
134
134
  }) : y.count(t) > 1 ? y.only(null) : null;
135
135
  });
136
- W.displayName = "SlotClone";
137
- const ke = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
136
+ G.displayName = "SlotClone";
137
+ const Oe = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
138
138
  function Ae(e) {
139
- return /* @__PURE__ */ O(e) && e.type === ke;
139
+ return /* @__PURE__ */ k(e) && e.type === Oe;
140
140
  }
141
- function Ce(e, n) {
141
+ function De(e, n) {
142
142
  const t = {
143
143
  ...n
144
144
  };
@@ -159,7 +159,7 @@ function Ce(e, n) {
159
159
  ...t
160
160
  };
161
161
  }
162
- const De = [
162
+ const Ce = [
163
163
  "a",
164
164
  "button",
165
165
  "div",
@@ -176,7 +176,7 @@ const De = [
176
176
  "span",
177
177
  "svg",
178
178
  "ul"
179
- ], Ee = De.reduce((e, n) => {
179
+ ], Ne = Ce.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(() => {
@@ -189,13 +189,13 @@ const De = [
189
189
  ...e,
190
190
  [n]: t
191
191
  };
192
- }, {}), Ne = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(Ee.label, V({}, e, {
192
+ }, {}), Ee = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(Ne.label, W({}, e, {
193
193
  ref: n,
194
194
  onMouseDown: (t) => {
195
195
  var o;
196
196
  (o = e.onMouseDown) === null || o === void 0 || o.call(e, t), !t.defaultPrevented && t.detail > 1 && t.preventDefault();
197
197
  }
198
- }))), je = Ne;
198
+ }))), je = Ee;
199
199
  function Re(e) {
200
200
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
201
201
  }
@@ -299,7 +299,7 @@ var ae = { exports: {} };
299
299
  })();
300
300
  })(ae);
301
301
  var Be = ae.exports;
302
- const Te = /* @__PURE__ */ Xe(Be), N = {
302
+ const Te = /* @__PURE__ */ Xe(Be), E = {
303
303
  "purpur-paragraph": "_purpur-paragraph_1rh57_1",
304
304
  "purpur-paragraph--disabled": "_purpur-paragraph--disabled_1rh57_7",
305
305
  "purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_1rh57_10",
@@ -337,12 +337,12 @@ const Te = /* @__PURE__ */ Xe(Be), N = {
337
337
  }) => {
338
338
  const i = Te([
339
339
  t,
340
- N[j],
341
- N[`${j}--${a}`],
340
+ E[j],
341
+ E[`${j}--${a}`],
342
342
  {
343
- [N[`${j}--hyphens`]]: c,
344
- [N[`${j}--disabled`]]: o,
345
- [N[`${j}--negative`]]: r
343
+ [E[`${j}--hyphens`]]: c,
344
+ [E[`${j}--disabled`]]: o,
345
+ [E[`${j}--negative`]]: r
346
346
  }
347
347
  ]);
348
348
  return /* @__PURE__ */ x("p", { ...u, className: i, "data-testid": e, children: n });
@@ -371,13 +371,13 @@ function ce(...e) {
371
371
  (t) => Fe(t, n)
372
372
  );
373
373
  }
374
- function Ve(...e) {
374
+ function We(...e) {
375
375
  return B(ce(...e), e);
376
376
  }
377
- function We(e, n = []) {
377
+ function Ge(e, n = []) {
378
378
  let t = [];
379
379
  function o(r, a) {
380
- const u = /* @__PURE__ */ K(a), i = t.length;
380
+ const u = /* @__PURE__ */ J(a), i = t.length;
381
381
  t = [
382
382
  ...t,
383
383
  a
@@ -405,7 +405,7 @@ function We(e, n = []) {
405
405
  ];
406
406
  }
407
407
  const c = () => {
408
- const r = t.map((a) => /* @__PURE__ */ K(a));
408
+ const r = t.map((a) => /* @__PURE__ */ J(a));
409
409
  return function(u) {
410
410
  const i = (u == null ? void 0 : u[e]) || r;
411
411
  return R(
@@ -459,7 +459,7 @@ function Ue(...e) {
459
459
  return t.scopeName = n.scopeName, t;
460
460
  }
461
461
  function ue(e) {
462
- const n = C(e);
462
+ const n = D(e);
463
463
  return A(() => {
464
464
  n.current = e;
465
465
  }), R(
@@ -470,7 +470,7 @@ function ue(e) {
470
470
  []
471
471
  );
472
472
  }
473
- function Ge({ prop: e, defaultProp: n, onChange: t = () => {
473
+ function Ve({ prop: e, defaultProp: n, onChange: t = () => {
474
474
  } }) {
475
475
  const [o, c] = Ze({
476
476
  defaultProp: n,
@@ -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 = C(o), r = ue(n);
496
+ const t = $(e), [o] = t, c = D(o), r = ue(n);
497
497
  return A(() => {
498
498
  c.current !== o && (r(o), c.current = o);
499
499
  }, [
@@ -502,8 +502,8 @@ function Ze({ defaultProp: e, onChange: n }) {
502
502
  r
503
503
  ]), t;
504
504
  }
505
- function Je(e) {
506
- const n = C({
505
+ function Ke(e) {
506
+ const n = D({
507
507
  value: e,
508
508
  previous: e
509
509
  });
@@ -511,11 +511,11 @@ function Je(e) {
511
511
  e
512
512
  ]);
513
513
  }
514
- const Ke = globalThis != null && globalThis.document ? re : () => {
514
+ const Je = globalThis != null && globalThis.document ? re : () => {
515
515
  };
516
516
  function Qe(e) {
517
517
  const [n, t] = $(void 0);
518
- return Ke(() => {
518
+ return Je(() => {
519
519
  if (e) {
520
520
  t({
521
521
  width: e.offsetWidth,
@@ -558,10 +558,10 @@ 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__ */ O(a) ? a.props.children : null : i);
561
+ const a = r.props.children, u = c.map((i) => i === r ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ k(a) ? a.props.children : null : i);
562
562
  return /* @__PURE__ */ _(U, L({}, o, {
563
563
  ref: n
564
- }), /* @__PURE__ */ O(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
564
+ }), /* @__PURE__ */ k(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
565
565
  }
566
566
  return /* @__PURE__ */ _(U, L({}, o, {
567
567
  ref: n
@@ -570,7 +570,7 @@ const ie = /* @__PURE__ */ w((e, n) => {
570
570
  ie.displayName = "Slot";
571
571
  const U = /* @__PURE__ */ w((e, n) => {
572
572
  const { children: t, ...o } = e;
573
- return /* @__PURE__ */ O(t) ? /* @__PURE__ */ X(t, {
573
+ return /* @__PURE__ */ k(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;
@@ -578,7 +578,7 @@ const U = /* @__PURE__ */ w((e, n) => {
578
578
  U.displayName = "SlotClone";
579
579
  const Ye = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
580
580
  function er(e) {
581
- return /* @__PURE__ */ O(e) && e.type === Ye;
581
+ return /* @__PURE__ */ k(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] = We(le), [or, ar] = nr(le), cr = /* @__PURE__ */ w((e, n) => {
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(
634
+ }, {}), le = "Switch", [nr, yr] = Ge(le), [or, ar] = nr(le), cr = /* @__PURE__ */ w((e, n) => {
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 = We(
636
636
  n,
637
637
  (m) => p(m)
638
- ), f = C(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ge({
638
+ ), f = D(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ve({
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
- (k) => !k
660
+ (O) => !O
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 = C(null), a = Je(t), u = Qe(n);
684
+ const { control: n, checked: t, bubbles: o = !0, ...c } = e, r = D(null), a = Ke(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 k = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
789
- if (!k)
788
+ const O = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
789
+ if (!O)
790
790
  return;
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;
791
+ const C = a + O;
792
+ !p && Math.abs(C) && v(!0);
793
+ const T = C > r.right ? r.right : C < r.left ? r.left : C;
794
794
  s(T), o == null || o({ x: T });
795
795
  },
796
796
  [o, s, p, h]
@@ -801,18 +801,18 @@ 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]), O(e) ? X(y.only(e), {
804
+ }), [d]), k(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
- var G, Z;
811
- const t = C(null), o = C(null), [c, r] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
810
+ var V, Z;
811
+ const t = D(null), o = D(null), [c, r] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
812
812
  re(() => {
813
- var E, z;
814
- l(((E = o.current) == null ? void 0 : E.clientHeight) || 0), v(((z = t.current) == null ? void 0 : z.clientHeight) || 0);
815
- }, [(G = o.current) == null ? void 0 : G.clientHeight, (Z = t.current) == null ? void 0 : Z.clientHeight]);
813
+ var N, z;
814
+ l(((N = o.current) == null ? void 0 : N.clientHeight) || 0), v(((z = t.current) == null ? void 0 : z.clientHeight) || 0);
815
+ }, [(V = o.current) == null ? void 0 : V.clientHeight, (Z = t.current) == null ? void 0 : Z.clientHeight]);
816
816
  const f = (p || 0) - h, g = h + f, d = f / 2, b = g / 2, m = typeof c == "number" && (e ? c < b : c > b);
817
817
  return {
818
818
  trackRef: t,
@@ -820,8 +820,8 @@ const F = /* @__PURE__ */ dr(fr), S = {
820
820
  isDragging: a,
821
821
  bounds: { left: d, right: g },
822
822
  position: e ? g : d,
823
- onDrag: ({ x: E }) => {
824
- r(E), Math.abs((e ? g : d) - E) > 2 && u(!0);
823
+ onDrag: ({ x: N }) => {
824
+ r(N), Math.abs((e ? g : d) - N) > 2 && u(!0);
825
825
  },
826
826
  onStop: () => {
827
827
  u(!1), a && s(Date.now()), m && (n == null || n(!e));
@@ -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: (k) => {
849
- i.disabled || (o == null || o(k), l(k));
848
+ onChange: (O) => {
849
+ i.disabled || (o == null || o(O), l(O));
850
850
  }
851
851
  }), m = () => /* @__PURE__ */ x(
852
852
  Le,
@@ -861,7 +861,7 @@ const F = /* @__PURE__ */ dr(fr), S = {
861
861
  children: /* @__PURE__ */ x(Ie, { variant: "paragraph-100", disabled: i.disabled, children: t })
862
862
  }
863
863
  );
864
- return /* @__PURE__ */ J("div", { className: F([n, S[`${P}__container`]]), children: [
864
+ return /* @__PURE__ */ K("div", { className: F([n, S[`${P}__container`]]), children: [
865
865
  t && c === "left" && m(),
866
866
  /* @__PURE__ */ x(
867
867
  lr,
@@ -873,7 +873,7 @@ const F = /* @__PURE__ */ dr(fr), S = {
873
873
  className: S[P],
874
874
  onCheckedChange: d,
875
875
  checked: p,
876
- children: /* @__PURE__ */ J("span", { ref: f, className: S[`${P}__track`], children: [
876
+ children: /* @__PURE__ */ K("span", { ref: f, className: S[`${P}__track`], children: [
877
877
  /* @__PURE__ */ x("span", { className: S[`${P}__checkmark-container`], children: /* @__PURE__ */ x(
878
878
  Se,
879
879
  {