@stackone/malachite 2.33.1 → 2.34.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,24 +1,22 @@
1
- import { jsxs as M, jsx as u } from "react/jsx-runtime";
2
- import $, { useRef as H, useState as mt, useCallback as L, useLayoutEffect as X } from "react";
3
- import Xt from "./CustomIcons/ArrowLeftIcon.js";
4
- import Wt from "./CustomIcons/ForwardArrowIcon.js";
5
- import Mt from "./CustomIcons/PlusIcon.js";
6
- import { CONTENT_INSET as Rt } from "./PageLayout/constants.js";
7
- import { CARD_FLARE_PX as m, STRIP_RULE_PX as Yt, CARD_FLARE_TIP_PX as et, CARD_WIDTH_PX as Vt, FLARE_CLASS as zt } from "./SelectableCard.js";
8
- import { CardStripSlotContext as gt, PINNED_SLOT as Kt, SCROLLED_SLOT as jt } from "./cardStripSlot.js";
9
- import { FOCUS_RING as qt } from "./focusRing.js";
10
- import { useAdoptedStyleSheet as Zt } from "./useAdoptedStyleSheet.js";
11
- const Jt = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"]), I = '[role="radio"]', Qt = "data-card-strip-scroller", te = "data-card-strip-trough", Y = "malachite-card-strip", R = "malachite-card-strip-scroller", wt = "malachite-card-strip-fade", x = "malachite-card-strip-add-tile", Ct = "[data-selectable-card-actions]", ee = 'a[href], area[href], button, input, select, textarea, iframe, [contenteditable="true"], [tabindex]', C = "data-card-strip-prev-tabindex", Q = 1, re = 0.8, ne = (t) => {
12
- const [r, c] = Array.from(t.children), s = r && c ? c.getBoundingClientRect().left - r.getBoundingClientRect().left : (r == null ? void 0 : r.getBoundingClientRect().width) ?? 0, i = t.clientWidth - m * 2;
13
- return s <= 0 ? i * re : Math.max(1, Math.floor(i / s)) * s;
14
- }, oe = 80, ae = 20, _t = 11, T = 12, P = 52, ce = (P + ae) / 2, It = "var(--malachite-shadow-default)", se = "var(--malachite-card-strip-arrow-background, var(--malachite-card-background, #ffffff))", ie = "var(--malachite-card-strip-arrow-border, #e8e8e8)", rt = "var(--malachite-card-strip-background, #f1f1f1)", At = "var(--malachite-radius-xxl, 14px)", le = `${At} ${At} 0 0`, xt = "var(--malachite-radius-xxxl, 16px)", de = `${xt} ${xt} 0 0`, V = 4, St = oe + (m - V), ue = Vt, fe = "var(--malachite-card-strip-divider, #dddddd)", Et = "var(--malachite-card-strip-fade, transparent)", pe = "var(--malachite-selectable-card-hover-background, #e8e8e8)", he = "var(--malachite-card-strip-arrow-border, #e8e8e8)", Lt = "var(--malachite-selectable-card-hover-rule, #bbbbbb)", $t = "0px 1px 0px 0px rgba(0, 0, 0, 0.4)", be = "var(--malachite-card-background, #ffffff)", me = "var(--malachite-text-primary, #0a0a0a)", Re = "var(--malachite-card-strip-add-primary-background, var(--malachite-text-primary, #0a0a0a))", ge = "var(--malachite-card-strip-add-primary-foreground, var(--malachite-card-background, #ffffff))", _e = "0px 1px 0px 0px rgba(10, 10, 10, 0.7)", ot = Yt, Tt = 16, W = 9999, Ae = 4, xe = `
15
- .${Y} {
16
- clip-path: inset(-${W}px -${W}px 0);
1
+ import { jsxs as U, jsx as h } from "react/jsx-runtime";
2
+ import C, { useRef as O, useState as nt, useLayoutEffect as w, useCallback as S } from "react";
3
+ import re from "./CustomIcons/ArrowLeftIcon.js";
4
+ import ne from "./CustomIcons/ForwardArrowIcon.js";
5
+ import oe from "./CustomIcons/PlusIcon.js";
6
+ import { CONTENT_INSET as $t } from "./PageLayout/constants.js";
7
+ import { STRIP_RULE_PX as ae, CARD_FLARE_TIP_PX as ct, CARD_WIDTH_PX as ce, FLARE_CLASS as se, CARD_FLARE_PX as q } from "./SelectableCard.js";
8
+ import { revealTargetFor as Dt, pageTargetFor as ie, EDGE_EPSILON_PX as ot, isCardInView as le } from "./cardStripGeometry.js";
9
+ import { CardStripSlotContext as yt, PINNED_SLOT as de, SCROLLED_SLOT as ue } from "./cardStripSlot.js";
10
+ import { FOCUS_RING as fe } from "./focusRing.js";
11
+ import { useAdoptedStyleSheet as Ot } from "./useAdoptedStyleSheet.js";
12
+ const pe = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End"]), G = '[role="radio"]', he = "data-card-strip-scroller", me = "data-card-strip-trough", K = "malachite-card-strip", g = "malachite-card-strip-scroller", Xt = "malachite-card-strip-fade", R = "malachite-card-strip-add-tile", st = "data-card-strip-add-slot", Wt = "[data-selectable-card-actions]", be = 'a[href], area[href], button, input, select, textarea, iframe, [contenteditable="true"], [tabindex]', B = "data-card-strip-prev-tabindex", ge = 80, vt = 11, H = 12, zt = "var(--malachite-shadow-default)", Re = "var(--malachite-card-strip-arrow-background, var(--malachite-card-background, #ffffff))", _e = "var(--malachite-card-strip-arrow-border, #e8e8e8)", it = "var(--malachite-card-strip-background, #f1f1f1)", wt = "var(--malachite-radius-xxl, 14px)", Ae = `${wt} ${wt} 0 0`, Ct = "var(--malachite-radius-xxxl, 16px)", Se = `${Ct} ${Ct} 0 0`, v = 4, xe = H + v, Yt = H, It = ge + (Yt - v), dt = ce, Le = 2 * (H + v) + dt, Ee = "var(--malachite-card-strip-divider, #dddddd)", Pt = "var(--malachite-card-strip-fade, transparent)", Te = "var(--malachite-selectable-card-hover-background, #e8e8e8)", $e = "var(--malachite-card-strip-arrow-border, #e8e8e8)", kt = "var(--malachite-selectable-card-hover-rule, #bbbbbb)", Nt = "0px 1px 0px 0px rgba(0, 0, 0, 0.4)", De = "var(--malachite-card-background, #ffffff)", ye = "var(--malachite-text-primary, #0a0a0a)", Oe = "var(--malachite-card-strip-add-primary-background, var(--malachite-text-primary, #0a0a0a))", ve = "var(--malachite-card-strip-add-primary-foreground, var(--malachite-card-background, #ffffff))", we = "0px 1px 0px 0px rgba(10, 10, 10, 0.7)", ut = ae, Ft = 16, M = 9999, Ce = 4, Ie = `
13
+ .${K} {
14
+ clip-path: inset(-${M}px -${M}px 0);
17
15
  }
