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