@gp-grid/core 0.16.0 → 0.17.0

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.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const e=(e,t,n,r,i)=>{let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null};var t=class{active=!1;colIndex=-1;startX=0;initialWidth=0;currentWidth=0;core;constructor(e){this.core=e}get isActive(){return this.active}start(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.colIndex=e,this.startX=n.clientX,this.initialWidth=t,this.currentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}move(e,t){let n=this.core.getColumns()[this.colIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.initialWidth+(e.clientX-this.startX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.currentWidth=a;let o=e.clientX-t.left>t.width-40?10:0,s=o===0?null:{dx:o,dy:0};return{targetRow:0,targetCol:this.colIndex,autoScroll:s}}end(){this.active&&this.core.setColumnWidth(this.colIndex,this.currentWidth),this.active=!1,this.colIndex=-1}getState(){return this.active===!1?null:{colIndex:this.colIndex,initialWidth:this.initialWidth,currentWidth:this.currentWidth}}};const n=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},r=e=>e.at(-1)??0,i=(e,t)=>{let i=n(e),a=r(i);if(t<=a||a===0)return{positions:i,widths:e.map(e=>e.width)};let o=t/a,s=e.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},a=(e,t)=>{for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t.at(-1)?t.length-2:0},o=e=>({minRow:Math.min(e.startRow,e.endRow),maxRow:Math.max(e.startRow,e.endRow),minCol:Math.min(e.startCol,e.endCol),maxCol:Math.max(e.startCol,e.endCol)}),s=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,c=(e,t,n)=>n?s(e,t,o(n)):!1,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,d=(e,t,n)=>n?.row===e&&n?.col===t,f=(e,t,n,r,i)=>{if(!n||!r||!i)return!1;let{minRow:a,maxRow:s,minCol:c,maxCol:l}=o(r),u=i.row>s,d=i.row<a;return u?e>s&&e<=i.row&&t>=c&&t<=l:d?e<a&&e>=i.row&&t>=c&&t<=l:!1},p=(e,t,n,r)=>{let i=[`gp-grid-cell`];return e&&i.push(`gp-grid-cell--active`),t&&!e&&i.push(`gp-grid-cell--selected`),n&&i.push(`gp-grid-cell--editing`),r&&i.push(`gp-grid-cell--fill-preview`),i.join(` `)},m=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=o(t);return e>=n&&e<=r},h=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=o(t);return e>=n&&e<=r};function g(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function _(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r.at(-1)]=n)}const v=()=>{let e=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),emit:t=>{for(let n of e)n(t)},clearListeners:()=>{e=[]}}},ee=()=>{let e=v(),t=[];return{onInstruction:e.onInstruction,onBatchInstruction:e=>(t.push(e),()=>{t=t.filter(t=>t!==e)}),emit:n=>{e.emit(n);for(let e of t)e([n])},emitBatch:n=>{if(n.length!==0){for(let e of t)e(n);for(let t of n)e.emit(t)}},clearListeners:()=>{e.clearListeners(),t=[]}}},te=(e,t)=>{for(let n of e.values())if(n.rowIndex===t)return n;return null},ne=(e,t,n,r,i,a=0)=>{let o=te(i,n);if(!o){t.scrollTop=e.getScrollTopForRow(n);return}let s=a+o.translateY-t.scrollTop,c=s+r;if(s<0)t.scrollTop=e.getScrollTopForRow(n);else if(c>t.clientHeight){let i=Math.floor(t.clientHeight/r),a=Math.max(0,n-i+1);t.scrollTop=e.getScrollTopForRow(a)}},y=(e,t)=>e==null?``:t?t(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e instanceof Date?String(e):JSON.stringify(e):String(e),re=e=>{let{activeCell:t,selectionRange:n,slots:r,columns:i,visibleColumnsWithIndices:a,columnPositions:o,columnWidths:s,rowHeight:c}=e;if(!t&&!n)return null;let l,u,d,f;if(n)l=Math.max(n.startRow,n.endRow),u=Math.max(n.startCol,n.endCol),d=Math.min(n.startCol,n.endCol),f=Math.max(n.startCol,n.endCol);else if(t)l=t.row,u=t.col,d=u,f=u;else return null;for(let e=d;e<=f;e++){let t=i[e];if(!(!t||t.hidden)&&t.editable!==!0)return null}let p=a.findIndex(e=>e.originalIndex===u);if(p===-1)return null;let m=null;for(let e of r.values())if(e.rowIndex===l){m=e.translateY;break}if(m===null)return null;let h=o[p]??0,g=s[p]??0;return{top:m+c-5,left:h+g-20}},ie=(e,t,n=8)=>{let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.bottom+4,o=r.left,s=Math.max(200,r.width);return o+i.width>window.innerWidth-n&&(o=window.innerWidth-i.width-n),o=Math.max(n,o),a+i.height>window.innerHeight-n&&(a=r.top-i.height-4),a=Math.max(n,a),{top:a,left:o,minWidth:s}},ae=e=>{if(!e||e.length===0)return;let t={};for(let n of e)n.valueFormatter&&(t[n.colId??n.field]=n.valueFormatter);return Object.keys(t).length>0?t:void 0},b=e=>({range:e.range,sort:e.sortModel.length>0?e.sortModel:void 0,filter:Object.keys(e.filterModel).length>0?e.filterModel:void 0,valueFormatters:ae(e.columns)}),oe=(e,t,n)=>{let r=e.get(t);if(r!==void 0){if(t<n){let i=n-1;for(let n=t;n<i;n++){let t=e.get(n+1);t===void 0?e.delete(n):e.set(n,t)}e.set(i,r);return}for(let r=t;r>n;r--){let t=e.get(r-1);t===void 0?e.delete(r):e.set(r,t)}e.set(n,r)}},se=e=>{let t=[0],n=0;for(let r of e)r.hidden||(n+=r.width,t.push(n));return t},ce=(e,t,n,r)=>{let i=e.get(n);if(!i)return null;let a=t[r];return a?g(i,a.field):null},le=(e,t,n,r,i,a)=>{let o=e.get(n);if(!o||typeof o!=`object`)return;let s=t[r];if(!s)return;let c=a.onCellValueChanged!==void 0,l=c?g(o,s.field):void 0;_(o,s.field,i),c&&a.onCellValueChanged({rowId:a.getRowId(o),colIndex:r,field:s.field,oldValue:l,newValue:i,rowData:o})};var ue=class{active=!1;sourceColIndex=-1;startX=0;startY=0;thresholdMet=!1;shiftKey=!1;ghostWidth=0;ghostHeight=0;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.sourceColIndex=e,this.startX=r.clientX,this.startY=r.clientY,this.thresholdMet=!1,this.shiftKey=r.shiftKey,this.ghostWidth=t,this.ghostHeight=n,this.currentX=r.clientX,this.currentY=r.clientY,this.dropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}move(e,t){let n=e.clientX-this.startX,r=e.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.thresholdMet=!0}this.currentX=e.clientX,this.currentY=e.clientY;let{left:i,width:o,scrollLeft:s}=t,c=e.clientX-i+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.dropTargetIndex=Math.max(0,Math.min(a(c,l),u));let d=e.clientX-i,f=0;d<40?f=-10:d>o-40&&(f=10);let p=f===0?null:{dx:f,dy:0};return{targetRow:0,targetCol:this.dropTargetIndex??0,autoScroll:p}}end(e){this.thresholdMet?this.commitMove():this.treatAsHeaderClick(e),this.reset()}commitMove(){if(this.dropTargetIndex===null)return;let e=this.sourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.dropTargetIndex,this.deps.getColumnCount()-1)):this.dropTargetIndex;e!==t&&this.core.moveColumn(e,t)}treatAsHeaderClick(e){let t=this.core.getColumns()[this.sourceColIndex];if(!t)return;let n=t.colId??t.field,r=this.core.getSortModel().find(e=>e.colId===n)?.direction;this.core.setSort(n,e(r),this.shiftKey)}reset(){this.active=!1,this.sourceColIndex=-1,this.thresholdMet=!1,this.shiftKey=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceColIndex:this.sourceColIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,ghostWidth:this.ghostWidth,ghostHeight:this.ghostHeight}}},de=class{active=!1;sourceRowIndex=-1;startX=0;startY=0;thresholdMet=!1;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n){this.active=!0,this.sourceRowIndex=e,this.startX=t,this.startY=n,this.thresholdMet=!1,this.currentX=t,this.currentY=n,this.dropTargetIndex=null}move(t,n){let r=t.clientX-this.startX,i=t.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(r)>5||Math.abs(i)>5))return null;this.thresholdMet=!0}this.currentX=t.clientX,this.currentY=t.clientY;let{top:a,left:o,height:s,width:c,scrollTop:l}=n,u=this.deps.getHeaderHeight(),d=t.clientY-a,f=this.core.getRowCount(),p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(d,l),f));return this.dropTargetIndex=p,{targetRow:p,targetCol:0,autoScroll:e(t.clientY-a,t.clientX-o,s,c,u)}}end(){this.thresholdMet&&this.dropTargetIndex!==null&&this.dropTargetIndex!==this.sourceRowIndex&&this.core.commitRowDrag(this.sourceRowIndex,this.dropTargetIndex),this.active=!1,this.sourceRowIndex=-1,this.thresholdMet=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceRowIndex:this.sourceRowIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,dropIndicatorY:this.dropTargetIndex===null?0:this.core.getRowTranslateY(this.dropTargetIndex)}}},fe=class{active=!1;core;constructor(e){this.core=e}get isActive(){return this.active}start(){this.active=!0}moveToTarget(e,t){this.active!==!1&&this.core.selection.startSelection({row:e,col:t},{shift:!0})}end(){this.active=!1}},pe=class{active=!1;sourceRange=null;target=null;core;constructor(e){this.core=e}get isActive(){return this.active}get stateSnapshot(){return{sourceRange:this.sourceRange,target:this.target}}start(e,t){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let n=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(n),this.sourceRange=n,this.target={row:Math.max(n.startRow,n.endRow),col:Math.max(n.startCol,n.endCol)},this.active=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}moveToTarget(e,t){this.active!==!1&&(this.core.fill.updateFillDrag(e,t),this.target={row:e,col:t})}end(){this.active&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.active=!1,this.sourceRange=null,this.target=null}},me=class{record=null;set(e){this.record=e}clear(){this.record=null}consume(){let e=this.record;return this.record=null,e}};const he=e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}};var ge=class{core;constructor(e){this.core=e}handle(e,t,n,r){if(r||n!==null&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let i=he(e.key);if(i!==null)return this.moveFocus(i,e.shiftKey);let a=e.ctrlKey||e.metaKey;return this.handleAction(e.key,t,n,e.shiftKey,a)}moveFocus(e,t){let{selection:n}=this.core;return n.moveFocus(e,t),{preventDefault:!0,scrollToCell:n.getActiveCell()??void 0}}handleAction(e,t,n,r,i){switch(e){case`Enter`:return this.handleEnter(t,n);case`Escape`:return this.handleEscape(n);case`Tab`:return this.handleTab(n,r);default:return this.handleNonSpecialKey(e,t,n,i)}}handleEnter(e,t){return t?this.core.commitEdit():e&&this.core.startEdit(e.row,e.col),{preventDefault:!0}}handleEscape(e){return e?this.core.cancelEdit():this.core.selection.clearSelection(),{preventDefault:!0}}handleTab(e,t){return e&&this.core.commitEdit(),this.core.selection.moveFocus(t?`left`:`right`,!1),{preventDefault:!0}}handleNonSpecialKey(e,t,n,r){let{selection:i}=this.core;return e===`a`&&r?(i.selectAll(),{preventDefault:!0}):e===`c`&&r?(i.copySelectionToClipboard(),{preventDefault:!0}):e===`F2`?(t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0}):e===`Delete`||e===`Backspace`?t&&!n?(this.core.startEdit(t.row,t.col),{preventDefault:!0}):{preventDefault:!1}:(t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col),{preventDefault:!1})}};const _e=(t,n,r,i)=>{let{top:o,left:s,width:c,height:l,scrollTop:u,scrollLeft:d}=i,f=n.getColumnPositions(),p=n.getColumnCount(),m=r.clientY-o,h=r.clientX-s+d,g=Math.max(0,Math.min(t.getRowIndexAtDisplayY(m,u),t.getRowCount()-1)),_=Math.max(0,Math.min(a(h,f),p-1));return{row:g,col:n.getOriginalColumnIndex?n.getOriginalColumnIndex(_):_,autoScroll:e(r.clientY-o,r.clientX-s,l,c,n.getHeaderHeight())}},x=e=>e==null?`asc`:e===`asc`?`desc`:null;var S=class{core;deps;columnResize;columnMove;rowDrag;selectionDrag;fillDrag;pendingRowDrag=new me;keyboard;constructor(e,n){this.core=e,this.deps=n,this.columnResize=new t(e),this.columnMove=new ue(e,n),this.rowDrag=new de(e,n),this.selectionDrag=new fe(e),this.fillDrag=new pe(e),this.keyboard=new ge(e)}updateDeps(e){this.deps={...this.deps,...e},this.columnMove.updateDeps(this.deps),this.rowDrag.updateDeps(this.deps)}getDragState(){let e=this.getDragType(),t=this.fillDrag.stateSnapshot;return{isDragging:e!==null,dragType:e,fillSourceRange:t.sourceRange,fillTarget:t.target,columnResize:this.columnResize.getState(),columnMove:this.columnMove.getState(),rowDrag:this.rowDrag.getState()}}getDragType(){return this.fillDrag.isActive?`fill`:this.columnResize.isActive?`column-resize`:this.columnMove.isDraggingForDisplay?`column-move`:this.rowDrag.isDraggingForDisplay?`row-drag`:this.selectionDrag.isActive?`selection`:null}handleHeaderMouseDown(e,t,n,r){return this.columnMove.start(e,t,n,r)}handleHeaderResizeMouseDown(e,t,n){return this.columnResize.start(e,t,n)}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return ve;let r=(this.core.getColumns()[t]?.rowDrag===!0||this.core.isRowDragEntireRow())&&!n.shiftKey;return r&&n.pointerType===`touch`?this.startPendingRowDrag(e,t,n):r?this.startRowDrag(e,t,n):this.startSelectionClick(e,t,n)}startPendingRowDrag(e,t,n){return this.pendingRowDrag.set({rowIndex:e,colIndex:t,clientX:n.clientX,clientY:n.clientY}),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:`row-drag-pending`}}startRowDrag(e,t,n){return this.rowDrag.start(e,n.clientX,n.clientY),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}}startSelectionClick(e,t,n){return this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`}}handleCellDoubleClick(e,t){this.core.startEdit(e,t)}handleCellMouseEnter(e,t){this.core.highlight?.setHoverPosition({row:e,col:t})}handleCellMouseLeave(){this.core.highlight?.setHoverPosition(null)}handleFillHandleMouseDown(e,t,n){return this.fillDrag.start(e,t)}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction;this.core.setSort(e,x(n),t)}startSelectionDrag(){this.selectionDrag.start()}confirmPendingRowDrag(){let e=this.pendingRowDrag.consume();return e===null?!1:(this.rowDrag.start(e.rowIndex,e.clientX,e.clientY),!0)}cancelPendingRowDrag(){this.pendingRowDrag.clear()}handleDragMove(e,t){return this.columnResize.isActive?this.columnResize.move(e,t):this.columnMove.isActive?this.columnMove.move(e,t):this.rowDrag.isActive?this.rowDrag.move(e,t):this.selectionFillMove(e,t)}selectionFillMove(e,t){if((this.selectionDrag.isActive||this.fillDrag.isActive)===!1)return null;let n=_e(this.core,this.deps,e,t);return this.selectionDrag.moveToTarget(n.row,n.col),this.fillDrag.moveToTarget(n.row,n.col),{targetRow:n.row,targetCol:n.col,autoScroll:n.autoScroll}}handleDragEnd(){if(this.columnResize.isActive)return this.columnResize.end();if(this.columnMove.isActive)return this.columnMove.end(x);if(this.rowDrag.isActive)return this.rowDrag.end();this.selectionDrag.end(),this.fillDrag.end()}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return this.keyboard.handle(e,t,n,r)}};const ve={preventDefault:!1,stopPropagation:!1};var C=class{options;highlightingOptions;hoverPosition=null;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;rowClassCache=new Map;columnClassCache=new Map;cellClassCache=new Map;constructor(e,t={}){this.options=e,this.highlightingOptions=t}isEnabled(){return!!(this.highlightingOptions.computeRowClasses||this.highlightingOptions.computeColumnClasses||this.highlightingOptions.computeCellClasses)}updateOptions(e){this.highlightingOptions=e,this.clearAllCaches()}setHoverPosition(e){this.isEnabled()&&(this.hoverPosition?.row===e?.row&&this.hoverPosition?.col===e?.col||(this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear(),this.hoverPosition=e,this.emit({type:`SET_HOVER_POSITION`,position:e})))}getHoverPosition(){return this.hoverPosition}onSelectionChange(){this.clearAllCaches()}buildRowContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:e,colIndex:null,column:void 0,rowData:t,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.row===e,isActive:n?.row===e,isSelected:m(e,r)}}buildColumnContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:null,colIndex:e,column:t,rowData:void 0,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.col===e,isActive:n?.col===e,isSelected:h(e,r)}}buildCellContext(e,t,n,r){let i=this.options.getActiveCell(),a=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(a){let{minRow:n,maxRow:r,minCol:i,maxCol:s}=o(a);c=e>=n&&e<=r&&t>=i&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:i,selectionRange:a,isHovered:s,isActive:i?.row===e&&i?.col===t,isSelected:c}}computeRowClasses(e,t){let n=this.highlightingOptions.computeRowClasses;if(!n)return[];let r=this.rowClassCache.get(e);if(r!==void 0)return r;let i=n(this.buildRowContext(e,t));return this.rowClassCache.set(e,i),i}computeColumnClasses(e,t){let n=this.columnClassCache.get(e);if(n!==void 0)return n;let r=this.buildColumnContext(e,t),i;if(t.computeColumnClasses)i=t.computeColumnClasses(r);else if(this.highlightingOptions.computeColumnClasses)i=this.highlightingOptions.computeColumnClasses(r);else return[];return this.columnClassCache.set(e,i),i}computeCellClasses(e,t,n,r){let i=`${e},${t}`,a=this.cellClassCache.get(i);if(a!==void 0)return a;let o=this.buildCellContext(e,t,n,r),s;if(n.computeCellClasses)s=n.computeCellClasses(o);else if(this.highlightingOptions.computeCellClasses)s=this.highlightingOptions.computeCellClasses(o);else return[];return this.cellClassCache.set(i,s),s}computeCombinedCellClasses(e,t,n,r){let i=this.computeColumnClasses(t,n),a=this.computeCellClasses(e,t,n,r);return[...i,...a]}clearAllCaches(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}destroy(){this.emitter.clearListeners(),this.clearAllCaches(),this.hoverPosition=null}},w=class{options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getRow(e){return this.options.getCachedRows().get(e)}addRows(e,t){if(e.length===0)return;let n=this.options.getCachedRows(),r=this.options.getTotalRows(),i=t??r,a=r+e.length;if(i<r){let t=new Map;for(let[r,a]of n)r>=i?t.set(r+e.length,a):t.set(r,a);this.options.setCachedRows(t)}let o=this.options.getCachedRows();e.forEach((e,t)=>{o.set(i+t,e)}),this.options.setTotalRows(a);let s=e.map((e,t)=>i+t);this.emit({type:`ROWS_ADDED`,indices:s,count:s.length,totalRows:a}),this.options.emitContentSize(),this.options.refreshAllSlots()}updateRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=[];for(let r of e){let e=t.get(r.index);e&&(t.set(r.index,{...e,...r.data}),n.push(r.index))}if(n.length!==0){this.emit({type:`ROWS_UPDATED`,indices:n});for(let e of n)this.options.updateSlot(e)}}deleteRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=this.options.getTotalRows(),r=[...e].sort((e,t)=>t-e);for(let e of r){if(e<0||e>=n)continue;t.delete(e);let r=new Map;for(let[n,i]of t)n>e?r.set(n-1,i):r.set(n,i);this.options.setCachedRows(r),n--}this.options.setTotalRows(n),this.options.clearSelectionIfInvalid(n),this.emit({type:`ROWS_REMOVED`,indices:r,totalRows:n}),this.options.emitContentSize(),this.options.refreshAllSlots()}setRow(e,t){let n=this.options.getTotalRows();e<0||e>=n||(this.options.getCachedRows().set(e,t),this.emit({type:`ROWS_UPDATED`,indices:[e]}),this.options.updateSlot(e))}destroy(){this.emitter.clearListeners()}};const ye={aggressive:{prefetchPages:0,maxPages:1},balanced:{prefetchPages:1,maxPages:5},conservative:{prefetchPages:2,maxPages:10}},T=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>0?Math.floor(e):t,be=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>=0?Math.floor(e):t,E=e=>{let t=ye[e?.eviction??`balanced`];return{pageSize:T(e?.pageSize,100),prefetchPages:be(e?.prefetchPages,t.prefetchPages),maxPages:T(e?.maxPages,t.maxPages)}};var xe=class{options;cacheOptions;generation=0;hasKnownTotal=!1;loadedBlocks=new Set;pendingBlocks=new Map;constructor(e,t){this.options=e,this.cacheOptions=E(t)}configure(e){this.cacheOptions=E(e)}getPageSize(){return this.cacheOptions.pageSize}reset(){this.generation+=1,this.hasKnownTotal=!1,this.loadedBlocks.clear(),this.pendingBlocks.clear(),this.options.getCachedRows().clear()}hasMissingRows(e){if(e.endRow<=e.startRow)return!1;let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return!1;let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.options.getCachedRows();for(let t=e.startRow;t<n;t+=1)if(!r.has(t))return!0;return!1}async loadRange(e,t=!1){t&&this.reset();let n=this.generation,r=this.options.getTotalRows(),i=this.getBlocksForRange(e).map(e=>this.getOrCreateBlockRequest(e,n)).filter(e=>e!==null);return i.length>0&&await Promise.all(i),n===this.generation?(this.evictAround(e),{applied:!0,loadedBlockCount:i.length,totalRowsChanged:r!==this.options.getTotalRows()}):{applied:!1,loadedBlockCount:0,totalRowsChanged:!1}}getOrCreateBlockRequest(e,t){if(this.loadedBlocks.has(e))return null;let n=this.pendingBlocks.get(e);if(n)return n;let r=this.fetchBlock(e,t);return this.pendingBlocks.set(e,r),r.then(()=>this.deletePendingBlock(e,r),()=>this.deletePendingBlock(e,r)),r}deletePendingBlock(e,t){this.pendingBlocks.get(e)===t&&this.pendingBlocks.delete(e)}async fetchBlock(e,t){let n=e*this.cacheOptions.pageSize,r=this.getBlockEndRow(e),i;try{i=await this.options.getDataSource().query(b({range:{startRow:n,endRow:r},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}))}catch(e){if(t===this.generation)throw e;return}t===this.generation&&this.applyBlockResponse(e,i.rows,i.totalRows)}applyBlockResponse(e,t,n){let r=this.options.getCachedRows(),i=this.options.getTotalRows();this.deleteRowsForBlock(e);let a=e*this.cacheOptions.pageSize;t.forEach((e,t)=>{e!==void 0&&r.set(a+t,e)}),this.options.setTotalRows(n),this.hasKnownTotal=!0,this.loadedBlocks.add(e),n<i&&this.deleteRowsAfterTotal(n)}getBlocksForRange(e){if(e.endRow<=e.startRow)return[];let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return[];let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.cacheOptions.pageSize,i=Math.floor(e.startRow/r),a=Math.floor((n-1)/r),o=Math.max(0,i-this.cacheOptions.prefetchPages),s=this.getLastPrefetchBlock(a),c=[];for(let e=o;e<=s;e+=1)c.push(e);return c}getLastPrefetchBlock(e){let t=this.options.getTotalRows(),n=e+this.cacheOptions.prefetchPages;if(this.hasKnownTotal&&t>0){let e=Math.floor((t-1)/this.cacheOptions.pageSize);return Math.min(n,e)}return n}getBlockEndRow(e){let t=e*this.cacheOptions.pageSize+this.cacheOptions.pageSize,n=this.options.getTotalRows();return this.hasKnownTotal&&n>0?Math.min(t,n):t}evictAround(e){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;let t=new Set(this.getBlocksForRange(e)),n=Math.floor(e.startRow/this.cacheOptions.pageSize),r=[...this.loadedBlocks].filter(e=>t.has(e)===!1).sort((e,t)=>Math.abs(t-n)-Math.abs(e-n));for(let e of r){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;this.loadedBlocks.delete(e),this.deleteRowsForBlock(e)}}deleteRowsForBlock(e){let t=this.options.getCachedRows(),n=e*this.cacheOptions.pageSize,r=n+this.cacheOptions.pageSize;for(let e=n;e<r;e+=1)t.delete(e)}deleteRowsAfterTotal(e){let t=this.options.getCachedRows();for(let n of t.keys())n>=e&&t.delete(n)}};const D=e=>{e.computeColumnPositions(),e.batcher.start();try{e.emitContentSize(),e.emitHeaders(),e.batcher.emit({type:`COLUMNS_CHANGED`,columns:[...e.columns]}),e.refreshSlots===`sync`?e.slotPool.syncSlots():e.slotPool.refreshAllSlots()}finally{e.batcher.flush()}e.onComplete()},Se=(e,t,n)=>{let r=n.columns[e];r&&(r.width=t,D({...n,refreshSlots:`sync`}))},Ce=(e,t,n)=>{if(e===t||e<0||e>=n.columns.length)return null;let r=t>e?t-1:t;if(r<0||r>=n.columns.length||e===r)return null;let[i]=n.columns.splice(e,1);return n.columns.splice(r,0,i),D({...n,refreshSlots:`all`}),r},we=(e,t,n)=>{let r=n.dataSource;if(!r.moveRow)return;r.moveRow(e,t),oe(n.cachedRows,e,t),n.highlight?.clearAllCaches();let i=Math.min(e,t),a=Math.max(e,t);for(let e=i;e<=a;e++)n.slotPool.updateSlot(e)},Te=async e=>{let t=await e.dataSource.query(b({range:{startRow:0,endRow:2**53-1},sortModel:e.sortModel,filterModel:e.filterModel,columns:e.getColumns()}));e.cachedRows.clear();for(let n=0;n<t.rows.length;n++){let r=t.rows[n];r!==void 0&&e.cachedRows.set(n,r)}return e.setTotalRows(t.totalRows),{totalRows:t.totalRows}};var O=class{dataSource;options;rowLoading;rowWindowLoader;cachedRows=new Map;totalRows=0;isDataLoading=!1;constructor(e){this.options=e,this.dataSource=e.dataSource,this.rowLoading=e.rowLoading??{},this.rowWindowLoader=new xe({getDataSource:()=>this.dataSource,getCachedRows:()=>this.cachedRows,getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},getSortModel:e.getSortModel,getFilterModel:e.getFilterModel,getColumns:e.getColumns},this.rowLoading.cache)}getCachedRows(){return this.cachedRows}setCachedRows(e){this.cachedRows=e}getTotalRows(){return this.totalRows}setTotalRows(e){this.totalRows=e}getDataSource(){return this.dataSource}getRowData(e){return this.cachedRows.get(e)}isLoading(){return this.isDataLoading}getCellValue(e,t){return ce(this.cachedRows,this.options.getColumns(),e,t)}setCellValue(e,t,n){le(this.cachedRows,this.options.getColumns(),e,t,n,{onCellValueChanged:this.options.onCellValueChanged,getRowId:this.options.getRowId})}async loadInitial(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getInitialPaginatedRange(),resetCache:!0,showLoading:!0,refreshSlots:!1});return}await this.fetchAllData()}requestVisibleRows(){if(this.isPaginatedLoading()===!1)return;let e=this.getPaginatedLoadRange(!0);if(e.endRow<=e.startRow)return;let t=this.getPaginatedLoadRange(!1),n=this.rowWindowLoader.hasMissingRows(t);this.fetchPaginatedData({range:e,resetCache:!1,showLoading:n,refreshSlots:!0})}async refreshFromTransaction(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getPaginatedLoadRange(!0),resetCache:!0,showLoading:!1,refreshSlots:!1});return}await Te({dataSource:this.dataSource,sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),cachedRows:this.cachedRows,setTotalRows:e=>{this.totalRows=e},getColumns:this.options.getColumns})}setDataSource(e){this.dataSource=e,this.rowWindowLoader.reset(),this.totalRows=0}destroy(){this.rowWindowLoader.reset(),this.cachedRows.clear(),this.totalRows=0,this.isDataLoading=!1}async fetchAllData(){this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`});try{let e=b({range:{startRow:0,endRow:2**53-1},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}),t=await this.dataSource.query(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(t,e)}),this.totalRows=t.totalRows,this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emitDataError(e)}finally{this.isDataLoading=!1}}async fetchPaginatedData(e){e.showLoading&&(this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`}));try{let t=await this.rowWindowLoader.loadRange(e.range,e.resetCache);if(t.applied===!1)return;(e.showLoading||t.totalRowsChanged)&&this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows}),e.refreshSlots&&(this.options.syncSlots(),this.options.emitVisibleRange(),t.totalRowsChanged&&this.options.emitContentSize())}catch(e){this.emitDataError(e)}finally{e.showLoading&&(this.isDataLoading=!1)}}emitDataError(e){this.options.batcher.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}isPaginatedLoading(){let e=this.rowLoading.mode??`auto`;return e===`paginated`?!0:e===`all`?!1:this.dataSource.loadMode===`paginated`}getInitialPaginatedRange(){let e=this.getPaginatedLoadRange(!0);return{startRow:0,endRow:Math.max(this.rowWindowLoader.getPageSize(),e.endRow)}}getPaginatedLoadRange(e){let t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getScrollTop(),i=e?this.options.getOverscan():0,a=Math.max(0,Math.floor(r/t)-i),o=Math.ceil((r+n)/t)+i+1,s=this.totalRows>0?Math.min(this.totalRows,o):o;return{startRow:a,endRow:Math.max(a,s)}}};const k=1e7;var A=class{naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;options;constructor(e){this.options=e}updateContentSize(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getViewportHeight(),i=e*t;if(this.naturalContentHeight=i+n,this.naturalContentHeight>k){this.virtualContentHeight=k;let e=this.virtualContentHeight-n-r,a=Math.ceil((i-r)/t)*t;this.scrollRatio=a>0?e/a:1}else this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1;return{naturalHeight:this.naturalContentHeight,virtualHeight:this.virtualContentHeight,scrollRatio:this.scrollRatio}}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.naturalContentHeight||e*t+n}getVirtualHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.virtualContentHeight||e*t+n}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.options.getViewportHeight(),t=this.options.getScrollTop(),n=this.options.getRowHeight(),r=this.options.getTotalRows(),i=e,a=Math.max(0,Math.floor(t/n)),o=Math.min(r-1,Math.ceil((t+i)/n)-1);return{start:a,end:Math.max(a,o)}}getScrollTopForRow(e){return e*this.options.getRowHeight()*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=this.options.getRowHeight(),r=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(r/n)}getVirtualContentHeight(){return this.virtualContentHeight}},j=class{options;emitter=v();sortModel=[];filterModel={};openFilterColIndex=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}async setSort(e,t,n=!1){if(!this.options.isSortingEnabled()||this.options.getColumns().find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null&&r>=0?this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.options.onSortFilterChange(),this.options.onDataRefreshed()}getSortModel(){return[...this.sortModel]}async setFilter(e,t){this.options.getColumns().find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions?.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.options.onSortFilterChange(),this.options.onDataRefreshed())}getFilterModel(){return{...this.filterModel}}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.options.isSortingEnabled()?this.options.getColumns()[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.options.getColumns()[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500,n=1e5){let r=this.options.getColumns().find(t=>(t.colId??t.field)===e);if(!r)return[];let i=this.options.getCachedRows(),a=i.size,o=a>n?Math.ceil(a/n):1,s=r.valueFormatter,c=new Map;for(let e=0;e<a;e+=o){let n=i.get(e);if(n===void 0)continue;let a=g(n,r.field),[o,l]=this.normalizeDistinctValue(a,s);if(!c.has(o)&&(c.set(o,l),c.size>=t))break}let l=Array.from(c.values());return l.sort((e,t)=>{let n=y(e,s),r=y(t,s);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),l}normalizeDistinctValue(e,t){if(Array.isArray(e)){let n=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[t?t(n):JSON.stringify(n),n]}return[t?t(e):JSON.stringify(e),e]}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.options.getColumns()[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortInfoMap(){let e=new Map;return this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})}),e}destroy(){this.emitter.clearListeners(),this.sortModel=[],this.filterModel={},this.openFilterColIndex=null}},M=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:t.removed+=this.options.store.removeRows(n.rowIds);break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}},Ee=class{listeners=[];buffer=null;subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}start(){this.buffer=[]}flush(){let e=this.buffer;if(this.buffer=null,e!==null&&e.length>0)for(let t of this.listeners)t(e)}emit(e){if(this.buffer!==null){this.buffer.push(e);return}this.notify([e])}emitBatch(e){if(e.length!==0){if(this.buffer!==null){this.buffer.push(...e);return}this.notify(e)}}clearListeners(){this.listeners=[]}notify(e){for(let t of this.listeners)t(e)}},De=class{scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;getScrollRatio;constructor(e){this.getScrollRatio=e}getScrollTop(){return this.scrollTop}getScrollLeft(){return this.scrollLeft}getViewportWidth(){return this.viewportWidth}getViewportHeight(){return this.viewportHeight}resetScrollTop(){this.scrollTop=0}update(e,t,n,r){let i=this.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r,s=this.scrollTop!==a||this.scrollLeft!==t||o;return s&&(this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r),{changed:s,viewportSizeChanged:o}}};const N=e=>e.replaceAll(`\r
1
+ const e=(e,t,n,r,i)=>{let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null};var t=class{active=!1;colIndex=-1;startX=0;initialWidth=0;currentWidth=0;core;constructor(e){this.core=e}get isActive(){return this.active}start(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.colIndex=e,this.startX=n.clientX,this.initialWidth=t,this.currentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}move(e,t){let n=this.core.getColumns()[this.colIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.initialWidth+(e.clientX-this.startX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.currentWidth=a;let o=e.clientX-t.left>t.width-40?10:0,s=o===0?null:{dx:o,dy:0};return{targetRow:0,targetCol:this.colIndex,autoScroll:s}}end(){this.active&&this.core.setColumnWidth(this.colIndex,this.currentWidth),this.active=!1,this.colIndex=-1}getState(){return this.active===!1?null:{colIndex:this.colIndex,initialWidth:this.initialWidth,currentWidth:this.currentWidth}}};const n=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},r=e=>e.at(-1)??0,i=(e,t)=>{let i=n(e),a=r(i);if(t<=a||a===0)return{positions:i,widths:e.map(e=>e.width)};let o=t/a,s=e.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},a=(e,t)=>{for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t.at(-1)?t.length-2:0},o=e=>({minRow:Math.min(e.startRow,e.endRow),maxRow:Math.max(e.startRow,e.endRow),minCol:Math.min(e.startCol,e.endCol),maxCol:Math.max(e.startCol,e.endCol)}),s=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,c=(e,t,n)=>n?s(e,t,o(n)):!1,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,d=(e,t,n)=>n?.row===e&&n?.col===t,f=(e,t,n,r,i)=>{if(!n||!r||!i)return!1;let{minRow:a,maxRow:s,minCol:c,maxCol:l}=o(r),u=i.row>s,d=i.row<a;return u?e>s&&e<=i.row&&t>=c&&t<=l:d?e<a&&e>=i.row&&t>=c&&t<=l:!1},p=(e,t,n,r)=>{let i=[`gp-grid-cell`];return e&&i.push(`gp-grid-cell--active`),t&&!e&&i.push(`gp-grid-cell--selected`),n&&i.push(`gp-grid-cell--editing`),r&&i.push(`gp-grid-cell--fill-preview`),i.join(` `)},m=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=o(t);return e>=n&&e<=r},h=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=o(t);return e>=n&&e<=r};function g(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}function _(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r.at(-1)]=n)}const v=()=>{let e=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),emit:t=>{for(let n of e)n(t)},clearListeners:()=>{e=[]}}},ee=()=>{let e=v(),t=[];return{onInstruction:e.onInstruction,onBatchInstruction:e=>(t.push(e),()=>{t=t.filter(t=>t!==e)}),emit:n=>{e.emit(n);for(let e of t)e([n])},emitBatch:n=>{if(n.length!==0){for(let e of t)e(n);for(let t of n)e.emit(t)}},clearListeners:()=>{e.clearListeners(),t=[]}}},te=(e,t)=>{for(let n of e.values())if(n.rowIndex===t)return n;return null},ne=(e,t,n,r,i,a=0)=>{let o=te(i,n);if(!o){t.scrollTop=e.getScrollTopForRow(n);return}let s=a+o.translateY-t.scrollTop,c=s+r;if(s<0)t.scrollTop=e.getScrollTopForRow(n);else if(c>t.clientHeight){let i=Math.floor(t.clientHeight/r),a=Math.max(0,n-i+1);t.scrollTop=e.getScrollTopForRow(a)}},y=(e,t)=>e==null?``:t?t(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e instanceof Date?String(e):JSON.stringify(e):String(e),re=e=>{let{activeCell:t,selectionRange:n,slots:r,columns:i,visibleColumnsWithIndices:a,columnPositions:o,columnWidths:s,rowHeight:c}=e;if(!t&&!n)return null;let l,u,d,f;if(n)l=Math.max(n.startRow,n.endRow),u=Math.max(n.startCol,n.endCol),d=Math.min(n.startCol,n.endCol),f=Math.max(n.startCol,n.endCol);else if(t)l=t.row,u=t.col,d=u,f=u;else return null;for(let e=d;e<=f;e++){let t=i[e];if(!(!t||t.hidden)&&t.editable!==!0)return null}let p=a.findIndex(e=>e.originalIndex===u);if(p===-1)return null;let m=null;for(let e of r.values())if(e.rowIndex===l){m=e.translateY;break}if(m===null)return null;let h=o[p]??0,g=s[p]??0;return{top:m+c-5,left:h+g-20}},ie=(e,t,n=8)=>{let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=r.bottom+4,o=r.left,s=Math.max(200,r.width);return o+i.width>window.innerWidth-n&&(o=window.innerWidth-i.width-n),o=Math.max(n,o),a+i.height>window.innerHeight-n&&(a=r.top-i.height-4),a=Math.max(n,a),{top:a,left:o,minWidth:s}},ae=e=>{if(typeof document>`u`)return()=>{};let t=t=>{if(t.key!==`a`&&t.key!==`A`||!(t.ctrlKey||t.metaKey))return;t.preventDefault();let n=globalThis.getSelection();if(!n)return;n.removeAllRanges();let r=document.createRange();r.selectNodeContents(e),n.addRange(r)};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},oe=e=>{if(!e||e.length===0)return;let t={};for(let n of e)n.valueFormatter&&(t[n.colId??n.field]=n.valueFormatter);return Object.keys(t).length>0?t:void 0},b=e=>({range:e.range,sort:e.sortModel.length>0?e.sortModel:void 0,filter:Object.keys(e.filterModel).length>0?e.filterModel:void 0,valueFormatters:oe(e.columns)}),se=(e,t,n)=>{let r=e.get(t);if(r!==void 0){if(t<n){let i=n-1;for(let n=t;n<i;n++){let t=e.get(n+1);t===void 0?e.delete(n):e.set(n,t)}e.set(i,r);return}for(let r=t;r>n;r--){let t=e.get(r-1);t===void 0?e.delete(r):e.set(r,t)}e.set(n,r)}},ce=e=>{let t=[0],n=0;for(let r of e)r.hidden||(n+=r.width,t.push(n));return t},le=(e,t,n,r)=>{let i=e.get(n);if(!i)return null;let a=t[r];return a?g(i,a.field):null},ue=(e,t,n,r,i,a)=>{let o=e.get(n);if(!o||typeof o!=`object`)return;let s=t[r];if(!s)return;let c=a.onCellValueChanged!==void 0,l=c?g(o,s.field):void 0;_(o,s.field,i),c&&a.onCellValueChanged({rowId:a.getRowId(o),colIndex:r,field:s.field,oldValue:l,newValue:i,rowData:o})};var de=class{active=!1;sourceColIndex=-1;startX=0;startY=0;thresholdMet=!1;shiftKey=!1;ghostWidth=0;ghostHeight=0;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.active=!0,this.sourceColIndex=e,this.startX=r.clientX,this.startY=r.clientY,this.thresholdMet=!1,this.shiftKey=r.shiftKey,this.ghostWidth=t,this.ghostHeight=n,this.currentX=r.clientX,this.currentY=r.clientY,this.dropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}move(e,t){let n=e.clientX-this.startX,r=e.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.thresholdMet=!0}this.currentX=e.clientX,this.currentY=e.clientY;let{left:i,width:o,scrollLeft:s}=t,c=e.clientX-i+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.dropTargetIndex=Math.max(0,Math.min(a(c,l),u));let d=e.clientX-i,f=0;d<40?f=-10:d>o-40&&(f=10);let p=f===0?null:{dx:f,dy:0};return{targetRow:0,targetCol:this.dropTargetIndex??0,autoScroll:p}}end(e){this.thresholdMet?this.commitMove():this.treatAsHeaderClick(e),this.reset()}commitMove(){if(this.dropTargetIndex===null)return;let e=this.sourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.dropTargetIndex,this.deps.getColumnCount()-1)):this.dropTargetIndex;e!==t&&this.core.moveColumn(e,t)}treatAsHeaderClick(e){let t=this.core.getColumns()[this.sourceColIndex];if(!t)return;let n=t.colId??t.field,r=this.core.getSortModel().find(e=>e.colId===n)?.direction;this.core.setSort(n,e(r),this.shiftKey)}reset(){this.active=!1,this.sourceColIndex=-1,this.thresholdMet=!1,this.shiftKey=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceColIndex:this.sourceColIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,ghostWidth:this.ghostWidth,ghostHeight:this.ghostHeight}}},fe=class{active=!1;sourceRowIndex=-1;startX=0;startY=0;thresholdMet=!1;currentX=0;currentY=0;dropTargetIndex=null;core;deps;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps=e}get isActive(){return this.active}get isDraggingForDisplay(){return this.active&&this.thresholdMet}start(e,t,n){this.active=!0,this.sourceRowIndex=e,this.startX=t,this.startY=n,this.thresholdMet=!1,this.currentX=t,this.currentY=n,this.dropTargetIndex=null}move(t,n){let r=t.clientX-this.startX,i=t.clientY-this.startY;if(this.thresholdMet===!1){if(!(Math.abs(r)>5||Math.abs(i)>5))return null;this.thresholdMet=!0}this.currentX=t.clientX,this.currentY=t.clientY;let{top:a,left:o,height:s,width:c,scrollTop:l}=n,u=this.deps.getHeaderHeight(),d=t.clientY-a,f=this.core.getRowCount(),p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(d,l),f));return this.dropTargetIndex=p,{targetRow:p,targetCol:0,autoScroll:e(t.clientY-a,t.clientX-o,s,c,u)}}end(){this.thresholdMet&&this.dropTargetIndex!==null&&this.dropTargetIndex!==this.sourceRowIndex&&this.core.commitRowDrag(this.sourceRowIndex,this.dropTargetIndex),this.active=!1,this.sourceRowIndex=-1,this.thresholdMet=!1,this.dropTargetIndex=null}getState(){return this.active===!1?null:{sourceRowIndex:this.sourceRowIndex,currentX:this.currentX,currentY:this.currentY,dropTargetIndex:this.dropTargetIndex,dropIndicatorY:this.dropTargetIndex===null?0:this.core.getRowTranslateY(this.dropTargetIndex)}}},pe=class{active=!1;core;constructor(e){this.core=e}get isActive(){return this.active}start(){this.active=!0}moveToTarget(e,t){this.active!==!1&&this.core.selection.startSelection({row:e,col:t},{shift:!0})}end(){this.active=!1}},me=class{active=!1;sourceRange=null;target=null;core;constructor(e){this.core=e}get isActive(){return this.active}get stateSnapshot(){return{sourceRange:this.sourceRange,target:this.target}}start(e,t){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let n=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(n),this.sourceRange=n,this.target={row:Math.max(n.startRow,n.endRow),col:Math.max(n.startCol,n.endCol)},this.active=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}moveToTarget(e,t){this.active!==!1&&(this.core.fill.updateFillDrag(e,t),this.target={row:e,col:t})}end(){this.active&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.active=!1,this.sourceRange=null,this.target=null}},he=class{record=null;set(e){this.record=e}clear(){this.record=null}consume(){let e=this.record;return this.record=null,e}};const ge=e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}};var _e=class{core;constructor(e){this.core=e}handle(e,t,n,r){if(r)return{preventDefault:!1};if(this.core.getPeekState()!==null)return e.key===`Escape`?(this.core.stopPeek(),{preventDefault:!0}):{preventDefault:!1};if(n!==null&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let i=ge(e.key);if(i!==null)return this.moveFocus(i,e.shiftKey);let a=e.ctrlKey||e.metaKey;return this.handleAction(e.key,t,n,e.shiftKey,a)}moveFocus(e,t){this.core.stopPeek();let{selection:n}=this.core;return n.moveFocus(e,t),{preventDefault:!0,scrollToCell:n.getActiveCell()??void 0}}handleAction(e,t,n,r,i){switch(e){case`Enter`:return this.handleEnter(t,n);case`Escape`:return this.handleEscape(n);case`Tab`:return this.handleTab(n,r);default:return this.handleNonSpecialKey(e,t,n,i)}}handleEnter(e,t){return t?this.core.commitEdit():e&&this.core.startEdit(e.row,e.col),{preventDefault:!0}}handleEscape(e){return e?this.core.cancelEdit():this.core.getPeekState()?this.core.stopPeek():this.core.selection.clearSelection(),{preventDefault:!0}}handleTab(e,t){return e&&this.core.commitEdit(),this.core.selection.moveFocus(t?`left`:`right`,!1),{preventDefault:!0}}handleNonSpecialKey(e,t,n,r){let{selection:i}=this.core;return e===`a`&&r?(i.selectAll(),{preventDefault:!0}):e===`c`&&r?(i.copySelectionToClipboard(),{preventDefault:!0}):e===`F2`?(t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0}):e===`Delete`||e===`Backspace`?t&&!n?(this.core.startEdit(t.row,t.col),{preventDefault:!0}):{preventDefault:!1}:(t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col),{preventDefault:!1})}};const ve=(t,n,r,i)=>{let{top:o,left:s,width:c,height:l,scrollTop:u,scrollLeft:d}=i,f=n.getColumnPositions(),p=n.getColumnCount(),m=r.clientY-o,h=r.clientX-s+d,g=Math.max(0,Math.min(t.getRowIndexAtDisplayY(m,u),t.getRowCount()-1)),_=Math.max(0,Math.min(a(h,f),p-1));return{row:g,col:n.getOriginalColumnIndex?n.getOriginalColumnIndex(_):_,autoScroll:e(r.clientY-o,r.clientX-s,l,c,n.getHeaderHeight())}},x=e=>e==null?`asc`:e===`asc`?`desc`:null;var S=class{core;deps;columnResize;columnMove;rowDrag;selectionDrag;fillDrag;pendingRowDrag=new he;keyboard;constructor(e,n){this.core=e,this.deps=n,this.columnResize=new t(e),this.columnMove=new de(e,n),this.rowDrag=new fe(e,n),this.selectionDrag=new pe(e),this.fillDrag=new me(e),this.keyboard=new _e(e)}updateDeps(e){this.deps={...this.deps,...e},this.columnMove.updateDeps(this.deps),this.rowDrag.updateDeps(this.deps)}getDragState(){let e=this.getDragType(),t=this.fillDrag.stateSnapshot;return{isDragging:e!==null,dragType:e,fillSourceRange:t.sourceRange,fillTarget:t.target,columnResize:this.columnResize.getState(),columnMove:this.columnMove.getState(),rowDrag:this.rowDrag.getState()}}getDragType(){return this.fillDrag.isActive?`fill`:this.columnResize.isActive?`column-resize`:this.columnMove.isDraggingForDisplay?`column-move`:this.rowDrag.isDraggingForDisplay?`row-drag`:this.selectionDrag.isActive?`selection`:null}handleHeaderMouseDown(e,t,n,r){return this.columnMove.start(e,t,n,r)}handleHeaderResizeMouseDown(e,t,n){return this.columnResize.start(e,t,n)}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return ye;this.core.stopPeek();let r=(this.core.getColumns()[t]?.rowDrag===!0||this.core.isRowDragEntireRow())&&!n.shiftKey;return r&&n.pointerType===`touch`?this.startPendingRowDrag(e,t,n):r?this.startRowDrag(e,t,n):this.startSelectionClick(e,t,n)}startPendingRowDrag(e,t,n){return this.pendingRowDrag.set({rowIndex:e,colIndex:t,clientX:n.clientX,clientY:n.clientY}),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:`row-drag-pending`}}startRowDrag(e,t,n){return this.rowDrag.start(e,n.clientX,n.clientY),this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}}startSelectionClick(e,t,n){return this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`}}handleCellDoubleClick(e,t){if(this.core.getColumns()[t]?.editable){this.core.startEdit(e,t);return}this.core.startPeek(e,t)}handleCellMouseEnter(e,t){this.core.highlight?.setHoverPosition({row:e,col:t})}handleCellMouseLeave(){this.core.highlight?.setHoverPosition(null)}handleFillHandleMouseDown(e,t,n){return this.fillDrag.start(e,t)}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction;this.core.setSort(e,x(n),t)}startSelectionDrag(){this.selectionDrag.start()}confirmPendingRowDrag(){let e=this.pendingRowDrag.consume();return e===null?!1:(this.rowDrag.start(e.rowIndex,e.clientX,e.clientY),!0)}cancelPendingRowDrag(){this.pendingRowDrag.clear()}handleDragMove(e,t){return this.columnResize.isActive?this.columnResize.move(e,t):this.columnMove.isActive?this.columnMove.move(e,t):this.rowDrag.isActive?this.rowDrag.move(e,t):this.selectionFillMove(e,t)}selectionFillMove(e,t){if((this.selectionDrag.isActive||this.fillDrag.isActive)===!1)return null;let n=ve(this.core,this.deps,e,t);return this.selectionDrag.moveToTarget(n.row,n.col),this.fillDrag.moveToTarget(n.row,n.col),{targetRow:n.row,targetCol:n.col,autoScroll:n.autoScroll}}handleDragEnd(){if(this.columnResize.isActive)return this.columnResize.end();if(this.columnMove.isActive)return this.columnMove.end(x);if(this.rowDrag.isActive)return this.rowDrag.end();this.selectionDrag.end(),this.fillDrag.end()}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return this.keyboard.handle(e,t,n,r)}};const ye={preventDefault:!1,stopPropagation:!1};var C=class{options;highlightingOptions;hoverPosition=null;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;rowClassCache=new Map;columnClassCache=new Map;cellClassCache=new Map;constructor(e,t={}){this.options=e,this.highlightingOptions=t}isEnabled(){return!!(this.highlightingOptions.computeRowClasses||this.highlightingOptions.computeColumnClasses||this.highlightingOptions.computeCellClasses)}updateOptions(e){this.highlightingOptions=e,this.clearAllCaches()}setHoverPosition(e){this.isEnabled()&&(this.hoverPosition?.row===e?.row&&this.hoverPosition?.col===e?.col||(this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear(),this.hoverPosition=e,this.emit({type:`SET_HOVER_POSITION`,position:e})))}getHoverPosition(){return this.hoverPosition}onSelectionChange(){this.clearAllCaches()}buildRowContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:e,colIndex:null,column:void 0,rowData:t,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.row===e,isActive:n?.row===e,isSelected:m(e,r)}}buildColumnContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:null,colIndex:e,column:t,rowData:void 0,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.col===e,isActive:n?.col===e,isSelected:h(e,r)}}buildCellContext(e,t,n,r){let i=this.options.getActiveCell(),a=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(a){let{minRow:n,maxRow:r,minCol:i,maxCol:s}=o(a);c=e>=n&&e<=r&&t>=i&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:i,selectionRange:a,isHovered:s,isActive:i?.row===e&&i?.col===t,isSelected:c}}computeRowClasses(e,t){let n=this.highlightingOptions.computeRowClasses;if(!n)return[];let r=this.rowClassCache.get(e);if(r!==void 0)return r;let i=n(this.buildRowContext(e,t));return this.rowClassCache.set(e,i),i}computeColumnClasses(e,t){let n=this.columnClassCache.get(e);if(n!==void 0)return n;let r=this.buildColumnContext(e,t),i;if(t.computeColumnClasses)i=t.computeColumnClasses(r);else if(this.highlightingOptions.computeColumnClasses)i=this.highlightingOptions.computeColumnClasses(r);else return[];return this.columnClassCache.set(e,i),i}computeCellClasses(e,t,n,r){let i=`${e},${t}`,a=this.cellClassCache.get(i);if(a!==void 0)return a;let o=this.buildCellContext(e,t,n,r),s;if(n.computeCellClasses)s=n.computeCellClasses(o);else if(this.highlightingOptions.computeCellClasses)s=this.highlightingOptions.computeCellClasses(o);else return[];return this.cellClassCache.set(i,s),s}computeCombinedCellClasses(e,t,n,r){let i=this.computeColumnClasses(t,n),a=this.computeCellClasses(e,t,n,r);return[...i,...a]}clearAllCaches(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}destroy(){this.emitter.clearListeners(),this.clearAllCaches(),this.hoverPosition=null}},w=class{options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getRow(e){return this.options.getCachedRows().get(e)}addRows(e,t){if(e.length===0)return;let n=this.options.getCachedRows(),r=this.options.getTotalRows(),i=t??r,a=r+e.length;if(i<r){let t=new Map;for(let[r,a]of n)r>=i?t.set(r+e.length,a):t.set(r,a);this.options.setCachedRows(t)}let o=this.options.getCachedRows();e.forEach((e,t)=>{o.set(i+t,e)}),this.options.setTotalRows(a);let s=e.map((e,t)=>i+t);this.emit({type:`ROWS_ADDED`,indices:s,count:s.length,totalRows:a}),this.options.emitContentSize(),this.options.refreshAllSlots()}updateRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=[];for(let r of e){let e=t.get(r.index);e&&(t.set(r.index,{...e,...r.data}),n.push(r.index))}if(n.length!==0){this.emit({type:`ROWS_UPDATED`,indices:n});for(let e of n)this.options.updateSlot(e)}}deleteRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=this.options.getTotalRows(),r=[...e].sort((e,t)=>t-e);for(let e of r){if(e<0||e>=n)continue;t.delete(e);let r=new Map;for(let[n,i]of t)n>e?r.set(n-1,i):r.set(n,i);this.options.setCachedRows(r),n--}this.options.setTotalRows(n),this.options.clearSelectionIfInvalid(n),this.emit({type:`ROWS_REMOVED`,indices:r,totalRows:n}),this.options.emitContentSize(),this.options.refreshAllSlots()}setRow(e,t){let n=this.options.getTotalRows();e<0||e>=n||(this.options.getCachedRows().set(e,t),this.emit({type:`ROWS_UPDATED`,indices:[e]}),this.options.updateSlot(e))}destroy(){this.emitter.clearListeners()}};const be={aggressive:{prefetchPages:0,maxPages:1},balanced:{prefetchPages:1,maxPages:5},conservative:{prefetchPages:2,maxPages:10}},T=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>0?Math.floor(e):t,xe=(e,t)=>e===void 0?t:Number.isFinite(e)&&e>=0?Math.floor(e):t,E=e=>{let t=be[e?.eviction??`balanced`];return{pageSize:T(e?.pageSize,100),prefetchPages:xe(e?.prefetchPages,t.prefetchPages),maxPages:T(e?.maxPages,t.maxPages)}};var Se=class{options;cacheOptions;generation=0;hasKnownTotal=!1;loadedBlocks=new Set;pendingBlocks=new Map;constructor(e,t){this.options=e,this.cacheOptions=E(t)}configure(e){this.cacheOptions=E(e)}getPageSize(){return this.cacheOptions.pageSize}reset(){this.generation+=1,this.hasKnownTotal=!1,this.loadedBlocks.clear(),this.pendingBlocks.clear(),this.options.getCachedRows().clear()}hasMissingRows(e){if(e.endRow<=e.startRow)return!1;let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return!1;let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.options.getCachedRows();for(let t=e.startRow;t<n;t+=1)if(!r.has(t))return!0;return!1}async loadRange(e,t=!1){t&&this.reset();let n=this.generation,r=this.options.getTotalRows(),i=this.getBlocksForRange(e).map(e=>this.getOrCreateBlockRequest(e,n)).filter(e=>e!==null);return i.length>0&&await Promise.all(i),n===this.generation?(this.evictAround(e),{applied:!0,loadedBlockCount:i.length,totalRowsChanged:r!==this.options.getTotalRows()}):{applied:!1,loadedBlockCount:0,totalRowsChanged:!1}}getOrCreateBlockRequest(e,t){if(this.loadedBlocks.has(e))return null;let n=this.pendingBlocks.get(e);if(n)return n;let r=this.fetchBlock(e,t);return this.pendingBlocks.set(e,r),r.then(()=>this.deletePendingBlock(e,r),()=>this.deletePendingBlock(e,r)),r}deletePendingBlock(e,t){this.pendingBlocks.get(e)===t&&this.pendingBlocks.delete(e)}async fetchBlock(e,t){let n=e*this.cacheOptions.pageSize,r=this.getBlockEndRow(e),i;try{i=await this.options.getDataSource().query(b({range:{startRow:n,endRow:r},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}))}catch(e){if(t===this.generation)throw e;return}t===this.generation&&this.applyBlockResponse(e,i.rows,i.totalRows)}applyBlockResponse(e,t,n){let r=this.options.getCachedRows(),i=this.options.getTotalRows();this.deleteRowsForBlock(e);let a=e*this.cacheOptions.pageSize;t.forEach((e,t)=>{e!==void 0&&r.set(a+t,e)}),this.options.setTotalRows(n),this.hasKnownTotal=!0,this.loadedBlocks.add(e),n<i&&this.deleteRowsAfterTotal(n)}getBlocksForRange(e){if(e.endRow<=e.startRow)return[];let t=this.options.getTotalRows();if(this.hasKnownTotal&&t===0||this.hasKnownTotal&&e.startRow>=t)return[];let n=this.hasKnownTotal?Math.min(e.endRow,t):e.endRow,r=this.cacheOptions.pageSize,i=Math.floor(e.startRow/r),a=Math.floor((n-1)/r),o=Math.max(0,i-this.cacheOptions.prefetchPages),s=this.getLastPrefetchBlock(a),c=[];for(let e=o;e<=s;e+=1)c.push(e);return c}getLastPrefetchBlock(e){let t=this.options.getTotalRows(),n=e+this.cacheOptions.prefetchPages;if(this.hasKnownTotal&&t>0){let e=Math.floor((t-1)/this.cacheOptions.pageSize);return Math.min(n,e)}return n}getBlockEndRow(e){let t=e*this.cacheOptions.pageSize+this.cacheOptions.pageSize,n=this.options.getTotalRows();return this.hasKnownTotal&&n>0?Math.min(t,n):t}evictAround(e){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;let t=new Set(this.getBlocksForRange(e)),n=Math.floor(e.startRow/this.cacheOptions.pageSize),r=[...this.loadedBlocks].filter(e=>t.has(e)===!1).sort((e,t)=>Math.abs(t-n)-Math.abs(e-n));for(let e of r){if(this.loadedBlocks.size<=this.cacheOptions.maxPages)return;this.loadedBlocks.delete(e),this.deleteRowsForBlock(e)}}deleteRowsForBlock(e){let t=this.options.getCachedRows(),n=e*this.cacheOptions.pageSize,r=n+this.cacheOptions.pageSize;for(let e=n;e<r;e+=1)t.delete(e)}deleteRowsAfterTotal(e){let t=this.options.getCachedRows();for(let n of t.keys())n>=e&&t.delete(n)}};const D=e=>{e.computeColumnPositions(),e.batcher.start();try{e.emitContentSize(),e.emitHeaders(),e.batcher.emit({type:`COLUMNS_CHANGED`,columns:[...e.columns]}),e.refreshSlots===`sync`?e.slotPool.syncSlots():e.slotPool.refreshAllSlots()}finally{e.batcher.flush()}e.onComplete()},Ce=(e,t,n,r)=>{if(n<=0)return t;let i=0;for(let t=0;t<r.length;t++){if(t===e)continue;let n=r[t];!n||n.hidden||(i+=n.width)}return i<=0||t+i>=n?t:t*i/(n-t)},we=(e,t,n,r)=>{let i=r.columns[e];i&&(i.width=i.hidden?t:Ce(e,t,n,r.columns),D({...r,refreshSlots:`sync`}))},Te=(e,t,n)=>{if(e===t||e<0||e>=n.columns.length)return null;let r=t>e?t-1:t;if(r<0||r>=n.columns.length||e===r)return null;let[i]=n.columns.splice(e,1);return n.columns.splice(r,0,i),D({...n,refreshSlots:`all`}),r},Ee=(e,t,n)=>{let r=n.dataSource;if(!r.moveRow)return;r.moveRow(e,t),se(n.cachedRows,e,t),n.highlight?.clearAllCaches();let i=Math.min(e,t),a=Math.max(e,t);for(let e=i;e<=a;e++)n.slotPool.updateSlot(e)},De=async e=>{let t=await e.dataSource.query(b({range:{startRow:0,endRow:2**53-1},sortModel:e.sortModel,filterModel:e.filterModel,columns:e.getColumns()}));e.cachedRows.clear();for(let n=0;n<t.rows.length;n++){let r=t.rows[n];r!==void 0&&e.cachedRows.set(n,r)}return e.setTotalRows(t.totalRows),{totalRows:t.totalRows}};var O=class{dataSource;options;rowLoading;rowWindowLoader;cachedRows=new Map;totalRows=0;isDataLoading=!1;constructor(e){this.options=e,this.dataSource=e.dataSource,this.rowLoading=e.rowLoading??{},this.rowWindowLoader=new Se({getDataSource:()=>this.dataSource,getCachedRows:()=>this.cachedRows,getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},getSortModel:e.getSortModel,getFilterModel:e.getFilterModel,getColumns:e.getColumns},this.rowLoading.cache)}getCachedRows(){return this.cachedRows}setCachedRows(e){this.cachedRows=e}getTotalRows(){return this.totalRows}setTotalRows(e){this.totalRows=e}getDataSource(){return this.dataSource}getRowData(e){return this.cachedRows.get(e)}isLoading(){return this.isDataLoading}getCellValue(e,t){return le(this.cachedRows,this.options.getColumns(),e,t)}setCellValue(e,t,n){ue(this.cachedRows,this.options.getColumns(),e,t,n,{onCellValueChanged:this.options.onCellValueChanged,getRowId:this.options.getRowId})}async loadInitial(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getInitialPaginatedRange(),resetCache:!0,showLoading:!0,refreshSlots:!1});return}await this.fetchAllData()}requestVisibleRows(){if(this.isPaginatedLoading()===!1)return;let e=this.getPaginatedLoadRange(!0);if(e.endRow<=e.startRow)return;let t=this.getPaginatedLoadRange(!1),n=this.rowWindowLoader.hasMissingRows(t);this.fetchPaginatedData({range:e,resetCache:!1,showLoading:n,refreshSlots:!0})}async refreshFromTransaction(){if(this.isPaginatedLoading()){await this.fetchPaginatedData({range:this.getPaginatedLoadRange(!0),resetCache:!0,showLoading:!1,refreshSlots:!1});return}await De({dataSource:this.dataSource,sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),cachedRows:this.cachedRows,setTotalRows:e=>{this.totalRows=e},getColumns:this.options.getColumns})}setDataSource(e){this.dataSource=e,this.rowWindowLoader.reset(),this.totalRows=0}destroy(){this.rowWindowLoader.reset(),this.cachedRows.clear(),this.totalRows=0,this.isDataLoading=!1}async fetchAllData(){this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`});try{let e=b({range:{startRow:0,endRow:2**53-1},sortModel:this.options.getSortModel(),filterModel:this.options.getFilterModel(),columns:this.options.getColumns()}),t=await this.dataSource.query(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(t,e)}),this.totalRows=t.totalRows,this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emitDataError(e)}finally{this.isDataLoading=!1}}async fetchPaginatedData(e){e.showLoading&&(this.isDataLoading=!0,this.options.batcher.emit({type:`DATA_LOADING`}));try{let t=await this.rowWindowLoader.loadRange(e.range,e.resetCache);if(t.applied===!1)return;(e.showLoading||t.totalRowsChanged)&&this.options.batcher.emit({type:`DATA_LOADED`,totalRows:this.totalRows}),e.refreshSlots&&(this.options.syncSlots(),this.options.emitVisibleRange(),t.totalRowsChanged&&this.options.emitContentSize())}catch(e){this.emitDataError(e)}finally{e.showLoading&&(this.isDataLoading=!1)}}emitDataError(e){this.options.batcher.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}isPaginatedLoading(){let e=this.rowLoading.mode??`auto`;return e===`paginated`?!0:e===`all`?!1:this.dataSource.loadMode===`paginated`}getInitialPaginatedRange(){let e=this.getPaginatedLoadRange(!0);return{startRow:0,endRow:Math.max(this.rowWindowLoader.getPageSize(),e.endRow)}}getPaginatedLoadRange(e){let t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getScrollTop(),i=e?this.options.getOverscan():0,a=Math.max(0,Math.floor(r/t)-i),o=Math.ceil((r+n)/t)+i+1,s=this.totalRows>0?Math.min(this.totalRows,o):o;return{startRow:a,endRow:Math.max(a,s)}}};const k=1e7;var A=class{naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;options;constructor(e){this.options=e}updateContentSize(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getViewportHeight(),i=e*t;if(this.naturalContentHeight=i+n,this.naturalContentHeight>k){this.virtualContentHeight=k;let e=this.virtualContentHeight-n-r,a=Math.ceil((i-r)/t)*t;this.scrollRatio=a>0?e/a:1}else this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1;return{naturalHeight:this.naturalContentHeight,virtualHeight:this.virtualContentHeight,scrollRatio:this.scrollRatio}}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.naturalContentHeight||e*t+n}getVirtualHeight(){let e=this.options.getTotalRows(),t=this.options.getRowHeight(),n=this.options.getHeaderHeight();return this.virtualContentHeight||e*t+n}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.options.getViewportHeight(),t=this.options.getScrollTop(),n=this.options.getRowHeight(),r=this.options.getTotalRows(),i=e,a=Math.max(0,Math.floor(t/n)),o=Math.min(r-1,Math.ceil((t+i)/n)-1);return{start:a,end:Math.max(a,o)}}getScrollTopForRow(e){return e*this.options.getRowHeight()*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=this.options.getRowHeight(),r=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(r/n)}getVirtualContentHeight(){return this.virtualContentHeight}},j=class{options;emitter=v();sortModel=[];filterModel={};openFilterColIndex=null;scanWarnedCols=new Set;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}async setSort(e,t,n=!1){if(!this.options.isSortingEnabled()||this.options.getColumns().find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null&&r>=0?this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.options.onSortFilterChange(),this.options.onDataRefreshed()}getSortModel(){return[...this.sortModel]}async setFilter(e,t){this.options.getColumns().find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions?.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.options.onSortFilterChange(),this.options.onDataRefreshed())}getFilterModel(){return{...this.filterModel}}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.options.isSortingEnabled()?this.options.getColumns()[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.options.getColumns()[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500){let n=this.options.getColumns().find(t=>(t.colId??t.field)===e);if(!n)return[];let r=n.valueFormatter,i=n.distinctValues??this.scanDistinctValues(n,t),a=new Map;for(let e of i){let[n,i]=this.normalizeDistinctValue(e,r);if(!a.has(n)&&(a.set(n,i),a.size>=t))break}let o=Array.from(a.values());return o.sort((e,t)=>{let n=y(e,r),i=y(t,r);return n.localeCompare(i,void 0,{numeric:!0,sensitivity:`base`})}),o}scanDistinctValues(e,t){let n=this.options.getCachedRows(),r=n.size,i=e.colId??e.field;r>1e4&&!this.scanWarnedCols.has(i)&&(this.scanWarnedCols.add(i),console.warn(`[gp-grid] Scanning ${r} rows to compute distinct values for column "${i}". Pre-supply ColumnDefinition.distinctValues to skip this scan.`));let a=e.valueFormatter,o=new Map;for(let i=0;i<r;i++){let r=n.get(i);if(r===void 0)continue;let s=g(r,e.field),[c,l]=this.normalizeDistinctValue(s,a);if(!o.has(c)&&(o.set(c,l),o.size>=t))break}return Array.from(o.values())}normalizeDistinctValue(e,t){if(Array.isArray(e)){let n=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[t?t(n):JSON.stringify(n),n]}return[t?t(e):JSON.stringify(e),e]}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.options.getColumns()[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortInfoMap(){let e=new Map;return this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})}),e}destroy(){this.emitter.clearListeners(),this.sortModel=[],this.filterModel={},this.openFilterColIndex=null}},M=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:t.removed+=this.options.store.removeRows(n.rowIds);break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}},Oe=class{listeners=[];buffer=null;subscribe(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}start(){this.buffer=[]}flush(){let e=this.buffer;if(this.buffer=null,e!==null&&e.length>0)for(let t of this.listeners)t(e)}emit(e){if(this.buffer!==null){this.buffer.push(e);return}this.notify([e])}emitBatch(e){if(e.length!==0){if(this.buffer!==null){this.buffer.push(...e);return}this.notify(e)}}clearListeners(){this.listeners=[]}notify(e){for(let t of this.listeners)t(e)}},ke=class{scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;getScrollRatio;constructor(e){this.getScrollRatio=e}getScrollTop(){return this.scrollTop}getScrollLeft(){return this.scrollLeft}getViewportWidth(){return this.viewportWidth}getViewportHeight(){return this.viewportHeight}resetScrollTop(){this.scrollTop=0}update(e,t,n,r){let i=this.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r,s=this.scrollTop!==a||this.scrollLeft!==t||o;return s&&(this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r),{changed:s,viewportSizeChanged:o}}};const N=e=>e.replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll(`\r`,`
4
- `),Oe=e=>{let t=N(e).split(`
5
- `);return t.length>1&&t.at(-1)===``&&t.pop(),t.map(e=>e.split(` `).map(e=>({value:e,text:e})))},ke=(e,t)=>{if(e.value===null)return{ok:!0,value:null};let n=e.text,r=n.trim();if(r.length===0)return Ae(t);switch(t.cellDataType){case`text`:return{ok:!0,value:n};case`number`:return je(e.value,r);case`boolean`:return Me(e.value,r);case`date`:case`dateTime`:return Ne(e.value,r);case`dateString`:case`dateTimeString`:return Pe(r,n);case`object`:return Fe(e.value,r)}},Ae=e=>e.cellDataType===`text`?{ok:!0,value:``}:{ok:!0,value:null},je=(e,t)=>{if(typeof e==`number`&&Number.isFinite(e))return{ok:!0,value:e};let n=Number(t);return Number.isFinite(n)?{ok:!0,value:n}:{ok:!1}},Me=(e,t)=>{if(typeof e==`boolean`)return{ok:!0,value:e};let n=t.toLowerCase();return n===`true`?{ok:!0,value:!0}:n===`false`?{ok:!0,value:!1}:{ok:!1}},Ne=(e,t)=>{if(e instanceof Date&&P(e))return{ok:!0,value:e};let n=new Date(t);return P(n)?{ok:!0,value:n}:{ok:!1}},Pe=(e,t)=>P(new Date(e))?{ok:!0,value:t}:{ok:!1},Fe=(e,t)=>{if(typeof e==`object`&&e&&!(e instanceof Date))return{ok:!0,value:e};try{let e=JSON.parse(t);if(typeof e==`object`&&e)return{ok:!0,value:e}}catch{return{ok:!1}}return{ok:!1}},P=e=>Number.isFinite(e.getTime());var F=class{state={activeCell:null,range:null,anchor:null,selectionMode:!1};options;emitter=v();clipboardSnapshot=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return{...this.state}}getActiveCell(){return this.state.activeCell}getSelectionRange(){return this.state.range}isSelected(e,t){let{range:n}=this.state;if(!n)return!1;let{minRow:r,maxRow:i,minCol:a,maxCol:s}=o(n);return e>=r&&e<=i&&t>=a&&t<=s}isActiveCell(e,t){let{activeCell:n}=this.state;return n?.row===e&&n?.col===t}startSelection(e,t={}){let{shift:n=!1,ctrl:r=!1}=t,{row:i,col:a}=this.clampPosition(e);n&&this.state.anchor?(this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a}):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null),this.state.selectionMode=r,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}moveFocus(e,t=!1){if(!this.state.activeCell){this.startSelection({row:0,col:0});return}let{row:n,col:r}=this.state.activeCell,i=n,a=r;switch(e){case`up`:i=Math.max(0,n-1);break;case`down`:i=Math.min(this.options.getRowCount()-1,n+1);break;case`left`:a=Math.max(0,r-1);break;case`right`:a=Math.min(this.options.getColumnCount()-1,r+1);break}t?(this.state.anchor??={row:n,col:r},this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null}))}selectAll(){let e=this.options.getRowCount(),t=this.options.getColumnCount();e===0||t===0||(this.state.range={startRow:0,startCol:0,endRow:e-1,endCol:t-1},this.state.activeCell||(this.state.activeCell={row:0,col:0},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell})),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range}))}clearSelection(){this.state.activeCell=null,this.state.range=null,this.state.anchor=null,this.state.selectionMode=!1,this.emit({type:`SET_ACTIVE_CELL`,position:null}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setActiveCell(e,t){let n=this.clampPosition({row:e,col:t});this.state.activeCell=n,this.state.anchor=n,this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setSelectionRange(e){this.state.range=e,this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}getSelectedData(){let e=this.getEffectiveRange();if(e===null)return[];let{minRow:t,maxRow:n,minCol:r,maxCol:i}=o(e),a=[];for(let e=t;e<=n;e++){let t=[];for(let n=r;n<=i;n++)t.push(this.options.getCellValue(e,n));a.push(t)}return a}async copySelectionToClipboard(){let e=this.getEffectiveRange();if(e===null)return;let t=this.createClipboardSnapshot(e);t.cells.length!==0&&(this.clipboardSnapshot=t,!(typeof navigator>`u`||typeof document>`u`)&&await navigator.clipboard.writeText(t.text))}pasteClipboardText(e){let t=this.getEffectiveRange();if(t===null)return{handled:!1,changedCells:[]};let n=this.getPasteSourceCells(e);return n.length===0?{handled:!1,changedCells:[]}:{handled:!0,changedCells:this.applyPasteSource(n,t,this.state.range!==null)}}destroy(){this.emitter.clearListeners(),this.state={activeCell:null,range:null,anchor:null,selectionMode:!1},this.clipboardSnapshot=null}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}getEffectiveRange(){let{range:e,activeCell:t}=this.state;return e||(t?{startRow:t.row,startCol:t.col,endRow:t.row,endCol:t.col}:null)}createClipboardSnapshot(e){let{minRow:t,maxRow:n,minCol:r,maxCol:i}=o(e),a=[];for(let e=t;e<=n;e++){let t=[];for(let n=r;n<=i;n++){let r=this.options.getCellValue(e,n),i=y(r,this.options.getColumn(n)?.valueFormatter);t.push({value:r,text:i})}a.push(t)}return{cells:a,text:a.map(e=>e.map(e=>e.text).join(` `)).join(`
6
- `)}}getPasteSourceCells(e){let t=this.clipboardSnapshot;return t&&N(t.text)===N(e)?t.cells:Oe(e)}applyPasteSource(e,t,n){let r=[],{minRow:i,maxRow:a,minCol:s,maxCol:c}=o(t),l=this.isSingleSourceCell(e),u=l?a:i+e.length-1,d=l?c:s+this.getMaxSourceColumnCount(e)-1,f=n?Math.min(u,a):u,p=n?Math.min(d,c):d,m=this.options.getRowCount(),h=this.options.getColumnCount(),g=Math.min(f,m-1),_=Math.min(p,h-1);for(let t=i;t<=g;t++)for(let n=s;n<=_;n++){let a=this.getSourceCellForTarget(e,t-i,n-s,l);a&&this.applyPasteCell(t,n,a,r)}return r}applyPasteCell(e,t,n,r){let i=this.options.getColumn(t);if(i===void 0||i.hidden===!0||i.editable!==!0)return;let a=ke(n,i);a.ok!==!1&&(this.options.setCellValue(e,t,a.value),r.push({row:e,col:t,value:a.value}))}getSourceCellForTarget(e,t,n,r){return r?e[0]?.[0]??null:e[t]?.[n]??null}isSingleSourceCell(e){return e.length===1&&e[0]?.length===1}getMaxSourceColumnCount(e){return e.reduce((e,t)=>Math.max(e,t.length),0)}},I=class{state=null;options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t}=this.state,n=this.calculateFilledCells(e,t);for(let{row:e,col:t,value:r}of n)this.options.setCellValue(e,t,r);this.emit({type:`COMMIT_FILL`,filledCells:n}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}destroy(){this.emitter.clearListeners(),this.state=null}calculateFilledCells(e,t){let n=[],{minRow:r,maxRow:i,minCol:a,maxCol:s}=o(e),c=t>i,l=t<r;if(c||l)for(let e=a;e<=s;e++){let a=this.getSourceColumnValues(r,i,e),o=this.detectPattern(a);if(c)for(let r=i+1;r<=t;r++){let t=r-i-1,s=this.applyPattern(o,a,t);n.push({row:r,col:e,value:s})}else if(l)for(let i=r-1;i>=t;i--){let t=r-i-1,s=this.applyPattern(o,a,t,!0);n.push({row:i,col:e,value:s})}}return n}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!Number.isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},L=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;emitter=ee();isDestroyed=!1;onInstruction=this.emitter.onInstruction;onBatchInstruction=this.emitter.onBatchInstruction;emit=this.emitter.emit;emitBatch=this.emitter.emitBatch;constructor(e){this.options=e}getSlotForRow(e){return this.state.rowToSlot.get(e)}getSlots(){return this.state.slots}syncSlots(){let e=this.options.getScrollTop(),t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getTotalRows(),i=this.options.getOverscan(),a=n,o=Math.max(0,Math.floor(e/t)-i),s=Math.min(r-1,Math.ceil((e+a)/t)+i);if(r===0||s<o){this.destroyAllSlots();return}let c=new Set;for(let e=o;e<=s;e++)c.add(e);let l=[],u=this.partitionSlots(c),d=0;for(let e of c){let t=this.options.getRowData(e);if(t===void 0)continue;let n=d<u.length?u[d++]:void 0;this.assignSlotToRow(e,t,n,l)}for(let e=d;e<u.length;e++){let t=u[e];this.state.slots.delete(t),l.push({type:`DESTROY_SLOT`,slotId:t})}this.updateSlotPositions(l),this.emitBatch(l)}partitionSlots(e){let t=[];for(let[n,r]of this.state.slots)e.has(r.rowIndex)?e.delete(r.rowIndex):(t.push(n),this.state.rowToSlot.delete(r.rowIndex));return t}assignSlotToRow(e,t,n,r){let i;if(n===void 0)i=`slot-${this.state.nextSlotId++}`,this.state.slots.set(i,{slotId:i,rowIndex:e,rowData:t,translateY:this.getRowTranslateY(e)}),r.push({type:`CREATE_SLOT`,slotId:i});else{i=n;let r=this.state.slots.get(i);r.rowIndex=e,r.rowData=t,r.translateY=this.getRowTranslateY(e)}this.state.rowToSlot.set(e,i),r.push({type:`ASSIGN_SLOT`,slotId:i,rowIndex:e,rowData:t},{type:`MOVE_SLOT`,slotId:i,translateY:this.getRowTranslateY(e)})}updateSlotPositions(e){for(let[t,n]of this.state.slots){let r=this.getRowTranslateY(n.rowIndex);n.translateY!==r&&(n.translateY=r,e.push({type:`MOVE_SLOT`,slotId:t,translateY:r}))}}destroyAllSlots(){let e=[];for(let t of this.state.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitBatch(e)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitter.clearListeners())}refreshAllSlots(){let e=[],t=this.options.getTotalRows();for(let[n,r]of this.state.slots)if(r.rowIndex>=0&&r.rowIndex<t){let t=this.options.getRowData(r.rowIndex);if(t===void 0)continue;let i=this.getRowTranslateY(r.rowIndex);r.rowData=t,r.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:n,rowIndex:r.rowIndex,rowData:t},{type:`MOVE_SLOT`,slotId:n,translateY:i})}this.emitBatch(e),this.syncSlots()}updateSlot(e){let t=this.state.rowToSlot.get(e);if(t){let n=this.options.getRowData(e);n&&this.emit({type:`ASSIGN_SLOT`,slotId:t,rowIndex:e,rowData:n})}}getRowTranslateY(e){let t=this.options.getRowHeight(),n=this.options.getScrollRatio(),r=this.options.getScrollTop(),i=e*t;return n>=1?i:i-Math.floor(r/t)*t}getRowTranslateYForIndex(e){return this.getRowTranslateY(e)}getRowsWrapperOffset(){let e=this.options.getScrollRatio(),t=this.options.getScrollTop(),n=this.options.getRowHeight();return e>=1?0:Math.floor(t/n)*n*e}},R=class{editState=null;options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.editState?{...this.editState}:null}isEditing(){return this.editState!==null}isEditingCell(e,t){return this.editState!==null&&this.editState.row===e&&this.editState.col===t}startEdit(e,t){if(!this.options.getColumn(t)?.editable)return!1;let n=this.options.getCellValue(e,t);return this.editState={row:e,col:t,initialValue:n,currentValue:n},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:n}),!0}updateValue(e){this.editState&&(this.editState.currentValue=e)}commit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.options.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`}),this.options.onCommit?.(e,t,n)}cancel(){this.editState=null,this.emit({type:`STOP_EDIT`})}destroy(){this.emitter.clearListeners(),this.editState=null}};const Ie=e=>{let{batcher:t}=e,n,r=new A({getRowHeight:e.getRowHeight,getHeaderHeight:e.getHeaderHeight,getTotalRows:e.getTotalRows,getScrollTop:()=>n.getScrollTop(),getViewportHeight:()=>n.getViewportHeight()});n=new De(()=>r.getScrollRatio());let i=null,a=new F({getRowCount:e.getTotalRows,getColumnCount:()=>e.getColumns().length,getCellValue:e.getCellValue,getRowData:t=>e.getCachedRows().get(t),getColumn:t=>e.getColumns()[t],setCellValue:e.setCellValue});a.onInstruction(e=>{t.emit(e),i?.onSelectionChange()}),e.highlighting&&(i=new C({getActiveCell:()=>a.getActiveCell(),getSelectionRange:()=>a.getSelectionRange(),getColumn:t=>e.getColumns()[t]},e.highlighting),i.onInstruction(e=>t.emit(e)));let o=new I({getRowCount:e.getTotalRows,getColumnCount:()=>e.getColumns().length,getCellValue:e.getCellValue,getColumn:t=>e.getColumns()[t],setCellValue:e.setCellValue});o.onInstruction(e=>t.emit(e));let s=new L({getRowHeight:e.getRowHeight,getHeaderHeight:e.getHeaderHeight,getOverscan:e.getOverscan,getScrollTop:()=>n.getScrollTop(),getViewportHeight:()=>n.getViewportHeight(),getTotalRows:e.getTotalRows,getScrollRatio:()=>r.getScrollRatio(),getVirtualContentHeight:()=>r.getVirtualContentHeight(),getRowData:t=>e.getCachedRows().get(t)});s.onBatchInstruction(e=>t.emitBatch(e));let c=new R({getColumn:t=>e.getColumns()[t],getCellValue:e.getCellValue,setCellValue:e.setCellValue,onCommit:e=>s.updateSlot(e)});c.onInstruction(e=>t.emit(e));let l=new j({getColumns:e.getColumns,isSortingEnabled:e.getSortingEnabled,getCachedRows:e.getCachedRows,onSortFilterChange:async()=>{await e.fetchData(),i?.clearAllCaches(),n.resetScrollTop(),t.start();try{t.emit({type:`SCROLL_TO`,scrollTop:0}),e.emitContentSize(),e.emitHeaders(),s.refreshAllSlots()}finally{t.flush()}},onDataRefreshed:()=>{}});l.onInstruction(e=>t.emit(e));let u=new w({getCachedRows:e.getCachedRows,setCachedRows:e.setCachedRows,getTotalRows:e.getTotalRows,setTotalRows:e.setTotalRows,updateSlot:e=>s.updateSlot(e),refreshAllSlots:()=>s.refreshAllSlots(),emitContentSize:e.emitContentSize,clearSelectionIfInvalid:e.clearSelectionIfInvalid});return u.onInstruction(e=>t.emit(e)),{selection:a,highlight:i,fill:o,scrollVirtualization:r,viewport:n,slotPool:s,editManager:c,sortFilter:l,rowMutation:u}},Le=e=>{let t=e.columnPositions.at(-1)??0;e.scrollVirtualization.updateContentSize(),e.batcher.emit({type:`SET_CONTENT_SIZE`,width:t,height:e.scrollVirtualization.getVirtualHeight(),viewportWidth:e.viewport.getViewportWidth(),viewportHeight:e.viewport.getViewportHeight(),rowsWrapperOffset:e.slotPool.getRowsWrapperOffset()})},Re=e=>{let t=e.sortFilter.getSortInfoMap();for(let n=0;n<e.columns.length;n++){let r=e.columns[n],i=r.colId??r.field,a=t.get(i);e.batcher.emit({type:`UPDATE_HEADER`,colIndex:n,column:r,sortDirection:a?.direction,sortIndex:a?.index,hasFilter:e.sortFilter.hasActiveFilter(i)})}},ze=e=>{let t=e.scrollVirtualization.getVisibleRowRange();e.batcher.emit({type:`UPDATE_VISIBLE_RANGE`,start:t.start,end:t.end,rowsWrapperOffset:e.slotPool.getRowsWrapperOffset()})};var Be=class{columns;rowHeight;headerHeight;overscan;sortingEnabled;getRowId;onCellValueChanged;rowDragEntireRow;onRowDragEnd;onColumnResized;onColumnMoved;viewport;rowData;selection;fill;input;highlight;sortFilter;rowMutation;slotPool;editManager;columnPositions=[];batcher=new Ee;scrollVirtualization;isDestroyed=!1;constructor(e){if(this.columns=e.columns,this.rowHeight=e.rowHeight,this.headerHeight=e.headerHeight??e.rowHeight,this.overscan=e.overscan??3,this.sortingEnabled=e.sortingEnabled??!0,this.getRowId=e.getRowId,this.onCellValueChanged=e.onCellValueChanged,this.rowDragEntireRow=e.rowDragEntireRow??!1,this.onRowDragEnd=e.onRowDragEnd,this.onColumnResized=e.onColumnResized,this.onColumnMoved=e.onColumnMoved,this.onCellValueChanged&&!this.getRowId)throw Error(`getRowId is required when onCellValueChanged is provided`);this.computeColumnPositions();let t,n,r;this.rowData=new O({dataSource:e.dataSource,rowLoading:e.rowLoading,batcher:this.batcher,getColumns:()=>this.columns,getSortModel:()=>r.getSortModel(),getFilterModel:()=>r.getFilterModel(),getRowHeight:()=>this.rowHeight,getOverscan:()=>this.overscan,getScrollTop:()=>t.getScrollTop(),getViewportHeight:()=>t.getViewportHeight(),onCellValueChanged:this.onCellValueChanged,getRowId:this.getRowId,syncSlots:()=>n.syncSlots(),emitVisibleRange:()=>this.emitVisibleRange(),emitContentSize:()=>this.emitContentSize()});let i=Ie({batcher:this.batcher,highlighting:e.highlighting,getColumns:()=>this.columns,getCachedRows:()=>this.rowData.getCachedRows(),setCachedRows:e=>this.rowData.setCachedRows(e),getTotalRows:()=>this.rowData.getTotalRows(),setTotalRows:e=>this.rowData.setTotalRows(e),getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getSortingEnabled:()=>this.sortingEnabled,getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),fetchData:()=>this.rowData.loadInitial(),clearSelectionIfInvalid:e=>this.clearSelectionIfInvalid(e)});this.selection=i.selection,this.highlight=i.highlight,this.fill=i.fill,this.scrollVirtualization=i.scrollVirtualization,this.viewport=i.viewport,this.slotPool=i.slotPool,this.editManager=i.editManager,this.sortFilter=i.sortFilter,this.rowMutation=i.rowMutation,t=this.viewport,n=this.slotPool,r=this.sortFilter,this.input=new S(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onBatchInstruction(e){return this.batcher.subscribe(e)}async initialize(){await this.rowData.loadInitial(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let{changed:i,viewportSizeChanged:a}=this.viewport.update(e,t,n,r);i&&(this.rowData.requestVisibleRows(),this.slotPool.syncSlots(),this.emitVisibleRange(),a&&this.emitContentSize())}async setSort(e,t,n=!1){if(!this.rowData.isLoading())return this.sortFilter.setSort(e,t,n)}async setFilter(e,t){if(!this.rowData.isLoading())return this.sortFilter.setFilter(e,t)}hasActiveFilter(e){return this.sortFilter.hasActiveFilter(e)}getDistinctValuesForColumn(e,t=500){return this.sortFilter.getDistinctValuesForColumn(e,t)}openFilterPopup(e,t){this.rowData.isLoading()||this.sortFilter.openFilterPopup(e,t)}closeFilterPopup(){this.sortFilter.closeFilterPopup()}getSortModel(){return this.sortFilter.getSortModel()}getFilterModel(){return this.sortFilter.getFilterModel()}startEdit(e,t){this.editManager.startEdit(e,t)}updateEditValue(e){this.editManager.updateValue(e)}commitEdit(){this.editManager.commit()}cancelEdit(){this.editManager.cancel()}pasteClipboardText(e){if(this.editManager.getState())return!1;let t=this.selection.pasteClipboardText(e);return t.changedCells.length>0&&this.refreshSlotData(),t.handled}getEditState(){return this.editManager.getState()}getCellValue(e,t){return this.rowData.getCellValue(e,t)}setCellValue(e,t,n){this.rowData.setCellValue(e,t,n)}clearSelectionIfInvalid(e){let t=this.selection.getActiveCell();t&&t.row>=e&&this.selection.clearSelection()}computeColumnPositions(){this.columnPositions=se(this.columns)}emitContentSize(){Le({batcher:this.batcher,scrollVirtualization:this.scrollVirtualization,slotPool:this.slotPool,viewport:this.viewport,columnPositions:this.columnPositions})}emitHeaders(){Re({batcher:this.batcher,sortFilter:this.sortFilter,columns:this.columns})}emitVisibleRange(){ze({batcher:this.batcher,scrollVirtualization:this.scrollVirtualization,slotPool:this.slotPool})}setColumnWidth(e,t){Se(e,t,{batcher:this.batcher,slotPool:this.slotPool,refreshSlots:`sync`,computeColumnPositions:()=>this.computeColumnPositions(),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),columns:this.columns,onComplete:()=>this.onColumnResized?.(e,t)})}moveColumn(e,t){let n=Ce(e,t,{batcher:this.batcher,slotPool:this.slotPool,refreshSlots:`all`,computeColumnPositions:()=>this.computeColumnPositions(),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),columns:this.columns,onComplete:()=>{}});n!==null&&this.onColumnMoved?.(e,n)}commitRowDrag(e,t){we(e,t,{dataSource:this.rowData.getDataSource(),cachedRows:this.rowData.getCachedRows(),slotPool:this.slotPool,highlight:this.highlight}),this.onRowDragEnd?.(e,t)}isRowDragEntireRow(){return this.rowDragEntireRow}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.rowData.getTotalRows()}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions.at(-1)??0}getTotalHeight(){return this.scrollVirtualization.getVirtualHeight()}isScalingActive(){return this.scrollVirtualization.isScalingActive()}getNaturalHeight(){return this.scrollVirtualization.getNaturalHeight()}getScrollRatio(){return this.scrollVirtualization.getScrollRatio()}getVisibleRowRange(){return this.scrollVirtualization.getVisibleRowRange()}getScrollTopForRow(e){return this.scrollVirtualization.getScrollTopForRow(e)}getRowIndexAtDisplayY(e,t){return this.scrollVirtualization.getRowIndexAtDisplayY(e,t)}getRowTranslateY(e){return this.slotPool.getRowTranslateYForIndex(e)}getRowData(e){return this.rowData.getRowData(e)}async refresh(){await this.rowData.loadInitial(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitVisibleRange()}async refreshFromTransaction(){await this.rowData.refreshFromTransaction(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitVisibleRange()}refreshSlotData(){this.slotPool.refreshAllSlots()}addRows(e,t){this.rowMutation.addRows(e,t)}updateRows(e){this.rowMutation.updateRows(e)}deleteRows(e){this.rowMutation.deleteRows(e)}getRow(e){return this.rowMutation.getRow(e)}setRow(e,t){this.rowMutation.setRow(e,t)}async setDataSource(e){this.editManager.getState()&&this.editManager.cancel(),this.rowData.setDataSource(e),await this.refresh(),this.clearSelectionIfInvalid(this.rowData.getTotalRows())}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.slotPool.syncSlots()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.slotPool.destroy(),this.highlight?.destroy(),this.sortFilter.destroy(),this.rowMutation.destroy(),this.rowData.destroy(),this.batcher.clearListeners())}},z=class{workerCode;maxWorkers;workers=[];workerUrl=null;nextRequestId=0;isTerminated=!1;constructor(e,t={}){this.workerCode=e;let n=typeof navigator>`u`?4:navigator.hardwareConcurrency;this.maxWorkers=Math.max(1,t.maxWorkers??n??4),t.preWarm&&this.preWarmWorkers()}getPoolSize(){return this.workers.length}getMaxWorkers(){return this.maxWorkers}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}async execute(e,t){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(typeof Worker>`u`)throw TypeError(`Web Workers are not available in this environment`);let n=this.getAvailableWorker(),r=this.nextRequestId++,i={...e,id:r};return new Promise((e,a)=>{n.pendingRequests.set(r,{resolve:e,reject:a}),n.busy=!0,t&&t.length>0?n.worker.postMessage(i,t):n.worker.postMessage(i)})}async executeParallel(e){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(e.length===0)return[];let t=Math.min(e.length,this.maxWorkers);this.ensureWorkers(t);let n=e.map((e,t)=>{let n=t%this.workers.length,r=this.workers[n],i=this.nextRequestId++,a={...e.request,id:i};return new Promise((t,n)=>{r.pendingRequests.set(i,{resolve:t,reject:n}),r.busy=!0,e.transferables&&e.transferables.length>0?r.worker.postMessage(a,e.transferables):r.worker.postMessage(a)})});return Promise.all(n)}terminate(){for(let e of this.workers){e.worker.terminate();for(let[,t]of e.pendingRequests)t.reject(Error(`Worker pool terminated`));e.pendingRequests.clear()}this.workers=[],this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null),this.isTerminated=!0}preWarmWorkers(){this.ensureWorkers(this.maxWorkers)}ensureWorkers(e){let t=Math.min(e,this.maxWorkers)-this.workers.length;for(let e=0;e<t;e++)this.createWorker()}getAvailableWorker(){return this.workers.find(e=>!e.busy)||(this.workers.length<this.maxWorkers?this.createWorker():this.workers.reduce((e,t)=>t.pendingRequests.size<e.pendingRequests.size?t:e,this.workers[0]))}createWorker(){if(!this.workerUrl){let e=new Blob([this.workerCode],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e)}let e=new Worker(this.workerUrl),t={worker:e,busy:!1,pendingRequests:new Map};return e.onmessage=e=>{let{id:n}=e.data,r=t.pendingRequests.get(n);r&&(t.pendingRequests.delete(n),t.pendingRequests.size===0&&(t.busy=!1),e.data.type===`error`?r.reject(Error(e.data.error)):r.resolve(e.data))},e.onerror=e=>{for(let[,n]of t.pendingRequests)n.reject(Error(`Worker error: ${e.message}`));t.pendingRequests.clear(),t.busy=!1,this.respawnWorker(t)},this.workers.push(t),t}respawnWorker(e){let t=this.workers.indexOf(e);if(t!==-1){try{e.worker.terminate()}catch{}this.workers.splice(t,1),this.workers.length<this.maxWorkers&&!this.isTerminated&&this.createWorker()}}};function B(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}const V=e=>e==null?``:Array.isArray(e)?e.join(`, `):typeof e==`object`&&!(e instanceof Date)?JSON.stringify(e):String(e);function Ve(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!Number.isNaN(n)&&!Number.isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():V(e).localeCompare(V(t))}function He(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=Ve(B(e,r),B(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}const H=globalThis;H.onmessage!==void 0&&(H.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=He(r,i);H.postMessage?.({type:`sorted`,id:n,data:e})}catch(e){H.postMessage?.({type:`error`,id:n,error:String(e)})}});var Ue=class{heap=[];compare;constructor(e){this.compare=e}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}};const We=(e,t,n)=>{let r=[];for(let i=0;i<n;i++)r.push(e.columns[i][t]);return r};function U(e,t){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let n=0;for(let t of e)n+=t.indices.length;let r=new Uint32Array(n),i=t===`asc`?1:-1,a=new Ue((e,t)=>(e.value-t.value)*i);for(let t=0;t<e.length;t++){let n=e[t];if(n.indices.length>0){let e=n.indices[0];a.push({chunkIndex:t,positionInChunk:0,value:n.values[0],globalIndex:e+n.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();r[o++]=t.globalIndex;let n=e[t.chunkIndex],i=t.positionInChunk+1;if(i<n.indices.length){let e=n.indices[i];a.push({chunkIndex:t.chunkIndex,positionInChunk:i,value:n.values[i],globalIndex:e+n.offset})}}return r}function Ge(e){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let t=e[0].directions,n=t.length,r=0;for(let t of e)r+=t.indices.length;let i=new Uint32Array(r),a=new Ue((e,n)=>{for(let r=0;r<t.length;r++){let i=(e.values[r]-n.values[r])*t[r];if(i!==0)return i}return 0});for(let t=0;t<e.length;t++){let r=e[t];if(r.indices.length>0){let e=r.indices[0];a.push({chunkIndex:t,positionInChunk:0,values:We(r,0,n),globalIndex:e+r.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();i[o++]=t.globalIndex;let r=e[t.chunkIndex],s=t.positionInChunk+1;if(s<r.indices.length){let e=r.indices[s];a.push({chunkIndex:t.chunkIndex,positionInChunk:s,values:We(r,s,n),globalIndex:e+r.offset})}}return i}function Ke(e,t){if(e.length<=1)return new Uint32Array;let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.indices.length-1,s=i.values[o],c=a.values[0];if(s===c){let e=o;for(;e>0&&i.values[e-1]===s;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===c;)t++;let l=r+e,u=r+i.indices.length+t+1;n.push(l,u)}r+=i.indices.length}return new Uint32Array(n)}const qe=(e,t,n)=>{let r=Math.max(n,Math.ceil(e/t)),i=[];for(let t=0;t<e;t+=r)i.push({offset:t,length:Math.min(r,e-t)});return i},Je=e=>{if(e.length<=1)return[];let t=[],n=0;for(let r=0;r<e.length-1;r++){let i=e[r],a=e[r+1];if(i.indices.length===0||a.indices.length===0){n+=i.indices.length;continue}let o=i.values[i.indices.length-1],s=a.values[0];if(o===s){let e=i.indices.length-1;for(;e>0&&i.values[e-1]===o;)e--;let r=0;for(;r<a.indices.length-1&&a.values[r+1]===s;)r++;t.push(n+e,n+i.indices.length+r+1)}n+=i.indices.length}return t},Ye=(e,t,n,r)=>{let i=r===`asc`?1:-1;for(let r=0;r<t.length;r+=2){let a=t[r],o=t[r+1];o<=a||o>e.length||Xe(e,a,o,n,i)}},Xe=(e,t,n,r,i)=>{let a=Array.from(e.slice(t,n));if(!Ze(a,r)){a.sort((e,t)=>i*r[e].localeCompare(r[t]));for(let n=0;n<a.length;n++)e[t+n]=a[n]}},Ze=(e,t)=>{let n=t[e[0]];for(let r=1;r<e.length;r++)if(t[e[r]]!==n)return!1;return!0};var W=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){this.pool=new z(`
4
+ `),Ae=e=>{let t=N(e).split(`
5
+ `);return t.length>1&&t.at(-1)===``&&t.pop(),t.map(e=>e.split(` `).map(e=>({value:e,text:e})))},je=(e,t)=>{if(e.value===null)return{ok:!0,value:null};let n=e.text,r=n.trim();if(r.length===0)return Me(t);switch(t.cellDataType){case`text`:return{ok:!0,value:n};case`number`:return Ne(e.value,r);case`boolean`:return Pe(e.value,r);case`date`:case`dateTime`:return Fe(e.value,r);case`dateString`:case`dateTimeString`:return Ie(r,n);case`object`:return Le(e.value,r)}},Me=e=>e.cellDataType===`text`?{ok:!0,value:``}:{ok:!0,value:null},Ne=(e,t)=>{if(typeof e==`number`&&Number.isFinite(e))return{ok:!0,value:e};let n=Number(t);return Number.isFinite(n)?{ok:!0,value:n}:{ok:!1}},Pe=(e,t)=>{if(typeof e==`boolean`)return{ok:!0,value:e};let n=t.toLowerCase();return n===`true`?{ok:!0,value:!0}:n===`false`?{ok:!0,value:!1}:{ok:!1}},Fe=(e,t)=>{if(e instanceof Date&&P(e))return{ok:!0,value:e};let n=new Date(t);return P(n)?{ok:!0,value:n}:{ok:!1}},Ie=(e,t)=>P(new Date(e))?{ok:!0,value:t}:{ok:!1},Le=(e,t)=>{if(typeof e==`object`&&e&&!(e instanceof Date))return{ok:!0,value:e};try{let e=JSON.parse(t);if(typeof e==`object`&&e)return{ok:!0,value:e}}catch{return{ok:!1}}return{ok:!1}},P=e=>Number.isFinite(e.getTime());var F=class{state={activeCell:null,range:null,anchor:null,selectionMode:!1};options;emitter=v();clipboardSnapshot=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return{...this.state}}getActiveCell(){return this.state.activeCell}getSelectionRange(){return this.state.range}isSelected(e,t){let{range:n}=this.state;if(!n)return!1;let{minRow:r,maxRow:i,minCol:a,maxCol:s}=o(n);return e>=r&&e<=i&&t>=a&&t<=s}isActiveCell(e,t){let{activeCell:n}=this.state;return n?.row===e&&n?.col===t}startSelection(e,t={}){let{shift:n=!1,ctrl:r=!1}=t,{row:i,col:a}=this.clampPosition(e);n&&this.state.anchor?(this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a}):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null),this.state.selectionMode=r,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}moveFocus(e,t=!1){if(!this.state.activeCell){this.startSelection({row:0,col:0});return}let{row:n,col:r}=this.state.activeCell,i=n,a=r;switch(e){case`up`:i=Math.max(0,n-1);break;case`down`:i=Math.min(this.options.getRowCount()-1,n+1);break;case`left`:a=Math.max(0,r-1);break;case`right`:a=Math.min(this.options.getColumnCount()-1,r+1);break}t?(this.state.anchor??={row:n,col:r},this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null}))}selectAll(){let e=this.options.getRowCount(),t=this.options.getColumnCount();e===0||t===0||(this.state.range={startRow:0,startCol:0,endRow:e-1,endCol:t-1},this.state.activeCell||(this.state.activeCell={row:0,col:0},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell})),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range}))}clearSelection(){this.state.activeCell=null,this.state.range=null,this.state.anchor=null,this.state.selectionMode=!1,this.emit({type:`SET_ACTIVE_CELL`,position:null}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setActiveCell(e,t){let n=this.clampPosition({row:e,col:t});this.state.activeCell=n,this.state.anchor=n,this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setSelectionRange(e){this.state.range=e,this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}getSelectedData(){let e=this.getEffectiveRange();if(e===null)return[];let{minRow:t,maxRow:n,minCol:r,maxCol:i}=o(e),a=[];for(let e=t;e<=n;e++){let t=[];for(let n=r;n<=i;n++)t.push(this.options.getCellValue(e,n));a.push(t)}return a}async copySelectionToClipboard(){let e=this.getEffectiveRange();if(e===null)return;let t=this.createClipboardSnapshot(e);t.cells.length!==0&&(this.clipboardSnapshot=t,!(typeof navigator>`u`||typeof document>`u`)&&await navigator.clipboard.writeText(t.text))}pasteClipboardText(e){let t=this.getEffectiveRange();if(t===null)return{handled:!1,changedCells:[]};let n=this.getPasteSourceCells(e);return n.length===0?{handled:!1,changedCells:[]}:{handled:!0,changedCells:this.applyPasteSource(n,t,this.state.range!==null)}}destroy(){this.emitter.clearListeners(),this.state={activeCell:null,range:null,anchor:null,selectionMode:!1},this.clipboardSnapshot=null}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}getEffectiveRange(){let{range:e,activeCell:t}=this.state;return e||(t?{startRow:t.row,startCol:t.col,endRow:t.row,endCol:t.col}:null)}createClipboardSnapshot(e){let{minRow:t,maxRow:n,minCol:r,maxCol:i}=o(e),a=[];for(let e=t;e<=n;e++){let t=[];for(let n=r;n<=i;n++){let r=this.options.getCellValue(e,n),i=y(r,this.options.getColumn(n)?.valueFormatter);t.push({value:r,text:i})}a.push(t)}return{cells:a,text:a.map(e=>e.map(e=>e.text).join(` `)).join(`
6
+ `)}}getPasteSourceCells(e){let t=this.clipboardSnapshot;return t&&N(t.text)===N(e)?t.cells:Ae(e)}applyPasteSource(e,t,n){let r=[],{minRow:i,maxRow:a,minCol:s,maxCol:c}=o(t),l=this.isSingleSourceCell(e),u=l?a:i+e.length-1,d=l?c:s+this.getMaxSourceColumnCount(e)-1,f=n?Math.min(u,a):u,p=n?Math.min(d,c):d,m=this.options.getRowCount(),h=this.options.getColumnCount(),g=Math.min(f,m-1),_=Math.min(p,h-1);for(let t=i;t<=g;t++)for(let n=s;n<=_;n++){let a=this.getSourceCellForTarget(e,t-i,n-s,l);a&&this.applyPasteCell(t,n,a,r)}return r}applyPasteCell(e,t,n,r){let i=this.options.getColumn(t);if(i===void 0||i.hidden===!0||i.editable!==!0)return;let a=je(n,i);a.ok!==!1&&(this.options.setCellValue(e,t,a.value),r.push({row:e,col:t,value:a.value}))}getSourceCellForTarget(e,t,n,r){return r?e[0]?.[0]??null:e[t]?.[n]??null}isSingleSourceCell(e){return e.length===1&&e[0]?.length===1}getMaxSourceColumnCount(e){return e.reduce((e,t)=>Math.max(e,t.length),0)}},I=class{state=null;options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t}=this.state,n=this.calculateFilledCells(e,t);for(let{row:e,col:t,value:r}of n)this.options.setCellValue(e,t,r);this.emit({type:`COMMIT_FILL`,filledCells:n}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}destroy(){this.emitter.clearListeners(),this.state=null}calculateFilledCells(e,t){let n=[],{minRow:r,maxRow:i,minCol:a,maxCol:s}=o(e),c=t>i,l=t<r;if(c||l)for(let e=a;e<=s;e++){let a=this.getSourceColumnValues(r,i,e),o=this.detectPattern(a);if(c)for(let r=i+1;r<=t;r++){let t=r-i-1,s=this.applyPattern(o,a,t);n.push({row:r,col:e,value:s})}else if(l)for(let i=r-1;i>=t;i--){let t=r-i-1,s=this.applyPattern(o,a,t,!0);n.push({row:i,col:e,value:s})}}return n}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!Number.isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},L=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;emitter=ee();isDestroyed=!1;onInstruction=this.emitter.onInstruction;onBatchInstruction=this.emitter.onBatchInstruction;emit=this.emitter.emit;emitBatch=this.emitter.emitBatch;constructor(e){this.options=e}getSlotForRow(e){return this.state.rowToSlot.get(e)}getSlots(){return this.state.slots}syncSlots(){let e=this.options.getScrollTop(),t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getTotalRows(),i=this.options.getOverscan(),a=n,o=Math.max(0,Math.floor(e/t)-i),s=Math.min(r-1,Math.ceil((e+a)/t)+i);if(r===0||s<o){this.destroyAllSlots();return}let c=new Set;for(let e=o;e<=s;e++)c.add(e);let l=[],u=this.partitionSlots(c),d=0;for(let e of c){let t=this.options.getRowData(e);if(t===void 0)continue;let n=d<u.length?u[d++]:void 0;this.assignSlotToRow(e,t,n,l)}for(let e=d;e<u.length;e++){let t=u[e];this.state.slots.delete(t),l.push({type:`DESTROY_SLOT`,slotId:t})}this.updateSlotPositions(l),this.emitBatch(l)}partitionSlots(e){let t=[];for(let[n,r]of this.state.slots)e.has(r.rowIndex)?e.delete(r.rowIndex):(t.push(n),this.state.rowToSlot.delete(r.rowIndex));return t}assignSlotToRow(e,t,n,r){let i;if(n===void 0)i=`slot-${this.state.nextSlotId++}`,this.state.slots.set(i,{slotId:i,rowIndex:e,rowData:t,translateY:this.getRowTranslateY(e)}),r.push({type:`CREATE_SLOT`,slotId:i});else{i=n;let r=this.state.slots.get(i);r.rowIndex=e,r.rowData=t,r.translateY=this.getRowTranslateY(e)}this.state.rowToSlot.set(e,i),r.push({type:`ASSIGN_SLOT`,slotId:i,rowIndex:e,rowData:t},{type:`MOVE_SLOT`,slotId:i,translateY:this.getRowTranslateY(e)})}updateSlotPositions(e){for(let[t,n]of this.state.slots){let r=this.getRowTranslateY(n.rowIndex);n.translateY!==r&&(n.translateY=r,e.push({type:`MOVE_SLOT`,slotId:t,translateY:r}))}}destroyAllSlots(){let e=[];for(let t of this.state.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitBatch(e)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitter.clearListeners())}refreshAllSlots(){let e=[],t=this.options.getTotalRows();for(let[n,r]of this.state.slots)if(r.rowIndex>=0&&r.rowIndex<t){let t=this.options.getRowData(r.rowIndex);if(t===void 0)continue;let i=this.getRowTranslateY(r.rowIndex);r.rowData=t,r.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:n,rowIndex:r.rowIndex,rowData:t},{type:`MOVE_SLOT`,slotId:n,translateY:i})}this.emitBatch(e),this.syncSlots()}updateSlot(e){let t=this.state.rowToSlot.get(e);if(t){let n=this.options.getRowData(e);n&&this.emit({type:`ASSIGN_SLOT`,slotId:t,rowIndex:e,rowData:n})}}getRowTranslateY(e){let t=this.options.getRowHeight(),n=this.options.getScrollRatio(),r=this.options.getScrollTop(),i=e*t;return n>=1?i:i-Math.floor(r/t)*t}getRowTranslateYForIndex(e){return this.getRowTranslateY(e)}getRowsWrapperOffset(){let e=this.options.getScrollRatio(),t=this.options.getScrollTop(),n=this.options.getRowHeight();return e>=1?0:Math.floor(t/n)*n*e}},R=class{editState=null;peekState=null;options;emitter=v();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.editState?{...this.editState}:null}isEditing(){return this.editState!==null}isEditingCell(e,t){return this.editState!==null&&this.editState.row===e&&this.editState.col===t}startEdit(e,t){if(!this.options.getColumn(t)?.editable)return!1;this.peekState!==null&&this.stopPeek();let n=this.options.getCellValue(e,t);return this.editState={row:e,col:t,initialValue:n,currentValue:n},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:n}),!0}getPeekState(){return this.peekState?{...this.peekState}:null}startPeek(e,t){return this.editState===null?(this.peekState={row:e,col:t},this.emit({type:`START_PEEK`,row:e,col:t}),!0):!1}stopPeek(){this.peekState!==null&&(this.peekState=null,this.emit({type:`STOP_PEEK`}))}updateValue(e){this.editState&&(this.editState.currentValue=e)}commit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.options.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`}),this.options.onCommit?.(e,t,n)}cancel(){this.editState=null,this.emit({type:`STOP_EDIT`})}destroy(){this.emitter.clearListeners(),this.editState=null,this.peekState=null}};const Re=e=>{let{batcher:t}=e,n,r=new A({getRowHeight:e.getRowHeight,getHeaderHeight:e.getHeaderHeight,getTotalRows:e.getTotalRows,getScrollTop:()=>n.getScrollTop(),getViewportHeight:()=>n.getViewportHeight()});n=new ke(()=>r.getScrollRatio());let i=null,a=new F({getRowCount:e.getTotalRows,getColumnCount:()=>e.getColumns().length,getCellValue:e.getCellValue,getRowData:t=>e.getCachedRows().get(t),getColumn:t=>e.getColumns()[t],setCellValue:e.setCellValue});a.onInstruction(e=>{t.emit(e),i?.onSelectionChange()}),e.highlighting&&(i=new C({getActiveCell:()=>a.getActiveCell(),getSelectionRange:()=>a.getSelectionRange(),getColumn:t=>e.getColumns()[t]},e.highlighting),i.onInstruction(e=>t.emit(e)));let o=new I({getRowCount:e.getTotalRows,getColumnCount:()=>e.getColumns().length,getCellValue:e.getCellValue,getColumn:t=>e.getColumns()[t],setCellValue:e.setCellValue});o.onInstruction(e=>t.emit(e));let s=new L({getRowHeight:e.getRowHeight,getHeaderHeight:e.getHeaderHeight,getOverscan:e.getOverscan,getScrollTop:()=>n.getScrollTop(),getViewportHeight:()=>n.getViewportHeight(),getTotalRows:e.getTotalRows,getScrollRatio:()=>r.getScrollRatio(),getVirtualContentHeight:()=>r.getVirtualContentHeight(),getRowData:t=>e.getCachedRows().get(t)});s.onBatchInstruction(e=>t.emitBatch(e));let c=new R({getColumn:t=>e.getColumns()[t],getCellValue:e.getCellValue,setCellValue:e.setCellValue,onCommit:e=>s.updateSlot(e)});c.onInstruction(e=>t.emit(e));let l=new j({getColumns:e.getColumns,isSortingEnabled:e.getSortingEnabled,getCachedRows:e.getCachedRows,onSortFilterChange:async()=>{await e.fetchData(),i?.clearAllCaches(),n.resetScrollTop(),t.start();try{t.emit({type:`SCROLL_TO`,scrollTop:0}),e.emitContentSize(),e.emitHeaders(),s.refreshAllSlots()}finally{t.flush()}},onDataRefreshed:()=>{}});l.onInstruction(e=>t.emit(e));let u=new w({getCachedRows:e.getCachedRows,setCachedRows:e.setCachedRows,getTotalRows:e.getTotalRows,setTotalRows:e.setTotalRows,updateSlot:e=>s.updateSlot(e),refreshAllSlots:()=>s.refreshAllSlots(),emitContentSize:e.emitContentSize,clearSelectionIfInvalid:e.clearSelectionIfInvalid});return u.onInstruction(e=>t.emit(e)),{selection:a,highlight:i,fill:o,scrollVirtualization:r,viewport:n,slotPool:s,editManager:c,sortFilter:l,rowMutation:u}},ze=e=>{let t=e.columnPositions.at(-1)??0;e.scrollVirtualization.updateContentSize(),e.batcher.emit({type:`SET_CONTENT_SIZE`,width:t,height:e.scrollVirtualization.getVirtualHeight(),viewportWidth:e.viewport.getViewportWidth(),viewportHeight:e.viewport.getViewportHeight(),rowsWrapperOffset:e.slotPool.getRowsWrapperOffset()})},Be=e=>{let t=e.sortFilter.getSortInfoMap();for(let n=0;n<e.columns.length;n++){let r=e.columns[n],i=r.colId??r.field,a=t.get(i);e.batcher.emit({type:`UPDATE_HEADER`,colIndex:n,column:r,sortDirection:a?.direction,sortIndex:a?.index,hasFilter:e.sortFilter.hasActiveFilter(i)})}},Ve=e=>{let t=e.scrollVirtualization.getVisibleRowRange();e.batcher.emit({type:`UPDATE_VISIBLE_RANGE`,start:t.start,end:t.end,rowsWrapperOffset:e.slotPool.getRowsWrapperOffset()})};var He=class{columns;rowHeight;headerHeight;overscan;sortingEnabled;getRowId;onCellValueChanged;rowDragEntireRow;onRowDragEnd;onColumnResized;onColumnMoved;viewport;rowData;selection;fill;input;highlight;sortFilter;rowMutation;slotPool;editManager;columnPositions=[];batcher=new Oe;scrollVirtualization;isDestroyed=!1;constructor(e){if(this.columns=e.columns,this.rowHeight=e.rowHeight,this.headerHeight=e.headerHeight??e.rowHeight,this.overscan=e.overscan??3,this.sortingEnabled=e.sortingEnabled??!0,this.getRowId=e.getRowId,this.onCellValueChanged=e.onCellValueChanged,this.rowDragEntireRow=e.rowDragEntireRow??!1,this.onRowDragEnd=e.onRowDragEnd,this.onColumnResized=e.onColumnResized,this.onColumnMoved=e.onColumnMoved,this.onCellValueChanged&&!this.getRowId)throw Error(`getRowId is required when onCellValueChanged is provided`);this.computeColumnPositions();let t,n,r;this.rowData=new O({dataSource:e.dataSource,rowLoading:e.rowLoading,batcher:this.batcher,getColumns:()=>this.columns,getSortModel:()=>r.getSortModel(),getFilterModel:()=>r.getFilterModel(),getRowHeight:()=>this.rowHeight,getOverscan:()=>this.overscan,getScrollTop:()=>t.getScrollTop(),getViewportHeight:()=>t.getViewportHeight(),onCellValueChanged:this.onCellValueChanged,getRowId:this.getRowId,syncSlots:()=>n.syncSlots(),emitVisibleRange:()=>this.emitVisibleRange(),emitContentSize:()=>this.emitContentSize()});let i=Re({batcher:this.batcher,highlighting:e.highlighting,getColumns:()=>this.columns,getCachedRows:()=>this.rowData.getCachedRows(),setCachedRows:e=>this.rowData.setCachedRows(e),getTotalRows:()=>this.rowData.getTotalRows(),setTotalRows:e=>this.rowData.setTotalRows(e),getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getSortingEnabled:()=>this.sortingEnabled,getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),fetchData:()=>this.rowData.loadInitial(),clearSelectionIfInvalid:e=>this.clearSelectionIfInvalid(e)});this.selection=i.selection,this.highlight=i.highlight,this.fill=i.fill,this.scrollVirtualization=i.scrollVirtualization,this.viewport=i.viewport,this.slotPool=i.slotPool,this.editManager=i.editManager,this.sortFilter=i.sortFilter,this.rowMutation=i.rowMutation,t=this.viewport,n=this.slotPool,r=this.sortFilter,this.input=new S(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onBatchInstruction(e){return this.batcher.subscribe(e)}async initialize(){await this.rowData.loadInitial(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let{changed:i,viewportSizeChanged:a}=this.viewport.update(e,t,n,r);i&&(this.rowData.requestVisibleRows(),this.slotPool.syncSlots(),this.emitVisibleRange(),a&&this.emitContentSize())}async setSort(e,t,n=!1){if(!this.rowData.isLoading())return this.sortFilter.setSort(e,t,n)}async setFilter(e,t){if(!this.rowData.isLoading())return this.sortFilter.setFilter(e,t)}hasActiveFilter(e){return this.sortFilter.hasActiveFilter(e)}getDistinctValuesForColumn(e,t=500){return this.sortFilter.getDistinctValuesForColumn(e,t)}openFilterPopup(e,t){this.rowData.isLoading()||this.sortFilter.openFilterPopup(e,t)}closeFilterPopup(){this.sortFilter.closeFilterPopup()}getSortModel(){return this.sortFilter.getSortModel()}getFilterModel(){return this.sortFilter.getFilterModel()}startEdit(e,t){this.editManager.startEdit(e,t)}startPeek(e,t){let n=this.columns[t];return!n||n.peekable===!1?!1:this.editManager.startPeek(e,t)}stopPeek(){this.editManager.stopPeek()}getPeekState(){return this.editManager.getPeekState()}updateEditValue(e){this.editManager.updateValue(e)}commitEdit(){this.editManager.commit()}cancelEdit(){this.editManager.cancel()}pasteClipboardText(e){if(this.editManager.getState())return!1;let t=this.selection.pasteClipboardText(e);return t.changedCells.length>0&&this.refreshSlotData(),t.handled}getEditState(){return this.editManager.getState()}getCellValue(e,t){return this.rowData.getCellValue(e,t)}setCellValue(e,t,n){this.rowData.setCellValue(e,t,n)}clearSelectionIfInvalid(e){let t=this.selection.getActiveCell();t&&t.row>=e&&this.selection.clearSelection()}computeColumnPositions(){this.columnPositions=ce(this.columns)}emitContentSize(){ze({batcher:this.batcher,scrollVirtualization:this.scrollVirtualization,slotPool:this.slotPool,viewport:this.viewport,columnPositions:this.columnPositions})}emitHeaders(){Be({batcher:this.batcher,sortFilter:this.sortFilter,columns:this.columns})}emitVisibleRange(){Ve({batcher:this.batcher,scrollVirtualization:this.scrollVirtualization,slotPool:this.slotPool})}setColumnWidth(e,t){we(e,t,this.viewport.getViewportWidth(),{batcher:this.batcher,slotPool:this.slotPool,refreshSlots:`sync`,computeColumnPositions:()=>this.computeColumnPositions(),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),columns:this.columns,onComplete:()=>this.onColumnResized?.(e,t)})}moveColumn(e,t){let n=Te(e,t,{batcher:this.batcher,slotPool:this.slotPool,refreshSlots:`all`,computeColumnPositions:()=>this.computeColumnPositions(),emitContentSize:()=>this.emitContentSize(),emitHeaders:()=>this.emitHeaders(),columns:this.columns,onComplete:()=>{}});n!==null&&this.onColumnMoved?.(e,n)}commitRowDrag(e,t){Ee(e,t,{dataSource:this.rowData.getDataSource(),cachedRows:this.rowData.getCachedRows(),slotPool:this.slotPool,highlight:this.highlight}),this.onRowDragEnd?.(e,t)}isRowDragEntireRow(){return this.rowDragEntireRow}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.rowData.getTotalRows()}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions.at(-1)??0}getTotalHeight(){return this.scrollVirtualization.getVirtualHeight()}isScalingActive(){return this.scrollVirtualization.isScalingActive()}getNaturalHeight(){return this.scrollVirtualization.getNaturalHeight()}getScrollRatio(){return this.scrollVirtualization.getScrollRatio()}getVisibleRowRange(){return this.scrollVirtualization.getVisibleRowRange()}getScrollTopForRow(e){return this.scrollVirtualization.getScrollTopForRow(e)}getRowIndexAtDisplayY(e,t){return this.scrollVirtualization.getRowIndexAtDisplayY(e,t)}getRowTranslateY(e){return this.slotPool.getRowTranslateYForIndex(e)}getRowData(e){return this.rowData.getRowData(e)}async refresh(){await this.rowData.loadInitial(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitVisibleRange()}async refreshFromTransaction(){await this.rowData.refreshFromTransaction(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitVisibleRange()}refreshSlotData(){this.slotPool.refreshAllSlots()}addRows(e,t){this.rowMutation.addRows(e,t)}updateRows(e){this.rowMutation.updateRows(e)}deleteRows(e){this.rowMutation.deleteRows(e)}getRow(e){return this.rowMutation.getRow(e)}setRow(e,t){this.rowMutation.setRow(e,t)}async setDataSource(e){this.editManager.getState()&&this.editManager.cancel(),this.rowData.setDataSource(e),await this.refresh(),this.clearSelectionIfInvalid(this.rowData.getTotalRows())}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.slotPool.syncSlots()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.slotPool.destroy(),this.highlight?.destroy(),this.sortFilter.destroy(),this.rowMutation.destroy(),this.rowData.destroy(),this.batcher.clearListeners())}},z=class{workerCode;maxWorkers;workers=[];workerUrl=null;nextRequestId=0;isTerminated=!1;constructor(e,t={}){this.workerCode=e;let n=typeof navigator>`u`?4:navigator.hardwareConcurrency;this.maxWorkers=Math.max(1,t.maxWorkers??n??4),t.preWarm&&this.preWarmWorkers()}getPoolSize(){return this.workers.length}getMaxWorkers(){return this.maxWorkers}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}async execute(e,t){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(typeof Worker>`u`)throw TypeError(`Web Workers are not available in this environment`);let n=this.getAvailableWorker(),r=this.nextRequestId++,i={...e,id:r};return new Promise((e,a)=>{n.pendingRequests.set(r,{resolve:e,reject:a}),n.busy=!0,t&&t.length>0?n.worker.postMessage(i,t):n.worker.postMessage(i)})}async executeParallel(e){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(e.length===0)return[];let t=Math.min(e.length,this.maxWorkers);this.ensureWorkers(t);let n=e.map((e,t)=>{let n=t%this.workers.length,r=this.workers[n],i=this.nextRequestId++,a={...e.request,id:i};return new Promise((t,n)=>{r.pendingRequests.set(i,{resolve:t,reject:n}),r.busy=!0,e.transferables&&e.transferables.length>0?r.worker.postMessage(a,e.transferables):r.worker.postMessage(a)})});return Promise.all(n)}terminate(){for(let e of this.workers){e.worker.terminate();for(let[,t]of e.pendingRequests)t.reject(Error(`Worker pool terminated`));e.pendingRequests.clear()}this.workers=[],this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null),this.isTerminated=!0}preWarmWorkers(){this.ensureWorkers(this.maxWorkers)}ensureWorkers(e){let t=Math.min(e,this.maxWorkers)-this.workers.length;for(let e=0;e<t;e++)this.createWorker()}getAvailableWorker(){return this.workers.find(e=>!e.busy)||(this.workers.length<this.maxWorkers?this.createWorker():this.workers.reduce((e,t)=>t.pendingRequests.size<e.pendingRequests.size?t:e,this.workers[0]))}createWorker(){if(!this.workerUrl){let e=new Blob([this.workerCode],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e)}let e=new Worker(this.workerUrl),t={worker:e,busy:!1,pendingRequests:new Map};return e.onmessage=e=>{let{id:n}=e.data,r=t.pendingRequests.get(n);r&&(t.pendingRequests.delete(n),t.pendingRequests.size===0&&(t.busy=!1),e.data.type===`error`?r.reject(Error(e.data.error)):r.resolve(e.data))},e.onerror=e=>{for(let[,n]of t.pendingRequests)n.reject(Error(`Worker error: ${e.message}`));t.pendingRequests.clear(),t.busy=!1,this.respawnWorker(t)},this.workers.push(t),t}respawnWorker(e){let t=this.workers.indexOf(e);if(t!==-1){try{e.worker.terminate()}catch{}this.workers.splice(t,1),this.workers.length<this.maxWorkers&&!this.isTerminated&&this.createWorker()}}};function B(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}const V=e=>e==null?``:Array.isArray(e)?e.join(`, `):typeof e==`object`&&!(e instanceof Date)?JSON.stringify(e):String(e);function Ue(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!Number.isNaN(n)&&!Number.isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():V(e).localeCompare(V(t))}function We(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=Ue(B(e,r),B(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}const H=globalThis;H.onmessage!==void 0&&(H.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=We(r,i);H.postMessage?.({type:`sorted`,id:n,data:e})}catch(e){H.postMessage?.({type:`error`,id:n,error:String(e)})}});var Ge=class{heap=[];compare;constructor(e){this.compare=e}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}};const Ke=(e,t,n)=>{let r=[];for(let i=0;i<n;i++)r.push(e.columns[i][t]);return r};function U(e,t){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let n=0;for(let t of e)n+=t.indices.length;let r=new Uint32Array(n),i=t===`asc`?1:-1,a=new Ge((e,t)=>(e.value-t.value)*i);for(let t=0;t<e.length;t++){let n=e[t];if(n.indices.length>0){let e=n.indices[0];a.push({chunkIndex:t,positionInChunk:0,value:n.values[0],globalIndex:e+n.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();r[o++]=t.globalIndex;let n=e[t.chunkIndex],i=t.positionInChunk+1;if(i<n.indices.length){let e=n.indices[i];a.push({chunkIndex:t.chunkIndex,positionInChunk:i,value:n.values[i],globalIndex:e+n.offset})}}return r}function qe(e){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let t=e[0].directions,n=t.length,r=0;for(let t of e)r+=t.indices.length;let i=new Uint32Array(r),a=new Ge((e,n)=>{for(let r=0;r<t.length;r++){let i=(e.values[r]-n.values[r])*t[r];if(i!==0)return i}return 0});for(let t=0;t<e.length;t++){let r=e[t];if(r.indices.length>0){let e=r.indices[0];a.push({chunkIndex:t,positionInChunk:0,values:Ke(r,0,n),globalIndex:e+r.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();i[o++]=t.globalIndex;let r=e[t.chunkIndex],s=t.positionInChunk+1;if(s<r.indices.length){let e=r.indices[s];a.push({chunkIndex:t.chunkIndex,positionInChunk:s,values:Ke(r,s,n),globalIndex:e+r.offset})}}return i}function Je(e,t){if(e.length<=1)return new Uint32Array;let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.indices.length-1,s=i.values[o],c=a.values[0];if(s===c){let e=o;for(;e>0&&i.values[e-1]===s;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===c;)t++;let l=r+e,u=r+i.indices.length+t+1;n.push(l,u)}r+=i.indices.length}return new Uint32Array(n)}const Ye=(e,t,n)=>{let r=Math.max(n,Math.ceil(e/t)),i=[];for(let t=0;t<e;t+=r)i.push({offset:t,length:Math.min(r,e-t)});return i},Xe=e=>{if(e.length<=1)return[];let t=[],n=0;for(let r=0;r<e.length-1;r++){let i=e[r],a=e[r+1];if(i.indices.length===0||a.indices.length===0){n+=i.indices.length;continue}let o=i.values[i.indices.length-1],s=a.values[0];if(o===s){let e=i.indices.length-1;for(;e>0&&i.values[e-1]===o;)e--;let r=0;for(;r<a.indices.length-1&&a.values[r+1]===s;)r++;t.push(n+e,n+i.indices.length+r+1)}n+=i.indices.length}return t},Ze=(e,t,n,r)=>{let i=r===`asc`?1:-1;for(let r=0;r<t.length;r+=2){let a=t[r],o=t[r+1];o<=a||o>e.length||Qe(e,a,o,n,i)}},Qe=(e,t,n,r,i)=>{let a=Array.from(e.slice(t,n));if(!$e(a,r)){a.sort((e,t)=>i*r[e].localeCompare(r[t]));for(let n=0;n<a.length;n++)e[t+n]=a[n]}},$e=(e,t)=>{let n=t[e[0]];for(let r=1;r<e.length;r++)if(t[e[r]]!==n)return!1;return!0};var W=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){let t=e.maxWorkers??(navigator===void 0?4:navigator.hardwareConcurrency)??4;this.pool=new z(`
7
7
  // ---- Shared helpers (inlined for worker isolation) ----------------------
8
8
  function getFieldValue(row, field) {
9
9
  const parts = field.split(".");
@@ -205,7 +205,7 @@ self.onmessage = function(e) {
205
205
  self.postMessage({ type: "error", id, error: String(error) });
206
206
  }
207
207
  };
208
- `,{maxWorkers:e.maxWorkers??(navigator===void 0?4:navigator.hardwareConcurrency)??4}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return this.isTerminated?!1:this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){return this.assertNotTerminated(),e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}assertNotTerminated(){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&Ye(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}boundariesFor(e){return qe(e,this.pool.getMaxWorkers(),this.minChunkSize)}async runChunks(e){let t=await this.pool.executeParallel(e);return t.sort((e,t)=>e.chunkOffset-t.chunkOffset),t}async sortIndicesParallel(e,t){let n=this.boundariesFor(e.length).map(n=>{let r=new Float64Array(e.slice(n.offset,n.offset+n.length));return{request:{type:`sortChunk`,id:0,values:r,direction:t,chunkOffset:n.offset},transferables:[r.buffer]}});return U((await this.runChunks(n)).map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=this.boundariesFor(e[0].length).map(n=>{let r=e.map(e=>{let t=new Float64Array(n.length);return t.set(new Float64Array(e.buffer,n.offset*8,n.length)),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),i=await this.runChunks(r),a=i.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),o=Qe(i),s=U(a,t),c=Je(a),l=new Uint32Array([...o,...c]);return l.length>0&&Ye(s,l,n,t),s}async sortMultiColumnParallel(e,t){let n=this.boundariesFor(e[0].length),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i=n.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),i=new Int8Array(r);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:i,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),i.buffer]}});return Ge((await this.runChunks(i)).map(e=>({indices:e.indices,columns:e.sortedColumns,directions:r,offset:e.chunkOffset})))}};const Qe=e=>{let t=[];for(let n of e)for(let e=0;e<n.collisionRuns.length;e+=2)t.push(n.collisionRuns[e]+n.chunkOffset,n.collisionRuns[e+1]+n.chunkOffset);return t};function G(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.codePointAt(e)??200,i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function K(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):y(e),r=Array.isArray(t)?t.join(`, `):y(t);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!Number.isNaN(i)&&!Number.isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():y(e).localeCompare(y(t))}function $e(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function et(e,t){let n=[];for(let r of t.sortModel){let i=$e(t.getFieldValue(e,r.colId));n.push(i)}return n}function tt(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function nt(e,t,n,r){for(let{colId:i,direction:a}of n){let n=K(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}function rt(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.codePointAt(n)??200:0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function it(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function at(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=K(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}const ot=(e,t,n)=>{for(let r of e){let e=n(r,t);if(e!=null)return typeof e==`string`||Array.isArray(e)||typeof e==`object`&&!(e instanceof Date)?`string`:`numeric`}return`numeric`},st=(e,t,n)=>{let r=[],i=Array.from({length:3},()=>[]);for(let a of e){let e=y(n(a,t));r.push(e);let o=rt(e);for(let e=0;e<3;e++)i[e].push(o[e])}return{originalStrings:r,hashChunkArrays:i.map(e=>new Float64Array(e))}},ct=(e,t,n)=>e.map(e=>it(n(e,t))),lt=(e,t,n)=>{let r=[],i=[];for(let{colId:a,direction:o}of t)r.push(e.map(e=>it(n(e,a)))),i.push(o??`asc`);return{columnValues:r,directions:i}},ut=(e,t)=>{let n=Array(e.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n},dt=async(e,t,n,r)=>{let{colId:i,direction:a}=t,o=a??`asc`;if(ot(e,i,r)===`string`){let{originalStrings:t,hashChunkArrays:a}=st(e,i,r);return n.sortStringHashes(a,o,t)}let s=ct(e,i,r);return n.sortIndices(s,o)},ft=async(e,t,n,r)=>{let{columnValues:i,directions:a}=lt(e,t,r);return n.sortMultiColumn(i,a)},pt=async(e,t,n,r)=>ut(e,t.length===1?await dt(e,t[0],n,r):await ft(e,t,n,r));function q(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function mt(e){return e==null||e===``||Array.isArray(e)&&e.length===0}const ht={contains:(e,t)=>e.includes(t),notContains:(e,t)=>!e.includes(t),equals:(e,t)=>e===t,notEquals:(e,t)=>e!==t,startsWith:(e,t)=>e.startsWith(t),endsWith:(e,t)=>e.endsWith(t),blank:(e,t,n)=>n,notBlank:(e,t,n)=>!n};function gt(e,t,n){let r=mt(e);if(t.selectedValues&&t.selectedValues.size>0){let i=t.includeBlank===!0&&r;if(Array.isArray(e)){let r=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1}),a=n?n(r):r.join(`, `);return t.selectedValues.has(a)||i}let a=y(e,n);return t.selectedValues.has(a)||i}let i=y(e,n).toLowerCase(),a=String(t.value??``).toLowerCase();return ht[t.operator](i,a,r)}const _t={"=":(e,t)=>e===t,"!=":(e,t)=>e!==t,">":(e,t)=>e>t,"<":(e,t)=>e<t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t,between:(e,t,n)=>e>=t&&e<=n};function vt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(Number.isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;return _t[t.operator](r,i,a)}const yt={"=":(e,t)=>q(e,t),"!=":(e,t)=>!q(e,t),">":(e,t)=>e.getTime()>t.getTime(),"<":(e,t)=>e.getTime()<t.getTime(),between:(e,t,n)=>{let r=e.getTime();return r>=t.getTime()&&r<=n.getTime()}};function bt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(y(e));if(Number.isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``));return yt[t.operator](r,i,a)}function xt(e,t,n){switch(t.type){case`text`:return gt(e,t,n);case`number`:return vt(e,t);case`date`:return bt(e,t);default:return!0}}function J(e,t,n){if(!t.conditions||t.conditions.length===0)return!0;let r=t.conditions[0];if(!r)return!0;let i=xt(e,r,n);for(let r=1;r<t.conditions.length;r++){let a=t.conditions[r-1],o=t.conditions[r],s=a.nextOperator??t.combination,c=xt(e,o,n);s===`and`?i&&=c:i||=c}return i}function St(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!=null);if(i.length===0)return!0;for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(!J(i,a,o))return!1}return!0}function Ct(e,t,n,r){let i=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return i.length===0?e:e.filter(e=>{for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(typeof a==`string`){if(!y(i,o).toLowerCase().includes(a.toLowerCase()))return!1;continue}if(!J(i,a,o))return!1}return!0})}function Y(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}function wt(e,t={}){let{getFieldValue:n=Y,getValueFormatter:r,useWorker:i=!0,parallelSort:a}=t,o=e,s=!1,c=i?new W(a===!1?{maxWorkers:1}:a):null;return{loadMode:`all`,async query(e){let t=o?[...o]:[];if(e.filter&&Object.keys(e.filter).length>0){let i=e.valueFormatters===null?r:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,i)}e.sort&&e.sort.length>0&&(t=c&&c.isAvailable()&&t.length>=2e5?await pt(t,e.sort,c,n):at(t,e.sort,n));let i=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:i}},destroy(){s||(s=!0,o=null,c&&c.terminate())},moveRow(e,t){if(!o||e===t||e<0||e>=o.length||t<0||t>=o.length)return;let[n]=o.splice(e,1),r=t>e?t-1:t;o.splice(r,0,n)}}}function X(e){return wt(e)}function Tt(e,t={}){return{loadMode:t.loadMode??`paginated`,async query(t){return e(t)}}}var Et=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e,t=[]){this.options={getRowId:e.getRowId,getFieldValue:e.getFieldValue??g,getValueFormatter:e.getValueFormatter??(()=>void 0)},this.setData(t)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,r=e.range.startRow,i=Math.min(e.range.endRow,n),a=[];for(let e=r;e<i;e++){let n=t[e];n!==void 0&&a.push(this.rows[n])}return{rows:a,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getAllRows(){return[...this.rows]}moveRow(e,t){if(e===t||e<0||e>=this.rows.length||t<0||t>=this.rows.length)return;let[n]=this.rows.splice(e,1),r=t>e?t-1:t;this.rows.splice(r,0,n),this.rowById.clear();for(let e=0;e<this.rows.length;e++)this.rowById.set(this.options.getRowId(this.rows[e]),e);this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.rowSortCache.clear()}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t.keys()):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length===0)return 0;t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e);return t.length}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(_(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=et(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=tt(i,a,this.sortModel);return o===null?nt(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).some(([,e])=>e!=null))for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return St(e,this.filterModel,this.options.getFieldValue,this.options.getValueFormatter)}getVisibleIndices(){return Object.entries(this.filterModel).some(([,e])=>e!=null)?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e))for(let[n,r]of Object.entries(e))r!=null&&(t===`add`?this.addToDistinctValues(n,r):this.decrementDistinctValues(n,r))}updateDistinctValueForField(e,t,n){t!=null&&this.decrementDistinctValues(e,t),n!=null&&this.addToDistinctValues(e,n)}addToDistinctValues(e,t){let n=this.distinctValues.get(e);if(n||(n=new Map,this.distinctValues.set(e,n)),Array.isArray(t)){for(let e of t)e!=null&&Dt(n,e);return}Dt(n,t)}decrementDistinctValues(e,t){let n=this.distinctValues.get(e);if(n!==void 0){if(Array.isArray(t)){for(let e of t)e!=null&&Z(n,e);return}Z(n,t)}}};const Dt=(e,t)=>{e.set(t,(e.get(t)??0)+1)},Z=(e,t)=>{let n=e.get(t);if(n!==void 0){if(n<=1){e.delete(t);return}e.set(t,n-1)}};function Ot(e,t){let{getRowId:n,getFieldValue:r,getValueFormatter:i,debounceMs:a=50,onTransactionProcessed:o,useWorker:s=!0,parallelSort:c}=t,l=new Et({getRowId:n,getFieldValue:r??Y,getValueFormatter:i},e),u=new Set,d=v().emit,f=s&&c!==!1?new W(c):null,p=new M({debounceMs:a,store:l,onProcessed:e=>{o?.(e);for(let t of u)t(e)}});return{loadMode:`all`,async query(e){if(p.hasPending()){d({type:`DATA_LOADING`});try{await p.flush()}finally{d({type:`DATA_LOADED`,totalRows:l.getTotalRowCount()})}}let t=l.getAllRows(),n=r??Y;if(e.filter&&Object.keys(e.filter).length>0){let r=e.valueFormatters===null?i:t=>e.valueFormatters?.[t];t=Ct(t,e.filter,n,r)}if(e.sort&&e.sort.length>0)if(f&&f.isAvailable()&&t.length>=2e5){d({type:`DATA_LOADING`});try{t=await pt(t,e.sort,f,n)}finally{d({type:`DATA_LOADED`,totalRows:t.length})}}else t=at(t,e.sort,n);let a=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:a}},addRows(e){p.add(e)},removeRows(e){p.remove(e)},updateCell(e,t,n){p.updateCell(e,t,n)},updateRow(e,t){p.updateRow(e,t)},async flushTransactions(){await p.flush()},hasPendingTransactions(){return p.hasPending()},getDistinctValues(e){return l.getDistinctValues(e)},getRowById(e){return l.getRowById(e)},getTotalRowCount(){return l.getTotalRowCount()},subscribe(e){return u.add(e),()=>{u.delete(e)}},clear(){let e=l.getTotalRowCount();l.clear();let t={added:0,removed:e,updated:0};o?.(t);for(let e of u)e(t)},moveRow(e,t){l.moveRow(e,t)}}}const kt=`
208
+ `,{maxWorkers:t}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return this.isTerminated?!1:this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){return this.assertNotTerminated(),e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){return this.assertNotTerminated(),(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}assertNotTerminated(){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&Ze(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}boundariesFor(e){return Ye(e,this.pool.getMaxWorkers(),this.minChunkSize)}async runChunks(e){let t=await this.pool.executeParallel(e);return t.sort((e,t)=>e.chunkOffset-t.chunkOffset),t}async sortIndicesParallel(e,t){let n=this.boundariesFor(e.length).map(n=>{let r=new Float64Array(e.slice(n.offset,n.offset+n.length));return{request:{type:`sortChunk`,id:0,values:r,direction:t,chunkOffset:n.offset},transferables:[r.buffer]}});return U((await this.runChunks(n)).map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=this.boundariesFor(e[0].length).map(n=>{let r=e.map(e=>{let t=new Float64Array(n.length);return t.set(new Float64Array(e.buffer,n.offset*8,n.length)),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),i=await this.runChunks(r),a=i.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),o=et(i),s=U(a,t),c=Xe(a),l=new Uint32Array([...o,...c]);return l.length>0&&Ze(s,l,n,t),s}async sortMultiColumnParallel(e,t){let n=this.boundariesFor(e[0].length),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i=n.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),i=new Int8Array(r);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:i,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),i.buffer]}});return qe((await this.runChunks(i)).map(e=>({indices:e.indices,columns:e.sortedColumns,directions:r,offset:e.chunkOffset})))}};const et=e=>{let t=[];for(let n of e)for(let e=0;e<n.collisionRuns.length;e+=2)t.push(n.collisionRuns[e]+n.chunkOffset,n.collisionRuns[e+1]+n.chunkOffset);return t};function G(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.codePointAt(e)??200,i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function K(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):y(e),r=Array.isArray(t)?t.join(`, `):y(t);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!Number.isNaN(i)&&!Number.isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():y(e).localeCompare(y(t))}function tt(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function nt(e,t){let n=[];for(let r of t.sortModel){let i=tt(t.getFieldValue(e,r.colId));n.push(i)}return n}function rt(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function it(e,t,n,r){for(let{colId:i,direction:a}of n){let n=K(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}function at(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.codePointAt(n)??200:0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function ot(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:G(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return G(e);if(typeof e==`object`)return G(JSON.stringify(e));let t=Number(e);return Number.isNaN(t)?0:t}function st(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=K(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}const ct=(e,t,n)=>{for(let r of e){let e=n(r,t);if(e!=null)return typeof e==`string`||Array.isArray(e)||typeof e==`object`&&!(e instanceof Date)?`string`:`numeric`}return`numeric`},lt=(e,t,n)=>{let r=[],i=Array.from({length:3},()=>[]);for(let a of e){let e=y(n(a,t));r.push(e);let o=at(e);for(let e=0;e<3;e++)i[e].push(o[e])}return{originalStrings:r,hashChunkArrays:i.map(e=>new Float64Array(e))}},ut=(e,t,n)=>e.map(e=>ot(n(e,t))),dt=(e,t,n)=>{let r=[],i=[];for(let{colId:a,direction:o}of t)r.push(e.map(e=>ot(n(e,a)))),i.push(o??`asc`);return{columnValues:r,directions:i}},ft=(e,t)=>{let n=Array(e.length);for(let r=0;r<t.length;r++)n[r]=e[t[r]];return n},pt=async(e,t,n,r)=>{let{colId:i,direction:a}=t,o=a??`asc`;if(ct(e,i,r)===`string`){let{originalStrings:t,hashChunkArrays:a}=lt(e,i,r);return n.sortStringHashes(a,o,t)}let s=ut(e,i,r);return n.sortIndices(s,o)},mt=async(e,t,n,r)=>{let{columnValues:i,directions:a}=dt(e,t,r);return n.sortMultiColumn(i,a)},ht=async(e,t,n,r)=>ft(e,t.length===1?await pt(e,t[0],n,r):await mt(e,t,n,r));function q(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function gt(e){return e==null||e===``||Array.isArray(e)&&e.length===0}const _t={contains:(e,t)=>e.includes(t),notContains:(e,t)=>!e.includes(t),equals:(e,t)=>e===t,notEquals:(e,t)=>e!==t,startsWith:(e,t)=>e.startsWith(t),endsWith:(e,t)=>e.endsWith(t),blank:(e,t,n)=>n,notBlank:(e,t,n)=>!n};function vt(e,t,n){let r=gt(e);if(t.selectedValues&&t.selectedValues.size>0){let i=t.includeBlank===!0&&r;if(Array.isArray(e)){let r=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1}),a=n?n(r):r.join(`, `);return t.selectedValues.has(a)||i}let a=y(e,n);return t.selectedValues.has(a)||i}let i=y(e,n).toLowerCase(),a=String(t.value??``).toLowerCase();return _t[t.operator](i,a,r)}const yt={"=":(e,t)=>e===t,"!=":(e,t)=>e!==t,">":(e,t)=>e>t,"<":(e,t)=>e<t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t,between:(e,t,n)=>e>=t&&e<=n};function bt(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(Number.isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;return yt[t.operator](r,i,a)}const xt={"=":(e,t)=>q(e,t),"!=":(e,t)=>!q(e,t),">":(e,t)=>e.getTime()>t.getTime(),"<":(e,t)=>e.getTime()<t.getTime(),between:(e,t,n)=>{let r=e.getTime();return r>=t.getTime()&&r<=n.getTime()}};function St(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(y(e));if(Number.isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``));return xt[t.operator](r,i,a)}function Ct(e,t,n){switch(t.type){case`text`:return vt(e,t,n);case`number`:return bt(e,t);case`date`:return St(e,t);default:return!0}}function J(e,t,n){if(!t.conditions||t.conditions.length===0)return!0;let r=t.conditions[0];if(!r)return!0;let i=Ct(e,r,n);for(let r=1;r<t.conditions.length;r++){let a=t.conditions[r-1],o=t.conditions[r],s=a.nextOperator??t.combination,c=Ct(e,o,n);s===`and`?i&&=c:i||=c}return i}function wt(e,t,n,r){let i=Object.entries(t).filter(([,e])=>e!=null);if(i.length===0)return!0;for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(!J(i,a,o))return!1}return!0}function Tt(e,t,n,r){let i=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return i.length===0?e:e.filter(e=>{for(let[t,a]of i){let i=n(e,t),o=r?.(t);if(typeof a==`string`){if(!y(i,o).toLowerCase().includes(a.toLowerCase()))return!1;continue}if(!J(i,a,o))return!1}return!0})}function Y(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r}function Et(e,t={}){let{getFieldValue:n=Y,getValueFormatter:r,useWorker:i=!0,parallelSort:a}=t,o=e,s=!1,c=i?new W(a===!1?{maxWorkers:1}:a):null;return{loadMode:`all`,async query(e){let t=o?[...o]:[];if(e.filter&&Object.keys(e.filter).length>0){let i=e.valueFormatters===null?r:t=>e.valueFormatters?.[t];t=Tt(t,e.filter,n,i)}e.sort&&e.sort.length>0&&(t=c&&c.isAvailable()&&t.length>=2e5?await ht(t,e.sort,c,n):st(t,e.sort,n));let i=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:i}},destroy(){s||(s=!0,o=null,c&&c.terminate())},moveRow(e,t){if(!o||e===t||e<0||e>=o.length||t<0||t>=o.length)return;let[n]=o.splice(e,1),r=t>e?t-1:t;o.splice(r,0,n)}}}function X(e){return Et(e)}function Dt(e,t={}){return{loadMode:t.loadMode??`paginated`,async query(t){return e(t)}}}var Ot=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e,t=[]){this.options={getRowId:e.getRowId,getFieldValue:e.getFieldValue??g,getValueFormatter:e.getValueFormatter??(()=>void 0)},this.setData(t)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,r=e.range.startRow,i=Math.min(e.range.endRow,n),a=[];for(let e=r;e<i;e++){let n=t[e];n!==void 0&&a.push(this.rows[n])}return{rows:a,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getAllRows(){return[...this.rows]}moveRow(e,t){if(e===t||e<0||e>=this.rows.length||t<0||t>=this.rows.length)return;let[n]=this.rows.splice(e,1),r=t>e?t-1:t;this.rows.splice(r,0,n),this.rowById.clear();for(let e=0;e<this.rows.length;e++)this.rowById.set(this.options.getRowId(this.rows[e]),e);this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.rowSortCache.clear()}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t.keys()):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length===0)return 0;t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e);return t.length}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(_(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=nt(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=rt(i,a,this.sortModel);return o===null?it(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).some(([,e])=>e!=null))for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return wt(e,this.filterModel,this.options.getFieldValue,this.options.getValueFormatter)}getVisibleIndices(){return Object.entries(this.filterModel).some(([,e])=>e!=null)?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e))for(let[n,r]of Object.entries(e))r!=null&&(t===`add`?this.addToDistinctValues(n,r):this.decrementDistinctValues(n,r))}updateDistinctValueForField(e,t,n){t!=null&&this.decrementDistinctValues(e,t),n!=null&&this.addToDistinctValues(e,n)}addToDistinctValues(e,t){let n=this.distinctValues.get(e);if(n||(n=new Map,this.distinctValues.set(e,n)),Array.isArray(t)){for(let e of t)e!=null&&kt(n,e);return}kt(n,t)}decrementDistinctValues(e,t){let n=this.distinctValues.get(e);if(n!==void 0){if(Array.isArray(t)){for(let e of t)e!=null&&At(n,e);return}At(n,t)}}};const kt=(e,t)=>{e.set(t,(e.get(t)??0)+1)},At=(e,t)=>{let n=e.get(t);if(n!==void 0){if(n<=1){e.delete(t);return}e.set(t,n-1)}};function jt(e,t){let{getRowId:n,getFieldValue:r,getValueFormatter:i,debounceMs:a=50,onTransactionProcessed:o,useWorker:s=!0,parallelSort:c}=t,l=new Ot({getRowId:n,getFieldValue:r??Y,getValueFormatter:i},e),u=new Set,d=v().emit,f=s&&c!==!1?new W(c):null,p=new M({debounceMs:a,store:l,onProcessed:e=>{o?.(e);for(let t of u)t(e)}});return{loadMode:`all`,async query(e){if(p.hasPending()){d({type:`DATA_LOADING`});try{await p.flush()}finally{d({type:`DATA_LOADED`,totalRows:l.getTotalRowCount()})}}let t=l.getAllRows(),n=r??Y;if(e.filter&&Object.keys(e.filter).length>0){let r=e.valueFormatters===null?i:t=>e.valueFormatters?.[t];t=Tt(t,e.filter,n,r)}if(e.sort&&e.sort.length>0)if(f&&f.isAvailable()&&t.length>=2e5){d({type:`DATA_LOADING`});try{t=await ht(t,e.sort,f,n)}finally{d({type:`DATA_LOADED`,totalRows:t.length})}}else t=st(t,e.sort,n);let a=t.length;return{rows:t.slice(e.range.startRow,e.range.endRow),totalRows:a}},addRows(e){p.add(e)},removeRows(e){p.remove(e)},updateCell(e,t,n){p.updateCell(e,t,n)},updateRow(e,t){p.updateRow(e,t)},async flushTransactions(){await p.flush()},hasPendingTransactions(){return p.hasPending()},getDistinctValues(e){return l.getDistinctValues(e)},getRowById(e){return l.getRowById(e)},getTotalRowCount(){return l.getTotalRowCount()},subscribe(e){return u.add(e),()=>{u.delete(e)}},clear(){let e=l.getTotalRowCount();l.clear();let t={added:0,removed:e,updated:0};o?.(t);for(let e of u)e(t)},moveRow(e,t){l.moveRow(e,t)}}}const Mt=`
209
209
  /* =============================================================================
210
210
  GP Grid - CSS Variables for Theming
211
211
  ============================================================================= */
@@ -289,14 +289,20 @@ self.onmessage = function(e) {
289
289
  --gp-grid-scrollbar-thumb: #373a40;
290
290
  --gp-grid-scrollbar-thumb-hover: #4a4d52;
291
291
  }
292
- `,At=`
292
+ `,Nt=`
293
293
  /* =============================================================================
294
294
  GP Grid - Clean Flat Design
295
295
  ============================================================================= */
296
296
 
297
- /* Grid Container */
297
+ /* Grid Container - structural */
298
298
  .gp-grid-container {
299
299
  outline: none;
300
+ user-select: none;
301
+ -webkit-user-select: none;
302
+ }
303
+
304
+ /* Visual properties - :where() for zero specificity, consumers can override with a single class */
305
+ :where(.gp-grid-container) {
300
306
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
301
307
  font-size: 13px;
302
308
  line-height: 1.5;
@@ -304,15 +310,16 @@ self.onmessage = function(e) {
304
310
  background-color: var(--gp-grid-bg);
305
311
  border: 1px solid var(--gp-grid-border);
306
312
  border-radius: 6px;
307
- user-select: none;
308
- -webkit-user-select: none;
309
313
  }
310
314
 
311
315
  .gp-grid-container:focus {
312
316
  outline: none;
317
+ }
318
+
319
+ :where(.gp-grid-container:focus) {
313
320
  border-color: var(--gp-grid-primary);
314
321
  }
315
- `,jt=`
322
+ `,Pt=`
316
323
  /* =============================================================================
317
324
  Header
318
325
  ============================================================================= */
@@ -321,39 +328,43 @@ self.onmessage = function(e) {
321
328
  position: sticky;
322
329
  top: 0;
323
330
  left: 0;
324
- /* z-index set inline (100) to ensure header stays above rows wrapper */
325
- background-color: var(--gp-grid-header-bg);
326
- border-bottom: 1px solid var(--gp-grid-border);
327
331
  flex-shrink: 0;
328
332
  z-index: 11;
329
333
  overflow: hidden;
330
334
  }
331
335
 
336
+ :where(.gp-grid-header) {
337
+ background-color: var(--gp-grid-header-bg);
338
+ border-bottom: 1px solid var(--gp-grid-border);
339
+ }
340
+
332
341
  .gp-grid-container .gp-grid-header-cell {
333
342
  position: absolute;
334
343
  box-sizing: border-box;
344
+ user-select: none;
345
+ display: flex;
346
+ top: 0;
347
+ touch-action: none;
348
+ }
349
+
350
+ :where(.gp-grid-header-cell) {
351
+ align-items: center;
352
+ padding: 0 12px;
335
353
  border-right: 1px solid var(--gp-grid-border);
336
354
  font-weight: 600;
337
355
  font-size: 12px;
338
356
  letter-spacing: 0.5px;
339
357
  color: var(--gp-grid-header-text);
340
358
  cursor: pointer;
341
- user-select: none;
342
- display: flex;
343
- align-items: center;
344
- padding: 0 12px;
345
359
  background-color: transparent;
346
360
  transition: background-color 0.1s ease;
347
- top: 0;
348
- background: transparent;
349
- touch-action: none;
350
361
  }
351
362
 
352
- .gp-grid-container .gp-grid-header-cell:hover {
363
+ :where(.gp-grid-header-cell:hover) {
353
364
  background-color: var(--gp-grid-hover);
354
365
  }
355
366
 
356
- .gp-grid-container .gp-grid-header-cell:active {
367
+ :where(.gp-grid-header-cell:active) {
357
368
  background-color: var(--gp-grid-border-light);
358
369
  }
359
370
 
@@ -362,6 +373,9 @@ self.onmessage = function(e) {
362
373
  overflow: hidden;
363
374
  text-overflow: ellipsis;
364
375
  white-space: nowrap;
376
+ }
377
+
378
+ :where(.gp-grid-header-text) {
365
379
  color: var(--gp-grid-header-text);
366
380
  }
367
381
 
@@ -389,20 +403,20 @@ self.onmessage = function(e) {
389
403
  gap: 2px;
390
404
  }
391
405
 
392
- .gp-grid-sort-arrow-up,
393
- .gp-grid-sort-arrow-down {
406
+ :where(.gp-grid-sort-arrow-up),
407
+ :where(.gp-grid-sort-arrow-down) {
394
408
  opacity: 0.35;
395
409
  transition: opacity 0.15s ease, color 0.15s ease;
396
410
  color: var(--gp-grid-text);
397
411
  }
398
412
 
399
- .gp-grid-sort-arrow-up.active,
400
- .gp-grid-sort-arrow-down.active {
413
+ :where(.gp-grid-sort-arrow-up.active),
414
+ :where(.gp-grid-sort-arrow-down.active) {
401
415
  opacity: 1;
402
416
  color: var(--gp-grid-primary);
403
417
  }
404
418
 
405
- .gp-grid-sort-index {
419
+ :where(.gp-grid-sort-index) {
406
420
  font-size: 9px;
407
421
  color: var(--gp-grid-primary);
408
422
  font-weight: 600;
@@ -415,6 +429,9 @@ self.onmessage = function(e) {
415
429
  justify-content: center;
416
430
  width: 20px;
417
431
  height: 20px;
432
+ }
433
+
434
+ :where(.gp-grid-filter-icon) {
418
435
  border-radius: 4px;
419
436
  cursor: pointer;
420
437
  color: var(--gp-grid-text-secondary);
@@ -422,12 +439,12 @@ self.onmessage = function(e) {
422
439
  margin-left: 2px;
423
440
  }
424
441
 
425
- .gp-grid-filter-icon:hover {
442
+ :where(.gp-grid-filter-icon:hover) {
426
443
  background-color: var(--gp-grid-hover);
427
444
  color: var(--gp-grid-primary);
428
445
  }
429
446
 
430
- .gp-grid-filter-icon.active {
447
+ :where(.gp-grid-filter-icon.active) {
431
448
  color: var(--gp-grid-primary);
432
449
  background-color: var(--gp-grid-primary-light);
433
450
  }
@@ -439,6 +456,8 @@ self.onmessage = function(e) {
439
456
  min-height: 44px;
440
457
  width: 44px;
441
458
  height: 44px;
459
+ }
460
+ :where(.gp-grid-filter-icon) {
442
461
  margin-left: 0;
443
462
  }
444
463
 
@@ -451,6 +470,9 @@ self.onmessage = function(e) {
451
470
  /* Disabled header state during data loading */
452
471
  .gp-grid-header--loading .gp-grid-header-cell {
453
472
  pointer-events: none;
473
+ }
474
+
475
+ :where(.gp-grid-header--loading .gp-grid-header-cell) {
454
476
  opacity: 0.6;
455
477
  cursor: default;
456
478
  }
@@ -470,8 +492,8 @@ self.onmessage = function(e) {
470
492
  touch-action: none;
471
493
  }
472
494
 
473
- .gp-grid-header-resize-handle:hover,
474
- .gp-grid-header-resize-handle--active {
495
+ :where(.gp-grid-header-resize-handle:hover),
496
+ :where(.gp-grid-header-resize-handle--active) {
475
497
  background-color: var(--gp-grid-primary);
476
498
  opacity: 0.4;
477
499
  }
@@ -489,11 +511,14 @@ self.onmessage = function(e) {
489
511
  top: 0;
490
512
  width: 2px;
491
513
  height: 100%;
492
- background-color: var(--gp-grid-primary);
493
514
  z-index: 1000;
494
515
  pointer-events: none;
495
516
  }
496
517
 
518
+ :where(.gp-grid-column-resize-line) {
519
+ background-color: var(--gp-grid-primary);
520
+ }
521
+
497
522
  /* =============================================================================
498
523
  Column Move
499
524
  ============================================================================= */
@@ -501,23 +526,26 @@ self.onmessage = function(e) {
501
526
  .gp-grid-column-move-ghost {
502
527
  position: fixed;
503
528
  pointer-events: none;
504
- opacity: 0.7;
505
529
  z-index: 2000;
530
+ display: flex;
531
+ align-items: center;
532
+ box-sizing: border-box;
533
+ overflow: hidden;
534
+ white-space: nowrap;
535
+ text-overflow: ellipsis;
536
+ }
537
+
538
+ :where(.gp-grid-column-move-ghost) {
539
+ opacity: 0.7;
506
540
  background-color: var(--gp-grid-header-bg);
507
541
  border: 2px solid var(--gp-grid-primary);
508
542
  border-radius: 4px;
509
543
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
510
- display: flex;
511
- align-items: center;
512
544
  padding: 0 12px;
513
545
  font-weight: 600;
514
546
  font-size: 12px;
515
547
  letter-spacing: 0.5px;
516
548
  color: var(--gp-grid-header-text);
517
- box-sizing: border-box;
518
- overflow: hidden;
519
- white-space: nowrap;
520
- text-overflow: ellipsis;
521
549
  }
522
550
 
523
551
  .gp-grid-column-drop-indicator {
@@ -526,12 +554,15 @@ self.onmessage = function(e) {
526
554
  left: 0;
527
555
  width: 3px;
528
556
  height: 100%;
529
- background-color: var(--gp-grid-primary);
530
557
  z-index: 1000;
531
558
  pointer-events: none;
559
+ }
560
+
561
+ :where(.gp-grid-column-drop-indicator) {
562
+ background-color: var(--gp-grid-primary);
532
563
  border-radius: 2px;
533
564
  }
534
- `,Mt=`
565
+ `,Ft=`
535
566
  /* =============================================================================
536
567
  Data Cells
537
568
  ============================================================================= */
@@ -563,7 +594,6 @@ self.onmessage = function(e) {
563
594
  top: 0;
564
595
  box-sizing: border-box;
565
596
  display: flex;
566
- align-items: center;
567
597
  overflow: hidden;
568
598
  text-overflow: ellipsis;
569
599
  white-space: nowrap;
@@ -573,6 +603,7 @@ self.onmessage = function(e) {
573
603
 
574
604
  /* Visual properties - :where() for zero specificity, so user highlight classes always win */
575
605
  :where(.gp-grid-cell) {
606
+ align-items: center;
576
607
  padding: 0 12px;
577
608
  cursor: cell;
578
609
  color: var(--gp-grid-text);
@@ -615,17 +646,20 @@ self.onmessage = function(e) {
615
646
  position: absolute;
616
647
  width: 8px;
617
648
  height: 8px;
618
- background-color: var(--gp-grid-primary);
619
- border: 2px solid var(--gp-grid-bg);
620
- cursor: crosshair;
621
649
  z-index: 11;
622
650
  pointer-events: auto;
623
651
  box-sizing: border-box;
624
- border-radius: 1px;
625
652
  touch-action: none;
626
653
  }
627
654
 
628
- .gp-grid-fill-handle:hover {
655
+ :where(.gp-grid-fill-handle) {
656
+ background-color: var(--gp-grid-primary);
657
+ border: 2px solid var(--gp-grid-bg);
658
+ cursor: crosshair;
659
+ border-radius: 1px;
660
+ }
661
+
662
+ :where(.gp-grid-fill-handle:hover) {
629
663
  transform: scale(1.2);
630
664
  }
631
665
 
@@ -633,13 +667,15 @@ self.onmessage = function(e) {
633
667
  .gp-grid-fill-handle {
634
668
  width: 24px;
635
669
  height: 24px;
670
+ }
671
+ :where(.gp-grid-fill-handle) {
636
672
  border-width: 3px;
637
673
  border-radius: 3px;
638
674
  }
639
675
  }
640
676
 
641
677
  /* Fill preview (cells being filled) */
642
- .gp-grid-cell.gp-grid-cell--fill-preview {
678
+ :where(.gp-grid-cell.gp-grid-cell--fill-preview) {
643
679
  background-color: var(--gp-grid-primary-light);
644
680
  border: 1px dashed var(--gp-grid-primary);
645
681
  }
@@ -651,6 +687,9 @@ self.onmessage = function(e) {
651
687
  .gp-grid-edit-input {
652
688
  width: 100%;
653
689
  height: 100%;
690
+ }
691
+
692
+ :where(.gp-grid-edit-input) {
654
693
  padding: 0 11px;
655
694
  font-family: inherit;
656
695
  font-size: inherit;
@@ -662,7 +701,39 @@ self.onmessage = function(e) {
662
701
  .gp-grid-edit-input:focus {
663
702
  outline: none;
664
703
  }
665
- `,Nt=`
704
+
705
+ /* =============================================================================
706
+ Cell Peek (read-only multi-line overlay on dblclick of non-editable cell)
707
+ ============================================================================= */
708
+
709
+ /* Structural: positioned absolutely by the framework wrapper; must sit above
710
+ selection (z:5), editing (z:10), fill handle (z:11). */
711
+ .gp-grid-cell-peek {
712
+ position: absolute;
713
+ z-index: 20;
714
+ box-sizing: border-box;
715
+ overflow: auto;
716
+ max-height: 320px;
717
+ }
718
+
719
+ :where(.gp-grid-cell-peek) {
720
+ padding: 8px 11px;
721
+ background-color: var(--gp-grid-bg);
722
+ color: var(--gp-grid-text);
723
+ border: 2px solid var(--gp-grid-primary);
724
+ border-radius: 3px;
725
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
726
+ font-family: inherit;
727
+ font-size: inherit;
728
+ line-height: 1.4;
729
+ white-space: pre-wrap;
730
+ overflow-wrap: anywhere;
731
+ cursor: text;
732
+ user-select: text;
733
+ -webkit-user-select: text;
734
+ }
735
+
736
+ `,Z=`
666
737
  /* =============================================================================
667
738
  Loading & Error States
668
739
  ============================================================================= */
@@ -684,12 +755,15 @@ self.onmessage = function(e) {
684
755
  top: 0;
685
756
  left: 0;
686
757
  width: 100%;
687
- height: 100%;
758
+ height: 100%;
688
759
  pointer-events: none;
760
+ }
761
+
762
+ :where(.gp-grid-loading-overlay) {
689
763
  background-color: var(--gp-grid-loading-overlay-bg, rgba(255, 255, 255, 0.4));
690
764
  }
691
765
 
692
- .gp-grid-container--dark .gp-grid-loading-overlay {
766
+ :where(.gp-grid-container--dark .gp-grid-loading-overlay) {
693
767
  background-color: var(--gp-grid-loading-overlay-bg, rgba(0, 0, 0, 0.3));
694
768
  }
695
769
 
@@ -699,6 +773,13 @@ self.onmessage = function(e) {
699
773
  top: 50%;
700
774
  left: 50%;
701
775
  transform: translate(-50%, -50%);
776
+ z-index: 1000;
777
+ display: flex;
778
+ pointer-events: auto;
779
+ }
780
+
781
+ :where(.gp-grid-loading) {
782
+ align-items: center;
702
783
  padding: 12px 20px;
703
784
  background-color: var(--gp-grid-loading-bg);
704
785
  color: var(--gp-grid-loading-text);
@@ -706,20 +787,19 @@ self.onmessage = function(e) {
706
787
  border: 1px solid var(--gp-grid-border);
707
788
  font-weight: 500;
708
789
  font-size: 13px;
709
- z-index: 1000;
710
- display: flex;
711
- align-items: center;
712
790
  gap: 10px;
713
- pointer-events: auto;
714
791
  }
715
792
 
716
793
  .gp-grid-loading-spinner {
717
794
  width: 16px;
718
795
  height: 16px;
796
+ animation: gp-grid-spin 0.7s linear infinite;
797
+ }
798
+
799
+ :where(.gp-grid-loading-spinner) {
719
800
  border: 2px solid var(--gp-grid-border);
720
801
  border-top-color: var(--gp-grid-primary);
721
802
  border-radius: 50%;
722
- animation: gp-grid-spin 0.7s linear infinite;
723
803
  }
724
804
 
725
805
  @keyframes gp-grid-spin {
@@ -733,6 +813,12 @@ self.onmessage = function(e) {
733
813
  top: 50%;
734
814
  left: 50%;
735
815
  transform: translate(-50%, -50%);
816
+ z-index: 1000;
817
+ user-select: text;
818
+ -webkit-user-select: text;
819
+ }
820
+
821
+ :where(.gp-grid-error) {
736
822
  padding: 12px 20px;
737
823
  background-color: var(--gp-grid-error-bg);
738
824
  color: var(--gp-grid-error-text);
@@ -740,11 +826,8 @@ self.onmessage = function(e) {
740
826
  border: 1px solid var(--gp-grid-error-text);
741
827
  font-weight: 500;
742
828
  font-size: 13px;
743
- z-index: 1000;
744
829
  max-width: 80%;
745
830
  text-align: center;
746
- user-select: text;
747
- -webkit-user-select: text;
748
831
  cursor: text;
749
832
  }
750
833
 
@@ -757,11 +840,14 @@ self.onmessage = function(e) {
757
840
  top: 50%;
758
841
  left: 50%;
759
842
  transform: translate(-50%, -50%);
843
+ }
844
+
845
+ :where(.gp-grid-empty) {
760
846
  color: var(--gp-grid-text-muted);
761
847
  font-size: 14px;
762
848
  text-align: center;
763
849
  }
764
- `,Pt=`
850
+ `,It=`
765
851
  /* =============================================================================
766
852
  Scrollbar Styling
767
853
  ============================================================================= */
@@ -771,39 +857,43 @@ self.onmessage = function(e) {
771
857
  height: 8px;
772
858
  }
773
859
 
774
- .gp-grid-container::-webkit-scrollbar-track {
860
+ :where(.gp-grid-container)::-webkit-scrollbar-track {
775
861
  background-color: var(--gp-grid-scrollbar-track);
776
862
  }
777
863
 
778
- .gp-grid-container::-webkit-scrollbar-thumb {
864
+ :where(.gp-grid-container)::-webkit-scrollbar-thumb {
779
865
  background-color: var(--gp-grid-scrollbar-thumb);
780
866
  border-radius: 4px;
781
867
  }
782
868
 
783
- .gp-grid-container::-webkit-scrollbar-thumb:hover {
869
+ :where(.gp-grid-container)::-webkit-scrollbar-thumb:hover {
784
870
  background-color: var(--gp-grid-scrollbar-thumb-hover);
785
871
  }
786
872
 
787
- .gp-grid-container::-webkit-scrollbar-corner {
873
+ :where(.gp-grid-container)::-webkit-scrollbar-corner {
788
874
  background-color: var(--gp-grid-scrollbar-track);
789
875
  }
790
- `,Ft=`
876
+ `,Lt=`
791
877
  /* =============================================================================
792
878
  Filter Popup
793
879
  ============================================================================= */
794
880
 
795
881
  .gp-grid-filter-popup {
882
+ max-height: 400px;
883
+ max-width: min(360px, calc(100vw - 16px));
884
+ display: flex;
885
+ flex-direction: column;
886
+ }
887
+
888
+ :where(.gp-grid-filter-popup) {
796
889
  background-color: var(--gp-grid-bg);
797
890
  border: 1px solid var(--gp-grid-border);
798
891
  border-radius: 6px;
799
892
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
800
- max-height: 400px;
801
- display: flex;
802
- flex-direction: column;
803
893
  font-size: 13px;
804
894
  }
805
895
 
806
- .gp-grid-filter-header {
896
+ :where(.gp-grid-filter-header) {
807
897
  padding: 10px 12px;
808
898
  font-weight: 600;
809
899
  border-bottom: 1px solid var(--gp-grid-border-light);
@@ -811,16 +901,23 @@ self.onmessage = function(e) {
811
901
  }
812
902
 
813
903
  .gp-grid-filter-content {
814
- padding: 10px 12px;
815
904
  display: flex;
816
905
  flex-direction: column;
906
+ overflow-y: auto;
907
+ min-height: 0;
908
+ }
909
+
910
+ :where(.gp-grid-filter-content) {
911
+ padding: 10px 12px;
817
912
  gap: 10px;
818
- overflow: hidden;
819
913
  }
820
914
 
821
915
  /* Mode toggle (Values / Condition) */
822
916
  .gp-grid-filter-mode-toggle {
823
917
  display: flex;
918
+ }
919
+
920
+ :where(.gp-grid-filter-mode-toggle) {
824
921
  gap: 4px;
825
922
  background-color: var(--gp-grid-bg-alt);
826
923
  border-radius: 4px;
@@ -829,6 +926,9 @@ self.onmessage = function(e) {
829
926
 
830
927
  .gp-grid-filter-mode-toggle button {
831
928
  flex: 1;
929
+ }
930
+
931
+ :where(.gp-grid-filter-mode-toggle button) {
832
932
  padding: 6px 10px;
833
933
  font-size: 11px;
834
934
  font-family: inherit;
@@ -840,18 +940,18 @@ self.onmessage = function(e) {
840
940
  transition: background-color 0.15s ease, color 0.15s ease;
841
941
  }
842
942
 
843
- .gp-grid-filter-mode-toggle button:hover {
943
+ :where(.gp-grid-filter-mode-toggle button:hover) {
844
944
  color: var(--gp-grid-text);
845
945
  }
846
946
 
847
- .gp-grid-filter-mode-toggle button.active {
947
+ :where(.gp-grid-filter-mode-toggle button.active) {
848
948
  background-color: var(--gp-grid-bg);
849
949
  color: var(--gp-grid-text);
850
950
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
851
951
  }
852
952
 
853
953
  /* Info message for too many values */
854
- .gp-grid-filter-info {
954
+ :where(.gp-grid-filter-info) {
855
955
  font-size: 11px;
856
956
  color: var(--gp-grid-text-secondary);
857
957
  padding: 6px 8px;
@@ -863,6 +963,10 @@ self.onmessage = function(e) {
863
963
  .gp-grid-filter-search {
864
964
  width: 100%;
865
965
  height: 30px;
966
+ box-sizing: border-box;
967
+ }
968
+
969
+ :where(.gp-grid-filter-search) {
866
970
  padding: 0 10px;
867
971
  font-family: inherit;
868
972
  font-size: 12px;
@@ -870,10 +974,9 @@ self.onmessage = function(e) {
870
974
  border-radius: 4px;
871
975
  background-color: var(--gp-grid-input-bg);
872
976
  color: var(--gp-grid-text);
873
- box-sizing: border-box;
874
977
  }
875
978
 
876
- .gp-grid-filter-search:focus {
979
+ :where(.gp-grid-filter-search:focus) {
877
980
  outline: none;
878
981
  border-color: var(--gp-grid-primary);
879
982
  }
@@ -881,11 +984,17 @@ self.onmessage = function(e) {
881
984
  /* Select All / Deselect All actions */
882
985
  .gp-grid-filter-actions {
883
986
  display: flex;
987
+ }
988
+
989
+ :where(.gp-grid-filter-actions) {
884
990
  gap: 8px;
885
991
  }
886
992
 
887
993
  .gp-grid-filter-actions button {
888
994
  flex: 1;
995
+ }
996
+
997
+ :where(.gp-grid-filter-actions button) {
889
998
  padding: 4px 8px;
890
999
  font-size: 11px;
891
1000
  font-family: inherit;
@@ -896,11 +1005,11 @@ self.onmessage = function(e) {
896
1005
  cursor: pointer;
897
1006
  }
898
1007
 
899
- .gp-grid-filter-actions button:hover:not(:disabled) {
1008
+ :where(.gp-grid-filter-actions button:hover:not(:disabled)) {
900
1009
  background-color: var(--gp-grid-hover);
901
1010
  }
902
1011
 
903
- .gp-grid-filter-actions button:disabled {
1012
+ :where(.gp-grid-filter-actions button:disabled) {
904
1013
  opacity: 0.5;
905
1014
  cursor: not-allowed;
906
1015
  }
@@ -911,6 +1020,9 @@ self.onmessage = function(e) {
911
1020
  overflow-y: auto;
912
1021
  display: flex;
913
1022
  flex-direction: column;
1023
+ }
1024
+
1025
+ :where(.gp-grid-filter-list) {
914
1026
  gap: 4px;
915
1027
  border: 1px solid var(--gp-grid-border-light);
916
1028
  border-radius: 4px;
@@ -920,18 +1032,24 @@ self.onmessage = function(e) {
920
1032
  .gp-grid-filter-option {
921
1033
  display: flex;
922
1034
  align-items: center;
1035
+ }
1036
+
1037
+ :where(.gp-grid-filter-option) {
923
1038
  gap: 8px;
924
1039
  padding: 4px 6px;
925
1040
  border-radius: 3px;
926
1041
  cursor: pointer;
927
1042
  }
928
1043
 
929
- .gp-grid-filter-option:hover {
1044
+ :where(.gp-grid-filter-option:hover) {
930
1045
  background-color: var(--gp-grid-hover);
931
1046
  }
932
1047
 
933
1048
  .gp-grid-filter-option input[type="checkbox"] {
934
1049
  margin: 0;
1050
+ }
1051
+
1052
+ :where(.gp-grid-filter-option input[type="checkbox"]) {
935
1053
  cursor: pointer;
936
1054
  }
937
1055
 
@@ -942,7 +1060,7 @@ self.onmessage = function(e) {
942
1060
  white-space: nowrap;
943
1061
  }
944
1062
 
945
- .gp-grid-filter-blank {
1063
+ :where(.gp-grid-filter-blank) {
946
1064
  font-style: italic;
947
1065
  color: var(--gp-grid-text-muted);
948
1066
  }
@@ -951,17 +1069,26 @@ self.onmessage = function(e) {
951
1069
  .gp-grid-filter-condition {
952
1070
  display: flex;
953
1071
  flex-direction: column;
1072
+ }
1073
+
1074
+ :where(.gp-grid-filter-condition) {
954
1075
  gap: 6px;
955
1076
  }
956
1077
 
957
1078
  .gp-grid-filter-row {
958
1079
  display: flex;
959
1080
  align-items: center;
1081
+ }
1082
+
1083
+ :where(.gp-grid-filter-row) {
960
1084
  gap: 6px;
961
1085
  }
962
1086
 
963
1087
  .gp-grid-filter-row select {
964
1088
  height: 30px;
1089
+ }
1090
+
1091
+ :where(.gp-grid-filter-row select) {
965
1092
  padding: 0 6px;
966
1093
  font-family: inherit;
967
1094
  font-size: 12px;
@@ -978,6 +1105,14 @@ self.onmessage = function(e) {
978
1105
  .gp-grid-filter-text-input {
979
1106
  flex: 1;
980
1107
  height: 30px;
1108
+ min-width: 0;
1109
+ box-sizing: border-box;
1110
+ }
1111
+
1112
+ :where(.gp-grid-filter-row input[type="number"]),
1113
+ :where(.gp-grid-filter-row input[type="date"]),
1114
+ :where(.gp-grid-filter-row input[type="text"]),
1115
+ :where(.gp-grid-filter-text-input) {
981
1116
  padding: 0 8px;
982
1117
  font-family: inherit;
983
1118
  font-size: 12px;
@@ -985,16 +1120,14 @@ self.onmessage = function(e) {
985
1120
  border-radius: 4px;
986
1121
  background-color: var(--gp-grid-input-bg);
987
1122
  color: var(--gp-grid-text);
988
- min-width: 0;
989
- box-sizing: border-box;
990
1123
  }
991
1124
 
992
- .gp-grid-filter-row input:focus {
1125
+ :where(.gp-grid-filter-row input:focus) {
993
1126
  outline: none;
994
1127
  border-color: var(--gp-grid-primary);
995
1128
  }
996
1129
 
997
- .gp-grid-filter-to {
1130
+ :where(.gp-grid-filter-to) {
998
1131
  font-size: 11px;
999
1132
  color: var(--gp-grid-text-secondary);
1000
1133
  }
@@ -1002,6 +1135,9 @@ self.onmessage = function(e) {
1002
1135
  .gp-grid-filter-remove {
1003
1136
  width: 24px;
1004
1137
  height: 24px;
1138
+ }
1139
+
1140
+ :where(.gp-grid-filter-remove) {
1005
1141
  padding: 0;
1006
1142
  font-size: 16px;
1007
1143
  line-height: 1;
@@ -1012,7 +1148,7 @@ self.onmessage = function(e) {
1012
1148
  cursor: pointer;
1013
1149
  }
1014
1150
 
1015
- .gp-grid-filter-remove:hover {
1151
+ :where(.gp-grid-filter-remove:hover) {
1016
1152
  background-color: var(--gp-grid-error-bg);
1017
1153
  color: var(--gp-grid-error-text);
1018
1154
  }
@@ -1020,12 +1156,18 @@ self.onmessage = function(e) {
1020
1156
  /* AND/OR combination toggle */
1021
1157
  .gp-grid-filter-combination {
1022
1158
  display: flex;
1159
+ }
1160
+
1161
+ :where(.gp-grid-filter-combination) {
1023
1162
  gap: 4px;
1024
1163
  margin-bottom: 4px;
1025
1164
  }
1026
1165
 
1027
1166
  .gp-grid-filter-combination button {
1028
1167
  flex: 1;
1168
+ }
1169
+
1170
+ :where(.gp-grid-filter-combination button) {
1029
1171
  padding: 4px 8px;
1030
1172
  font-size: 10px;
1031
1173
  font-family: inherit;
@@ -1036,7 +1178,7 @@ self.onmessage = function(e) {
1036
1178
  cursor: pointer;
1037
1179
  }
1038
1180
 
1039
- .gp-grid-filter-combination button.active {
1181
+ :where(.gp-grid-filter-combination button.active) {
1040
1182
  background-color: var(--gp-grid-primary);
1041
1183
  border-color: var(--gp-grid-primary);
1042
1184
  color: #fff;
@@ -1045,6 +1187,9 @@ self.onmessage = function(e) {
1045
1187
  /* Add condition button */
1046
1188
  .gp-grid-filter-add {
1047
1189
  width: 100%;
1190
+ }
1191
+
1192
+ :where(.gp-grid-filter-add) {
1048
1193
  padding: 6px;
1049
1194
  font-size: 11px;
1050
1195
  font-family: inherit;
@@ -1055,7 +1200,7 @@ self.onmessage = function(e) {
1055
1200
  cursor: pointer;
1056
1201
  }
1057
1202
 
1058
- .gp-grid-filter-add:hover {
1203
+ :where(.gp-grid-filter-add:hover) {
1059
1204
  background-color: var(--gp-grid-hover);
1060
1205
  border-color: var(--gp-grid-primary);
1061
1206
  color: var(--gp-grid-primary);
@@ -1064,6 +1209,9 @@ self.onmessage = function(e) {
1064
1209
  /* Apply / Clear buttons */
1065
1210
  .gp-grid-filter-buttons {
1066
1211
  display: flex;
1212
+ }
1213
+
1214
+ :where(.gp-grid-filter-buttons) {
1067
1215
  gap: 8px;
1068
1216
  padding-top: 8px;
1069
1217
  border-top: 1px solid var(--gp-grid-border-light);
@@ -1072,6 +1220,10 @@ self.onmessage = function(e) {
1072
1220
  .gp-grid-filter-btn-clear,
1073
1221
  .gp-grid-filter-btn-apply {
1074
1222
  flex: 1;
1223
+ }
1224
+
1225
+ :where(.gp-grid-filter-btn-clear),
1226
+ :where(.gp-grid-filter-btn-apply) {
1075
1227
  padding: 8px 12px;
1076
1228
  font-size: 12px;
1077
1229
  font-family: inherit;
@@ -1079,36 +1231,39 @@ self.onmessage = function(e) {
1079
1231
  cursor: pointer;
1080
1232
  }
1081
1233
 
1082
- .gp-grid-filter-btn-clear {
1234
+ :where(.gp-grid-filter-btn-clear) {
1083
1235
  border: 1px solid var(--gp-grid-input-border);
1084
1236
  background-color: var(--gp-grid-bg);
1085
1237
  color: var(--gp-grid-text);
1086
1238
  }
1087
1239
 
1088
- .gp-grid-filter-btn-clear:hover {
1240
+ :where(.gp-grid-filter-btn-clear:hover) {
1089
1241
  background-color: var(--gp-grid-hover);
1090
1242
  }
1091
1243
 
1092
- .gp-grid-filter-btn-apply {
1244
+ :where(.gp-grid-filter-btn-apply) {
1093
1245
  border: 1px solid var(--gp-grid-primary);
1094
1246
  background-color: var(--gp-grid-primary);
1095
1247
  color: #fff;
1096
1248
  }
1097
1249
 
1098
- .gp-grid-filter-btn-apply:hover {
1250
+ :where(.gp-grid-filter-btn-apply:hover) {
1099
1251
  opacity: 0.9;
1100
1252
  }
1101
- `,It=`
1253
+ `,Rt=`
1102
1254
  /* =============================================================================
1103
1255
  Row Drag
1104
1256
  ============================================================================= */
1105
1257
 
1106
1258
  .gp-grid-cell--row-drag-handle {
1107
- cursor: grab;
1108
1259
  touch-action: none;
1109
1260
  }
1110
1261
 
1111
- .gp-grid-cell--row-drag-handle:active {
1262
+ :where(.gp-grid-cell--row-drag-handle) {
1263
+ cursor: grab;
1264
+ }
1265
+
1266
+ :where(.gp-grid-cell--row-drag-handle:active) {
1112
1267
  cursor: grabbing;
1113
1268
  }
1114
1269
 
@@ -1118,6 +1273,9 @@ self.onmessage = function(e) {
1118
1273
  justify-content: center;
1119
1274
  width: 100%;
1120
1275
  height: 100%;
1276
+ }
1277
+
1278
+ :where(.gp-grid-row-drag-icon) {
1121
1279
  color: var(--gp-grid-text-secondary);
1122
1280
  }
1123
1281
 
@@ -1129,14 +1287,17 @@ self.onmessage = function(e) {
1129
1287
  .gp-grid-row-drag-ghost {
1130
1288
  position: fixed;
1131
1289
  pointer-events: none;
1132
- opacity: 0.8;
1133
1290
  z-index: 2000;
1291
+ overflow: hidden;
1292
+ box-sizing: border-box;
1293
+ }
1294
+
1295
+ :where(.gp-grid-row-drag-ghost) {
1296
+ opacity: 0.8;
1134
1297
  background-color: var(--gp-grid-bg, #fff);
1135
1298
  border: 2px solid var(--gp-grid-primary);
1136
1299
  border-radius: 4px;
1137
1300
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
1138
- overflow: hidden;
1139
- box-sizing: border-box;
1140
1301
  }
1141
1302
 
1142
1303
  .gp-grid-row-drop-indicator {
@@ -1144,10 +1305,13 @@ self.onmessage = function(e) {
1144
1305
  left: 0;
1145
1306
  width: 100%;
1146
1307
  height: 3px;
1147
- background-color: var(--gp-grid-primary);
1148
1308
  z-index: 1000;
1149
1309
  pointer-events: none;
1310
+ }
1311
+
1312
+ :where(.gp-grid-row-drop-indicator) {
1313
+ background-color: var(--gp-grid-primary);
1150
1314
  border-radius: 2px;
1151
1315
  }
1152
- `,Lt=[kt,At,jt,Mt,Nt,Pt,Ft,It].join(`
1153
- `),Rt=e=>({slots:new Map,activeCell:null,selectionRange:null,editingCell:null,contentWidth:0,contentHeight:e?.initialHeight??0,viewportWidth:e?.initialWidth??0,viewportHeight:e?.initialHeight??0,rowsWrapperOffset:0,headers:new Map,filterPopup:null,isLoading:!1,error:null,totalRows:0,visibleRowRange:null,hoverPosition:null,columns:null,pendingScrollTop:null}),zt=(e,t,n)=>{switch(e.type){case`CREATE_SLOT`:return t.set(e.slotId,{slotId:e.slotId,rowIndex:-1,rowData:{},translateY:0}),null;case`DESTROY_SLOT`:return t.delete(e.slotId),null;case`ASSIGN_SLOT`:{let n=t.get(e.slotId);return n&&t.set(e.slotId,{...n,rowIndex:e.rowIndex,rowData:e.rowData}),null}case`MOVE_SLOT`:{let n=t.get(e.slotId);return n&&t.set(e.slotId,{...n,translateY:e.translateY}),null}case`SCROLL_TO`:return{pendingScrollTop:e.scrollTop};case`SET_ACTIVE_CELL`:return{activeCell:e.position};case`SET_SELECTION_RANGE`:return{selectionRange:e.range};case`UPDATE_VISIBLE_RANGE`:return{visibleRowRange:{start:e.start,end:e.end},rowsWrapperOffset:e.rowsWrapperOffset};case`SET_HOVER_POSITION`:return{hoverPosition:e.position};case`START_EDIT`:return{editingCell:{row:e.row,col:e.col,initialValue:e.initialValue}};case`STOP_EDIT`:return{editingCell:null};case`SET_CONTENT_SIZE`:return{contentWidth:e.width,contentHeight:e.height,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,rowsWrapperOffset:e.rowsWrapperOffset};case`UPDATE_HEADER`:return n.set(e.colIndex,{column:e.column,sortDirection:e.sortDirection,sortIndex:e.sortIndex,hasFilter:e.hasFilter}),null;case`OPEN_FILTER_POPUP`:return{filterPopup:{isOpen:!0,colIndex:e.colIndex,column:e.column,anchorRect:e.anchorRect,distinctValues:e.distinctValues,currentFilter:e.currentFilter}};case`CLOSE_FILTER_POPUP`:return{filterPopup:null};case`DATA_LOADING`:return{isLoading:!0,error:null};case`DATA_LOADED`:return{isLoading:!1,totalRows:e.totalRows};case`DATA_ERROR`:return{isLoading:!1,error:e.error};case`ROWS_ADDED`:case`ROWS_REMOVED`:return{totalRows:e.totalRows};case`ROWS_UPDATED`:case`TRANSACTION_PROCESSED`:return null;case`COLUMNS_CHANGED`:return{columns:e.columns};default:return null}},Q=e=>({clientX:e.clientX,clientY:e.clientY,button:e.button,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,pointerId:e.pointerId,pointerType:e.pointerType});var Bt=class{intervalId=null;lastPointerEvent=null;getBodyEl;onTick;constructor(e,t){this.getBodyEl=e,this.onTick=t}recordPointer(e){this.lastPointerEvent=e}clearPointer(){this.lastPointerEvent=null}start(e,t){this.stop(),this.intervalId=setInterval(()=>{let n=this.getBodyEl();if(!n)return;n.scrollTop+=t,n.scrollLeft+=e;let r=this.lastPointerEvent;r&&this.onTick(r)},16)}stop(){this.intervalId!==null&&(clearInterval(this.intervalId),this.intervalId=null)}},Vt=class{timer=null;capture=null;savedContainerOverflow=null;blockTouchMove=e=>e.preventDefault();deps;constructor(e){this.deps=e}start(e){this.cancel(),this.capture={pointerId:e.pointerId,target:e.currentTarget};let t=e.clientX,n=e.clientY,r=e=>{let r=e.clientX-t,i=e.clientY-n;(Math.abs(r)>10||Math.abs(i)>10)&&(this.cancel(),a())},i=()=>{this.cancel(),a()},a=()=>{document.removeEventListener(`pointermove`,r),document.removeEventListener(`pointerup`,i),document.removeEventListener(`pointercancel`,i)};document.addEventListener(`pointermove`,r),document.addEventListener(`pointerup`,i,{once:!0}),document.addEventListener(`pointercancel`,i,{once:!0}),this.timer=setTimeout(()=>{this.timer=null,a(),this.confirm()},300)}cancel(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null),this.deps.getCore()?.input.cancelPendingRowDrag(),this.capture=null}releaseLocks(){if(!this.deps.isBrowser)return;let e=this.deps.getContainer();this.savedContainerOverflow!==null&&e&&(e.style.overflow=this.savedContainerOverflow),this.savedContainerOverflow=null,document.removeEventListener(`touchmove`,this.blockTouchMove)}confirm(){let e=this.deps.getCore(),t=this.capture;this.capture=null,e!==null&&e.input.confirmPendingRowDrag()&&(this.lockContainer(),document.addEventListener(`touchmove`,this.blockTouchMove,{passive:!1}),this.applyPointerCapture(t),this.deps.onDragConfirmed(e.input.getDragState()))}lockContainer(){let e=this.deps.getContainer();e&&(this.savedContainerOverflow=e.style.overflow,e.style.overflow=`hidden`)}applyPointerCapture(e){e&&e.target.setPointerCapture(e.pointerId)}};const Ht=(e,t,n,r)=>{let i={slots:new Map(t),headers:new Map(n)};for(let t of e){let e=zt(t,i.slots,i.headers);e!==null&&Ut(e,i,r)}return i},Ut=(e,t,n)=>{e.slots!==void 0&&$(t.slots,e.slots),e.headers!==void 0&&$(t.headers,e.headers),Wt(e,n),e.columns!==void 0&&e.columns!==null&&n.setColumnsOverride(e.columns),e.filterPopup!==void 0&&n.onFilterPopupChange(e.filterPopup)},Wt=(e,t)=>{e.contentWidth!==void 0&&t.setContentWidth(e.contentWidth),e.contentHeight!==void 0&&t.setContentHeight(e.contentHeight),e.rowsWrapperOffset!==void 0&&t.setRowsWrapperOffset(e.rowsWrapperOffset),e.isLoading!==void 0&&t.setIsLoading(e.isLoading),e.error!==void 0&&t.setErrorMessage(e.error),e.totalRows!==void 0&&t.setTotalRows(e.totalRows),e.pendingScrollTop!==void 0&&t.setPendingScrollTop(e.pendingScrollTop),e.activeCell!==void 0&&t.setActiveCell(e.activeCell),e.selectionRange!==void 0&&t.setSelectionRange(e.selectionRange),e.editingCell!==void 0&&t.setEditingCell(e.editingCell),e.hoverPosition!==void 0&&t.setHoverPosition(e.hoverPosition)},$=(e,t)=>{e.clear(),t.forEach((t,n)=>e.set(n,t))};var Gt=class{owned=null;lastAppliedRows=null;lastAppliedColumns=null;initialize(e,t){return e===null?(this.owned=X(t),this.lastAppliedRows=t,this.owned):e}syncRows(e,t){return t!==null||this.lastAppliedRows===e?null:(this.lastAppliedRows=e,e.length>1e4&&console.warn(`[gp-grid] rows input changed with ${e.length} rows — this triggers a full rebuild. Use createGridData() for efficient updates.`),this.owned?.destroy?.(),this.owned=X(e),this.owned)}syncColumns(e){return e.length===0||this.lastAppliedColumns===e?!1:(this.lastAppliedColumns=e,!0)}destroy(){this.owned?.destroy?.(),this.owned=null}},Kt=class{deps;constructor(e){this.deps=e}headerPointerDown(e,t,n,r){let i=this.deps.getCore();return i===null?!1:i.input.handleHeaderMouseDown(e,t,n,Q(r)).preventDefault}resizePointerDown(e,t,n){let r=this.deps.getCore();return r===null?!1:r.input.handleHeaderResizeMouseDown(e,t,Q(n)).preventDefault}cellPointerDown(e,t,n){let r=this.deps.getCore();if(r===null)return{preventDefault:!1,focusContainer:!1};let i=r.input.handleCellMouseDown(e,t,Q(n));return this.dispatchCellDragStart(i.startDrag,n),{preventDefault:i.preventDefault,focusContainer:i.focusContainer??!1}}cellPointerEnter(e,t){this.deps.getCore()?.input.handleCellMouseEnter(e,t)}cellPointerLeave(){this.deps.getCore()?.input.handleCellMouseLeave()}fillHandlePointerDown(e,t,n){let r=this.deps.getCore();if(r===null)return{preventDefault:!1,stopPropagation:!1};let i=r.input.handleFillHandleMouseDown(e,t,Q(n));return i.startDrag===`fill`&&(qt(n),this.deps.onDragStateChange(r.input.getDragState())),{preventDefault:i.preventDefault,stopPropagation:i.stopPropagation}}dragMove(e){let t=this.deps.getCore(),n=this.deps.getBodyEl();if(t===null||n===null)return;let r=n.getBoundingClientRect(),i=t.input.handleDragMove(Q(e),{top:r.top,left:r.left,width:r.width,height:r.height,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft});this.deps.onDragStateChange(t.input.getDragState()),i?.autoScroll?this.deps.autoScroll.start(i.autoScroll.dx,i.autoScroll.dy):this.deps.autoScroll.stop()}documentPointerMove(e){let t=this.deps.getCore();if(t===null)return!1;let n=t.input.getDragState().isDragging;return this.deps.autoScroll.recordPointer(e),this.dragMove(e),n}documentPointerUp(){let e=this.deps.getCore();if(e===null)return{wasRowDrag:!1};let t=e.input.getDragState().dragType===`row-drag`;return this.deps.autoScroll.stop(),this.deps.autoScroll.clearPointer(),e.input.handleDragEnd(),this.deps.onDragStateChange(e.input.getDragState()),{wasRowDrag:t}}wheel(e,t,n){let r=this.deps.getCore();return r===null?null:r.input.handleWheel(e,t,n)}keyDown(e,t,n,r){let i=this.deps.getCore();return i===null?{preventDefault:!1}:i.input.handleKeyDown({key:e.key,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey},t,n,r)}pasteText(e,t,n){let r=this.deps.getCore();return r===null||t!==null||n?!1:r.pasteClipboardText(e)}dispatchCellDragStart(e,t){let n=this.deps.getCore();if(!(n===null||e===void 0)){if(e===`selection`){n.input.startSelectionDrag(),this.deps.onDragStateChange(n.input.getDragState());return}if(e===`row-drag`){this.deps.onDragStateChange(n.input.getDragState());return}e===`row-drag-pending`&&this.deps.pendingRowDrag.start(t)}}};const qt=e=>{e.target.setPointerCapture(e.pointerId)};export{Bt as AutoScrollDriver,Gt as DataSourceOwner,R as EditManager,I as FillManager,Be as GridCore,C as HighlightManager,Et as IndexedDataStore,Kt as InputEventAdapter,S as InputHandler,W as ParallelSortManager,Vt as PendingRowDragController,O as RowDataManager,w as RowMutationManager,A as ScrollVirtualizationManager,F as SelectionManager,L as SlotPoolManager,j as SortFilterManager,M as TransactionManager,z as WorkerPool,Ht as applyBatchInstructions,zt as applyInstruction,p as buildCellClasses,n as calculateColumnPositions,re as calculateFillHandlePosition,ie as calculateFilterPopupPosition,i as calculateScaledColumnPositions,Mt as cellStyles,K as compareValues,$e as computeValueHash,At as containerStyles,wt as createClientDataSource,X as createDataSourceFromArray,Rt as createInitialState,Ot as createMutableClientDataSource,Tt as createServerDataSource,Ke as detectBoundaryCollisions,J as evaluateColumnFilter,bt as evaluateDateCondition,vt as evaluateNumberCondition,gt as evaluateTextCondition,Ft as filtersStyles,a as findColumnAtX,te as findSlotForRow,y as formatCellValue,g as getFieldValue,r as getTotalWidth,Lt as gridStyles,jt as headerStyles,l as isCellActive,d as isCellEditing,f as isCellInFillPreview,c as isCellSelected,h as isColumnInSelectionRange,m as isRowInSelectionRange,u as isRowVisible,q as isSameDay,U as kWayMerge,Ge as kWayMergeMultiColumn,It as rowDragStyles,St as rowPassesFilter,ne as scrollCellIntoView,Pt as scrollbarStyles,_ as setFieldValue,Nt as statesStyles,G as stringToSortableNumber,Q as toPointerEventData,kt as variablesStyles};
1316
+ `,zt=[Mt,Nt,Pt,Ft,Z,It,Lt,Rt].join(`
1317
+ `),Bt=e=>({slots:new Map,activeCell:null,selectionRange:null,editingCell:null,peekCell:null,contentWidth:0,contentHeight:e?.initialHeight??0,viewportWidth:e?.initialWidth??0,viewportHeight:e?.initialHeight??0,rowsWrapperOffset:0,headers:new Map,filterPopup:null,isLoading:!1,error:null,totalRows:0,visibleRowRange:null,hoverPosition:null,columns:null,pendingScrollTop:null}),Vt=(e,t,n)=>{switch(e.type){case`CREATE_SLOT`:return t.set(e.slotId,{slotId:e.slotId,rowIndex:-1,rowData:{},translateY:0}),null;case`DESTROY_SLOT`:return t.delete(e.slotId),null;case`ASSIGN_SLOT`:{let n=t.get(e.slotId);return n&&t.set(e.slotId,{...n,rowIndex:e.rowIndex,rowData:e.rowData}),null}case`MOVE_SLOT`:{let n=t.get(e.slotId);return n&&t.set(e.slotId,{...n,translateY:e.translateY}),null}case`SCROLL_TO`:return{pendingScrollTop:e.scrollTop};case`SET_ACTIVE_CELL`:return{activeCell:e.position};case`SET_SELECTION_RANGE`:return{selectionRange:e.range};case`UPDATE_VISIBLE_RANGE`:return{visibleRowRange:{start:e.start,end:e.end},rowsWrapperOffset:e.rowsWrapperOffset};case`SET_HOVER_POSITION`:return{hoverPosition:e.position};case`START_EDIT`:return{editingCell:{row:e.row,col:e.col,initialValue:e.initialValue}};case`STOP_EDIT`:return{editingCell:null};case`START_PEEK`:return{peekCell:{row:e.row,col:e.col}};case`STOP_PEEK`:return{peekCell:null};case`SET_CONTENT_SIZE`:return{contentWidth:e.width,contentHeight:e.height,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,rowsWrapperOffset:e.rowsWrapperOffset};case`UPDATE_HEADER`:return n.set(e.colIndex,{column:e.column,sortDirection:e.sortDirection,sortIndex:e.sortIndex,hasFilter:e.hasFilter}),null;case`OPEN_FILTER_POPUP`:return{filterPopup:{isOpen:!0,colIndex:e.colIndex,column:e.column,anchorRect:e.anchorRect,distinctValues:e.distinctValues,currentFilter:e.currentFilter}};case`CLOSE_FILTER_POPUP`:return{filterPopup:null};case`DATA_LOADING`:return{isLoading:!0,error:null};case`DATA_LOADED`:return{isLoading:!1,totalRows:e.totalRows};case`DATA_ERROR`:return{isLoading:!1,error:e.error};case`ROWS_ADDED`:case`ROWS_REMOVED`:return{totalRows:e.totalRows};case`ROWS_UPDATED`:case`TRANSACTION_PROCESSED`:return null;case`COLUMNS_CHANGED`:return{columns:e.columns};default:return null}},Q=e=>({clientX:e.clientX,clientY:e.clientY,button:e.button,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,pointerId:e.pointerId,pointerType:e.pointerType});var Ht=class{intervalId=null;lastPointerEvent=null;getBodyEl;onTick;constructor(e,t){this.getBodyEl=e,this.onTick=t}recordPointer(e){this.lastPointerEvent=e}clearPointer(){this.lastPointerEvent=null}start(e,t){this.stop(),this.intervalId=setInterval(()=>{let n=this.getBodyEl();if(!n)return;n.scrollTop+=t,n.scrollLeft+=e;let r=this.lastPointerEvent;r&&this.onTick(r)},16)}stop(){this.intervalId!==null&&(clearInterval(this.intervalId),this.intervalId=null)}},Ut=class{timer=null;capture=null;savedContainerOverflow=null;blockTouchMove=e=>e.preventDefault();deps;constructor(e){this.deps=e}start(e){this.cancel(),this.capture={pointerId:e.pointerId,target:e.currentTarget};let t=e.clientX,n=e.clientY,r=e=>{let r=e.clientX-t,i=e.clientY-n;(Math.abs(r)>10||Math.abs(i)>10)&&(this.cancel(),a())},i=()=>{this.cancel(),a()},a=()=>{document.removeEventListener(`pointermove`,r),document.removeEventListener(`pointerup`,i),document.removeEventListener(`pointercancel`,i)};document.addEventListener(`pointermove`,r),document.addEventListener(`pointerup`,i,{once:!0}),document.addEventListener(`pointercancel`,i,{once:!0}),this.timer=setTimeout(()=>{this.timer=null,a(),this.confirm()},300)}cancel(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null),this.deps.getCore()?.input.cancelPendingRowDrag(),this.capture=null}releaseLocks(){if(!this.deps.isBrowser)return;let e=this.deps.getContainer();this.savedContainerOverflow!==null&&e&&(e.style.overflow=this.savedContainerOverflow),this.savedContainerOverflow=null,document.removeEventListener(`touchmove`,this.blockTouchMove)}confirm(){let e=this.deps.getCore(),t=this.capture;this.capture=null,e!==null&&e.input.confirmPendingRowDrag()&&(this.lockContainer(),document.addEventListener(`touchmove`,this.blockTouchMove,{passive:!1}),this.applyPointerCapture(t),this.deps.onDragConfirmed(e.input.getDragState()))}lockContainer(){let e=this.deps.getContainer();e&&(this.savedContainerOverflow=e.style.overflow,e.style.overflow=`hidden`)}applyPointerCapture(e){e&&e.target.setPointerCapture(e.pointerId)}};const Wt=(e,t,n,r)=>{let i={slots:new Map(t),headers:new Map(n)};for(let t of e){let e=Vt(t,i.slots,i.headers);e!==null&&Gt(e,i,r)}return i},Gt=(e,t,n)=>{e.slots!==void 0&&$(t.slots,e.slots),e.headers!==void 0&&$(t.headers,e.headers),Kt(e,n),e.columns!==void 0&&e.columns!==null&&n.setColumnsOverride(e.columns),e.filterPopup!==void 0&&n.onFilterPopupChange(e.filterPopup)},Kt=(e,t)=>{e.contentWidth!==void 0&&t.setContentWidth(e.contentWidth),e.contentHeight!==void 0&&t.setContentHeight(e.contentHeight),e.rowsWrapperOffset!==void 0&&t.setRowsWrapperOffset(e.rowsWrapperOffset),e.isLoading!==void 0&&t.setIsLoading(e.isLoading),e.error!==void 0&&t.setErrorMessage(e.error),e.totalRows!==void 0&&t.setTotalRows(e.totalRows),e.pendingScrollTop!==void 0&&t.setPendingScrollTop(e.pendingScrollTop),e.activeCell!==void 0&&t.setActiveCell(e.activeCell),e.selectionRange!==void 0&&t.setSelectionRange(e.selectionRange),e.editingCell!==void 0&&t.setEditingCell(e.editingCell),e.hoverPosition!==void 0&&t.setHoverPosition(e.hoverPosition),e.peekCell!==void 0&&t.setPeekCell(e.peekCell)},$=(e,t)=>{e.clear(),t.forEach((t,n)=>e.set(n,t))};var qt=class{owned=null;lastAppliedRows=null;lastAppliedColumns=null;initialize(e,t){return e===null?(this.owned=X(t),this.lastAppliedRows=t,this.owned):e}syncRows(e,t){return t!==null||this.lastAppliedRows===e?null:(this.lastAppliedRows=e,e.length>1e4&&console.warn(`[gp-grid] rows input changed with ${e.length} rows — this triggers a full rebuild. Use createGridData() for efficient updates.`),this.owned?.destroy?.(),this.owned=X(e),this.owned)}syncColumns(e){return e.length===0||this.lastAppliedColumns===e?!1:(this.lastAppliedColumns=e,!0)}destroy(){this.owned?.destroy?.(),this.owned=null}},Jt=class{deps;constructor(e){this.deps=e}headerPointerDown(e,t,n,r){let i=this.deps.getCore();return i===null?!1:i.input.handleHeaderMouseDown(e,t,n,Q(r)).preventDefault}resizePointerDown(e,t,n){let r=this.deps.getCore();return r===null?!1:r.input.handleHeaderResizeMouseDown(e,t,Q(n)).preventDefault}cellPointerDown(e,t,n){let r=this.deps.getCore();if(r===null)return{preventDefault:!1,focusContainer:!1};let i=r.input.handleCellMouseDown(e,t,Q(n));return this.dispatchCellDragStart(i.startDrag,n),{preventDefault:i.preventDefault,focusContainer:i.focusContainer??!1}}cellPointerEnter(e,t){this.deps.getCore()?.input.handleCellMouseEnter(e,t)}cellPointerLeave(){this.deps.getCore()?.input.handleCellMouseLeave()}fillHandlePointerDown(e,t,n){let r=this.deps.getCore();if(r===null)return{preventDefault:!1,stopPropagation:!1};let i=r.input.handleFillHandleMouseDown(e,t,Q(n));return i.startDrag===`fill`&&(Yt(n),this.deps.onDragStateChange(r.input.getDragState())),{preventDefault:i.preventDefault,stopPropagation:i.stopPropagation}}dragMove(e){let t=this.deps.getCore(),n=this.deps.getBodyEl();if(t===null||n===null)return;let r=n.getBoundingClientRect(),i=t.input.handleDragMove(Q(e),{top:r.top,left:r.left,width:r.width,height:r.height,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft});this.deps.onDragStateChange(t.input.getDragState()),i?.autoScroll?this.deps.autoScroll.start(i.autoScroll.dx,i.autoScroll.dy):this.deps.autoScroll.stop()}documentPointerMove(e){let t=this.deps.getCore();if(t===null)return!1;let n=t.input.getDragState().isDragging;return this.deps.autoScroll.recordPointer(e),this.dragMove(e),n}documentPointerUp(){let e=this.deps.getCore();if(e===null)return{wasRowDrag:!1};let t=e.input.getDragState().dragType===`row-drag`;return this.deps.autoScroll.stop(),this.deps.autoScroll.clearPointer(),e.input.handleDragEnd(),this.deps.onDragStateChange(e.input.getDragState()),{wasRowDrag:t}}wheel(e,t,n){let r=this.deps.getCore();return r===null?null:r.input.handleWheel(e,t,n)}keyDown(e,t,n,r){let i=this.deps.getCore();return i===null?{preventDefault:!1}:i.input.handleKeyDown({key:e.key,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey},t,n,r)}pasteText(e,t,n){let r=this.deps.getCore();return r===null||t!==null||n?!1:r.pasteClipboardText(e)}dispatchCellDragStart(e,t){let n=this.deps.getCore();if(!(n===null||e===void 0)){if(e===`selection`){n.input.startSelectionDrag(),this.deps.onDragStateChange(n.input.getDragState());return}if(e===`row-drag`){this.deps.onDragStateChange(n.input.getDragState());return}e===`row-drag-pending`&&this.deps.pendingRowDrag.start(t)}}};const Yt=e=>{e.target.setPointerCapture(e.pointerId)};export{Ht as AutoScrollDriver,qt as DataSourceOwner,R as EditManager,I as FillManager,He as GridCore,C as HighlightManager,Ot as IndexedDataStore,Jt as InputEventAdapter,S as InputHandler,W as ParallelSortManager,Ut as PendingRowDragController,O as RowDataManager,w as RowMutationManager,A as ScrollVirtualizationManager,F as SelectionManager,L as SlotPoolManager,j as SortFilterManager,M as TransactionManager,z as WorkerPool,Wt as applyBatchInstructions,Vt as applyInstruction,ae as bindPeekSelectAll,p as buildCellClasses,n as calculateColumnPositions,re as calculateFillHandlePosition,ie as calculateFilterPopupPosition,i as calculateScaledColumnPositions,Ft as cellStyles,K as compareValues,tt as computeValueHash,Nt as containerStyles,Et as createClientDataSource,X as createDataSourceFromArray,Bt as createInitialState,jt as createMutableClientDataSource,Dt as createServerDataSource,Je as detectBoundaryCollisions,J as evaluateColumnFilter,St as evaluateDateCondition,bt as evaluateNumberCondition,vt as evaluateTextCondition,Lt as filtersStyles,a as findColumnAtX,te as findSlotForRow,y as formatCellValue,g as getFieldValue,r as getTotalWidth,zt as gridStyles,Pt as headerStyles,l as isCellActive,d as isCellEditing,f as isCellInFillPreview,c as isCellSelected,h as isColumnInSelectionRange,m as isRowInSelectionRange,u as isRowVisible,q as isSameDay,U as kWayMerge,qe as kWayMergeMultiColumn,Rt as rowDragStyles,wt as rowPassesFilter,ne as scrollCellIntoView,It as scrollbarStyles,_ as setFieldValue,Z as statesStyles,G as stringToSortableNumber,Q as toPointerEventData,Mt as variablesStyles};