@tanstack/solid-virtual 3.0.0-beta.6 → 3.0.0-beta.61

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