@blakesteve/roster 5.13.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.
@@ -1,21 +1,23 @@
1
1
  "use client";
2
- import { jsx as c, jsxs as k, Fragment as Ht } from "react/jsx-runtime";
3
- import * as n from "react";
4
- import { Button as jt } from "../../atoms/Button/Button.js";
5
- import { cn as y } from "../../../lib/utils.js";
6
- import { withLabels as zt } from "../../../lib/labels.js";
7
- import { prefersReducedMotion as Ut } from "../../../internal/motion.js";
8
- import { currentIndex as Vt, canScrollNext as Wt, canScrollPrev as qt, overflows as Xt, pageTarget as Gt, snapPosition as U, nearestIndex as Jt, CAROUSEL_DRAG_THRESHOLD as Kt } from "./carousel-math.js";
9
- import { perViewVars as Qt, FLUID_ITEM_WIDTH as Yt, FLUID_CLASSES as Zt } from "./carousel-layout.js";
10
- import { useKeyFocus as te } from "../../../internal/key-focus.js";
11
- const ee = { position: (i, u) => `${i} of ${u}` }, re = (i) => Math.min(3e3, 500 + i * 0.35), ne = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable]:not([contenteditable="false"])', V = (i) => typeof i == "number" ? `${i}px` : i;
12
- function st(i) {
13
- const u = parseFloat(i);
2
+ import { jsx as g, jsxs as q, Fragment as Ee } from "react/jsx-runtime";
3
+ import * as s from "react";
4
+ import { Button as Te } from "../../atoms/Button/Button.js";
5
+ import { cn as F } from "../../../lib/utils.js";
6
+ import { withLabels as Ie } from "../../../lib/labels.js";
7
+ import { prefersReducedMotion as Ne } from "../../../internal/motion.js";
8
+ import { currentIndex as Ce, canScrollNext as Re, canScrollPrev as Le, overflows as Pe, pageTarget as De, revealTarget as Lt, snapPosition as ct, pageStep as Oe, nearestIndex as Me, CAROUSEL_DRAG_THRESHOLD as Ae } from "./carousel-math.js";
9
+ import { perViewVars as Fe, FLUID_ITEM_WIDTH as _e, FLUID_CLASSES as $e } from "./carousel-layout.js";
10
+ import { survivingNeighbor as Be, TYPEAHEAD_RESET_MS as He, typeaheadIndex as ze } from "./carousel-selection.js";
11
+ import { useKeyFocus as Ve } from "../../../internal/key-focus.js";
12
+ import { isDevelopment as je } from "../../../internal/dev.js";
13
+ const Ke = { position: (a, u) => `${a} of ${u}` }, Ue = (a) => Math.min(3e3, 500 + a * 0.35), at = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable]:not([contenteditable="false"])', ut = (a) => typeof a == "number" ? `${a}px` : a;
14
+ function Pt(a) {
15
+ const u = parseFloat(a);
14
16
  return Number.isFinite(u) ? u : 0;
15
17
  }
