@sheetxl/grid-react 0.7.6 → 0.7.8

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