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