16
- const se = "rst:hidden rst:[@media(any-hover:hover)]:inline-flex", oe = "rst:hidden rst:[@media(any-hover:hover)]:flex";
17
- function ot({ direction: i }) {
18
- return /* @__PURE__ */ c(
18
+ const qe = "rst:hidden rst:[@media(any-hover:hover)]:inline-flex", We = "rst:hidden rst:[@media(any-hover:hover)]:flex";
19
+ function Dt({ direction: a }) {
20
+ return /* @__PURE__ */ g(
19
21
  "svg",
20
22
  {
21
23
  "aria-hidden": "true",
@@ -27,339 +29,488 @@ function ot({ direction: i }) {
27
29
  strokeWidth: "2",
28
30
  strokeLinecap: "round",
29
31
  strokeLinejoin: "round",
30
- children: /* @__PURE__ */ c("path", { d: i === "prev" ? "M12.5 4.5 7 10l5.5 5.5" : "M7.5 4.5 13 10l-5.5 5.5" })
32
+ children: /* @__PURE__ */ g("path", { d: a === "prev" ? "M12.5 4.5 7 10l5.5 5.5" : "M7.5 4.5 13 10l-5.5 5.5" })
31
33
  }
32
34
  );
33
35
  }
34
- const lt = {
36
+ const Ge = "rst:cursor-pointer rst:in-data-dragging:cursor-grabbing rst:outline-hidden rst:focus-visible:outline-solid rst:focus-visible:outline-2 rst:focus-visible:outline-offset-2 rst:focus-visible:outline-ring", Xe = s.memo(function({ child: u, index: p, count: b, selected: N, active: S, label: R, style: _, className: $ }) {
37
+ return /* @__PURE__ */ g(
38
+ "li",
39
+ {
40
+ role: "option",
41
+ "aria-selected": N,
42
+ "aria-setsize": b,
43
+ "aria-posinset": p + 1,
44
+ "aria-label": R,
45
+ tabIndex: S ? 0 : -1,
46
+ "data-carousel-item": "",
47
+ "data-selected": N ? "" : void 0,
48
+ style: _,
49
+ className: $,
50
+ children: u
51
+ }
52
+ );
53
+ });
54
+ function Je(a) {
55
+ const u = [];
56
+ return s.Children.forEach(a, (p) => {
57
+ if (p == null || typeof p == "boolean") return;
58
+ const b = s.isValidElement(p) && p.key !== null;
59
+ u.push({ child: p, key: b ? String(p.key) : `#${u.length}`, keyed: b });
60
+ }), u;
61
+ }
62
+ const Ye = { active: null, keys: [], sig: "", selected: null, init: !1 }, W = (a, u) => Array.prototype.indexOf.call(a.children, u), Ot = {
35
63
  overflowing: null,
36
64
  canScrollPrev: !1,
37
65
  canScrollNext: !1,
38
66
  index: 0
39
- }, pe = n.forwardRef(function({
67
+ }, cr = s.forwardRef(function({
40
68
  "aria-label": u,
41
- "aria-labelledby": w,
42
- children: W,
43
- itemWidth: N,
44
- perView: C,
45
- gap: q = 12,
46
- gutter: X = 16,
47
- bleed: ct = !1,
48
- snap: R = "start",
49
- snapStrictness: it = "mandatory",
50
- oneAtATime: at = !1,
51
- arrows: P = "hover",
52
- arrowPlacement: M = "controls",
53
- renderArrows: I,
54
- prevLabel: ut,
55
- nextLabel: dt,
56
- prevIcon: ft,
57
- nextIcon: gt,
58
- arrowButtonProps: pt,
59
- fade: vt = !1,
60
- scrollbar: mt = !1,
61
- showPosition: G = !1,
62
- labels: bt,
63
- onIndexChange: J,
64
- onScrollStateChange: K,
65
- itemClassName: xt,
66
- listClassName: ht,
67
- className: St,
68
- style: yt,
69
- ...wt
70
- }, Nt) {
71
- te();
72
- const Q = zt(ee, bt), g = n.useRef(null), Y = `${n.useId()}-list`, Z = n.Children.toArray(W), T = Z.length, [o, It] = n.useState(lt), tt = n.useRef(lt), [Tt, Et] = n.useState(""), [Lt, kt] = n.useState(!1), A = n.useRef({ onIndexChange: J, onScrollStateChange: K });
73
- n.useEffect(() => {
74
- A.current = { onIndexChange: J, onScrollStateChange: K };
69
+ "aria-labelledby": p,
70
+ "aria-describedby": b,
71
+ children: N,
72
+ itemWidth: S,
73
+ perView: R,
74
+ gap: _ = 12,
75
+ gutter: $ = 16,
76
+ bleed: Mt = !1,
77
+ snap: G = "start",
78
+ snapStrictness: At = "mandatory",
79
+ oneAtATime: Ft = !1,
80
+ arrows: X = "hover",
81
+ arrowPlacement: J = "controls",
82
+ renderArrows: B,
83
+ prevLabel: _t,
84
+ nextLabel: $t,
85
+ prevIcon: Bt,
86
+ nextIcon: Ht,
87
+ arrowButtonProps: zt,
88
+ fade: Vt = !1,
89
+ scrollbar: jt = !1,
90
+ showPosition: dt = !1,
91
+ labels: Kt,
92
+ onIndexChange: ft,
93
+ onScrollStateChange: gt,
94
+ selectable: f = !1,
95
+ selectedKey: pt,
96
+ defaultSelectedKey: Ut = null,
97
+ onSelectionChange: qt,
98
+ onActivate: mt,
99
+ clearable: Wt = !1,
100
+ getOptionLabel: Y,
101
+ itemClassName: Gt,
102
+ listClassName: Xt,
103
+ className: Jt,
104
+ style: Yt,
105
+ ...Qt
106
+ }, Zt) {
107
+ Ve();
108
+ const vt = Ie(Ke, Kt), y = s.useRef(null), yt = `${s.useId()}-list`, ht = s.Children.toArray(N), k = f ? Je(N) : null, L = k ? k.length : ht.length, xt = pt !== void 0, [te, ee] = s.useState(Ut), l = xt ? pt : te, [re, bt] = s.useState(!1), m = k ? k.map((t) => t.key) : [], St = m.join("\0"), [w, H] = s.useState(Ye);
109
+ let E = w.active;
110
+ if (f && (!w.init || w.sig !== St || w.selected !== l)) {
111
+ const t = new Set(m);
112
+ w.init && w.selected !== l && !re && l !== null && t.has(l) && (E = l), (E === null || !t.has(E)) && (E = Be(w.keys, t, E) ?? (l !== null && t.has(l) ? l : m[0] ?? null)), H({ active: E, keys: m, sig: St, selected: l, init: !0 });
113
+ }
114
+ const [c, ne] = s.useState(Ot), kt = s.useRef(Ot), [se, oe] = s.useState(""), [ie, le] = s.useState(!1), Q = s.useRef({ onIndexChange: ft, onScrollStateChange: gt });
115
+ s.useEffect(() => {
116
+ Q.current = { onIndexChange: ft, onScrollStateChange: gt };
75
117
  });
76
- const d = n.useCallback(() => {
77
- const t = g.current;
118
+ const v = s.useCallback(() => {
119
+ const t = y.current;
78
120
  if (!t) return null;
79
- const e = t.getBoundingClientRect(), r = getComputedStyle(t), s = e.left + t.clientLeft - t.scrollLeft;
121
+ const e = t.getBoundingClientRect(), r = getComputedStyle(t), n = e.left + t.clientLeft - t.scrollLeft;
80
122
  return {
81
- items: Array.from(t.children).map((a) => {
82
- const v = a.getBoundingClientRect();
83
- return { start: v.left - s, end: v.right - s };
123
+ items: Array.from(t.children).map((i) => {
124
+ const d = i.getBoundingClientRect();
125
+ return { start: d.left - n, end: d.right - n };
84
126
  }),
85
127
  scrollLeft: t.scrollLeft,
86
128
  clientWidth: t.clientWidth,
87
129
  scrollWidth: t.scrollWidth,
88
- paddingStart: st(r.scrollPaddingInlineStart || r.scrollPaddingLeft),
89
- paddingEnd: st(r.scrollPaddingInlineEnd || r.scrollPaddingRight),
90
- align: R
130
+ paddingStart: Pt(r.scrollPaddingInlineStart || r.scrollPaddingLeft),
131
+ paddingEnd: Pt(r.scrollPaddingInlineEnd || r.scrollPaddingRight),
132
+ align: G
91
133
  };
92
- }, [R]), m = n.useCallback(() => {
93
- const t = d();
134
+ }, [G]), P = s.useCallback(() => {
135
+ const t = v();
94
136
  if (!t) return;
95
137
  const e = {
96
- overflowing: Xt(t),
97
- canScrollPrev: qt(t),
98
- canScrollNext: Wt(t),
99
- index: t.items.length ? Vt(t) : 0
100
- }, r = tt.current;
101
- r.overflowing === e.overflowing && r.canScrollPrev === e.canScrollPrev && r.canScrollNext === e.canScrollNext && r.index === e.index || (tt.current = e, It(e), r.index !== e.index && A.current.onIndexChange?.(e.index), (r.canScrollPrev !== e.canScrollPrev || r.canScrollNext !== e.canScrollNext) && A.current.onScrollStateChange?.({
138
+ overflowing: Pe(t),
139
+ canScrollPrev: Le(t),
140
+ canScrollNext: Re(t),
141
+ index: t.items.length ? Ce(t) : 0
142
+ }, r = kt.current;
143
+ r.overflowing === e.overflowing && r.canScrollPrev === e.canScrollPrev && r.canScrollNext === e.canScrollNext && r.index === e.index || (kt.current = e, ne(e), r.index !== e.index && Q.current.onIndexChange?.(e.index), (r.canScrollPrev !== e.canScrollPrev || r.canScrollNext !== e.canScrollNext) && Q.current.onScrollStateChange?.({
102
144
  canScrollPrev: e.canScrollPrev,
103
145
  canScrollNext: e.canScrollNext
104
146
  }));
105
- }, [d]), Ct = JSON.stringify([q, X, N, C]);
106
- n.useLayoutEffect(() => {
107
- const t = g.current;
147
+ }, [v]), ce = JSON.stringify([_, $, S, R]);
148
+ s.useLayoutEffect(() => {
149
+ const t = y.current;
108
150
  if (!t) return;
109
- m();
151
+ P();
110
152
  let e = 0;
111
153
  const r = () => {
112
154
  e || (e = requestAnimationFrame(() => {
113
- e = 0, m();
155
+ e = 0, P();
114
156
  }));
115
157
  };
116
158
  t.addEventListener("scroll", r, { passive: !0 });
117
- const s = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => m()), l = () => {
118
- s?.observe(t), Array.from(t.children).forEach((v) => s?.observe(v));
159
+ const n = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => P()), o = () => {
160
+ n?.observe(t), Array.from(t.children).forEach((d) => n?.observe(d));
119
161
  };
120
- l();
121
- const a = typeof MutationObserver > "u" ? null : new MutationObserver(() => {
122
- l(), m();
162
+ o();
163
+ const i = typeof MutationObserver > "u" ? null : new MutationObserver(() => {
164
+ o(), P();
123
165
  });
124
- return a?.observe(t, { childList: !0 }), () => {
125
- t.removeEventListener("scroll", r), s?.disconnect(), a?.disconnect(), e && cancelAnimationFrame(e);
166
+ return i?.observe(t, { childList: !0 }), () => {
167
+ t.removeEventListener("scroll", r), n?.disconnect(), i?.disconnect(), e && cancelAnimationFrame(e);
126
168
  };
127
- }, [m, T, Ct]), n.useLayoutEffect(() => {
128
- const t = g.current;
129
- if (t && (kt(!t.querySelector(ne)), w)) {
130
- const e = w.split(/\s+/).map((r) => document.getElementById(r)?.textContent?.trim() ?? "").filter(Boolean).join(" ");
131
- Et(e);
169
+ }, [P, L, ce]), s.useLayoutEffect(() => {
170
+ const t = y.current;
171
+ if (t && (le(!t.querySelector(at)), p)) {
172
+ const e = p.split(/\s+/).map((r) => document.getElementById(r)?.textContent?.trim() ?? "").filter(Boolean).join(" ");
173
+ oe(e);
132
174
  }
133
- }, [W, w]);
134
- const b = n.useRef(null), f = n.useCallback(() => {
135
- const t = g.current, e = b.current;
136
- e && (b.current = null, window.clearTimeout(e.timer), t?.removeEventListener("scrollend", e.done), t && (t.style.scrollSnapType = "", delete t.dataset.settling));
137
- }, []), p = n.useCallback(
175
+ }, [N, p]);
176
+ const T = s.useRef(null), I = s.useCallback(() => {
177
+ const t = y.current, e = T.current;
178
+ e && (T.current = null, window.clearTimeout(e.timer), t?.removeEventListener("scrollend", e.done), t && (t.style.scrollSnapType = "", delete t.dataset.settling));
179
+ }, []), h = s.useCallback(
138
180
  (t, e) => {
139
- const r = g.current;
181
+ const r = y.current;
140
182
  if (!r) return;
141
- if (f(), e !== "smooth" || Ut() || Math.abs(r.scrollLeft - t) < 1) {
183
+ if (I(), e !== "smooth" || Ne() || Math.abs(r.scrollLeft - t) < 1) {
142
184
  r.style.scrollSnapType = "none", r.scrollTo({ left: t, behavior: "instant" }), r.style.scrollSnapType = "";
143
185
  return;
144
186
  }
145
187
  r.style.scrollSnapType = "none", r.dataset.settling = "";
146
- const l = r.scrollLeft, a = () => {
147
- Math.abs(r.scrollLeft - l) < 0.5 || f();
188
+ const o = r.scrollLeft, i = () => {
189
+ Math.abs(r.scrollLeft - o) < 0.5 || I();
148
190
  };
149
- b.current = {
150
- timer: window.setTimeout(f, re(Math.abs(r.scrollLeft - t))),
151
- done: a,
191
+ T.current = {
192
+ timer: window.setTimeout(I, Ue(Math.abs(r.scrollLeft - t))),
193
+ done: i,
152
194
  target: t
153
- }, r.addEventListener("scrollend", a), r.scrollTo({ left: t, behavior: "smooth" });
195
+ }, r.addEventListener("scrollend", i), r.scrollTo({ left: t, behavior: "smooth" });
154
196
  },
155
- [f]
156
- ), E = n.useCallback(
197
+ [I]
198
+ ), z = s.useCallback(
157
199
  (t) => {
158
- const e = d();
200
+ const e = v();
159
201
  if (!e) return;
160
- const r = b.current ? { ...e, scrollLeft: b.current.target } : e;
161
- p(Gt(r, t), "smooth");
202
+ const r = T.current ? { ...e, scrollLeft: T.current.target } : e;
203
+ h(De(r, t), "smooth");
162
204
  },
163
- [d, p]
205
+ [v, h]
164
206
  );
165
- n.useImperativeHandle(
166
- Nt,
207
+ s.useImperativeHandle(
208
+ Zt,
167
209
  () => ({
168
210
  scrollToIndex: (t, e) => {
169
- const r = d();
211
+ const r = v();
170
212
  if (!r || !r.items.length) return;
171
- const s = Math.min(Math.max(0, Math.round(t)), r.items.length - 1);
172
- p(U(r, s), e?.behavior ?? "smooth");
213
+ const n = Math.min(Math.max(0, Math.round(t)), r.items.length - 1);
214
+ h(ct(r, n), e?.behavior ?? "smooth");
173
215
  },
174
- scrollPrev: () => E(-1),
175
- scrollNext: () => E(1)
216
+ scrollPrev: () => z(-1),
217
+ scrollNext: () => z(1),
218
+ focus: () => {
219
+ const t = y.current;
220
+ if (!t) return;
221
+ const e = f ? t.querySelector(':scope > [tabindex="0"]') : t.querySelector(at) ?? (t.tabIndex === 0 ? t : null);
222
+ if (!e) return;
223
+ e.focus({ preventScroll: !0 });
224
+ const r = e.closest("[data-carousel-item]"), n = v(), o = r && r.parentElement === t ? W(t, r) : -1, i = n && o >= 0 ? Lt(n, o, T.current?.target ?? n.scrollLeft) : null;
225
+ i !== null && h(i, "smooth");
226
+ }
176
227
  }),
177
- [d, E, p]
178
- ), n.useEffect(() => f, [f]);
179
- const D = n.useRef(null), F = n.useRef(null), O = n.useRef(null);
180
- n.useLayoutEffect(() => {
181
- const t = O.current;
228
+ [v, z, h, f]
229
+ ), s.useEffect(() => I, [I]);
230
+ const Z = s.useRef(null), tt = s.useRef(null), et = s.useRef(null);
231
+ s.useLayoutEffect(() => {
232
+ const t = et.current;
182
233
  if (!t) return;
183
- const e = t === "prev" ? D.current : F.current, r = t === "prev" ? F.current : D.current, s = t === "prev" ? !o.canScrollPrev : !o.canScrollNext, l = document.activeElement;
184
- s && (l !== e && l !== document.body && l !== null || r && !r.disabled && r.focus());
185
- }, [o.canScrollPrev, o.canScrollNext]);
186
- const x = n.useRef(null), h = n.useRef(!1), Rt = (t) => {
187
- t.pointerType !== "mouse" || t.button !== 0 || o.overflowing && (f(), h.current = !1, x.current = {
234
+ const e = t === "prev" ? Z.current : tt.current, r = t === "prev" ? tt.current : Z.current, n = t === "prev" ? !c.canScrollPrev : !c.canScrollNext, o = document.activeElement;
235
+ n && (o !== e && o !== document.body && o !== null || r && !r.disabled && r.focus());
236
+ }, [c.canScrollPrev, c.canScrollNext]);
237
+ const C = s.useRef(null), D = s.useRef(!1), ae = (t) => {
238
+ t.pointerType !== "mouse" || t.button !== 0 || c.overflowing && (I(), D.current = !1, C.current = {
188
239
  pointerId: t.pointerId,
189
240
  x0: t.clientX,
190
241
  scroll0: t.currentTarget.scrollLeft,
191
242
  dragging: !1
192
243
  });
193
- }, Pt = (t) => {
194
- const e = x.current;
244
+ }, ue = (t) => {
245
+ const e = C.current;
195
246
  if (!e || t.pointerId !== e.pointerId) return;
196
- const r = t.currentTarget, s = t.clientX - e.x0;
247
+ const r = t.currentTarget, n = t.clientX - e.x0;
197
248
  if (!e.dragging) {
198
- if (Math.abs(s) <= Kt) return;
249
+ if (Math.abs(n) <= Ae) return;
199
250
  e.dragging = !0, r.dataset.dragging = "", r.style.scrollSnapType = "none", window.getSelection?.()?.removeAllRanges();
200
251
  try {
201
252
  r.setPointerCapture(t.pointerId);
202
253
  } catch {
203
254
  }
204
255
  }
205
- r.scrollLeft = e.scroll0 - s;
206
- }, _ = (t) => {
207
- const e = x.current;
208
- if (!e || t.pointerId !== e.pointerId || (x.current = null, !e.dragging)) return;
256
+ r.scrollLeft = e.scroll0 - n;
257
+ }, rt = (t) => {
258
+ const e = C.current;
259
+ if (!e || t.pointerId !== e.pointerId || (C.current = null, !e.dragging)) return;
209
260
  const r = t.currentTarget;
210
- delete r.dataset.dragging, h.current = t.type === "pointerup", window.setTimeout(() => {
211
- h.current = !1;
261
+ delete r.dataset.dragging, D.current = t.type === "pointerup", window.setTimeout(() => {
262
+ D.current = !1;
212
263
  }, 0);
213
- const s = d();
214
- s ? p(U(s, Jt(s)), "smooth") : r.style.scrollSnapType = "";
215
- }, Mt = (t) => {
216
- !h.current || t.detail === 0 || (h.current = !1, t.preventDefault(), t.stopPropagation());
217
- }, At = (t) => {
218
- o.overflowing && t.preventDefault();
219
- }, Dt = (t) => {
264
+ const n = v();
265
+ n ? h(ct(n, Me(n)), "smooth") : r.style.scrollSnapType = "";
266
+ }, de = (t) => {
267
+ !D.current || t.detail === 0 || (D.current = !1, t.preventDefault(), t.stopPropagation());
268
+ }, fe = (t) => {
269
+ c.overflowing && t.preventDefault();
270
+ }, ge = (t) => {
271
+ if (f) {
272
+ me(t);
273
+ return;
274
+ }
275
+ const e = t.currentTarget, r = t.target;
276
+ if (r === e || C.current?.dragging) return;
277
+ let n = !1;
278
+ try {
279
+ n = r.matches(":focus-visible, [data-key-focus]");
280
+ } catch {
281
+ n = !1;
282
+ }
283
+ if (!n) return;
284
+ const o = r.closest("[data-carousel-item]");
285
+ if (!o || o.parentElement !== e) return;
286
+ const i = v();
287
+ if (!i) return;
288
+ const d = Array.prototype.indexOf.call(e.children, o);
289
+ h(ct(i, d), "instant");
290
+ }, V = (t) => {
291
+ xt || ee(t), qt?.(t);
292
+ }, pe = (t) => {
293
+ const e = v();
294
+ if (!e) return;
295
+ const r = Lt(e, t, T.current?.target ?? e.scrollLeft);
296
+ r !== null && h(r, "smooth");
297
+ }, me = (t) => {
220
298
  const e = t.currentTarget, r = t.target;
221
- if (r === e || x.current?.dragging) return;
222
- let s = !1;
299
+ if (r.parentElement !== e) return;
300
+ const n = W(e, r), o = m[n];
301
+ if (o === void 0 || (H((d) => d.active === o ? d : { ...d, active: o }), bt(!0), C.current?.dragging)) return;
302
+ let i = !1;
223
303
  try {
224
- s = r.matches(":focus-visible, [data-key-focus]");
304
+ i = r.matches(":focus-visible, [data-key-focus]");
225
305
  } catch {
226
- s = !1;
306
+ i = !1;
227
307
  }
228
- if (!s) return;
229
- const l = r.closest("[data-carousel-item]");
230
- if (!l || l.parentElement !== e) return;
231
- const a = d();
232
- if (!a) return;
233
- const v = Array.prototype.indexOf.call(e.children, l);
234
- p(U(a, v), "instant");
235
- }, [Ft, Ot] = n.useState(0);
236
- n.useEffect(() => {
237
- const t = window.setTimeout(() => Ot(o.index), 150);
308
+ i && pe(n);
309
+ }, ve = (t) => {
310
+ const e = t.relatedTarget;
311
+ e && t.currentTarget.contains(e) || (bt(!1), l !== null && m.includes(l) && H((r) => r.active === l ? r : { ...r, active: l }));
312
+ }, ye = (t) => {
313
+ const e = t.currentTarget, r = t.target.closest("[data-carousel-item]");
314
+ if (!r || r.parentElement !== e) return;
315
+ const n = m[W(e, r)];
316
+ n !== void 0 && (H((o) => o.active === n ? o : { ...o, active: n }), n === l ? mt?.(n) : V(n));
317
+ }, O = s.useRef({ text: "", at: -1 / 0 }), he = (t) => {
318
+ const e = t.currentTarget, r = t.target;
319
+ if (r.parentElement !== e || t.nativeEvent.isComposing || t.ctrlKey || t.metaKey || t.altKey) return;
320
+ const n = m.length - 1, o = W(e, r), i = m[o];
321
+ if (i === void 0) return;
322
+ const d = (x) => {
323
+ t.preventDefault();
324
+ const A = Math.min(n, Math.max(0, x));
325
+ A !== o && e.children[A].focus({ preventScroll: !0 });
326
+ }, Ct = t.timeStamp - O.current.at < He && O.current.text !== "";
327
+ switch (t.key.length !== 1 && (O.current = { text: "", at: -1 / 0 }), t.key) {
328
+ case "ArrowRight":
329
+ return d(o + 1);
330
+ case "ArrowLeft":
331
+ return d(o - 1);
332
+ case "Home":
333
+ return d(0);
334
+ case "End":
335
+ return d(n);
336
+ case "PageDown":
337
+ case "PageUp": {
338
+ const x = v(), A = x ? Oe(x) : 1;
339
+ return d(t.key === "PageDown" ? o + A : o - A);
340
+ }
341
+ case "Enter":
342
+ t.preventDefault(), i === l ? mt?.(i) : V(i);
343
+ return;
344
+ case " ":
345
+ if (Ct) break;
346
+ t.preventDefault(), i !== l && V(i);
347
+ return;
348
+ case "Escape":
349
+ if (!Wt || l === null) return;
350
+ t.preventDefault(), t.stopPropagation(), V(null);
351
+ return;
352
+ }
353
+ if (t.key.length !== 1) return;
354
+ const Rt = (Ct ? O.current.text : "") + t.key.toLowerCase();
355
+ O.current = { text: Rt, at: t.timeStamp }, t.preventDefault();
356
+ const we = (x) => Y ? Y(m[x], x) : e.children[x]?.textContent ?? "", lt = ze(m.length, o, Rt, we);
357
+ lt >= 0 && lt !== o && e.children[lt].focus({ preventScroll: !0 });
358
+ }, j = s.useRef({ keys: !1, interactive: !1 });
359
+ s.useEffect(() => {
360
+ if (!f || !je()) return;
361
+ const t = y.current;
362
+ !j.current.keys && k?.some((e) => !e.keyed) && (j.current.keys = !0, console.warn("Roster Carousel: selection mode needs a key on every child; it's the option's identity.")), !j.current.interactive && t?.querySelector(`[data-carousel-item] :is(${at})`) && (j.current.interactive = !0, console.warn("Roster Carousel: an option holds something that takes focus. In selection mode the keys can't reach it; put it outside the row, or use onActivate."));
363
+ });
364
+ const [xe, be] = s.useState(0);
365
+ s.useEffect(() => {
366
+ const t = window.setTimeout(() => be(c.index), 150);
238
367
  return () => window.clearTimeout(t);
239
- }, [o.index]);
240
- const et = u ?? Tt, rt = (t) => et ? `${t} ${et}` : t, $ = P !== "none" && o.overflowing !== !1, _t = P === "hover" ? se : "rst:inline-flex", nt = (t) => {
241
- const e = t === "prev", { className: r, ...s } = pt ?? {};
242
- return /* @__PURE__ */ c(
243
- jt,
368
+ }, [c.index]);
369
+ const wt = u ?? se, Et = (t) => wt ? `${t} ${wt}` : t, nt = X !== "none" && c.overflowing !== !1, Se = X === "hover" ? qe : "rst:inline-flex", Tt = (t) => {
370
+ const e = t === "prev", { className: r, ...n } = zt ?? {};
371
+ return /* @__PURE__ */ g(
372
+ Te,
244
373
  {
245
374
  type: "button",
246
375
  variant: "outline",
247
376
  colorScheme: "neutral",
248
377
  size: "icon",
249
- ...s,
250
- "aria-label": e ? ut ?? rt("Previous") : dt ?? rt("Next"),
251
- "aria-controls": Y,
252
- disabled: e ? !o.canScrollPrev : !o.canScrollNext,
253
- onClick: () => E(e ? -1 : 1),
254
- ref: e ? D : F,
378
+ ...n,
379
+ "aria-label": e ? _t ?? Et("Previous") : $t ?? Et("Next"),
380
+ "aria-controls": yt,
381
+ disabled: e ? !c.canScrollPrev : !c.canScrollNext,
382
+ onClick: () => z(e ? -1 : 1),
383
+ ref: e ? Z : tt,
255
384
  onFocus: () => {
256
- O.current = t;
385
+ et.current = t;
257
386
  },
258
- onBlur: (l) => {
259
- l.relatedTarget && (O.current = null);
387
+ onBlur: (o) => {
388
+ o.relatedTarget && (et.current = null);
260
389
  },
261
390
  "data-carousel-arrow": t,
262
- className: y(
391
+ className: F(
263
392
  /* 44px, the target size, whatever the Button's own icon size is. */
264
393
  "rst:size-11 rst:shrink-0 rst:rounded-full",
265
394
  /* Over the row, a disabled arrow would sit on top of the first or
266
395
  last item for nothing, so it hides. Hidden is also out of the tab
267
396
  order and the accessibility tree, as disabled already was. */
268
- M === "overlay" && !I && "rst:bg-[var(--roster-popover-bg)] rst:elevation-raised rst:hover:bg-[var(--roster-popover-bg)] rst:disabled:invisible",
269
- _t,
397
+ J === "overlay" && !B && "rst:bg-[var(--roster-popover-bg)] rst:elevation-raised rst:hover:bg-[var(--roster-popover-bg)] rst:disabled:invisible",
398
+ Se,
270
399
  r
271
400
  ),
272
- children: e ? ft ?? /* @__PURE__ */ c(ot, { direction: "prev" }) : gt ?? /* @__PURE__ */ c(ot, { direction: "next" })
401
+ children: e ? Bt ?? /* @__PURE__ */ g(Dt, { direction: "prev" }) : Ht ?? /* @__PURE__ */ g(Dt, { direction: "next" })
273
402
  }
274
403
  );
275
- }, L = $ ? nt("prev") : null, B = $ ? nt("next") : null, S = G && T ? (
404
+ }, K = nt ? Tt("prev") : null, st = nt ? Tt("next") : null, M = dt && L ? (
276
405
  /* `font-ui` here and not on the root: the readout is the only text the
277
406
  carousel owns. The items are the host's content, and not Roster's to
278
407
  restyle. */
279
- /* @__PURE__ */ c("p", { "aria-live": "polite", className: "rst:font-ui rst:m-0 rst:text-sm rst:tabular-nums rst:opacity-75", "data-carousel-position": "", children: Q.position(Ft + 1, T) })
408
+ /* @__PURE__ */ g("p", { "aria-live": "polite", className: "rst:font-ui rst:m-0 rst:text-sm rst:tabular-nums rst:opacity-75", "data-carousel-position": "", children: vt.position(xe + 1, L) })
280
409
  ) : null;
281
- let H = null;
282
- I ? H = I({ prev: L, next: B, position: S }) : M === "controls" && (L || S) && (H = /* @__PURE__ */ k(
410
+ let ot = null;
411
+ B ? ot = B({ prev: K, next: st, position: M }) : J === "controls" && (K || M) && (ot = /* @__PURE__ */ q(
283
412
  "div",
284
413
  {
285
- className: y(
414
+ className: F(
286
415
  "rst:mb-2 rst:items-center rst:justify-end rst:gap-2",
287
416
  /* A line with only arrows in it takes no room where they can't show. */
288
- !S && P === "hover" ? oe : "rst:flex"
417
+ !M && X === "hover" ? We : "rst:flex"
289
418
  ),
290
419
  "data-carousel-controls": "",
291
420
  children: [
292
- S && /* @__PURE__ */ c("div", { className: "rst:mr-auto", children: S }),
293
- L,
294
- B
421
+ M && /* @__PURE__ */ g("div", { className: "rst:mr-auto", children: M }),
422
+ K,
423
+ st
295
424
  ]
296
425
  }
297
426
  ));
298
- const j = vt && o.overflowing && (o.canScrollPrev || o.canScrollNext) ? `linear-gradient(to right, ${o.canScrollPrev ? "transparent, black 48px" : "black"}, ${o.canScrollNext ? "black calc(100% - 48px), transparent" : "black"})` : void 0, z = N === void 0 && C !== void 0, $t = {
299
- "--rst-cv-gap": V(q),
300
- "--rst-cv-gutter": V(X),
301
- ...z ? Qt(C) : {},
302
- ...j ? { maskImage: j, WebkitMaskImage: j } : {}
303
- }, Bt = N !== void 0 ? { width: V(N) } : z ? { width: Yt } : void 0;
304
- return /* @__PURE__ */ k("div", { className: y("rst:min-w-0", St), style: yt, ...wt, children: [
305
- H,
306
- /* @__PURE__ */ k("div", { className: "rst:relative", children: [
307
- /* @__PURE__ */ c(
427
+ const it = Vt && c.overflowing && (c.canScrollPrev || c.canScrollNext) ? `linear-gradient(to right, ${c.canScrollPrev ? "transparent, black 48px" : "black"}, ${c.canScrollNext ? "black calc(100% - 48px), transparent" : "black"})` : void 0, U = S === void 0 && R !== void 0, ke = {
428
+ "--rst-cv-gap": ut(_),
429
+ "--rst-cv-gutter": ut($),
430
+ ...U ? Fe(R) : {},
431
+ ...it ? { maskImage: it, WebkitMaskImage: it } : {}
432
+ }, It = s.useMemo(
433
+ () => S !== void 0 ? { width: ut(S) } : U ? { width: _e } : void 0,
434
+ [S, U]
435
+ ), Nt = F(
436
+ "rst:shrink-0",
437
+ G === "start" ? "rst:snap-start" : "rst:snap-center",
438
+ Ft && "rst:snap-always",
439
+ f && Ge,
440
+ Gt
441
+ );
442
+ return /* @__PURE__ */ q("div", { className: F("rst:min-w-0", Jt), style: Yt, ...Qt, "aria-describedby": f ? void 0 : b, children: [
443
+ ot,
444
+ /* @__PURE__ */ q("div", { className: "rst:relative", children: [
445
+ /* @__PURE__ */ g(
308
446
  "ul",
309
447
  {
310
- ref: g,
311
- id: Y,
312
- role: "list",
448
+ ref: y,
449
+ id: yt,
450
+ role: f ? "listbox" : "list",
313
451
  "aria-label": u,
314
- "aria-labelledby": u ? void 0 : w,
315
- tabIndex: Lt && o.overflowing ? 0 : void 0,
316
- "data-overflowing": o.overflowing ? "" : void 0,
317
- onPointerDown: Rt,
318
- onPointerMove: Pt,
319
- onPointerUp: _,
320
- onPointerCancel: _,
321
- onLostPointerCapture: _,
322
- onClickCapture: Mt,
323
- onDragStart: At,
324
- onFocus: Dt,
325
- style: $t,
326
- className: y(
452
+ "aria-labelledby": u ? void 0 : p,
453
+ "aria-orientation": f ? "horizontal" : void 0,
454
+ "aria-describedby": f ? b : void 0,
455
+ tabIndex: !f && ie && c.overflowing ? 0 : void 0,
456
+ "data-overflowing": c.overflowing ? "" : void 0,
457
+ onPointerDown: ae,
458
+ onPointerMove: ue,
459
+ onPointerUp: rt,
460
+ onPointerCancel: rt,
461
+ onLostPointerCapture: rt,
462
+ onClickCapture: de,
463
+ onClick: f ? ye : void 0,
464
+ onKeyDown: f ? he : void 0,
465
+ onBlur: f ? ve : void 0,
466
+ onDragStart: fe,
467
+ onFocus: ge,
468
+ style: ke,
469
+ className: F(
327
470
  "rst:m-0 rst:flex rst:list-none rst:overflow-x-auto rst:overflow-y-hidden",
328
471
  "rst:gap-(--rst-cv-gap) rst:px-(--rst-cv-gutter) rst:py-1 rst:scroll-px-(--rst-cv-gutter)",
329
472
  "rst:overscroll-x-contain",
330
- it === "mandatory" ? "rst:snap-x rst:snap-mandatory" : "rst:snap-x rst:snap-proximity",
331
- ct && "rst:-mx-(--rst-cv-gutter)",
332
- !mt && "rst:[scrollbar-width:none] rst:[&::-webkit-scrollbar]:hidden",
333
- z && Zt,
473
+ At === "mandatory" ? "rst:snap-x rst:snap-mandatory" : "rst:snap-x rst:snap-proximity",
474
+ Mt && "rst:-mx-(--rst-cv-gutter)",
475
+ !jt && "rst:[scrollbar-width:none] rst:[&::-webkit-scrollbar]:hidden",
476
+ U && $e,
334
477
  "rst:data-overflowing:cursor-grab rst:data-dragging:cursor-grabbing rst:data-dragging:select-none",
335
478
  "rst:focus-visible:outline-hidden rst:focus-visible:ring-2 rst:focus-visible:ring-ring rst:focus-visible:ring-inset",
336
- ht
479
+ Xt
337
480
  ),
338
- children: Z.map((t, e) => /* @__PURE__ */ c(
481
+ children: k ? k.map((t, e) => /* @__PURE__ */ g(
482
+ Xe,
483
+ {
484
+ child: t.child,
485
+ index: e,
486
+ count: L,
487
+ selected: t.key === l,
488
+ active: t.key === E,
489
+ label: Y?.(t.key, e),
490
+ style: It,
491
+ className: Nt
492
+ },
493
+ t.key
494
+ )) : ht.map((t, e) => /* @__PURE__ */ g(
339
495
  "li",
340
496
  {
341
497
  "data-carousel-item": "",
342
- "aria-label": G ? Q.position(e + 1, T) : void 0,
343
- style: Bt,
344
- className: y(
345
- "rst:shrink-0",
346
- R === "start" ? "rst:snap-start" : "rst:snap-center",
347
- at && "rst:snap-always",
348
- xt
349
- ),
498
+ "aria-label": dt ? vt.position(e + 1, L) : void 0,
499
+ style: It,
500
+ className: Nt,
350
501
  children: t
351
502
  },
352
- n.isValidElement(t) && t.key != null ? t.key : e
503
+ s.isValidElement(t) && t.key != null ? t.key : e
353
504
  ))
354
505
  }
355
506
  ),
356
- !I && M === "overlay" && $ && /* @__PURE__ */ k(Ht, { children: [
357
- /* @__PURE__ */ c("div", { className: "rst:pointer-events-none rst:absolute rst:inset-y-0 rst:start-1 rst:flex rst:items-center", children: /* @__PURE__ */ c("div", { className: "rst:pointer-events-auto", children: L }) }),
358
- /* @__PURE__ */ c("div", { className: "rst:pointer-events-none rst:absolute rst:inset-y-0 rst:end-1 rst:flex rst:items-center", children: /* @__PURE__ */ c("div", { className: "rst:pointer-events-auto", children: B }) })
507
+ !B && J === "overlay" && nt && /* @__PURE__ */ q(Ee, { children: [
508
+ /* @__PURE__ */ g("div", { className: "rst:pointer-events-none rst:absolute rst:inset-y-0 rst:start-1 rst:flex rst:items-center", children: /* @__PURE__ */ g("div", { className: "rst:pointer-events-auto", children: K }) }),
509
+ /* @__PURE__ */ g("div", { className: "rst:pointer-events-none rst:absolute rst:inset-y-0 rst:end-1 rst:flex rst:items-center", children: /* @__PURE__ */ g("div", { className: "rst:pointer-events-auto", children: st }) })
359
510
  ] })
360
511
  ] })
361
512
  ] });
362
513
  });
363
514
  export {
364
- pe as Carousel
515
+ cr as Carousel
365
516
  };