@iblai/web-containers 1.67.0 → 1.67.2

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 (41) hide show
  1. package/dist/cjs/components/chat/index.js +5 -0
  2. package/dist/cjs/components/chat/index.js.map +1 -1
  3. package/dist/cjs/components/profile/csv-editor.js +44 -7
  4. package/dist/cjs/components/profile/csv-editor.js.map +1 -1
  5. package/dist/cjs/node_modules/.pnpm/@tanstack_react-virtual@3.14.25_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/@tanstack/react-virtual/dist/esm/index.js +165 -0
  6. package/dist/cjs/node_modules/.pnpm/@tanstack_react-virtual@3.14.25_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -0
  7. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/index.js +1648 -0
  8. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -0
  9. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/ios-gesture.js +127 -0
  10. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/ios-gesture.js.map +1 -0
  11. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/lazy-measurements.js +39 -0
  12. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/lazy-measurements.js.map +1 -0
  13. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +87 -0
  14. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -0
  15. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/utils.js +85 -0
  16. package/dist/cjs/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/utils.js.map +1 -0
  17. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  18. package/dist/esm/_virtual/index2.js +2 -2
  19. package/dist/esm/_virtual/index3.js +2 -2
  20. package/dist/esm/components/chat/index.js +5 -0
  21. package/dist/esm/components/chat/index.js.map +1 -1
  22. package/dist/esm/components/profile/csv-editor.js +45 -8
  23. package/dist/esm/components/profile/csv-editor.js.map +1 -1
  24. package/dist/esm/node_modules/.pnpm/@tanstack_react-virtual@3.14.25_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/@tanstack/react-virtual/dist/esm/index.js +138 -0
  25. package/dist/esm/node_modules/.pnpm/@tanstack_react-virtual@3.14.25_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -0
  26. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/index.js +1636 -0
  27. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -0
  28. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/ios-gesture.js +122 -0
  29. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/ios-gesture.js.map +1 -0
  30. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/lazy-measurements.js +36 -0
  31. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/lazy-measurements.js.map +1 -0
  32. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +82 -0
  33. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -0
  34. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/utils.js +80 -0
  35. package/dist/esm/node_modules/.pnpm/@tanstack_virtual-core@3.19.10/node_modules/@tanstack/virtual-core/dist/esm/utils.js.map +1 -0
  36. package/dist/esm/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  37. package/dist/esm/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  38. package/dist/esm/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  39. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  40. package/dist/package.json +2 -1
  41. package/package.json +4 -3