18
- .${Y}:has(:focus-visible) {
19
- clip-path: inset(-${W}px -${W}px -${Ae}px);
16
+ .${K}:has(:focus-visible) {
17
+ clip-path: inset(-${M}px -${M}px -${Ce}px);
20
18
  }
21
- .${R} {
19
+ .${g} {
22
20
  display: flex;
23
21
  flex-wrap: nowrap;
24
22
  overflow-x: auto;
@@ -26,405 +24,471 @@ const Jt = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight", "ArrowUp", "Arrow
26
24
  scroll-behavior: smooth;
27
25
  scrollbar-width: none;
28
26
  -ms-overflow-style: none;
29
- padding-block: ${Tt}px;
30
- margin-block: -${Tt}px;
27
+ padding-block: ${Ft}px;
28
+ margin-block: -${Ft}px;
31
29
  /* overflow-x clips both axes, so the end cards would lose a flare; the negative margin trades
32
30
  the padding back out and scroll-padding keeps the rest position at zero. */
33
- padding-inline: ${m}px;
34
- margin-inline: -${m}px;
35
- scroll-padding-inline: ${m}px;
31
+ padding-inline: ${q}px;
32
+ margin-inline: -${q}px;
33
+ scroll-padding-inline: ${q}px;
36
34
  }
37
35
  /* A card focused at a faded edge has to stay readable, so the fade lifts entirely. */
38
- .${Y}:has(:focus-visible) .${wt} {
36
+ .${K}:has(:focus-visible) .${Xt} {
39
37
  display: none;
40
38
  }
41
- .${R}::-webkit-scrollbar {
39
+ .${g}::-webkit-scrollbar {
42
40
  display: none;
43
41
  }
44
42
  /* No bottom edge: the strip's rule is the baseline for the add tile as much as for a card. */
45
- .${x} > * {
46
- background: ${rt};
47
- border-radius: ${le};
43
+ .${R} > * {
44
+ background: ${it};
45
+ border-radius: ${Ae};
48
46
  }
49
- .${x}:hover:not(:has(button:disabled)) > * {
50
- background: ${pe};
47
+ .${R}:hover:not(:has(button:disabled)) > * {
48
+ background: ${Te};
51
49
  }
52
- .${x} button:active:not(:disabled) {
50
+ .${R} button:active:not(:disabled) {
53
51
  opacity: 0.8;
54
52
  }
55
- .${x}:has(button:active) > * {
56
- background: ${rt};
53
+ .${R}:has(button:active) > * {
54
+ background: ${it};
57
55
  }
58
- .${x}[data-emphasis='secondary'] button {
59
- border-color: ${he};
60
- box-shadow: ${It};
56
+ .${R}[data-emphasis='secondary'] button {
57
+ border-color: ${$e};
58
+ box-shadow: ${zt};
61
59
  }
62
- .${x}[data-emphasis='secondary']:hover:not(:has(button:disabled)) button {
63
- border-color: ${Lt};
64
- box-shadow: ${$t};
60
+ .${R}[data-emphasis='secondary']:hover:not(:has(button:disabled)) button {
61
+ border-color: ${kt};
62
+ box-shadow: ${Nt};
65
63
  }
66
- .${x}[data-emphasis='secondary'] button:active:not(:disabled) {
67
- border-color: ${Lt};
68
- box-shadow: ${$t};
64
+ .${R}[data-emphasis='secondary'] button:active:not(:disabled) {
65
+ border-color: ${kt};
66
+ box-shadow: ${Nt};
69
67
  }
70
- .${x}[data-emphasis='primary'] button {
68
+ .${R}[data-emphasis='primary'] button {
71
69
  border-color: transparent;
72
- box-shadow: ${_e};
70
+ box-shadow: ${we};
73
71
  }
74
- .${R} > * {
72
+ .${g} > * {
75
73
  flex: 0 0 auto;
76
74
  min-width: 0;
77
75
  }
78
- .${R} > * + * {
79
- border-left: 1px solid ${fe};
76
+ .${g} > * + * {
77
+ border-left: 1px solid ${Ee};
80
78
  }
81
- .${R}[data-snap='true'] {
79
+ .${g}[data-snap='true'] {
82
80
  scroll-snap-type: x proximity;
83
81
  }
84
- .${R}[data-snap='true'] > * {
82
+ .${g}[data-snap='true'] > * {
85
83
  scroll-snap-align: start;
86
84
  }
87
85
  @media (prefers-reduced-motion: reduce) {
88
- .${R} {
86
+ .${g} {
89
87
  scroll-behavior: auto;
90
88
  }
91
- .${R}[data-snap='true'] {
89
+ .${g}[data-snap='true'] {
92
90
  scroll-snap-type: none;
93
91
  }
94
- .${R}[data-snap='true'] > * {
92
+ .${g}[data-snap='true'] > * {
95
93
  scroll-snap-align: none;
96
94
  }
97
- }`, Se = "malachite-card-strip-style", vt = () => typeof window > "u" || typeof window.matchMedia != "function" ? !0 : window.matchMedia("(prefers-reduced-motion: reduce)").matches, A = (t) => t.dataset.value ?? t.getAttribute("value"), tt = (t) => t.hasAttribute("disabled") || t.getAttribute("aria-disabled") === "true", Ee = (t) => {
98
- const r = t.parentElement;
99
- return !r || r.querySelectorAll(I).length !== 1 ? null : r.querySelector(Ct);
100
- }, Le = (t, r) => {
101
- const c = t.closest(I);
102
- if (c)
103
- return c;
104
- if (t.closest(Ct))
95
+ }`, Pe = "malachite-card-strip-style", ke = "malachite-card-strip-add-slot", Ne = `
96
+ .${g} > [${st}] {
97
+ display: flex;
98
+ border-left: none;
99
+ }
100
+ [${st}] > .${R} {
101
+ height: 100% !important;
102
+ padding: 0 !important;
103
+ }
104
+ `, Ut = () => typeof window > "u" || typeof window.matchMedia != "function" ? !0 : window.matchMedia("(prefers-reduced-motion: reduce)").matches, x = (e) => e.dataset.value ?? e.getAttribute("value"), at = (e) => e.hasAttribute("disabled") || e.getAttribute("aria-disabled") === "true", Fe = (e) => {
105
+ const a = e.parentElement;
106
+ return !a || a.querySelectorAll(G).length !== 1 ? null : a.querySelector(Wt);
107
+ }, Ue = (e, a) => {
108
+ const l = e.closest(G);
109
+ if (l)
110
+ return l;
111
+ if (e.closest(Wt))
105
112
  return null;
106
- let s = t;
107
- for (; s && r.contains(s); ) {
108
- const i = s.querySelectorAll(I);
109
- if (i.length === 1 && i[0].parentElement === s)
110
- return i[0];
111
- s = s.parentElement;
113
+ let u = e;
114
+ for (; u && a.contains(u); ) {
115
+ const f = u.querySelectorAll(G);
116
+ if (f.length === 1 && f[0].parentElement === u)
117
+ return f[0];
118
+ u = u.parentElement;
112
119
  }
113
120
  return null;
114
- }, $e = (t) => {
115
- const r = Ee(t);
116
- return r ? Array.from(r.querySelectorAll(ee)) : [];
117
- }, Te = (t) => {
118
- t.hasAttribute(C) || t.setAttribute(C, t.getAttribute("tabindex") ?? ""), t.setAttribute("tabindex", "-1");
119
- }, ve = (t) => {
120
- if (!t.hasAttribute(C))
121
+ }, Be = (e) => {
122
+ const a = Fe(e);
123
+ return a ? Array.from(a.querySelectorAll(be)) : [];
124
+ }, Ge = (e) => {
125
+ e.hasAttribute(B) || e.setAttribute(B, e.getAttribute("tabindex") ?? ""), e.setAttribute("tabindex", "-1");
126
+ }, He = (e) => {
127
+ if (!e.hasAttribute(B))
121
128
  return;
122
- const r = t.getAttribute(C);
123
- t.removeAttribute(C), r ? t.setAttribute("tabindex", r) : t.removeAttribute("tabindex");
124
- }, ye = {
129
+ const a = e.getAttribute(B);
130
+ e.removeAttribute(B), a ? e.setAttribute("tabindex", a) : e.removeAttribute("tabindex");
131
+ }, Xe = {
125
132
  profile: "var(--malachite-selectable-card-selected-border, #047b43)",
126
133
  library: "var(--malachite-selectable-card-library-selected-border, #bbbbbb)",
127
134
  editing: "var(--malachite-selectable-card-pending-foreground, #96580a)"
128
- }, De = {
135
+ }, We = {
129
136
  backgroundRepeat: "no-repeat",
130
137
  backgroundPosition: "left bottom",
131
- backgroundSize: `100% ${ot}px`
132
- }, yt = 0.5, Dt = m - et, Oe = (t) => {
133
- const r = t.querySelector(`:scope > .${zt}`);
134
- if (!r)
138
+ backgroundSize: `100% ${ut}px`
139
+ }, Bt = 0.5, Gt = q - ct, ze = (e) => {
140
+ const a = e.querySelector(`:scope > .${se}`);
141
+ if (!a)
135
142
  return null;
136
- const { left: c, right: s } = r.getBoundingClientRect();
137
- return { left: c + Dt, right: s - Dt };
138
- }, we = (t, r, c, s) => {
139
- if (!t)
143
+ const { left: l, right: u } = a.getBoundingClientRect();
144
+ return { left: l + Gt, right: u - Gt };
145
+ }, Ye = (e, a, l, u) => {
146
+ if (!e)
140
147
  return;
141
- const i = ye[s], S = t.getBoundingClientRect(), v = S.left, k = c && (r != null && r.contains(c)) ? r.getBoundingClientRect() : S, E = c == null ? void 0 : c.getBoundingClientRect(), g = c ? Oe(c) : null, K = (g == null ? void 0 : g.left) ?? (E ? E.left - et : 0), j = (g == null ? void 0 : g.right) ?? (E ? E.right + et : 0), y = E ? Math.max(K, k.left) + yt - v : 0, b = E ? Math.min(j, k.right) - yt - v : 0;
142
- t.style.backgroundImage = b > y ? `linear-gradient(to right, ${i} 0 ${y}px, transparent ${y}px ${b}px, ${i} ${b}px 100%)` : `linear-gradient(to right, ${i} 0 100%)`;
143
- }, Ce = {
144
- marginInline: `calc(${Rt} * -1)`,
145
- paddingInline: Rt
146
- }, z = {
147
- background: rt,
148
- borderRadius: de,
149
- paddingTop: `${V}px`,
150
- paddingInline: `${V}px`,
151
- marginBottom: `${ot}px`
152
- }, Ie = {
153
- ...z,
154
- marginInline: `${T}px`
155
- }, Pe = Object.fromEntries(
156
- [T, P].flatMap(
157
- (t) => [T, P].map((r) => [
158
- `${t}:${r}`,
159
- { ...z, marginInline: `${t}px ${r}px` }
160
- ])
161
- )
162
- ), ke = z, Ne = z, Ue = {
163
- marginInlineStart: `${T}px`
164
- }, Be = {
148
+ const f = Xe[u], T = e.getBoundingClientRect(), I = T.left, _ = l && (a != null && a.contains(l)) ? a.getBoundingClientRect() : T, L = l == null ? void 0 : l.getBoundingClientRect(), m = l ? ze(l) : null, j = (m == null ? void 0 : m.left) ?? (L ? L.left - ct : 0), J = (m == null ? void 0 : m.right) ?? (L ? L.right + ct : 0), P = L ? Math.max(j, _.left) + Bt - I : 0, b = L ? Math.min(J, _.right) - Bt - I : 0;
149
+ e.style.backgroundImage = b > P ? `linear-gradient(to right, ${f} 0 ${P}px, transparent ${P}px ${b}px, ${f} ${b}px 100%)` : `linear-gradient(to right, ${f} 0 100%)`;
150
+ }, Ve = {
151
+ marginInline: `calc(${$t} * -1)`,
152
+ paddingInline: $t
153
+ }, ft = {
154
+ background: it,
155
+ borderRadius: Se,
156
+ paddingTop: `${v}px`,
157
+ paddingInline: `${v}px`,
158
+ marginBottom: `${ut}px`
159
+ }, Me = {
160
+ ...ft,
161
+ marginInline: `${H}px`
162
+ }, qe = ft, Ke = ft, je = {
163
+ marginInlineStart: `${H}px`
164
+ }, Je = {
165
165
  primary: {
166
- backgroundColor: Re,
167
- color: ge
166
+ backgroundColor: Oe,
167
+ color: ve
168
168
  },
169
- secondary: { backgroundColor: be, color: me }
170
- }, Pt = ({
171
- label: t,
172
- icon: r,
173
- onClick: c,
174
- disabled: s = !1,
175
- emphasis: i = "secondary",
176
- className: S = ""
177
- }) => /* @__PURE__ */ u(
169
+ secondary: { backgroundColor: De, color: ye }
170
+ }, Vt = ({
171
+ label: e,
172
+ icon: a,
173
+ onClick: l,
174
+ disabled: u = !1,
175
+ emphasis: f = "secondary",
176
+ className: T = ""
177
+ }) => /* @__PURE__ */ h(
178
178
  "div",
179
179
  {
180
- className: x,
181
- "data-emphasis": i,
180
+ className: R,
181
+ "data-emphasis": f,
182
182
  style: {
183
- ...ke,
184
- width: `${ue}px`,
185
- height: `calc(100% - ${ot}px)`
183
+ ...qe,
184
+ width: `${dt}px`,
185
+ height: `calc(100% - ${ut}px)`
186
186
  },
187
- children: /* @__PURE__ */ u("div", { className: "flex h-full items-center justify-center px-4", children: /* @__PURE__ */ M(
187
+ children: /* @__PURE__ */ h("div", { className: "flex h-full items-center justify-center px-4", children: /* @__PURE__ */ U(
188
188
  "button",
189
189
  {
190
190
  type: "button",
191
- onClick: c,
192
- disabled: s,
193
- style: Be[i],
194
- className: `${qt} inline-flex items-center justify-center gap-1.5 h-[var(--malachite-control-height-medium,32px)] w-[108px] px-2.5 rounded-xl border border-solid text-[length:var(--malachite-font-size-small,13px)] font-medium whitespace-nowrap ${s ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${S}`,
191
+ onClick: l,
192
+ disabled: u,
193
+ style: Je[f],
194
+ className: `${fe} inline-flex items-center justify-center gap-1.5 h-[var(--malachite-control-height-medium,32px)] w-[108px] px-2.5 rounded-xl border border-solid text-[length:var(--malachite-font-size-small,13px)] font-medium whitespace-nowrap ${u ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${T}`,
195
195
  children: [
196
- /* @__PURE__ */ u("span", { className: "inline-flex h-[13px] w-[13px] shrink-0 items-center justify-center", children: r ?? /* @__PURE__ */ u(Mt, { size: 13 }) }),
197
- t
196
+ /* @__PURE__ */ h("span", { className: "inline-flex h-[13px] w-[13px] shrink-0 items-center justify-center", children: a ?? /* @__PURE__ */ h(oe, { size: 13 }) }),
197
+ e
198
198
  ]
199
199
  }
200
200
  ) })
201
201
  }
202
- ), nt = (t) => $.isValidElement(t) && t.type === Pt, Ge = (t) => $.isValidElement(t) && t.type === $.Fragment && $.Children.toArray(t.props.children).some(nt), Ot = ({ side: t, onClick: r }) => /* @__PURE__ */ u(
202
+ ), lt = (e) => C.isValidElement(e) && e.type === Vt, Qe = (e) => C.isValidElement(e) && e.type === C.Fragment && C.Children.toArray(e.props.children).some(lt), Ht = ({ side: e, onClick: a }) => /* @__PURE__ */ h(
203
203
  "button",
204
204
  {
205
205
  type: "button",
206
206
  tabIndex: -1,
207
207
  "aria-hidden": "true",
208
- "aria-label": t === "left" ? "Scroll left" : "Scroll right",
209
- onClick: r,
208
+ "aria-label": e === "left" ? "Scroll left" : "Scroll right",
209
+ onClick: a,
210
210
  className: "absolute top-1/2 -translate-y-1/2 z-10 inline-flex items-center justify-center w-5 h-5 rounded-lg cursor-pointer text-[var(--malachite-text-secondary)]",
211
211
  style: {
212
- [t]: `-${ce}px`,
213
- background: se,
214
- border: `1px solid ${ie}`,
215
- boxShadow: It
212
+ [e]: `-${xe}px`,
213
+ background: Re,
214
+ border: `1px solid ${_e}`,
215
+ boxShadow: zt
216
216
  },
217
- children: t === "left" ? /* @__PURE__ */ u(Xt, { size: _t }) : /* @__PURE__ */ u(Wt, { size: _t })
217
+ children: e === "left" ? /* @__PURE__ */ h(re, { size: vt }) : /* @__PURE__ */ h(ne, { size: vt })
218
218
  }
219
- ), Fe = ({
220
- value: t,
221
- tone: r,
222
- onChange: c,
223
- children: s,
224
- leading: i,
225
- arrows: S = !0,
226
- fadeEdges: v = !0,
227
- snap: k = !0,
228
- bleed: E = !1,
229
- scrollSelectedIntoView: g = !0,
230
- "aria-label": K,
231
- "aria-labelledby": j,
232
- className: y = "",
219
+ ), Ze = ({
220
+ value: e,
221
+ tone: a,
222
+ onChange: l,
223
+ children: u,
224
+ leading: f,
225
+ arrows: T = !0,
226
+ fadeEdges: I = !0,
227
+ snap: _ = !0,
228
+ bleed: L = !1,
229
+ scrollSelectedIntoView: m = !0,
230
+ "aria-label": j,
231
+ "aria-labelledby": J,
232
+ className: P = "",
233
233
  style: b
234
234
  }) => {
235
- const D = H(null), O = H(null), at = H(!1), [N, kt] = mt({ canScrollLeft: !1, canScrollRight: !1 });
236
- Zt(D, xe, Se);
237
- const q = $.Children.toArray(s), Z = q.filter((e) => !nt(e)), Nt = Z.some(Ge), U = Z.length > 0, ct = q.filter(nt).map(
238
- (e) => e.props.emphasis === void 0 ? $.cloneElement(e, { emphasis: U ? "secondary" : "primary" }) : e
239
- ), st = q.length, _ = L(() => {
240
- const e = D.current;
241
- return e ? Array.from(e.querySelectorAll(I)) : [];
242
- }, []), J = L(
243
- () => _().filter((e) => A(e) !== null),
244
- [_]
245
- ), it = H(/* @__PURE__ */ new Set()), w = L((e, n) => {
246
- it.current.has(e) || (it.current.add(e), console.warn(n));
247
- }, []), [Ut, Bt] = mt("profile");
248
- X(() => {
249
- var n, a;
250
- const e = (a = (n = _().find((d) => A(d) === t)) == null ? void 0 : n.parentElement) == null ? void 0 : a.getAttribute("data-variant");
251
- (e === "profile" || e === "library" || e === "editing") && Bt(e);
252
- }, [_, t]), X(() => {
253
- const e = _(), n = J(), d = n.find((o) => A(o) === t) ?? n.find((o) => !tt(o)) ?? null;
254
- if (e.forEach((o) => {
255
- const h = o === d, G = h ? 0 : -1;
256
- o.tabIndex !== G && (o.tabIndex = G);
257
- for (const F of $e(o))
258
- h ? ve(F) : Te(F);
235
+ const $ = O(null), pt = O(null), k = O(null), ht = O(!1), [X, Mt] = nt({ canScrollLeft: !1, canScrollRight: !1 }), [qt, mt] = nt(!1), W = O(null), bt = O(!1);
236
+ Ot($, Ie, Pe), Ot($, Ne, ke);
237
+ const Q = C.Children.toArray(u), Z = Q.filter((t) => !lt(t)), Kt = Z.some(Qe), D = Z.length > 0, z = Q.filter(lt).map(
238
+ (t) => t.props.emphasis === void 0 ? C.cloneElement(t, { emphasis: D ? "secondary" : "primary" }) : t
239
+ ), gt = Q.length, tt = z.length;
240
+ w(() => {
241
+ const t = $.current;
242
+ if (!t || !D || tt === 0) {
243
+ mt(!1);
244
+ return;
245
+ }
246
+ const r = pt.current, { paddingLeft: o, paddingRight: s } = getComputedStyle(t), i = (parseFloat(o) || 0) + (parseFloat(s) || 0);
247
+ let d = t.clientWidth - i, p = (r == null ? void 0 : r.offsetWidth) ?? 0;
248
+ const n = () => {
249
+ const y = p + tt * dt + Le;
250
+ mt(d > 0 && d < y);
251
+ };
252
+ n();
253
+ const c = typeof ResizeObserver < "u" ? new ResizeObserver((y) => {
254
+ var E, Tt;
255
+ for (const V of y ?? [])
256
+ V.target === t ? d = V.contentRect.width : p = ((Tt = (E = V.borderBoxSize) == null ? void 0 : E[0]) == null ? void 0 : Tt.inlineSize) ?? V.contentRect.width + 2 * v;
257
+ n();
258
+ }) : null;
259
+ return c == null || c.observe(t), r && (c == null || c.observe(r)), () => c == null ? void 0 : c.disconnect();
260
+ }, [D, tt, !!f]);
261
+ const et = qt && D, Rt = S((t) => {
262
+ var o;
263
+ const r = t.type === "focus" ? t.target : t.relatedTarget;
264
+ bt.current = !!(r instanceof Node && ((o = W.current) != null && o.contains(r)));
265
+ }, []);
266
+ w(() => {
267
+ var o;
268
+ const t = W.current, r = t ? t.getRootNode().activeElement : null;
269
+ bt.current && t && !(r && t.contains(r)) && ((o = t.querySelector("button")) == null || o.focus({ preventScroll: !0 }));
270
+ }, [et]);
271
+ const A = S(() => {
272
+ const t = $.current;
273
+ return t ? Array.from(t.querySelectorAll(G)) : [];
274
+ }, []), rt = S(
275
+ () => A().filter((t) => x(t) !== null),
276
+ [A]
277
+ ), _t = O(/* @__PURE__ */ new Set()), N = S((t, r) => {
278
+ _t.current.has(t) || (_t.current.add(t), console.warn(r));
279
+ }, []), [jt, Jt] = nt("profile");
280
+ w(() => {
281
+ var r, o;
282
+ const t = (o = (r = A().find((s) => x(s) === e)) == null ? void 0 : r.parentElement) == null ? void 0 : o.getAttribute("data-variant");
283
+ (t === "profile" || t === "library" || t === "editing") && Jt(t);
284
+ }, [A, e]), w(() => {
285
+ const t = A(), r = rt(), s = r.find((n) => x(n) === e) ?? r.find((n) => !at(n)) ?? null;
286
+ if (t.forEach((n) => {
287
+ const c = n === s, y = c ? 0 : -1;
288
+ n.tabIndex !== y && (n.tabIndex = y);
289
+ for (const E of Be(n))
290
+ c ? He(E) : Ge(E);
259
291
  }), process.env.NODE_ENV === "production")
260
292
  return;
261
- n.length !== e.length && w(
293
+ r.length !== t.length && N(
262
294
  "missing-value",
263
295
  'CardStrip: a child with role="radio" has no `data-value`. It cannot be selected or reached by arrow keys, so it is excluded from the radio set. Give every card a `data-value`.'
264
296
  );
265
- const l = /* @__PURE__ */ new Set();
266
- for (const o of n) {
267
- const h = A(o);
268
- h !== null && (l.has(h) && w(
269
- `duplicate:${h}`,
270
- `CardStrip: two cards share the data-value "${h}". Both will read as checked and only the first is selectable — data-value must be unique.`
271
- ), l.add(h));
297
+ const i = /* @__PURE__ */ new Set();
298
+ for (const n of r) {
299
+ const c = x(n);
300
+ c !== null && (i.has(c) && N(
301
+ `duplicate:${c}`,
302
+ `CardStrip: two cards share the data-value "${c}". Both will read as checked and only the first is selectable — data-value must be unique.`
303
+ ), i.add(c));
272
304
  }
273
- const p = t !== "";
274
- e.length > 0 && p && !l.has(t) && w(
275
- `unmatched:${t}`,
276
- `CardStrip: value "${t}" matches no card's data-value, so the group reports no selection.`
305
+ const d = e !== "";
306
+ t.length > 0 && d && !i.has(e) && N(
307
+ `unmatched:${e}`,
308
+ `CardStrip: value "${e}" matches no card's data-value, so the group reports no selection.`
277
309
  );
278
- const f = e.filter(
279
- (o) => o.getAttribute("aria-checked") === "true"
310
+ const p = t.filter(
311
+ (n) => n.getAttribute("aria-checked") === "true"
280
312
  ).length;
281
- e.length > 0 && p && f !== 1 && w(
282
- `checked:${f}`,
283
- `CardStrip: ${f} cards are aria-checked, but a radiogroup has exactly one. Drive each card's checked state from the strip's \`value\`.`
284
- ), Nt && w(
313
+ t.length > 0 && d && p !== 1 && N(
314
+ `checked:${p}`,
315
+ `CardStrip: ${p} cards are aria-checked, but a radiogroup has exactly one. Drive each card's checked state from the strip's \`value\`.`
316
+ ), Kt && N(
285
317
  "wrapped-add-tile",
286
318
  "CardStrip: a CardStrip.AddTile inside a fragment is treated as a card and scrolls with them. The add tile must be a direct child of CardStrip."
287
319
  );
288
- }), X(() => {
289
- if (!g)
320
+ });
321
+ const F = S(() => {
322
+ const t = A().find((r) => x(r) === e);
323
+ return t ? t.closest('[role="radio"]') ?? t : null;
324
+ }, [A, e]);
325
+ w(() => {
326
+ if (!m)
290
327
  return;
291
- const e = O.current, n = _().find((F) => A(F) === t);
292
- if (!e || !n || typeof e.scrollTo != "function")
328
+ const t = k.current, r = F();
329
+ if (!t || !r || typeof t.scrollTo != "function")
293
330
  return;
294
- const d = (n.closest('[role="radio"]') ?? n).getBoundingClientRect(), l = e.getBoundingClientRect(), p = e.scrollLeft + (d.left - l.left), f = p + d.width, o = e.scrollLeft + m, h = e.scrollLeft + e.clientWidth - m, G = at.current;
295
- at.current = !0, !(p >= o && f <= h) && e.scrollTo({
296
- left: f > h ? f - e.clientWidth + m : p - m,
297
- behavior: G && !vt() ? "smooth" : "instant"
331
+ const o = ht.current;
332
+ ht.current = !0;
333
+ const s = Dt(t, r, _);
334
+ s !== null && t.scrollTo({
335
+ left: s,
336
+ behavior: o && !Ut() ? "smooth" : "instant"
298
337
  });
299
- }, [_, g, t, st]);
300
- const lt = r ?? Ut, dt = (b == null ? void 0 : b.background) !== void 0 || (b == null ? void 0 : b.backgroundImage) !== void 0, B = L(() => {
301
- var f;
302
- const e = O.current;
303
- if (dt || we(
304
- D.current,
305
- e,
306
- (f = _().find((o) => A(o) === t)) == null ? void 0 : f.parentElement,
307
- lt
308
- ), !e)
338
+ }, [F, m, _, gt]);
339
+ const At = a ?? jt, St = (b == null ? void 0 : b.background) !== void 0 || (b == null ? void 0 : b.backgroundImage) !== void 0, Y = S(() => {
340
+ var p;
341
+ const t = k.current;
342
+ if (St || Ye(
343
+ $.current,
344
+ t,
345
+ (p = A().find((n) => x(n) === e)) == null ? void 0 : p.parentElement,
346
+ At
347
+ ), !t)
309
348
  return;
310
- const { scrollWidth: n, clientWidth: a, scrollLeft: d } = e, l = n > a + Q, p = {
311
- canScrollLeft: l && d > Q,
312
- canScrollRight: l && d + a < n - Q
349
+ const { scrollWidth: r, clientWidth: o, scrollLeft: s } = t, i = r > o + ot, d = {
350
+ canScrollLeft: i && s > ot,
351
+ canScrollRight: i && s + o < r - ot
313
352
  };
314
- kt(
315
- (o) => o.canScrollLeft === p.canScrollLeft && o.canScrollRight === p.canScrollRight ? o : p
353
+ Mt(
354
+ (n) => n.canScrollLeft === d.canScrollLeft && n.canScrollRight === d.canScrollRight ? n : d
316
355
  );
317
- }, [dt, _, lt, t]);
318
- X(() => {
319
- B();
320
- const e = O.current;
321
- if (!e)
356
+ }, [St, A, At, e]);
357
+ w(() => {
358
+ Y();
359
+ const t = k.current;
360
+ if (!t)
322
361
  return;
323
- const n = () => B();
324
- e.addEventListener("scroll", n, { passive: !0 });
325
- const a = typeof ResizeObserver < "u" ? new ResizeObserver(() => B()) : null;
326
- return a == null || a.observe(e), () => {
327
- e.removeEventListener("scroll", n), a == null || a.disconnect();
362
+ const r = () => {
363
+ const c = F();
364
+ return c !== null && le(t, c);
328
365
  };
329
- }, [B, st]);
330
- const ut = L((e) => {
331
- const n = O.current;
332
- !n || typeof n.scrollBy != "function" || n.scrollBy({
333
- left: e * ne(n),
334
- behavior: vt() ? "auto" : "smooth"
335
- });
336
- }, []), Gt = L(
337
- (e) => {
338
- if (!Jt.has(e.key))
366
+ let o = r();
367
+ const s = () => {
368
+ Y(), o = r();
369
+ };
370
+ t.addEventListener("scroll", s, { passive: !0 });
371
+ let i = 0;
372
+ const d = () => {
373
+ const c = F(), E = m && o && typeof t.scrollTo == "function" && c ? Dt(t, c, _) : null;
374
+ E !== null && t.scrollTo({ left: E, behavior: "instant" }), o = r();
375
+ }, p = () => {
376
+ if (Y(), typeof requestAnimationFrame != "function") {
377
+ d();
378
+ return;
379
+ }
380
+ cancelAnimationFrame(i), i = requestAnimationFrame(d);
381
+ }, n = typeof ResizeObserver < "u" ? new ResizeObserver(p) : null;
382
+ return n == null || n.observe(t), () => {
383
+ t.removeEventListener("scroll", s), n == null || n.disconnect(), typeof cancelAnimationFrame == "function" && cancelAnimationFrame(i);
384
+ };
385
+ }, [Y, F, m, _, gt]);
386
+ const xt = S(
387
+ (t) => {
388
+ const r = k.current;
389
+ !r || typeof r.scrollBy != "function" || r.scrollBy({
390
+ left: ie(r, t, _) - r.scrollLeft,
391
+ behavior: Ut() ? "auto" : "smooth"
392
+ });
393
+ },
394
+ [_]
395
+ ), Qt = S(
396
+ (t) => {
397
+ if (!pe.has(t.key))
339
398
  return;
340
- const n = e.target;
341
- if (!(n instanceof Element) || !n.closest(I))
399
+ const r = t.target;
400
+ if (!(r instanceof Element) || !r.closest(G))
342
401
  return;
343
- const a = J().filter((o) => !tt(o));
344
- if (a.length === 0)
402
+ const o = rt().filter((n) => !at(n));
403
+ if (o.length === 0)
345
404
  return;
346
- e.preventDefault();
347
- const d = a.findIndex((o) => A(o) === t);
348
- let l;
349
- if (e.key === "Home")
350
- l = 0;
351
- else if (e.key === "End")
352
- l = a.length - 1;
405
+ t.preventDefault();
406
+ const s = o.findIndex((n) => x(n) === e);
407
+ let i;
408
+ if (t.key === "Home")
409
+ i = 0;
410
+ else if (t.key === "End")
411
+ i = o.length - 1;
353
412
  else {
354
- const o = e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1 : 1;
355
- l = ((d === -1 ? 0 : d) + o + a.length) % a.length;
413
+ const n = t.key === "ArrowLeft" || t.key === "ArrowUp" ? -1 : 1;
414
+ i = ((s === -1 ? 0 : s) + n + o.length) % o.length;
356
415
  }
357
- const p = a[l], f = A(p);
358
- f !== null && f !== t && c(f), p.focus();
416
+ const d = o[i], p = x(d);
417
+ p !== null && p !== e && l(p), d.focus();
359
418
  },
360
- [J, c, t]
361
- ), Ft = L(
362
- (e) => {
363
- const n = e.target;
364
- if (!(n instanceof Element))
419
+ [rt, l, e]
420
+ ), Zt = S(
421
+ (t) => {
422
+ const r = t.target;
423
+ if (!(r instanceof Element) || r.closest(`.${R}`))
365
424
  return;
366
- const a = D.current;
367
- if (!a)
425
+ const o = $.current;
426
+ if (!o)
368
427
  return;
369
- const d = Le(n, a);
370
- if (!d || tt(d))
428
+ const s = Ue(r, o);
429
+ if (!s || at(s))
371
430
  return;
372
- const l = A(d);
373
- l !== null && l !== t && c(l);
431
+ const i = x(s);
432
+ i !== null && i !== e && l(i);
374
433
  },
375
- [c, t]
376
- ), ft = S && N.canScrollLeft, pt = S && N.canScrollRight, ht = v && N.canScrollLeft, bt = v && N.canScrollRight, Ht = S ? Pe[`${ft ? P : T}:${pt ? P : T}`] : Ie;
377
- return /* @__PURE__ */ M(
434
+ [l, e]
435
+ ), te = T && X.canScrollLeft, ee = T && X.canScrollRight, Lt = I && X.canScrollLeft, Et = I && X.canScrollRight;
436
+ return /* @__PURE__ */ U(
378
437
  "div",
379
438
  {
380
- ref: D,
381
- onKeyDown: Gt,
382
- onClick: Ft,
383
- className: `${Y} flex items-stretch ${y}`,
439
+ ref: $,
440
+ onKeyDown: Qt,
441
+ onFocus: Rt,
442
+ onBlur: Rt,
443
+ onClick: Zt,
444
+ className: `${K} flex items-stretch ${P}`,
384
445
  style: {
385
- ...De,
386
- ...E ? Ce : null,
446
+ ...We,
447
+ ...L ? Ve : null,
387
448
  ...b
388
449
  },
389
450
  children: [
390
- /* @__PURE__ */ M(
451
+ /* @__PURE__ */ U(
391
452
  "div",
392
453
  {
393
454
  role: "radiogroup",
394
- "aria-label": K,
395
- "aria-labelledby": j,
396
- className: U ? "flex items-stretch min-w-0" : "flex items-stretch",
455
+ "aria-label": j,
456
+ "aria-labelledby": J,
457
+ className: D ? "flex items-stretch min-w-0" : "flex items-stretch",
397
458
  children: [
398
- i ? /* @__PURE__ */ u(gt.Provider, { value: Kt, children: /* @__PURE__ */ u("div", { className: "shrink-0", style: Ne, children: i }) }) : null,
399
- U ? /* @__PURE__ */ M(
459
+ f ? /* @__PURE__ */ h(yt.Provider, { value: de, children: /* @__PURE__ */ h("div", { ref: pt, className: "shrink-0", style: Ke, children: f }) }) : null,
460
+ D ? /* @__PURE__ */ U(
400
461
  "div",
401
462
  {
402
- [te]: "",
463
+ [me]: "",
403
464
  className: "relative min-w-0 shrink basis-auto",
404
- style: Ht,
465
+ style: Me,
405
466
  children: [
406
- /* @__PURE__ */ u(
467
+ /* @__PURE__ */ U(
407
468
  "div",
408
469
  {
409
- ref: O,
470
+ ref: k,
410
471
  tabIndex: -1,
411
- [Qt]: "",
412
- "data-snap": k ? "true" : "false",
413
- className: R,
414
- children: /* @__PURE__ */ u(gt.Provider, { value: jt, children: Z })
472
+ [he]: "",
473
+ "data-snap": _ ? "true" : "false",
474
+ className: g,
475
+ children: [
476
+ /* @__PURE__ */ h(yt.Provider, { value: ue, children: Z }),
477
+ et ? /* @__PURE__ */ h("div", { ref: W, [st]: "", children: z }) : null
478
+ ]
415
479
  }
416
480
  ),
417
- ft ? /* @__PURE__ */ u(Ot, { side: "left", onClick: () => ut(-1) }) : null,
418
- pt ? /* @__PURE__ */ u(Ot, { side: "right", onClick: () => ut(1) }) : null,
419
- ht || bt ? /* @__PURE__ */ u(
481
+ te ? /* @__PURE__ */ h(Ht, { side: "left", onClick: () => xt(-1) }) : null,
482
+ ee ? /* @__PURE__ */ h(Ht, { side: "right", onClick: () => xt(1) }) : null,
483
+ Lt || Et ? /* @__PURE__ */ h(
420
484
  "div",
421
485
  {
422
486
  "aria-hidden": !0,
423
487
  "data-card-strip-fade": "",
424
- className: `${wt} absolute pointer-events-none`,
488
+ className: `${Xt} absolute pointer-events-none`,
425
489
  style: {
426
- inset: `-${V}px -${m}px 0`,
427
- background: `linear-gradient(to right, ${ht ? Et : "transparent"} 0, transparent ${St}px, transparent calc(100% - ${St}px), ${bt ? Et : "transparent"} 100%)`
490
+ inset: `-${v}px -${Yt}px 0`,
491
+ background: `linear-gradient(to right, ${Lt ? Pt : "transparent"} 0, transparent ${It}px, transparent calc(100% - ${It}px), ${Et ? Pt : "transparent"} 100%)`
428
492
  }
429
493
  }
430
494
  ) : null
@@ -434,21 +498,22 @@ const Jt = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight", "ArrowUp", "Arrow
434
498
  ]
435
499
  }
436
500
  ),
437
- ct.length > 0 ? /* @__PURE__ */ u(
501
+ z.length > 0 && !et ? /* @__PURE__ */ h(
438
502
  "div",
439
503
  {
504
+ ref: W,
440
505
  className: "shrink-0",
441
- style: !U && i ? Ue : void 0,
442
- children: ct
506
+ style: !D && f ? je : void 0,
507
+ children: z
443
508
  }
444
509
  ) : null
445
510
  ]
446
511
  }
447
512
  );
448
513
  };
449
- Fe.AddTile = Pt;
514
+ Ze.AddTile = Vt;
450
515
  export {
451
- Fe as CardStrip,
452
- Fe as default
516
+ Ze as CardStrip,
517
+ Ze as default
453
518
  };
454
519
  //# sourceMappingURL=CardStrip.js.map