Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tanstack/virtual-core

Package Overview
Dependencies
Maintainers
1
Versions
87
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.15 to 3.0.0-beta.16

1

build/cjs/index.js

@@ -446,2 +446,3 @@ /**

this.scrollOffset = this.options.initialOffset;
this.calculateRange();
}

@@ -448,0 +449,0 @@

@@ -481,2 +481,3 @@ /**

this.scrollOffset = this.options.initialOffset;
this.calculateRange();
}

@@ -483,0 +484,0 @@

28

build/stats.json

@@ -13,7 +13,7 @@ {

{
"uid": "7b43-5",
"uid": "9482-5",
"name": "utils.ts"
},
{
"uid": "7b43-7",
"uid": "9482-7",
"name": "index.ts"

@@ -29,20 +29,20 @@ }

"nodeParts": {
"7b43-5": {
"9482-5": {
"renderedLength": 1432,
"gzipLength": 544,
"brotliLength": 0,
"mainUid": "7b43-4"
"mainUid": "9482-4"
},
"7b43-7": {
"renderedLength": 14182,
"gzipLength": 3228,
"9482-7": {
"renderedLength": 14211,
"gzipLength": 3232,
"brotliLength": 0,
"mainUid": "7b43-6"
"mainUid": "9482-6"
}
},
"nodeMetas": {
"7b43-4": {
"9482-4": {
"id": "/packages/virtual-core/src/utils.ts",
"moduleParts": {
"index.production.js": "7b43-5"
"index.production.js": "9482-5"
},

@@ -52,14 +52,14 @@ "imported": [],

{
"uid": "7b43-6"
"uid": "9482-6"
}
]
},
"7b43-6": {
"9482-6": {
"id": "/packages/virtual-core/src/index.ts",
"moduleParts": {
"index.production.js": "7b43-7"
"index.production.js": "9482-7"
},
"imported": [
{
"uid": "7b43-4"
"uid": "9482-4"
}

@@ -66,0 +66,0 @@ ],

@@ -487,2 +487,3 @@ /**

this.scrollOffset = this.options.initialOffset;
this.calculateRange();
}

@@ -489,0 +490,0 @@

@@ -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(e,t,s){let n,o=[];return()=>{let i;s.key&&null!=s.debug&&s.debug()&&(i=Date.now());const l=e();if(!(l.length!==o.length||l.some(((e,t)=>o[t]!==e))))return n;let r;if(o=l,s.key&&null!=s.debug&&s.debug()&&(r=Date.now()),n=t(...l),null==s||null==s.onChange||s.onChange(n),s.key&&null!=s.debug&&s.debug()){const e=Math.round(100*(Date.now()-i))/100,t=Math.round(100*(Date.now()-r))/100,n=t/16,o=(e,t)=>{for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+o(t,5)+" /"+o(e,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*n,120))+"deg 100% 31%);",null==s?void 0:s.key)}return n}}const s=e=>e,n=e=>{const t=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let e=t;e<=s;e++)n.push(e);return n},o={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},i=e=>(t,s)=>{if(!t.scrollElement)return;const n=o[e][0],i=o[e][1];let l=t.scrollElement[n],r=t.scrollElement[i];const h=()=>{s(t.scrollElement[t.options.horizontal?n:i])};h();const a=e=>{const s=e.currentTarget,o=s[n],a=s[i];(t.options.horizontal?l-o:r-a)&&h(),l=o,r=a};return t.scrollElement.addEventListener("scroll",a,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",a)}},l=i("element"),r=i("window"),h=(e,t)=>e.getBoundingClientRect()[t.options.horizontal?"width":"height"];e.Virtualizer=class{constructor(e){var o=this;this.unsubs=[],this.scrollElement=null,this.measurementsCache=[],this.itemMeasurementsCache={},this.pendingMeasuredCacheIndexes=[],this.measureElementCache={},this.range={startIndex:0,endIndex:0},this.setOptions=e=>{Object.entries(e).forEach((t=>{let[s,n]=t;void 0===n&&delete e[s]})),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:s,rangeExtractor:n,enableSmoothScroll:!0,onChange:()=>{},measureElement:h,initialRect:{width:0,height:0},...e}},this.notify=()=>{var e,t;null==(e=(t=this.options).onChange)||e.call(t,this)},this.cleanup=()=>{this.unsubs.filter(Boolean).forEach((e=>e())),this.unsubs=[],this.scrollElement=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{const e=this.options.getScrollElement();this.scrollElement!==e&&(this.cleanup(),this.scrollElement=e,this.unsubs.push(this.options.observeElementRect(this,(e=>{this.scrollRect=e,this.calculateRange()}))),this.unsubs.push(this.options.observeElementOffset(this,(e=>{this.scrollOffset=e,this.calculateRange()}))))},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=t((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const o=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const i=this.measurementsCache.slice(0,o);for(let l=o;l<e;l++){const e=s(l),o=n[e],r=i[l-1]?i[l-1].end:t,h="number"==typeof o?o:this.options.estimateSize(l),a=r+h;i[l]={index:l,start:r,size:h,end:a,key:e}}return this.measurementsCache=i,i}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=t((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const o=t.length-1,i=((e,t,s,n)=>{for(;e<=t;){const o=(e+t)/2|0,i=s(o);if(i<n)e=o+1;else{if(!(i>n))return o;t=o-1}}return e>0?e-1:0})(0,o,(e=>t[e].start),n);let l=i;for(;l<o&&t[l].end<n+s;)l++;return{startIndex:i,endIndex:l}}({measurements:e,outerSize:t,scrollOffset:s});return n.startIndex===this.range.startIndex&&n.endIndex===this.range.endIndex||(this.range=n,this.notify()),this.range}),{key:!1,debug:()=>this.options.debug}),this.getIndexes=t((()=>[this.options.rangeExtractor,this.range,this.options.overscan,this.options.count]),((e,t,s,n)=>e({...t,overscan:s,count:n})),{key:!1,debug:()=>this.options.debug}),this.getVirtualItems=t((()=>[this.getIndexes(),this.getMeasurements(),this.options.measureElement]),((e,t,s)=>{const n=e=>t=>{var n;const o=this.measurementsCache[e];if(!t)return;const i=s(t,this),l=null!=(n=this.itemMeasurementsCache[o.key])?n:o.size;i!==l&&(o.start<this.scrollOffset&&(this.destinationOffset||this._scrollToOffset(this.scrollOffset+(i-l),!1)),this.pendingMeasuredCacheIndexes.push(e),this.itemMeasurementsCache={...this.itemMeasurementsCache,[o.key]:i},this.notify())},o=[],i={};for(let s=0,r=e.length;s<r;s++){var l;const r=e[s],h={...t[r],measureElement:i[r]=null!=(l=this.measureElementCache[r])?l:n(r)};o.push(h)}return this.measureElementCache=i,o}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,t){let{align:s}=void 0===t?{align:"start"}:t;const n=o.scrollOffset,i=o.getSize();"auto"===s&&(s=e<=n?"start":e>=n+i?"end":"start"),"start"===s?o._scrollToOffset(e,!0):"end"===s?o._scrollToOffset(e-i,!0):"center"===s&&o._scrollToOffset(e-i/2,!0)},this.scrollToIndex=function(e,t){let{align:s,...n}=void 0===t?{align:"auto"}:t;const i=o.getMeasurements(),l=o.scrollOffset,r=o.getSize(),{count:h}=o.options,a=i[Math.max(0,Math.min(e,h-1))];if(!a)return;if("auto"===s)if(a.end>=l+r-o.options.scrollPaddingEnd)s="end";else{if(!(a.start<=l+o.options.scrollPaddingStart))return;s="start"}const c="end"===s?a.end+o.options.scrollPaddingEnd:a.start-o.options.scrollPaddingStart;o.scrollToOffset(c,{align:s,...n})},this.getTotalSize=()=>{var e;return((null==(e=this.getMeasurements()[this.options.count-1])?void 0:e.end)||this.options.paddingStart)+this.options.paddingEnd},this._scrollToOffset=(e,t)=>{let s;clearTimeout(this.scrollCheckFrame),this.destinationOffset=e,this.options.scrollToFn(e,this.options.enableSmoothScroll&&t,this);const n=()=>{let e=this.scrollOffset;this.scrollCheckFrame=s=setTimeout((()=>{this.scrollCheckFrame===s&&(this.scrollOffset!==e?(e=this.scrollOffset,n()):this.destinationOffset=void 0)}),100)};n()},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset}},e.defaultKeyExtractor=s,e.defaultRangeExtractor=n,e.elementScroll=(e,t,s)=>{var n;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:e,behavior:t?"smooth":void 0})},e.measureElement=h,e.memo=t,e.observeElementOffset=l,e.observeElementRect=(e,t)=>{const s=new ResizeObserver((e=>{var s,n;t({width:null==(s=e[0])?void 0:s.contentRect.width,height:null==(n=e[0])?void 0:n.contentRect.height})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),s.observe(e.scrollElement),()=>{s.unobserve(e.scrollElement)}},e.observeWindowOffset=r,e.observeWindowRect=(e,t)=>{const s=((e,t)=>{let s={height:-1,width:-1};return n=>{(e.options.horizontal?n.width!==s.width:n.height!==s.height)&&t(n),s=n}})(e,t),n=()=>s({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight});if(e.scrollElement)return n(),e.scrollElement.addEventListener("resize",n,{capture:!1,passive:!0}),()=>{e.scrollElement.removeEventListener("resize",n)}},e.windowScroll=(e,t,s)=>{var n;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:e,behavior:t?"smooth":void 0})},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(e,t,s){let n,o=[];return()=>{let i;s.key&&null!=s.debug&&s.debug()&&(i=Date.now());const l=e();if(!(l.length!==o.length||l.some(((e,t)=>o[t]!==e))))return n;let r;if(o=l,s.key&&null!=s.debug&&s.debug()&&(r=Date.now()),n=t(...l),null==s||null==s.onChange||s.onChange(n),s.key&&null!=s.debug&&s.debug()){const e=Math.round(100*(Date.now()-i))/100,t=Math.round(100*(Date.now()-r))/100,n=t/16,o=(e,t)=>{for(e=String(e);e.length<t;)e=" "+e;return e};console.info("%c⏱ "+o(t,5)+" /"+o(e,5)+" ms","\n font-size: .6rem;\n font-weight: bold;\n color: hsl("+Math.max(0,Math.min(120-120*n,120))+"deg 100% 31%);",null==s?void 0:s.key)}return n}}const s=e=>e,n=e=>{const t=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let e=t;e<=s;e++)n.push(e);return n},o={element:["scrollLeft","scrollTop"],window:["scrollX","scrollY"]},i=e=>(t,s)=>{if(!t.scrollElement)return;const n=o[e][0],i=o[e][1];let l=t.scrollElement[n],r=t.scrollElement[i];const h=()=>{s(t.scrollElement[t.options.horizontal?n:i])};h();const a=e=>{const s=e.currentTarget,o=s[n],a=s[i];(t.options.horizontal?l-o:r-a)&&h(),l=o,r=a};return t.scrollElement.addEventListener("scroll",a,{capture:!1,passive:!0}),()=>{t.scrollElement.removeEventListener("scroll",a)}},l=i("element"),r=i("window"),h=(e,t)=>e.getBoundingClientRect()[t.options.horizontal?"width":"height"];e.Virtualizer=class{constructor(e){var o=this;this.unsubs=[],this.scrollElement=null,this.measurementsCache=[],this.itemMeasurementsCache={},this.pendingMeasuredCacheIndexes=[],this.measureElementCache={},this.range={startIndex:0,endIndex:0},this.setOptions=e=>{Object.entries(e).forEach((t=>{let[s,n]=t;void 0===n&&delete e[s]})),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:s,rangeExtractor:n,enableSmoothScroll:!0,onChange:()=>{},measureElement:h,initialRect:{width:0,height:0},...e}},this.notify=()=>{var e,t;null==(e=(t=this.options).onChange)||e.call(t,this)},this.cleanup=()=>{this.unsubs.filter(Boolean).forEach((e=>e())),this.unsubs=[],this.scrollElement=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{const e=this.options.getScrollElement();this.scrollElement!==e&&(this.cleanup(),this.scrollElement=e,this.unsubs.push(this.options.observeElementRect(this,(e=>{this.scrollRect=e,this.calculateRange()}))),this.unsubs.push(this.options.observeElementOffset(this,(e=>{this.scrollOffset=e,this.calculateRange()}))))},this.getSize=()=>this.scrollRect[this.options.horizontal?"width":"height"],this.getMeasurements=t((()=>[this.options.count,this.options.paddingStart,this.options.getItemKey,this.itemMeasurementsCache]),((e,t,s,n)=>{const o=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const i=this.measurementsCache.slice(0,o);for(let l=o;l<e;l++){const e=s(l),o=n[e],r=i[l-1]?i[l-1].end:t,h="number"==typeof o?o:this.options.estimateSize(l),a=r+h;i[l]={index:l,start:r,size:h,end:a,key:e}}return this.measurementsCache=i,i}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=t((()=>[this.getMeasurements(),this.getSize(),this.scrollOffset]),((e,t,s)=>{const n=function(e){let{measurements:t,outerSize:s,scrollOffset:n}=e;const o=t.length-1,i=((e,t,s,n)=>{for(;e<=t;){const o=(e+t)/2|0,i=s(o);if(i<n)e=o+1;else{if(!(i>n))return o;t=o-1}}return e>0?e-1:0})(0,o,(e=>t[e].start),n);let l=i;for(;l<o&&t[l].end<n+s;)l++;return{startIndex:i,endIndex:l}}({measurements:e,outerSize:t,scrollOffset:s});return n.startIndex===this.range.startIndex&&n.endIndex===this.range.endIndex||(this.range=n,this.notify()),this.range}),{key:!1,debug:()=>this.options.debug}),this.getIndexes=t((()=>[this.options.rangeExtractor,this.range,this.options.overscan,this.options.count]),((e,t,s,n)=>e({...t,overscan:s,count:n})),{key:!1,debug:()=>this.options.debug}),this.getVirtualItems=t((()=>[this.getIndexes(),this.getMeasurements(),this.options.measureElement]),((e,t,s)=>{const n=e=>t=>{var n;const o=this.measurementsCache[e];if(!t)return;const i=s(t,this),l=null!=(n=this.itemMeasurementsCache[o.key])?n:o.size;i!==l&&(o.start<this.scrollOffset&&(this.destinationOffset||this._scrollToOffset(this.scrollOffset+(i-l),!1)),this.pendingMeasuredCacheIndexes.push(e),this.itemMeasurementsCache={...this.itemMeasurementsCache,[o.key]:i},this.notify())},o=[],i={};for(let s=0,r=e.length;s<r;s++){var l;const r=e[s],h={...t[r],measureElement:i[r]=null!=(l=this.measureElementCache[r])?l:n(r)};o.push(h)}return this.measureElementCache=i,o}),{key:!1,debug:()=>this.options.debug}),this.scrollToOffset=function(e,t){let{align:s}=void 0===t?{align:"start"}:t;const n=o.scrollOffset,i=o.getSize();"auto"===s&&(s=e<=n?"start":e>=n+i?"end":"start"),"start"===s?o._scrollToOffset(e,!0):"end"===s?o._scrollToOffset(e-i,!0):"center"===s&&o._scrollToOffset(e-i/2,!0)},this.scrollToIndex=function(e,t){let{align:s,...n}=void 0===t?{align:"auto"}:t;const i=o.getMeasurements(),l=o.scrollOffset,r=o.getSize(),{count:h}=o.options,a=i[Math.max(0,Math.min(e,h-1))];if(!a)return;if("auto"===s)if(a.end>=l+r-o.options.scrollPaddingEnd)s="end";else{if(!(a.start<=l+o.options.scrollPaddingStart))return;s="start"}const c="end"===s?a.end+o.options.scrollPaddingEnd:a.start-o.options.scrollPaddingStart;o.scrollToOffset(c,{align:s,...n})},this.getTotalSize=()=>{var e;return((null==(e=this.getMeasurements()[this.options.count-1])?void 0:e.end)||this.options.paddingStart)+this.options.paddingEnd},this._scrollToOffset=(e,t)=>{let s;clearTimeout(this.scrollCheckFrame),this.destinationOffset=e,this.options.scrollToFn(e,this.options.enableSmoothScroll&&t,this);const n=()=>{let e=this.scrollOffset;this.scrollCheckFrame=s=setTimeout((()=>{this.scrollCheckFrame===s&&(this.scrollOffset!==e?(e=this.scrollOffset,n()):this.destinationOffset=void 0)}),100)};n()},this.measure=()=>{this.itemMeasurementsCache={},this.notify()},this.setOptions(e),this.scrollRect=this.options.initialRect,this.scrollOffset=this.options.initialOffset,this.calculateRange()}},e.defaultKeyExtractor=s,e.defaultRangeExtractor=n,e.elementScroll=(e,t,s)=>{var n;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:e,behavior:t?"smooth":void 0})},e.measureElement=h,e.memo=t,e.observeElementOffset=l,e.observeElementRect=(e,t)=>{const s=new ResizeObserver((e=>{var s,n;t({width:null==(s=e[0])?void 0:s.contentRect.width,height:null==(n=e[0])?void 0:n.contentRect.height})}));if(e.scrollElement)return t(e.scrollElement.getBoundingClientRect()),s.observe(e.scrollElement),()=>{s.unobserve(e.scrollElement)}},e.observeWindowOffset=r,e.observeWindowRect=(e,t)=>{const s=((e,t)=>{let s={height:-1,width:-1};return n=>{(e.options.horizontal?n.width!==s.width:n.height!==s.height)&&t(n),s=n}})(e,t),n=()=>s({width:e.scrollElement.innerWidth,height:e.scrollElement.innerHeight});if(e.scrollElement)return n(),e.scrollElement.addEventListener("resize",n,{capture:!1,passive:!0}),()=>{e.scrollElement.removeEventListener("resize",n)}},e.windowScroll=(e,t,s)=>{var n;null==(n=s.scrollElement)||null==n.scrollTo||n.scrollTo({[s.options.horizontal?"left":"top"]:e,behavior:t?"smooth":void 0})},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@tanstack/virtual-core",
"author": "Tanner Linsley",
"version": "3.0.0-beta.15",
"version": "3.0.0-beta.16",
"description": "Headless UI for virtualizing scrollable elements in TS/JS + Frameworks",

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

@@ -281,2 +281,4 @@ import { memo } from './utils'

this.scrollOffset = this.options.initialOffset
this.calculateRange()
}

@@ -283,0 +285,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

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