@sheetxl/grid-react 0.7.14 → 0.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("._sheetxl-grid_h9wwa_7{position:relative;box-sizing:border-box;user-select:none}._sheetxl-grid_h9wwa_7 *{box-sizing:border-box!important}._sheetxl-grid_h9wwa_7 *:focus{outline:none}._sheetxl-grid_h9wwa_7 .cell-container{position:absolute;overflow:visible;white-space:pre}._sheetxl-grid_h9wwa_7 .cell-container>*{inset:0;position:absolute}._sheetxl-grid_h9wwa_7 .sheetxl-stage{contain:strict}._sheetxl-grid_h9wwa_7 .sheetxl-stage>*{contain:strict}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
2
  "use strict";/**
3
- * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.14
3
+ * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.16
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.
@@ -8,5 +8,5 @@
8
8
  to {
9
9
  stroke-dashoffset: 0px;
10
10
  }
11
- }`,we=document.createElement("style");return we.appendChild(document.createTextNode(X)),document.head.appendChild(we),we.sheet.insertRule(X,0),()=>{document.head.removeChild(we)}},[B]),B&&(U={strokeDasharray:`${re.dashLength}px ${re.dashGap}px`,strokeDashoffset:`${_}px`,animation:`${Z} ${ee}ms linear infinite`,willChange:"stroke-dashoffset"}),Q.jsx(en,{x:c,y:d,width:f,height:a,stroke:r,fill:i,shapeRendering:"crispEdges",style:{...U,...s},...D})});function tn(t){var r,i,c="";if(typeof t=="string"||typeof t=="number")c+=t;else if(typeof t=="object")if(Array.isArray(t)){var d=t.length;for(r=0;r<d;r++)t[r]&&(i=tn(t[r]))&&(c&&(c+=" "),c+=i)}else for(i in t)t[i]&&(c&&(c+=" "),c+=i);return c}function Vt(){for(var t,r,i=0,c="",d=arguments.length;i<d;i++)(t=arguments[i])&&(r=tn(t))&&(c&&(c+=" "),c+=r);return c}Oo.displayName="Selection";const Uo=l.memo(l.forwardRef((t,r)=>{const{x:i=0,y:c=0,borderWidth:d=1,size:f=6,borderStroke:a,corner:s,style:p,className:O,background:T,...M}=t;if(i===0||c===0)return null;let D=!0,B=!0,re=!0,_=!0;switch(s){case"tl":D=!1,B=!1;break;case"bl":D=!1,_=!1;break;case"br":re=!1,_=!1;break;case"tr":B=!1,re=!1}return Q.jsx("div",{className:Vt("fill-handle",O),style:{position:"absolute",left:i-(f+(D?d:0))/2,top:c-(f+(B?d:0))/2,width:f,height:f,borderLeft:D?`${d}px ${a}`:void 0,borderTop:B?`${d}px ${a}`:void 0,borderRight:re?`${d}px ${a}`:void 0,borderBottom:_?`${d}px ${a}`:void 0,background:T,cursor:"crosshair",pointerEvents:"all",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top",willChange:"left, top",...p},tabIndex:-1,...M})}));function ko(t,r){if(typeof t=="function")return t(r);t&&(t.current=r)}Uo.displayName="FillHandle";var yn=parseInt(l.version.split(".")[0],10)>=19?function(t){return r=>{const i=[];for(const c of t){const d=ko(c,r),f=typeof d=="function";i.push(f?d:()=>ko(c,null))}return()=>{for(const c of i)c()}}}:function(t){return r=>{for(const i of t)ko(i,r)}};const Rn=o.ReactUtils.detectIt().supportsTouchEvents,fo=l.memo(l.forwardRef((t,r)=>{const{range:i,view:c,anchor:d,borderStroke:f="rgb(33, 115, 70)",background:a="white",borderWidth:s=1.5,size:p=22,style:O,className:T,selectionTouchPointerHandler:M,onTouchSelectStart:D,onTouchSelectEnd:B,currentTouchAnchor:re,scrollableElement:_,scrollableRoot:ee,...Me}=t;if(!Rn)return null;const Z=o.useCallbackRef(D,[D]),U=o.useCallbackRef(B,[B]),{bounds:X,coordsPivot:we,key:K}=l.useMemo(()=>{if(!i||!c)return null;let me=null,q=null;switch(d){case"tl":me={colIndex:i.colEnd,rowIndex:i.rowEnd},q={colIndex:i.colStart,rowIndex:i.rowStart};break;case"br":me={colIndex:i.colStart,rowIndex:i.rowStart},q={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"t":case"l":me={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"b":me={colIndex:i.colStart,rowIndex:i.rowStart};break;case"r":me={colIndex:i.colStart,rowIndex:i.rowEnd}}let L=c.getRangeCoordsBounds(q?{rowStart:q.rowIndex,colStart:q.colIndex,rowEnd:q.rowIndex,colEnd:q.colIndex}:i);const j=c.getBounds(),St=c.getViewportSize(),xt=j.x,ct=j.y,rt=St.width,se=St.height;switch(d){case"tl":break;case"br":L.x=L.x+L.width,L.y=L.y+L.height;break;case"t":L.x=rt/2-xt;break;case"b":L.x=rt/2-xt,L.y=L.y+L.height;break;case"l":L.y=se/2-ct;break;case"r":L.x=L.x+L.width,L.y=se/2-ct}const Pt=c.toClipBounds(L,0);return!Pt||Pt.width<=0||Pt.height<=0||L.x<0||L.y<0||L.x>rt||L.y>se?{bounds:null,coordsAnchor:null,coordsPivot:null,key:null}:{bounds:L,coordsAnchor:null,coordsPivot:me,key:"touchSelect-"+c.getAnchor()+"-"+d}},[i,c,d]),ge=l.useRef(null),Le=l.useMemo(()=>{const me=q=>d==="t"||d==="b"?{...q,colIndex:void 0}:d==="l"||d==="r"?{...q,rowIndex:void 0}:q;return{processTouch:!0,consumeTouch:!0,onPointerDown:(q,L)=>{const j=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return ge.current={coordsPivot:we},Z?.(d),M.onSelectionPointerDown(q,L,c,j,we,!1,!0)},onPointerMoveOrWait:(q,L,j)=>{const St=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return M.onSelectionPointerMoveOrWait(q,L,j,c,St,ge.current?.coordsPivot,!0,!0)},onPointerUp:(q,L,j)=>(ge.current=null,U?.(d),M.onPointerUp(q,L,j))}},[M,i,c,d]),ye=o.useSynchronizedPointerHandler(Le),[Oe,{y:ce,x:pe}]=o.useAnimatedMeasure(),A=l.useRef(null),{getPortalContainer:C,isFullscreen:$e}=o.useFullscreenPortal(),[Ve,G]=l.useState(null);return l.useEffect(()=>{const me=A.current?.getBoundingClientRect();if(!me||!X)return void G(null);let q=0,L=0,j=_;for(;j;)q+=j.scrollLeft,L+=j.scrollTop,j=ee&&j===ee.parentElement?null:j.parentElement;G(Zo.createPortal(Q.jsx("div",{className:Vt("touch-select-handle",T),ref:r,style:{position:"absolute",left:q+(me?.x??0)-(p+s)/2,top:L+(me?.y??0)-(p+s)/2,width:p,height:p,borderWidth:`${s}px`,border:f,borderRadius:"50%",background:a,boxShadow:`0 0 0 1.5px ${a}`,cursor:"grab",pointerEvents:"all",opacity:re?0:1,transitionDuration:"160ms",transitionProperty:"opacity",...O},tabIndex:-1,onPointerDown:ye,...Me}),ee??C(),K))},[ce,pe,X?.x,X?.y,X?.width,X?.height,T,re,a,p,s,f,_,$e]),X?Q.jsxs(Q.Fragment,{children:[Q.jsx("div",{ref:yn([Oe,A]),style:{position:"absolute",left:X.x,top:X.y,opacity:0}}),Ve]}):null}));fo.displayName="TouchSelectHandle";const It=-10,En=Object.freeze({rowStart:0,colStart:0,rowEnd:0,colEnd:0}),on=Object.freeze({colIndex:0,rowIndex:0}),To=Object.freeze([]),yt=t=>{if(t&&t.cell&&t.ranges&&t.rangeIndex>-1&&t.rangeIndex<=t.ranges.length)return t;const r={cell:null,ranges:t?.ranges??To};return r.rangeIndex=t?.rangeIndex??r.ranges.length-1,r.cell=t?.cell,!r.cell&&r.ranges.length>0&&(r.cell={rowIndex:r.ranges[r.rangeIndex].rowStart,colIndex:r.ranges[r.rangeIndex].colStart}),r.cell||(r.cell=on),n.CoordUtils.isEqualSelectionCoords(r,t)?t:r},ho=(t,r,i)=>{const c=t.getVisibleRangeCoords(),d=t.getScrollOrientation();!d.horizontal&&(r.colIndex>c.colEnd||r.colIndex<c.colStart)&&(r={...r,colIndex:r.colIndex>c.colEnd?c.colEnd+1:c.colEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),!d.vertical&&(r.rowIndex>c.rowEnd||r.rowIndex<c.rowStart)&&(r={...r,rowIndex:r.rowIndex>c.rowEnd?c.rowEnd+1:c.rowEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),t.scrollCellCoordsIntoView(r)},In=()=>!1;function go(t,r){if(!t)throw new Error("Invariant failed")}const Yo={"sheetxl-grid":"_sheetxl-grid_h9wwa_7"},kn=Object.freeze({top:0,left:0}),Mn=Object.freeze({bottom:-4,right:-4}),Dn=Object.freeze({horizontal:!0,vertical:!0}),Xo=[n.AnchorLocation.TopLeft,n.AnchorLocation.Top,n.AnchorLocation.Left,n.AnchorLocation.Center],zt=3e3,Mo={},zo=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,rowCount:d=1,columnCount:f=1,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O,layout:T,onViewportScroll:M,onImmediateScroll:D,showGridLines:B=!0,gridLineColor:re="rgb(224, 224, 224)",gridLineRowsProps:_,gridLineColumnsProps:ee,clipCells:Me=!0,cursor:Z,freezeLeft:U=0,freezeTop:X=0,freezeLeftProps:we,freezeTopProps:K,cellRenderer:ge,onViewportChange:Le,onFirstRender:ye,overlayRenderer:Oe,overlayProps:ce,overlays:pe,overlaysProps:A,allowOverlaysOverflow:C=!1,stageProps:$e,stageWrapper:Ve=null,hiddenRowsAt:G,hiddenColumnsAt:me,hiddenCellAt:q,getVisibleCells:L,zoom:j=1,enableMouseWheel:St=!0,onWheelScroll:xt,getCellCoordsAsRangeCoords:ct=n.CoordUtils.cellToRange,scrollPoint:rt=kn,style:se={},...Pt}=t;go(ge),go(!t?.children);const P=o.useCallbackRef(D,[D]),R=o.useCallbackRef(Le,[Le]),be=o.useCallbackRef(M,[M]),te=o.useCallbackRef(xt,[xt]),ue=o.useCallbackRef(ye,[ye]),ze=l.useRef(null),Je=l.useRef(null),mt=l.useRef(null),[Qe,Tt]=l.useReducer(w=>w+1,0),[st,b]=l.useState({left:rt?.left??0,top:rt?.top??0,horizontalScrollDirection:null,verticalScrollDirection:null}),oe=l.useRef(null),Ae=l.useRef(st),{top:lt,left:qe,verticalScrollDirection:Ht,horizontalScrollDirection:$t}=st,bt=l.useRef(!1),Xt=Qo({rowCount:d,columnCount:f,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O}),At=l.useRef(null),Re=l.useMemo(()=>{const w=T||Xt;return At.current=null,{getColOffset:S=>w.getColOffset(S)*j,getColIndex:S=>w.getColIndex(S/j),getRowOffset:S=>w.getRowOffset(S)*j,getRowIndex:S=>w.getRowIndex(S/j)}},[Xt,T,j]),Ut=(w,S,E)=>{const v=(S?.left??0)+0,y=(S?.top??0)+0;return{getColOffset:z=>w.getColOffset(z)-v,getColIndex:z=>w.getColIndex(z+v),getRowOffset:z=>w.getRowOffset(z)-y,getRowIndex:z=>w.getRowIndex(z+y)}},ut=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getRowOffset,S?0:d),[d,Re?.getRowOffset]),kt=o.useCallbackRef(G??ut,[G]),eo=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getColOffset,S?f:0),[f,Re?.getColOffset]),jt=o.useCallbackRef(me??eo,[me]),He=l.useMemo(()=>Math.min(i??800,Re.getColOffset(f)),[Re.getColOffset,f,i]),Be=l.useMemo(()=>Math.min(c??600,Re.getRowOffset(d)),[Re.getRowOffset,d,c]),Ft=l.useCallback(w=>{n.CommonUtils.canUseDOM&&setTimeout(()=>{ze.current?.focus({preventScroll:!0,...w})},0)},[]),ht=l.useCallback(w=>ze.current?.contains(w)||Je.current?.contains(w),[]);l.useEffect(()=>{bt.current&&(oe.current&&oe.current.left!==Ae.current?.left&&oe.current.top!==Ae.current?.top||(oe.current=null,be?.({left:qe,top:lt})))},[qe,lt]);const Lt=o.useCallbackRef(()=>({top:lt,left:qe}),[lt,qe]),ve=l.useMemo(()=>{const w=[];let S=0,E=0;typeof X=="number"?S=X:(S=X.index??0,E=(X.scrollOffset??0)*j);const v=E,y=Re.getRowOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{top:E+Re.getRowOffset(0)}),Pe=Re.getRowIndex(v),Ne=Re.getRowIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(kt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,Be-z),ne=Ut(Re,{top:lt+z}),ae=ne.getRowIndex(0),F=ne.getRowIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:d-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(kt,ae,F)),Se),layout:ne,maxVirtualBounds:Re.getRowOffset(d),scrollOffset:lt,freezeOffset:(S>0?Re.getRowOffset(S):0)-E},w},[Re.getRowIndex,Re.getRowOffset,kt,Be,d,X,lt,j]),je=l.useMemo(()=>{const w=[];let S=0,E=0;typeof U=="number"?S=U:(S=U.index??0,E=(U.scrollOffset??0)*j);const v=E,y=Re.getColOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{left:E+Re.getColOffset(0)}),Pe=Re.getColIndex(v),Ne=Re.getColIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(jt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,He-z),ne=Ut(Re,{left:qe+z}),ae=ne.getColIndex(0),F=ne.getColIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:f-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(jt,ae,F)),Se),layout:ne,maxVirtualBounds:Re.getColOffset(f),scrollOffset:qe,freezeOffset:(S>0?Re.getColOffset(S):0)-E},w},[Re.getColIndex,Re.getColOffset,jt,He,f,U,qe,j]),it=l.useRef({}),pt=l.useRef([]),Ce=l.useMemo(()=>{let w={};const S=(v,y,z,he,ne)=>{const ae={vertical:he?.vertical||!1,horizontal:he?.horizontal||!1};if(v>=je.length||y>=ve.length)return null;const F={rowStart:ve[y].minIndex,colStart:je[v].minIndex,rowEnd:ve[y].maxIndex,colEnd:je[v].maxIndex};if(F.rowStart>F.rowEnd||F.colStart>F.colEnd)return null;const Se={getColIndex:J=>je[v].layout.getColIndex(J),getColOffset:J=>je[v].layout.getColOffset(J),getRowIndex:J=>ve[y].layout.getRowIndex(J),getRowOffset:J=>ve[y].layout.getRowOffset(J)},Ke=Object.freeze({left:ne?.left??0,top:ne?.top??0,right:ne?.right??0,bottom:ne?.bottom??0}),Pe=Object.freeze({x:je[v].minBounds,y:ve[y].minBounds,width:je[v].maxBounds,height:ve[y].maxBounds}),Ne=(J,We)=>No(Se,J??F,We),Ee={width:je[v].maxVirtualBounds,height:ve[y].maxVirtualBounds},le={left:je[v].scrollOffset,top:ve[y].scrollOffset},et={left:je[v].freezeOffset,top:ve[y].freezeOffset},Ye={width:He,height:Be};let Ue=null,Xe=null;const ft=(et.top+(he.vertical?le.top:0))/j,Fe=(et.left+(he.horizontal?le.left:0))/j;return{getStage:()=>ze.current??null,getVisibleRangeCoords:()=>F,toClipBounds:(J,We)=>{let at,Ie=0;return We===void 0||typeof We=="number"?(at=Ne(F),Ie=We):at=We,((Ge,De,ke=0)=>{if(Ge.x>De.width||Ge.y>De.height)return null;const dt={left:Ge.x,top:Ge.y,bottom:Ge.height+Ge.y,right:Ge.width+Ge.x},tt={left:De.x+ke,top:De.y+ke,bottom:De.height-2*ke+De.y,right:De.width-2*ke+De.x},gt={left:Math.max(dt.left,tt.left),top:Math.max(dt.top,tt.top),bottom:Math.min(dt.bottom,tt.bottom),right:Math.min(dt.right,tt.right)},Et={x:gt.left,y:gt.top,width:gt.right-gt.left,height:gt.bottom-gt.top};return Et.height<0||Et.width<0?null:Et})(J??{x:0,y:0,width:Pe.width,height:Pe.height},at,Ie)},toViewBounds:J=>Fe===0&&ft===0&&j===1?J:{x:(J.x-Fe)*j,y:(J.y-ft)*j,width:J.width*j,height:J.height*j},toAbsoluteBounds:J=>Fe===0&&ft===0&&j===1?J:{x:J.x/j+Fe,y:J.y/j+ft,width:J.width/j,height:J.height/j},getRelativePointFromClient:(J,We)=>{const at=Nt(J,We);return{x:at.x-Pe.x,y:at.y-Pe.y}},getLayout:()=>Se,getCellCoordsAsRangeCoords:ct,getVisibleColumns:()=>je[v].visibleIndices(),getVisibleRows:()=>ve[y].visibleIndices(),getVisibleColumnOffsets:()=>(Ue||(Ue=jo(je[v].layout,!0,je[v].visibleIndices(),F.colStart,F.colEnd)),Ue),getVisibleRowOffsets:()=>(Xe||(Xe=jo(ve[y].layout,!1,ve[y].visibleIndices(),F.rowStart,F.rowEnd)),Xe),getTotalRangeCoords:()=>({colStart:je[v].minCoord,colEnd:je[v].maxCoord,rowStart:ve[y].minCoord,rowEnd:ve[y].maxCoord}),getRangeCoordsBounds:Ne,scrollCellCoordsIntoView:(J,We)=>Gt(J,We,z),getCellCoordsFromClient:(J,We,at=!1)=>{const Ie=Nt(J,We);if(!Ie)return null;const Ge=Se.getColIndex(Ie.x-Pe.x),De={rowIndex:Se.getRowIndex(Ie.y-Pe.y),colIndex:Ge};if(at)return De;const ke=ct(De);return{rowIndex:ke.rowStart,colIndex:ke.colStart}},getZoom:()=>j,getAnchor:()=>z,getBounds:()=>Pe,getInsets:()=>Ke,getTotalSize:()=>Ee,getViewportSize:()=>Ye,getScrollTopLeft:()=>le,getFreezeTopLeft:()=>et,getScrollOrientation:()=>ae,allViews:()=>w}};let E=w[n.AnchorLocation.Center]=S(0,0,n.AnchorLocation.Center,Dn,Mn);return E&&(w[n.AnchorLocation.Center]=E),E=S(0,1,n.AnchorLocation.Top,{horizontal:!0}),E&&(w[n.AnchorLocation.Top]=E),E=S(1,0,n.AnchorLocation.Left,{vertical:!0}),E&&(w[n.AnchorLocation.Left]=E),E=S(1,1,n.AnchorLocation.TopLeft,{}),E&&(w[n.AnchorLocation.TopLeft]=E),it.current=null,w=Object.freeze(w)},[ve,je,ct]),Bt=Object.keys(Ce),Rt=je[0]?.maxVirtualBounds??0,_e=ve[0]?.maxVirtualBounds??0,Ct=l.useMemo(()=>({left:je[1]?je[1].layout.getColOffset(je[1].maxIndex+1):0,top:ve[1]?ve[1].layout.getRowOffset(ve[1].maxIndex+1):0}),[Ce]);l.useEffect(()=>{if(pt.current.length>0){for(let w=0;w<pt.current.length;w++)pt.current[w]();pt.current=[]}},[Ce]);const vt=o.useCallbackRef(()=>({containerWidth:He,containerHeight:Be,totalWidth:Rt,totalHeight:_e}),[He,Be,Re]);l.useEffect(()=>{!oe.current&&bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[lt,qe,Rt,_e]),l.useEffect(()=>{bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[He,Be]);const Nt=l.useCallback((w,S)=>{go(typeof w=="number"&&typeof S=="number");const E=ze.current?.getBoundingClientRect();return E?{x:w-E.x,y:S-E.y}:{x:w,y:S}},[]),xo=o.useCallbackRef(w=>Ce[w]||null,[Ce]),po=o.useCallbackRef((w,S)=>{if(Object.keys(Ce).length===1)return Ce[n.AnchorLocation.Center];const E=Nt(w,S);if(!E)return null;const{x:v,y}=E;let z=null;const he=Xo,ne=he.length;for(let ae=0;!z&&ae<ne;ae++){const F=Ce[he[ae]];F&&vn(v,y,F.getBounds())&&(z=F)}return z||(z=Ce[n.AnchorLocation.Center]),z},[Ce,ct]),Ze=o.useCallbackRef(()=>Ce[n.AnchorLocation.Center].getVisibleRangeCoords(),[Ce[n.AnchorLocation.Center]]),Ot=l.useRef(null),mo=l.useCallback(()=>{Ot.current!==null&&n.CommonUtils.cancelTimeout(Ot.current),Ot.current=n.CommonUtils.requestTimeout(Co,150)},[]),Co=l.useCallback(()=>{Ot.current=null,b(w=>{const S={...w,verticalScrollDirection:null,horizontalScrollDirection:null};return Ae.current=S,S})},[]),Kt=o.useCallbackRef(w=>{const S=w?.left??w?.[0],E=w?.top??w?.[1];let v=Ae.current.left;S!==void 0&&S!==v&&(S>v?(v=Math.max(je?.[1]?.scrollOffset??0,S),v=Math.min(Rt-He,v)):v=Math.max(je?.[1]?.scrollOffset??0,S));let y=Ae.current.top;if(E!==void 0&&E!==y&&(E>y?(y=Math.max(ve?.[1]?.scrollOffset??0,E),y=Math.min(_e-Be,y)):y=Math.max(ve?.[1]?.scrollOffset??0,E)),Ae.current.left===v&&Ae.current.top===y)return;let z=null,he=null;Ae.current.left>v?z=n.Direction.Left:Ae.current.left<v&&(z=n.Direction.Right),Ae.current.top>y?he=n.Direction.Up:Ae.current.top<y&&(he=n.Direction.Down),n.CommonUtils.throttle(()=>{b(ne=>{const ae={...ne,left:v,top:y,horizontalScrollDirection:z,verticalScrollDirection:he};return Ae.current=ae,ae})},17)(),oe.current?.top===y&&oe.current?.left===v||(oe.current={left:v,top:y},P({left:v,top:y}),R({left:v,top:y,width:He,height:Be,totalWidth:Rt,totalHeight:_e})),mo()},[Rt,_e,ve,je]);l.useEffect(()=>{oe.current||Kt({left:qe,top:lt})},[He,Be]),l.useEffect(()=>{let w,S,E=!1;Ae.current.left>Rt&&(w=0,E=!0),Ae.current.top>_e&&(S=0,E=!0),E&&Kt({left:w,top:S})},[Rt,_e]),l.useLayoutEffect(()=>{oe.current={left:rt?.left,top:rt?.top},Kt(oe.current)},[rt?.left,rt?.top]);const to=o.useCallbackRef(w=>{let S=w?.left??w?.[0],E=w?.top??w?.[1];if(S===void 0&&E===void 0)return;const v=w?.behavior??"auto";S!==void 0&&(S=Ae.current.left+(S??0)),E!==void 0&&(E=Ae.current.top+(E??0)),!(Ae.current.left===S&&Ae.current.top===E)&&Kt({left:S,top:E,behavior:v})},[]),oo=l.useCallback(w=>{let S=null;if(Object.keys(Ce).length>1){const E=Xo,v=E.length;for(let y=0;!S&&y<v;y++){const z=Ce[E[y]];z&&n.CoordUtils.isCellWithinRange(w,z.getVisibleRangeCoords())&&(S=z)}}return S||(S=Ce[n.AnchorLocation.Center]),S},[Ce]),Gt=o.useCallbackRef((w,S={inline:"nearest",block:"nearest"},E=null)=>{const v={rowIndex:0,colIndex:0,...w};let y=null;if(E!==null){if(y=Ce[E],y===null)return new Promise((Ye,Ue)=>{Ue("Invalid view")})}else y=oo(v);const z=ct(v),he=y.getLayout(),ne=he.getColOffset(z.colStart),ae=he.getRowOffset(z.rowStart),F=he.getColOffset(z.colEnd+1),Se=he.getRowOffset(z.rowEnd+1),Ke=y.getBounds(),Pe=y.getTotalSize(),Ne=y.getScrollTopLeft(),Ee=((Ye,Ue,Xe=!0)=>{Xe=Xe===!0?{block:"start",inline:"end"}:Xe===!1?{block:"end",inline:"end"}:{block:"end",inline:"end",...Xe};const ft=Wo(Xe.inline,Ye.x,Ye.x+Ye.width,Ue.left,Ue.left+Ue.width,Ue.totalWidth),Fe=Wo(Xe.block,Ye.y,Ye.y+Ye.height,Ue.top,Ue.top+Ue.height,Ue.totalHeight);if(ft!==void 0||Fe!==void 0)return{left:ft,top:Fe}})({x:ne+Ne.left,y:ae+Ne.top,width:F-ne,height:Se-ae},{left:Ne.left,top:Ne.top,width:Ke.width,height:Ke.height,totalWidth:Pe.width,totalHeight:Pe.height},S);if(!Ee)return Promise.resolve({...Ne});const le={...Ee};le.left>qe?le.left+=20:le.left<qe&&(le.left-=0),le.top>lt?le.top+=20:le.top<lt&&(le.top-=0);const et=y.getScrollOrientation();return et.horizontal&&w.colIndex!==void 0||delete le.left,et.vertical&&w.rowIndex!==void 0||delete le.top,new Promise((Ye,Ue)=>{try{Kt(le),Ye(le)}catch(Xe){Ue(Xe)}})},[Rt,_e,Ce,ct]),qt=o.useCallbackRef(w=>{const S=w.shiftKey;w.preventDefault();const{deltaX:E,deltaY:v,deltaMode:y}=w;if(mt.current||te?.(w)===!1)return;let he=S?v:E,ne=v;const ae=S||Math.abs(he)>Math.abs(ne);y===1&&(ne*=0),mt.current=window.requestAnimationFrame(()=>{mt.current=null,to(ae?{left:he}:{top:ne})})},[te]),_t=l.useCallback((w=null)=>{At.current=null,it.current=null,Tt()},[]);l.useLayoutEffect(()=>{_t()},[ge]);const Wt=o.useImperativeElement(r,()=>({stage:ze.current,focus:Ft,contains:ht,invalidate:_t,scrollTo:Kt,scrollBy:to,scrollCellCoordsIntoView:Gt,getScrollPosition:Lt,getDimensions:vt,getViewport:Ze,handleWheel:qt,rowCount:d,columnCount:f,getLayout:()=>Re,getRelativePointFromClient:Nt,getViewFromClient:po,getViewFromCellCoords:oo,getViewFromLocation:xo,onViewChangeOnce:w=>{pt.current.push(w)}}),[d,f,Ce]);l.useEffect(()=>(St&&Wt.current?.addEventListener("wheel",qt,{passive:!1}),bt.current=!0,oe.current=null,()=>{Wt.current?.removeEventListener("wheel",qt)}),[St]);const Zt=l.useRef([]),So=(w,S)=>{!w||!Oe||(Zt.current=[],S.push(((E,v)=>{const y=`view:${E.getAnchor()}:overlay:${S.length}`,z=Oe?.({key:y,view:E},ne=>Zt.current[v]=ne);if(!z)return null;const he=E.getBounds();return Q.jsx("div",{style:{position:"absolute",left:"0px",top:"0px",width:`${he.width}px`,height:`${he.height}px`,overflow:"hidden"},children:z},`overlay-${E.getAnchor()}-${v}`)})(w,0)))},bo=l.useMemo(()=>{const w={},S=Object.keys(Ce),E=S.length;for(let v=0;v<E;v++){const y=S[v],z=[];So(Ce[y],z),w[y]={overlays:z}}return w},[Qe,Oe,d,f,ve,je]),no=(w,S,E,v,y,z,he)=>{if(!w)return;const ne=w.getVisibleColumns(),ae=w.getVisibleRows();if(ne.length===0||ae.length===0)return;let F=null;if(L)F=L(w);else{F=[];const Ie=ae.length,Ge=ne.length;for(let De=0;De<Ie;De++){const ke=ae[De];for(let dt=0;dt<Ge;dt++){const tt={rowIndex:ke,colIndex:ne[dt]};if(q?.(tt))continue;const gt={coords:tt,range:ct(tt)};F.push(gt)}}}const Se=w.getVisibleColumnOffsets(),Ke=w.getVisibleRowOffsets(),Pe=w.getScrollTopLeft(),Ne=w.getFreezeTopLeft(),Ee=Pe.left+Ne.left,le=Pe.top+Ne.top,et=Math.trunc(Ee/zt),Ye=Math.trunc(le/zt),Ue={},Xe=(Ie,Ge,De,ke,dt)=>{const tt=`view:${Ie.getAnchor()}:cell:${Fo(Ge.rowIndex,Ge.colIndex)}`,gt=ke.x,Et=ke.y,e=Math.trunc((Ee+gt)/zt)-et,u=Math.trunc((le+Et)/zt)-Ye;Ue[u]||(Ue[u]={});let g=Ue[u][e];g||(g=Ue[u][e]=[]);let h=z?.get(tt);if(!h){const x=(Ee+gt)%zt,k=(le+Et)%zt;h=ge({key:tt,coords:Ge,bounds:ke,zoom:j,range:De,view:Ie,value:dt,style:{left:o.ReactUtils.boundPixel(x),top:o.ReactUtils.boundPixel(k),width:o.ReactUtils.boundPixel(ke.width,!0),height:o.ReactUtils.boundPixel(ke.height,!0)}})}he?.set(tt,h),g.push(h)},ft=F.length;for(let Ie=0;F&&Ie<ft;Ie++){const Ge=F[Ie],De=Ge?.coords??Ge;if(!De)continue;const ke=Ge?.range??{rowStart:De.rowIndex,colStart:De.colIndex,rowEnd:De.rowIndex,colEnd:De.colIndex},dt=w.getVisibleRangeCoords();if(!n.CoordUtils.isRangesIntersect(ke,dt)&&!n.CoordUtils.isRangeWithinRange(ke,dt))continue;const tt=ke&&!n.CoordUtils.isSingleCell(ke);if(!tt&&q?.(De))continue;const gt=De.rowIndex,Et=De.colIndex,e=Ke[gt],u=Se[Et];let g=null;e&&u&&(g={x:u.offset,y:e.offset,width:u.size,height:e.size});const h=Fo(ke.rowStart,ke.colStart);if(tt){if(y.has(h))continue;y.add(h),ke.rowEnd-ke.rowStart>0&&E.push(ke),ke.colEnd-ke.colStart>0&&v.push(ke)}if(tt&&(g=No(w.getLayout(),ke)),!g){console.warn("no bounds for cell",h);continue}const x=Ge?.value;Xe(w,De,ke,g,x)}const Fe=Ee%zt,J=le%zt,We=Object.keys(Ue),at=We.length;for(let Ie=0;Ie<at;Ie++){const Ge=We[Ie],De=Ue[Ge];if(!De)continue;const ke=Object.keys(De),dt=ke.length;for(let tt=0;tt<dt;tt++){const gt=ke[tt],Et=De[gt];if(!Et)continue;const e=parseInt(Ge),u=parseInt(gt),g=e+Ye,h=u+et,x=`view:${w.getAnchor()}:segment:${h}:${g}`;S.push(Q.jsx("div",{className:"cell-container",style:{transform:`translate(${o.ReactUtils.boundPixel(u*zt-Fe,!0)}px, ${o.ReactUtils.boundPixel(e*zt-J,!0)}px)`,willChange:"transform"},children:Et},x))}}},Mt=l.useMemo(()=>{const w=At.current,S=new Map,E={},v=Object.keys(Ce),y=v.length;for(let z=0;z<y;z++){const he=v[z],ne=[],ae=[],F=[];no(Ce[he],F,ne,ae,new Set,w,S),E[he]={cells:F,rangesH:ne,rangesV:ae}}return At.current=S,E},[Qe,d,f,ve,je,B,se,Me,q,L,me,G,ct]),ro=(w,S,E,v,y)=>{if(!w)return;const z=w.getLayout(),he=window.devicePixelRatio||1,ne=String(1/he);if(S){const ae=`view:${w.getAnchor()}:hl:`,F=w.getVisibleRows();if((F?F.length:0)===0)return;const Se=y.sort(n.CoordUtils.rowFirstRangeComparator),Ke=w.getVisibleRangeCoords(),Pe=0,Ne=Math.min(w.getBounds().width,z.getColOffset(Ke.colEnd+1));let Ee=[];for(let le=0;le<F.length&&F[le]<=Ke.rowEnd;le++){const et=F[le];if(et<Ke.rowStart)continue;let Ye=!1;for(;Se.length>0&&Se[0].rowStart<=et;){const Fe=Se.shift();Fe.rowEnd>et&&(Ee.push(Fe),Ye=!0)}Ye&&(Ee=Ee.sort(n.CoordUtils.columnFirstRangeComparator));const Ue=z.getRowOffset(et+1);let Xe=Pe;const ft=Ee.length;for(let Fe=0;Fe<ft+1;Fe++){let J=Xe,We=Ne;const at=Ee[Fe];Fe<ft&&(We=Math.min(Ne,z.getColOffset(at.colStart)),Xe=Math.min(Ne,z.getColOffset(at.colEnd+1))),v.push(l.createElement("path",{d:`M ${o.ReactUtils.boundPixel(J)} ${o.ReactUtils.boundPixel(Ue,!1,E)} L ${o.ReactUtils.boundPixel(We)} ${o.ReactUtils.boundPixel(Ue,!1,E)}`,stroke:re,strokeWidth:ne,vectorEffect:"non-scaling-stroke",..._,key:ae+et+":"+Fe}))}for(let Fe=ft-1;Fe>=0;Fe--)Ee[Fe].rowEnd<=F[le+1]&&Ee.splice(Fe,1)}}else{const ae=`view:${w.getAnchor()}:vl:`,F=w.getVisibleColumns(),Se=F?F.length:0;if(Se===0)return;const Ke=y.sort(n.CoordUtils.columnFirstRangeComparator),Pe=w.getVisibleRangeCoords(),Ne=0,Ee=Math.min(w.getBounds().height,z.getRowOffset(Pe.rowEnd+1));let le=[];for(let et=0;et<Se&&F[et]<=Pe.colEnd;et++){const Ye=F[et];if(Ye<Pe.colStart)continue;let Ue=!1;for(;Ke.length>0&&Ke[0].colStart<=Ye;){const J=Ke.shift();J.colEnd>Ye&&(le.push(J),Ue=!0)}Ue&&(le=le.sort(n.CoordUtils.rowFirstRangeComparator));const Xe=z.getColOffset(Ye+1);let ft=Ne;const Fe=le.length;for(let J=0;J<Fe+1;J++){let We=ft,at=Ee;const Ie=le[J];J<Fe&&(at=Math.min(Ee,z.getRowOffset(Ie.rowStart)),ft=Math.min(Ee,z.getRowOffset(Ie.rowEnd+1))),v.push(Q.jsx("path",{d:`M ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(We)} L ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(at)}`,stroke:re,strokeWidth:ne,vectorEffect:"non-scaling-stroke",...ee},ae+Ye+":"+J))}for(let J=Fe-1;J>=0;J--)le[J].colEnd<=F[et+1]&&le.splice(J,1)}}},Jt=w=>{if(!Mt)return;const S={},E=Bt.length;for(let v=0;v<E;v++){const y=Bt[v],z=Ce[y],he=[];ro(z,w,0,he,w?Mt[y].rangesH:Mt[y].rangesV);const ne=z.getRangeCoordsBounds(),ae=Math.ceil(ne.width),F=Math.ceil(ne.height);S[y]=Q.jsx("svg",{width:`${ae}`,height:`${F}`,viewBox:`0 0 ${ae} ${F}`,preserveAspectRatio:"none",shapeRendering:"crispEdges",style:{position:"absolute"},children:he})}return S},lo=l.useMemo(()=>B===!0||B?.horizontal===!0?Jt(!0):null,[Qe,B,ve,X,U,re,_,d,f,He,Rt,Ce,Mt]),io=l.useMemo(()=>B===!0||B?.vertical===!0?Jt(!1):null,[Qe,B,je,X,U,re,ee,d,f,Be,_e,Ce,Mt]),vo=l.useMemo(()=>Ct.left===0?null:Q.jsx(Po,{linePoints:[0,0,0,Be+1],bounds:{x:Ct.left,y:0,width:1,height:Be+1},...we}),[Qe,Ct.left,Be,we]),yo=l.useMemo(()=>Ct.top===0?null:Q.jsx(Po,{linePoints:[0,0,He+1,0],bounds:{x:0,y:Ct.top,width:He+1,height:1},...K}),[Qe,Ct.top,He,K]),Qt=l.useMemo(()=>{const w=[],S=v=>{if(!v||!Ce[v])return;const y=Ce[v].getBounds();return Q.jsxs("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:y.width,height:y.height,clip:`rect(0, ${y.width+1}px, ${y.height+1}px, 0)`},className:`view view-${v}`,children:[lo?.[v],io?.[v],Mt?.[v].cells]},`view:${v}`)},E=Bt.length;for(let v=0;v<E;v++)w.push(S(Bt[v]));return Q.jsx(Q.Fragment,{children:w})},[Ce,lo,io,Mt]),Ro=l.useMemo(()=>{if(!r)return;const w=(ne,ae,F,Se)=>{if(!Se||Se.length===0)return;const Ke=[],Pe=Se.length;for(let Ne=0;Ne<Pe;Ne++){const Ee=Se[Ne];let le=ne?.get(Ee);le!==Mo&&(le=Ee(F)??Mo),ae.set(Ee,le),le&&le!==Mo&&Ke.push(le)}return Ke},S=(ne,ae,F)=>{if(!F)return;const Se=F.getBounds(),Ke=F.getInsets(),Pe=F.getAnchor();return Q.jsxs("div",{className:Vt("view",`view-${Pe}`,Yo.view),style:{position:"absolute",pointerEvents:"none",left:Se.x-Ke.left,top:Se.y-Ke.top,width:Se.width-(Ke.left+Ke.right),height:Se.height-(Ke.top+Ke.bottom),clipPath:C?"inset(-2px)":"inset(0px)"},children:[w(ne,ae,F,pe),bo?.[Pe].overlays]},`view:${Pe}`)},E=it.current,v={},y=[],z=Object.keys(Ce),he=z.length;for(let ne=0;ne<he;ne++){const ae=z[ne],F=E?.[ae],Se=v[ae]=new Map;y.push(S(F,Se,Ce[ae]))}return it.current=v,y},[Qe,Ce,C,pe]),Eo=l.useMemo(()=>{const{style:w,...S}=$e??{};return Q.jsx("div",{style:{width:He,height:Be,...w},className:"sheetxl-stage",tabIndex:0,ref:ze,...S,...Pt,children:Ve?Ve(Qt):Qt})},[He,Be,Qt,$e,Ve]),co=l.useRef(!1);return l.useEffect(()=>{!co.current&&Mt&&(co.current=!0,ue?.(Wt.current))},[Mt]),Q.jsxs("div",{className:Vt("sheetxl-grid",Yo["sheetxl-grid"]),style:{overflow:"visible",cursor:Z,maxWidth:He,maxHeight:Be,width:He,height:Be,...se},ref:Wt,children:[Eo,Q.jsxs("div",{className:Vt("sheetxl-overlays"),ref:Je,...A,children:[Ro,vo,yo]})]})}));zo.displayName="BaseGrid";var Pn=function(){},nn=typeof window<"u",Un=nn?l.useLayoutEffect:l.useEffect,Go={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};const Tn=nn&&window.ResizeObserver!==void 0?function(){var t=l.useState(null),r=t[0],i=t[1],c=l.useState(Go),d=c[0],f=c[1],a=l.useMemo(function(){return new window.ResizeObserver(function(s){if(s[0]){var p=s[0].contentRect,O=p.x,T=p.y,M=p.width,D=p.height,B=p.top,re=p.left,_=p.bottom,ee=p.right;f({x:O,y:T,width:M,height:D,top:B,left:re,bottom:_,right:ee})}})},[]);return Un(function(){if(r)return a.observe(r),function(){a.disconnect()}},[r]),[i,d]}:function(){return[Pn,Go]},Ao=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,style:d={},className:f,...a}=t,[s,{width:p,height:O}]=Tn(),T=i??p,M=c??O;return Q.jsx("div",{className:f,style:{...d},children:Q.jsx("div",{style:{position:"relative",top:"0px",left:"0px",width:"100%",height:"100%",maxWidth:"100%",maxHeight:"100%",boxSizing:"content-box"},ref:s,children:Q.jsx(zo,{ref:r,width:T,height:M,...a})})})}));Ao.displayName="Grid";const rn=l.memo(l.forwardRef((t,r)=>{const{showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:s,onScrollViewport:p,style:O={},className:T,onScroll:M,...D}=t,[B,re]=l.useState(null),_=l.useRef(null),ee=l.useRef(null);go(!s),l.useImperativeHandle(r,()=>ee.current&&_.current?Object.assign(ee.current,_.current):null);const Me=l.useCallback(Z=>{ee.current?.scrollTo(Z),p?.(Z)},[]);return Q.jsx(o.ScrollPane,{className:T,style:O,ref:_,showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:B,onScrollViewport:Me,children:Q.jsx(Ao,{style:{width:"100%",height:"100%"},...D,onViewportChange:Z=>re(Z),ref:ee})})}));rn.displayName="ScrollableGrid";const _o=()=>!1,ln=l.memo(t=>{const{index:r,value:i,zoom:c,zoomScale:d=100,headerText:f=pe=>`${pe}`,headerStyle:a,headerStyleSelect:s=a,headerStyleSelectAll:p=s,headerStyleHover:O=p,verticalPadding:T=0,horizontalPadding:M=0,isSelected:D=_o,isSelectedAll:B=_o,coords:re,bounds:_,range:ee,orientation:Me,view:Z,style:U,...X}=t,we=d/100,K=l.useRef(null),[ge,Le]=l.useState(!1),ye=D?.(r)||!1,Oe=B?.(r)?p:ye?s:a;let ce=Oe;if(ge){let pe=O;typeof O=="function"&&(pe=O(Oe)),ce=n.CommonUtils.mergeContentful(Oe,pe)}return Q.jsx("div",{ref:K,style:{background:ce.fill,color:ce.text?.fill,fontFamily:ce.text?.fontFamily??a.text?.fontFamily,fontSize:96*(ce.text?.fontSize??11)/72*we,fontStyle:ce.text?.fontStyle,fontWeight:ce.text?.fontWeight,lineHeight:1.2,display:"flex",justifyContent:"center",alignItems:"end",pointerEvents:"auto",paddingBottom:`${we}px`,...U,left:U.left-(Me===n.RangeOrientation.Column?1:0),top:U.top-(Me===n.RangeOrientation.Row?1:0),width:U.width+1,height:U.height+1,overflow:"hidden"},...X,onMouseMove:pe=>{o.ReactUtils.detectIt().primaryInput!=="touch"&&pe.buttons===0&&Le(!0)},onMouseOut:pe=>{Le(!1)},children:f(r)})});ln.displayName="HeaderRenderer";const cn="ew-resize",sn="ns-resize",an=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,className:f,style:a,disabled:s=!1,disabledResize:p=!1,isNextHidden:O,isHidden:T,isSelected:M,isSelectedAll:D,showTouchDivider:B,headerStyle:re,headerStyleSelect:_,headerStyleSelectAll:ee,headerStyleHover:Me,bounds:Z,onPointerDown:U,onAutoFit:X,...we}=t,K=i===n.RangeOrientation.Column;let ge=re;M&&_&&(ge=_),D&&ee&&(ge=ee);const Le=o.ReactUtils.detectIt().primaryInput==="touch";let ye=K?14:8,Oe=ye/2,ce=0;O&&(ce=-2),T&&(ce=2),T&&(ye=ye/2+ce,Oe=2*ce);let pe=ge.dividerStrokeFill??ge.strokeFill;return!(M||D)&&ce===0&&(pe=`linear-gradient(${K?180:90}deg, ${ge.fill}, ${pe} 55%, ${pe} 100%)`),Q.jsxs("div",{className:Vt("header-divider",{disabled:s},f,`index-${d}`),ref:r,onPointerDown:Le?void 0:U,onDoubleClick:Le?void 0:()=>X?.(),style:{top:(K?0:-ye/2+(ce-1))+"px",left:(K?-ye/2+(ce-1):0)+"px",width:K?ye:"calc(100% + 1px)",height:K?"calc(100% + 1px)":ye,position:"absolute",overflow:"visible",pointerEvents:"all",cursor:s||p||Le?void 0:K?cn:sn,...a},...we,children:[Q.jsx("div",{style:{position:"relative",top:`${K?0:Oe}px`,left:`${K?Oe:0}px`,width:K?1:"100%",height:K?"100%":1,background:pe},onDoubleClick:()=>X?.()}),B&&Le?Q.jsx("div",{style:{position:"absolute",cursor:"grab",zIndex:1,borderRadius:"4px",right:K?"-6px":"2px",bottom:K?"2px":"-9px",height:"24px",width:K?"24px":"18px",maxHeight:K?"calc(100% - 4px)":void 0,maxWidth:K?void 0:"calc(100% - 4px)",background:ge.fill,border:`${ee.edgeStrokeFill} solid 1px`,boxShadow:`0.5px 0.5px 0px 0px ${re.text.fill}`,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:U,children:Q.jsx("div",{style:{width:"6.4px",height:"12px",backgroundImage:`url("data:image/svg+xml,%3Csvg width='6.4' height='12' viewBox='0 0 9.6 16' version='1.1' fill='${encodeURIComponent(_.text.fill)}' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cpath d='M 9.60008,14.40009 C 9.60008,15.28374 8.88368,16 8.00003,16 7.11639,16 6.40012,15.28374 6.40012,14.40009 c 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40012 c 0,0.88364 -0.7164,1.60004 -1.60005,1.60004 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60004 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40006 c 0,0.88365 -0.7164,1.60005 -1.60005,1.60005 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60005 C 6.40012,0.71626 7.11639,0 8.00003,0 8.88368,0 9.60008,0.71626 9.60008,1.59991 M 3.19996,14.40009 C 3.19996,15.28374 2.48369,16 1.60005,16 0.7164,16 0,15.28374 0,14.40009 c 0,-0.88365 0.7164,-1.60005 1.60005,-1.60005 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40012 c 0,0.88364 -0.71627,1.60004 -1.59991,1.60004 C 0.7164,9.60001 0,8.88361 0,7.99997 0,7.11632 0.7164,6.39992 1.60005,6.39992 c 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40006 c 0,0.88365 -0.71627,1.60005 -1.59991,1.60005 C 0.7164,3.19996 0,2.48356 0,1.59991 0,0.71626 0.7164,0 1.60005,0 2.48369,0 3.19996,0.71626 3.19996,1.59991' /%3E%3C/svg%3E%0A")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",transform:K?void 0:"rotate(90deg)"}})}):null]})})),Ln=(t,r)=>Q.jsx(an,{...t,ref:r}),On=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,disabled:f=!1,disabledResize:a=!1,resizeThreshold:s=1,dividerRenderer:p=Ln,onDividerMouseDown:O,onDividerResizeStart:T,onDividerResize:M,onDividerResizeEnd:D,onDividerMouseUp:B,onDividerAutoFit:re,onPointerDown:_,...ee}=t,Me=o.useCallbackRef(_,[_]),Z=o.useCallbackRef(re,[re]),U=i===n.RangeOrientation.Column;let X=U?c.getVisibleColumns():c.getVisibleRows(),we=null;X.length>0&&(U?we=c.getRangeCoordsBounds({rowStart:0,rowEnd:0,colStart:X[0],colEnd:X[X.length-1]}):c.getRangeCoordsBounds({rowStart:X[0],rowEnd:X[X.length-1],colStart:0,colEnd:0}),we=c.toClipBounds(we,It));const K=l.useRef(null),[ge,Le]=l.useState(null),ye=(G,me)=>U?G.clientX-me.clientX:G.clientY-me.clientY,Oe=c.getLayout(),ce=U?Oe.getColOffset(d+1):Oe.getRowOffset(d+1),pe=o.useSynchronizedPointerHandler({processTouch:!0,onPointerDown:G=>{if(Me?.(G),!f&&!a){const me=U?Oe.getColOffset(d):Oe.getRowOffset(d),q=ce-me;K.current={isResizing:!1,startSize:q,index:d,view:c,orientation:i,onDividerMouseDown:O,onDividerResizeStart:T,onDividerResize:M,onDividerResizeEnd:D,onDividerMouseUp:B},Le(K.current),O?.(d,q)}G.stopPropagation(),G.preventDefault()},onPointerUp:(G,me,q)=>{if(!K.current)return;K.current.isResizing&&K.current.onDividerResizeEnd?.(K.current.index,Math.max(0,K.current.startSize+ye(G,q)),K.current.startSize);const L=K.current;K.current=null,Le(K.current),L.onDividerMouseUp?.(L.index)},onPointerMoveOrWait:(G,me,q)=>{if(!K.current)return;const L=ye(G,q);K.current.isResizing?K.current.onDividerResize?.(K.current.index,Math.max(0,K.current.startSize+L),K.current.startSize):Math.abs(L)>Math.max(1,s)&&(K.current={...K.current,isResizing:!0},Le(K.current),K.current.onDividerResizeStart?.(K.current.index,Math.max(0,K.current.startSize+L))),G.stopPropagation(),G.preventDefault()}}),A=o.useCallbackRef(()=>{Z?.(d)},[d]);if(!we)return;const C=p({bounds:we,orientation:i,view:c,index:d,disabled:f,disabledResize:a,onAutoFit:A,onPointerDown:pe,...ee},r);if(!C)return;const{getPortalContainer:$e}=o.useFullscreenPortal();let Ve=null;return ge&&ge.isResizing&&ge.index===d&&(Ve=Zo.createPortal(Q.jsx("div",{style:{position:"absolute",cursor:U?cn:sn,left:0,top:0,width:"100%",height:"100%"}}),$e(),"divider:"+d)),Q.jsxs(Q.Fragment,{children:[Ve,Q.jsx("div",{className:Vt("header-divider-anchor"),style:{position:"absolute",pointerEvents:"auto",top:`${U?we.y:ce}px`,left:`${U?ce:we.x}px`,width:(U?0:we.width-1)+"px",height:(U?we.height-1:0)+"px",display:"flex"},tabIndex:-1,children:C})]})}));class zn{naturalDimensions(r,i={}){const c=document.createElement("div");let d=i?.lineHeight??"1";!i?.lineHeight&&i.paintableText?.fontSize&&(d=Math.ceil(1.2*i.paintableText.fontSize)+"px");const f=document.createElement("div");f.style.visibility="hidden",f.style.position="absolute",f.style.textRendering="geometricprecision",f.style.display="inline-grid",f.style.overflowWrap="break-word",f.style.maxWidth=i.maxWidth?i.maxWidth+"px":"100%",f.style.lineHeight=d,f.style.letterSpacing=(i.paintableText?.letterSpacing??0)+"px",f.style.fontSize=i.paintableText?.fontSize?i.paintableText.fontSize+"px":"unset",f.style.fontFamily=i.paintableText?.fontSize?i.paintableText.fontFamily:"unset",f.style.fontWeight=i.paintableText?.fontWeight?""+i.paintableText.fontWeight:"400",f.style.fontStyle=i.paintableText?.fontStyle?i.paintableText.fontStyle:"normal",f.style.whiteSpace=i.paintableText?.wrap==="wrap"?"break-spaces":"pre",c.appendChild(f);const a=r.split(`
12
- `);for(let p=0;p<a.length;p++){let O=document.createElement("span");f.appendChild(O),O.textContent=a[p]}a.length!==0&&a[a.length-1].length!==0||f.appendChild(document.createElement("br")),document.body.appendChild(f);let s=f.getBoundingClientRect();return f.remove(),{width:s.width,height:s.height,maxLineHeight:1.2*(i.paintableText?.fontSize||1056/72)}}}const dn=(t=void 0)=>Object.freeze({clean:t,dirty:void 0,editMode:!1}),An=dn(),$n=l.memo(l.forwardRef((t,r)=>{const{editState:i=An,defaultTextStyle:c,onStartEdit:d,onChangeEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,containerBounds:O,setNaturalSize:T,onNavigate:M,textProperties:D,style:B,autoFocus:re,..._}=t,ee=l.useRef(null),{width:Me=0}=O??{},[Z,U]=l.useState(()=>i);l.useEffect(()=>{U(i)},[i]);const X=D?.align||"left",we=D?.vAlign||"middle",K=D?.fill||"#040404",ge=D?.wrap||"wrap",Le=D?.fontFamily||"Calibri",ye=D?.fontSize||11,Oe=D?.fontWeight||400,ce=D?.fontStyle||"normal",pe=Z.dirty??Z.clean??"";let A=2;const C=96*ye/72,$e=1.2*C;we==="right"&&(A+=1);const Ve=l.useMemo(()=>new zn().naturalDimensions(pe,{maxWidth:ge==="wrap"?Me-A:void 0,lineHeight:`${$e}px`,paintableText:{fontStyle:ce,wrap:ge,letterSpacing:-.25}}),[pe,ge,A,C,Le,Oe,ce,T,Me]),G=l.useCallback(()=>Ve.maxLineHeight?Ve.maxLineHeight+"px":"1.2",[Ve]),[me,q]=l.useState(G);l.useLayoutEffect(()=>{q(G())},[O,Ve]),l.useLayoutEffect(()=>{T?.({width:ge==="wrap"?void 0:Ve.width+A,height:Ve.height})},[Ve,T]);const L=o.useCallbackRef(f,[f]),j=o.useCallbackRef(R=>{if(Z.dirty===R)return;const be={...Z};be.dirty=R,ee.current,U(be),L?.(be)},[Z]),St=o.useCallbackRef(R=>{if(Z.editMode===R)return;const be={...Z};be.editMode=R,U(be),L?.(be)},[Z]),xt=o.useCallbackRef(()=>{try{return a?.(Z),p?.(),!0}catch{return!1}},[a,Z]),ct=o.useCallbackRef(()=>{U(i),s?.(),p?.()},[s,i]),rt=o.useCallbackRef(R=>{if(!ee.current)return;if(R.isDefaultPrevented(),!(R.isTrusted||R.nativeEvent.ctrlKey||R.nativeEvent.metaKey||R.nativeEvent.altKey||R.nativeEvent.isComposing)&&Lo.indexOf(R.nativeEvent.key)!==-1){const te={...Z};return te.dirty=R.nativeEvent.key==="Backspace"?"":(te.dirty??"")+R.key,U(te),L?.(te),void R.preventDefault()}const be=R.nativeEvent.shiftKey;if(R.which===o.KeyCodes.Escape)return R.preventDefault(),void ct();if(R.which===o.KeyCodes.F2)return St(!0),void R.preventDefault();if(R.which===o.KeyCodes.Enter&&(R.preventDefault(),xt()&&M?.(be?n.Direction.Up:n.Direction.Down)),R.which===o.KeyCodes.Tab)return R.preventDefault(),void(xt()&&M?.(be?n.Direction.Left:n.Direction.Right));if(!Z.editMode){let te=null;switch(R.which){case o.KeyCodes.Left:te=n.Direction.Left;break;case o.KeyCodes.Right:te=n.Direction.Right;break;case o.KeyCodes.Up:te=n.Direction.Up;break;case o.KeyCodes.Down:te=n.Direction.Down}if(te)return void xt()}},[Z,M]),[se,Pt]=l.useState(!re);l.useEffect(()=>{Pt(!1)},[]);const P=o.useImperativeElement(r,()=>({startEdit(R){let be=R?.initialSelection;if(!be){const ue=ee.current.value.length??0;be={start:ue,end:ue,direction:"forward"}}ee.current?.setSelectionRange(be.start,be.end,be.direction);const te={...i,editMode:R?.editMode??!1};R?.text!==void 0&&(te.dirty=R.text),te.editMode===i.editMode&&te.dirty===i.dirty||(U(te),L?.(te))},submitEdit:()=>xt(),cancelEdit(){ct()},autoFocus(){ee.current?.focus()},getLineHeight:()=>Ve?.maxLineHeight??$e,dispatchEvent:R=>ee.current.dispatchEvent(R)}),[i,d]);return Q.jsx("div",{ref:P,..._,style:{background:"transparent",display:"flex",flexGrow:1,alignSelf:"center",height:Ve.height,maxWidth:"100%",maxHeight:"100%",...B},children:Q.jsx("textarea",{spellCheck:"false",ref:ee,value:pe,autoFocus:!1,disabled:se,name:"cell-editor",autoComplete:"off",autoCapitalize:"off",style:{flex:"1 1 100%",position:"relative",fontSize:`${C}px`,fontFamily:`${Le}`,fontWeight:`${Oe}`,fontStyle:`${ce}`,padding:"0px",marginRight:X==="right"?"3px":"0px",marginLeft:X==="left"?"2px":"0px",lineHeight:me,height:Ve.height,textRendering:"geometricPrecision",letterSpacing:"-0.25px",boxSizing:"border-box",borderWidth:0,outline:"none",resize:"none",overflow:"hidden",verticalAlign:"baseline",textAlign:X,background:"transparent",color:K,marginBottom:"0px",userSelect:"text",maxHeight:"100%",whiteSpace:ge==="wrap"?"break-spaces":"pre",wordWrap:"break-word"},onChange:R=>{j(R.target.value)},onDoubleClick:R=>{R.isTrusted},onMouseDown:R=>{St(!0)},onKeyDown:rt})})})),Bn=l.memo(t=>{const{value:r,view:i,bounds:c,range:d,zoom:f,children:a,style:s,...p}=t,O=s?.fontSize||1056/72;return Q.jsx("div",{style:{padding:"2px 4px",fontFamily:"Calibri",letterSpacing:-.25,lineHeight:1.2,fontSize:O,...s},...p,children:r})});exports.BaseGrid=zo,exports.DefaultCellEditor=$n,exports.DefaultCellRenderer=Bn,exports.DefaultHeaderDivider=an,exports.FillHandle=Uo,exports.Grid=Ao,exports.HeaderDivider=On,exports.HeaderRenderer=ln,exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL=150,exports.SELECTION_CLIP_INSETS=It,exports.STANDARD_KEY_CHARS=Lo,exports.SVGLine=Po,exports.SVGRect=en,exports.ScrollableGrid=rn,exports.Selection=Oo,exports.TouchSelectHandle=fo,exports.defaultSelectionRenderer=qo,exports.getDefaultStringEditState=dn,exports.safeSelectionCoords=yt,exports.useCellLayout=Qo,exports.useHeaderSelection=({gridRef:t,gridMainRef:r,orientation:i=n.RangeOrientation.Row,headerCount:c,selectionPolicy:d="multiple",newSelectionMode:f="clear",alwaysScrollToActiveCoords:a=!0,onDragStart:s,onDragEnd:p,pointerDownInterceptor:O,pointerMoveInterceptor:T,onPointerUp:M,newSelection:D,modifySelection:B,appendSelection:re,clearSelections:_})=>{const ee=c??((i===n.RangeOrientation.Row?t.current?.rowCount:t.current?.columnCount)||0),Me=l.useRef(null),Z=l.useRef(null),U=l.useRef(!1),X=l.useRef(null),we=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:0},[i]),K=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:r.current?r.current.rowCount-1:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:r.current?r.current.columnCount-1:0},[i]),ge=A=>{Z.current=K(A),B(Z.current,Me.current)},Le=l.useCallback((A,C)=>{if(!t.current)return;const $e=t.current.getViewFromClient(A,C)?.getCellCoordsFromClient(A,C);return $e?(i===n.RangeOrientation.Column?$e.rowIndex=r.current.getViewport().rowStart:$e.colIndex=r.current.getViewport().colStart,$e):void 0},[]),ye=l.useCallback((A,C=!1)=>{let $e=A;return C||($e={...A},i===n.RangeOrientation.Row?delete $e.colIndex:delete $e.rowIndex),r.current?.scrollCellCoordsIntoView($e)},[i]),Oe=o.useCallbackRef(p,[p]),ce=o.useCallbackRef(s,[s]),pe=l.useMemo(()=>({onPointerDown:A=>{if(!t||!t.current||A.nativeEvent.defaultPrevented)return;const C=Le(A.nativeEvent.clientX,A.nativeEvent.clientY);if(!C)return;A.nativeEvent.which,o.MouseButtonCodes.Right;const $e=A.nativeEvent.shiftKey,Ve=A.nativeEvent.ctrlKey||A.nativeEvent.metaKey;if(O?.(A,C)===!1)return;ce?.(),U.current=!0;const G=r.current?.getViewFromClient(A.nativeEvent.clientX,A.nativeEvent.clientY),me=((q,L)=>i===n.RangeOrientation.Column?{...q,rowIndex:L.rowStart}:{...q,colIndex:L.colStart})(C,G.getVisibleRangeCoords());if($e)ge(C);else{if(Ve)return((q,L=q,j)=>{Me.current=we(q),Z.current=K(L),re(Me.current,Z.current,j)})(C,C,me),void(a&&ye(me,!0));((q,L=q,j)=>{Me.current=we(q),Z.current=K(L),D(Me.current,Z.current,j)})(C,C,me),ge(C),a&&ye(me,!0)}},onPointerMoveOrWait:n.CommonUtils.throttle(A=>{if(!U.current||!t?.current)return;const C=Le(A.clientX,A.clientY);if(C&&T?.(A,C)!==!1){if(n.CoordUtils.isEqualCells(X.current,C))return _();ge(C),ye(C)}},60),onPointerUp:A=>{U.current=!1,Oe?.(),M?.(A)},processTouch:!0,consumeTouch:!0}),[d,a,ee,f,_,O,M]);return{onPointerDown:o.useCallbackRef(o.useSynchronizedPointerHandler(pe),[]),getCellCoordsFromClient:Le}},exports.useKeyboardEditorOverlay=t=>{const{view:r,canEdit:i=gn,getCellEditor:c,onBeforeStartEdit:d,onStartEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,isEditorStartKeyEvent:O=wn,isEditorStartPointerEvent:T=xn,containerProps:M,borderStrokeFill:D,borderStrokeWidth:B=2,getRangeCoords:re=null,activeCoords:_,alignment:ee=o.HorizontalAlignment.Left}=t,[Me,Z]=l.useState(!1),[U,X]=l.useState(void 0),we=o.useCallbackRef((P,R,be,te,ue,ze)=>{if(!R)return null;const Je=ue?.(R,P),mt=P.getRangeCoordsBounds(Je),Qe=P.toClipBounds(mt),Tt=mt,st=P.getZoom();if(!Qe)return null;be&&(be*=st),te&&(te*=st);let b=Tt,oe=!1;if(be!==void 0){let qe={...Je},Ht=0;for(;!oe&&b.width<=be&&Ht<20;){Ht++,Ht>19&&console.warn("max width reached");const $t=P.getTotalRangeCoords(),bt=P.getLayout();ze===o.HorizontalAlignment.Left?qe.colEnd+1<$t.colEnd?qe.colEnd=bt.getColIndex(b.x+be):oe=!0:ze===o.HorizontalAlignment.Right?qe.colStart-1>=0?qe.colStart=bt.getColIndex(b.x-(be-b.width)):oe=!0:ze===o.HorizontalAlignment.Center&&qe.colEnd+1<$t.colEnd&&qe.colStart-1>=0?(qe.colStart=bt.getColIndex(b.x-(be-b.width)/2),qe.colEnd=bt.getColIndex(b.x+b.width+(be-b.width)/2)):oe=!0,oe||(b=P.getRangeCoordsBounds(qe))}}b.height=Tt.height,te!==void 0&&(b.height=Math.max(te+1,Tt.height));const{width:Ae,height:lt}=P.getViewportSize();return{x:b.x??0,y:b.y??0,height:Math.min(lt-b.y,b.height)+1,width:Math.min(Ae-b.x,b.width)+1}},[ee]),K=o.useCallbackRef(i,[i]),ge=l.useCallback(()=>{r?.getStage()?.focus()},[r]),Le=l.useRef(null),ye=o.useCallbackRef(P=>{d?.(P),L(),Z(!0),Le.current=null},[d]),Oe=o.useCallbackRef(P=>{f?.(P.coords)},[f]),ce=o.useCallbackRef(P=>{P.isSubmitted||P.isCancelled||(C.current.isEditorClosed=!0,ge(),P.isCancelled=!0,s?.(P.coords),L())},[s]),pe=o.useCallbackRef(P=>{if(P.isSubmitted||P.isCancelled)return!1;try{return Le.current=P.coords,P.isEditorClosing=!0,P.isSubmitted=!0,P.isEditorSubmitted||(P.isEditorSubmitted=!0,P.editorRefs[0]?.submitEdit?.()),P.coords,a?.(P.coords),P.isEditorClosed=!0,ge(),L(),!0}catch(R){throw P.isEditorClosing=!1,P.isSubmitted=!1,R}},[a]),A=o.useCallbackRef(P=>{Z(!1),p?.(P.coords),L()},[p]),C=l.useRef(null),$e=l.useRef(null),Ve=l.useRef(null),G=l.useRef([]),[me,q]=l.useReducer(P=>P+1,0),L=l.useCallback(P=>{P&&G.current.push(P),q()},[]),j=o.useCallbackRef(P=>{if(P.defaultPrevented||P.isSynthetic||!r)return;const R=r?.getCellCoordsFromClient(P.clientX,P.clientY);R&&L({eventType:"pointer",event:P,coords:R})},[r]),St=o.useCallbackRef(P=>{const R=P.nativeEvent;j(R)},[r]),xt=o.useCallbackRef(P=>{if(P.defaultPrevented||P.isSynthetic||!r?.getStage())return;const R=$e.current;O(P,R)&&(P.stopPropagation(),P.preventDefault()),P.key,L({eventType:"keyboard",event:P,coords:R})},[r]);l.useLayoutEffect(()=>{const P=(te,ue)=>{const ze=ue?.cell??te;if(!ze)return null;const Je=ze;if(!K(ze))return null;ye?.(ze);const mt=n.CommonUtils.uuidV4();ue=Object.freeze({autoFocus:!0,...ue}),Ve.current=ze;const Qe={coords:Je,startEvent:ue,uuid:mt,isMounted:!1,isStarted:!1,isSubmitted:!1,isEditorSubmitted:!1,isEditorClosing:!1,isEditorClosed:!1,isCancelled:!1,events:[],editorRefsDispatchEditorEvent:[],editorRefs:[],onMount:Tt=>{Qe.isMounted||(Qe.isMounted=!0,L())},onUnmount:Tt=>{if(Qe.editorRefs.length===0){const st=()=>{Qe.isMounted=!1,L()};if(document.activeElement!==document.body)st();else{const b=oe=>{oe.defaultPrevented||oe.target!==document.body||xt(oe)};window.addEventListener("keydown",b,!0),r.getStage()?.addEventListener("focusin",()=>{window.removeEventListener("keydown",b),st()},mn),ge()}}}};return Qe};if(G.current.length<=0&&!C.current)return;const R=G.current[0];Ko(R),(te=>{const ue=[],ze=te?.length??0;for(let Je=0;Je<ze;Je++){const mt=te[Je];ue.push(Ko(mt))}})(G.current),C.current,C.current;let be=C.current;if(C.current){if(C.current.isDone)C.current=null;else if(C.current.isSubmitted||C.current.isCancelled){if(C.current.isMounted)return;C.current.isDone||(A(C.current),C.current.isDone=!0)}}if(R){if(R.eventType==="start"){const te=R,ue=te.startEvent?.cell??$e.current;C.current&&n.CoordUtils.isEqualCells(C.current.coords,ue)||(C.current=P(ue,te.startEvent))}else if(R.eventType==="keyboard"){const te=R.event;if(C.current){let ue=!1;switch(te.which){case o.KeyCodes.Left:case o.KeyCodes.Right:case o.KeyCodes.Up:case o.KeyCodes.Down:case o.KeyCodes.Enter:case o.KeyCodes.Tab:ue=!0}if(!ue){C.current.events.push(R);for(let ze=0;ze<C.current.editorRefsDispatchEditorEvent.length;ze++)C.current.editorRefsDispatchEditorEvent[ze](R)}}else if(O(te,R.coords)){let ue;const ze=P(ue?.cell??$e.current,ue);ze&&ze.events.push(R),C.current=ze}}else if(R.eventType==="pointer"){const te=R.event;if(C.current){C.current.events.push(R);for(let ue=0;ue<C.current.editorRefsDispatchEditorEvent.length;ue++)C.current.editorRefsDispatchEditorEvent[ue](R)}else{const ue=R?.coords??$e.current,ze=T(te,ue);if(ze){let Je;typeof Je!="boolean"&&(Je=ze);const mt=P(ue,Je);mt&&mt.events.push(R),C.current=mt}}}else if(R.eventType==="submit"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;pe(C.current)}}else if(R.eventType==="cancel"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;ce(C.current)}}else if(R.eventType==="coordsChange"){const te=R;if($e.current=te.activeCoords,C.current,C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;try{pe(C.current)}catch{}}}}G.current.length>0&&(G.current.shift(),L()),G.current.length===0&&(!C.current||C.current.isEditorClosing||C.current.isEditorClosed?!C.current&&be&&ge():C.current.isMounted&&!C.current.isStarted&&(C.current.isStarted=!0,C.current.startEvent.autoFocus&&(typeof C.current.startEvent.autoFocus=="string"?C.current.editorRefs[0]?.autoFocus(C.current.startEvent.autoFocus):C.current.editorRefs[0]?.autoFocus()),Oe?.(C.current),requestAnimationFrame(()=>{r&&C.current?.coords&&r.scrollCellCoordsIntoView(C.current.coords)})))},[me]),l.useEffect(()=>{Ve.current=_;const P=C.current?.coords;n.CoordUtils.isEqualCells(P,_)||(C.current&&(C.current.isEditorClosing=!0),L({eventType:"coordsChange",activeCoords:_}))},[_]);const ct=l.useCallback(P=>{xt(P.nativeEvent)},[]),{width:rt=0,height:se=0}=U??{width:0,height:0},Pt=o.useCallbackRef(c,[c]);return{overlay:o.useCallbackRef(P=>{if(!C.current||C.current.isEditorClosed)return C.current,null;C.current.coords;let R=we(P,C.current.coords,rt,se,re,ee),be=!0;R&&R.width!==0&&R.height!==0||(R={x:0,y:0,width:rt,height:rt},be=!1);const te=P.getZoom(),ue={containerBounds:{x:0,y:0,width:R.width/te,height:R.height/te},setNaturalSize:X,zoom:te};return Q.jsx(pn,{session:C.current,refLatestCoords:Ve,handleSubmitEdit:pe,handleCancelEdit:ce,cellBounds:R,borderStrokeWidth:B,borderStrokeFill:D,isInBounds:be,getCellEditor:Pt,propsEditor:ue,alignment:ee,...M},"editor:"+C.current.uuid)},[c,re,me,rt,se,ee,B,D]),startEdit:l.useCallback(P=>{L({eventType:"start",startEvent:P})},[]),submitEdit:l.useCallback(()=>{L({eventType:"submit"})},[]),cancelEdit:l.useCallback(()=>{L({eventType:"cancel"})},[]),onKeyboardEvent:ct,onPointerEvent:St,onKeyboardEventNative:xt,onPointerEventNative:j,isEditing:Me}},exports.useSelection=({gridRef:t,commands:r,layout:i,selection:c,onSelectionChange:d,onSelectionDragStart:f,onSelectionDragEnd:a,selectionPolicy:s="multiple",newSelectionMode:p="clear",allowDeselectSelection:O=!0,onFillPreview:T,onFillCancel:M,onFillDone:D,onFill:B,disableFillDrag:re=!B,fillHandleBorderColor:_="white",hiddenRowsAt:ee,hiddenColumnsAt:Me,isContentfulCell:Z,contentfulCellFinder:U=bn,getDataCoords:X,alwaysScrollToActiveCoords:we=!1,selectionBounds:K,pointerDownInterceptor:ge,pointerMoveInterceptor:Le,mergedRanges:ye,canSelectionSpanMergedCells:Oe=In,onMoveDragStart:ce,onMoveDragUpdate:pe,onMoveDragEnd:A,onMoveDragDone:C,selectionRenderer:$e=qo,disableMoveDrag:Ve=!A,getCellCoordsAsRangeCoords:G=n.CoordUtils.cellToRange,moveDragHitSize:me=6,moveDragOutlineSize:q=4,selectionBackgroundColor:L="rgba(16, 124, 65, 0.1)",selectionBorderColor:j="rgb(33, 115, 70)",selectionRemoveBorderColor:St="rgb(255, 0, 0)",selectionRemoveBackgroundColor:xt="rgba(250, 10, 10, 0.1)",disableTouchSelection:ct=!1,touchSelectHandleProps:rt})=>{const se=l.useCallback(()=>({top:K?.top??0,left:K?.left??0,bottom:t.current?.rowCount-1||0,right:t.current?.columnCount-1||0}),[]),Pt=o.useCallbackRef(B,[B]),P=o.useCallbackRef(T,[T]),R=o.useCallbackRef(M,[M]),be=o.useCallbackRef(D,[D]),te=o.useCallbackRef(Z,[Z]),ue=o.useCallbackRef($e,[$e]),ze=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getRowOffset,u?se().bottom:se().top),[i?.getRowOffset]),Je=o.useCallbackRef(ee??ze,[ee]),mt=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getColOffset,u?se().right:se().left),[i?.getColOffset]),Qe=o.useCallbackRef(Me??mt,[Me]),[Tt,st]=l.useState(()=>yt(c)),b=l.useMemo(()=>yt(Tt),[Tt]),oe=l.useRef(b),Ae=l.useRef(!0);l.useLayoutEffect(n.CommonUtils.throttle(()=>{st(e=>{Ae.current=!0;const u=yt(c);return n.CoordUtils.isEqualSelectionCoords(u,e)?e:u})},0),[c]),l.useLayoutEffect(()=>{oe.current=b},[b]),l.useEffect(()=>{Ae.current||!d||n.CoordUtils.isEqualSelectionCoords(c,b)||d(b)},[b]);const lt=l.useCallback(e=>{st(u=>{Ae.current=!1,u=yt(u);let g=typeof e=="function"?e(u.ranges):e??To;if(n.CoordUtils.isEqualRangesArrays(g,u.ranges))return u;let h=Math.max(g.length?0:-1,Math.min(u.rangeIndex,g.length-1)),x=u.cell;h===-1||n.CoordUtils.isCellWithinRange(x,g[h])||(x={rowIndex:g[h].rowStart,colIndex:g[h].colStart}),g.length===1&&n.CoordUtils.isSingleCell(g[0])&&n.CoordUtils.isCellWithinRange(x,g[0])&&(g=[],h=-1);const k={cell:x,ranges:g,rangeIndex:h};return n.CoordUtils.isEqualSelectionCoords(k,u)?u:k})},[]),qe=o.useCallbackRef(e=>{st(u=>{Ae.current=!1,u=yt(u);const g=e??on,h=G(g);if(!n.CoordUtils.isSingleCell(h)&&u.ranges.length===0)return{ranges:[h],rangeIndex:0,cell:g};if(n.CoordUtils.isEqualCells(g,u.cell))return u;let x=u.ranges,k=u.rangeIndex;u.ranges.length===1&&(n.CoordUtils.isSingleCell(u.ranges[0])&&n.CoordUtils.isCellWithinRange(g,u.ranges[0])||!n.CoordUtils.isCellWithinRange(g,u.ranges[0]))&&(x=[],k=-1);const m={ranges:x,rangeIndex:k,cell:g};return n.CoordUtils.isEqualSelectionCoords(m,u)?u:m})},[G]),[Ht,$t]=l.useState(null),[bt,Xt]=l.useState(null),At=l.useRef(null),[Re,Ut]=l.useState(null),ut=l.useRef(null),kt=l.useRef(null),[eo,jt]=l.useState(null),He=l.useRef(null),Be=l.useRef(null),Ft=l.useRef(ye);l.useEffect(()=>{Ft.current=ye},[ye]);const ht=o.useCallbackRef((e,u={inline:"nearest",block:"nearest"})=>{let{rowIndex:g,colIndex:h}=e;g===void 0&&b?.cell&&(g=b.cell.rowIndex),h===void 0&&b?.cell&&(h=b.cell.colIndex),g!==void 0&&h!==void 0&&t.current?.scrollCellCoordsIntoView({rowIndex:g,colIndex:h},u)},[b]),Lt=l.useCallback(e=>{const u=se();return e.rowIndex<u.top||e.colIndex<u.left||e.colIndex>u.right||e.rowIndex>u.bottom},[]),ve=o.useCallbackRef((e,u)=>{if(!t?.current)return null;const g={rowStart:Math.min(e.rowIndex,u.rowIndex),colStart:Math.min(e.colIndex,u.colIndex),rowEnd:Math.max(e.rowIndex,u.rowIndex),colEnd:Math.max(e.colIndex,u.colIndex)};if(Oe?.(g))return g;const x=G(e),k=G(u),m={rowStart:Math.min(x.rowStart,k.rowStart),colStart:Math.min(x.colStart,k.colStart),rowEnd:Math.max(x.rowEnd,k.rowEnd),colEnd:Math.max(x.colEnd,k.colEnd)};let N;return typeof Ft.current=="function"?N=Ft.current(m):ye&&(N=ye),N?n.CoordUtils.extendRangeToUnionRanges(m,N):m},[Oe,G]),je=o.useCallbackRef((e,u,g)=>{const h=e.ranges.length>0?e.ranges[e.rangeIndex]:{rowStart:e.cell.rowIndex,colStart:e.cell.colIndex,rowEnd:e.cell.rowIndex,colEnd:e.cell.colIndex},x={rowStart:Math.min(u.rowIndex??h.rowStart,g.rowIndex??h.rowStart),colStart:Math.min(u.colIndex??h.colStart,g.colIndex??h.colStart),rowEnd:Math.max(u.rowIndex??h.rowEnd,g.rowIndex??h.rowEnd),colEnd:Math.max(u.colIndex??h.colEnd,g.colIndex??h.colEnd)},k={rowIndex:x.rowStart,colIndex:x.colStart},m={rowIndex:x.rowEnd,colIndex:x.colEnd};if(!(Lt(k)||Lt(m)))return ve(k,m)},[ve]),it=o.useCallbackRef((e,u,g)=>{if(s==="single"||!oe.current)return;const h=je(oe.current,e,u??oe.current.cell);if(!h)return;const x=oe.current.rangeIndex;lt(k=>k.length?k.map((m,N)=>x===N?h:m):[h]),g&&h&&qe({colIndex:h.colStart,rowIndex:h.rowStart})},[]),pt=l.useCallback((e,u,g)=>{if(!oe.current)return;e={...oe.current?.cell,...e},u=u??e;const h=je(oe.current,e,u);if(!h)return;const x={rowIndex:h.rowStart,colIndex:h.colStart},k={...x,...g};p==="clear"?(He.current=k,Bt()):p==="modify"?it(x):Ce(x),qe(k)},[]),Ce=l.useCallback((e,u=e,g)=>{s!=="multiple"||!e||Lt(e)||Lt(u)||st(h=>{Ae.current=!1,h=yt(h);const x=ve(e,u);if(!x)return h;let k=h.ranges.length>0?[...h.ranges]:[ve(h.cell,h.cell)];k.push(x);const m={ranges:k,cell:{rowIndex:x.rowStart,colIndex:x.colStart,...g},rangeIndex:k.length-1};return n.CoordUtils.isEqualSelectionCoords(m,h)?h:m})},[]),Bt=()=>{lt(To)},Rt=o.ReactUtils.detectIt().primaryInput==="touch",_e=l.useRef(null),Ct=l.useRef(null),vt=l.useRef(null),Nt=l.useMemo(()=>({onPointerDown:e=>{if(!t||!t.current)return!1;const u=e.nativeEvent,g=t.current.getViewFromClient(u.clientX,u.clientY);if(u.pointerType==="touch"||u.type==="touchstart")return Ct.current={topLeft:g.getScrollTopLeft(),point:{x:u.clientX,y:u.clientY}},!0;const h=g.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return!1;_e.current={anchor:g.getAnchor(),coords:h},Be.current=null;const x=e.nativeEvent.which===o.MouseButtonCodes.Right;if(x&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1)return!1;const k=e.nativeEvent.shiftKey,m=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,N=m,$=O,W=b.ranges.length>0,Y=m&&$;if(ge?.(e,h,b)===!1)return!1;f?.(oe.current,e.nativeEvent);const xe=!x&&s!=="single";if(k)return it(h),xe;const H=n.CoordUtils.isEqualCells(h,b.cell);if(N){if(H&&(!Y||!W))return xe;if(m&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1&&$){ut.current=h;const V=ve(h,h);return kt.current=V,Ut(V),xe}return Ce(h),xe}we&&ht(h),H&&b.ranges.length===0||pt(h)},onPointerMoveOrWait:n.CommonUtils.throttle((e,u)=>{if(!t?.current||e.pointerType==="touch"||e.type==="touchmove"||!_e.current)return;const g=_e.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(x,_e.current?.coords)&&(_e.current={anchor:g,coords:x},x&&Le?.(e,x,oe.current)!==!1)){if(ut.current){const k={rowStart:Math.min(x.rowIndex,ut.current.rowIndex),colStart:Math.min(x.colIndex,ut.current.colIndex),rowEnd:Math.max(x.rowIndex,ut.current.rowIndex),colEnd:Math.max(x.colIndex,ut.current.colIndex)},m={rowIndex:k.rowStart,colIndex:k.colStart},N={rowIndex:k.rowEnd,colIndex:k.colEnd};if(Lt(m)||Lt(N))return;const $=ve(m,N);kt.current=$,Ut($)}else it(x);vt.current=u,ho(h,x,t)}},60),onPointerUp:e=>{if(_e.current=null,e.pointerType==="touch"||e.type==="touchend"){if(Ct.current){const g=t.current.getViewFromClient(Ct.current.point.x,Ct.current.point.y),h=g.getScrollTopLeft();if(h.left===Ct.current.topLeft.left&&h.top===Ct.current.topLeft.top){const x=g.getCellCoordsFromClient(Ct.current.point.x,Ct.current.point.y);pt(x)}}return Ct.current=null,void(_e.current=null)}try{a?.(oe.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})},processTouch:!0,consumeTouch:!1}),[b,s,O,we,p]),xo=o.useCallbackRef(o.useSynchronizedPointerHandler(Nt),[]),po=l.useMemo(()=>({onSelectionPointerDown:(e,u,g,h,x=b.cell,k=we,m=e.nativeEvent.shiftKey,N=!1)=>{if(!t||!t.current)return!1;e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();const $=g??t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),W=h??$.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!W)return!1;_e.current={anchor:$.getAnchor(),coords:W},Be.current=null;const Y=e.nativeEvent.which===o.MouseButtonCodes.Right;if(Y&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1)return!1;const xe=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,H=xe,V=O,nt=b.ranges.length>0,I=xe&&V;if(ge?.(e,W,b)===!1)return!1;f?.(oe.current,e.nativeEvent);const fe=!Y&&s!=="single";if(m)return it(W,x,N),fe;const wt=n.CoordUtils.isEqualCells(W,x);if(H){if(wt&&(!I||!nt))return fe;if(I&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1&&V){ut.current=W;const de=ve(W,W);return kt.current=de,Ut(de),fe}return Ce(W),fe}k&&ht(W),wt&&b.ranges.length===0||pt(W)},onSelectionPointerMoveOrWait:(e,u,g,h,x,k=b.cell,m=!0,N=!1)=>{if(!t?.current||(e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation(),!_e.current))return;const $=_e.current.anchor;let W=h??t.current.getViewFromLocation($),Y=x??W.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(Y,_e.current?.coords)&&(_e.current={anchor:$,coords:Y},Y&&Le?.(e,Y,oe.current)!==!1)){if(ut.current){const xe={rowStart:Math.min(Y.rowIndex,ut.current.rowIndex),colStart:Math.min(Y.colIndex,ut.current.colIndex),rowEnd:Math.max(Y.rowIndex,ut.current.rowIndex),colEnd:Math.max(Y.colIndex,ut.current.colIndex)},H={rowIndex:xe.rowStart,colIndex:xe.colStart},V={rowIndex:xe.rowEnd,colIndex:xe.colEnd};if(Lt(H)||Lt(V))return;const nt=ve(H,V);kt.current=nt,Ut(nt)}else it(Y,k,N);m&&ho(W,Y,t)}},onPointerUp:e=>{_e.current=null,e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation();try{a?.(oe.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})}}),[b,s,O,we,p]),Ze=o.useCallbackRef((e,u=!1,g=!1,h=0)=>{if(!t.current||!b.cell)return;let x=b.cell,k=b.cell;if(u&&b.ranges.length>0){const I=b.ranges[b.rangeIndex],fe=b.cell;switch(e){case n.Direction.Up:k={rowIndex:fe.rowIndex===I.rowStart?I.rowEnd:I.rowStart,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowStart?I.rowStart:I.rowEnd,colIndex:I.colStart};break;case n.Direction.Down:k={rowIndex:fe.rowIndex===I.rowEnd?I.rowStart:I.rowEnd,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowEnd?I.rowEnd:I.rowStart,colIndex:I.colStart};break;case n.Direction.Left:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colStart?I.colEnd:I.colStart},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colStart?I.colStart:I.colEnd};break;case n.Direction.Right:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colEnd?I.colStart:I.colEnd},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colEnd?I.colEnd:I.colStart}}}const m=G(k);let{rowStart:N,colStart:$}=m;const W=se();if(Be.current)switch(e){case n.Direction.Up:case n.Direction.Down:Be.current.colIndex>=m.colStart&&Be.current.colIndex<=m.colEnd&&($=Be.current.colIndex);break;case n.Direction.Left:case n.Direction.Right:Be.current.rowIndex>=m.rowStart&&Be.current.rowIndex<=m.rowEnd&&(N=Be.current.rowIndex)}if(!h){switch(e){case n.Direction.Up:N=Te(Je,Math.max(m.rowStart-1,W.top),e);break;case n.Direction.Down:N=Te(Je,Math.min(m.rowEnd+1,W.bottom),e);break;case n.Direction.Left:$=Te(Qe,Math.max(m.colStart-1,W.left),e);break;case n.Direction.Right:$=Te(Qe,Math.min(m.colEnd+1,W.right),e)}if(g)switch(e){case n.Direction.Up:N=U({...k,colIndex:b.cell.colIndex},te,Je,e,!1,Math.max(W.top,Je(W.top,!1)));break;case n.Direction.Down:N=U({...k,colIndex:b.cell.colIndex},te,Je,e,!1,Math.min(W.bottom,W.bottom-Je(W.bottom,!0)));break;case n.Direction.Left:$=U({...k,rowIndex:b.cell.rowIndex},te,Qe,e,!1,Math.max(W.left,Qe(W.left,!1)));break;case n.Direction.Right:$=U({...k,rowIndex:b.cell.rowIndex},te,Qe,e,!1,Math.min(W.right,W.right-Qe(W.right,!0)))}}let Y=null;if(h){let I=0;switch(e){case n.Direction.Up:I=i.getRowOffset(N+1),N=Math.max(W.top,i.getRowIndex(I-h)),Y={top:i.getRowOffset(N+1)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Down:I=i.getRowOffset(N),N=Math.min(W.bottom,i.getRowIndex(I+h)),Y={top:i.getRowOffset(N)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Left:I=i.getColOffset($+1),$=Math.max(W.left,i.getColIndex(I-h)),Y={left:i.getColOffset($+1)-(I-t.current.getScrollPosition().left)};break;case n.Direction.Right:I=i.getColOffset($),$=Math.min(W.right,i.getColIndex(I+h)),Y={left:i.getColOffset($)-(I-t.current.getScrollPosition().left)}}}const xe={rowIndex:N,colIndex:$},H=G(xe),V={rowIndex:H.rowStart,colIndex:H.colStart};u||(Be.current=xe);const nt=n.CoordUtils.isEqualCells(He.current,V)&&n.CoordUtils.isEqualCells(He.current,x);if(u&&!nt?it(V,x):pt(V),Y)t.current.scrollTo(Y);else{if(u&&He.current){const I=se();if(e===n.Direction.Right&&He.current.colIndex===I.left||e===n.Direction.Left&&He.current.colIndex===I.right||e===n.Direction.Up&&He.current.rowIndex===I.bottom||e===n.Direction.Down&&He.current.rowIndex===I.top)return}e===n.Direction.Left||e===n.Direction.Right?ht({colIndex:xe.colIndex}):e!==n.Direction.Up&&e!==n.Direction.Down||ht({rowIndex:xe.rowIndex})}},[b,G]),Ot=o.useCallbackRef(e=>{if(!t.current)return;if(b.ranges.length===0)return void Ze(e);const u=G(b.cell);if(n.CoordUtils.isEqualRangesArrays([u],b.ranges))return void Ze(e);const g=Do(b,e,G,Je,Qe);st(h=>{Ae.current=!1,h=yt(h);const x={...h,cell:g.cell,rangeIndex:g.rangeIndex};return n.CoordUtils.isEqualSelectionCoords(x,h)?h:x}),g.cell&&ht(g.cell)},[b,G]),mo=l.useCallback(()=>{const e=se();it({rowIndex:e.top},{rowIndex:e.bottom})},[]),Co=l.useCallback(()=>{const e=se();it({colIndex:e.left},{colIndex:e.right})},[]),Kt=o.useCallbackRef(()=>{b.cell&&t?.current&&ht(b.cell)},[b.cell]),to=l.useCallback((e=!1)=>{const u={rowIndex:se().top};e?it(u):pt(u),ht(u)},[]),oo=l.useCallback((e=!1)=>{const u={rowIndex:se().bottom};e?it(u):pt(u),ht(u)},[]),Gt=l.useCallback((e=!1)=>{const u={colIndex:se().left};e?it(u):pt(u),ht(u)},[]),qt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:u.top,colIndex:u.left};e?it(g):pt(g),ht(g)},[]),_t=l.useCallback((e=!1)=>{const u=se(),g={colIndex:X?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[X]),Wt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:X?.()?.rowEnd??u.bottom,colIndex:X?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[X]),Zt=o.useCallbackRef(e=>{if(!t.current||b.ranges.length<=1)return;const u=e===n.Direction.Left||e===n.Direction.Up;let g=b.rangeIndex+(u?-1:1);g<0?g=b.ranges.length-1:g>b.ranges.length-1&&(g=0);const h=b.ranges[g],x=Do({cell:{rowIndex:h.rowEnd,colIndex:h.colEnd},rangeIndex:0,ranges:[h]},n.Direction.Right,G,Je,Qe);st(k=>{Ae.current=!1,k=yt(k);const m={...k,cell:x.cell,rangeIndex:g};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x.cell&&ht(x.cell)},[b,G]),So=o.useCallbackRef(()=>{const e=Vo(b);st(u=>{Ae.current=!1,u=yt(u);const g={...u,visibleSelection:e};return n.CoordUtils.isEqualSelectionCoords(g,u)?u:g}),e.cell&&ht(e.cell)},[b,G]),bo=o.useCallbackRef(()=>{if(!t.current||b.ranges.length===0)return;const e=b.cell,u=b.ranges[b.rangeIndex],g=Vo({cell:e,rangeIndex:0,ranges:[u]}),h=g.ranges[g.rangeIndex];let x;x=h.rowStart===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowStart,colIndex:h.colEnd}:h.rowStart===e.rowIndex&&h.colEnd===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colStart}:h.rowEnd===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colEnd}:{rowIndex:h.rowStart,colIndex:h.colStart},st(k=>{k=yt(k);const m={...k,cell:x};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x&&ht(x)},[b,G]),no=l.useCallback((e=!1)=>{Ze(n.Direction.Down,e,!1,t.current.getDimensions().containerHeight)},[]),Mt=l.useCallback((e=!1)=>{Ze(n.Direction.Up,e,!1,t.current.getDimensions().containerHeight)},[]),ro=l.useCallback((e=!1)=>{Ze(n.Direction.Right,e,!1,t.current.getDimensions().containerWidth)},[]),Jt=l.useCallback((e=!1)=>{Ze(n.Direction.Left,e,!1,t.current.getDimensions().containerWidth)},[]),lo=l.useCallback(()=>{Ot(n.Direction.Left)},[]),io=l.useCallback(()=>{Ot(n.Direction.Right)},[]),vo=l.useCallback(()=>{Ot(n.Direction.Up)},[]),yo=l.useCallback(()=>{Ot(n.Direction.Down)},[]),Qt=l.useCallback(()=>{Zt(n.Direction.Left)},[]),Ro=l.useCallback(()=>{Zt(n.Direction.Right)},[]),Eo=l.useCallback(()=>{bo()},[]),co=l.useCallback(()=>{Ze(n.Direction.Left,!1,!1)},[]),w=l.useCallback(()=>{Ze(n.Direction.Left,!0,!1)},[]),S=l.useCallback(()=>{Ze(n.Direction.Left,!1,!0)},[]),E=l.useCallback(()=>{Ze(n.Direction.Left,!0,!0)},[]),v=l.useCallback(()=>{Ze(n.Direction.Right,!1,!1)},[]),y=l.useCallback(()=>{Ze(n.Direction.Right,!0,!1)},[]),z=l.useCallback(()=>{Ze(n.Direction.Right,!1,!0)},[]),he=l.useCallback(()=>{Ze(n.Direction.Right,!0,!0)},[]),ne=l.useCallback(()=>{Ze(n.Direction.Up,!1,!1)},[]),ae=l.useCallback(()=>{Ze(n.Direction.Up,!0,!1)},[]),F=l.useCallback(()=>{Ze(n.Direction.Up,!1,!0)},[]),Se=l.useCallback(()=>{Ze(n.Direction.Up,!0,!0)},[]),Ke=l.useCallback(()=>{Ze(n.Direction.Down,!1,!1)},[]),Pe=l.useCallback(()=>{Ze(n.Direction.Down,!0,!1)},[]),Ne=l.useCallback(()=>{Ze(n.Direction.Down,!1,!0)},[]),Ee=l.useCallback(()=>{Ze(n.Direction.Down,!0,!0)},[]),le=l.useCallback(()=>{lt(e=>e.slice(0,-1))},[]),et=l.useMemo(()=>{const e=se();return((u,g,h,x,k)=>{const m=u.length;for(let N=0;N<m;N++){const $=u[N];if($.rowStart===g&&$.colStart===h&&$.rowEnd===x&&$.colEnd===k)return!0}return!1})(b.ranges,e.top,e.left,e.bottom,e.right)},[K,b.ranges]),Ye=l.useCallback((e,u=!0)=>{He.current=e,qe(e),u&&e&&t?.current&&ht(e)},[]),Ue=o.useCallbackRef((e=!0)=>{const u=At.current;if(!oe.current?.cell)return;const g=oe.current?.ranges,h=oe.current?.cell;if(!h||!u||!u)return;let x=null;if(x=g.length>0?g[g.length-1]:G(h),x.colEnd>=x.colStart&&x.rowEnd>=x.rowStart){const k=Ho(x,u);let m=e?Pt:P;try{m?.(x,u,k.direction)}catch(N){console.warn(N)}finally{e&&be?.()}}},[G]),Xe=l.useRef(null),ft=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);h&&(e.stopPropagation(),$t("crosshair"),Xe.current={anchor:g.getAnchor(),coords:h})},onPointerMoveOrWait:(e,u)=>{if(re||!t?.current||!oe.current||!Xe.current)return;const g=Xe.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!x)return;Xe.current={anchor:g,coords:x};const k=oe.current.ranges;let m=ve(oe.current.cell,x);if(!m)return;const N=k.length>0,$=N?k[k.length-1]:G(oe.current.cell);if(!m)return;const W=m.rowStart<$.rowStart?n.Direction.Up:m.rowEnd>$.rowEnd?n.Direction.Down:m.colEnd>$.colEnd?n.Direction.Right:n.Direction.Left,Y=se();W===n.Direction.Left&&(m={...$,colStart:Math.max(Y.left,m.colStart)}),W===n.Direction.Up&&(m={...$,rowStart:Math.max(Y.top,m.rowStart)}),W===n.Direction.Right&&(m={...$,colEnd:Math.min(Y.right,m.colEnd)}),W===n.Direction.Down&&(m={...$,rowEnd:Math.min(Y.bottom,m.rowEnd)});const xe=Ho($,m);if(!Oe?.($)){let H;typeof Ft.current=="function"?H=Ft.current($):ye&&(H=ye),m=((V,nt,I,fe,wt,de)=>{const ie={...nt};if(I.length===0)return ie;if(wt===n.Direction.Left){const ot=V.colEnd+1-V.colStart;ie.colStart=V.colStart-Math.ceil(de/ot)*ot,ie.colStart<fe.left&&(ie.colStart=ie.colStart+Math.ceil((fe.left-ie.colStart)/ot)*ot)}else if(wt===n.Direction.Right){const ot=V.colEnd+1-V.colStart;ie.colEnd=V.colEnd+Math.ceil(de/ot)*ot,ie.colEnd>fe.right&&(ie.colEnd=ie.colEnd-Math.ceil((fe.right-ie.colEnd)/ot)*ot)}else if(wt===n.Direction.Up){const ot=V.rowEnd+1-V.rowStart;ie.rowStart=V.rowStart-Math.ceil(de/ot)*ot,ie.rowStart<fe.top&&(ie.rowStart=ie.rowStart+Math.ceil((fe.top-ie.rowStart)/ot)*ot)}else if(wt===n.Direction.Down){const ot=V.rowEnd+1-V.rowStart;ie.rowEnd=V.rowEnd+Math.ceil(de/ot)*ot,ie.rowEnd>fe.bottom&&(ie.rowEnd=ie.rowEnd-Math.ceil((fe.bottom-ie.rowEnd)/ot)*ot)}return ie})($,m,H,Y,xe.direction,xe.amount)}if(N&&n.CoordUtils.isRangeWithinRange(m,$)&&(m=null),!n.CoordUtils.isEqualRanges(m,At.current)){if(Xt(m),At.current=m,!m){try{R?.()}catch{}return void be?.()}Ue(!1)}vt.current=u,ho(h,x,t)},onPointerUp:(e,u)=>{vt.current=u,Promise.resolve(Ue(!0)).finally(()=>{be?.(),Xt(null),At.current=null,Xe.current=null,$t(null),t.current?.focus()})}}),[G]),Fe=o.useSynchronizedPointerHandler(ft),J=l.useMemo(()=>({onPointerDown:Fe}),[Fe]),[We,at]=l.useState(null),Ie=l.useRef(null),Ge=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return;if(ge?.(e,h,b)===!1)return!1;e.stopPropagation(),$t("default");const x=g.getRelativePointFromClient(0,0),k=oe.current?.ranges[oe.current?.ranges.length-1]??n.CoordUtils.cellToRange(oe.current?.cell),m=g.toClipBounds(g.getRangeCoordsBounds(k)),N={x:0,y:0};m.x-x.x>e.nativeEvent.clientX?N.x=e.nativeEvent.clientX-(m.x-x.x):e.nativeEvent.clientX>=m.x-x.x+m.width&&(N.x=Math.max(0,e.nativeEvent.clientX-(m.x-x.x+m.width))+1),m.y-x.y>e.nativeEvent.clientY?N.y=e.nativeEvent.clientY-(m.y-x.y):e.nativeEvent.clientY>=m.y-x.y+m.height&&(N.y=Math.max(0,e.nativeEvent.clientY-(m.y-x.y+m.height))+1),ce?.(k,e.nativeEvent,u),Ie.current={range:k,anchor:g.getAnchor(),cell:h,isMoving:!1,extrusion:N}},onPointerMoveOrWait:(e,u,g)=>{if(Ve||!t?.current||!oe.current||!Ie.current)return;const h=e.clientX-g.clientX,x=e.clientY-g.clientY;if(Ie.current.isMoving=Ie.current.isMoving||Math.abs(h)>Math.max(1,2)||Math.abs(x)>Math.max(1,2)||performance.now()-g.timeStamp>500,!Ie.current.isMoving)return;const k=Ie.current.anchor,m=Ie.current.extrusion;let N=t.current.getViewFromLocation(k),$=N.getCellCoordsFromClient(e.clientX-m.x,e.clientY-m.y,!0);if(!$)return;const W=Ie.current.cell,Y=Ie.current.range,xe=se(),H=Y.colEnd-Y.colStart+1,V=Math.min(Math.max(0,W.colIndex-Y.colStart),H-1),nt=Math.min(xe.right-H+1,Math.max(xe.left,$.colIndex-V)),I=Y.rowEnd-Y.rowStart+1,fe=Math.min(Math.max(0,W.rowIndex-Y.rowStart),I-1),wt=Math.min(xe.bottom-I+1,Math.max(xe.top,$.rowIndex-fe)),de={colStart:nt,colEnd:nt+H-1,rowStart:wt,rowEnd:wt+I-1};n.CoordUtils.isEqualRanges(We,de)&&!(ie=>!ie||!vt.current||vt.current.ctrlKey!==ie.ctrlKey||vt.current.shiftKey!==ie.shiftKey||vt.current.altKey!==ie.altKey||vt.current.metaKey!==ie.metaKey)(e)||(at(de),pe?.(de,e,u)),vt.current=u,ho(N,$,t)},onPointerUp:(e,u)=>{vt.current=u;const g=()=>{at(null),Ie.current=null,$t(null),t.current?.focus()};if(!Ie.current)return void g();const h=Ie.current.range,x=We;A?.(h,e,u),Promise.resolve(h&&x&&C?.(h,x,e,u)).finally(()=>{g()})}}),[We]),De=o.useSynchronizedPointerHandler(Ge),ke=l.useMemo(()=>({onPointerDown:De}),[De]),dt=l.useRef(null),tt=l.useMemo(()=>{const e=n.CoordUtils.isEqualSelectionCoords(b,dt.current)?dt.current:b;return dt.current=e,e},[b]),gt=l.useCallback(e=>{let u=null,g="br";const h=[],x={stroke:_,fill:L,strokeWidth:.5},k=(H,V,nt)=>{const I=e.toClipBounds(e.getRangeCoordsBounds(H),It);if(!I)return;I.x=I.width>0?I.x:I.x-x.strokeWidth/2,I.y=I.height>0?I.y:I.y-x.strokeWidth/2,I.width=Math.max(I.width,x.strokeWidth),I.height=Math.max(I.height,x.strokeWidth);const fe={key:`selection-fill-${V}`,range:H,...I,...x};if(nt){const wt=e.getCellCoordsAsRangeCoords(nt);fe.cell=nt,fe.pathBounds=e.toClipBounds(e.getRangeCoordsBounds(wt),It),fe.pathBounds&&(fe.pathBounds.width<=0||fe.pathBounds.height<=0)&&(delete fe.pathBounds,delete fe.cell)}return ue(fe)};let m=b?yt(b):null;const N=m?.cell?e.getCellCoordsAsRangeCoords(m?.cell):En;!m||m.ranges&&m.ranges.length!==0||(m={ranges:[N],rangeIndex:0,cell:m.cell});for(let H=0;m&&H<m.ranges.length;H++){const V=m.ranges[H],nt=k(V,H,H===m.rangeIndex?m.cell:null);nt&&h.push(nt);const I=2,fe=.5,wt=e.toClipBounds(e.getRangeCoordsBounds(V,{top:0,left:0,right:0,bottom:0}),It);if(wt){const de=(m.ranges.length,4);h.push(ue({range:V,key:`selection-inside-edge-${H}`,x:wt.x-1,y:wt.y-1,width:Math.max(wt.width+1,0),height:Math.max(wt.height+1,0),style:{overflow:"hidden"},stroke:_,strokeWidth:de}))}if(m.ranges.length===1){const de=e.toClipBounds(e.getRangeCoordsBounds(V),It);if(de){Ve||h.push(ue({range:V,key:`move-selection-hit-box-${H}`,x:de.width>1?de.x:de.x-(me/2+1),y:de.height>1?de.y:de.y-(me/2+1),width:Math.max(de.width+2,1),height:Math.max(de.height+2,1),stroke:"transparent",style:{boxShadow:"none"},pathProps:{cursor:We?void 0:"move",pointerEvents:"stroke"},strokeWidth:me,...ke}));const ie=I;h.push(ue({range:V,key:`selection-single-${H}`,x:de.x-ie/2,y:de.y-ie/2,width:Math.max(de.width+ie/2,1),height:Math.max(de.height+ie/2,1),stroke:j,strokeWidth:ie}))}}else{const de=e.toClipBounds(e.getRangeCoordsBounds(V,{top:-1,left:-1,right:-2,bottom:-2}),It);de&&h.push(ue({range:V,key:`selection-multi-${H}`,x:de.width>1?de.x:de.x-fe/2,y:de.height>1?de.y:de.y-fe/2,width:Math.max(de.width,fe)+1,height:Math.max(de.height,fe)+1,stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(m.ranges.length>1&&H===m.rangeIndex){const de=e.getCellCoordsAsRangeCoords(m.cell),ie=e.toClipBounds(e.getRangeCoordsBounds(de,{top:1,left:1,right:-1,bottom:-1}),It);ie&&h.push(ue({range:V,key:`selection-anchor-${H}`,x:ie.x,y:ie.y,width:Math.max(ie.width,fe),height:Math.max(ie.height,fe),stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(H===m.ranges.length-1){u=null,g=null;const de=V.rowStart===se().top&&V.rowEnd===se().bottom,ie=V.colStart===se().left&&V.colEnd===se().right,ot=e.getRangeCoordsBounds(V);let Dt=null;if(de||ie){if(Dt=e.toClipBounds(ot,It),Object.keys(e.allViews()).length>1){const so=e.getVisibleRangeCoords(),$o=e.allViews()[n.AnchorLocation.TopLeft],un=e.allViews()[n.AnchorLocation.Top],hn=e.allViews()[n.AnchorLocation.Left],ao=e.getAnchor();(ie&&(ao===n.AnchorLocation.Top&&$o||ao===n.AnchorLocation.Center&&hn||!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd+1},so))||de&&(ao===n.AnchorLocation.Left&&$o||ao===n.AnchorLocation.Center&&un||!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd,rowIndex:V.rowStart},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd+1,rowIndex:V.rowStart},so)))&&(Dt=null)}}else Dt=e.toClipBounds(ot,It);if(!Dt||Dt.width===0||Dt.height===0)continue;u={x:Dt.x+Dt.width+1,y:Dt.y+Dt.height+1},Dt.width===0||Dt.height===0||V.rowStart===se().top&&V.colStart===se().left&&V.rowEnd===se().bottom&&V.colEnd===se().right||(de?(u.y=I,g="tr"):ie&&(u.x=I,g="bl"))}}let $=null;if(Re){const H=e.toClipBounds(e.getRangeCoordsBounds(Re,{top:0,left:0,right:0,bottom:0}),It);H&&($=ue({...x,range:Re,key:"remove-selection",x:H.x,y:H.y,width:H.width,height:H.height,strokeWidth:2,stroke:St,fill:xt}))}let W=null;if(bt){const H=e.toClipBounds(e.getRangeCoordsBounds(bt,{top:0,left:0,right:0,bottom:0}),It);H&&(W=ue({range:bt,key:"selection-fill-outline",x:H.x-2/2,y:H.y-2/2,width:H.width+2/2,height:H.height+2/2,strokeWidth:2,stroke:j,strokeDasharray:"3 2"}))}let Y=null;!re&&u&&!We&&(Y=l.createElement(Uo,{...u,corner:g,size:7.5,borderStroke:`${_} solid`,style:{borderRadius:1},background:j,...J,key:"fillHandle"}));const xe=[...h];if($&&xe.push($),W&&xe.push(W),Y&&xe.push(Y),!ct&&Rt&&m?.ranges.length===1&&m.ranges[m.ranges.length-1]){const H=m.ranges[m.ranges.length-1],V=H.rowStart===se().top&&H.rowEnd===se().bottom,nt=H.colStart===se().left&&H.colEnd===se().right,I={view:e,range:H,borderStroke:`${j} solid`,background:_,selectionTouchPointerHandler:po,...rt,onTouchSelectStart:fe=>jt(fe),onTouchSelectEnd:()=>jt(null),currentTouchAnchor:eo};xe.push(Q.jsx(fo,{anchor:nt?"b":V?"r":"br",scrollableElement:t.current,...I},"touch-select-handle-after")),xe.push(Q.jsx(fo,{anchor:nt?"t":V?"l":"tl",scrollableElement:t.current,...I},"touch-select-handle-before"))}if(We){const H=e.toClipBounds(e.getRangeCoordsBounds(We,{top:1,left:1,right:1,bottom:1}),It);H&&xe.push(ue({range:We,key:"selection-move-outline",x:H.x-q/2,y:H.y-q/2,width:Math.max(H.width+q/2,1),height:Math.max(H.height+q/2,1),stroke:j,style:{boxShadow:"none",transitionDuration:"70ms",transitionTimingFunction:"ease-in",transitionProperty:"left, top, width, height",willChange:"left, top, width, height"},strokeWidth:q}))}return Q.jsx("div",{children:xe},"selection")},[tt,Re,re,bt,Ve,We,se,_,j,L,St,xt,ct,rt,eo]),Et=l.useMemo(()=>{const e=()=>t.current;return[new o.SimpleCommand("moveToPageDown",e,{label:"Page Down",description:"Shift viewport down one page.",shortcut:[{key:"PageDown"}]},()=>no(!1)),new o.SimpleCommand("selectToPageDown",e,{label:"Select To Page Down",description:"Shift viewport and select down one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Shift]}]},()=>no(!0)),new o.SimpleCommand("moveToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt]}]},()=>ro(!1)),new o.SimpleCommand("selectToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>ro(!0)),new o.SimpleCommand("moveToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp"}]},()=>Mt(!1)),new o.SimpleCommand("selectToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Shift]}]},()=>Mt(!0)),new o.SimpleCommand("moveToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt]}]},()=>Jt(!1)),new o.SimpleCommand("selectToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>Jt(!0)),new o.SimpleCommand("selectColumn",e,{label:"Select Column",description:"Select the columns for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Ctrl]}},mo),new o.SimpleCommand("selectRow",e,{label:"Select Row",description:"Select the rows for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Shift]}},Co),new o.SimpleCommand("selectToColumnStart",e,{label:"Select To Column Start",description:"Select the columns to the beginning of the sheet."},()=>to(!0)),new o.SimpleCommand("selectToColumnEnd",e,{label:"Select To Column End",description:"Select the columns to the end of the sheet."},()=>oo(!0)),new o.SimpleCommand("moveToRowStart",e,{label:"Move to Row Home",description:"Move to the beginning of the row.",shortcut:[{key:"Home"}]},()=>Gt(!1)),new o.SimpleCommand("selectToRowStart",e,{label:"Select to Row Home",description:"Select to the beginning of the row.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Shift]}]},()=>Gt(!0)),new o.SimpleCommand("moveToSheetStart",e,{label:"Move to Sheet Home",description:"Move to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl]}]},()=>qt(!1)),new o.SimpleCommand("selectToSheetStart",e,{label:"Select to Sheet Home",description:"Select to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>qt(!0)),new o.SimpleCommand("moveToRowEnd",e,{label:"Move to Row End",description:"Move to the end of the row.",shortcut:[{key:"End"}]},()=>_t(!1)),new o.SimpleCommand("selectToRowEnd",e,{label:"Select to Row End",description:"Select to the end of the row.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Shift]}]},()=>_t(!0)),new o.SimpleCommand("moveToSheetEnd",e,{label:"Move to Sheet End",description:"Move to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl]}]},()=>Wt(!1)),new o.SimpleCommand("selectToSheetEnd",e,{label:"Select to Sheet End",description:"Select to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>Wt(!0)),new o.SimpleCommand("scrollToActiveCoords",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Ctrl]}},Kt),new o.SimpleCommand("scrollToActiveCoordsClearSelection",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell and clear selection.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Shift]}},()=>{Bt(),Ye(b.cell,!0)}),new o.SimpleCommand("traverseSelectionRight",e,{label:"Traverse Right",description:"Traverse the selection moving rightward.",shortcut:{key:"Tab"}},io),new o.SimpleCommand("traverseSelectionLeft",e,{label:"Traverse Left",description:"Traverse the selection moving leftward.",shortcut:{key:"Tab",modifiers:[o.KeyModifiers.Shift]}},lo),new o.SimpleCommand("traverseSelectionDown",e,{label:"Traverse Down",description:"Traverse the selection moving downward.",shortcut:[{key:"Enter"},{key:"NumpadEnter"}]},yo),new o.SimpleCommand("traverseSelectionUp",e,{label:"Traverse Up",description:"Traverse the selection moving upward.",shortcut:[{key:"Enter",modifiers:[o.KeyModifiers.Shift]},{key:"NumpadEnter",modifiers:[o.KeyModifiers.Shift]}]},vo),new o.SimpleCommand("moveLeft",e,{label:"Move Left",description:"Move active cell to the left.",shortcut:[{key:"ArrowLeft"}]},co),new o.SimpleCommand("selectLeft",e,{label:"Select Left",description:"Extend selection left.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Shift]}]},w),new o.SimpleCommand("moveContentfulLeft",e,{label:"Move Left Contentful",description:"Move left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl]}]},S),new o.SimpleCommand("selectContentfulLeft",e,{label:"Select Left Contentful",description:"Extend selection left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},E),new o.SimpleCommand("moveRight",e,{label:"Move Right",description:"Move active cell to the right.",shortcut:[{key:"ArrowRight"}]},v),new o.SimpleCommand("selectRight",e,{label:"Select Right",description:"Extend selection right.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Shift]}]},y),new o.SimpleCommand("moveContentfulRight",e,{label:"Move Right Contentful",description:"Move right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl]}]},z),new o.SimpleCommand("selectContentfulRight",e,{label:"Select Right Contentful",description:"Extend selection right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},he),new o.SimpleCommand("moveUp",e,{label:"Move Up",description:"Move active cell to the up.",shortcut:[{key:"ArrowUp"}]},ne),new o.SimpleCommand("selectUp",e,{label:"Select Up",description:"Extend selection up.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Shift]}]},ae),new o.SimpleCommand("moveContentfulUp",e,{label:"Move Up Contentful",description:"Move up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl]}]},F),new o.SimpleCommand("selectContentfulUp",e,{label:"Select Up Contentful",description:"Extend selection up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Se),new o.SimpleCommand("moveDown",e,{label:"Move Down",description:"Move active cell to the down.",shortcut:[{key:"ArrowDown"}]},Ke),new o.SimpleCommand("selectDown",e,{label:"Select Down",description:"Extend selection down.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Shift]}]},Pe),new o.SimpleCommand("moveContentfulDown",e,{label:"Move Down Contentful",description:"Move down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl]}]},Ne),new o.SimpleCommand("selectContentfulDown",e,{label:"Select Down Contentful",description:"Extend selection down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Ee),new o.SimpleCommand("selectVisible",e,{label:"Select Visible",description:"Select visible cells only.",shortcut:{key:";",modifiers:[o.KeyModifiers.Alt]}},So),new o.SimpleCommand("traverseSelectionPreviousRange",e,{label:"Traverse Previous Range",description:"Traverse the selection to the previous range.",shortcut:{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Qt),new o.SimpleCommand("traverseSelectionNextRange",e,{label:"Traverse Next Range",description:"Traverse the selection to the next range.",shortcut:{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Ro),new o.SimpleCommand("traverseSelectionCorners",e,{label:"Traverse Corners",description:"Traverse the selection through the corners of the selected range.",shortcut:{key:".",modifiers:[o.KeyModifiers.Ctrl]}},Eo)]},[]);return l.useMemo(()=>{r?.addCommands(Et,!0)},[r]),{selection:tt,setSelectionCell:Ye,setSelectionRanges:lt,overlay:gt,cursor:Ht,onPointerDown:xo,clearLastSelection:le,newSelection:pt,modifySelection:it,appendSelection:Ce,clearSelections:Bt,isEntire:et,navigate:Ze,navigateSelection:Ot}};
11
+ }`,we=document.createElement("style");return we.appendChild(document.createTextNode(X)),document.head.appendChild(we),we.sheet.insertRule(X,0),()=>{document.head.removeChild(we)}},[B]),B&&(U={strokeDasharray:`${re.dashLength}px ${re.dashGap}px`,strokeDashoffset:`${_}px`,animation:`${Z} ${ee}ms linear infinite`,willChange:"stroke-dashoffset"}),Q.jsx(en,{x:c,y:d,width:f,height:a,stroke:r,fill:i,shapeRendering:"crispEdges",style:{...U,...s},...D})});function tn(t){var r,i,c="";if(typeof t=="string"||typeof t=="number")c+=t;else if(typeof t=="object")if(Array.isArray(t)){var d=t.length;for(r=0;r<d;r++)t[r]&&(i=tn(t[r]))&&(c&&(c+=" "),c+=i)}else for(i in t)t[i]&&(c&&(c+=" "),c+=i);return c}function Vt(){for(var t,r,i=0,c="",d=arguments.length;i<d;i++)(t=arguments[i])&&(r=tn(t))&&(c&&(c+=" "),c+=r);return c}Oo.displayName="Selection";const Uo=l.memo(l.forwardRef((t,r)=>{const{x:i=0,y:c=0,borderWidth:d=1,size:f=6,borderStroke:a,corner:s,style:p,className:O,background:T,...M}=t;if(i===0||c===0)return null;let D=!0,B=!0,re=!0,_=!0;switch(s){case"tl":D=!1,B=!1;break;case"bl":D=!1,_=!1;break;case"br":re=!1,_=!1;break;case"tr":B=!1,re=!1}return Q.jsx("div",{className:Vt("fill-handle",O),style:{position:"absolute",left:i-(f+(D?d:0))/2,top:c-(f+(B?d:0))/2,width:f,height:f,borderLeft:D?`${d}px ${a}`:void 0,borderTop:B?`${d}px ${a}`:void 0,borderRight:re?`${d}px ${a}`:void 0,borderBottom:_?`${d}px ${a}`:void 0,background:T,cursor:"crosshair",pointerEvents:"all",transitionDuration:"0ms",transitionTimingFunction:"linear",transitionDelay:"0",transitionProperty:"left, top",willChange:"left, top",...p},tabIndex:-1,...M})}));function ko(t,r){if(typeof t=="function")return t(r);t&&(t.current=r)}Uo.displayName="FillHandle";var yn=parseInt(l.version.split(".")[0],10)>=19?function(t){return r=>{const i=[];for(const c of t){const d=ko(c,r),f=typeof d=="function";i.push(f?d:()=>ko(c,null))}return()=>{for(const c of i)c()}}}:function(t){return r=>{for(const i of t)ko(i,r)}};const Rn=o.ReactUtils.detectIt().supportsTouchEvents,fo=l.memo(l.forwardRef((t,r)=>{const{range:i,view:c,anchor:d,borderStroke:f="var(--sxl-app-color-primary, rgb(33, 115, 70))",background:a="var(--sxl-app-color-background, white)",borderWidth:s=3,size:p=22,style:O,className:T,selectionTouchPointerHandler:M,onTouchSelectStart:D,onTouchSelectEnd:B,currentTouchAnchor:re,scrollableElement:_,scrollableRoot:ee,...Me}=t;if(!Rn)return null;const Z=o.useCallbackRef(D,[D]),U=o.useCallbackRef(B,[B]),{bounds:X,coordsPivot:we,key:K}=l.useMemo(()=>{if(!i||!c)return null;let me=null,q=null;switch(d){case"tl":me={colIndex:i.colEnd,rowIndex:i.rowEnd},q={colIndex:i.colStart,rowIndex:i.rowStart};break;case"br":me={colIndex:i.colStart,rowIndex:i.rowStart},q={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"t":case"l":me={colIndex:i.colEnd,rowIndex:i.rowEnd};break;case"b":me={colIndex:i.colStart,rowIndex:i.rowStart};break;case"r":me={colIndex:i.colStart,rowIndex:i.rowEnd}}let L=c.getRangeCoordsBounds(q?{rowStart:q.rowIndex,colStart:q.colIndex,rowEnd:q.rowIndex,colEnd:q.colIndex}:i);const j=c.getBounds(),St=c.getViewportSize(),xt=j.x,ct=j.y,rt=St.width,se=St.height;switch(d){case"tl":break;case"br":L.x=L.x+L.width,L.y=L.y+L.height;break;case"t":L.x=rt/2-xt;break;case"b":L.x=rt/2-xt,L.y=L.y+L.height;break;case"l":L.y=se/2-ct;break;case"r":L.x=L.x+L.width,L.y=se/2-ct}const Pt=c.toClipBounds(L,0);return!Pt||Pt.width<=0||Pt.height<=0||L.x<0||L.y<0||L.x>rt||L.y>se?{bounds:null,coordsAnchor:null,coordsPivot:null,key:null}:{bounds:L,coordsAnchor:null,coordsPivot:me,key:"touchSelect-"+c.getAnchor()+"-"+d}},[i,c,d]),ge=l.useRef(null),Le=l.useMemo(()=>{const me=q=>d==="t"||d==="b"?{...q,colIndex:void 0}:d==="l"||d==="r"?{...q,rowIndex:void 0}:q;return{processTouch:!0,consumeTouch:!0,onPointerDown:(q,L)=>{const j=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return ge.current={coordsPivot:we},Z?.(d),M.onSelectionPointerDown(q,L,c,j,we,!1,!0)},onPointerMoveOrWait:(q,L,j)=>{const St=me(c.getCellCoordsFromClient(q.clientX,q.clientY));return M.onSelectionPointerMoveOrWait(q,L,j,c,St,ge.current?.coordsPivot,!0,!0)},onPointerUp:(q,L,j)=>(ge.current=null,U?.(d),M.onPointerUp(q,L,j))}},[M,i,c,d]),ye=o.useSynchronizedPointerHandler(Le),[Oe,{y:ce,x:pe}]=o.useAnimatedMeasure(),A=l.useRef(null),{getPortalContainer:C,isFullscreen:$e}=o.useFullscreenPortal(),[Ve,G]=l.useState(null);return l.useEffect(()=>{const me=A.current?.getBoundingClientRect();if(!me||!X)return void G(null);let q=0,L=0,j=_;for(;j;)q+=j.scrollLeft,L+=j.scrollTop,j=ee&&j===ee.parentElement?null:j.parentElement;G(Zo.createPortal(Q.jsx("div",{className:Vt("touch-select-handle",T),ref:r,style:{position:"absolute",left:q+(me?.x??0)-(p+s)/2,top:L+(me?.y??0)-(p+s)/2,width:p,height:p,borderWidth:`${s}px`,border:f,borderRadius:"50%",background:a,boxShadow:`0 0 0 1.5px ${a}`,cursor:"grab",pointerEvents:"all",opacity:re?0:1,transitionDuration:"160ms",transitionProperty:"opacity",...O},tabIndex:-1,onPointerDown:ye,...Me}),ee??C(),K))},[ce,pe,X?.x,X?.y,X?.width,X?.height,T,re,a,p,s,f,_,$e]),X?Q.jsxs(Q.Fragment,{children:[Q.jsx("div",{ref:yn([Oe,A]),style:{position:"absolute",left:X.x,top:X.y,opacity:0}}),Ve]}):null}));fo.displayName="TouchSelectHandle";const It=-10,En=Object.freeze({rowStart:0,colStart:0,rowEnd:0,colEnd:0}),on=Object.freeze({colIndex:0,rowIndex:0}),To=Object.freeze([]),yt=t=>{if(t&&t.cell&&t.ranges&&t.rangeIndex>-1&&t.rangeIndex<=t.ranges.length)return t;const r={cell:null,ranges:t?.ranges??To};return r.rangeIndex=t?.rangeIndex??r.ranges.length-1,r.cell=t?.cell,!r.cell&&r.ranges.length>0&&(r.cell={rowIndex:r.ranges[r.rangeIndex].rowStart,colIndex:r.ranges[r.rangeIndex].colStart}),r.cell||(r.cell=on),n.CoordUtils.isEqualSelectionCoords(r,t)?t:r},ho=(t,r,i)=>{const c=t.getVisibleRangeCoords(),d=t.getScrollOrientation();!d.horizontal&&(r.colIndex>c.colEnd||r.colIndex<c.colStart)&&(r={...r,colIndex:r.colIndex>c.colEnd?c.colEnd+1:c.colEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),!d.vertical&&(r.rowIndex>c.rowEnd||r.rowIndex<c.rowStart)&&(r={...r,rowIndex:r.rowIndex>c.rowEnd?c.rowEnd+1:c.rowEnd-1},t=i.current.getViewFromLocation(n.AnchorLocation.Center)),t.scrollCellCoordsIntoView(r)},In=()=>!1;function go(t,r){if(!t)throw new Error("Invariant failed")}const Yo={"sheetxl-grid":"_sheetxl-grid_h9wwa_7"},kn=Object.freeze({top:0,left:0}),Mn=Object.freeze({bottom:-4,right:-4}),Dn=Object.freeze({horizontal:!0,vertical:!0}),Xo=[n.AnchorLocation.TopLeft,n.AnchorLocation.Top,n.AnchorLocation.Left,n.AnchorLocation.Center],zt=3e3,Mo={},zo=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,rowCount:d=1,columnCount:f=1,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O,layout:T,onViewportScroll:M,onImmediateScroll:D,showGridLines:B=!0,gridLineColor:re="rgb(224, 224, 224)",gridLineRowsProps:_,gridLineColumnsProps:ee,clipCells:Me=!0,cursor:Z,freezeLeft:U=0,freezeTop:X=0,freezeLeftProps:we,freezeTopProps:K,cellRenderer:ge,onViewportChange:Le,onFirstRender:ye,overlayRenderer:Oe,overlayProps:ce,overlays:pe,overlaysProps:A,allowOverlaysOverflow:C=!1,stageProps:$e,stageWrapper:Ve=null,hiddenRowsAt:G,hiddenColumnsAt:me,hiddenCellAt:q,getVisibleCells:L,zoom:j=1,enableMouseWheel:St=!0,onWheelScroll:xt,getCellCoordsAsRangeCoords:ct=n.CoordUtils.cellToRange,scrollPoint:rt=kn,style:se={},...Pt}=t;go(ge),go(!t?.children);const P=o.useCallbackRef(D,[D]),R=o.useCallbackRef(Le,[Le]),be=o.useCallbackRef(M,[M]),te=o.useCallbackRef(xt,[xt]),ue=o.useCallbackRef(ye,[ye]),ze=l.useRef(null),Je=l.useRef(null),mt=l.useRef(null),[Qe,Tt]=l.useReducer(w=>w+1,0),[st,b]=l.useState({left:rt?.left??0,top:rt?.top??0,horizontalScrollDirection:null,verticalScrollDirection:null}),oe=l.useRef(null),Ae=l.useRef(st),{top:lt,left:qe,verticalScrollDirection:Ht,horizontalScrollDirection:$t}=st,bt=l.useRef(!1),Xt=Qo({rowCount:d,columnCount:f,defaultRowHeight:a,defaultColumnWidth:s,getRowHeight:p,getColumnWidth:O}),At=l.useRef(null),Re=l.useMemo(()=>{const w=T||Xt;return At.current=null,{getColOffset:S=>w.getColOffset(S)*j,getColIndex:S=>w.getColIndex(S/j),getRowOffset:S=>w.getRowOffset(S)*j,getRowIndex:S=>w.getRowIndex(S/j)}},[Xt,T,j]),Ut=(w,S,E)=>{const v=(S?.left??0)+0,y=(S?.top??0)+0;return{getColOffset:z=>w.getColOffset(z)-v,getColIndex:z=>w.getColIndex(z+v),getRowOffset:z=>w.getRowOffset(z)-y,getRowIndex:z=>w.getRowIndex(z+y)}},ut=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getRowOffset,S?0:d),[d,Re?.getRowOffset]),kt=o.useCallbackRef(G??ut,[G]),eo=o.useCallbackRef((w,S=!1)=>wo(w,S,Re.getColOffset,S?f:0),[f,Re?.getColOffset]),jt=o.useCallbackRef(me??eo,[me]),He=l.useMemo(()=>Math.min(i??800,Re.getColOffset(f)),[Re.getColOffset,f,i]),Be=l.useMemo(()=>Math.min(c??600,Re.getRowOffset(d)),[Re.getRowOffset,d,c]),Ft=l.useCallback(w=>{n.CommonUtils.canUseDOM&&setTimeout(()=>{ze.current?.focus({preventScroll:!0,...w})},0)},[]),ht=l.useCallback(w=>ze.current?.contains(w)||Je.current?.contains(w),[]);l.useEffect(()=>{bt.current&&(oe.current&&oe.current.left!==Ae.current?.left&&oe.current.top!==Ae.current?.top||(oe.current=null,be?.({left:qe,top:lt})))},[qe,lt]);const Lt=o.useCallbackRef(()=>({top:lt,left:qe}),[lt,qe]),ve=l.useMemo(()=>{const w=[];let S=0,E=0;typeof X=="number"?S=X:(S=X.index??0,E=(X.scrollOffset??0)*j);const v=E,y=Re.getRowOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{top:E+Re.getRowOffset(0)}),Pe=Re.getRowIndex(v),Ne=Re.getRowIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(kt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,Be-z),ne=Ut(Re,{top:lt+z}),ae=ne.getRowIndex(0),F=ne.getRowIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:d-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(kt,ae,F)),Se),layout:ne,maxVirtualBounds:Re.getRowOffset(d),scrollOffset:lt,freezeOffset:(S>0?Re.getRowOffset(S):0)-E},w},[Re.getRowIndex,Re.getRowOffset,kt,Be,d,X,lt,j]),je=l.useMemo(()=>{const w=[];let S=0,E=0;typeof U=="number"?S=U:(S=U.index??0,E=(U.scrollOffset??0)*j);const v=E,y=Re.getColOffset(S),z=y-v;if(S>0){const Ke=Ut(Re,{left:E+Re.getColOffset(0)}),Pe=Re.getColIndex(v),Ne=Re.getColIndex(y-1);let Ee;w[1]={minIndex:Pe,maxIndex:Ne,minCoord:0,maxCoord:S-1,minBounds:0,maxBounds:z,visibleIndices:()=>Ee||(Ee=Object.freeze(uo(jt,Pe,Ne)),Ee),layout:Ke,maxVirtualBounds:y,scrollOffset:E,freezeOffset:E}}const he=Math.max(0,He-z),ne=Ut(Re,{left:qe+z}),ae=ne.getColIndex(0),F=ne.getColIndex(he);let Se;return w[0]={minIndex:ae,maxIndex:F,minCoord:S,maxCoord:f-1,minBounds:z,maxBounds:he,visibleIndices:()=>Se||(Se=Object.freeze(uo(jt,ae,F)),Se),layout:ne,maxVirtualBounds:Re.getColOffset(f),scrollOffset:qe,freezeOffset:(S>0?Re.getColOffset(S):0)-E},w},[Re.getColIndex,Re.getColOffset,jt,He,f,U,qe,j]),it=l.useRef({}),pt=l.useRef([]),Ce=l.useMemo(()=>{let w={};const S=(v,y,z,he,ne)=>{const ae={vertical:he?.vertical||!1,horizontal:he?.horizontal||!1};if(v>=je.length||y>=ve.length)return null;const F={rowStart:ve[y].minIndex,colStart:je[v].minIndex,rowEnd:ve[y].maxIndex,colEnd:je[v].maxIndex};if(F.rowStart>F.rowEnd||F.colStart>F.colEnd)return null;const Se={getColIndex:J=>je[v].layout.getColIndex(J),getColOffset:J=>je[v].layout.getColOffset(J),getRowIndex:J=>ve[y].layout.getRowIndex(J),getRowOffset:J=>ve[y].layout.getRowOffset(J)},Ke=Object.freeze({left:ne?.left??0,top:ne?.top??0,right:ne?.right??0,bottom:ne?.bottom??0}),Pe=Object.freeze({x:je[v].minBounds,y:ve[y].minBounds,width:je[v].maxBounds,height:ve[y].maxBounds}),Ne=(J,We)=>No(Se,J??F,We),Ee={width:je[v].maxVirtualBounds,height:ve[y].maxVirtualBounds},le={left:je[v].scrollOffset,top:ve[y].scrollOffset},et={left:je[v].freezeOffset,top:ve[y].freezeOffset},Ye={width:He,height:Be};let Ue=null,Xe=null;const ft=(et.top+(he.vertical?le.top:0))/j,Fe=(et.left+(he.horizontal?le.left:0))/j;return{getStage:()=>ze.current??null,getVisibleRangeCoords:()=>F,toClipBounds:(J,We)=>{let at,Ie=0;return We===void 0||typeof We=="number"?(at=Ne(F),Ie=We):at=We,((Ge,De,ke=0)=>{if(Ge.x>De.width||Ge.y>De.height)return null;const dt={left:Ge.x,top:Ge.y,bottom:Ge.height+Ge.y,right:Ge.width+Ge.x},tt={left:De.x+ke,top:De.y+ke,bottom:De.height-2*ke+De.y,right:De.width-2*ke+De.x},gt={left:Math.max(dt.left,tt.left),top:Math.max(dt.top,tt.top),bottom:Math.min(dt.bottom,tt.bottom),right:Math.min(dt.right,tt.right)},Et={x:gt.left,y:gt.top,width:gt.right-gt.left,height:gt.bottom-gt.top};return Et.height<0||Et.width<0?null:Et})(J??{x:0,y:0,width:Pe.width,height:Pe.height},at,Ie)},toViewBounds:J=>Fe===0&&ft===0&&j===1?J:{x:(J.x-Fe)*j,y:(J.y-ft)*j,width:J.width*j,height:J.height*j},toAbsoluteBounds:J=>Fe===0&&ft===0&&j===1?J:{x:J.x/j+Fe,y:J.y/j+ft,width:J.width/j,height:J.height/j},getRelativePointFromClient:(J,We)=>{const at=Nt(J,We);return{x:at.x-Pe.x,y:at.y-Pe.y}},getLayout:()=>Se,getCellCoordsAsRangeCoords:ct,getVisibleColumns:()=>je[v].visibleIndices(),getVisibleRows:()=>ve[y].visibleIndices(),getVisibleColumnOffsets:()=>(Ue||(Ue=jo(je[v].layout,!0,je[v].visibleIndices(),F.colStart,F.colEnd)),Ue),getVisibleRowOffsets:()=>(Xe||(Xe=jo(ve[y].layout,!1,ve[y].visibleIndices(),F.rowStart,F.rowEnd)),Xe),getTotalRangeCoords:()=>({colStart:je[v].minCoord,colEnd:je[v].maxCoord,rowStart:ve[y].minCoord,rowEnd:ve[y].maxCoord}),getRangeCoordsBounds:Ne,scrollCellCoordsIntoView:(J,We)=>Gt(J,We,z),getCellCoordsFromClient:(J,We,at=!1)=>{const Ie=Nt(J,We);if(!Ie)return null;const Ge=Se.getColIndex(Ie.x-Pe.x),De={rowIndex:Se.getRowIndex(Ie.y-Pe.y),colIndex:Ge};if(at)return De;const ke=ct(De);return{rowIndex:ke.rowStart,colIndex:ke.colStart}},getZoom:()=>j,getAnchor:()=>z,getBounds:()=>Pe,getInsets:()=>Ke,getTotalSize:()=>Ee,getViewportSize:()=>Ye,getScrollTopLeft:()=>le,getFreezeTopLeft:()=>et,getScrollOrientation:()=>ae,allViews:()=>w}};let E=w[n.AnchorLocation.Center]=S(0,0,n.AnchorLocation.Center,Dn,Mn);return E&&(w[n.AnchorLocation.Center]=E),E=S(0,1,n.AnchorLocation.Top,{horizontal:!0}),E&&(w[n.AnchorLocation.Top]=E),E=S(1,0,n.AnchorLocation.Left,{vertical:!0}),E&&(w[n.AnchorLocation.Left]=E),E=S(1,1,n.AnchorLocation.TopLeft,{}),E&&(w[n.AnchorLocation.TopLeft]=E),it.current=null,w=Object.freeze(w)},[ve,je,ct]),Bt=Object.keys(Ce),Rt=je[0]?.maxVirtualBounds??0,_e=ve[0]?.maxVirtualBounds??0,Ct=l.useMemo(()=>({left:je[1]?je[1].layout.getColOffset(je[1].maxIndex+1):0,top:ve[1]?ve[1].layout.getRowOffset(ve[1].maxIndex+1):0}),[Ce]);l.useEffect(()=>{if(pt.current.length>0){for(let w=0;w<pt.current.length;w++)pt.current[w]();pt.current=[]}},[Ce]);const vt=o.useCallbackRef(()=>({containerWidth:He,containerHeight:Be,totalWidth:Rt,totalHeight:_e}),[He,Be,Re]);l.useEffect(()=>{!oe.current&&bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[lt,qe,Rt,_e]),l.useEffect(()=>{bt.current&&R({top:lt,left:qe,width:He,height:Be,totalWidth:Rt,totalHeight:_e})},[He,Be]);const Nt=l.useCallback((w,S)=>{go(typeof w=="number"&&typeof S=="number");const E=ze.current?.getBoundingClientRect();return E?{x:w-E.x,y:S-E.y}:{x:w,y:S}},[]),xo=o.useCallbackRef(w=>Ce[w]||null,[Ce]),po=o.useCallbackRef((w,S)=>{if(Object.keys(Ce).length===1)return Ce[n.AnchorLocation.Center];const E=Nt(w,S);if(!E)return null;const{x:v,y}=E;let z=null;const he=Xo,ne=he.length;for(let ae=0;!z&&ae<ne;ae++){const F=Ce[he[ae]];F&&vn(v,y,F.getBounds())&&(z=F)}return z||(z=Ce[n.AnchorLocation.Center]),z},[Ce,ct]),Ze=o.useCallbackRef(()=>Ce[n.AnchorLocation.Center].getVisibleRangeCoords(),[Ce[n.AnchorLocation.Center]]),Ot=l.useRef(null),mo=l.useCallback(()=>{Ot.current!==null&&n.CommonUtils.cancelTimeout(Ot.current),Ot.current=n.CommonUtils.requestTimeout(Co,150)},[]),Co=l.useCallback(()=>{Ot.current=null,b(w=>{const S={...w,verticalScrollDirection:null,horizontalScrollDirection:null};return Ae.current=S,S})},[]),Kt=o.useCallbackRef(w=>{const S=w?.left??w?.[0],E=w?.top??w?.[1];let v=Ae.current.left;S!==void 0&&S!==v&&(S>v?(v=Math.max(je?.[1]?.scrollOffset??0,S),v=Math.min(Rt-He,v)):v=Math.max(je?.[1]?.scrollOffset??0,S));let y=Ae.current.top;if(E!==void 0&&E!==y&&(E>y?(y=Math.max(ve?.[1]?.scrollOffset??0,E),y=Math.min(_e-Be,y)):y=Math.max(ve?.[1]?.scrollOffset??0,E)),Ae.current.left===v&&Ae.current.top===y)return;let z=null,he=null;Ae.current.left>v?z=n.Direction.Left:Ae.current.left<v&&(z=n.Direction.Right),Ae.current.top>y?he=n.Direction.Up:Ae.current.top<y&&(he=n.Direction.Down),n.CommonUtils.throttle(()=>{b(ne=>{const ae={...ne,left:v,top:y,horizontalScrollDirection:z,verticalScrollDirection:he};return Ae.current=ae,ae})},17)(),oe.current?.top===y&&oe.current?.left===v||(oe.current={left:v,top:y},P({left:v,top:y}),R({left:v,top:y,width:He,height:Be,totalWidth:Rt,totalHeight:_e})),mo()},[Rt,_e,ve,je]);l.useEffect(()=>{oe.current||Kt({left:qe,top:lt})},[He,Be]),l.useEffect(()=>{let w,S,E=!1;Ae.current.left>Rt&&(w=0,E=!0),Ae.current.top>_e&&(S=0,E=!0),E&&Kt({left:w,top:S})},[Rt,_e]),l.useLayoutEffect(()=>{oe.current={left:rt?.left,top:rt?.top},Kt(oe.current)},[rt?.left,rt?.top]);const to=o.useCallbackRef(w=>{let S=w?.left??w?.[0],E=w?.top??w?.[1];if(S===void 0&&E===void 0)return;const v=w?.behavior??"auto";S!==void 0&&(S=Ae.current.left+(S??0)),E!==void 0&&(E=Ae.current.top+(E??0)),!(Ae.current.left===S&&Ae.current.top===E)&&Kt({left:S,top:E,behavior:v})},[]),oo=l.useCallback(w=>{let S=null;if(Object.keys(Ce).length>1){const E=Xo,v=E.length;for(let y=0;!S&&y<v;y++){const z=Ce[E[y]];z&&n.CoordUtils.isCellWithinRange(w,z.getVisibleRangeCoords())&&(S=z)}}return S||(S=Ce[n.AnchorLocation.Center]),S},[Ce]),Gt=o.useCallbackRef((w,S={inline:"nearest",block:"nearest"},E=null)=>{const v={rowIndex:0,colIndex:0,...w};let y=null;if(E!==null){if(y=Ce[E],y===null)return new Promise((Ye,Ue)=>{Ue("Invalid view")})}else y=oo(v);const z=ct(v),he=y.getLayout(),ne=he.getColOffset(z.colStart),ae=he.getRowOffset(z.rowStart),F=he.getColOffset(z.colEnd+1),Se=he.getRowOffset(z.rowEnd+1),Ke=y.getBounds(),Pe=y.getTotalSize(),Ne=y.getScrollTopLeft(),Ee=((Ye,Ue,Xe=!0)=>{Xe=Xe===!0?{block:"start",inline:"end"}:Xe===!1?{block:"end",inline:"end"}:{block:"end",inline:"end",...Xe};const ft=Wo(Xe.inline,Ye.x,Ye.x+Ye.width,Ue.left,Ue.left+Ue.width,Ue.totalWidth),Fe=Wo(Xe.block,Ye.y,Ye.y+Ye.height,Ue.top,Ue.top+Ue.height,Ue.totalHeight);if(ft!==void 0||Fe!==void 0)return{left:ft,top:Fe}})({x:ne+Ne.left,y:ae+Ne.top,width:F-ne,height:Se-ae},{left:Ne.left,top:Ne.top,width:Ke.width,height:Ke.height,totalWidth:Pe.width,totalHeight:Pe.height},S);if(!Ee)return Promise.resolve({...Ne});const le={...Ee};le.left>qe?le.left+=20:le.left<qe&&(le.left-=0),le.top>lt?le.top+=20:le.top<lt&&(le.top-=0);const et=y.getScrollOrientation();return et.horizontal&&w.colIndex!==void 0||delete le.left,et.vertical&&w.rowIndex!==void 0||delete le.top,new Promise((Ye,Ue)=>{try{Kt(le),Ye(le)}catch(Xe){Ue(Xe)}})},[Rt,_e,Ce,ct]),qt=o.useCallbackRef(w=>{const S=w.shiftKey;w.preventDefault();const{deltaX:E,deltaY:v,deltaMode:y}=w;if(mt.current||te?.(w)===!1)return;let he=S?v:E,ne=v;const ae=S||Math.abs(he)>Math.abs(ne);y===1&&(ne*=0),mt.current=window.requestAnimationFrame(()=>{mt.current=null,to(ae?{left:he}:{top:ne})})},[te]),_t=l.useCallback((w=null)=>{At.current=null,it.current=null,Tt()},[]);l.useLayoutEffect(()=>{_t()},[ge]);const Wt=o.useImperativeElement(r,()=>({stage:ze.current,focus:Ft,contains:ht,invalidate:_t,scrollTo:Kt,scrollBy:to,scrollCellCoordsIntoView:Gt,getScrollPosition:Lt,getDimensions:vt,getViewport:Ze,handleWheel:qt,rowCount:d,columnCount:f,getLayout:()=>Re,getRelativePointFromClient:Nt,getViewFromClient:po,getViewFromCellCoords:oo,getViewFromLocation:xo,onViewChangeOnce:w=>{pt.current.push(w)}}),[d,f,Ce]);l.useEffect(()=>(St&&Wt.current?.addEventListener("wheel",qt,{passive:!1}),bt.current=!0,oe.current=null,()=>{Wt.current?.removeEventListener("wheel",qt)}),[St]);const Zt=l.useRef([]),So=(w,S)=>{!w||!Oe||(Zt.current=[],S.push(((E,v)=>{const y=`view:${E.getAnchor()}:overlay:${S.length}`,z=Oe?.({key:y,view:E},ne=>Zt.current[v]=ne);if(!z)return null;const he=E.getBounds();return Q.jsx("div",{style:{position:"absolute",left:"0px",top:"0px",width:`${he.width}px`,height:`${he.height}px`,overflow:"hidden"},children:z},`overlay-${E.getAnchor()}-${v}`)})(w,0)))},bo=l.useMemo(()=>{const w={},S=Object.keys(Ce),E=S.length;for(let v=0;v<E;v++){const y=S[v],z=[];So(Ce[y],z),w[y]={overlays:z}}return w},[Qe,Oe,d,f,ve,je]),no=(w,S,E,v,y,z,he)=>{if(!w)return;const ne=w.getVisibleColumns(),ae=w.getVisibleRows();if(ne.length===0||ae.length===0)return;let F=null;if(L)F=L(w);else{F=[];const Ie=ae.length,Ge=ne.length;for(let De=0;De<Ie;De++){const ke=ae[De];for(let dt=0;dt<Ge;dt++){const tt={rowIndex:ke,colIndex:ne[dt]};if(q?.(tt))continue;const gt={coords:tt,range:ct(tt)};F.push(gt)}}}const Se=w.getVisibleColumnOffsets(),Ke=w.getVisibleRowOffsets(),Pe=w.getScrollTopLeft(),Ne=w.getFreezeTopLeft(),Ee=Pe.left+Ne.left,le=Pe.top+Ne.top,et=Math.trunc(Ee/zt),Ye=Math.trunc(le/zt),Ue={},Xe=(Ie,Ge,De,ke,dt)=>{const tt=`view:${Ie.getAnchor()}:cell:${Fo(Ge.rowIndex,Ge.colIndex)}`,gt=ke.x,Et=ke.y,e=Math.trunc((Ee+gt)/zt)-et,u=Math.trunc((le+Et)/zt)-Ye;Ue[u]||(Ue[u]={});let g=Ue[u][e];g||(g=Ue[u][e]=[]);let h=z?.get(tt);if(!h){const x=(Ee+gt)%zt,k=(le+Et)%zt;h=ge({key:tt,coords:Ge,bounds:ke,zoom:j,range:De,view:Ie,value:dt,style:{left:o.ReactUtils.boundPixel(x),top:o.ReactUtils.boundPixel(k),width:o.ReactUtils.boundPixel(ke.width,!0),height:o.ReactUtils.boundPixel(ke.height,!0)}})}he?.set(tt,h),g.push(h)},ft=F.length;for(let Ie=0;F&&Ie<ft;Ie++){const Ge=F[Ie],De=Ge?.coords??Ge;if(!De)continue;const ke=Ge?.range??{rowStart:De.rowIndex,colStart:De.colIndex,rowEnd:De.rowIndex,colEnd:De.colIndex},dt=w.getVisibleRangeCoords();if(!n.CoordUtils.isRangesIntersect(ke,dt)&&!n.CoordUtils.isRangeWithinRange(ke,dt))continue;const tt=ke&&!n.CoordUtils.isSingleCell(ke);if(!tt&&q?.(De))continue;const gt=De.rowIndex,Et=De.colIndex,e=Ke[gt],u=Se[Et];let g=null;e&&u&&(g={x:u.offset,y:e.offset,width:u.size,height:e.size});const h=Fo(ke.rowStart,ke.colStart);if(tt){if(y.has(h))continue;y.add(h),ke.rowEnd-ke.rowStart>0&&E.push(ke),ke.colEnd-ke.colStart>0&&v.push(ke)}if(tt&&(g=No(w.getLayout(),ke)),!g){console.warn("no bounds for cell",h);continue}const x=Ge?.value;Xe(w,De,ke,g,x)}const Fe=Ee%zt,J=le%zt,We=Object.keys(Ue),at=We.length;for(let Ie=0;Ie<at;Ie++){const Ge=We[Ie],De=Ue[Ge];if(!De)continue;const ke=Object.keys(De),dt=ke.length;for(let tt=0;tt<dt;tt++){const gt=ke[tt],Et=De[gt];if(!Et)continue;const e=parseInt(Ge),u=parseInt(gt),g=e+Ye,h=u+et,x=`view:${w.getAnchor()}:segment:${h}:${g}`;S.push(Q.jsx("div",{className:"cell-container",style:{transform:`translate(${o.ReactUtils.boundPixel(u*zt-Fe,!0)}px, ${o.ReactUtils.boundPixel(e*zt-J,!0)}px)`,willChange:"transform"},children:Et},x))}}},Mt=l.useMemo(()=>{const w=At.current,S=new Map,E={},v=Object.keys(Ce),y=v.length;for(let z=0;z<y;z++){const he=v[z],ne=[],ae=[],F=[];no(Ce[he],F,ne,ae,new Set,w,S),E[he]={cells:F,rangesH:ne,rangesV:ae}}return At.current=S,E},[Qe,d,f,ve,je,B,se,Me,q,L,me,G,ct]),ro=(w,S,E,v,y)=>{if(!w)return;const z=w.getLayout(),he=window.devicePixelRatio||1,ne=String(1/he);if(S){const ae=`view:${w.getAnchor()}:hl:`,F=w.getVisibleRows();if((F?F.length:0)===0)return;const Se=y.sort(n.CoordUtils.rowFirstRangeComparator),Ke=w.getVisibleRangeCoords(),Pe=0,Ne=Math.min(w.getBounds().width,z.getColOffset(Ke.colEnd+1));let Ee=[];for(let le=0;le<F.length&&F[le]<=Ke.rowEnd;le++){const et=F[le];if(et<Ke.rowStart)continue;let Ye=!1;for(;Se.length>0&&Se[0].rowStart<=et;){const Fe=Se.shift();Fe.rowEnd>et&&(Ee.push(Fe),Ye=!0)}Ye&&(Ee=Ee.sort(n.CoordUtils.columnFirstRangeComparator));const Ue=z.getRowOffset(et+1);let Xe=Pe;const ft=Ee.length;for(let Fe=0;Fe<ft+1;Fe++){let J=Xe,We=Ne;const at=Ee[Fe];Fe<ft&&(We=Math.min(Ne,z.getColOffset(at.colStart)),Xe=Math.min(Ne,z.getColOffset(at.colEnd+1))),v.push(l.createElement("path",{d:`M ${o.ReactUtils.boundPixel(J)} ${o.ReactUtils.boundPixel(Ue,!1,E)} L ${o.ReactUtils.boundPixel(We)} ${o.ReactUtils.boundPixel(Ue,!1,E)}`,stroke:re,strokeWidth:ne,vectorEffect:"non-scaling-stroke",..._,key:ae+et+":"+Fe}))}for(let Fe=ft-1;Fe>=0;Fe--)Ee[Fe].rowEnd<=F[le+1]&&Ee.splice(Fe,1)}}else{const ae=`view:${w.getAnchor()}:vl:`,F=w.getVisibleColumns(),Se=F?F.length:0;if(Se===0)return;const Ke=y.sort(n.CoordUtils.columnFirstRangeComparator),Pe=w.getVisibleRangeCoords(),Ne=0,Ee=Math.min(w.getBounds().height,z.getRowOffset(Pe.rowEnd+1));let le=[];for(let et=0;et<Se&&F[et]<=Pe.colEnd;et++){const Ye=F[et];if(Ye<Pe.colStart)continue;let Ue=!1;for(;Ke.length>0&&Ke[0].colStart<=Ye;){const J=Ke.shift();J.colEnd>Ye&&(le.push(J),Ue=!0)}Ue&&(le=le.sort(n.CoordUtils.rowFirstRangeComparator));const Xe=z.getColOffset(Ye+1);let ft=Ne;const Fe=le.length;for(let J=0;J<Fe+1;J++){let We=ft,at=Ee;const Ie=le[J];J<Fe&&(at=Math.min(Ee,z.getRowOffset(Ie.rowStart)),ft=Math.min(Ee,z.getRowOffset(Ie.rowEnd+1))),v.push(Q.jsx("path",{d:`M ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(We)} L ${o.ReactUtils.boundPixel(Xe,!1,E)} ${o.ReactUtils.boundPixel(at)}`,stroke:re,strokeWidth:ne,vectorEffect:"non-scaling-stroke",...ee},ae+Ye+":"+J))}for(let J=Fe-1;J>=0;J--)le[J].colEnd<=F[et+1]&&le.splice(J,1)}}},Jt=w=>{if(!Mt)return;const S={},E=Bt.length;for(let v=0;v<E;v++){const y=Bt[v],z=Ce[y],he=[];ro(z,w,0,he,w?Mt[y].rangesH:Mt[y].rangesV);const ne=z.getRangeCoordsBounds(),ae=Math.ceil(ne.width),F=Math.ceil(ne.height);S[y]=Q.jsx("svg",{width:`${ae}`,height:`${F}`,viewBox:`0 0 ${ae} ${F}`,preserveAspectRatio:"none",shapeRendering:"crispEdges",style:{position:"absolute"},children:he})}return S},lo=l.useMemo(()=>B===!0||B?.horizontal===!0?Jt(!0):null,[Qe,B,ve,X,U,re,_,d,f,He,Rt,Ce,Mt]),io=l.useMemo(()=>B===!0||B?.vertical===!0?Jt(!1):null,[Qe,B,je,X,U,re,ee,d,f,Be,_e,Ce,Mt]),vo=l.useMemo(()=>Ct.left===0?null:Q.jsx(Po,{linePoints:[0,0,0,Be+1],bounds:{x:Ct.left,y:0,width:1,height:Be+1},...we}),[Qe,Ct.left,Be,we]),yo=l.useMemo(()=>Ct.top===0?null:Q.jsx(Po,{linePoints:[0,0,He+1,0],bounds:{x:0,y:Ct.top,width:He+1,height:1},...K}),[Qe,Ct.top,He,K]),Qt=l.useMemo(()=>{const w=[],S=v=>{if(!v||!Ce[v])return;const y=Ce[v].getBounds();return Q.jsxs("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:y.width,height:y.height,clip:`rect(0, ${y.width+1}px, ${y.height+1}px, 0)`},className:`view view-${v}`,children:[lo?.[v],io?.[v],Mt?.[v].cells]},`view:${v}`)},E=Bt.length;for(let v=0;v<E;v++)w.push(S(Bt[v]));return Q.jsx(Q.Fragment,{children:w})},[Ce,lo,io,Mt]),Ro=l.useMemo(()=>{if(!r)return;const w=(ne,ae,F,Se)=>{if(!Se||Se.length===0)return;const Ke=[],Pe=Se.length;for(let Ne=0;Ne<Pe;Ne++){const Ee=Se[Ne];let le=ne?.get(Ee);le!==Mo&&(le=Ee(F)??Mo),ae.set(Ee,le),le&&le!==Mo&&Ke.push(le)}return Ke},S=(ne,ae,F)=>{if(!F)return;const Se=F.getBounds(),Ke=F.getInsets(),Pe=F.getAnchor();return Q.jsxs("div",{className:Vt("view",`view-${Pe}`,Yo.view),style:{position:"absolute",pointerEvents:"none",left:Se.x-Ke.left,top:Se.y-Ke.top,width:Se.width-(Ke.left+Ke.right),height:Se.height-(Ke.top+Ke.bottom),clipPath:C?"inset(-2px)":"inset(0px)"},children:[w(ne,ae,F,pe),bo?.[Pe].overlays]},`view:${Pe}`)},E=it.current,v={},y=[],z=Object.keys(Ce),he=z.length;for(let ne=0;ne<he;ne++){const ae=z[ne],F=E?.[ae],Se=v[ae]=new Map;y.push(S(F,Se,Ce[ae]))}return it.current=v,y},[Qe,Ce,C,pe]),Eo=l.useMemo(()=>{const{style:w,...S}=$e??{};return Q.jsx("div",{style:{width:He,height:Be,...w},className:"sheetxl-stage",tabIndex:0,ref:ze,...S,...Pt,children:Ve?Ve(Qt):Qt})},[He,Be,Qt,$e,Ve]),co=l.useRef(!1);return l.useEffect(()=>{!co.current&&Mt&&(co.current=!0,ue?.(Wt.current))},[Mt]),Q.jsxs("div",{className:Vt("sheetxl-grid",Yo["sheetxl-grid"]),style:{overflow:"visible",cursor:Z,maxWidth:He,maxHeight:Be,width:He,height:Be,...se},ref:Wt,children:[Eo,Q.jsxs("div",{className:Vt("sheetxl-overlays"),ref:Je,...A,children:[Ro,vo,yo]})]})}));zo.displayName="BaseGrid";var Pn=function(){},nn=typeof window<"u",Un=nn?l.useLayoutEffect:l.useEffect,Go={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};const Tn=nn&&window.ResizeObserver!==void 0?function(){var t=l.useState(null),r=t[0],i=t[1],c=l.useState(Go),d=c[0],f=c[1],a=l.useMemo(function(){return new window.ResizeObserver(function(s){if(s[0]){var p=s[0].contentRect,O=p.x,T=p.y,M=p.width,D=p.height,B=p.top,re=p.left,_=p.bottom,ee=p.right;f({x:O,y:T,width:M,height:D,top:B,left:re,bottom:_,right:ee})}})},[]);return Un(function(){if(r)return a.observe(r),function(){a.disconnect()}},[r]),[i,d]}:function(){return[Pn,Go]},Ao=l.memo(l.forwardRef((t,r)=>{const{width:i,height:c,style:d={},className:f,...a}=t,[s,{width:p,height:O}]=Tn(),T=i??p,M=c??O;return Q.jsx("div",{className:f,style:{...d},children:Q.jsx("div",{style:{position:"relative",top:"0px",left:"0px",width:"100%",height:"100%",maxWidth:"100%",maxHeight:"100%",boxSizing:"content-box"},ref:s,children:Q.jsx(zo,{ref:r,width:T,height:M,...a})})})}));Ao.displayName="Grid";const rn=l.memo(l.forwardRef((t,r)=>{const{showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:s,onScrollViewport:p,style:O={},className:T,onScroll:M,...D}=t,[B,re]=l.useState(null),_=l.useRef(null),ee=l.useRef(null);go(!s),l.useImperativeHandle(r,()=>ee.current&&_.current?Object.assign(ee.current,_.current):null);const Me=l.useCallback(Z=>{ee.current?.scrollTo(Z),p?.(Z)},[]);return Q.jsx(o.ScrollPane,{className:T,style:O,ref:_,showVerticalScrollbar:i,showHorizontalScrollbar:c,createHorizontalScrollbar:d,createVerticalScrollbar:f,createScrollCorner:a,viewport:B,onScrollViewport:Me,children:Q.jsx(Ao,{style:{width:"100%",height:"100%"},...D,onViewportChange:Z=>re(Z),ref:ee})})}));rn.displayName="ScrollableGrid";const _o=()=>!1,ln=l.memo(t=>{const{index:r,value:i,zoom:c,zoomScale:d=100,headerText:f=pe=>`${pe}`,headerStyle:a,headerStyleSelect:s=a,headerStyleSelectAll:p=s,headerStyleHover:O=p,verticalPadding:T=0,horizontalPadding:M=0,isSelected:D=_o,isSelectedAll:B=_o,coords:re,bounds:_,range:ee,orientation:Me,view:Z,style:U,...X}=t,we=d/100,K=l.useRef(null),[ge,Le]=l.useState(!1),ye=D?.(r)||!1,Oe=B?.(r)?p:ye?s:a;let ce=Oe;if(ge){let pe=O;typeof O=="function"&&(pe=O(Oe)),ce=n.CommonUtils.mergeContentful(Oe,pe)}return Q.jsx("div",{ref:K,style:{background:ce.fill,color:ce.text?.fill,fontFamily:ce.text?.fontFamily??a.text?.fontFamily,fontSize:96*(ce.text?.fontSize??11)/72*we,fontStyle:ce.text?.fontStyle,fontWeight:ce.text?.fontWeight,lineHeight:1.2,display:"flex",justifyContent:"center",alignItems:"end",pointerEvents:"auto",paddingBottom:`${we}px`,...U,left:U.left-(Me===n.RangeOrientation.Column?1:0),top:U.top-(Me===n.RangeOrientation.Row?1:0),width:U.width+1,height:U.height+1,overflow:"hidden"},...X,onMouseMove:pe=>{o.ReactUtils.detectIt().primaryInput!=="touch"&&pe.buttons===0&&Le(!0)},onMouseOut:pe=>{Le(!1)},children:f(r)})});ln.displayName="HeaderRenderer";const cn="ew-resize",sn="ns-resize",an=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,className:f,style:a,disabled:s=!1,disabledResize:p=!1,isNextHidden:O,isHidden:T,isSelected:M,isSelectedAll:D,showTouchDivider:B,headerStyle:re,headerStyleSelect:_,headerStyleSelectAll:ee,headerStyleHover:Me,bounds:Z,onPointerDown:U,onAutoFit:X,...we}=t,K=i===n.RangeOrientation.Column;let ge=re;M&&_&&(ge=_),D&&ee&&(ge=ee);const Le=o.ReactUtils.detectIt().primaryInput==="touch";let ye=K?14:8,Oe=ye/2,ce=0;O&&(ce=-2),T&&(ce=2),T&&(ye=ye/2+ce,Oe=2*ce);let pe=ge.dividerStrokeFill??ge.strokeFill;return!(M||D)&&ce===0&&(pe=`linear-gradient(${K?180:90}deg, ${ge.fill}, ${pe} 55%, ${pe} 100%)`),Q.jsxs("div",{className:Vt("header-divider",{disabled:s},f,`index-${d}`),ref:r,onPointerDown:Le?void 0:U,onDoubleClick:Le?void 0:()=>X?.(),style:{top:(K?0:-ye/2+(ce-1))+"px",left:(K?-ye/2+(ce-1):0)+"px",width:K?ye:"calc(100% + 1px)",height:K?"calc(100% + 1px)":ye,position:"absolute",overflow:"visible",pointerEvents:"all",cursor:s||p||Le?void 0:K?cn:sn,...a},...we,children:[Q.jsx("div",{style:{position:"relative",top:`${K?0:Oe}px`,left:`${K?Oe:0}px`,width:K?1:"100%",height:K?"100%":1,background:pe},onDoubleClick:()=>X?.()}),B&&Le?Q.jsx("div",{style:{position:"absolute",cursor:"grab",zIndex:1,borderRadius:"4px",right:K?"-6px":"2px",bottom:K?"2px":"-9px",height:"24px",width:K?"24px":"18px",maxHeight:K?"calc(100% - 4px)":void 0,maxWidth:K?void 0:"calc(100% - 4px)",background:ge.fill,border:`${ee.edgeStrokeFill} solid 1px`,boxShadow:`0.5px 0.5px 0px 0px ${re.text.fill}`,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:U,children:Q.jsx("div",{style:{width:"6.4px",height:"12px",backgroundImage:`url("data:image/svg+xml,%3Csvg width='6.4' height='12' viewBox='0 0 9.6 16' version='1.1' fill='${encodeURIComponent(_.text.fill)}' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'%3E%3Cpath d='M 9.60008,14.40009 C 9.60008,15.28374 8.88368,16 8.00003,16 7.11639,16 6.40012,15.28374 6.40012,14.40009 c 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40012 c 0,0.88364 -0.7164,1.60004 -1.60005,1.60004 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60004 0,-0.88365 0.71627,-1.60005 1.59991,-1.60005 0.88365,0 1.60005,0.7164 1.60005,1.60005 m 0,-6.40006 c 0,0.88365 -0.7164,1.60005 -1.60005,1.60005 -0.88364,0 -1.59991,-0.7164 -1.59991,-1.60005 C 6.40012,0.71626 7.11639,0 8.00003,0 8.88368,0 9.60008,0.71626 9.60008,1.59991 M 3.19996,14.40009 C 3.19996,15.28374 2.48369,16 1.60005,16 0.7164,16 0,15.28374 0,14.40009 c 0,-0.88365 0.7164,-1.60005 1.60005,-1.60005 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40012 c 0,0.88364 -0.71627,1.60004 -1.59991,1.60004 C 0.7164,9.60001 0,8.88361 0,7.99997 0,7.11632 0.7164,6.39992 1.60005,6.39992 c 0.88364,0 1.59991,0.7164 1.59991,1.60005 m 0,-6.40006 c 0,0.88365 -0.71627,1.60005 -1.59991,1.60005 C 0.7164,3.19996 0,2.48356 0,1.59991 0,0.71626 0.7164,0 1.60005,0 2.48369,0 3.19996,0.71626 3.19996,1.59991' /%3E%3C/svg%3E%0A")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",transform:K?void 0:"rotate(90deg)"}})}):null]})})),Ln=(t,r)=>Q.jsx(an,{...t,ref:r}),On=l.memo(l.forwardRef((t,r)=>{const{orientation:i,view:c,index:d,disabled:f=!1,disabledResize:a=!1,resizeThreshold:s=1,dividerRenderer:p=Ln,onDividerMouseDown:O,onDividerResizeStart:T,onDividerResize:M,onDividerResizeEnd:D,onDividerMouseUp:B,onDividerAutoFit:re,onPointerDown:_,...ee}=t,Me=o.useCallbackRef(_,[_]),Z=o.useCallbackRef(re,[re]),U=i===n.RangeOrientation.Column;let X=U?c.getVisibleColumns():c.getVisibleRows(),we=null;X.length>0&&(U?we=c.getRangeCoordsBounds({rowStart:0,rowEnd:0,colStart:X[0],colEnd:X[X.length-1]}):c.getRangeCoordsBounds({rowStart:X[0],rowEnd:X[X.length-1],colStart:0,colEnd:0}),we=c.toClipBounds(we,It));const K=l.useRef(null),[ge,Le]=l.useState(null),ye=(G,me)=>U?G.clientX-me.clientX:G.clientY-me.clientY,Oe=c.getLayout(),ce=U?Oe.getColOffset(d+1):Oe.getRowOffset(d+1),pe=o.useSynchronizedPointerHandler({processTouch:!0,onPointerDown:G=>{if(Me?.(G),!f&&!a){const me=U?Oe.getColOffset(d):Oe.getRowOffset(d),q=ce-me;K.current={isResizing:!1,startSize:q,index:d,view:c,orientation:i,onDividerMouseDown:O,onDividerResizeStart:T,onDividerResize:M,onDividerResizeEnd:D,onDividerMouseUp:B},Le(K.current),O?.(d,q)}G.stopPropagation(),G.preventDefault()},onPointerUp:(G,me,q)=>{if(!K.current)return;K.current.isResizing&&K.current.onDividerResizeEnd?.(K.current.index,Math.max(0,K.current.startSize+ye(G,q)),K.current.startSize);const L=K.current;K.current=null,Le(K.current),L.onDividerMouseUp?.(L.index)},onPointerMoveOrWait:(G,me,q)=>{if(!K.current)return;const L=ye(G,q);K.current.isResizing?K.current.onDividerResize?.(K.current.index,Math.max(0,K.current.startSize+L),K.current.startSize):Math.abs(L)>Math.max(1,s)&&(K.current={...K.current,isResizing:!0},Le(K.current),K.current.onDividerResizeStart?.(K.current.index,Math.max(0,K.current.startSize+L))),G.stopPropagation(),G.preventDefault()}}),A=o.useCallbackRef(()=>{Z?.(d)},[d]);if(!we)return;const C=p({bounds:we,orientation:i,view:c,index:d,disabled:f,disabledResize:a,onAutoFit:A,onPointerDown:pe,...ee},r);if(!C)return;const{getPortalContainer:$e}=o.useFullscreenPortal();let Ve=null;return ge&&ge.isResizing&&ge.index===d&&(Ve=Zo.createPortal(Q.jsx("div",{style:{position:"absolute",cursor:U?cn:sn,left:0,top:0,width:"100%",height:"100%"}}),$e(),"divider:"+d)),Q.jsxs(Q.Fragment,{children:[Ve,Q.jsx("div",{className:Vt("header-divider-anchor"),style:{position:"absolute",pointerEvents:"auto",top:`${U?we.y:ce}px`,left:`${U?ce:we.x}px`,width:(U?0:we.width-1)+"px",height:(U?we.height-1:0)+"px",display:"flex"},tabIndex:-1,children:C})]})}));class zn{naturalDimensions(r,i={}){const c=document.createElement("div");let d=i?.lineHeight??"1";!i?.lineHeight&&i.paintableText?.fontSize&&(d=Math.ceil(1.2*i.paintableText.fontSize)+"px");const f=document.createElement("div");f.style.visibility="hidden",f.style.position="absolute",f.style.textRendering="geometricprecision",f.style.display="inline-grid",f.style.overflowWrap="break-word",f.style.maxWidth=i.maxWidth?i.maxWidth+"px":"100%",f.style.lineHeight=d,f.style.letterSpacing=(i.paintableText?.letterSpacing??0)+"px",f.style.fontSize=i.paintableText?.fontSize?i.paintableText.fontSize+"px":"unset",f.style.fontFamily=i.paintableText?.fontSize?i.paintableText.fontFamily:"unset",f.style.fontWeight=i.paintableText?.fontWeight?""+i.paintableText.fontWeight:"400",f.style.fontStyle=i.paintableText?.fontStyle?i.paintableText.fontStyle:"normal",f.style.whiteSpace=i.paintableText?.wrap==="wrap"?"break-spaces":"pre",c.appendChild(f);const a=r.split(`
12
+ `);for(let p=0;p<a.length;p++){let O=document.createElement("span");f.appendChild(O),O.textContent=a[p]}a.length!==0&&a[a.length-1].length!==0||f.appendChild(document.createElement("br")),document.body.appendChild(f);let s=f.getBoundingClientRect();return f.remove(),{width:s.width,height:s.height,maxLineHeight:1.2*(i.paintableText?.fontSize||1056/72)}}}const dn=(t=void 0)=>Object.freeze({clean:t,dirty:void 0,editMode:!1}),An=dn(),$n=l.memo(l.forwardRef((t,r)=>{const{editState:i=An,defaultTextStyle:c,onStartEdit:d,onChangeEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,containerBounds:O,setNaturalSize:T,onNavigate:M,textProperties:D,style:B,autoFocus:re,..._}=t,ee=l.useRef(null),{width:Me=0}=O??{},[Z,U]=l.useState(()=>i);l.useEffect(()=>{U(i)},[i]);const X=D?.align||"left",we=D?.vAlign||"middle",K=D?.fill||"#040404",ge=D?.wrap||"wrap",Le=D?.fontFamily||"Calibri",ye=D?.fontSize||11,Oe=D?.fontWeight||400,ce=D?.fontStyle||"normal",pe=Z.dirty??Z.clean??"";let A=2;const C=96*ye/72,$e=1.2*C;we==="right"&&(A+=1);const Ve=l.useMemo(()=>new zn().naturalDimensions(pe,{maxWidth:ge==="wrap"?Me-A:void 0,lineHeight:`${$e}px`,paintableText:{fontStyle:ce,wrap:ge,letterSpacing:-.25}}),[pe,ge,A,C,Le,Oe,ce,T,Me]),G=l.useCallback(()=>Ve.maxLineHeight?Ve.maxLineHeight+"px":"1.2",[Ve]),[me,q]=l.useState(G);l.useLayoutEffect(()=>{q(G())},[O,Ve]),l.useLayoutEffect(()=>{T?.({width:ge==="wrap"?void 0:Ve.width+A,height:Ve.height})},[Ve,T]);const L=o.useCallbackRef(f,[f]),j=o.useCallbackRef(R=>{if(Z.dirty===R)return;const be={...Z};be.dirty=R,ee.current,U(be),L?.(be)},[Z]),St=o.useCallbackRef(R=>{if(Z.editMode===R)return;const be={...Z};be.editMode=R,U(be),L?.(be)},[Z]),xt=o.useCallbackRef(()=>{try{return a?.(Z),p?.(),!0}catch{return!1}},[a,Z]),ct=o.useCallbackRef(()=>{U(i),s?.(),p?.()},[s,i]),rt=o.useCallbackRef(R=>{if(!ee.current)return;if(R.isDefaultPrevented(),!(R.isTrusted||R.nativeEvent.ctrlKey||R.nativeEvent.metaKey||R.nativeEvent.altKey||R.nativeEvent.isComposing)&&Lo.indexOf(R.nativeEvent.key)!==-1){const te={...Z};return te.dirty=R.nativeEvent.key==="Backspace"?"":(te.dirty??"")+R.key,U(te),L?.(te),void R.preventDefault()}const be=R.nativeEvent.shiftKey;if(R.which===o.KeyCodes.Escape)return R.preventDefault(),void ct();if(R.which===o.KeyCodes.F2)return St(!0),void R.preventDefault();if(R.which===o.KeyCodes.Enter&&(R.preventDefault(),xt()&&M?.(be?n.Direction.Up:n.Direction.Down)),R.which===o.KeyCodes.Tab)return R.preventDefault(),void(xt()&&M?.(be?n.Direction.Left:n.Direction.Right));if(!Z.editMode){let te=null;switch(R.which){case o.KeyCodes.Left:te=n.Direction.Left;break;case o.KeyCodes.Right:te=n.Direction.Right;break;case o.KeyCodes.Up:te=n.Direction.Up;break;case o.KeyCodes.Down:te=n.Direction.Down}if(te)return void xt()}},[Z,M]),[se,Pt]=l.useState(!re);l.useEffect(()=>{Pt(!1)},[]);const P=o.useImperativeElement(r,()=>({startEdit(R){let be=R?.initialSelection;if(!be){const ue=ee.current.value.length??0;be={start:ue,end:ue,direction:"forward"}}ee.current?.setSelectionRange(be.start,be.end,be.direction);const te={...i,editMode:R?.editMode??!1};R?.text!==void 0&&(te.dirty=R.text),te.editMode===i.editMode&&te.dirty===i.dirty||(U(te),L?.(te))},submitEdit:()=>xt(),cancelEdit(){ct()},autoFocus(){ee.current?.focus()},getLineHeight:()=>Ve?.maxLineHeight??$e,dispatchEvent:R=>ee.current.dispatchEvent(R)}),[i,d]);return Q.jsx("div",{ref:P,..._,style:{background:"transparent",display:"flex",flexGrow:1,alignSelf:"center",height:Ve.height,maxWidth:"100%",maxHeight:"100%",...B},children:Q.jsx("textarea",{spellCheck:"false",ref:ee,value:pe,autoFocus:!1,disabled:se,name:"cell-editor",autoComplete:"off",autoCapitalize:"off",style:{flex:"1 1 100%",position:"relative",fontSize:`${C}px`,fontFamily:`${Le}`,fontWeight:`${Oe}`,fontStyle:`${ce}`,padding:"0px",marginRight:X==="right"?"3px":"0px",marginLeft:X==="left"?"2px":"0px",lineHeight:me,height:Ve.height,textRendering:"geometricPrecision",letterSpacing:"-0.25px",boxSizing:"border-box",borderWidth:0,outline:"none",resize:"none",overflow:"hidden",verticalAlign:"baseline",textAlign:X,background:"transparent",color:K,marginBottom:"0px",userSelect:"text",maxHeight:"100%",whiteSpace:ge==="wrap"?"break-spaces":"pre",wordWrap:"break-word"},onChange:R=>{j(R.target.value)},onDoubleClick:R=>{R.isTrusted},onMouseDown:R=>{St(!0)},onKeyDown:rt})})})),Bn=l.memo(t=>{const{value:r,view:i,bounds:c,range:d,zoom:f,children:a,style:s,...p}=t,O=s?.fontSize||1056/72;return Q.jsx("div",{style:{padding:"2px 4px",fontFamily:"Calibri",letterSpacing:-.25,lineHeight:1.2,fontSize:O,...s},...p,children:r})});exports.BaseGrid=zo,exports.DefaultCellEditor=$n,exports.DefaultCellRenderer=Bn,exports.DefaultHeaderDivider=an,exports.FillHandle=Uo,exports.Grid=Ao,exports.HeaderDivider=On,exports.HeaderRenderer=ln,exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL=150,exports.SELECTION_CLIP_INSETS=It,exports.STANDARD_KEY_CHARS=Lo,exports.SVGLine=Po,exports.SVGRect=en,exports.ScrollableGrid=rn,exports.Selection=Oo,exports.TouchSelectHandle=fo,exports.defaultSelectionRenderer=qo,exports.getDefaultStringEditState=dn,exports.safeSelectionCoords=yt,exports.useCellLayout=Qo,exports.useHeaderSelection=({gridRef:t,gridMainRef:r,orientation:i=n.RangeOrientation.Row,headerCount:c,selectionPolicy:d="multiple",newSelectionMode:f="clear",alwaysScrollToActiveCoords:a=!0,onDragStart:s,onDragEnd:p,pointerDownInterceptor:O,pointerMoveInterceptor:T,onPointerUp:M,newSelection:D,modifySelection:B,appendSelection:re,clearSelections:_})=>{const ee=c??((i===n.RangeOrientation.Row?t.current?.rowCount:t.current?.columnCount)||0),Me=l.useRef(null),Z=l.useRef(null),U=l.useRef(!1),X=l.useRef(null),we=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:0},[i]),K=l.useCallback(A=>i===n.RangeOrientation.Column?{rowIndex:r.current?r.current.rowCount-1:0,colIndex:A.colIndex}:{rowIndex:A.rowIndex,colIndex:r.current?r.current.columnCount-1:0},[i]),ge=A=>{Z.current=K(A),B(Z.current,Me.current)},Le=l.useCallback((A,C)=>{if(!t.current)return;const $e=t.current.getViewFromClient(A,C)?.getCellCoordsFromClient(A,C);return $e?(i===n.RangeOrientation.Column?$e.rowIndex=r.current.getViewport().rowStart:$e.colIndex=r.current.getViewport().colStart,$e):void 0},[]),ye=l.useCallback((A,C=!1)=>{let $e=A;return C||($e={...A},i===n.RangeOrientation.Row?delete $e.colIndex:delete $e.rowIndex),r.current?.scrollCellCoordsIntoView($e)},[i]),Oe=o.useCallbackRef(p,[p]),ce=o.useCallbackRef(s,[s]),pe=l.useMemo(()=>({onPointerDown:A=>{if(!t||!t.current||A.nativeEvent.defaultPrevented)return;const C=Le(A.nativeEvent.clientX,A.nativeEvent.clientY);if(!C)return;A.nativeEvent.which,o.MouseButtonCodes.Right;const $e=A.nativeEvent.shiftKey,Ve=A.nativeEvent.ctrlKey||A.nativeEvent.metaKey;if(O?.(A,C)===!1)return;ce?.(),U.current=!0;const G=r.current?.getViewFromClient(A.nativeEvent.clientX,A.nativeEvent.clientY),me=((q,L)=>i===n.RangeOrientation.Column?{...q,rowIndex:L.rowStart}:{...q,colIndex:L.colStart})(C,G.getVisibleRangeCoords());if($e)ge(C);else{if(Ve)return((q,L=q,j)=>{Me.current=we(q),Z.current=K(L),re(Me.current,Z.current,j)})(C,C,me),void(a&&ye(me,!0));((q,L=q,j)=>{Me.current=we(q),Z.current=K(L),D(Me.current,Z.current,j)})(C,C,me),ge(C),a&&ye(me,!0)}},onPointerMoveOrWait:n.CommonUtils.throttle(A=>{if(!U.current||!t?.current)return;const C=Le(A.clientX,A.clientY);if(C&&T?.(A,C)!==!1){if(n.CoordUtils.isEqualCells(X.current,C))return _();ge(C),ye(C)}},60),onPointerUp:A=>{U.current=!1,Oe?.(),M?.(A)},processTouch:!0,consumeTouch:!0}),[d,a,ee,f,_,O,M]);return{onPointerDown:o.useCallbackRef(o.useSynchronizedPointerHandler(pe),[]),getCellCoordsFromClient:Le}},exports.useKeyboardEditorOverlay=t=>{const{view:r,canEdit:i=gn,getCellEditor:c,onBeforeStartEdit:d,onStartEdit:f,onSubmitEdit:a,onCancelEdit:s,onDoneEdit:p,isEditorStartKeyEvent:O=wn,isEditorStartPointerEvent:T=xn,containerProps:M,borderStrokeFill:D,borderStrokeWidth:B=2,getRangeCoords:re=null,activeCoords:_,alignment:ee=o.HorizontalAlignment.Left}=t,[Me,Z]=l.useState(!1),[U,X]=l.useState(void 0),we=o.useCallbackRef((P,R,be,te,ue,ze)=>{if(!R)return null;const Je=ue?.(R,P),mt=P.getRangeCoordsBounds(Je),Qe=P.toClipBounds(mt),Tt=mt,st=P.getZoom();if(!Qe)return null;be&&(be*=st),te&&(te*=st);let b=Tt,oe=!1;if(be!==void 0){let qe={...Je},Ht=0;for(;!oe&&b.width<=be&&Ht<20;){Ht++,Ht>19&&console.warn("max width reached");const $t=P.getTotalRangeCoords(),bt=P.getLayout();ze===o.HorizontalAlignment.Left?qe.colEnd+1<$t.colEnd?qe.colEnd=bt.getColIndex(b.x+be):oe=!0:ze===o.HorizontalAlignment.Right?qe.colStart-1>=0?qe.colStart=bt.getColIndex(b.x-(be-b.width)):oe=!0:ze===o.HorizontalAlignment.Center&&qe.colEnd+1<$t.colEnd&&qe.colStart-1>=0?(qe.colStart=bt.getColIndex(b.x-(be-b.width)/2),qe.colEnd=bt.getColIndex(b.x+b.width+(be-b.width)/2)):oe=!0,oe||(b=P.getRangeCoordsBounds(qe))}}b.height=Tt.height,te!==void 0&&(b.height=Math.max(te+1,Tt.height));const{width:Ae,height:lt}=P.getViewportSize();return{x:b.x??0,y:b.y??0,height:Math.min(lt-b.y,b.height)+1,width:Math.min(Ae-b.x,b.width)+1}},[ee]),K=o.useCallbackRef(i,[i]),ge=l.useCallback(()=>{r?.getStage()?.focus()},[r]),Le=l.useRef(null),ye=o.useCallbackRef(P=>{d?.(P),L(),Z(!0),Le.current=null},[d]),Oe=o.useCallbackRef(P=>{f?.(P.coords)},[f]),ce=o.useCallbackRef(P=>{P.isSubmitted||P.isCancelled||(C.current.isEditorClosed=!0,ge(),P.isCancelled=!0,s?.(P.coords),L())},[s]),pe=o.useCallbackRef(P=>{if(P.isSubmitted||P.isCancelled)return!1;try{return Le.current=P.coords,P.isEditorClosing=!0,P.isSubmitted=!0,P.isEditorSubmitted||(P.isEditorSubmitted=!0,P.editorRefs[0]?.submitEdit?.()),P.coords,a?.(P.coords),P.isEditorClosed=!0,ge(),L(),!0}catch(R){throw P.isEditorClosing=!1,P.isSubmitted=!1,R}},[a]),A=o.useCallbackRef(P=>{Z(!1),p?.(P.coords),L()},[p]),C=l.useRef(null),$e=l.useRef(null),Ve=l.useRef(null),G=l.useRef([]),[me,q]=l.useReducer(P=>P+1,0),L=l.useCallback(P=>{P&&G.current.push(P),q()},[]),j=o.useCallbackRef(P=>{if(P.defaultPrevented||P.isSynthetic||!r)return;const R=r?.getCellCoordsFromClient(P.clientX,P.clientY);R&&L({eventType:"pointer",event:P,coords:R})},[r]),St=o.useCallbackRef(P=>{const R=P.nativeEvent;j(R)},[r]),xt=o.useCallbackRef(P=>{if(P.defaultPrevented||P.isSynthetic||!r?.getStage())return;const R=$e.current;O(P,R)&&(P.stopPropagation(),P.preventDefault()),P.key,L({eventType:"keyboard",event:P,coords:R})},[r]);l.useLayoutEffect(()=>{const P=(te,ue)=>{const ze=ue?.cell??te;if(!ze)return null;const Je=ze;if(!K(ze))return null;ye?.(ze);const mt=n.CommonUtils.uuidV4();ue=Object.freeze({autoFocus:!0,...ue}),Ve.current=ze;const Qe={coords:Je,startEvent:ue,uuid:mt,isMounted:!1,isStarted:!1,isSubmitted:!1,isEditorSubmitted:!1,isEditorClosing:!1,isEditorClosed:!1,isCancelled:!1,events:[],editorRefsDispatchEditorEvent:[],editorRefs:[],onMount:Tt=>{Qe.isMounted||(Qe.isMounted=!0,L())},onUnmount:Tt=>{if(Qe.editorRefs.length===0){const st=()=>{Qe.isMounted=!1,L()};if(document.activeElement!==document.body)st();else{const b=oe=>{oe.defaultPrevented||oe.target!==document.body||xt(oe)};window.addEventListener("keydown",b,!0),r.getStage()?.addEventListener("focusin",()=>{window.removeEventListener("keydown",b),st()},mn),ge()}}}};return Qe};if(G.current.length<=0&&!C.current)return;const R=G.current[0];Ko(R),(te=>{const ue=[],ze=te?.length??0;for(let Je=0;Je<ze;Je++){const mt=te[Je];ue.push(Ko(mt))}})(G.current),C.current,C.current;let be=C.current;if(C.current){if(C.current.isDone)C.current=null;else if(C.current.isSubmitted||C.current.isCancelled){if(C.current.isMounted)return;C.current.isDone||(A(C.current),C.current.isDone=!0)}}if(R){if(R.eventType==="start"){const te=R,ue=te.startEvent?.cell??$e.current;C.current&&n.CoordUtils.isEqualCells(C.current.coords,ue)||(C.current=P(ue,te.startEvent))}else if(R.eventType==="keyboard"){const te=R.event;if(C.current){let ue=!1;switch(te.which){case o.KeyCodes.Left:case o.KeyCodes.Right:case o.KeyCodes.Up:case o.KeyCodes.Down:case o.KeyCodes.Enter:case o.KeyCodes.Tab:ue=!0}if(!ue){C.current.events.push(R);for(let ze=0;ze<C.current.editorRefsDispatchEditorEvent.length;ze++)C.current.editorRefsDispatchEditorEvent[ze](R)}}else if(O(te,R.coords)){let ue;const ze=P(ue?.cell??$e.current,ue);ze&&ze.events.push(R),C.current=ze}}else if(R.eventType==="pointer"){const te=R.event;if(C.current){C.current.events.push(R);for(let ue=0;ue<C.current.editorRefsDispatchEditorEvent.length;ue++)C.current.editorRefsDispatchEditorEvent[ue](R)}else{const ue=R?.coords??$e.current,ze=T(te,ue);if(ze){let Je;typeof Je!="boolean"&&(Je=ze);const mt=P(ue,Je);mt&&mt.events.push(R),C.current=mt}}}else if(R.eventType==="submit"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;pe(C.current)}}else if(R.eventType==="cancel"){if(C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;ce(C.current)}}else if(R.eventType==="coordsChange"){const te=R;if($e.current=te.activeCoords,C.current,C.current&&!C.current.isSubmitted&&!C.current.isCancelled){if(!C.current.isMounted)return;try{pe(C.current)}catch{}}}}G.current.length>0&&(G.current.shift(),L()),G.current.length===0&&(!C.current||C.current.isEditorClosing||C.current.isEditorClosed?!C.current&&be&&ge():C.current.isMounted&&!C.current.isStarted&&(C.current.isStarted=!0,C.current.startEvent.autoFocus&&(typeof C.current.startEvent.autoFocus=="string"?C.current.editorRefs[0]?.autoFocus(C.current.startEvent.autoFocus):C.current.editorRefs[0]?.autoFocus()),Oe?.(C.current),requestAnimationFrame(()=>{r&&C.current?.coords&&r.scrollCellCoordsIntoView(C.current.coords)})))},[me]),l.useEffect(()=>{Ve.current=_;const P=C.current?.coords;n.CoordUtils.isEqualCells(P,_)||(C.current&&(C.current.isEditorClosing=!0),L({eventType:"coordsChange",activeCoords:_}))},[_]);const ct=l.useCallback(P=>{xt(P.nativeEvent)},[]),{width:rt=0,height:se=0}=U??{width:0,height:0},Pt=o.useCallbackRef(c,[c]);return{overlay:o.useCallbackRef(P=>{if(!C.current||C.current.isEditorClosed)return C.current,null;C.current.coords;let R=we(P,C.current.coords,rt,se,re,ee),be=!0;R&&R.width!==0&&R.height!==0||(R={x:0,y:0,width:rt,height:rt},be=!1);const te=P.getZoom(),ue={containerBounds:{x:0,y:0,width:R.width/te,height:R.height/te},setNaturalSize:X,zoom:te};return Q.jsx(pn,{session:C.current,refLatestCoords:Ve,handleSubmitEdit:pe,handleCancelEdit:ce,cellBounds:R,borderStrokeWidth:B,borderStrokeFill:D,isInBounds:be,getCellEditor:Pt,propsEditor:ue,alignment:ee,...M},"editor:"+C.current.uuid)},[c,re,me,rt,se,ee,B,D]),startEdit:l.useCallback(P=>{L({eventType:"start",startEvent:P})},[]),submitEdit:l.useCallback(()=>{L({eventType:"submit"})},[]),cancelEdit:l.useCallback(()=>{L({eventType:"cancel"})},[]),onKeyboardEvent:ct,onPointerEvent:St,onKeyboardEventNative:xt,onPointerEventNative:j,isEditing:Me}},exports.useSelection=({gridRef:t,commands:r,layout:i,selection:c,onSelectionChange:d,onSelectionDragStart:f,onSelectionDragEnd:a,selectionPolicy:s="multiple",newSelectionMode:p="clear",allowDeselectSelection:O=!0,onFillPreview:T,onFillCancel:M,onFillDone:D,onFill:B,disableFillDrag:re=!B,fillHandleBorderColor:_="white",hiddenRowsAt:ee,hiddenColumnsAt:Me,isContentfulCell:Z,contentfulCellFinder:U=bn,getDataCoords:X,alwaysScrollToActiveCoords:we=!1,selectionBounds:K,pointerDownInterceptor:ge,pointerMoveInterceptor:Le,mergedRanges:ye,canSelectionSpanMergedCells:Oe=In,onMoveDragStart:ce,onMoveDragUpdate:pe,onMoveDragEnd:A,onMoveDragDone:C,selectionRenderer:$e=qo,disableMoveDrag:Ve=!A,getCellCoordsAsRangeCoords:G=n.CoordUtils.cellToRange,moveDragHitSize:me=6,moveDragOutlineSize:q=4,selectionBackgroundColor:L="rgba(16, 124, 65, 0.1)",selectionBorderColor:j="rgb(33, 115, 70)",selectionRemoveBorderColor:St="rgb(255, 0, 0)",selectionRemoveBackgroundColor:xt="rgba(250, 10, 10, 0.1)",disableTouchSelection:ct=!1,touchSelectHandleProps:rt})=>{const se=l.useCallback(()=>({top:K?.top??0,left:K?.left??0,bottom:t.current?.rowCount-1||0,right:t.current?.columnCount-1||0}),[]),Pt=o.useCallbackRef(B,[B]),P=o.useCallbackRef(T,[T]),R=o.useCallbackRef(M,[M]),be=o.useCallbackRef(D,[D]),te=o.useCallbackRef(Z,[Z]),ue=o.useCallbackRef($e,[$e]),ze=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getRowOffset,u?se().bottom:se().top),[i?.getRowOffset]),Je=o.useCallbackRef(ee??ze,[ee]),mt=o.useCallbackRef((e,u=!1)=>wo(e,u,i.getColOffset,u?se().right:se().left),[i?.getColOffset]),Qe=o.useCallbackRef(Me??mt,[Me]),[Tt,st]=l.useState(()=>yt(c)),b=l.useMemo(()=>yt(Tt),[Tt]),oe=l.useRef(b),Ae=l.useRef(!0);l.useLayoutEffect(n.CommonUtils.throttle(()=>{st(e=>{Ae.current=!0;const u=yt(c);return n.CoordUtils.isEqualSelectionCoords(u,e)?e:u})},0),[c]),l.useLayoutEffect(()=>{oe.current=b},[b]),l.useEffect(()=>{Ae.current||!d||n.CoordUtils.isEqualSelectionCoords(c,b)||d(b)},[b]);const lt=l.useCallback(e=>{st(u=>{Ae.current=!1,u=yt(u);let g=typeof e=="function"?e(u.ranges):e??To;if(n.CoordUtils.isEqualRangesArrays(g,u.ranges))return u;let h=Math.max(g.length?0:-1,Math.min(u.rangeIndex,g.length-1)),x=u.cell;h===-1||n.CoordUtils.isCellWithinRange(x,g[h])||(x={rowIndex:g[h].rowStart,colIndex:g[h].colStart}),g.length===1&&n.CoordUtils.isSingleCell(g[0])&&n.CoordUtils.isCellWithinRange(x,g[0])&&(g=[],h=-1);const k={cell:x,ranges:g,rangeIndex:h};return n.CoordUtils.isEqualSelectionCoords(k,u)?u:k})},[]),qe=o.useCallbackRef(e=>{st(u=>{Ae.current=!1,u=yt(u);const g=e??on,h=G(g);if(!n.CoordUtils.isSingleCell(h)&&u.ranges.length===0)return{ranges:[h],rangeIndex:0,cell:g};if(n.CoordUtils.isEqualCells(g,u.cell))return u;let x=u.ranges,k=u.rangeIndex;u.ranges.length===1&&(n.CoordUtils.isSingleCell(u.ranges[0])&&n.CoordUtils.isCellWithinRange(g,u.ranges[0])||!n.CoordUtils.isCellWithinRange(g,u.ranges[0]))&&(x=[],k=-1);const m={ranges:x,rangeIndex:k,cell:g};return n.CoordUtils.isEqualSelectionCoords(m,u)?u:m})},[G]),[Ht,$t]=l.useState(null),[bt,Xt]=l.useState(null),At=l.useRef(null),[Re,Ut]=l.useState(null),ut=l.useRef(null),kt=l.useRef(null),[eo,jt]=l.useState(null),He=l.useRef(null),Be=l.useRef(null),Ft=l.useRef(ye);l.useEffect(()=>{Ft.current=ye},[ye]);const ht=o.useCallbackRef((e,u={inline:"nearest",block:"nearest"})=>{let{rowIndex:g,colIndex:h}=e;g===void 0&&b?.cell&&(g=b.cell.rowIndex),h===void 0&&b?.cell&&(h=b.cell.colIndex),g!==void 0&&h!==void 0&&t.current?.scrollCellCoordsIntoView({rowIndex:g,colIndex:h},u)},[b]),Lt=l.useCallback(e=>{const u=se();return e.rowIndex<u.top||e.colIndex<u.left||e.colIndex>u.right||e.rowIndex>u.bottom},[]),ve=o.useCallbackRef((e,u)=>{if(!t?.current)return null;const g={rowStart:Math.min(e.rowIndex,u.rowIndex),colStart:Math.min(e.colIndex,u.colIndex),rowEnd:Math.max(e.rowIndex,u.rowIndex),colEnd:Math.max(e.colIndex,u.colIndex)};if(Oe?.(g))return g;const x=G(e),k=G(u),m={rowStart:Math.min(x.rowStart,k.rowStart),colStart:Math.min(x.colStart,k.colStart),rowEnd:Math.max(x.rowEnd,k.rowEnd),colEnd:Math.max(x.colEnd,k.colEnd)};let N;return typeof Ft.current=="function"?N=Ft.current(m):ye&&(N=ye),N?n.CoordUtils.extendRangeToUnionRanges(m,N):m},[Oe,G]),je=o.useCallbackRef((e,u,g)=>{const h=e.ranges.length>0?e.ranges[e.rangeIndex]:{rowStart:e.cell.rowIndex,colStart:e.cell.colIndex,rowEnd:e.cell.rowIndex,colEnd:e.cell.colIndex},x={rowStart:Math.min(u.rowIndex??h.rowStart,g.rowIndex??h.rowStart),colStart:Math.min(u.colIndex??h.colStart,g.colIndex??h.colStart),rowEnd:Math.max(u.rowIndex??h.rowEnd,g.rowIndex??h.rowEnd),colEnd:Math.max(u.colIndex??h.colEnd,g.colIndex??h.colEnd)},k={rowIndex:x.rowStart,colIndex:x.colStart},m={rowIndex:x.rowEnd,colIndex:x.colEnd};if(!(Lt(k)||Lt(m)))return ve(k,m)},[ve]),it=o.useCallbackRef((e,u,g)=>{if(s==="single"||!oe.current)return;const h=je(oe.current,e,u??oe.current.cell);if(!h)return;const x=oe.current.rangeIndex;lt(k=>k.length?k.map((m,N)=>x===N?h:m):[h]),g&&h&&qe({colIndex:h.colStart,rowIndex:h.rowStart})},[]),pt=l.useCallback((e,u,g)=>{if(!oe.current)return;e={...oe.current?.cell,...e},u=u??e;const h=je(oe.current,e,u);if(!h)return;const x={rowIndex:h.rowStart,colIndex:h.colStart},k={...x,...g};p==="clear"?(He.current=k,Bt()):p==="modify"?it(x):Ce(x),qe(k)},[]),Ce=l.useCallback((e,u=e,g)=>{s!=="multiple"||!e||Lt(e)||Lt(u)||st(h=>{Ae.current=!1,h=yt(h);const x=ve(e,u);if(!x)return h;let k=h.ranges.length>0?[...h.ranges]:[ve(h.cell,h.cell)];k.push(x);const m={ranges:k,cell:{rowIndex:x.rowStart,colIndex:x.colStart,...g},rangeIndex:k.length-1};return n.CoordUtils.isEqualSelectionCoords(m,h)?h:m})},[]),Bt=()=>{lt(To)},Rt=o.ReactUtils.detectIt().primaryInput==="touch",_e=l.useRef(null),Ct=l.useRef(null),vt=l.useRef(null),Nt=l.useMemo(()=>({onPointerDown:e=>{if(!t||!t.current)return!1;const u=e.nativeEvent,g=t.current.getViewFromClient(u.clientX,u.clientY);if(u.pointerType==="touch"||u.type==="touchstart")return Ct.current={topLeft:g.getScrollTopLeft(),point:{x:u.clientX,y:u.clientY}},!0;const h=g.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return!1;_e.current={anchor:g.getAnchor(),coords:h},Be.current=null;const x=e.nativeEvent.which===o.MouseButtonCodes.Right;if(x&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1)return!1;const k=e.nativeEvent.shiftKey,m=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,N=m,$=O,W=b.ranges.length>0,Y=m&&$;if(ge?.(e,h,b)===!1)return!1;f?.(oe.current,e);const xe=!x&&s!=="single";if(k)return it(h),xe;const H=n.CoordUtils.isEqualCells(h,b.cell);if(N){if(H&&(!Y||!W))return xe;if(m&&n.CoordUtils.indexOfCoords(h,b.ranges)!==-1&&$){ut.current=h;const V=ve(h,h);return kt.current=V,Ut(V),xe}return Ce(h),xe}we&&ht(h),H&&b.ranges.length===0||pt(h)},onPointerMoveOrWait:n.CommonUtils.throttle((e,u)=>{if(!t?.current||e.pointerType==="touch"||e.type==="touchmove"||!_e.current)return;const g=_e.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(x,_e.current?.coords)&&(_e.current={anchor:g,coords:x},x&&Le?.(e,x,oe.current)!==!1)){if(ut.current){const k={rowStart:Math.min(x.rowIndex,ut.current.rowIndex),colStart:Math.min(x.colIndex,ut.current.colIndex),rowEnd:Math.max(x.rowIndex,ut.current.rowIndex),colEnd:Math.max(x.colIndex,ut.current.colIndex)},m={rowIndex:k.rowStart,colIndex:k.colStart},N={rowIndex:k.rowEnd,colIndex:k.colEnd};if(Lt(m)||Lt(N))return;const $=ve(m,N);kt.current=$,Ut($)}else it(x);vt.current=u,ho(h,x,t)}},60),onPointerUp:e=>{if(_e.current=null,e.pointerType==="touch"||e.type==="touchend"){if(Ct.current){const g=t.current.getViewFromClient(Ct.current.point.x,Ct.current.point.y),h=g.getScrollTopLeft();if(h.left===Ct.current.topLeft.left&&h.top===Ct.current.topLeft.top){const x=g.getCellCoordsFromClient(Ct.current.point.x,Ct.current.point.y);pt(x)}}return Ct.current=null,void(_e.current=null)}try{a?.(oe.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})},processTouch:!0,consumeTouch:!1}),[b,s,O,we,p]),xo=o.useCallbackRef(o.useSynchronizedPointerHandler(Nt),[]),po=l.useMemo(()=>({onSelectionPointerDown:(e,u,g,h,x=b.cell,k=we,m=e.nativeEvent.shiftKey,N=!1)=>{if(!t||!t.current)return!1;e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();const $=g??t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),W=h??$.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!W)return!1;_e.current={anchor:$.getAnchor(),coords:W},Be.current=null;const Y=e.nativeEvent.which===o.MouseButtonCodes.Right;if(Y&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1)return!1;const xe=e.nativeEvent.ctrlKey||e.nativeEvent.metaKey,H=xe,V=O,nt=b.ranges.length>0,I=xe&&V;if(ge?.(e,W,b)===!1)return!1;f?.(oe.current,e);const fe=!Y&&s!=="single";if(m)return it(W,x,N),fe;const wt=n.CoordUtils.isEqualCells(W,x);if(H){if(wt&&(!I||!nt))return fe;if(I&&n.CoordUtils.indexOfCoords(W,b.ranges)!==-1&&V){ut.current=W;const de=ve(W,W);return kt.current=de,Ut(de),fe}return Ce(W),fe}k&&ht(W),wt&&b.ranges.length===0||pt(W)},onSelectionPointerMoveOrWait:(e,u,g,h,x,k=b.cell,m=!0,N=!1)=>{if(!t?.current||(e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation(),!_e.current))return;const $=_e.current.anchor;let W=h??t.current.getViewFromLocation($),Y=x??W.getCellCoordsFromClient(e.clientX,e.clientY);if(!n.CoordUtils.isEqualCells(Y,_e.current?.coords)&&(_e.current={anchor:$,coords:Y},Y&&Le?.(e,Y,oe.current)!==!1)){if(ut.current){const xe={rowStart:Math.min(Y.rowIndex,ut.current.rowIndex),colStart:Math.min(Y.colIndex,ut.current.colIndex),rowEnd:Math.max(Y.rowIndex,ut.current.rowIndex),colEnd:Math.max(Y.colIndex,ut.current.colIndex)},H={rowIndex:xe.rowStart,colIndex:xe.colStart},V={rowIndex:xe.rowEnd,colIndex:xe.colEnd};if(Lt(H)||Lt(V))return;const nt=ve(H,V);kt.current=nt,Ut(nt)}else it(Y,k,N);m&&ho(W,Y,t)}},onPointerUp:e=>{_e.current=null,e.stopPropagation(),e.preventDefault(),e.nativeEvent.stopImmediatePropagation();try{a?.(oe.current,e)}catch(g){console.warn(g)}if(!ut.current)return;const u=kt.current;ut.current=null,kt.current=null,Ut(null),st(g=>{if(Ae.current=!1,(g=yt(g)).ranges.length===0)return g;let h=[],x=-1,k=g.cell;for(let N=0;N<g.ranges.length;N++){const $=g.ranges[N];if(n.CoordUtils.isRangesIntersect($,u)){const W=n.CommonUtils.subtractRect({top:$.rowStart,left:$.colStart,bottom:$.rowEnd+1,right:$.colEnd+1},{top:u.rowStart,left:u.colStart,bottom:u.rowEnd+1,right:u.colEnd+1});for(let Y=0;Y<W.length;Y++){const xe={rowStart:W[Y].top,colStart:W[Y].left,rowEnd:W[Y].bottom-1,colEnd:W[Y].right-1};h.push(xe),n.CoordUtils.isCellWithinRange(g.cell,xe)&&(x=h.length-1)}}else h.push($);h.length>0&&x===-1&&n.CoordUtils.isCellWithinRange(g.cell,$)&&(x=h.length-1,k={rowIndex:h[h.length-1].rowStart,colIndex:h[h.length-1].colStart})}const m={cell:k,rangeIndex:x,ranges:h};return n.CoordUtils.isEqualSelectionCoords(m,g)?g:m})}}),[b,s,O,we,p]),Ze=o.useCallbackRef((e,u=!1,g=!1,h=0)=>{if(!t.current||!b.cell)return;let x=b.cell,k=b.cell;if(u&&b.ranges.length>0){const I=b.ranges[b.rangeIndex],fe=b.cell;switch(e){case n.Direction.Up:k={rowIndex:fe.rowIndex===I.rowStart?I.rowEnd:I.rowStart,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowStart?I.rowStart:I.rowEnd,colIndex:I.colStart};break;case n.Direction.Down:k={rowIndex:fe.rowIndex===I.rowEnd?I.rowStart:I.rowEnd,colIndex:I.colEnd},x={rowIndex:fe.rowIndex===I.rowEnd?I.rowEnd:I.rowStart,colIndex:I.colStart};break;case n.Direction.Left:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colStart?I.colEnd:I.colStart},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colStart?I.colStart:I.colEnd};break;case n.Direction.Right:k={rowIndex:I.rowEnd,colIndex:fe.colIndex===I.colEnd?I.colStart:I.colEnd},x={rowIndex:I.rowStart,colIndex:fe.colIndex===I.colEnd?I.colEnd:I.colStart}}}const m=G(k);let{rowStart:N,colStart:$}=m;const W=se();if(Be.current)switch(e){case n.Direction.Up:case n.Direction.Down:Be.current.colIndex>=m.colStart&&Be.current.colIndex<=m.colEnd&&($=Be.current.colIndex);break;case n.Direction.Left:case n.Direction.Right:Be.current.rowIndex>=m.rowStart&&Be.current.rowIndex<=m.rowEnd&&(N=Be.current.rowIndex)}if(!h){switch(e){case n.Direction.Up:N=Te(Je,Math.max(m.rowStart-1,W.top),e);break;case n.Direction.Down:N=Te(Je,Math.min(m.rowEnd+1,W.bottom),e);break;case n.Direction.Left:$=Te(Qe,Math.max(m.colStart-1,W.left),e);break;case n.Direction.Right:$=Te(Qe,Math.min(m.colEnd+1,W.right),e)}if(g)switch(e){case n.Direction.Up:N=U({...k,colIndex:b.cell.colIndex},te,Je,e,!1,Math.max(W.top,Je(W.top,!1)));break;case n.Direction.Down:N=U({...k,colIndex:b.cell.colIndex},te,Je,e,!1,Math.min(W.bottom,W.bottom-Je(W.bottom,!0)));break;case n.Direction.Left:$=U({...k,rowIndex:b.cell.rowIndex},te,Qe,e,!1,Math.max(W.left,Qe(W.left,!1)));break;case n.Direction.Right:$=U({...k,rowIndex:b.cell.rowIndex},te,Qe,e,!1,Math.min(W.right,W.right-Qe(W.right,!0)))}}let Y=null;if(h){let I=0;switch(e){case n.Direction.Up:I=i.getRowOffset(N+1),N=Math.max(W.top,i.getRowIndex(I-h)),Y={top:i.getRowOffset(N+1)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Down:I=i.getRowOffset(N),N=Math.min(W.bottom,i.getRowIndex(I+h)),Y={top:i.getRowOffset(N)-(I-t.current.getScrollPosition().top)};break;case n.Direction.Left:I=i.getColOffset($+1),$=Math.max(W.left,i.getColIndex(I-h)),Y={left:i.getColOffset($+1)-(I-t.current.getScrollPosition().left)};break;case n.Direction.Right:I=i.getColOffset($),$=Math.min(W.right,i.getColIndex(I+h)),Y={left:i.getColOffset($)-(I-t.current.getScrollPosition().left)}}}const xe={rowIndex:N,colIndex:$},H=G(xe),V={rowIndex:H.rowStart,colIndex:H.colStart};u||(Be.current=xe);const nt=n.CoordUtils.isEqualCells(He.current,V)&&n.CoordUtils.isEqualCells(He.current,x);if(u&&!nt?it(V,x):pt(V),Y)t.current.scrollTo(Y);else{if(u&&He.current){const I=se();if(e===n.Direction.Right&&He.current.colIndex===I.left||e===n.Direction.Left&&He.current.colIndex===I.right||e===n.Direction.Up&&He.current.rowIndex===I.bottom||e===n.Direction.Down&&He.current.rowIndex===I.top)return}e===n.Direction.Left||e===n.Direction.Right?ht({colIndex:xe.colIndex}):e!==n.Direction.Up&&e!==n.Direction.Down||ht({rowIndex:xe.rowIndex})}},[b,G]),Ot=o.useCallbackRef(e=>{if(!t.current)return;if(b.ranges.length===0)return void Ze(e);const u=G(b.cell);if(n.CoordUtils.isEqualRangesArrays([u],b.ranges))return void Ze(e);const g=Do(b,e,G,Je,Qe);st(h=>{Ae.current=!1,h=yt(h);const x={...h,cell:g.cell,rangeIndex:g.rangeIndex};return n.CoordUtils.isEqualSelectionCoords(x,h)?h:x}),g.cell&&ht(g.cell)},[b,G]),mo=l.useCallback(()=>{const e=se();it({rowIndex:e.top},{rowIndex:e.bottom})},[]),Co=l.useCallback(()=>{const e=se();it({colIndex:e.left},{colIndex:e.right})},[]),Kt=o.useCallbackRef(()=>{b.cell&&t?.current&&ht(b.cell)},[b.cell]),to=l.useCallback((e=!1)=>{const u={rowIndex:se().top};e?it(u):pt(u),ht(u)},[]),oo=l.useCallback((e=!1)=>{const u={rowIndex:se().bottom};e?it(u):pt(u),ht(u)},[]),Gt=l.useCallback((e=!1)=>{const u={colIndex:se().left};e?it(u):pt(u),ht(u)},[]),qt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:u.top,colIndex:u.left};e?it(g):pt(g),ht(g)},[]),_t=l.useCallback((e=!1)=>{const u=se(),g={colIndex:X?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[X]),Wt=l.useCallback((e=!1)=>{const u=se(),g={rowIndex:X?.()?.rowEnd??u.bottom,colIndex:X?.()?.colEnd??u.right};e?it(g):pt(g),ht(g)},[X]),Zt=o.useCallbackRef(e=>{if(!t.current||b.ranges.length<=1)return;const u=e===n.Direction.Left||e===n.Direction.Up;let g=b.rangeIndex+(u?-1:1);g<0?g=b.ranges.length-1:g>b.ranges.length-1&&(g=0);const h=b.ranges[g],x=Do({cell:{rowIndex:h.rowEnd,colIndex:h.colEnd},rangeIndex:0,ranges:[h]},n.Direction.Right,G,Je,Qe);st(k=>{Ae.current=!1,k=yt(k);const m={...k,cell:x.cell,rangeIndex:g};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x.cell&&ht(x.cell)},[b,G]),So=o.useCallbackRef(()=>{const e=Vo(b);st(u=>{Ae.current=!1,u=yt(u);const g={...u,visibleSelection:e};return n.CoordUtils.isEqualSelectionCoords(g,u)?u:g}),e.cell&&ht(e.cell)},[b,G]),bo=o.useCallbackRef(()=>{if(!t.current||b.ranges.length===0)return;const e=b.cell,u=b.ranges[b.rangeIndex],g=Vo({cell:e,rangeIndex:0,ranges:[u]}),h=g.ranges[g.rangeIndex];let x;x=h.rowStart===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowStart,colIndex:h.colEnd}:h.rowStart===e.rowIndex&&h.colEnd===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colStart}:h.rowEnd===e.rowIndex&&h.colStart===e.colIndex?{rowIndex:h.rowEnd,colIndex:h.colEnd}:{rowIndex:h.rowStart,colIndex:h.colStart},st(k=>{k=yt(k);const m={...k,cell:x};return n.CoordUtils.isEqualSelectionCoords(m,k)?k:m}),x&&ht(x)},[b,G]),no=l.useCallback((e=!1)=>{Ze(n.Direction.Down,e,!1,t.current.getDimensions().containerHeight)},[]),Mt=l.useCallback((e=!1)=>{Ze(n.Direction.Up,e,!1,t.current.getDimensions().containerHeight)},[]),ro=l.useCallback((e=!1)=>{Ze(n.Direction.Right,e,!1,t.current.getDimensions().containerWidth)},[]),Jt=l.useCallback((e=!1)=>{Ze(n.Direction.Left,e,!1,t.current.getDimensions().containerWidth)},[]),lo=l.useCallback(()=>{Ot(n.Direction.Left)},[]),io=l.useCallback(()=>{Ot(n.Direction.Right)},[]),vo=l.useCallback(()=>{Ot(n.Direction.Up)},[]),yo=l.useCallback(()=>{Ot(n.Direction.Down)},[]),Qt=l.useCallback(()=>{Zt(n.Direction.Left)},[]),Ro=l.useCallback(()=>{Zt(n.Direction.Right)},[]),Eo=l.useCallback(()=>{bo()},[]),co=l.useCallback(()=>{Ze(n.Direction.Left,!1,!1)},[]),w=l.useCallback(()=>{Ze(n.Direction.Left,!0,!1)},[]),S=l.useCallback(()=>{Ze(n.Direction.Left,!1,!0)},[]),E=l.useCallback(()=>{Ze(n.Direction.Left,!0,!0)},[]),v=l.useCallback(()=>{Ze(n.Direction.Right,!1,!1)},[]),y=l.useCallback(()=>{Ze(n.Direction.Right,!0,!1)},[]),z=l.useCallback(()=>{Ze(n.Direction.Right,!1,!0)},[]),he=l.useCallback(()=>{Ze(n.Direction.Right,!0,!0)},[]),ne=l.useCallback(()=>{Ze(n.Direction.Up,!1,!1)},[]),ae=l.useCallback(()=>{Ze(n.Direction.Up,!0,!1)},[]),F=l.useCallback(()=>{Ze(n.Direction.Up,!1,!0)},[]),Se=l.useCallback(()=>{Ze(n.Direction.Up,!0,!0)},[]),Ke=l.useCallback(()=>{Ze(n.Direction.Down,!1,!1)},[]),Pe=l.useCallback(()=>{Ze(n.Direction.Down,!0,!1)},[]),Ne=l.useCallback(()=>{Ze(n.Direction.Down,!1,!0)},[]),Ee=l.useCallback(()=>{Ze(n.Direction.Down,!0,!0)},[]),le=l.useCallback(()=>{lt(e=>e.slice(0,-1))},[]),et=l.useMemo(()=>{const e=se();return((u,g,h,x,k)=>{const m=u.length;for(let N=0;N<m;N++){const $=u[N];if($.rowStart===g&&$.colStart===h&&$.rowEnd===x&&$.colEnd===k)return!0}return!1})(b.ranges,e.top,e.left,e.bottom,e.right)},[K,b.ranges]),Ye=l.useCallback((e,u=!0)=>{He.current=e,qe(e),u&&e&&t?.current&&ht(e)},[]),Ue=o.useCallbackRef((e=!0)=>{const u=At.current;if(!oe.current?.cell)return;const g=oe.current?.ranges,h=oe.current?.cell;if(!h||!u||!u)return;let x=null;if(x=g.length>0?g[g.length-1]:G(h),x.colEnd>=x.colStart&&x.rowEnd>=x.rowStart){const k=Ho(x,u);let m=e?Pt:P;try{m?.(x,u,k.direction)}catch(N){console.warn(N)}finally{e&&be?.()}}},[G]),Xe=l.useRef(null),ft=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);h&&(e.stopPropagation(),$t("crosshair"),Xe.current={anchor:g.getAnchor(),coords:h})},onPointerMoveOrWait:(e,u)=>{if(re||!t?.current||!oe.current||!Xe.current)return;const g=Xe.current.anchor;let h=t.current.getViewFromLocation(g),x=h.getCellCoordsFromClient(e.clientX,e.clientY);if(!x)return;Xe.current={anchor:g,coords:x};const k=oe.current.ranges;let m=ve(oe.current.cell,x);if(!m)return;const N=k.length>0,$=N?k[k.length-1]:G(oe.current.cell);if(!m)return;const W=m.rowStart<$.rowStart?n.Direction.Up:m.rowEnd>$.rowEnd?n.Direction.Down:m.colEnd>$.colEnd?n.Direction.Right:n.Direction.Left,Y=se();W===n.Direction.Left&&(m={...$,colStart:Math.max(Y.left,m.colStart)}),W===n.Direction.Up&&(m={...$,rowStart:Math.max(Y.top,m.rowStart)}),W===n.Direction.Right&&(m={...$,colEnd:Math.min(Y.right,m.colEnd)}),W===n.Direction.Down&&(m={...$,rowEnd:Math.min(Y.bottom,m.rowEnd)});const xe=Ho($,m);if(!Oe?.($)){let H;typeof Ft.current=="function"?H=Ft.current($):ye&&(H=ye),m=((V,nt,I,fe,wt,de)=>{const ie={...nt};if(I.length===0)return ie;if(wt===n.Direction.Left){const ot=V.colEnd+1-V.colStart;ie.colStart=V.colStart-Math.ceil(de/ot)*ot,ie.colStart<fe.left&&(ie.colStart=ie.colStart+Math.ceil((fe.left-ie.colStart)/ot)*ot)}else if(wt===n.Direction.Right){const ot=V.colEnd+1-V.colStart;ie.colEnd=V.colEnd+Math.ceil(de/ot)*ot,ie.colEnd>fe.right&&(ie.colEnd=ie.colEnd-Math.ceil((fe.right-ie.colEnd)/ot)*ot)}else if(wt===n.Direction.Up){const ot=V.rowEnd+1-V.rowStart;ie.rowStart=V.rowStart-Math.ceil(de/ot)*ot,ie.rowStart<fe.top&&(ie.rowStart=ie.rowStart+Math.ceil((fe.top-ie.rowStart)/ot)*ot)}else if(wt===n.Direction.Down){const ot=V.rowEnd+1-V.rowStart;ie.rowEnd=V.rowEnd+Math.ceil(de/ot)*ot,ie.rowEnd>fe.bottom&&(ie.rowEnd=ie.rowEnd-Math.ceil((fe.bottom-ie.rowEnd)/ot)*ot)}return ie})($,m,H,Y,xe.direction,xe.amount)}if(N&&n.CoordUtils.isRangeWithinRange(m,$)&&(m=null),!n.CoordUtils.isEqualRanges(m,At.current)){if(Xt(m),At.current=m,!m){try{R?.()}catch{}return void be?.()}Ue(!1)}vt.current=u,ho(h,x,t)},onPointerUp:(e,u)=>{vt.current=u,Promise.resolve(Ue(!0)).finally(()=>{be?.(),Xt(null),At.current=null,Xe.current=null,$t(null),t.current?.focus()})}}),[G]),Fe=o.useSynchronizedPointerHandler(ft),J=l.useMemo(()=>({onPointerDown:Fe}),[Fe]),[We,at]=l.useState(null),Ie=l.useRef(null),Ge=l.useMemo(()=>({onPointerDown:(e,u)=>{if(vt.current=u,!t||!t.current)return!1;const g=t.current.getViewFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY),h=g?.getCellCoordsFromClient(e.nativeEvent.clientX,e.nativeEvent.clientY);if(!h)return;if(ge?.(e,h,b)===!1)return!1;e.stopPropagation(),$t("default");const x=g.getRelativePointFromClient(0,0),k=oe.current?.ranges[oe.current?.ranges.length-1]??n.CoordUtils.cellToRange(oe.current?.cell),m=g.toClipBounds(g.getRangeCoordsBounds(k)),N={x:0,y:0};m.x-x.x>e.nativeEvent.clientX?N.x=e.nativeEvent.clientX-(m.x-x.x):e.nativeEvent.clientX>=m.x-x.x+m.width&&(N.x=Math.max(0,e.nativeEvent.clientX-(m.x-x.x+m.width))+1),m.y-x.y>e.nativeEvent.clientY?N.y=e.nativeEvent.clientY-(m.y-x.y):e.nativeEvent.clientY>=m.y-x.y+m.height&&(N.y=Math.max(0,e.nativeEvent.clientY-(m.y-x.y+m.height))+1),ce?.(k,e,u),Ie.current={range:k,anchor:g.getAnchor(),cell:h,isMoving:!1,extrusion:N}},onPointerMoveOrWait:(e,u,g)=>{if(Ve||!t?.current||!oe.current||!Ie.current)return;const h=e.clientX-g.clientX,x=e.clientY-g.clientY;if(Ie.current.isMoving=Ie.current.isMoving||Math.abs(h)>Math.max(1,2)||Math.abs(x)>Math.max(1,2)||performance.now()-g.timeStamp>500,!Ie.current.isMoving)return;const k=Ie.current.anchor,m=Ie.current.extrusion;let N=t.current.getViewFromLocation(k),$=N.getCellCoordsFromClient(e.clientX-m.x,e.clientY-m.y,!0);if(!$)return;const W=Ie.current.cell,Y=Ie.current.range,xe=se(),H=Y.colEnd-Y.colStart+1,V=Math.min(Math.max(0,W.colIndex-Y.colStart),H-1),nt=Math.min(xe.right-H+1,Math.max(xe.left,$.colIndex-V)),I=Y.rowEnd-Y.rowStart+1,fe=Math.min(Math.max(0,W.rowIndex-Y.rowStart),I-1),wt=Math.min(xe.bottom-I+1,Math.max(xe.top,$.rowIndex-fe)),de={colStart:nt,colEnd:nt+H-1,rowStart:wt,rowEnd:wt+I-1};n.CoordUtils.isEqualRanges(We,de)&&!(ie=>!ie||!vt.current||vt.current.ctrlKey!==ie.ctrlKey||vt.current.shiftKey!==ie.shiftKey||vt.current.altKey!==ie.altKey||vt.current.metaKey!==ie.metaKey)(e)||(at(de),pe?.(de,e,u)),vt.current=u,ho(N,$,t)},onPointerUp:(e,u)=>{vt.current=u;const g=()=>{at(null),Ie.current=null,$t(null),t.current?.focus()};if(!Ie.current)return void g();const h=Ie.current.range,x=We;A?.(h,e,u),Promise.resolve(h&&x&&C?.(h,x,e,u)).finally(()=>{g()})}}),[We]),De=o.useSynchronizedPointerHandler(Ge),ke=l.useMemo(()=>({onPointerDown:De}),[De]),dt=l.useRef(null),tt=l.useMemo(()=>{const e=n.CoordUtils.isEqualSelectionCoords(b,dt.current)?dt.current:b;return dt.current=e,e},[b]),gt=l.useCallback(e=>{let u=null,g="br";const h=[],x={stroke:_,fill:L,strokeWidth:.5},k=(H,V,nt)=>{const I=e.toClipBounds(e.getRangeCoordsBounds(H),It);if(!I)return;I.x=I.width>0?I.x:I.x-x.strokeWidth/2,I.y=I.height>0?I.y:I.y-x.strokeWidth/2,I.width=Math.max(I.width,x.strokeWidth),I.height=Math.max(I.height,x.strokeWidth);const fe={key:`selection-fill-${V}`,range:H,...I,...x};if(nt){const wt=e.getCellCoordsAsRangeCoords(nt);fe.cell=nt,fe.pathBounds=e.toClipBounds(e.getRangeCoordsBounds(wt),It),fe.pathBounds&&(fe.pathBounds.width<=0||fe.pathBounds.height<=0)&&(delete fe.pathBounds,delete fe.cell)}return ue(fe)};let m=b?yt(b):null;const N=m?.cell?e.getCellCoordsAsRangeCoords(m?.cell):En;!m||m.ranges&&m.ranges.length!==0||(m={ranges:[N],rangeIndex:0,cell:m.cell});for(let H=0;m&&H<m.ranges.length;H++){const V=m.ranges[H],nt=k(V,H,H===m.rangeIndex?m.cell:null);nt&&h.push(nt);const I=2,fe=.5,wt=e.toClipBounds(e.getRangeCoordsBounds(V,{top:0,left:0,right:0,bottom:0}),It);if(wt){const de=(m.ranges.length,4);h.push(ue({range:V,key:`selection-inside-edge-${H}`,x:wt.x-1,y:wt.y-1,width:Math.max(wt.width+1,0),height:Math.max(wt.height+1,0),style:{overflow:"hidden"},stroke:_,strokeWidth:de}))}if(m.ranges.length===1){const de=e.toClipBounds(e.getRangeCoordsBounds(V),It);if(de){Ve||h.push(ue({range:V,key:`move-selection-hit-box-${H}`,x:de.width>1?de.x:de.x-(me/2+1),y:de.height>1?de.y:de.y-(me/2+1),width:Math.max(de.width+2,1),height:Math.max(de.height+2,1),stroke:"transparent",style:{boxShadow:"none"},pathProps:{cursor:We?void 0:"move",pointerEvents:"stroke"},strokeWidth:me,...ke}));const ie=I;h.push(ue({range:V,key:`selection-single-${H}`,x:de.x-ie/2,y:de.y-ie/2,width:Math.max(de.width+ie/2,1),height:Math.max(de.height+ie/2,1),stroke:j,strokeWidth:ie}))}}else{const de=e.toClipBounds(e.getRangeCoordsBounds(V,{top:-1,left:-1,right:-2,bottom:-2}),It);de&&h.push(ue({range:V,key:`selection-multi-${H}`,x:de.width>1?de.x:de.x-fe/2,y:de.height>1?de.y:de.y-fe/2,width:Math.max(de.width,fe)+1,height:Math.max(de.height,fe)+1,stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(m.ranges.length>1&&H===m.rangeIndex){const de=e.getCellCoordsAsRangeCoords(m.cell),ie=e.toClipBounds(e.getRangeCoordsBounds(de,{top:1,left:1,right:-1,bottom:-1}),It);ie&&h.push(ue({range:V,key:`selection-anchor-${H}`,x:ie.x,y:ie.y,width:Math.max(ie.width,fe),height:Math.max(ie.height,fe),stroke:j,style:{overflow:"hidden"},strokeWidth:2}))}if(H===m.ranges.length-1){u=null,g=null;const de=V.rowStart===se().top&&V.rowEnd===se().bottom,ie=V.colStart===se().left&&V.colEnd===se().right,ot=e.getRangeCoordsBounds(V);let Dt=null;if(de||ie){if(Dt=e.toClipBounds(ot,It),Object.keys(e.allViews()).length>1){const so=e.getVisibleRangeCoords(),$o=e.allViews()[n.AnchorLocation.TopLeft],un=e.allViews()[n.AnchorLocation.Top],hn=e.allViews()[n.AnchorLocation.Left],ao=e.getAnchor();(ie&&(ao===n.AnchorLocation.Top&&$o||ao===n.AnchorLocation.Center&&hn||!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colStart,rowIndex:V.rowEnd+1},so))||de&&(ao===n.AnchorLocation.Left&&$o||ao===n.AnchorLocation.Center&&un||!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd,rowIndex:V.rowStart},so)&&!n.CoordUtils.isCellWithinRange({colIndex:V.colEnd+1,rowIndex:V.rowStart},so)))&&(Dt=null)}}else Dt=e.toClipBounds(ot,It);if(!Dt||Dt.width===0||Dt.height===0)continue;u={x:Dt.x+Dt.width+1,y:Dt.y+Dt.height+1},Dt.width===0||Dt.height===0||V.rowStart===se().top&&V.colStart===se().left&&V.rowEnd===se().bottom&&V.colEnd===se().right||(de?(u.y=I,g="tr"):ie&&(u.x=I,g="bl"))}}let $=null;if(Re){const H=e.toClipBounds(e.getRangeCoordsBounds(Re,{top:0,left:0,right:0,bottom:0}),It);H&&($=ue({...x,range:Re,key:"remove-selection",x:H.x,y:H.y,width:H.width,height:H.height,strokeWidth:2,stroke:St,fill:xt}))}let W=null;if(bt){const H=e.toClipBounds(e.getRangeCoordsBounds(bt,{top:0,left:0,right:0,bottom:0}),It);H&&(W=ue({range:bt,key:"selection-fill-outline",x:H.x-2/2,y:H.y-2/2,width:H.width+2/2,height:H.height+2/2,strokeWidth:2,stroke:j,strokeDasharray:"3 2"}))}let Y=null;!re&&u&&!We&&(Y=l.createElement(Uo,{...u,corner:g,size:7.5,borderStroke:`${_} solid`,style:{borderRadius:1},background:j,...J,key:"fillHandle"}));const xe=[...h];if($&&xe.push($),W&&xe.push(W),Y&&xe.push(Y),!ct&&Rt&&m?.ranges.length===1&&m.ranges[m.ranges.length-1]){const H=m.ranges[m.ranges.length-1],V=H.rowStart===se().top&&H.rowEnd===se().bottom,nt=H.colStart===se().left&&H.colEnd===se().right,I={view:e,range:H,borderStroke:`${j} solid 3px`,background:_,selectionTouchPointerHandler:po,...rt,onTouchSelectStart:fe=>jt(fe),onTouchSelectEnd:()=>jt(null),currentTouchAnchor:eo};xe.push(Q.jsx(fo,{anchor:nt?"b":V?"r":"br",scrollableElement:t.current,...I},"touch-select-handle-after")),xe.push(Q.jsx(fo,{anchor:nt?"t":V?"l":"tl",scrollableElement:t.current,...I},"touch-select-handle-before"))}if(We){const H=e.toClipBounds(e.getRangeCoordsBounds(We,{top:1,left:1,right:1,bottom:1}),It);H&&xe.push(ue({range:We,key:"selection-move-outline",x:H.x-q/2,y:H.y-q/2,width:Math.max(H.width+q/2,1),height:Math.max(H.height+q/2,1),stroke:j,style:{boxShadow:"none",transitionDuration:"70ms",transitionTimingFunction:"ease-in",transitionProperty:"left, top, width, height",willChange:"left, top, width, height"},strokeWidth:q}))}return Q.jsx("div",{children:xe},"selection")},[tt,Re,re,bt,Ve,We,se,_,j,L,St,xt,ct,rt,eo]),Et=l.useMemo(()=>{const e=()=>t.current;return[new o.SimpleCommand("moveToPageDown",e,{label:"Page Down",description:"Shift viewport down one page.",shortcut:[{key:"PageDown"}]},()=>no(!1)),new o.SimpleCommand("selectToPageDown",e,{label:"Select To Page Down",description:"Shift viewport and select down one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Shift]}]},()=>no(!0)),new o.SimpleCommand("moveToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt]}]},()=>ro(!1)),new o.SimpleCommand("selectToPageRight",e,{label:"Page Right",description:"Shift viewport right one page.",shortcut:[{key:"PageDown",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>ro(!0)),new o.SimpleCommand("moveToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp"}]},()=>Mt(!1)),new o.SimpleCommand("selectToPageUp",e,{label:"Page Up",description:"Shift viewport up one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Shift]}]},()=>Mt(!0)),new o.SimpleCommand("moveToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt]}]},()=>Jt(!1)),new o.SimpleCommand("selectToPageLeft",e,{label:"Page Left",description:"Shift viewport left one page.",shortcut:[{key:"PageUp",modifiers:[o.KeyModifiers.Alt,o.KeyModifiers.Shift]}]},()=>Jt(!0)),new o.SimpleCommand("selectColumn",e,{label:"Select Column",description:"Select the columns for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Ctrl]}},mo),new o.SimpleCommand("selectRow",e,{label:"Select Row",description:"Select the rows for the selected cells.",shortcut:{key:"Space",modifiers:[o.KeyModifiers.Shift]}},Co),new o.SimpleCommand("selectToColumnStart",e,{label:"Select To Column Start",description:"Select the columns to the beginning of the sheet."},()=>to(!0)),new o.SimpleCommand("selectToColumnEnd",e,{label:"Select To Column End",description:"Select the columns to the end of the sheet."},()=>oo(!0)),new o.SimpleCommand("moveToRowStart",e,{label:"Move to Row Home",description:"Move to the beginning of the row.",shortcut:[{key:"Home"}]},()=>Gt(!1)),new o.SimpleCommand("selectToRowStart",e,{label:"Select to Row Home",description:"Select to the beginning of the row.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Shift]}]},()=>Gt(!0)),new o.SimpleCommand("moveToSheetStart",e,{label:"Move to Sheet Home",description:"Move to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl]}]},()=>qt(!1)),new o.SimpleCommand("selectToSheetStart",e,{label:"Select to Sheet Home",description:"Select to the beginning of the sheet.",shortcut:[{key:"Home",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>qt(!0)),new o.SimpleCommand("moveToRowEnd",e,{label:"Move to Row End",description:"Move to the end of the row.",shortcut:[{key:"End"}]},()=>_t(!1)),new o.SimpleCommand("selectToRowEnd",e,{label:"Select to Row End",description:"Select to the end of the row.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Shift]}]},()=>_t(!0)),new o.SimpleCommand("moveToSheetEnd",e,{label:"Move to Sheet End",description:"Move to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl]}]},()=>Wt(!1)),new o.SimpleCommand("selectToSheetEnd",e,{label:"Select to Sheet End",description:"Select to the end of the sheet.",shortcut:[{key:"End",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},()=>Wt(!0)),new o.SimpleCommand("scrollToActiveCoords",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Ctrl]}},Kt),new o.SimpleCommand("scrollToActiveCoordsClearSelection",e,{label:"Scroll to Active Cell",description:"Scroll to the Active Cell and clear selection.",shortcut:{key:"Backspace",modifiers:[o.KeyModifiers.Shift]}},()=>{Bt(),Ye(b.cell,!0)}),new o.SimpleCommand("traverseSelectionRight",e,{label:"Traverse Right",description:"Traverse the selection moving rightward.",shortcut:{key:"Tab"}},io),new o.SimpleCommand("traverseSelectionLeft",e,{label:"Traverse Left",description:"Traverse the selection moving leftward.",shortcut:{key:"Tab",modifiers:[o.KeyModifiers.Shift]}},lo),new o.SimpleCommand("traverseSelectionDown",e,{label:"Traverse Down",description:"Traverse the selection moving downward.",shortcut:[{key:"Enter"},{key:"NumpadEnter"}]},yo),new o.SimpleCommand("traverseSelectionUp",e,{label:"Traverse Up",description:"Traverse the selection moving upward.",shortcut:[{key:"Enter",modifiers:[o.KeyModifiers.Shift]},{key:"NumpadEnter",modifiers:[o.KeyModifiers.Shift]}]},vo),new o.SimpleCommand("moveLeft",e,{label:"Move Left",description:"Move active cell to the left.",shortcut:[{key:"ArrowLeft"}]},co),new o.SimpleCommand("selectLeft",e,{label:"Select Left",description:"Extend selection left.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Shift]}]},w),new o.SimpleCommand("moveContentfulLeft",e,{label:"Move Left Contentful",description:"Move left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl]}]},S),new o.SimpleCommand("selectContentfulLeft",e,{label:"Select Left Contentful",description:"Extend selection left to the next cell with content.",shortcut:[{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},E),new o.SimpleCommand("moveRight",e,{label:"Move Right",description:"Move active cell to the right.",shortcut:[{key:"ArrowRight"}]},v),new o.SimpleCommand("selectRight",e,{label:"Select Right",description:"Extend selection right.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Shift]}]},y),new o.SimpleCommand("moveContentfulRight",e,{label:"Move Right Contentful",description:"Move right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl]}]},z),new o.SimpleCommand("selectContentfulRight",e,{label:"Select Right Contentful",description:"Extend selection right to the next cell with content.",shortcut:[{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},he),new o.SimpleCommand("moveUp",e,{label:"Move Up",description:"Move active cell to the up.",shortcut:[{key:"ArrowUp"}]},ne),new o.SimpleCommand("selectUp",e,{label:"Select Up",description:"Extend selection up.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Shift]}]},ae),new o.SimpleCommand("moveContentfulUp",e,{label:"Move Up Contentful",description:"Move up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl]}]},F),new o.SimpleCommand("selectContentfulUp",e,{label:"Select Up Contentful",description:"Extend selection up to the next cell with content.",shortcut:[{key:"ArrowUp",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Se),new o.SimpleCommand("moveDown",e,{label:"Move Down",description:"Move active cell to the down.",shortcut:[{key:"ArrowDown"}]},Ke),new o.SimpleCommand("selectDown",e,{label:"Select Down",description:"Extend selection down.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Shift]}]},Pe),new o.SimpleCommand("moveContentfulDown",e,{label:"Move Down Contentful",description:"Move down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl]}]},Ne),new o.SimpleCommand("selectContentfulDown",e,{label:"Select Down Contentful",description:"Extend selection down to the next cell with content.",shortcut:[{key:"ArrowDown",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Shift]}]},Ee),new o.SimpleCommand("selectVisible",e,{label:"Select Visible",description:"Select visible cells only.",shortcut:{key:";",modifiers:[o.KeyModifiers.Alt]}},So),new o.SimpleCommand("traverseSelectionPreviousRange",e,{label:"Traverse Previous Range",description:"Traverse the selection to the previous range.",shortcut:{key:"ArrowLeft",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Qt),new o.SimpleCommand("traverseSelectionNextRange",e,{label:"Traverse Next Range",description:"Traverse the selection to the next range.",shortcut:{key:"ArrowRight",modifiers:[o.KeyModifiers.Ctrl,o.KeyModifiers.Alt]}},Ro),new o.SimpleCommand("traverseSelectionCorners",e,{label:"Traverse Corners",description:"Traverse the selection through the corners of the selected range.",shortcut:{key:".",modifiers:[o.KeyModifiers.Ctrl]}},Eo)]},[]);return l.useMemo(()=>{r?.addCommands(Et,!0)},[r]),{selection:tt,setSelectionCell:Ye,setSelectionRanges:lt,overlay:gt,cursor:Ht,onPointerDown:xo,clearLastSelection:le,newSelection:pt,modifySelection:it,appendSelection:Ce,clearSelections:Bt,isEntire:et,navigate:Ze,navigateSelection:Ot}};
@@ -5,7 +5,7 @@ import { useRef as se, useReducer as Zn, useState as gt, useEffect as It, useCal
5
5
  import { CoordUtils as F, CommonUtils as Nt, RangeOrientation as Ht, Direction as g, AnchorLocation as Qe } from "@sheetxl/utils";
6
6
  import { createPortal as xo } from "react-dom";
7
7
  /**
8
- * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.14
8
+ * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.16
9
9
  *
10
10
  * (C) 2025-present SheetXL Inc. & Michael T. Ford
11
11
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -586,7 +586,7 @@ var Xo = parseInt(zo.split(".")[0], 10) >= 19 ? function(t) {
586
586
  };
587
587
  };
588
588
  const Go = X.detectIt().supportsTouchEvents, Xn = Kt(tn((t, n) => {
589
- const { range: o, view: r, anchor: c, borderStroke: d = "rgb(33, 115, 70)", background: i = "white", borderWidth: l = 1.5, size: w = 22, style: L, className: O, selectionTouchPointerHandler: R, onTouchSelectStart: M, onTouchSelectEnd: A, currentTouchAnchor: le, scrollableElement: J, scrollableRoot: te, ...ze } = t;
589
+ const { range: o, view: r, anchor: c, borderStroke: d = "var(--sxl-app-color-primary, rgb(33, 115, 70))", background: i = "var(--sxl-app-color-background, white)", borderWidth: l = 3, size: w = 22, style: L, className: O, selectionTouchPointerHandler: R, onTouchSelectStart: M, onTouchSelectEnd: A, currentTouchAnchor: le, scrollableElement: J, scrollableRoot: te, ...ze } = t;
590
590
  if (!Go) return null;
591
591
  const Q = P(M, [M]), T = P(A, [A]), { bounds: _, coordsPivot: ve, key: W } = Ae(() => {
592
592
  if (!o || !r) return null;
@@ -748,7 +748,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
748
748
  return !1;
749
749
  const E = e.nativeEvent.shiftKey, x = e.nativeEvent.ctrlKey || e.nativeEvent.metaKey, j = x, B = L, H = v.ranges.length > 0, G = x && B;
750
750
  if (me?.(e, a, v) === !1) return !1;
751
- d?.(oe.current, e.nativeEvent);
751
+ d?.(oe.current, e);
752
752
  const Se = !f && l !== "single";
753
753
  if (E) return ft(a), Se;
754
754
  const K = F.isEqualCells(a, v.cell);
@@ -821,7 +821,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
821
821
  return !1;
822
822
  const Se = e.nativeEvent.ctrlKey || e.nativeEvent.metaKey, K = Se, N = L, dt = v.ranges.length > 0, I = Se && N;
823
823
  if (me?.(e, H, v) === !1) return !1;
824
- d?.(oe.current, e.nativeEvent);
824
+ d?.(oe.current, e);
825
825
  const pe = !G && l !== "single";
826
826
  if (x) return ft(H, f, j), pe;
827
827
  const Ct = F.isEqualCells(H, f);
@@ -836,7 +836,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
836
836
  }
837
837
  E && St(H), Ct && v.ranges.length === 0 || Rt(H);
838
838
  }, onSelectionPointerMoveOrWait: (e, s, u, a, f, E = v.cell, x = !0, j = !1) => {
839
- if (!t?.current || (e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation(), !ot.current)) return;
839
+ if (!t?.current || (e.stopPropagation(), e.preventDefault(), e.nativeEvent.stopImmediatePropagation(), !ot.current)) return;
840
840
  const B = ot.current.anchor;
841
841
  let H = a ?? t.current.getViewFromLocation(B), G = f ?? H.getCellCoordsFromClient(e.clientX, e.clientY);
842
842
  if (!F.isEqualCells(G, ot.current?.coords) && (ot.current = { anchor: B, coords: G }, G && Ve?.(e, G, oe.current) !== !1)) {
@@ -849,7 +849,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
849
849
  x && Tn(H, G, t);
850
850
  }
851
851
  }, onPointerUp: (e) => {
852
- ot.current = null, e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
852
+ ot.current = null, e.stopPropagation(), e.preventDefault(), e.nativeEvent.stopImmediatePropagation();
853
853
  try {
854
854
  i?.(oe.current, e);
855
855
  } catch (u) {
@@ -1171,7 +1171,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
1171
1171
  if (me?.(e, a, v) === !1) return !1;
1172
1172
  e.stopPropagation(), _t("default");
1173
1173
  const f = u.getRelativePointFromClient(0, 0), E = oe.current?.ranges[oe.current?.ranges.length - 1] ?? F.cellToRange(oe.current?.cell), x = u.toClipBounds(u.getRangeCoordsBounds(E)), j = { x: 0, y: 0 };
1174
- x.x - f.x > e.nativeEvent.clientX ? j.x = e.nativeEvent.clientX - (x.x - f.x) : e.nativeEvent.clientX >= x.x - f.x + x.width && (j.x = Math.max(0, e.nativeEvent.clientX - (x.x - f.x + x.width)) + 1), x.y - f.y > e.nativeEvent.clientY ? j.y = e.nativeEvent.clientY - (x.y - f.y) : e.nativeEvent.clientY >= x.y - f.y + x.height && (j.y = Math.max(0, e.nativeEvent.clientY - (x.y - f.y + x.height)) + 1), ue?.(E, e.nativeEvent, s), De.current = { range: E, anchor: u.getAnchor(), cell: a, isMoving: !1, extrusion: j };
1174
+ x.x - f.x > e.nativeEvent.clientX ? j.x = e.nativeEvent.clientX - (x.x - f.x) : e.nativeEvent.clientX >= x.x - f.x + x.width && (j.x = Math.max(0, e.nativeEvent.clientX - (x.x - f.x + x.width)) + 1), x.y - f.y > e.nativeEvent.clientY ? j.y = e.nativeEvent.clientY - (x.y - f.y) : e.nativeEvent.clientY >= x.y - f.y + x.height && (j.y = Math.max(0, e.nativeEvent.clientY - (x.y - f.y + x.height)) + 1), ue?.(E, e, s), De.current = { range: E, anchor: u.getAnchor(), cell: a, isMoving: !1, extrusion: j };
1175
1175
  }, onPointerMoveOrWait: (e, s, u) => {
1176
1176
  if (Xe || !t?.current || !oe.current || !De.current) return;
1177
1177
  const a = e.clientX - u.clientX, f = e.clientY - u.clientY;
@@ -1261,7 +1261,7 @@ const Vt = -10, _o = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
1261
1261
  !le && s && !Ye && (G = wo(yo, { ...s, corner: u, size: 7.5, borderStroke: `${J} solid`, style: { borderRadius: 1 }, background: q, ...ee, key: "fillHandle" }));
1262
1262
  const Se = [...a];
1263
1263
  if (B && Se.push(B), H && Se.push(H), G && Se.push(G), !wt && zt && x?.ranges.length === 1 && x.ranges[x.ranges.length - 1]) {
1264
- const K = x.ranges[x.ranges.length - 1], N = K.rowStart === he().top && K.rowEnd === he().bottom, dt = K.colStart === he().left && K.colEnd === he().right, I = { view: e, range: K, borderStroke: `${q} solid`, background: J, selectionTouchPointerHandler: Ln, ...ut, onTouchSelectStart: (pe) => cn(pe), onTouchSelectEnd: () => cn(null), currentTouchAnchor: vn };
1264
+ const K = x.ranges[x.ranges.length - 1], N = K.rowStart === he().top && K.rowEnd === he().bottom, dt = K.colStart === he().left && K.colEnd === he().right, I = { view: e, range: K, borderStroke: `${q} solid 3px`, background: J, selectionTouchPointerHandler: Ln, ...ut, onTouchSelectStart: (pe) => cn(pe), onTouchSelectEnd: () => cn(null), currentTouchAnchor: vn };
1265
1265
  Se.push(Ce(Xn, { anchor: dt ? "b" : N ? "r" : "br", scrollableElement: t.current, ...I }, "touch-select-handle-after")), Se.push(Ce(Xn, { anchor: dt ? "t" : N ? "l" : "tl", scrollableElement: t.current, ...I }, "touch-select-handle-before"));
1266
1266
  }
1267
1267
  if (Ye) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.14
2
+ * @license @sheetxl/grid-react - Grid React - Advanced grid component for React - v0.7.16
3
3
  *
4
4
  * (C) 2025-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -574,7 +574,7 @@ const xe = C(I((t2, n2) => {
574
574
  }));
575
575
  xe.displayName = "FillHandle";
576
576
  const pe = i.detectIt().supportsTouchEvents, me = C(I((r2, l2) => {
577
- const { range: i2, view: c2, anchor: a2, borderStroke: h2 = "rgb(33, 115, 70)", background: g2 = "white", borderWidth: f2 = 1.5, size: w2 = 22, style: p2, className: S2, selectionTouchPointerHandler: y2, onTouchSelectStart: C2, onTouchSelectEnd: I2, currentTouchAnchor: E2, scrollableElement: R2, scrollableRoot: M2, ...P2 } = r2;
577
+ const { range: i2, view: c2, anchor: a2, borderStroke: h2 = "var(--sxl-app-color-primary, rgb(33, 115, 70))", background: g2 = "var(--sxl-app-color-background, white)", borderWidth: f2 = 3, size: w2 = 22, style: p2, className: S2, selectionTouchPointerHandler: y2, onTouchSelectStart: C2, onTouchSelectEnd: I2, currentTouchAnchor: E2, scrollableElement: R2, scrollableRoot: M2, ...P2 } = r2;
578
578
  if (!pe) return null;
579
579
  const T2 = o(C2, [C2]), D2 = o(I2, [I2]), { bounds: O2, coordsPivot: z2, key: L2 } = b(() => {
580
580
  if (!i2 || !c2) return null;
@@ -738,7 +738,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
738
738
  }
739
739
  const i2 = e2.nativeEvent.shiftKey, s2 = e2.nativeEvent.ctrlKey || e2.nativeEvent.metaKey, a3 = s2, u3 = p2, h2 = $e2.ranges.length > 0, g2 = s2 && u3;
740
740
  if (false === U2?.(e2, r3, $e2)) return false;
741
- d2?.(Be2.current, e2.nativeEvent);
741
+ d2?.(Be2.current, e2);
742
742
  const w3 = !l3 && "single" !== f2;
743
743
  if (i2) return rt(r3), w3;
744
744
  const x2 = P.isEqualCells(r3, $e2.cell);
@@ -816,7 +816,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
816
816
  }
817
817
  const w3 = e2.nativeEvent.ctrlKey || e2.nativeEvent.metaKey, x2 = w3, m2 = p2, v2 = $e2.ranges.length > 0, S2 = w3 && m2;
818
818
  if (false === U2?.(e2, h2, $e2)) return false;
819
- d2?.(Be2.current, e2.nativeEvent);
819
+ d2?.(Be2.current, e2);
820
820
  const y2 = !g2 && "single" !== f2;
821
821
  if (s2) return rt(h2, l3, a3), y2;
822
822
  const b2 = P.isEqualCells(h2, l3);
@@ -834,7 +834,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
834
834
  i2 && et(h2), b2 && 0 === $e2.ranges.length || lt(h2);
835
835
  }, onSelectionPointerMoveOrWait: (e2, n3, o2, r3, l3, i2 = $e2.cell, c2 = true, s2 = false) => {
836
836
  if (!t2?.current) return;
837
- if (e2.stopPropagation(), e2.preventDefault(), e2.stopImmediatePropagation(), !at.current) return;
837
+ if (e2.stopPropagation(), e2.preventDefault(), e2.nativeEvent.stopImmediatePropagation(), !at.current) return;
838
838
  const a3 = at.current.anchor;
839
839
  let d3 = r3 ?? t2.current.getViewFromLocation(a3), u3 = l3 ?? d3.getCellCoordsFromClient(e2.clientX, e2.clientY);
840
840
  if (!P.isEqualCells(u3, at.current?.coords) && (at.current = { anchor: a3, coords: u3 }, u3 && false !== H2?.(e2, u3, Be2.current))) {
@@ -847,7 +847,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
847
847
  c2 && Ie(d3, u3, t2);
848
848
  }
849
849
  }, onPointerUp: (e2) => {
850
- at.current = null, e2.stopPropagation(), e2.preventDefault(), e2.stopImmediatePropagation();
850
+ at.current = null, e2.stopPropagation(), e2.preventDefault(), e2.nativeEvent.stopImmediatePropagation();
851
851
  try {
852
852
  u2?.(Be2.current, e2);
853
853
  } catch (e3) {
@@ -1172,7 +1172,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
1172
1172
  if (false === U2?.(e2, r3, $e2)) return false;
1173
1173
  e2.stopPropagation(), Ue2("default");
1174
1174
  const l3 = o2.getRelativePointFromClient(0, 0), i2 = Be2.current?.ranges[Be2.current?.ranges.length - 1] ?? P.cellToRange(Be2.current?.cell), c2 = o2.toClipBounds(o2.getRangeCoordsBounds(i2)), s2 = { x: 0, y: 0 };
1175
- c2.x - l3.x > e2.nativeEvent.clientX ? s2.x = e2.nativeEvent.clientX - (c2.x - l3.x) : e2.nativeEvent.clientX >= c2.x - l3.x + c2.width && (s2.x = Math.max(0, e2.nativeEvent.clientX - (c2.x - l3.x + c2.width)) + 1), c2.y - l3.y > e2.nativeEvent.clientY ? s2.y = e2.nativeEvent.clientY - (c2.y - l3.y) : e2.nativeEvent.clientY >= c2.y - l3.y + c2.height && (s2.y = Math.max(0, e2.nativeEvent.clientY - (c2.y - l3.y + c2.height)) + 1), q2?.(i2, e2.nativeEvent, n3), gn.current = { range: i2, anchor: o2.getAnchor(), cell: r3, isMoving: false, extrusion: s2 };
1175
+ c2.x - l3.x > e2.nativeEvent.clientX ? s2.x = e2.nativeEvent.clientX - (c2.x - l3.x) : e2.nativeEvent.clientX >= c2.x - l3.x + c2.width && (s2.x = Math.max(0, e2.nativeEvent.clientX - (c2.x - l3.x + c2.width)) + 1), c2.y - l3.y > e2.nativeEvent.clientY ? s2.y = e2.nativeEvent.clientY - (c2.y - l3.y) : e2.nativeEvent.clientY >= c2.y - l3.y + c2.height && (s2.y = Math.max(0, e2.nativeEvent.clientY - (c2.y - l3.y + c2.height)) + 1), q2?.(i2, e2, n3), gn.current = { range: i2, anchor: o2.getAnchor(), cell: r3, isMoving: false, extrusion: s2 };
1176
1176
  }, onPointerMoveOrWait: (e2, n3, o2) => {
1177
1177
  if (Z2 || !t2?.current || !Be2.current || !gn.current) return;
1178
1178
  const r3 = e2.clientX - o2.clientX, l3 = e2.clientY - o2.clientY;
@@ -1268,7 +1268,7 @@ const ve = -10, Se = Object.freeze({ rowStart: 0, colStart: 0, rowEnd: 0, colEnd
1268
1268
  !k2 && o2 && !un && (h2 = E(xe, { ...o2, corner: r3, size: 7.5, borderStroke: `${D2} solid`, style: { borderRadius: 1 }, background: oe2, ...dn, key: "fillHandle" }));
1269
1269
  const g2 = [...l3];
1270
1270
  if (d3 && g2.push(d3), u3 && g2.push(u3), h2 && g2.push(h2), !de2 && st && 1 === s2?.ranges.length && s2.ranges[s2.ranges.length - 1]) {
1271
- const o3 = s2.ranges[s2.ranges.length - 1], r4 = o3.rowStart === he2().top && o3.rowEnd === he2().bottom, l4 = o3.colStart === he2().left && o3.colEnd === he2().right, i3 = { view: n3, range: o3, borderStroke: `${oe2} solid`, background: D2, selectionTouchPointerHandler: ft, ...ue2, onTouchSelectStart: (e2) => Ze(e2), onTouchSelectEnd: () => Ze(null), currentTouchAnchor: Ge2 };
1271
+ const o3 = s2.ranges[s2.ranges.length - 1], r4 = o3.rowStart === he2().top && o3.rowEnd === he2().bottom, l4 = o3.colStart === he2().left && o3.colEnd === he2().right, i3 = { view: n3, range: o3, borderStroke: `${oe2} solid 3px`, background: D2, selectionTouchPointerHandler: ft, ...ue2, onTouchSelectStart: (e2) => Ze(e2), onTouchSelectEnd: () => Ze(null), currentTouchAnchor: Ge2 };
1272
1272
  g2.push(e(me, { anchor: l4 ? "b" : r4 ? "r" : "br", scrollableElement: t2.current, ...i3 }, "touch-select-handle-after")), g2.push(e(me, { anchor: l4 ? "t" : r4 ? "l" : "tl", scrollableElement: t2.current, ...i3 }, "touch-select-handle-before"));
1273
1273
  }
1274
1274
  if (un) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/grid-react",
3
3
  "description": "Grid React - Advanced grid component for React",
4
- "version": "0.7.14",
4
+ "version": "0.7.16",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -41,8 +41,8 @@
41
41
  "table"
42
42
  ],
43
43
  "dependencies": {
44
- "@sheetxl/utils": "^0.7.14",
45
- "@sheetxl/utils-react": "^0.7.14",
44
+ "@sheetxl/utils": "^0.7.16",
45
+ "@sheetxl/utils-react": "^0.7.16",
46
46
  "clsx": "^2.1.1",
47
47
  "react-merge-refs": "^3.0.2",
48
48
  "react-use": "^17.6.0",
package/types/index.d.ts CHANGED
@@ -906,7 +906,7 @@ export declare const SELECTION_CLIP_INSETS = -10;
906
906
 
907
907
  export declare interface SelectionPointerHandlerOptions extends Omit<PointerHandlerOptions, "onPointerDown" | "onPointerMoveOrWait"> {
908
908
  onSelectionPointerDown: (event: default_2.PointerEvent<Element>, modifiers: PointerModifiers, view?: GridView, coords?: CellCoords, pivotCoords?: CellCoords, extendSelection?: boolean, scrollToAnchor?: boolean, resetCellAnchor?: boolean) => boolean | void;
909
- onSelectionPointerMoveOrWait?: (event: globalThis.PointerEvent, modifiers: PointerModifiers, originalEvent: default_2.PointerEvent<Element>, view?: GridView, coords?: CellCoords, pivotCoords?: CellCoords, scrollToAnchor?: boolean, resetCellAnchor?: boolean) => void;
909
+ onSelectionPointerMoveOrWait?: (event: default_2.PointerEvent<Element>, modifiers: PointerModifiers, originalEvent: default_2.PointerEvent<Element>, view?: GridView, coords?: CellCoords, pivotCoords?: CellCoords, scrollToAnchor?: boolean, resetCellAnchor?: boolean) => void;
910
910
  }
911
911
 
912
912
  export declare type SelectionPolicy = "single" | "range" | "multiple";
@@ -940,7 +940,7 @@ export declare interface SelectionResults {
940
940
  /**
941
941
  * Handler for pointerdown, use to set activeCoords
942
942
  */
943
- onPointerDown: (e: default_2.PointerEvent<HTMLDivElement>) => void;
943
+ onPointerDown: (e: default_2.PointerEvent) => void;
944
944
  /**
945
945
  * Returns a flag indicating if the entire range is selected
946
946
  */
@@ -1178,11 +1178,11 @@ export declare interface UseHeaderSelectionOptions {
1178
1178
  /**
1179
1179
  * Pointer Move Interceptor
1180
1180
  */
1181
- pointerMoveInterceptor?: (e: globalThis.PointerEvent, coords: CellCoords) => boolean | undefined;
1181
+ pointerMoveInterceptor?: (e: default_2.PointerEvent, coords: CellCoords) => boolean | undefined;
1182
1182
  /**
1183
1183
  * Pointer Up Listener
1184
1184
  */
1185
- onPointerUp?: (e: globalThis.PointerEvent) => void;
1185
+ onPointerUp?: (e: default_2.PointerEvent) => void;
1186
1186
  /**
1187
1187
  * Returns true if the coordinate span can overlap merged ranges.
1188
1188
  * @param start
@@ -1330,11 +1330,11 @@ export declare interface UseSelectionOptions {
1330
1330
  /**
1331
1331
  * Callback at the start of selection change driven by the pointer.
1332
1332
  */
1333
- onSelectionDragStart?: (selection: SelectionCoords, e: globalThis.PointerEvent) => void;
1333
+ onSelectionDragStart?: (selection: SelectionCoords, e: default_2.PointerEvent<Element>) => void;
1334
1334
  /**
1335
1335
  * Callback at the end of selection change driven by the pointer.
1336
1336
  */
1337
- onSelectionDragEnd?: (selection: SelectionCoords, e: globalThis.PointerEvent) => void;
1337
+ onSelectionDragEnd?: (selection: SelectionCoords, e: default_2.PointerEvent<Element>) => void;
1338
1338
  /**
1339
1339
  * Allow deselect a selected area
1340
1340
  */
@@ -1376,7 +1376,7 @@ export declare interface UseSelectionOptions {
1376
1376
  * pointerDownInterceptor
1377
1377
  */
1378
1378
  pointerDownInterceptor?: (e: default_2.PointerEvent<Element>, coords: CellCoords, selection: SelectionCoords) => boolean | undefined;
1379
- pointerMoveInterceptor?: (e: globalThis.PointerEvent, coords: CellCoords, selection: SelectionCoords) => boolean | undefined;
1379
+ pointerMoveInterceptor?: (e: default_2.PointerEvent<Element>, coords: CellCoords, selection: SelectionCoords) => boolean | undefined;
1380
1380
  /**
1381
1381
  * Is the current selection able to intersect merged cells.
1382
1382
  */
@@ -1407,19 +1407,19 @@ export declare interface UseSelectionOptions {
1407
1407
  /**
1408
1408
  * Callback at the start of selection change driven by the pointer.
1409
1409
  */
1410
- onMoveDragStart?: (from: RangeCoords, e: globalThis.PointerEvent, modifiers: PointerModifiers) => void;
1410
+ onMoveDragStart?: (from: RangeCoords, e: default_2.PointerEvent<Element>, modifiers: PointerModifiers) => void;
1411
1411
  /**
1412
1412
  * Callback at the start of selection change driven by the pointer.
1413
1413
  */
1414
- onMoveDragUpdate?: (from: RangeCoords, e: globalThis.PointerEvent, modifiers: PointerModifiers) => void;
1414
+ onMoveDragUpdate?: (from: RangeCoords, e: default_2.PointerEvent<Element>, modifiers: PointerModifiers) => void;
1415
1415
  /**
1416
1416
  * Callback at the end of selection change driven by the pointer.
1417
1417
  */
1418
- onMoveDragEnd?: (from: RangeCoords, e: globalThis.PointerEvent, modifiers: PointerModifiers) => void;
1418
+ onMoveDragEnd?: (from: RangeCoords, e: default_2.PointerEvent<Element>, modifiers: PointerModifiers) => void;
1419
1419
  /**
1420
1420
  * When selection is moved.
1421
1421
  */
1422
- onMoveDragDone?: (from: RangeCoords, to: RangeCoords, event: globalThis.PointerEvent, modifiers: PointerModifiers) => Promise<void>;
1422
+ onMoveDragDone?: (from: RangeCoords, to: RangeCoords, event: default_2.PointerEvent<Element>, modifiers: PointerModifiers) => Promise<void>;
1423
1423
  /**
1424
1424
  * Disable fill drag.
1425
1425
  * @defaultValue to a value based on if onFill is provided.