@@ -0,0 +1,1648 @@
1
+ 'use strict';
2
+
3
+ var lazyMeasurements = require('./lazy-measurements.js');
4
+ var utils = require('./utils.js');
5
+ var scrollClassifier = require('./scroll-classifier.js');
6
+ var iosGesture = require('./ios-gesture.js');
7
+
8
+ const getRect = (element) => {
9
+ const { clientWidth, clientHeight } = element;
10
+ return { width: clientWidth, height: clientHeight };
11
+ };
12
+ const createFrameQueue = (targetWindow) => {
13
+ const ids = /* @__PURE__ */ new Set();
14
+ return {
15
+ schedule: (fn) => {
16
+ const id = targetWindow.requestAnimationFrame(() => {
17
+ ids.delete(id);
18
+ fn();
19
+ });
20
+ ids.add(id);
21
+ },
22
+ cancel: () => {
23
+ ids.forEach((id) => targetWindow.cancelAnimationFrame(id));
24
+ ids.clear();
25
+ }
26
+ };
27
+ };
28
+ const defaultKeyExtractor = (index) => index;
29
+ const defaultRangeExtractor = (range) => {
30
+ const overscan = range.overscan * Math.max(range.lanes ?? 1, 1);
31
+ const start = Math.max(range.startIndex - overscan, 0);
32
+ const end = Math.min(range.endIndex + overscan, range.count - 1);
33
+ const len = end - start + 1;
34
+ const arr = new Array(len);
35
+ for (let i = 0; i < len; i++) {
36
+ arr[i] = start + i;
37
+ }
38
+ return arr;
39
+ };
40
+ const observeElementRect = (instance, cb) => {
41
+ const element = instance.scrollElement;
42
+ if (!element) {
43
+ return;
44
+ }
45
+ const targetWindow = instance.targetWindow;
46
+ if (!targetWindow) {
47
+ return;
48
+ }
49
+ const handler = (rect) => {
50
+ const { width, height } = rect;
51
+ cb({ width: Math.round(width), height: Math.round(height) });
52
+ };
53
+ handler(getRect(element));
54
+ if (!targetWindow.ResizeObserver) {
55
+ return () => {
56
+ };
57
+ }
58
+ const frames = createFrameQueue(targetWindow);
59
+ const observer = new targetWindow.ResizeObserver(() => {
60
+ const run = () => {
61
+ handler(getRect(element));
62
+ };
63
+ instance.options.useAnimationFrameWithResizeObserver ? frames.schedule(run) : run();
64
+ });
65
+ observer.observe(element, { box: "content-box" });
66
+ return () => {
67
+ observer.unobserve(element);
68
+ frames.cancel();
69
+ };
70
+ };
71
+ const addEventListenerOptions = {
72
+ passive: true
73
+ };
74
+ const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
75
+ const observeOffset = (instance, cb, readOffset) => {
76
+ const element = instance.scrollElement;
77
+ if (!element) {
78
+ return;
79
+ }
80
+ const targetWindow = instance.targetWindow;
81
+ if (!targetWindow) {
82
+ return;
83
+ }
84
+ const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
85
+ let offset = 0;
86
+ const fallback = registerScrollendEvent ? null : utils.debounce(
87
+ targetWindow,
88
+ () => cb(readOffset(element), false),
89
+ instance.options.isScrollingResetDelay
90
+ );
91
+ const createHandler = (isScrolling) => () => {
92
+ offset = readOffset(element);
93
+ fallback == null ? void 0 : fallback();
94
+ cb(offset, isScrolling);
95
+ };
96
+ const handler = createHandler(true);
97
+ const endHandler = createHandler(false);
98
+ element.addEventListener("scroll", handler, addEventListenerOptions);
99
+ if (registerScrollendEvent) {
100
+ element.addEventListener("scrollend", endHandler, addEventListenerOptions);
101
+ }
102
+ return () => {
103
+ element.removeEventListener("scroll", handler);
104
+ if (registerScrollendEvent) {
105
+ element.removeEventListener("scrollend", endHandler);
106
+ }
107
+ fallback == null ? void 0 : fallback.cancel();
108
+ };
109
+ };
110
+ const observeElementOffset = (instance, cb) => observeOffset(instance, cb, (el) => {
111
+ const { horizontal, isRtl } = instance.options;
112
+ return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
113
+ });
114
+ const measureElement = (element, entry, instance) => {
115
+ if (instance.options.useCachedMeasurements) {
116
+ const index = instance.indexFromElement(element);
117
+ const key = instance.options.getItemKey(index);
118
+ return instance.itemSizeCache.get(key) ?? instance.options.estimateSize(index);
119
+ }
120
+ if (entry == null ? void 0 : entry.borderBoxSize) {
121
+ const box = entry.borderBoxSize[0];
122
+ if (box) {
123
+ const size = Math.round(
124
+ box[instance.options.horizontal ? "inlineSize" : "blockSize"]
125
+ );
126
+ return size;
127
+ }
128
+ }
129
+ if (!entry) {
130
+ const index = instance.indexFromElement(element);
131
+ const key = instance.options.getItemKey(index);
132
+ const cachedSize = instance.itemSizeCache.get(key);
133
+ if (cachedSize !== void 0) {
134
+ return cachedSize;
135
+ }
136
+ }
137
+ return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
138
+ };
139
+ const scrollWithAdjustments = (offset, {
140
+ adjustments = 0,
141
+ behavior
142
+ }, instance) => {
143
+ var _a, _b;
144
+ (_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
145
+ [instance.options.horizontal ? "left" : "top"]: offset + adjustments,
146
+ behavior
147
+ });
148
+ };
149
+ const elementScroll = scrollWithAdjustments;
150
+ const initialScrollPhase = (behavior, atTarget) => behavior === "smooth" ? atTarget ? "smoothLanded" : "smooth" : "instant";
151
+ const isSmoothScroll = (state) => (state == null ? void 0 : state.phase) === "smooth" || (state == null ? void 0 : state.phase) === "smoothLanded";
152
+ function isAppendWithTrim(prevCount, nextCount, getPreviousKey, getNextKey) {
153
+ if (nextCount === 0) return false;
154
+ const firstKey = getNextKey(0);
155
+ const removedKeys = /* @__PURE__ */ new Set();
156
+ let removedCount = 0;
157
+ while (removedCount < prevCount) {
158
+ const key = getPreviousKey(removedCount);
159
+ if (key === firstKey) break;
160
+ removedKeys.add(key);
161
+ removedCount++;
162
+ }
163
+ const retainedCount = prevCount - removedCount;
164
+ if (retainedCount === 0 || retainedCount >= nextCount) return false;
165
+ for (let i = 0; i < retainedCount; i++) {
166
+ if (getNextKey(i) !== getPreviousKey(removedCount + i)) return false;
167
+ }
168
+ for (let i = retainedCount; i < nextCount; i++) {
169
+ if (removedKeys.has(getNextKey(i))) return false;
170
+ }
171
+ return true;
172
+ }
173
+ class Virtualizer {
174
+ constructor(opts) {
175
+ this.unsubs = [];
176
+ this.scrollElement = null;
177
+ this.targetWindow = null;
178
+ this.isScrolling = false;
179
+ this.scrollState = null;
180
+ this.measurementsCache = [];
181
+ this._singleLaneMeasurements = null;
182
+ this.itemSizeCache = /* @__PURE__ */ new Map();
183
+ this.itemSizeCacheVersion = 0;
184
+ this.laneAssignments = /* @__PURE__ */ new Map();
185
+ this.pendingMin = null;
186
+ this.prevLanes = void 0;
187
+ this.lanesChangedFlag = false;
188
+ this.lanesSettling = false;
189
+ this.pendingScrollAnchor = null;
190
+ this.scrollRect = null;
191
+ this.scrollOffset = null;
192
+ this.scrollDirection = null;
193
+ this._holdOffset = 0;
194
+ this._reportedOverscroll = false;
195
+ this._iosGesture = new iosGesture.IosGesture({
196
+ getWindow: () => this.targetWindow,
197
+ now: () => this.now(),
198
+ // The end of a fling can move less than a pixel per scroll event, so
199
+ // events can stop for 150ms while the fling is still running (seen on
200
+ // an iPhone, 27.0.1). A command waiting for it would then be written
201
+ // into the fling and overridden. The element having moved since the
202
+ // last event means it has not ended: wait again. Not while our own
203
+ // write has yet to report: that moved it.
204
+ tailStillMoving: () => {
205
+ const state = this.scrollState;
206
+ if ((state == null ? void 0 : state.phase) !== "queued" || this.pendingWrite !== null) {
207
+ return false;
208
+ }
209
+ const now = this._readElementOffset();
210
+ if (now === null || this._lastElementOffset === null || Math.abs(now - this._lastElementOffset) < 1) {
211
+ return false;
212
+ }
213
+ this._lastElementOffset = now;
214
+ state.samples = [...state.samples ?? [], { t: this.now(), offset: now }];
215
+ return true;
216
+ },
217
+ onTailClosed: () => {
218
+ const state = this.scrollState;
219
+ if ((state == null ? void 0 : state.phase) === "queued" && scrollClassifier.flingCaught(state.samples ?? [])) {
220
+ this.scrollState = null;
221
+ }
222
+ this._flushHoldIfReady(true);
223
+ this._writeAwaitingCommand();
224
+ this._retryClampedAdjustment();
225
+ }
226
+ });
227
+ this._lastElementOffset = null;
228
+ this.pendingWrite = null;
229
+ this._clampedAdjustment = null;
230
+ this.elementsCache = /* @__PURE__ */ new Map();
231
+ this._resizeBatch = null;
232
+ this.now = () => {
233
+ var _a, _b, _c;
234
+ return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
235
+ };
236
+ this.observer = /* @__PURE__ */ (() => {
237
+ let _ro = null;
238
+ let _frames = null;
239
+ let delivering = false;
240
+ let observeQueued = false;
241
+ const pendingObservations = /* @__PURE__ */ new Set();
242
+ const get = () => {
243
+ if (_ro) {
244
+ return _ro;
245
+ }
246
+ const targetWindow = this.targetWindow;
247
+ if (!targetWindow || !targetWindow.ResizeObserver) {
248
+ return null;
249
+ }
250
+ const frames = _frames = createFrameQueue(targetWindow);
251
+ return _ro = new targetWindow.ResizeObserver((entries) => {
252
+ const run = () => {
253
+ const batch = { sync: false };
254
+ this._resizeBatch = batch;
255
+ try {
256
+ entries.forEach(measureEntry);
257
+ } finally {
258
+ this._resizeBatch = null;
259
+ if (batch.notify) {
260
+ this.notify(batch.sync);
261
+ this._noteClampMax();
262
+ this._flushHoldIfReady(true);
263
+ this._retryClampedAdjustment();
264
+ this.measureElement(null);
265
+ }
266
+ }
267
+ };
268
+ if (this.options.useAnimationFrameWithResizeObserver) {
269
+ frames.schedule(run);
270
+ } else {
271
+ delivering = true;
272
+ try {
273
+ run();
274
+ } finally {
275
+ delivering = false;
276
+ }
277
+ }
278
+ });
279
+ };
280
+ const measureEntry = (entry) => {
281
+ const node = entry.target;
282
+ const index = this.indexFromElement(node);
283
+ if (!node.isConnected) {
284
+ this.observer.unobserve(node);
285
+ for (const [cacheKey, cachedNode] of this.elementsCache) {
286
+ if (cachedNode === node) {
287
+ this.elementsCache.delete(cacheKey);
288
+ break;
289
+ }
290
+ }
291
+ return;
292
+ }
293
+ if (!this.isIndexInRange(index)) return;
294
+ if (this.shouldMeasureDuringScroll(index)) {
295
+ this.resizeItem(index, this.options.measureElement(node, entry, this));
296
+ }
297
+ };
298
+ return {
299
+ disconnect: () => {
300
+ var _a;
301
+ (_a = get()) == null ? void 0 : _a.disconnect();
302
+ _frames == null ? void 0 : _frames.cancel();
303
+ pendingObservations.clear();
304
+ observeQueued = false;
305
+ _ro = null;
306
+ _frames = null;
307
+ },
308
+ observe: (target) => {
309
+ const observer = get();
310
+ if (!observer) return;
311
+ if (!delivering) {
312
+ observer.observe(target, { box: "border-box" });
313
+ return;
314
+ }
315
+ pendingObservations.add(target);
316
+ if (!observeQueued) {
317
+ observeQueued = true;
318
+ _frames == null ? void 0 : _frames.schedule(() => {
319
+ observeQueued = false;
320
+ pendingObservations.forEach((node) => {
321
+ if (node.isConnected) _ro == null ? void 0 : _ro.observe(node, { box: "border-box" });
322
+ });
323
+ pendingObservations.clear();
324
+ });
325
+ }
326
+ },
327
+ unobserve: (target) => {
328
+ var _a;
329
+ pendingObservations.delete(target);
330
+ (_a = get()) == null ? void 0 : _a.unobserve(target);
331
+ }
332
+ };
333
+ })();
334
+ this.range = null;
335
+ this.setOptions = (opts2) => {
336
+ var _a;
337
+ const merged = {
338
+ debug: false,
339
+ initialOffset: 0,
340
+ overscan: 1,
341
+ paddingStart: 0,
342
+ paddingEnd: 0,
343
+ scrollPaddingStart: 0,
344
+ scrollPaddingEnd: 0,
345
+ horizontal: false,
346
+ getItemKey: defaultKeyExtractor,
347
+ rangeExtractor: defaultRangeExtractor,
348
+ onChange: () => {
349
+ },
350
+ measureElement,
351
+ initialRect: { width: 0, height: 0 },
352
+ scrollMargin: 0,
353
+ gap: 0,
354
+ indexAttribute: "data-index",
355
+ initialMeasurementsCache: [],
356
+ lanes: 1,
357
+ anchorTo: "start",
358
+ followOnAppend: false,
359
+ scrollEndThreshold: 1,
360
+ isScrollingResetDelay: 150,
361
+ enabled: true,
362
+ isRtl: false,
363
+ useScrollendEvent: false,
364
+ useAnimationFrameWithResizeObserver: false,
365
+ laneAssignmentMode: "estimate",
366
+ useCachedMeasurements: false
367
+ };
368
+ for (const key in opts2) {
369
+ const v = opts2[key];
370
+ if (v !== void 0) merged[key] = v;
371
+ }
372
+ const prevOptions = this.options;
373
+ let anchor = null;
374
+ let followOnAppend = null;
375
+ let edgeKeysChanged = false;
376
+ if (prevOptions !== void 0 && prevOptions.enabled && merged.enabled && merged.anchorTo === "end" && this.scrollElement !== null) {
377
+ const prevCount = prevOptions.count;
378
+ const nextCount = merged.count;
379
+ const measurements = this.getMeasurements();
380
+ const previousItems = ((_a = this._singleLaneMeasurements) == null ? void 0 : _a.items) ?? measurements;
381
+ const getPreviousKey = (index) => lazyMeasurements.getMeasurementKey(previousItems[index]);
382
+ const prevFirstKey = prevCount > 0 ? getPreviousKey(0) : null;
383
+ const prevLastKey = prevCount > 0 ? getPreviousKey(prevCount - 1) : null;
384
+ const didCountChange = nextCount !== prevCount;
385
+ const didEdgeKeysChange = didCountChange || prevCount > 0 && nextCount > 0 && (merged.getItemKey(0) !== prevFirstKey || merged.getItemKey(nextCount - 1) !== prevLastKey);
386
+ if (didEdgeKeysChange) {
387
+ edgeKeysChanged = true;
388
+ const item = prevCount > 0 ? this.getVirtualItemForOffset(this.getScrollOffset()) ?? measurements[0] : null;
389
+ if (item) {
390
+ anchor = [item.key, this.getScrollOffset() - item.start];
391
+ }
392
+ const behavior = merged.followOnAppend === true ? "auto" : merged.followOnAppend || null;
393
+ if (behavior && nextCount > 0 && this.isAtEnd(prevOptions.scrollEndThreshold) && (prevCount === 0 || merged.getItemKey(nextCount - 1) !== prevLastKey)) {
394
+ if (nextCount > prevCount || isAppendWithTrim(
395
+ prevCount,
396
+ nextCount,
397
+ getPreviousKey,
398
+ merged.getItemKey
399
+ )) {
400
+ followOnAppend = behavior;
401
+ }
402
+ }
403
+ }
404
+ }
405
+ this.options = merged;
406
+ if (edgeKeysChanged) {
407
+ this.pendingMin = 0;
408
+ this.itemSizeCacheVersion++;
409
+ }
410
+ let anchorDelta = null;
411
+ if (anchor && this.scrollOffset !== null && !this._awaitingCommandReadBack()) {
412
+ const [anchorKey, anchorOffset] = anchor;
413
+ const newMeasurements = this.getMeasurements();
414
+ const { count, getItemKey } = this.options;
415
+ let idx = 0;
416
+ while (idx < count && getItemKey(idx) !== anchorKey) {
417
+ idx++;
418
+ }
419
+ if (idx < count) {
420
+ const anchorItem = newMeasurements[idx];
421
+ if (anchorItem) {
422
+ const newOffset = Math.max(0, anchorItem.start + anchorOffset);
423
+ if (!followOnAppend && newOffset !== this.scrollOffset) {
424
+ anchorDelta = newOffset - this.scrollOffset;
425
+ this.scrollOffset = newOffset;
426
+ }
427
+ }
428
+ }
429
+ }
430
+ if (followOnAppend) {
431
+ this.pendingScrollAnchor = { kind: "follow", behavior: followOnAppend };
432
+ } else if (anchorDelta !== null) {
433
+ if (this._canWriteScroll()) {
434
+ this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
435
+ } else {
436
+ this._holdOffset += anchorDelta;
437
+ this._followOffsetTarget(anchorDelta);
438
+ }
439
+ }
440
+ };
441
+ this.notify = (sync) => {
442
+ var _a, _b;
443
+ (_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
444
+ };
445
+ this.maybeNotify = utils.memo(
446
+ () => {
447
+ this.calculateRange();
448
+ return [
449
+ this.isScrolling,
450
+ this.range ? this.range.startIndex : null,
451
+ this.range ? this.range.endIndex : null
452
+ ];
453
+ },
454
+ (isScrolling) => {
455
+ this.notify(isScrolling);
456
+ },
457
+ {
458
+ key: process.env.NODE_ENV !== "production" && "maybeNotify",
459
+ debug: () => this.options.debug,
460
+ initialDeps: [
461
+ this.isScrolling,
462
+ this.range ? this.range.startIndex : null,
463
+ this.range ? this.range.endIndex : null
464
+ ]
465
+ }
466
+ );
467
+ this.cleanup = () => {
468
+ var _a;
469
+ this.unsubs.filter(Boolean).forEach((d) => d());
470
+ this.unsubs = [];
471
+ this.observer.disconnect();
472
+ if (this.rafId != null && this.targetWindow) {
473
+ this.targetWindow.cancelAnimationFrame(this.rafId);
474
+ this.rafId = null;
475
+ }
476
+ this.scrollState = null;
477
+ (_a = this._momentumStop) == null ? void 0 : _a.restore();
478
+ this._momentumStop = null;
479
+ this.isScrolling = false;
480
+ this.scrollDirection = null;
481
+ this._holdOffset = 0;
482
+ this._reportedOverscroll = false;
483
+ this._clampedAdjustment = null;
484
+ this.pendingWrite = null;
485
+ this.scrollElement = null;
486
+ this.targetWindow = null;
487
+ };
488
+ this._didMount = () => {
489
+ return () => {
490
+ this.cleanup();
491
+ };
492
+ };
493
+ this._willUpdate = () => {
494
+ var _a;
495
+ const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
496
+ if (this.scrollElement !== scrollElement) {
497
+ this.cleanup();
498
+ if (!scrollElement) {
499
+ this.maybeNotify();
500
+ return;
501
+ }
502
+ this.scrollElement = scrollElement;
503
+ if (this.scrollElement && "ownerDocument" in this.scrollElement) {
504
+ this.targetWindow = this.scrollElement.ownerDocument.defaultView;
505
+ } else {
506
+ this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
507
+ }
508
+ this.elementsCache.forEach((cached) => {
509
+ this.observer.observe(cached);
510
+ });
511
+ this.unsubs.push(
512
+ this.options.observeElementRect(this, (rect) => {
513
+ this.scrollRect = rect;
514
+ this.maybeNotify();
515
+ })
516
+ );
517
+ this.unsubs.push(
518
+ this.options.observeElementOffset(this, (offset, isScrolling) => {
519
+ var _a2, _b, _c, _d;
520
+ const elementMax = isScrolling ? this._elementMaxScrollOffset() : null;
521
+ const wasOverscrolled = this._reportedOverscroll;
522
+ this._reportedOverscroll = offset < 0 || elementMax !== null && offset > elementMax + 1;
523
+ const elementOffset = offset;
524
+ this._lastElementOffset = elementOffset;
525
+ offset = this._toLayoutOffset(offset);
526
+ const kind = this._classifyScrollEvent(
527
+ offset,
528
+ isScrolling,
529
+ elementMax
530
+ );
531
+ if (kind === "spurious") return;
532
+ if (kind === "readBack") {
533
+ offset = this.pendingWrite.target;
534
+ } else if (kind === "clampedReadBack" && ((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null && // Not `elementMax`: an adapter can report the read-back at rest.
535
+ offset < this.getMaxScrollOffset() - 1.5) {
536
+ this.scrollState.lastTargetOffset = offset;
537
+ } else if (scrollClassifier.externalRetiresCommand({
538
+ kind,
539
+ offset,
540
+ command: this.scrollState,
541
+ target: () => this.getScrollStateTarget(this.scrollState)
542
+ })) {
543
+ this.scrollState = null;
544
+ }
545
+ this.pendingWrite = null;
546
+ if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
547
+ this._clampedAdjustment = null;
548
+ }
549
+ const prevOffset = this.getScrollOffset();
550
+ const prevDirection = this.scrollDirection;
551
+ this.scrollDirection = isScrolling ? prevOffset === offset ? this.scrollDirection : prevOffset < offset ? "forward" : "backward" : null;
552
+ this.scrollOffset = offset;
553
+ this.isScrolling = isScrolling;
554
+ const queued = this.scrollState;
555
+ if ((queued == null ? void 0 : queued.phase) === "queued" && kind === "external" && isScrolling) {
556
+ if (wasOverscrolled || this._reportedOverscroll) {
557
+ queued.samples = [];
558
+ } else {
559
+ const t = this.now();
560
+ queued.samples = [
561
+ ...(queued.samples ?? []).filter(
562
+ (sample) => t - sample.t <= 200
563
+ ),
564
+ { t, offset: elementOffset }
565
+ ];
566
+ if (prevDirection !== null && this.scrollDirection !== prevDirection || scrollClassifier.flingSpedUp(queued.samples)) {
567
+ this.scrollState = null;
568
+ }
569
+ }
570
+ }
571
+ if (this._iosGesture.onScroll({
572
+ isScrolling,
573
+ ownReadBack: kind === "readBack",
574
+ moved: offset !== prevOffset,
575
+ // Neither our write's read-back nor a frame of our smooth
576
+ // animation: the user or a fling moved it.
577
+ external: kind === "external" && ((_b = this.scrollState) == null ? void 0 : _b.phase) !== "smooth" && ((_c = this.scrollState) == null ? void 0 : _c.phase) !== "smoothFinishing"
578
+ }) && // The user scrolls: a command still waiting for the tail is
579
+ // theirs to override, like a written one would be.
580
+ ((_d = this.scrollState) == null ? void 0 : _d.phase) === "queued") {
581
+ this.scrollState = null;
582
+ }
583
+ this._flushHoldIfReady(true);
584
+ if (this.scrollState) {
585
+ this.scheduleScrollReconcile();
586
+ }
587
+ this.maybeNotify();
588
+ })
589
+ );
590
+ if ("addEventListener" in this.scrollElement) {
591
+ this.unsubs.push(
592
+ this._iosGesture.listen(this.scrollElement)
593
+ );
594
+ }
595
+ this._scrollToOffset(this.getScrollOffset());
596
+ }
597
+ this._noteClampMax();
598
+ const anchor = this.pendingScrollAnchor;
599
+ this.pendingScrollAnchor = null;
600
+ if (anchor && this.scrollElement && this.options.enabled) {
601
+ if (anchor.kind === "anchor") {
602
+ if (!this._canWriteScroll()) {
603
+ this._holdOffset += anchor.delta;
604
+ this._followOffsetTarget(anchor.delta);
605
+ this.notify(false);
606
+ } else if (isSmoothScroll(this.scrollState) && !utils.approxEqual(
607
+ this.getScrollOffset() - anchor.delta,
608
+ this.scrollState.lastTargetOffset
609
+ )) ;
610
+ else {
611
+ this._followOffsetTarget(anchor.delta);
612
+ this._scrollToOffset(this.getScrollOffset());
613
+ }
614
+ } else {
615
+ this.scrollToEnd({ behavior: anchor.behavior });
616
+ }
617
+ }
618
+ this._flushHoldIfReady(false);
619
+ this._retryClampedAdjustment();
620
+ };
621
+ this._classifyScrollEvent = (offset, isScrolling, elementMax) => {
622
+ var _a;
623
+ return scrollClassifier.classifyScrollEvent({
624
+ offset,
625
+ isScrolling,
626
+ elementMax,
627
+ holdOffset: this._holdOffset,
628
+ scrollOffset: this.scrollOffset,
629
+ pendingWrite: this.pendingWrite,
630
+ clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null
631
+ });
632
+ };
633
+ this._retryClampedAdjustment = () => {
634
+ if (this._clampedAdjustment === null || !this.scrollElement || !this.options.enabled || !this._canWriteScroll()) {
635
+ return;
636
+ }
637
+ const { target, maxAtWrite } = this._clampedAdjustment;
638
+ const max = this.getMaxScrollOffset();
639
+ if (max > maxAtWrite + 0.5) {
640
+ this._clampedAdjustment = target > max + 0.5 ? { target, maxAtWrite: max } : null;
641
+ this._scrollToOffset(target);
642
+ }
643
+ };
644
+ this._writeAwaitingCommand = () => {
645
+ const state = this.scrollState;
646
+ if (state === null || state.phase !== "queued") return;
647
+ const { behavior } = state;
648
+ this.getMeasurements();
649
+ const offset = this.getScrollStateTarget(state);
650
+ state.lastTargetOffset = offset;
651
+ this._clampedAdjustment = null;
652
+ state.phase = initialScrollPhase(
653
+ behavior,
654
+ state.index != null && utils.approxEqual(offset, this.getScrollOffset())
655
+ );
656
+ this._scrollToOffset(offset, { behavior });
657
+ this.scheduleScrollReconcile();
658
+ };
659
+ this._readElementOffset = () => {
660
+ const el = this.scrollElement;
661
+ if (el == null) return null;
662
+ const { horizontal, isRtl } = this.options;
663
+ if (typeof el.scrollTop === "number") {
664
+ return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
665
+ }
666
+ if (typeof el.scrollY === "number") {
667
+ return horizontal ? el.scrollX : el.scrollY;
668
+ }
669
+ return null;
670
+ };
671
+ this._canWriteScroll = () => !(iosGesture.isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll;
672
+ this._flushHoldIfReady = (sync) => {
673
+ var _a;
674
+ if (this._holdOffset === 0) return;
675
+ if (!this.scrollElement || !this.options.enabled) return;
676
+ if (!this._canWriteScroll()) return;
677
+ if (((_a = this.scrollState) == null ? void 0 : _a.phase) === "smooth") return;
678
+ this._holdOffset = 0;
679
+ if (this.scrollOffset !== null && this.scrollOffset < 0) {
680
+ this.scrollOffset = 0;
681
+ }
682
+ this.notify(sync);
683
+ const target = this.getCommandWrittenOffset() ?? this.getScrollOffset();
684
+ this._clampedAdjustment = this._clampedBy(target);
685
+ this._scrollToOffset(target);
686
+ };
687
+ this.rafId = null;
688
+ this.getSize = () => {
689
+ if (!this.options.enabled) {
690
+ this.scrollRect = null;
691
+ return 0;
692
+ }
693
+ this.scrollRect = this.scrollRect ?? this.options.initialRect;
694
+ return this.scrollRect[this.options.horizontal ? "width" : "height"];
695
+ };
696
+ this.getScrollOffset = () => {
697
+ if (!this.options.enabled) {
698
+ this.scrollOffset = null;
699
+ return 0;
700
+ }
701
+ this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
702
+ return this.scrollOffset;
703
+ };
704
+ this.getMeasurementOptions = utils.memo(
705
+ () => [
706
+ this.options.count,
707
+ this.options.paddingStart,
708
+ this.options.scrollMargin,
709
+ this.options.getItemKey,
710
+ this.options.enabled,
711
+ this.options.lanes,
712
+ this.options.laneAssignmentMode,
713
+ this.options.gap
714
+ ],
715
+ (count, paddingStart, scrollMargin, getItemKey, enabled, lanes, laneAssignmentMode, gap) => {
716
+ const lanesChanged = this.prevLanes !== void 0 && this.prevLanes !== lanes;
717
+ if (lanesChanged) {
718
+ this.lanesChangedFlag = true;
719
+ }
720
+ this.prevLanes = lanes;
721
+ this.pendingMin = null;
722
+ return {
723
+ count,
724
+ paddingStart,
725
+ scrollMargin,
726
+ getItemKey,
727
+ enabled,
728
+ lanes,
729
+ laneAssignmentMode,
730
+ gap
731
+ };
732
+ },
733
+ {
734
+ key: false
735
+ }
736
+ );
737
+ this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
738
+ this.getMeasurements = utils.memo(
739
+ () => [this.getMeasurementOptions(), this.itemSizeCacheVersion],
740
+ ({
741
+ count,
742
+ paddingStart,
743
+ scrollMargin,
744
+ getItemKey,
745
+ enabled,
746
+ lanes,
747
+ laneAssignmentMode,
748
+ gap
749
+ }, _itemSizeCacheVersion) => {
750
+ var _a;
751
+ const itemSizeCache = this.itemSizeCache;
752
+ if (!enabled) {
753
+ this.measurementsCache = [];
754
+ this._singleLaneMeasurements = null;
755
+ this.itemSizeCache.clear();
756
+ this.laneAssignments.clear();
757
+ return [];
758
+ }
759
+ if (this.laneAssignments.size > count) {
760
+ for (const index of this.laneAssignments.keys()) {
761
+ if (index >= count) {
762
+ this.laneAssignments.delete(index);
763
+ }
764
+ }
765
+ }
766
+ if (this.lanesChangedFlag) {
767
+ this.lanesChangedFlag = false;
768
+ this.lanesSettling = true;
769
+ this.measurementsCache = [];
770
+ this._singleLaneMeasurements = null;
771
+ this.itemSizeCache.clear();
772
+ this.laneAssignments.clear();
773
+ this.pendingMin = null;
774
+ }
775
+ if (this.measurementsCache.length === 0 && !this.lanesSettling) {
776
+ this.measurementsCache = this.options.initialMeasurementsCache;
777
+ this.measurementsCache.forEach((item) => {
778
+ this.itemSizeCache.set(item.key, item.size);
779
+ });
780
+ }
781
+ const min = this.lanesSettling ? 0 : this.pendingMin ?? 0;
782
+ this.pendingMin = null;
783
+ if (this.lanesSettling && this.measurementsCache.length === count) {
784
+ this.lanesSettling = false;
785
+ }
786
+ if (lanes === 1) {
787
+ const need = count * 2;
788
+ let flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
789
+ if (!flat || flat.length < need) {
790
+ const next = new Float64Array(need);
791
+ if (flat && min > 0) next.set(flat.subarray(0, min * 2));
792
+ flat = next;
793
+ }
794
+ const items = min === 0 ? new Array(count) : this._singleLaneMeasurements.items.slice();
795
+ let runningStart;
796
+ if (min === 0) {
797
+ runningStart = paddingStart + scrollMargin;
798
+ } else {
799
+ const prevIdx = min - 1;
800
+ runningStart = flat[prevIdx * 2] + flat[prevIdx * 2 + 1] + gap;
801
+ }
802
+ for (let i = min; i < count; i++) {
803
+ const key = getItemKey(i);
804
+ items[i] = key;
805
+ const measuredSize = itemSizeCache.get(key);
806
+ const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
807
+ flat[i * 2] = runningStart;
808
+ flat[i * 2 + 1] = size;
809
+ runningStart += size + gap;
810
+ }
811
+ this._singleLaneMeasurements = { flat, items };
812
+ const view = lazyMeasurements.createLazyMeasurementsView(items, flat);
813
+ this.measurementsCache = view;
814
+ return view;
815
+ }
816
+ const measurements = this.measurementsCache.slice(0, min);
817
+ const laneLastIndex = new Array(lanes).fill(
818
+ void 0
819
+ );
820
+ const laneEnds = new Float64Array(lanes);
821
+ let filledLanes = 0;
822
+ for (let m = 0; m < min; m++) {
823
+ const item = measurements[m];
824
+ if (item) {
825
+ if (laneLastIndex[item.lane] === void 0) filledLanes++;
826
+ laneLastIndex[item.lane] = m;
827
+ laneEnds[item.lane] = item.end;
828
+ }
829
+ }
830
+ for (let i = min; i < count; i++) {
831
+ const key = getItemKey(i);
832
+ const cachedLane = this.laneAssignments.get(i);
833
+ let lane;
834
+ let start;
835
+ const shouldCacheLane = laneAssignmentMode === "estimate" || itemSizeCache.has(key);
836
+ if (cachedLane !== void 0 && this.options.lanes > 1) {
837
+ lane = cachedLane;
838
+ const prevIndex = laneLastIndex[lane];
839
+ const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
840
+ start = prevInLane ? prevInLane.end + gap : paddingStart + scrollMargin;
841
+ } else if (filledLanes === lanes) {
842
+ let bestLane = 0;
843
+ let bestEnd = laneEnds[0];
844
+ let bestIdx = laneLastIndex[0];
845
+ for (let l = 1; l < lanes; l++) {
846
+ const e = laneEnds[l];
847
+ if (e < bestEnd || e === bestEnd && laneLastIndex[l] < bestIdx) {
848
+ bestLane = l;
849
+ bestEnd = e;
850
+ bestIdx = laneLastIndex[l];
851
+ }
852
+ }
853
+ lane = bestLane;
854
+ start = bestEnd + gap;
855
+ if (shouldCacheLane) {
856
+ this.laneAssignments.set(i, lane);
857
+ }
858
+ } else {
859
+ lane = i % this.options.lanes;
860
+ start = paddingStart + scrollMargin;
861
+ if (shouldCacheLane) {
862
+ this.laneAssignments.set(i, lane);
863
+ }
864
+ }
865
+ const measuredSize = itemSizeCache.get(key);
866
+ const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
867
+ const end = start + size;
868
+ measurements[i] = {
869
+ index: i,
870
+ start,
871
+ size,
872
+ end,
873
+ key,
874
+ lane
875
+ };
876
+ if (laneLastIndex[lane] === void 0) filledLanes++;
877
+ laneLastIndex[lane] = i;
878
+ laneEnds[lane] = end;
879
+ }
880
+ this.measurementsCache = measurements;
881
+ return measurements;
882
+ },
883
+ {
884
+ key: process.env.NODE_ENV !== "production" && "getMeasurements",
885
+ debug: () => this.options.debug
886
+ }
887
+ );
888
+ this.calculateRange = utils.memo(
889
+ () => [
890
+ this.getMeasurements(),
891
+ this.getSize(),
892
+ this.getScrollOffset(),
893
+ this.options.lanes,
894
+ // scrollOffset is measured in the scroll element and the layout total
895
+ // from the list start, so the list ends scrollMargin further down.
896
+ this._getLayoutTotalSize() + this.options.scrollMargin
897
+ ],
898
+ (measurements, outerSize, scrollOffset, lanes, listEnd) => {
899
+ if (measurements.length === 0 || outerSize === 0) {
900
+ this.range = null;
901
+ return null;
902
+ }
903
+ const maxScrollOffset = Math.max(listEnd - outerSize, 0);
904
+ this.range = calculateRangeImpl(
905
+ measurements,
906
+ outerSize,
907
+ Math.min(scrollOffset, maxScrollOffset),
908
+ lanes,
909
+ // Pass the typed array so binary search + forward-walk can read
910
+ // start/end directly from Float64Array, skipping the Proxy traps.
911
+ lanes === 1 && this._singleLaneMeasurements !== null ? this._singleLaneMeasurements.flat : null
912
+ );
913
+ return this.range;
914
+ },
915
+ {
916
+ key: process.env.NODE_ENV !== "production" && "calculateRange",
917
+ debug: () => this.options.debug
918
+ }
919
+ );
920
+ this.getVirtualIndexes = utils.memo(
921
+ () => {
922
+ let startIndex = null;
923
+ let endIndex = null;
924
+ const range = this.calculateRange();
925
+ if (range) {
926
+ startIndex = range.startIndex;
927
+ endIndex = range.endIndex;
928
+ }
929
+ this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex]);
930
+ return [
931
+ this.options.rangeExtractor,
932
+ this.options.overscan,
933
+ this.options.count,
934
+ startIndex,
935
+ endIndex,
936
+ this.options.lanes
937
+ ];
938
+ },
939
+ (rangeExtractor, overscan, count, startIndex, endIndex, lanes) => {
940
+ return startIndex === null || endIndex === null ? [] : rangeExtractor({
941
+ startIndex,
942
+ endIndex,
943
+ overscan,
944
+ count,
945
+ lanes
946
+ });
947
+ },
948
+ {
949
+ key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
950
+ debug: () => this.options.debug
951
+ }
952
+ );
953
+ this.indexFromElement = (node) => {
954
+ const attributeName = this.options.indexAttribute;
955
+ const indexStr = node.getAttribute(attributeName);
956
+ if (!indexStr) {
957
+ console.warn(
958
+ `Missing attribute name '${attributeName}={index}' on measured element.`
959
+ );
960
+ return -1;
961
+ }
962
+ return parseInt(indexStr, 10);
963
+ };
964
+ this.shouldMeasureDuringScroll = (index) => {
965
+ var _a;
966
+ if (!isSmoothScroll(this.scrollState)) {
967
+ return true;
968
+ }
969
+ const scrollIndex = this.scrollState.index ?? ((_a = this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)) == null ? void 0 : _a.index);
970
+ if (scrollIndex !== void 0 && this.range) {
971
+ const bufferSize = Math.max(
972
+ this.options.overscan,
973
+ Math.ceil((this.range.endIndex - this.range.startIndex) / 2)
974
+ );
975
+ const minIndex = Math.max(0, scrollIndex - bufferSize);
976
+ const maxIndex = Math.min(
977
+ this.options.count - 1,
978
+ scrollIndex + bufferSize
979
+ );
980
+ return index >= minIndex && index <= maxIndex;
981
+ }
982
+ return true;
983
+ };
984
+ this.measureElement = (node) => {
985
+ if (!node) {
986
+ this.elementsCache.forEach((cached, key2) => {
987
+ if (!cached.isConnected) {
988
+ this.observer.unobserve(cached);
989
+ this.elementsCache.delete(key2);
990
+ }
991
+ });
992
+ return;
993
+ }
994
+ const index = this.indexFromElement(node);
995
+ if (!this.isIndexInRange(index)) return;
996
+ const key = this.options.getItemKey(index);
997
+ const prevNode = this.elementsCache.get(key);
998
+ if (prevNode !== node) {
999
+ if (prevNode) {
1000
+ this.observer.unobserve(prevNode);
1001
+ }
1002
+ this.observer.observe(node);
1003
+ this.elementsCache.set(key, node);
1004
+ }
1005
+ if (node.isConnected && (!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
1006
+ this.resizeItem(index, this.options.measureElement(node, void 0, this));
1007
+ }
1008
+ };
1009
+ this.resizeItem = (index, size) => {
1010
+ var _a, _b, _c;
1011
+ if (!this.isIndexInRange(index)) return;
1012
+ if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
1013
+ let cachedSize;
1014
+ let itemStart;
1015
+ let key;
1016
+ const flat = (_b = this._singleLaneMeasurements) == null ? void 0 : _b.flat;
1017
+ if (this.options.lanes === 1 && flat != null) {
1018
+ key = this.options.getItemKey(index);
1019
+ itemStart = flat[index * 2];
1020
+ cachedSize = flat[index * 2 + 1];
1021
+ } else {
1022
+ const item = this.measurementsCache[index];
1023
+ if (!item) return;
1024
+ key = item.key;
1025
+ itemStart = item.start;
1026
+ cachedSize = item.size;
1027
+ }
1028
+ const itemSize = this.itemSizeCache.get(key) ?? cachedSize;
1029
+ const delta = size - itemSize;
1030
+ if (delta !== 0) {
1031
+ const wasAtEnd = this.options.anchorTo === "end" && !isSmoothScroll(this.scrollState) && this.getVirtualDistanceFromEnd() <= this.options.scrollEndThreshold;
1032
+ const prevTotalSize = wasAtEnd ? this._getLayoutTotalSize() : 0;
1033
+ const scrollOffset = this.getScrollOffset();
1034
+ const isFirstMeasure = !this.itemSizeCache.has(key);
1035
+ const defaultShouldAdjust = isFirstMeasure ? (
1036
+ // First measurement: compensate any item whose top sits above the
1037
+ // fold — the estimate→actual delta must be corrected regardless of
1038
+ // scroll direction, since the whole estimated block was above it.
1039
+ itemStart < scrollOffset
1040
+ ) : (
1041
+ // Re-measurement: only compensate an item that is ENTIRELY above the
1042
+ // fold. An item that merely *spans* the fold (top above, bottom
1043
+ // below — e.g. a streaming chat message growing at its bottom)
1044
+ // changes size *below* the anchor point, so shifting scrollTop by the
1045
+ // delta would drag the viewport downward on every growth (#1218).
1046
+ // Also skip during backward scroll to avoid the "items jump while
1047
+ // scrolling up" cascade.
1048
+ itemStart + itemSize <= scrollOffset && this.scrollDirection !== "backward"
1049
+ );
1050
+ const shouldAdjustScroll = !isSmoothScroll(this.scrollState) && (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(
1051
+ // The callback expects a VirtualItem; build one lazily only
1052
+ // when the consumer actually supplied a custom predicate.
1053
+ this.measurementsCache[index] ?? {
1054
+ index,
1055
+ key,
1056
+ start: itemStart,
1057
+ size: cachedSize,
1058
+ end: itemStart + cachedSize,
1059
+ lane: 0
1060
+ },
1061
+ delta,
1062
+ this
1063
+ ) : defaultShouldAdjust);
1064
+ if (this.pendingMin === null || index < this.pendingMin) {
1065
+ this.pendingMin = index;
1066
+ }
1067
+ this.itemSizeCache.set(key, size);
1068
+ this.itemSizeCacheVersion++;
1069
+ let adjustedSync = false;
1070
+ if (!this._awaitingCommandReadBack()) {
1071
+ if (wasAtEnd) {
1072
+ adjustedSync = this.applyScrollAdjustment(
1073
+ this._getLayoutTotalSize() - prevTotalSize
1074
+ );
1075
+ } else if (shouldAdjustScroll) {
1076
+ adjustedSync = this.applyScrollAdjustment(delta);
1077
+ }
1078
+ }
1079
+ if (this._resizeBatch) {
1080
+ this._resizeBatch.notify = true;
1081
+ (_c = this._resizeBatch).sync || (_c.sync = adjustedSync);
1082
+ return;
1083
+ }
1084
+ this.notify(adjustedSync);
1085
+ this._noteClampMax();
1086
+ this._flushHoldIfReady(true);
1087
+ this._retryClampedAdjustment();
1088
+ }
1089
+ };
1090
+ this.getVirtualItems = utils.memo(
1091
+ () => [this.getVirtualIndexes(), this.getMeasurements(), this._holdOffset],
1092
+ (indexes, measurements, hold) => {
1093
+ const virtualItems = [];
1094
+ for (let k = 0, len = indexes.length; k < len; k++) {
1095
+ const i = indexes[k];
1096
+ const measurement = measurements[i];
1097
+ virtualItems.push(
1098
+ hold === 0 ? measurement : {
1099
+ ...measurement,
1100
+ start: measurement.start - hold,
1101
+ end: measurement.end - hold
1102
+ }
1103
+ );
1104
+ }
1105
+ return virtualItems;
1106
+ },
1107
+ {
1108
+ key: process.env.NODE_ENV !== "production" && "getVirtualItems",
1109
+ debug: () => this.options.debug
1110
+ }
1111
+ );
1112
+ this.getVirtualItemForOffset = (offset) => {
1113
+ var _a;
1114
+ const measurements = this.getMeasurements();
1115
+ if (measurements.length === 0) {
1116
+ return void 0;
1117
+ }
1118
+ const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
1119
+ const useFlat = this.options.lanes === 1 && flat != null;
1120
+ const idx = findNearestBinarySearch(
1121
+ 0,
1122
+ measurements.length - 1,
1123
+ useFlat ? (i) => flat[i * 2] : (i) => utils.notUndefined(measurements[i]).start,
1124
+ offset
1125
+ );
1126
+ return utils.notUndefined(measurements[idx]);
1127
+ };
1128
+ this._noteClampMax = () => {
1129
+ if (!this._awaitingCommandReadBack()) return;
1130
+ const elementMax = this._elementMaxScrollOffset();
1131
+ if (elementMax === null) return;
1132
+ const write = this.pendingWrite;
1133
+ const max = Math.max(elementMax, 0) + this._holdOffset;
1134
+ if (max >= write.target) return;
1135
+ const lowMaxes = write.lowMaxes ?? (write.lowMaxes = []);
1136
+ if (lowMaxes[lowMaxes.length - 1] !== max) lowMaxes.push(max);
1137
+ };
1138
+ this.getMaxScrollOffset = () => (this._elementMaxScrollOffset() ?? 0) + this._holdOffset;
1139
+ this._toLayoutOffset = (elementOffset) => {
1140
+ var _a;
1141
+ let offset = elementOffset + this._holdOffset;
1142
+ if (((_a = this.pendingScrollAnchor) == null ? void 0 : _a.kind) === "anchor") {
1143
+ offset += this.pendingScrollAnchor.delta;
1144
+ }
1145
+ return offset;
1146
+ };
1147
+ this._elementMaxScrollOffset = () => {
1148
+ const el = this.scrollElement;
1149
+ if (el === null) return null;
1150
+ if ("scrollHeight" in el) {
1151
+ return this.options.horizontal ? el.scrollWidth - el.clientWidth : el.scrollHeight - el.clientHeight;
1152
+ }
1153
+ if ("document" in el) {
1154
+ const doc = el.document.documentElement;
1155
+ return this.options.horizontal ? doc.scrollWidth - el.innerWidth : doc.scrollHeight - el.innerHeight;
1156
+ }
1157
+ return null;
1158
+ };
1159
+ this._momentumStop = null;
1160
+ this._stopMomentum = (done) => {
1161
+ const el = this.scrollElement;
1162
+ const win = this.targetWindow;
1163
+ if (el === null || win === null) return;
1164
+ const scroller = "document" in el ? el.document.scrollingElement : el;
1165
+ if (!(scroller == null ? void 0 : scroller.style)) return;
1166
+ if (this._momentumStop) {
1167
+ this._momentumStop.done = done;
1168
+ return;
1169
+ }
1170
+ const { style } = scroller;
1171
+ const property = this.options.horizontal ? "overflow-x" : "overflow-y";
1172
+ const value = style.getPropertyValue(property);
1173
+ const priority = style.getPropertyPriority(property);
1174
+ const crossSize = () => this.options.horizontal ? scroller.clientHeight : scroller.clientWidth;
1175
+ const crossSizeBefore = crossSize();
1176
+ style.setProperty(property, "hidden", "important");
1177
+ if (crossSize() !== crossSizeBefore) {
1178
+ style.setProperty(property, value, priority);
1179
+ return;
1180
+ }
1181
+ const stop = {
1182
+ // False when the app replaced the hidden value: the fling may not
1183
+ // have stopped.
1184
+ restore: () => {
1185
+ if (style.getPropertyValue(property) !== "hidden" || style.getPropertyPriority(property) !== "important") {
1186
+ return false;
1187
+ }
1188
+ style.setProperty(property, value, priority);
1189
+ return true;
1190
+ },
1191
+ done
1192
+ };
1193
+ this._momentumStop = stop;
1194
+ win.requestAnimationFrame(
1195
+ () => win.requestAnimationFrame(() => {
1196
+ if (this._momentumStop !== stop) return;
1197
+ this._momentumStop = null;
1198
+ if (stop.restore()) stop.done();
1199
+ })
1200
+ );
1201
+ };
1202
+ this._clampedBy = (target) => {
1203
+ const elementMax = this._elementMaxScrollOffset();
1204
+ if (elementMax === null) return null;
1205
+ const maxAtWrite = elementMax + this._holdOffset;
1206
+ return target > maxAtWrite + 0.5 ? { target, maxAtWrite } : null;
1207
+ };
1208
+ this.getVirtualDistanceFromEnd = () => {
1209
+ return Math.max(
1210
+ this._getLayoutTotalSize() + this.options.scrollMargin - this.getSize() - this.getScrollOffset(),
1211
+ 0
1212
+ );
1213
+ };
1214
+ this.getDistanceFromEnd = () => {
1215
+ return Math.max(this.getMaxScrollOffset() - this.getScrollOffset(), 0);
1216
+ };
1217
+ this.isAtEnd = (threshold = this.options.scrollEndThreshold) => {
1218
+ return this.getDistanceFromEnd() <= threshold;
1219
+ };
1220
+ this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
1221
+ if (!this.scrollElement) return 0;
1222
+ const size = this.getSize();
1223
+ const scrollOffset = this.getScrollOffset();
1224
+ if (align === "auto") {
1225
+ align = toOffset >= scrollOffset + size ? "end" : "start";
1226
+ }
1227
+ if (align === "center") {
1228
+ toOffset += (itemSize - size) / 2;
1229
+ } else if (align === "end") {
1230
+ toOffset -= size;
1231
+ }
1232
+ const maxOffset = this.getMaxScrollOffset();
1233
+ return Math.max(Math.min(maxOffset, toOffset), 0);
1234
+ };
1235
+ this.getOffsetForIndex = (index, align = "auto") => {
1236
+ index = Math.max(0, Math.min(index, this.options.count - 1));
1237
+ const size = this.getSize();
1238
+ const scrollOffset = this.getScrollOffset();
1239
+ const item = this.measurementsCache[index];
1240
+ if (!item) return;
1241
+ if (align === "auto") {
1242
+ if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) {
1243
+ align = "end";
1244
+ } else if (item.start <= scrollOffset + this.options.scrollPaddingStart) {
1245
+ align = "start";
1246
+ } else {
1247
+ return [scrollOffset, align];
1248
+ }
1249
+ }
1250
+ if (align === "end" && index === this.options.count - 1) {
1251
+ const maxOffset = this.getMaxScrollOffset();
1252
+ const toOffset2 = maxOffset - this.options.paddingEnd + this.options.scrollPaddingEnd;
1253
+ return [Math.max(Math.min(toOffset2, maxOffset), 0), align];
1254
+ }
1255
+ const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
1256
+ return [
1257
+ this.getOffsetForAlignment(toOffset, align, item.size),
1258
+ align
1259
+ ];
1260
+ };
1261
+ this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
1262
+ this._startScroll(
1263
+ { index: null, align },
1264
+ this.getOffsetForAlignment(toOffset, align),
1265
+ behavior,
1266
+ "absolute"
1267
+ );
1268
+ };
1269
+ this.scrollToIndex = (index, {
1270
+ align: initialAlign = "auto",
1271
+ behavior = "auto"
1272
+ } = {}) => {
1273
+ index = Math.max(0, Math.min(index, this.options.count - 1));
1274
+ const offsetInfo = this.getOffsetForIndex(index, initialAlign);
1275
+ if (!offsetInfo) return;
1276
+ const [offset, align] = offsetInfo;
1277
+ this._startScroll({ index, align }, offset, behavior, "absolute");
1278
+ };
1279
+ this.scrollBy = (delta, { behavior = "auto" } = {}) => {
1280
+ const offset = this.getOffsetForAlignment(
1281
+ (this.getCommandWrittenOffset() ?? this.getScrollOffset()) + delta,
1282
+ "start"
1283
+ );
1284
+ this._startScroll(
1285
+ { index: null, align: "start" },
1286
+ offset,
1287
+ behavior,
1288
+ "relative"
1289
+ );
1290
+ };
1291
+ this.scrollToEnd = ({ behavior = "auto" } = {}) => {
1292
+ if (this.options.count > 0) {
1293
+ this._startScroll(
1294
+ { index: this.options.count - 1, align: "end", toEnd: true },
1295
+ Math.max(this.getMaxScrollOffset(), 0),
1296
+ behavior,
1297
+ "absolute"
1298
+ );
1299
+ return;
1300
+ }
1301
+ this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
1302
+ behavior
1303
+ });
1304
+ };
1305
+ this.cancelScroll = () => {
1306
+ if (this.rafId != null && this.targetWindow) {
1307
+ this.targetWindow.cancelAnimationFrame(this.rafId);
1308
+ this.rafId = null;
1309
+ }
1310
+ this.scrollState = null;
1311
+ };
1312
+ this.getTotalSize = () => Math.max(this._getLayoutTotalSize() - this._holdOffset, 0);
1313
+ this._getLayoutTotalSize = () => {
1314
+ var _a, _b;
1315
+ const measurements = this.getMeasurements();
1316
+ let end;
1317
+ if (measurements.length === 0) {
1318
+ end = this.options.paddingStart;
1319
+ } else if (this.options.lanes === 1) {
1320
+ const lastIdx = measurements.length - 1;
1321
+ const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
1322
+ if (flat != null) {
1323
+ end = flat[lastIdx * 2] + flat[lastIdx * 2 + 1];
1324
+ } else {
1325
+ end = ((_b = measurements[lastIdx]) == null ? void 0 : _b.end) ?? 0;
1326
+ }
1327
+ } else {
1328
+ const endByLane = Array(this.options.lanes).fill(null);
1329
+ let endIndex = measurements.length - 1;
1330
+ while (endIndex >= 0 && endByLane.some((val) => val === null)) {
1331
+ const item = measurements[endIndex];
1332
+ if (endByLane[item.lane] === null) {
1333
+ endByLane[item.lane] = item.end;
1334
+ }
1335
+ endIndex--;
1336
+ }
1337
+ end = Math.max(...endByLane.filter((val) => val !== null));
1338
+ }
1339
+ return Math.max(
1340
+ end - this.options.scrollMargin + this.options.paddingEnd,
1341
+ 0
1342
+ );
1343
+ };
1344
+ this.takeSnapshot = () => {
1345
+ const snapshot = [];
1346
+ if (this.itemSizeCache.size === 0) return snapshot;
1347
+ const m = this.getMeasurements();
1348
+ for (const item of m) {
1349
+ if (item && this.itemSizeCache.has(item.key)) {
1350
+ snapshot.push({
1351
+ index: item.index,
1352
+ key: item.key,
1353
+ start: item.start,
1354
+ size: item.size,
1355
+ end: item.end,
1356
+ lane: item.lane
1357
+ });
1358
+ }
1359
+ }
1360
+ return snapshot;
1361
+ };
1362
+ this._scrollToOffset = (offset, {
1363
+ adjustments,
1364
+ behavior
1365
+ } = {}) => {
1366
+ const write = {
1367
+ target: offset + (adjustments ?? 0),
1368
+ smooth: behavior === "smooth"
1369
+ };
1370
+ this.pendingWrite = write;
1371
+ this.options.scrollToFn(
1372
+ offset - this._holdOffset,
1373
+ { behavior, adjustments },
1374
+ this
1375
+ );
1376
+ return write;
1377
+ };
1378
+ this.getCommandWrittenOffset = () => this.scrollState !== null && this.pendingWrite !== null && !this.pendingWrite.smooth ? this.pendingWrite.target : null;
1379
+ this._awaitingCommandReadBack = () => {
1380
+ const writtenOffset = this.getCommandWrittenOffset();
1381
+ return !(iosGesture.isIOSWebKit() && this._iosGesture.dragging()) && writtenOffset !== null && !utils.approxEqual(writtenOffset, this.getScrollOffset());
1382
+ };
1383
+ this._followOffsetTarget = (delta) => {
1384
+ if (this.scrollState !== null && this.scrollState.index == null) {
1385
+ this.scrollState.lastTargetOffset += delta;
1386
+ }
1387
+ };
1388
+ this.measure = () => {
1389
+ this.pendingMin = null;
1390
+ this.itemSizeCache.clear();
1391
+ this.laneAssignments.clear();
1392
+ this.itemSizeCacheVersion++;
1393
+ this.notify(false);
1394
+ };
1395
+ this.setOptions(opts);
1396
+ }
1397
+ /**
1398
+ * @deprecated Always 0: a scroll correction is folded into `scrollOffset`
1399
+ * at once, so there is never an outstanding adjustment to add to it. Read
1400
+ * `scrollOffset` alone.
1401
+ */
1402
+ get scrollAdjustments() {
1403
+ return 0;
1404
+ }
1405
+ // Returns `true` when it performed a synchronous `scrollTop` write this
1406
+ // tick, `false` when the delta was zero or the write was deferred (iOS).
1407
+ // `resizeItem` uses that to decide whether the follow-up `notify` must be
1408
+ // synchronous so the grown transforms commit in the same paint (#1227).
1409
+ applyScrollAdjustment(delta, behavior) {
1410
+ if (delta === 0) return false;
1411
+ if (process.env.NODE_ENV !== "production" && this.options.debug) {
1412
+ console.info("correction", delta);
1413
+ }
1414
+ this._followOffsetTarget(delta);
1415
+ if (!this._canWriteScroll()) {
1416
+ this._holdOffset += delta;
1417
+ if (this.scrollOffset !== null) this.scrollOffset += delta;
1418
+ return true;
1419
+ } else {
1420
+ const offset = this.getScrollOffset();
1421
+ this._clampedAdjustment = this._clampedBy(offset + delta);
1422
+ const write = this._scrollToOffset(offset, {
1423
+ adjustments: delta,
1424
+ behavior
1425
+ });
1426
+ if (this.scrollOffset !== null) {
1427
+ if (this.pendingWrite === write) this.scrollOffset += delta;
1428
+ if (this.scrollOffset < 0) this.scrollOffset = 0;
1429
+ }
1430
+ return true;
1431
+ }
1432
+ }
1433
+ scheduleScrollReconcile() {
1434
+ if (!this.targetWindow) {
1435
+ this.scrollState = null;
1436
+ return;
1437
+ }
1438
+ if (this.rafId != null) return;
1439
+ this.rafId = this.targetWindow.requestAnimationFrame(() => {
1440
+ this.rafId = null;
1441
+ this.reconcileScroll();
1442
+ });
1443
+ }
1444
+ getScrollStateTarget(state) {
1445
+ const offsetInfo = state.toEnd ? [Math.max(this.getMaxScrollOffset(), 0)] : state.index != null ? this.getOffsetForIndex(state.index, state.align) : void 0;
1446
+ return offsetInfo ? offsetInfo[0] : state.lastTargetOffset;
1447
+ }
1448
+ reconcileScroll() {
1449
+ if (!this.scrollState) return;
1450
+ const el = this.scrollElement;
1451
+ if (!el) return;
1452
+ const MAX_RECONCILE_MS = 5e3;
1453
+ if (this.now() - this.scrollState.startedAt > MAX_RECONCILE_MS) {
1454
+ this.scrollState = null;
1455
+ return;
1456
+ }
1457
+ if (this.scrollState.phase === "queued") {
1458
+ this.scheduleScrollReconcile();
1459
+ return;
1460
+ }
1461
+ this.getMeasurements();
1462
+ const targetOffset = this.getScrollStateTarget(this.scrollState);
1463
+ const STABLE_FRAMES = this.scrollState.index == null ? 1 : this.options.useAnimationFrameWithResizeObserver ? 3 : 2;
1464
+ const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
1465
+ if (!targetChanged && utils.approxEqual(targetOffset, this.getScrollOffset())) {
1466
+ if (this.scrollState.phase === "smooth") {
1467
+ this.scrollState.phase = "smoothLanded";
1468
+ } else if (this.scrollState.phase === "smoothFinishing") {
1469
+ this.scrollState.phase = "instant";
1470
+ }
1471
+ this.scrollState.stableFrames++;
1472
+ if (this.scrollState.stableFrames >= STABLE_FRAMES) {
1473
+ if (this.getScrollOffset() !== targetOffset) {
1474
+ this._scrollToOffset(targetOffset, { behavior: "auto" });
1475
+ }
1476
+ this.scrollState = null;
1477
+ return;
1478
+ }
1479
+ } else {
1480
+ this.scrollState.stableFrames = 0;
1481
+ if (targetChanged) {
1482
+ const viewport = this.getSize() || 600;
1483
+ const distance = Math.abs(targetOffset - this.getScrollOffset());
1484
+ const keepSmooth = isSmoothScroll(this.scrollState) && distance > viewport;
1485
+ this.scrollState.lastTargetOffset = targetOffset;
1486
+ if (keepSmooth) {
1487
+ this.scrollState.phase = "smooth";
1488
+ } else if (this.scrollState.phase === "smooth") {
1489
+ this.scrollState.phase = "smoothFinishing";
1490
+ } else if (this.scrollState.phase === "smoothLanded") {
1491
+ this.scrollState.phase = "instant";
1492
+ }
1493
+ this._scrollToOffset(targetOffset, {
1494
+ behavior: keepSmooth ? "smooth" : "auto"
1495
+ });
1496
+ }
1497
+ }
1498
+ this.scheduleScrollReconcile();
1499
+ }
1500
+ // Every scroll command starts here: it becomes the in-flight command,
1501
+ // writes its first target and leaves reconcile to retarget and retire it.
1502
+ //
1503
+ // Targets are layout offsets. A held correction is not dropped by a
1504
+ // command: the write lands the element `_holdOffset` short of the target,
1505
+ // under the rows exposed shifted by the same amount, and the flush moves
1506
+ // both together once a write is possible.
1507
+ //
1508
+ // An index or end target that is already at its offset starts a smooth
1509
+ // scroll as landed; an offset target never does, so its first scroll
1510
+ // event is read as the user's (see the scroll handler in `_willUpdate`).
1511
+ _startScroll(target, offset, behavior, kind) {
1512
+ this.pendingScrollAnchor = null;
1513
+ this._clampedAdjustment = null;
1514
+ const tail = this._iosGesture.tail();
1515
+ if (kind === "absolute" && tail !== null) {
1516
+ if (tail === "fling" && iosGesture.momentumOverridesWrites()) {
1517
+ this._stopMomentum(() => {
1518
+ const state = this.scrollState;
1519
+ if ((state == null ? void 0 : state.phase) !== "queued" || // A finger came down: it owns the scroll until it lifts.
1520
+ this._iosGesture.tail() !== "fling" || // In a bounce WebKit can drop the write (#1287): the tail
1521
+ // decides, as without the stop. (Not `flingCaught`: our stop
1522
+ // also ends the fling at speed, so a slow frame would read as
1523
+ // a catch and the tail would drop the command.)
1524
+ this._reportedOverscroll) {
1525
+ return;
1526
+ }
1527
+ this._iosGesture.end();
1528
+ this._flushHoldIfReady(true);
1529
+ this._writeAwaitingCommand();
1530
+ });
1531
+ this.scrollState = {
1532
+ ...target,
1533
+ startedAt: this.now(),
1534
+ lastTargetOffset: offset,
1535
+ stableFrames: 0,
1536
+ phase: "queued",
1537
+ behavior,
1538
+ samples: []
1539
+ };
1540
+ this.scheduleScrollReconcile();
1541
+ return;
1542
+ }
1543
+ this._iosGesture.end();
1544
+ }
1545
+ this.scrollState = {
1546
+ ...target,
1547
+ startedAt: this.now(),
1548
+ lastTargetOffset: offset,
1549
+ stableFrames: 0,
1550
+ behavior,
1551
+ phase: initialScrollPhase(
1552
+ behavior,
1553
+ target.index != null && utils.approxEqual(offset, this.getScrollOffset())
1554
+ )
1555
+ };
1556
+ this._scrollToOffset(offset, { behavior });
1557
+ this.scheduleScrollReconcile();
1558
+ }
1559
+ }
1560
+ const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
1561
+ while (low <= high) {
1562
+ const middle = (low + high) / 2 | 0;
1563
+ const currentValue = getCurrentValue(middle);
1564
+ if (currentValue < value) {
1565
+ low = middle + 1;
1566
+ } else if (currentValue > value) {
1567
+ high = middle - 1;
1568
+ } else {
1569
+ return middle;
1570
+ }
1571
+ }
1572
+ if (low > 0) {
1573
+ return low - 1;
1574
+ } else {
1575
+ return 0;
1576
+ }
1577
+ };
1578
+ function findNearestBinarySearchFlat(flat, high, value) {
1579
+ let low = 0;
1580
+ while (low <= high) {
1581
+ const middle = (low + high) / 2 | 0;
1582
+ const currentValue = flat[middle * 2];
1583
+ if (currentValue < value) {
1584
+ low = middle + 1;
1585
+ } else if (currentValue > value) {
1586
+ high = middle - 1;
1587
+ } else {
1588
+ return middle;
1589
+ }
1590
+ }
1591
+ return low > 0 ? low - 1 : 0;
1592
+ }
1593
+ function calculateRangeImpl(measurements, outerSize, scrollOffset, lanes, flat) {
1594
+ const lastIndex = measurements.length - 1;
1595
+ if (measurements.length <= lanes) {
1596
+ return { startIndex: 0, endIndex: lastIndex };
1597
+ }
1598
+ if (lanes === 1 && flat !== null) {
1599
+ const startIndex2 = findNearestBinarySearchFlat(
1600
+ flat,
1601
+ lastIndex,
1602
+ scrollOffset
1603
+ );
1604
+ let endIndex2 = startIndex2;
1605
+ const limit = scrollOffset + outerSize;
1606
+ while (endIndex2 < lastIndex && flat[endIndex2 * 2] + flat[endIndex2 * 2 + 1] < limit) {
1607
+ endIndex2++;
1608
+ }
1609
+ return { startIndex: startIndex2, endIndex: endIndex2 };
1610
+ }
1611
+ const getStart = (index) => measurements[index].start;
1612
+ let startIndex = findNearestBinarySearch(0, lastIndex, getStart, scrollOffset);
1613
+ let endIndex = startIndex;
1614
+ if (lanes === 1) {
1615
+ while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) {
1616
+ endIndex++;
1617
+ }
1618
+ } else if (lanes > 1) {
1619
+ const endPerLane = Array(lanes).fill(0);
1620
+ while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
1621
+ const item = measurements[endIndex];
1622
+ endPerLane[item.lane] = item.end;
1623
+ endIndex++;
1624
+ }
1625
+ const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
1626
+ while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
1627
+ const item = measurements[startIndex];
1628
+ startPerLane[item.lane] = item.start;
1629
+ startIndex--;
1630
+ }
1631
+ startIndex = Math.max(0, startIndex - startIndex % lanes);
1632
+ endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
1633
+ }
1634
+ return { startIndex, endIndex };
1635
+ }
1636
+
1637
+ exports.approxEqual = utils.approxEqual;
1638
+ exports.debounce = utils.debounce;
1639
+ exports.memo = utils.memo;
1640
+ exports.notUndefined = utils.notUndefined;
1641
+ exports.Virtualizer = Virtualizer;
1642
+ exports.defaultKeyExtractor = defaultKeyExtractor;
1643
+ exports.defaultRangeExtractor = defaultRangeExtractor;
1644
+ exports.elementScroll = elementScroll;
1645
+ exports.measureElement = measureElement;
1646
+ exports.observeElementOffset = observeElementOffset;
1647
+ exports.observeElementRect = observeElementRect;
1648
+ //# sourceMappingURL=index.js.map