@tanstack/react-virtual 3.0.0-beta.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,10 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactVirtual = {}, global.React));
15
- })(this, (function (exports, React) { 'use strict';
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactVirtual = {}, global.React, global.ReactDOM));
15
+ })(this, (function (exports, React, reactDom) { 'use strict';
16
16
 
17
17
  function _interopNamespace(e) {
18
18
  if (e && e.__esModule) return e;
@@ -34,6 +34,21 @@
34
34
 
35
35
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
36
 
37
+ function _extends$1() {
38
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
39
+ for (var i = 1; i < arguments.length; i++) {
40
+ var source = arguments[i];
41
+ for (var key in source) {
42
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
43
+ target[key] = source[key];
44
+ }
45
+ }
46
+ }
47
+ return target;
48
+ };
49
+ return _extends$1.apply(this, arguments);
50
+ }
51
+
37
52
  /**
38
53
  * virtual-core
39
54
  *
@@ -44,515 +59,678 @@
44
59
  *
45
60
  * @license MIT
46
61
  */
47
- var props = ["bottom", "height", "left", "right", "top", "width"];
48
-
49
- var rectChanged = function rectChanged(a, b) {
50
- if (a === void 0) {
51
- a = {};
52
- }
53
-
54
- if (b === void 0) {
55
- b = {};
56
- }
57
-
58
- return props.some(function (prop) {
59
- return a[prop] !== b[prop];
60
- });
61
- };
62
-
63
- var observedNodes = /*#__PURE__*/new Map();
64
- var rafId;
65
-
66
- var run = function run() {
67
- var changedStates = [];
68
- observedNodes.forEach(function (state, node) {
69
- var newRect = node.getBoundingClientRect();
70
-
71
- if (rectChanged(newRect, state.rect)) {
72
- state.rect = newRect;
73
- changedStates.push(state);
74
- }
75
- });
76
- changedStates.forEach(function (state) {
77
- state.callbacks.forEach(function (cb) {
78
- return cb(state.rect);
79
- });
80
- });
81
- rafId = window.requestAnimationFrame(run);
82
- };
83
-
84
- function observeRect(node, cb) {
85
- return {
86
- observe: function observe() {
87
- var wasEmpty = observedNodes.size === 0;
88
-
89
- if (observedNodes.has(node)) {
90
- observedNodes.get(node).callbacks.push(cb);
91
- } else {
92
- observedNodes.set(node, {
93
- rect: undefined,
94
- hasRectChanged: false,
95
- callbacks: [cb]
96
- });
97
- }
98
-
99
- if (wasEmpty) run();
100
- },
101
- unobserve: function unobserve() {
102
- var state = observedNodes.get(node);
103
-
104
- if (state) {
105
- // Remove the callback
106
- var index = state.callbacks.indexOf(cb);
107
- if (index >= 0) state.callbacks.splice(index, 1); // Remove the node reference
108
-
109
- if (!state.callbacks.length) observedNodes["delete"](node); // Stop the loop
110
-
111
- if (!observedNodes.size) cancelAnimationFrame(rafId);
62
+ function _extends() {
63
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
64
+ for (var i = 1; i < arguments.length; i++) {
65
+ var source = arguments[i];
66
+ for (var key in source) {
67
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
68
+ target[key] = source[key];
69
+ }
112
70
  }
113
71
  }
72
+ return target;
114
73
  };
74
+ return _extends.apply(this, arguments);
115
75
  }
116
76
 
77
+ /**
78
+ * virtual-core
79
+ *
80
+ * Copyright (c) TanStack
81
+ *
82
+ * This source code is licensed under the MIT license found in the
83
+ * LICENSE.md file in the root directory of this source tree.
84
+ *
85
+ * @license MIT
86
+ */
117
87
  function memo(getDeps, fn, opts) {
118
- let deps = [];
119
- let result;
120
- return () => {
121
- let depTime;
88
+ var _opts$initialDeps;
89
+ var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
90
+ var result;
91
+ return function () {
92
+ var depTime;
122
93
  if (opts.key && opts.debug != null && opts.debug()) depTime = Date.now();
123
- const newDeps = getDeps();
124
- const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
125
-
94
+ var newDeps = getDeps();
95
+ var depsChanged = newDeps.length !== deps.length || newDeps.some(function (dep, index) {
96
+ return deps[index] !== dep;
97
+ });
126
98
  if (!depsChanged) {
127
99
  return result;
128
100
  }
129
-
130
101
  deps = newDeps;
131
- let resultTime;
102
+ var resultTime;
132
103
  if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
133
- result = fn(...newDeps);
134
- opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
135
-
104
+ result = fn.apply(void 0, newDeps);
136
105
  if (opts.key && opts.debug != null && opts.debug()) {
137
- const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
138
- const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
139
- const resultFpsPercentage = resultEndTime / 16;
140
-
141
- const pad = (str, num) => {
106
+ var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
107
+ var resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
108
+ var resultFpsPercentage = resultEndTime / 16;
109
+ var pad = function pad(str, num) {
142
110
  str = String(str);
143
-
144
111
  while (str.length < num) {
145
112
  str = ' ' + str;
146
113
  }
147
-
148
114
  return str;
149
115
  };
150
-
151
116
  console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
152
117
  }
153
-
118
+ opts == null || opts.onChange == null || opts.onChange(result);
154
119
  return result;
155
120
  };
156
121
  }
122
+ function notUndefined(value, msg) {
123
+ if (value === undefined) {
124
+ throw new Error("Unexpected undefined" + (msg ? ": " + msg : ''));
125
+ } else {
126
+ return value;
127
+ }
128
+ }
129
+ var approxEqual = function approxEqual(a, b) {
130
+ return Math.abs(a - b) < 1;
131
+ };
132
+
133
+ /**
134
+ * virtual-core
135
+ *
136
+ * Copyright (c) TanStack
137
+ *
138
+ * This source code is licensed under the MIT license found in the
139
+ * LICENSE.md file in the root directory of this source tree.
140
+ *
141
+ * @license MIT
142
+ */
157
143
 
158
144
  //
159
- const defaultKeyExtractor = index => index;
160
- const defaultRangeExtractor = range => {
161
- const start = Math.max(range.startIndex - range.overscan, 0);
162
- const end = Math.min(range.endIndex + range.overscan, range.count - 1);
163
- const arr = [];
164
145
 
165
- for (let i = start; i <= end; i++) {
166
- arr.push(i);
167
- }
146
+ //
168
147
 
148
+ var defaultKeyExtractor = function defaultKeyExtractor(index) {
149
+ return index;
150
+ };
151
+ var defaultRangeExtractor = function defaultRangeExtractor(range) {
152
+ var start = Math.max(range.startIndex - range.overscan, 0);
153
+ var end = Math.min(range.endIndex + range.overscan, range.count - 1);
154
+ var arr = [];
155
+ for (var _i = start; _i <= end; _i++) {
156
+ arr.push(_i);
157
+ }
169
158
  return arr;
170
159
  };
171
- const observeElementRect = (instance, cb) => {
172
- const observer = observeRect(instance.scrollElement, rect => {
173
- cb(rect);
174
- });
175
-
176
- if (!instance.scrollElement) {
160
+ var observeElementRect = function observeElementRect(instance, cb) {
161
+ var element = instance.scrollElement;
162
+ if (!element) {
177
163
  return;
178
164
  }
179
-
180
- cb(instance.scrollElement.getBoundingClientRect());
181
- observer.observe();
182
- return () => {
183
- observer.unobserve();
184
- };
185
- };
186
- const observeWindowRect = (instance, cb) => {
187
- const onResize = () => {
165
+ var handler = function handler(rect) {
166
+ var width = rect.width,
167
+ height = rect.height;
188
168
  cb({
189
- width: instance.scrollElement.innerWidth,
190
- height: instance.scrollElement.innerHeight
169
+ width: Math.round(width),
170
+ height: Math.round(height)
191
171
  });
192
172
  };
193
-
194
- if (!instance.scrollElement) {
173
+ handler(element.getBoundingClientRect());
174
+ var observer = new ResizeObserver(function (entries) {
175
+ var entry = entries[0];
176
+ if (entry != null && entry.borderBoxSize) {
177
+ var box = entry.borderBoxSize[0];
178
+ if (box) {
179
+ handler({
180
+ width: box.inlineSize,
181
+ height: box.blockSize
182
+ });
183
+ return;
184
+ }
185
+ }
186
+ handler(element.getBoundingClientRect());
187
+ });
188
+ observer.observe(element, {
189
+ box: 'border-box'
190
+ });
191
+ return function () {
192
+ observer.unobserve(element);
193
+ };
194
+ };
195
+ var observeWindowRect = function observeWindowRect(instance, cb) {
196
+ var element = instance.scrollElement;
197
+ if (!element) {
195
198
  return;
196
199
  }
197
-
198
- onResize();
199
- instance.scrollElement.addEventListener('resize', onResize, {
200
- capture: false,
200
+ var handler = function handler() {
201
+ cb({
202
+ width: element.innerWidth,
203
+ height: element.innerHeight
204
+ });
205
+ };
206
+ handler();
207
+ element.addEventListener('resize', handler, {
201
208
  passive: true
202
209
  });
203
- return () => {
204
- instance.scrollElement.removeEventListener('resize', onResize);
210
+ return function () {
211
+ element.removeEventListener('resize', handler);
205
212
  };
206
213
  };
207
- const observeElementOffset = (instance, cb) => {
208
- const onScroll = () => cb(instance.scrollElement[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']);
209
-
210
- if (!instance.scrollElement) {
214
+ var observeElementOffset = function observeElementOffset(instance, cb) {
215
+ var element = instance.scrollElement;
216
+ if (!element) {
211
217
  return;
212
218
  }
213
-
214
- onScroll();
215
- instance.scrollElement.addEventListener('scroll', onScroll, {
216
- capture: false,
219
+ var handler = function handler() {
220
+ cb(element[instance.options.horizontal ? 'scrollLeft' : 'scrollTop']);
221
+ };
222
+ handler();
223
+ element.addEventListener('scroll', handler, {
217
224
  passive: true
218
225
  });
219
- return () => {
220
- instance.scrollElement.removeEventListener('scroll', onScroll);
226
+ return function () {
227
+ element.removeEventListener('scroll', handler);
221
228
  };
222
229
  };
223
- const observeWindowOffset = (instance, cb) => {
224
- const onScroll = () => cb(instance.scrollElement[instance.options.horizontal ? 'scrollX' : 'scrollY']);
225
-
226
- if (!instance.scrollElement) {
230
+ var observeWindowOffset = function observeWindowOffset(instance, cb) {
231
+ var element = instance.scrollElement;
232
+ if (!element) {
227
233
  return;
228
234
  }
229
-
230
- onScroll();
231
- instance.scrollElement.addEventListener('scroll', onScroll, {
232
- capture: false,
235
+ var handler = function handler() {
236
+ cb(element[instance.options.horizontal ? 'scrollX' : 'scrollY']);
237
+ };
238
+ handler();
239
+ element.addEventListener('scroll', handler, {
233
240
  passive: true
234
241
  });
235
- return () => {
236
- instance.scrollElement.removeEventListener('scroll', onScroll);
242
+ return function () {
243
+ element.removeEventListener('scroll', handler);
237
244
  };
238
245
  };
239
- const measureElement = (element, instance) => {
240
- return element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height'];
246
+ var measureElement = function measureElement(element, entry, instance) {
247
+ if (entry != null && entry.borderBoxSize) {
248
+ var box = entry.borderBoxSize[0];
249
+ if (box) {
250
+ var size = Math.round(box[instance.options.horizontal ? 'inlineSize' : 'blockSize']);
251
+ return size;
252
+ }
253
+ }
254
+ return Math.round(element.getBoundingClientRect()[instance.options.horizontal ? 'width' : 'height']);
241
255
  };
242
- const windowScroll = (offset, canSmooth, instance) => {
243
- var _instance$scrollEleme;
244
- (_instance$scrollEleme = instance.scrollElement) == null ? void 0 : _instance$scrollEleme.scrollTo({
245
- [instance.options.horizontal ? 'left' : 'top']: offset,
246
- behavior: canSmooth ? 'smooth' : undefined
247
- });
256
+ var windowScroll = function windowScroll(offset, _ref, instance) {
257
+ var _instance$scrollEleme, _instance$scrollEleme2;
258
+ var _ref$adjustments = _ref.adjustments,
259
+ adjustments = _ref$adjustments === void 0 ? 0 : _ref$adjustments,
260
+ behavior = _ref.behavior;
261
+ var toOffset = offset + adjustments;
262
+ (_instance$scrollEleme = instance.scrollElement) == null || _instance$scrollEleme.scrollTo == null || _instance$scrollEleme.scrollTo((_instance$scrollEleme2 = {}, _instance$scrollEleme2[instance.options.horizontal ? 'left' : 'top'] = toOffset, _instance$scrollEleme2.behavior = behavior, _instance$scrollEleme2));
248
263
  };
249
- const elementScroll = (offset, canSmooth, instance) => {
250
- var _instance$scrollEleme2;
251
- (_instance$scrollEleme2 = instance.scrollElement) == null ? void 0 : _instance$scrollEleme2.scrollTo({
252
- [instance.options.horizontal ? 'left' : 'top']: offset,
253
- behavior: canSmooth ? 'smooth' : undefined
254
- });
264
+ var elementScroll = function elementScroll(offset, _ref2, instance) {
265
+ var _instance$scrollEleme3, _instance$scrollEleme4;
266
+ var _ref2$adjustments = _ref2.adjustments,
267
+ adjustments = _ref2$adjustments === void 0 ? 0 : _ref2$adjustments,
268
+ behavior = _ref2.behavior;
269
+ var toOffset = offset + adjustments;
270
+ (_instance$scrollEleme3 = instance.scrollElement) == null || _instance$scrollEleme3.scrollTo == null || _instance$scrollEleme3.scrollTo((_instance$scrollEleme4 = {}, _instance$scrollEleme4[instance.options.horizontal ? 'left' : 'top'] = toOffset, _instance$scrollEleme4.behavior = behavior, _instance$scrollEleme4));
255
271
  };
256
- class Virtualizer {
257
- constructor(_opts) {
258
- var _this = this;
259
-
260
- this.unsubs = [];
261
- this.scrollElement = null;
262
- this.measurementsCache = [];
263
- this.itemMeasurementsCache = {};
264
- this.pendingMeasuredCacheIndexes = [];
265
- this.measureElementCache = {};
266
-
267
- this.setOptions = opts => {
268
- Object.entries(opts).forEach(_ref => {
269
- let [key, value] = _ref;
270
- if (typeof value === 'undefined') delete opts[key];
271
- });
272
- this.options = {
273
- debug: false,
274
- initialOffset: 0,
275
- overscan: 1,
276
- paddingStart: 0,
277
- paddingEnd: 0,
278
- scrollPaddingStart: 0,
279
- scrollPaddingEnd: 0,
280
- horizontal: false,
281
- getItemKey: defaultKeyExtractor,
282
- rangeExtractor: defaultRangeExtractor,
283
- enableSmoothScroll: true,
284
- onChange: () => {},
285
- measureElement,
286
- initialRect: {
287
- width: 0,
288
- height: 0
289
- },
290
- ...opts
291
- };
292
- };
293
-
294
- this.notify = () => {
295
- var _this$options$onChang, _this$options;
296
-
297
- (_this$options$onChang = (_this$options = this.options).onChange) == null ? void 0 : _this$options$onChang.call(_this$options, this);
298
- };
299
-
300
- this.cleanup = () => {
301
- this.unsubs.filter(Boolean).forEach(d => d());
302
- this.unsubs = [];
303
- this.scrollElement = null;
304
- };
305
-
306
- this._didMount = () => {
307
- return () => {
308
- this.cleanup();
309
- };
310
- };
311
-
312
- this._willUpdate = () => {
313
- const scrollElement = this.options.getScrollElement();
314
-
315
- if (this.scrollElement !== scrollElement) {
316
- this.cleanup();
317
- this.scrollElement = scrollElement;
318
- this.unsubs.push(this.options.observeElementRect(this, rect => {
319
- this.scrollRect = rect;
320
- this.notify();
321
- }));
322
- this.unsubs.push(this.options.observeElementOffset(this, offset => {
323
- this.scrollOffset = offset;
324
- this.notify();
325
- }));
272
+ var Virtualizer = function Virtualizer(_opts) {
273
+ var _this = this;
274
+ this.unsubs = [];
275
+ this.scrollElement = null;
276
+ this.isScrolling = false;
277
+ this.isScrollingTimeoutId = null;
278
+ this.scrollToIndexTimeoutId = null;
279
+ this.measurementsCache = [];
280
+ this.itemSizeCache = new Map();
281
+ this.pendingMeasuredCacheIndexes = [];
282
+ this.scrollDirection = null;
283
+ this.scrollAdjustments = 0;
284
+ this.measureElementCache = new Map();
285
+ this.observer = function () {
286
+ var _ro = null;
287
+ var get = function get() {
288
+ if (_ro) {
289
+ return _ro;
290
+ } else if (typeof ResizeObserver !== 'undefined') {
291
+ return _ro = new ResizeObserver(function (entries) {
292
+ entries.forEach(function (entry) {
293
+ _this._measureElement(entry.target, entry);
294
+ });
295
+ });
296
+ } else {
297
+ return null;
326
298
  }
327
299
  };
328
-
329
- this.getSize = () => {
330
- return this.scrollRect[this.options.horizontal ? 'width' : 'height'];
331
- };
332
-
333
- this.getMeasurements = memo(() => [this.options.count, this.options.paddingStart, this.options.getItemKey, this.itemMeasurementsCache], (count, paddingStart, getItemKey, measurementsCache) => {
334
- const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
335
- this.pendingMeasuredCacheIndexes = [];
336
- const measurements = this.measurementsCache.slice(0, min);
337
-
338
- for (let i = min; i < count; i++) {
339
- const key = getItemKey(i);
340
- const measuredSize = measurementsCache[key];
341
- const start = measurements[i - 1] ? measurements[i - 1].end : paddingStart;
342
- const size = typeof measuredSize === 'number' ? measuredSize : this.options.estimateSize(i);
343
- const end = start + size;
344
- measurements[i] = {
345
- index: i,
346
- start,
347
- size,
348
- end,
349
- key
350
- };
300
+ return {
301
+ disconnect: function disconnect() {
302
+ var _get;
303
+ return (_get = get()) == null ? void 0 : _get.disconnect();
304
+ },
305
+ observe: function observe(target) {
306
+ var _get2;
307
+ return (_get2 = get()) == null ? void 0 : _get2.observe(target, {
308
+ box: 'border-box'
309
+ });
310
+ },
311
+ unobserve: function unobserve(target) {
312
+ var _get3;
313
+ return (_get3 = get()) == null ? void 0 : _get3.unobserve(target);
351
314
  }
352
-
353
- this.measurementsCache = measurements;
354
- return measurements;
355
- }, {
356
- key: 'getMeasurements',
357
- debug: () => this.options.debug
315
+ };
316
+ }();
317
+ this.range = null;
318
+ this.setOptions = function (opts) {
319
+ Object.entries(opts).forEach(function (_ref3) {
320
+ var key = _ref3[0],
321
+ value = _ref3[1];
322
+ if (typeof value === 'undefined') delete opts[key];
358
323
  });
359
- this.calculateRange = memo(() => [this.getMeasurements(), this.getSize(), this.scrollOffset], (measurements, outerSize, scrollOffset) => {
360
- return calculateRange({
361
- measurements,
362
- outerSize,
363
- scrollOffset
364
- });
365
- }, {
366
- key: 'calculateRange',
367
- debug: () => this.options.debug
324
+ _this.options = _extends({
325
+ debug: false,
326
+ initialOffset: 0,
327
+ overscan: 1,
328
+ paddingStart: 0,
329
+ paddingEnd: 0,
330
+ scrollPaddingStart: 0,
331
+ scrollPaddingEnd: 0,
332
+ horizontal: false,
333
+ getItemKey: defaultKeyExtractor,
334
+ rangeExtractor: defaultRangeExtractor,
335
+ onChange: function onChange() {},
336
+ measureElement: measureElement,
337
+ initialRect: {
338
+ width: 0,
339
+ height: 0
340
+ },
341
+ scrollMargin: 0,
342
+ scrollingDelay: 150,
343
+ indexAttribute: 'data-index',
344
+ initialMeasurementsCache: [],
345
+ lanes: 1
346
+ }, opts);
347
+ };
348
+ this.notify = function (sync) {
349
+ _this.options.onChange == null || _this.options.onChange(_this, sync);
350
+ };
351
+ this.maybeNotify = memo(function () {
352
+ _this.calculateRange();
353
+ return [_this.isScrolling, _this.range ? _this.range.startIndex : null, _this.range ? _this.range.endIndex : null];
354
+ }, function (isScrolling) {
355
+ _this.notify(isScrolling);
356
+ }, {
357
+ key: 'maybeNotify',
358
+ debug: function debug() {
359
+ return _this.options.debug;
360
+ },
361
+ initialDeps: [this.isScrolling, this.range ? this.range.startIndex : null, this.range ? this.range.endIndex : null]
362
+ });
363
+ this.cleanup = function () {
364
+ _this.unsubs.filter(Boolean).forEach(function (d) {
365
+ return d();
368
366
  });
369
- this.getIndexes = memo(() => [this.options.rangeExtractor, this.calculateRange(), this.options.overscan, this.options.count], (rangeExtractor, range, overscan, count) => {
370
- return rangeExtractor({ ...range,
371
- overscan,
372
- count: count
367
+ _this.unsubs = [];
368
+ _this.scrollElement = null;
369
+ };
370
+ this._didMount = function () {
371
+ _this.measureElementCache.forEach(_this.observer.observe);
372
+ return function () {
373
+ _this.observer.disconnect();
374
+ _this.cleanup();
375
+ };
376
+ };
377
+ this._willUpdate = function () {
378
+ var scrollElement = _this.options.getScrollElement();
379
+ if (_this.scrollElement !== scrollElement) {
380
+ _this.cleanup();
381
+ _this.scrollElement = scrollElement;
382
+ _this._scrollToOffset(_this.scrollOffset, {
383
+ adjustments: undefined,
384
+ behavior: undefined
373
385
  });
374
- }, {
375
- key: 'getIndexes'
376
- });
377
- this.getVirtualItems = memo(() => [this.getIndexes(), this.getMeasurements(), this.options.measureElement], (indexes, measurements, measureElement) => {
378
- const makeMeasureElement = index => measurableItem => {
379
- var _this$itemMeasurement;
380
-
381
- const item = this.measurementsCache[index];
382
-
383
- if (!measurableItem) {
386
+ _this.unsubs.push(_this.options.observeElementRect(_this, function (rect) {
387
+ _this.scrollRect = rect;
388
+ _this.maybeNotify();
389
+ }));
390
+ _this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {
391
+ _this.scrollAdjustments = 0;
392
+ if (_this.scrollOffset === offset) {
384
393
  return;
385
394
  }
386
-
387
- const measuredItemSize = measureElement(measurableItem, this);
388
- const itemSize = (_this$itemMeasurement = this.itemMeasurementsCache[item.key]) != null ? _this$itemMeasurement : item.size;
389
-
390
- if (measuredItemSize !== itemSize) {
391
- if (item.start < this.scrollOffset) {
392
- if (this.options.debug) {
393
- console.info('correction', measuredItemSize - itemSize);
394
- }
395
-
396
- if (!this.destinationOffset) {
397
- this._scrollToOffset(this.scrollOffset + (measuredItemSize - itemSize), false);
398
- }
399
- }
400
-
401
- this.pendingMeasuredCacheIndexes.push(index);
402
- this.itemMeasurementsCache = { ...this.itemMeasurementsCache,
403
- [item.key]: measuredItemSize
404
- };
405
- this.notify();
395
+ if (_this.isScrollingTimeoutId !== null) {
396
+ clearTimeout(_this.isScrollingTimeoutId);
397
+ _this.isScrollingTimeoutId = null;
406
398
  }
407
- };
408
-
409
- const virtualItems = [];
410
- const currentMeasureElements = {};
411
-
412
- for (let k = 0, len = indexes.length; k < len; k++) {
413
- var _this$measureElementC;
414
-
415
- const i = indexes[k];
416
- const measurement = measurements[i];
417
- const item = { ...measurement,
418
- measureElement: currentMeasureElements[i] = (_this$measureElementC = this.measureElementCache[i]) != null ? _this$measureElementC : makeMeasureElement(i)
419
- };
420
- virtualItems.push(item);
399
+ _this.isScrolling = true;
400
+ _this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
401
+ _this.scrollOffset = offset;
402
+ _this.maybeNotify();
403
+ _this.isScrollingTimeoutId = setTimeout(function () {
404
+ _this.isScrollingTimeoutId = null;
405
+ _this.isScrolling = false;
406
+ _this.scrollDirection = null;
407
+ _this.maybeNotify();
408
+ }, _this.options.scrollingDelay);
409
+ }));
410
+ }
411
+ };
412
+ this.getSize = function () {
413
+ return _this.scrollRect[_this.options.horizontal ? 'width' : 'height'];
414
+ };
415
+ this.memoOptions = memo(function () {
416
+ return [_this.options.count, _this.options.paddingStart, _this.options.scrollMargin, _this.options.getItemKey];
417
+ }, function (count, paddingStart, scrollMargin, getItemKey) {
418
+ _this.pendingMeasuredCacheIndexes = [];
419
+ return {
420
+ count: count,
421
+ paddingStart: paddingStart,
422
+ scrollMargin: scrollMargin,
423
+ getItemKey: getItemKey
424
+ };
425
+ }, {
426
+ key: false
427
+ });
428
+ this.getFurthestMeasurement = function (measurements, index) {
429
+ var furthestMeasurementsFound = new Map();
430
+ var furthestMeasurements = new Map();
431
+ for (var m = index - 1; m >= 0; m--) {
432
+ var measurement = measurements[m];
433
+ if (furthestMeasurementsFound.has(measurement.lane)) {
434
+ continue;
421
435
  }
422
-
423
- this.measureElementCache = currentMeasureElements;
424
- return virtualItems;
425
- }, {
426
- key: 'getIndexes'
427
- });
428
-
429
- this.scrollToOffset = function (toOffset, _temp) {
430
- let {
431
- align
432
- } = _temp === void 0 ? {
433
- align: 'start'
434
- } : _temp;
435
-
436
- const attempt = () => {
437
- const offset = _this.scrollOffset;
438
-
439
- const size = _this.getSize();
440
-
441
- if (align === 'auto') {
442
- if (toOffset <= offset) {
443
- align = 'start';
444
- } else if (toOffset >= offset + size) {
445
- align = 'end';
446
- } else {
447
- align = 'start';
448
- }
449
- }
450
-
451
- if (align === 'start') {
452
- _this._scrollToOffset(toOffset, true);
453
- } else if (align === 'end') {
454
- _this._scrollToOffset(toOffset - size, true);
455
- } else if (align === 'center') {
456
- _this._scrollToOffset(toOffset - size / 2, true);
457
- }
436
+ var previousFurthestMeasurement = furthestMeasurements.get(measurement.lane);
437
+ if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
438
+ furthestMeasurements.set(measurement.lane, measurement);
439
+ } else if (measurement.end < previousFurthestMeasurement.end) {
440
+ furthestMeasurementsFound.set(measurement.lane, true);
441
+ }
442
+ if (furthestMeasurementsFound.size === _this.options.lanes) {
443
+ break;
444
+ }
445
+ }
446
+ return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
447
+ return a.end - b.end;
448
+ })[0] : undefined;
449
+ };
450
+ this.getMeasurements = memo(function () {
451
+ return [_this.memoOptions(), _this.itemSizeCache];
452
+ }, function (_ref4, itemSizeCache) {
453
+ var count = _ref4.count,
454
+ paddingStart = _ref4.paddingStart,
455
+ scrollMargin = _ref4.scrollMargin,
456
+ getItemKey = _ref4.getItemKey;
457
+ var min = _this.pendingMeasuredCacheIndexes.length > 0 ? Math.min.apply(Math, _this.pendingMeasuredCacheIndexes) : 0;
458
+ _this.pendingMeasuredCacheIndexes = [];
459
+ var measurements = _this.measurementsCache.slice(0, min);
460
+ for (var _i2 = min; _i2 < count; _i2++) {
461
+ var key = getItemKey(_i2);
462
+ var furthestMeasurement = _this.options.lanes === 1 ? measurements[_i2 - 1] : _this.getFurthestMeasurement(measurements, _i2);
463
+ var start = furthestMeasurement ? furthestMeasurement.end : paddingStart + scrollMargin;
464
+ var measuredSize = itemSizeCache.get(key);
465
+ var size = typeof measuredSize === 'number' ? measuredSize : _this.options.estimateSize(_i2);
466
+ var end = start + size;
467
+ var lane = furthestMeasurement ? furthestMeasurement.lane : _i2 % _this.options.lanes;
468
+ measurements[_i2] = {
469
+ index: _i2,
470
+ start: start,
471
+ size: size,
472
+ end: end,
473
+ key: key,
474
+ lane: lane
458
475
  };
459
-
460
- attempt();
461
- requestAnimationFrame(() => {
462
- attempt();
476
+ }
477
+ _this.measurementsCache = measurements;
478
+ return measurements;
479
+ }, {
480
+ key: 'getMeasurements',
481
+ debug: function debug() {
482
+ return _this.options.debug;
483
+ }
484
+ });
485
+ this.calculateRange = memo(function () {
486
+ return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
487
+ }, function (measurements, outerSize, scrollOffset) {
488
+ return _this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
489
+ measurements: measurements,
490
+ outerSize: outerSize,
491
+ scrollOffset: scrollOffset
492
+ }) : null;
493
+ }, {
494
+ key: 'calculateRange',
495
+ debug: function debug() {
496
+ return _this.options.debug;
497
+ }
498
+ });
499
+ this.getIndexes = memo(function () {
500
+ return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
501
+ }, function (rangeExtractor, range, overscan, count) {
502
+ return range === null ? [] : rangeExtractor(_extends({}, range, {
503
+ overscan: overscan,
504
+ count: count
505
+ }));
506
+ }, {
507
+ key: 'getIndexes',
508
+ debug: function debug() {
509
+ return _this.options.debug;
510
+ }
511
+ });
512
+ this.indexFromElement = function (node) {
513
+ var attributeName = _this.options.indexAttribute;
514
+ var indexStr = node.getAttribute(attributeName);
515
+ if (!indexStr) {
516
+ console.warn("Missing attribute name '" + attributeName + "={index}' on measured element.");
517
+ return -1;
518
+ }
519
+ return parseInt(indexStr, 10);
520
+ };
521
+ this._measureElement = function (node, entry) {
522
+ var item = _this.measurementsCache[_this.indexFromElement(node)];
523
+ if (!item || !node.isConnected) {
524
+ _this.measureElementCache.forEach(function (cached, key) {
525
+ if (cached === node) {
526
+ _this.observer.unobserve(node);
527
+ _this.measureElementCache["delete"](key);
528
+ }
463
529
  });
464
- };
465
-
466
- this.scrollToIndex = function (index, _temp2) {
467
- let {
468
- align,
469
- ...rest
470
- } = _temp2 === void 0 ? {
471
- align: 'auto'
472
- } : _temp2;
473
-
474
- const measurements = _this.getMeasurements();
475
-
476
- const offset = _this.scrollOffset;
477
-
478
- const size = _this.getSize();
479
-
480
- const {
481
- count
482
- } = _this.options;
483
- const measurement = measurements[Math.max(0, Math.min(index, count - 1))];
484
-
485
- if (!measurement) {
486
- return;
530
+ return;
531
+ }
532
+ var prevNode = _this.measureElementCache.get(item.key);
533
+ if (prevNode !== node) {
534
+ if (prevNode) {
535
+ _this.observer.unobserve(prevNode);
487
536
  }
488
-
489
- if (align === 'auto') {
490
- if (measurement.end >= offset + size - _this.options.scrollPaddingEnd) {
491
- align = 'end';
492
- } else if (measurement.start <= offset + _this.options.scrollPaddingStart) {
493
- align = 'start';
494
- } else {
495
- return;
537
+ _this.observer.observe(node);
538
+ _this.measureElementCache.set(item.key, node);
539
+ }
540
+ var measuredItemSize = _this.options.measureElement(node, entry, _this);
541
+ _this.resizeItem(item, measuredItemSize);
542
+ };
543
+ this.resizeItem = function (item, size) {
544
+ var _this$itemSizeCache$g;
545
+ var itemSize = (_this$itemSizeCache$g = _this.itemSizeCache.get(item.key)) != null ? _this$itemSizeCache$g : item.size;
546
+ var delta = size - itemSize;
547
+ if (delta !== 0) {
548
+ if (item.start < _this.scrollOffset) {
549
+ if (_this.options.debug) {
550
+ console.info('correction', delta);
496
551
  }
552
+ _this._scrollToOffset(_this.scrollOffset, {
553
+ adjustments: _this.scrollAdjustments += delta,
554
+ behavior: undefined
555
+ });
497
556
  }
498
-
499
- const toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
500
-
501
- _this.scrollToOffset(toOffset, {
502
- align,
503
- ...rest
504
- });
505
- };
506
-
507
- this.getTotalSize = () => {
508
- var _this$getMeasurements;
509
-
510
- return (((_this$getMeasurements = this.getMeasurements()[this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || this.options.paddingStart) + this.options.paddingEnd;
511
- };
512
-
513
- this._scrollToOffset = (offset, canSmooth) => {
514
- clearTimeout(this.scrollCheckFrame);
515
- this.destinationOffset = offset;
516
- this.options.scrollToFn(offset, this.options.enableSmoothScroll && canSmooth, this);
517
- let scrollCheckFrame;
518
-
519
- const check = () => {
520
- let lastOffset = this.scrollOffset;
521
- this.scrollCheckFrame = scrollCheckFrame = setTimeout(() => {
522
- if (this.scrollCheckFrame !== scrollCheckFrame) {
523
- return;
524
- }
525
-
526
- if (this.scrollOffset === lastOffset) {
527
- this.destinationOffset = undefined;
528
- return;
557
+ _this.pendingMeasuredCacheIndexes.push(item.index);
558
+ _this.itemSizeCache = new Map(_this.itemSizeCache.set(item.key, size));
559
+ _this.notify(false);
560
+ }
561
+ };
562
+ this.measureElement = function (node) {
563
+ if (!node) {
564
+ return;
565
+ }
566
+ _this._measureElement(node, undefined);
567
+ };
568
+ this.getVirtualItems = memo(function () {
569
+ return [_this.getIndexes(), _this.getMeasurements()];
570
+ }, function (indexes, measurements) {
571
+ var virtualItems = [];
572
+ for (var k = 0, len = indexes.length; k < len; k++) {
573
+ var _i3 = indexes[k];
574
+ var measurement = measurements[_i3];
575
+ virtualItems.push(measurement);
576
+ }
577
+ return virtualItems;
578
+ }, {
579
+ key: 'getIndexes',
580
+ debug: function debug() {
581
+ return _this.options.debug;
582
+ }
583
+ });
584
+ this.getVirtualItemForOffset = function (offset) {
585
+ var measurements = _this.getMeasurements();
586
+ return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, function (index) {
587
+ return notUndefined(measurements[index]).start;
588
+ }, offset)]);
589
+ };
590
+ this.getOffsetForAlignment = function (toOffset, align) {
591
+ var size = _this.getSize();
592
+ if (align === 'auto') {
593
+ if (toOffset <= _this.scrollOffset) {
594
+ align = 'start';
595
+ } else if (toOffset >= _this.scrollOffset + size) {
596
+ align = 'end';
597
+ } else {
598
+ align = 'start';
599
+ }
600
+ }
601
+ if (align === 'start') {
602
+ toOffset = toOffset;
603
+ } else if (align === 'end') {
604
+ toOffset = toOffset - size;
605
+ } else if (align === 'center') {
606
+ toOffset = toOffset - size / 2;
607
+ }
608
+ var scrollSizeProp = _this.options.horizontal ? 'scrollWidth' : 'scrollHeight';
609
+ var scrollSize = _this.scrollElement ? 'document' in _this.scrollElement ? _this.scrollElement.document.documentElement[scrollSizeProp] : _this.scrollElement[scrollSizeProp] : 0;
610
+ var maxOffset = scrollSize - _this.getSize();
611
+ return Math.max(Math.min(maxOffset, toOffset), 0);
612
+ };
613
+ this.getOffsetForIndex = function (index, align) {
614
+ if (align === void 0) {
615
+ align = 'auto';
616
+ }
617
+ index = Math.max(0, Math.min(index, _this.options.count - 1));
618
+ var measurement = notUndefined(_this.getMeasurements()[index]);
619
+ if (align === 'auto') {
620
+ if (measurement.end >= _this.scrollOffset + _this.getSize() - _this.options.scrollPaddingEnd) {
621
+ align = 'end';
622
+ } else if (measurement.start <= _this.scrollOffset + _this.options.scrollPaddingStart) {
623
+ align = 'start';
624
+ } else {
625
+ return [_this.scrollOffset, align];
626
+ }
627
+ }
628
+ var toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
629
+ return [_this.getOffsetForAlignment(toOffset, align), align];
630
+ };
631
+ this.isDynamicMode = function () {
632
+ return _this.measureElementCache.size > 0;
633
+ };
634
+ this.cancelScrollToIndex = function () {
635
+ if (_this.scrollToIndexTimeoutId !== null) {
636
+ clearTimeout(_this.scrollToIndexTimeoutId);
637
+ _this.scrollToIndexTimeoutId = null;
638
+ }
639
+ };
640
+ this.scrollToOffset = function (toOffset, _temp) {
641
+ var _ref5 = _temp === void 0 ? {} : _temp,
642
+ _ref5$align = _ref5.align,
643
+ align = _ref5$align === void 0 ? 'start' : _ref5$align,
644
+ behavior = _ref5.behavior;
645
+ _this.cancelScrollToIndex();
646
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
647
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
648
+ }
649
+ _this._scrollToOffset(_this.getOffsetForAlignment(toOffset, align), {
650
+ adjustments: undefined,
651
+ behavior: behavior
652
+ });
653
+ };
654
+ this.scrollToIndex = function (index, _temp2) {
655
+ var _ref6 = _temp2 === void 0 ? {} : _temp2,
656
+ _ref6$align = _ref6.align,
657
+ initialAlign = _ref6$align === void 0 ? 'auto' : _ref6$align,
658
+ behavior = _ref6.behavior;
659
+ index = Math.max(0, Math.min(index, _this.options.count - 1));
660
+ _this.cancelScrollToIndex();
661
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
662
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
663
+ }
664
+ var _this$getOffsetForInd = _this.getOffsetForIndex(index, initialAlign),
665
+ toOffset = _this$getOffsetForInd[0],
666
+ align = _this$getOffsetForInd[1];
667
+ _this._scrollToOffset(toOffset, {
668
+ adjustments: undefined,
669
+ behavior: behavior
670
+ });
671
+ if (behavior !== 'smooth' && _this.isDynamicMode()) {
672
+ _this.scrollToIndexTimeoutId = setTimeout(function () {
673
+ _this.scrollToIndexTimeoutId = null;
674
+ var elementInDOM = _this.measureElementCache.has(_this.options.getItemKey(index));
675
+ if (elementInDOM) {
676
+ var _this$getOffsetForInd2 = _this.getOffsetForIndex(index, align),
677
+ _toOffset = _this$getOffsetForInd2[0];
678
+ if (!approxEqual(_toOffset, _this.scrollOffset)) {
679
+ _this.scrollToIndex(index, {
680
+ align: align,
681
+ behavior: behavior
682
+ });
529
683
  }
530
-
531
- lastOffset = this.scrollOffset;
532
- check();
533
- }, 100);
534
- };
535
-
536
- check();
537
- };
538
-
539
- this.measure = () => {
540
- this.itemMeasurementsCache = {};
541
- this.notify();
542
- };
543
-
544
- this.setOptions(_opts);
545
- this.scrollRect = this.options.initialRect;
546
- this.scrollOffset = this.options.initialOffset;
547
- }
548
-
549
- }
550
-
551
- const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
684
+ } else {
685
+ _this.scrollToIndex(index, {
686
+ align: align,
687
+ behavior: behavior
688
+ });
689
+ }
690
+ });
691
+ }
692
+ };
693
+ this.scrollBy = function (delta, _temp3) {
694
+ var _ref7 = _temp3 === void 0 ? {} : _temp3,
695
+ behavior = _ref7.behavior;
696
+ _this.cancelScrollToIndex();
697
+ if (behavior === 'smooth' && _this.isDynamicMode()) {
698
+ console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
699
+ }
700
+ _this._scrollToOffset(_this.scrollOffset + delta, {
701
+ adjustments: undefined,
702
+ behavior: behavior
703
+ });
704
+ };
705
+ this.getTotalSize = function () {
706
+ var _this$getMeasurements;
707
+ return (((_this$getMeasurements = _this.getMeasurements()[_this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || _this.options.paddingStart) - _this.options.scrollMargin + _this.options.paddingEnd;
708
+ };
709
+ this._scrollToOffset = function (offset, _ref8) {
710
+ var adjustments = _ref8.adjustments,
711
+ behavior = _ref8.behavior;
712
+ _this.options.scrollToFn(offset, {
713
+ behavior: behavior,
714
+ adjustments: adjustments
715
+ }, _this);
716
+ };
717
+ this.measure = function () {
718
+ _this.itemSizeCache = new Map();
719
+ _this.notify(false);
720
+ };
721
+ this.setOptions(_opts);
722
+ this.scrollRect = this.options.initialRect;
723
+ this.scrollOffset = this.options.initialOffset;
724
+ this.measurementsCache = this.options.initialMeasurementsCache;
725
+ this.measurementsCache.forEach(function (item) {
726
+ _this.itemSizeCache.set(item.key, item.size);
727
+ });
728
+ this.maybeNotify();
729
+ };
730
+ var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
552
731
  while (low <= high) {
553
- const middle = (low + high) / 2 | 0;
554
- const currentValue = getCurrentValue(middle);
555
-
732
+ var middle = (low + high) / 2 | 0;
733
+ var currentValue = getCurrentValue(middle);
556
734
  if (currentValue < value) {
557
735
  low = middle + 1;
558
736
  } else if (currentValue > value) {
@@ -561,82 +739,88 @@
561
739
  return middle;
562
740
  }
563
741
  }
564
-
565
742
  if (low > 0) {
566
743
  return low - 1;
567
744
  } else {
568
745
  return 0;
569
746
  }
570
747
  };
571
-
572
- function calculateRange(_ref2) {
573
- let {
574
- measurements,
575
- outerSize,
576
- scrollOffset
577
- } = _ref2;
578
- const count = measurements.length - 1;
579
-
580
- const getOffset = index => measurements[index].start;
581
-
582
- const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
583
- let endIndex = startIndex;
584
-
748
+ function calculateRange(_ref9) {
749
+ var measurements = _ref9.measurements,
750
+ outerSize = _ref9.outerSize,
751
+ scrollOffset = _ref9.scrollOffset;
752
+ var count = measurements.length - 1;
753
+ var getOffset = function getOffset(index) {
754
+ return measurements[index].start;
755
+ };
756
+ var startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
757
+ var endIndex = startIndex;
585
758
  while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
586
759
  endIndex++;
587
760
  }
588
-
589
761
  return {
590
- startIndex,
591
- endIndex
762
+ startIndex: startIndex,
763
+ endIndex: endIndex
592
764
  };
593
765
  }
594
766
 
595
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
767
+ //
596
768
 
769
+ var useIsomorphicLayoutEffect = typeof document !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
597
770
  function useVirtualizerBase(options) {
598
- const rerender = React__namespace.useReducer(() => ({}), {})[1];
599
- const resolvedOptions = { ...options,
600
- onChange: instance => {
601
- rerender();
602
- options.onChange == null ? void 0 : options.onChange(instance);
771
+ var rerender = React__namespace.useReducer(function () {
772
+ return {};
773
+ }, {})[1];
774
+ var resolvedOptions = _extends$1({}, options, {
775
+ onChange: function onChange(instance, sync) {
776
+ if (sync) {
777
+ reactDom.flushSync(rerender);
778
+ } else {
779
+ rerender();
780
+ }
781
+ options.onChange == null || options.onChange(instance, sync);
603
782
  }
604
- };
605
- const [instance] = React__namespace.useState(() => new Virtualizer(resolvedOptions));
783
+ });
784
+ var _React$useState = React__namespace.useState(function () {
785
+ return new Virtualizer(resolvedOptions);
786
+ }),
787
+ instance = _React$useState[0];
606
788
  instance.setOptions(resolvedOptions);
607
- React__namespace.useEffect(() => {
789
+ React__namespace.useEffect(function () {
608
790
  return instance._didMount();
609
791
  }, []);
610
- useIsomorphicLayoutEffect(() => {
792
+ useIsomorphicLayoutEffect(function () {
611
793
  return instance._willUpdate();
612
794
  });
613
795
  return instance;
614
796
  }
615
-
616
797
  function useVirtualizer(options) {
617
- return useVirtualizerBase({
798
+ return useVirtualizerBase(_extends$1({
618
799
  observeElementRect: observeElementRect,
619
800
  observeElementOffset: observeElementOffset,
620
- scrollToFn: elementScroll,
621
- ...options
622
- });
801
+ scrollToFn: elementScroll
802
+ }, options));
623
803
  }
624
804
  function useWindowVirtualizer(options) {
625
- return useVirtualizerBase({
626
- getScrollElement: () => typeof window !== 'undefined' ? window : null,
805
+ return useVirtualizerBase(_extends$1({
806
+ getScrollElement: function getScrollElement() {
807
+ return typeof document !== 'undefined' ? window : null;
808
+ },
627
809
  observeElementRect: observeWindowRect,
628
810
  observeElementOffset: observeWindowOffset,
629
811
  scrollToFn: windowScroll,
630
- ...options
631
- });
812
+ initialOffset: typeof document !== 'undefined' ? window.scrollY : undefined
813
+ }, options));
632
814
  }
633
815
 
634
816
  exports.Virtualizer = Virtualizer;
817
+ exports.approxEqual = approxEqual;
635
818
  exports.defaultKeyExtractor = defaultKeyExtractor;
636
819
  exports.defaultRangeExtractor = defaultRangeExtractor;
637
820
  exports.elementScroll = elementScroll;
638
821
  exports.measureElement = measureElement;
639
822
  exports.memo = memo;
823
+ exports.notUndefined = notUndefined;
640
824
  exports.observeElementOffset = observeElementOffset;
641
825
  exports.observeElementRect = observeElementRect;
642
826
  exports.observeWindowOffset = observeWindowOffset;