@purpurds/tabs 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,988 @@
1
+ import { jsx as N, jsxs as J } from "react/jsx-runtime";
2
+ import * as fe from "react";
3
+ import E, { createContext as ee, useMemo as Y, createElement as g, useContext as pe, useCallback as U, forwardRef as T, Children as P, isValidElement as G, cloneElement as oe, Fragment as Pe, useLayoutEffect as Re, useEffect as R, useRef as M, useState as D, useReducer as Me } from "react";
4
+ import { flushSync as Oe } from "react-dom";
5
+ function Fe(e) {
6
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
7
+ }
8
+ var be = { exports: {} };
9
+ /*!
10
+ Copyright (c) 2018 Jed Watson.
11
+ Licensed under the MIT License (MIT), see
12
+ http://jedwatson.github.io/classnames
13
+ */
14
+ (function(e) {
15
+ (function() {
16
+ var t = {}.hasOwnProperty;
17
+ function n() {
18
+ for (var r = "", c = 0; c < arguments.length; c++) {
19
+ var a = arguments[c];
20
+ a && (r = s(r, o.call(this, a)));
21
+ }
22
+ return r;
23
+ }
24
+ function o(r) {
25
+ if (typeof r == "string" || typeof r == "number")
26
+ return this && this[r] || r;
27
+ if (typeof r != "object")
28
+ return "";
29
+ if (Array.isArray(r))
30
+ return n.apply(this, r);
31
+ if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
32
+ return r.toString();
33
+ var c = "";
34
+ for (var a in r)
35
+ t.call(r, a) && r[a] && (c = s(c, this && this[a] || a));
36
+ return c;
37
+ }
38
+ function s(r, c) {
39
+ return c ? r ? r + " " + c : r + c : r;
40
+ }
41
+ e.exports ? (n.default = n, e.exports = n) : window.classNames = n;
42
+ })();
43
+ })(be);
44
+ var De = be.exports;
45
+ const qe = /* @__PURE__ */ Fe(De), Le = {
46
+ "purpur-icon": "_purpur-icon_8u1lq_1",
47
+ "purpur-icon--xxs": "_purpur-icon--xxs_8u1lq_4",
48
+ "purpur-icon--xs": "_purpur-icon--xs_8u1lq_8",
49
+ "purpur-icon--sm": "_purpur-icon--sm_8u1lq_12",
50
+ "purpur-icon--md": "_purpur-icon--md_8u1lq_16",
51
+ "purpur-icon--lg": "_purpur-icon--lg_8u1lq_20",
52
+ "purpur-icon--xl": "_purpur-icon--xl_8u1lq_24"
53
+ }, Ue = {
54
+ name: "chevron-left",
55
+ svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M16.175 3.905a.9.9 0 0 1-.08 1.27L8.36 12l7.736 6.825a.9.9 0 0 1-1.191 1.35l-8.5-7.5a.9.9 0 0 1 0-1.35l8.5-7.5a.9.9 0 0 1 1.27.08Z" clip-rule="evenodd"/></svg>',
56
+ keywords: ["chevron-left"],
57
+ category: "utility"
58
+ }, Ve = {
59
+ name: "chevron-right",
60
+ svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M7.809 3.924a.9.9 0 0 0 .115 1.267L16.094 12l-8.17 6.809a.9.9 0 0 0 1.152 1.382l9-7.5a.9.9 0 0 0 0-1.382l-9-7.5a.9.9 0 0 0-1.267.115Z" clip-rule="evenodd"/></svg>',
61
+ keywords: ["chevron-right"],
62
+ category: "utility"
63
+ }, Be = qe.bind(Le), le = "purpur-icon", je = "md", ke = (e) => e.filter((t) => Object.keys(t).length >= 1).map((t) => `${t.name}="${t.value}"`).join(" "), Ge = ({ content: e = "", title: t } = {}) => {
64
+ const n = [
65
+ { name: "xmlns", value: "http://www.w3.org/2000/svg" },
66
+ { name: "fill", value: "currentColor" },
67
+ { name: "viewBox", value: "0 0 24 24" },
68
+ t ? { name: "role", value: "img" } : { name: "aria-hidden", value: "true" }
69
+ ], o = t ? `<title>${t}</title>` : "";
70
+ return `<svg ${ke(n)}>${o}${e}</svg>`;
71
+ }, Ke = (e) => e.replace(/<(\/?)svg([^>]*)>/g, "").trim(), ze = ({
72
+ ["data-testid"]: e,
73
+ svg: t,
74
+ allyTitle: n,
75
+ className: o = "",
76
+ size: s = je,
77
+ ...r
78
+ }) => {
79
+ const c = Ge({
80
+ content: Ke(t.svg),
81
+ title: n
82
+ }), a = Be(o, le, `${le}--${s}`);
83
+ return /* @__PURE__ */ N(
84
+ "span",
85
+ {
86
+ "aria-label": n,
87
+ className: a,
88
+ "data-testid": e,
89
+ dangerouslySetInnerHTML: { __html: c },
90
+ ...r
91
+ }
92
+ );
93
+ };
94
+ function y() {
95
+ return y = Object.assign ? Object.assign.bind() : function(e) {
96
+ for (var t = 1; t < arguments.length; t++) {
97
+ var n = arguments[t];
98
+ for (var o in n)
99
+ Object.prototype.hasOwnProperty.call(n, o) && (e[o] = n[o]);
100
+ }
101
+ return e;
102
+ }, y.apply(this, arguments);
103
+ }
104
+ function O(e, t, { checkForDefaultPrevented: n = !0 } = {}) {
105
+ return function(s) {
106
+ if (e == null || e(s), n === !1 || !s.defaultPrevented)
107
+ return t == null ? void 0 : t(s);
108
+ };
109
+ }
110
+ function ce(e, t = []) {
111
+ let n = [];
112
+ function o(r, c) {
113
+ const a = /* @__PURE__ */ ee(c), u = n.length;
114
+ n = [
115
+ ...n,
116
+ c
117
+ ];
118
+ function i(l) {
119
+ const { scope: $, children: m, ...d } = l, b = ($ == null ? void 0 : $[e][u]) || a, _ = Y(
120
+ () => d,
121
+ Object.values(d)
122
+ );
123
+ return /* @__PURE__ */ g(b.Provider, {
124
+ value: _
125
+ }, m);
126
+ }
127
+ function f(l, $) {
128
+ const m = ($ == null ? void 0 : $[e][u]) || a, d = pe(m);
129
+ if (d)
130
+ return d;
131
+ if (c !== void 0)
132
+ return c;
133
+ throw new Error(`\`${l}\` must be used within \`${r}\``);
134
+ }
135
+ return i.displayName = r + "Provider", [
136
+ i,
137
+ f
138
+ ];
139
+ }
140
+ const s = () => {
141
+ const r = n.map((c) => /* @__PURE__ */ ee(c));
142
+ return function(a) {
143
+ const u = (a == null ? void 0 : a[e]) || r;
144
+ return Y(
145
+ () => ({
146
+ [`__scope${e}`]: {
147
+ ...a,
148
+ [e]: u
149
+ }
150
+ }),
151
+ [
152
+ a,
153
+ u
154
+ ]
155
+ );
156
+ };
157
+ };
158
+ return s.scopeName = e, [
159
+ o,
160
+ We(s, ...t)
161
+ ];
162
+ }
163
+ function We(...e) {
164
+ const t = e[0];
165
+ if (e.length === 1)
166
+ return t;
167
+ const n = () => {
168
+ const o = e.map(
169
+ (s) => ({
170
+ useScope: s(),
171
+ scopeName: s.scopeName
172
+ })
173
+ );
174
+ return function(r) {
175
+ const c = o.reduce((a, { useScope: u, scopeName: i }) => {
176
+ const l = u(r)[`__scope${i}`];
177
+ return {
178
+ ...a,
179
+ ...l
180
+ };
181
+ }, {});
182
+ return Y(
183
+ () => ({
184
+ [`__scope${t.scopeName}`]: c
185
+ }),
186
+ [
187
+ c
188
+ ]
189
+ );
190
+ };
191
+ };
192
+ return n.scopeName = t.scopeName, n;
193
+ }
194
+ function Ye(e, t) {
195
+ typeof e == "function" ? e(t) : e != null && (e.current = t);
196
+ }
197
+ function $e(...e) {
198
+ return (t) => e.forEach(
199
+ (n) => Ye(n, t)
200
+ );
201
+ }
202
+ function Z(...e) {
203
+ return U($e(...e), e);
204
+ }
205
+ const H = /* @__PURE__ */ T((e, t) => {
206
+ const { children: n, ...o } = e, s = P.toArray(n), r = s.find(He);
207
+ if (r) {
208
+ const c = r.props.children, a = s.map((u) => u === r ? P.count(c) > 1 ? P.only(null) : /* @__PURE__ */ G(c) ? c.props.children : null : u);
209
+ return /* @__PURE__ */ g(te, y({}, o, {
210
+ ref: t
211
+ }), /* @__PURE__ */ G(c) ? /* @__PURE__ */ oe(c, void 0, a) : null);
212
+ }
213
+ return /* @__PURE__ */ g(te, y({}, o, {
214
+ ref: t
215
+ }), n);
216
+ });
217
+ H.displayName = "Slot";
218
+ const te = /* @__PURE__ */ T((e, t) => {
219
+ const { children: n, ...o } = e;
220
+ return /* @__PURE__ */ G(n) ? /* @__PURE__ */ oe(n, {
221
+ ...Xe(o, n.props),
222
+ ref: t ? $e(t, n.ref) : n.ref
223
+ }) : P.count(n) > 1 ? P.only(null) : null;
224
+ });
225
+ te.displayName = "SlotClone";
226
+ const Ze = ({ children: e }) => /* @__PURE__ */ g(Pe, null, e);
227
+ function He(e) {
228
+ return /* @__PURE__ */ G(e) && e.type === Ze;
229
+ }
230
+ function Xe(e, t) {
231
+ const n = {
232
+ ...t
233
+ };
234
+ for (const o in t) {
235
+ const s = e[o], r = t[o];
236
+ /^on[A-Z]/.test(o) ? s && r ? n[o] = (...a) => {
237
+ r(...a), s(...a);
238
+ } : s && (n[o] = s) : o === "style" ? n[o] = {
239
+ ...s,
240
+ ...r
241
+ } : o === "className" && (n[o] = [
242
+ s,
243
+ r
244
+ ].filter(Boolean).join(" "));
245
+ }
246
+ return {
247
+ ...e,
248
+ ...n
249
+ };
250
+ }
251
+ function Je(e) {
252
+ const t = e + "CollectionProvider", [n, o] = ce(t), [s, r] = n(t, {
253
+ collectionRef: {
254
+ current: null
255
+ },
256
+ itemMap: /* @__PURE__ */ new Map()
257
+ }), c = (m) => {
258
+ const { scope: d, children: b } = m, _ = E.useRef(null), v = E.useRef(/* @__PURE__ */ new Map()).current;
259
+ return /* @__PURE__ */ E.createElement(s, {
260
+ scope: d,
261
+ itemMap: v,
262
+ collectionRef: _
263
+ }, b);
264
+ }, a = e + "CollectionSlot", u = /* @__PURE__ */ E.forwardRef((m, d) => {
265
+ const { scope: b, children: _ } = m, v = r(a, b), h = Z(d, v.collectionRef);
266
+ return /* @__PURE__ */ E.createElement(H, {
267
+ ref: h
268
+ }, _);
269
+ }), i = e + "CollectionItemSlot", f = "data-radix-collection-item", l = /* @__PURE__ */ E.forwardRef((m, d) => {
270
+ const { scope: b, children: _, ...v } = m, h = E.useRef(null), F = Z(d, h), A = r(i, b);
271
+ return E.useEffect(() => (A.itemMap.set(h, {
272
+ ref: h,
273
+ ...v
274
+ }), () => void A.itemMap.delete(h))), /* @__PURE__ */ E.createElement(H, {
275
+ [f]: "",
276
+ ref: F
277
+ }, _);
278
+ });
279
+ function $(m) {
280
+ const d = r(e + "CollectionConsumer", m);
281
+ return E.useCallback(() => {
282
+ const _ = d.collectionRef.current;
283
+ if (!_)
284
+ return [];
285
+ const v = Array.from(_.querySelectorAll(`[${f}]`));
286
+ return Array.from(d.itemMap.values()).sort(
287
+ (A, V) => v.indexOf(A.ref.current) - v.indexOf(V.ref.current)
288
+ );
289
+ }, [
290
+ d.collectionRef,
291
+ d.itemMap
292
+ ]);
293
+ }
294
+ return [
295
+ {
296
+ Provider: c,
297
+ Slot: u,
298
+ ItemSlot: l
299
+ },
300
+ $,
301
+ o
302
+ ];
303
+ }
304
+ const ne = globalThis != null && globalThis.document ? Re : () => {
305
+ }, Qe = fe.useId || (() => {
306
+ });
307
+ let et = 0;
308
+ function ve(e) {
309
+ const [t, n] = fe.useState(Qe());
310
+ return ne(() => {
311
+ e || n(
312
+ (o) => o ?? String(et++)
313
+ );
314
+ }, [
315
+ e
316
+ ]), e || (t ? `radix-${t}` : "");
317
+ }
318
+ const tt = [
319
+ "a",
320
+ "button",
321
+ "div",
322
+ "form",
323
+ "h2",
324
+ "h3",
325
+ "img",
326
+ "input",
327
+ "label",
328
+ "li",
329
+ "nav",
330
+ "ol",
331
+ "p",
332
+ "span",
333
+ "svg",
334
+ "ul"
335
+ ], k = tt.reduce((e, t) => {
336
+ const n = /* @__PURE__ */ T((o, s) => {
337
+ const { asChild: r, ...c } = o, a = r ? H : t;
338
+ return R(() => {
339
+ window[Symbol.for("radix-ui")] = !0;
340
+ }, []), /* @__PURE__ */ g(a, y({}, c, {
341
+ ref: s
342
+ }));
343
+ });
344
+ return n.displayName = `Primitive.${t}`, {
345
+ ...e,
346
+ [t]: n
347
+ };
348
+ }, {});
349
+ function se(e) {
350
+ const t = M(e);
351
+ return R(() => {
352
+ t.current = e;
353
+ }), Y(
354
+ () => (...n) => {
355
+ var o;
356
+ return (o = t.current) === null || o === void 0 ? void 0 : o.call(t, ...n);
357
+ },
358
+ []
359
+ );
360
+ }
361
+ function me({ prop: e, defaultProp: t, onChange: n = () => {
362
+ } }) {
363
+ const [o, s] = nt({
364
+ defaultProp: t,
365
+ onChange: n
366
+ }), r = e !== void 0, c = r ? e : o, a = se(n), u = U((i) => {
367
+ if (r) {
368
+ const l = typeof i == "function" ? i(e) : i;
369
+ l !== e && a(l);
370
+ } else
371
+ s(i);
372
+ }, [
373
+ r,
374
+ e,
375
+ s,
376
+ a
377
+ ]);
378
+ return [
379
+ c,
380
+ u
381
+ ];
382
+ }
383
+ function nt({ defaultProp: e, onChange: t }) {
384
+ const n = D(e), [o] = n, s = M(o), r = se(t);
385
+ return R(() => {
386
+ s.current !== o && (r(o), s.current = o);
387
+ }, [
388
+ o,
389
+ s,
390
+ r
391
+ ]), n;
392
+ }
393
+ const rt = /* @__PURE__ */ ee(void 0);
394
+ function _e(e) {
395
+ const t = pe(rt);
396
+ return e || t || "ltr";
397
+ }
398
+ const Q = "rovingFocusGroup.onEntryFocus", ot = {
399
+ bubbles: !1,
400
+ cancelable: !0
401
+ }, ae = "RovingFocusGroup", [re, he, ct] = Je(ae), [st, ge] = ce(ae, [
402
+ ct
403
+ ]), [at, it] = st(ae), ut = /* @__PURE__ */ T((e, t) => /* @__PURE__ */ g(re.Provider, {
404
+ scope: e.__scopeRovingFocusGroup
405
+ }, /* @__PURE__ */ g(re.Slot, {
406
+ scope: e.__scopeRovingFocusGroup
407
+ }, /* @__PURE__ */ g(lt, y({}, e, {
408
+ ref: t
409
+ }))))), lt = /* @__PURE__ */ T((e, t) => {
410
+ const { __scopeRovingFocusGroup: n, orientation: o, loop: s = !1, dir: r, currentTabStopId: c, defaultCurrentTabStopId: a, onCurrentTabStopIdChange: u, onEntryFocus: i, ...f } = e, l = M(null), $ = Z(t, l), m = _e(r), [d = null, b] = me({
411
+ prop: c,
412
+ defaultProp: a,
413
+ onChange: u
414
+ }), [_, v] = D(!1), h = se(i), F = he(n), A = M(!1), [V, B] = D(0);
415
+ return R(() => {
416
+ const x = l.current;
417
+ if (x)
418
+ return x.addEventListener(Q, h), () => x.removeEventListener(Q, h);
419
+ }, [
420
+ h
421
+ ]), /* @__PURE__ */ g(at, {
422
+ scope: n,
423
+ orientation: o,
424
+ dir: m,
425
+ loop: s,
426
+ currentTabStopId: d,
427
+ onItemFocus: U(
428
+ (x) => b(x),
429
+ [
430
+ b
431
+ ]
432
+ ),
433
+ onItemShiftTab: U(
434
+ () => v(!0),
435
+ []
436
+ ),
437
+ onFocusableItemAdd: U(
438
+ () => B(
439
+ (x) => x + 1
440
+ ),
441
+ []
442
+ ),
443
+ onFocusableItemRemove: U(
444
+ () => B(
445
+ (x) => x - 1
446
+ ),
447
+ []
448
+ )
449
+ }, /* @__PURE__ */ g(k.div, y({
450
+ tabIndex: _ || V === 0 ? -1 : 0,
451
+ "data-orientation": o
452
+ }, f, {
453
+ ref: $,
454
+ style: {
455
+ outline: "none",
456
+ ...e.style
457
+ },
458
+ onMouseDown: O(e.onMouseDown, () => {
459
+ A.current = !0;
460
+ }),
461
+ onFocus: O(e.onFocus, (x) => {
462
+ const X = !A.current;
463
+ if (x.target === x.currentTarget && X && !_) {
464
+ const K = new CustomEvent(Q, ot);
465
+ if (x.currentTarget.dispatchEvent(K), !K.defaultPrevented) {
466
+ const j = F().filter(
467
+ (C) => C.focusable
468
+ ), p = j.find(
469
+ (C) => C.active
470
+ ), I = j.find(
471
+ (C) => C.id === d
472
+ ), z = [
473
+ p,
474
+ I,
475
+ ...j
476
+ ].filter(Boolean).map(
477
+ (C) => C.ref.current
478
+ );
479
+ xe(z);
480
+ }
481
+ }
482
+ A.current = !1;
483
+ }),
484
+ onBlur: O(
485
+ e.onBlur,
486
+ () => v(!1)
487
+ )
488
+ })));
489
+ }), dt = "RovingFocusGroupItem", ft = /* @__PURE__ */ T((e, t) => {
490
+ const { __scopeRovingFocusGroup: n, focusable: o = !0, active: s = !1, tabStopId: r, ...c } = e, a = ve(), u = r || a, i = it(dt, n), f = i.currentTabStopId === u, l = he(n), { onFocusableItemAdd: $, onFocusableItemRemove: m } = i;
491
+ return R(() => {
492
+ if (o)
493
+ return $(), () => m();
494
+ }, [
495
+ o,
496
+ $,
497
+ m
498
+ ]), /* @__PURE__ */ g(re.ItemSlot, {
499
+ scope: n,
500
+ id: u,
501
+ focusable: o,
502
+ active: s
503
+ }, /* @__PURE__ */ g(k.span, y({
504
+ tabIndex: f ? 0 : -1,
505
+ "data-orientation": i.orientation
506
+ }, c, {
507
+ ref: t,
508
+ onMouseDown: O(e.onMouseDown, (d) => {
509
+ o ? i.onItemFocus(u) : d.preventDefault();
510
+ }),
511
+ onFocus: O(
512
+ e.onFocus,
513
+ () => i.onItemFocus(u)
514
+ ),
515
+ onKeyDown: O(e.onKeyDown, (d) => {
516
+ if (d.key === "Tab" && d.shiftKey) {
517
+ i.onItemShiftTab();
518
+ return;
519
+ }
520
+ if (d.target !== d.currentTarget)
521
+ return;
522
+ const b = $t(d, i.orientation, i.dir);
523
+ if (b !== void 0) {
524
+ d.preventDefault();
525
+ let v = l().filter(
526
+ (h) => h.focusable
527
+ ).map(
528
+ (h) => h.ref.current
529
+ );
530
+ if (b === "last")
531
+ v.reverse();
532
+ else if (b === "prev" || b === "next") {
533
+ b === "prev" && v.reverse();
534
+ const h = v.indexOf(d.currentTarget);
535
+ v = i.loop ? vt(v, h + 1) : v.slice(h + 1);
536
+ }
537
+ setTimeout(
538
+ () => xe(v)
539
+ );
540
+ }
541
+ })
542
+ })));
543
+ }), pt = {
544
+ ArrowLeft: "prev",
545
+ ArrowUp: "prev",
546
+ ArrowRight: "next",
547
+ ArrowDown: "next",
548
+ PageUp: "first",
549
+ Home: "first",
550
+ PageDown: "last",
551
+ End: "last"
552
+ };
553
+ function bt(e, t) {
554
+ return t !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
555
+ }
556
+ function $t(e, t, n) {
557
+ const o = bt(e.key, n);
558
+ if (!(t === "vertical" && [
559
+ "ArrowLeft",
560
+ "ArrowRight"
561
+ ].includes(o)) && !(t === "horizontal" && [
562
+ "ArrowUp",
563
+ "ArrowDown"
564
+ ].includes(o)))
565
+ return pt[o];
566
+ }
567
+ function xe(e) {
568
+ const t = document.activeElement;
569
+ for (const n of e)
570
+ if (n === t || (n.focus(), document.activeElement !== t))
571
+ return;
572
+ }
573
+ function vt(e, t) {
574
+ return e.map(
575
+ (n, o) => e[(t + o) % e.length]
576
+ );
577
+ }
578
+ const mt = ut, _t = ft;
579
+ function ht(e, t) {
580
+ return Me((n, o) => {
581
+ const s = t[n][o];
582
+ return s ?? n;
583
+ }, e);
584
+ }
585
+ const Ce = (e) => {
586
+ const { present: t, children: n } = e, o = gt(t), s = typeof n == "function" ? n({
587
+ present: o.isPresent
588
+ }) : P.only(n), r = Z(o.ref, s.ref);
589
+ return typeof n == "function" || o.isPresent ? /* @__PURE__ */ oe(s, {
590
+ ref: r
591
+ }) : null;
592
+ };
593
+ Ce.displayName = "Presence";
594
+ function gt(e) {
595
+ const [t, n] = D(), o = M({}), s = M(e), r = M("none"), c = e ? "mounted" : "unmounted", [a, u] = ht(c, {
596
+ mounted: {
597
+ UNMOUNT: "unmounted",
598
+ ANIMATION_OUT: "unmountSuspended"
599
+ },
600
+ unmountSuspended: {
601
+ MOUNT: "mounted",
602
+ ANIMATION_END: "unmounted"
603
+ },
604
+ unmounted: {
605
+ MOUNT: "mounted"
606
+ }
607
+ });
608
+ return R(() => {
609
+ const i = W(o.current);
610
+ r.current = a === "mounted" ? i : "none";
611
+ }, [
612
+ a
613
+ ]), ne(() => {
614
+ const i = o.current, f = s.current;
615
+ if (f !== e) {
616
+ const $ = r.current, m = W(i);
617
+ e ? u("MOUNT") : m === "none" || (i == null ? void 0 : i.display) === "none" ? u("UNMOUNT") : u(f && $ !== m ? "ANIMATION_OUT" : "UNMOUNT"), s.current = e;
618
+ }
619
+ }, [
620
+ e,
621
+ u
622
+ ]), ne(() => {
623
+ if (t) {
624
+ const i = (l) => {
625
+ const m = W(o.current).includes(l.animationName);
626
+ l.target === t && m && Oe(
627
+ () => u("ANIMATION_END")
628
+ );
629
+ }, f = (l) => {
630
+ l.target === t && (r.current = W(o.current));
631
+ };
632
+ return t.addEventListener("animationstart", f), t.addEventListener("animationcancel", i), t.addEventListener("animationend", i), () => {
633
+ t.removeEventListener("animationstart", f), t.removeEventListener("animationcancel", i), t.removeEventListener("animationend", i);
634
+ };
635
+ } else
636
+ u("ANIMATION_END");
637
+ }, [
638
+ t,
639
+ u
640
+ ]), {
641
+ isPresent: [
642
+ "mounted",
643
+ "unmountSuspended"
644
+ ].includes(a),
645
+ ref: U((i) => {
646
+ i && (o.current = getComputedStyle(i)), n(i);
647
+ }, [])
648
+ };
649
+ }
650
+ function W(e) {
651
+ return (e == null ? void 0 : e.animationName) || "none";
652
+ }
653
+ const Ie = "Tabs", [xt, Xt] = ce(Ie, [
654
+ ge
655
+ ]), ye = ge(), [Ct, ie] = xt(Ie), It = /* @__PURE__ */ T((e, t) => {
656
+ const { __scopeTabs: n, value: o, onValueChange: s, defaultValue: r, orientation: c = "horizontal", dir: a, activationMode: u = "automatic", ...i } = e, f = _e(a), [l, $] = me({
657
+ prop: o,
658
+ onChange: s,
659
+ defaultProp: r
660
+ });
661
+ return /* @__PURE__ */ g(Ct, {
662
+ scope: n,
663
+ baseId: ve(),
664
+ value: l,
665
+ onValueChange: $,
666
+ orientation: c,
667
+ dir: f,
668
+ activationMode: u
669
+ }, /* @__PURE__ */ g(k.div, y({
670
+ dir: f,
671
+ "data-orientation": c
672
+ }, i, {
673
+ ref: t
674
+ })));
675
+ }), yt = "TabsList", St = /* @__PURE__ */ T((e, t) => {
676
+ const { __scopeTabs: n, loop: o = !0, ...s } = e, r = ie(yt, n), c = ye(n);
677
+ return /* @__PURE__ */ g(mt, y({
678
+ asChild: !0
679
+ }, c, {
680
+ orientation: r.orientation,
681
+ dir: r.dir,
682
+ loop: o
683
+ }), /* @__PURE__ */ g(k.div, y({
684
+ role: "tablist",
685
+ "aria-orientation": r.orientation
686
+ }, s, {
687
+ ref: t
688
+ })));
689
+ }), wt = "TabsTrigger", Tt = /* @__PURE__ */ T((e, t) => {
690
+ const { __scopeTabs: n, value: o, disabled: s = !1, ...r } = e, c = ie(wt, n), a = ye(n), u = Se(c.baseId, o), i = we(c.baseId, o), f = o === c.value;
691
+ return /* @__PURE__ */ g(_t, y({
692
+ asChild: !0
693
+ }, a, {
694
+ focusable: !s,
695
+ active: f
696
+ }), /* @__PURE__ */ g(k.button, y({
697
+ type: "button",
698
+ role: "tab",
699
+ "aria-selected": f,
700
+ "aria-controls": i,
701
+ "data-state": f ? "active" : "inactive",
702
+ "data-disabled": s ? "" : void 0,
703
+ disabled: s,
704
+ id: u
705
+ }, r, {
706
+ ref: t,
707
+ onMouseDown: O(e.onMouseDown, (l) => {
708
+ !s && l.button === 0 && l.ctrlKey === !1 ? c.onValueChange(o) : l.preventDefault();
709
+ }),
710
+ onKeyDown: O(e.onKeyDown, (l) => {
711
+ [
712
+ " ",
713
+ "Enter"
714
+ ].includes(l.key) && c.onValueChange(o);
715
+ }),
716
+ onFocus: O(e.onFocus, () => {
717
+ const l = c.activationMode !== "manual";
718
+ !f && !s && l && c.onValueChange(o);
719
+ })
720
+ })));
721
+ }), Nt = "TabsContent", At = /* @__PURE__ */ T((e, t) => {
722
+ const { __scopeTabs: n, value: o, forceMount: s, children: r, ...c } = e, a = ie(Nt, n), u = Se(a.baseId, o), i = we(a.baseId, o), f = o === a.value, l = M(f);
723
+ return R(() => {
724
+ const $ = requestAnimationFrame(
725
+ () => l.current = !1
726
+ );
727
+ return () => cancelAnimationFrame($);
728
+ }, []), /* @__PURE__ */ g(
729
+ Ce,
730
+ {
731
+ present: s || f
732
+ },
733
+ ({ present: $ }) => /* @__PURE__ */ g(k.div, y({
734
+ "data-state": f ? "active" : "inactive",
735
+ "data-orientation": a.orientation,
736
+ role: "tabpanel",
737
+ "aria-labelledby": u,
738
+ hidden: !$,
739
+ id: i,
740
+ tabIndex: 0
741
+ }, c, {
742
+ ref: t,
743
+ style: {
744
+ ...e.style,
745
+ animationDuration: l.current ? "0s" : void 0
746
+ }
747
+ }), $ && r)
748
+ );
749
+ });
750
+ function Se(e, t) {
751
+ return `${e}-trigger-${t}`;
752
+ }
753
+ function we(e, t) {
754
+ return `${e}-content-${t}`;
755
+ }
756
+ const Et = It, Pt = St, Rt = Tt, Mt = At;
757
+ function Ot(e) {
758
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
759
+ }
760
+ var Te = { exports: {} };
761
+ /*!
762
+ Copyright (c) 2018 Jed Watson.
763
+ Licensed under the MIT License (MIT), see
764
+ http://jedwatson.github.io/classnames
765
+ */
766
+ (function(e) {
767
+ (function() {
768
+ var t = {}.hasOwnProperty;
769
+ function n() {
770
+ for (var r = "", c = 0; c < arguments.length; c++) {
771
+ var a = arguments[c];
772
+ a && (r = s(r, o.call(this, a)));
773
+ }
774
+ return r;
775
+ }
776
+ function o(r) {
777
+ if (typeof r == "string" || typeof r == "number")
778
+ return this && this[r] || r;
779
+ if (typeof r != "object")
780
+ return "";
781
+ if (Array.isArray(r))
782
+ return n.apply(this, r);
783
+ if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
784
+ return r.toString();
785
+ var c = "";
786
+ for (var a in r)
787
+ t.call(r, a) && r[a] && (c = s(c, this && this[a] || a));
788
+ return c;
789
+ }
790
+ function s(r, c) {
791
+ return c ? r ? r + " " + c : r + c : r;
792
+ }
793
+ e.exports ? (n.default = n, e.exports = n) : window.classNames = n;
794
+ })();
795
+ })(Te);
796
+ var Ft = Te.exports;
797
+ const ue = /* @__PURE__ */ Ot(Ft), Dt = {
798
+ "purpur-tab-content": "_purpur-tab-content_rbfjg_1"
799
+ }, qt = ue.bind(Dt), Lt = "purpur-tab-content", Ut = T(
800
+ ({ children: e, tabId: t, "data-testid": n, className: o, ...s }, r) => /* @__PURE__ */ N(
801
+ Mt,
802
+ {
803
+ ref: r,
804
+ className: qt([Lt, o]),
805
+ "data-testid": n,
806
+ value: t,
807
+ ...s,
808
+ children: e
809
+ }
810
+ )
811
+ ), Vt = (e) => !!e && G(e) && !!e.props.name && !!e.props.tabId, Bt = {
812
+ "purpur-tab-header": "_purpur-tab-header_1hk4f_1",
813
+ "purpur-tab-header--contained": "_purpur-tab-header--contained_1hk4f_32",
814
+ "purpur-tab-header--contained-negative": "_purpur-tab-header--contained-negative_1hk4f_32",
815
+ "purpur-tab-header--line": "_purpur-tab-header--line_1hk4f_35",
816
+ "purpur-tab-header--line-negative": "_purpur-tab-header--line-negative_1hk4f_47"
817
+ }, jt = ue.bind(Bt), de = "purpur-tab-header", kt = T(
818
+ ({ index: e, tabId: t, variant: n, onFocus: o, "data-testid": s, children: r }, c) => /* @__PURE__ */ N(
819
+ Rt,
820
+ {
821
+ id: `${t}-trigger`,
822
+ className: jt([de, `${de}--${n}`]),
823
+ value: t,
824
+ "data-testid": s,
825
+ "data-index": e,
826
+ ref: c,
827
+ onFocus: o,
828
+ children: r
829
+ }
830
+ )
831
+ ), Gt = {
832
+ "purpur-tabs__wrapper": "_purpur-tabs__wrapper_1dpqy_1",
833
+ "purpur-tabs__scroll-button": "_purpur-tabs__scroll-button_1dpqy_9",
834
+ "purpur-tabs__scroll-button--left": "_purpur-tabs__scroll-button--left_1dpqy_63",
835
+ "purpur-tabs__scroll-button--right": "_purpur-tabs__scroll-button--right_1dpqy_66",
836
+ "purpur-tabs__wrapper--scroll-end": "_purpur-tabs__wrapper--scroll-end_1dpqy_69",
837
+ "purpur-tabs__wrapper--scroll-start": "_purpur-tabs__wrapper--scroll-start_1dpqy_72",
838
+ "purpur-tabs--line": "_purpur-tabs--line_1dpqy_75",
839
+ "purpur-tabs--line-negative": "_purpur-tabs--line-negative_1dpqy_75",
840
+ "purpur-tabs__selected-border": "_purpur-tabs__selected-border_1dpqy_83",
841
+ "purpur-tabs--contained": "_purpur-tabs--contained_1dpqy_103",
842
+ "purpur-tabs__list": "_purpur-tabs__list_1dpqy_103",
843
+ "purpur-tabs--contained-negative": "_purpur-tabs--contained-negative_1dpqy_103",
844
+ "purpur-tabs__content-container": "_purpur-tabs__content-container_1dpqy_106",
845
+ "purpur-tabs--fullWidth": "_purpur-tabs--fullWidth_1dpqy_115"
846
+ }, Jt = ["line", "line-negative", "contained", "contained-negative"], Kt = (e) => new CustomEvent("tabChangeDetail", { detail: { value: e } }), L = ue.bind(Gt), w = "purpur-tabs", zt = (e, t) => {
847
+ var u;
848
+ if (typeof (e == null ? void 0 : e.getBoundingClientRect) != "function" || typeof (t == null ? void 0 : t.scroll) != "function")
849
+ return;
850
+ const n = e.getBoundingClientRect(), o = t.getBoundingClientRect(), s = t.clientWidth, r = parseInt((u = getComputedStyle(t).borderLeftWidth) == null ? void 0 : u.split("px")[0], 10), c = o.left + (isNaN(r) ? 0 : r);
851
+ let a;
852
+ n.right > o.right && (a = n.left + t.scrollLeft, a = a + n.width - s + s * 0.1, a = a - c), n.left < o.left && (a = n.left + t.scrollLeft, a = a - s * 0.1, a = a - c), a !== void 0 && t.scroll({ left: a, behavior: "smooth" });
853
+ }, Wt = ({
854
+ children: e,
855
+ variant: t = "line",
856
+ fullWidth: n = !1,
857
+ onChange: o,
858
+ className: s,
859
+ "data-testid": r,
860
+ ...c
861
+ }) => {
862
+ const [a, u] = D(0), [i, f] = D({}), [l, $] = D(0), [m, d] = D(0), b = P.toArray(e).filter(Vt), _ = M(), v = M(new Array(b.length)), h = 200, F = t === "line" || t === "line-negative", A = L([
863
+ w,
864
+ `${w}--${t}`,
865
+ { [`${w}--fullWidth`]: n },
866
+ s
867
+ ]), V = P.map(b, ({ props: { tabId: p } }) => p);
868
+ if (new Set(V).size !== V.length)
869
+ throw new Error("tabId must be unique");
870
+ const B = (p, I) => I || r ? `${I || r}-${p}` : void 0, x = () => {
871
+ if (!F)
872
+ return;
873
+ const p = v.current[a];
874
+ $((p == null ? void 0 : p.offsetLeft) || 0), d((p == null ? void 0 : p.getBoundingClientRect().width) || 0);
875
+ }, X = (p) => {
876
+ F && u(b.findIndex((I) => I.props.tabId === p)), o == null || o(Kt(p));
877
+ }, K = (p) => {
878
+ if (_ != null && _.current) {
879
+ const { scrollLeft: I } = _.current, S = p === "left" ? -h : h;
880
+ _.current.scroll({ left: I + S, behavior: "smooth" });
881
+ }
882
+ }, j = ({ side: p }) => /* @__PURE__ */ N(
883
+ "button",
884
+ {
885
+ className: L(`${w}__scroll-button`, `${w}__scroll-button--${p}`),
886
+ onClick: () => K(p),
887
+ type: "button",
888
+ "aria-hidden": "true",
889
+ tabIndex: -1,
890
+ "data-testid": B("scroll-button"),
891
+ children: /* @__PURE__ */ N(ze, { svg: p === "left" ? Ue : Ve, size: "md" })
892
+ }
893
+ );
894
+ return R(() => (window.addEventListener("resize", x), () => {
895
+ window.removeEventListener("resize", x);
896
+ }), []), R(() => {
897
+ x();
898
+ }, [a, n, b, t]), R(() => {
899
+ const p = (S) => {
900
+ if (S.every((C) => C.isIntersecting) && S.length === b.length) {
901
+ f({});
902
+ return;
903
+ }
904
+ S.forEach((C) => {
905
+ const q = Number(C.target.getAttribute("data-index")), Ne = q === 0, Ae = q === b.length - 1;
906
+ f((Ee) => ({
907
+ ...Ee,
908
+ ...Ne && {
909
+ [`${w}__wrapper--scroll-end`]: !C.isIntersecting
910
+ },
911
+ ...Ae && {
912
+ [`${w}__wrapper--scroll-start`]: !C.isIntersecting
913
+ }
914
+ }));
915
+ });
916
+ }, I = new IntersectionObserver(p, {
917
+ threshold: [0.99],
918
+ root: _.current
919
+ });
920
+ return v.current.forEach((S) => I.observe(S)), () => {
921
+ v.current.forEach((S) => I.unobserve(S));
922
+ };
923
+ }, [b.length]), /* @__PURE__ */ N(
924
+ Et,
925
+ {
926
+ defaultValue: b[0].props.tabId,
927
+ onValueChange: X,
928
+ "data-testid": r,
929
+ className: A,
930
+ ...c,
931
+ children: /* @__PURE__ */ J("div", { className: L(`${w}__container`), children: [
932
+ /* @__PURE__ */ J("div", { className: L([`${w}__wrapper`, i]), children: [
933
+ /* @__PURE__ */ J(
934
+ Pt,
935
+ {
936
+ ref: (p) => {
937
+ _.current = p;
938
+ },
939
+ className: L(`${w}__list`),
940
+ children: [
941
+ P.map(b, (p, I) => {
942
+ const { name: S, tabId: z, "data-testid": C } = p.props;
943
+ return /* @__PURE__ */ N(
944
+ kt,
945
+ {
946
+ "data-testid": B("header", C),
947
+ index: I,
948
+ tabId: z,
949
+ ref: (q) => {
950
+ q && (v.current[I] = q);
951
+ },
952
+ onFocus: (q) => {
953
+ zt(q.target, _.current);
954
+ },
955
+ variant: t,
956
+ children: S
957
+ }
958
+ );
959
+ }),
960
+ F && /* @__PURE__ */ N(
961
+ "div",
962
+ {
963
+ className: L(`${w}__selected-border`),
964
+ style: {
965
+ width: m,
966
+ transform: `translateX(${l}px)`
967
+ },
968
+ "data-testid": B("selected-border")
969
+ }
970
+ )
971
+ ]
972
+ }
973
+ ),
974
+ /* @__PURE__ */ N(j, { side: "left" }),
975
+ /* @__PURE__ */ N(j, { side: "right" })
976
+ ] }),
977
+ /* @__PURE__ */ N("div", { className: L(`${w}__content-container`), children: P.map(b, (p) => p) })
978
+ ] })
979
+ }
980
+ );
981
+ };
982
+ Wt.Content = Ut;
983
+ export {
984
+ Wt as Tabs,
985
+ Kt as createTabChangeDetailEvent,
986
+ Jt as tabsVariants
987
+ };
988
+ //# sourceMappingURL=tabs.es.js.map