@digdir/designsystemet-react 0.55.1-alpha.1 → 0.56.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.
Files changed (38) hide show
  1. package/dist/cjs/components/Chip/Chip.module.css.js +1 -1
  2. package/dist/cjs/components/Popover/Popover.js +2 -2
  3. package/dist/cjs/components/Popover/PopoverContent.js +2 -2
  4. package/dist/cjs/components/Tooltip/Tooltip.js +1 -1
  5. package/dist/cjs/components/form/Combobox/Combobox.js +19 -4
  6. package/dist/cjs/components/form/Search/Search.js +1 -1
  7. package/dist/cjs/node_modules/@floating-ui/react/dist/floating-ui.react.js +1 -1
  8. package/dist/cjs/node_modules/@floating-ui/{react/node_modules/@floating-ui/react-dom → react-dom}/dist/floating-ui.react-dom.js +2 -2
  9. package/dist/cjs/node_modules/@tanstack/react-virtual/{build/lib → dist/esm}/index.js +18 -32
  10. package/dist/cjs/node_modules/@tanstack/virtual-core/dist/esm/index.js +606 -0
  11. package/dist/cjs/node_modules/@tanstack/virtual-core/dist/esm/utils.js +60 -0
  12. package/dist/cjs/react-css-modules.css +76 -79
  13. package/dist/esm/components/Chip/Chip.module.css.js +1 -1
  14. package/dist/esm/components/Popover/Popover.js +2 -2
  15. package/dist/esm/components/Popover/PopoverContent.js +2 -2
  16. package/dist/esm/components/Tooltip/Tooltip.js +1 -1
  17. package/dist/esm/components/form/Combobox/Combobox.js +19 -4
  18. package/dist/esm/components/form/Search/Search.js +1 -1
  19. package/dist/esm/node_modules/@floating-ui/react/dist/floating-ui.react.js +2 -2
  20. package/dist/esm/node_modules/@floating-ui/{react/node_modules/@floating-ui/react-dom → react-dom}/dist/floating-ui.react-dom.js +4 -4
  21. package/dist/esm/node_modules/@tanstack/react-virtual/dist/esm/index.js +43 -0
  22. package/dist/esm/node_modules/@tanstack/virtual-core/dist/esm/index.js +595 -0
  23. package/dist/esm/node_modules/@tanstack/virtual-core/dist/esm/utils.js +56 -0
  24. package/dist/esm/react-css-modules.css +76 -79
  25. package/dist/types/components/Popover/Popover.d.ts +1 -6
  26. package/dist/types/components/Popover/Popover.d.ts.map +1 -1
  27. package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
  28. package/dist/types/components/form/Search/Search.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/dist/cjs/node_modules/@tanstack/react-virtual/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -29
  31. package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -29
  32. package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/index.js +0 -607
  33. package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/utils.js +0 -62
  34. package/dist/esm/node_modules/@tanstack/react-virtual/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -27
  35. package/dist/esm/node_modules/@tanstack/react-virtual/build/lib/index.js +0 -57
  36. package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -27
  37. package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/index.js +0 -596
  38. package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/utils.js +0 -58
