New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tanstack/virtual-core

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/virtual-core - npm Package Compare versions

Comparing version 3.0.0-beta.42 to 3.0.0-beta.43

5

build/lib/index.d.ts

@@ -100,6 +100,7 @@ export * from './utils';

private getMeasurements;
calculateRange: (fArgs_0?: boolean | undefined) => {
calculateRange: () => {
startIndex: number;
endIndex: number;
};
private maybeNotify;
private getIndexes;

@@ -109,3 +110,3 @@ indexFromElement: (node: TItemElement) => number;

measureElement: (node: TItemElement | null) => void;
getVirtualItems: (...fArgs: readonly any[]) => VirtualItem[];
getVirtualItems: () => VirtualItem[];
getOffsetForAlignment: (toOffset: number, align: ScrollAlignment) => number;

@@ -112,0 +113,0 @@ scrollToOffset: (toOffset: number, { align, behavior }?: ScrollToOffsetOptions) => void;

77

build/lib/index.esm.js

@@ -241,3 +241,3 @@ /**

_this.scrollRect = rect;
_this.calculateRange();
_this.maybeNotify();
}));

@@ -253,16 +253,11 @@ _this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {

}
var onIsScrollingChange = function onIsScrollingChange(isScrolling) {
if (_this.isScrolling !== isScrolling) {
_this.isScrolling = isScrolling;
_this.notify();
}
};
_this.isScrolling = true;
_this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
_this.scrollOffset = offset;
_this.calculateRange();
onIsScrollingChange(true);
_this.maybeNotify();
_this.isScrollingTimeoutId = setTimeout(function () {
_this.isScrollingTimeoutId = null;
_this.isScrolling = false;
_this.scrollDirection = null;
onIsScrollingChange(false);
_this.maybeNotify();
}, _this.options.scrollingDelay);

@@ -305,6 +300,4 @@ }));

return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
}, function (measurements, outerSize, scrollOffset, _ref4) {
var _ref4$ = _ref4[0],
flush = _ref4$ === void 0 ? true : _ref4$;
var range = calculateRange({
}, function (measurements, outerSize, scrollOffset) {
return _this.range = calculateRange({
measurements: measurements,

@@ -314,9 +307,2 @@ outerSize: outerSize,

});
if (range.startIndex !== _this.range.startIndex || range.endIndex !== _this.range.endIndex) {
_this.range = range;
if (flush) {
_this.notify();
}
}
return _this.range;
}, {

@@ -328,4 +314,15 @@ key: process.env.NODE_ENV !== 'production' && 'calculateRange',

});
this.maybeNotify = memo(function () {
return [].concat(Object.values(_this.calculateRange()), [_this.isScrolling]);
}, function () {
_this.notify();
}, {
key: process.env.NODE_ENV !== 'production' && 'maybeNotify',
debug: function debug() {
return _this.options.debug;
},
initialDeps: [].concat(Object.values(this.range), [this.isScrolling])
});
this.getIndexes = memo(function () {
return [_this.options.rangeExtractor, _this.calculateRange(false), _this.options.overscan, _this.options.count];
return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
}, function (rangeExtractor, range, overscan, count) {

@@ -444,6 +441,6 @@ return rangeExtractor(_extends({}, range, {

this.scrollToOffset = function (toOffset, _temp) {
var _ref5 = _temp === void 0 ? {} : _temp,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'start' : _ref5$align,
behavior = _ref5.behavior;
var _ref4 = _temp === void 0 ? {} : _temp,
_ref4$align = _ref4.align,
align = _ref4$align === void 0 ? 'start' : _ref4$align,
behavior = _ref4.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -462,6 +459,6 @@ if (isDynamic && behavior === 'smooth') {

this.scrollToIndex = function (index, _temp2) {
var _ref6 = _temp2 === void 0 ? {} : _temp2,
_ref6$align = _ref6.align,
align = _ref6$align === void 0 ? 'auto' : _ref6$align,
behavior = _ref6.behavior;
var _ref5 = _temp2 === void 0 ? {} : _temp2,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'auto' : _ref5$align,
behavior = _ref5.behavior;
index = Math.max(0, Math.min(index, _this.options.count - 1));

@@ -519,4 +516,4 @@ if (_this.scrollToIndexTimeoutId !== null) {

this.scrollBy = function (delta, _temp3) {
var _ref7 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref7.behavior;
var _ref6 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref6.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -536,5 +533,5 @@ if (isDynamic && behavior === 'smooth') {

};
this._scrollToOffset = function (offset, _ref8) {
var adjustments = _ref8.adjustments,
behavior = _ref8.behavior;
this._scrollToOffset = function (offset, _ref7) {
var adjustments = _ref7.adjustments,
behavior = _ref7.behavior;
_this.options.scrollToFn(offset, {

@@ -556,3 +553,3 @@ behavior: behavior,

});
this.calculateRange();
this.maybeNotify();
};

@@ -577,6 +574,6 @@ var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {

};
function calculateRange(_ref9) {
var measurements = _ref9.measurements,
outerSize = _ref9.outerSize,
scrollOffset = _ref9.scrollOffset;
function calculateRange(_ref8) {
var measurements = _ref8.measurements,
outerSize = _ref8.outerSize,
scrollOffset = _ref8.scrollOffset;
var count = measurements.length - 1;

@@ -583,0 +580,0 @@ var getOffset = function getOffset(index) {

@@ -244,3 +244,3 @@ /**

_this.scrollRect = rect;
_this.calculateRange();
_this.maybeNotify();
}));

@@ -256,16 +256,11 @@ _this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {

}
var onIsScrollingChange = function onIsScrollingChange(isScrolling) {
if (_this.isScrolling !== isScrolling) {
_this.isScrolling = isScrolling;
_this.notify();
}
};
_this.isScrolling = true;
_this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
_this.scrollOffset = offset;
_this.calculateRange();
onIsScrollingChange(true);
_this.maybeNotify();
_this.isScrollingTimeoutId = setTimeout(function () {
_this.isScrollingTimeoutId = null;
_this.isScrolling = false;
_this.scrollDirection = null;
onIsScrollingChange(false);
_this.maybeNotify();
}, _this.options.scrollingDelay);

@@ -308,6 +303,4 @@ }));

return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
}, function (measurements, outerSize, scrollOffset, _ref4) {
var _ref4$ = _ref4[0],
flush = _ref4$ === void 0 ? true : _ref4$;
var range = calculateRange({
}, function (measurements, outerSize, scrollOffset) {
return _this.range = calculateRange({
measurements: measurements,

@@ -317,9 +310,2 @@ outerSize: outerSize,

});
if (range.startIndex !== _this.range.startIndex || range.endIndex !== _this.range.endIndex) {
_this.range = range;
if (flush) {
_this.notify();
}
}
return _this.range;
}, {

@@ -331,4 +317,15 @@ key: process.env.NODE_ENV !== 'production' && 'calculateRange',

});
this.maybeNotify = utils.memo(function () {
return [].concat(Object.values(_this.calculateRange()), [_this.isScrolling]);
}, function () {
_this.notify();
}, {
key: process.env.NODE_ENV !== 'production' && 'maybeNotify',
debug: function debug() {
return _this.options.debug;
},
initialDeps: [].concat(Object.values(this.range), [this.isScrolling])
});
this.getIndexes = utils.memo(function () {
return [_this.options.rangeExtractor, _this.calculateRange(false), _this.options.overscan, _this.options.count];
return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
}, function (rangeExtractor, range, overscan, count) {

@@ -447,6 +444,6 @@ return rangeExtractor(_rollupPluginBabelHelpers["extends"]({}, range, {

this.scrollToOffset = function (toOffset, _temp) {
var _ref5 = _temp === void 0 ? {} : _temp,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'start' : _ref5$align,
behavior = _ref5.behavior;
var _ref4 = _temp === void 0 ? {} : _temp,
_ref4$align = _ref4.align,
align = _ref4$align === void 0 ? 'start' : _ref4$align,
behavior = _ref4.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -465,6 +462,6 @@ if (isDynamic && behavior === 'smooth') {

this.scrollToIndex = function (index, _temp2) {
var _ref6 = _temp2 === void 0 ? {} : _temp2,
_ref6$align = _ref6.align,
align = _ref6$align === void 0 ? 'auto' : _ref6$align,
behavior = _ref6.behavior;
var _ref5 = _temp2 === void 0 ? {} : _temp2,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'auto' : _ref5$align,
behavior = _ref5.behavior;
index = Math.max(0, Math.min(index, _this.options.count - 1));

@@ -522,4 +519,4 @@ if (_this.scrollToIndexTimeoutId !== null) {

this.scrollBy = function (delta, _temp3) {
var _ref7 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref7.behavior;
var _ref6 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref6.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -539,5 +536,5 @@ if (isDynamic && behavior === 'smooth') {

};
this._scrollToOffset = function (offset, _ref8) {
var adjustments = _ref8.adjustments,
behavior = _ref8.behavior;
this._scrollToOffset = function (offset, _ref7) {
var adjustments = _ref7.adjustments,
behavior = _ref7.behavior;
_this.options.scrollToFn(offset, {

@@ -559,3 +556,3 @@ behavior: behavior,

});
this.calculateRange();
this.maybeNotify();
};

@@ -580,6 +577,6 @@ var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {

};
function calculateRange(_ref9) {
var measurements = _ref9.measurements,
outerSize = _ref9.outerSize,
scrollOffset = _ref9.scrollOffset;
function calculateRange(_ref8) {
var measurements = _ref8.measurements,
outerSize = _ref8.outerSize,
scrollOffset = _ref8.scrollOffset;
var count = measurements.length - 1;

@@ -586,0 +583,0 @@ var getOffset = function getOffset(index) {

export type NoInfer<A extends any> = [A][A extends any ? 0 : never];
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export declare function memo<TDeps extends readonly any[], TResult, FArgs extends readonly any[]>(getDeps: () => [...TDeps], fn: (...args: [...TDeps, FArgs]) => TResult, opts: {
export declare function memo<TDeps extends readonly any[], TResult>(getDeps: () => [...TDeps], fn: (...args: NoInfer<[...TDeps]>) => TResult, opts: {
key: any;
debug?: () => any;
onChange?: (result: TResult) => void;
}): (...fArgs: FArgs) => TResult;
initialDeps?: TDeps;
}): () => TResult;
export declare function notUndefined<T>(value: T | undefined, msg?: string): T;
export declare const approxEqual: (a: number, b: number) => boolean;

@@ -12,3 +12,4 @@ /**

function memo(getDeps, fn, opts) {
var deps = [];
var _opts$initialDeps;
var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
var result;

@@ -28,7 +29,3 @@ return function () {

if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
for (var _len = arguments.length, fArgs = new Array(_len), _key = 0; _key < _len; _key++) {
fArgs[_key] = arguments[_key];
}
result = fn.apply(void 0, newDeps.concat([fArgs]));
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
result = fn.apply(void 0, newDeps);
if (opts.key && opts.debug != null && opts.debug()) {

@@ -47,2 +44,3 @@ var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;

}
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
return result;

@@ -49,0 +47,0 @@ };

@@ -16,3 +16,4 @@ /**

function memo(getDeps, fn, opts) {
var deps = [];
var _opts$initialDeps;
var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
var result;

@@ -32,7 +33,3 @@ return function () {

if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
for (var _len = arguments.length, fArgs = new Array(_len), _key = 0; _key < _len; _key++) {
fArgs[_key] = arguments[_key];
}
result = fn.apply(void 0, newDeps.concat([fArgs]));
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
result = fn.apply(void 0, newDeps);
if (opts.key && opts.debug != null && opts.debug()) {

@@ -51,2 +48,3 @@ var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;

}
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
return result;

@@ -53,0 +51,0 @@ };

@@ -33,3 +33,4 @@ /**

function memo(getDeps, fn, opts) {
var deps = [];
var _opts$initialDeps;
var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
var result;

@@ -49,7 +50,3 @@ return function () {

if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
for (var _len = arguments.length, fArgs = new Array(_len), _key = 0; _key < _len; _key++) {
fArgs[_key] = arguments[_key];
}
result = fn.apply(void 0, newDeps.concat([fArgs]));
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
result = fn.apply(void 0, newDeps);
if (opts.key && opts.debug != null && opts.debug()) {

@@ -68,2 +65,3 @@ var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;

}
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
return result;

@@ -309,3 +307,3 @@ };

_this.scrollRect = rect;
_this.calculateRange();
_this.maybeNotify();
}));

@@ -321,16 +319,11 @@ _this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {

}
var onIsScrollingChange = function onIsScrollingChange(isScrolling) {
if (_this.isScrolling !== isScrolling) {
_this.isScrolling = isScrolling;
_this.notify();
}
};
_this.isScrolling = true;
_this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
_this.scrollOffset = offset;
_this.calculateRange();
onIsScrollingChange(true);
_this.maybeNotify();
_this.isScrollingTimeoutId = setTimeout(function () {
_this.isScrollingTimeoutId = null;
_this.isScrolling = false;
_this.scrollDirection = null;
onIsScrollingChange(false);
_this.maybeNotify();
}, _this.options.scrollingDelay);

@@ -373,6 +366,4 @@ }));

return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
}, function (measurements, outerSize, scrollOffset, _ref4) {
var _ref4$ = _ref4[0],
flush = _ref4$ === void 0 ? true : _ref4$;
var range = calculateRange({
}, function (measurements, outerSize, scrollOffset) {
return _this.range = calculateRange({
measurements: measurements,

@@ -382,9 +373,2 @@ outerSize: outerSize,

});
if (range.startIndex !== _this.range.startIndex || range.endIndex !== _this.range.endIndex) {
_this.range = range;
if (flush) {
_this.notify();
}
}
return _this.range;
}, {

@@ -396,4 +380,15 @@ key: 'calculateRange',

});
this.maybeNotify = memo(function () {
return [].concat(Object.values(_this.calculateRange()), [_this.isScrolling]);
}, function () {
_this.notify();
}, {
key: 'maybeNotify',
debug: function debug() {
return _this.options.debug;
},
initialDeps: [].concat(Object.values(this.range), [this.isScrolling])
});
this.getIndexes = memo(function () {
return [_this.options.rangeExtractor, _this.calculateRange(false), _this.options.overscan, _this.options.count];
return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
}, function (rangeExtractor, range, overscan, count) {

@@ -512,6 +507,6 @@ return rangeExtractor(_extends({}, range, {

this.scrollToOffset = function (toOffset, _temp) {
var _ref5 = _temp === void 0 ? {} : _temp,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'start' : _ref5$align,
behavior = _ref5.behavior;
var _ref4 = _temp === void 0 ? {} : _temp,
_ref4$align = _ref4.align,
align = _ref4$align === void 0 ? 'start' : _ref4$align,
behavior = _ref4.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -530,6 +525,6 @@ if (isDynamic && behavior === 'smooth') {

this.scrollToIndex = function (index, _temp2) {
var _ref6 = _temp2 === void 0 ? {} : _temp2,
_ref6$align = _ref6.align,
align = _ref6$align === void 0 ? 'auto' : _ref6$align,
behavior = _ref6.behavior;
var _ref5 = _temp2 === void 0 ? {} : _temp2,
_ref5$align = _ref5.align,
align = _ref5$align === void 0 ? 'auto' : _ref5$align,
behavior = _ref5.behavior;
index = Math.max(0, Math.min(index, _this.options.count - 1));

@@ -587,4 +582,4 @@ if (_this.scrollToIndexTimeoutId !== null) {

this.scrollBy = function (delta, _temp3) {
var _ref7 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref7.behavior;
var _ref6 = _temp3 === void 0 ? {} : _temp3,
behavior = _ref6.behavior;
var isDynamic = Object.keys(_this.measureElementCache).length > 0;

@@ -604,5 +599,5 @@ if (isDynamic && behavior === 'smooth') {

};
this._scrollToOffset = function (offset, _ref8) {
var adjustments = _ref8.adjustments,
behavior = _ref8.behavior;
this._scrollToOffset = function (offset, _ref7) {
var adjustments = _ref7.adjustments,
behavior = _ref7.behavior;
_this.options.scrollToFn(offset, {

@@ -624,3 +619,3 @@ behavior: behavior,

});
this.calculateRange();
this.maybeNotify();
};

@@ -645,6 +640,6 @@ var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {

};
function calculateRange(_ref9) {
var measurements = _ref9.measurements,
outerSize = _ref9.outerSize,
scrollOffset = _ref9.scrollOffset;
function calculateRange(_ref8) {
var measurements = _ref8.measurements,
outerSize = _ref8.outerSize,
scrollOffset = _ref8.scrollOffset;
var count = measurements.length - 1;

@@ -651,0 +646,0 @@ var getOffset = function getOffset(index) {

@@ -11,3 +11,3 @@ /**

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VirtualCore={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},t.apply(this,arguments)}function n(e,t,n){var o,r=[];return function(){var i;n.key&&null!=n.debug&&n.debug()&&(i=Date.now());var s,l=e(),a=l.length!==r.length||l.some((function(e,t){return r[t]!==e}));if(!a)return o;r=l,n.key&&null!=n.debug&&n.debug()&&(s=Date.now());for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];if(o=t.apply(void 0,l.concat([c])),null==n||null==n.onChange||n.onChange(o),n.key&&null!=n.debug&&n.debug()){var f=Math.round(100*(Date.now()-i))/100,h=Math.round(100*(Date.now()-s))/100,m=h/16,g=function(e,t){for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+g(h,5)+" /"+g(f,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*m,120))+"deg 100% 31%);",null==n?void 0:n.key)}return o}}function o(e,t){if(void 0===e)throw new Error("Unexpected undefined"+(t?": "+t:""));return e}var r=function(e,t){return Math.abs(e-t)<1},i=function(e){return e},s=function(e){for(var t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),o=[],r=t;r<=n;r++)o.push(r);return o},l={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},a=function(e){return function(t,n){if(t.scrollElement){var o=l[e][0],r=l[e][1],i=t.scrollElement[o],s=t.scrollElement[r],a=function(){var e=t.scrollElement[t.options.horizontal?o:r];n(e)};a();var u=function(e){var n=e.currentTarget,l=n[o],u=n[r];(t.options.horizontal?i-l:s-u)&&a(),i=l,s=u};return t.scrollElement.addEventListener("scroll",u,{capture:!1,passive:!0}),function(){t.scrollElement.removeEventListener("scroll",u)}}}},u=a("element"),c=a("window"),d=function(e,t){return Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"])};e.Virtualizer=function(e){var l,a=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache={},this.pendingMeasuredCacheIndexes=[],this.scrollDirection=null,this.scrollAdjustments=0,this.measureElementCache={},this.getResizeObserver=(l=null,function(){return l||("undefined"!=typeof ResizeObserver?l=new ResizeObserver((function(e){e.forEach((function(e){a._measureElement(e.target,!1)}))})):null)}),this.range={startIndex:0,endIndex:0},this.setOptions=function(e){Object.entries(e).forEach((function(t){var n=t[0];void 0===t[1]&&delete e[n]})),a.options=t({debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:i,rangeExtractor:s,onChange:function(){},measureElement:d,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",initialMeasurementsCache:[]},e)},this.notify=function(){null==a.options.onChange||a.options.onChange(a)},this.cleanup=function(){a.unsubs.filter(Boolean).forEach((function(e){return e()})),a.unsubs=[],a.scrollElement=null},this._didMount=function(){var e=a.getResizeObserver();return Object.values(a.measureElementCache).forEach((function(t){return null==e?void 0:e.observe(t)})),function(){null==e||e.disconnect(),a.cleanup()}},this._willUpdate=function(){var e=a.options.getScrollElement();a.scrollElement!==e&&(a.cleanup(),a.scrollElement=e,a._scrollToOffset(a.scrollOffset,{adjustments:void 0,behavior:void 0}),a.unsubs.push(a.options.observeElementRect(a,(function(e){a.scrollRect=e,a.calculateRange()}))),a.unsubs.push(a.options.observeElementOffset(a,(function(e){if(a.scrollAdjustments=0,a.scrollOffset!==e){null!==a.isScrollingTimeoutId&&(clearTimeout(a.isScrollingTimeoutId),a.isScrollingTimeoutId=null);var t=function(e){a.isScrolling!==e&&(a.isScrolling=e,a.notify())};a.scrollDirection=a.scrollOffset<e?"forward":"backward",a.scrollOffset=e,a.calculateRange(),t(!0),a.isScrollingTimeoutId=setTimeout((function(){a.isScrollingTimeoutId=null,a.scrollDirection=null,t(!1)}),a.options.scrollingDelay)}}))))},this.getSize=function(){return a.scrollRect[a.options.horizontal?"width":"height"]},this.getMeasurements=n((function(){return[a.options.count,a.options.paddingStart,a.options.scrollMargin,a.options.getItemKey,a.itemSizeCache]}),(function(e,t,n,o,r){var i=a.pendingMeasuredCacheIndexes.length>0?Math.min.apply(Math,a.pendingMeasuredCacheIndexes):0;a.pendingMeasuredCacheIndexes=[];for(var s=a.measurementsCache.slice(0,i),l=i;l<e;l++){var u=o(l),c=r[u],d=s[l-1]?s[l-1].end:t+n,f="number"==typeof c?c:a.options.estimateSize(l),h=d+f;s[l]={index:l,start:d,size:f,end:h,key:u}}return a.measurementsCache=s,s}),{key:!1,debug:function(){return a.options.debug}}),this.calculateRange=n((function(){return[a.getMeasurements(),a.getSize(),a.scrollOffset]}),(function(e,t,n,o){var r=o[0],i=void 0===r||r,s=function(e){var t=e.measurements,n=e.outerSize,o=e.scrollOffset,r=t.length-1,i=function(e,t,n,o){for(;e<=t;){var r=(e+t)/2|0,i=n(r);if(i<o)e=r+1;else{if(!(i>o))return r;t=r-1}}return e>0?e-1:0}(0,r,(function(e){return t[e].start}),o),s=i;for(;s<r&&t[s].end<o+n;)s++;return{startIndex:i,endIndex:s}}({measurements:e,outerSize:t,scrollOffset:n});return s.startIndex===a.range.startIndex&&s.endIndex===a.range.endIndex||(a.range=s,i&&a.notify()),a.range}),{key:!1,debug:function(){return a.options.debug}}),this.getIndexes=n((function(){return[a.options.rangeExtractor,a.calculateRange(!1),a.options.overscan,a.options.count]}),(function(e,n,o,r){return e(t({},n,{overscan:o,count:r}))}),{key:!1,debug:function(){return a.options.debug}}),this.indexFromElement=function(e){var t=a.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn("Missing attribute name '"+t+"={index}' on measured element."),-1)},this._measureElement=function(e,n){var o,r=a.indexFromElement(e),i=a.measurementsCache[r];if(i){var s=a.measureElementCache[i.key],l=a.getResizeObserver();if(!e.isConnected)return null==l||l.unobserve(e),void(e===s&&delete a.measureElementCache[i.key]);if(s!==e)s&&(null==l||l.unobserve(s)),null==l||l.observe(e),a.measureElementCache[i.key]=e;else if(!n&&!s.__virtualizerSkipFirstNotSync)return void(s.__virtualizerSkipFirstNotSync=!0);var u,c=a.options.measureElement(e,a),d=c-(null!=(o=a.itemSizeCache[i.key])?o:i.size);if(0!==d)i.start<a.scrollOffset&&a._scrollToOffset(a.scrollOffset,{adjustments:a.scrollAdjustments+=d,behavior:void 0}),a.pendingMeasuredCacheIndexes.push(r),a.itemSizeCache=t({},a.itemSizeCache,((u={})[i.key]=c,u)),a.notify()}},this.measureElement=function(e){e&&a._measureElement(e,!0)},this.getVirtualItems=n((function(){return[a.getIndexes(),a.getMeasurements()]}),(function(e,t){for(var n=[],o=0,r=e.length;o<r;o++){var i=t[e[o]];n.push(i)}return n}),{key:!1,debug:function(){return a.options.debug}}),this.getOffsetForAlignment=function(e,t){var n=a.getSize();"auto"===t&&(t=e<=a.scrollOffset?"start":e>=a.scrollOffset+n?"end":"start"),"start"===t||("end"===t?e-=n:"center"===t&&(e-=n/2));var o=a.options.horizontal?"scrollWidth":"scrollHeight",r=(a.scrollElement?"document"in a.scrollElement?a.scrollElement.document.documentElement[o]:a.scrollElement[o]:0)-a.getSize();return Math.max(Math.min(r,e),0)},this.scrollToOffset=function(e,t){var n=void 0===t?{}:t,o=n.align,r=void 0===o?"start":o,i=n.behavior;if(Object.keys(a.measureElementCache).length>0&&"smooth"===i)console.warn("The `smooth` scroll behavior is not supported with dynamic size.");else{var s={adjustments:void 0,behavior:i,sync:!1};a._scrollToOffset(a.getOffsetForAlignment(e,r),s)}},this.scrollToIndex=function(e,t){var n=void 0===t?{}:t,i=n.align,s=void 0===i?"auto":i,l=n.behavior;e=Math.max(0,Math.min(e,a.options.count-1)),null!==a.scrollToIndexTimeoutId&&(clearTimeout(a.scrollToIndexTimeoutId),a.scrollToIndexTimeoutId=null);var u=Object.keys(a.measureElementCache).length>0;if(u&&"smooth"===l)console.warn("The `smooth` scroll behavior is not supported with dynamic size.");else{var c=o(a.getMeasurements()[e]);if("auto"===s)if(c.end>=a.scrollOffset+a.getSize()-a.options.scrollPaddingEnd)s="end";else{if(!(c.start<=a.scrollOffset+a.options.scrollPaddingStart))return;s="start"}var d=function(e){var t="end"===s?e.end+a.options.scrollPaddingEnd:e.start-a.options.scrollPaddingStart;return a.getOffsetForAlignment(t,s)},f=d(c),h={adjustments:void 0,behavior:l};a._scrollToOffset(f,h),u&&(a.scrollToIndexTimeoutId=setTimeout((function(){if(a.scrollToIndexTimeoutId=null,!!a.measureElementCache[a.options.getItemKey(e)]){var t=d(o(a.getMeasurements()[e]));r(t,a.scrollOffset)||a.scrollToIndex(e,{align:s,behavior:l})}else a.scrollToIndex(e,{align:s,behavior:l})})))}},this.scrollBy=function(e,t){var n=(void 0===t?{}:t).behavior;Object.keys(a.measureElementCache).length>0&&"smooth"===n?console.warn("The `smooth` scroll behavior is not supported with dynamic size."):a._scrollToOffset(a.scrollOffset+e,{adjustments:void 0,behavior:n})},this.getTotalSize=function(){var e;return((null==(e=a.getMeasurements()[a.options.count-1])?void 0:e.end)||a.options.paddingStart)-a.options.scrollMargin+a.options.paddingEnd},this._scrollToOffset=function(e,t){var n=t.adjustments,o=t.behavior;a.options.scrollToFn(e,{behavior:o,adjustments:n},a)},this.measure=function(){a.itemSizeCache={},a.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((function(e){a.itemSizeCache[e.key]=e.size})),this.calculateRange()},e.approxEqual=r,e.defaultKeyExtractor=i,e.defaultRangeExtractor=s,e.elementScroll=function(e,t,n){var o,r,i=t.adjustments,s=void 0===i?0:i,l=t.behavior,a=e+s;null==(o=n.scrollElement)||null==o.scrollTo||o.scrollTo(((r={})[n.options.horizontal?"left":"top"]=a,r.behavior=l,r))},e.measureElement=d,e.memo=n,e.notUndefined=o,e.observeElementOffset=u,e.observeElementRect=function(e,t){var n=new ResizeObserver((function(e){var n=e[0];if(n){var o=n.contentRect,r=o.width,i=o.height;t({width:Math.round(r),height:Math.round(i)})}else t({width:0,height:0})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),n.observe(e.scrollElement),function(){n.unobserve(e.scrollElement)}},e.observeWindowOffset=c,e.observeWindowRect=function(e,t){var n=function(e,t){var n={height:-1,width:-1};return function(o){(e.options.horizontal?o.width!==n.width:o.height!==n.height)&&t(o),n=o}}(e,t),o=function(){return n({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight})};if(e.scrollElement)return o(),e.scrollElement.addEventListener("resize",o,{capture:!1,passive:!0}),function(){e.scrollElement.removeEventListener("resize",o)}},e.windowScroll=function(e,t,n){var o,r,i=t.adjustments,s=void 0===i?0:i,l=t.behavior,a=e+s;null==(o=n.scrollElement)||null==o.scrollTo||o.scrollTo(((r={})[n.options.horizontal?"left":"top"]=a,r.behavior=l,r))},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VirtualCore={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},t.apply(this,arguments)}function n(e,t,n){var o,i,r=null!=(o=n.initialDeps)?o:[];return function(){var o;n.key&&null!=n.debug&&n.debug()&&(o=Date.now());var s,l=e();if(!(l.length!==r.length||l.some((function(e,t){return r[t]!==e}))))return i;if(r=l,n.key&&null!=n.debug&&n.debug()&&(s=Date.now()),i=t.apply(void 0,l),n.key&&null!=n.debug&&n.debug()){var a=Math.round(100*(Date.now()-o))/100,u=Math.round(100*(Date.now()-s))/100,c=u/16,d=function(e,t){for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+d(u,5)+" /"+d(a,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*c,120))+"deg 100% 31%);",null==n?void 0:n.key)}return null==n||null==n.onChange||n.onChange(i),i}}function o(e,t){if(void 0===e)throw new Error("Unexpected undefined"+(t?": "+t:""));return e}var i=function(e,t){return Math.abs(e-t)<1},r=function(e){return e},s=function(e){for(var t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),o=[],i=t;i<=n;i++)o.push(i);return o},l={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},a=function(e){return function(t,n){if(t.scrollElement){var o=l[e][0],i=l[e][1],r=t.scrollElement[o],s=t.scrollElement[i],a=function(){var e=t.scrollElement[t.options.horizontal?o:i];n(e)};a();var u=function(e){var n=e.currentTarget,l=n[o],u=n[i];(t.options.horizontal?r-l:s-u)&&a(),r=l,s=u};return t.scrollElement.addEventListener("scroll",u,{capture:!1,passive:!0}),function(){t.scrollElement.removeEventListener("scroll",u)}}}},u=a("element"),c=a("window"),d=function(e,t){return Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"])};e.Virtualizer=function(e){var l,a=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache={},this.pendingMeasuredCacheIndexes=[],this.scrollDirection=null,this.scrollAdjustments=0,this.measureElementCache={},this.getResizeObserver=(l=null,function(){return l||("undefined"!=typeof ResizeObserver?l=new ResizeObserver((function(e){e.forEach((function(e){a._measureElement(e.target,!1)}))})):null)}),this.range={startIndex:0,endIndex:0},this.setOptions=function(e){Object.entries(e).forEach((function(t){var n=t[0];void 0===t[1]&&delete e[n]})),a.options=t({debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:r,rangeExtractor:s,onChange:function(){},measureElement:d,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",initialMeasurementsCache:[]},e)},this.notify=function(){null==a.options.onChange||a.options.onChange(a)},this.cleanup=function(){a.unsubs.filter(Boolean).forEach((function(e){return e()})),a.unsubs=[],a.scrollElement=null},this._didMount=function(){var e=a.getResizeObserver();return Object.values(a.measureElementCache).forEach((function(t){return null==e?void 0:e.observe(t)})),function(){null==e||e.disconnect(),a.cleanup()}},this._willUpdate=function(){var e=a.options.getScrollElement();a.scrollElement!==e&&(a.cleanup(),a.scrollElement=e,a._scrollToOffset(a.scrollOffset,{adjustments:void 0,behavior:void 0}),a.unsubs.push(a.options.observeElementRect(a,(function(e){a.scrollRect=e,a.maybeNotify()}))),a.unsubs.push(a.options.observeElementOffset(a,(function(e){a.scrollAdjustments=0,a.scrollOffset!==e&&(null!==a.isScrollingTimeoutId&&(clearTimeout(a.isScrollingTimeoutId),a.isScrollingTimeoutId=null),a.isScrolling=!0,a.scrollDirection=a.scrollOffset<e?"forward":"backward",a.scrollOffset=e,a.maybeNotify(),a.isScrollingTimeoutId=setTimeout((function(){a.isScrollingTimeoutId=null,a.isScrolling=!1,a.scrollDirection=null,a.maybeNotify()}),a.options.scrollingDelay))}))))},this.getSize=function(){return a.scrollRect[a.options.horizontal?"width":"height"]},this.getMeasurements=n((function(){return[a.options.count,a.options.paddingStart,a.options.scrollMargin,a.options.getItemKey,a.itemSizeCache]}),(function(e,t,n,o,i){var r=a.pendingMeasuredCacheIndexes.length>0?Math.min.apply(Math,a.pendingMeasuredCacheIndexes):0;a.pendingMeasuredCacheIndexes=[];for(var s=a.measurementsCache.slice(0,r),l=r;l<e;l++){var u=o(l),c=i[u],d=s[l-1]?s[l-1].end:t+n,f="number"==typeof c?c:a.options.estimateSize(l),h=d+f;s[l]={index:l,start:d,size:f,end:h,key:u}}return a.measurementsCache=s,s}),{key:!1,debug:function(){return a.options.debug}}),this.calculateRange=n((function(){return[a.getMeasurements(),a.getSize(),a.scrollOffset]}),(function(e,t,n){return a.range=function(e){var t=e.measurements,n=e.outerSize,o=e.scrollOffset,i=t.length-1,r=function(e,t,n,o){for(;e<=t;){var i=(e+t)/2|0,r=n(i);if(r<o)e=i+1;else{if(!(r>o))return i;t=i-1}}return e>0?e-1:0}(0,i,(function(e){return t[e].start}),o),s=r;for(;s<i&&t[s].end<o+n;)s++;return{startIndex:r,endIndex:s}}({measurements:e,outerSize:t,scrollOffset:n})}),{key:!1,debug:function(){return a.options.debug}}),this.maybeNotify=n((function(){return[].concat(Object.values(a.calculateRange()),[a.isScrolling])}),(function(){a.notify()}),{key:!1,debug:function(){return a.options.debug},initialDeps:[].concat(Object.values(this.range),[this.isScrolling])}),this.getIndexes=n((function(){return[a.options.rangeExtractor,a.calculateRange(),a.options.overscan,a.options.count]}),(function(e,n,o,i){return e(t({},n,{overscan:o,count:i}))}),{key:!1,debug:function(){return a.options.debug}}),this.indexFromElement=function(e){var t=a.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn("Missing attribute name '"+t+"={index}' on measured element."),-1)},this._measureElement=function(e,n){var o,i=a.indexFromElement(e),r=a.measurementsCache[i];if(r){var s=a.measureElementCache[r.key],l=a.getResizeObserver();if(!e.isConnected)return null==l||l.unobserve(e),void(e===s&&delete a.measureElementCache[r.key]);if(s!==e)s&&(null==l||l.unobserve(s)),null==l||l.observe(e),a.measureElementCache[r.key]=e;else if(!n&&!s.__virtualizerSkipFirstNotSync)return void(s.__virtualizerSkipFirstNotSync=!0);var u,c=a.options.measureElement(e,a),d=c-(null!=(o=a.itemSizeCache[r.key])?o:r.size);if(0!==d)r.start<a.scrollOffset&&a._scrollToOffset(a.scrollOffset,{adjustments:a.scrollAdjustments+=d,behavior:void 0}),a.pendingMeasuredCacheIndexes.push(i),a.itemSizeCache=t({},a.itemSizeCache,((u={})[r.key]=c,u)),a.notify()}},this.measureElement=function(e){e&&a._measureElement(e,!0)},this.getVirtualItems=n((function(){return[a.getIndexes(),a.getMeasurements()]}),(function(e,t){for(var n=[],o=0,i=e.length;o<i;o++){var r=t[e[o]];n.push(r)}return n}),{key:!1,debug:function(){return a.options.debug}}),this.getOffsetForAlignment=function(e,t){var n=a.getSize();"auto"===t&&(t=e<=a.scrollOffset?"start":e>=a.scrollOffset+n?"end":"start"),"start"===t||("end"===t?e-=n:"center"===t&&(e-=n/2));var o=a.options.horizontal?"scrollWidth":"scrollHeight",i=(a.scrollElement?"document"in a.scrollElement?a.scrollElement.document.documentElement[o]:a.scrollElement[o]:0)-a.getSize();return Math.max(Math.min(i,e),0)},this.scrollToOffset=function(e,t){var n=void 0===t?{}:t,o=n.align,i=void 0===o?"start":o,r=n.behavior;if(Object.keys(a.measureElementCache).length>0&&"smooth"===r)console.warn("The `smooth` scroll behavior is not supported with dynamic size.");else{var s={adjustments:void 0,behavior:r,sync:!1};a._scrollToOffset(a.getOffsetForAlignment(e,i),s)}},this.scrollToIndex=function(e,t){var n=void 0===t?{}:t,r=n.align,s=void 0===r?"auto":r,l=n.behavior;e=Math.max(0,Math.min(e,a.options.count-1)),null!==a.scrollToIndexTimeoutId&&(clearTimeout(a.scrollToIndexTimeoutId),a.scrollToIndexTimeoutId=null);var u=Object.keys(a.measureElementCache).length>0;if(u&&"smooth"===l)console.warn("The `smooth` scroll behavior is not supported with dynamic size.");else{var c=o(a.getMeasurements()[e]);if("auto"===s)if(c.end>=a.scrollOffset+a.getSize()-a.options.scrollPaddingEnd)s="end";else{if(!(c.start<=a.scrollOffset+a.options.scrollPaddingStart))return;s="start"}var d=function(e){var t="end"===s?e.end+a.options.scrollPaddingEnd:e.start-a.options.scrollPaddingStart;return a.getOffsetForAlignment(t,s)},f=d(c),h={adjustments:void 0,behavior:l};a._scrollToOffset(f,h),u&&(a.scrollToIndexTimeoutId=setTimeout((function(){if(a.scrollToIndexTimeoutId=null,!!a.measureElementCache[a.options.getItemKey(e)]){var t=d(o(a.getMeasurements()[e]));i(t,a.scrollOffset)||a.scrollToIndex(e,{align:s,behavior:l})}else a.scrollToIndex(e,{align:s,behavior:l})})))}},this.scrollBy=function(e,t){var n=(void 0===t?{}:t).behavior;Object.keys(a.measureElementCache).length>0&&"smooth"===n?console.warn("The `smooth` scroll behavior is not supported with dynamic size."):a._scrollToOffset(a.scrollOffset+e,{adjustments:void 0,behavior:n})},this.getTotalSize=function(){var e;return((null==(e=a.getMeasurements()[a.options.count-1])?void 0:e.end)||a.options.paddingStart)-a.options.scrollMargin+a.options.paddingEnd},this._scrollToOffset=function(e,t){var n=t.adjustments,o=t.behavior;a.options.scrollToFn(e,{behavior:o,adjustments:n},a)},this.measure=function(){a.itemSizeCache={},a.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((function(e){a.itemSizeCache[e.key]=e.size})),this.maybeNotify()},e.approxEqual=i,e.defaultKeyExtractor=r,e.defaultRangeExtractor=s,e.elementScroll=function(e,t,n){var o,i,r=t.adjustments,s=void 0===r?0:r,l=t.behavior,a=e+s;null==(o=n.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[n.options.horizontal?"left":"top"]=a,i.behavior=l,i))},e.measureElement=d,e.memo=n,e.notUndefined=o,e.observeElementOffset=u,e.observeElementRect=function(e,t){var n=new ResizeObserver((function(e){var n=e[0];if(n){var o=n.contentRect,i=o.width,r=o.height;t({width:Math.round(i),height:Math.round(r)})}else t({width:0,height:0})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),n.observe(e.scrollElement),function(){n.unobserve(e.scrollElement)}},e.observeWindowOffset=c,e.observeWindowRect=function(e,t){var n=function(e,t){var n={height:-1,width:-1};return function(o){(e.options.horizontal?o.width!==n.width:o.height!==n.height)&&t(o),n=o}}(e,t),o=function(){return n({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight})};if(e.scrollElement)return o(),e.scrollElement.addEventListener("resize",o,{capture:!1,passive:!0}),function(){e.scrollElement.removeEventListener("resize",o)}},e.windowScroll=function(e,t,n){var o,i,r=t.adjustments,s=void 0===r?0:r,l=t.behavior,a=e+s;null==(o=n.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[n.options.horizontal?"left":"top"]=a,i.behavior=l,i))},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@tanstack/virtual-core",
"author": "Tanner Linsley",
"version": "3.0.0-beta.42",
"version": "3.0.0-beta.43",
"description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -334,3 +334,3 @@ import { approxEqual, memo, notUndefined } from './utils'

this.calculateRange()
this.maybeNotify()
}

@@ -402,3 +402,3 @@

this.scrollRect = rect
this.calculateRange()
this.maybeNotify()
}),

@@ -420,22 +420,15 @@ )

const onIsScrollingChange = (isScrolling: boolean) => {
if (this.isScrolling !== isScrolling) {
this.isScrolling = isScrolling
this.notify()
}
}
this.isScrolling = true
this.scrollDirection =
this.scrollOffset < offset ? 'forward' : 'backward'
this.scrollOffset = offset
this.calculateRange()
this.maybeNotify()
onIsScrollingChange(true)
this.isScrollingTimeoutId = setTimeout(() => {
this.isScrollingTimeoutId = null
this.isScrolling = false
this.scrollDirection = null
onIsScrollingChange(false)
this.maybeNotify()
}, this.options.scrollingDelay)

@@ -494,18 +487,8 @@ }),

() => [this.getMeasurements(), this.getSize(), this.scrollOffset],
(measurements, outerSize, scrollOffset, [flush = true]: [boolean?]) => {
const range = calculateRange({
(measurements, outerSize, scrollOffset) => {
return (this.range = calculateRange({
measurements,
outerSize,
scrollOffset,
})
if (
range.startIndex !== this.range.startIndex ||
range.endIndex !== this.range.endIndex
) {
this.range = range
if (flush) {
this.notify()
}
}
return this.range
}))
},

@@ -518,6 +501,18 @@ {

private maybeNotify = memo(
() => [...Object.values(this.calculateRange()), this.isScrolling],
() => {
this.notify()
},
{
key: process.env.NODE_ENV !== 'production' && 'maybeNotify',
debug: () => this.options.debug,
initialDeps: [...Object.values(this.range), this.isScrolling],
},
)
private getIndexes = memo(
() => [
this.options.rangeExtractor,
this.calculateRange(false),
this.calculateRange(),
this.options.overscan,

@@ -524,0 +519,0 @@ this.options.count,

@@ -5,9 +5,5 @@ export type NoInfer<A extends any> = [A][A extends any ? 0 : never]

export function memo<
TDeps extends readonly any[],
TResult,
FArgs extends readonly any[],
>(
export function memo<TDeps extends readonly any[], TResult>(
getDeps: () => [...TDeps],
fn: (...args: [...TDeps, FArgs]) => TResult,
fn: (...args: NoInfer<[...TDeps]>) => TResult,
opts: {

@@ -17,8 +13,9 @@ key: any

onChange?: (result: TResult) => void
initialDeps?: TDeps
},
) {
let deps: any[] = []
let deps = opts.initialDeps ?? []
let result: TResult | undefined
return (...fArgs: FArgs): TResult => {
return (): TResult => {
let depTime: number

@@ -42,4 +39,3 @@ if (opts.key && opts.debug?.()) depTime = Date.now()

result = fn(...newDeps, fArgs)
opts?.onChange?.(result)
result = fn(...newDeps)

@@ -72,2 +68,4 @@ if (opts.key && opts.debug?.()) {

opts?.onChange?.(result)
return result!

@@ -74,0 +72,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc