Socket
Socket
Sign inDemoInstall

@tanstack/virtual-core

Package Overview
Dependencies
Maintainers
2
Versions
86
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.2 to 3.0.3

3

build/lib/index.esm.js

@@ -318,2 +318,5 @@ /**

return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
if (a.end === b.end) {
return a.index - b.index;
}
return a.end - b.end;

@@ -320,0 +323,0 @@ })[0] : undefined;

@@ -321,2 +321,5 @@ /**

return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
if (a.end === b.end) {
return a.index - b.index;
}
return a.end - b.end;

@@ -323,0 +326,0 @@ })[0] : undefined;

@@ -381,2 +381,5 @@ /**

return furthestMeasurements.size === _this.options.lanes ? Array.from(furthestMeasurements.values()).sort(function (a, b) {
if (a.end === b.end) {
return a.index - b.index;
}
return a.end - b.end;

@@ -383,0 +386,0 @@ })[0] : undefined;

2

build/umd/index.production.js

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

*/
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).VirtualCore={})}(this,(function(e){"use strict";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n.apply(this,arguments)}function t(e,n,t){var o,i,r=null!=(o=t.initialDeps)?o:[];return function(){var o;t.key&&null!=t.debug&&t.debug()&&(o=Date.now());var s,l=e();if(!(l.length!==r.length||l.some((function(e,n){return r[n]!==e}))))return i;if(r=l,t.key&&null!=t.debug&&t.debug()&&(s=Date.now()),i=n.apply(void 0,l),t.key&&null!=t.debug&&t.debug()){var a=Math.round(100*(Date.now()-o))/100,u=Math.round(100*(Date.now()-s))/100,c=u/16,d=function(e,n){for(e=String(e);e.length<n;)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==t?void 0:t.key)}return null==t||null==t.onChange||t.onChange(i),i}}function o(e,n){if(void 0===e)throw new Error("Unexpected undefined"+(n?": "+n:""));return e}var i=function(e,n){return Math.abs(e-n)<1},r=function(e){return e},s=function(e){for(var n=Math.max(e.startIndex-e.overscan,0),t=Math.min(e.endIndex+e.overscan,e.count-1),o=[],i=n;i<=t;i++)o.push(i);return o},l=function(e,n,t){if(null!=n&&n.borderBoxSize){var o=n.borderBoxSize[0];if(o)return Math.round(o[t.options.horizontal?"inlineSize":"blockSize"])}return Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"])},a=function(e,n,t,o){for(;e<=n;){var i=(e+n)/2|0,r=t(i);if(r<o)e=i+1;else{if(!(r>o))return i;n=i-1}}return e>0?e-1:0};e.Virtualizer=function(e){var u,c,d=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollDirection=null,this.scrollAdjustments=0,this.measureElementCache=new Map,this.observer=(u=null,c=function(){return u||("undefined"!=typeof ResizeObserver?u=new ResizeObserver((function(e){e.forEach((function(e){d._measureElement(e.target,e)}))})):null)},{disconnect:function(){var e;return null==(e=c())?void 0:e.disconnect()},observe:function(e){var n;return null==(n=c())?void 0:n.observe(e,{box:"border-box"})},unobserve:function(e){var n;return null==(n=c())?void 0:n.unobserve(e)}}),this.range=null,this.setOptions=function(e){Object.entries(e).forEach((function(n){var t=n[0];void 0===n[1]&&delete e[t]})),d.options=n({debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:r,rangeExtractor:s,onChange:function(){},measureElement:l,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1},e)},this.notify=function(e){null==d.options.onChange||d.options.onChange(d,e)},this.maybeNotify=t((function(){return d.calculateRange(),[d.isScrolling,d.range?d.range.startIndex:null,d.range?d.range.endIndex:null]}),(function(e){d.notify(e)}),{key:!1,debug:function(){return d.options.debug},initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=function(){d.unsubs.filter(Boolean).forEach((function(e){return e()})),d.unsubs=[],d.scrollElement=null},this._didMount=function(){return d.measureElementCache.forEach(d.observer.observe),function(){d.observer.disconnect(),d.cleanup()}},this._willUpdate=function(){var e=d.options.getScrollElement();d.scrollElement!==e&&(d.cleanup(),d.scrollElement=e,d._scrollToOffset(d.scrollOffset,{adjustments:void 0,behavior:void 0}),d.unsubs.push(d.options.observeElementRect(d,(function(e){d.scrollRect=e,d.maybeNotify()}))),d.unsubs.push(d.options.observeElementOffset(d,(function(e){d.scrollAdjustments=0,d.scrollOffset!==e&&(null!==d.isScrollingTimeoutId&&(clearTimeout(d.isScrollingTimeoutId),d.isScrollingTimeoutId=null),d.isScrolling=!0,d.scrollDirection=d.scrollOffset<e?"forward":"backward",d.scrollOffset=e,d.maybeNotify(),d.isScrollingTimeoutId=setTimeout((function(){d.isScrollingTimeoutId=null,d.isScrolling=!1,d.scrollDirection=null,d.maybeNotify()}),d.options.scrollingDelay))}))))},this.getSize=function(){return d.scrollRect[d.options.horizontal?"width":"height"]},this.memoOptions=t((function(){return[d.options.count,d.options.paddingStart,d.options.scrollMargin,d.options.getItemKey]}),(function(e,n,t,o){return d.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:n,scrollMargin:t,getItemKey:o}}),{key:!1}),this.getFurthestMeasurement=function(e,n){for(var t=new Map,o=new Map,i=n-1;i>=0;i--){var r=e[i];if(!t.has(r.lane)){var s=o.get(r.lane);if(null==s||r.end>s.end?o.set(r.lane,r):r.end<s.end&&t.set(r.lane,!0),t.size===d.options.lanes)break}}return o.size===d.options.lanes?Array.from(o.values()).sort((function(e,n){return e.end-n.end}))[0]:void 0},this.getMeasurements=t((function(){return[d.memoOptions(),d.itemSizeCache]}),(function(e,n){var t=e.count,o=e.paddingStart,i=e.scrollMargin,r=e.getItemKey,s=d.pendingMeasuredCacheIndexes.length>0?Math.min.apply(Math,d.pendingMeasuredCacheIndexes):0;d.pendingMeasuredCacheIndexes=[];for(var l=d.measurementsCache.slice(0,s),a=s;a<t;a++){var u=r(a),c=1===d.options.lanes?l[a-1]:d.getFurthestMeasurement(l,a),f=c?c.end:o+i,h=n.get(u),m="number"==typeof h?h:d.options.estimateSize(a),g=f+m,v=c?c.lane:a%d.options.lanes;l[a]={index:a,start:f,size:m,end:g,key:u,lane:v}}return d.measurementsCache=l,l}),{key:!1,debug:function(){return d.options.debug}}),this.calculateRange=t((function(){return[d.getMeasurements(),d.getSize(),d.scrollOffset]}),(function(e,n,t){return d.range=e.length>0&&n>0?function(e){var n=e.measurements,t=e.outerSize,o=e.scrollOffset,i=n.length-1,r=function(e){return n[e].start},s=a(0,i,r,o),l=s;for(;l<i&&n[l].end<o+t;)l++;return{startIndex:s,endIndex:l}}({measurements:e,outerSize:n,scrollOffset:t}):null}),{key:!1,debug:function(){return d.options.debug}}),this.getIndexes=t((function(){return[d.options.rangeExtractor,d.calculateRange(),d.options.overscan,d.options.count]}),(function(e,t,o,i){return null===t?[]:e(n({},t,{overscan:o,count:i}))}),{key:!1,debug:function(){return d.options.debug}}),this.indexFromElement=function(e){var n=d.options.indexAttribute,t=e.getAttribute(n);return t?parseInt(t,10):(console.warn("Missing attribute name '"+n+"={index}' on measured element."),-1)},this._measureElement=function(e,n){var t=d.measurementsCache[d.indexFromElement(e)];if(t&&e.isConnected){var o=d.measureElementCache.get(t.key);o!==e&&(o&&d.observer.unobserve(o),d.observer.observe(e),d.measureElementCache.set(t.key,e));var i=d.options.measureElement(e,n,d);d.resizeItem(t,i)}else d.measureElementCache.forEach((function(n,t){n===e&&(d.observer.unobserve(e),d.measureElementCache.delete(t))}))},this.resizeItem=function(e,n){var t,o=n-(null!=(t=d.itemSizeCache.get(e.key))?t:e.size);0!==o&&(e.start<d.scrollOffset+d.scrollAdjustments&&d._scrollToOffset(d.scrollOffset,{adjustments:d.scrollAdjustments+=o,behavior:void 0}),d.pendingMeasuredCacheIndexes.push(e.index),d.itemSizeCache=new Map(d.itemSizeCache.set(e.key,n)),d.notify(!1))},this.measureElement=function(e){e&&d._measureElement(e,void 0)},this.getVirtualItems=t((function(){return[d.getIndexes(),d.getMeasurements()]}),(function(e,n){for(var t=[],o=0,i=e.length;o<i;o++){var r=n[e[o]];t.push(r)}return t}),{key:!1,debug:function(){return d.options.debug}}),this.getVirtualItemForOffset=function(e){var n=d.getMeasurements();return o(n[a(0,n.length-1,(function(e){return o(n[e]).start}),e)])},this.getOffsetForAlignment=function(e,n){var t=d.getSize();"auto"===n&&(n=e<=d.scrollOffset?"start":e>=d.scrollOffset+t?"end":"start"),"start"===n||("end"===n?e-=t:"center"===n&&(e-=t/2));var o=d.options.horizontal?"scrollWidth":"scrollHeight",i=(d.scrollElement?"document"in d.scrollElement?d.scrollElement.document.documentElement[o]:d.scrollElement[o]:0)-d.getSize();return Math.max(Math.min(i,e),0)},this.getOffsetForIndex=function(e,n){void 0===n&&(n="auto"),e=Math.max(0,Math.min(e,d.options.count-1));var t=o(d.getMeasurements()[e]);if("auto"===n)if(t.end>=d.scrollOffset+d.getSize()-d.options.scrollPaddingEnd)n="end";else{if(!(t.start<=d.scrollOffset+d.options.scrollPaddingStart))return[d.scrollOffset,n];n="start"}var i="end"===n?t.end+d.options.scrollPaddingEnd:t.start-d.options.scrollPaddingStart;return[d.getOffsetForAlignment(i,n),n]},this.isDynamicMode=function(){return d.measureElementCache.size>0},this.cancelScrollToIndex=function(){null!==d.scrollToIndexTimeoutId&&(clearTimeout(d.scrollToIndexTimeoutId),d.scrollToIndexTimeoutId=null)},this.scrollToOffset=function(e,n){var t=void 0===n?{}:n,o=t.align,i=void 0===o?"start":o,r=t.behavior;d.cancelScrollToIndex(),"smooth"===r&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),d._scrollToOffset(d.getOffsetForAlignment(e,i),{adjustments:void 0,behavior:r})},this.scrollToIndex=function(e,n){var t=void 0===n?{}:n,o=t.align,r=void 0===o?"auto":o,s=t.behavior;e=Math.max(0,Math.min(e,d.options.count-1)),d.cancelScrollToIndex(),"smooth"===s&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");var l=d.getOffsetForIndex(e,r),a=l[0],u=l[1];d._scrollToOffset(a,{adjustments:void 0,behavior:s}),"smooth"!==s&&d.isDynamicMode()&&(d.scrollToIndexTimeoutId=setTimeout((function(){if(d.scrollToIndexTimeoutId=null,d.measureElementCache.has(d.options.getItemKey(e))){var n=d.getOffsetForIndex(e,u)[0];i(n,d.scrollOffset)||d.scrollToIndex(e,{align:u,behavior:s})}else d.scrollToIndex(e,{align:u,behavior:s})})))},this.scrollBy=function(e,n){var t=(void 0===n?{}:n).behavior;d.cancelScrollToIndex(),"smooth"===t&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),d._scrollToOffset(d.scrollOffset+e,{adjustments:void 0,behavior:t})},this.getTotalSize=function(){var e;return((null==(e=d.getMeasurements()[d.options.count-1])?void 0:e.end)||d.options.paddingStart)-d.options.scrollMargin+d.options.paddingEnd},this._scrollToOffset=function(e,n){var t=n.adjustments,o=n.behavior;d.options.scrollToFn(e,{behavior:o,adjustments:t},d)},this.measure=function(){d.itemSizeCache=new Map,d.notify(!1)},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((function(e){d.itemSizeCache.set(e.key,e.size)})),this.maybeNotify()},e.approxEqual=i,e.defaultKeyExtractor=r,e.defaultRangeExtractor=s,e.elementScroll=function(e,n,t){var o,i,r=n.adjustments,s=void 0===r?0:r,l=n.behavior,a=e+s;null==(o=t.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[t.options.horizontal?"left":"top"]=a,i.behavior=l,i))},e.measureElement=l,e.memo=t,e.notUndefined=o,e.observeElementOffset=function(e,n){var t=e.scrollElement;if(t){var o=function(){n(t[e.options.horizontal?"scrollLeft":"scrollTop"])};return o(),t.addEventListener("scroll",o,{passive:!0}),function(){t.removeEventListener("scroll",o)}}},e.observeElementRect=function(e,n){var t=e.scrollElement;if(t){var o=function(e){var t=e.width,o=e.height;n({width:Math.round(t),height:Math.round(o)})};o(t.getBoundingClientRect());var i=new ResizeObserver((function(e){var n=e[0];if(null!=n&&n.borderBoxSize){var i=n.borderBoxSize[0];if(i)return void o({width:i.inlineSize,height:i.blockSize})}o(t.getBoundingClientRect())}));return i.observe(t,{box:"border-box"}),function(){i.unobserve(t)}}},e.observeWindowOffset=function(e,n){var t=e.scrollElement;if(t){var o=function(){n(t[e.options.horizontal?"scrollX":"scrollY"])};return o(),t.addEventListener("scroll",o,{passive:!0}),function(){t.removeEventListener("scroll",o)}}},e.observeWindowRect=function(e,n){var t=e.scrollElement;if(t){var o=function(){n({width:t.innerWidth,height:t.innerHeight})};return o(),t.addEventListener("resize",o,{passive:!0}),function(){t.removeEventListener("resize",o)}}},e.windowScroll=function(e,n,t){var o,i,r=n.adjustments,s=void 0===r?0:r,l=n.behavior,a=e+s;null==(o=t.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[t.options.horizontal?"left":"top"]=a,i.behavior=l,i))},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).VirtualCore={})}(this,(function(e){"use strict";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n.apply(this,arguments)}function t(e,n,t){var o,i,r=null!=(o=t.initialDeps)?o:[];return function(){var o;t.key&&null!=t.debug&&t.debug()&&(o=Date.now());var s,l=e();if(!(l.length!==r.length||l.some((function(e,n){return r[n]!==e}))))return i;if(r=l,t.key&&null!=t.debug&&t.debug()&&(s=Date.now()),i=n.apply(void 0,l),t.key&&null!=t.debug&&t.debug()){var a=Math.round(100*(Date.now()-o))/100,u=Math.round(100*(Date.now()-s))/100,c=u/16,d=function(e,n){for(e=String(e);e.length<n;)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==t?void 0:t.key)}return null==t||null==t.onChange||t.onChange(i),i}}function o(e,n){if(void 0===e)throw new Error("Unexpected undefined"+(n?": "+n:""));return e}var i=function(e,n){return Math.abs(e-n)<1},r=function(e){return e},s=function(e){for(var n=Math.max(e.startIndex-e.overscan,0),t=Math.min(e.endIndex+e.overscan,e.count-1),o=[],i=n;i<=t;i++)o.push(i);return o},l=function(e,n,t){if(null!=n&&n.borderBoxSize){var o=n.borderBoxSize[0];if(o)return Math.round(o[t.options.horizontal?"inlineSize":"blockSize"])}return Math.round(e.getBoundingClientRect()[t.options.horizontal?"width":"height"])},a=function(e,n,t,o){for(;e<=n;){var i=(e+n)/2|0,r=t(i);if(r<o)e=i+1;else{if(!(r>o))return i;n=i-1}}return e>0?e-1:0};e.Virtualizer=function(e){var u,c,d=this;this.unsubs=[],this.scrollElement=null,this.isScrolling=!1,this.isScrollingTimeoutId=null,this.scrollToIndexTimeoutId=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollDirection=null,this.scrollAdjustments=0,this.measureElementCache=new Map,this.observer=(u=null,c=function(){return u||("undefined"!=typeof ResizeObserver?u=new ResizeObserver((function(e){e.forEach((function(e){d._measureElement(e.target,e)}))})):null)},{disconnect:function(){var e;return null==(e=c())?void 0:e.disconnect()},observe:function(e){var n;return null==(n=c())?void 0:n.observe(e,{box:"border-box"})},unobserve:function(e){var n;return null==(n=c())?void 0:n.unobserve(e)}}),this.range=null,this.setOptions=function(e){Object.entries(e).forEach((function(n){var t=n[0];void 0===n[1]&&delete e[t]})),d.options=n({debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:r,rangeExtractor:s,onChange:function(){},measureElement:l,initialRect:{width:0,height:0},scrollMargin:0,scrollingDelay:150,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1},e)},this.notify=function(e){null==d.options.onChange||d.options.onChange(d,e)},this.maybeNotify=t((function(){return d.calculateRange(),[d.isScrolling,d.range?d.range.startIndex:null,d.range?d.range.endIndex:null]}),(function(e){d.notify(e)}),{key:!1,debug:function(){return d.options.debug},initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=function(){d.unsubs.filter(Boolean).forEach((function(e){return e()})),d.unsubs=[],d.scrollElement=null},this._didMount=function(){return d.measureElementCache.forEach(d.observer.observe),function(){d.observer.disconnect(),d.cleanup()}},this._willUpdate=function(){var e=d.options.getScrollElement();d.scrollElement!==e&&(d.cleanup(),d.scrollElement=e,d._scrollToOffset(d.scrollOffset,{adjustments:void 0,behavior:void 0}),d.unsubs.push(d.options.observeElementRect(d,(function(e){d.scrollRect=e,d.maybeNotify()}))),d.unsubs.push(d.options.observeElementOffset(d,(function(e){d.scrollAdjustments=0,d.scrollOffset!==e&&(null!==d.isScrollingTimeoutId&&(clearTimeout(d.isScrollingTimeoutId),d.isScrollingTimeoutId=null),d.isScrolling=!0,d.scrollDirection=d.scrollOffset<e?"forward":"backward",d.scrollOffset=e,d.maybeNotify(),d.isScrollingTimeoutId=setTimeout((function(){d.isScrollingTimeoutId=null,d.isScrolling=!1,d.scrollDirection=null,d.maybeNotify()}),d.options.scrollingDelay))}))))},this.getSize=function(){return d.scrollRect[d.options.horizontal?"width":"height"]},this.memoOptions=t((function(){return[d.options.count,d.options.paddingStart,d.options.scrollMargin,d.options.getItemKey]}),(function(e,n,t,o){return d.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:n,scrollMargin:t,getItemKey:o}}),{key:!1}),this.getFurthestMeasurement=function(e,n){for(var t=new Map,o=new Map,i=n-1;i>=0;i--){var r=e[i];if(!t.has(r.lane)){var s=o.get(r.lane);if(null==s||r.end>s.end?o.set(r.lane,r):r.end<s.end&&t.set(r.lane,!0),t.size===d.options.lanes)break}}return o.size===d.options.lanes?Array.from(o.values()).sort((function(e,n){return e.end===n.end?e.index-n.index:e.end-n.end}))[0]:void 0},this.getMeasurements=t((function(){return[d.memoOptions(),d.itemSizeCache]}),(function(e,n){var t=e.count,o=e.paddingStart,i=e.scrollMargin,r=e.getItemKey,s=d.pendingMeasuredCacheIndexes.length>0?Math.min.apply(Math,d.pendingMeasuredCacheIndexes):0;d.pendingMeasuredCacheIndexes=[];for(var l=d.measurementsCache.slice(0,s),a=s;a<t;a++){var u=r(a),c=1===d.options.lanes?l[a-1]:d.getFurthestMeasurement(l,a),f=c?c.end:o+i,h=n.get(u),m="number"==typeof h?h:d.options.estimateSize(a),g=f+m,v=c?c.lane:a%d.options.lanes;l[a]={index:a,start:f,size:m,end:g,key:u,lane:v}}return d.measurementsCache=l,l}),{key:!1,debug:function(){return d.options.debug}}),this.calculateRange=t((function(){return[d.getMeasurements(),d.getSize(),d.scrollOffset]}),(function(e,n,t){return d.range=e.length>0&&n>0?function(e){var n=e.measurements,t=e.outerSize,o=e.scrollOffset,i=n.length-1,r=function(e){return n[e].start},s=a(0,i,r,o),l=s;for(;l<i&&n[l].end<o+t;)l++;return{startIndex:s,endIndex:l}}({measurements:e,outerSize:n,scrollOffset:t}):null}),{key:!1,debug:function(){return d.options.debug}}),this.getIndexes=t((function(){return[d.options.rangeExtractor,d.calculateRange(),d.options.overscan,d.options.count]}),(function(e,t,o,i){return null===t?[]:e(n({},t,{overscan:o,count:i}))}),{key:!1,debug:function(){return d.options.debug}}),this.indexFromElement=function(e){var n=d.options.indexAttribute,t=e.getAttribute(n);return t?parseInt(t,10):(console.warn("Missing attribute name '"+n+"={index}' on measured element."),-1)},this._measureElement=function(e,n){var t=d.measurementsCache[d.indexFromElement(e)];if(t&&e.isConnected){var o=d.measureElementCache.get(t.key);o!==e&&(o&&d.observer.unobserve(o),d.observer.observe(e),d.measureElementCache.set(t.key,e));var i=d.options.measureElement(e,n,d);d.resizeItem(t,i)}else d.measureElementCache.forEach((function(n,t){n===e&&(d.observer.unobserve(e),d.measureElementCache.delete(t))}))},this.resizeItem=function(e,n){var t,o=n-(null!=(t=d.itemSizeCache.get(e.key))?t:e.size);0!==o&&(e.start<d.scrollOffset+d.scrollAdjustments&&d._scrollToOffset(d.scrollOffset,{adjustments:d.scrollAdjustments+=o,behavior:void 0}),d.pendingMeasuredCacheIndexes.push(e.index),d.itemSizeCache=new Map(d.itemSizeCache.set(e.key,n)),d.notify(!1))},this.measureElement=function(e){e&&d._measureElement(e,void 0)},this.getVirtualItems=t((function(){return[d.getIndexes(),d.getMeasurements()]}),(function(e,n){for(var t=[],o=0,i=e.length;o<i;o++){var r=n[e[o]];t.push(r)}return t}),{key:!1,debug:function(){return d.options.debug}}),this.getVirtualItemForOffset=function(e){var n=d.getMeasurements();return o(n[a(0,n.length-1,(function(e){return o(n[e]).start}),e)])},this.getOffsetForAlignment=function(e,n){var t=d.getSize();"auto"===n&&(n=e<=d.scrollOffset?"start":e>=d.scrollOffset+t?"end":"start"),"start"===n||("end"===n?e-=t:"center"===n&&(e-=t/2));var o=d.options.horizontal?"scrollWidth":"scrollHeight",i=(d.scrollElement?"document"in d.scrollElement?d.scrollElement.document.documentElement[o]:d.scrollElement[o]:0)-d.getSize();return Math.max(Math.min(i,e),0)},this.getOffsetForIndex=function(e,n){void 0===n&&(n="auto"),e=Math.max(0,Math.min(e,d.options.count-1));var t=o(d.getMeasurements()[e]);if("auto"===n)if(t.end>=d.scrollOffset+d.getSize()-d.options.scrollPaddingEnd)n="end";else{if(!(t.start<=d.scrollOffset+d.options.scrollPaddingStart))return[d.scrollOffset,n];n="start"}var i="end"===n?t.end+d.options.scrollPaddingEnd:t.start-d.options.scrollPaddingStart;return[d.getOffsetForAlignment(i,n),n]},this.isDynamicMode=function(){return d.measureElementCache.size>0},this.cancelScrollToIndex=function(){null!==d.scrollToIndexTimeoutId&&(clearTimeout(d.scrollToIndexTimeoutId),d.scrollToIndexTimeoutId=null)},this.scrollToOffset=function(e,n){var t=void 0===n?{}:n,o=t.align,i=void 0===o?"start":o,r=t.behavior;d.cancelScrollToIndex(),"smooth"===r&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),d._scrollToOffset(d.getOffsetForAlignment(e,i),{adjustments:void 0,behavior:r})},this.scrollToIndex=function(e,n){var t=void 0===n?{}:n,o=t.align,r=void 0===o?"auto":o,s=t.behavior;e=Math.max(0,Math.min(e,d.options.count-1)),d.cancelScrollToIndex(),"smooth"===s&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");var l=d.getOffsetForIndex(e,r),a=l[0],u=l[1];d._scrollToOffset(a,{adjustments:void 0,behavior:s}),"smooth"!==s&&d.isDynamicMode()&&(d.scrollToIndexTimeoutId=setTimeout((function(){if(d.scrollToIndexTimeoutId=null,d.measureElementCache.has(d.options.getItemKey(e))){var n=d.getOffsetForIndex(e,u)[0];i(n,d.scrollOffset)||d.scrollToIndex(e,{align:u,behavior:s})}else d.scrollToIndex(e,{align:u,behavior:s})})))},this.scrollBy=function(e,n){var t=(void 0===n?{}:n).behavior;d.cancelScrollToIndex(),"smooth"===t&&d.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),d._scrollToOffset(d.scrollOffset+e,{adjustments:void 0,behavior:t})},this.getTotalSize=function(){var e;return((null==(e=d.getMeasurements()[d.options.count-1])?void 0:e.end)||d.options.paddingStart)-d.options.scrollMargin+d.options.paddingEnd},this._scrollToOffset=function(e,n){var t=n.adjustments,o=n.behavior;d.options.scrollToFn(e,{behavior:o,adjustments:t},d)},this.measure=function(){d.itemSizeCache=new Map,d.notify(!1)},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((function(e){d.itemSizeCache.set(e.key,e.size)})),this.maybeNotify()},e.approxEqual=i,e.defaultKeyExtractor=r,e.defaultRangeExtractor=s,e.elementScroll=function(e,n,t){var o,i,r=n.adjustments,s=void 0===r?0:r,l=n.behavior,a=e+s;null==(o=t.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[t.options.horizontal?"left":"top"]=a,i.behavior=l,i))},e.measureElement=l,e.memo=t,e.notUndefined=o,e.observeElementOffset=function(e,n){var t=e.scrollElement;if(t){var o=function(){n(t[e.options.horizontal?"scrollLeft":"scrollTop"])};return o(),t.addEventListener("scroll",o,{passive:!0}),function(){t.removeEventListener("scroll",o)}}},e.observeElementRect=function(e,n){var t=e.scrollElement;if(t){var o=function(e){var t=e.width,o=e.height;n({width:Math.round(t),height:Math.round(o)})};o(t.getBoundingClientRect());var i=new ResizeObserver((function(e){var n=e[0];if(null!=n&&n.borderBoxSize){var i=n.borderBoxSize[0];if(i)return void o({width:i.inlineSize,height:i.blockSize})}o(t.getBoundingClientRect())}));return i.observe(t,{box:"border-box"}),function(){i.unobserve(t)}}},e.observeWindowOffset=function(e,n){var t=e.scrollElement;if(t){var o=function(){n(t[e.options.horizontal?"scrollX":"scrollY"])};return o(),t.addEventListener("scroll",o,{passive:!0}),function(){t.removeEventListener("scroll",o)}}},e.observeWindowRect=function(e,n){var t=e.scrollElement;if(t){var o=function(){n({width:t.innerWidth,height:t.innerHeight})};return o(),t.addEventListener("resize",o,{passive:!0}),function(){t.removeEventListener("resize",o)}}},e.windowScroll=function(e,n,t){var o,i,r=n.adjustments,s=void 0===r?0:r,l=n.behavior,a=e+s;null==(o=t.scrollElement)||null==o.scrollTo||o.scrollTo(((i={})[t.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.2",
"version": "3.0.3",
"description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",

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

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

? Array.from(furthestMeasurements.values()).sort(
(a, b) => a.end - b.end,
(a, b) => {
if (a.end === b.end) {
return a.index - b.index;
}
return a.end - b.end;
},
)[0]

@@ -509,0 +515,0 @@ : undefined

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