@arcadeai/design-system 3.27.0 → 3.27.1

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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/dist/calendar-w1IATMME.js +3042 -0
  3. package/dist/components/index.js +442 -435
  4. package/dist/components/ui/atoms/calendar.d.ts +21 -0
  5. package/dist/components/ui/atoms/calendar.d.ts.map +1 -0
  6. package/dist/components/ui/atoms/calendar.js +10 -0
  7. package/dist/components/ui/atoms/index.d.ts +2 -0
  8. package/dist/components/ui/atoms/index.d.ts.map +1 -1
  9. package/dist/components/ui/atoms/index.js +427 -422
  10. package/dist/components/ui/atoms/virtualized-grid.d.ts +23 -0
  11. package/dist/components/ui/atoms/virtualized-grid.d.ts.map +1 -0
  12. package/dist/components/ui/atoms/virtualized-grid.js +682 -0
  13. package/dist/components/ui/index.js +442 -435
  14. package/dist/components/ui/molecules/date-time-picker.d.ts +12 -0
  15. package/dist/components/ui/molecules/date-time-picker.d.ts.map +1 -0
  16. package/dist/components/ui/molecules/date-time-picker.js +84 -0
  17. package/dist/components/ui/molecules/index.d.ts +1 -0
  18. package/dist/components/ui/molecules/index.d.ts.map +1 -1
  19. package/dist/components/ui/molecules/index.js +13 -11
  20. package/dist/components/ui/molecules/requirement-badges.js +6 -5
  21. package/dist/components/ui/molecules/toolkit-card.d.ts.map +1 -1
  22. package/dist/components/ui/molecules/toolkit-card.js +1 -1
  23. package/dist/components/ui/molecules/toolkit-selection-summary.js +5 -4
  24. package/dist/components/ui/organisms/toolkit-picker/components/search-input.js +15 -14
  25. package/dist/components/ui/organisms/toolkit-picker/components/select-button.d.ts.map +1 -1
  26. package/dist/components/ui/organisms/toolkit-picker/components/select-button.js +10 -9
  27. package/dist/components/ui/organisms/toolkit-picker/components/toolkit-card-with-selection.js +1 -1
  28. package/dist/components/ui/organisms/toolkit-picker/components/toolkit-list.d.ts +3 -1
  29. package/dist/components/ui/organisms/toolkit-picker/components/toolkit-list.d.ts.map +1 -1
  30. package/dist/components/ui/organisms/toolkit-picker/components/toolkit-list.js +109 -57
  31. package/dist/components/ui/organisms/toolkit-picker/components/tools-list.d.ts +3 -1
  32. package/dist/components/ui/organisms/toolkit-picker/components/tools-list.d.ts.map +1 -1
  33. package/dist/components/ui/organisms/toolkit-picker/components/tools-list.js +74 -69
  34. package/dist/components/ui/organisms/toolkit-picker/hooks/featured-toolkits.d.ts +8 -0
  35. package/dist/components/ui/organisms/toolkit-picker/hooks/featured-toolkits.d.ts.map +1 -0
  36. package/dist/components/ui/organisms/toolkit-picker/hooks/featured-toolkits.js +11 -0
  37. package/dist/components/ui/organisms/toolkit-picker/hooks/use-toolkit-picker.d.ts +6 -4
  38. package/dist/components/ui/organisms/toolkit-picker/hooks/use-toolkit-picker.d.ts.map +1 -1
  39. package/dist/components/ui/organisms/toolkit-picker/hooks/use-toolkit-picker.js +195 -261
  40. package/dist/components/ui/organisms/toolkit-picker/mocks/toolkit-collection.d.ts +5 -1
  41. package/dist/components/ui/organisms/toolkit-picker/mocks/toolkit-collection.d.ts.map +1 -1
  42. package/dist/components/ui/organisms/toolkit-picker/mocks/toolkit-collection.js +154 -80
  43. package/dist/components/ui/organisms/toolkit-picker/toolkit-picker.d.ts.map +1 -1
  44. package/dist/components/ui/organisms/toolkit-picker/toolkit-picker.js +89 -75
  45. package/dist/hooks/use-columns.d.ts +6 -0
  46. package/dist/hooks/use-columns.d.ts.map +1 -0
  47. package/dist/hooks/use-columns.js +20 -0
  48. package/dist/main.js +476 -469
  49. package/dist/{toolkit-card-CsV6xoOG.js → toolkit-card-Qou74oWg.js} +4 -2
  50. package/package.json +7 -2
