(function(u,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("../../core/plugin/base-plugin")):typeof define=="function"&&define.amd?define(["exports","../../core/plugin/base-plugin"],a):(u=typeof globalThis<"u"?globalThis:u||self,a(u.TbwGridPlugin_columnVirtualization={},u.TbwGrid))})(this,(function(u,a){"use strict";function f(e){if(e==null)return 100;if(typeof e=="number")return e;const t=parseFloat(e);return isNaN(t)?100:t}function d(e){return e.map(t=>f(t.width))}function c(e){const t=[];let i=0;for(const s of e)t.push(i),i+=f(s.width);return t}function g(e){return e.reduce((t,i)=>t+f(i.width),0)}function m(e,t,i,s,l){const o=i.length;if(o===0)return{startCol:0,endCol:0,visibleColumns:[]};let n=p(e,i,s);n=Math.max(0,n-l);const V=e+t;let h=n;for(let r=n;r<o;r++){if(i[r]>=V){h=r-1;break}h=r}h=Math.min(o-1,h+l);const C=[];for(let r=n;r<=h;r++)C.push(r);return{startCol:n,endCol:h,visibleColumns:C}}function p(e,t,i){let s=0,l=t.length-1;for(;s<l;){const o=Math.floor((s+l)/2);t[o]+i[o]<=e?s=o+1:l=o}return s}function W(e,t,i){return i?e>t:!1}class b extends a.BaseGridPlugin{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];attach(t){super.attach(t);const i=this.columns;this.columnWidths=d(i),this.columnOffsets=c(i),this.totalWidth=g(i),this.endCol=i.length-1}detach(){this.columnWidths=[],this.columnOffsets=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}processColumns(t){const i=W(t.length,this.config.threshold??30,this.config.autoEnable??!0);if(this.isVirtualized=i??!1,this.columnWidths=d(t),this.columnOffsets=c(t),this.totalWidth=g(t),!i)return this.startCol=0,this.endCol=t.length-1,[...t];const s=this.grid.clientWidth||800,l=m(this.scrollLeft,s,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=l.startCol,this.endCol=l.endCol,l.visibleColumns.map(o=>t[o])}afterRender(){if(!this.isVirtualized)return;const t=this.gridElement;if(!t)return;const i=this.columnOffsets[this.startCol]??0,s=t.querySelector(".header-row"),l=t.querySelectorAll(".data-grid-row");s&&(s.style.paddingLeft=`${i}px`),l.forEach(n=>{n.style.paddingLeft=`${i}px`});const o=t.querySelector(".rows-viewport .rows");o&&(o.style.width=`${this.totalWidth}px`)}onScroll(t){!this.isVirtualized||Math.abs(t.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=t.scrollLeft,this.requestRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(t){const i=this.columnOffsets[t]??0,s=this.grid;s.scrollLeft=i}getColumnOffset(t){return this.columnOffsets[t]??0}getTotalWidth(){return this.totalWidth}}u.ColumnVirtualizationPlugin=b,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=column-virtualization.umd.js.map
