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