@@ -0,0 +1,682 @@
1
+ import { jsx as x } from "react/jsx-runtime";
2
+ import * as M from "react";
3
+ import { useRef as F, useState as D, useEffect as T, useMemo as k } from "react";
4
+ import { flushSync as N } from "react-dom";
5
+ function y(r, l, e) {
6
+ let s = e.initialDeps ?? [], t, n = !0;
7
+ function o() {
8
+ var i, h, u;
9
+ let c;
10
+ e.key && ((i = e.debug) != null && i.call(e)) && (c = Date.now());
11
+ const v = r();
12
+ if (!(v.length !== s.length || v.some((b, f) => s[f] !== b)))
13
+ return t;
14
+ s = v;
15
+ let g;
16
+ if (e.key && ((h = e.debug) != null && h.call(e)) && (g = Date.now()), t = l(...v), e.key && ((u = e.debug) != null && u.call(e))) {
17
+ const b = Math.round((Date.now() - c) * 100) / 100, f = Math.round((Date.now() - g) * 100) / 100, m = f / 16, p = (d, E) => {
18
+ for (d = String(d); d.length < E; )
19
+ d = " " + d;
20
+ return d;
21
+ };
22
+ console.info(
23
+ `%c⏱ ${p(f, 5)} /${p(b, 5)} ms`,
24
+ `
25
+ font-size: .6rem;
26
+ font-weight: bold;
27
+ color: hsl(${Math.max(
28
+ 0,
29
+ Math.min(120 - 120 * m, 120)
30
+ )}deg 100% 31%);`,
31
+ e?.key
32
+ );
33
+ }
34
+ return e?.onChange && !(n && e.skipInitialOnChange) && e.onChange(t), n = !1, t;
35
+ }
36
+ return o.updateDeps = (i) => {
37
+ s = i;
38
+ }, o;
39
+ }
40
+ function O(r, l) {
41
+ if (r === void 0)
42
+ throw new Error("Unexpected undefined");
43
+ return r;
44
+ }
45
+ const W = (r, l) => Math.abs(r - l) < 1.01, L = (r, l, e) => {
46
+ let s;
47
+ return function(...t) {
48
+ r.clearTimeout(s), s = r.setTimeout(() => l.apply(this, t), e);
49
+ };
50
+ }, z = (r) => {
51
+ const { offsetWidth: l, offsetHeight: e } = r;
52
+ return { width: l, height: e };
53
+ }, V = (r) => r, j = (r) => {
54
+ const l = Math.max(r.startIndex - r.overscan, 0), e = Math.min(r.endIndex + r.overscan, r.count - 1), s = [];
55
+ for (let t = l; t <= e; t++)
56
+ s.push(t);
57
+ return s;
58
+ }, B = (r, l) => {
59
+ const e = r.scrollElement;
60
+ if (!e)
61
+ return;
62
+ const s = r.targetWindow;
63
+ if (!s)
64
+ return;
65
+ const t = (o) => {
66
+ const { width: i, height: h } = o;
67
+ l({ width: Math.round(i), height: Math.round(h) });
68
+ };
69
+ if (t(z(e)), !s.ResizeObserver)
70
+ return () => {
71
+ };
72
+ const n = new s.ResizeObserver((o) => {
73
+ const i = () => {
74
+ const h = o[0];
75
+ if (h?.borderBoxSize) {
76
+ const u = h.borderBoxSize[0];
77
+ if (u) {
78
+ t({ width: u.inlineSize, height: u.blockSize });
79
+ return;
80
+ }
81
+ }
82
+ t(z(e));
83
+ };
84
+ r.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(i) : i();
85
+ });
86
+ return n.observe(e, { box: "border-box" }), () => {
87
+ n.unobserve(e);
88
+ };
89
+ }, C = {
90
+ passive: !0
91
+ }, I = typeof window > "u" ? !0 : "onscrollend" in window, P = (r, l) => {
92
+ const e = r.scrollElement;
93
+ if (!e)
94
+ return;
95
+ const s = r.targetWindow;
96
+ if (!s)
97
+ return;
98
+ let t = 0;
99
+ const n = r.options.useScrollendEvent && I ? () => {
100
+ } : L(
101
+ s,
102
+ () => {
103
+ l(t, !1);
104
+ },
105
+ r.options.isScrollingResetDelay
106
+ ), o = (c) => () => {
107
+ const { horizontal: v, isRtl: a } = r.options;
108
+ t = v ? e.scrollLeft * (a && -1 || 1) : e.scrollTop, n(), l(t, c);
109
+ }, i = o(!0), h = o(!1);
110
+ e.addEventListener("scroll", i, C);
111
+ const u = r.options.useScrollendEvent && I;
112
+ return u && e.addEventListener("scrollend", h, C), () => {
113
+ e.removeEventListener("scroll", i), u && e.removeEventListener("scrollend", h);
114
+ };
115
+ }, $ = (r, l, e) => {
116
+ if (l?.borderBoxSize) {
117
+ const s = l.borderBoxSize[0];
118
+ if (s)
119
+ return Math.round(
120
+ s[e.options.horizontal ? "inlineSize" : "blockSize"]
121
+ );
122
+ }
123
+ return r[e.options.horizontal ? "offsetWidth" : "offsetHeight"];
124
+ }, H = (r, {
125
+ adjustments: l = 0,
126
+ behavior: e
127
+ }, s) => {
128
+ var t, n;
129
+ const o = r + l;
130
+ (n = (t = s.scrollElement) == null ? void 0 : t.scrollTo) == null || n.call(t, {
131
+ [s.options.horizontal ? "left" : "top"]: o,
132
+ behavior: e
133
+ });
134
+ };
135
+ class U {
136
+ constructor(l) {
137
+ this.unsubs = [], this.scrollElement = null, this.targetWindow = null, this.isScrolling = !1, this.currentScrollToIndex = null, this.measurementsCache = [], this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.pendingMeasuredCacheIndexes = [], this.prevLanes = void 0, this.lanesChangedFlag = !1, this.lanesSettling = !1, this.scrollRect = null, this.scrollOffset = null, this.scrollDirection = null, this.scrollAdjustments = 0, this.elementsCache = /* @__PURE__ */ new Map(), this.observer = /* @__PURE__ */ (() => {
138
+ let e = null;
139
+ const s = () => e || (!this.targetWindow || !this.targetWindow.ResizeObserver ? null : e = new this.targetWindow.ResizeObserver((t) => {
140
+ t.forEach((n) => {
141
+ const o = () => {
142
+ this._measureElement(n.target, n);
143
+ };
144
+ this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(o) : o();
145
+ });
146
+ }));
147
+ return {
148
+ disconnect: () => {
149
+ var t;
150
+ (t = s()) == null || t.disconnect(), e = null;
151
+ },
152
+ observe: (t) => {
153
+ var n;
154
+ return (n = s()) == null ? void 0 : n.observe(t, { box: "border-box" });
155
+ },
156
+ unobserve: (t) => {
157
+ var n;
158
+ return (n = s()) == null ? void 0 : n.unobserve(t);
159
+ }
160
+ };
161
+ })(), this.range = null, this.setOptions = (e) => {
162
+ Object.entries(e).forEach(([s, t]) => {
163
+ typeof t > "u" && delete e[s];
164
+ }), this.options = {
165
+ debug: !1,
166
+ initialOffset: 0,
167
+ overscan: 1,
168
+ paddingStart: 0,
169
+ paddingEnd: 0,
170
+ scrollPaddingStart: 0,
171
+ scrollPaddingEnd: 0,
172
+ horizontal: !1,
173
+ getItemKey: V,
174
+ rangeExtractor: j,
175
+ onChange: () => {
176
+ },
177
+ measureElement: $,
178
+ initialRect: { width: 0, height: 0 },
179
+ scrollMargin: 0,
180
+ gap: 0,
181
+ indexAttribute: "data-index",
182
+ initialMeasurementsCache: [],
183
+ lanes: 1,
184
+ isScrollingResetDelay: 150,
185
+ enabled: !0,
186
+ isRtl: !1,
187
+ useScrollendEvent: !1,
188
+ useAnimationFrameWithResizeObserver: !1,
189
+ ...e
190
+ };
191
+ }, this.notify = (e) => {
192
+ var s, t;
193
+ (t = (s = this.options).onChange) == null || t.call(s, this, e);
194
+ }, this.maybeNotify = y(
195
+ () => (this.calculateRange(), [
196
+ this.isScrolling,
197
+ this.range ? this.range.startIndex : null,
198
+ this.range ? this.range.endIndex : null
199
+ ]),
200
+ (e) => {
201
+ this.notify(e);
202
+ },
203
+ {
204
+ key: process.env.NODE_ENV !== "production" && "maybeNotify",
205
+ debug: () => this.options.debug,
206
+ initialDeps: [
207
+ this.isScrolling,
208
+ this.range ? this.range.startIndex : null,
209
+ this.range ? this.range.endIndex : null
210
+ ]
211
+ }
212
+ ), this.cleanup = () => {
213
+ this.unsubs.filter(Boolean).forEach((e) => e()), this.unsubs = [], this.observer.disconnect(), this.scrollElement = null, this.targetWindow = null;
214
+ }, this._didMount = () => () => {
215
+ this.cleanup();
216
+ }, this._willUpdate = () => {
217
+ var e;
218
+ const s = this.options.enabled ? this.options.getScrollElement() : null;
219
+ if (this.scrollElement !== s) {
220
+ if (this.cleanup(), !s) {
221
+ this.maybeNotify();
222
+ return;
223
+ }
224
+ this.scrollElement = s, this.scrollElement && "ownerDocument" in this.scrollElement ? this.targetWindow = this.scrollElement.ownerDocument.defaultView : this.targetWindow = ((e = this.scrollElement) == null ? void 0 : e.window) ?? null, this.elementsCache.forEach((t) => {
225
+ this.observer.observe(t);
226
+ }), this.unsubs.push(
227
+ this.options.observeElementRect(this, (t) => {
228
+ this.scrollRect = t, this.maybeNotify();
229
+ })
230
+ ), this.unsubs.push(
231
+ this.options.observeElementOffset(this, (t, n) => {
232
+ this.scrollAdjustments = 0, this.scrollDirection = n ? this.getScrollOffset() < t ? "forward" : "backward" : null, this.scrollOffset = t, this.isScrolling = n, this.maybeNotify();
233
+ })
234
+ ), this._scrollToOffset(this.getScrollOffset(), {
235
+ adjustments: void 0,
236
+ behavior: void 0
237
+ });
238
+ }
239
+ }, this.getSize = () => this.options.enabled ? (this.scrollRect = this.scrollRect ?? this.options.initialRect, this.scrollRect[this.options.horizontal ? "width" : "height"]) : (this.scrollRect = null, 0), this.getScrollOffset = () => this.options.enabled ? (this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset == "function" ? this.options.initialOffset() : this.options.initialOffset), this.scrollOffset) : (this.scrollOffset = null, 0), this.getFurthestMeasurement = (e, s) => {
240
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
241
+ for (let o = s - 1; o >= 0; o--) {
242
+ const i = e[o];
243
+ if (t.has(i.lane))
244
+ continue;
245
+ const h = n.get(
246
+ i.lane
247
+ );
248
+ if (h == null || i.end > h.end ? n.set(i.lane, i) : i.end < h.end && t.set(i.lane, !0), t.size === this.options.lanes)
249
+ break;
250
+ }
251
+ return n.size === this.options.lanes ? Array.from(n.values()).sort((o, i) => o.end === i.end ? o.index - i.index : o.end - i.end)[0] : void 0;
252
+ }, this.getMeasurementOptions = y(
253
+ () => [
254
+ this.options.count,
255
+ this.options.paddingStart,
256
+ this.options.scrollMargin,
257
+ this.options.getItemKey,
258
+ this.options.enabled,
259
+ this.options.lanes
260
+ ],
261
+ (e, s, t, n, o, i) => (this.prevLanes !== void 0 && this.prevLanes !== i && (this.lanesChangedFlag = !0), this.prevLanes = i, this.pendingMeasuredCacheIndexes = [], {
262
+ count: e,
263
+ paddingStart: s,
264
+ scrollMargin: t,
265
+ getItemKey: n,
266
+ enabled: o,
267
+ lanes: i
268
+ }),
269
+ {
270
+ key: !1
271
+ }
272
+ ), this.getMeasurements = y(
273
+ () => [this.getMeasurementOptions(), this.itemSizeCache],
274
+ ({ count: e, paddingStart: s, scrollMargin: t, getItemKey: n, enabled: o, lanes: i }, h) => {
275
+ if (!o)
276
+ return this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), [];
277
+ if (this.laneAssignments.size > e)
278
+ for (const a of this.laneAssignments.keys())
279
+ a >= e && this.laneAssignments.delete(a);
280
+ this.lanesChangedFlag && (this.lanesChangedFlag = !1, this.lanesSettling = !0, this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), this.pendingMeasuredCacheIndexes = []), this.measurementsCache.length === 0 && !this.lanesSettling && (this.measurementsCache = this.options.initialMeasurementsCache, this.measurementsCache.forEach((a) => {
281
+ this.itemSizeCache.set(a.key, a.size);
282
+ }));
283
+ const u = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
284
+ this.pendingMeasuredCacheIndexes = [], this.lanesSettling && this.measurementsCache.length === e && (this.lanesSettling = !1);
285
+ const c = this.measurementsCache.slice(0, u), v = new Array(i).fill(
286
+ void 0
287
+ );
288
+ for (let a = 0; a < u; a++) {
289
+ const g = c[a];
290
+ g && (v[g.lane] = a);
291
+ }
292
+ for (let a = u; a < e; a++) {
293
+ const g = n(a), b = this.laneAssignments.get(a);
294
+ let f, m;
295
+ if (b !== void 0 && this.options.lanes > 1) {
296
+ f = b;
297
+ const S = v[f], w = S !== void 0 ? c[S] : void 0;
298
+ m = w ? w.end + this.options.gap : s + t;
299
+ } else {
300
+ const S = this.options.lanes === 1 ? c[a - 1] : this.getFurthestMeasurement(c, a);
301
+ m = S ? S.end + this.options.gap : s + t, f = S ? S.lane : a % this.options.lanes, this.options.lanes > 1 && this.laneAssignments.set(a, f);
302
+ }
303
+ const p = h.get(g), d = typeof p == "number" ? p : this.options.estimateSize(a), E = m + d;
304
+ c[a] = {
305
+ index: a,
306
+ start: m,
307
+ size: d,
308
+ end: E,
309
+ key: g,
310
+ lane: f
311
+ }, v[f] = a;
312
+ }
313
+ return this.measurementsCache = c, c;
314
+ },
315
+ {
316
+ key: process.env.NODE_ENV !== "production" && "getMeasurements",
317
+ debug: () => this.options.debug
318
+ }
319
+ ), this.calculateRange = y(
320
+ () => [
321
+ this.getMeasurements(),
322
+ this.getSize(),
323
+ this.getScrollOffset(),
324
+ this.options.lanes
325
+ ],
326
+ (e, s, t, n) => this.range = e.length > 0 && s > 0 ? q({
327
+ measurements: e,
328
+ outerSize: s,
329
+ scrollOffset: t,
330
+ lanes: n
331
+ }) : null,
332
+ {
333
+ key: process.env.NODE_ENV !== "production" && "calculateRange",
334
+ debug: () => this.options.debug
335
+ }
336
+ ), this.getVirtualIndexes = y(
337
+ () => {
338
+ let e = null, s = null;
339
+ const t = this.calculateRange();
340
+ return t && (e = t.startIndex, s = t.endIndex), this.maybeNotify.updateDeps([this.isScrolling, e, s]), [
341
+ this.options.rangeExtractor,
342
+ this.options.overscan,
343
+ this.options.count,
344
+ e,
345
+ s
346
+ ];
347
+ },
348
+ (e, s, t, n, o) => n === null || o === null ? [] : e({
349
+ startIndex: n,
350
+ endIndex: o,
351
+ overscan: s,
352
+ count: t
353
+ }),
354
+ {
355
+ key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
356
+ debug: () => this.options.debug
357
+ }
358
+ ), this.indexFromElement = (e) => {
359
+ const s = this.options.indexAttribute, t = e.getAttribute(s);
360
+ return t ? parseInt(t, 10) : (console.warn(
361
+ `Missing attribute name '${s}={index}' on measured element.`
362
+ ), -1);
363
+ }, this._measureElement = (e, s) => {
364
+ const t = this.indexFromElement(e), n = this.measurementsCache[t];
365
+ if (!n)
366
+ return;
367
+ const o = n.key, i = this.elementsCache.get(o);
368
+ i !== e && (i && this.observer.unobserve(i), this.observer.observe(e), this.elementsCache.set(o, e)), e.isConnected && this.resizeItem(t, this.options.measureElement(e, s, this));
369
+ }, this.resizeItem = (e, s) => {
370
+ const t = this.measurementsCache[e];
371
+ if (!t)
372
+ return;
373
+ const n = this.itemSizeCache.get(t.key) ?? t.size, o = s - n;
374
+ o !== 0 && ((this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(t, o, this) : t.start < this.getScrollOffset() + this.scrollAdjustments) && (process.env.NODE_ENV !== "production" && this.options.debug && console.info("correction", o), this._scrollToOffset(this.getScrollOffset(), {
375
+ adjustments: this.scrollAdjustments += o,
376
+ behavior: void 0
377
+ })), this.pendingMeasuredCacheIndexes.push(t.index), this.itemSizeCache = new Map(this.itemSizeCache.set(t.key, s)), this.notify(!1));
378
+ }, this.measureElement = (e) => {
379
+ if (!e) {
380
+ this.elementsCache.forEach((s, t) => {
381
+ s.isConnected || (this.observer.unobserve(s), this.elementsCache.delete(t));
382
+ });
383
+ return;
384
+ }
385
+ this._measureElement(e, void 0);
386
+ }, this.getVirtualItems = y(
387
+ () => [this.getVirtualIndexes(), this.getMeasurements()],
388
+ (e, s) => {
389
+ const t = [];
390
+ for (let n = 0, o = e.length; n < o; n++) {
391
+ const i = e[n], h = s[i];
392
+ t.push(h);
393
+ }
394
+ return t;
395
+ },
396
+ {
397
+ key: process.env.NODE_ENV !== "production" && "getVirtualItems",
398
+ debug: () => this.options.debug
399
+ }
400
+ ), this.getVirtualItemForOffset = (e) => {
401
+ const s = this.getMeasurements();
402
+ if (s.length !== 0)
403
+ return O(
404
+ s[_(
405
+ 0,
406
+ s.length - 1,
407
+ (t) => O(s[t]).start,
408
+ e
409
+ )]
410
+ );
411
+ }, this.getMaxScrollOffset = () => {
412
+ if (!this.scrollElement) return 0;
413
+ if ("scrollHeight" in this.scrollElement)
414
+ return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
415
+ {
416
+ const e = this.scrollElement.document.documentElement;
417
+ return this.options.horizontal ? e.scrollWidth - this.scrollElement.innerWidth : e.scrollHeight - this.scrollElement.innerHeight;
418
+ }
419
+ }, this.getOffsetForAlignment = (e, s, t = 0) => {
420
+ if (!this.scrollElement) return 0;
421
+ const n = this.getSize(), o = this.getScrollOffset();
422
+ s === "auto" && (s = e >= o + n ? "end" : "start"), s === "center" ? e += (t - n) / 2 : s === "end" && (e -= n);
423
+ const i = this.getMaxScrollOffset();
424
+ return Math.max(Math.min(i, e), 0);
425
+ }, this.getOffsetForIndex = (e, s = "auto") => {
426
+ e = Math.max(0, Math.min(e, this.options.count - 1));
427
+ const t = this.measurementsCache[e];
428
+ if (!t)
429
+ return;
430
+ const n = this.getSize(), o = this.getScrollOffset();
431
+ if (s === "auto")
432
+ if (t.end >= o + n - this.options.scrollPaddingEnd)
433
+ s = "end";
434
+ else if (t.start <= o + this.options.scrollPaddingStart)
435
+ s = "start";
436
+ else
437
+ return [o, s];
438
+ if (s === "end" && e === this.options.count - 1)
439
+ return [this.getMaxScrollOffset(), s];
440
+ const i = s === "end" ? t.end + this.options.scrollPaddingEnd : t.start - this.options.scrollPaddingStart;
441
+ return [
442
+ this.getOffsetForAlignment(i, s, t.size),
443
+ s
444
+ ];
445
+ }, this.isDynamicMode = () => this.elementsCache.size > 0, this.scrollToOffset = (e, { align: s = "start", behavior: t } = {}) => {
446
+ t === "smooth" && this.isDynamicMode() && console.warn(
447
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
448
+ ), this._scrollToOffset(this.getOffsetForAlignment(e, s), {
449
+ adjustments: void 0,
450
+ behavior: t
451
+ });
452
+ }, this.scrollToIndex = (e, { align: s = "auto", behavior: t } = {}) => {
453
+ t === "smooth" && this.isDynamicMode() && console.warn(
454
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
455
+ ), e = Math.max(0, Math.min(e, this.options.count - 1)), this.currentScrollToIndex = e;
456
+ let n = 0;
457
+ const o = 10, i = (u) => {
458
+ if (!this.targetWindow) return;
459
+ const c = this.getOffsetForIndex(e, u);
460
+ if (!c) {
461
+ console.warn("Failed to get offset for index:", e);
462
+ return;
463
+ }
464
+ const [v, a] = c;
465
+ this._scrollToOffset(v, { adjustments: void 0, behavior: t }), this.targetWindow.requestAnimationFrame(() => {
466
+ const g = () => {
467
+ if (this.currentScrollToIndex !== e) return;
468
+ const b = this.getScrollOffset(), f = this.getOffsetForIndex(e, a);
469
+ if (!f) {
470
+ console.warn("Failed to get offset for index:", e);
471
+ return;
472
+ }
473
+ W(f[0], b) || h(a);
474
+ };
475
+ this.isDynamicMode() ? this.targetWindow.requestAnimationFrame(g) : g();
476
+ });
477
+ }, h = (u) => {
478
+ this.targetWindow && this.currentScrollToIndex === e && (n++, n < o ? (process.env.NODE_ENV !== "production" && this.options.debug && console.info("Schedule retry", n, o), this.targetWindow.requestAnimationFrame(() => i(u))) : console.warn(
479
+ `Failed to scroll to index ${e} after ${o} attempts.`
480
+ ));
481
+ };
482
+ i(s);
483
+ }, this.scrollBy = (e, { behavior: s } = {}) => {
484
+ s === "smooth" && this.isDynamicMode() && console.warn(
485
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
486
+ ), this._scrollToOffset(this.getScrollOffset() + e, {
487
+ adjustments: void 0,
488
+ behavior: s
489
+ });
490
+ }, this.getTotalSize = () => {
491
+ var e;
492
+ const s = this.getMeasurements();
493
+ let t;
494
+ if (s.length === 0)
495
+ t = this.options.paddingStart;
496
+ else if (this.options.lanes === 1)
497
+ t = ((e = s[s.length - 1]) == null ? void 0 : e.end) ?? 0;
498
+ else {
499
+ const n = Array(this.options.lanes).fill(null);
500
+ let o = s.length - 1;
501
+ for (; o >= 0 && n.some((i) => i === null); ) {
502
+ const i = s[o];
503
+ n[i.lane] === null && (n[i.lane] = i.end), o--;
504
+ }
505
+ t = Math.max(...n.filter((i) => i !== null));
506
+ }
507
+ return Math.max(
508
+ t - this.options.scrollMargin + this.options.paddingEnd,
509
+ 0
510
+ );
511
+ }, this._scrollToOffset = (e, {
512
+ adjustments: s,
513
+ behavior: t
514
+ }) => {
515
+ this.options.scrollToFn(e, { behavior: t, adjustments: s }, this);
516
+ }, this.measure = () => {
517
+ this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.notify(!1);
518
+ }, this.setOptions(l);
519
+ }
520
+ }
521
+ const _ = (r, l, e, s) => {
522
+ for (; r <= l; ) {
523
+ const t = (r + l) / 2 | 0, n = e(t);
524
+ if (n < s)
525
+ r = t + 1;
526
+ else if (n > s)
527
+ l = t - 1;
528
+ else
529
+ return t;
530
+ }
531
+ return r > 0 ? r - 1 : 0;
532
+ };
533
+ function q({
534
+ measurements: r,
535
+ outerSize: l,
536
+ scrollOffset: e,
537
+ lanes: s
538
+ }) {
539
+ const t = r.length - 1, n = (h) => r[h].start;
540
+ if (r.length <= s)
541
+ return {
542
+ startIndex: 0,
543
+ endIndex: t
544
+ };
545
+ let o = _(
546
+ 0,
547
+ t,
548
+ n,
549
+ e
550
+ ), i = o;
551
+ if (s === 1)
552
+ for (; i < t && r[i].end < e + l; )
553
+ i++;
554
+ else if (s > 1) {
555
+ const h = Array(s).fill(0);
556
+ for (; i < t && h.some((c) => c < e + l); ) {
557
+ const c = r[i];
558
+ h[c.lane] = c.end, i++;
559
+ }
560
+ const u = Array(s).fill(e + l);
561
+ for (; o >= 0 && u.some((c) => c >= e); ) {
562
+ const c = r[o];
563
+ u[c.lane] = c.start, o--;
564
+ }
565
+ o = Math.max(0, o - o % s), i = Math.min(t, i + (s - 1 - i % s));
566
+ }
567
+ return { startIndex: o, endIndex: i };
568
+ }
569
+ const A = typeof document < "u" ? M.useLayoutEffect : M.useEffect;
570
+ function K({
571
+ useFlushSync: r = !0,
572
+ ...l
573
+ }) {
574
+ const e = M.useReducer(() => ({}), {})[1], s = {
575
+ ...l,
576
+ onChange: (n, o) => {
577
+ var i;
578
+ r && o ? N(e) : e(), (i = l.onChange) == null || i.call(l, n, o);
579
+ }
580
+ }, [t] = M.useState(
581
+ () => new U(s)
582
+ );
583
+ return t.setOptions(s), A(() => t._didMount(), []), A(() => t._willUpdate()), t;
584
+ }
585
+ function G(r) {
586
+ return K({
587
+ observeElementRect: B,
588
+ observeElementOffset: P,
589
+ scrollToFn: H,
590
+ ...r
591
+ });
592
+ }
593
+ const X = 5, Y = 0, J = "grid grid-cols-1 gap-4";
594
+ function Q(r, l) {
595
+ if (l <= 0)
596
+ throw new Error(`chunkArray: size must be positive, received ${l}`);
597
+ const e = [];
598
+ for (let s = 0; s < r.length; s += l)
599
+ e.push(r.slice(s, s + l));
600
+ return e;
601
+ }
602
+ function se({
603
+ items: r,
604
+ columns: l,
605
+ parentRef: e,
606
+ renderItem: s,
607
+ estimateRowSize: t,
608
+ getItemKey: n,
609
+ overscan: o = X,
610
+ rowGapPx: i = Y,
611
+ gridClassName: h = J
612
+ }) {
613
+ if (l <= 0)
614
+ throw new Error(
615
+ `VirtualizedGrid: columns must be positive, received ${l}`
616
+ );
617
+ const u = F(null), [c, v] = D(0);
618
+ T(() => {
619
+ const m = u.current, p = e.current;
620
+ if (!(m && p))
621
+ return;
622
+ const d = () => {
623
+ const S = p.getBoundingClientRect(), R = m.getBoundingClientRect().top - S.top + p.scrollTop;
624
+ v(Math.max(0, Math.round(R)));
625
+ };
626
+ d();
627
+ const E = new ResizeObserver(d);
628
+ return E.observe(m), E.observe(p), () => E.disconnect();
629
+ }, [e]);
630
+ const a = k(() => Q(r, l).map(
631
+ (p, d) => p.map((E, S) => ({
632
+ item: E,
633
+ index: d * l + S
634
+ }))
635
+ ), [r, l]), g = G({
636
+ count: a.length,
637
+ getScrollElement: () => e.current,
638
+ estimateSize: () => t + i,
639
+ overscan: o,
640
+ scrollMargin: c
641
+ });
642
+ if (r.length === 0)
643
+ return null;
644
+ const b = g.getVirtualItems(), f = g.getTotalSize();
645
+ return b.length === 0 ? /* @__PURE__ */ x(
646
+ "div",
647
+ {
648
+ className: "relative w-full",
649
+ "data-testid": "virtualized-grid",
650
+ ref: u,
651
+ style: { height: a.length * (t + i) }
652
+ }
653
+ ) : /* @__PURE__ */ x(
654
+ "div",
655
+ {
656
+ className: "relative w-full",
657
+ "data-testid": "virtualized-grid",
658
+ ref: u,
659
+ style: { height: f },
660
+ children: b.map((m) => {
661
+ const p = a[m.index];
662
+ return p ? /* @__PURE__ */ x(
663
+ "div",
664
+ {
665
+ className: "absolute top-0 left-0 w-full",
666
+ "data-index": m.index,
667
+ ref: g.measureElement,
668
+ style: {
669
+ transform: `translateY(${m.start - c}px)`,
670
+ paddingBottom: i
671
+ },
672
+ children: /* @__PURE__ */ x("div", { className: h, children: p.map(({ item: d, index: E }) => /* @__PURE__ */ x("div", { children: s(d, E) }, n(d))) })
673
+ },
674
+ m.key
675
+ ) : null;
676
+ })
677
+ }
678
+ );
679
+ }
680
+ export {
681
+ se as VirtualizedGrid
682
+ };