@purpurds/toggle 3.0.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.
@@ -0,0 +1,900 @@
1
+ import { jsx as w, jsxs as G } from "react/jsx-runtime";
2
+ import { forwardRef as x, Children as y, isValidElement as j, createElement as _, cloneElement as H, useEffect as O, Fragment as ee, useCallback as B, createContext as Z, useMemo as N, useContext as fe, useRef as A, useState as $, useLayoutEffect as te } from "react";
3
+ import "react-dom";
4
+ function ge(e) {
5
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
6
+ }
7
+ var re = { exports: {} };
8
+ /*!
9
+ Copyright (c) 2018 Jed Watson.
10
+ Licensed under the MIT License (MIT), see
11
+ http://jedwatson.github.io/classnames
12
+ */
13
+ (function(e) {
14
+ (function() {
15
+ var n = {}.hasOwnProperty;
16
+ function r() {
17
+ for (var t = "", a = 0; a < arguments.length; a++) {
18
+ var u = arguments[a];
19
+ u && (t = c(t, o.call(this, u)));
20
+ }
21
+ return t;
22
+ }
23
+ function o(t) {
24
+ if (typeof t == "string" || typeof t == "number")
25
+ return this && this[t] || t;
26
+ if (typeof t != "object")
27
+ return "";
28
+ if (Array.isArray(t))
29
+ return r.apply(this, t);
30
+ if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]"))
31
+ return t.toString();
32
+ var a = "";
33
+ for (var u in t)
34
+ n.call(t, u) && t[u] && (a = c(a, this && this[u] || u));
35
+ return a;
36
+ }
37
+ function c(t, a) {
38
+ return a ? t ? t + " " + a : t + a : t;
39
+ }
40
+ e.exports ? (r.default = r, e.exports = r) : window.classNames = r;
41
+ })();
42
+ })(re);
43
+ var he = re.exports;
44
+ const be = /* @__PURE__ */ ge(he), _e = {
45
+ "purpur-icon": "_purpur-icon_8u1lq_1",
46
+ "purpur-icon--xxs": "_purpur-icon--xxs_8u1lq_4",
47
+ "purpur-icon--xs": "_purpur-icon--xs_8u1lq_8",
48
+ "purpur-icon--sm": "_purpur-icon--sm_8u1lq_12",
49
+ "purpur-icon--md": "_purpur-icon--md_8u1lq_16",
50
+ "purpur-icon--lg": "_purpur-icon--lg_8u1lq_20",
51
+ "purpur-icon--xl": "_purpur-icon--xl_8u1lq_24"
52
+ }, ve = {
53
+ name: "checkmark-bold",
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
+ keywords: ["checkmark-bold"],
56
+ category: "utility"
57
+ }, me = be.bind(_e), J = "purpur-icon", $e = "md", ye = (e) => e.filter((n) => Object.keys(n).length >= 1).map((n) => `${n.name}="${n.value}"`).join(" "), we = ({ content: e = "", title: n } = {}) => {
58
+ const r = [
59
+ { name: "xmlns", value: "http://www.w3.org/2000/svg" },
60
+ { name: "fill", value: "currentColor" },
61
+ { name: "viewBox", value: "0 0 24 24" },
62
+ n ? { name: "role", value: "img" } : { name: "aria-hidden", value: "true" }
63
+ ], o = n ? `<title>${n}</title>` : "";
64
+ return `<svg ${ye(r)}>${o}${e}</svg>`;
65
+ }, xe = (e) => e.replace(/<(\/?)svg([^>]*)>/g, "").trim(), Se = ({
66
+ ["data-testid"]: e,
67
+ svg: n,
68
+ allyTitle: r,
69
+ className: o = "",
70
+ size: c = $e,
71
+ ...t
72
+ }) => {
73
+ const a = we({
74
+ content: xe(n.svg),
75
+ title: r
76
+ }), u = me(o, J, `${J}--${c}`);
77
+ return /* @__PURE__ */ w(
78
+ "span",
79
+ {
80
+ "aria-label": r,
81
+ className: u,
82
+ "data-testid": e,
83
+ dangerouslySetInnerHTML: { __html: a },
84
+ ...t
85
+ }
86
+ );
87
+ };
88
+ function q() {
89
+ return q = Object.assign ? Object.assign.bind() : function(e) {
90
+ for (var n = 1; n < arguments.length; n++) {
91
+ var r = arguments[n];
92
+ for (var o in r)
93
+ Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o]);
94
+ }
95
+ return e;
96
+ }, q.apply(this, arguments);
97
+ }
98
+ function E() {
99
+ return E = Object.assign ? Object.assign.bind() : function(e) {
100
+ for (var n = 1; n < arguments.length; n++) {
101
+ var r = arguments[n];
102
+ for (var o in r)
103
+ Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o]);
104
+ }
105
+ return e;
106
+ }, E.apply(this, arguments);
107
+ }
108
+ function Pe(e, n) {
109
+ typeof e == "function" ? e(n) : e != null && (e.current = n);
110
+ }
111
+ function je(...e) {
112
+ return (n) => e.forEach(
113
+ (r) => Pe(r, n)
114
+ );
115
+ }
116
+ const ne = /* @__PURE__ */ x((e, n) => {
117
+ const { children: r, ...o } = e, c = y.toArray(r), t = c.find(Oe);
118
+ if (t) {
119
+ const a = t.props.children, u = c.map((i) => i === t ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ j(a) ? a.props.children : null : i);
120
+ return /* @__PURE__ */ _(F, E({}, o, {
121
+ ref: n
122
+ }), /* @__PURE__ */ j(a) ? /* @__PURE__ */ H(a, void 0, u) : null);
123
+ }
124
+ return /* @__PURE__ */ _(F, E({}, o, {
125
+ ref: n
126
+ }), r);
127
+ });
128
+ ne.displayName = "Slot";
129
+ const F = /* @__PURE__ */ x((e, n) => {
130
+ const { children: r, ...o } = e;
131
+ return /* @__PURE__ */ j(r) ? /* @__PURE__ */ H(r, {
132
+ ...Ae(o, r.props),
133
+ ref: n ? je(n, r.ref) : r.ref
134
+ }) : y.count(r) > 1 ? y.only(null) : null;
135
+ });
136
+ F.displayName = "SlotClone";
137
+ const ke = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
138
+ function Oe(e) {
139
+ return /* @__PURE__ */ j(e) && e.type === ke;
140
+ }
141
+ function Ae(e, n) {
142
+ const r = {
143
+ ...n
144
+ };
145
+ for (const o in n) {
146
+ const c = e[o], t = n[o];
147
+ /^on[A-Z]/.test(o) ? c && t ? r[o] = (...a) => {
148
+ t(...a), c(...a);
149
+ } : c && (r[o] = c) : o === "style" ? r[o] = {
150
+ ...c,
151
+ ...t
152
+ } : o === "className" && (r[o] = [
153
+ c,
154
+ t
155
+ ].filter(Boolean).join(" "));
156
+ }
157
+ return {
158
+ ...e,
159
+ ...r
160
+ };
161
+ }
162
+ const Ce = [
163
+ "a",
164
+ "button",
165
+ "div",
166
+ "form",
167
+ "h2",
168
+ "h3",
169
+ "img",
170
+ "input",
171
+ "label",
172
+ "li",
173
+ "nav",
174
+ "ol",
175
+ "p",
176
+ "span",
177
+ "svg",
178
+ "ul"
179
+ ], De = Ce.reduce((e, n) => {
180
+ const r = /* @__PURE__ */ x((o, c) => {
181
+ const { asChild: t, ...a } = o, u = t ? ne : n;
182
+ return O(() => {
183
+ window[Symbol.for("radix-ui")] = !0;
184
+ }, []), /* @__PURE__ */ _(u, E({}, a, {
185
+ ref: c
186
+ }));
187
+ });
188
+ return r.displayName = `Primitive.${n}`, {
189
+ ...e,
190
+ [n]: r
191
+ };
192
+ }, {}), Ne = /* @__PURE__ */ x((e, n) => /* @__PURE__ */ _(De.label, q({}, e, {
193
+ ref: n,
194
+ onMouseDown: (r) => {
195
+ var o;
196
+ (o = e.onMouseDown) === null || o === void 0 || o.call(e, r), !r.defaultPrevented && r.detail > 1 && r.preventDefault();
197
+ }
198
+ }))), Ee = Ne;
199
+ function Re(e) {
200
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
201
+ }
202
+ var oe = { exports: {} };
203
+ /*!
204
+ Copyright (c) 2018 Jed Watson.
205
+ Licensed under the MIT License (MIT), see
206
+ http://jedwatson.github.io/classnames
207
+ */
208
+ (function(e) {
209
+ (function() {
210
+ var n = {}.hasOwnProperty;
211
+ function r() {
212
+ for (var t = "", a = 0; a < arguments.length; a++) {
213
+ var u = arguments[a];
214
+ u && (t = c(t, o(u)));
215
+ }
216
+ return t;
217
+ }
218
+ function o(t) {
219
+ if (typeof t == "string" || typeof t == "number")
220
+ return t;
221
+ if (typeof t != "object")
222
+ return "";
223
+ if (Array.isArray(t))
224
+ return r.apply(null, t);
225
+ if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]"))
226
+ return t.toString();
227
+ var a = "";
228
+ for (var u in t)
229
+ n.call(t, u) && t[u] && (a = c(a, u));
230
+ return a;
231
+ }
232
+ function c(t, a) {
233
+ return a ? t ? t + " " + a : t + a : t;
234
+ }
235
+ e.exports ? (r.default = r, e.exports = r) : window.classNames = r;
236
+ })();
237
+ })(oe);
238
+ var Me = oe.exports;
239
+ const He = /* @__PURE__ */ Re(Me), K = {
240
+ "purpur-label": "_purpur-label_1jub8_1",
241
+ "purpur-label--disabled": "_purpur-label--disabled_1jub8_9"
242
+ }, Q = "purpur-label", Le = ({
243
+ children: e,
244
+ className: n,
245
+ htmlFor: r,
246
+ "data-testid": o,
247
+ disabled: c,
248
+ ...t
249
+ }) => {
250
+ const a = He([
251
+ n,
252
+ K[Q],
253
+ { [K[`${Q}--disabled`]]: c }
254
+ ]);
255
+ return /* @__PURE__ */ w(Ee, { className: a, "data-testid": o, htmlFor: r, ...t, children: e });
256
+ };
257
+ function Xe(e) {
258
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
259
+ }
260
+ var ae = { exports: {} };
261
+ /*!
262
+ Copyright (c) 2018 Jed Watson.
263
+ Licensed under the MIT License (MIT), see
264
+ http://jedwatson.github.io/classnames
265
+ */
266
+ (function(e) {
267
+ (function() {
268
+ var n = {}.hasOwnProperty;
269
+ function r() {
270
+ for (var t = "", a = 0; a < arguments.length; a++) {
271
+ var u = arguments[a];
272
+ u && (t = c(t, o(u)));
273
+ }
274
+ return t;
275
+ }
276
+ function o(t) {
277
+ if (typeof t == "string" || typeof t == "number")
278
+ return t;
279
+ if (typeof t != "object")
280
+ return "";
281
+ if (Array.isArray(t))
282
+ return r.apply(null, t);
283
+ if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]"))
284
+ return t.toString();
285
+ var a = "";
286
+ for (var u in t)
287
+ n.call(t, u) && t[u] && (a = c(a, u));
288
+ return a;
289
+ }
290
+ function c(t, a) {
291
+ return a ? t ? t + " " + a : t + a : t;
292
+ }
293
+ e.exports ? (r.default = r, e.exports = r) : window.classNames = r;
294
+ })();
295
+ })(ae);
296
+ var Be = ae.exports;
297
+ const Te = /* @__PURE__ */ Xe(Be), L = {
298
+ "purpur-paragraph": "_purpur-paragraph_hwaj6_1",
299
+ "purpur-paragraph--disabled": "_purpur-paragraph--disabled_hwaj6_7",
300
+ "purpur-paragraph--hyphens": "_purpur-paragraph--hyphens_hwaj6_10",
301
+ "purpur-paragraph--paragraph-100": "_purpur-paragraph--paragraph-100_hwaj6_13",
302
+ "purpur-paragraph--paragraph-100-medium": "_purpur-paragraph--paragraph-100-medium_hwaj6_19",
303
+ "purpur-paragraph--paragraph-100-bold": "_purpur-paragraph--paragraph-100-bold_hwaj6_26",
304
+ "purpur-paragraph--paragraph-200": "_purpur-paragraph--paragraph-200_hwaj6_33",
305
+ "purpur-paragraph--preamble-100": "_purpur-paragraph--preamble-100_hwaj6_39",
306
+ "purpur-paragraph--preamble-200": "_purpur-paragraph--preamble-200_hwaj6_45",
307
+ "purpur-paragraph--additional-100": "_purpur-paragraph--additional-100_hwaj6_51",
308
+ "purpur-paragraph--additional-100-medium": "_purpur-paragraph--additional-100-medium_hwaj6_57",
309
+ "purpur-paragraph--overline-100": "_purpur-paragraph--overline-100_hwaj6_64",
310
+ "purpur-paragraph--overline-200": "_purpur-paragraph--overline-200_hwaj6_71"
311
+ }, ze = {
312
+ PARAGRAPH100: "paragraph-100",
313
+ PARAGRAPH100MEDIUM: "paragraph-100-medium",
314
+ PARAGRAPH100BOLD: "paragraph-100-bold",
315
+ PARAGRAPH200: "paragraph-200",
316
+ PREAMBLE100: "preamble-100",
317
+ PREAMBLE200: "preamble-200",
318
+ ADDITIONAL100: "additional-100",
319
+ ADDITIONAL100MEDIUM: "additional-100-medium",
320
+ OVERLINE100: "overline-100",
321
+ OVERLINE200: "overline-200"
322
+ }, X = "purpur-paragraph", Ie = ({
323
+ ["data-testid"]: e,
324
+ children: n,
325
+ className: r = "",
326
+ disabled: o,
327
+ enableHyphenation: c = !1,
328
+ variant: t = ze.PARAGRAPH100,
329
+ ...a
330
+ }) => {
331
+ const u = Te([
332
+ r,
333
+ L[X],
334
+ L[`${X}--${t}`],
335
+ {
336
+ [L[`${X}--hyphens`]]: c,
337
+ [L[`${X}--disabled`]]: o
338
+ }
339
+ ]);
340
+ return /* @__PURE__ */ w("p", { ...a, className: u, "data-testid": e, children: n });
341
+ };
342
+ function R() {
343
+ return R = Object.assign ? Object.assign.bind() : function(e) {
344
+ for (var n = 1; n < arguments.length; n++) {
345
+ var r = arguments[n];
346
+ for (var o in r)
347
+ Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o]);
348
+ }
349
+ return e;
350
+ }, R.apply(this, arguments);
351
+ }
352
+ function qe(e, n, { checkForDefaultPrevented: r = !0 } = {}) {
353
+ return function(c) {
354
+ if (e == null || e(c), r === !1 || !c.defaultPrevented)
355
+ return n == null ? void 0 : n(c);
356
+ };
357
+ }
358
+ function Fe(e, n) {
359
+ typeof e == "function" ? e(n) : e != null && (e.current = n);
360
+ }
361
+ function ce(...e) {
362
+ return (n) => e.forEach(
363
+ (r) => Fe(r, n)
364
+ );
365
+ }
366
+ function Ue(...e) {
367
+ return B(ce(...e), e);
368
+ }
369
+ function Ve(e, n = []) {
370
+ let r = [];
371
+ function o(t, a) {
372
+ const u = /* @__PURE__ */ Z(a), i = r.length;
373
+ r = [
374
+ ...r,
375
+ a
376
+ ];
377
+ function s(l) {
378
+ const { scope: p, children: v, ...f } = l, g = (p == null ? void 0 : p[e][i]) || u, d = N(
379
+ () => f,
380
+ Object.values(f)
381
+ );
382
+ return /* @__PURE__ */ _(g.Provider, {
383
+ value: d
384
+ }, v);
385
+ }
386
+ function h(l, p) {
387
+ const v = (p == null ? void 0 : p[e][i]) || u, f = fe(v);
388
+ if (f)
389
+ return f;
390
+ if (a !== void 0)
391
+ return a;
392
+ throw new Error(`\`${l}\` must be used within \`${t}\``);
393
+ }
394
+ return s.displayName = t + "Provider", [
395
+ s,
396
+ h
397
+ ];
398
+ }
399
+ const c = () => {
400
+ const t = r.map((a) => /* @__PURE__ */ Z(a));
401
+ return function(u) {
402
+ const i = (u == null ? void 0 : u[e]) || t;
403
+ return N(
404
+ () => ({
405
+ [`__scope${e}`]: {
406
+ ...u,
407
+ [e]: i
408
+ }
409
+ }),
410
+ [
411
+ u,
412
+ i
413
+ ]
414
+ );
415
+ };
416
+ };
417
+ return c.scopeName = e, [
418
+ o,
419
+ We(c, ...n)
420
+ ];
421
+ }
422
+ function We(...e) {
423
+ const n = e[0];
424
+ if (e.length === 1)
425
+ return n;
426
+ const r = () => {
427
+ const o = e.map(
428
+ (c) => ({
429
+ useScope: c(),
430
+ scopeName: c.scopeName
431
+ })
432
+ );
433
+ return function(t) {
434
+ const a = o.reduce((u, { useScope: i, scopeName: s }) => {
435
+ const l = i(t)[`__scope${s}`];
436
+ return {
437
+ ...u,
438
+ ...l
439
+ };
440
+ }, {});
441
+ return N(
442
+ () => ({
443
+ [`__scope${n.scopeName}`]: a
444
+ }),
445
+ [
446
+ a
447
+ ]
448
+ );
449
+ };
450
+ };
451
+ return r.scopeName = n.scopeName, r;
452
+ }
453
+ function ue(e) {
454
+ const n = A(e);
455
+ return O(() => {
456
+ n.current = e;
457
+ }), N(
458
+ () => (...r) => {
459
+ var o;
460
+ return (o = n.current) === null || o === void 0 ? void 0 : o.call(n, ...r);
461
+ },
462
+ []
463
+ );
464
+ }
465
+ function Ge({ prop: e, defaultProp: n, onChange: r = () => {
466
+ } }) {
467
+ const [o, c] = Ze({
468
+ defaultProp: n,
469
+ onChange: r
470
+ }), t = e !== void 0, a = t ? e : o, u = ue(r), i = B((s) => {
471
+ if (t) {
472
+ const l = typeof s == "function" ? s(e) : s;
473
+ l !== e && u(l);
474
+ } else
475
+ c(s);
476
+ }, [
477
+ t,
478
+ e,
479
+ c,
480
+ u
481
+ ]);
482
+ return [
483
+ a,
484
+ i
485
+ ];
486
+ }
487
+ function Ze({ defaultProp: e, onChange: n }) {
488
+ const r = $(e), [o] = r, c = A(o), t = ue(n);
489
+ return O(() => {
490
+ c.current !== o && (t(o), c.current = o);
491
+ }, [
492
+ o,
493
+ c,
494
+ t
495
+ ]), r;
496
+ }
497
+ function Je(e) {
498
+ const n = A({
499
+ value: e,
500
+ previous: e
501
+ });
502
+ return N(() => (n.current.value !== e && (n.current.previous = n.current.value, n.current.value = e), n.current.previous), [
503
+ e
504
+ ]);
505
+ }
506
+ const Ke = globalThis != null && globalThis.document ? te : () => {
507
+ };
508
+ function Qe(e) {
509
+ const [n, r] = $(void 0);
510
+ return Ke(() => {
511
+ if (e) {
512
+ r({
513
+ width: e.offsetWidth,
514
+ height: e.offsetHeight
515
+ });
516
+ const o = new ResizeObserver((c) => {
517
+ if (!Array.isArray(c) || !c.length)
518
+ return;
519
+ const t = c[0];
520
+ let a, u;
521
+ if ("borderBoxSize" in t) {
522
+ const i = t.borderBoxSize, s = Array.isArray(i) ? i[0] : i;
523
+ a = s.inlineSize, u = s.blockSize;
524
+ } else
525
+ a = e.offsetWidth, u = e.offsetHeight;
526
+ r({
527
+ width: a,
528
+ height: u
529
+ });
530
+ });
531
+ return o.observe(e, {
532
+ box: "border-box"
533
+ }), () => o.unobserve(e);
534
+ } else
535
+ r(void 0);
536
+ }, [
537
+ e
538
+ ]), n;
539
+ }
540
+ function M() {
541
+ return M = Object.assign ? Object.assign.bind() : function(e) {
542
+ for (var n = 1; n < arguments.length; n++) {
543
+ var r = arguments[n];
544
+ for (var o in r)
545
+ Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o]);
546
+ }
547
+ return e;
548
+ }, M.apply(this, arguments);
549
+ }
550
+ const ie = /* @__PURE__ */ x((e, n) => {
551
+ const { children: r, ...o } = e, c = y.toArray(r), t = c.find(et);
552
+ if (t) {
553
+ const a = t.props.children, u = c.map((i) => i === t ? y.count(a) > 1 ? y.only(null) : /* @__PURE__ */ j(a) ? a.props.children : null : i);
554
+ return /* @__PURE__ */ _(U, M({}, o, {
555
+ ref: n
556
+ }), /* @__PURE__ */ j(a) ? /* @__PURE__ */ H(a, void 0, u) : null);
557
+ }
558
+ return /* @__PURE__ */ _(U, M({}, o, {
559
+ ref: n
560
+ }), r);
561
+ });
562
+ ie.displayName = "Slot";
563
+ const U = /* @__PURE__ */ x((e, n) => {
564
+ const { children: r, ...o } = e;
565
+ return /* @__PURE__ */ j(r) ? /* @__PURE__ */ H(r, {
566
+ ...tt(o, r.props),
567
+ ref: n ? ce(n, r.ref) : r.ref
568
+ }) : y.count(r) > 1 ? y.only(null) : null;
569
+ });
570
+ U.displayName = "SlotClone";
571
+ const Ye = ({ children: e }) => /* @__PURE__ */ _(ee, null, e);
572
+ function et(e) {
573
+ return /* @__PURE__ */ j(e) && e.type === Ye;
574
+ }
575
+ function tt(e, n) {
576
+ const r = {
577
+ ...n
578
+ };
579
+ for (const o in n) {
580
+ const c = e[o], t = n[o];
581
+ /^on[A-Z]/.test(o) ? c && t ? r[o] = (...u) => {
582
+ t(...u), c(...u);
583
+ } : c && (r[o] = c) : o === "style" ? r[o] = {
584
+ ...c,
585
+ ...t
586
+ } : o === "className" && (r[o] = [
587
+ c,
588
+ t
589
+ ].filter(Boolean).join(" "));
590
+ }
591
+ return {
592
+ ...e,
593
+ ...r
594
+ };
595
+ }
596
+ const rt = [
597
+ "a",
598
+ "button",
599
+ "div",
600
+ "form",
601
+ "h2",
602
+ "h3",
603
+ "img",
604
+ "input",
605
+ "label",
606
+ "li",
607
+ "nav",
608
+ "ol",
609
+ "p",
610
+ "span",
611
+ "svg",
612
+ "ul"
613
+ ], se = rt.reduce((e, n) => {
614
+ const r = /* @__PURE__ */ x((o, c) => {
615
+ const { asChild: t, ...a } = o, u = t ? ie : n;
616
+ return O(() => {
617
+ window[Symbol.for("radix-ui")] = !0;
618
+ }, []), /* @__PURE__ */ _(u, M({}, a, {
619
+ ref: c
620
+ }));
621
+ });
622
+ return r.displayName = `Primitive.${n}`, {
623
+ ...e,
624
+ [n]: r
625
+ };
626
+ }, {}), le = "Switch", [nt, yt] = Ve(le), [ot, at] = nt(le), ct = /* @__PURE__ */ x((e, n) => {
627
+ const { __scopeSwitch: r, name: o, checked: c, defaultChecked: t, required: a, disabled: u, value: i = "on", onCheckedChange: s, ...h } = e, [l, p] = $(null), v = Ue(
628
+ n,
629
+ (m) => p(m)
630
+ ), f = A(!1), g = l ? !!l.closest("form") : !0, [d = !1, b] = Ge({
631
+ prop: c,
632
+ defaultProp: t,
633
+ onChange: s
634
+ });
635
+ return /* @__PURE__ */ _(ot, {
636
+ scope: r,
637
+ checked: d,
638
+ disabled: u
639
+ }, /* @__PURE__ */ _(se.button, R({
640
+ type: "button",
641
+ role: "switch",
642
+ "aria-checked": d,
643
+ "aria-required": a,
644
+ "data-state": pe(d),
645
+ "data-disabled": u ? "" : void 0,
646
+ disabled: u,
647
+ value: i
648
+ }, h, {
649
+ ref: v,
650
+ onClick: qe(e.onClick, (m) => {
651
+ b(
652
+ (k) => !k
653
+ ), g && (f.current = m.isPropagationStopped(), f.current || m.stopPropagation());
654
+ })
655
+ })), g && /* @__PURE__ */ _(st, {
656
+ control: l,
657
+ bubbles: !f.current,
658
+ name: o,
659
+ value: i,
660
+ checked: d,
661
+ required: a,
662
+ disabled: u,
663
+ style: {
664
+ transform: "translateX(-100%)"
665
+ }
666
+ }));
667
+ }), ut = "SwitchThumb", it = /* @__PURE__ */ x((e, n) => {
668
+ const { __scopeSwitch: r, ...o } = e, c = at(ut, r);
669
+ return /* @__PURE__ */ _(se.span, R({
670
+ "data-state": pe(c.checked),
671
+ "data-disabled": c.disabled ? "" : void 0
672
+ }, o, {
673
+ ref: n
674
+ }));
675
+ }), st = (e) => {
676
+ const { control: n, checked: r, bubbles: o = !0, ...c } = e, t = A(null), a = Je(r), u = Qe(n);
677
+ return O(() => {
678
+ const i = t.current, s = window.HTMLInputElement.prototype, l = Object.getOwnPropertyDescriptor(s, "checked").set;
679
+ if (a !== r && l) {
680
+ const p = new Event("click", {
681
+ bubbles: o
682
+ });
683
+ l.call(i, r), i.dispatchEvent(p);
684
+ }
685
+ }, [
686
+ a,
687
+ r,
688
+ o
689
+ ]), /* @__PURE__ */ _("input", R({
690
+ type: "checkbox",
691
+ "aria-hidden": !0,
692
+ defaultChecked: r
693
+ }, c, {
694
+ tabIndex: -1,
695
+ ref: t,
696
+ style: {
697
+ ...e.style,
698
+ ...u,
699
+ position: "absolute",
700
+ pointerEvents: "none",
701
+ opacity: 0,
702
+ margin: 0
703
+ }
704
+ }));
705
+ };
706
+ function pe(e) {
707
+ return e ? "checked" : "unchecked";
708
+ }
709
+ const lt = ct, pt = it;
710
+ function dt(e) {
711
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
712
+ }
713
+ var de = { exports: {} };
714
+ /*!
715
+ Copyright (c) 2018 Jed Watson.
716
+ Licensed under the MIT License (MIT), see
717
+ http://jedwatson.github.io/classnames
718
+ */
719
+ (function(e) {
720
+ (function() {
721
+ var n = {}.hasOwnProperty;
722
+ function r() {
723
+ for (var t = "", a = 0; a < arguments.length; a++) {
724
+ var u = arguments[a];
725
+ u && (t = c(t, o(u)));
726
+ }
727
+ return t;
728
+ }
729
+ function o(t) {
730
+ if (typeof t == "string" || typeof t == "number")
731
+ return t;
732
+ if (typeof t != "object")
733
+ return "";
734
+ if (Array.isArray(t))
735
+ return r.apply(null, t);
736
+ if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]"))
737
+ return t.toString();
738
+ var a = "";
739
+ for (var u in t)
740
+ n.call(t, u) && t[u] && (a = c(a, u));
741
+ return a;
742
+ }
743
+ function c(t, a) {
744
+ return a ? t ? t + " " + a : t + a : t;
745
+ }
746
+ e.exports ? (r.default = r, e.exports = r) : window.classNames = r;
747
+ })();
748
+ })(de);
749
+ var ft = de.exports;
750
+ const I = /* @__PURE__ */ dt(ft), S = {
751
+ "purpur-toggle": "_purpur-toggle_1xng6_1",
752
+ "purpur-toggle__track": "_purpur-toggle__track_1xng6_7",
753
+ "purpur-toggle__checkmark-container": "_purpur-toggle__checkmark-container_1xng6_45",
754
+ "purpur-toggle__thumb": "_purpur-toggle__thumb_1xng6_60",
755
+ "purpur-toggle__thumb--dragging": "_purpur-toggle__thumb--dragging_1xng6_80",
756
+ "purpur-toggle__checkmark": "_purpur-toggle__checkmark_1xng6_45",
757
+ "purpur-toggle__label--right": "_purpur-toggle__label--right_1xng6_100",
758
+ "purpur-toggle__label--left": "_purpur-toggle__label--left_1xng6_103",
759
+ "purpur-toggle__container": "_purpur-toggle__container_1xng6_106"
760
+ }, Y = (e) => e && "touches" in e, gt = ({
761
+ children: e,
762
+ disabled: n,
763
+ onStart: r,
764
+ onDrag: o,
765
+ onStop: c,
766
+ bounds: t,
767
+ position: a,
768
+ style: u
769
+ }) => {
770
+ const [i, s] = $(void 0), [h, l] = $(void 0), [p, v] = $(!1), f = (b) => {
771
+ if (!n) {
772
+ b.preventDefault();
773
+ const m = Y(b.nativeEvent) ? b.nativeEvent.touches[0].clientX : b.nativeEvent.clientX;
774
+ l(m), r == null || r();
775
+ }
776
+ }, g = B(
777
+ (b) => {
778
+ if (typeof h != "number")
779
+ return;
780
+ const k = (Y(b) ? b.touches[0].clientX : b.clientX) - h;
781
+ if (!k)
782
+ return;
783
+ const C = a + k;
784
+ !p && Math.abs(C) && v(!0);
785
+ const T = C > t.right ? t.right : C < t.left ? t.left : C;
786
+ s(T), o == null || o({ x: T });
787
+ },
788
+ [o, s, p, h]
789
+ ), d = B(() => {
790
+ l(void 0), s(void 0), v(!1), c == null || c();
791
+ }, [c, l]);
792
+ return O(() => (window.addEventListener("mousemove", g), window.addEventListener("touchmove", g), () => {
793
+ window.removeEventListener("mousemove", g), window.removeEventListener("touchmove", g);
794
+ }), [g]), O(() => (window.addEventListener("mouseup", d), window.addEventListener("touchend", d), () => {
795
+ window.removeEventListener("mouseup", d), window.removeEventListener("touchend", d);
796
+ }), [d]), j(e) ? H(y.only(e), {
797
+ onMouseDown: f,
798
+ onTouchStart: f,
799
+ style: { ...u, transform: `translateX(${p ? i : a}px)` }
800
+ }) : null;
801
+ }, ht = ({ checked: e, onChange: n }) => {
802
+ var V, W;
803
+ const r = A(null), o = A(null), [c, t] = $(void 0), [a, u] = $(!1), [i, s] = $(0), [h, l] = $(0), [p, v] = $(0);
804
+ te(() => {
805
+ var D, z;
806
+ l(((D = o.current) == null ? void 0 : D.clientHeight) || 0), v(((z = r.current) == null ? void 0 : z.clientHeight) || 0);
807
+ }, [(V = o.current) == null ? void 0 : V.clientHeight, (W = r.current) == null ? void 0 : W.clientHeight]);
808
+ const f = (p || 0) - h, g = h + f, d = f / 2, b = g / 2, m = typeof c == "number" && (e ? c < b : c > b);
809
+ return {
810
+ trackRef: r,
811
+ thumbRef: o,
812
+ isDragging: a,
813
+ bounds: { left: d, right: g },
814
+ position: e ? g : d,
815
+ onDrag: ({ x: D }) => {
816
+ t(D), Math.abs((e ? g : d) - D) > 2 && u(!0);
817
+ },
818
+ onStop: () => {
819
+ u(!1), a && s(Date.now()), m && (n == null || n(!e));
820
+ },
821
+ onChangeWithDrag: () => {
822
+ Date.now() - i > 50 && (n == null || n(!e)), t(void 0);
823
+ }
824
+ };
825
+ }, P = "purpur-toggle", bt = ({
826
+ ["data-testid"]: e,
827
+ className: n,
828
+ label: r,
829
+ onChange: o,
830
+ labelPosition: c = "right",
831
+ checked: t,
832
+ disableDrag: a,
833
+ defaultChecked: u,
834
+ ...i
835
+ }, s) => {
836
+ const [h, l] = $(
837
+ typeof t == "boolean" ? t : !!u
838
+ ), p = !!(typeof t == "boolean" ? t : h), { thumbRef: v, trackRef: f, isDragging: g, onChangeWithDrag: d, ...b } = ht({
839
+ checked: p,
840
+ onChange: (k) => {
841
+ i.disabled || (o == null || o(k), l(k));
842
+ }
843
+ }), m = () => /* @__PURE__ */ w(
844
+ Le,
845
+ {
846
+ htmlFor: i.id,
847
+ "data-testid": e && `${e}-label`,
848
+ disabled: i.disabled,
849
+ className: I(
850
+ S[`${P}__label`],
851
+ S[`${P}__label--${c}`]
852
+ ),
853
+ children: /* @__PURE__ */ w(Ie, { variant: "paragraph-100", disabled: i.disabled, children: r })
854
+ }
855
+ );
856
+ return /* @__PURE__ */ G("div", { className: I([n, S[`${P}__container`]]), children: [
857
+ r && c === "left" && m(),
858
+ /* @__PURE__ */ w(
859
+ lt,
860
+ {
861
+ ...i,
862
+ ref: s,
863
+ id: i.id,
864
+ "data-testid": e,
865
+ className: S[P],
866
+ onCheckedChange: d,
867
+ checked: p,
868
+ children: /* @__PURE__ */ G("span", { ref: f, className: S[`${P}__track`], children: [
869
+ /* @__PURE__ */ w("span", { className: S[`${P}__checkmark-container`], children: /* @__PURE__ */ w(
870
+ Se,
871
+ {
872
+ className: S[`${P}__checkmark`],
873
+ svg: ve,
874
+ size: "xxs"
875
+ }
876
+ ) }),
877
+ /* @__PURE__ */ w(gt, { disabled: a, ...b, children: /* @__PURE__ */ w(
878
+ pt,
879
+ {
880
+ ref: v,
881
+ "data-testid": e && `${e}-thumb`,
882
+ className: I([
883
+ S[`${P}__thumb`],
884
+ {
885
+ [S[`${P}__thumb--dragging`]]: g
886
+ }
887
+ ])
888
+ }
889
+ ) })
890
+ ] })
891
+ }
892
+ ),
893
+ r && c === "right" && m()
894
+ ] });
895
+ }, _t = x(bt);
896
+ _t.displayName = "Toggle";
897
+ export {
898
+ _t as Toggle
899
+ };
900
+ //# sourceMappingURL=toggle.es.js.map