@purpurds/toggle 5.12.0 → 5.14.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 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 ge, useRef as D, useState as $, useLayoutEffect as re } from "react";
1
+ import { jsx as x, jsxs as J } 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 Y, useMemo as R, useContext as ge, useRef as N, useState as $, useLayoutEffect as re } from "react";
3
3
  import "react-dom";
4
4
  function he(e) {
5
5
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -54,7 +54,7 @@ const _e = /* @__PURE__ */ he(be), ve = {
54
54
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M21.243 4.176a2 2 0 0 1 .324 2.81l-10.45 13.176a2.092 2.092 0 0 1-3.118.18l-5.413-5.413A2 2 0 1 1 5.414 12.1l3.9 3.9 9.118-11.5a2 2 0 0 1 2.81-.324Z" clip-rule="evenodd"/></svg>',
55
55
  keywords: ["checkmark-bold"],
56
56
  category: "utility"
57
- }, $e = _e.bind(ve), Q = "purpur-icon", ye = "md", xe = (e) => e.filter((n) => Object.keys(n).length >= 1).map((n) => `${n.name}="${n.value}"`).join(" "), we = ({ content: e = "", title: n } = {}) => {
57
+ }, $e = _e.bind(ve), K = "purpur-icon", ye = "md", xe = (e) => e.filter((n) => Object.keys(n).length >= 1).map((n) => `${n.name}="${n.value}"`).join(" "), we = ({ content: e = "", title: n } = {}) => {
58
58
  const t = [
59
59
  { name: "xmlns", value: "http://www.w3.org/2000/svg" },
60
60
  { name: "fill", value: "currentColor" },
@@ -73,7 +73,7 @@ const _e = /* @__PURE__ */ he(be), ve = {
73
73
  const a = we({
74
74
  content: Se(n.svg),
75
75
  title: t
76
- }), u = $e(o, Q, `${Q}--${c}`);
76
+ }), u = $e(o, K, `${K}--${c}`);
77
77
  return /* @__PURE__ */ x(
78
78
  "span",
79
79
  {
@@ -85,15 +85,15 @@ const _e = /* @__PURE__ */ he(be), ve = {
85
85
  }
86
86
  );
87
87
  };
88
- function W() {
89
- return W = Object.assign ? Object.assign.bind() : function(e) {
88
+ function U() {
89
+ return U = 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
- }, W.apply(this, arguments);
96
+ }, U.apply(this, arguments);
97
97
  }
98
98
  function M() {
99
99
  return M = Object.assign ? Object.assign.bind() : function(e) {
@@ -114,31 +114,31 @@ function Oe(...e) {
114
114
  );
115
115
  }
116
116
  const ne = /* @__PURE__ */ w((e, n) => {
117
- const { children: t, ...o } = e, c = y.toArray(t), r = c.find(De);
117
+ const { children: t, ...o } = e, c = y.toArray(t), r = c.find(Ne);
118
118
  if (r) {
119
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, {
120
+ return /* @__PURE__ */ _(V, M({}, o, {
121
121
  ref: n
122
122
  }), /* @__PURE__ */ k(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
123
123
  }
124
- return /* @__PURE__ */ _(G, M({}, o, {
124
+ return /* @__PURE__ */ _(V, M({}, o, {
125
125
  ref: n
126
126
  }), t);
127
127
  });
128
128
  ne.displayName = "Slot";
129
- const G = /* @__PURE__ */ w((e, n) => {
129
+ const V = /* @__PURE__ */ w((e, n) => {
130
130
  const { children: t, ...o } = e;
131
131
  return /* @__PURE__ */ k(t) ? /* @__PURE__ */ X(t, {
132
- ...Ne(o, t.props),
132
+ ...De(o, t.props),
133
133
  ref: n ? Oe(n, t.ref) : t.ref
134
134
  }) : y.count(t) > 1 ? y.only(null) : null;
135
135
  });
136
- G.displayName = "SlotClone";
136
+ V.displayName = "SlotClone";
137
137
  const Ae = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
138
- function De(e) {
138
+ function Ne(e) {
139
139
  return /* @__PURE__ */ k(e) && e.type === Ae;
140
140
  }
141
- function Ne(e, n) {
141
+ function De(e, n) {
142
142
  const t = {
143
143
  ...n
144
144
  };
@@ -189,7 +189,7 @@ const Ce = [
189
189
  ...e,
190
190
  [n]: t
191
191
  };
192
- }, {}), je = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(Ee.label, W({}, e, {
192
+ }, {}), je = /* @__PURE__ */ w((e, n) => /* @__PURE__ */ _(Ee.label, U({}, e, {
193
193
  ref: n,
194
194
  onMouseDown: (t) => {
195
195
  var o;
@@ -371,13 +371,13 @@ function ue(...e) {
371
371
  (t) => Fe(t, n)
372
372
  );
373
373
  }
374
- function We(...e) {
374
+ function Ue(...e) {
375
375
  return B(ue(...e), e);
376
376
  }
377
- function Ge(e, n = []) {
377
+ function Ve(e, n = []) {
378
378
  let t = [];
379
379
  function o(r, a) {
380
- const u = /* @__PURE__ */ J(a), i = t.length;
380
+ const u = /* @__PURE__ */ Y(a), i = t.length;
381
381
  t = [
382
382
  ...t,
383
383
  a
@@ -403,7 +403,7 @@ function Ge(e, n = []) {
403
403
  ];
404
404
  }
405
405
  const c = () => {
406
- const r = t.map((a) => /* @__PURE__ */ J(a));
406
+ const r = t.map((a) => /* @__PURE__ */ Y(a));
407
407
  return function(u) {
408
408
  const i = (u == null ? void 0 : u[e]) || r;
409
409
  return R(
@@ -422,10 +422,10 @@ function Ge(e, n = []) {
422
422
  };
423
423
  return c.scopeName = e, [
424
424
  o,
425
- Ue(c, ...n)
425
+ We(c, ...n)
426
426
  ];
427
427
  }
428
- function Ue(...e) {
428
+ function We(...e) {
429
429
  const n = e[0];
430
430
  if (e.length === 1) return n;
431
431
  const t = () => {
@@ -456,7 +456,7 @@ function Ue(...e) {
456
456
  return t.scopeName = n.scopeName, t;
457
457
  }
458
458
  function ie(e) {
459
- const n = D(e);
459
+ const n = N(e);
460
460
  return A(() => {
461
461
  n.current = e;
462
462
  }), R(
@@ -467,7 +467,7 @@ function ie(e) {
467
467
  []
468
468
  );
469
469
  }
470
- function Ve({ prop: e, defaultProp: n, onChange: t = () => {
470
+ function Ge({ prop: e, defaultProp: n, onChange: t = () => {
471
471
  } }) {
472
472
  const [o, c] = Ze({
473
473
  defaultProp: n,
@@ -489,7 +489,7 @@ function Ve({ prop: e, defaultProp: n, onChange: t = () => {
489
489
  ];
490
490
  }
491
491
  function Ze({ defaultProp: e, onChange: n }) {
492
- const t = $(e), [o] = t, c = D(o), r = ie(n);
492
+ const t = $(e), [o] = t, c = N(o), r = ie(n);
493
493
  return A(() => {
494
494
  c.current !== o && (r(o), c.current = o);
495
495
  }, [
@@ -498,8 +498,8 @@ function Ze({ defaultProp: e, onChange: n }) {
498
498
  r
499
499
  ]), t;
500
500
  }
501
- function Ke(e) {
502
- const n = D({
501
+ function Je(e) {
502
+ const n = N({
503
503
  value: e,
504
504
  previous: e
505
505
  });
@@ -507,11 +507,11 @@ function Ke(e) {
507
507
  e
508
508
  ]);
509
509
  }
510
- const Je = globalThis != null && globalThis.document ? re : () => {
510
+ const Ye = globalThis != null && globalThis.document ? re : () => {
511
511
  };
512
- function Qe(e) {
512
+ function Ke(e) {
513
513
  const [n, t] = $(void 0);
514
- return Je(() => {
514
+ return Ye(() => {
515
515
  if (e) {
516
516
  t({
517
517
  width: e.offsetWidth,
@@ -554,26 +554,26 @@ const se = /* @__PURE__ */ w((e, n) => {
554
554
  const { children: t, ...o } = e, c = y.toArray(t), r = c.find(er);
555
555
  if (r) {
556
556
  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);
557
- return /* @__PURE__ */ _(U, L({}, o, {
557
+ return /* @__PURE__ */ _(W, L({}, o, {
558
558
  ref: n
559
559
  }), /* @__PURE__ */ k(a) ? /* @__PURE__ */ X(a, void 0, u) : null);
560
560
  }
561
- return /* @__PURE__ */ _(U, L({}, o, {
561
+ return /* @__PURE__ */ _(W, L({}, o, {
562
562
  ref: n
563
563
  }), t);
564
564
  });
565
565
  se.displayName = "Slot";
566
- const U = /* @__PURE__ */ w((e, n) => {
566
+ const W = /* @__PURE__ */ w((e, n) => {
567
567
  const { children: t, ...o } = e;
568
568
  return /* @__PURE__ */ k(t) ? /* @__PURE__ */ X(t, {
569
569
  ...rr(o, t.props),
570
570
  ref: n ? ue(n, t.ref) : t.ref
571
571
  }) : y.count(t) > 1 ? y.only(null) : null;
572
572
  });
573
- U.displayName = "SlotClone";
574
- const Ye = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
573
+ W.displayName = "SlotClone";
574
+ const Qe = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
575
575
  function er(e) {
576
- return /* @__PURE__ */ k(e) && e.type === Ye;
576
+ return /* @__PURE__ */ k(e) && e.type === Qe;
577
577
  }
578
578
  function rr(e, n) {
579
579
  const t = {
@@ -626,11 +626,11 @@ const tr = [
626
626
  ...e,
627
627
  [n]: t
628
628
  };
629
- }, {}), pe = "Switch", [nr, yr] = Ge(pe), [or, ar] = nr(pe), cr = /* @__PURE__ */ w((e, n) => {
630
- 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(
629
+ }, {}), pe = "Switch", [nr, yr] = Ve(pe), [or, ar] = nr(pe), cr = /* @__PURE__ */ w((e, n) => {
630
+ const { __scopeSwitch: t, name: o, checked: c, defaultChecked: r, required: a, disabled: u, value: i = "on", onCheckedChange: s, ...h } = e, [l, p] = $(null), v = Ue(
631
631
  n,
632
632
  (m) => p(m)
633
- ), f = D(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ve({
633
+ ), f = N(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ge({
634
634
  prop: c,
635
635
  defaultProp: r,
636
636
  onChange: s
@@ -676,7 +676,7 @@ const tr = [
676
676
  ref: n
677
677
  }));
678
678
  }), sr = (e) => {
679
- const { control: n, checked: t, bubbles: o = !0, ...c } = e, r = D(null), a = Ke(t), u = Qe(n);
679
+ const { control: n, checked: t, bubbles: o = !0, ...c } = e, r = N(null), a = Je(t), u = Ke(n);
680
680
  return A(() => {
681
681
  const i = r.current, s = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(s, "checked").set;
682
682
  if (a !== t && l) {
@@ -760,7 +760,7 @@ const F = /* @__PURE__ */ dr(fr), S = {
760
760
  "purpur-toggle__label--right": "_purpur-toggle__label--right_1xng6_100",
761
761
  "purpur-toggle__label--left": "_purpur-toggle__label--left_1xng6_103",
762
762
  "purpur-toggle__container": "_purpur-toggle__container_1xng6_106"
763
- }, Y = (e) => e && "touches" in e, gr = ({
763
+ }, Q = (e) => e && "touches" in e, gr = ({
764
764
  children: e,
765
765
  disabled: n,
766
766
  onStart: t,
@@ -773,19 +773,19 @@ const F = /* @__PURE__ */ dr(fr), S = {
773
773
  const [i, s] = $(void 0), [h, l] = $(void 0), [p, v] = $(!1), f = (b) => {
774
774
  if (!n) {
775
775
  b.preventDefault();
776
- const m = Y(b.nativeEvent) ? b.nativeEvent.touches[0].clientX : b.nativeEvent.clientX;
776
+ const m = Q(b.nativeEvent) ? b.nativeEvent.touches[0].clientX : b.nativeEvent.clientX;
777
777
  l(m), t == null || t();
778
778
  }
779
779
  }, g = B(
780
780
  (b) => {
781
781
  if (typeof h != "number")
782
782
  return;
783
- const O = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
783
+ const O = (Q(b) ? b.touches[0].clientX : b.clientX) - h;
784
784
  if (!O)
785
785
  return;
786
- const N = a + O;
787
- !p && Math.abs(N) && v(!0);
788
- const T = N > r.right ? r.right : N < r.left ? r.left : N;
786
+ const D = a + O;
787
+ !p && Math.abs(D) && v(!0);
788
+ const T = D > r.right ? r.right : D < r.left ? r.left : D;
789
789
  s(T), o == null || o({ x: T });
790
790
  },
791
791
  [o, s, p, h]
@@ -802,12 +802,12 @@ const F = /* @__PURE__ */ dr(fr), S = {
802
802
  style: { ...u, transform: `translateX(${p ? i : a}px)` }
803
803
  }) : null;
804
804
  }, hr = ({ checked: e, onChange: n }) => {
805
- var V, Z;
806
- const t = D(null), o = D(null), [c, r] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
805
+ var G, Z;
806
+ const t = N(null), o = N(null), [c, r] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
807
807
  re(() => {
808
808
  var C, z;
809
809
  l(((C = o.current) == null ? void 0 : C.clientHeight) || 0), v(((z = t.current) == null ? void 0 : z.clientHeight) || 0);
810
- }, [(V = o.current) == null ? void 0 : V.clientHeight, (Z = t.current) == null ? void 0 : Z.clientHeight]);
810
+ }, [(G = o.current) == null ? void 0 : G.clientHeight, (Z = t.current) == null ? void 0 : Z.clientHeight]);
811
811
  const f = (p || 0) - h, g = h + f, d = f / 2, b = g / 2, m = typeof c == "number" && (e ? c < b : c > b);
812
812
  return {
813
813
  trackRef: t,
@@ -856,7 +856,7 @@ const F = /* @__PURE__ */ dr(fr), S = {
856
856
  children: /* @__PURE__ */ x(ce, { variant: "paragraph-100", disabled: i.disabled, children: t })
857
857
  }
858
858
  );
859
- return /* @__PURE__ */ K("div", { className: F([n, S[`${P}__container`]]), children: [
859
+ return /* @__PURE__ */ J("div", { className: F([n, S[`${P}__container`]]), children: [
860
860
  t && c === "left" && m(),
861
861
  /* @__PURE__ */ x(
862
862
  lr,
@@ -868,7 +868,7 @@ const F = /* @__PURE__ */ dr(fr), S = {
868
868
  className: S[P],
869
869
  onCheckedChange: d,
870
870
  checked: p,
871
- children: /* @__PURE__ */ K("span", { ref: f, className: S[`${P}__track`], children: [
871
+ children: /* @__PURE__ */ J("span", { ref: f, className: S[`${P}__track`], children: [
872
872
  /* @__PURE__ */ x("span", { className: S[`${P}__checkmark-container`], children: /* @__PURE__ */ x(
873
873
  Pe,
874
874
  {