@gp-grid/core 0.10.1 → 0.10.2

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const e=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},t=e=>e.at(-1)??0,n=(n,r)=>{let i=e(n),a=t(i);if(r<=a||a===0)return{positions:i,widths:n.map(e=>e.width)};let o=r/a,s=n.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},r=(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},i=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)}),a=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,o=(e,t,n)=>n?a(e,t,i(n)):!1,s=(e,t,n)=>n?.row===e&&n?.col===t,c=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t,n,r,a)=>{if(!n||!r||!a)return!1;let{minRow:o,maxRow:s,minCol:c,maxCol:l}=i(r),u=a.row>s,d=a.row<o;return u?e>s&&e<=a.row&&t>=c&&t<=l:d?e<o&&e>=a.row&&t>=c&&t<=l:!1},d=(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(` `)},f=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=i(t);return e>=n&&e<=r},p=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=i(t);return e>=n&&e<=r};function m(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 h(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 g=()=>{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=[]}}},_=()=>{let e=g(),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=[]}}},v=(e,t)=>{for(let n of e.values())if(n.rowIndex===t)return n;return null},ee=(e,t,n,r,i,a=0)=>{let o=v(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),te=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}},ne=(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}};var b=class{state={activeCell:null,range:null,anchor:null,selectionMode:!1};options;emitter=g();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:a,minCol:o,maxCol:s}=i(n);return e>=r&&e<=a&&t>=o&&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{range:e,activeCell:t}=this.state;if(!e&&!t)return[];let{minRow:n,maxRow:r,minCol:a,maxCol:o}=i(e||{startRow:t.row,startCol:t.col,endRow:t.row,endCol:t.col}),s=[];for(let e=n;e<=r;e++){let t=[];for(let n=a;n<=o;n++)t.push(this.options.getCellValue(e,n));s.push(t)}return s}async copySelectionToClipboard(){if(typeof navigator>`u`||typeof document>`u`)return;let e=this.getSelectedData();if(e.length===0)return;let t=e.map(e=>e.map(e=>y(e)).join(` `)).join(`
2
- `);await navigator.clipboard.writeText(t)}destroy(){this.emitter.clearListeners(),this.state={activeCell:null,range:null,anchor:null,selectionMode:!1}}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))}}},x=class{state=null;options;emitter=g();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:a,minCol:o,maxCol:s}=i(e),c=t>a,l=t<r;if(c||l)for(let e=o;e<=s;e++){let i=this.getSourceColumnValues(r,a,e),o=this.detectPattern(i);if(c)for(let r=a+1;r<=t;r++){let t=r-a-1,s=this.applyPattern(o,i,t);n.push({row:r,col:e,value:s})}else if(l)for(let a=r-1;a>=t;a--){let t=r-a-1,s=this.applyPattern(o,i,t,!0);n.push({row:a,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}}}},S=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;emitter=_();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}},C=class{editState=null;options;emitter=g();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}},re=class{core;deps;isDraggingSelection=!1;isDraggingFill=!1;fillSourceRange=null;fillTarget=null;isDraggingColumnResize=!1;resizeColIndex=-1;resizeStartX=0;resizeInitialWidth=0;resizeCurrentWidth=0;isDraggingColumnMove=!1;moveSourceColIndex=-1;moveStartX=0;moveStartY=0;moveThresholdMet=!1;moveShiftKey=!1;moveGhostWidth=0;moveGhostHeight=0;moveCurrentX=0;moveCurrentY=0;moveDropTargetIndex=null;isDraggingRow=!1;rowDragSourceIndex=-1;rowDragStartX=0;rowDragStartY=0;rowDragThresholdMet=!1;rowDragCurrentX=0;rowDragCurrentY=0;rowDragDropTargetIndex=null;pendingRowDrag=null;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps={...this.deps,...e}}getDragState(){let e=this.getDragType(),t=e===`column-resize`?{colIndex:this.resizeColIndex,initialWidth:this.resizeInitialWidth,currentWidth:this.resizeCurrentWidth}:null,n=e===`column-move`?{sourceColIndex:this.moveSourceColIndex,currentX:this.moveCurrentX,currentY:this.moveCurrentY,dropTargetIndex:this.moveDropTargetIndex,ghostWidth:this.moveGhostWidth,ghostHeight:this.moveGhostHeight}:null,r=e===`row-drag`?{sourceRowIndex:this.rowDragSourceIndex,currentX:this.rowDragCurrentX,currentY:this.rowDragCurrentY,dropTargetIndex:this.rowDragDropTargetIndex,dropIndicatorY:this.rowDragDropTargetIndex===null?0:this.core.getRowTranslateY(this.rowDragDropTargetIndex)}:null;return{isDragging:e!==null,dragType:e,fillSourceRange:this.fillSourceRange,fillTarget:this.fillTarget,columnResize:t,columnMove:n,rowDrag:r}}getDragType(){return this.isDraggingFill?`fill`:this.isDraggingColumnResize?`column-resize`:this.isDraggingColumnMove&&this.moveThresholdMet?`column-move`:this.isDraggingRow&&this.rowDragThresholdMet?`row-drag`:this.isDraggingSelection?`selection`:null}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return{preventDefault:!1,stopPropagation:!1};let r=this.core.getColumns()[t],i=this.core.isRowDragEntireRow();return(r?.rowDrag===!0||i)&&!n.shiftKey?n.pointerType===`touch`?(this.pendingRowDrag={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`}):(this.isDraggingRow=!0,this.rowDragSourceIndex=e,this.rowDragStartX=n.clientX,this.rowDragStartY=n.clientY,this.rowDragThresholdMet=!1,this.rowDragCurrentX=n.clientX,this.rowDragCurrentY=n.clientY,this.rowDragDropTargetIndex=null,this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}):(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){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let r=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(r),this.fillSourceRange=r,this.fillTarget={row:Math.max(r.startRow,r.endRow),col:Math.max(r.startCol,r.endCol)},this.isDraggingFill=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction,r=this.cycleSortDirection(n);this.core.setSort(e,r,t)}handleHeaderResizeMouseDown(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.isDraggingColumnResize=!0,this.resizeColIndex=e,this.resizeStartX=n.clientX,this.resizeInitialWidth=t,this.resizeCurrentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}handleHeaderMouseDown(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.isDraggingColumnMove=!0,this.moveSourceColIndex=e,this.moveStartX=r.clientX,this.moveStartY=r.clientY,this.moveThresholdMet=!1,this.moveShiftKey=r.shiftKey,this.moveGhostWidth=t,this.moveGhostHeight=n,this.moveCurrentX=r.clientX,this.moveCurrentY=r.clientY,this.moveDropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}startSelectionDrag(){this.isDraggingSelection=!0}confirmPendingRowDrag(){let e=this.pendingRowDrag;return e?(this.pendingRowDrag=null,this.isDraggingRow=!0,this.rowDragSourceIndex=e.rowIndex,this.rowDragStartX=e.clientX,this.rowDragStartY=e.clientY,this.rowDragThresholdMet=!1,this.rowDragCurrentX=e.clientX,this.rowDragCurrentY=e.clientY,this.rowDragDropTargetIndex=null,!0):!1}cancelPendingRowDrag(){this.pendingRowDrag=null}handleDragMove(e,t){return this.isDraggingColumnResize?this.handleColumnResizeDragMove(e,t):this.isDraggingColumnMove?this.handleColumnMoveDragMove(e,t):this.isDraggingRow?this.handleRowDragDragMove(e,t):this.handleSelectionFillDragMove(e,t)}handleColumnResizeDragMove(e,t){let n=this.core.getColumns()[this.resizeColIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.resizeInitialWidth+(e.clientX-this.resizeStartX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.resizeCurrentWidth=a;let o=e.clientX-t.left,s=0;o>t.width-40&&(s=10);let c=s===0?null:{dx:s,dy:0};return{targetRow:0,targetCol:this.resizeColIndex,autoScroll:c}}handleColumnMoveDragMove(e,t){let n=e.clientX-this.moveStartX,i=e.clientY-this.moveStartY;if(this.moveThresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(i)>5))return null;this.moveThresholdMet=!0}this.moveCurrentX=e.clientX,this.moveCurrentY=e.clientY;let{left:a,width:o,scrollLeft:s}=t,c=e.clientX-a+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.moveDropTargetIndex=Math.max(0,Math.min(r(c,l),u));let d=e.clientX-a,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.moveDropTargetIndex??0,autoScroll:p}}handleRowDragDragMove(e,t){let n=e.clientX-this.rowDragStartX,r=e.clientY-this.rowDragStartY;if(this.rowDragThresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.rowDragThresholdMet=!0}this.rowDragCurrentX=e.clientX,this.rowDragCurrentY=e.clientY;let{top:i,height:a,width:o,scrollTop:s}=t,c=this.deps.getHeaderHeight(),l=e.clientY-i,u=this.core.getRowCount(),d=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(l,s),u));this.rowDragDropTargetIndex=d;let f=e.clientY-i,p=e.clientX-t.left;return{targetRow:d,targetCol:0,autoScroll:this.calculateAutoScroll(f,p,a,o,c)}}handleSelectionFillDragMove(e,t){if((this.isDraggingSelection||this.isDraggingFill)===!1)return null;let{top:n,left:i,width:a,height:o,scrollTop:s,scrollLeft:c}=t,l=this.deps.getHeaderHeight(),u=this.deps.getColumnPositions(),d=this.deps.getColumnCount(),f=e.clientX-i+c,p=e.clientY-n,m=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(p,s),this.core.getRowCount()-1)),h=Math.max(0,Math.min(r(f,u),d-1)),g=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(h):h;this.isDraggingSelection&&this.core.selection.startSelection({row:m,col:g},{shift:!0}),this.isDraggingFill&&(this.core.fill.updateFillDrag(m,g),this.fillTarget={row:m,col:g});let _=e.clientY-n,v=e.clientX-i;return{targetRow:m,targetCol:g,autoScroll:this.calculateAutoScroll(_,v,o,a,l)}}handleDragEnd(){if(this.isDraggingColumnResize)return this.endColumnResizeDrag();if(this.isDraggingColumnMove)return this.endColumnMoveDrag();if(this.isDraggingRow)return this.endRowDrag();this.endSelectionFillDrag()}endColumnResizeDrag(){this.core.setColumnWidth(this.resizeColIndex,this.resizeCurrentWidth),this.isDraggingColumnResize=!1,this.resizeColIndex=-1}endColumnMoveDrag(){if(this.moveThresholdMet){if(this.moveDropTargetIndex!==null){let e=this.moveSourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.moveDropTargetIndex,this.deps.getColumnCount()-1)):this.moveDropTargetIndex;e!==t&&this.core.moveColumn(e,t)}}else{let e=this.core.getColumns()[this.moveSourceColIndex];if(e){let t=e.colId??e.field;this.handleHeaderClick(t,this.moveShiftKey)}}this.isDraggingColumnMove=!1,this.moveSourceColIndex=-1,this.moveThresholdMet=!1,this.moveShiftKey=!1,this.moveDropTargetIndex=null}endRowDrag(){this.rowDragThresholdMet&&this.rowDragDropTargetIndex!==null&&this.rowDragDropTargetIndex!==this.rowDragSourceIndex&&this.core.commitRowDrag(this.rowDragSourceIndex,this.rowDragDropTargetIndex),this.isDraggingRow=!1,this.rowDragSourceIndex=-1,this.rowDragThresholdMet=!1,this.rowDragDropTargetIndex=null}endSelectionFillDrag(){this.isDraggingFill&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.isDraggingSelection=!1,this.isDraggingFill=!1,this.fillSourceRange=null,this.fillTarget=null}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return r||n&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`?{preventDefault:!1}:this.handleKeyAction(e,t,n)}handleKeyAction(e,t,n){let{selection:r}=this.core,i=e.shiftKey,a=e.ctrlKey||e.metaKey,o=this.keyToDirection(e.key);if(o)return r.moveFocus(o,i),{preventDefault:!0,scrollToCell:r.getActiveCell()??void 0};switch(e.key){case`Enter`:return n?this.core.commitEdit():t&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Escape`:return n?this.core.cancelEdit():r.clearSelection(),{preventDefault:!0};case`Tab`:return n&&this.core.commitEdit(),r.moveFocus(i?`left`:`right`,!1),{preventDefault:!0};default:return this.handleNonEditingKey(e.key,t,n,a)}}handleNonEditingKey(e,t,n,r){let{selection:i}=this.core;switch(e){case`a`:if(r)return i.selectAll(),{preventDefault:!0};break;case`c`:if(r)return i.copySelectionToClipboard(),{preventDefault:!0};break;case`F2`:return t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Delete`:case`Backspace`:if(t&&!n)return this.core.startEdit(t.row,t.col),{preventDefault:!0};break;default:t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col);break}return{preventDefault:!1}}keyToDirection(e){switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}}cycleSortDirection(e){return e==null?`asc`:e===`asc`?`desc`:null}calculateAutoScroll(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}},w=class{options;highlightingOptions;hoverPosition=null;emitter=g();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:f(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:p(e,r)}}buildCellContext(e,t,n,r){let a=this.options.getActiveCell(),o=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(o){let{minRow:n,maxRow:r,minCol:a,maxCol:s}=i(o);c=e>=n&&e<=r&&t>=a&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:a,selectionRange:o,isHovered:s,isActive:a?.row===e&&a?.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}},ie=class{options;emitter=g();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 T=1e7;var E=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();return this.naturalContentHeight=e*t+n,this.naturalContentHeight>T?(this.virtualContentHeight=T,this.scrollRatio=T/this.naturalContentHeight):(this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1),{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}},D=class{options;emitter=g();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=new Map,o=0;for(let e of i.values()){if(++o>n)break;let i=m(e,r.field),[s,c]=this.normalizeDistinctValue(i);if(!a.has(s)&&(a.set(s,c),a.size>=t))break}let s=Array.from(a.values());return s.sort((e,t)=>{let n=y(e),r=y(t);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),s}normalizeDistinctValue(e){if(Array.isArray(e)){let t=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[JSON.stringify(t),t]}return[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}},O=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`:this.options.store.removeRows(n.rowIds),t.removed+=n.rowIds.length;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)}}},ae=class{columns;dataSource;rowHeight;headerHeight;overscan;sortingEnabled;getRowId;onCellValueChanged;rowDragEntireRow;onRowDragEnd;onColumnResized;onColumnMoved;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;currentPageIndex=0;pageSize=2**53-1;cachedRows=new Map;totalRows=0;selection;fill;input;highlight;sortFilter;rowMutation;slotPool;editManager;columnPositions=[];batchListeners=[];instructionBuffer=null;scrollVirtualization;isDestroyed=!1;_isDataLoading=!1;constructor(e){if(this.columns=e.columns,this.dataSource=e.dataSource,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(),this.selection=new b({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>{this.emit(e),this.highlight?.onSelectionChange()}),e.highlighting?(this.highlight=new w({getActiveCell:()=>this.selection.getActiveCell(),getSelectionRange:()=>this.selection.getSelectionRange(),getColumn:e=>this.columns[e]},e.highlighting),this.highlight.onInstruction(e=>this.emit(e))):this.highlight=null,this.fill=new x({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e)),this.scrollVirtualization=new E({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getTotalRows:()=>this.totalRows,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight}),this.slotPool=new S({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight,getTotalRows:()=>this.totalRows,getScrollRatio:()=>this.scrollVirtualization.getScrollRatio(),getVirtualContentHeight:()=>this.scrollVirtualization.getVirtualContentHeight(),getRowData:e=>this.cachedRows.get(e)}),this.slotPool.onBatchInstruction(e=>this.emitBatch(e)),this.editManager=new C({getColumn:e=>this.columns[e],getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),onCommit:e=>{this.slotPool.updateSlot(e)}}),this.editManager.onInstruction(e=>this.emit(e)),this.sortFilter=new D({getColumns:()=>this.columns,isSortingEnabled:()=>this.sortingEnabled,getCachedRows:()=>this.cachedRows,onSortFilterChange:async()=>{await this.fetchData(),this.highlight?.clearAllCaches(),this.scrollTop=0,this.startBatch();try{this.emit({type:`SCROLL_TO`,scrollTop:0}),this.emitContentSize(),this.emitHeaders(),this.slotPool.refreshAllSlots()}finally{this.flushBatch()}},onDataRefreshed:()=>{}}),this.sortFilter.onInstruction(e=>this.emit(e)),this.rowMutation=new ie({getCachedRows:()=>this.cachedRows,setCachedRows:e=>{this.cachedRows=e},getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},updateSlot:e=>this.slotPool.updateSlot(e),refreshAllSlots:()=>this.slotPool.refreshAllSlots(),emitContentSize:()=>this.emitContentSize(),clearSelectionIfInvalid:e=>this.clearSelectionIfInvalid(e)}),this.rowMutation.onInstruction(e=>this.emit(e)),this.input=new re(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}startBatch(){this.instructionBuffer=[]}flushBatch(){let e=this.instructionBuffer;if(this.instructionBuffer=null,e&&e.length>0)for(let t of this.batchListeners)t(e)}emit(e){this.instructionBuffer?this.instructionBuffer.push(e):this.emitBatch([e])}emitBatch(e){if(e.length!==0){if(this.instructionBuffer){this.instructionBuffer.push(...e);return}for(let t of this.batchListeners)t(e)}}async initialize(){await this.fetchData(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let i=this.scrollVirtualization.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r;if(!(this.scrollTop!==a||this.scrollLeft!==t||o))return;this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.slotPool.syncSlots();let s=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:s.start,end:s.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()}),o&&this.emitContentSize()}async fetchData(){this._isDataLoading=!0,this.emit({type:`DATA_LOADING`});try{let e=this.sortFilter.getSortModel(),t=this.sortFilter.getFilterModel(),n={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:e.length>0?e:void 0,filter:Object.keys(t).length>0?t:void 0},r=await this.dataSource.fetch(n);this.cachedRows.clear();let i=this.currentPageIndex*this.pageSize;r.rows.forEach((e,t)=>{this.cachedRows.set(i+t,e)}),this.totalRows=r.totalRows,this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}finally{this._isDataLoading=!1}}async setSort(e,t,n=!1){if(!this._isDataLoading)return this.sortFilter.setSort(e,t,n)}async setFilter(e,t){if(!this._isDataLoading)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._isDataLoading||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()}getEditState(){return this.editManager.getState()}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?m(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];if(!i)return;let a=this.onCellValueChanged?m(r,i.field):void 0;h(r,i.field,n),this.onCellValueChanged&&this.onCellValueChanged({rowId:this.getRowId(r),colIndex:t,field:i.field,oldValue:a,newValue:n,rowData:r})}clearSelectionIfInvalid(e){let t=this.selection.getActiveCell();t&&t.row>=e&&this.selection.clearSelection()}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)t.hidden||(e+=t.width,this.columnPositions.push(e))}emitContentSize(){let e=this.columnPositions.at(-1)??0;this.scrollVirtualization.updateContentSize(),this.emit({type:`SET_CONTENT_SIZE`,width:e,height:this.scrollVirtualization.getVirtualHeight(),viewportWidth:this.viewportWidth,viewportHeight:this.viewportHeight,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}emitHeaders(){let e=this.sortFilter.getSortInfoMap();for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index,hasFilter:this.sortFilter.hasActiveFilter(r)})}}setColumnWidth(e,t){let n=this.columns[e];if(n){n.width=t,this.computeColumnPositions(),this.startBatch();try{this.emitContentSize(),this.emitHeaders(),this.emit({type:`COLUMNS_CHANGED`,columns:[...this.columns]}),this.slotPool.syncSlots()}finally{this.flushBatch()}this.onColumnResized?.(e,t)}}moveColumn(e,t){if(e===t||e<0||e>=this.columns.length)return;let n=t>e?t-1:t;if(n<0||n>=this.columns.length||e===n)return;console.log(`[gp-grid] moveColumn`,e,`->`,n,`batching:`,this.instructionBuffer!==null);let[r]=this.columns.splice(e,1);this.columns.splice(n,0,r),this.computeColumnPositions(),this.startBatch();try{this.emitContentSize(),this.emitHeaders(),this.emit({type:`COLUMNS_CHANGED`,columns:[...this.columns]}),this.slotPool.refreshAllSlots(),console.log(`[gp-grid] moveColumn batch size:`,this.instructionBuffer?.length)}finally{this.flushBatch(),console.log(`[gp-grid] moveColumn batch flushed`)}this.onColumnMoved?.(e,n)}commitRowDrag(e,t){let n=this.dataSource;if(n.moveRow){n.moveRow(e,t),this.reorderCachedRows(e,t),this.highlight?.clearAllCaches();let r=Math.min(e,t),i=Math.max(e,t);for(let e=r;e<=i;e++)this.slotPool.updateSlot(e)}this.onRowDragEnd?.(e,t)}reorderCachedRows(e,t){let n=this.cachedRows.get(e);if(n!==void 0)if(e<t){let r=t-1;for(let t=e;t<r;t++){let e=this.cachedRows.get(t+1);e===void 0?this.cachedRows.delete(t):this.cachedRows.set(t,e)}this.cachedRows.set(r,n)}else{for(let n=e;n>t;n--){let e=this.cachedRows.get(n-1);e===void 0?this.cachedRows.delete(n):this.cachedRows.set(n,e)}this.cachedRows.set(t,n)}}isRowDragEntireRow(){return this.rowDragEntireRow}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}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.cachedRows.get(e)}async refresh(){await this.fetchData(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize();let e=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}async refreshFromTransaction(){let e=this.getVisibleRowRange(),t=Math.max(0,e.start-this.overscan),n=e.end+this.overscan,r=this.sortFilter.getSortModel(),i=this.sortFilter.getFilterModel(),a=await this.dataSource.fetch({pagination:{pageIndex:0,pageSize:n+1},sort:r.length>0?r:void 0,filter:Object.keys(i).length>0?i:void 0});this.totalRows=a.totalRows;for(let e=t;e<Math.min(n+1,a.rows.length);e++){let t=a.rows[e];t!==void 0&&this.cachedRows.set(e,t)}this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}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.dataSource=e,await this.refresh(),this.clearSelectionIfInvalid(this.totalRows)}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.cachedRows.clear(),this.batchListeners=[],this.totalRows=0)}},k=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 A(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 j=e=>e==null?``:Array.isArray(e)?e.join(`, `):typeof e==`object`&&!(e instanceof Date)?JSON.stringify(e):String(e);function oe(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():j(e).localeCompare(j(t))}function se(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=oe(A(e,r),A(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}self?.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=se(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var M=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 N=(e,t,n)=>{let r=[];for(let i=0;i<n;i++)r.push(e.columns[i][t]);return r};function P(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 M((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 F(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 M((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:N(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:N(r,s,n),globalIndex:e+r.offset})}}return i}function ce(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)}var I=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){this.pool=new k(`
2
+ `);await navigator.clipboard.writeText(t)}destroy(){this.emitter.clearListeners(),this.state={activeCell:null,range:null,anchor:null,selectionMode:!1}}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))}}},x=class{state=null;options;emitter=g();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:a,minCol:o,maxCol:s}=i(e),c=t>a,l=t<r;if(c||l)for(let e=o;e<=s;e++){let i=this.getSourceColumnValues(r,a,e),o=this.detectPattern(i);if(c)for(let r=a+1;r<=t;r++){let t=r-a-1,s=this.applyPattern(o,i,t);n.push({row:r,col:e,value:s})}else if(l)for(let a=r-1;a>=t;a--){let t=r-a-1,s=this.applyPattern(o,i,t,!0);n.push({row:a,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}}}},S=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;emitter=_();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}},C=class{editState=null;options;emitter=g();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}},re=class{core;deps;isDraggingSelection=!1;isDraggingFill=!1;fillSourceRange=null;fillTarget=null;isDraggingColumnResize=!1;resizeColIndex=-1;resizeStartX=0;resizeInitialWidth=0;resizeCurrentWidth=0;isDraggingColumnMove=!1;moveSourceColIndex=-1;moveStartX=0;moveStartY=0;moveThresholdMet=!1;moveShiftKey=!1;moveGhostWidth=0;moveGhostHeight=0;moveCurrentX=0;moveCurrentY=0;moveDropTargetIndex=null;isDraggingRow=!1;rowDragSourceIndex=-1;rowDragStartX=0;rowDragStartY=0;rowDragThresholdMet=!1;rowDragCurrentX=0;rowDragCurrentY=0;rowDragDropTargetIndex=null;pendingRowDrag=null;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps={...this.deps,...e}}getDragState(){let e=this.getDragType(),t=e===`column-resize`?{colIndex:this.resizeColIndex,initialWidth:this.resizeInitialWidth,currentWidth:this.resizeCurrentWidth}:null,n=e===`column-move`?{sourceColIndex:this.moveSourceColIndex,currentX:this.moveCurrentX,currentY:this.moveCurrentY,dropTargetIndex:this.moveDropTargetIndex,ghostWidth:this.moveGhostWidth,ghostHeight:this.moveGhostHeight}:null,r=e===`row-drag`?{sourceRowIndex:this.rowDragSourceIndex,currentX:this.rowDragCurrentX,currentY:this.rowDragCurrentY,dropTargetIndex:this.rowDragDropTargetIndex,dropIndicatorY:this.rowDragDropTargetIndex===null?0:this.core.getRowTranslateY(this.rowDragDropTargetIndex)}:null;return{isDragging:e!==null,dragType:e,fillSourceRange:this.fillSourceRange,fillTarget:this.fillTarget,columnResize:t,columnMove:n,rowDrag:r}}getDragType(){return this.isDraggingFill?`fill`:this.isDraggingColumnResize?`column-resize`:this.isDraggingColumnMove&&this.moveThresholdMet?`column-move`:this.isDraggingRow&&this.rowDragThresholdMet?`row-drag`:this.isDraggingSelection?`selection`:null}handleCellMouseDown(e,t,n){if(n.button!==0||this.core.getEditState()!==null)return{preventDefault:!1,stopPropagation:!1};let r=this.core.getColumns()[t],i=this.core.isRowDragEntireRow();return(r?.rowDrag===!0||i)&&!n.shiftKey?n.pointerType===`touch`?(this.pendingRowDrag={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`}):(this.isDraggingRow=!0,this.rowDragSourceIndex=e,this.rowDragStartX=n.clientX,this.rowDragStartY=n.clientY,this.rowDragThresholdMet=!1,this.rowDragCurrentX=n.clientX,this.rowDragCurrentY=n.clientY,this.rowDragDropTargetIndex=null,this.core.selection.startSelection({row:e,col:t},{shift:!1,ctrl:!1}),{preventDefault:!0,stopPropagation:!0,focusContainer:!0,startDrag:`row-drag`}):(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){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let r=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(r),this.fillSourceRange=r,this.fillTarget={row:Math.max(r.startRow,r.endRow),col:Math.max(r.startCol,r.endCol)},this.isDraggingFill=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction,r=this.cycleSortDirection(n);this.core.setSort(e,r,t)}handleHeaderResizeMouseDown(e,t,n){return n.button!==0||this.core.getColumns()[e]?.resizable===!1?{preventDefault:!1,stopPropagation:!1}:(this.isDraggingColumnResize=!0,this.resizeColIndex=e,this.resizeStartX=n.clientX,this.resizeInitialWidth=t,this.resizeCurrentWidth=t,{preventDefault:!0,stopPropagation:!0,startDrag:`column-resize`})}handleHeaderMouseDown(e,t,n,r){return r.button!==0||this.core.getColumns()[e]?.movable===!1?{preventDefault:!1,stopPropagation:!1}:(this.isDraggingColumnMove=!0,this.moveSourceColIndex=e,this.moveStartX=r.clientX,this.moveStartY=r.clientY,this.moveThresholdMet=!1,this.moveShiftKey=r.shiftKey,this.moveGhostWidth=t,this.moveGhostHeight=n,this.moveCurrentX=r.clientX,this.moveCurrentY=r.clientY,this.moveDropTargetIndex=null,{preventDefault:!0,stopPropagation:!0,startDrag:`column-move`})}startSelectionDrag(){this.isDraggingSelection=!0}confirmPendingRowDrag(){let e=this.pendingRowDrag;return e?(this.pendingRowDrag=null,this.isDraggingRow=!0,this.rowDragSourceIndex=e.rowIndex,this.rowDragStartX=e.clientX,this.rowDragStartY=e.clientY,this.rowDragThresholdMet=!1,this.rowDragCurrentX=e.clientX,this.rowDragCurrentY=e.clientY,this.rowDragDropTargetIndex=null,!0):!1}cancelPendingRowDrag(){this.pendingRowDrag=null}handleDragMove(e,t){return this.isDraggingColumnResize?this.handleColumnResizeDragMove(e,t):this.isDraggingColumnMove?this.handleColumnMoveDragMove(e,t):this.isDraggingRow?this.handleRowDragDragMove(e,t):this.handleSelectionFillDragMove(e,t)}handleColumnResizeDragMove(e,t){let n=this.core.getColumns()[this.resizeColIndex],r=n?.minWidth??50,i=n?.maxWidth,a=this.resizeInitialWidth+(e.clientX-this.resizeStartX);a=Math.max(r,a),i!==void 0&&(a=Math.min(i,a)),this.resizeCurrentWidth=a;let o=e.clientX-t.left,s=0;o>t.width-40&&(s=10);let c=s===0?null:{dx:s,dy:0};return{targetRow:0,targetCol:this.resizeColIndex,autoScroll:c}}handleColumnMoveDragMove(e,t){let n=e.clientX-this.moveStartX,i=e.clientY-this.moveStartY;if(this.moveThresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(i)>5))return null;this.moveThresholdMet=!0}this.moveCurrentX=e.clientX,this.moveCurrentY=e.clientY;let{left:a,width:o,scrollLeft:s}=t,c=e.clientX-a+s,l=this.deps.getColumnPositions(),u=this.deps.getColumnCount();this.moveDropTargetIndex=Math.max(0,Math.min(r(c,l),u));let d=e.clientX-a,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.moveDropTargetIndex??0,autoScroll:p}}handleRowDragDragMove(e,t){let n=e.clientX-this.rowDragStartX,r=e.clientY-this.rowDragStartY;if(this.rowDragThresholdMet===!1){if(!(Math.abs(n)>5||Math.abs(r)>5))return null;this.rowDragThresholdMet=!0}this.rowDragCurrentX=e.clientX,this.rowDragCurrentY=e.clientY;let{top:i,height:a,width:o,scrollTop:s}=t,c=this.deps.getHeaderHeight(),l=e.clientY-i,u=this.core.getRowCount(),d=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(l,s),u));this.rowDragDropTargetIndex=d;let f=e.clientY-i,p=e.clientX-t.left;return{targetRow:d,targetCol:0,autoScroll:this.calculateAutoScroll(f,p,a,o,c)}}handleSelectionFillDragMove(e,t){if((this.isDraggingSelection||this.isDraggingFill)===!1)return null;let{top:n,left:i,width:a,height:o,scrollTop:s,scrollLeft:c}=t,l=this.deps.getHeaderHeight(),u=this.deps.getColumnPositions(),d=this.deps.getColumnCount(),f=e.clientX-i+c,p=e.clientY-n,m=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(p,s),this.core.getRowCount()-1)),h=Math.max(0,Math.min(r(f,u),d-1)),g=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(h):h;this.isDraggingSelection&&this.core.selection.startSelection({row:m,col:g},{shift:!0}),this.isDraggingFill&&(this.core.fill.updateFillDrag(m,g),this.fillTarget={row:m,col:g});let _=e.clientY-n,v=e.clientX-i;return{targetRow:m,targetCol:g,autoScroll:this.calculateAutoScroll(_,v,o,a,l)}}handleDragEnd(){if(this.isDraggingColumnResize)return this.endColumnResizeDrag();if(this.isDraggingColumnMove)return this.endColumnMoveDrag();if(this.isDraggingRow)return this.endRowDrag();this.endSelectionFillDrag()}endColumnResizeDrag(){this.core.setColumnWidth(this.resizeColIndex,this.resizeCurrentWidth),this.isDraggingColumnResize=!1,this.resizeColIndex=-1}endColumnMoveDrag(){if(this.moveThresholdMet){if(this.moveDropTargetIndex!==null){let e=this.moveSourceColIndex,t=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(Math.min(this.moveDropTargetIndex,this.deps.getColumnCount()-1)):this.moveDropTargetIndex;e!==t&&this.core.moveColumn(e,t)}}else{let e=this.core.getColumns()[this.moveSourceColIndex];if(e){let t=e.colId??e.field;this.handleHeaderClick(t,this.moveShiftKey)}}this.isDraggingColumnMove=!1,this.moveSourceColIndex=-1,this.moveThresholdMet=!1,this.moveShiftKey=!1,this.moveDropTargetIndex=null}endRowDrag(){this.rowDragThresholdMet&&this.rowDragDropTargetIndex!==null&&this.rowDragDropTargetIndex!==this.rowDragSourceIndex&&this.core.commitRowDrag(this.rowDragSourceIndex,this.rowDragDropTargetIndex),this.isDraggingRow=!1,this.rowDragSourceIndex=-1,this.rowDragThresholdMet=!1,this.rowDragDropTargetIndex=null}endSelectionFillDrag(){this.isDraggingFill&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.isDraggingSelection=!1,this.isDraggingFill=!1,this.fillSourceRange=null,this.fillTarget=null}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){return r||n&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`?{preventDefault:!1}:this.handleKeyAction(e,t,n)}handleKeyAction(e,t,n){let{selection:r}=this.core,i=e.shiftKey,a=e.ctrlKey||e.metaKey,o=this.keyToDirection(e.key);if(o)return r.moveFocus(o,i),{preventDefault:!0,scrollToCell:r.getActiveCell()??void 0};switch(e.key){case`Enter`:return n?this.core.commitEdit():t&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Escape`:return n?this.core.cancelEdit():r.clearSelection(),{preventDefault:!0};case`Tab`:return n&&this.core.commitEdit(),r.moveFocus(i?`left`:`right`,!1),{preventDefault:!0};default:return this.handleNonEditingKey(e.key,t,n,a)}}handleNonEditingKey(e,t,n,r){let{selection:i}=this.core;switch(e){case`a`:if(r)return i.selectAll(),{preventDefault:!0};break;case`c`:if(r)return i.copySelectionToClipboard(),{preventDefault:!0};break;case`F2`:return t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Delete`:case`Backspace`:if(t&&!n)return this.core.startEdit(t.row,t.col),{preventDefault:!0};break;default:t&&!n&&!r&&e.length===1&&this.core.startEdit(t.row,t.col);break}return{preventDefault:!1}}keyToDirection(e){switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}}cycleSortDirection(e){return e==null?`asc`:e===`asc`?`desc`:null}calculateAutoScroll(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}},w=class{options;highlightingOptions;hoverPosition=null;emitter=g();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:f(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:p(e,r)}}buildCellContext(e,t,n,r){let a=this.options.getActiveCell(),o=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(o){let{minRow:n,maxRow:r,minCol:a,maxCol:s}=i(o);c=e>=n&&e<=r&&t>=a&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:a,selectionRange:o,isHovered:s,isActive:a?.row===e&&a?.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}},ie=class{options;emitter=g();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 T=1e7;var E=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();return this.naturalContentHeight=e*t+n,this.naturalContentHeight>T?(this.virtualContentHeight=T,this.scrollRatio=T/this.naturalContentHeight):(this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1),{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}},D=class{options;emitter=g();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=new Map,o=0;for(let e of i.values()){if(++o>n)break;let i=m(e,r.field),[s,c]=this.normalizeDistinctValue(i);if(!a.has(s)&&(a.set(s,c),a.size>=t))break}let s=Array.from(a.values());return s.sort((e,t)=>{let n=y(e),r=y(t);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),s}normalizeDistinctValue(e){if(Array.isArray(e)){let t=[...e].sort((e,t)=>{let n=String(e),r=String(t);return n===r?0:n<r?-1:1});return[JSON.stringify(t),t]}return[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}},O=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`:this.options.store.removeRows(n.rowIds),t.removed+=n.rowIds.length;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)}}},ae=class{columns;dataSource;rowHeight;headerHeight;overscan;sortingEnabled;getRowId;onCellValueChanged;rowDragEntireRow;onRowDragEnd;onColumnResized;onColumnMoved;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;currentPageIndex=0;pageSize=2**53-1;cachedRows=new Map;totalRows=0;selection;fill;input;highlight;sortFilter;rowMutation;slotPool;editManager;columnPositions=[];batchListeners=[];instructionBuffer=null;scrollVirtualization;isDestroyed=!1;_isDataLoading=!1;constructor(e){if(this.columns=e.columns,this.dataSource=e.dataSource,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(),this.selection=new b({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>{this.emit(e),this.highlight?.onSelectionChange()}),e.highlighting?(this.highlight=new w({getActiveCell:()=>this.selection.getActiveCell(),getSelectionRange:()=>this.selection.getSelectionRange(),getColumn:e=>this.columns[e]},e.highlighting),this.highlight.onInstruction(e=>this.emit(e))):this.highlight=null,this.fill=new x({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e)),this.scrollVirtualization=new E({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getTotalRows:()=>this.totalRows,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight}),this.slotPool=new S({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight,getTotalRows:()=>this.totalRows,getScrollRatio:()=>this.scrollVirtualization.getScrollRatio(),getVirtualContentHeight:()=>this.scrollVirtualization.getVirtualContentHeight(),getRowData:e=>this.cachedRows.get(e)}),this.slotPool.onBatchInstruction(e=>this.emitBatch(e)),this.editManager=new C({getColumn:e=>this.columns[e],getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),onCommit:e=>{this.slotPool.updateSlot(e)}}),this.editManager.onInstruction(e=>this.emit(e)),this.sortFilter=new D({getColumns:()=>this.columns,isSortingEnabled:()=>this.sortingEnabled,getCachedRows:()=>this.cachedRows,onSortFilterChange:async()=>{await this.fetchData(),this.highlight?.clearAllCaches(),this.scrollTop=0,this.startBatch();try{this.emit({type:`SCROLL_TO`,scrollTop:0}),this.emitContentSize(),this.emitHeaders(),this.slotPool.refreshAllSlots()}finally{this.flushBatch()}},onDataRefreshed:()=>{}}),this.sortFilter.onInstruction(e=>this.emit(e)),this.rowMutation=new ie({getCachedRows:()=>this.cachedRows,setCachedRows:e=>{this.cachedRows=e},getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},updateSlot:e=>this.slotPool.updateSlot(e),refreshAllSlots:()=>this.slotPool.refreshAllSlots(),emitContentSize:()=>this.emitContentSize(),clearSelectionIfInvalid:e=>this.clearSelectionIfInvalid(e)}),this.rowMutation.onInstruction(e=>this.emit(e)),this.input=new re(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}startBatch(){this.instructionBuffer=[]}flushBatch(){let e=this.instructionBuffer;if(this.instructionBuffer=null,e&&e.length>0)for(let t of this.batchListeners)t(e)}emit(e){this.instructionBuffer?this.instructionBuffer.push(e):this.emitBatch([e])}emitBatch(e){if(e.length!==0){if(this.instructionBuffer){this.instructionBuffer.push(...e);return}for(let t of this.batchListeners)t(e)}}async initialize(){await this.fetchData(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let i=this.scrollVirtualization.getScrollRatio(),a=i<1?e/i:e,o=this.viewportWidth!==n||this.viewportHeight!==r;if(!(this.scrollTop!==a||this.scrollLeft!==t||o))return;this.scrollTop=a,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.slotPool.syncSlots();let s=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:s.start,end:s.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()}),o&&this.emitContentSize()}async fetchData(){this._isDataLoading=!0,this.emit({type:`DATA_LOADING`});try{let e=this.sortFilter.getSortModel(),t=this.sortFilter.getFilterModel(),n={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:e.length>0?e:void 0,filter:Object.keys(t).length>0?t:void 0},r=await this.dataSource.fetch(n);this.cachedRows.clear();let i=this.currentPageIndex*this.pageSize;r.rows.forEach((e,t)=>{this.cachedRows.set(i+t,e)}),this.totalRows=r.totalRows,this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}finally{this._isDataLoading=!1}}async setSort(e,t,n=!1){if(!this._isDataLoading)return this.sortFilter.setSort(e,t,n)}async setFilter(e,t){if(!this._isDataLoading)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._isDataLoading||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()}getEditState(){return this.editManager.getState()}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?m(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];if(!i)return;let a=this.onCellValueChanged?m(r,i.field):void 0;h(r,i.field,n),this.onCellValueChanged&&this.onCellValueChanged({rowId:this.getRowId(r),colIndex:t,field:i.field,oldValue:a,newValue:n,rowData:r})}clearSelectionIfInvalid(e){let t=this.selection.getActiveCell();t&&t.row>=e&&this.selection.clearSelection()}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)t.hidden||(e+=t.width,this.columnPositions.push(e))}emitContentSize(){let e=this.columnPositions.at(-1)??0;this.scrollVirtualization.updateContentSize(),this.emit({type:`SET_CONTENT_SIZE`,width:e,height:this.scrollVirtualization.getVirtualHeight(),viewportWidth:this.viewportWidth,viewportHeight:this.viewportHeight,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}emitHeaders(){let e=this.sortFilter.getSortInfoMap();for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index,hasFilter:this.sortFilter.hasActiveFilter(r)})}}setColumnWidth(e,t){let n=this.columns[e];if(n){n.width=t,this.computeColumnPositions(),this.startBatch();try{this.emitContentSize(),this.emitHeaders(),this.emit({type:`COLUMNS_CHANGED`,columns:[...this.columns]}),this.slotPool.syncSlots()}finally{this.flushBatch()}this.onColumnResized?.(e,t)}}moveColumn(e,t){if(e===t||e<0||e>=this.columns.length)return;let n=t>e?t-1:t;if(n<0||n>=this.columns.length||e===n)return;console.log(`[gp-grid] moveColumn`,e,`->`,n,`batching:`,this.instructionBuffer!==null);let[r]=this.columns.splice(e,1);this.columns.splice(n,0,r),this.computeColumnPositions(),this.startBatch();try{this.emitContentSize(),this.emitHeaders(),this.emit({type:`COLUMNS_CHANGED`,columns:[...this.columns]}),this.slotPool.refreshAllSlots(),console.log(`[gp-grid] moveColumn batch size:`,this.instructionBuffer?.length)}finally{this.flushBatch(),console.log(`[gp-grid] moveColumn batch flushed`)}this.onColumnMoved?.(e,n)}commitRowDrag(e,t){let n=this.dataSource;if(n.moveRow){n.moveRow(e,t),this.reorderCachedRows(e,t),this.highlight?.clearAllCaches();let r=Math.min(e,t),i=Math.max(e,t);for(let e=r;e<=i;e++)this.slotPool.updateSlot(e)}this.onRowDragEnd?.(e,t)}reorderCachedRows(e,t){let n=this.cachedRows.get(e);if(n!==void 0)if(e<t){let r=t-1;for(let t=e;t<r;t++){let e=this.cachedRows.get(t+1);e===void 0?this.cachedRows.delete(t):this.cachedRows.set(t,e)}this.cachedRows.set(r,n)}else{for(let n=e;n>t;n--){let e=this.cachedRows.get(n-1);e===void 0?this.cachedRows.delete(n):this.cachedRows.set(n,e)}this.cachedRows.set(t,n)}}isRowDragEntireRow(){return this.rowDragEntireRow}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}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.cachedRows.get(e)}async refresh(){await this.fetchData(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize();let e=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}async refreshFromTransaction(){let e=this.getVisibleRowRange(),t=Math.max(0,e.start-this.overscan),n=e.end+this.overscan,r=this.sortFilter.getSortModel(),i=this.sortFilter.getFilterModel(),a=await this.dataSource.fetch({pagination:{pageIndex:0,pageSize:n+1},sort:r.length>0?r:void 0,filter:Object.keys(i).length>0?i:void 0});this.totalRows=a.totalRows;for(let e=t;e<Math.min(n+1,a.rows.length);e++){let t=a.rows[e];t!==void 0&&this.cachedRows.set(e,t)}this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end,rowsWrapperOffset:this.slotPool.getRowsWrapperOffset()})}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.dataSource=e,await this.refresh(),this.clearSelectionIfInvalid(this.totalRows)}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.cachedRows.clear(),this.batchListeners=[],this.totalRows=0)}},k=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 A(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 j=e=>e==null?``:Array.isArray(e)?e.join(`, `):typeof e==`object`&&!(e instanceof Date)?JSON.stringify(e):String(e);function oe(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():j(e).localeCompare(j(t))}function se(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=oe(A(e,r),A(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}typeof self<`u`&&self.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=se(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var M=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 N=(e,t,n)=>{let r=[];for(let i=0;i<n;i++)r.push(e.columns[i][t]);return r};function P(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 M((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 F(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 M((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:N(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:N(r,s,n),globalIndex:e+r.offset})}}return i}function ce(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)}var I=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){this.pool=new k(`
3
3
  // Inline sort worker code
4
4
  function getFieldValue(row, field) {
5
5
  const parts = field.split(".");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gp-grid/core",
3
3
  "description": "A high-performance, framework-agnostic TypeScript data grid core with virtual scrolling",
4
4
  "private": false,
5
- "version": "0.10.1",
5
+ "version": "0.10.2",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",