@sheetxl/grid-react 0.7.20 → 0.7.22

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.
@@ -1,12 +1,12 @@
1
1
  (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("._sheetxl-grid_h9wwa_7{position:relative;box-sizing:border-box;user-select:none}._sheetxl-grid_h9wwa_7 *{box-sizing:border-box!important}._sheetxl-grid_h9wwa_7 *:focus{outline:none}._sheetxl-grid_h9wwa_7 .cell-container{position:absolute;overflow:visible;white-space:pre}._sheetxl-grid_h9wwa_7 .cell-container>*{inset:0;position:absolute}._sheetxl-grid_h9wwa_7 .sheetxl-stage{contain:strict}._sheetxl-grid_h9wwa_7 .sheetxl-stage>*{contain:strict}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
2
  "use strict";/**
3
- * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.20
3
+ * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.22
4
4
  *
5
5
  * (C) 2025-present SheetXL Inc. & Michael T. Ford
6
6
  * License: The license can be found at https://www.sheetxl.com/license.
7
- */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("react/jsx-runtime"),o=require("@sheetxl/utils-react"),l=require("react"),n=require("@sheetxl/utils"),Zo=require("react-dom"),Yt=({itemType:t,index:r,itemSize:i,instanceProps:c,scale:d=1})=>{let f,a,s;t==="column"?(f=c.columnMetadataMap,a=c.lastMeasuredColumnIndex,s=c.recalcColumnIndices):(f=c.rowMetadataMap,a=c.lastMeasuredRowIndex,s=c.recalcRowIndices);const p=s.length>0;if(r>a){let O=0;if(a>=0){const U=f[a];O=U.offset+U.size}for(let U=a+1;U<=r;U++){let M=p?s.includes(U)?i(U)*d:f[U]?.size||i(U)*d:i(U)*d;f[U]={offset:O,size:M},O+=M}t==="column"?c.lastMeasuredColumnIndex=r:c.lastMeasuredRowIndex=r}return f[r],f[r]},Bo=({itemType:t,itemSize:r,itemCount:i,instanceProps:c,offset:d,scale:f})=>{let a,s;t==="column"?(a=c.columnMetadataMap,s=c.lastMeasuredColumnIndex):(a=c.rowMetadataMap,s=c.lastMeasuredRowIndex);let p=0;return p=(s>0?a[s].offset:0)>=d?Jo({itemType:t,itemSize:r,instanceProps:c,high:s,low:0,offset:d,scale:f}):fn({itemType:t,itemSize:r,itemCount:i,instanceProps:c,index:Math.max(0,s),offset:d,scale:f}),p=Math.min(p,i),p},Jo=({itemType:t,itemSize:r,instanceProps:i,high:c,low:d,offset:f,scale:a})=>{for(;d<=c;){const s=d+Math.floor((c-d)/2),p=Yt({itemType:t,itemSize:r,index:s,instanceProps:i,scale:a}).offset;if(p===f)return s;p<f?d=s+1:p>f&&(c=s-1)}return d>0?d-1:0},fn=({itemType:t,itemSize:r,itemCount:i,instanceProps:c,index:d,offset:f,scale:a})=>{let s=1;for(;d<i&&Yt({itemType:t,itemSize:r,index:d,instanceProps:c,scale:a}).offset<f;)d+=s,s*=2;return Jo({itemType:t,itemSize:r,instanceProps:c,high:Math.min(d,i-1),low:Math.floor(d/2),offset:f,scale:a})},Qo=t=>{const{rowCount:r,columnCount:i,defaultRowHeight:c,getRowHeight:d,defaultColumnWidth:f,getColumnWidth:a}=t||{},s=l.useRef({columnMetadataMap:{},rowMetadataMap:{},lastMeasuredColumnIndex:-1,lastMeasuredRowIndex:-1,recalcColumnIndices:[],recalcRowIndices:[]}),p=o.useCallbackRef(P=>Bo({itemType:"row",itemCount:r,itemSize:d??(()=>c??20),instanceProps:s.current,offset:P}),[r,d,c]),O=o.useCallbackRef(P=>P===-1?0:Yt({itemType:"row",index:P,itemSize:d??(()=>c??20),instanceProps:s.current}).offset,[d,c]),U=o.useCallbackRef(P=>Yt({itemType:"row",index:P,itemSize:d??(()=>c??20),instanceProps:s.current}).size,[d,c]),M=o.useCallbackRef(P=>Bo({itemType:"column",itemCount:i,itemSize:a??(()=>f??75),instanceProps:s.current,offset:P}),[i,a,f]),T=o.useCallbackRef(P=>P===-1?0:Yt({itemType:"column",index:P,itemSize:a??(()=>f??75),instanceProps:s.current}).offset,[a,f]),B=o.useCallbackRef(P=>Yt({itemType:"column",index:P,itemSize:a??(()=>f??75),instanceProps:s.current}).size,[a,f]),[te,Z]=l.useReducer(P=>P+1,0),X=()=>({getRowOffset:O,getColOffset:T,getRowIndex:p,getColIndex:M}),[Me,J]=l.useState(()=>t?X():null);return l.useEffect(()=>{J(t?X():null)},[te,r,i,f,c,U,B]),Me},Lo="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ~`!@#$%^&*()-_=+[{]};:'\",<.>/?|\\",Ko=t=>{if(!t)return null;if(t.eventType==="start")return{type:t.eventType};if(t.eventType==="submit")return{type:t.eventType};if(t.eventType==="cancel")return{type:t.eventType};if(t.eventType==="keyboard")return{type:t.eventType,key:t.event.key};if(t.eventType==="pointer")return{type:t.eventType};if(t.eventType==="coordsChange"){const r={type:t.eventType};return t.activeCoords&&(r.activeCoords=t.activeCoords),r}return{type:t.eventType??"unknown"}},gn=t=>!0,wn=t=>!!t&&!(t.ctrlKey||t.metaKey||t.altKey||t.isComposing)&&(!(t.shiftKey||t.key!=="F2"&&t.key!==" "&&t.key!=="Backspace")||(!t.shiftKey||t.key!==" ")&&Lo.indexOf(t.key)!==-1),xn=t=>!!t&&t.type==="dblclick"&&{editMode:!0},pn=t=>{const{session:r,refLatestCoords:i,handleSubmitEdit:c,handleCancelEdit:d,cellBounds:f,isInBounds:a,getCellEditor:s,propsEditor:p,borderStrokeFill:O="rgb(33, 115, 70)",borderStrokeWidth:U=2,alignment:M=o.HorizontalAlignment.Left,style:T,...B}=t,te=l.useRef(null),Z=l.useRef(null),[X,Me]=l.useState(!1),J=r.coords,P=l.useCallback(async ce=>{if(te.current?.getBoundingClientRect()){if(ce.eventType==="keyboard"){const A=ce.event,C=new KeyboardEvent(A.type,{bubbles:!0,cancelable:!0,view:window,key:A.key,code:A.code,location:A.location,repeat:A.repeat,isComposing:A.isComposing,charCode:A.charCode,keyCode:A.keyCode,which:A.which,ctrlKey:A.ctrlKey,shiftKey:A.shiftKey,altKey:A.altKey,metaKey:A.metaKey});C.isSynthetic=!0,C.key,Z.current?.dispatchEvent(C)}else ce.eventType==="pointer"||console.warn("unsupported event type",ce);await new Promise(A=>requestAnimationFrame(A))}},[]);l.useEffect(()=>{const ce=Z.current;return Me(!0),Z.current.startEdit?.(r.startEvent),(async()=>{r.editorRefs.push(ce),r.editorRefsDispatchEditorEvent.push(P);const pe=[...r.events];for(let A=0;A<pe.length;A++)await P(pe[A]);r.onMount(ce)})(),()=>{const pe=r.editorRefs.indexOf(ce);pe!==-1&&r.editorRefs.splice(pe,1),r.onUnmount(ce)}},[]);const G=l.useCallback(()=>c(r),[]),we=l.useCallback(()=>{d(r)},[]),K=i.current&&n.CoordUtils.isEqualCells(i.current,J),ge=a&&K&&X,Le=s({autoFocus:!!r.startEvent?.autoFocus,...p,onSubmitEdit:G,onCancelEdit:we,ref:Z},J),ye=f.x+o.ReactUtils.boundPixel(-U/2),Oe=o.ReactUtils.boundPixel(f.width+U/2,!0);return ee.jsx("div",{tabIndex:0,ref:te,style:{background:void 0,...T,opacity:ge?T?.opacity??1:0,pointerEvents:"auto",position:"absolute",boxSizing:"border-box",top:`${f.y+o.ReactUtils.boundPixel(-U/2)}px`,height:o.ReactUtils.boundPixel(f.height+U/2,!0),left:`${ye}px`,width:Oe},...B,children:ee.jsx("div",{className:"editor-container",style:{position:"absolute",boxSizing:"border-box",left:`${o.ReactUtils.boundPixel(1)}px`,top:`${o.ReactUtils.boundPixel(1)}px`,width:o.ReactUtils.boundPixel(f.width-2,!0),height:o.ReactUtils.boundPixel(f.height-2,!0),outline:`${U}px ${O} solid`,boxShadow:"rgba(60,64,67,.35) 2px 2px 6px 3px",maxHeight:"100%",overflow:"hidden",display:"flex"},children:Le})})},mn=Object.freeze({once:!0}),Te=(t,r,i)=>{if(!t)return r;let c=r;const d=i===n.Direction.Right||i===n.Direction.Down;for(;;){const f=t(c,!d);if(f===0)return c;d?c+=f:c-=f}},uo=(t,r,i)=>{const c=[];let d=r;for(;d<=i;){const f=Math.max(0,t(d));f===0?(c.push(d),d++):d+=f}return c},Cn=(t,r,i,c,d,f)=>{if(!r)return f;let{rowIndex:a,colIndex:s}=t;switch(c){case n.Direction.Down:{a=Te(i,Math.min(a+1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&a<f;)a=Te(i,Math.min(++a,f),c),p=r({rowIndex:a,colIndex:s});return a}case n.Direction.Up:{a=Te(i,Math.max(a-1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&a>f;)a=Te(i,Math.max(--a,f),c),p=r({rowIndex:a,colIndex:s});return a}case n.Direction.Right:{s=Te(i,Math.min(s+1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&s<f;)s=Te(i,Math.min(++s,f),c),p=r({rowIndex:a,colIndex:s});return s}case n.Direction.Left:{s=Te(i,Math.max(s-1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&s>f;)s=Te(i,Math.max(--s,f),c),p=r({rowIndex:a,colIndex:s});return s}default:return f}},Sn=(t,r=()=>!0,i,c,d,f)=>{let{rowIndex:a,colIndex:s}=t;switch(c){case n.Direction.Down:{a=Te(i,Math.min(a+1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&a<f;)a=Te(i,Math.min(++a,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?a:a-1}case n.Direction.Up:{a=Te(i,Math.max(a-1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&a>f;)a=Te(i,Math.max(--a,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?a:a+1}case n.Direction.Right:{s=Te(i,Math.min(s+1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&s<f;)s=Te(i,Math.min(++s,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?s:s-1}case n.Direction.Left:{s=Te(i,Math.max(s-1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&s>f;)s=Te(i,Math.max(--s,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?s:s+1}default:return null}},bn=(t,r,i,c,d,f)=>{if(!r)return f;let a,{rowIndex:s,colIndex:p}=t;c===n.Direction.Down?a={rowIndex:s+1,colIndex:p}:c===n.Direction.Up?a={rowIndex:s-1,colIndex:p}:c===n.Direction.Right?a={rowIndex:s,colIndex:p+1}:c===n.Direction.Left&&(a={rowIndex:s,colIndex:p-1});const O=r(t),U=r(a);var M,T;return(T=U,!(M=O)&&!T||!M&&T||M&&!T?Cn:Sn)(t,r,i,c,!1,f)??f},Fo=(t,r)=>`${t}:${r}`,Wo=(t,r,i,c,d,f)=>{if(i-r>=d-c)return c;let a=c;return t==="nearest"&&(c-r>0?t="start":i-d>0&&(t="end")),t==="start"?a=r:t==="end"?a=i-(d-c):t==="center"&&(a=r+(i-r)/2-(d-c)/2),a<c?Math.max(0,a):a>c?Math.min(a,f-(d-c)):void 0},Vo=(t,r,i,c)=>(console.log("todo: implement convertToVisibleRanges"),t),Do=(t,r=n.Direction.Right,i,c,d,f=null)=>{if(f&&n.CoordUtils.isEqualSelectionCoords(f,t))return t;const a=t.ranges[t.rangeIndex];if(!n.CoordUtils.isRangesIntersect({rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},a))return t;let s={...t.cell},p=t.rangeIndex;switch(r){case n.Direction.Right:s.colIndex=Te(d,s.colIndex+1,r);break;case n.Direction.Left:s.colIndex=Te(d,s.colIndex-1,r);break;case n.Direction.Down:s.rowIndex=Te(c,s.rowIndex+1,r);break;case n.Direction.Up:s.rowIndex=Te(c,s.rowIndex-1,r)}const O=T=>{if(T){p=t.rangeIndex>=t.ranges.length-1?0:t.rangeIndex+1;const B=t.ranges[p];s={colIndex:B.colStart,rowIndex:B.rowStart}}else{p=t.rangeIndex<=0?t.ranges.length-1:t.rangeIndex-1;const B=t.ranges[p];s={colIndex:B.colEnd,rowIndex:B.rowEnd}}};if(r===n.Direction.Right&&s.colIndex>a.colEnd&&s.rowIndex===a.rowEnd)O(!0);else if(r===n.Direction.Left&&s.colIndex<a.colStart&&s.rowIndex===a.rowStart)O(!1);else if(r===n.Direction.Down&&s.colIndex===a.colEnd&&s.rowIndex>a.rowEnd)O(!0);else if(r===n.Direction.Up&&s.colIndex===a.colStart&&s.rowIndex<a.rowStart)O(!1);else{let T=s.rowIndex,B=s.colIndex;switch(r){case n.Direction.Right:B>a.colEnd&&(T=Te(c,T+1,r),B=a.colStart,T>a.rowEnd&&(T=a.rowStart));break;case n.Direction.Left:B<a.colStart&&(T=Te(c,T-1,r),B=a.colEnd,T<a.rowStart&&(T=a.rowEnd));break;case n.Direction.Down:T>a.rowEnd&&(B=Te(d,B+1,r),T=a.rowStart,B>a.colEnd&&(B=a.colStart));break;case n.Direction.Up:T<a.rowStart&&(B=Te(d,B-1,r),T=a.rowEnd,B<a.colStart&&(B=a.colEnd))}s={rowIndex:T,colIndex:B}}let U=i(s);if(!n.CoordUtils.isRangeWithinRange(U,a)){const T=n.CoordUtils.intersectRanges(U,a);T&&(U=T)}let M={rowStart:Te(c,U.rowStart,n.Direction.Down),colStart:Te(d,U.colStart,n.Direction.Right),rowEnd:Te(c,U.rowEnd,n.Direction.Up),colEnd:Te(d,U.colEnd,n.Direction.Left)};if(M.rowStart!==s.rowIndex||M.colStart!==s.colIndex){switch(r){case n.Direction.Right:t.ranges[p].colStart===M.colStart&&t.ranges[p].colEnd===M.colEnd&&(s.rowIndex=M.rowEnd),s.colIndex=M.colEnd;break;case n.Direction.Left:t.ranges[p].colStart===M.colStart&&t.ranges[p].colEnd===M.colEnd&&(s.rowIndex=M.rowStart),s.rowIndex===M.rowStart?s.colIndex=M.colStart+1:s.colIndex=M.colStart;break;case n.Direction.Down:t.ranges[p].rowStart===M.rowStart&&t.ranges[p].rowEnd===M.rowEnd&&(s.colIndex=M.colEnd),s.rowIndex=M.rowEnd;break;case n.Direction.Up:t.ranges[p].rowStart===M.rowStart&&t.ranges[p].rowEnd===M.rowEnd&&(s.colIndex=M.colStart),s.colIndex===M.colStart?s.rowIndex=M.rowStart+1:s.rowIndex=M.rowStart}return Do({cell:s,ranges:t.ranges,rangeIndex:p},r,i,c,d,f??t)}return{ranges:t.ranges,cell:s,rangeIndex:p}},Ho=(t,r)=>{let i,c=0,d=0;return r.colStart<t.colStart?(i=n.Direction.Left,c=t.colStart-r.colStart,d=r.colStart):r.colEnd>t.colEnd?(i=n.Direction.Right,c=r.colEnd-t.colEnd,d=r.colEnd):r.rowStart<t.rowStart?(i=n.Direction.Up,c=t.rowStart-r.rowStart,d=r.rowStart):r.rowEnd>t.rowEnd&&(i=n.Direction.Down,c=r.rowEnd-t.rowEnd,d=r.rowEnd),{direction:i,amount:c,index:d}},wo=(t,r=!1,i,c)=>{if(!i)return 0;const d=!r,f=d?1:-1;let a=i(d?t:t+1),s=i(d?t+1:t),p=t+(d?2:-1),O=0;for(;(s-a)*f<=0;){if(d&&p-1>c+1||!d&&p+1<c)return O;a=s,s=i(p),p+=f,O++}return O},jo=(t,r,i,c,d)=>{const f={};let a=null,s=null;const p=i.length;for(let O=0;O<p&&i[O]<=d;O++){const U=i[O];if(U<c)continue;const M=a===U?s:r?t.getColOffset(U):t.getRowOffset(U),T=r?t.getColOffset(U+1):t.getRowOffset(U+1);a=U+1,s=T,f[U]=Object.freeze({offset:M,size:T-M,spanIndex:O})}return Object.freeze(f)},No=(t,r,i)=>{const c=t.getColOffset(r.colStart)+(i?.left??0),d=t.getRowOffset(r.rowStart)+(i?.top??0);return{x:c,y:d,width:t.getColOffset(r.colEnd+1)+(i?.right??0)-(i?.left??0)-c,height:t.getRowOffset(r.rowEnd+1)+(i?.bottom??0)-(i?.top??0)-d}},vn=(t,r,i)=>{if(!i)return!1;const c=i.x;if(t<c||t>c+i.width)return!1;const d=i.y;return!(r<d||r>d+i.height)},Io=(t,r=!0)=>`M ${o.ReactUtils.boundPixel(t.left)} ${o.ReactUtils.boundPixel(t.top)} L ${o.ReactUtils.boundPixel(t.right,!0)} ${o.ReactUtils.boundPixel(t.top)} L ${o.ReactUtils.boundPixel(t.right,!0)} ${o.ReactUtils.boundPixel(t.bottom,!0)} L ${o.ReactUtils.boundPixel(t.left)} ${o.ReactUtils.boundPixel(t.bottom,!0)} L ${o.ReactUtils.boundPixel(t.left)} ${o.ReactUtils.boundPixel(t.top)} ${r?"Z":""}`,Po=t=>{const{linePoints:r,bounds:i,pathProps:c,style:d,...f}=t;return ee.jsx("svg",{width:`${o.ReactUtils.boundPixel(i.width,!0)}`,height:`${o.ReactUtils.boundPixel(i.height,!0)}`,viewBox:`0 0 ${o.ReactUtils.boundPixel(i.width,!0)} ${o.ReactUtils.boundPixel(i.height,!0)}`,style:{position:"absolute",left:`${o.ReactUtils.boundPixel(i.x)}px`,top:`${o.ReactUtils.boundPixel(i.y)}px`,width:`${o.ReactUtils.boundPixel(i.width,!0)}px`,height:`${o.ReactUtils.boundPixel(i.height,!0)}px`,pointerEvents:"none",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top, width, height",willChange:"left, top, width, height, stroke-dashoffset",...d},...f,children:ee.jsx("path",{d:`M ${o.ReactUtils.boundPixel(r[0])} ${o.ReactUtils.boundPixel(r[1])} L ${o.ReactUtils.boundPixel(r[2])} ${o.ReactUtils.boundPixel(r[3])}`,fill:"none",vectorEffect:"non-scaling-stroke",stroke:"black",...c})})},en=t=>{const{x:r=0,y:i=0,width:c=0,height:d=0,fill:f,stroke:a,strokeWidth:s=0,strokeDasharray:p,strokeDashoffset:O,clipPath:U,pathBounds:M,pathProps:T,style:B,...te}=t,Z=i,X=r,Me=c,J=d;let P=null;if(f){let G=Io({top:0,left:0,bottom:J,right:Me});M&&(G=G+" "+Io({top:M.y-Z,left:M.x-X,bottom:M.height+M.y-Z,right:M.width+M.x-X})),P=[ee.jsx("path",{d:G,fill:f,stroke:"none",fillRule:"evenodd"},"fill")]}return ee.jsxs("svg",{width:`${o.ReactUtils.boundPixel(c,!0)}`,height:`${o.ReactUtils.boundPixel(d,!0)}`,viewBox:`0 0 ${o.ReactUtils.boundPixel(c,!0)} ${o.ReactUtils.boundPixel(d,!0)}`,preserveAspectRatio:"none",style:{position:"absolute",left:`${o.ReactUtils.boundPixel(r)}px`,top:`${o.ReactUtils.boundPixel(i)}px`,pointerEvents:"none",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top, width, height",willChange:"left, top, width, height, stroke-dashoffset",boxShadow:"rgb(60 64 67 / 5%) 0px 1px 4px 2px, rgb(255 255 255 / 15%) 0px 0px 2px 1px",overflow:"visible",...B},...te,children:[P,ee.jsx("path",{d:Io({top:0,left:0,right:Me,bottom:J}),fill:"none",strokeDasharray:p,strokeDashoffset:O,stroke:a,vectorEffect:"non-scaling-stroke",strokeWidth:s,...T})]})},qo=t=>{const{key:r,...i}=t;return ee.jsx(Oo,{...i},r)},Oo=l.memo(t=>{const{stroke:r,fill:i,x:c=0,y:d=0,width:f=0,height:a=0,style:s,isAnimatedStroke:p,animatedStrokeProps:O,range:U,cell:M,...T}=t,B=p||!!O,te={name:"walking-offset",dashGap:2,speed:50,dashLength:8,...O};let Z=te.dashGap+te.dashLength;const X=te.speed*Z,Me=o.useId().replaceAll(":",""),J=`${te.name}-${Me}`;let P;return l.useEffect(()=>{if(!B)return;const G=`@keyframes ${J} {
7
+ */Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("react/jsx-runtime"),n=require("@sheetxl/utils-react"),l=require("react"),o=require("@sheetxl/utils"),Jn=require("react-dom"),Yt=({itemType:t,index:r,itemSize:i,instanceProps:c,scale:u=1})=>{let f,a,s;t==="column"?(f=c.columnMetadataMap,a=c.lastMeasuredColumnIndex,s=c.recalcColumnIndices):(f=c.rowMetadataMap,a=c.lastMeasuredRowIndex,s=c.recalcRowIndices);const p=s.length>0;if(r>a){let O=0;if(a>=0){const P=f[a];O=P.offset+P.size}for(let P=a+1;P<=r;P++){let M=p?s.includes(P)?i(P)*u:f[P]?.size||i(P)*u:i(P)*u;f[P]={offset:O,size:M},O+=M}t==="column"?c.lastMeasuredColumnIndex=r:c.lastMeasuredRowIndex=r}return f[r],f[r]},Bn=({itemType:t,itemSize:r,itemCount:i,instanceProps:c,offset:u,scale:f})=>{let a,s;t==="column"?(a=c.columnMetadataMap,s=c.lastMeasuredColumnIndex):(a=c.rowMetadataMap,s=c.lastMeasuredRowIndex);let p=0;return p=(s>0?a[s].offset:0)>=u?Qn({itemType:t,itemSize:r,instanceProps:c,high:s,low:0,offset:u,scale:f}):wo({itemType:t,itemSize:r,itemCount:i,instanceProps:c,index:Math.max(0,s),offset:u,scale:f}),p=Math.min(p,i),p},Qn=({itemType:t,itemSize:r,instanceProps:i,high:c,low:u,offset:f,scale:a})=>{for(;u<=c;){const s=u+Math.floor((c-u)/2),p=Yt({itemType:t,itemSize:r,index:s,instanceProps:i,scale:a}).offset;if(p===f)return s;p<f?u=s+1:p>f&&(c=s-1)}return u>0?u-1:0},wo=({itemType:t,itemSize:r,itemCount:i,instanceProps:c,index:u,offset:f,scale:a})=>{let s=1;for(;u<i&&Yt({itemType:t,itemSize:r,index:u,instanceProps:c,scale:a}).offset<f;)u+=s,s*=2;return Qn({itemType:t,itemSize:r,instanceProps:c,high:Math.min(u,i-1),low:Math.floor(u/2),offset:f,scale:a})},eo=t=>{const{rowCount:r,columnCount:i,defaultRowHeight:c,getRowHeight:u,defaultColumnWidth:f,getColumnWidth:a}=t||{},s=l.useRef({columnMetadataMap:{},rowMetadataMap:{},lastMeasuredColumnIndex:-1,lastMeasuredRowIndex:-1,recalcColumnIndices:[],recalcRowIndices:[]}),p=n.useCallbackRef(k=>Bn({itemType:"row",itemCount:r,itemSize:u??(()=>c??20),instanceProps:s.current,offset:k}),[r,u,c]),O=n.useCallbackRef(k=>k===-1?0:Yt({itemType:"row",index:k,itemSize:u??(()=>c??20),instanceProps:s.current}).offset,[u,c]),P=n.useCallbackRef(k=>Yt({itemType:"row",index:k,itemSize:u??(()=>c??20),instanceProps:s.current}).size,[u,c]),M=n.useCallbackRef(k=>Bn({itemType:"column",itemCount:i,itemSize:a??(()=>f??75),instanceProps:s.current,offset:k}),[i,a,f]),U=n.useCallbackRef(k=>k===-1?0:Yt({itemType:"column",index:k,itemSize:a??(()=>f??75),instanceProps:s.current}).offset,[a,f]),K=n.useCallbackRef(k=>Yt({itemType:"column",index:k,itemSize:a??(()=>f??75),instanceProps:s.current}).size,[a,f]),[ee,Z]=l.useReducer(k=>k+1,0),_=()=>({getRowOffset:O,getColOffset:U,getRowIndex:p,getColIndex:M}),[Me,re]=l.useState(()=>t?_():null);return l.useEffect(()=>{re(t?_():null)},[ee,r,i,f,c,P,K]),Me},On="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ~`!@#$%^&*()-_=+[{]};:'\",<.>/?|\\",Fn=t=>{if(!t)return null;if(t.eventType==="start")return{type:t.eventType};if(t.eventType==="submit")return{type:t.eventType};if(t.eventType==="cancel")return{type:t.eventType};if(t.eventType==="keyboard")return{type:t.eventType,key:t.event.key};if(t.eventType==="pointer")return{type:t.eventType};if(t.eventType==="coordsChange"){const r={type:t.eventType};return t.activeCoords&&(r.activeCoords=t.activeCoords),r}return{type:t.eventType??"unknown"}},xo=t=>!0,po=t=>!!t&&!(t.ctrlKey||t.metaKey||t.altKey||t.isComposing)&&(!(t.shiftKey||t.key!=="F2"&&t.key!==" "&&t.key!=="Backspace")||(!t.shiftKey||t.key!==" ")&&On.indexOf(t.key)!==-1),mo=t=>!!t&&t.type==="dblclick"&&{editMode:!0},Co=t=>{const{session:r,refLatestCoords:i,handleSubmitEdit:c,handleCancelEdit:u,cellBounds:f,isInBounds:a,getCellEditor:s,propsEditor:p,borderStrokeFill:O="rgb(33, 115, 70)",borderStrokeWidth:P=2,alignment:M=n.HorizontalAlignment.Left,style:U,...K}=t,ee=l.useRef(null),Z=l.useRef(null),[_,Me]=l.useState(!1),re=r.coords,k=l.useCallback(async se=>{if(ee.current?.getBoundingClientRect()){if(se.eventType==="keyboard"){const A=se.event,C=new KeyboardEvent(A.type,{bubbles:!0,cancelable:!0,view:window,key:A.key,code:A.code,location:A.location,repeat:A.repeat,isComposing:A.isComposing,charCode:A.charCode,keyCode:A.keyCode,which:A.which,ctrlKey:A.ctrlKey,shiftKey:A.shiftKey,altKey:A.altKey,metaKey:A.metaKey});C.isSynthetic=!0,C.key,Z.current?.dispatchEvent(C)}else se.eventType==="pointer"||console.warn("unsupported event type",se);await new Promise(A=>requestAnimationFrame(A))}},[]);l.useEffect(()=>{const se=Z.current;return Me(!0),Z.current.startEdit?.(r.startEvent),(async()=>{r.editorRefs.push(se),r.editorRefsDispatchEditorEvent.push(k);const we=[...r.events];for(let A=0;A<we.length;A++)await k(we[A]);r.onMount(se)})(),()=>{const we=r.editorRefs.indexOf(se);we!==-1&&r.editorRefs.splice(we,1),r.onUnmount(se)}},[]);const X=l.useCallback(()=>c(r),[]),ge=l.useCallback(()=>{u(r)},[]),F=i.current&&o.CoordUtils.isEqualCells(i.current,re),fe=a&&F&&_,Le=s({autoFocus:!!r.startEvent?.autoFocus,...p,onSubmitEdit:X,onCancelEdit:ge,ref:Z},re),be=f.x+n.ReactUtils.boundPixel(-P/2),ze=n.ReactUtils.boundPixel(f.width+P/2,!0);return Q.jsx("div",{tabIndex:0,ref:ee,style:{background:void 0,...U,opacity:fe?U?.opacity??1:0,pointerEvents:"auto",position:"absolute",boxSizing:"border-box",top:`${f.y+n.ReactUtils.boundPixel(-P/2)}px`,height:n.ReactUtils.boundPixel(f.height+P/2,!0),left:`${be}px`,width:ze},...K,children:Q.jsx("div",{className:"editor-container",style:{position:"absolute",boxSizing:"border-box",left:`${n.ReactUtils.boundPixel(1)}px`,top:`${n.ReactUtils.boundPixel(1)}px`,width:n.ReactUtils.boundPixel(f.width-2,!0),height:n.ReactUtils.boundPixel(f.height-2,!0),outline:`${P}px ${O} solid`,boxShadow:"rgba(60,64,67,.35) 2px 2px 6px 3px",maxHeight:"100%",overflow:"hidden",display:"flex"},children:Le})})},So=Object.freeze({once:!0}),Oe=(t,r,i)=>{if(!t)return r;let c=r;const u=i===o.Direction.Right||i===o.Direction.Down;for(;;){const f=t(c,!u);if(f===0)return c;u?c+=f:c-=f}},un=(t,r,i)=>{const c=[];let u=r;for(;u<=i;){const f=Math.max(0,t(u));f===0?(c.push(u),u++):u+=f}return c},bo=(t,r,i,c,u,f)=>{if(!r)return f;let{rowIndex:a,colIndex:s}=t;switch(c){case o.Direction.Down:{a=Oe(i,Math.min(a+1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&a<f;)a=Oe(i,Math.min(++a,f),c),p=r({rowIndex:a,colIndex:s});return a}case o.Direction.Up:{a=Oe(i,Math.max(a-1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&a>f;)a=Oe(i,Math.max(--a,f),c),p=r({rowIndex:a,colIndex:s});return a}case o.Direction.Right:{s=Oe(i,Math.min(s+1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&s<f;)s=Oe(i,Math.min(++s,f),c),p=r({rowIndex:a,colIndex:s});return s}case o.Direction.Left:{s=Oe(i,Math.max(s-1,f),c);let p=r({rowIndex:a,colIndex:s});for(;!p&&s>f;)s=Oe(i,Math.max(--s,f),c),p=r({rowIndex:a,colIndex:s});return s}default:return f}},vo=(t,r=()=>!0,i,c,u,f)=>{let{rowIndex:a,colIndex:s}=t;switch(c){case o.Direction.Down:{a=Oe(i,Math.min(a+1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&a<f;)a=Oe(i,Math.min(++a,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?a:a-1}case o.Direction.Up:{a=Oe(i,Math.max(a-1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&a>f;)a=Oe(i,Math.max(--a,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?a:a+1}case o.Direction.Right:{s=Oe(i,Math.min(s+1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&s<f;)s=Oe(i,Math.min(++s,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?s:s-1}case o.Direction.Left:{s=Oe(i,Math.max(s-1,f),c);let p=r?.({rowIndex:a,colIndex:s});for(;p&&s>f;)s=Oe(i,Math.max(--s,f),c),p=r?.({rowIndex:a,colIndex:s});return r?.({rowIndex:a,colIndex:s})?s:s+1}default:return null}},yo=(t,r,i,c,u,f)=>{if(!r)return f;let a,{rowIndex:s,colIndex:p}=t;c===o.Direction.Down?a={rowIndex:s+1,colIndex:p}:c===o.Direction.Up?a={rowIndex:s-1,colIndex:p}:c===o.Direction.Right?a={rowIndex:s,colIndex:p+1}:c===o.Direction.Left&&(a={rowIndex:s,colIndex:p-1});const O=r(t),P=r(a);var M,U;return(U=P,!(M=O)&&!U||!M&&U||M&&!U?bo:vo)(t,r,i,c,!1,f)??f},Vn=(t,r)=>`${t}:${r}`,Wn=(t,r,i,c,u,f)=>{if(i-r>=u-c)return c;let a=c;return t==="nearest"&&(c-r>0?t="start":i-u>0&&(t="end")),t==="start"?a=r:t==="end"?a=i-(u-c):t==="center"&&(a=r+(i-r)/2-(u-c)/2),a<c?Math.max(0,a):a>c?Math.min(a,f-(u-c)):void 0},jn=(t,r,i,c)=>(console.log("todo: implement convertToVisibleRanges"),t),Dn=(t,r=o.Direction.Right,i,c,u,f=null)=>{if(f&&o.CoordUtils.isEqualSelectionCoords(f,t))return t;const a=t.ranges[t.rangeIndex];if(!o.CoordUtils.isRangesIntersect({rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},a))return t;let s={...t.cell},p=t.rangeIndex;switch(r){case o.Direction.Right:s.colIndex=Oe(u,s.colIndex+1,r);break;case o.Direction.Left:s.colIndex=Oe(u,s.colIndex-1,r);break;case o.Direction.Down:s.rowIndex=Oe(c,s.rowIndex+1,r);break;case o.Direction.Up:s.rowIndex=Oe(c,s.rowIndex-1,r)}const O=U=>{if(U){p=t.rangeIndex>=t.ranges.length-1?0:t.rangeIndex+1;const K=t.ranges[p];s={colIndex:K.colStart,rowIndex:K.rowStart}}else{p=t.rangeIndex<=0?t.ranges.length-1:t.rangeIndex-1;const K=t.ranges[p];s={colIndex:K.colEnd,rowIndex:K.rowEnd}}};if(r===o.Direction.Right&&s.colIndex>a.colEnd&&s.rowIndex===a.rowEnd)O(!0);else if(r===o.Direction.Left&&s.colIndex<a.colStart&&s.rowIndex===a.rowStart)O(!1);else if(r===o.Direction.Down&&s.colIndex===a.colEnd&&s.rowIndex>a.rowEnd)O(!0);else if(r===o.Direction.Up&&s.colIndex===a.colStart&&s.rowIndex<a.rowStart)O(!1);else{let U=s.rowIndex,K=s.colIndex;switch(r){case o.Direction.Right:K>a.colEnd&&(U=Oe(c,U+1,r),K=a.colStart,U>a.rowEnd&&(U=a.rowStart));break;case o.Direction.Left:K<a.colStart&&(U=Oe(c,U-1,r),K=a.colEnd,U<a.rowStart&&(U=a.rowEnd));break;case o.Direction.Down:U>a.rowEnd&&(K=Oe(u,K+1,r),U=a.rowStart,K>a.colEnd&&(K=a.colStart));break;case o.Direction.Up:U<a.rowStart&&(K=Oe(u,K-1,r),U=a.rowEnd,K<a.colStart&&(K=a.colEnd))}s={rowIndex:U,colIndex:K}}let P=i(s);if(!o.CoordUtils.isRangeWithinRange(P,a)){const U=o.CoordUtils.intersectRanges(P,a);U&&(P=U)}let M={rowStart:Oe(c,P.rowStart,o.Direction.Down),colStart:Oe(u,P.colStart,o.Direction.Right),rowEnd:Oe(c,P.rowEnd,o.Direction.Up),colEnd:Oe(u,P.colEnd,o.Direction.Left)};if(M.rowStart!==s.rowIndex||M.colStart!==s.colIndex){switch(r){case o.Direction.Right:t.ranges[p].colStart===M.colStart&&t.ranges[p].colEnd===M.colEnd&&(s.rowIndex=M.rowEnd),s.colIndex=M.colEnd;break;case o.Direction.Left:t.ranges[p].colStart===M.colStart&&t.ranges[p].colEnd===M.colEnd&&(s.rowIndex=M.rowStart),s.rowIndex===M.rowStart?s.colIndex=M.colStart+1:s.colIndex=M.colStart;break;case o.Direction.Down:t.ranges[p].rowStart===M.rowStart&&t.ranges[p].rowEnd===M.rowEnd&&(s.colIndex=M.colEnd),s.rowIndex=M.rowEnd;break;case o.Direction.Up:t.ranges[p].rowStart===M.rowStart&&t.ranges[p].rowEnd===M.rowEnd&&(s.colIndex=M.colStart),s.colIndex===M.colStart?s.rowIndex=M.rowStart+1:s.rowIndex=M.rowStart}return Dn({cell:s,ranges:t.ranges,rangeIndex:p},r,i,c,u,f??t)}return{ranges:t.ranges,cell:s,rangeIndex:p}},Hn=(t,r)=>{let i,c=0,u=0;return r.colStart<t.colStart?(i=o.Direction.Left,c=t.colStart-r.colStart,u=r.colStart):r.colEnd>t.colEnd?(i=o.Direction.Right,c=r.colEnd-t.colEnd,u=r.colEnd):r.rowStart<t.rowStart?(i=o.Direction.Up,c=t.rowStart-r.rowStart,u=r.rowStart):r.rowEnd>t.rowEnd&&(i=o.Direction.Down,c=r.rowEnd-t.rowEnd,u=r.rowEnd),{direction:i,amount:c,index:u}},wn=(t,r=!1,i,c)=>{if(!i)return 0;const u=!r,f=u?1:-1;let a=i(u?t:t+1),s=i(u?t+1:t),p=t+(u?2:-1),O=0;for(;(s-a)*f<=0;){if(u&&p-1>c+1||!u&&p+1<c)return O;a=s,s=i(p),p+=f,O++}return O},Nn=(t,r,i,c,u)=>{const f={};let a=null,s=null;const p=i.length;for(let O=0;O<p&&i[O]<=u;O++){const P=i[O];if(P<c)continue;const M=a===P?s:r?t.getColOffset(P):t.getRowOffset(P),U=r?t.getColOffset(P+1):t.getRowOffset(P+1);a=P+1,s=U,f[P]=Object.freeze({offset:M,size:U-M,spanIndex:O})}return Object.freeze(f)},qn=(t,r,i)=>{const c=t.getColOffset(r.colStart)+(i?.left??0),u=t.getRowOffset(r.rowStart)+(i?.top??0);return{x:c,y:u,width:t.getColOffset(r.colEnd+1)+(i?.right??0)-(i?.left??0)-c,height:t.getRowOffset(r.rowEnd+1)+(i?.bottom??0)-(i?.top??0)-u}},Ro=(t,r,i)=>{if(!i)return!1;const c=i.x;if(t<c||t>c+i.width)return!1;const u=i.y;return!(r<u||r>u+i.height)},In=(t,r=!0)=>`M ${n.ReactUtils.boundPixel(t.left)} ${n.ReactUtils.boundPixel(t.top)} L ${n.ReactUtils.boundPixel(t.right,!0)} ${n.ReactUtils.boundPixel(t.top)} L ${n.ReactUtils.boundPixel(t.right,!0)} ${n.ReactUtils.boundPixel(t.bottom,!0)} L ${n.ReactUtils.boundPixel(t.left)} ${n.ReactUtils.boundPixel(t.bottom,!0)} L ${n.ReactUtils.boundPixel(t.left)} ${n.ReactUtils.boundPixel(t.top)} ${r?"Z":""}`,Pn=t=>{const{linePoints:r,bounds:i,propsPath:c,style:u,...f}=t;return Q.jsx("svg",{width:`${n.ReactUtils.boundPixel(i.width,!0)}`,height:`${n.ReactUtils.boundPixel(i.height,!0)}`,viewBox:`0 0 ${n.ReactUtils.boundPixel(i.width,!0)} ${n.ReactUtils.boundPixel(i.height,!0)}`,style:{position:"absolute",left:`${n.ReactUtils.boundPixel(i.x)}px`,top:`${n.ReactUtils.boundPixel(i.y)}px`,width:`${n.ReactUtils.boundPixel(i.width,!0)}px`,height:`${n.ReactUtils.boundPixel(i.height,!0)}px`,pointerEvents:"none",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top, width, height",willChange:"left, top, width, height, stroke-dashoffset",...u},...f,children:Q.jsx("path",{d:`M ${n.ReactUtils.boundPixel(r[0])} ${n.ReactUtils.boundPixel(r[1])} L ${n.ReactUtils.boundPixel(r[2])} ${n.ReactUtils.boundPixel(r[3])}`,fill:"none",vectorEffect:"non-scaling-stroke",stroke:"black",...c})})},to=t=>{const{x:r=0,y:i=0,width:c=0,height:u=0,fill:f,stroke:a,strokeWidth:s=0,strokeDasharray:p,strokeDashoffset:O,clipPath:P,boundsPath:M,propsPath:U,style:K,...ee}=t,Z=i,_=r,Me=c,re=u;let k=null;if(f){let X=In({top:0,left:0,bottom:re,right:Me});M&&(X=X+" "+In({top:M.y-Z,left:M.x-_,bottom:M.height+M.y-Z,right:M.width+M.x-_})),k=[Q.jsx("path",{d:X,fill:f,stroke:"none",fillRule:"evenodd"},"fill")]}return Q.jsxs("svg",{width:`${n.ReactUtils.boundPixel(c,!0)}`,height:`${n.ReactUtils.boundPixel(u,!0)}`,viewBox:`0 0 ${n.ReactUtils.boundPixel(c,!0)} ${n.ReactUtils.boundPixel(u,!0)}`,preserveAspectRatio:"none",style:{position:"absolute",left:`${n.ReactUtils.boundPixel(r)}px`,top:`${n.ReactUtils.boundPixel(i)}px`,pointerEvents:"none",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top, width, height",willChange:"left, top, width, height, stroke-dashoffset",boxShadow:"rgb(60 64 67 / 5%) 0px 1px 4px 2px, rgb(255 255 255 / 15%) 0px 0px 2px 1px",overflow:"visible",...K},...ee,children:[k,Q.jsx("path",{d:In({top:0,left:0,right:Me,bottom:re}),fill:"none",strokeDasharray:p,strokeDashoffset:O,stroke:a,vectorEffect:"non-scaling-stroke",strokeWidth:s,...U})]})},Yn=t=>{const{key:r,...i}=t;return Q.jsx(Ln,{...i},r)},Ln=l.memo(t=>{const{stroke:r,fill:i,x:c=0,y:u=0,width:f=0,height:a=0,style:s,isAnimatedStroke:p,propsAnimatedStroke:O,range:P,cell:M,...U}=t,K=p||!!O,ee={name:"walking-offset",dashGap:2,speed:50,dashLength:8,...O};let Z=ee.dashGap+ee.dashLength;const _=ee.speed*Z,Me=n.useId().replaceAll(":",""),re=`${ee.name}-${Me}`;let k;return l.useEffect(()=>{if(!K)return;const X=`@keyframes ${re} {
8
8
  to {
9
9
  stroke-dashoffset: 0px;
10
10
  }
11
- }`,we=document.createElement("style");return we.appendChild(document.createTextNode(G)),document.head.appendChild(we),we.sheet.insertRule(G,0),()=>{document.head.removeChild(we)}},[B]),B&&(P={strokeDasharray:`${te.dashLength}px ${te.dashGap}px`,strokeDashoffset:`${Z}px`,animation:`${J} ${X}ms linear infinite`,willChange:"stroke-dashoffset"}),ee.jsx(en,{x:c,y:d,width:f,height:a,stroke:r,fill:i,shapeRendering:"crispEdges",style:{...P,...s},...T})});function tn(t){var r,i,c="";if(typeof t=="string"||typeof t=="number")c+=t;else if(typeof t=="object")if(Array.isArray(t)){var d=t.length;for(r=0;r<d;r++)t[r]&&(i=tn(t[r]))&&(c&&(c+=" "),c+=i)}else for(i in t)t[i]&&(c&&(c+=" "),c+=i);return c}function Vt(){for(var t,r,i=0,c="",d=arguments.length;i<d;i++)(t=arguments[i])&&(r=tn(t))&&(c&&(c+=" "),c+=r);return c}Oo.displayName="Selection";const Uo=l.memo(l.forwardRef((t,r)=>{const{x:i=0,y:c=0,borderWidth:d=1,size:f=6,borderStroke:a,corner:s,style:p,className:O,background:U,ref:M,...T}=t;if(i===0||c===0)return null;let B=!0,te=!0,Z=!0,X=!0;switch(s){case"tl":B=!1,te=!1;break;case"bl":B=!1,X=!1;break;case"br":Z=!1,X=!1;break;case"tr":te=!1,Z=!1}return ee.jsx("div",{className:Vt("fill-handle",O),style:{position:"absolute",left:i-(f+(B?d:0))/2,top:c-(f+(te?d:0))/2,width:f,height:f,borderLeft:B?`${d}px ${a}`:void 0,borderTop:te?`${d}px ${a}`:void 0,borderRight:Z?`${d}px ${a}`:void 0,borderBottom:X?`${d}px ${a}`:void 0,background:U,cursor:"crosshair",pointerEvents:"all",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top",willChange:"left, top",...p},tabIndex:-1,...T})}));function ko(t,r){if(typeof t=="function")return t(r);t&&(t.current=r)}Uo.displayName="FillHandle";var yn=parseInt(l.version.split(".")[0],10)>=19?function(t){return r=>{const i=[];for(const c of t){const d=ko(c,r),f=typeof d=="function";i.push(f?d:()=>ko(c,null))}return()=>{for(const c of i)c()}}}:function(t){return r=>{for(const i of t)ko(i,r)}};const Rn=o.ReactUtils.detectIt().supportsTouchEvents,fo=l.memo(l.forwardRef((t,r)=>{const{range:i,view:c,anchor:d,borderStroke:f="var(--sxl-app-color-primary, rgb(33, 115, 70))",background:a="var(--sxl-app-color-background, white)",borderWidth:s=3,size:p=22,style:O,className:U,selectionTouchPointerHandler:M,onTouchSelectStart:T,onTouchSelectEnd:B,currentTouchAnchor:te,scrollableElement:Z,scrollableRoot:X,...Me}=t;if(!Rn)return null;const J=o.useCallbackRef(T,[T]),P=o.useCallbackRef(B,[B]),{bounds:G,coordsPivot:we,key:K}=l.useMemo(()=>{if(!i||!c)return null;let me=null,q=null;switch(d){case"tl":me={colIndex:i.colEnd,rowIndex:i.rowEnd},q={colIndex:i.colStart,rowIndex:i.rowStart};break;case"br":me={colIndex:i.colStart,rowIndex:i.rowStart},q={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"t":case"l":me={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"b":me={colIndex:i.colStart,rowIndex:i.rowStart};break;case"r":me={colIndex:i.colStart,rowIndex:i.rowEnd}}let L=c.getRangeCoordsBounds(q?{rowStart:q.rowIndex,colStart:q.colIndex,rowEnd:q.rowIndex,colEnd:q.colIndex}:i);const j=c.getBounds(),St=c.getViewportSize(),xt=j.x,ct=j.y,rt=St.width,se=St.height;switch(d){case"tl":break;case"br":L.x=L.x+L.width,L.y=L.y+L.height;break;case"t":L.x=rt/2-xt;break;case"b":L.x=rt/2-xt,L.y=L.y+L.height;break;case"l":L.y=se/2-ct;break;case"r":L.x=L.x+L.width,L.y=se/2-ct}const Pt=c.toClipBounds(L,0);return!Pt||Pt.width<=0||Pt.height<=0||L.x<0||L.y<0||L.x>rt||L.y>se?{bounds:null,coordsAnchor:null,coordsPivot:null,key:null}:{bounds:L,coordsAnchor:null,coordsPivot:me,key:"touchSelect-"+c.getAnchor()+"-"+d}},[i,c,d]),ge=l.useRef(null),Le=l.useMemo(()=>{const me=q=>d==="t"||d==="b"?{...q,colIndex:void 0}:d==="l"||d==="r"?{...q,rowIndex:void 0}:q;return{processTouch:!0,consumeTouch:!0,onPointerDown:(q,L)=>{const j=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return ge.current={coordsPivot:we},J?.(d),M.onSelectionPointerDown(q,L,c,j,we,!1,!0)},onPointerMoveOrWait:(q,L,j)=>{const St=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return M.onSelectionPointerMoveOrWait(q,L,j,c,St,ge.current?.coordsPivot,!0,!0)},onPointerUp:(q,L,j)=>(ge.current=null,P?.(d),M.onPointerUp(q,L,j))}},[M,i,c,d]),ye=o.useSynchronizedPointerHandler(Le),[Oe,{y:ce,x:pe}]=o.useAnimatedMeasure(),A=l.useRef(null),{getPortalContainer:C,isFullscreen:$e}=o.useFullscreenPortal(),[Ve,_]=l.useState(null);return l.useEffect(()=>{const me=A.current?.getBoundingClientRect();if(!me||!G)return void _(null);let q=0,L=0,j=Z;for(;j;)q+=j.scrollLeft,L+=j.scrollTop,j=X&&j===X.parentElement?null:j.parentElement;_(Zo.createPortal(ee.jsx("div",{className:Vt("touch-select-handle",U),ref:r,style:{position:"absolute",left:q+(me?.x??0)-(p+s)/2,top:L+(me?.y??0)-(p+s)/2,width:p,height:p,borderWidth:`${s}px`,border:f,borderRadius:"50%",background:a,boxShadow:`0 0 0 1.5px ${a}`,cursor:"grab",pointerEvents:"all",opacity:te?0:1,transitionDuration:"160ms",transitionProperty:"opacity",...O},tabIndex:-1,onPointerDown:ye,...Me}),X??C(),K))},[ce,pe,G?.x,G?.y,G?.width,G?.height,U,te,a,p,s,f,Z,$e]),G?ee.jsxs(ee.Fragment,{children:[ee.jsx("div",{ref:yn([Oe,A]),style:{position:"absolute",left:G.x,top:G.y,opacity:0}}),Ve]}):null}));fo.displayName="TouchSelectHandle";const It=-10,En=Object.freeze({rowStart:0,colStart:0,rowEnd:0,colEnd:0}),on=Object.freeze({colIndex:0,rowIndex:0}),To=Object.freeze([]),yt=t=>{if(t&&t.cell&&t.ranges&&t.rangeIndex>-1&&t.rangeIndex<=t.ranges.length)return t;const r={cell:null,ranges:t?.ranges??To};return r.rangeIndex=t?.rangeIndex??r.ranges.length-1,r.cell=t?.cell,!r.cell&&r.ranges.length>0&&(r.cell={rowIndex:r.ranges[r.rangeIndex].rowStart,colIndex:r.ranges[r.rangeIndex].colStart}),r.cell||(r.cell=on),n.CoordUtils.isEqualSelectionCoords(r,t)?t:r},ho=(t,r,i)=>{const c=t.getVisibleRangeCoords(),d=t.getScrollOrientation();!d.horizontal&&(r.colIndex>c.colEnd||r.colIndex<c.colStart)&&(r={...r,colIndex:r.colIndex>c.colEnd?c.colEnd+1:c.colEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),!d.vertical&&(r.rowIndex>c.rowEnd||r.rowIndex<c.rowStart)&&(r={...r,rowIndex:r.rowIndex>c.rowEnd?c.rowEnd+1:c.rowEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),t.scrollCellCoordsIntoView(r)},In=()=>!1;function go(t,r){if(!t)throw new Error("Invariant failed")}const Yo={"sheetxl-grid":"_sheetxl-grid_h9wwa_7"},kn=Object.freeze({top:0,left:0}),Mn=Object.freeze({bottom:-4,right:-4}),Dn=Object.freeze({horizontal:!0,vertical:!0}),Xo=[n.AnchorLocation.TopLeft,n.AnchorLocation.Top,n.AnchorLocation.Left,n.AnchorLocation.Center],zt=3e3,Mo={},zo=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,rowCount:d=1,columnCount:f=1,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O,layout:U,onViewportScroll:M,onImmediateScroll:T,showGridLines:B=!0,gridLineColor:te="rgb(224, 224, 224)",gridLineRowsProps:Z,gridLineColumnsProps:X,clipCells:Me=!0,cursor:J,freezeLeft:P=0,freezeTop:G=0,freezeLeftProps:we,freezeTopProps:K,cellRenderer:ge,onViewportChange:Le,onFirstRender:ye,overlayRenderer:Oe,overlayProps:ce,overlays:pe,overlaysProps:A,allowOverlaysOverflow:C=!1,stageProps:$e,stageWrapper:Ve=null,hiddenRowsAt:_,hiddenColumnsAt:me,hiddenCellAt:q,getVisibleCells:L,zoom:j=1,enableMouseWheel:St=!0,onWheelScroll:xt,getCellCoordsAsRangeCoords:ct=n.CoordUtils.cellToRange,scrollPoint:rt=kn,style:se={},...Pt}=t;go(ge),go(!t?.children);const D=o.useCallbackRef(T,[T]),R=o.useCallbackRef(Le,[Le]),be=o.useCallbackRef(M,[M]),oe=o.useCallbackRef(xt,[xt]),ue=o.useCallbackRef(ye,[ye]),ze=l.useRef(null),Je=l.useRef(null),mt=l.useRef(null),[Qe,Tt]=l.useReducer(w=>w+1,0),[st,b]=l.useState({left:rt?.left??0,top:rt?.top??0,horizontalScrollDirection:null,verticalScrollDirection:null}),ne=l.useRef(null),Ae=l.useRef(st),{top:lt,left:qe,verticalScrollDirection:Ht,horizontalScrollDirection:$t}=st,bt=l.useRef(!1),Xt=Qo({rowCount:d,columnCount:f,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O}),At=l.useRef(null),Re=l.useMemo(()=>{const w=U||Xt;return At.current=null,{getColOffset:S=>w.getColOffset(S)*j,getColIndex:S=>w.getColIndex(S/j),getRowOffset:S=>w.getRowOffset(S)*j,getRowIndex:S=>w.getRowIndex(S/j)}},[Xt,U,j]),Ut=(w,S,E)=>{const v=(S?.left??0)+0,y=(S?.top??0)+0;return{getColOffset:z=>w.getColOffset(z)-v,getColIndex:z=>w.getColIndex(z+v),getRowOffset:z=>w.getRowOffset(z)-y,getRowIndex:z=>w.getRowIndex(z+y)}},ut=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getRowOffset,S?0:d),[d,Re?.getRowOffset]),kt=o.useCallbackRef(_??ut,[_]),eo=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getColOffset,S?f:0),[f,Re?.getColOffset]),jt=o.useCallbackRef(me??eo,[me]),He=l.useMemo(()=>Math.min(i??800,Re.getColOffset(f)),[Re.getColOffset,f,i]),Be=l.useMemo(()=>Math.min(c??600,Re.getRowOffset(d)),[Re.getRowOffset,d,c]),Ft=l.useCallback(w=>{n.CommonUtils.canUseDOM&&setTimeout(()=>{ze.current?.focus({preventScroll:!0,...w})},0)},[]),ht=l.useCallback(w=>ze.current?.contains(w)||Je.current?.contains(w),[]);l.useEffect(()=>{bt.current&&(ne.current&&ne.current.left!==Ae.current?.left&&ne.current.top!==Ae.current?.top||(ne.current=null,be?.({left:qe,top:lt})))},[qe,lt]);const Lt=o.useCallbackRef(()=>({top:lt,left:qe}),[lt,qe]),ve=l.useMemo(()=>{const w=[];let S=0,E=0;typeof G=="number"?S=G:(S=G.index??0,E=(G.scrollOffset??0)*j);const v=E,y=Re.getRowOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{top:E+Re.getRowOffset(0)}),Pe=Re.getRowIndex(v),Ne=Re.getRowIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(kt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,Be-z),re=Ut(Re,{top:lt+z}),ae=re.getRowIndex(0),F=re.getRowIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:d-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(kt,ae,F)),Se),layout:re,maxVirtualBounds:Re.getRowOffset(d),scrollOffset:lt,freezeOffset:(S>0?Re.getRowOffset(S):0)-E},w},[Re.getRowIndex,Re.getRowOffset,kt,Be,d,G,lt,j]),je=l.useMemo(()=>{const w=[];let S=0,E=0;typeof P=="number"?S=P:(S=P.index??0,E=(P.scrollOffset??0)*j);const v=E,y=Re.getColOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{left:E+Re.getColOffset(0)}),Pe=Re.getColIndex(v),Ne=Re.getColIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(jt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,He-z),re=Ut(Re,{left:qe+z}),ae=re.getColIndex(0),F=re.getColIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:f-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(jt,ae,F)),Se),layout:re,maxVirtualBounds:Re.getColOffset(f),scrollOffset:qe,freezeOffset:(S>0?Re.getColOffset(S):0)-E},w},[Re.getColIndex,Re.getColOffset,jt,He,f,P,qe,j]),it=l.useRef({}),pt=l.useRef([]),Ce=l.useMemo(()=>{let w={};const S=(v,y,z,he,re)=>{const ae={vertical:he?.vertical||!1,horizontal:he?.horizontal||!1};if(v>=je.length||y>=ve.length)return null;const F={rowStart:ve[y].minIndex,colStart:je[v].minIndex,rowEnd:ve[y].maxIndex,colEnd:je[v].maxIndex};if(F.rowStart>F.rowEnd||F.colStart>F.colEnd)return null;const Se={getColIndex:Q=>je[v].layout.getColIndex(Q),getColOffset:Q=>je[v].layout.getColOffset(Q),getRowIndex:Q=>ve[y].layout.getRowIndex(Q),getRowOffset:Q=>ve[y].layout.getRowOffset(Q)},Ke=Object.freeze({left:re?.left??0,top:re?.top??0,right:re?.right??0,bottom:re?.bottom??0}),Pe=Object.freeze({x:je[v].minBounds,y:ve[y].minBounds,width:je[v].maxBounds,height:ve[y].maxBounds}),Ne=(Q,We)=>No(Se,Q??F,We),Ee={width:je[v].maxVirtualBounds,height:ve[y].maxVirtualBounds},le={left:je[v].scrollOffset,top:ve[y].scrollOffset},et={left:je[v].freezeOffset,top:ve[y].freezeOffset},Ye={width:He,height:Be};let Ue=null,Xe=null;const ft=(et.top+(he.vertical?le.top:0))/j,Fe=(et.left+(he.horizontal?le.left:0))/j;return{getStage:()=>ze.current??null,getVisibleRangeCoords:()=>F,toClipBounds:(Q,We)=>{let at,Ie=0;return We===void 0||typeof We=="number"?(at=Ne(F),Ie=We):at=We,((Ge,De,ke=0)=>{if(Ge.x>De.width||Ge.y>De.height)return null;const dt={left:Ge.x,top:Ge.y,bottom:Ge.height+Ge.y,right:Ge.width+Ge.x},tt={left:De.x+ke,top:De.y+ke,bottom:De.height-2*ke+De.y,right:De.width-2*ke+De.x},gt={left:Math.max(dt.left,tt.left),top:Math.max(dt.top,tt.top),bottom:Math.min(dt.bottom,tt.bottom),right:Math.min(dt.right,tt.right)},Et={x:gt.left,y:gt.top,width:gt.right-gt.left,height:gt.bottom-gt.top};return Et.height<0||Et.width<0?null:Et})(Q??{x:0,y:0,width:Pe.width,height:Pe.height},at,Ie)},toViewBounds:Q=>Fe===0&&ft===0&&j===1?Q:{x:(Q.x-Fe)*j,y:(Q.y-ft)*j,width:Q.width*j,height:Q.height*j},toAbsoluteBounds:Q=>Fe===0&&ft===0&&j===1?Q:{x:Q.x/j+Fe,y:Q.y/j+ft,width:Q.width/j,height:Q.height/j},getRelativePointFromClient:(Q,We)=>{const at=Nt(Q,We);return{x:at.x-Pe.x,y:at.y-Pe.y}},getLayout:()=>Se,getCellCoordsAsRangeCoords:ct,getVisibleColumns:()=>je[v].visibleIndices(),getVisibleRows:()=>ve[y].visibleIndices(),getVisibleColumnOffsets:()=>(Ue||(Ue=jo(je[v].layout,!0,je[v].visibleIndices(),F.colStart,F.colEnd)),Ue),getVisibleRowOffsets:()=>(Xe||(Xe=jo(ve[y].layout,!1,ve[y].visibleIndices(),F.rowStart,F.rowEnd)),Xe),getTotalRangeCoords:()=>({colStart:je[v].minCoord,colEnd:je[v].maxCoord,rowStart:ve[y].minCoord,rowEnd:ve[y].maxCoord}),getRangeCoordsBounds:Ne,scrollCellCoordsIntoView:(Q,We)=>Gt(Q,We,z),getCellCoordsFromClient:(Q,We,at=!1)=>{const Ie=Nt(Q,We);if(!Ie)return null;const Ge=Se.getColIndex(Ie.x-Pe.x),De={rowIndex:Se.getRowIndex(Ie.y-Pe.y),colIndex:Ge};if(at)return De;const ke=ct(De);return{rowIndex:ke.rowStart,colIndex:ke.colStart}},getZoom:()=>j,getAnchor:()=>z,getBounds:()=>Pe,getInsets:()=>Ke,getTotalSize:()=>Ee,getViewportSize:()=>Ye,getScrollTopLeft:()=>le,getFreezeTopLeft:()=>et,getScrollOrientation:()=>ae,allViews:()=>w}};let E=w[n.AnchorLocation.Center]=S(0,0,n.AnchorLocation.Center,Dn,Mn);return E&&(w[n.AnchorLocation.Center]=E),E=S(0,1,n.AnchorLocation.Top,{horizontal:!0}),E&&(w[n.AnchorLocation.Top]=E),E=S(1,0,n.AnchorLocation.Left,{vertical:!0}),E&&(w[n.AnchorLocation.Left]=E),E=S(1,1,n.AnchorLocation.TopLeft,{}),E&&(w[n.AnchorLocation.TopLeft]=E),it.current=null,w=Object.freeze(w)},[ve,je,ct]),Bt=Object.keys(Ce),Rt=je[0]?.maxVirtualBounds??0,_e=ve[0]?.maxVirtualBounds??0,Ct=l.useMemo(()=>({left:je[1]?je[1].layout.getColOffset(je[1].maxIndex+1):0,top:ve[1]?ve[1].layout.getRowOffset(ve[1].maxIndex+1):0}),[Ce]);l.useEffect(()=>{if(pt.current.length>0){for(let w=0;w<pt.current.length;w++)pt.current[w]();pt.current=[]}},[Ce]);const vt=o.useCallbackRef(()=>({containerWidth:He,containerHeight:Be,totalWidth:Rt,totalHeight:_e}),[He,Be,Re]);l.useEffect(()=>{!ne.current&&bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[lt,qe,Rt,_e]),l.useEffect(()=>{bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[He,Be]);const Nt=l.useCallback((w,S)=>{go(typeof w=="number"&&typeof S=="number");const E=ze.current?.getBoundingClientRect();return E?{x:w-E.x,y:S-E.y}:{x:w,y:S}},[]),xo=o.useCallbackRef(w=>Ce[w]||null,[Ce]),po=o.useCallbackRef((w,S)=>{if(Object.keys(Ce).length===1)return Ce[n.AnchorLocation.Center];const E=Nt(w,S);if(!E)return null;const{x:v,y}=E;let z=null;const he=Xo,re=he.length;for(let ae=0;!z&&ae<re;ae++){const F=Ce[he[ae]];F&&vn(v,y,F.getBounds())&&(z=F)}return z||(z=Ce[n.AnchorLocation.Center]),z},[Ce,ct]),Ze=o.useCallbackRef(()=>Ce[n.AnchorLocation.Center].getVisibleRangeCoords(),[Ce[n.AnchorLocation.Center]]),Ot=l.useRef(null),mo=l.useCallback(()=>{Ot.current!==null&&n.CommonUtils.cancelTimeout(Ot.current),Ot.current=n.CommonUtils.requestTimeout(Co,150)},[]),Co=l.useCallback(()=>{Ot.current=null,b(w=>{const S={...w,verticalScrollDirection:null,horizontalScrollDirection:null};return Ae.current=S,S})},[]),Kt=o.useCallbackRef(w=>{const S=w?.left??w?.[0],E=w?.top??w?.[1];let v=Ae.current.left;S!==void 0&&S!==v&&(S>v?(v=Math.max(je?.[1]?.scrollOffset??0,S),v=Math.min(Rt-He,v)):v=Math.max(je?.[1]?.scrollOffset??0,S));let y=Ae.current.top;if(E!==void 0&&E!==y&&(E>y?(y=Math.max(ve?.[1]?.scrollOffset??0,E),y=Math.min(_e-Be,y)):y=Math.max(ve?.[1]?.scrollOffset??0,E)),Ae.current.left===v&&Ae.current.top===y)return;let z=null,he=null;Ae.current.left>v?z=n.Direction.Left:Ae.current.left<v&&(z=n.Direction.Right),Ae.current.top>y?he=n.Direction.Up:Ae.current.top<y&&(he=n.Direction.Down),n.CommonUtils.throttle(()=>{b(re=>{const ae={...re,left:v,top:y,horizontalScrollDirection:z,verticalScrollDirection:he};return Ae.current=ae,ae})},17)(),ne.current?.top===y&&ne.current?.left===v||(ne.current={left:v,top:y},D({left:v,top:y}),R({left:v,top:y,width:He,height:Be,totalWidth:Rt,totalHeight:_e})),mo()},[Rt,_e,ve,je]);l.useEffect(()=>{ne.current||Kt({left:qe,top:lt})},[He,Be]),l.useEffect(()=>{let w,S,E=!1;Ae.current.left>Rt&&(w=0,E=!0),Ae.current.top>_e&&(S=0,E=!0),E&&Kt({left:w,top:S})},[Rt,_e]),l.useLayoutEffect(()=>{ne.current={left:rt?.left,top:rt?.top},Kt(ne.current)},[rt?.left,rt?.top]);const to=o.useCallbackRef(w=>{let S=w?.left??w?.[0],E=w?.top??w?.[1];if(S===void 0&&E===void 0)return;const v=w?.behavior??"auto";S!==void 0&&(S=Ae.current.left+(S??0)),E!==void 0&&(E=Ae.current.top+(E??0)),!(Ae.current.left===S&&Ae.current.top===E)&&Kt({left:S,top:E,behavior:v})},[]),oo=l.useCallback(w=>{let S=null;if(Object.keys(Ce).length>1){const E=Xo,v=E.length;for(let y=0;!S&&y<v;y++){const z=Ce[E[y]];z&&n.CoordUtils.isCellWithinRange(w,z.getVisibleRangeCoords())&&(S=z)}}return S||(S=Ce[n.AnchorLocation.Center]),S},[Ce]),Gt=o.useCallbackRef((w,S={inline:"nearest",block:"nearest"},E=null)=>{const v={rowIndex:0,colIndex:0,...w};let y=null;if(E!==null){if(y=Ce[E],y===null)return new Promise((Ye,Ue)=>{Ue("Invalid view")})}else y=oo(v);const z=ct(v),he=y.getLayout(),re=he.getColOffset(z.colStart),ae=he.getRowOffset(z.rowStart),F=he.getColOffset(z.colEnd+1),Se=he.getRowOffset(z.rowEnd+1),Ke=y.getBounds(),Pe=y.getTotalSize(),Ne=y.getScrollTopLeft(),Ee=((Ye,Ue,Xe=!0)=>{Xe=Xe===!0?{block:"start",inline:"end"}:Xe===!1?{block:"end",inline:"end"}:{block:"end",inline:"end",...Xe};const ft=Wo(Xe.inline,Ye.x,Ye.x+Ye.width,Ue.left,Ue.left+Ue.width,Ue.totalWidth),Fe=Wo(Xe.block,Ye.y,Ye.y+Ye.height,Ue.top,Ue.top+Ue.height,Ue.totalHeight);if(ft!==void 0||Fe!==void 0)return{left:ft,top:Fe}})({x:re+Ne.left,y:ae+Ne.top,width:F-re,height:Se-ae},{left:Ne.left,top:Ne.top,width:Ke.width,height:Ke.height,totalWidth:Pe.width,totalHeight:Pe.height},S);if(!Ee)return Promise.resolve({...Ne});const le={...Ee};le.left>qe?le.left+=20:le.left<qe&&(le.left-=0),le.top>lt?le.top+=20:le.top<lt&&(le.top-=0);const et=y.getScrollOrientation();return et.horizontal&&w.colIndex!==void 0||delete le.left,et.vertical&&w.rowIndex!==void 0||delete le.top,new Promise((Ye,Ue)=>{try{Kt(le),Ye(le)}catch(Xe){Ue(Xe)}})},[Rt,_e,Ce,ct]),qt=o.useCallbackRef(w=>{const S=w.shiftKey;w.preventDefault();const{deltaX:E,deltaY:v,deltaMode:y}=w;if(mt.current||oe?.(w)===!1)return;let he=S?v:E,re=v;const ae=S||Math.abs(he)>Math.abs(re);y===1&&(re*=0),mt.current=window.requestAnimationFrame(()=>{mt.current=null,to(ae?{left:he}:{top:re})})},[oe]),_t=l.useCallback((w=null)=>{At.current=null,it.current=null,Tt()},[]);l.useLayoutEffect(()=>{_t()},[ge]);const Wt=o.useImperativeElement(r,()=>({stage:ze.current,focus:Ft,contains:ht,invalidate:_t,scrollTo:Kt,scrollBy:to,scrollCellCoordsIntoView:Gt,getScrollPosition:Lt,getDimensions:vt,getViewport:Ze,handleWheel:qt,rowCount:d,columnCount:f,getLayout:()=>Re,getRelativePointFromClient:Nt,getViewFromClient:po,getViewFromCellCoords:oo,getViewFromLocation:xo,onViewChangeOnce:w=>{pt.current.push(w)}}),[d,f,Ce]);l.useEffect(()=>(St&&Wt.current?.addEventListener("wheel",qt,{passive:!1}),bt.current=!0,ne.current=null,()=>{Wt.current?.removeEventListener("wheel",qt)}),[St]);const Zt=l.useRef([]),So=(w,S)=>{!w||!Oe||(Zt.current=[],S.push(((E,v)=>{const y=`view:${E.getAnchor()}:overlay:${S.length}`,z=Oe?.({key:y,view:E},re=>Zt.current[v]=re);if(!z)return null;const he=E.getBounds();return ee.jsx("div",{style:{position:"absolute",left:"0px",top:"0px",width:`${he.width}px`,height:`${he.height}px`,overflow:"hidden"},children:z},`overlay-${E.getAnchor()}-${v}`)})(w,0)))},bo=l.useMemo(()=>{const w={},S=Object.keys(Ce),E=S.length;for(let v=0;v<E;v++){const y=S[v],z=[];So(Ce[y],z),w[y]={overlays:z}}return w},[Qe,Oe,d,f,ve,je]),no=(w,S,E,v,y,z,he)=>{if(!w)return;const re=w.getVisibleColumns(),ae=w.getVisibleRows();if(re.length===0||ae.length===0)return;let F=null;if(L)F=L(w);else{F=[];const Ie=ae.length,Ge=re.length;for(let De=0;De<Ie;De++){const ke=ae[De];for(let dt=0;dt<Ge;dt++){const tt={rowIndex:ke,colIndex:re[dt]};if(q?.(tt))continue;const gt={coords:tt,range:ct(tt)};F.push(gt)}}}const Se=w.getVisibleColumnOffsets(),Ke=w.getVisibleRowOffsets(),Pe=w.getScrollTopLeft(),Ne=w.getFreezeTopLeft(),Ee=Pe.left+Ne.left,le=Pe.top+Ne.top,et=Math.trunc(Ee/zt),Ye=Math.trunc(le/zt),Ue={},Xe=(Ie,Ge,De,ke,dt)=>{const tt=`view:${Ie.getAnchor()}:cell:${Fo(Ge.rowIndex,Ge.colIndex)}`,gt=ke.x,Et=ke.y,e=Math.trunc((Ee+gt)/zt)-et,u=Math.trunc((le+Et)/zt)-Ye;Ue[u]||(Ue[u]={});let g=Ue[u][e];g||(g=Ue[u][e]=[]);let h=z?.get(tt);if(!h){const x=(Ee+gt)%zt,k=(le+Et)%zt;h=ge({key:tt,coords:Ge,bounds:ke,zoom:j,range:De,view:Ie,value:dt,style:{left:o.ReactUtils.boundPixel(x),top:o.ReactUtils.boundPixel(k),width:o.ReactUtils.boundPixel(ke.width,!0),height:o.ReactUtils.boundPixel(ke.height,!0)}})}he?.set(tt,h),g.push(h)},ft=F.length;for(let Ie=0;F&&Ie<ft;Ie++){const Ge=F[Ie],De=Ge?.coords??Ge;if(!De)continue;const ke=Ge?.range??{rowStart:De.rowIndex,colStart:De.colIndex,rowEnd:De.rowIndex,colEnd:De.colIndex},dt=w.getVisibleRangeCoords();if(!n.CoordUtils.isRangesIntersect(ke,dt)&&!n.CoordUtils.isRangeWithinRange(ke,dt))continue;const tt=ke&&!n.CoordUtils.isSingleCell(ke);if(!tt&&q?.(De))continue;const gt=De.rowIndex,Et=De.colIndex,e=Ke[gt],u=Se[Et];let g=null;e&&u&&(g={x:u.offset,y:e.offset,width:u.size,height:e.size});const h=Fo(ke.rowStart,ke.colStart);if(tt){if(y.has(h))continue;y.add(h),ke.rowEnd-ke.rowStart>0&&E.push(ke),ke.colEnd-ke.colStart>0&&v.push(ke)}if(tt&&(g=No(w.getLayout(),ke)),!g){console.warn("no bounds for cell",h);continue}const x=Ge?.value;Xe(w,De,ke,g,x)}const Fe=Ee%zt,Q=le%zt,We=Object.keys(Ue),at=We.length;for(let Ie=0;Ie<at;Ie++){const Ge=We[Ie],De=Ue[Ge];if(!De)continue;const ke=Object.keys(De),dt=ke.length;for(let tt=0;tt<dt;tt++){const gt=ke[tt],Et=De[gt];if(!Et)continue;const e=parseInt(Ge),u=parseInt(gt),g=e+Ye,h=u+et,x=`view:${w.getAnchor()}:segment:${h}:${g}`;S.push(ee.jsx("div",{className:"cell-container",style:{transform:`translate(${o.ReactUtils.boundPixel(u*zt-Fe,!0)}px, ${o.ReactUtils.boundPixel(e*zt-Q,!0)}px)`,willChange:"transform"},children:Et},x))}}},Mt=l.useMemo(()=>{const w=At.current,S=new Map,E={},v=Object.keys(Ce),y=v.length;for(let z=0;z<y;z++){const he=v[z],re=[],ae=[],F=[];no(Ce[he],F,re,ae,new Set,w,S),E[he]={cells:F,rangesH:re,rangesV:ae}}return At.current=S,E},[Qe,d,f,ve,je,B,se,Me,q,L,me,_,ct]),ro=(w,S,E,v,y)=>{if(!w)return;const z=w.getLayout(),he=window.devicePixelRatio||1,re=String(1/he);if(S){const ae=`view:${w.getAnchor()}:hl:`,F=w.getVisibleRows();if((F?F.length:0)===0)return;const Se=y.sort(n.CoordUtils.rowFirstRangeComparator),Ke=w.getVisibleRangeCoords(),Pe=0,Ne=Math.min(w.getBounds().width,z.getColOffset(Ke.colEnd+1));let Ee=[];for(let le=0;le<F.length&&F[le]<=Ke.rowEnd;le++){const et=F[le];if(et<Ke.rowStart)continue;let Ye=!1;for(;Se.length>0&&Se[0].rowStart<=et;){const Fe=Se.shift();Fe.rowEnd>et&&(Ee.push(Fe),Ye=!0)}Ye&&(Ee=Ee.sort(n.CoordUtils.columnFirstRangeComparator));const Ue=z.getRowOffset(et+1);let Xe=Pe;const ft=Ee.length;for(let Fe=0;Fe<ft+1;Fe++){let Q=Xe,We=Ne;const at=Ee[Fe];Fe<ft&&(We=Math.min(Ne,z.getColOffset(at.colStart)),Xe=Math.min(Ne,z.getColOffset(at.colEnd+1))),v.push(l.createElement("path",{d:`M ${o.ReactUtils.boundPixel(Q)} ${o.ReactUtils.boundPixel(Ue,!1,E)} L ${o.ReactUtils.boundPixel(We)} ${o.ReactUtils.boundPixel(Ue,!1,E)}`,stroke:te,strokeWidth:re,vectorEffect:"non-scaling-stroke",...Z,key:ae+et+":"+Fe}))}for(let Fe=ft-1;Fe>=0;Fe--)Ee[Fe].rowEnd<=F[le+1]&&Ee.splice(Fe,1)}}else{const ae=`view:${w.getAnchor()}:vl:`,F=w.getVisibleColumns(),Se=F?F.length:0;if(Se===0)return;const Ke=y.sort(n.CoordUtils.columnFirstRangeComparator),Pe=w.getVisibleRangeCoords(),Ne=0,Ee=Math.min(w.getBounds().height,z.getRowOffset(Pe.rowEnd+1));let le=[];for(let et=0;et<Se&&F[et]<=Pe.colEnd;et++){const Ye=F[et];if(Ye<Pe.colStart)continue;let Ue=!1;for(;Ke.length>0&&Ke[0].colStart<=Ye;){const Q=Ke.shift();Q.colEnd>Ye&&(le.push(Q),Ue=!0)}Ue&&(le=le.sort(n.CoordUtils.rowFirstRangeComparator));const Xe=z.getColOffset(Ye+1);let ft=Ne;const Fe=le.length;for(let Q=0;Q<Fe+1;Q++){let We=ft,at=Ee;const Ie=le[Q];Q<Fe&&(at=Math.min(Ee,z.getRowOffset(Ie.rowStart)),ft=Math.min(Ee,z.getRowOffset(Ie.rowEnd+1))),v.push(ee.jsx("path",{d:`M ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(We)} L ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(at)}`,stroke:te,strokeWidth:re,vectorEffect:"non-scaling-stroke",...X},ae+Ye+":"+Q))}for(let Q=Fe-1;Q>=0;Q--)le[Q].colEnd<=F[et+1]&&le.splice(Q,1)}}},Jt=w=>{if(!Mt)return;const S={},E=Bt.length;for(let v=0;v<E;v++){const y=Bt[v],z=Ce[y],he=[];ro(z,w,0,he,w?Mt[y].rangesH:Mt[y].rangesV);const re=z.getRangeCoordsBounds(),ae=Math.ceil(re.width),F=Math.ceil(re.height);S[y]=ee.jsx("svg",{width:`${ae}`,height:`${F}`,viewBox:`0 0 ${ae} ${F}`,preserveAspectRatio:"none",shapeRendering:"crispEdges",style:{position:"absolute"},children:he})}return S},lo=l.useMemo(()=>B===!0||B?.horizontal===!0?Jt(!0):null,[Qe,B,ve,G,P,te,Z,d,f,He,Rt,Ce,Mt]),io=l.useMemo(()=>B===!0||B?.vertical===!0?Jt(!1):null,[Qe,B,je,G,P,te,X,d,f,Be,_e,Ce,Mt]),vo=l.useMemo(()=>Ct.left===0?null:ee.jsx(Po,{linePoints:[0,0,0,Be+1],bounds:{x:Ct.left,y:0,width:1,height:Be+1},...we}),[Qe,Ct.left,Be,we]),yo=l.useMemo(()=>Ct.top===0?null:ee.jsx(Po,{linePoints:[0,0,He+1,0],bounds:{x:0,y:Ct.top,width:He+1,height:1},...K}),[Qe,Ct.top,He,K]),Qt=l.useMemo(()=>{const w=[],S=v=>{if(!v||!Ce[v])return;const y=Ce[v].getBounds();return ee.jsxs("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:y.width,height:y.height,clip:`rect(0, ${y.width+1}px, ${y.height+1}px, 0)`},className:`view view-${v}`,children:[lo?.[v],io?.[v],Mt?.[v].cells]},`view:${v}`)},E=Bt.length;for(let v=0;v<E;v++)w.push(S(Bt[v]));return ee.jsx(ee.Fragment,{children:w})},[Ce,lo,io,Mt]),Ro=l.useMemo(()=>{if(!r)return;const w=(re,ae,F,Se)=>{if(!Se||Se.length===0)return;const Ke=[],Pe=Se.length;for(let Ne=0;Ne<Pe;Ne++){const Ee=Se[Ne];let le=re?.get(Ee);le!==Mo&&(le=Ee(F)??Mo),ae.set(Ee,le),le&&le!==Mo&&Ke.push(le)}return Ke},S=(re,ae,F)=>{if(!F)return;const Se=F.getBounds(),Ke=F.getInsets(),Pe=F.getAnchor();return ee.jsxs("div",{className:Vt("view",`view-${Pe}`,Yo.view),style:{position:"absolute",pointerEvents:"none",left:Se.x-Ke.left,top:Se.y-Ke.top,width:Se.width-(Ke.left+Ke.right),height:Se.height-(Ke.top+Ke.bottom),clipPath:C?"inset(-2px)":"inset(0px)"},children:[w(re,ae,F,pe),bo?.[Pe].overlays]},`view:${Pe}`)},E=it.current,v={},y=[],z=Object.keys(Ce),he=z.length;for(let re=0;re<he;re++){const ae=z[re],F=E?.[ae],Se=v[ae]=new Map;y.push(S(F,Se,Ce[ae]))}return it.current=v,y},[Qe,Ce,C,pe]),Eo=l.useMemo(()=>{const{style:w,...S}=$e??{};return ee.jsx("div",{style:{width:He,height:Be,...w},className:"sheetxl-stage",tabIndex:0,ref:ze,...S,...Pt,children:Ve?Ve(Qt):Qt})},[He,Be,Qt,$e,Ve]),co=l.useRef(!1);return l.useEffect(()=>{!co.current&&Mt&&(co.current=!0,ue?.(Wt.current))},[Mt]),ee.jsxs("div",{className:Vt("sheetxl-grid",Yo["sheetxl-grid"]),style:{overflow:"visible",cursor:J,maxWidth:He,maxHeight:Be,width:He,height:Be,...se},ref:Wt,children:[Eo,ee.jsxs("div",{className:Vt("sheetxl-overlays"),ref:Je,...A,children:[Ro,vo,yo]})]})}));zo.displayName="BaseGrid";var Pn=function(){},nn=typeof window<"u",Un=nn?l.useLayoutEffect:l.useEffect,Go={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};const Tn=nn&&window.ResizeObserver!==void 0?function(){var t=l.useState(null),r=t[0],i=t[1],c=l.useState(Go),d=c[0],f=c[1],a=l.useMemo(function(){return new window.ResizeObserver(function(s){if(s[0]){var p=s[0].contentRect,O=p.x,U=p.y,M=p.width,T=p.height,B=p.top,te=p.left,Z=p.bottom,X=p.right;f({x:O,y:U,width:M,height:T,top:B,left:te,bottom:Z,right:X})}})},[]);return Un(function(){if(r)return a.observe(r),function(){a.disconnect()}},[r]),[i,d]}:function(){return[Pn,Go]},Ao=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,style:d={},className:f,...a}=t,[s,{width:p,height:O}]=Tn(),U=i??p,M=c??O;return ee.jsx("div",{className:f,style:{...d},children:ee.jsx("div",{style:{position:"relative",top:"0px",left:"0px",width:"100%",height:"100%",maxWidth:"100%",maxHeight:"100%",boxSizing:"content-box"},ref:s,children:ee.jsx(zo,{ref:r,width:U,height:M,...a})})})}));Ao.displayName="Grid";const rn=l.memo(l.forwardRef((t,r)=>{const{showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:s,onScrollViewport:p,style:O={},className:U,onScroll:M,...T}=t,[B,te]=l.useState(null),Z=l.useRef(null),X=l.useRef(null);go(!s),l.useImperativeHandle(r,()=>X.current&&Z.current?Object.assign(X.current,Z.current):null);const Me=l.useCallback(J=>{X.current?.scrollTo(J),p?.(J)},[]);return ee.jsx(o.ScrollPane,{className:U,style:O,ref:Z,showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:B,onScrollViewport:Me,children:ee.jsx(Ao,{style:{width:"100%",height:"100%"},...T,onViewportChange:J=>te(J),ref:X})})}));rn.displayName="ScrollableGrid";const _o=()=>!1,ln=l.memo(t=>{const{index:r,value:i,zoom:c,zoomScale:d=100,headerText:f=pe=>`${pe}`,headerStyle:a,headerStyleSelect:s=a,headerStyleSelectAll:p=s,headerStyleHover:O=p,verticalPadding:U=0,horizontalPadding:M=0,isSelected:T=_o,isSelectedAll:B=_o,coords:te,bounds:Z,range:X,orientation:Me,view:J,style:P,...G}=t,we=d/100,K=l.useRef(null),[ge,Le]=l.useState(!1),ye=T?.(r)||!1,Oe=B?.(r)?p:ye?s:a;let ce=Oe;if(ge){let pe=O;typeof O=="function"&&(pe=O(Oe)),ce=n.CommonUtils.mergeContentful(Oe,pe)}return ee.jsx("div",{ref:K,style:{background:ce.fill,color:ce.text?.fill,fontFamily:ce.text?.fontFamily??a.text?.fontFamily,fontSize:96*(ce.text?.fontSize??11)/72*we,fontStyle:ce.text?.fontStyle,fontWeight:ce.text?.fontWeight,lineHeight:1.2,display:"flex",justifyContent:"center",alignItems:"end",pointerEvents:"auto",paddingBottom:`${we}px`,...P,left:P.left-(Me===n.RangeOrientation.Column?1:0),top:P.top-(Me===n.RangeOrientation.Row?1:0),width:P.width+1,height:P.height+1,overflow:"hidden"},...G,onMouseMove:pe=>{o.ReactUtils.detectIt().primaryInput!=="touch"&&pe.buttons===0&&Le(!0)},onMouseOut:pe=>{Le(!1)},children:f(r)})});ln.displayName="HeaderRenderer";const cn="ew-resize",sn="ns-resize",an=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,className:f,style:a,disabled:s=!1,disabledResize:p=!1,isNextHidden:O,isHidden:U,isSelected:M,isSelectedAll:T,showTouchDivider:B,headerStyle:te,headerStyleSelect:Z,headerStyleSelectAll:X,headerStyleHover:Me,bounds:J,onPointerDown:P,onAutoFit:G,...we}=t,K=i===n.RangeOrientation.Column;let ge=te;M&&Z&&(ge=Z),T&&X&&(ge=X);const Le=o.ReactUtils.detectIt().primaryInput==="touch";let ye=K?14:8,Oe=ye/2,ce=0;O&&(ce=-2),U&&(ce=2),U&&(ye=ye/2+ce,Oe=2*ce);let pe=ge.dividerStrokeFill??ge.strokeFill;return!(M||T)&&ce===0&&(pe=`linear-gradient(${K?180:90}deg, ${ge.fill}, ${pe} 55%, ${pe} 100%)`),ee.jsxs("div",{className:Vt("header-divider",{disabled:s},f,`index-${d}`),ref:r,onPointerDown:Le?void 0:P,onDoubleClick:Le?void 0:()=>G?.(),style:{top:(K?0:-ye/2+(ce-1))+"px",left:(K?-ye/2+(ce-1):0)+"px",width:K?ye:"calc(100% + 1px)",height:K?"calc(100% + 1px)":ye,position:"absolute",overflow:"visible",pointerEvents:"all",cursor:s||p||Le?void 0:K?cn:sn,...a},...we,children:[ee.jsx("div",{style:{position:"relative",top:`${K?0:Oe}px`,left:`${K?Oe:0}px`,width:K?1:"100%",height:K?"100%":1,background:pe},onDoubleClick:()=>G?.()}),B&&Le?ee.jsx("div",{style:{position:"absolute",cursor:"grab",zIndex:1,borderRadius:"4px",right:K?"-6px":"2px",bottom:K?"2px":"-9px",height:"24px",width:K?"24px":"18px",maxHeight:K?"calc(100% - 4px)":void 0,maxWidth:K?void 0:"calc(100% - 4px)",background:ge.fill,border:`${X.edgeStrokeFill} solid 1px`,boxShadow:`0.5px 0.5px 0px 0px ${te.text.fill}`,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:P,children:ee.jsx("div",{style:{width:"6.4px",height:"12px",backgroundImage:`url("data:image/svg+xml,%3Csvg width='6.4' height='12' viewBox='0 0 9.6 16' version='1.1' fill='${encodeURIComponent(Z.text.fill)}' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cpath d='M 9.60008,14.40009 C 9.60008,15.28374 8.88368,16 8.00003,16 7.11639,16 6.40012,15.28374 6.40012,14.40009 c 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40012 c 0,0.88364 -0.7164,1.60004 -1.60005,1.60004 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60004 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40006 c 0,0.88365 -0.7164,1.60005 -1.60005,1.60005 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60005 C 6.40012,0.71626 7.11639,0 8.00003,0 8.88368,0 9.60008,0.71626 9.60008,1.59991 M 3.19996,14.40009 C 3.19996,15.28374 2.48369,16 1.60005,16 0.7164,16 0,15.28374 0,14.40009 c 0,-0.88365 0.7164,-1.60005 1.60005,-1.60005 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40012 c 0,0.88364 -0.71627,1.60004 -1.59991,1.60004 C 0.7164,9.60001 0,8.88361 0,7.99997 0,7.11632 0.7164,6.39992 1.60005,6.39992 c 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40006 c 0,0.88365 -0.71627,1.60005 -1.59991,1.60005 C 0.7164,3.19996 0,2.48356 0,1.59991 0,0.71626 0.7164,0 1.60005,0 2.48369,0 3.19996,0.71626 3.19996,1.59991' /%3E%3C/svg%3E%0A")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",transform:K?void 0:"rotate(90deg)"}})}):null]})})),Ln=(t,r)=>ee.jsx(an,{...t,ref:r}),On=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,disabled:f=!1,disabledResize:a=!1,resizeThreshold:s=1,dividerRenderer:p=Ln,onDividerMouseDown:O,onDividerResizeStart:U,onDividerResize:M,onDividerResizeEnd:T,onDividerMouseUp:B,onDividerAutoFit:te,onPointerDown:Z,...X}=t,Me=o.useCallbackRef(Z,[Z]),J=o.useCallbackRef(te,[te]),P=i===n.RangeOrientation.Column;let G=P?c.getVisibleColumns():c.getVisibleRows(),we=null;G.length>0&&(P?we=c.getRangeCoordsBounds({rowStart:0,rowEnd:0,colStart:G[0],colEnd:G[G.length-1]}):c.getRangeCoordsBounds({rowStart:G[0],rowEnd:G[G.length-1],colStart:0,colEnd:0}),we=c.toClipBounds(we,It));const K=l.useRef(null),[ge,Le]=l.useState(null),ye=(_,me)=>P?_.clientX-me.clientX:_.clientY-me.clientY,Oe=c.getLayout(),ce=P?Oe.getColOffset(d+1):Oe.getRowOffset(d+1),pe=o.useSynchronizedPointerHandler({processTouch:!0,onPointerDown:_=>{if(Me?.(_),!f&&!a){const me=P?Oe.getColOffset(d):Oe.getRowOffset(d),q=ce-me;K.current={isResizing:!1,startSize:q,index:d,view:c,orientation:i,onDividerMouseDown:O,onDividerResizeStart:U,onDividerResize:M,onDividerResizeEnd:T,onDividerMouseUp:B},Le(K.current),O?.(d,q)}_.stopPropagation(),_.preventDefault()},onPointerUp:(_,me,q)=>{if(!K.current)return;K.current.isResizing&&K.current.onDividerResizeEnd?.(K.current.index,Math.max(0,K.current.startSize+ye(_,q)),K.current.startSize);const L=K.current;K.current=null,Le(K.current),L.onDividerMouseUp?.(L.index)},onPointerMoveOrWait:(_,me,q)=>{if(!K.current)return;const L=ye(_,q);K.current.isResizing?K.current.onDividerResize?.(K.current.index,Math.max(0,K.current.startSize+L),K.current.startSize):Math.abs(L)>Math.max(1,s)&&(K.current={...K.current,isResizing:!0},Le(K.current),K.current.onDividerResizeStart?.(K.current.index,Math.max(0,K.current.startSize+L))),_.stopPropagation(),_.preventDefault()}}),A=o.useCallbackRef(()=>{J?.(d)},[d]);if(!we)return;const C=p({bounds:we,orientation:i,view:c,index:d,disabled:f,disabledResize:a,onAutoFit:A,onPointerDown:pe,...X},r);if(!C)return;const{getPortalContainer:$e}=o.useFullscreenPortal();let Ve=null;return ge&&ge.isResizing&&ge.index===d&&(Ve=Zo.createPortal(ee.jsx("div",{style:{position:"absolute",cursor:P?cn:sn,left:0,top:0,width:"100%",height:"100%"}}),$e(),"divider:"+d)),ee.jsxs(ee.Fragment,{children:[Ve,ee.jsx("div",{className:Vt("header-divider-anchor"),style:{position:"absolute",pointerEvents:"auto",top:`${P?we.y:ce}px`,left:`${P?ce:we.x}px`,width:(P?0:we.width-1)+"px",height:(P?we.height-1:0)+"px",display:"flex"},tabIndex:-1,children:C})]})}));class zn{naturalDimensions(r,i={}){const c=document.createElement("div");let d=i?.lineHeight??"1";!i?.lineHeight&&i.paintableText?.fontSize&&(d=Math.ceil(1.2*i.paintableText.fontSize)+"px");const f=document.createElement("div");f.style.visibility="hidden",f.style.position="absolute",f.style.textRendering="geometricprecision",f.style.display="inline-grid",f.style.overflowWrap="break-word",f.style.maxWidth=i.maxWidth?i.maxWidth+"px":"100%",f.style.lineHeight=d,f.style.letterSpacing=(i.paintableText?.letterSpacing??0)+"px",f.style.fontSize=i.paintableText?.fontSize?i.paintableText.fontSize+"px":"unset",f.style.fontFamily=i.paintableText?.fontSize?i.paintableText.fontFamily:"unset",f.style.fontWeight=i.paintableText?.fontWeight?""+i.paintableText.fontWeight:"400",f.style.fontStyle=i.paintableText?.fontStyle?i.paintableText.fontStyle:"normal",f.style.whiteSpace=i.paintableText?.wrap==="wrap"?"break-spaces":"pre",c.appendChild(f);const a=r.split(`
12
- `);for(let p=0;p<a.length;p++){let O=document.createElement("span");f.appendChild(O),O.textContent=a[p]}a.length!==0&&a[a.length-1].length!==0||f.appendChild(document.createElement("br")),document.body.appendChild(f);let s=f.getBoundingClientRect();return f.remove(),{width:s.width,height:s.height,maxLineHeight:1.2*(i.paintableText?.fontSize||1056/72)}}}const dn=(t=void 0)=>Object.freeze({clean:t,dirty:void 0,editMode:!1}),An=dn(),$n=l.memo(l.forwardRef((t,r)=>{const{editState:i=An,defaultTextStyle:c,onStartEdit:d,onChangeEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,containerBounds:O,setNaturalSize:U,onNavigate:M,textProperties:T,style:B,autoFocus:te,...Z}=t,X=l.useRef(null),{width:Me=0}=O??{},[J,P]=l.useState(()=>i);l.useEffect(()=>{P(i)},[i]);const G=T?.align||"left",we=T?.vAlign||"middle",K=T?.fill||"#040404",ge=T?.wrap||"wrap",Le=T?.fontFamily||"Calibri",ye=T?.fontSize||11,Oe=T?.fontWeight||400,ce=T?.fontStyle||"normal",pe=J.dirty??J.clean??"";let A=2;const C=96*ye/72,$e=1.2*C;we==="right"&&(A+=1);const Ve=l.useMemo(()=>new zn().naturalDimensions(pe,{maxWidth:ge==="wrap"?Me-A:void 0,lineHeight:`${$e}px`,paintableText:{fontStyle:ce,wrap:ge,letterSpacing:-.25}}),[pe,ge,A,C,Le,Oe,ce,U,Me]),_=l.useCallback(()=>Ve.maxLineHeight?Ve.maxLineHeight+"px":"1.2",[Ve]),[me,q]=l.useState(_);l.useLayoutEffect(()=>{q(_())},[O,Ve]),l.useLayoutEffect(()=>{U?.({width:ge==="wrap"?void 0:Ve.width+A,height:Ve.height})},[Ve,U]);const L=o.useCallbackRef(f,[f]),j=o.useCallbackRef(R=>{if(J.dirty===R)return;const be={...J};be.dirty=R,X.current,P(be),L?.(be)},[J]),St=o.useCallbackRef(R=>{if(J.editMode===R)return;const be={...J};be.editMode=R,P(be),L?.(be)},[J]),xt=o.useCallbackRef(()=>{try{return a?.(J),p?.(),!0}catch{return!1}},[a,J]),ct=o.useCallbackRef(()=>{P(i),s?.(),p?.()},[s,i]),rt=o.useCallbackRef(R=>{if(!X.current)return;if(R.isDefaultPrevented(),!(R.isTrusted||R.nativeEvent.ctrlKey||R.nativeEvent.metaKey||R.nativeEvent.altKey||R.nativeEvent.isComposing)&&Lo.indexOf(R.nativeEvent.key)!==-1){const oe={...J};return oe.dirty=R.nativeEvent.key==="Backspace"?"":(oe.dirty??"")+R.key,P(oe),L?.(oe),void R.preventDefault()}const be=R.nativeEvent.shiftKey;if(R.which===o.KeyCodes.Escape)return R.preventDefault(),void ct();if(R.which===o.KeyCodes.F2)return St(!0),void R.preventDefault();if(R.which===o.KeyCodes.Enter&&(R.preventDefault(),xt()&&M?.(be?n.Direction.Up:n.Direction.Down)),R.which===o.KeyCodes.Tab)return R.preventDefault(),void(xt()&&M?.(be?n.Direction.Left:n.Direction.Right));if(!J.editMode){let oe=null;switch(R.which){case o.KeyCodes.Left:oe=n.Direction.Left;break;case o.KeyCodes.Right:oe=n.Direction.Right;break;case o.KeyCodes.Up:oe=n.Direction.Up;break;case o.KeyCodes.Down:oe=n.Direction.Down}if(oe)return void xt()}},[J,M]),[se,Pt]=l.useState(!te);l.useEffect(()=>{Pt(!1)},[]);const D=o.useImperativeElement(r,()=>({startEdit(R){let be=R?.initialSelection;if(!be){const ue=X.current.value.length??0;be={start:ue,end:ue,direction:"forward"}}X.current?.setSelectionRange(be.start,be.end,be.direction);const oe={...i,editMode:R?.editMode??!1};R?.text!==void 0&&(oe.dirty=R.text),oe.editMode===i.editMode&&oe.dirty===i.dirty||(P(oe),L?.(oe))},submitEdit:()=>xt(),cancelEdit(){ct()},autoFocus(){X.current?.focus()},getLineHeight:()=>Ve?.maxLineHeight??$e,dispatchEvent:R=>X.current.dispatchEvent(R)}),[i,d]);return ee.jsx("div",{ref:D,...Z,style:{background:"transparent",display:"flex",flexGrow:1,alignSelf:"center",height:Ve.height,maxWidth:"100%",maxHeight:"100%",...B},children:ee.jsx("textarea",{spellCheck:"false",ref:X,value:pe,autoFocus:!1,disabled:se,name:"cell-editor",autoComplete:"off",autoCapitalize:"off",style:{flex:"1 1 100%",position:"relative",fontSize:`${C}px`,fontFamily:`${Le}`,fontWeight:`${Oe}`,fontStyle:`${ce}`,padding:"0px",marginRight:G==="right"?"3px":"0px",marginLeft:G==="left"?"2px":"0px",lineHeight:me,height:Ve.height,textRendering:"geometricPrecision",letterSpacing:"-0.25px",boxSizing:"border-box",borderWidth:0,outline:"none",resize:"none",overflow:"hidden",verticalAlign:"baseline",textAlign:G,background:"transparent",color:K,marginBottom:"0px",userSelect:"text",maxHeight:"100%",whiteSpace:ge==="wrap"?"break-spaces":"pre",wordWrap:"break-word"},onChange:R=>{j(R.target.value)},onDoubleClick:R=>{R.isTrusted},onMouseDown:R=>{St(!0)},onKeyDown:rt})})})),Bn=l.memo(t=>{const{value:r,view:i,bounds:c,range:d,zoom:f,children:a,style:s,...p}=t,O=s?.fontSize||1056/72;return ee.jsx("div",{style:{padding:"2px 4px",fontFamily:"Calibri",letterSpacing:-.25,lineHeight:1.2,fontSize:O,...s},...p,children:r})});exports.BaseGrid=zo,exports.DefaultCellEditor=$n,exports.DefaultCellRenderer=Bn,exports.DefaultHeaderDivider=an,exports.FillHandle=Uo,exports.Grid=Ao,exports.HeaderDivider=On,exports.HeaderRenderer=ln,exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL=150,exports.SELECTION_CLIP_INSETS=It,exports.STANDARD_KEY_CHARS=Lo,exports.SVGLine=Po,exports.SVGRect=en,exports.ScrollableGrid=rn,exports.Selection=Oo,exports.TouchSelectHandle=fo,exports.defaultSelectionRenderer=qo,exports.getDefaultStringEditState=dn,exports.safeSelectionCoords=yt,exports.useCellLayout=Qo,exports.useHeaderSelection=({gridRef:t,gridMainRef:r,orientation:i=n.RangeOrientation.Row,headerCount:c,selectionPolicy:d="multiple",newSelectionMode:f="clear",alwaysScrollToActiveCoords:a=!0,onDragStart:s,onDragEnd:p,pointerDownInterceptor:O,pointerMoveInterceptor:U,onPointerUp:M,newSelection:T,modifySelection:B,appendSelection:te,clearSelections:Z})=>{const X=c??((i===n.RangeOrientation.Row?t.current?.rowCount:t.current?.columnCount)||0),Me=l.useRef(null),J=l.useRef(null),P=l.useRef(!1),G=l.useRef(null),we=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:0},[i]),K=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:r.current?r.current.rowCount-1:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:r.current?r.current.columnCount-1:0},[i]),ge=A=>{J.current=K(A),B(J.current,Me.current)},Le=l.useCallback((A,C)=>{if(!t.current)return;const $e=t.current.getViewFromClient(A,C)?.getCellCoordsFromClient(A,C);return $e?(i===n.RangeOrientation.Column?$e.rowIndex=r.current.getViewport().rowStart:$e.colIndex=r.current.getViewport().colStart,$e):void 0},[]),ye=l.useCallback((A,C=!1)=>{let $e=A;return C||($e={...A},i===n.RangeOrientation.Row?delete $e.colIndex:delete $e.rowIndex),r.current?.scrollCellCoordsIntoView($e)},[i]),Oe=o.useCallbackRef(p,[p]),ce=o.useCallbackRef(s,[s]),pe=l.useMemo(()=>({onPointerDown:A=>{if(!t||!t.current||A.nativeEvent.defaultPrevented)return;const C=Le(A.nativeEvent.clientX,A.nativeEvent.clientY);if(!C)return;A.nativeEvent.which,o.MouseButtonCodes.Right;const $e=A.nativeEvent.shiftKey,Ve=A.nativeEvent.ctrlKey||A.nativeEvent.metaKey;if(O?.(A,C)===!1)return;ce?.(),P.current=!0;const _=r.current?.getViewFromClient(A.nativeEvent.clientX,A.nativeEvent.clientY),me=((q,L)=>i===n.RangeOrientation.Column?{...q,rowIndex:L.rowStart}:{...q,colIndex:L.colStart})(C,_.getVisibleRangeCoords());if($e)ge(C);else{if(Ve)return((q,L=q,j)=>{Me.current=we(q),J.current=K(L),te(Me.current,J.current,j)})(C,C,me),void(a&&ye(me,!0));((q,L=q,j)=>{Me.current=we(q),J.current=K(L),T(Me.current,J.current,j)})(C,C,me),ge(C),a&&ye(me,!0)}},onPointerMoveOrWait:n.CommonUtils.throttle(A=>{if(!P.current||!t?.current)return;const C=Le(A.clientX,A.clientY);if(C&&U?.(A,C)!==!1){if(n.CoordUtils.isEqualCells(G.current,C))return Z();ge(C),ye(C)}},60),onPointerUp:A=>{P.current=!1,Oe?.(),M?.(A)},processTouch:!0,consumeTouch:!0}),[d,a,X,f,Z,O,M]);return{onPointerDown:o.useCallbackRef(o.useSynchronizedPointerHandler(pe),[]),getCellCoordsFromClient:Le}},exports.useKeyboardEditorOverlay=t=>{const{view:r,canEdit:i=gn,getCellEditor:c,onBeforeStartEdit:d,onStartEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,isEditorStartKeyEvent:O=wn,isEditorStartPointerEvent:U=xn,containerProps:M,borderStrokeFill:T,borderStrokeWidth:B=2,getRangeCoords:te=null,activeCoords:Z,alignment:X=o.HorizontalAlignment.Left}=t,[Me,J]=l.useState(!1),[P,G]=l.useState(void 0),we=o.useCallbackRef((D,R,be,oe,ue,ze)=>{if(!R)return null;const Je=ue?.(R,D),mt=D.getRangeCoordsBounds(Je),Qe=D.toClipBounds(mt),Tt=mt,st=D.getZoom();if(!Qe)return null;be&&(be*=st),oe&&(oe*=st);let b=Tt,ne=!1;if(be!==void 0){let qe={...Je},Ht=0;for(;!ne&&b.width<=be&&Ht<20;){Ht++,Ht>19&&console.warn("max width reached");const $t=D.getTotalRangeCoords(),bt=D.getLayout();ze===o.HorizontalAlignment.Left?qe.colEnd+1<$t.colEnd?qe.colEnd=bt.getColIndex(b.x+be):ne=!0:ze===o.HorizontalAlignment.Right?qe.colStart-1>=0?qe.colStart=bt.getColIndex(b.x-(be-b.width)):ne=!0:ze===o.HorizontalAlignment.Center&&qe.colEnd+1<$t.colEnd&&qe.colStart-1>=0?(qe.colStart=bt.getColIndex(b.x-(be-b.width)/2),qe.colEnd=bt.getColIndex(b.x+b.width+(be-b.width)/2)):ne=!0,ne||(b=D.getRangeCoordsBounds(qe))}}b.height=Tt.height,oe!==void 0&&(b.height=Math.max(oe+1,Tt.height));const{width:Ae,height:lt}=D.getViewportSize();return{x:b.x??0,y:b.y??0,height:Math.min(lt-b.y,b.height)+1,width:Math.min(Ae-b.x,b.width)+1}},[X]),K=o.useCallbackRef(i,[i]),ge=l.useCallback(()=>{r?.getStage()?.focus()},[r]),Le=l.useRef(null),ye=o.useCallbackRef(D=>{d?.(D),L(),J(!0),Le.current=null},[d]),Oe=o.useCallbackRef(D=>{f?.(D.coords)},[f]),ce=o.useCallbackRef(D=>{D.isSubmitted||D.isCancelled||(C.current.isEditorClosed=!0,ge(),D.isCancelled=!0,s?.(D.coords),L())},[s]),pe=o.useCallbackRef(D=>{if(D.isSubmitted||D.isCancelled)return!1;try{return Le.current=D.coords,D.isEditorClosing=!0,D.isSubmitted=!0,D.isEditorSubmitted||(D.isEditorSubmitted=!0,D.editorRefs[0]?.submitEdit?.()),D.coords,a?.(D.coords),D.isEditorClosed=!0,ge(),L(),!0}catch(R){throw D.isEditorClosing=!1,D.isSubmitted=!1,R}},[a]),A=o.useCallbackRef(D=>{J(!1),p?.(D.coords),L()},[p]),C=l.useRef(null),$e=l.useRef(null),Ve=l.useRef(null),_=l.useRef([]),[me,q]=l.useReducer(D=>D+1,0),L=l.useCallback(D=>{D&&_.current.push(D),q()},[]),j=o.useCallbackRef(D=>{if(D.defaultPrevented||D.isSynthetic||!r)return;const R=r?.getCellCoordsFromClient(D.clientX,D.clientY);R&&L({eventType:"pointer",event:D,coords:R})},[r]),St=o.useCallbackRef(D=>{const R=D.nativeEvent;j(R)},[r]),xt=o.useCallbackRef(D=>{if(D.defaultPrevented||D.isSynthetic||!r?.getStage())return;const R=$e.current;O(D,R)&&(D.stopPropagation(),D.preventDefault()),D.key,L({eventType:"keyboard",event:D,coords:R})},[r]);l.useLayoutEffect(()=>{const D=(oe,ue)=>{const ze=ue?.cell??oe;if(!ze)return null;const Je=ze;if(!K(ze))return null;ye?.(ze);const mt=n.CommonUtils.uuidV4();ue=Object.freeze({autoFocus:!0,...ue}),Ve.current=ze;const Qe={coords:Je,startEvent:ue,uuid:mt,isMounted:!1,isStarted:!1,isSubmitted:!1,isEditorSubmitted:!1,isEditorClosing:!1,isEditorClosed:!1,isCancelled:!1,events:[],editorRefsDispatchEditorEvent:[],editorRefs:[],onMount:Tt=>{Qe.isMounted||(Qe.isMounted=!0,L())},onUnmount:Tt=>{if(Qe.editorRefs.length===0){const st=()=>{Qe.isMounted=!1,L()};if(document.activeElement!==document.body)st();else{const b=ne=>{ne.defaultPrevented||ne.target!==document.body||xt(ne)};window.addEventListener("keydown",b,!0),r.getStage()?.addEventListener("focusin",()=>{window.removeEventListener("keydown",b),st()},mn),ge()}}}};return Qe};if(_.current.length<=0&&!C.current)return;const R=_.current[0];Ko(R),(oe=>{const ue=[],ze=oe?.length??0;for(let Je=0;Je<ze;Je++){const mt=oe[Je];ue.push(Ko(mt))}})(_.current),C.current,C.current;let be=C.current;if(C.current){if(C.current.isDone)C.current=null;else if(C.current.isSubmitted||C.current.isCancelled){if(C.current.isMounted)return;C.current.isDone||(A(C.current),C.current.isDone=!0)}}if(R){if(R.eventType==="start"){const oe=R,ue=oe.startEvent?.cell??$e.current;C.current&&n.CoordUtils.isEqualCells(C.current.coords,ue)||(C.current=D(ue,oe.startEvent))}else if(R.eventType==="keyboard"){const oe=R.event;if(C.current){let ue=!1;switch(oe.which){case o.KeyCodes.Left:case o.KeyCodes.Right:case o.KeyCodes.Up:case o.KeyCodes.Down:case o.KeyCodes.Enter:case o.KeyCodes.Tab:ue=!0}if(!ue){C.current.events.push(R);for(let ze=0;ze<C.current.editorRefsDispatchEditorEvent.length;ze++)C.current.editorRefsDispatchEditorEvent[ze](R)}}else if(O(oe,R.coords)){let ue;const ze=D(ue?.cell??$e.current,ue);ze&&ze.events.push(R),C.current=ze}}else if(R.eventType==="pointer"){const oe=R.event;if(C.current){C.current.events.push(R);for(let ue=0;ue<C.current.editorRefsDispatchEditorEvent.length;ue++)C.current.editorRefsDispatchEditorEvent[ue](R)}else{const ue=R?.coords??$e.current,ze=U(oe,ue);if(ze){let Je;typeof Je!="boolean"&&(Je=ze);const mt=D(ue,Je);mt&&mt.events.push(R),C.current=mt}}}else if(R.eventType==="submit"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;pe(C.current)}}else if(R.eventType==="cancel"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;ce(C.current)}}else if(R.eventType==="coordsChange"){const oe=R;if($e.current=oe.activeCoords,C.current,C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;try{pe(C.current)}catch{}}}}_.current.length>0&&(_.current.shift(),L()),_.current.length===0&&(!C.current||C.current.isEditorClosing||C.current.isEditorClosed?!C.current&&be&&ge():C.current.isMounted&&!C.current.isStarted&&(C.current.isStarted=!0,C.current.startEvent.autoFocus&&(typeof C.current.startEvent.autoFocus=="string"?C.current.editorRefs[0]?.autoFocus(C.current.startEvent.autoFocus):C.current.editorRefs[0]?.autoFocus()),Oe?.(C.current),requestAnimationFrame(()=>{r&&C.current?.coords&&r.scrollCellCoordsIntoView(C.current.coords)})))},[me]),l.useEffect(()=>{Ve.current=Z;const D=C.current?.coords;n.CoordUtils.isEqualCells(D,Z)||(C.current&&(C.current.isEditorClosing=!0),L({eventType:"coordsChange",activeCoords:Z}))},[Z]);const ct=l.useCallback(D=>{xt(D.nativeEvent)},[]),{width:rt=0,height:se=0}=P??{width:0,height:0},Pt=o.useCallbackRef(c,[c]);return{overlay:o.useCallbackRef(D=>{if(!C.current||C.current.isEditorClosed)return C.current,null;C.current.coords;let R=we(D,C.current.coords,rt,se,te,X),be=!0;R&&R.width!==0&&R.height!==0||(R={x:0,y:0,width:rt,height:rt},be=!1);const oe=D.getZoom(),ue={containerBounds:{x:0,y:0,width:R.width/oe,height:R.height/oe},setNaturalSize:G,zoom:oe};return ee.jsx(pn,{session:C.current,refLatestCoords:Ve,handleSubmitEdit:pe,handleCancelEdit:ce,cellBounds:R,borderStrokeWidth:B,borderStrokeFill:T,isInBounds:be,getCellEditor:Pt,propsEditor:ue,alignment:X,...M},"editor:"+C.current.uuid)},[c,te,me,rt,se,X,B,T]),startEdit:l.useCallback(D=>{L({eventType:"start",startEvent:D})},[]),submitEdit:l.useCallback(()=>{L({eventType:"submit"})},[]),cancelEdit:l.useCallback(()=>{L({eventType:"cancel"})},[]),onKeyboardEvent:ct,onPointerEvent:St,onKeyboardEventNative:xt,onPointerEventNative:j,isEditing:Me}},exports.useSelection=({gridRef:t,commands:r,layout:i,selection:c,onSelectionChange:d,onSelectionDragStart:f,onSelectionDragEnd:a,selectionPolicy:s="multiple",newSelectionMode:p="clear",allowDeselectSelection:O=!0,onFillPreview:U,onFillCancel:M,onFillDone:T,onFill:B,disableFillDrag:te=!B,fillHandleBorderColor:Z="white",hiddenRowsAt:X,hiddenColumnsAt:Me,isContentfulCell:J,contentfulCellFinder:P=bn,getDataCoords:G,alwaysScrollToActiveCoords:we=!1,selectionBounds:K,pointerDownInterceptor:ge,pointerMoveInterceptor:Le,mergedRanges:ye,canSelectionSpanMergedCells:Oe=In,onMoveDragStart:ce,onMoveDragUpdate:pe,onMoveDragEnd:A,onMoveDragDone:C,selectionRenderer:$e=qo,disableMoveDrag:Ve=!A,getCellCoordsAsRangeCoords:_=n.CoordUtils.cellToRange,moveDragHitSize:me=6,moveDragOutlineSize:q=4,selectionBackgroundColor:L="rgba(16, 124, 65, 0.1)",selectionBorderColor:j="rgb(33, 115, 70)",selectionRemoveBorderColor:St="rgb(255, 0, 0)",selectionRemoveBackgroundColor:xt="rgba(250, 10, 10, 0.1)",disableTouchSelection:ct=!1,touchSelectHandleProps:rt})=>{const se=l.useCallback(()=>({top:K?.top??0,left:K?.left??0,bottom:t.current?.rowCount-1||0,right:t.current?.columnCount-1||0}),[]),Pt=o.useCallbackRef(B,[B]),D=o.useCallbackRef(U,[U]),R=o.useCallbackRef(M,[M]),be=o.useCallbackRef(T,[T]),oe=o.useCallbackRef(J,[J]),ue=o.useCallbackRef($e,[$e]),ze=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getRowOffset,u?se().bottom:se().top),[i?.getRowOffset]),Je=o.useCallbackRef(X??ze,[X]),mt=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getColOffset,u?se().right:se().left),[i?.getColOffset]),Qe=o.useCallbackRef(Me??mt,[Me]),[Tt,st]=l.useState(()=>yt(c)),b=l.useMemo(()=>yt(Tt),[Tt]),ne=l.useRef(b),Ae=l.useRef(!0);l.useLayoutEffect(n.CommonUtils.throttle(()=>{st(e=>{Ae.current=!0;const u=yt(c);return n.CoordUtils.isEqualSelectionCoords(u,e)?e:u})},0),[c]),l.useLayoutEffect(()=>{ne.current=b},[b]),l.useEffect(()=>{Ae.current||!d||n.CoordUtils.isEqualSelectionCoords(c,b)||d(b)},[b]);const lt=l.useCallback(e=>{st(u=>{Ae.current=!1,u=yt(u);let g=typeof e=="function"?e(u.ranges):e??To;if(n.CoordUtils.isEqualRangesArrays(g,u.ranges))return u;let h=Math.max(g.length?0:-1,Math.min(u.rangeIndex,g.length-1)),x=u.cell;h===-1||n.CoordUtils.isCellWithinRange(x,g[h])||(x={rowIndex:g[h].rowStart,colIndex:g[h].colStart}),g.length===1&&n.CoordUtils.isSingleCell(g[0])&&n.CoordUtils.isCellWithinRange(x,g[0])&&(g=[],h=-1);const k={cell:x,ranges:g,rangeIndex:h};return n.CoordUtils.isEqualSelectionCoords(k,u)?u:k})},[]),qe=o.useCallbackRef(e=>{st(u=>{Ae.current=!1,u=yt(u);const g=e??on,h=_(g);if(!n.CoordUtils.isSingleCell(h)&&u.ranges.length===0)return{ranges:[h],rangeIndex:0,cell:g};if(n.CoordUtils.isEqualCells(g,u.cell))return u;let x=u.ranges,k=u.rangeIndex;u.ranges.length===1&&(n.CoordUtils.isSingleCell(u.ranges[0])&&n.CoordUtils.isCellWithinRange(g,u.ranges[0])||!n.CoordUtils.isCellWithinRange(g,u.ranges[0]))&&(x=[],k=-1);const m={ranges:x,rangeIndex:k,cell:g};return n.CoordUtils.isEqualSelectionCoords(m,u)?u:m})},[_]),[Ht,$t]=l.useState(null),[bt,Xt]=l.useState(null),At=l.useRef(null),[Re,Ut]=l.useState(null),ut=l.useRef(null),kt=l.useRef(null),[eo,jt]=l.useState(null),He=l.useRef(null),Be=l.useRef(null),Ft=l.useRef(ye);l.useEffect(()=>{Ft.current=ye},[ye]);const ht=o.useCallbackRef((e,u={inline:"nearest",block:"nearest"})=>{let{rowIndex:g,colIndex:h}=e;g===void 0&&b?.cell&&(g=b.cell.rowIndex),h===void 0&&b?.cell&&(h=b.cell.colIndex),g!==void 0&&h!==void 0&&t.current?.scrollCellCoordsIntoView({rowIndex:g,colIndex:h},u)},[b]),Lt=l.useCallback(e=>{const u=se();return e.rowIndex<u.top||e.colIndex<u.left||e.colIndex>u.right||e.rowIndex>u.bottom},[]),ve=o.useCallbackRef((e,u)=>{if(!t?.current)return null;const g={rowStart:Math.min(e.rowIndex,u.rowIndex),colStart:Math.min(e.colIndex,u.colIndex),rowEnd:Math.max(e.rowIndex,u.rowIndex),colEnd:Math.max(e.colIndex,u.colIndex)};if(Oe?.(g))return g;const x=_(e),k=_(u),m={rowStart:Math.min(x.rowStart,k.rowStart),colStart:Math.min(x.colStart,k.colStart),rowEnd:Math.max(x.rowEnd,k.rowEnd),colEnd:Math.max(x.colEnd,k.colEnd)};let N;return typeof Ft.current=="function"?N=Ft.current(m):ye&&(N=ye),N?n.CoordUtils.extendRangeToUnionRanges(m,N):m},[Oe,_]),je=o.useCallbackRef((e,u,g)=>{const h=e.ranges.length>0?e.ranges[e.rangeIndex]:{rowStart:e.cell.rowIndex,colStart:e.cell.colIndex,rowEnd:e.cell.rowIndex,colEnd:e.cell.colIndex},x={rowStart:Math.min(u.rowIndex??h.rowStart,g.rowIndex??h.rowStart),colStart:Math.min(u.colIndex??h.colStart,g.colIndex??h.colStart),rowEnd:Math.max(u.rowIndex??h.rowEnd,g.rowIndex??h.rowEnd),colEnd:Math.max(u.colIndex??h.colEnd,g.colIndex??h.colEnd)},k={rowIndex:x.rowStart,colIndex:x.colStart},m={rowIndex:x.rowEnd,colIndex:x.colEnd};if(!(Lt(k)||Lt(m)))return ve(k,m)},[ve]),it=o.useCallbackRef((e,u,g)=>{if(s==="single"||!ne.current)return;const h=je(ne.current,e,u??ne.current.cell);if(!h)return;const x=ne.current.rangeIndex;lt(k=>k.length?k.map((m,N)=>x===N?h:m):[h]),g&&h&&qe({colIndex:h.colStart,rowIndex:h.rowStart})},[]),pt=l.useCallback((e,u,g)=>{if(!ne.current)return;e={...ne.current?.cell,...e},u=u??e;const h=je(ne.current,e,u);if(!h)return;const x={rowIndex:h.rowStart,colIndex:h.colStart},k={...x,...g};p==="clear"?(He.current=k,Bt()):p==="modify"?it(x):Ce(x),qe(k)},[]),Ce=l.useCallback((e,u=e,g)=>{s!=="multiple"||!e||Lt(e)||Lt(u)||st(h=>{Ae.current=!1,h=yt(h);const x=ve(e,u);if(!x)return h;let k=h.ranges.length>0?[...h.ranges]:[ve(h.cell,h.cell)];k.push(x);const m={ranges:k,cell:{rowIndex:x.rowStart,colIndex:x.colStart,...g},rangeIndex:k.length-1};return n.CoordUtils.isEqualSelectionCoords(m,h)?h:m})},[]),Bt=()=>{lt(To)},Rt=o.ReactUtils.detectIt().primaryInput==="touch",_e=l.useRef(null),Ct=l.useRef(null),vt=l.useRef(null),Nt=l.useMemo(()=>({onPointerDown:e=>{if(!t||!t.current)return!1;const u=e.nativeEvent,g=t.current.getViewFromClient(u.clientX,u.clientY);if(u.pointerType==="touch"||u.type==="touchstart")return Ct.current={topLeft:g.getScrollTopLeft(),point:{x:u.clientX,y:u.clientY}},!0;const h=g.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return!1;_e.current={anchor:g.getAnchor(),coords:h},Be.current=null;const x=e.nativeEvent.which===o.MouseButtonCodes.Right;if(x&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1)return!1;const k=e.nativeEvent.shiftKey,m=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,N=m,$=O,W=b.ranges.length>0,Y=m&&$;if(ge?.(e,h,b)===!1)return!1;f?.(ne.current,e);const xe=!x&&s!=="single";if(k)return it(h),xe;const H=n.CoordUtils.isEqualCells(h,b.cell);if(N){if(H&&(!Y||!W))return xe;if(m&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1&&$){ut.current=h;const V=ve(h,h);return kt.current=V,Ut(V),xe}return Ce(h),xe}we&&ht(h),H&&b.ranges.length===0||pt(h)},onPointerMoveOrWait:n.CommonUtils.throttle((e,u)=>{if(!t?.current||e.pointerType==="touch"||e.type==="touchmove"||!_e.current)return;const g=_e.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(x,_e.current?.coords)&&(_e.current={anchor:g,coords:x},x&&Le?.(e,x,ne.current)!==!1)){if(ut.current){const k={rowStart:Math.min(x.rowIndex,ut.current.rowIndex),colStart:Math.min(x.colIndex,ut.current.colIndex),rowEnd:Math.max(x.rowIndex,ut.current.rowIndex),colEnd:Math.max(x.colIndex,ut.current.colIndex)},m={rowIndex:k.rowStart,colIndex:k.colStart},N={rowIndex:k.rowEnd,colIndex:k.colEnd};if(Lt(m)||Lt(N))return;const $=ve(m,N);kt.current=$,Ut($)}else it(x);vt.current=u,ho(h,x,t)}},60),onPointerUp:e=>{if(_e.current=null,e.pointerType==="touch"||e.type==="touchend"){if(Ct.current){const g=t.current.getViewFromClient(Ct.current.point.x,Ct.current.point.y),h=g.getScrollTopLeft();if(h.left===Ct.current.topLeft.left&&h.top===Ct.current.topLeft.top){const x=g.getCellCoordsFromClient(Ct.current.point.x,Ct.current.point.y);pt(x)}}return Ct.current=null,void(_e.current=null)}try{a?.(ne.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})},processTouch:!0,consumeTouch:!1}),[b,s,O,we,p]),xo=o.useCallbackRef(o.useSynchronizedPointerHandler(Nt),[]),po=l.useMemo(()=>({onSelectionPointerDown:(e,u,g,h,x=b.cell,k=we,m=e.nativeEvent.shiftKey,N=!1)=>{if(!t||!t.current)return!1;e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();const $=g??t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),W=h??$.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!W)return!1;_e.current={anchor:$.getAnchor(),coords:W},Be.current=null;const Y=e.nativeEvent.which===o.MouseButtonCodes.Right;if(Y&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1)return!1;const xe=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,H=xe,V=O,nt=b.ranges.length>0,I=xe&&V;if(ge?.(e,W,b)===!1)return!1;f?.(ne.current,e);const fe=!Y&&s!=="single";if(m)return it(W,x,N),fe;const wt=n.CoordUtils.isEqualCells(W,x);if(H){if(wt&&(!I||!nt))return fe;if(I&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1&&V){ut.current=W;const de=ve(W,W);return kt.current=de,Ut(de),fe}return Ce(W),fe}k&&ht(W),wt&&b.ranges.length===0||pt(W)},onSelectionPointerMoveOrWait:(e,u,g,h,x,k=b.cell,m=!0,N=!1)=>{if(!t?.current||(e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation(),!_e.current))return;const $=_e.current.anchor;let W=h??t.current.getViewFromLocation($),Y=x??W.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(Y,_e.current?.coords)&&(_e.current={anchor:$,coords:Y},Y&&Le?.(e,Y,ne.current)!==!1)){if(ut.current){const xe={rowStart:Math.min(Y.rowIndex,ut.current.rowIndex),colStart:Math.min(Y.colIndex,ut.current.colIndex),rowEnd:Math.max(Y.rowIndex,ut.current.rowIndex),colEnd:Math.max(Y.colIndex,ut.current.colIndex)},H={rowIndex:xe.rowStart,colIndex:xe.colStart},V={rowIndex:xe.rowEnd,colIndex:xe.colEnd};if(Lt(H)||Lt(V))return;const nt=ve(H,V);kt.current=nt,Ut(nt)}else it(Y,k,N);m&&ho(W,Y,t)}},onPointerUp:e=>{_e.current=null,e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();try{a?.(ne.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})}}),[b,s,O,we,p]),Ze=o.useCallbackRef((e,u=!1,g=!1,h=0)=>{if(!t.current||!b.cell)return;let x=b.cell,k=b.cell;if(u&&b.ranges.length>0){const I=b.ranges[b.rangeIndex],fe=b.cell;switch(e){case n.Direction.Up:k={rowIndex:fe.rowIndex===I.rowStart?I.rowEnd:I.rowStart,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowStart?I.rowStart:I.rowEnd,colIndex:I.colStart};break;case n.Direction.Down:k={rowIndex:fe.rowIndex===I.rowEnd?I.rowStart:I.rowEnd,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowEnd?I.rowEnd:I.rowStart,colIndex:I.colStart};break;case n.Direction.Left:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colStart?I.colEnd:I.colStart},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colStart?I.colStart:I.colEnd};break;case n.Direction.Right:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colEnd?I.colStart:I.colEnd},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colEnd?I.colEnd:I.colStart}}}const m=_(k);let{rowStart:N,colStart:$}=m;const W=se();if(Be.current)switch(e){case n.Direction.Up:case n.Direction.Down:Be.current.colIndex>=m.colStart&&Be.current.colIndex<=m.colEnd&&($=Be.current.colIndex);break;case n.Direction.Left:case n.Direction.Right:Be.current.rowIndex>=m.rowStart&&Be.current.rowIndex<=m.rowEnd&&(N=Be.current.rowIndex)}if(!h){switch(e){case n.Direction.Up:N=Te(Je,Math.max(m.rowStart-1,W.top),e);break;case n.Direction.Down:N=Te(Je,Math.min(m.rowEnd+1,W.bottom),e);break;case n.Direction.Left:$=Te(Qe,Math.max(m.colStart-1,W.left),e);break;case n.Direction.Right:$=Te(Qe,Math.min(m.colEnd+1,W.right),e)}if(g)switch(e){case n.Direction.Up:N=P({...k,colIndex:b.cell.colIndex},oe,Je,e,!1,Math.max(W.top,Je(W.top,!1)));break;case n.Direction.Down:N=P({...k,colIndex:b.cell.colIndex},oe,Je,e,!1,Math.min(W.bottom,W.bottom-Je(W.bottom,!0)));break;case n.Direction.Left:$=P({...k,rowIndex:b.cell.rowIndex},oe,Qe,e,!1,Math.max(W.left,Qe(W.left,!1)));break;case n.Direction.Right:$=P({...k,rowIndex:b.cell.rowIndex},oe,Qe,e,!1,Math.min(W.right,W.right-Qe(W.right,!0)))}}let Y=null;if(h){let I=0;switch(e){case n.Direction.Up:I=i.getRowOffset(N+1),N=Math.max(W.top,i.getRowIndex(I-h)),Y={top:i.getRowOffset(N+1)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Down:I=i.getRowOffset(N),N=Math.min(W.bottom,i.getRowIndex(I+h)),Y={top:i.getRowOffset(N)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Left:I=i.getColOffset($+1),$=Math.max(W.left,i.getColIndex(I-h)),Y={left:i.getColOffset($+1)-(I-t.current.getScrollPosition().left)};break;case n.Direction.Right:I=i.getColOffset($),$=Math.min(W.right,i.getColIndex(I+h)),Y={left:i.getColOffset($)-(I-t.current.getScrollPosition().left)}}}const xe={rowIndex:N,colIndex:$},H=_(xe),V={rowIndex:H.rowStart,colIndex:H.colStart};u||(Be.current=xe);const nt=n.CoordUtils.isEqualCells(He.current,V)&&n.CoordUtils.isEqualCells(He.current,x);if(u&&!nt?it(V,x):pt(V),Y)t.current.scrollTo(Y);else{if(u&&He.current){const I=se();if(e===n.Direction.Right&&He.current.colIndex===I.left||e===n.Direction.Left&&He.current.colIndex===I.right||e===n.Direction.Up&&He.current.rowIndex===I.bottom||e===n.Direction.Down&&He.current.rowIndex===I.top)return}e===n.Direction.Left||e===n.Direction.Right?ht({colIndex:xe.colIndex}):e!==n.Direction.Up&&e!==n.Direction.Down||ht({rowIndex:xe.rowIndex})}},[b,_]),Ot=o.useCallbackRef(e=>{if(!t.current)return;if(b.ranges.length===0)return void Ze(e);const u=_(b.cell);if(n.CoordUtils.isEqualRangesArrays([u],b.ranges))return void Ze(e);const g=Do(b,e,_,Je,Qe);st(h=>{Ae.current=!1,h=yt(h);const x={...h,cell:g.cell,rangeIndex:g.rangeIndex};return n.CoordUtils.isEqualSelectionCoords(x,h)?h:x}),g.cell&&ht(g.cell)},[b,_]),mo=l.useCallback(()=>{const e=se();it({rowIndex:e.top},{rowIndex:e.bottom})},[]),Co=l.useCallback(()=>{const e=se();it({colIndex:e.left},{colIndex:e.right})},[]),Kt=o.useCallbackRef(()=>{b.cell&&t?.current&&ht(b.cell)},[b.cell]),to=l.useCallback((e=!1)=>{const u={rowIndex:se().top};e?it(u):pt(u),ht(u)},[]),oo=l.useCallback((e=!1)=>{const u={rowIndex:se().bottom};e?it(u):pt(u),ht(u)},[]),Gt=l.useCallback((e=!1)=>{const u={colIndex:se().left};e?it(u):pt(u),ht(u)},[]),qt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:u.top,colIndex:u.left};e?it(g):pt(g),ht(g)},[]),_t=l.useCallback((e=!1)=>{const u=se(),g={colIndex:G?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[G]),Wt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:G?.()?.rowEnd??u.bottom,colIndex:G?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[G]),Zt=o.useCallbackRef(e=>{if(!t.current||b.ranges.length<=1)return;const u=e===n.Direction.Left||e===n.Direction.Up;let g=b.rangeIndex+(u?-1:1);g<0?g=b.ranges.length-1:g>b.ranges.length-1&&(g=0);const h=b.ranges[g],x=Do({cell:{rowIndex:h.rowEnd,colIndex:h.colEnd},rangeIndex:0,ranges:[h]},n.Direction.Right,_,Je,Qe);st(k=>{Ae.current=!1,k=yt(k);const m={...k,cell:x.cell,rangeIndex:g};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x.cell&&ht(x.cell)},[b,_]),So=o.useCallbackRef(()=>{const e=Vo(b);st(u=>{Ae.current=!1,u=yt(u);const g={...u,visibleSelection:e};return n.CoordUtils.isEqualSelectionCoords(g,u)?u:g}),e.cell&&ht(e.cell)},[b,_]),bo=o.useCallbackRef(()=>{if(!t.current||b.ranges.length===0)return;const e=b.cell,u=b.ranges[b.rangeIndex],g=Vo({cell:e,rangeIndex:0,ranges:[u]}),h=g.ranges[g.rangeIndex];let x;x=h.rowStart===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowStart,colIndex:h.colEnd}:h.rowStart===e.rowIndex&&h.colEnd===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colStart}:h.rowEnd===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colEnd}:{rowIndex:h.rowStart,colIndex:h.colStart},st(k=>{k=yt(k);const m={...k,cell:x};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x&&ht(x)},[b,_]),no=l.useCallback((e=!1)=>{Ze(n.Direction.Down,e,!1,t.current.getDimensions().containerHeight)},[]),Mt=l.useCallback((e=!1)=>{Ze(n.Direction.Up,e,!1,t.current.getDimensions().containerHeight)},[]),ro=l.useCallback((e=!1)=>{Ze(n.Direction.Right,e,!1,t.current.getDimensions().containerWidth)},[]),Jt=l.useCallback((e=!1)=>{Ze(n.Direction.Left,e,!1,t.current.getDimensions().containerWidth)},[]),lo=l.useCallback(()=>{Ot(n.Direction.Left)},[]),io=l.useCallback(()=>{Ot(n.Direction.Right)},[]),vo=l.useCallback(()=>{Ot(n.Direction.Up)},[]),yo=l.useCallback(()=>{Ot(n.Direction.Down)},[]),Qt=l.useCallback(()=>{Zt(n.Direction.Left)},[]),Ro=l.useCallback(()=>{Zt(n.Direction.Right)},[]),Eo=l.useCallback(()=>{bo()},[]),co=l.useCallback(()=>{Ze(n.Direction.Left,!1,!1)},[]),w=l.useCallback(()=>{Ze(n.Direction.Left,!0,!1)},[]),S=l.useCallback(()=>{Ze(n.Direction.Left,!1,!0)},[]),E=l.useCallback(()=>{Ze(n.Direction.Left,!0,!0)},[]),v=l.useCallback(()=>{Ze(n.Direction.Right,!1,!1)},[]),y=l.useCallback(()=>{Ze(n.Direction.Right,!0,!1)},[]),z=l.useCallback(()=>{Ze(n.Direction.Right,!1,!0)},[]),he=l.useCallback(()=>{Ze(n.Direction.Right,!0,!0)},[]),re=l.useCallback(()=>{Ze(n.Direction.Up,!1,!1)},[]),ae=l.useCallback(()=>{Ze(n.Direction.Up,!0,!1)},[]),F=l.useCallback(()=>{Ze(n.Direction.Up,!1,!0)},[]),Se=l.useCallback(()=>{Ze(n.Direction.Up,!0,!0)},[]),Ke=l.useCallback(()=>{Ze(n.Direction.Down,!1,!1)},[]),Pe=l.useCallback(()=>{Ze(n.Direction.Down,!0,!1)},[]),Ne=l.useCallback(()=>{Ze(n.Direction.Down,!1,!0)},[]),Ee=l.useCallback(()=>{Ze(n.Direction.Down,!0,!0)},[]),le=l.useCallback(()=>{lt(e=>e.slice(0,-1))},[]),et=l.useMemo(()=>{const e=se();return((u,g,h,x,k)=>{const m=u.length;for(let N=0;N<m;N++){const $=u[N];if($.rowStart===g&&$.colStart===h&&$.rowEnd===x&&$.colEnd===k)return!0}return!1})(b.ranges,e.top,e.left,e.bottom,e.right)},[K,b.ranges]),Ye=l.useCallback((e,u=!0)=>{He.current=e,qe(e),u&&e&&t?.current&&ht(e)},[]),Ue=o.useCallbackRef((e=!0)=>{const u=At.current;if(!ne.current?.cell)return;const g=ne.current?.ranges,h=ne.current?.cell;if(!h||!u||!u)return;let x=null;if(x=g.length>0?g[g.length-1]:_(h),x.colEnd>=x.colStart&&x.rowEnd>=x.rowStart){const k=Ho(x,u);let m=e?Pt:D;try{m?.(x,u,k.direction)}catch(N){console.warn(N)}finally{e&&be?.()}}},[_]),Xe=l.useRef(null),ft=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);h&&(e.stopPropagation(),$t("crosshair"),Xe.current={anchor:g.getAnchor(),coords:h})},onPointerMoveOrWait:(e,u)=>{if(te||!t?.current||!ne.current||!Xe.current)return;const g=Xe.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!x)return;Xe.current={anchor:g,coords:x};const k=ne.current.ranges;let m=ve(ne.current.cell,x);if(!m)return;const N=k.length>0,$=N?k[k.length-1]:_(ne.current.cell);if(!m)return;const W=m.rowStart<$.rowStart?n.Direction.Up:m.rowEnd>$.rowEnd?n.Direction.Down:m.colEnd>$.colEnd?n.Direction.Right:n.Direction.Left,Y=se();W===n.Direction.Left&&(m={...$,colStart:Math.max(Y.left,m.colStart)}),W===n.Direction.Up&&(m={...$,rowStart:Math.max(Y.top,m.rowStart)}),W===n.Direction.Right&&(m={...$,colEnd:Math.min(Y.right,m.colEnd)}),W===n.Direction.Down&&(m={...$,rowEnd:Math.min(Y.bottom,m.rowEnd)});const xe=Ho($,m);if(!Oe?.($)){let H;typeof Ft.current=="function"?H=Ft.current($):ye&&(H=ye),m=((V,nt,I,fe,wt,de)=>{const ie={...nt};if(I.length===0)return ie;if(wt===n.Direction.Left){const ot=V.colEnd+1-V.colStart;ie.colStart=V.colStart-Math.ceil(de/ot)*ot,ie.colStart<fe.left&&(ie.colStart=ie.colStart+Math.ceil((fe.left-ie.colStart)/ot)*ot)}else if(wt===n.Direction.Right){const ot=V.colEnd+1-V.colStart;ie.colEnd=V.colEnd+Math.ceil(de/ot)*ot,ie.colEnd>fe.right&&(ie.colEnd=ie.colEnd-Math.ceil((fe.right-ie.colEnd)/ot)*ot)}else if(wt===n.Direction.Up){const ot=V.rowEnd+1-V.rowStart;ie.rowStart=V.rowStart-Math.ceil(de/ot)*ot,ie.rowStart<fe.top&&(ie.rowStart=ie.rowStart+Math.ceil((fe.top-ie.rowStart)/ot)*ot)}else if(wt===n.Direction.Down){const ot=V.rowEnd+1-V.rowStart;ie.rowEnd=V.rowEnd+Math.ceil(de/ot)*ot,ie.rowEnd>fe.bottom&&(ie.rowEnd=ie.rowEnd-Math.ceil((fe.bottom-ie.rowEnd)/ot)*ot)}return ie})($,m,H,Y,xe.direction,xe.amount)}if(N&&n.CoordUtils.isRangeWithinRange(m,$)&&(m=null),!n.CoordUtils.isEqualRanges(m,At.current)){if(Xt(m),At.current=m,!m){try{R?.()}catch{}return void be?.()}Ue(!1)}vt.current=u,ho(h,x,t)},onPointerUp:(e,u)=>{vt.current=u,Promise.resolve(Ue(!0)).finally(()=>{be?.(),Xt(null),At.current=null,Xe.current=null,$t(null),t.current?.focus()})}}),[_]),Fe=o.useSynchronizedPointerHandler(ft),Q=l.useMemo(()=>({onPointerDown:Fe}),[Fe]),[We,at]=l.useState(null),Ie=l.useRef(null),Ge=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return;if(ge?.(e,h,b)===!1)return!1;e.stopPropagation(),$t("default");const x=g.getRelativePointFromClient(0,0),k=ne.current?.ranges[ne.current?.ranges.length-1]??n.CoordUtils.cellToRange(ne.current?.cell),m=g.toClipBounds(g.getRangeCoordsBounds(k)),N={x:0,y:0};m.x-x.x>e.nativeEvent.clientX?N.x=e.nativeEvent.clientX-(m.x-x.x):e.nativeEvent.clientX>=m.x-x.x+m.width&&(N.x=Math.max(0,e.nativeEvent.clientX-(m.x-x.x+m.width))+1),m.y-x.y>e.nativeEvent.clientY?N.y=e.nativeEvent.clientY-(m.y-x.y):e.nativeEvent.clientY>=m.y-x.y+m.height&&(N.y=Math.max(0,e.nativeEvent.clientY-(m.y-x.y+m.height))+1),ce?.(k,e,u),Ie.current={range:k,anchor:g.getAnchor(),cell:h,isMoving:!1,extrusion:N}},onPointerMoveOrWait:(e,u,g)=>{if(Ve||!t?.current||!ne.current||!Ie.current)return;const h=e.clientX-g.clientX,x=e.clientY-g.clientY;if(Ie.current.isMoving=Ie.current.isMoving||Math.abs(h)>Math.max(1,2)||Math.abs(x)>Math.max(1,2)||performance.now()-g.timeStamp>500,!Ie.current.isMoving)return;const k=Ie.current.anchor,m=Ie.current.extrusion;let N=t.current.getViewFromLocation(k),$=N.getCellCoordsFromClient(e.clientX-m.x,e.clientY-m.y,!0);if(!$)return;const W=Ie.current.cell,Y=Ie.current.range,xe=se(),H=Y.colEnd-Y.colStart+1,V=Math.min(Math.max(0,W.colIndex-Y.colStart),H-1),nt=Math.min(xe.right-H+1,Math.max(xe.left,$.colIndex-V)),I=Y.rowEnd-Y.rowStart+1,fe=Math.min(Math.max(0,W.rowIndex-Y.rowStart),I-1),wt=Math.min(xe.bottom-I+1,Math.max(xe.top,$.rowIndex-fe)),de={colStart:nt,colEnd:nt+H-1,rowStart:wt,rowEnd:wt+I-1};n.CoordUtils.isEqualRanges(We,de)&&!(ie=>!ie||!vt.current||vt.current.ctrlKey!==ie.ctrlKey||vt.current.shiftKey!==ie.shiftKey||vt.current.altKey!==ie.altKey||vt.current.metaKey!==ie.metaKey)(e)||(at(de),pe?.(de,e,u)),vt.current=u,ho(N,$,t)},onPointerUp:(e,u)=>{vt.current=u;const g=()=>{at(null),Ie.current=null,$t(null),t.current?.focus()};if(!Ie.current)return void g();const h=Ie.current.range,x=We;A?.(h,e,u),Promise.resolve(h&&x&&C?.(h,x,e,u)).finally(()=>{g()})}}),[We]),De=o.useSynchronizedPointerHandler(Ge),ke=l.useMemo(()=>({onPointerDown:De}),[De]),dt=l.useRef(null),tt=l.useMemo(()=>{const e=n.CoordUtils.isEqualSelectionCoords(b,dt.current)?dt.current:b;return dt.current=e,e},[b]),gt=l.useCallback(e=>{let u=null,g="br";const h=[],x={stroke:Z,fill:L,strokeWidth:.5},k=(H,V,nt)=>{const I=e.toClipBounds(e.getRangeCoordsBounds(H),It);if(!I)return;I.x=I.width>0?I.x:I.x-x.strokeWidth/2,I.y=I.height>0?I.y:I.y-x.strokeWidth/2,I.width=Math.max(I.width,x.strokeWidth),I.height=Math.max(I.height,x.strokeWidth);const fe={key:`selection-fill-${V}`,range:H,...I,...x};if(nt){const wt=e.getCellCoordsAsRangeCoords(nt);fe.cell=nt,fe.pathBounds=e.toClipBounds(e.getRangeCoordsBounds(wt),It),fe.pathBounds&&(fe.pathBounds.width<=0||fe.pathBounds.height<=0)&&(delete fe.pathBounds,delete fe.cell)}return ue(fe)};let m=b?yt(b):null;const N=m?.cell?e.getCellCoordsAsRangeCoords(m?.cell):En;!m||m.ranges&&m.ranges.length!==0||(m={ranges:[N],rangeIndex:0,cell:m.cell});for(let H=0;m&&H<m.ranges.length;H++){const V=m.ranges[H],nt=k(V,H,H===m.rangeIndex?m.cell:null);nt&&h.push(nt);const I=2,fe=.5,wt=e.toClipBounds(e.getRangeCoordsBounds(V,{top:0,left:0,right:0,bottom:0}),It);if(wt){const de=(m.ranges.length,4);h.push(ue({range:V,key:`selection-inside-edge-${H}`,x:wt.x-1,y:wt.y-1,width:Math.max(wt.width+1,0),height:Math.max(wt.height+1,0),style:{overflow:"hidden"},stroke:Z,strokeWidth:de}))}if(m.ranges.length===1){const de=e.toClipBounds(e.getRangeCoordsBounds(V),It);if(de){Ve||h.push(ue({range:V,key:`move-selection-hit-box-${H}`,x:de.width>1?de.x:de.x-(me/2+1),y:de.height>1?de.y:de.y-(me/2+1),width:Math.max(de.width+2,1),height:Math.max(de.height+2,1),stroke:"transparent",style:{boxShadow:"none"},pathProps:{cursor:We?void 0:"move",pointerEvents:"stroke"},strokeWidth:me,...ke}));const ie=I;h.push(ue({range:V,key:`selection-single-${H}`,x:de.x-ie/2,y:de.y-ie/2,width:Math.max(de.width+ie/2,1),height:Math.max(de.height+ie/2,1),stroke:j,strokeWidth:ie}))}}else{const de=e.toClipBounds(e.getRangeCoordsBounds(V,{top:-1,left:-1,right:-2,bottom:-2}),It);de&&h.push(ue({range:V,key:`selection-multi-${H}`,x:de.width>1?de.x:de.x-fe/2,y:de.height>1?de.y:de.y-fe/2,width:Math.max(de.width,fe)+1,height:Math.max(de.height,fe)+1,stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(m.ranges.length>1&&H===m.rangeIndex){const de=e.getCellCoordsAsRangeCoords(m.cell),ie=e.toClipBounds(e.getRangeCoordsBounds(de,{top:1,left:1,right:-1,bottom:-1}),It);ie&&h.push(ue({range:V,key:`selection-anchor-${H}`,x:ie.x,y:ie.y,width:Math.max(ie.width,fe),height:Math.max(ie.height,fe),stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(H===m.ranges.length-1){u=null,g=null;const de=V.rowStart===se().top&&V.rowEnd===se().bottom,ie=V.colStart===se().left&&V.colEnd===se().right,ot=e.getRangeCoordsBounds(V);let Dt=null;if(de||ie){if(Dt=e.toClipBounds(ot,It),Object.keys(e.allViews()).length>1){const so=e.getVisibleRangeCoords(),$o=e.allViews()[n.AnchorLocation.TopLeft],un=e.allViews()[n.AnchorLocation.Top],hn=e.allViews()[n.AnchorLocation.Left],ao=e.getAnchor();(ie&&(ao===n.AnchorLocation.Top&&$o||ao===n.AnchorLocation.Center&&hn||!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd+1},so))||de&&(ao===n.AnchorLocation.Left&&$o||ao===n.AnchorLocation.Center&&un||!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd,rowIndex:V.rowStart},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd+1,rowIndex:V.rowStart},so)))&&(Dt=null)}}else Dt=e.toClipBounds(ot,It);if(!Dt||Dt.width===0||Dt.height===0)continue;u={x:Dt.x+Dt.width+1,y:Dt.y+Dt.height+1},Dt.width===0||Dt.height===0||V.rowStart===se().top&&V.colStart===se().left&&V.rowEnd===se().bottom&&V.colEnd===se().right||(de?(u.y=I,g="tr"):ie&&(u.x=I,g="bl"))}}let $=null;if(Re){const H=e.toClipBounds(e.getRangeCoordsBounds(Re,{top:0,left:0,right:0,bottom:0}),It);H&&($=ue({...x,range:Re,key:"remove-selection",x:H.x,y:H.y,width:H.width,height:H.height,strokeWidth:2,stroke:St,fill:xt}))}let W=null;if(bt){const H=e.toClipBounds(e.getRangeCoordsBounds(bt,{top:0,left:0,right:0,bottom:0}),It);H&&(W=ue({range:bt,key:"selection-fill-outline",x:H.x-2/2,y:H.y-2/2,width:H.width+2/2,height:H.height+2/2,strokeWidth:2,stroke:j,strokeDasharray:"3 2"}))}let Y=null;!te&&u&&!We&&(Y=l.createElement(Uo,{...u,corner:g,size:7.5,borderStroke:`${Z} solid`,style:{borderRadius:1},background:j,...Q,key:"fillHandle"}));const xe=[...h];if($&&xe.push($),W&&xe.push(W),Y&&xe.push(Y),!ct&&Rt&&m?.ranges.length===1&&m.ranges[m.ranges.length-1]){const H=m.ranges[m.ranges.length-1],V=H.rowStart===se().top&&H.rowEnd===se().bottom,nt=H.colStart===se().left&&H.colEnd===se().right,I={view:e,range:H,borderStroke:`${j} solid 3px`,background:Z,selectionTouchPointerHandler:po,...rt,onTouchSelectStart:fe=>jt(fe),onTouchSelectEnd:()=>jt(null),currentTouchAnchor:eo};xe.push(ee.jsx(fo,{anchor:nt?"b":V?"r":"br",scrollableElement:t.current,...I},"touch-select-handle-after")),xe.push(ee.jsx(fo,{anchor:nt?"t":V?"l":"tl",scrollableElement:t.current,...I},"touch-select-handle-before"))}if(We){const H=e.toClipBounds(e.getRangeCoordsBounds(We,{top:1,left:1,right:1,bottom:1}),It);H&&xe.push(ue({range:We,key:"selection-move-outline",x:H.x-q/2,y:H.y-q/2,width:Math.max(H.width+q/2,1),height:Math.max(H.height+q/2,1),stroke:j,style:{boxShadow:"none",transitionDuration:"70ms",transitionTimingFunction:"ease-in",transitionProperty:"left, top, width, height",willChange:"left, top, width, height"},strokeWidth:q}))}return ee.jsx("div",{children:xe},"selection")},[tt,Re,te,bt,Ve,We,se,Z,j,L,St,xt,ct,rt,eo]),Et=l.useMemo(()=>{const e=()=>t.current;return[new o.SimpleCommand("moveToPageDown",e,{label:"Page Down",description:"Shift viewport down one page.",shortcut:[{key:"PageDown"}]},()=>no(!1)),new o.SimpleCommand("selectToPageDown",e,{label:"Select To Page Down",description:"Shift viewport and select down one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Shift]}]},()=>no(!0)),new o.SimpleCommand("moveToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt]}]},()=>ro(!1)),new o.SimpleCommand("selectToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>ro(!0)),new o.SimpleCommand("moveToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp"}]},()=>Mt(!1)),new o.SimpleCommand("selectToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Shift]}]},()=>Mt(!0)),new o.SimpleCommand("moveToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt]}]},()=>Jt(!1)),new o.SimpleCommand("selectToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>Jt(!0)),new o.SimpleCommand("selectColumn",e,{label:"Select Column",description:"Select the columns for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Ctrl]}},mo),new o.SimpleCommand("selectRow",e,{label:"Select Row",description:"Select the rows for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Shift]}},Co),new o.SimpleCommand("selectToColumnStart",e,{label:"Select To Column Start",description:"Select the columns to the beginning of the sheet."},()=>to(!0)),new o.SimpleCommand("selectToColumnEnd",e,{label:"Select To Column End",description:"Select the columns to the end of the sheet."},()=>oo(!0)),new o.SimpleCommand("moveToRowStart",e,{label:"Move to Row Home",description:"Move to the beginning of the row.",shortcut:[{key:"Home"}]},()=>Gt(!1)),new o.SimpleCommand("selectToRowStart",e,{label:"Select to Row Home",description:"Select to the beginning of the row.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Shift]}]},()=>Gt(!0)),new o.SimpleCommand("moveToSheetStart",e,{label:"Move to Sheet Home",description:"Move to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl]}]},()=>qt(!1)),new o.SimpleCommand("selectToSheetStart",e,{label:"Select to Sheet Home",description:"Select to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>qt(!0)),new o.SimpleCommand("moveToRowEnd",e,{label:"Move to Row End",description:"Move to the end of the row.",shortcut:[{key:"End"}]},()=>_t(!1)),new o.SimpleCommand("selectToRowEnd",e,{label:"Select to Row End",description:"Select to the end of the row.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Shift]}]},()=>_t(!0)),new o.SimpleCommand("moveToSheetEnd",e,{label:"Move to Sheet End",description:"Move to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl]}]},()=>Wt(!1)),new o.SimpleCommand("selectToSheetEnd",e,{label:"Select to Sheet End",description:"Select to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>Wt(!0)),new o.SimpleCommand("scrollToActiveCoords",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Ctrl]}},Kt),new o.SimpleCommand("scrollToActiveCoordsClearSelection",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell and clear selection.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Shift]}},()=>{Bt(),Ye(b.cell,!0)}),new o.SimpleCommand("traverseSelectionRight",e,{label:"Traverse Right",description:"Traverse the selection moving rightward.",shortcut:{key:"Tab"}},io),new o.SimpleCommand("traverseSelectionLeft",e,{label:"Traverse Left",description:"Traverse the selection moving leftward.",shortcut:{key:"Tab",modifiers:[o.KeyModifiers.Shift]}},lo),new o.SimpleCommand("traverseSelectionDown",e,{label:"Traverse Down",description:"Traverse the selection moving downward.",shortcut:[{key:"Enter"},{key:"NumpadEnter"}]},yo),new o.SimpleCommand("traverseSelectionUp",e,{label:"Traverse Up",description:"Traverse the selection moving upward.",shortcut:[{key:"Enter",modifiers:[o.KeyModifiers.Shift]},{key:"NumpadEnter",modifiers:[o.KeyModifiers.Shift]}]},vo),new o.SimpleCommand("moveLeft",e,{label:"Move Left",description:"Move active cell to the left.",shortcut:[{key:"ArrowLeft"}]},co),new o.SimpleCommand("selectLeft",e,{label:"Select Left",description:"Extend selection left.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Shift]}]},w),new o.SimpleCommand("moveContentfulLeft",e,{label:"Move Left Contentful",description:"Move left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl]}]},S),new o.SimpleCommand("selectContentfulLeft",e,{label:"Select Left Contentful",description:"Extend selection left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},E),new o.SimpleCommand("moveRight",e,{label:"Move Right",description:"Move active cell to the right.",shortcut:[{key:"ArrowRight"}]},v),new o.SimpleCommand("selectRight",e,{label:"Select Right",description:"Extend selection right.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Shift]}]},y),new o.SimpleCommand("moveContentfulRight",e,{label:"Move Right Contentful",description:"Move right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl]}]},z),new o.SimpleCommand("selectContentfulRight",e,{label:"Select Right Contentful",description:"Extend selection right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},he),new o.SimpleCommand("moveUp",e,{label:"Move Up",description:"Move active cell to the up.",shortcut:[{key:"ArrowUp"}]},re),new o.SimpleCommand("selectUp",e,{label:"Select Up",description:"Extend selection up.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Shift]}]},ae),new o.SimpleCommand("moveContentfulUp",e,{label:"Move Up Contentful",description:"Move up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl]}]},F),new o.SimpleCommand("selectContentfulUp",e,{label:"Select Up Contentful",description:"Extend selection up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Se),new o.SimpleCommand("moveDown",e,{label:"Move Down",description:"Move active cell to the down.",shortcut:[{key:"ArrowDown"}]},Ke),new o.SimpleCommand("selectDown",e,{label:"Select Down",description:"Extend selection down.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Shift]}]},Pe),new o.SimpleCommand("moveContentfulDown",e,{label:"Move Down Contentful",description:"Move down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl]}]},Ne),new o.SimpleCommand("selectContentfulDown",e,{label:"Select Down Contentful",description:"Extend selection down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Ee),new o.SimpleCommand("selectVisible",e,{label:"Select Visible",description:"Select visible cells only.",shortcut:{key:";",modifiers:[o.KeyModifiers.Alt]}},So),new o.SimpleCommand("traverseSelectionPreviousRange",e,{label:"Traverse Previous Range",description:"Traverse the selection to the previous range.",shortcut:{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Qt),new o.SimpleCommand("traverseSelectionNextRange",e,{label:"Traverse Next Range",description:"Traverse the selection to the next range.",shortcut:{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Ro),new o.SimpleCommand("traverseSelectionCorners",e,{label:"Traverse Corners",description:"Traverse the selection through the corners of the selected range.",shortcut:{key:".",modifiers:[o.KeyModifiers.Ctrl]}},Eo)]},[]);return l.useMemo(()=>{r?.addCommands(Et,!0)},[r]),{selection:tt,setSelectionCell:Ye,setSelectionRanges:lt,overlay:gt,cursor:Ht,onPointerDown:xo,clearLastSelection:le,newSelection:pt,modifySelection:it,appendSelection:Ce,clearSelections:Bt,isEntire:et,navigate:Ze,navigateSelection:Ot}};
11
+ }`,ge=document.createElement("style");return ge.appendChild(document.createTextNode(X)),document.head.appendChild(ge),ge.sheet.insertRule(X,0),()=>{document.head.removeChild(ge)}},[K]),K&&(k={strokeDasharray:`${ee.dashLength}px ${ee.dashGap}px`,strokeDashoffset:`${Z}px`,animation:`${re} ${_}ms linear infinite`,willChange:"stroke-dashoffset"}),Q.jsx(to,{x:c,y:u,width:f,height:a,stroke:r,fill:i,shapeRendering:"crispEdges",style:{...k,...s},...U})});function no(t){var r,i,c="";if(typeof t=="string"||typeof t=="number")c+=t;else if(typeof t=="object")if(Array.isArray(t)){var u=t.length;for(r=0;r<u;r++)t[r]&&(i=no(t[r]))&&(c&&(c+=" "),c+=i)}else for(i in t)t[i]&&(c&&(c+=" "),c+=i);return c}function Wt(){for(var t,r,i=0,c="",u=arguments.length;i<u;i++)(t=arguments[i])&&(r=no(t))&&(c&&(c+=" "),c+=r);return c}Ln.displayName="Selection";const Un=l.memo(l.forwardRef((t,r)=>{const{x:i=0,y:c=0,borderWidth:u=1,size:f=6,borderStroke:a,corner:s,style:p,className:O,background:P,ref:M,...U}=t;if(i===0||c===0)return null;let K=!0,ee=!0,Z=!0,_=!0;switch(s){case"tl":K=!1,ee=!1;break;case"bl":K=!1,_=!1;break;case"br":Z=!1,_=!1;break;case"tr":ee=!1,Z=!1}return Q.jsx("div",{className:Wt("fill-handle",O),style:{position:"absolute",left:i-(f+(K?u:0))/2,top:c-(f+(ee?u:0))/2,width:f,height:f,borderLeft:K?`${u}px ${a}`:void 0,borderTop:ee?`${u}px ${a}`:void 0,borderRight:Z?`${u}px ${a}`:void 0,borderBottom:_?`${u}px ${a}`:void 0,background:P,cursor:"crosshair",pointerEvents:"all",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top",willChange:"left, top",...p},tabIndex:-1,...U})}));function kn(t,r){if(typeof t=="function")return t(r);t&&(t.current=r)}Un.displayName="FillHandle";var oo=parseInt(l.version.split(".")[0],10)>=19?function(t){return r=>{const i=[];for(const c of t){const u=kn(c,r),f=typeof u=="function";i.push(f?u:()=>kn(c,null))}return()=>{for(const c of i)c()}}}:function(t){return r=>{for(const i of t)kn(i,r)}};const Eo=n.ReactUtils.detectIt().supportsTouchEvents,fn=l.memo(l.forwardRef((t,r)=>{const{range:i,view:c,anchor:u,borderStroke:f="var(--sxl-app-color-primary, rgb(33, 115, 70))",background:a="var(--sxl-app-color-background, white)",borderWidth:s=3,size:p=22,style:O,className:P,selectionTouchPointerHandler:M,onTouchSelectStart:U,onTouchSelectEnd:K,currentTouchAnchor:ee,scrollableElement:Z,scrollableRoot:_,...Me}=t;if(!Eo)return null;const re=n.useCallbackRef(U,[U]),k=n.useCallbackRef(K,[K]),{bounds:X,coordsPivot:ge,key:F}=l.useMemo(()=>{if(!i||!c)return null;let xe=null,q=null;switch(u){case"tl":xe={colIndex:i.colEnd,rowIndex:i.rowEnd},q={colIndex:i.colStart,rowIndex:i.rowStart};break;case"br":xe={colIndex:i.colStart,rowIndex:i.rowStart},q={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"t":case"l":xe={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"b":xe={colIndex:i.colStart,rowIndex:i.rowStart};break;case"r":xe={colIndex:i.colStart,rowIndex:i.rowEnd}}let T=c.getRangeCoordsBounds(q?{rowStart:q.rowIndex,colStart:q.colIndex,rowEnd:q.rowIndex,colEnd:q.colIndex}:i);const H=c.getBounds(),St=c.getViewportSize(),xt=H.x,ct=H.y,rt=St.width,ae=St.height;switch(u){case"tl":break;case"br":T.x=T.x+T.width,T.y=T.y+T.height;break;case"t":T.x=rt/2-xt;break;case"b":T.x=rt/2-xt,T.y=T.y+T.height;break;case"l":T.y=ae/2-ct;break;case"r":T.x=T.x+T.width,T.y=ae/2-ct}const Pt=c.toClipBounds(T,0);return!Pt||Pt.width<=0||Pt.height<=0||T.x<0||T.y<0||T.x>rt||T.y>ae?{bounds:null,coordsAnchor:null,coordsPivot:null,key:null}:{bounds:T,coordsAnchor:null,coordsPivot:xe,key:"touchSelect-"+c.getAnchor()+"-"+u}},[i,c,u]),fe=l.useRef(null),Le=l.useMemo(()=>{const xe=q=>u==="t"||u==="b"?{...q,colIndex:void 0}:u==="l"||u==="r"?{...q,rowIndex:void 0}:q;return{processTouch:!0,consumeTouch:!0,onPointerDown:(q,T)=>{const H=xe(c.getCellCoordsFromClient(q.clientX,q.clientY));return fe.current={coordsPivot:ge},re?.(u),M.onSelectionPointerDown(q,T,c,H,ge,!1,!0)},onPointerMoveOrWait:(q,T,H)=>{const St=xe(c.getCellCoordsFromClient(q.clientX,q.clientY));return M.onSelectionPointerMoveOrWait(q,T,H,c,St,fe.current?.coordsPivot,!0,!0)},onPointerUp:(q,T,H)=>(fe.current=null,k?.(u),M.onPointerUp(q,T,H))}},[M,i,c,u]),be=n.useSynchronizedPointerHandler(Le),[ze,{y:se,x:we}]=n.useAnimatedMeasure(),A=l.useRef(null),{getPortalContainer:C,isFullscreen:$e}=n.useFullscreenPortal(),[We,G]=l.useState(null);return l.useEffect(()=>{const xe=A.current?.getBoundingClientRect();if(!xe||!X)return void G(null);let q=0,T=0,H=Z;for(;H;)q+=H.scrollLeft,T+=H.scrollTop,H=_&&H===_.parentElement?null:H.parentElement;G(Jn.createPortal(Q.jsx("div",{className:Wt("touch-select-handle",P),ref:r,style:{position:"absolute",left:q+(xe?.x??0)-(p+s)/2,top:T+(xe?.y??0)-(p+s)/2,width:p,height:p,borderWidth:`${s}px`,border:f,borderRadius:"50%",background:a,boxShadow:`0 0 0 1.5px ${a}`,cursor:"grab",pointerEvents:"all",opacity:ee?0:1,transitionDuration:"160ms",transitionProperty:"opacity",...O},tabIndex:-1,onPointerDown:be,...Me}),_??C(),F))},[se,we,X?.x,X?.y,X?.width,X?.height,P,ee,a,p,s,f,Z,$e]),X?Q.jsxs(Q.Fragment,{children:[Q.jsx("div",{ref:oo([ze,A]),style:{position:"absolute",left:X.x,top:X.y,opacity:0}}),We]}):null}));fn.displayName="TouchSelectHandle";const It=-10,Io=Object.freeze({rowStart:0,colStart:0,rowEnd:0,colEnd:0}),ro=Object.freeze({colIndex:0,rowIndex:0}),Tn=Object.freeze([]),yt=t=>{if(t&&t.cell&&t.ranges&&t.rangeIndex>-1&&t.rangeIndex<=t.ranges.length)return t;const r={cell:null,ranges:t?.ranges??Tn};return r.rangeIndex=t?.rangeIndex??r.ranges.length-1,r.cell=t?.cell,!r.cell&&r.ranges.length>0&&(r.cell={rowIndex:r.ranges[r.rangeIndex].rowStart,colIndex:r.ranges[r.rangeIndex].colStart}),r.cell||(r.cell=ro),o.CoordUtils.isEqualSelectionCoords(r,t)?t:r},hn=(t,r,i)=>{const c=t.getVisibleRangeCoords(),u=t.getScrollOrientation();!u.horizontal&&(r.colIndex>c.colEnd||r.colIndex<c.colStart)&&(r={...r,colIndex:r.colIndex>c.colEnd?c.colEnd+1:c.colEnd-1},t=i.current.getViewFromLocation(o.AnchorLocation.Center)),!u.vertical&&(r.rowIndex>c.rowEnd||r.rowIndex<c.rowStart)&&(r={...r,rowIndex:r.rowIndex>c.rowEnd?c.rowEnd+1:c.rowEnd-1},t=i.current.getViewFromLocation(o.AnchorLocation.Center)),t.scrollCellCoordsIntoView(r)},ko=()=>!1;function gn(t,r){if(!t)throw new Error("Invariant failed")}const Xn={"sheetxl-grid":"_sheetxl-grid_h9wwa_7"},Mo=Object.freeze({top:0,left:0}),Do=Object.freeze({bottom:-4,right:-4}),Po=Object.freeze({horizontal:!0,vertical:!0}),Gn=[o.AnchorLocation.TopLeft,o.AnchorLocation.Top,o.AnchorLocation.Left,o.AnchorLocation.Center],zt=3e3,Mn={},zn=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,rowCount:u=1,columnCount:f=1,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O,layout:P,onViewportScroll:M,onImmediateScroll:U,showGridLines:K=!0,gridLineColor:ee="rgb(224, 224, 224)",propsGridLineRows:Z,propsGridLineColumns:_,clipCells:Me=!0,cursor:re,freezeLeft:k=0,freezeTop:X=0,propsFreezeLeft:ge,propsFreezeTop:F,renderCell:fe,onViewportChange:Le,onFirstRender:be,renderOverlay:ze,propsOverlay:se,renderOverlays:we,propsOverlays:A,allowOverlaysOverflow:C=!1,propsStage:$e,wrapperStage:We=null,hiddenRowsAt:G,hiddenColumnsAt:xe,hiddenCellAt:q,getVisibleCells:T,zoom:H=1,enableMouseWheel:St=!0,onWheelScroll:xt,getCellCoordsAsRangeCoords:ct=o.CoordUtils.cellToRange,scrollPoint:rt=Mo,style:ae={},...Pt}=t;gn(fe),gn(!t?.children);const D=n.useCallbackRef(U,[U]),R=n.useCallbackRef(Le,[Le]),Ce=n.useCallbackRef(M,[M]),te=n.useCallbackRef(xt,[xt]),ue=n.useCallbackRef(be,[be]),Ae=l.useRef(null),et=l.useRef(null),mt=l.useRef(null),[tt,Tt]=l.useReducer(w=>w+1,0),[st,b]=l.useState({left:rt?.left??0,top:rt?.top??0,horizontalScrollDirection:null,verticalScrollDirection:null}),ne=l.useRef(null),Pe=l.useRef(st),{top:lt,left:Ye,verticalScrollDirection:jt,horizontalScrollDirection:$t}=st,bt=l.useRef(!1),Xt=eo({rowCount:u,columnCount:f,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O}),At=l.useRef(null),ve=l.useMemo(()=>{const w=P||Xt;return At.current=null,{getColOffset:S=>w.getColOffset(S)*H,getColIndex:S=>w.getColIndex(S/H),getRowOffset:S=>w.getRowOffset(S)*H,getRowIndex:S=>w.getRowIndex(S/H)}},[Xt,P,H]),Ut=(w,S,E)=>{const v=(S?.left??0)+0,y=(S?.top??0)+0;return{getColOffset:L=>w.getColOffset(L)-v,getColIndex:L=>w.getColIndex(L+v),getRowOffset:L=>w.getRowOffset(L)-y,getRowIndex:L=>w.getRowIndex(L+y)}},ht=n.useCallbackRef((w,S=!1)=>wn(w,S,ve.getRowOffset,S?0:u),[u,ve?.getRowOffset]),kt=n.useCallbackRef(G??ht,[G]),en=n.useCallbackRef((w,S=!1)=>wn(w,S,ve.getColOffset,S?f:0),[f,ve?.getColOffset]),Ht=n.useCallbackRef(xe??en,[xe]),je=l.useMemo(()=>Math.min(i??800,ve.getColOffset(f)),[ve.getColOffset,f,i]),Ke=l.useMemo(()=>Math.min(c??600,ve.getRowOffset(u)),[ve.getRowOffset,u,c]),Ft=l.useCallback(w=>{o.CommonUtils.canUseDOM&&setTimeout(()=>{Ae.current?.focus({preventScroll:!0,...w})},0)},[]),ft=l.useCallback(w=>Ae.current?.contains(w)||et.current?.contains(w),[]);l.useEffect(()=>{bt.current&&(ne.current&&ne.current.left!==Pe.current?.left&&ne.current.top!==Pe.current?.top||(ne.current=null,Ce?.({left:Ye,top:lt})))},[Ye,lt]);const Ot=n.useCallbackRef(()=>({top:lt,left:Ye}),[lt,Ye]),Se=l.useMemo(()=>{const w=[];let S=0,E=0;typeof X=="number"?S=X:(S=X.index??0,E=(X.scrollOffset??0)*H);const v=E,y=ve.getRowOffset(S),L=y-v;if(S>0){const Be=Ut(ve,{top:E+ve.getRowOffset(0)}),Ue=ve.getRowIndex(v),Ne=ve.getRowIndex(y-1);let ye;w[1]={minIndex:Ue,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:L,visibleIndices:()=>ye||(ye=Object.freeze(un(kt,Ue,Ne)),ye),layout:Be,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,Ke-L),oe=Ut(ve,{top:lt+L}),de=oe.getRowIndex(0),V=oe.getRowIndex(he);let me;return w[0]={minIndex:de,maxIndex:V,minCoord:S,maxCoord:u-1,minBounds:L,maxBounds:he,visibleIndices:()=>me||(me=Object.freeze(un(kt,de,V)),me),layout:oe,maxVirtualBounds:ve.getRowOffset(u),scrollOffset:lt,freezeOffset:(S>0?ve.getRowOffset(S):0)-E},w},[ve.getRowIndex,ve.getRowOffset,kt,Ke,u,X,lt,H]),He=l.useMemo(()=>{const w=[];let S=0,E=0;typeof k=="number"?S=k:(S=k.index??0,E=(k.scrollOffset??0)*H);const v=E,y=ve.getColOffset(S),L=y-v;if(S>0){const Be=Ut(ve,{left:E+ve.getColOffset(0)}),Ue=ve.getColIndex(v),Ne=ve.getColIndex(y-1);let ye;w[1]={minIndex:Ue,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:L,visibleIndices:()=>ye||(ye=Object.freeze(un(Ht,Ue,Ne)),ye),layout:Be,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,je-L),oe=Ut(ve,{left:Ye+L}),de=oe.getColIndex(0),V=oe.getColIndex(he);let me;return w[0]={minIndex:de,maxIndex:V,minCoord:S,maxCoord:f-1,minBounds:L,maxBounds:he,visibleIndices:()=>me||(me=Object.freeze(un(Ht,de,V)),me),layout:oe,maxVirtualBounds:ve.getColOffset(f),scrollOffset:Ye,freezeOffset:(S>0?ve.getColOffset(S):0)-E},w},[ve.getColIndex,ve.getColOffset,Ht,je,f,k,Ye,H]),it=l.useRef({}),pt=l.useRef([]),pe=l.useMemo(()=>{let w={};const S=(v,y,L,he,oe)=>{const de={vertical:he?.vertical||!1,horizontal:he?.horizontal||!1};if(v>=He.length||y>=Se.length)return null;const V={rowStart:Se[y].minIndex,colStart:He[v].minIndex,rowEnd:Se[y].maxIndex,colEnd:He[v].maxIndex};if(V.rowStart>V.rowEnd||V.colStart>V.colEnd)return null;const me={getColIndex:J=>He[v].layout.getColIndex(J),getColOffset:J=>He[v].layout.getColOffset(J),getRowIndex:J=>Se[y].layout.getRowIndex(J),getRowOffset:J=>Se[y].layout.getRowOffset(J)},Be=Object.freeze({left:oe?.left??0,top:oe?.top??0,right:oe?.right??0,bottom:oe?.bottom??0}),Ue=Object.freeze({x:He[v].minBounds,y:Se[y].minBounds,width:He[v].maxBounds,height:Se[y].maxBounds}),Ne=(J,Ve)=>qn(me,J??V,Ve),ye={width:He[v].maxVirtualBounds,height:Se[y].maxVirtualBounds},ce={left:He[v].scrollOffset,top:Se[y].scrollOffset},nt={left:He[v].freezeOffset,top:Se[y].freezeOffset},Ge={width:je,height:Ke};let Te=null,_e=null;const gt=(nt.top+(he.vertical?ce.top:0))/H,Fe=(nt.left+(he.horizontal?ce.left:0))/H;return{getStage:()=>Ae.current??null,getVisibleRangeCoords:()=>V,toClipBounds:(J,Ve)=>{let at,Re=0;return Ve===void 0||typeof Ve=="number"?(at=Ne(V),Re=Ve):at=Ve,((Ze,De,Ee=0)=>{if(Ze.x>De.width||Ze.y>De.height)return null;const dt={left:Ze.x,top:Ze.y,bottom:Ze.height+Ze.y,right:Ze.width+Ze.x},ot={left:De.x+Ee,top:De.y+Ee,bottom:De.height-2*Ee+De.y,right:De.width-2*Ee+De.x},wt={left:Math.max(dt.left,ot.left),top:Math.max(dt.top,ot.top),bottom:Math.min(dt.bottom,ot.bottom),right:Math.min(dt.right,ot.right)},Et={x:wt.left,y:wt.top,width:wt.right-wt.left,height:wt.bottom-wt.top};return Et.height<0||Et.width<0?null:Et})(J??{x:0,y:0,width:Ue.width,height:Ue.height},at,Re)},toViewBounds:J=>Fe===0&&gt===0&&H===1?J:{x:(J.x-Fe)*H,y:(J.y-gt)*H,width:J.width*H,height:J.height*H},toAbsoluteBounds:J=>Fe===0&&gt===0&&H===1?J:{x:J.x/H+Fe,y:J.y/H+gt,width:J.width/H,height:J.height/H},getRelativePointFromClient:(J,Ve)=>{const at=Nt(J,Ve);return{x:at.x-Ue.x,y:at.y-Ue.y}},getLayout:()=>me,getCellCoordsAsRangeCoords:ct,getVisibleColumns:()=>He[v].visibleIndices(),getVisibleRows:()=>Se[y].visibleIndices(),getVisibleColumnOffsets:()=>(Te||(Te=Nn(He[v].layout,!0,He[v].visibleIndices(),V.colStart,V.colEnd)),Te),getVisibleRowOffsets:()=>(_e||(_e=Nn(Se[y].layout,!1,Se[y].visibleIndices(),V.rowStart,V.rowEnd)),_e),getTotalRangeCoords:()=>({colStart:He[v].minCoord,colEnd:He[v].maxCoord,rowStart:Se[y].minCoord,rowEnd:Se[y].maxCoord}),getRangeCoordsBounds:Ne,scrollCellCoordsIntoView:(J,Ve)=>Gt(J,Ve,L),getCellCoordsFromClient:(J,Ve,at=!1)=>{const Re=Nt(J,Ve);if(!Re)return null;const Ze=me.getColIndex(Re.x-Ue.x),De={rowIndex:me.getRowIndex(Re.y-Ue.y),colIndex:Ze};if(at)return De;const Ee=ct(De);return{rowIndex:Ee.rowStart,colIndex:Ee.colStart}},getZoom:()=>H,getAnchor:()=>L,getBounds:()=>Ue,getInsets:()=>Be,getTotalSize:()=>ye,getViewportSize:()=>Ge,getScrollTopLeft:()=>ce,getFreezeTopLeft:()=>nt,getScrollOrientation:()=>de,allViews:()=>w}};let E=w[o.AnchorLocation.Center]=S(0,0,o.AnchorLocation.Center,Po,Do);return E&&(w[o.AnchorLocation.Center]=E),E=S(0,1,o.AnchorLocation.Top,{horizontal:!0}),E&&(w[o.AnchorLocation.Top]=E),E=S(1,0,o.AnchorLocation.Left,{vertical:!0}),E&&(w[o.AnchorLocation.Left]=E),E=S(1,1,o.AnchorLocation.TopLeft,{}),E&&(w[o.AnchorLocation.TopLeft]=E),it.current=null,w=Object.freeze(w)},[Se,He,ct]),Kt=Object.keys(pe),Rt=He[0]?.maxVirtualBounds??0,Je=Se[0]?.maxVirtualBounds??0,Ct=l.useMemo(()=>({left:He[1]?He[1].layout.getColOffset(He[1].maxIndex+1):0,top:Se[1]?Se[1].layout.getRowOffset(Se[1].maxIndex+1):0}),[pe]);l.useEffect(()=>{if(pt.current.length>0){for(let w=0;w<pt.current.length;w++)pt.current[w]();pt.current=[]}},[pe]);const vt=n.useCallbackRef(()=>({containerWidth:je,containerHeight:Ke,totalWidth:Rt,totalHeight:Je}),[je,Ke,ve]);l.useEffect(()=>{!ne.current&&bt.current&&R({top:lt,left:Ye,width:je,height:Ke,totalWidth:Rt,totalHeight:Je})},[lt,Ye,Rt,Je]),l.useEffect(()=>{bt.current&&R({top:lt,left:Ye,width:je,height:Ke,totalWidth:Rt,totalHeight:Je})},[je,Ke]);const Nt=l.useCallback((w,S)=>{gn(typeof w=="number"&&typeof S=="number");const E=Ae.current?.getBoundingClientRect();return E?{x:w-E.x,y:S-E.y}:{x:w,y:S}},[]),xn=n.useCallbackRef(w=>pe[w]||null,[pe]),pn=n.useCallbackRef((w,S)=>{if(Object.keys(pe).length===1)return pe[o.AnchorLocation.Center];const E=Nt(w,S);if(!E)return null;const{x:v,y}=E;let L=null;const he=Gn,oe=he.length;for(let de=0;!L&&de<oe;de++){const V=pe[he[de]];V&&Ro(v,y,V.getBounds())&&(L=V)}return L||(L=pe[o.AnchorLocation.Center]),L},[pe,ct]),Qe=n.useCallbackRef(()=>pe[o.AnchorLocation.Center].getVisibleRangeCoords(),[pe[o.AnchorLocation.Center]]),Lt=l.useRef(null),mn=l.useCallback(()=>{Lt.current!==null&&o.CommonUtils.cancelTimeout(Lt.current),Lt.current=o.CommonUtils.requestTimeout(Cn,150)},[]),Cn=l.useCallback(()=>{Lt.current=null,b(w=>{const S={...w,verticalScrollDirection:null,horizontalScrollDirection:null};return Pe.current=S,S})},[]),Bt=n.useCallbackRef(w=>{const S=w?.left??w?.[0],E=w?.top??w?.[1];let v=Pe.current.left;S!==void 0&&S!==v&&(S>v?(v=Math.max(He?.[1]?.scrollOffset??0,S),v=Math.min(Rt-je,v)):v=Math.max(He?.[1]?.scrollOffset??0,S));let y=Pe.current.top;if(E!==void 0&&E!==y&&(E>y?(y=Math.max(Se?.[1]?.scrollOffset??0,E),y=Math.min(Je-Ke,y)):y=Math.max(Se?.[1]?.scrollOffset??0,E)),Pe.current.left===v&&Pe.current.top===y)return;let L=null,he=null;Pe.current.left>v?L=o.Direction.Left:Pe.current.left<v&&(L=o.Direction.Right),Pe.current.top>y?he=o.Direction.Up:Pe.current.top<y&&(he=o.Direction.Down),o.CommonUtils.throttle(()=>{b(oe=>{const de={...oe,left:v,top:y,horizontalScrollDirection:L,verticalScrollDirection:he};return Pe.current=de,de})},17)(),ne.current?.top===y&&ne.current?.left===v||(ne.current={left:v,top:y},D({left:v,top:y}),R({left:v,top:y,width:je,height:Ke,totalWidth:Rt,totalHeight:Je})),mn()},[Rt,Je,Se,He]);l.useEffect(()=>{ne.current||Bt({left:Ye,top:lt})},[je,Ke]),l.useEffect(()=>{let w,S,E=!1;Pe.current.left>Rt&&(w=0,E=!0),Pe.current.top>Je&&(S=0,E=!0),E&&Bt({left:w,top:S})},[Rt,Je]),l.useLayoutEffect(()=>{ne.current={left:rt?.left,top:rt?.top},Bt(ne.current)},[rt?.left,rt?.top]);const tn=n.useCallbackRef(w=>{let S=w?.left??w?.[0],E=w?.top??w?.[1];if(S===void 0&&E===void 0)return;const v=w?.behavior??"auto";S!==void 0&&(S=Pe.current.left+(S??0)),E!==void 0&&(E=Pe.current.top+(E??0)),!(Pe.current.left===S&&Pe.current.top===E)&&Bt({left:S,top:E,behavior:v})},[]),nn=l.useCallback(w=>{let S=null;if(Object.keys(pe).length>1){const E=Gn,v=E.length;for(let y=0;!S&&y<v;y++){const L=pe[E[y]];L&&o.CoordUtils.isCellWithinRange(w,L.getVisibleRangeCoords())&&(S=L)}}return S||(S=pe[o.AnchorLocation.Center]),S},[pe]),Gt=n.useCallbackRef((w,S={inline:"nearest",block:"nearest"},E=null)=>{const v={rowIndex:0,colIndex:0,...w};let y=null;if(E!==null){if(y=pe[E],y===null)return new Promise((Ge,Te)=>{Te("Invalid view")})}else y=nn(v);const L=ct(v),he=y.getLayout(),oe=he.getColOffset(L.colStart),de=he.getRowOffset(L.rowStart),V=he.getColOffset(L.colEnd+1),me=he.getRowOffset(L.rowEnd+1),Be=y.getBounds(),Ue=y.getTotalSize(),Ne=y.getScrollTopLeft(),ye=((Ge,Te,_e=!0)=>{_e=_e===!0?{block:"start",inline:"end"}:_e===!1?{block:"end",inline:"end"}:{block:"end",inline:"end",..._e};const gt=Wn(_e.inline,Ge.x,Ge.x+Ge.width,Te.left,Te.left+Te.width,Te.totalWidth),Fe=Wn(_e.block,Ge.y,Ge.y+Ge.height,Te.top,Te.top+Te.height,Te.totalHeight);if(gt!==void 0||Fe!==void 0)return{left:gt,top:Fe}})({x:oe+Ne.left,y:de+Ne.top,width:V-oe,height:me-de},{left:Ne.left,top:Ne.top,width:Be.width,height:Be.height,totalWidth:Ue.width,totalHeight:Ue.height},S);if(!ye)return Promise.resolve({...Ne});const ce={...ye};ce.left>Ye?ce.left+=20:ce.left<Ye&&(ce.left-=0),ce.top>lt?ce.top+=20:ce.top<lt&&(ce.top-=0);const nt=y.getScrollOrientation();return nt.horizontal&&w.colIndex!==void 0||delete ce.left,nt.vertical&&w.rowIndex!==void 0||delete ce.top,new Promise((Ge,Te)=>{try{Bt(ce),Ge(ce)}catch(_e){Te(_e)}})},[Rt,Je,pe,ct]),qt=n.useCallbackRef(w=>{const S=w.shiftKey;w.preventDefault();const{deltaX:E,deltaY:v,deltaMode:y}=w;if(mt.current||te?.(w)===!1)return;let he=S?v:E,oe=v;const de=S||Math.abs(he)>Math.abs(oe);y===1&&(oe*=0),mt.current=window.requestAnimationFrame(()=>{mt.current=null,tn(de?{left:he}:{top:oe})})},[te]),_t=l.useCallback((w=null)=>{At.current=null,it.current=null,Tt()},[]);l.useLayoutEffect(()=>{_t()},[fe]);const Vt=n.useImperativeElement(r,()=>({stage:Ae.current,focus:Ft,contains:ft,invalidate:_t,scrollTo:Bt,scrollBy:tn,scrollCellCoordsIntoView:Gt,getScrollPosition:Ot,getDimensions:vt,getViewport:Qe,handleWheel:qt,rowCount:u,columnCount:f,getLayout:()=>ve,getRelativePointFromClient:Nt,getViewFromClient:pn,getViewFromCellCoords:nn,getViewFromLocation:xn,onViewChangeOnce:w=>{pt.current.push(w)}}),[u,f,pe]);l.useEffect(()=>(St&&Vt.current?.addEventListener("wheel",qt,{passive:!1}),bt.current=!0,ne.current=null,()=>{Vt.current?.removeEventListener("wheel",qt)}),[St]);const Zt=l.useRef([]),Sn=(w,S)=>{!w||!ze||(Zt.current=[],S.push(((E,v)=>{const y=`view:${E.getAnchor()}:overlay:${S.length}`,L=ze({key:y,view:E,ref:oe=>Zt.current[v]=oe});if(!L)return null;const he=E.getBounds();return Q.jsx("div",{style:{position:"absolute",left:"0px",top:"0px",width:`${he.width}px`,height:`${he.height}px`,overflow:"hidden"},children:L},`overlay-${E.getAnchor()}-${v}`)})(w,0)))},bn=l.useMemo(()=>{const w={},S=Object.keys(pe),E=S.length;for(let v=0;v<E;v++){const y=S[v],L=[];Sn(pe[y],L),w[y]={overlays:L}}return w},[tt,ze,u,f,Se,He]),on=(w,S,E,v,y,L,he)=>{if(!w)return;const oe=w.getVisibleColumns(),de=w.getVisibleRows();if(oe.length===0||de.length===0)return;let V=null;if(T)V=T(w);else{V=[];const Re=de.length,Ze=oe.length;for(let De=0;De<Re;De++){const Ee=de[De];for(let dt=0;dt<Ze;dt++){const ot={rowIndex:Ee,colIndex:oe[dt]};if(q?.(ot))continue;const wt={coords:ot,range:ct(ot)};V.push(wt)}}}const me=w.getVisibleColumnOffsets(),Be=w.getVisibleRowOffsets(),Ue=w.getScrollTopLeft(),Ne=w.getFreezeTopLeft(),ye=Ue.left+Ne.left,ce=Ue.top+Ne.top,nt=Math.trunc(ye/zt),Ge=Math.trunc(ce/zt),Te={},_e=(Re,Ze,De,Ee,dt)=>{const ot=`view:${Re.getAnchor()}:cell:${Vn(Ze.rowIndex,Ze.colIndex)}`,wt=Ee.x,Et=Ee.y,e=Math.trunc((ye+wt)/zt)-nt,d=Math.trunc((ce+Et)/zt)-Ge;Te[d]||(Te[d]={});let g=Te[d][e];g||(g=Te[d][e]=[]);let h=L?.get(ot);if(!h){const x=(ye+wt)%zt,I=(ce+Et)%zt;h=fe({key:ot,coords:Ze,bounds:Ee,zoom:H,range:De,view:Re,value:dt,style:{left:n.ReactUtils.boundPixel(x),top:n.ReactUtils.boundPixel(I),width:n.ReactUtils.boundPixel(Ee.width,!0),height:n.ReactUtils.boundPixel(Ee.height,!0)}})}he?.set(ot,h),g.push(h)},gt=V.length;for(let Re=0;V&&Re<gt;Re++){const Ze=V[Re],De=Ze?.coords??Ze;if(!De)continue;const Ee=Ze?.range??{rowStart:De.rowIndex,colStart:De.colIndex,rowEnd:De.rowIndex,colEnd:De.colIndex},dt=w.getVisibleRangeCoords();if(!o.CoordUtils.isRangesIntersect(Ee,dt)&&!o.CoordUtils.isRangeWithinRange(Ee,dt))continue;const ot=Ee&&!o.CoordUtils.isSingleCell(Ee);if(!ot&&q?.(De))continue;const wt=De.rowIndex,Et=De.colIndex,e=Be[wt],d=me[Et];let g=null;e&&d&&(g={x:d.offset,y:e.offset,width:d.size,height:e.size});const h=Vn(Ee.rowStart,Ee.colStart);if(ot){if(y.has(h))continue;y.add(h),Ee.rowEnd-Ee.rowStart>0&&E.push(Ee),Ee.colEnd-Ee.colStart>0&&v.push(Ee)}if(ot&&(g=qn(w.getLayout(),Ee)),!g){console.warn("no bounds for cell",h);continue}const x=Ze?.value;_e(w,De,Ee,g,x)}const Fe=ye%zt,J=ce%zt,Ve=Object.keys(Te),at=Ve.length;for(let Re=0;Re<at;Re++){const Ze=Ve[Re],De=Te[Ze];if(!De)continue;const Ee=Object.keys(De),dt=Ee.length;for(let ot=0;ot<dt;ot++){const wt=Ee[ot],Et=De[wt];if(!Et)continue;const e=parseInt(Ze),d=parseInt(wt),g=e+Ge,h=d+nt,x=`view:${w.getAnchor()}:segment:${h}:${g}`;S.push(Q.jsx("div",{className:"cell-container",style:{transform:`translate(${n.ReactUtils.boundPixel(d*zt-Fe,!0)}px, ${n.ReactUtils.boundPixel(e*zt-J,!0)}px)`,willChange:"transform"},children:Et},x))}}},Mt=l.useMemo(()=>{const w=At.current,S=new Map,E={},v=Object.keys(pe),y=v.length;for(let L=0;L<y;L++){const he=v[L],oe=[],de=[],V=[];on(pe[he],V,oe,de,new Set,w,S),E[he]={cells:V,rangesH:oe,rangesV:de}}return At.current=S,E},[tt,u,f,Se,He,K,ae,Me,q,T,xe,G,ct]),rn=(w,S,E,v,y)=>{if(!w)return;const L=w.getLayout(),he=window.devicePixelRatio||1,oe=String(1/he);if(S){const de=`view:${w.getAnchor()}:hl:`,V=w.getVisibleRows();if((V?V.length:0)===0)return;const me=y.sort(o.CoordUtils.rowFirstRangeComparator),Be=w.getVisibleRangeCoords(),Ue=0,Ne=Math.min(w.getBounds().width,L.getColOffset(Be.colEnd+1));let ye=[];for(let ce=0;ce<V.length&&V[ce]<=Be.rowEnd;ce++){const nt=V[ce];if(nt<Be.rowStart)continue;let Ge=!1;for(;me.length>0&&me[0].rowStart<=nt;){const Fe=me.shift();Fe.rowEnd>nt&&(ye.push(Fe),Ge=!0)}Ge&&(ye=ye.sort(o.CoordUtils.columnFirstRangeComparator));const Te=L.getRowOffset(nt+1);let _e=Ue;const gt=ye.length;for(let Fe=0;Fe<gt+1;Fe++){let J=_e,Ve=Ne;const at=ye[Fe];Fe<gt&&(Ve=Math.min(Ne,L.getColOffset(at.colStart)),_e=Math.min(Ne,L.getColOffset(at.colEnd+1))),v.push(l.createElement("path",{d:`M ${n.ReactUtils.boundPixel(J)} ${n.ReactUtils.boundPixel(Te,!1,E)} L ${n.ReactUtils.boundPixel(Ve)} ${n.ReactUtils.boundPixel(Te,!1,E)}`,stroke:ee,strokeWidth:oe,vectorEffect:"non-scaling-stroke",...Z,key:de+nt+":"+Fe}))}for(let Fe=gt-1;Fe>=0;Fe--)ye[Fe].rowEnd<=V[ce+1]&&ye.splice(Fe,1)}}else{const de=`view:${w.getAnchor()}:vl:`,V=w.getVisibleColumns(),me=V?V.length:0;if(me===0)return;const Be=y.sort(o.CoordUtils.columnFirstRangeComparator),Ue=w.getVisibleRangeCoords(),Ne=0,ye=Math.min(w.getBounds().height,L.getRowOffset(Ue.rowEnd+1));let ce=[];for(let nt=0;nt<me&&V[nt]<=Ue.colEnd;nt++){const Ge=V[nt];if(Ge<Ue.colStart)continue;let Te=!1;for(;Be.length>0&&Be[0].colStart<=Ge;){const J=Be.shift();J.colEnd>Ge&&(ce.push(J),Te=!0)}Te&&(ce=ce.sort(o.CoordUtils.rowFirstRangeComparator));const _e=L.getColOffset(Ge+1);let gt=Ne;const Fe=ce.length;for(let J=0;J<Fe+1;J++){let Ve=gt,at=ye;const Re=ce[J];J<Fe&&(at=Math.min(ye,L.getRowOffset(Re.rowStart)),gt=Math.min(ye,L.getRowOffset(Re.rowEnd+1))),v.push(Q.jsx("path",{d:`M ${n.ReactUtils.boundPixel(_e,!1,E)} ${n.ReactUtils.boundPixel(Ve)} L ${n.ReactUtils.boundPixel(_e,!1,E)} ${n.ReactUtils.boundPixel(at)}`,stroke:ee,strokeWidth:oe,vectorEffect:"non-scaling-stroke",..._},de+Ge+":"+J))}for(let J=Fe-1;J>=0;J--)ce[J].colEnd<=V[nt+1]&&ce.splice(J,1)}}},Jt=w=>{if(!Mt)return;const S={},E=Kt.length;for(let v=0;v<E;v++){const y=Kt[v],L=pe[y],he=[];rn(L,w,0,he,w?Mt[y].rangesH:Mt[y].rangesV);const oe=L.getRangeCoordsBounds(),de=Math.ceil(oe.width),V=Math.ceil(oe.height);S[y]=Q.jsx("svg",{width:`${de}`,height:`${V}`,viewBox:`0 0 ${de} ${V}`,preserveAspectRatio:"none",shapeRendering:"crispEdges",style:{position:"absolute"},children:he})}return S},ln=l.useMemo(()=>K===!0||K?.horizontal===!0?Jt(!0):null,[tt,K,Se,X,k,ee,Z,u,f,je,Rt,pe,Mt]),cn=l.useMemo(()=>K===!0||K?.vertical===!0?Jt(!1):null,[tt,K,He,X,k,ee,_,u,f,Ke,Je,pe,Mt]),vn=l.useMemo(()=>Ct.left===0?null:Q.jsx(Pn,{linePoints:[0,0,0,Ke+1],bounds:{x:Ct.left,y:0,width:1,height:Ke+1},...ge}),[tt,Ct.left,Ke,ge]),yn=l.useMemo(()=>Ct.top===0?null:Q.jsx(Pn,{linePoints:[0,0,je+1,0],bounds:{x:0,y:Ct.top,width:je+1,height:1},...F}),[tt,Ct.top,je,F]),Qt=l.useMemo(()=>{const w=[],S=v=>{if(!v||!pe[v])return;const y=pe[v].getBounds();return Q.jsxs("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:y.width,height:y.height,clip:`rect(0, ${y.width+1}px, ${y.height+1}px, 0)`},className:`view view-${v}`,children:[ln?.[v],cn?.[v],Mt?.[v].cells]},`view:${v}`)},E=Kt.length;for(let v=0;v<E;v++)w.push(S(Kt[v]));return Q.jsx(Q.Fragment,{children:w})},[pe,ln,cn,Mt]),Rn=l.useMemo(()=>{if(!r)return;const w=(oe,de,V,me)=>{if(!me||me.length===0)return;const Be=[],Ue=me.length;for(let Ne=0;Ne<Ue;Ne++){const ye=me[Ne];let ce=oe?.get(ye);ce!==Mn&&(ce=ye(V)??Mn),de.set(ye,ce),ce&&ce!==Mn&&Be.push(ce)}return Be},S=(oe,de,V)=>{if(!V)return;const me=V.getBounds(),Be=V.getInsets(),Ue=V.getAnchor();return Q.jsxs("div",{className:Wt("view",`view-${Ue}`,Xn.view),style:{position:"absolute",pointerEvents:"none",left:me.x-Be.left,top:me.y-Be.top,width:me.width-(Be.left+Be.right),height:me.height-(Be.top+Be.bottom),clipPath:C?"inset(-2px)":"inset(0px)"},children:[w(oe,de,V,we),bn?.[Ue].overlays]},`view:${Ue}`)},E=it.current,v={},y=[],L=Object.keys(pe),he=L.length;for(let oe=0;oe<he;oe++){const de=L[oe],V=E?.[de],me=v[de]=new Map;y.push(S(V,me,pe[de]))}return it.current=v,y},[tt,pe,C,we]),En=l.useMemo(()=>{const{style:w,...S}=$e??o.CommonUtils.EmptyObject;return Q.jsx("div",{style:{width:je,height:Ke,...w},className:"sheetxl-stage",tabIndex:0,ref:Ae,...S,...Pt,children:We?We(Qt):Qt})},[je,Ke,Qt,$e,We]),sn=l.useRef(!1);return l.useEffect(()=>{!sn.current&&Mt&&(sn.current=!0,ue?.(Vt.current))},[Mt]),Q.jsxs("div",{className:Wt("sheetxl-grid",Xn["sheetxl-grid"]),style:{overflow:"visible",cursor:re,maxWidth:je,maxHeight:Ke,width:je,height:Ke,...ae},ref:Vt,children:[En,Q.jsxs("div",{className:Wt("sheetxl-overlays"),ref:et,...A,children:[Rn,vn,yn]})]})}));zn.displayName="BaseGrid";var Uo=function(){},lo=typeof window<"u",To=lo?l.useLayoutEffect:l.useEffect,_n={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};const Oo=lo&&window.ResizeObserver!==void 0?function(){var t=l.useState(null),r=t[0],i=t[1],c=l.useState(_n),u=c[0],f=c[1],a=l.useMemo(function(){return new window.ResizeObserver(function(s){if(s[0]){var p=s[0].contentRect,O=p.x,P=p.y,M=p.width,U=p.height,K=p.top,ee=p.left,Z=p.bottom,_=p.right;f({x:O,y:P,width:M,height:U,top:K,left:ee,bottom:Z,right:_})}})},[]);return To(function(){if(r)return a.observe(r),function(){a.disconnect()}},[r]),[i,u]}:function(){return[Uo,_n]},An=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,style:u={},className:f,...a}=t,[s,{width:p,height:O}]=Oo(),P=i??p,M=c??O;return Q.jsx("div",{className:f,style:{...u},children:Q.jsx("div",{style:{position:"relative",top:"0px",left:"0px",width:"100%",height:"100%",maxWidth:"100%",maxHeight:"100%",boxSizing:"content-box"},ref:s,children:Q.jsx(zn,{ref:r,width:P,height:M,...a})})})}));An.displayName="Grid";const io=l.memo(l.forwardRef((t,r)=>{const{showVerticalScrollbar:i,showHorizontalScrollbar:c,renderScrollbarHorizontal:u,renderScrollbarVertical:f,createScrollCorner:a,viewport:s,onScrollViewport:p,style:O={},className:P,onScroll:M,...U}=t,[K,ee]=l.useState(null),Z=l.useRef(null),_=l.useRef(null);gn(!s);const Me=oo([_,r]),re=l.useCallback(k=>{_.current?.scrollTo(k),p?.(k)},[]);return Q.jsx(n.ScrollPane,{className:P,style:O,ref:Z,showVerticalScrollbar:i,showHorizontalScrollbar:c,renderScrollbarHorizontal:u,renderScrollbarVertical:f,createScrollCorner:a,viewport:K,onScrollViewport:re,children:Q.jsx(An,{style:{width:"100%",height:"100%"},...U,onViewportChange:k=>ee(k),ref:Me})})}));io.displayName="ScrollableGrid";const Zn=()=>!1,co=l.memo(t=>{const{index:r,value:i,zoom:c,zoomScale:u=100,headerText:f=we=>`${we}`,headerStyle:a,headerStyleSelect:s=a,headerStyleSelectAll:p=s,headerStyleHover:O=p,verticalPadding:P=0,horizontalPadding:M=0,isSelected:U=Zn,isSelectedAll:K=Zn,coords:ee,bounds:Z,range:_,orientation:Me,view:re,style:k,...X}=t,ge=u/100,F=l.useRef(null),[fe,Le]=l.useState(!1),be=U?.(r)||!1,ze=K?.(r)?p:be?s:a;let se=ze;if(fe){let we=O;typeof O=="function"&&(we=O(ze)),se=o.CommonUtils.mergeContentful(ze,we)}return Q.jsx("div",{ref:F,style:{background:se.fill,color:se.text?.fill,fontFamily:se.text?.fontFamily??a.text?.fontFamily,fontSize:96*(se.text?.fontSize??11)/72*ge,fontStyle:se.text?.fontStyle,fontWeight:se.text?.fontWeight,lineHeight:1.2,display:"flex",justifyContent:"center",alignItems:"end",pointerEvents:"auto",paddingBottom:`${ge}px`,...k,left:k.left-(Me===o.RangeOrientation.Column?1:0),top:k.top-(Me===o.RangeOrientation.Row?1:0),width:k.width+1,height:k.height+1,overflow:"hidden"},...X,onMouseMove:we=>{n.ReactUtils.detectIt().primaryInput!=="touch"&&we.buttons===0&&Le(!0)},onMouseOut:we=>{Le(!1)},children:f(r)})});co.displayName="HeaderRenderer";const so="ew-resize",ao="ns-resize",uo=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:u,className:f,style:a,disabled:s=!1,disabledResize:p=!1,isNextHidden:O,isHidden:P,isSelected:M,isSelectedAll:U,showTouchDivider:K,headerStyle:ee,headerStyleSelect:Z,headerStyleSelectAll:_,headerStyleHover:Me,bounds:re,onPointerDown:k,onAutoFit:X,...ge}=t,F=i===o.RangeOrientation.Column;let fe=ee;M&&Z&&(fe=Z),U&&_&&(fe=_);const Le=n.ReactUtils.detectIt().primaryInput==="touch";let be=F?14:8,ze=be/2,se=0;O&&(se=-2),P&&(se=2),P&&(be=be/2+se,ze=2*se);let we=fe.dividerStrokeFill??fe.strokeFill;return!(M||U)&&se===0&&(we=`linear-gradient(${F?180:90}deg, ${fe.fill}, ${we} 55%, ${we} 100%)`),Q.jsxs("div",{className:Wt("header-divider",{disabled:s},f,`index-${u}`),ref:r,onPointerDown:Le?void 0:k,onDoubleClick:Le?void 0:()=>X?.(),style:{top:(F?0:-be/2+(se-1))+"px",left:(F?-be/2+(se-1):0)+"px",width:F?be:"calc(100% + 1px)",height:F?"calc(100% + 1px)":be,position:"absolute",overflow:"visible",pointerEvents:"all",cursor:s||p||Le?void 0:F?so:ao,...a},...ge,children:[Q.jsx("div",{style:{position:"relative",top:`${F?0:ze}px`,left:`${F?ze:0}px`,width:F?1:"100%",height:F?"100%":1,background:we},onDoubleClick:()=>X?.()}),K&&Le?Q.jsx("div",{style:{position:"absolute",cursor:"grab",zIndex:1,borderRadius:"4px",right:F?"-6px":"2px",bottom:F?"2px":"-9px",height:"24px",width:F?"24px":"18px",maxHeight:F?"calc(100% - 4px)":void 0,maxWidth:F?void 0:"calc(100% - 4px)",background:fe.fill,border:`${_.edgeStrokeFill} solid 1px`,boxShadow:`0.5px 0.5px 0px 0px ${ee.text.fill}`,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:k,children:Q.jsx("div",{style:{width:"6.4px",height:"12px",backgroundImage:`url("data:image/svg+xml,%3Csvg width='6.4' height='12' viewBox='0 0 9.6 16' version='1.1' fill='${encodeURIComponent(Z.text.fill)}' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cpath d='M 9.60008,14.40009 C 9.60008,15.28374 8.88368,16 8.00003,16 7.11639,16 6.40012,15.28374 6.40012,14.40009 c 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40012 c 0,0.88364 -0.7164,1.60004 -1.60005,1.60004 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60004 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40006 c 0,0.88365 -0.7164,1.60005 -1.60005,1.60005 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60005 C 6.40012,0.71626 7.11639,0 8.00003,0 8.88368,0 9.60008,0.71626 9.60008,1.59991 M 3.19996,14.40009 C 3.19996,15.28374 2.48369,16 1.60005,16 0.7164,16 0,15.28374 0,14.40009 c 0,-0.88365 0.7164,-1.60005 1.60005,-1.60005 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40012 c 0,0.88364 -0.71627,1.60004 -1.59991,1.60004 C 0.7164,9.60001 0,8.88361 0,7.99997 0,7.11632 0.7164,6.39992 1.60005,6.39992 c 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40006 c 0,0.88365 -0.71627,1.60005 -1.59991,1.60005 C 0.7164,3.19996 0,2.48356 0,1.59991 0,0.71626 0.7164,0 1.60005,0 2.48369,0 3.19996,0.71626 3.19996,1.59991' /%3E%3C/svg%3E%0A")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",transform:F?void 0:"rotate(90deg)"}})}):null]})})),Lo=t=>Q.jsx(uo,{...t}),zo=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:u,disabled:f=!1,disabledResize:a=!1,resizeThreshold:s=1,renderDivider:p=Lo,onDividerMouseDown:O,onDividerResizeStart:P,onDividerResize:M,onDividerResizeEnd:U,onDividerMouseUp:K,onDividerAutoFit:ee,onPointerDown:Z,..._}=t,Me=n.useCallbackRef(Z,[Z]),re=n.useCallbackRef(ee,[ee]),k=i===o.RangeOrientation.Column;let X=k?c.getVisibleColumns():c.getVisibleRows(),ge=null;X.length>0&&(k?ge=c.getRangeCoordsBounds({rowStart:0,rowEnd:0,colStart:X[0],colEnd:X[X.length-1]}):c.getRangeCoordsBounds({rowStart:X[0],rowEnd:X[X.length-1],colStart:0,colEnd:0}),ge=c.toClipBounds(ge,It));const F=l.useRef(null),[fe,Le]=l.useState(null),be=(G,xe)=>k?G.clientX-xe.clientX:G.clientY-xe.clientY,ze=c.getLayout(),se=k?ze.getColOffset(u+1):ze.getRowOffset(u+1),we=n.useSynchronizedPointerHandler({processTouch:!0,onPointerDown:G=>{if(Me?.(G),!f&&!a){const xe=k?ze.getColOffset(u):ze.getRowOffset(u),q=se-xe;F.current={isResizing:!1,startSize:q,index:u,view:c,orientation:i,onDividerMouseDown:O,onDividerResizeStart:P,onDividerResize:M,onDividerResizeEnd:U,onDividerMouseUp:K},Le(F.current),O?.(u,q)}G.stopPropagation(),G.preventDefault()},onPointerUp:(G,xe,q)=>{if(!F.current)return;F.current.isResizing&&F.current.onDividerResizeEnd?.(F.current.index,Math.max(0,F.current.startSize+be(G,q)),F.current.startSize);const T=F.current;F.current=null,Le(F.current),T.onDividerMouseUp?.(T.index)},onPointerMoveOrWait:(G,xe,q)=>{if(!F.current)return;const T=be(G,q);F.current.isResizing?F.current.onDividerResize?.(F.current.index,Math.max(0,F.current.startSize+T),F.current.startSize):Math.abs(T)>Math.max(1,s)&&(F.current={...F.current,isResizing:!0},Le(F.current),F.current.onDividerResizeStart?.(F.current.index,Math.max(0,F.current.startSize+T))),G.stopPropagation(),G.preventDefault()}}),A=n.useCallbackRef(()=>{re?.(u)},[u]);if(!ge)return;const C=p({bounds:ge,orientation:i,view:c,index:u,disabled:f,disabledResize:a,onAutoFit:A,onPointerDown:we,ref:r,..._});if(!C)return;const{getPortalContainer:$e}=n.useFullscreenPortal();let We=null;return fe&&fe.isResizing&&fe.index===u&&(We=Jn.createPortal(Q.jsx("div",{style:{position:"absolute",cursor:k?so:ao,left:0,top:0,width:"100%",height:"100%"}}),$e(),"divider:"+u)),Q.jsxs(Q.Fragment,{children:[We,Q.jsx("div",{className:Wt("header-divider-anchor"),style:{position:"absolute",pointerEvents:"auto",top:`${k?ge.y:se}px`,left:`${k?se:ge.x}px`,width:(k?0:ge.width-1)+"px",height:(k?ge.height-1:0)+"px",display:"flex"},tabIndex:-1,children:C})]})}));class Ao{naturalDimensions(r,i={}){const c=document.createElement("div");let u=i?.lineHeight??"1";!i?.lineHeight&&i.paintableText?.fontSize&&(u=Math.ceil(1.2*i.paintableText.fontSize)+"px");const f=document.createElement("div");f.style.visibility="hidden",f.style.position="absolute",f.style.textRendering="geometricprecision",f.style.display="inline-grid",f.style.overflowWrap="break-word",f.style.maxWidth=i.maxWidth?i.maxWidth+"px":"100%",f.style.lineHeight=u,f.style.letterSpacing=(i.paintableText?.letterSpacing??0)+"px",f.style.fontSize=i.paintableText?.fontSize?i.paintableText.fontSize+"px":"unset",f.style.fontFamily=i.paintableText?.fontSize?i.paintableText.fontFamily:"unset",f.style.fontWeight=i.paintableText?.fontWeight?""+i.paintableText.fontWeight:"400",f.style.fontStyle=i.paintableText?.fontStyle?i.paintableText.fontStyle:"normal",f.style.whiteSpace=i.paintableText?.wrap==="wrap"?"break-spaces":"pre",c.appendChild(f);const a=r.split(`
12
+ `);for(let p=0;p<a.length;p++){let O=document.createElement("span");f.appendChild(O),O.textContent=a[p]}a.length!==0&&a[a.length-1].length!==0||f.appendChild(document.createElement("br")),document.body.appendChild(f);let s=f.getBoundingClientRect();return f.remove(),{width:s.width,height:s.height,maxLineHeight:1.2*(i.paintableText?.fontSize||1056/72)}}}const ho=(t=void 0)=>Object.freeze({clean:t,dirty:void 0,editMode:!1}),$o=ho(),Ko=l.memo(l.forwardRef((t,r)=>{const{editState:i=$o,defaultTextStyle:c,onStartEdit:u,onChangeEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,containerBounds:O,setNaturalSize:P,onNavigate:M,textProperties:U,style:K,autoFocus:ee,...Z}=t,_=l.useRef(null),{width:Me=0}=O??{},[re,k]=l.useState(()=>i);l.useEffect(()=>{k(i)},[i]);const X=U?.align||"left",ge=U?.vAlign||"middle",F=U?.fill||"#040404",fe=U?.wrap||"wrap",Le=U?.fontFamily||"Calibri",be=U?.fontSize||11,ze=U?.fontWeight||400,se=U?.fontStyle||"normal",we=re.dirty??re.clean??"";let A=2;const C=96*be/72,$e=1.2*C;ge==="right"&&(A+=1);const We=l.useMemo(()=>new Ao().naturalDimensions(we,{maxWidth:fe==="wrap"?Me-A:void 0,lineHeight:`${$e}px`,paintableText:{fontStyle:se,wrap:fe,letterSpacing:-.25}}),[we,fe,A,C,Le,ze,se,P,Me]),G=l.useCallback(()=>We.maxLineHeight?We.maxLineHeight+"px":"1.2",[We]),[xe,q]=l.useState(G);l.useLayoutEffect(()=>{q(G())},[O,We]),l.useLayoutEffect(()=>{P?.({width:fe==="wrap"?void 0:We.width+A,height:We.height})},[We,P]);const T=n.useCallbackRef(f,[f]),H=n.useCallbackRef(R=>{if(re.dirty===R)return;const Ce={...re};Ce.dirty=R,_.current,k(Ce),T?.(Ce)},[re]),St=n.useCallbackRef(R=>{if(re.editMode===R)return;const Ce={...re};Ce.editMode=R,k(Ce),T?.(Ce)},[re]),xt=n.useCallbackRef(()=>{try{return a?.(re),p?.(),!0}catch{return!1}},[a,re]),ct=n.useCallbackRef(()=>{k(i),s?.(),p?.()},[s,i]),rt=n.useCallbackRef(R=>{if(!_.current)return;if(R.isDefaultPrevented(),!(R.isTrusted||R.nativeEvent.ctrlKey||R.nativeEvent.metaKey||R.nativeEvent.altKey||R.nativeEvent.isComposing)&&On.indexOf(R.nativeEvent.key)!==-1){const te={...re};return te.dirty=R.nativeEvent.key==="Backspace"?"":(te.dirty??"")+R.key,k(te),T?.(te),void R.preventDefault()}const Ce=R.nativeEvent.shiftKey;if(R.which===n.KeyCodes.Escape)return R.preventDefault(),void ct();if(R.which===n.KeyCodes.F2)return St(!0),void R.preventDefault();if(R.which===n.KeyCodes.Enter&&(R.preventDefault(),xt()&&M?.(Ce?o.Direction.Up:o.Direction.Down)),R.which===n.KeyCodes.Tab)return R.preventDefault(),void(xt()&&M?.(Ce?o.Direction.Left:o.Direction.Right));if(!re.editMode){let te=null;switch(R.which){case n.KeyCodes.Left:te=o.Direction.Left;break;case n.KeyCodes.Right:te=o.Direction.Right;break;case n.KeyCodes.Up:te=o.Direction.Up;break;case n.KeyCodes.Down:te=o.Direction.Down}if(te)return void xt()}},[re,M]),[ae,Pt]=l.useState(!ee);l.useEffect(()=>{Pt(!1)},[]);const D=n.useImperativeElement(r,()=>({startEdit(R){let Ce=R?.initialSelection;if(!Ce){const ue=_.current.value.length??0;Ce={start:ue,end:ue,direction:"forward"}}_.current?.setSelectionRange(Ce.start,Ce.end,Ce.direction);const te={...i,editMode:R?.editMode??!1};R?.text!==void 0&&(te.dirty=R.text),te.editMode===i.editMode&&te.dirty===i.dirty||(k(te),T?.(te))},submitEdit:()=>xt(),cancelEdit(){ct()},autoFocus(){_.current?.focus()},getLineHeight:()=>We?.maxLineHeight??$e,dispatchEvent:R=>_.current.dispatchEvent(R)}),[i,u]);return Q.jsx("div",{ref:D,...Z,style:{background:"transparent",display:"flex",flexGrow:1,alignSelf:"center",height:We.height,maxWidth:"100%",maxHeight:"100%",...K},children:Q.jsx("textarea",{spellCheck:"false",ref:_,value:we,autoFocus:!1,disabled:ae,name:"cell-editor",autoComplete:"off",autoCapitalize:"off",style:{flex:"1 1 100%",position:"relative",fontSize:`${C}px`,fontFamily:`${Le}`,fontWeight:`${ze}`,fontStyle:`${se}`,padding:"0px",marginRight:X==="right"?"3px":"0px",marginLeft:X==="left"?"2px":"0px",lineHeight:xe,height:We.height,textRendering:"geometricPrecision",letterSpacing:"-0.25px",boxSizing:"border-box",borderWidth:0,outline:"none",resize:"none",overflow:"hidden",verticalAlign:"baseline",textAlign:X,background:"transparent",color:F,marginBottom:"0px",userSelect:"text",maxHeight:"100%",whiteSpace:fe==="wrap"?"break-spaces":"pre",wordWrap:"break-word"},onChange:R=>{H(R.target.value)},onDoubleClick:R=>{R.isTrusted},onMouseDown:R=>{St(!0)},onKeyDown:rt})})})),Bo=l.memo(t=>{const{value:r,view:i,bounds:c,range:u,zoom:f,children:a,style:s,...p}=t,O=s?.fontSize||1056/72;return Q.jsx("div",{style:{padding:"2px 4px",fontFamily:"Calibri",letterSpacing:-.25,lineHeight:1.2,fontSize:O,...s},...p,children:r})});exports.BaseGrid=zn,exports.DefaultCellEditor=Ko,exports.DefaultCellRenderer=Bo,exports.DefaultHeaderDivider=uo,exports.FillHandle=Un,exports.Grid=An,exports.HeaderDivider=zo,exports.HeaderRenderer=co,exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL=150,exports.SELECTION_CLIP_INSETS=It,exports.STANDARD_KEY_CHARS=On,exports.SVGLine=Pn,exports.SVGRect=to,exports.ScrollableGrid=io,exports.Selection=Ln,exports.TouchSelectHandle=fn,exports.defaultSelectionRenderer=Yn,exports.getDefaultStringEditState=ho,exports.safeSelectionCoords=yt,exports.useCellLayout=eo,exports.useHeaderSelection=({gridRef:t,gridMainRef:r,orientation:i=o.RangeOrientation.Row,headerCount:c,selectionPolicy:u="multiple",newSelectionMode:f="clear",alwaysScrollToActiveCoords:a=!0,onDragStart:s,onDragEnd:p,pointerDownInterceptor:O,pointerMoveInterceptor:P,onPointerUp:M,newSelection:U,modifySelection:K,appendSelection:ee,clearSelections:Z})=>{const _=c??((i===o.RangeOrientation.Row?t.current?.rowCount:t.current?.columnCount)||0),Me=l.useRef(null),re=l.useRef(null),k=l.useRef(!1),X=l.useRef(null),ge=l.useCallback(A=>i===o.RangeOrientation.Column?{rowIndex:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:0},[i]),F=l.useCallback(A=>i===o.RangeOrientation.Column?{rowIndex:r.current?r.current.rowCount-1:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:r.current?r.current.columnCount-1:0},[i]),fe=A=>{re.current=F(A),K(re.current,Me.current)},Le=l.useCallback((A,C)=>{if(!t.current)return;const $e=t.current.getViewFromClient(A,C)?.getCellCoordsFromClient(A,C);return $e?(i===o.RangeOrientation.Column?$e.rowIndex=r.current.getViewport().rowStart:$e.colIndex=r.current.getViewport().colStart,$e):void 0},[]),be=l.useCallback((A,C=!1)=>{let $e=A;return C||($e={...A},i===o.RangeOrientation.Row?delete $e.colIndex:delete $e.rowIndex),r.current?.scrollCellCoordsIntoView($e)},[i]),ze=n.useCallbackRef(p,[p]),se=n.useCallbackRef(s,[s]),we=l.useMemo(()=>({onPointerDown:A=>{if(!t||!t.current||A.nativeEvent.defaultPrevented)return;const C=Le(A.nativeEvent.clientX,A.nativeEvent.clientY);if(!C)return;A.nativeEvent.which,n.MouseButtonCodes.Right;const $e=A.nativeEvent.shiftKey,We=A.nativeEvent.ctrlKey||A.nativeEvent.metaKey;if(O?.(A,C)===!1)return;se?.(),k.current=!0;const G=r.current?.getViewFromClient(A.nativeEvent.clientX,A.nativeEvent.clientY),xe=((q,T)=>i===o.RangeOrientation.Column?{...q,rowIndex:T.rowStart}:{...q,colIndex:T.colStart})(C,G.getVisibleRangeCoords());if($e)fe(C);else{if(We)return((q,T=q,H)=>{Me.current=ge(q),re.current=F(T),ee(Me.current,re.current,H)})(C,C,xe),void(a&&be(xe,!0));((q,T=q,H)=>{Me.current=ge(q),re.current=F(T),U(Me.current,re.current,H)})(C,C,xe),fe(C),a&&be(xe,!0)}},onPointerMoveOrWait:o.CommonUtils.throttle(A=>{if(!k.current||!t?.current)return;const C=Le(A.clientX,A.clientY);if(C&&P?.(A,C)!==!1){if(o.CoordUtils.isEqualCells(X.current,C))return Z();fe(C),be(C)}},60),onPointerUp:A=>{k.current=!1,ze?.(),M?.(A)},processTouch:!0,consumeTouch:!0}),[u,a,_,f,Z,O,M]);return{onPointerDown:n.useCallbackRef(n.useSynchronizedPointerHandler(we),[]),getCellCoordsFromClient:Le}},exports.useKeyboardEditorOverlay=t=>{const{view:r,canEdit:i=xo,getCellEditor:c,onBeforeStartEdit:u,onStartEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,isEditorStartKeyEvent:O=po,isEditorStartPointerEvent:P=mo,propsContainer:M,borderStrokeFill:U,borderStrokeWidth:K=2,getRangeCoords:ee=null,activeCoords:Z,alignment:_=n.HorizontalAlignment.Left}=t,[Me,re]=l.useState(!1),[k,X]=l.useState(void 0),ge=n.useCallbackRef((D,R,Ce,te,ue,Ae)=>{if(!R)return null;const et=ue?.(R,D),mt=D.getRangeCoordsBounds(et),tt=D.toClipBounds(mt),Tt=mt,st=D.getZoom();if(!tt)return null;Ce&&(Ce*=st),te&&(te*=st);let b=Tt,ne=!1;if(Ce!==void 0){let Ye={...et},jt=0;for(;!ne&&b.width<=Ce&&jt<20;){jt++,jt>19&&console.warn("max width reached");const $t=D.getTotalRangeCoords(),bt=D.getLayout();Ae===n.HorizontalAlignment.Left?Ye.colEnd+1<$t.colEnd?Ye.colEnd=bt.getColIndex(b.x+Ce):ne=!0:Ae===n.HorizontalAlignment.Right?Ye.colStart-1>=0?Ye.colStart=bt.getColIndex(b.x-(Ce-b.width)):ne=!0:Ae===n.HorizontalAlignment.Center&&Ye.colEnd+1<$t.colEnd&&Ye.colStart-1>=0?(Ye.colStart=bt.getColIndex(b.x-(Ce-b.width)/2),Ye.colEnd=bt.getColIndex(b.x+b.width+(Ce-b.width)/2)):ne=!0,ne||(b=D.getRangeCoordsBounds(Ye))}}b.height=Tt.height,te!==void 0&&(b.height=Math.max(te+1,Tt.height));const{width:Pe,height:lt}=D.getViewportSize();return{x:b.x??0,y:b.y??0,height:Math.min(lt-b.y,b.height)+1,width:Math.min(Pe-b.x,b.width)+1}},[_]),F=n.useCallbackRef(i,[i]),fe=l.useCallback(()=>{r?.getStage()?.focus()},[r]),Le=l.useRef(null),be=n.useCallbackRef(D=>{u?.(D),T(),re(!0),Le.current=null},[u]),ze=n.useCallbackRef(D=>{f?.(D.coords)},[f]),se=n.useCallbackRef(D=>{D.isSubmitted||D.isCancelled||(C.current.isEditorClosed=!0,fe(),D.isCancelled=!0,s?.(D.coords),T())},[s]),we=n.useCallbackRef(D=>{if(D.isSubmitted||D.isCancelled)return!1;try{return Le.current=D.coords,D.isEditorClosing=!0,D.isSubmitted=!0,D.isEditorSubmitted||(D.isEditorSubmitted=!0,D.editorRefs[0]?.submitEdit?.()),D.coords,a?.(D.coords),D.isEditorClosed=!0,fe(),T(),!0}catch(R){throw D.isEditorClosing=!1,D.isSubmitted=!1,R}},[a]),A=n.useCallbackRef(D=>{re(!1),p?.(D.coords),T()},[p]),C=l.useRef(null),$e=l.useRef(null),We=l.useRef(null),G=l.useRef([]),[xe,q]=l.useReducer(D=>D+1,0),T=l.useCallback(D=>{D&&G.current.push(D),q()},[]),H=n.useCallbackRef(D=>{if(D.defaultPrevented||D.isSynthetic||!r)return;const R=r?.getCellCoordsFromClient(D.clientX,D.clientY);R&&T({eventType:"pointer",event:D,coords:R})},[r]),St=n.useCallbackRef(D=>{const R=D.nativeEvent;H(R)},[r]),xt=n.useCallbackRef(D=>{if(D.defaultPrevented||D.isSynthetic||!r?.getStage())return;const R=$e.current;O(D,R)&&(D.stopPropagation(),D.preventDefault()),D.key,T({eventType:"keyboard",event:D,coords:R})},[r]);l.useLayoutEffect(()=>{const D=(te,ue)=>{const Ae=ue?.cell??te;if(!Ae)return null;const et=Ae;if(!F(Ae))return null;be?.(Ae);const mt=o.CommonUtils.uuidV4();ue=Object.freeze({autoFocus:!0,...ue}),We.current=Ae;const tt={coords:et,startEvent:ue,uuid:mt,isMounted:!1,isStarted:!1,isSubmitted:!1,isEditorSubmitted:!1,isEditorClosing:!1,isEditorClosed:!1,isCancelled:!1,events:[],editorRefsDispatchEditorEvent:[],editorRefs:[],onMount:Tt=>{tt.isMounted||(tt.isMounted=!0,T())},onUnmount:Tt=>{if(tt.editorRefs.length===0){const st=()=>{tt.isMounted=!1,T()};if(document.activeElement!==document.body)st();else{const b=ne=>{ne.defaultPrevented||ne.target!==document.body||xt(ne)};window.addEventListener("keydown",b,!0),r.getStage()?.addEventListener("focusin",()=>{window.removeEventListener("keydown",b),st()},So),fe()}}}};return tt};if(G.current.length<=0&&!C.current)return;const R=G.current[0];Fn(R),(te=>{const ue=[],Ae=te?.length??0;for(let et=0;et<Ae;et++){const mt=te[et];ue.push(Fn(mt))}})(G.current),C.current,C.current;let Ce=C.current;if(C.current){if(C.current.isDone)C.current=null;else if(C.current.isSubmitted||C.current.isCancelled){if(C.current.isMounted)return;C.current.isDone||(A(C.current),C.current.isDone=!0)}}if(R){if(R.eventType==="start"){const te=R,ue=te.startEvent?.cell??$e.current;C.current&&o.CoordUtils.isEqualCells(C.current.coords,ue)||(C.current=D(ue,te.startEvent))}else if(R.eventType==="keyboard"){const te=R.event;if(C.current){let ue=!1;switch(te.which){case n.KeyCodes.Left:case n.KeyCodes.Right:case n.KeyCodes.Up:case n.KeyCodes.Down:case n.KeyCodes.Enter:case n.KeyCodes.Tab:ue=!0}if(!ue){C.current.events.push(R);for(let Ae=0;Ae<C.current.editorRefsDispatchEditorEvent.length;Ae++)C.current.editorRefsDispatchEditorEvent[Ae](R)}}else if(O(te,R.coords)){let ue;const Ae=D(ue?.cell??$e.current,ue);Ae&&Ae.events.push(R),C.current=Ae}}else if(R.eventType==="pointer"){const te=R.event;if(C.current){C.current.events.push(R);for(let ue=0;ue<C.current.editorRefsDispatchEditorEvent.length;ue++)C.current.editorRefsDispatchEditorEvent[ue](R)}else{const ue=R?.coords??$e.current,Ae=P(te,ue);if(Ae){let et;typeof et!="boolean"&&(et=Ae);const mt=D(ue,et);mt&&mt.events.push(R),C.current=mt}}}else if(R.eventType==="submit"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;we(C.current)}}else if(R.eventType==="cancel"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;se(C.current)}}else if(R.eventType==="coordsChange"){const te=R;if($e.current=te.activeCoords,C.current,C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;try{we(C.current)}catch{}}}}G.current.length>0&&(G.current.shift(),T()),G.current.length===0&&(!C.current||C.current.isEditorClosing||C.current.isEditorClosed?!C.current&&Ce&&fe():C.current.isMounted&&!C.current.isStarted&&(C.current.isStarted=!0,C.current.startEvent.autoFocus&&(typeof C.current.startEvent.autoFocus=="string"?C.current.editorRefs[0]?.autoFocus(C.current.startEvent.autoFocus):C.current.editorRefs[0]?.autoFocus()),ze?.(C.current),requestAnimationFrame(()=>{r&&C.current?.coords&&r.scrollCellCoordsIntoView(C.current.coords)})))},[xe]),l.useEffect(()=>{We.current=Z;const D=C.current?.coords;o.CoordUtils.isEqualCells(D,Z)||(C.current&&(C.current.isEditorClosing=!0),T({eventType:"coordsChange",activeCoords:Z}))},[Z]);const ct=l.useCallback(D=>{xt(D.nativeEvent)},[]),{width:rt=0,height:ae=0}=k??{width:0,height:0},Pt=n.useCallbackRef(c,[c]);return{renderOverlay:n.useCallbackRef(D=>{if(!C.current||C.current.isEditorClosed)return C.current,null;C.current.coords;let R=ge(D,C.current.coords,rt,ae,ee,_),Ce=!0;R&&R.width!==0&&R.height!==0||(R={x:0,y:0,width:rt,height:rt},Ce=!1);const te=D.getZoom(),ue={containerBounds:{x:0,y:0,width:R.width/te,height:R.height/te},setNaturalSize:X,zoom:te};return Q.jsx(Co,{session:C.current,refLatestCoords:We,handleSubmitEdit:we,handleCancelEdit:se,cellBounds:R,borderStrokeWidth:K,borderStrokeFill:U,isInBounds:Ce,getCellEditor:Pt,propsEditor:ue,alignment:_,...M},"editor:"+C.current.uuid)},[c,ee,xe,rt,ae,_,K,U]),startEdit:l.useCallback(D=>{T({eventType:"start",startEvent:D})},[]),submitEdit:l.useCallback(()=>{T({eventType:"submit"})},[]),cancelEdit:l.useCallback(()=>{T({eventType:"cancel"})},[]),onKeyboardEvent:ct,onPointerEvent:St,onKeyboardEventNative:xt,onPointerEventNative:H,isEditing:Me}},exports.useSelection=({gridRef:t,commands:r,layout:i,selection:c,onSelectionChange:u,onSelectionDragStart:f,onSelectionDragEnd:a,selectionPolicy:s="multiple",newSelectionMode:p="clear",allowDeselectSelection:O=!0,onFillPreview:P,onFillCancel:M,onFillDone:U,onFill:K,disableFillDrag:ee=!K,fillHandleBorderColor:Z="white",hiddenRowsAt:_,hiddenColumnsAt:Me,isContentfulCell:re,contentfulCellFinder:k=yo,getDataCoords:X,alwaysScrollToActiveCoords:ge=!1,selectionBounds:F,pointerDownInterceptor:fe,pointerMoveInterceptor:Le,mergedRanges:be,canSelectionSpanMergedCells:ze=ko,onMoveDragStart:se,onMoveDragUpdate:we,onMoveDragEnd:A,onMoveDragDone:C,renderSelection:$e=Yn,disableMoveDrag:We=!A,getCellCoordsAsRangeCoords:G=o.CoordUtils.cellToRange,moveDragHitSize:xe=6,moveDragOutlineSize:q=4,selectionBackgroundColor:T="rgba(16, 124, 65, 0.1)",selectionBorderColor:H="rgb(33, 115, 70)",selectionRemoveBorderColor:St="rgb(255, 0, 0)",selectionRemoveBackgroundColor:xt="rgba(250, 10, 10, 0.1)",disableTouchSelection:ct=!1,propsTouchSelectHandle:rt})=>{const ae=l.useCallback(()=>({top:F?.top??0,left:F?.left??0,bottom:t.current?.rowCount-1||0,right:t.current?.columnCount-1||0}),[]),Pt=n.useCallbackRef(K,[K]),D=n.useCallbackRef(P,[P]),R=n.useCallbackRef(M,[M]),Ce=n.useCallbackRef(U,[U]),te=n.useCallbackRef(re,[re]),ue=n.useCallbackRef($e,[$e]),Ae=n.useCallbackRef((e,d=!1)=>wn(e,d,i.getRowOffset,d?ae().bottom:ae().top),[i?.getRowOffset]),et=n.useCallbackRef(_??Ae,[_]),mt=n.useCallbackRef((e,d=!1)=>wn(e,d,i.getColOffset,d?ae().right:ae().left),[i?.getColOffset]),tt=n.useCallbackRef(Me??mt,[Me]),[Tt,st]=l.useState(()=>yt(c)),b=l.useMemo(()=>yt(Tt),[Tt]),ne=l.useRef(b),Pe=l.useRef(null);l.useMemo(()=>{Pe.current=c},[c]),l.useLayoutEffect(o.CommonUtils.throttle(()=>{st(e=>{const d=yt(c);return Pe.current=d,o.CoordUtils.isEqualSelectionCoords(d,e)?e:d})},0),[c]),l.useLayoutEffect(()=>{ne.current=b},[b]),l.useEffect(()=>{Pe.current||!u||o.CoordUtils.isEqualSelectionCoords(c,b)||u(b)},[b]);const lt=l.useCallback(e=>{st(d=>{Pe.current=null,d=yt(d);let g=typeof e=="function"?e(d.ranges):e??Tn;if(o.CoordUtils.isEqualRangesArrays(g,d.ranges))return d;let h=Math.max(g.length?0:-1,Math.min(d.rangeIndex,g.length-1)),x=d.cell;h===-1||o.CoordUtils.isCellWithinRange(x,g[h])||(x={rowIndex:g[h].rowStart,colIndex:g[h].colStart}),g.length===1&&o.CoordUtils.isSingleCell(g[0])&&o.CoordUtils.isCellWithinRange(x,g[0])&&(g=[],h=-1);const I={cell:x,ranges:g,rangeIndex:h};return o.CoordUtils.isEqualSelectionCoords(I,d)?d:I})},[]),Ye=n.useCallbackRef(e=>{st(d=>{Pe.current=null,d=yt(d);const g=e??ro,h=G(g);if(!o.CoordUtils.isSingleCell(h)&&d.ranges.length===0)return{ranges:[h],rangeIndex:0,cell:g};if(o.CoordUtils.isEqualCells(g,d.cell))return d;let x=d.ranges,I=d.rangeIndex;d.ranges.length===1&&(o.CoordUtils.isSingleCell(d.ranges[0])&&o.CoordUtils.isCellWithinRange(g,d.ranges[0])||!o.CoordUtils.isCellWithinRange(g,d.ranges[0]))&&(x=[],I=-1);const m={ranges:x,rangeIndex:I,cell:g};return o.CoordUtils.isEqualSelectionCoords(m,d)?d:m})},[G]),[jt,$t]=l.useState(null),[bt,Xt]=l.useState(null),At=l.useRef(null),[ve,Ut]=l.useState(null),ht=l.useRef(null),kt=l.useRef(null),[en,Ht]=l.useState(null),je=l.useRef(null),Ke=l.useRef(null),Ft=l.useRef(be);l.useEffect(()=>{Ft.current=be},[be]);const ft=n.useCallbackRef((e,d={inline:"nearest",block:"nearest"})=>{let{rowIndex:g,colIndex:h}=e;g===void 0&&b?.cell&&(g=b.cell.rowIndex),h===void 0&&b?.cell&&(h=b.cell.colIndex),g!==void 0&&h!==void 0&&t.current?.scrollCellCoordsIntoView({rowIndex:g,colIndex:h},d)},[b]),Ot=l.useCallback(e=>{const d=ae();return e.rowIndex<d.top||e.colIndex<d.left||e.colIndex>d.right||e.rowIndex>d.bottom},[]),Se=n.useCallbackRef((e,d)=>{if(!t?.current)return null;const g={rowStart:Math.min(e.rowIndex,d.rowIndex),colStart:Math.min(e.colIndex,d.colIndex),rowEnd:Math.max(e.rowIndex,d.rowIndex),colEnd:Math.max(e.colIndex,d.colIndex)};if(ze?.(g))return g;const x=G(e),I=G(d),m={rowStart:Math.min(x.rowStart,I.rowStart),colStart:Math.min(x.colStart,I.colStart),rowEnd:Math.max(x.rowEnd,I.rowEnd),colEnd:Math.max(x.colEnd,I.colEnd)};let N;return typeof Ft.current=="function"?N=Ft.current(m):be&&(N=be),N?o.CoordUtils.extendRangeToUnionRanges(m,N):m},[ze,G]),He=n.useCallbackRef((e,d,g)=>{const h=e.ranges.length>0?e.ranges[e.rangeIndex]:{rowStart:e.cell.rowIndex,colStart:e.cell.colIndex,rowEnd:e.cell.rowIndex,colEnd:e.cell.colIndex},x={rowStart:Math.min(d.rowIndex??h.rowStart,g.rowIndex??h.rowStart),colStart:Math.min(d.colIndex??h.colStart,g.colIndex??h.colStart),rowEnd:Math.max(d.rowIndex??h.rowEnd,g.rowIndex??h.rowEnd),colEnd:Math.max(d.colIndex??h.colEnd,g.colIndex??h.colEnd)},I={rowIndex:x.rowStart,colIndex:x.colStart},m={rowIndex:x.rowEnd,colIndex:x.colEnd};if(!(Ot(I)||Ot(m)))return Se(I,m)},[Se]),it=n.useCallbackRef((e,d,g)=>{if(s==="single"||!ne.current)return;const h=He(ne.current,e,d??ne.current.cell);if(!h)return;const x=ne.current.rangeIndex;lt(I=>I.length?I.map((m,N)=>x===N?h:m):[h]),g&&h&&Ye({colIndex:h.colStart,rowIndex:h.rowStart})},[]),pt=l.useCallback((e,d,g)=>{if(!ne.current)return;e={...ne.current?.cell,...e},d=d??e;const h=He(ne.current,e,d);if(!h)return;const x={rowIndex:h.rowStart,colIndex:h.colStart},I={...x,...g};p==="clear"?(je.current=I,Kt()):p==="modify"?it(x):pe(x),Ye(I)},[]),pe=l.useCallback((e,d=e,g)=>{s!=="multiple"||!e||Ot(e)||Ot(d)||st(h=>{Pe.current=null,h=yt(h);const x=Se(e,d);if(!x)return h;let I=h.ranges.length>0?[...h.ranges]:[Se(h.cell,h.cell)];I.push(x);const m={ranges:I,cell:{rowIndex:x.rowStart,colIndex:x.colStart,...g},rangeIndex:I.length-1};return o.CoordUtils.isEqualSelectionCoords(m,h)?h:m})},[]),Kt=()=>{lt(Tn)},Rt=n.ReactUtils.detectIt().primaryInput==="touch",Je=l.useRef(null),Ct=l.useRef(null),vt=l.useRef(null),Nt=l.useMemo(()=>({onPointerDown:e=>{if(!t||!t.current)return!1;const d=e.nativeEvent,g=t.current.getViewFromClient(d.clientX,d.clientY);if(d.pointerType==="touch"||d.type==="touchstart")return Ct.current={topLeft:g.getScrollTopLeft(),point:{x:d.clientX,y:d.clientY}},!0;const h=g.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return!1;Je.current={anchor:g.getAnchor(),coords:h},Ke.current=null;const x=e.nativeEvent.which===n.MouseButtonCodes.Right;if(x&&o.CoordUtils.indexOfCoords(h,b.ranges)!==-1)return!1;const I=e.nativeEvent.shiftKey,m=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,N=m,B=O,W=b.ranges.length>0,Y=m&&B;if(fe?.(e,h,b)===!1)return!1;f?.(ne.current,e);const Ie=!x&&s!=="single";if(I)return it(h),Ie;const Xe=o.CoordUtils.isEqualCells(h,b.cell);if(N){if(Xe&&(!Y||!W))return Ie;if(m&&o.CoordUtils.indexOfCoords(h,b.ranges)!==-1&&B){ht.current=h;const $=Se(h,h);return kt.current=$,Ut($),Ie}return pe(h),Ie}ge&&ft(h),Xe&&b.ranges.length===0||pt(h)},onPointerMoveOrWait:o.CommonUtils.throttle((e,d)=>{if(!t?.current||e.pointerType==="touch"||e.type==="touchmove"||!Je.current)return;const g=Je.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!o.CoordUtils.isEqualCells(x,Je.current?.coords)&&(Je.current={anchor:g,coords:x},x&&Le?.(e,x,ne.current)!==!1)){if(ht.current){const I={rowStart:Math.min(x.rowIndex,ht.current.rowIndex),colStart:Math.min(x.colIndex,ht.current.colIndex),rowEnd:Math.max(x.rowIndex,ht.current.rowIndex),colEnd:Math.max(x.colIndex,ht.current.colIndex)},m={rowIndex:I.rowStart,colIndex:I.colStart},N={rowIndex:I.rowEnd,colIndex:I.colEnd};if(Ot(m)||Ot(N))return;const B=Se(m,N);kt.current=B,Ut(B)}else it(x);vt.current=d,hn(h,x,t)}},60),onPointerUp:e=>{if(Je.current=null,e.pointerType==="touch"||e.type==="touchend"){if(Ct.current){const g=t.current.getViewFromClient(Ct.current.point.x,Ct.current.point.y),h=g.getScrollTopLeft();if(h.left===Ct.current.topLeft.left&&h.top===Ct.current.topLeft.top){const x=g.getCellCoordsFromClient(Ct.current.point.x,Ct.current.point.y);pt(x)}}return Ct.current=null,void(Je.current=null)}try{a?.(ne.current,e)}catch(g){console.warn(g)}if(!ht.current)return;const d=kt.current;ht.current=null,kt.current=null,Ut(null),st(g=>{if(Pe.current=null,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,I=g.cell;for(let N=0;N<g.ranges.length;N++){const B=g.ranges[N];if(o.CoordUtils.isRangesIntersect(B,d)){const W=o.CommonUtils.subtractRect({top:B.rowStart,left:B.colStart,bottom:B.rowEnd+1,right:B.colEnd+1},{top:d.rowStart,left:d.colStart,bottom:d.rowEnd+1,right:d.colEnd+1});for(let Y=0;Y<W.length;Y++){const Ie={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(Ie),o.CoordUtils.isCellWithinRange(g.cell,Ie)&&(x=h.length-1)}}else h.push(B);h.length>0&&x===-1&&o.CoordUtils.isCellWithinRange(g.cell,B)&&(x=h.length-1,I={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:I,rangeIndex:x,ranges:h};return o.CoordUtils.isEqualSelectionCoords(m,g)?g:m})},processTouch:!0,consumeTouch:!1}),[b,s,O,ge,p]),xn=n.useCallbackRef(n.useSynchronizedPointerHandler(Nt),[]),pn=l.useMemo(()=>({onSelectionPointerDown:(e,d,g,h,x=b.cell,I=ge,m=e.nativeEvent.shiftKey,N=!1)=>{if(!t||!t.current)return!1;e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();const B=g??t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),W=h??B.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!W)return!1;Je.current={anchor:B.getAnchor(),coords:W},Ke.current=null;const Y=e.nativeEvent.which===n.MouseButtonCodes.Right;if(Y&&o.CoordUtils.indexOfCoords(W,b.ranges)!==-1)return!1;const Ie=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,Xe=Ie,$=O,ie=b.ranges.length>0,z=Ie&&$;if(fe?.(e,W,b)===!1)return!1;f?.(ne.current,e);const le=!Y&&s!=="single";if(m)return it(W,x,N),le;const qe=o.CoordUtils.isEqualCells(W,x);if(Xe){if(qe&&(!z||!ie))return le;if(z&&o.CoordUtils.indexOfCoords(W,b.ranges)!==-1&&$){ht.current=W;const ut=Se(W,W);return kt.current=ut,Ut(ut),le}return pe(W),le}I&&ft(W),qe&&b.ranges.length===0||pt(W)},onSelectionPointerMoveOrWait:(e,d,g,h,x,I=b.cell,m=!0,N=!1)=>{if(!t?.current||(e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation(),!Je.current))return;const B=Je.current.anchor;let W=h??t.current.getViewFromLocation(B),Y=x??W.getCellCoordsFromClient(e.clientX,e.clientY);if(!o.CoordUtils.isEqualCells(Y,Je.current?.coords)&&(Je.current={anchor:B,coords:Y},Y&&Le?.(e,Y,ne.current)!==!1)){if(ht.current){const Ie={rowStart:Math.min(Y.rowIndex,ht.current.rowIndex),colStart:Math.min(Y.colIndex,ht.current.colIndex),rowEnd:Math.max(Y.rowIndex,ht.current.rowIndex),colEnd:Math.max(Y.colIndex,ht.current.colIndex)},Xe={rowIndex:Ie.rowStart,colIndex:Ie.colStart},$={rowIndex:Ie.rowEnd,colIndex:Ie.colEnd};if(Ot(Xe)||Ot($))return;const ie=Se(Xe,$);kt.current=ie,Ut(ie)}else it(Y,I,N);m&&hn(W,Y,t)}},onPointerUp:e=>{Je.current=null,e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();try{a?.(ne.current,e)}catch(g){console.warn(g)}if(!ht.current)return;const d=kt.current;ht.current=null,kt.current=null,Ut(null),st(g=>{if(Pe.current=null,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,I=g.cell;for(let N=0;N<g.ranges.length;N++){const B=g.ranges[N];if(o.CoordUtils.isRangesIntersect(B,d)){const W=o.CommonUtils.subtractRect({top:B.rowStart,left:B.colStart,bottom:B.rowEnd+1,right:B.colEnd+1},{top:d.rowStart,left:d.colStart,bottom:d.rowEnd+1,right:d.colEnd+1});for(let Y=0;Y<W.length;Y++){const Ie={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(Ie),o.CoordUtils.isCellWithinRange(g.cell,Ie)&&(x=h.length-1)}}else h.push(B);h.length>0&&x===-1&&o.CoordUtils.isCellWithinRange(g.cell,B)&&(x=h.length-1,I={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:I,rangeIndex:x,ranges:h};return o.CoordUtils.isEqualSelectionCoords(m,g)?g:m})}}),[b,s,O,ge,p]),Qe=n.useCallbackRef((e,d=!1,g=!1,h=0)=>{if(!t.current||!b.cell)return;let x=b.cell,I=b.cell;if(d&&b.ranges.length>0){const z=b.ranges[b.rangeIndex],le=b.cell;switch(e){case o.Direction.Up:I={rowIndex:le.rowIndex===z.rowStart?z.rowEnd:z.rowStart,colIndex:z.colEnd},x={rowIndex:le.rowIndex===z.rowStart?z.rowStart:z.rowEnd,colIndex:z.colStart};break;case o.Direction.Down:I={rowIndex:le.rowIndex===z.rowEnd?z.rowStart:z.rowEnd,colIndex:z.colEnd},x={rowIndex:le.rowIndex===z.rowEnd?z.rowEnd:z.rowStart,colIndex:z.colStart};break;case o.Direction.Left:I={rowIndex:z.rowEnd,colIndex:le.colIndex===z.colStart?z.colEnd:z.colStart},x={rowIndex:z.rowStart,colIndex:le.colIndex===z.colStart?z.colStart:z.colEnd};break;case o.Direction.Right:I={rowIndex:z.rowEnd,colIndex:le.colIndex===z.colEnd?z.colStart:z.colEnd},x={rowIndex:z.rowStart,colIndex:le.colIndex===z.colEnd?z.colEnd:z.colStart}}}const m=G(I);let{rowStart:N,colStart:B}=m;const W=ae();if(Ke.current)switch(e){case o.Direction.Up:case o.Direction.Down:Ke.current.colIndex>=m.colStart&&Ke.current.colIndex<=m.colEnd&&(B=Ke.current.colIndex);break;case o.Direction.Left:case o.Direction.Right:Ke.current.rowIndex>=m.rowStart&&Ke.current.rowIndex<=m.rowEnd&&(N=Ke.current.rowIndex)}if(!h){switch(e){case o.Direction.Up:N=Oe(et,Math.max(m.rowStart-1,W.top),e);break;case o.Direction.Down:N=Oe(et,Math.min(m.rowEnd+1,W.bottom),e);break;case o.Direction.Left:B=Oe(tt,Math.max(m.colStart-1,W.left),e);break;case o.Direction.Right:B=Oe(tt,Math.min(m.colEnd+1,W.right),e)}if(g)switch(e){case o.Direction.Up:N=k({...I,colIndex:b.cell.colIndex},te,et,e,!1,Math.max(W.top,et(W.top,!1)));break;case o.Direction.Down:N=k({...I,colIndex:b.cell.colIndex},te,et,e,!1,Math.min(W.bottom,W.bottom-et(W.bottom,!0)));break;case o.Direction.Left:B=k({...I,rowIndex:b.cell.rowIndex},te,tt,e,!1,Math.max(W.left,tt(W.left,!1)));break;case o.Direction.Right:B=k({...I,rowIndex:b.cell.rowIndex},te,tt,e,!1,Math.min(W.right,W.right-tt(W.right,!0)))}}let Y=null;if(h){let z=0;switch(e){case o.Direction.Up:z=i.getRowOffset(N+1),N=Math.max(W.top,i.getRowIndex(z-h)),Y={top:i.getRowOffset(N+1)-(z-t.current.getScrollPosition().top)};break;case o.Direction.Down:z=i.getRowOffset(N),N=Math.min(W.bottom,i.getRowIndex(z+h)),Y={top:i.getRowOffset(N)-(z-t.current.getScrollPosition().top)};break;case o.Direction.Left:z=i.getColOffset(B+1),B=Math.max(W.left,i.getColIndex(z-h)),Y={left:i.getColOffset(B+1)-(z-t.current.getScrollPosition().left)};break;case o.Direction.Right:z=i.getColOffset(B),B=Math.min(W.right,i.getColIndex(z+h)),Y={left:i.getColOffset(B)-(z-t.current.getScrollPosition().left)}}}const Ie={rowIndex:N,colIndex:B},Xe=G(Ie),$={rowIndex:Xe.rowStart,colIndex:Xe.colStart};d||(Ke.current=Ie);const ie=o.CoordUtils.isEqualCells(je.current,$)&&o.CoordUtils.isEqualCells(je.current,x);if(d&&!ie?it($,x):pt($),Y)t.current.scrollTo(Y);else{if(d&&je.current){const z=ae();if(e===o.Direction.Right&&je.current.colIndex===z.left||e===o.Direction.Left&&je.current.colIndex===z.right||e===o.Direction.Up&&je.current.rowIndex===z.bottom||e===o.Direction.Down&&je.current.rowIndex===z.top)return}e===o.Direction.Left||e===o.Direction.Right?ft({colIndex:Ie.colIndex}):e!==o.Direction.Up&&e!==o.Direction.Down||ft({rowIndex:Ie.rowIndex})}},[b,G]),Lt=n.useCallbackRef(e=>{if(!t.current)return;if(b.ranges.length===0)return void Qe(e);const d=G(b.cell);if(o.CoordUtils.isEqualRangesArrays([d],b.ranges))return void Qe(e);const g=Dn(b,e,G,et,tt);st(h=>{Pe.current=null,h=yt(h);const x={...h,cell:g.cell,rangeIndex:g.rangeIndex};return o.CoordUtils.isEqualSelectionCoords(x,h)?h:x}),g.cell&&ft(g.cell)},[b,G]),mn=l.useCallback(()=>{const e=ae();it({rowIndex:e.top},{rowIndex:e.bottom})},[]),Cn=l.useCallback(()=>{const e=ae();it({colIndex:e.left},{colIndex:e.right})},[]),Bt=n.useCallbackRef(()=>{b.cell&&t?.current&&ft(b.cell)},[b.cell]),tn=l.useCallback((e=!1)=>{const d={rowIndex:ae().top};e?it(d):pt(d),ft(d)},[]),nn=l.useCallback((e=!1)=>{const d={rowIndex:ae().bottom};e?it(d):pt(d),ft(d)},[]),Gt=l.useCallback((e=!1)=>{const d={colIndex:ae().left};e?it(d):pt(d),ft(d)},[]),qt=l.useCallback((e=!1)=>{const d=ae(),g={rowIndex:d.top,colIndex:d.left};e?it(g):pt(g),ft(g)},[]),_t=l.useCallback((e=!1)=>{const d=ae(),g={colIndex:X?.()?.colEnd??d.right};e?it(g):pt(g),ft(g)},[X]),Vt=l.useCallback((e=!1)=>{const d=ae(),g={rowIndex:X?.()?.rowEnd??d.bottom,colIndex:X?.()?.colEnd??d.right};e?it(g):pt(g),ft(g)},[X]),Zt=n.useCallbackRef(e=>{if(!t.current||b.ranges.length<=1)return;const d=e===o.Direction.Left||e===o.Direction.Up;let g=b.rangeIndex+(d?-1:1);g<0?g=b.ranges.length-1:g>b.ranges.length-1&&(g=0);const h=b.ranges[g],x=Dn({cell:{rowIndex:h.rowEnd,colIndex:h.colEnd},rangeIndex:0,ranges:[h]},o.Direction.Right,G,et,tt);st(I=>{Pe.current=null,I=yt(I);const m={...I,cell:x.cell,rangeIndex:g};return o.CoordUtils.isEqualSelectionCoords(m,I)?I:m}),x.cell&&ft(x.cell)},[b,G]),Sn=n.useCallbackRef(()=>{const e=jn(b);st(d=>{Pe.current=null,d=yt(d);const g={...d,visibleSelection:e};return o.CoordUtils.isEqualSelectionCoords(g,d)?d:g}),e.cell&&ft(e.cell)},[b,G]),bn=n.useCallbackRef(()=>{if(!t.current||b.ranges.length===0)return;const e=b.cell,d=b.ranges[b.rangeIndex],g=jn({cell:e,rangeIndex:0,ranges:[d]}),h=g.ranges[g.rangeIndex];let x;x=h.rowStart===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowStart,colIndex:h.colEnd}:h.rowStart===e.rowIndex&&h.colEnd===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colStart}:h.rowEnd===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colEnd}:{rowIndex:h.rowStart,colIndex:h.colStart},st(I=>{I=yt(I);const m={...I,cell:x};return o.CoordUtils.isEqualSelectionCoords(m,I)?I:m}),x&&ft(x)},[b,G]),on=l.useCallback((e=!1)=>{Qe(o.Direction.Down,e,!1,t.current.getDimensions().containerHeight)},[]),Mt=l.useCallback((e=!1)=>{Qe(o.Direction.Up,e,!1,t.current.getDimensions().containerHeight)},[]),rn=l.useCallback((e=!1)=>{Qe(o.Direction.Right,e,!1,t.current.getDimensions().containerWidth)},[]),Jt=l.useCallback((e=!1)=>{Qe(o.Direction.Left,e,!1,t.current.getDimensions().containerWidth)},[]),ln=l.useCallback(()=>{Lt(o.Direction.Left)},[]),cn=l.useCallback(()=>{Lt(o.Direction.Right)},[]),vn=l.useCallback(()=>{Lt(o.Direction.Up)},[]),yn=l.useCallback(()=>{Lt(o.Direction.Down)},[]),Qt=l.useCallback(()=>{Zt(o.Direction.Left)},[]),Rn=l.useCallback(()=>{Zt(o.Direction.Right)},[]),En=l.useCallback(()=>{bn()},[]),sn=l.useCallback(()=>{Qe(o.Direction.Left,!1,!1)},[]),w=l.useCallback(()=>{Qe(o.Direction.Left,!0,!1)},[]),S=l.useCallback(()=>{Qe(o.Direction.Left,!1,!0)},[]),E=l.useCallback(()=>{Qe(o.Direction.Left,!0,!0)},[]),v=l.useCallback(()=>{Qe(o.Direction.Right,!1,!1)},[]),y=l.useCallback(()=>{Qe(o.Direction.Right,!0,!1)},[]),L=l.useCallback(()=>{Qe(o.Direction.Right,!1,!0)},[]),he=l.useCallback(()=>{Qe(o.Direction.Right,!0,!0)},[]),oe=l.useCallback(()=>{Qe(o.Direction.Up,!1,!1)},[]),de=l.useCallback(()=>{Qe(o.Direction.Up,!0,!1)},[]),V=l.useCallback(()=>{Qe(o.Direction.Up,!1,!0)},[]),me=l.useCallback(()=>{Qe(o.Direction.Up,!0,!0)},[]),Be=l.useCallback(()=>{Qe(o.Direction.Down,!1,!1)},[]),Ue=l.useCallback(()=>{Qe(o.Direction.Down,!0,!1)},[]),Ne=l.useCallback(()=>{Qe(o.Direction.Down,!1,!0)},[]),ye=l.useCallback(()=>{Qe(o.Direction.Down,!0,!0)},[]),ce=l.useCallback(()=>{lt(e=>e.slice(0,-1))},[]),nt=l.useMemo(()=>{const e=ae();return((d,g,h,x,I)=>{const m=d.length;for(let N=0;N<m;N++){const B=d[N];if(B.rowStart===g&&B.colStart===h&&B.rowEnd===x&&B.colEnd===I)return!0}return!1})(b.ranges,e.top,e.left,e.bottom,e.right)},[F,b.ranges]),Ge=l.useCallback((e,d=!0)=>{je.current=e,Ye(e),d&&e&&t?.current&&ft(e)},[]),Te=n.useCallbackRef((e=!0)=>{const d=At.current;if(!ne.current?.cell)return;const g=ne.current?.ranges,h=ne.current?.cell;if(!h||!d||!d)return;let x=null;if(x=g.length>0?g[g.length-1]:G(h),x.colEnd>=x.colStart&&x.rowEnd>=x.rowStart){const I=Hn(x,d);let m=e?Pt:D;try{m?.(x,d,I.direction)}catch(N){console.warn(N)}finally{e&&Ce?.()}}},[G]),_e=l.useRef(null),gt=l.useMemo(()=>({onPointerDown:(e,d)=>{if(vt.current=d,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);h&&(e.stopPropagation(),$t("crosshair"),_e.current={anchor:g.getAnchor(),coords:h})},onPointerMoveOrWait:(e,d)=>{if(ee||!t?.current||!ne.current||!_e.current)return;const g=_e.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!x)return;_e.current={anchor:g,coords:x};const I=ne.current.ranges;let m=Se(ne.current.cell,x);if(!m)return;const N=I.length>0,B=N?I[I.length-1]:G(ne.current.cell);if(!m)return;const W=m.rowStart<B.rowStart?o.Direction.Up:m.rowEnd>B.rowEnd?o.Direction.Down:m.colEnd>B.colEnd?o.Direction.Right:o.Direction.Left,Y=ae();W===o.Direction.Left&&(m={...B,colStart:Math.max(Y.left,m.colStart)}),W===o.Direction.Up&&(m={...B,rowStart:Math.max(Y.top,m.rowStart)}),W===o.Direction.Right&&(m={...B,colEnd:Math.min(Y.right,m.colEnd)}),W===o.Direction.Down&&(m={...B,rowEnd:Math.min(Y.bottom,m.rowEnd)});const Ie=Hn(B,m);if(!ze?.(B)){let Xe;typeof Ft.current=="function"?Xe=Ft.current(B):be&&(Xe=be),m=(($,ie,z,le,qe,ut)=>{const j={...ie};if(z.length===0)return j;if(qe===o.Direction.Left){const ke=$.colEnd+1-$.colStart;j.colStart=$.colStart-Math.ceil(ut/ke)*ke,j.colStart<le.left&&(j.colStart=j.colStart+Math.ceil((le.left-j.colStart)/ke)*ke)}else if(qe===o.Direction.Right){const ke=$.colEnd+1-$.colStart;j.colEnd=$.colEnd+Math.ceil(ut/ke)*ke,j.colEnd>le.right&&(j.colEnd=j.colEnd-Math.ceil((le.right-j.colEnd)/ke)*ke)}else if(qe===o.Direction.Up){const ke=$.rowEnd+1-$.rowStart;j.rowStart=$.rowStart-Math.ceil(ut/ke)*ke,j.rowStart<le.top&&(j.rowStart=j.rowStart+Math.ceil((le.top-j.rowStart)/ke)*ke)}else if(qe===o.Direction.Down){const ke=$.rowEnd+1-$.rowStart;j.rowEnd=$.rowEnd+Math.ceil(ut/ke)*ke,j.rowEnd>le.bottom&&(j.rowEnd=j.rowEnd-Math.ceil((le.bottom-j.rowEnd)/ke)*ke)}return j})(B,m,Xe,Y,Ie.direction,Ie.amount)}if(N&&o.CoordUtils.isRangeWithinRange(m,B)&&(m=null),!o.CoordUtils.isEqualRanges(m,At.current)){if(Xt(m),At.current=m,!m){try{R?.()}catch{}return void Ce?.()}Te(!1)}vt.current=d,hn(h,x,t)},onPointerUp:(e,d)=>{vt.current=d,Promise.resolve(Te(!0)).finally(()=>{Ce?.(),Xt(null),At.current=null,_e.current=null,$t(null),t.current?.focus()})}}),[G]),Fe=n.useSynchronizedPointerHandler(gt),J=l.useMemo(()=>({onPointerDown:Fe}),[Fe]),[Ve,at]=l.useState(null),Re=l.useRef(null),Ze=l.useMemo(()=>({onPointerDown:(e,d)=>{if(vt.current=d,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return;if(fe?.(e,h,b)===!1)return!1;e.stopPropagation(),$t("default");const x=g.getRelativePointFromClient(0,0),I=ne.current?.ranges[ne.current?.ranges.length-1]??o.CoordUtils.cellToRange(ne.current?.cell),m=g.toClipBounds(g.getRangeCoordsBounds(I)),N={x:0,y:0};m.x-x.x>e.nativeEvent.clientX?N.x=e.nativeEvent.clientX-(m.x-x.x):e.nativeEvent.clientX>=m.x-x.x+m.width&&(N.x=Math.max(0,e.nativeEvent.clientX-(m.x-x.x+m.width))+1),m.y-x.y>e.nativeEvent.clientY?N.y=e.nativeEvent.clientY-(m.y-x.y):e.nativeEvent.clientY>=m.y-x.y+m.height&&(N.y=Math.max(0,e.nativeEvent.clientY-(m.y-x.y+m.height))+1),se?.(I,e,d),Re.current={range:I,anchor:g.getAnchor(),cell:h,isMoving:!1,extrusion:N}},onPointerMoveOrWait:(e,d,g)=>{if(We||!t?.current||!ne.current||!Re.current)return;const h=e.clientX-g.clientX,x=e.clientY-g.clientY;if(Re.current.isMoving=Re.current.isMoving||Math.abs(h)>Math.max(1,2)||Math.abs(x)>Math.max(1,2)||performance.now()-g.timeStamp>500,!Re.current.isMoving)return;const I=Re.current.anchor,m=Re.current.extrusion;let N=t.current.getViewFromLocation(I),B=N.getCellCoordsFromClient(e.clientX-m.x,e.clientY-m.y,!0);if(!B)return;const W=Re.current.cell,Y=Re.current.range,Ie=ae(),Xe=Y.colEnd-Y.colStart+1,$=Math.min(Math.max(0,W.colIndex-Y.colStart),Xe-1),ie=Math.min(Ie.right-Xe+1,Math.max(Ie.left,B.colIndex-$)),z=Y.rowEnd-Y.rowStart+1,le=Math.min(Math.max(0,W.rowIndex-Y.rowStart),z-1),qe=Math.min(Ie.bottom-z+1,Math.max(Ie.top,B.rowIndex-le)),ut={colStart:ie,colEnd:ie+Xe-1,rowStart:qe,rowEnd:qe+z-1};o.CoordUtils.isEqualRanges(Ve,ut)&&!(j=>!j||!vt.current||vt.current.ctrlKey!==j.ctrlKey||vt.current.shiftKey!==j.shiftKey||vt.current.altKey!==j.altKey||vt.current.metaKey!==j.metaKey)(e)||(at(ut),we?.(ut,e,d)),vt.current=d,hn(N,B,t)},onPointerUp:(e,d)=>{vt.current=d;const g=()=>{at(null),Re.current=null,$t(null),t.current?.focus()};if(!Re.current)return void g();const h=Re.current.range,x=Ve;A?.(h,e,d),Promise.resolve(h&&x&&C?.(h,x,e,d)).finally(()=>{g()})}}),[Ve]),De=n.useSynchronizedPointerHandler(Ze),Ee=l.useMemo(()=>({onPointerDown:De}),[De]),dt=l.useRef(null),ot=l.useMemo(()=>{const e=o.CoordUtils.isEqualSelectionCoords(b,dt.current)?dt.current:b;return dt.current=e,e},[b]),wt=l.useCallback(e=>{let d=null,g="br";const h=[],x={stroke:Z,fill:T,strokeWidth:.5},I=($,ie,z)=>{const le=e.toClipBounds(e.getRangeCoordsBounds($),It);if(!le)return;le.x=le.width>0?le.x:le.x-x.strokeWidth/2,le.y=le.height>0?le.y:le.y-x.strokeWidth/2,le.width=Math.max(le.width,x.strokeWidth),le.height=Math.max(le.height,x.strokeWidth);const qe={key:`selection-fill-${ie}`,range:$,...le,...x};if(z){const ut=e.getCellCoordsAsRangeCoords(z);qe.cell=z,qe.boundsPath=e.toClipBounds(e.getRangeCoordsBounds(ut),It),qe.boundsPath&&(qe.boundsPath.width<=0||qe.boundsPath.height<=0)&&(delete qe.boundsPath,delete qe.cell)}return ue(qe)};let m=Pe.current||(b?yt(b):null);const N=m?.cell?e.getCellCoordsAsRangeCoords(m?.cell):Io;!m||m.ranges&&m.ranges.length!==0||(m={ranges:[N],rangeIndex:0,cell:m.cell});const B=m?m.ranges:null;B&&B.length;for(let $=0;m&&$<m.ranges.length;$++){const ie=m.ranges[$],z=I(ie,$,$===m.rangeIndex?m.cell:null);z&&h.push(z);const le=2,qe=.5,ut=e.toClipBounds(e.getRangeCoordsBounds(ie,{top:0,left:0,right:0,bottom:0}),It);if(ut){const j=(m.ranges.length,4);h.push(ue({range:ie,key:`selection-inside-edge-${$}`,x:ut.x-1,y:ut.y-1,width:Math.max(ut.width+1,0),height:Math.max(ut.height+1,0),style:{overflow:"hidden"},stroke:Z,strokeWidth:j}))}if(m.ranges.length===1){const j=e.toClipBounds(e.getRangeCoordsBounds(ie),It);if(j){We||h.push(ue({range:ie,key:`move-selection-hit-box-${$}`,x:j.width>1?j.x:j.x-(xe/2+1),y:j.height>1?j.y:j.y-(xe/2+1),width:Math.max(j.width+2,1),height:Math.max(j.height+2,1),stroke:"transparent",style:{boxShadow:"none"},propsPath:{cursor:Ve?void 0:"move",pointerEvents:"stroke"},strokeWidth:xe,...Ee}));const ke=le;h.push(ue({range:ie,key:`selection-single-${$}`,x:j.x-ke/2,y:j.y-ke/2,width:Math.max(j.width+ke/2,1),height:Math.max(j.height+ke/2,1),stroke:H,strokeWidth:ke}))}}else{const j=e.toClipBounds(e.getRangeCoordsBounds(ie,{top:-1,left:-1,right:-2,bottom:-2}),It);j&&h.push(ue({range:ie,key:`selection-multi-${$}`,x:j.width>1?j.x:j.x-qe/2,y:j.height>1?j.y:j.y-qe/2,width:Math.max(j.width,qe)+1,height:Math.max(j.height,qe)+1,stroke:H,style:{overflow:"hidden"},strokeWidth:2}))}if(m.ranges.length>1&&$===m.rangeIndex){const j=e.getCellCoordsAsRangeCoords(m.cell),ke=e.toClipBounds(e.getRangeCoordsBounds(j,{top:1,left:1,right:-1,bottom:-1}),It);ke&&h.push(ue({range:ie,key:`selection-anchor-${$}`,x:ke.x,y:ke.y,width:Math.max(ke.width,qe),height:Math.max(ke.height,qe),stroke:H,style:{overflow:"hidden"},strokeWidth:2}))}if($===m.ranges.length-1){d=null,g=null;const j=ie.rowStart===ae().top&&ie.rowEnd===ae().bottom,ke=ie.colStart===ae().left&&ie.colEnd===ae().right,$n=e.getRangeCoordsBounds(ie);let Dt=null;if(j||ke){if(Dt=e.toClipBounds($n,It),Object.keys(e.allViews()).length>1){const an=e.getVisibleRangeCoords(),Kn=e.allViews()[o.AnchorLocation.TopLeft],fo=e.allViews()[o.AnchorLocation.Top],go=e.allViews()[o.AnchorLocation.Left],dn=e.getAnchor();(ke&&(dn===o.AnchorLocation.Top&&Kn||dn===o.AnchorLocation.Center&&go||!o.CoordUtils.isCellWithinRange({colIndex:ie.colStart,rowIndex:ie.rowEnd},an)&&!o.CoordUtils.isCellWithinRange({colIndex:ie.colStart,rowIndex:ie.rowEnd+1},an))||j&&(dn===o.AnchorLocation.Left&&Kn||dn===o.AnchorLocation.Center&&fo||!o.CoordUtils.isCellWithinRange({colIndex:ie.colEnd,rowIndex:ie.rowStart},an)&&!o.CoordUtils.isCellWithinRange({colIndex:ie.colEnd+1,rowIndex:ie.rowStart},an)))&&(Dt=null)}}else Dt=e.toClipBounds($n,It);if(!Dt||Dt.width===0||Dt.height===0)continue;d={x:Dt.x+Dt.width+1,y:Dt.y+Dt.height+1},Dt.width===0||Dt.height===0||ie.rowStart===ae().top&&ie.colStart===ae().left&&ie.rowEnd===ae().bottom&&ie.colEnd===ae().right||(j?(d.y=le,g="tr"):ke&&(d.x=le,g="bl"))}}let W=null;if(ve){const $=e.toClipBounds(e.getRangeCoordsBounds(ve,{top:0,left:0,right:0,bottom:0}),It);$&&(W=ue({...x,range:ve,key:"remove-selection",x:$.x,y:$.y,width:$.width,height:$.height,strokeWidth:2,stroke:St,fill:xt}))}let Y=null;if(bt){const $=e.toClipBounds(e.getRangeCoordsBounds(bt,{top:0,left:0,right:0,bottom:0}),It);$&&(Y=ue({range:bt,key:"selection-fill-outline",x:$.x-2/2,y:$.y-2/2,width:$.width+2/2,height:$.height+2/2,strokeWidth:2,stroke:H,strokeDasharray:"3 2"}))}let Ie=null;!ee&&d&&!Ve&&(Ie=l.createElement(Un,{...d,corner:g,size:7.5,borderStroke:`${Z} solid`,style:{borderRadius:1},background:H,...J,key:"fillHandle"}));const Xe=[...h];if(W&&Xe.push(W),Y&&Xe.push(Y),Ie&&Xe.push(Ie),!ct&&Rt&&m?.ranges.length===1&&m.ranges[m.ranges.length-1]){const $=m.ranges[m.ranges.length-1],ie=$.rowStart===ae().top&&$.rowEnd===ae().bottom,z=$.colStart===ae().left&&$.colEnd===ae().right,le={view:e,range:$,borderStroke:`${H} solid 3px`,background:Z,selectionTouchPointerHandler:pn,...rt,onTouchSelectStart:qe=>Ht(qe),onTouchSelectEnd:()=>Ht(null),currentTouchAnchor:en};Xe.push(Q.jsx(fn,{anchor:z?"b":ie?"r":"br",scrollableElement:t.current,...le},"touch-select-handle-after")),Xe.push(Q.jsx(fn,{anchor:z?"t":ie?"l":"tl",scrollableElement:t.current,...le},"touch-select-handle-before"))}if(Ve){const $=e.toClipBounds(e.getRangeCoordsBounds(Ve,{top:1,left:1,right:1,bottom:1}),It);$&&Xe.push(ue({range:Ve,key:"selection-move-outline",x:$.x-q/2,y:$.y-q/2,width:Math.max($.width+q/2,1),height:Math.max($.height+q/2,1),stroke:H,style:{boxShadow:"none",transitionDuration:"70ms",transitionTimingFunction:"ease-in",transitionProperty:"left, top, width, height",willChange:"left, top, width, height"},strokeWidth:q}))}return Q.jsx("div",{children:Xe},"selection")},[ot,ve,ee,bt,We,Ve,ae,Z,H,T,St,xt,ct,rt,en]),Et=l.useMemo(()=>{const e=()=>t.current;return[new n.SimpleCommand("moveToPageDown",e,{label:"Page Down",description:"Shift viewport down one page.",shortcut:[{key:"PageDown"}]},()=>on(!1)),new n.SimpleCommand("selectToPageDown",e,{label:"Select To Page Down",description:"Shift viewport and select down one page.",shortcut:[{key:"PageDown",modifiers:[n.KeyModifiers.Shift]}]},()=>on(!0)),new n.SimpleCommand("moveToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[n.KeyModifiers.Alt]}]},()=>rn(!1)),new n.SimpleCommand("selectToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[n.KeyModifiers.Alt,n.KeyModifiers.Shift]}]},()=>rn(!0)),new n.SimpleCommand("moveToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp"}]},()=>Mt(!1)),new n.SimpleCommand("selectToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp",modifiers:[n.KeyModifiers.Shift]}]},()=>Mt(!0)),new n.SimpleCommand("moveToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[n.KeyModifiers.Alt]}]},()=>Jt(!1)),new n.SimpleCommand("selectToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[n.KeyModifiers.Alt,n.KeyModifiers.Shift]}]},()=>Jt(!0)),new n.SimpleCommand("selectColumn",e,{label:"Select Column",description:"Select the columns for the selected cells.",shortcut:{key:"Space",modifiers:[n.KeyModifiers.Ctrl]}},mn),new n.SimpleCommand("selectRow",e,{label:"Select Row",description:"Select the rows for the selected cells.",shortcut:{key:"Space",modifiers:[n.KeyModifiers.Shift]}},Cn),new n.SimpleCommand("selectToColumnStart",e,{label:"Select To Column Start",description:"Select the columns to the beginning of the sheet."},()=>tn(!0)),new n.SimpleCommand("selectToColumnEnd",e,{label:"Select To Column End",description:"Select the columns to the end of the sheet."},()=>nn(!0)),new n.SimpleCommand("moveToRowStart",e,{label:"Move to Row Home",description:"Move to the beginning of the row.",shortcut:[{key:"Home"}]},()=>Gt(!1)),new n.SimpleCommand("selectToRowStart",e,{label:"Select to Row Home",description:"Select to the beginning of the row.",shortcut:[{key:"Home",modifiers:[n.KeyModifiers.Shift]}]},()=>Gt(!0)),new n.SimpleCommand("moveToSheetStart",e,{label:"Move to Sheet Home",description:"Move to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[n.KeyModifiers.Ctrl]}]},()=>qt(!1)),new n.SimpleCommand("selectToSheetStart",e,{label:"Select to Sheet Home",description:"Select to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},()=>qt(!0)),new n.SimpleCommand("moveToRowEnd",e,{label:"Move to Row End",description:"Move to the end of the row.",shortcut:[{key:"End"}]},()=>_t(!1)),new n.SimpleCommand("selectToRowEnd",e,{label:"Select to Row End",description:"Select to the end of the row.",shortcut:[{key:"End",modifiers:[n.KeyModifiers.Shift]}]},()=>_t(!0)),new n.SimpleCommand("moveToSheetEnd",e,{label:"Move to Sheet End",description:"Move to the end of the sheet.",shortcut:[{key:"End",modifiers:[n.KeyModifiers.Ctrl]}]},()=>Vt(!1)),new n.SimpleCommand("selectToSheetEnd",e,{label:"Select to Sheet End",description:"Select to the end of the sheet.",shortcut:[{key:"End",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},()=>Vt(!0)),new n.SimpleCommand("scrollToActiveCoords",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell.",shortcut:{key:"Backspace",modifiers:[n.KeyModifiers.Ctrl]}},Bt),new n.SimpleCommand("scrollToActiveCoordsClearSelection",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell and clear selection.",shortcut:{key:"Backspace",modifiers:[n.KeyModifiers.Shift]}},()=>{Kt(),Ge(b.cell,!0)}),new n.SimpleCommand("traverseSelectionRight",e,{label:"Traverse Right",description:"Traverse the selection moving rightward.",shortcut:{key:"Tab"}},cn),new n.SimpleCommand("traverseSelectionLeft",e,{label:"Traverse Left",description:"Traverse the selection moving leftward.",shortcut:{key:"Tab",modifiers:[n.KeyModifiers.Shift]}},ln),new n.SimpleCommand("traverseSelectionDown",e,{label:"Traverse Down",description:"Traverse the selection moving downward.",shortcut:[{key:"Enter"},{key:"NumpadEnter"}]},yn),new n.SimpleCommand("traverseSelectionUp",e,{label:"Traverse Up",description:"Traverse the selection moving upward.",shortcut:[{key:"Enter",modifiers:[n.KeyModifiers.Shift]},{key:"NumpadEnter",modifiers:[n.KeyModifiers.Shift]}]},vn),new n.SimpleCommand("moveLeft",e,{label:"Move Left",description:"Move active cell to the left.",shortcut:[{key:"ArrowLeft"}]},sn),new n.SimpleCommand("selectLeft",e,{label:"Select Left",description:"Extend selection left.",shortcut:[{key:"ArrowLeft",modifiers:[n.KeyModifiers.Shift]}]},w),new n.SimpleCommand("moveContentfulLeft",e,{label:"Move Left Contentful",description:"Move left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[n.KeyModifiers.Ctrl]}]},S),new n.SimpleCommand("selectContentfulLeft",e,{label:"Select Left Contentful",description:"Extend selection left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},E),new n.SimpleCommand("moveRight",e,{label:"Move Right",description:"Move active cell to the right.",shortcut:[{key:"ArrowRight"}]},v),new n.SimpleCommand("selectRight",e,{label:"Select Right",description:"Extend selection right.",shortcut:[{key:"ArrowRight",modifiers:[n.KeyModifiers.Shift]}]},y),new n.SimpleCommand("moveContentfulRight",e,{label:"Move Right Contentful",description:"Move right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[n.KeyModifiers.Ctrl]}]},L),new n.SimpleCommand("selectContentfulRight",e,{label:"Select Right Contentful",description:"Extend selection right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},he),new n.SimpleCommand("moveUp",e,{label:"Move Up",description:"Move active cell to the up.",shortcut:[{key:"ArrowUp"}]},oe),new n.SimpleCommand("selectUp",e,{label:"Select Up",description:"Extend selection up.",shortcut:[{key:"ArrowUp",modifiers:[n.KeyModifiers.Shift]}]},de),new n.SimpleCommand("moveContentfulUp",e,{label:"Move Up Contentful",description:"Move up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[n.KeyModifiers.Ctrl]}]},V),new n.SimpleCommand("selectContentfulUp",e,{label:"Select Up Contentful",description:"Extend selection up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},me),new n.SimpleCommand("moveDown",e,{label:"Move Down",description:"Move active cell to the down.",shortcut:[{key:"ArrowDown"}]},Be),new n.SimpleCommand("selectDown",e,{label:"Select Down",description:"Extend selection down.",shortcut:[{key:"ArrowDown",modifiers:[n.KeyModifiers.Shift]}]},Ue),new n.SimpleCommand("moveContentfulDown",e,{label:"Move Down Contentful",description:"Move down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[n.KeyModifiers.Ctrl]}]},Ne),new n.SimpleCommand("selectContentfulDown",e,{label:"Select Down Contentful",description:"Extend selection down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Shift]}]},ye),new n.SimpleCommand("selectVisible",e,{label:"Select Visible",description:"Select visible cells only.",shortcut:{key:";",modifiers:[n.KeyModifiers.Alt]}},Sn),new n.SimpleCommand("traverseSelectionPreviousRange",e,{label:"Traverse Previous Range",description:"Traverse the selection to the previous range.",shortcut:{key:"ArrowLeft",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Alt]}},Qt),new n.SimpleCommand("traverseSelectionNextRange",e,{label:"Traverse Next Range",description:"Traverse the selection to the next range.",shortcut:{key:"ArrowRight",modifiers:[n.KeyModifiers.Ctrl,n.KeyModifiers.Alt]}},Rn),new n.SimpleCommand("traverseSelectionCorners",e,{label:"Traverse Corners",description:"Traverse the selection through the corners of the selected range.",shortcut:{key:".",modifiers:[n.KeyModifiers.Ctrl]}},En)]},[]);return l.useMemo(()=>{r?.addCommands(Et,!0)},[r]),{selection:ot,setSelectionCell:Ge,setSelectionRanges:lt,renderOverlay:wt,cursor:jt,onPointerDown:xn,clearLastSelection:ce,newSelection:pt,modifySelection:it,appendSelection:pe,clearSelections:Kt,isEntire:nt,navigate:Qe,navigateSelection:Lt}};