@@ -0,0 +1,595 @@
1
+ 'use client';
2
+ import { memo, notUndefined, approxEqual } from './utils.js';
3
+
4
+ const defaultKeyExtractor = (index) => index;
5
+ const defaultRangeExtractor = (range) => {
6
+ const start = Math.max(range.startIndex - range.overscan, 0);
7
+ const end = Math.min(range.endIndex + range.overscan, range.count - 1);
8
+ const arr = [];
9
+ for (let i = start; i <= end; i++) {
10
+ arr.push(i);
11
+ }
12
+ return arr;
13
+ };
14
+ const observeElementRect = (instance, cb) => {
15
+ const element = instance.scrollElement;
16
+ if (!element) {
17
+ return;
18
+ }
19
+ const handler = (rect) => {
20
+ const { width, height } = rect;
21
+ cb({ width: Math.round(width), height: Math.round(height) });
22
+ };
23
+ handler(element.getBoundingClientRect());
24
+ if (typeof ResizeObserver === "undefined") {
25
+ return () => {
26
+ };
27
+ }
28
+ const observer = new ResizeObserver((entries) => {
29
+ const entry = entries[0];
30
+ if (entry == null ? void 0 : entry.borderBoxSize) {
31
+ const box = entry.borderBoxSize[0];
32
+ if (box) {
33
+ handler({ width: box.inlineSize, height: box.blockSize });
34
+ return;
35
+ }
36
+ }
37
+ handler(element.getBoundingClientRect());
38
+ });
39
+ observer.observe(element, { box: "border-box" });
40
+ return () => {
41
+ observer.unobserve(element);
42
+ };
43
+ };
44
+ const observeElementOffset = (instance, cb) => {
45
+ const element = instance.scrollElement;
46
+ if (!element) {
47
+ return;
48
+ }
49
+ const handler = () => {
50
+ cb(element[instance.options.horizontal ? "scrollLeft" : "scrollTop"]);
51
+ };
52
+ handler();
53
+ element.addEventListener("scroll", handler, {
54
+ passive: true
55
+ });
56
+ return () => {
57
+ element.removeEventListener("scroll", handler);
58
+ };
59
+ };
60
+ const measureElement = (element, entry, instance) => {
61
+ if (entry == null ? void 0 : entry.borderBoxSize) {
62
+ const box = entry.borderBoxSize[0];
63
+ if (box) {
64
+ const size = Math.round(
65
+ box[instance.options.horizontal ? "inlineSize" : "blockSize"]
66
+ );
67
+ return size;
68
+ }
69
+ }
70
+ return Math.round(
71
+ element.getBoundingClientRect()[instance.options.horizontal ? "width" : "height"]
72
+ );
73
+ };
74
+ const elementScroll = (offset, {
75
+ adjustments = 0,
76
+ behavior
77
+ }, instance) => {
78
+ var _a, _b;
79
+ const toOffset = offset + adjustments;
80
+ (_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
81
+ [instance.options.horizontal ? "left" : "top"]: toOffset,
82
+ behavior
83
+ });
84
+ };
85
+ class Virtualizer {
86
+ constructor(opts) {
87
+ this.unsubs = [];
88
+ this.scrollElement = null;
89
+ this.isScrolling = false;
90
+ this.isScrollingTimeoutId = null;
91
+ this.scrollToIndexTimeoutId = null;
92
+ this.measurementsCache = [];
93
+ this.itemSizeCache = /* @__PURE__ */ new Map();
94
+ this.pendingMeasuredCacheIndexes = [];
95
+ this.scrollDirection = null;
96
+ this.scrollAdjustments = 0;
97
+ this.measureElementCache = /* @__PURE__ */ new Map();
98
+ this.observer = /* @__PURE__ */ (() => {
99
+ let _ro = null;
100
+ const get = () => {
101
+ if (_ro) {
102
+ return _ro;
103
+ } else if (typeof ResizeObserver !== "undefined") {
104
+ return _ro = new ResizeObserver((entries) => {
105
+ entries.forEach((entry) => {
106
+ this._measureElement(entry.target, entry);
107
+ });
108
+ });
109
+ } else {
110
+ return null;
111
+ }
112
+ };
113
+ return {
114
+ disconnect: () => {
115
+ var _a;
116
+ return (_a = get()) == null ? void 0 : _a.disconnect();
117
+ },
118
+ observe: (target) => {
119
+ var _a;
120
+ return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
121
+ },
122
+ unobserve: (target) => {
123
+ var _a;
124
+ return (_a = get()) == null ? void 0 : _a.unobserve(target);
125
+ }
126
+ };
127
+ })();
128
+ this.range = null;
129
+ this.setOptions = (opts2) => {
130
+ Object.entries(opts2).forEach(([key, value]) => {
131
+ if (typeof value === "undefined")
132
+ delete opts2[key];
133
+ });
134
+ this.options = {
135
+ debug: false,
136
+ initialOffset: 0,
137
+ overscan: 1,
138
+ paddingStart: 0,
139
+ paddingEnd: 0,
140
+ scrollPaddingStart: 0,
141
+ scrollPaddingEnd: 0,
142
+ horizontal: false,
143
+ getItemKey: defaultKeyExtractor,
144
+ rangeExtractor: defaultRangeExtractor,
145
+ onChange: () => {
146
+ },
147
+ measureElement,
148
+ initialRect: { width: 0, height: 0 },
149
+ scrollMargin: 0,
150
+ gap: 0,
151
+ scrollingDelay: 150,
152
+ indexAttribute: "data-index",
153
+ initialMeasurementsCache: [],
154
+ lanes: 1,
155
+ ...opts2
156
+ };
157
+ };
158
+ this.notify = (sync) => {
159
+ var _a, _b;
160
+ (_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
161
+ };
162
+ this.maybeNotify = memo(
163
+ () => {
164
+ this.calculateRange();
165
+ return [
166
+ this.isScrolling,
167
+ this.range ? this.range.startIndex : null,
168
+ this.range ? this.range.endIndex : null
169
+ ];
170
+ },
171
+ (isScrolling) => {
172
+ this.notify(isScrolling);
173
+ },
174
+ {
175
+ key: process.env.NODE_ENV !== "production" && "maybeNotify",
176
+ debug: () => this.options.debug,
177
+ initialDeps: [
178
+ this.isScrolling,
179
+ this.range ? this.range.startIndex : null,
180
+ this.range ? this.range.endIndex : null
181
+ ]
182
+ }
183
+ );
184
+ this.cleanup = () => {
185
+ this.unsubs.filter(Boolean).forEach((d) => d());
186
+ this.unsubs = [];
187
+ this.scrollElement = null;
188
+ };
189
+ this._didMount = () => {
190
+ this.measureElementCache.forEach(this.observer.observe);
191
+ return () => {
192
+ this.observer.disconnect();
193
+ this.cleanup();
194
+ };
195
+ };
196
+ this._willUpdate = () => {
197
+ const scrollElement = this.options.getScrollElement();
198
+ if (this.scrollElement !== scrollElement) {
199
+ this.cleanup();
200
+ this.scrollElement = scrollElement;
201
+ this._scrollToOffset(this.scrollOffset, {
202
+ adjustments: void 0,
203
+ behavior: void 0
204
+ });
205
+ this.unsubs.push(
206
+ this.options.observeElementRect(this, (rect) => {
207
+ this.scrollRect = rect;
208
+ this.maybeNotify();
209
+ })
210
+ );
211
+ this.unsubs.push(
212
+ this.options.observeElementOffset(this, (offset) => {
213
+ this.scrollAdjustments = 0;
214
+ if (this.scrollOffset === offset) {
215
+ return;
216
+ }
217
+ if (this.isScrollingTimeoutId !== null) {
218
+ clearTimeout(this.isScrollingTimeoutId);
219
+ this.isScrollingTimeoutId = null;
220
+ }
221
+ this.isScrolling = true;
222
+ this.scrollDirection = this.scrollOffset < offset ? "forward" : "backward";
223
+ this.scrollOffset = offset;
224
+ this.maybeNotify();
225
+ this.isScrollingTimeoutId = setTimeout(() => {
226
+ this.isScrollingTimeoutId = null;
227
+ this.isScrolling = false;
228
+ this.scrollDirection = null;
229
+ this.maybeNotify();
230
+ }, this.options.scrollingDelay);
231
+ })
232
+ );
233
+ }
234
+ };
235
+ this.getSize = () => {
236
+ return this.scrollRect[this.options.horizontal ? "width" : "height"];
237
+ };
238
+ this.memoOptions = memo(
239
+ () => [
240
+ this.options.count,
241
+ this.options.paddingStart,
242
+ this.options.scrollMargin,
243
+ this.options.getItemKey
244
+ ],
245
+ (count, paddingStart, scrollMargin, getItemKey) => {
246
+ this.pendingMeasuredCacheIndexes = [];
247
+ return {
248
+ count,
249
+ paddingStart,
250
+ scrollMargin,
251
+ getItemKey
252
+ };
253
+ },
254
+ {
255
+ key: false
256
+ }
257
+ );
258
+ this.getFurthestMeasurement = (measurements, index) => {
259
+ const furthestMeasurementsFound = /* @__PURE__ */ new Map();
260
+ const furthestMeasurements = /* @__PURE__ */ new Map();
261
+ for (let m = index - 1; m >= 0; m--) {
262
+ const measurement = measurements[m];
263
+ if (furthestMeasurementsFound.has(measurement.lane)) {
264
+ continue;
265
+ }
266
+ const previousFurthestMeasurement = furthestMeasurements.get(
267
+ measurement.lane
268
+ );
269
+ if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
270
+ furthestMeasurements.set(measurement.lane, measurement);
271
+ } else if (measurement.end < previousFurthestMeasurement.end) {
272
+ furthestMeasurementsFound.set(measurement.lane, true);
273
+ }
274
+ if (furthestMeasurementsFound.size === this.options.lanes) {
275
+ break;
276
+ }
277
+ }
278
+ return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
279
+ if (a.end === b.end) {
280
+ return a.index - b.index;
281
+ }
282
+ return a.end - b.end;
283
+ })[0] : void 0;
284
+ };
285
+ this.getMeasurements = memo(
286
+ () => [this.memoOptions(), this.itemSizeCache],
287
+ ({ count, paddingStart, scrollMargin, getItemKey }, itemSizeCache) => {
288
+ const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
289
+ this.pendingMeasuredCacheIndexes = [];
290
+ const measurements = this.measurementsCache.slice(0, min);
291
+ for (let i = min; i < count; i++) {
292
+ const key = getItemKey(i);
293
+ const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
294
+ const start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
295
+ const measuredSize = itemSizeCache.get(key);
296
+ const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
297
+ const end = start + size;
298
+ const lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
299
+ measurements[i] = {
300
+ index: i,
301
+ start,
302
+ size,
303
+ end,
304
+ key,
305
+ lane
306
+ };
307
+ }
308
+ this.measurementsCache = measurements;
309
+ return measurements;
310
+ },
311
+ {
312
+ key: process.env.NODE_ENV !== "production" && "getMeasurements",
313
+ debug: () => this.options.debug
314
+ }
315
+ );
316
+ this.calculateRange = memo(
317
+ () => [this.getMeasurements(), this.getSize(), this.scrollOffset],
318
+ (measurements, outerSize, scrollOffset) => {
319
+ return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
320
+ measurements,
321
+ outerSize,
322
+ scrollOffset
323
+ }) : null;
324
+ },
325
+ {
326
+ key: process.env.NODE_ENV !== "production" && "calculateRange",
327
+ debug: () => this.options.debug
328
+ }
329
+ );
330
+ this.getIndexes = memo(
331
+ () => [
332
+ this.options.rangeExtractor,
333
+ this.calculateRange(),
334
+ this.options.overscan,
335
+ this.options.count
336
+ ],
337
+ (rangeExtractor, range, overscan, count) => {
338
+ return range === null ? [] : rangeExtractor({
339
+ ...range,
340
+ overscan,
341
+ count
342
+ });
343
+ },
344
+ {
345
+ key: process.env.NODE_ENV !== "production" && "getIndexes",
346
+ debug: () => this.options.debug
347
+ }
348
+ );
349
+ this.indexFromElement = (node) => {
350
+ const attributeName = this.options.indexAttribute;
351
+ const indexStr = node.getAttribute(attributeName);
352
+ if (!indexStr) {
353
+ console.warn(
354
+ `Missing attribute name '${attributeName}={index}' on measured element.`
355
+ );
356
+ return -1;
357
+ }
358
+ return parseInt(indexStr, 10);
359
+ };
360
+ this._measureElement = (node, entry) => {
361
+ const item = this.measurementsCache[this.indexFromElement(node)];
362
+ if (!item || !node.isConnected) {
363
+ this.measureElementCache.forEach((cached, key) => {
364
+ if (cached === node) {
365
+ this.observer.unobserve(node);
366
+ this.measureElementCache.delete(key);
367
+ }
368
+ });
369
+ return;
370
+ }
371
+ const prevNode = this.measureElementCache.get(item.key);
372
+ if (prevNode !== node) {
373
+ if (prevNode) {
374
+ this.observer.unobserve(prevNode);
375
+ }
376
+ this.observer.observe(node);
377
+ this.measureElementCache.set(item.key, node);
378
+ }
379
+ const measuredItemSize = this.options.measureElement(node, entry, this);
380
+ this.resizeItem(item, measuredItemSize);
381
+ };
382
+ this.resizeItem = (item, size) => {
383
+ const itemSize = this.itemSizeCache.get(item.key) ?? item.size;
384
+ const delta = size - itemSize;
385
+ if (delta !== 0) {
386
+ if (item.start < this.scrollOffset + this.scrollAdjustments) {
387
+ if (process.env.NODE_ENV !== "production" && this.options.debug) {
388
+ console.info("correction", delta);
389
+ }
390
+ this._scrollToOffset(this.scrollOffset, {
391
+ adjustments: this.scrollAdjustments += delta,
392
+ behavior: void 0
393
+ });
394
+ }
395
+ this.pendingMeasuredCacheIndexes.push(item.index);
396
+ this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
397
+ this.notify(false);
398
+ }
399
+ };
400
+ this.measureElement = (node) => {
401
+ if (!node) {
402
+ return;
403
+ }
404
+ this._measureElement(node, void 0);
405
+ };
406
+ this.getVirtualItems = memo(
407
+ () => [this.getIndexes(), this.getMeasurements()],
408
+ (indexes, measurements) => {
409
+ const virtualItems = [];
410
+ for (let k = 0, len = indexes.length; k < len; k++) {
411
+ const i = indexes[k];
412
+ const measurement = measurements[i];
413
+ virtualItems.push(measurement);
414
+ }
415
+ return virtualItems;
416
+ },
417
+ {
418
+ key: process.env.NODE_ENV !== "production" && "getIndexes",
419
+ debug: () => this.options.debug
420
+ }
421
+ );
422
+ this.getVirtualItemForOffset = (offset) => {
423
+ const measurements = this.getMeasurements();
424
+ return notUndefined(
425
+ measurements[findNearestBinarySearch(
426
+ 0,
427
+ measurements.length - 1,
428
+ (index) => notUndefined(measurements[index]).start,
429
+ offset
430
+ )]
431
+ );
432
+ };
433
+ this.getOffsetForAlignment = (toOffset, align) => {
434
+ const size = this.getSize();
435
+ if (align === "auto") {
436
+ if (toOffset <= this.scrollOffset) {
437
+ align = "start";
438
+ } else if (toOffset >= this.scrollOffset + size) {
439
+ align = "end";
440
+ } else {
441
+ align = "start";
442
+ }
443
+ }
444
+ if (align === "start") {
445
+ toOffset = toOffset;
446
+ } else if (align === "end") {
447
+ toOffset = toOffset - size;
448
+ } else if (align === "center") {
449
+ toOffset = toOffset - size / 2;
450
+ }
451
+ const scrollSizeProp = this.options.horizontal ? "scrollWidth" : "scrollHeight";
452
+ const scrollSize = this.scrollElement ? "document" in this.scrollElement ? this.scrollElement.document.documentElement[scrollSizeProp] : this.scrollElement[scrollSizeProp] : 0;
453
+ const maxOffset = scrollSize - this.getSize();
454
+ return Math.max(Math.min(maxOffset, toOffset), 0);
455
+ };
456
+ this.getOffsetForIndex = (index, align = "auto") => {
457
+ index = Math.max(0, Math.min(index, this.options.count - 1));
458
+ const measurement = notUndefined(this.getMeasurements()[index]);
459
+ if (align === "auto") {
460
+ if (measurement.end >= this.scrollOffset + this.getSize() - this.options.scrollPaddingEnd) {
461
+ align = "end";
462
+ } else if (measurement.start <= this.scrollOffset + this.options.scrollPaddingStart) {
463
+ align = "start";
464
+ } else {
465
+ return [this.scrollOffset, align];
466
+ }
467
+ }
468
+ const toOffset = align === "end" ? measurement.end + this.options.scrollPaddingEnd : measurement.start - this.options.scrollPaddingStart;
469
+ return [this.getOffsetForAlignment(toOffset, align), align];
470
+ };
471
+ this.isDynamicMode = () => this.measureElementCache.size > 0;
472
+ this.cancelScrollToIndex = () => {
473
+ if (this.scrollToIndexTimeoutId !== null) {
474
+ clearTimeout(this.scrollToIndexTimeoutId);
475
+ this.scrollToIndexTimeoutId = null;
476
+ }
477
+ };
478
+ this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
479
+ this.cancelScrollToIndex();
480
+ if (behavior === "smooth" && this.isDynamicMode()) {
481
+ console.warn(
482
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
483
+ );
484
+ }
485
+ this._scrollToOffset(this.getOffsetForAlignment(toOffset, align), {
486
+ adjustments: void 0,
487
+ behavior
488
+ });
489
+ };
490
+ this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
491
+ index = Math.max(0, Math.min(index, this.options.count - 1));
492
+ this.cancelScrollToIndex();
493
+ if (behavior === "smooth" && this.isDynamicMode()) {
494
+ console.warn(
495
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
496
+ );
497
+ }
498
+ const [toOffset, align] = this.getOffsetForIndex(index, initialAlign);
499
+ this._scrollToOffset(toOffset, { adjustments: void 0, behavior });
500
+ if (behavior !== "smooth" && this.isDynamicMode()) {
501
+ this.scrollToIndexTimeoutId = setTimeout(() => {
502
+ this.scrollToIndexTimeoutId = null;
503
+ const elementInDOM = this.measureElementCache.has(
504
+ this.options.getItemKey(index)
505
+ );
506
+ if (elementInDOM) {
507
+ const [toOffset2] = this.getOffsetForIndex(index, align);
508
+ if (!approxEqual(toOffset2, this.scrollOffset)) {
509
+ this.scrollToIndex(index, { align, behavior });
510
+ }
511
+ } else {
512
+ this.scrollToIndex(index, { align, behavior });
513
+ }
514
+ });
515
+ }
516
+ };
517
+ this.scrollBy = (delta, { behavior } = {}) => {
518
+ this.cancelScrollToIndex();
519
+ if (behavior === "smooth" && this.isDynamicMode()) {
520
+ console.warn(
521
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
522
+ );
523
+ }
524
+ this._scrollToOffset(this.scrollOffset + delta, {
525
+ adjustments: void 0,
526
+ behavior
527
+ });
528
+ };
529
+ this.getTotalSize = () => {
530
+ var _a;
531
+ const measurements = this.getMeasurements();
532
+ let end;
533
+ if (measurements.length === 0) {
534
+ end = this.options.paddingStart;
535
+ } else {
536
+ end = this.options.lanes === 1 ? ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0 : Math.max(
537
+ ...measurements.slice(-this.options.lanes).map((m) => m.end)
538
+ );
539
+ }
540
+ return end - this.options.scrollMargin + this.options.paddingEnd;
541
+ };
542
+ this._scrollToOffset = (offset, {
543
+ adjustments,
544
+ behavior
545
+ }) => {
546
+ this.options.scrollToFn(offset, { behavior, adjustments }, this);
547
+ };
548
+ this.measure = () => {
549
+ this.itemSizeCache = /* @__PURE__ */ new Map();
550
+ this.notify(false);
551
+ };
552
+ this.setOptions(opts);
553
+ this.scrollRect = this.options.initialRect;
554
+ this.scrollOffset = this.options.initialOffset;
555
+ this.measurementsCache = this.options.initialMeasurementsCache;
556
+ this.measurementsCache.forEach((item) => {
557
+ this.itemSizeCache.set(item.key, item.size);
558
+ });
559
+ this.maybeNotify();
560
+ }
561
+ }
562
+ const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
563
+ while (low <= high) {
564
+ const middle = (low + high) / 2 | 0;
565
+ const currentValue = getCurrentValue(middle);
566
+ if (currentValue < value) {
567
+ low = middle + 1;
568
+ } else if (currentValue > value) {
569
+ high = middle - 1;
570
+ } else {
571
+ return middle;
572
+ }
573
+ }
574
+ if (low > 0) {
575
+ return low - 1;
576
+ } else {
577
+ return 0;
578
+ }
579
+ };
580
+ function calculateRange({
581
+ measurements,
582
+ outerSize,
583
+ scrollOffset
584
+ }) {
585
+ const count = measurements.length - 1;
586
+ const getOffset = (index) => measurements[index].start;
587
+ const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
588
+ let endIndex = startIndex;
589
+ while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
590
+ endIndex++;
591
+ }
592
+ return { startIndex, endIndex };
593
+ }
594
+
595
+ export { Virtualizer, approxEqual, defaultKeyExtractor, defaultRangeExtractor, elementScroll, measureElement, memo, notUndefined, observeElementOffset, observeElementRect };
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+ function memo(getDeps, fn, opts) {
3
+ let deps = opts.initialDeps ?? [];
4
+ let result;
5
+ return () => {
6
+ var _a, _b, _c, _d;
7
+ let depTime;
8
+ if (opts.key && ((_a = opts.debug) == null ? void 0 : _a.call(opts)))
9
+ depTime = Date.now();
10
+ const newDeps = getDeps();
11
+ const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
12
+ if (!depsChanged) {
13
+ return result;
14
+ }
15
+ deps = newDeps;
16
+ let resultTime;
17
+ if (opts.key && ((_b = opts.debug) == null ? void 0 : _b.call(opts)))
18
+ resultTime = Date.now();
19
+ result = fn(...newDeps);
20
+ if (opts.key && ((_c = opts.debug) == null ? void 0 : _c.call(opts))) {
21
+ const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
22
+ const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
23
+ const resultFpsPercentage = resultEndTime / 16;
24
+ const pad = (str, num) => {
25
+ str = String(str);
26
+ while (str.length < num) {
27
+ str = " " + str;
28
+ }
29
+ return str;
30
+ };
31
+ console.info(
32
+ `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,
33
+ `
34
+ font-size: .6rem;
35
+ font-weight: bold;
36
+ color: hsl(${Math.max(
37
+ 0,
38
+ Math.min(120 - 120 * resultFpsPercentage, 120)
39
+ )}deg 100% 31%);`,
40
+ opts == null ? void 0 : opts.key
41
+ );
42
+ }
43
+ (_d = opts == null ? void 0 : opts.onChange) == null ? void 0 : _d.call(opts, result);
44
+ return result;
45
+ };
46
+ }
47
+ function notUndefined(value, msg) {
48
+ if (value === void 0) {
49
+ throw new Error(`Unexpected undefined${msg ? `: ${msg}` : ""}`);
50
+ } else {
51
+ return value;
52
+ }
53
+ }
54
+ const approxEqual = (a, b) => Math.abs(a - b) < 1;
55
+
56
+ export { approxEqual, memo, notUndefined };