@aiquants/spreadsheet 0.20.2 → 0.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ut=require("./tsv.cjs"),ze=require("./view-BkwCUzTl.cjs"),rt=require("@aiquants/virtualscroll"),U=require("react/jsx-runtime"),i=require("react"),Ms=1e3,dn=1e4,Ns=10,Ul=2**(1/4),td=(e,t)=>e<=0?e:t>0?e>=dn?e:Math.min(dn,Math.max(e+1,Math.round(e*Ul))):Math.max(1,Math.min(e-1,Math.round(e/Ul))),Xl=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),Fs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Ns):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),dn))}let l=[...s].map(([a,p])=>({index:a,size:p}));if(e.count-e.hiddenCount()-Xl(e,l)===0){const a=n===null?l[0].index:n;l=l.map(p=>p.index===a?{index:p.index,size:1}:p)}if(r.axisKind==="row"){const a=e.hiddenCount()+Xl(e,l);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:l}},Ps="#000000",Hr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},nd=20,rd=256,Br=new Map,Xo=new WeakMap,gt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},od=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},sd=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:nd}:Hr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Hr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Hr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Hr(e.decimals)};default:return null}},ld=e=>{const t=Xo.get(e);if(t!==void 0)return t;const n=JSON.stringify([e.type,e.locale??null,e.decimals===void 0?null:String(e.decimals),e.type==="number"?e.grouping??!1:null,e.type==="currency"?e.currency:null]),r=Br.get(n);if(r!==void 0)return Xo.set(e,r),r;Br.size>=rd&&Br.clear();const o=sd(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Br.set(n,s),Xo.set(e,s),s},id=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Sc=e=>{const t=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>id(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},cd=(e,t)=>{const n=Sc(e);if(n===null)return e;const r=(o,s)=>String(o).padStart(s,"0");return t.replace(/yyyy|MM|dd|HH|mm|ss/g,o=>{switch(o){case"yyyy":return r(n.year,4);case"MM":return r(n.month,2);case"dd":return r(n.day,2);case"HH":return r(n.hour,2);case"mm":return r(n.minute,2);default:return r(n.second,2)}})},Xn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return cd(e,t.pattern??"yyyy/MM/dd");const n=gt(e);if(n===null)return e;const r=ld(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?od(n,-2):n)},Gl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Sc(n)!==null?"right":"left":gt(n)!==null?"right":"left",Rr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",kc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],ad=["bottom","left","right","top"],Ec=(e,t,n)=>{e[t]=n},Oc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},ud=e=>{if(e===void 0)return;const t={};for(const n of ad){const r=e[n];r!==void 0&&(t[n]=Oc(r))}return Object.keys(t).length===0?void 0:t},xt=e=>{const t={};for(const n of kc){const r=n==="borders"?ud(e.borders):n==="value"?e.value===void 0?void 0:Oc(e.value):e[n];r!==void 0&&r!==!1&&Ec(t,n,r)}return Object.keys(t).length===0?void 0:t},_s=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;const o=e,s=t;for(let l=0;l<n.length;l+=1){const c=n[l];if(c!==r[l]||!_s(o[c],s[c]))return!1}return!0},dd=(e,t)=>e===t?!0:_s(e===void 0?void 0:xt(e),t===void 0?void 0:xt(t)),qs=(e,t)=>{const n={};for(const o of kc){const s=t[o];Ec(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=xt(n);return _s(r,e===void 0?void 0:xt(e))?e:r},Ac="data-aqsp-clip",po="application/x-aqsp-clip",gs=512,Zl=16*1024,ws=`${Ac}=`,fd=16,js=()=>{const e=globalThis.crypto;if(e===void 0||typeof e.getRandomValues!="function")throw new RangeError("[spreadsheet] newClipId requires crypto.getRandomValues — there is no counter or randomUUID substitute by design");const t=e.getRandomValues(new Uint8Array(fd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},xr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),fe=e=>typeof e=="string",tt=e=>typeof e=="boolean",ln=e=>typeof e=="number"&&Number.isFinite(e),At=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Jl=e=>At(e)&&e>=1,pd=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=dn,Kt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},hd=e=>t=>Array.isArray(t)&&t.every(e),Me=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),Gt=(e,t)=>{if(!xr(e))return!1;for(const n of Object.keys(e)){const r=e[n];if(r===void 0)continue;const o=t.fields.get(n);if(o===void 0||!o(r))return!1}for(const n of t.required)if(e[n]===void 0)return!1;return!0},Is=e=>t=>{if(!xr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&Gt(t,n)},md=["left","center","right"],gd=["top","middle","bottom"],wd=["thin","medium","thick","dashed","dotted","double","hair"],Go=["gt","gte","lt","lte","eq","neq","between","notBetween"],Cd=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],bd=["eq","neq","gt","gte","lt","lte","between","notBetween"],yd=["contains","notContains","startsWith","endsWith"],Rd=new Map([["number",Me({type:fe,decimals:ln,grouping:tt,locale:fe},["type"])],["percent",Me({type:fe,decimals:ln,scale:tt,locale:fe},["type"])],["currency",Me({type:fe,currency:fe,decimals:ln,locale:fe},["type","currency"])],["scientific",Me({type:fe,decimals:ln,locale:fe},["type"])],["date",Me({type:fe,pattern:fe},["type"])],["text",Me({type:fe},["type"])]]),vd=Me({style:Kt(wd),color:fe},["style"]),Wr=e=>Gt(e,vd),Sd=Me({top:Wr,right:Wr,bottom:Wr,left:Wr},[]),kd=Me({value:Is(Rd),align:Kt(md),verticalAlign:Kt(gd),wrap:tt,background:fe,color:fe,bold:tt,italic:tt,underline:tt,strikethrough:tt,fontFamily:fe,fontSize:ln,borders:e=>Gt(e,Sd)},[]),Ed=e=>Gt(e,kd),bn={strict:tt,inputMessage:fe,errorMessage:fe},Od=new Map([["list",Me({...bn,type:fe,values:hd(fe),showDropdown:tt},["type","values"])],["number",Me({...bn,type:fe,op:Kt(Go),a:fe,b:fe},["type","op","a"])],["textLength",Me({...bn,type:fe,op:Kt(Go),a:ln,b:ln},["type","op","a"])],["date",Me({...bn,type:fe,op:Kt(Go),a:fe,b:fe},["type","op","a"])],["text",Me({...bn,type:fe,op:Kt(Cd),value:fe},["type","op"])],["checkbox",Me({...bn,type:fe,checked:fe,unchecked:fe},["type"])],["custom",Me({...bn,type:fe,formula:fe},["type","formula"])]]),Ad=Is(Od),xd=Me({startRow:At,startCol:At,endRow:At,endCol:At},["startRow","startCol","endRow","endCol"]),Td=e=>{if(!Gt(e,xd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return At(t)&&At(r)&&At(n)&&At(o)&&t<=r&&n<=o},$d=Me({color:fe,value:ln},["color"]),Zo=e=>Gt(e,$d),Ld=new Map([["cellValue",Me({type:fe,op:Kt(bd),a:fe,b:fe},["type","op","a"])],["text",Me({type:fe,op:Kt(yd),value:fe},["type","op","value"])],["empty",Me({type:fe},["type"])],["notEmpty",Me({type:fe},["type"])],["colorScale",Me({type:fe,min:Zo,mid:Zo,max:Zo},["type","min","max"])],["customFormula",Me({type:fe,formula:fe},["type","formula"])]]),Dd=Me({background:fe,color:fe,bold:tt,italic:tt,underline:tt,strikethrough:tt},[]),zd=Me({sourceRuleId:fe,ranges:Array.isArray,condition:Is(Ld),style:e=>Gt(e,Dd),stopIfTrue:tt},["sourceRuleId","ranges","condition","style"]),Md=(e,t,n)=>{if(!Gt(e,zd))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Td(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Nd=Me({text:fe,author:fe,createdAt:fe},["text","author","createdAt"]),Fd=e=>Gt(e,Nd),Pd=(e,t,n)=>{if(!xr(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!At(o)||o>=t)return!1;break;case"val":if(!At(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(Fd)))return!1;break;default:return!1}}return!0},Ql=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(pd),_d=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),xc=e=>{if(!xr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!_d.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Jl(t)&&Jl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Ed)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Ad)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!Pd(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Ql(e.colWidths,n)||e.rowHeights!==void 0&&!Ql(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Md(c,t,n))},Er=e=>Array.isArray(e)?`[${e.map(Er).join(",")}]`:xr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Er(e[n])}`).join(",")}}`:JSON.stringify(e),qd=e=>{const t=xt(e);return t===void 0?"{}":JSON.stringify(t)},jd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Id=e=>{let t=`{"t":${JSON.stringify(e.t)}`;return e.f!==void 0&&(t+=`,"f":${JSON.stringify(e.f)}`),e.fmt!==void 0&&(t+=`,"fmt":${e.fmt}`),e.val!==void 0&&(t+=`,"val":${e.val}`),e.note!==void 0&&(t+=`,"note":${JSON.stringify(e.note)}`),e.comments!==void 0&&(t+=`,"comments":[${e.comments.map(jd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Tc=e=>{if(!xc(e))throw new RangeError("[spreadsheet] serializeClipPayload received a payload outside the wire format v1 vocabulary");const t=`{"v":1,"rows":${e.rows},"cols":${e.cols},"clipId":${JSON.stringify(e.clipId)}`,n=e.formats.map(qd).join(","),r=e.validations.map(Er).join(","),o=e.cells.map(a=>`[${a.map(Id).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(Er).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Cs=e=>{let t;try{t=JSON.parse(e)}catch{return null}return xc(t)?t:null},Hd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Bd=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),$c=e=>e.includes("&")?e.replace(Hd,t=>Bd[t]):e,Wd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,ei=e=>{const t=e.length>gs?e.slice(0,gs):e,n=Wd.exec($c(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Vd=e=>{const t=e.indexOf(ws);if(t===-1)return null;const n=t+ws.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Lc=(e,t)=>{if(t==="event"&&e.types.includes(po))return{kind:"mime",json:e.getData(po)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Vd(n);return r===null?null:{kind:"attribute",html:n,at:r}},Yd=(e,t)=>{const n=Lc(e,t);return n===null?null:n.kind==="mime"?ei(n.json):ei(n.html.slice(n.at.start,n.at.start+gs))},Kd=(e,t)=>{const n=Lc(e,t);if(n===null)return null;if(n.kind==="mime")return Cs(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Cs($c(n.html.slice(n.at.start,r)))},Ud=/<google-sheets-html-origin[\s>]/,Xd='data-sheets-root="1"',Gd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Zd="mso-",Jd=/\.xl\d+\s*\{/,Qd="<table",ef=e=>e.includes(ws)?"aqsp":Ud.test(e)&&e.includes(Xd)?"sheets":Gd.test(e)||e.includes(Zd)||Jd.test(e)?"excel":null,Dc=(e,t)=>{if(t==="event"&&e.types.includes(po))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Zl?n.slice(0,Zl):n,o=ef(r);if(o==="aqsp")return"aqsp";if(n.includes(Qd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Hs=1e3,zc=65534,tf=9,nf=10,rf=12,of=13,sf=32,Mc=34,Nc=39,lf=43,Bs=47,ti=48,cf=57,af=61,uf=62,df=97,ff=98,pf=100,hf=102,Fc=104,Pc=114,_c=116,mf=["able","body","head","foot"],vr=e=>e===sf||e===tf||e===nf||e===of||e===rf,bs=e=>e===uf||e===Bs||vr(e),gf=e=>vr(e)||e===Bs||e===Mc||e===Nc,wf=(e,t,n,r)=>{if(t===0||!gf(e.charCodeAt(t-1)))return null;let o=t+n;for(;vr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==af)return 1;for(o+=1;vr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Mc||s===Nc)&&(o+=1);vr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===lf&&(o+=1);let l=0,c=0;for(let a=e.charCodeAt(o);a>=ti&&a<=cf;a=e.charCodeAt(o))l=l*10+(a-ti),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},ni=(e,t,n)=>{let r=e.indexOf(t);return(o,s)=>{for(;r!==-1&&r<o;)r=e.indexOf(t,r+t.length);for(;r!==-1&&r<s;r=e.indexOf(t,r+t.length)){const l=wf(e,r,t.length,n);if(l!==null)return l}return 1}},Cf=(e,t)=>{if(e.charCodeAt(t+2)!==_c)return!1;const n=e.charCodeAt(t+3);if(n===Pc)return bs(e.charCodeAt(t+4));if(n!==df&&n!==ff&&n!==Fc&&n!==hf)return!1;for(const r of mf)if(e.startsWith(r,t+3)&&bs(e.charCodeAt(t+3+r.length)))return!0;return!1},bf=e=>{const t=e.toLowerCase(),n=ni(t,"colspan",Hs),r=ni(t,"rowspan",zc);let o=0;const s=q=>(o!==-1&&o<q&&(o=t.indexOf(">",q)),o===-1?t.length:o);let l=0,c=0,a=0,p=0,g=!1;const y=new Map,N=(q,X)=>{const K=y.get(q);y.set(q,K===void 0?X:K+X)},F=()=>{g&&a+p>c&&(c=a+p),g=!1},M=()=>{F(),l+=1,g=!0,a=0;const q=y.get(l-1);q!==void 0&&(p+=q)};for(let q=t.indexOf("<");q!==-1;q=t.indexOf("<",q+1)){const X=t.charCodeAt(q+1);if(X===Bs){Cf(t,q)&&F();continue}if(X!==_c||!bs(t.charCodeAt(q+3)))continue;const K=t.charCodeAt(q+2);if(K===Pc)M();else if(K===pf||K===Fc){g||M();const T=q+3,$=s(T),P=n(T,$);a+=P;const I=r(T,$);I>1&&(N(l,P),N(l-1+I,-P))}}return F(),{rows:l,cols:c}},qc=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),l=n.get(s);if(l!==void 0)return l;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},jc=()=>{const e=new WeakMap,t=qc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=xt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},yf=()=>{const e=new WeakMap,t=qc(Er);return{intern:r=>{const o=e.get(r);if(o!==void 0)return o;const s=t.intern(r);return e.set(r,s),s},entries:t.entries}},Rf=new Set(["http:","https:","mailto:","tel:"]),fn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Rf.has(n.protocol)?n.href:null},Jn=e=>{if(e===void 0)return;const t=fn(e);return t===null?void 0:t},Ic=(e,t)=>e.startCol===0&&e.endCol===t-1,Hc=(e,t)=>e.startRow===0&&e.endRow===t-1,ys=13,Vt=Object.freeze({style:Object.freeze({}),lineBoxPx:ys,verticalAlign:"middle"}),vf={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:"#00000000"},Sf=new Map(Object.entries(vf)),kf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Ef=/^rgba?\((.*)\)$/,Bc=/^(\d+(?:\.\d+)?)%$/,Vr=e=>e.toString(16).padStart(2,"0"),Jo=e=>{const t=Bc.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^\d+$/.test(e))return null;const n=Number(e);return n<=255?n:null},Of=e=>{const t=Bc.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(e))return null;const n=Number(e);return n<=1?Math.round(n*255):null},Af=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Jo(t[0]),r=Jo(t[1]),o=Jo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Vr(n)}${Vr(r)}${Vr(o)}`;if(t.length===3)return s;const l=Of(t[3]);return l===null?null:l===255?s:`${s}${Vr(l)}`},nt=e=>{const t=e.trim().toLowerCase(),n=kf.exec(t);if(n!==null){const s=n[1],l=s.length<=4?s.replace(/./g,c=>c+c):s;return l.length===8&&l.endsWith("ff")?`#${l.slice(0,6)}`:`#${l}`}const r=Ef.exec(t);if(r!==null)return Af(r[1]);const o=Sf.get(t);return o===void 0?null:o},ri={thin:{width:1,line:"solid"},medium:{width:2,line:"solid"},thick:{width:3,line:"solid"},dashed:{width:1,line:"dashed"},dotted:{width:1,line:"dotted"},double:{width:3,line:"double"},hair:{width:1,line:"dotted"}},oi=e=>{if(!Object.hasOwn(ri,e.style))return null;const t=ri[e.style],n=e.color===void 0?Ps:nt(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},xf={top:"flex-start",middle:"center",bottom:"flex-end"},Tf=e=>e==="left"||e==="center"||e==="right",Wc=e=>e==="top"||e==="middle"||e==="bottom",Vc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Yc=(e,t)=>{if(typeof e.background=="string"){const s=nt(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=nt(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=Vc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Yr=(e,t)=>{const n=e===void 0?null:oi(e);return n!==null?n:t===void 0?null:oi(t)},Qo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Tf(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=Rr(e.align)),Wc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=xf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Yc(e,s));const c=e?.borders,a=Yr(c?.right,t);a!==null&&(s.borderRight=a);const p=Yr(c?.bottom,n);if(p!==null&&(s.borderBottom=p),r){const g=Yr(c?.left,void 0);g!==null&&(s.borderLeft=g)}if(o){const g=Yr(c?.top,void 0);g!==null&&(s.borderTop=g)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},si=new WeakMap,$f=(e,t,n,r,o)=>{const s=t?.borders?.left,l=n?.borders?.top,c=!(r||o)&&s===void 0&&l===void 0;if(e===void 0)return c?null:Qo(void 0,s,l,r,o);if(!c)return Qo(e,s,l,r,o);const a=si.get(e);if(a!==void 0)return a;const p=Qo(e,void 0,void 0,!1,!1);return si.set(e,p),p},Lf=e=>{if(e===void 0)return Vt;const t={};Yc(e,t);const n=Vc(e.fontSize),r=n===null?ys:Math.round(n),o=Wc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===ys&&o==="middle"?Vt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Df="#REF!",zf=11,Mf=15,Nf=4096,so=33,Sr=34,Ws=36,Ff=38,Rs=39,Kc=40,Pf=42,_f=43,qf=44,Uc=45,jf=46,If=47,Vn=58,Hf=59,Bf=60,Xc=61,Wf=62,Vf=67,Yf=82,yo=91,Gc=93,Kf=94,Uf=95,Zc=e=>e>=65&&e<=90||e>=97&&e<=122,Jc=e=>e>=48&&e<=57,Vs=e=>Zc(e)||Jc(e)||e===Uf||e===jf||e===Ws||e>=128,Xf=e=>e===32||e>=9&&e<=13||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279,Gf=e=>e===Xc||e===Kc||e===qf||e===Hf||e===_f||e===Uc||e===Pf||e===If||e===Kf||e===Ff||e===Bf||e===Wf||e===Vn,Qc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Vs(n)||n===Kc||n===so||n===yo)},li=(e,t)=>{let n=t;for(;n<e.length&&Vs(e.charCodeAt(n));)n+=1;return n},vs=(e,t,n)=>{let r=t+1;for(;r<e.length;){if(e.charCodeAt(r)===n){if(e.charCodeAt(r+1)===n){r+=2;continue}return r+1}r+=1}return e.length},Zf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Rs){r+=2;continue}if(o===yo)n+=1;else if(o===Gc&&(n-=1,n===0))return r+1;r+=1}return e.length},ii=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Qc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},ea=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Sr){o=vs(e,o,Sr);continue}if(s===Rs){const a=vs(e,o,Rs);o=e.charCodeAt(a)===so?ii(e,o,a,t,n):a;continue}if(s===yo){o=Zf(e,o);continue}if(!Vs(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Qc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=li(e,o);if(e.charCodeAt(c)===Vn){const a=li(e,c+1);a>c+1&&e.charCodeAt(a)===so&&(c=a)}o=e.charCodeAt(c)===so?ii(e,o,c,t,n):c}return n},es=(e,t)=>{let n=t;const r=e.charCodeAt(n)===Ws;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Zc(l))break;if(s+=1,s>zf)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Ss=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Jc(o))break;if(n-t>=Mf)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Kr=(e,t)=>{const n=e.charCodeAt(t)===Ws,r=Ss(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Jf=(e,t)=>{const n=es(e,t);if(n!==null){const o=Kr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Vn){const s=es(e,o.end+1);if(s!==null){const l=Kr(e,s.end);if(l!==null)return{end:l.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:l.index,col:s.col,absRow:l.abs,absCol:s.abs}}}}}return{end:o.end,token:{kind:"cell",row:o.index,col:n.col,absRow:o.abs,absCol:n.abs}}}if(e.charCodeAt(n.end)===Vn){const s=es(e,n.end+1);if(s!==null)return{end:s.end,token:{kind:"column",start:{col:n.col,abs:n.abs},end:{col:s.col,abs:s.abs}}}}return null}const r=Kr(e,t);if(r!==null&&e.charCodeAt(r.end)===Vn){const o=Kr(e,r.end+1);if(o!==null)return{end:o.end,token:{kind:"row",start:{row:r.index,abs:r.abs},end:{row:o.index,abs:o.abs}}}}return null},Tr=e=>ea(e,Jf),ta=(e,t=Nf)=>{if(!Number.isInteger(t)||t<=0)throw new RangeError(`[spreadsheet] createFormulaMemo requires a positive integer limit, received ${t}`);const n=new Map;return r=>{const o=n.get(r);if(o!==void 0)return o;n.size>=t&&n.clear();const s=e(r);return n.set(r,s),s}},ks=e=>{let t=e+1,n="";for(;t>0;){const r=(t-1)%26;n=String.fromCharCode(65+r)+n,t=Math.floor((t-1)/26)}return n},ts=e=>`${e.absCol?"$":""}${ks(e.col)}${e.absRow?"$":""}${e.row+1}`,Ys=e=>e.sheet===void 0?"":`${e.sheet}!`,cn=e=>{const t=Ys(e);switch(e.kind){case"cell":return`${t}${ts(e)}`;case"range":return`${t}${ts(e.start)}:${ts(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${ks(e.start.col)}:${e.end.abs?"$":""}${ks(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},jn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Qf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(jn(n.startRow,"formatRangeReference startRow"),jn(n.startCol,"formatRangeReference startCol"),jn(n.endRow,"formatRangeReference endRow"),jn(n.endCol,"formatRangeReference endCol"),t){case"columns":return cn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return cn({kind:"row",start:{row:n.startRow,abs:!1},end:{row:n.endRow,abs:!1}});case"cells":return n.startRow===n.endRow&&n.startCol===n.endCol?cn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):cn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Ks=(e,t,n)=>{if(t.length===0)return e;let r="",o=0;for(const s of t){const l=n(s.token);r+=e.slice(o,s.start)+(l===null?`${Ys(s.token)}${Df}`:l),o=s.end}return r+e.slice(o)},Ro=e=>e.charCodeAt(0)===Xc,ns=(e,t,n)=>{const r=e.absRow?e.row:e.row+t,o=e.absCol?e.col:e.col+n;return r<0||o<0?null:{row:r,col:o,absRow:e.absRow,absCol:e.absCol}},ep=(e,t,n)=>{switch(e.kind){case"cell":{const r=ns(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=ns(e.start,t,n),o=ns(e.end,t,n);return r===null||o===null?null:{...e,start:r,end:o}}case"column":{const r=e.start.abs?e.start.col:e.start.col+n,o=e.end.abs?e.end.col:e.end.col+n;return r<0||o<0?null:{...e,start:{col:r,abs:e.start.abs},end:{col:o,abs:e.end.abs}}}case"row":{const r=e.start.abs?e.start.row:e.start.row+t,o=e.end.abs?e.end.row:e.end.row+t;return r<0||o<0?null:{...e,start:{row:r,abs:e.start.abs},end:{row:o,abs:e.end.abs}}}}},na=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Ro(e)?Ks(e,Tr(e),r=>{const o=ep(r,t,n);return o===null?null:cn(o)}):e},ra=(e,t)=>{jn(e.row,`${t} origin.row`),jn(e.col,`${t} origin.col`)},In=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,rs=(e,t)=>`${In("R",e.row,e.absRow,t.row)}${In("C",e.col,e.absCol,t.col)}`,tp=(e,t)=>{const n=Ys(e);switch(e.kind){case"cell":return`${n}${rs(e,t)}`;case"range":return`${n}${rs(e.start,t)}:${rs(e.end,t)}`;case"column":return`${n}${In("C",e.start.col,e.start.abs,t.col)}:${In("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${In("R",e.start.row,e.start.abs,t.row)}:${In("R",e.end.row,e.end.abs,t.row)}`}},vo=(e,t)=>(ra(t,"toR1C1"),Ro(e)?Ks(e,Tr(e),n=>tp(n,t)):e),ci=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===yo){const l=e.charCodeAt(o+1)===Uc,c=Ss(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Gc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Ss(e,o);return s===null?{end:o,axis:{rel:!0,n:0}}:s.value===0?null:{end:s.end,axis:{rel:!1,n:s.value}}},ai=(e,t)=>{const n=ci(e,t,Yf),r=ci(e,n===null?t:n.end,Vf);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},np=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},rp=(e,t)=>e.shape==="cell"&&t.shape==="cell"?{shape:"cell",start:e.cell,end:t.cell}:e.shape==="row"&&t.shape==="row"?{shape:"row",start:e.row,end:t.row}:e.shape==="column"&&t.shape==="column"?{shape:"column",start:e.col,end:t.col}:null,op=(e,t)=>{const n=ai(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Vn){const r=ai(e,n.end+1);if(r!==null){const o=rp(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:np(n)}},sp=e=>ea(e,op),lp=ta(sp),Hn=(e,t)=>e.rel?t+e.n:e.n-1,ui=(e,t)=>{const n=Hn(e.row,t.row),r=Hn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},ip=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=ui(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=ui(e.end,t);return o===null?null:{kind:"range",start:r,end:o,...n}}case"row":{const r=e.end===null?e.start:e.end,o=Hn(e.start,t.row),s=Hn(r,t.row);return o<0||s<0?null:{kind:"row",start:{row:o,abs:!e.start.rel},end:{row:s,abs:!r.rel},...n}}case"column":{const r=e.end===null?e.start:e.end,o=Hn(e.start,t.col),s=Hn(r,t.col);return o<0||s<0?null:{kind:"column",start:{col:o,abs:!e.start.rel},end:{col:s,abs:!r.rel},...n}}}},$r=(e,t)=>(ra(t,"fromR1C1"),Ro(e)?Ks(e,lp(e),n=>{const r=ip(n,t);return r===null?null:cn(r)}):e),di=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},cp=e=>{switch(e.kind){case"cell":return{...e,...di(e.absCol,e.absRow)};case"range":{const t=di(e.start.absCol,e.start.absRow);return{...e,start:{...e.start,...t},end:{...e.end,...t}}}case"column":{const t=!e.start.abs;return{...e,start:{col:e.start.col,abs:t},end:{col:e.end.col,abs:t}}}case"row":{const t=!e.start.abs;return{...e,start:{row:e.start.row,abs:t},end:{row:e.end.row,abs:t}}}}},oa=(e,t)=>Ro(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,sa=(e,t)=>{if(!oa(e,t))return null;for(const n of Tr(e))if(n.start<=t&&t<=n.end)return n;return null},ap=(e,t)=>{const n=sa(e,t);if(n===null)return null;const r=cn(cp(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},fi=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Sr){const s=vs(e,r,Sr);if(s>t)return!1;n=Sr,r=s;continue}Xf(o)||(n=o),r+=1}return Gf(n)},la=(e,t)=>{if(!oa(e,t))return null;for(const n of Tr(e))if(n.start<=t&&t<=n.end)return fi(e,n.start)?{replace:[n.start,n.end]}:null;return fi(e,t)?{insertAt:t}:null},Gn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],So=(e,t)=>`[$${e}-${t}]`,up=new Map(Gn.map(e=>[So(e.symbol,e.lcid),e])),dp=new Map(Gn.filter((e,t)=>Gn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Gn.map(e=>[So(e.symbol,e.lcid),e.code]));const fp=new Set([...Gn.map(e=>e.symbol),...Gn.map(e=>e.code),"¥"]),pp=20,hp="yyyy/MM/dd",ia=/yyyy|MM|dd|HH|mm|ss/g,ca=" -+/():!^&'~{}<>=",mp="$¥€£₩₹¥",Es=e=>{let t="",n=0;for(;n<e.length;){const r=e[n];if(r!=="\\"){t+=r,n+=1;continue}const o=e.slice(n+1,n+5);if(/^[0-9a-fA-F]{4}$/.test(o)){t+=String.fromCharCode(Number.parseInt(o,16)),n+=5;continue}if(n+1<e.length){t+=e[n+1],n+=2;continue}t+=r,n+=1}return t},gp=e=>{let t=0;for(;t<e.length;){const n=e[t];if(n==='"'){const r=e.indexOf('"',t+1);t=r<0?e.length:r+1}else if(n==="["){const r=e.indexOf("]",t+1);t=r<0?e.length:r+1}else if(n==="\\"||n==="_"||n==="*")t+=2;else{if(n===";")return e.slice(0,t);t+=1}}return e},wp=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),a=c.lastIndexOf("-"),p=a<0?c:c.slice(0,a),g=a<0?null:c.slice(a+1);if(g!==null&&!/^[0-9a-fA-F]{1,8}$/.test(g)||p===""&&g===null)return null;const y=g===null?null:Number.parseInt(g,16).toString(16);t.push(p===""?{kind:"locale"}:{kind:"currency",symbol:p,lcid:y}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(ca.includes(o)||mp.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},Ot=e=>e===void 0?{}:{locale:e},Cp=/^(0|#,##0)(?:\.(0+))?$/,pi=(e,t,n,r)=>{if(t!==null){const o=up.get(So(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!fp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...Ot(r.locale)}},bp=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",a="";for(const M of e)switch(M.kind){case"locale":break;case"literal":r?a+=M.text:c+=M.text;break;case"digits":if(r)return;n=M.text,r=!0;break;case"currency":if(o!==null)return;o=M;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const p=Cp.exec(n);if(p===null)return;const g=p[1]==="#,##0",y=p[2]===void 0?0:p[2].length,N=c.trim(),F=a.trim();if(s)return l===0&&o===null&&!g&&N===""&&F===""?{type:"scientific",decimals:y,...Ot(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&F===""?{type:"percent",decimals:y,...Ot(t.locale)}:void 0;if(F==="%"&&N===""&&o===null)return{type:"percent",decimals:y,scale:!1,...Ot(t.locale)};if(o!==null)return N===""&&F===""?pi(o.symbol,o.lcid,y,t):void 0;if(!(N!==""&&F!==""))return N!==""||F!==""?pi(N+F,null,y,t):{type:"number",decimals:y,...g?{grouping:!0}:{},...Ot(t.locale)}},yp=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Rp=(e,t)=>{const n=[...e.matchAll(ia)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},vp=e=>{const t=e.flatMap(s=>s.kind==="date"?[s.text]:[]),n=[];let r="",o=0;for(const s of e){if(s.kind==="locale")continue;if(s.kind==="literal"){r+=s.text;continue}if(s.kind!=="date")return;const l=s.text==="mm"?t[o-1]==="hh"||t[o+1]==="ss"?"mm":"MM":yp.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Rp(r,n)?{type:"date",pattern:r}:void 0},Sp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...Ot(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...Ot(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...Ot(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...Ot(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...Ot(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...Ot(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Us=(e,t)=>{const n=gp(e).trim(),r=Sp.get(n);if(r!==void 0)return r(t);const o=wp(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return bp(o,t);if(o.some(s=>s.kind==="date"))return vp(o)}},kp=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return}if(typeof n!="object"||n===null||Array.isArray(n))return;const r=n,o=r[1],s=r[2];if(typeof o!="number"||!Number.isInteger(o)||o<0||o>8||s!==void 0&&typeof s!="string"||o===0)return;if(o===1)return{type:"text"};const l=s===void 0?void 0:Us(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Cr=e=>e===0?"":`.${"0".repeat(e)}`,lo=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=pp,Ep=`${ca}.,`,hi=e=>e.includes('"')?null:[...e].every(t=>Ep.includes(t))?e:`"${e}"`,Op=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(ia)){const a=hi(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=hi(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Us(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Ap=e=>{const t=dp.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!lo(n))return null;const r=`#,##0${Cr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${So(t.symbol,t.lcid)}${r}`},aa=e=>{switch(e.type){case"text":return"@";case"date":return Op(e.pattern===void 0?hp:e.pattern);case"number":return lo(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Cr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return lo(t)?e.scale===!1?`0${Cr(t)}"%"`:`0${Cr(t)}%`:null}case"scientific":return lo(e.decimals)?`0${Cr(e.decimals)}E+00`:null;case"currency":return Ap(e);default:return null}},mi="-−",xp=(e,t)=>{if(t===""||!e.includes(t))return/^\d+$/.test(e)?e:null;const n=e.split(t);return!/^\d{1,3}$/.test(n[0])||n.slice(1).some(r=>!/^\d{3}$/.test(r))?null:n.join("")},Tp=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const p=xp(c[0],t);return p===null?null:{integer:p,fraction:a,exponent:l}},$p=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const a=c===""?l:`${l}.${c}`;return r&&a!=="0"?`-${a}`:a},Lp=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",a=P=>P>="0"&&P<="9"||l!==""&&l.includes(P)||n.decimal.includes(P)||c&&(P==="e"||P==="E");let p=0;for(;p<o.length&&!a(o[p]);)p+=1;let g=o.length;for(;g>p&&!a(o[g-1]);)g-=1;let y=0,N=0,F=0,M="";for(const P of o.slice(0,p))mi.includes(P)?y+=1:P==="("?N+=1:M+=P;for(const P of o.slice(g))mi.includes(P)?y+=1:P===")"?F+=1:M+=P;const q=y+N;if(N!==F||q>1||q===1&&s||(s=s||q===1,r!=="currency"&&M.trim()!==""))return e;const X=Tp(o.slice(p,g).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(X===null)return e;const K=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,T=X.exponent+K;if(T>330||T<-330)return e;const $=$p(X.integer,X.fraction,T,s);return Number.isFinite(Number($))?$:e},gi="google-sheets-html-origin",ua=Object.freeze({group:",",decimal:"."}),wi=Object.freeze({thin:".5pt solid",medium:"1.0pt solid",thick:"1.5pt solid",dashed:".5pt dashed",dotted:".5pt dotted",double:"1.5pt double",hair:".5pt hairline"}),da=["top","right","bottom","left"],Dp=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),zp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Mp=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),Ci=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Np=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Fp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Pp=new Set(["div","p","li","ul","ol","dl","dt","dd","h1","h2","h3","h4","h5","h6","blockquote","pre","section","article","header","footer","table","tr","hr"]),_p=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),qp=3,jp=1,fa=-25569,io=86400,Ip=-693959,Hp=2958465,Bp=" ",ko=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),a=c.indexOf(":");if(a>0){const p=c.slice(0,a).trim().toLowerCase(),g=c.slice(a+1).trim();p!==""&&g!==""&&t.set(p,g)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},ho=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Xs=e=>{const t=[];let n="",r=0;for(const o of e)o==="("?r+=1:o===")"&&(r=r>0?r-1:0),r===0&&/\s/.test(o)?n!==""&&(t.push(n),n=""):n+=o;return n!==""&&t.push(n),t},Wp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Vp=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const a=l.indexOf("{",c);if(a===-1)break;const p=l.indexOf("}",a+1);if(p===-1)break;const g=l.slice(c,a),y=l.slice(a+1,p);if(c=p+1,g.trim().startsWith("@"))continue;const N=ko(y);for(const F of g.split(",")){const M=F.trim(),q=Wp.exec(M);if(q!==null){const X=t.get(q[1]);if(X===void 0)t.set(q[1],new Map(N));else for(const[K,T]of N)X.set(K,T)}else if(M.toLowerCase()==="table"){const X=N.get("mso-displayed-decimal-separator"),K=N.get("mso-displayed-thousand-separator");X!==void 0&&(n=Es(ho(X))),K!==void 0&&(r=Es(ho(K)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:ua}},Yp="%_-*? ",Kp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Yp.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Up=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},pa=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,a=l<10?l+3:l-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},Pn=(e,t)=>String(e).padStart(t,"0"),ha=e=>{if(e<Ip||e>Hp)return null;let t=Math.floor(e),n=Math.round((e-t)*io);n>=io&&(t+=1,n-=io);const r=pa(t+fa),o=`${Pn(r.year,4)}-${Pn(r.month,2)}-${Pn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Pn(s,2)}:${Pn(l,2)}:${Pn(n%60,2)}`},Xp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Gp=e=>{const t=Xp.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const a=Up(n,r,o),p=pa(a);return p.year!==n||p.month!==r||p.day!==o?null:a-fa+(s*3600+l*60+c)/io},Gs=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),yn=e=>Gs(e).replaceAll('"',"&quot;"),ma=e=>Gs(e).replaceAll("'","&#39;"),Zp=e=>Gs(e).replaceAll(`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const rn=require("./tsv.cjs"),Pe=require("./view-BkwCUzTl.cjs"),ot=require("@aiquants/virtualscroll"),q=require("react/jsx-runtime"),i=require("react"),Ks=1e3,Cn=1e4,Ys=10,fi=2**(1/4),Td=(e,t)=>e<=0?e:t>0?e>=Cn?e:Math.min(Cn,Math.max(e+1,Math.round(e*fi))):Math.max(1,Math.min(e-1,Math.round(e/fi))),pi=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),Xs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Ys):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),Cn))}let l=[...s].map(([a,u])=>({index:a,size:u}));if(e.count-e.hiddenCount()-pi(e,l)===0){const a=n===null?l[0].index:n;l=l.map(u=>u.index===a?{index:u.index,size:1}:u)}if(r.axisKind==="row"){const a=e.hiddenCount()+pi(e,l);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:l}},Us="#000000",Qr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},$d=20,Md=256,eo=new Map,ls=new WeakMap,vt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Ld=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},zd=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:$d}:Qr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Qr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Qr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Qr(e.decimals)};default:return null}},Nd=e=>{const t=ls.get(e);if(t!==void 0)return t;const n=JSON.stringify([e.type,e.locale??null,e.decimals===void 0?null:String(e.decimals),e.type==="number"?e.grouping??!1:null,e.type==="currency"?e.currency:null]),r=eo.get(n);if(r!==void 0)return ls.set(e,r),r;eo.size>=Md&&eo.clear();const o=zd(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return eo.set(n,s),ls.set(e,s),s},Dd=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Vc=e=>{const t=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>Dd(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Fd=(e,t)=>{const n=Vc(e);if(n===null)return e;const r=(o,s)=>String(o).padStart(s,"0");return t.replace(/yyyy|MM|dd|HH|mm|ss/g,o=>{switch(o){case"yyyy":return r(n.year,4);case"MM":return r(n.month,2);case"dd":return r(n.day,2);case"HH":return r(n.hour,2);case"mm":return r(n.minute,2);default:return r(n.second,2)}})},An=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Fd(e,t.pattern??"yyyy/MM/dd");const n=vt(e);if(n===null)return e;const r=Nd(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Ld(n,-2):n)},hi=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Vc(n)!==null?"right":"left":vt(n)!==null?"right":"left",Ar=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Wc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Pd=["bottom","left","right","top"],Kc=(e,t,n)=>{e[t]=n},Yc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},qd=e=>{if(e===void 0)return;const t={};for(const n of Pd){const r=e[n];r!==void 0&&(t[n]=Yc(r))}return Object.keys(t).length===0?void 0:t},Dt=e=>{const t={};for(const n of Wc){const r=n==="borders"?qd(e.borders):n==="value"?e.value===void 0?void 0:Yc(e.value):e[n];r!==void 0&&r!==!1&&Kc(t,n,r)}return Object.keys(t).length===0?void 0:t},Gs=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;const o=e,s=t;for(let l=0;l<n.length;l+=1){const c=n[l];if(c!==r[l]||!Gs(o[c],s[c]))return!1}return!0},_d=(e,t)=>e===t?!0:Gs(e===void 0?void 0:Dt(e),t===void 0?void 0:Dt(t)),Zs=(e,t)=>{const n={};for(const o of Wc){const s=t[o];Kc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=Dt(n);return Gs(r,e===void 0?void 0:Dt(e))?e:r},Xc="data-aqsp-clip",ko="application/x-aqsp-clip",xs=512,mi=16*1024,As=`${Xc}=`,jd=16,Js=()=>{const e=globalThis.crypto;if(e===void 0||typeof e.getRandomValues!="function")throw new RangeError("[spreadsheet] newClipId requires crypto.getRandomValues — there is no counter or randomUUID substitute by design");const t=e.getRandomValues(new Uint8Array(jd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Dr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),pe=e=>typeof e=="string",nt=e=>typeof e=="boolean",fn=e=>typeof e=="number"&&Number.isFinite(e),Nt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,gi=e=>Nt(e)&&e>=1,Id=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Cn,nn=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Hd=e=>t=>Array.isArray(t)&&t.every(e),qe=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),on=(e,t)=>{if(!Dr(e))return!1;for(const n of Object.keys(e)){const r=e[n];if(r===void 0)continue;const o=t.fields.get(n);if(o===void 0||!o(r))return!1}for(const n of t.required)if(e[n]===void 0)return!1;return!0},Qs=e=>t=>{if(!Dr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&on(t,n)},Bd=["left","center","right"],Vd=["top","middle","bottom"],Wd=["thin","medium","thick","dashed","dotted","double","hair"],is=["gt","gte","lt","lte","eq","neq","between","notBetween"],Kd=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Yd=["eq","neq","gt","gte","lt","lte","between","notBetween"],Xd=["contains","notContains","startsWith","endsWith"],Ud=new Map([["number",qe({type:pe,decimals:fn,grouping:nt,locale:pe},["type"])],["percent",qe({type:pe,decimals:fn,scale:nt,locale:pe},["type"])],["currency",qe({type:pe,currency:pe,decimals:fn,locale:pe},["type","currency"])],["scientific",qe({type:pe,decimals:fn,locale:pe},["type"])],["date",qe({type:pe,pattern:pe},["type"])],["text",qe({type:pe},["type"])]]),Gd=qe({style:nn(Wd),color:pe},["style"]),to=e=>on(e,Gd),Zd=qe({top:to,right:to,bottom:to,left:to},[]),Jd=qe({value:Qs(Ud),align:nn(Bd),verticalAlign:nn(Vd),wrap:nt,background:pe,color:pe,bold:nt,italic:nt,underline:nt,strikethrough:nt,fontFamily:pe,fontSize:fn,borders:e=>on(e,Zd)},[]),Qd=e=>on(e,Jd),kn={strict:nt,inputMessage:pe,errorMessage:pe},ef=new Map([["list",qe({...kn,type:pe,values:Hd(pe),showDropdown:nt},["type","values"])],["number",qe({...kn,type:pe,op:nn(is),a:pe,b:pe},["type","op","a"])],["textLength",qe({...kn,type:pe,op:nn(is),a:fn,b:fn},["type","op","a"])],["date",qe({...kn,type:pe,op:nn(is),a:pe,b:pe},["type","op","a"])],["text",qe({...kn,type:pe,op:nn(Kd),value:pe},["type","op"])],["checkbox",qe({...kn,type:pe,checked:pe,unchecked:pe},["type"])],["custom",qe({...kn,type:pe,formula:pe},["type","formula"])]]),tf=Qs(ef),nf=qe({startRow:Nt,startCol:Nt,endRow:Nt,endCol:Nt},["startRow","startCol","endRow","endCol"]),rf=e=>{if(!on(e,nf))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return Nt(t)&&Nt(r)&&Nt(n)&&Nt(o)&&t<=r&&n<=o},of=qe({color:pe,value:fn},["color"]),cs=e=>on(e,of),sf=new Map([["cellValue",qe({type:pe,op:nn(Yd),a:pe,b:pe},["type","op","a"])],["text",qe({type:pe,op:nn(Xd),value:pe},["type","op","value"])],["empty",qe({type:pe},["type"])],["notEmpty",qe({type:pe},["type"])],["colorScale",qe({type:pe,min:cs,mid:cs,max:cs},["type","min","max"])],["customFormula",qe({type:pe,formula:pe},["type","formula"])]]),lf=qe({background:pe,color:pe,bold:nt,italic:nt,underline:nt,strikethrough:nt},[]),cf=qe({sourceRuleId:pe,ranges:Array.isArray,condition:Qs(sf),style:e=>on(e,lf),stopIfTrue:nt},["sourceRuleId","ranges","condition","style"]),af=(e,t,n)=>{if(!on(e,cf))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!rf(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},uf=qe({text:pe,author:pe,createdAt:pe},["text","author","createdAt"]),df=e=>on(e,uf),ff=(e,t,n)=>{if(!Dr(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!Nt(o)||o>=t)return!1;break;case"val":if(!Nt(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(df)))return!1;break;default:return!1}}return!0},wi=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Id),pf=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Uc=e=>{if(!Dr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!pf.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(gi(t)&&gi(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Qd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(tf)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!ff(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!wi(e.colWidths,n)||e.rowHeights!==void 0&&!wi(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>af(c,t,n))},Lr=e=>Array.isArray(e)?`[${e.map(Lr).join(",")}]`:Dr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Lr(e[n])}`).join(",")}}`:JSON.stringify(e),hf=e=>{const t=Dt(e);return t===void 0?"{}":JSON.stringify(t)},mf=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,gf=e=>{let t=`{"t":${JSON.stringify(e.t)}`;return e.f!==void 0&&(t+=`,"f":${JSON.stringify(e.f)}`),e.fmt!==void 0&&(t+=`,"fmt":${e.fmt}`),e.val!==void 0&&(t+=`,"val":${e.val}`),e.note!==void 0&&(t+=`,"note":${JSON.stringify(e.note)}`),e.comments!==void 0&&(t+=`,"comments":[${e.comments.map(mf).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Gc=e=>{if(!Uc(e))throw new RangeError("[spreadsheet] serializeClipPayload received a payload outside the wire format v1 vocabulary");const t=`{"v":1,"rows":${e.rows},"cols":${e.cols},"clipId":${JSON.stringify(e.clipId)}`,n=e.formats.map(hf).join(","),r=e.validations.map(Lr).join(","),o=e.cells.map(a=>`[${a.map(gf).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(Lr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Ts=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Uc(t)?t:null},wf=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Cf=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),Zc=e=>e.includes("&")?e.replace(wf,t=>Cf[t]):e,yf=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Ci=e=>{const t=e.length>xs?e.slice(0,xs):e,n=yf.exec(Zc(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},bf=e=>{const t=e.indexOf(As);if(t===-1)return null;const n=t+As.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Jc=(e,t)=>{if(t==="event"&&e.types.includes(ko))return{kind:"mime",json:e.getData(ko)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=bf(n);return r===null?null:{kind:"attribute",html:n,at:r}},vf=(e,t)=>{const n=Jc(e,t);return n===null?null:n.kind==="mime"?Ci(n.json):Ci(n.html.slice(n.at.start,n.at.start+xs))},Rf=(e,t)=>{const n=Jc(e,t);if(n===null)return null;if(n.kind==="mime")return Ts(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Ts(Zc(n.html.slice(n.at.start,r)))},Sf=/<google-sheets-html-origin[\s>]/,Ef='data-sheets-root="1"',kf=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Of="mso-",xf=/\.xl\d+\s*\{/,Af="<table",Tf=e=>e.includes(As)?"aqsp":Sf.test(e)&&e.includes(Ef)?"sheets":kf.test(e)||e.includes(Of)||xf.test(e)?"excel":null,Qc=(e,t)=>{if(t==="event"&&e.types.includes(ko))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>mi?n.slice(0,mi):n,o=Tf(r);if(o==="aqsp")return"aqsp";if(n.includes(Af))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},el=1e3,ea=65534,$f=9,Mf=10,Lf=12,zf=13,Nf=32,ta=34,na=39,Df=43,tl=47,yi=48,Ff=57,Pf=61,qf=62,_f=97,jf=98,If=100,Hf=102,ra=104,oa=114,sa=116,Bf=["able","body","head","foot"],Tr=e=>e===Nf||e===$f||e===Mf||e===zf||e===Lf,$s=e=>e===qf||e===tl||Tr(e),Vf=e=>Tr(e)||e===tl||e===ta||e===na,Wf=(e,t,n,r)=>{if(t===0||!Vf(e.charCodeAt(t-1)))return null;let o=t+n;for(;Tr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Pf)return 1;for(o+=1;Tr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===ta||s===na)&&(o+=1);Tr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Df&&(o+=1);let l=0,c=0;for(let a=e.charCodeAt(o);a>=yi&&a<=Ff;a=e.charCodeAt(o))l=l*10+(a-yi),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},bi=(e,t,n)=>{let r=e.indexOf(t);return(o,s)=>{for(;r!==-1&&r<o;)r=e.indexOf(t,r+t.length);for(;r!==-1&&r<s;r=e.indexOf(t,r+t.length)){const l=Wf(e,r,t.length,n);if(l!==null)return l}return 1}},Kf=(e,t)=>{if(e.charCodeAt(t+2)!==sa)return!1;const n=e.charCodeAt(t+3);if(n===oa)return $s(e.charCodeAt(t+4));if(n!==_f&&n!==jf&&n!==ra&&n!==Hf)return!1;for(const r of Bf)if(e.startsWith(r,t+3)&&$s(e.charCodeAt(t+3+r.length)))return!0;return!1},Yf=e=>{const t=e.toLowerCase(),n=bi(t,"colspan",el),r=bi(t,"rowspan",ea);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,a=0,u=0,m=!1;const C=new Map,L=(_,G)=>{const Z=C.get(_);C.set(_,Z===void 0?G:Z+G)},M=()=>{m&&a+u>c&&(c=a+u),m=!1},$=()=>{M(),l+=1,m=!0,a=0;const _=C.get(l-1);_!==void 0&&(u+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const G=t.charCodeAt(_+1);if(G===tl){Kf(t,_)&&M();continue}if(G!==sa||!$s(t.charCodeAt(_+3)))continue;const Z=t.charCodeAt(_+2);if(Z===oa)$();else if(Z===If||Z===ra){m||$();const O=_+3,F=s(O),V=n(O,F);a+=V;const H=r(O,F);H>1&&(L(l,V),L(l-1+H,-V))}}return M(),{rows:l,cols:c}},la=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),l=n.get(s);if(l!==void 0)return l;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},ia=()=>{const e=new WeakMap,t=la(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=Dt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Xf=()=>{const e=new WeakMap,t=la(Lr);return{intern:r=>{const o=e.get(r);if(o!==void 0)return o;const s=t.intern(r);return e.set(r,s),s},entries:t.entries}},Uf=new Set(["http:","https:","mailto:","tel:"]),yn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Uf.has(n.protocol)?n.href:null},cr=e=>{if(e===void 0)return;const t=yn(e);return t===null?void 0:t},ca=(e,t)=>e.startCol===0&&e.endCol===t-1,aa=(e,t)=>e.startRow===0&&e.endRow===t-1,Ms=13,en=Object.freeze({style:Object.freeze({}),lineBoxPx:Ms,verticalAlign:"middle"}),Gf={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:"#00000000"},Zf=new Map(Object.entries(Gf)),Jf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Qf=/^rgba?\((.*)\)$/,ua=/^(\d+(?:\.\d+)?)%$/,no=e=>e.toString(16).padStart(2,"0"),as=e=>{const t=ua.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^\d+$/.test(e))return null;const n=Number(e);return n<=255?n:null},ep=e=>{const t=ua.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(e))return null;const n=Number(e);return n<=1?Math.round(n*255):null},tp=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=as(t[0]),r=as(t[1]),o=as(t[2]);if(n===null||r===null||o===null)return null;const s=`#${no(n)}${no(r)}${no(o)}`;if(t.length===3)return s;const l=ep(t[3]);return l===null?null:l===255?s:`${s}${no(l)}`},rt=e=>{const t=e.trim().toLowerCase(),n=Jf.exec(t);if(n!==null){const s=n[1],l=s.length<=4?s.replace(/./g,c=>c+c):s;return l.length===8&&l.endsWith("ff")?`#${l.slice(0,6)}`:`#${l}`}const r=Qf.exec(t);if(r!==null)return tp(r[1]);const o=Zf.get(t);return o===void 0?null:o},vi={thin:{width:1,line:"solid"},medium:{width:2,line:"solid"},thick:{width:3,line:"solid"},dashed:{width:1,line:"dashed"},dotted:{width:1,line:"dotted"},double:{width:3,line:"double"},hair:{width:1,line:"dotted"}},Ri=e=>{if(!Object.hasOwn(vi,e.style))return null;const t=vi[e.style],n=e.color===void 0?Us:rt(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},np={top:"flex-start",middle:"center",bottom:"flex-end"},rp=e=>e==="left"||e==="center"||e==="right",da=e=>e==="top"||e==="middle"||e==="bottom",fa=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,pa=(e,t)=>{if(typeof e.background=="string"){const s=rt(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=rt(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=fa(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},ro=(e,t)=>{const n=e===void 0?null:Ri(e);return n!==null?n:t===void 0?null:Ri(t)},us=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(rp(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=Ar(e.align)),da(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=np[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),pa(e,s));const c=e?.borders,a=ro(c?.right,t);a!==null&&(s.borderRight=a);const u=ro(c?.bottom,n);if(u!==null&&(s.borderBottom=u),r){const m=ro(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=ro(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Si=new WeakMap,op=(e,t,n,r,o)=>{const s=t?.borders?.left,l=n?.borders?.top,c=!(r||o)&&s===void 0&&l===void 0;if(e===void 0)return c?null:us(void 0,s,l,r,o);if(!c)return us(e,s,l,r,o);const a=Si.get(e);if(a!==void 0)return a;const u=us(e,void 0,void 0,!1,!1);return Si.set(e,u),u},sp=e=>{if(e===void 0)return en;const t={};pa(e,t);const n=fa(e.fontSize),r=n===null?Ms:Math.round(n),o=da(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Ms&&o==="middle"?en:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},lp="#REF!",ip=11,cp=15,ap=4096,Co=33,$r=34,nl=36,up=38,Ls=39,ha=40,dp=42,fp=43,pp=44,ma=45,hp=46,mp=47,tr=58,gp=59,wp=60,ga=61,Cp=62,yp=67,bp=82,zo=91,wa=93,vp=94,Rp=95,Ca=e=>e>=65&&e<=90||e>=97&&e<=122,ya=e=>e>=48&&e<=57,rl=e=>Ca(e)||ya(e)||e===Rp||e===hp||e===nl||e>=128,Sp=e=>e===32||e>=9&&e<=13||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279,Ep=e=>e===ga||e===ha||e===pp||e===gp||e===fp||e===ma||e===dp||e===mp||e===vp||e===up||e===wp||e===Cp||e===tr,ba=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(rl(n)||n===ha||n===Co||n===zo)},Ei=(e,t)=>{let n=t;for(;n<e.length&&rl(e.charCodeAt(n));)n+=1;return n},zs=(e,t,n)=>{let r=t+1;for(;r<e.length;){if(e.charCodeAt(r)===n){if(e.charCodeAt(r+1)===n){r+=2;continue}return r+1}r+=1}return e.length},kp=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Ls){r+=2;continue}if(o===zo)n+=1;else if(o===wa&&(n-=1,n===0))return r+1;r+=1}return e.length},ki=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&ba(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},va=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===$r){o=zs(e,o,$r);continue}if(s===Ls){const a=zs(e,o,Ls);o=e.charCodeAt(a)===Co?ki(e,o,a,t,n):a;continue}if(s===zo){o=kp(e,o);continue}if(!rl(s)){o+=1;continue}const l=t(e,o);if(l!==null&&ba(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Ei(e,o);if(e.charCodeAt(c)===tr){const a=Ei(e,c+1);a>c+1&&e.charCodeAt(a)===Co&&(c=a)}o=e.charCodeAt(c)===Co?ki(e,o,c,t,n):c}return n},ds=(e,t)=>{let n=t;const r=e.charCodeAt(n)===nl;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Ca(l))break;if(s+=1,s>ip)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Ns=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!ya(o))break;if(n-t>=cp)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},oo=(e,t)=>{const n=e.charCodeAt(t)===nl,r=Ns(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Op=(e,t)=>{const n=ds(e,t);if(n!==null){const o=oo(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===tr){const s=ds(e,o.end+1);if(s!==null){const l=oo(e,s.end);if(l!==null)return{end:l.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:l.index,col:s.col,absRow:l.abs,absCol:s.abs}}}}}return{end:o.end,token:{kind:"cell",row:o.index,col:n.col,absRow:o.abs,absCol:n.abs}}}if(e.charCodeAt(n.end)===tr){const s=ds(e,n.end+1);if(s!==null)return{end:s.end,token:{kind:"column",start:{col:n.col,abs:n.abs},end:{col:s.col,abs:s.abs}}}}return null}const r=oo(e,t);if(r!==null&&e.charCodeAt(r.end)===tr){const o=oo(e,r.end+1);if(o!==null)return{end:o.end,token:{kind:"row",start:{row:r.index,abs:r.abs},end:{row:o.index,abs:o.abs}}}}return null},Fr=e=>va(e,Op),Ra=(e,t=ap)=>{if(!Number.isInteger(t)||t<=0)throw new RangeError(`[spreadsheet] createFormulaMemo requires a positive integer limit, received ${t}`);const n=new Map;return r=>{const o=n.get(r);if(o!==void 0)return o;n.size>=t&&n.clear();const s=e(r);return n.set(r,s),s}},Ds=e=>{let t=e+1,n="";for(;t>0;){const r=(t-1)%26;n=String.fromCharCode(65+r)+n,t=Math.floor((t-1)/26)}return n},fs=e=>`${e.absCol?"$":""}${Ds(e.col)}${e.absRow?"$":""}${e.row+1}`,ol=e=>e.sheet===void 0?"":`${e.sheet}!`,pn=e=>{const t=ol(e);switch(e.kind){case"cell":return`${t}${fs(e)}`;case"range":return`${t}${fs(e.start)}:${fs(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Ds(e.start.col)}:${e.end.abs?"$":""}${Ds(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Gn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},xp=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Gn(n.startRow,"formatRangeReference startRow"),Gn(n.startCol,"formatRangeReference startCol"),Gn(n.endRow,"formatRangeReference endRow"),Gn(n.endCol,"formatRangeReference endCol"),t){case"columns":return pn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return pn({kind:"row",start:{row:n.startRow,abs:!1},end:{row:n.endRow,abs:!1}});case"cells":return n.startRow===n.endRow&&n.startCol===n.endCol?pn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):pn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},sl=(e,t,n)=>{if(t.length===0)return e;let r="",o=0;for(const s of t){const l=n(s.token);r+=e.slice(o,s.start)+(l===null?`${ol(s.token)}${lp}`:l),o=s.end}return r+e.slice(o)},No=e=>e.charCodeAt(0)===ga,ps=(e,t,n)=>{const r=e.absRow?e.row:e.row+t,o=e.absCol?e.col:e.col+n;return r<0||o<0?null:{row:r,col:o,absRow:e.absRow,absCol:e.absCol}},Ap=(e,t,n)=>{switch(e.kind){case"cell":{const r=ps(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=ps(e.start,t,n),o=ps(e.end,t,n);return r===null||o===null?null:{...e,start:r,end:o}}case"column":{const r=e.start.abs?e.start.col:e.start.col+n,o=e.end.abs?e.end.col:e.end.col+n;return r<0||o<0?null:{...e,start:{col:r,abs:e.start.abs},end:{col:o,abs:e.end.abs}}}case"row":{const r=e.start.abs?e.start.row:e.start.row+t,o=e.end.abs?e.end.row:e.end.row+t;return r<0||o<0?null:{...e,start:{row:r,abs:e.start.abs},end:{row:o,abs:e.end.abs}}}}},Sa=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return No(e)?sl(e,Fr(e),r=>{const o=Ap(r,t,n);return o===null?null:pn(o)}):e},Ea=(e,t)=>{Gn(e.row,`${t} origin.row`),Gn(e.col,`${t} origin.col`)},Zn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,hs=(e,t)=>`${Zn("R",e.row,e.absRow,t.row)}${Zn("C",e.col,e.absCol,t.col)}`,Tp=(e,t)=>{const n=ol(e);switch(e.kind){case"cell":return`${n}${hs(e,t)}`;case"range":return`${n}${hs(e.start,t)}:${hs(e.end,t)}`;case"column":return`${n}${Zn("C",e.start.col,e.start.abs,t.col)}:${Zn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Zn("R",e.start.row,e.start.abs,t.row)}:${Zn("R",e.end.row,e.end.abs,t.row)}`}},Do=(e,t)=>(Ea(t,"toR1C1"),No(e)?sl(e,Fr(e),n=>Tp(n,t)):e),Oi=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===zo){const l=e.charCodeAt(o+1)===ma,c=Ns(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==wa?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Ns(e,o);return s===null?{end:o,axis:{rel:!0,n:0}}:s.value===0?null:{end:s.end,axis:{rel:!1,n:s.value}}},xi=(e,t)=>{const n=Oi(e,t,bp),r=Oi(e,n===null?t:n.end,yp);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},$p=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},Mp=(e,t)=>e.shape==="cell"&&t.shape==="cell"?{shape:"cell",start:e.cell,end:t.cell}:e.shape==="row"&&t.shape==="row"?{shape:"row",start:e.row,end:t.row}:e.shape==="column"&&t.shape==="column"?{shape:"column",start:e.col,end:t.col}:null,Lp=(e,t)=>{const n=xi(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===tr){const r=xi(e,n.end+1);if(r!==null){const o=Mp(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:$p(n)}},zp=e=>va(e,Lp),Np=Ra(zp),Jn=(e,t)=>e.rel?t+e.n:e.n-1,Ai=(e,t)=>{const n=Jn(e.row,t.row),r=Jn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Dp=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Ai(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Ai(e.end,t);return o===null?null:{kind:"range",start:r,end:o,...n}}case"row":{const r=e.end===null?e.start:e.end,o=Jn(e.start,t.row),s=Jn(r,t.row);return o<0||s<0?null:{kind:"row",start:{row:o,abs:!e.start.rel},end:{row:s,abs:!r.rel},...n}}case"column":{const r=e.end===null?e.start:e.end,o=Jn(e.start,t.col),s=Jn(r,t.col);return o<0||s<0?null:{kind:"column",start:{col:o,abs:!e.start.rel},end:{col:s,abs:!r.rel},...n}}}},Pr=(e,t)=>(Ea(t,"fromR1C1"),No(e)?sl(e,Np(e),n=>{const r=Dp(n,t);return r===null?null:pn(r)}):e),Ti=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Fp=e=>{switch(e.kind){case"cell":return{...e,...Ti(e.absCol,e.absRow)};case"range":{const t=Ti(e.start.absCol,e.start.absRow);return{...e,start:{...e.start,...t},end:{...e.end,...t}}}case"column":{const t=!e.start.abs;return{...e,start:{col:e.start.col,abs:t},end:{col:e.end.col,abs:t}}}case"row":{const t=!e.start.abs;return{...e,start:{row:e.start.row,abs:t},end:{row:e.end.row,abs:t}}}}},ka=(e,t)=>No(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Oa=(e,t)=>{if(!ka(e,t))return null;for(const n of Fr(e))if(n.start<=t&&t<=n.end)return n;return null},Pp=(e,t)=>{const n=Oa(e,t);if(n===null)return null;const r=pn(Fp(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},$i=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===$r){const s=zs(e,r,$r);if(s>t)return!1;n=$r,r=s;continue}Sp(o)||(n=o),r+=1}return Ep(n)},xa=(e,t)=>{if(!ka(e,t))return null;for(const n of Fr(e))if(n.start<=t&&t<=n.end)return $i(e,n.start)?{replace:[n.start,n.end]}:null;return $i(e,t)?{insertAt:t}:null},lr=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],Fo=(e,t)=>`[$${e}-${t}]`,qp=new Map(lr.map(e=>[Fo(e.symbol,e.lcid),e])),_p=new Map(lr.filter((e,t)=>lr.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(lr.map(e=>[Fo(e.symbol,e.lcid),e.code]));const jp=new Set([...lr.map(e=>e.symbol),...lr.map(e=>e.code),"¥"]),Ip=20,Hp="yyyy/MM/dd",Aa=/yyyy|MM|dd|HH|mm|ss/g,Ta=" -+/():!^&'~{}<>=",Bp="$¥€£₩₹¥",Fs=e=>{let t="",n=0;for(;n<e.length;){const r=e[n];if(r!=="\\"){t+=r,n+=1;continue}const o=e.slice(n+1,n+5);if(/^[0-9a-fA-F]{4}$/.test(o)){t+=String.fromCharCode(Number.parseInt(o,16)),n+=5;continue}if(n+1<e.length){t+=e[n+1],n+=2;continue}t+=r,n+=1}return t},Vp=e=>{let t=0;for(;t<e.length;){const n=e[t];if(n==='"'){const r=e.indexOf('"',t+1);t=r<0?e.length:r+1}else if(n==="["){const r=e.indexOf("]",t+1);t=r<0?e.length:r+1}else if(n==="\\"||n==="_"||n==="*")t+=2;else{if(n===";")return e.slice(0,t);t+=1}}return e},Wp=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),a=c.lastIndexOf("-"),u=a<0?c:c.slice(0,a),m=a<0?null:c.slice(a+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||u===""&&m===null)return null;const C=m===null?null:Number.parseInt(m,16).toString(16);t.push(u===""?{kind:"locale"}:{kind:"currency",symbol:u,lcid:C}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(Ta.includes(o)||Bp.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},zt=e=>e===void 0?{}:{locale:e},Kp=/^(0|#,##0)(?:\.(0+))?$/,Mi=(e,t,n,r)=>{if(t!==null){const o=qp.get(Fo(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!jp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...zt(r.locale)}},Yp=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",a="";for(const $ of e)switch($.kind){case"locale":break;case"literal":r?a+=$.text:c+=$.text;break;case"digits":if(r)return;n=$.text,r=!0;break;case"currency":if(o!==null)return;o=$;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const u=Kp.exec(n);if(u===null)return;const m=u[1]==="#,##0",C=u[2]===void 0?0:u[2].length,L=c.trim(),M=a.trim();if(s)return l===0&&o===null&&!m&&L===""&&M===""?{type:"scientific",decimals:C,...zt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&L===""&&M===""?{type:"percent",decimals:C,...zt(t.locale)}:void 0;if(M==="%"&&L===""&&o===null)return{type:"percent",decimals:C,scale:!1,...zt(t.locale)};if(o!==null)return L===""&&M===""?Mi(o.symbol,o.lcid,C,t):void 0;if(!(L!==""&&M!==""))return L!==""||M!==""?Mi(L+M,null,C,t):{type:"number",decimals:C,...m?{grouping:!0}:{},...zt(t.locale)}},Xp=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Up=(e,t)=>{const n=[...e.matchAll(Aa)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Gp=e=>{const t=e.flatMap(s=>s.kind==="date"?[s.text]:[]),n=[];let r="",o=0;for(const s of e){if(s.kind==="locale")continue;if(s.kind==="literal"){r+=s.text;continue}if(s.kind!=="date")return;const l=s.text==="mm"?t[o-1]==="hh"||t[o+1]==="ss"?"mm":"MM":Xp.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Up(r,n)?{type:"date",pattern:r}:void 0},Zp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...zt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...zt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...zt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...zt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...zt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...zt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),ll=(e,t)=>{const n=Vp(e).trim(),r=Zp.get(n);if(r!==void 0)return r(t);const o=Wp(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Yp(o,t);if(o.some(s=>s.kind==="date"))return Gp(o)}},Jp=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return}if(typeof n!="object"||n===null||Array.isArray(n))return;const r=n,o=r[1],s=r[2];if(typeof o!="number"||!Number.isInteger(o)||o<0||o>8||s!==void 0&&typeof s!="string"||o===0)return;if(o===1)return{type:"text"};const l=s===void 0?void 0:ll(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},kr=e=>e===0?"":`.${"0".repeat(e)}`,yo=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Ip,Qp=`${Ta}.,`,Li=e=>e.includes('"')?null:[...e].every(t=>Qp.includes(t))?e:`"${e}"`,eh=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Aa)){const a=Li(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=Li(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=ll(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},th=e=>{const t=_p.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!yo(n))return null;const r=`#,##0${kr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Fo(t.symbol,t.lcid)}${r}`},$a=e=>{switch(e.type){case"text":return"@";case"date":return eh(e.pattern===void 0?Hp:e.pattern);case"number":return yo(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${kr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return yo(t)?e.scale===!1?`0${kr(t)}"%"`:`0${kr(t)}%`:null}case"scientific":return yo(e.decimals)?`0${kr(e.decimals)}E+00`:null;case"currency":return th(e);default:return null}},zi="-−",nh=(e,t)=>{if(t===""||!e.includes(t))return/^\d+$/.test(e)?e:null;const n=e.split(t);return!/^\d{1,3}$/.test(n[0])||n.slice(1).some(r=>!/^\d{3}$/.test(r))?null:n.join("")},rh=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const u=nh(c[0],t);return u===null?null:{integer:u,fraction:a,exponent:l}},oh=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const a=c===""?l:`${l}.${c}`;return r&&a!=="0"?`-${a}`:a},sh=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",a=V=>V>="0"&&V<="9"||l!==""&&l.includes(V)||n.decimal.includes(V)||c&&(V==="e"||V==="E");let u=0;for(;u<o.length&&!a(o[u]);)u+=1;let m=o.length;for(;m>u&&!a(o[m-1]);)m-=1;let C=0,L=0,M=0,$="";for(const V of o.slice(0,u))zi.includes(V)?C+=1:V==="("?L+=1:$+=V;for(const V of o.slice(m))zi.includes(V)?C+=1:V===")"?M+=1:$+=V;const _=C+L;if(L!==M||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&$.trim()!==""))return e;const G=rh(o.slice(u,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(G===null)return e;const Z=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,O=G.exponent+Z;if(O>330||O<-330)return e;const F=oh(G.integer,G.fraction,O,s);return Number.isFinite(Number(F))?F:e},Ni="google-sheets-html-origin",Ma=Object.freeze({group:",",decimal:"."}),Di=Object.freeze({thin:".5pt solid",medium:"1.0pt solid",thick:"1.5pt solid",dashed:".5pt dashed",dotted:".5pt dotted",double:"1.5pt double",hair:".5pt hairline"}),La=["top","right","bottom","left"],lh=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),ih=new Set(["windowtext","currentcolor","inherit","initial","unset"]),ch=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),Fi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],ah=Object.freeze({number:2,percent:3,currency:4,scientific:8}),uh=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),dh=new Set(["div","p","li","ul","ol","dl","dt","dd","h1","h2","h3","h4","h5","h6","blockquote","pre","section","article","header","footer","table","tr","hr"]),fh=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),ph=3,hh=1,za=-25569,bo=86400,mh=-693959,gh=2958465,wh=" ",Po=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),a=c.indexOf(":");if(a>0){const u=c.slice(0,a).trim().toLowerCase(),m=c.slice(a+1).trim();u!==""&&m!==""&&t.set(u,m)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},Oo=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},il=e=>{const t=[];let n="",r=0;for(const o of e)o==="("?r+=1:o===")"&&(r=r>0?r-1:0),r===0&&/\s/.test(o)?n!==""&&(t.push(n),n=""):n+=o;return n!==""&&t.push(n),t},Ch=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,yh=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const a=l.indexOf("{",c);if(a===-1)break;const u=l.indexOf("}",a+1);if(u===-1)break;const m=l.slice(c,a),C=l.slice(a+1,u);if(c=u+1,m.trim().startsWith("@"))continue;const L=Po(C);for(const M of m.split(",")){const $=M.trim(),_=Ch.exec($);if(_!==null){const G=t.get(_[1]);if(G===void 0)t.set(_[1],new Map(L));else for(const[Z,O]of L)G.set(Z,O)}else if($.toLowerCase()==="table"){const G=L.get("mso-displayed-decimal-separator"),Z=L.get("mso-displayed-thousand-separator");G!==void 0&&(n=Fs(Oo(G))),Z!==void 0&&(r=Fs(Oo(Z)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Ma}},bh="%_-*? ",vh=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||bh.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Rh=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},Na=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,a=l<10?l+3:l-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},Yn=(e,t)=>String(e).padStart(t,"0"),Da=e=>{if(e<mh||e>gh)return null;let t=Math.floor(e),n=Math.round((e-t)*bo);n>=bo&&(t+=1,n-=bo);const r=Na(t+za),o=`${Yn(r.year,4)}-${Yn(r.month,2)}-${Yn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Yn(s,2)}:${Yn(l,2)}:${Yn(n%60,2)}`},Sh=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Eh=e=>{const t=Sh.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const a=Rh(n,r,o),u=Na(a);return u.year!==n||u.month!==r||u.day!==o?null:a-za+(s*3600+l*60+c)/bo},cl=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),On=e=>cl(e).replaceAll('"',"&quot;"),Fa=e=>cl(e).replaceAll("'","&#39;"),kh=e=>cl(e).replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
4
  `).replaceAll(`
5
- `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),co=(e,t)=>`${e}="${yn(JSON.stringify(t))}"`,ga=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Jp=e=>{if(gt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Qp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},eh=e=>{if(e.type==="text")return{1:1};const t=aa(e);return t===null?null:{1:e.type==="date"?Qp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Np[e.type],2:t,3:1}},th=/[;"'{}<>&\\]/,wa=e=>e==="left"||e==="center"||e==="right",Ca=e=>e==="top"||e==="middle"||e==="bottom",nh=e=>{const t=[];e.bold===!0&&t.push("font-weight:bold"),e.italic===!0&&t.push("font-style:italic");const n=[...e.underline===!0?["underline"]:[],...e.strikethrough===!0?["line-through"]:[]];n.length>0&&t.push(`text-decoration:${n.join(" ")}`);const r=typeof e.color=="string"?nt(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?nt(e.background):null;if(o!==null&&t.push(`background-color:${o}`),wa(e.align)&&t.push(`text-align:${e.align}`),Ca(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!th.test(e.fontFamily)&&t.push(`font-family:${e.fontFamily.trim()}`),typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0&&t.push(`font-size:${e.fontSize}pt`),e.borders!==void 0)for(const s of da){const l=e.borders[s];if(l===void 0||!Object.hasOwn(wi,l.style))continue;const c=l.color===void 0?"windowtext":nt(l.color);c!==null&&t.push(`border-${s}:${wi[l.style]} ${c}`)}if(e.value!==void 0){const s=aa(e.value);s!==null&&t.push(`mso-number-format:"${Kp(s)}"`)}return t},rh={value:void 0,style:"white-space:pre",numberFormatAttribute:null},oh=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=ma([n,...nh(e)].join(";"));let o=null;if(t!==void 0){const s=eh(t);s!==null&&(o=co("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},sh=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Xn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&ga(o)?Jp(e.t):null,a=!l&&c===null&&o!==void 0&&o.type==="date"?Gp(e.t):null,p=[];if(l?p.push(co("data-sheets-value",{1:2,2:e.t})):c!==null?p.push(co("data-sheets-value",{1:3,3:c})):a!==null&&p.push(co("data-sheets-value",{1:3,3:a})),e.f!==void 0&&p.push(`data-sheets-formula="${yn(e.f)}"`),t.numberFormatAttribute!==null&&p.push(t.numberFormatAttribute),e.link!==void 0&&p.push(`data-sheets-hyperlink="${yn(e.link)}"`),e.note!==void 0&&p.push(`data-sheets-note="${yn(e.note)}"`),l?p.push("x:str"):c!==null?p.push(`x:num="${yn(e.t)}"`):a!==null&&p.push(`x:num="${a}"`),e.f!==void 0){const N=$r(e.f,{row:n,col:r});N.includes("#REF!")||p.push(`x:fmla="${yn(N)}"`)}const g=Zp(s),y=e.link===void 0?g:`<a href="${yn(e.link)}">${g}</a>`;return`<td style='${t.style}'${p.map(N=>` ${N}`).join("")}>${y}</td>`},ba=(e,t)=>{if(e.cells.length!==e.rows||e.cells.some(s=>s.length!==e.cols))throw new RangeError(`serializeHtmlTable: cells must be exactly rows × cols (${e.rows} × ${e.cols})`);const n=e.colWidths===void 0?"":`<colgroup>${e.colWidths.map(s=>`<col width="${s}">`).join("")}</colgroup>`,r=e.formats.map(oh);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let a=0;a<e.cols;a+=1){const p=e.cells[s][a],g=p.fmt===void 0?void 0:r[p.fmt];c+=sh(p,g===void 0?rh:g,s,a)}o+=`<tr${l}>${c}</tr>`}return`<${gi}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Ac}='${ma(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${gi}>`},Os=(e,t)=>{for(const[n,r]of t)e.set(n,r)},ya=(e,t)=>{const n=new Map,r=e.getAttribute("bgcolor");r!==null&&r.trim()!==""&&n.set("background",r);for(const s of e.classList){const l=t.classes.get(s);l!==void 0&&Os(n,l)}const o=e.getAttribute("style");return o!==null&&Os(n,ko(o)),n},lh=e=>{const t=e.toLowerCase();if(t==="thin")return{pt:.75,unit:"px"};if(t==="medium")return{pt:1.5,unit:"px"};if(t==="thick")return{pt:3,unit:"px"};const n=/^(\d*\.?\d+)(pt|px)$/.exec(t);if(n===null)return null;const r=Number(n[1]);return n[2]==="pt"?{pt:r,unit:"pt"}:{pt:r*.75,unit:"px"}},ih=e=>{if(e.unit==="px"){const t=e.pt/.75;return t<=1?"thin":t<3?"medium":"thick"}return e.pt<.75?"thin":e.pt<1.25?"medium":"thick"},ch=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),ah={pt:1.5,unit:"px"},bi=e=>{let t=null,n=null;const r=[];for(const a of Xs(e)){const p=a.toLowerCase(),g=lh(a);Dp.has(p)?n=p:g!==null?t=g:r.push(a)}if(n===null||n==="none"||n==="hidden")return null;const o=ch.get(n),s=o===void 0?ih(t===null?ah:t):o,l=r.join(" ");if(l===""||zp.has(l.toLowerCase()))return{style:s};const c=nt(l);return c===null||c.length===9?null:{style:s,color:c}},uh=e=>e.style==="thin"&&e.color==="#cccccc",dh=e=>{const t=nt(e);if(t!==null)return t;for(const n of Xs(e)){const r=nt(n);if(r!==null)return r}return null},fh=e=>{const t=ho(Xs(e.split(",")[0]).join(" ").trim()).trim();return t===""||Mp.has(t.toLowerCase())?null:t},ph=e=>{const t=/^(\d*\.?\d+)(pt|px)$/i.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=t[2].toLowerCase()==="pt"?n:n*.75;return Number.isFinite(r)&&r>0?r:null},hh=e=>{const t=new Set;for(const n of["text-decoration","text-decoration-line"]){const r=e.get(n);if(r!==void 0)for(const o of r.toLowerCase().split(/\s+/))t.add(o)}return t},mh=e=>{const t=e.get("white-space"),n=t===void 0?"":t.toLowerCase();return n==="pre"||n==="pre-wrap"?"pre":n==="pre-line"?"pre-line":"collapse"},gh=new Set(["normal","pre-wrap","pre-line"]),wh=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const W=o.toLowerCase();(W==="bold"||W==="bolder"||Number(W)>=600)&&(r.bold=!0)}const s=e.get("font-style");s!==void 0&&(s.toLowerCase()==="italic"||s.toLowerCase().startsWith("oblique"))&&(r.italic=!0);const l=hh(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),a=c===void 0?null:nt(c);a!==null&&a.length!==9&&(r.color=a);const p=e.has("background-color")?e.get("background-color"):e.get("background"),g=p===void 0?null:dh(p);g!==null&&g.length!==9&&(r.background=g);const y=e.get("text-align"),N=y===void 0?"":y.toLowerCase();wa(N)&&(r.align=N);const F=e.get("vertical-align"),M=F===void 0?"":F.toLowerCase();Ca(M)&&(r.verticalAlign=M);const q=e.get("font-family"),X=q===void 0?null:fh(q);X!==null&&(r.fontFamily=X);const K=e.get("font-size"),T=K===void 0?null:ph(K);T!==null&&(r.fontSize=T);const $=e.get("white-space");$!==void 0&&gh.has($.toLowerCase())&&(r.wrap=!0);const P={},I=e.get("border"),z=I===void 0?null:bi(I);for(const W of da){const D=e.get(`border-${W}`),m=D===void 0?z:bi(D);m!==null&&!(n==="sheets"&&uh(m))&&(P[W]=m)}return Object.keys(P).length>0&&(r.borders=P),r},yi=e=>{e.text!==""&&!e.text.endsWith(`
5
+ `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),vo=(e,t)=>`${e}="${On(JSON.stringify(t))}"`,Pa=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Oh=e=>{if(vt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},xh=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Ah=e=>{if(e.type==="text")return{1:1};const t=$a(e);return t===null?null:{1:e.type==="date"?xh(e.pattern===void 0?"yyyy/MM/dd":e.pattern):ah[e.type],2:t,3:1}},Th=/[;"'{}<>&\\]/,qa=e=>e==="left"||e==="center"||e==="right",_a=e=>e==="top"||e==="middle"||e==="bottom",$h=e=>{const t=[];e.bold===!0&&t.push("font-weight:bold"),e.italic===!0&&t.push("font-style:italic");const n=[...e.underline===!0?["underline"]:[],...e.strikethrough===!0?["line-through"]:[]];n.length>0&&t.push(`text-decoration:${n.join(" ")}`);const r=typeof e.color=="string"?rt(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?rt(e.background):null;if(o!==null&&t.push(`background-color:${o}`),qa(e.align)&&t.push(`text-align:${e.align}`),_a(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Th.test(e.fontFamily)&&t.push(`font-family:${e.fontFamily.trim()}`),typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0&&t.push(`font-size:${e.fontSize}pt`),e.borders!==void 0)for(const s of La){const l=e.borders[s];if(l===void 0||!Object.hasOwn(Di,l.style))continue;const c=l.color===void 0?"windowtext":rt(l.color);c!==null&&t.push(`border-${s}:${Di[l.style]} ${c}`)}if(e.value!==void 0){const s=$a(e.value);s!==null&&t.push(`mso-number-format:"${vh(s)}"`)}return t},Mh={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Lh=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=Fa([n,...$h(e)].join(";"));let o=null;if(t!==void 0){const s=Ah(t);s!==null&&(o=vo("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},zh=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:An(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Pa(o)?Oh(e.t):null,a=!l&&c===null&&o!==void 0&&o.type==="date"?Eh(e.t):null,u=[];if(l?u.push(vo("data-sheets-value",{1:2,2:e.t})):c!==null?u.push(vo("data-sheets-value",{1:3,3:c})):a!==null&&u.push(vo("data-sheets-value",{1:3,3:a})),e.f!==void 0&&u.push(`data-sheets-formula="${On(e.f)}"`),t.numberFormatAttribute!==null&&u.push(t.numberFormatAttribute),e.link!==void 0&&u.push(`data-sheets-hyperlink="${On(e.link)}"`),e.note!==void 0&&u.push(`data-sheets-note="${On(e.note)}"`),l?u.push("x:str"):c!==null?u.push(`x:num="${On(e.t)}"`):a!==null&&u.push(`x:num="${a}"`),e.f!==void 0){const L=Pr(e.f,{row:n,col:r});L.includes("#REF!")||u.push(`x:fmla="${On(L)}"`)}const m=kh(s),C=e.link===void 0?m:`<a href="${On(e.link)}">${m}</a>`;return`<td style='${t.style}'${u.map(L=>` ${L}`).join("")}>${C}</td>`},ja=(e,t)=>{if(e.cells.length!==e.rows||e.cells.some(s=>s.length!==e.cols))throw new RangeError(`serializeHtmlTable: cells must be exactly rows × cols (${e.rows} × ${e.cols})`);const n=e.colWidths===void 0?"":`<colgroup>${e.colWidths.map(s=>`<col width="${s}">`).join("")}</colgroup>`,r=e.formats.map(Lh);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let a=0;a<e.cols;a+=1){const u=e.cells[s][a],m=u.fmt===void 0?void 0:r[u.fmt];c+=zh(u,m===void 0?Mh:m,s,a)}o+=`<tr${l}>${c}</tr>`}return`<${Ni}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Xc}='${Fa(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Ni}>`},Ps=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Ia=(e,t)=>{const n=new Map,r=e.getAttribute("bgcolor");r!==null&&r.trim()!==""&&n.set("background",r);for(const s of e.classList){const l=t.classes.get(s);l!==void 0&&Ps(n,l)}const o=e.getAttribute("style");return o!==null&&Ps(n,Po(o)),n},Nh=e=>{const t=e.toLowerCase();if(t==="thin")return{pt:.75,unit:"px"};if(t==="medium")return{pt:1.5,unit:"px"};if(t==="thick")return{pt:3,unit:"px"};const n=/^(\d*\.?\d+)(pt|px)$/.exec(t);if(n===null)return null;const r=Number(n[1]);return n[2]==="pt"?{pt:r,unit:"pt"}:{pt:r*.75,unit:"px"}},Dh=e=>{if(e.unit==="px"){const t=e.pt/.75;return t<=1?"thin":t<3?"medium":"thick"}return e.pt<.75?"thin":e.pt<1.25?"medium":"thick"},Fh=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),Ph={pt:1.5,unit:"px"},Pi=e=>{let t=null,n=null;const r=[];for(const a of il(e)){const u=a.toLowerCase(),m=Nh(a);lh.has(u)?n=u:m!==null?t=m:r.push(a)}if(n===null||n==="none"||n==="hidden")return null;const o=Fh.get(n),s=o===void 0?Dh(t===null?Ph:t):o,l=r.join(" ");if(l===""||ih.has(l.toLowerCase()))return{style:s};const c=rt(l);return c===null||c.length===9?null:{style:s,color:c}},qh=e=>e.style==="thin"&&e.color==="#cccccc",_h=e=>{const t=rt(e);if(t!==null)return t;for(const n of il(e)){const r=rt(n);if(r!==null)return r}return null},jh=e=>{const t=Oo(il(e.split(",")[0]).join(" ").trim()).trim();return t===""||ch.has(t.toLowerCase())?null:t},Ih=e=>{const t=/^(\d*\.?\d+)(pt|px)$/i.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=t[2].toLowerCase()==="pt"?n:n*.75;return Number.isFinite(r)&&r>0?r:null},Hh=e=>{const t=new Set;for(const n of["text-decoration","text-decoration-line"]){const r=e.get(n);if(r!==void 0)for(const o of r.toLowerCase().split(/\s+/))t.add(o)}return t},Bh=e=>{const t=e.get("white-space"),n=t===void 0?"":t.toLowerCase();return n==="pre"||n==="pre-wrap"?"pre":n==="pre-line"?"pre-line":"collapse"},Vh=new Set(["normal","pre-wrap","pre-line"]),Wh=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const P=o.toLowerCase();(P==="bold"||P==="bolder"||Number(P)>=600)&&(r.bold=!0)}const s=e.get("font-style");s!==void 0&&(s.toLowerCase()==="italic"||s.toLowerCase().startsWith("oblique"))&&(r.italic=!0);const l=Hh(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),a=c===void 0?null:rt(c);a!==null&&a.length!==9&&(r.color=a);const u=e.has("background-color")?e.get("background-color"):e.get("background"),m=u===void 0?null:_h(u);m!==null&&m.length!==9&&(r.background=m);const C=e.get("text-align"),L=C===void 0?"":C.toLowerCase();qa(L)&&(r.align=L);const M=e.get("vertical-align"),$=M===void 0?"":M.toLowerCase();_a($)&&(r.verticalAlign=$);const _=e.get("font-family"),G=_===void 0?null:jh(_);G!==null&&(r.fontFamily=G);const Z=e.get("font-size"),O=Z===void 0?null:Ih(Z);O!==null&&(r.fontSize=O);const F=e.get("white-space");F!==void 0&&Vh.has(F.toLowerCase())&&(r.wrap=!0);const V={},H=e.get("border"),S=H===void 0?null:Pi(H);for(const P of La){const j=e.get(`border-${P}`),w=j===void 0?S:Pi(j);w!==null&&!(n==="sheets"&&qh(w))&&(V[P]=w)}return Object.keys(V).length>0&&(r.borders=V),r},qi=e=>{e.text!==""&&!e.text.endsWith(`
6
6
  `)&&(e.text+=`
7
- `)},Ch=e=>{const t=e.getAttribute("style");return t!==null&&ko(t).get("mso-spacerun")==="yes"},bh=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){_p.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&yi(t);continue}const o=r.node;if(o.nodeType===qp){const a=o.data;t.text+=t.mode==="collapse"?a.replace(/[\r\n\t\f]/g," "):a.replace(/\r\n?/g,`
8
- `);continue}if(o.nodeType!==jp)continue;const s=o,l=s.localName;if(Fp.has(l)||Ch(s))continue;if(l==="br"){t.text+=`
9
- `;continue}const c=t.mode==="collapse"&&Pp.has(l);if(c&&yi(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const a=s.getAttribute("href");a!==null&&(t.href=a)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let a=s.lastChild;a!==null;a=a.previousSibling)n.push({kind:"enter",node:a})}},yh=(e,t,n,r)=>{const o=e.text.trimEnd().length;if(o===0)return;const s=e.text.length-e.text.trimStart().length;for(const l of e.runs)l.before<=s&&l.end>=o&&vh(l.element,t,n,r)},Rh=(e,t)=>{const n=e.replaceAll(Bp," ");if(t==="pre")return n;const r=n.split(`
7
+ `)},Kh=e=>{const t=e.getAttribute("style");return t!==null&&Po(t).get("mso-spacerun")==="yes"},Yh=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){fh.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&qi(t);continue}const o=r.node;if(o.nodeType===ph){const a=o.data;t.text+=t.mode==="collapse"?a.replace(/[\r\n\t\f]/g," "):a.replace(/\r\n?/g,`
8
+ `);continue}if(o.nodeType!==hh)continue;const s=o,l=s.localName;if(uh.has(l)||Kh(s))continue;if(l==="br"){t.text+=`
9
+ `;continue}const c=t.mode==="collapse"&&dh.has(l);if(c&&qi(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const a=s.getAttribute("href");a!==null&&(t.href=a)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let a=s.lastChild;a!==null;a=a.previousSibling)n.push({kind:"enter",node:a})}},Xh=(e,t,n,r)=>{const o=e.text.trimEnd().length;if(o===0)return;const s=e.text.length-e.text.trimStart().length;for(const l of e.runs)l.before<=s&&l.end>=o&&Gh(l.element,t,n,r)},Uh=(e,t)=>{const n=e.replaceAll(wh," ");if(t==="pre")return n;const r=n.split(`
10
10
  `).map(l=>l.replace(/[ \t\f\r]+/g," ").trim());if(t==="pre-line")return r.join(`
11
11
  `);let o=0;for(;o<r.length&&r[o]==="";)o+=1;let s=r.length;for(;s>o&&r[s-1]==="";)s-=1;return r.slice(o,s).join(`
12
- `)},vh=(e,t,n,r)=>{const o=e.localName;if(o==="b"||o==="strong")t.set("font-weight","bold");else if(o==="i"||o==="em")t.set("font-style","italic");else if(o==="u")n.underline=!0;else if(o==="s"||o==="strike"||o==="del")n.strikethrough=!0;else if(o==="font"){const s=e.getAttribute("color"),l=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),l!==null&&l.trim()!==""&&t.set("font-family",l)}Os(t,ya(e,r))},Sh=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?ha(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<Ci.length?Ci[l]:null}return null},Ra=(e,t,n)=>t!==void 0&&ga(t)?Lp(e,t,n):e,kh=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&gt(c)!==null)if(n!==void 0&&n.type==="date"){const a=ha(Number(c));if(a!==null)return a}else return c;return Ra(t,n,r)},Eh=(e,t,n,r)=>{const o=ya(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:mh(o)};for(const g of Th(e))bh(g,l);yh(l,o,s,r.rules);const c=Rh(l.text,l.mode),a=wh(o,s,r.kind),p={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),y=g===null?void 0:kp(g,r.options);y!==void 0&&(a.value=y);const N=e.getAttribute("data-sheets-value"),F=N===null?null:Sh(N,y);p.t=F===null?Ra(c,y,ua):F;const M=e.getAttribute("data-sheets-formula");M?.startsWith("=")&&(p.f=M);const q=e.getAttribute("data-sheets-hyperlink"),X=q!==null?q:l.href,K=X===null?null:fn(X);K!==null&&(p.link=K);const T=e.getAttribute("data-sheets-note");T!==null&&T!==""&&(p.note=T)}else{const g=o.get("mso-number-format"),y=g===void 0?void 0:Us(Es(ho(g)),r.options);y!==void 0&&(a.value=y),p.t=kh(e,c,y,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(p.f=vo(N,{row:t,col:n}));const F=l.href===null?null:fn(l.href);F!==null&&(p.link=F)}return{cell:p,format:a}},As=(e,t,n)=>{const r=e.getAttribute(t);if(r===null)return 1;const o=/^\s*\+?(\d+)/.exec(r);if(o===null)return 1;const s=Number(o[1]);return s<1?1:s>n?n:s},Oh=e=>{const t=/^(\d*\.?\d+)(px|pt)$/i.exec(e.trim());if(t===null)return null;const n=Number(t[1]);return t[2].toLowerCase()==="pt"?Math.round(n*4/3):Math.round(n)},Ah=(e,t)=>{const n=e.getAttribute(t);if(n===null)return null;const r=/^\s*\+?(\d*\.?\d+)/.exec(n);return r===null?null:Math.round(Number(r[1]))},va=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:ko(n);if(r!==null){const s=r.get("display");if(s!==void 0&&s.toLowerCase()==="none")return 0;const l=r.get(t),c=l===void 0?null:Oh(l);if(c!==null)return Math.min(c,dn)}const o=Ah(e,t);return o===null?null:Math.min(o,dn)},xh=(e,t)=>{const n=[],r=o=>{const s=va(o,"width");for(let l=As(o,"span",Hs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Or(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Or(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Or(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Th(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*$h(e){for(const t of["thead","tbody","tfoot"])for(const n of Or(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Or(n))o.localName==="tr"&&(yield o)}}const os=()=>({t:""}),Lh=(e,t,n)=>{const r=jc(),o=[],s=[],l=[];let c=0;for(const F of $h(e)){const M=o.length,q=(M+1)*Math.max(c,1);if(q>n)return{outcome:"limit",cells:q};const X=[];for(let T=0;T<l.length;T+=1)l[T]>0&&(X[T]=os(),l[T]-=1);let K=0;for(const T of Or(F)){const $=T.localName;if($!=="td"&&$!=="th")continue;for(;X[K]!==void 0;)K+=1;const P=As(T,"colspan",Hs),I=As(T,"rowspan",zc),z=(M+1)*Math.max(c,K+P);if(z>n)return{outcome:"limit",cells:z};const W=Eh(T,M,K,t),D=r.intern(W.format);D!==void 0&&(W.cell.fmt=D),X[K]=W.cell;for(let m=1;m<P;m+=1)X[K+m]===void 0&&(X[K+m]=os());if(I>1)for(let m=0;m<P;m+=1){const f=I-1,C=K+m;l[C]=l[C]===void 0||l[C]<f?f:l[C]}K+=P}X.length>c&&(c=X.length),o.push(X),s.push(va(F,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map(F=>{const M=[];for(let q=0;q<c;q+=1){const X=F[q];M.push(X===void 0?os():X)}return M}),p=xh(e,c),g=p.length===c&&p.every(F=>F!==null)?p.map(F=>F===null?0:F):void 0,y=s.every(F=>F!==null)?s.map(F=>F===null?0:F):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:js(),formats:[...r.entries],validations:[],cells:a,...g===void 0?{}:{colWidths:g},...y===void 0?{}:{rowHeights:y},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Sa=(e,t,n,r)=>{if(!Number.isInteger(r)||r<=0)throw new RangeError(`[spreadsheet] parseHtmlTable requires a positive integer maxCells, received ${r}`);let o;try{o=new DOMParser().parseFromString(e,"text/html")}catch{return{outcome:"none"}}const s=o.querySelector("table");if(s===null)return{outcome:"none"};const l=Vp(o);return Lh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},me=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),Pt=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,wt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),mt=e=>e.reduce((t,n)=>t+wt(n).rows*wt(n).cols,0),Dh=(e,t)=>{if(!Pt(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(me({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(me({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(me({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(me({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},sn=(e,t)=>{if(e.length===1){const r=e[0];for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1)t({row:o,col:s});return}const n=new Set;for(const r of e)for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1){const l=`${o}:${s}`;n.has(l)||(n.add(l),t({row:o,col:s}))}},pn=(e,t,n)=>{if(t<=0||n<=0)throw new RangeError(`[spreadsheet] clampCoord requires a non-empty grid, received ${t} x ${n}`);return{row:Math.min(Math.max(Math.trunc(e.row),0),t-1),col:Math.min(Math.max(Math.trunc(e.col),0),n-1)}},Xt=(e,t)=>e.row===t.row&&e.col===t.col,ka=(e,t)=>e===void 0?Gl(void 0,void 0,t()):Gl(e.align,e.value,e.align===void 0?t():""),ao=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Zn=(e,t,n)=>{if(e.getCellFormula!==void 0){const r=e.getCellFormula(t,n);if(r!==void 0){if(typeof r!="string"||!r.startsWith("="))throw new RangeError(`[spreadsheet] getCellFormula(${t}, ${n}) must return a string starting with "=", received ${JSON.stringify(r)}`);return{text:r,isFormula:!0}}}return{text:e.getCellText(t,n),isFormula:!1}},uo=e=>({format:e.getCellFormat!==void 0,note:e.getCellNote!==void 0,comments:e.getCellComments!==void 0,hyperlink:e.getCellHyperlink!==void 0,validation:e.getCellValidation!==void 0,cf:e.getConditionalFormats!==void 0,formula:e.getCellFormula!==void 0}),Ea=e=>e.isCellReadOnly!==void 0,Je=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,zh=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],Mh=()=>!0,Nh=e=>{const t=new WeakMap,n={};for(const r of zh)r!=="isCellReadOnly"&&Object.defineProperty(n,r,{enumerable:!0,get:()=>{const o=Reflect.get(e,r,e);if(typeof o!="function")return o;const s=t.get(o);if(s!==void 0)return s;const l=o.bind(e);return t.set(o,l),l}});return Object.defineProperty(n,"isCellReadOnly",{enumerable:!0,value:Mh}),n},Fh=/^data-[a-z0-9-]+$/,Ph=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},_h=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Ph(r))throw new RangeError(`[spreadsheet] getCellAttributes must return a plain data-* record or null (got ${Object.prototype.toString.call(r)})`);for(const[o,s]of Object.entries(r)){if(!Fh.test(o))throw new RangeError(`[spreadsheet] getCellAttributes key must be a lowercase data-* name (got ${JSON.stringify(o)})`);if(o.startsWith("data-aqsp")||o.startsWith("data-aqvs")||o==="data-row"||o==="data-col")throw new RangeError(`[spreadsheet] getCellAttributes key ${JSON.stringify(o)} shadows a package- or engine-emitted cell attribute`);if(typeof s!="string")throw new RangeError(`[spreadsheet] getCellAttributes value for ${JSON.stringify(o)} must be a string (got ${typeof s})`)}return r},br=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},Bn=(e,t)=>{for(const n of t)if(br(e,n))return!0;return!1},qh=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=wt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},xs=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=wt(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,a=c?s.rows:e.rows,p=c?s.cols:e.cols,g=l?n:{row:t.startRow,col:t.startCol},y=Math.min(a,r-g.row),N=Math.min(p,o-g.col);return y<=0||N<=0?null:me(g,{row:g.row+y-1,col:g.col+N-1})},Oa=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,a=xs({rows:l,cols:c},t,n,r,o);if(a===null)return[];const p={row:a.startRow,col:a.startCol},g=a.endRow-a.startRow+1,y=a.endCol-a.startCol+1,N=[];for(let F=0;F<g;F+=l){const M=[];for(let X=0;X<y;X+=c){const K={row:p.row+F,col:p.col+X};M.push(K),N.push(K)}const q=Math.min(l,g-F);for(let X=0;X<q;X+=1){const K=p.row+F+X,T=e[X];for(let $=0;$<M.length;$+=1){const P=$*c,I=Math.min(c,y-P);for(let z=0;z<I;z+=1)s(K,p.col+P+z,T[z],M[$])}}}return N},jh=(e,t,n,r,o)=>{const s=[];return Oa(e,t,n,r,o,(l,c,a)=>{s.push({row:l,col:c,text:a})}),s},Ri=(e,t,n,r,o,s)=>{const l=[],c=Oa(e,t,n,r,o,(a,p,g,y)=>{const N=s(g,a,p,y);N!==null&&l.push({...N,row:a,col:p})});return{edits:l,tiles:c}},Aa=(e,t)=>{const n=t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol,r=t.startRow!==e.startRow||t.endRow!==e.endRow||t.startCol!==e.startCol||t.endCol!==e.endCol;if(!(n&&r))throw new RangeError(`[spreadsheet] expandFill requires a box strictly containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`)},Ih=(e,t)=>{Aa(e,t);const n=wt(t),r=wt(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},Hh=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(me({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(me({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(me({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(me({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Bh=(e,t,n,r)=>{Aa(t,n);const o=wt(t).rows,s=wt(t).cols,l=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const p=t.startRow+((a-t.startRow)%o+o)%o,g=a>=t.startRow&&a<=t.endRow;for(let y=n.startCol;y<=n.endCol;y+=1){if(g&&y>=t.startCol&&y<=t.endCol)continue;const N=t.startCol+((y-t.startCol)%s+s)%s,F=p*2**21+N;let M=c.get(F);M===void 0&&(M={value:e(p,N),origin:{row:p,col:N}},c.set(F,M)),l.push(r(M.value,M.origin,{row:a,col:y}))}}return l},xa=(e,t,n)=>{const r=Zn(e,t,n),o={text:r.text,isFormula:r.isFormula};if(e.getCellFormat!==void 0){const s=e.getCellFormat(t,n);o.format=s===void 0?null:xt(s)}if(e.getCellValidation!==void 0){const s=e.getCellValidation(t,n);o.validation=s===void 0?null:s}if(e.getCellHyperlink!==void 0){const s=Jn(e.getCellHyperlink(t,n));o.hyperlink=s===void 0?null:s}if(e.getCellNote!==void 0){const s=e.getCellNote(t,n);o.note=s===void 0?null:s}return o},Ta=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?na(e.text,n.row-t.row,n.col-t.col):e.text};return e.format!==void 0&&(r.format=e.format),e.validation!==void 0&&(r.validation=e.validation),e.hyperlink!==void 0&&(r.hyperlink=e.hyperlink),e.note!==void 0&&(r.note=e.note),r},Eo=["bold","italic","underline","strikethrough","clearFormatting","alignLeft","alignCenter","alignRight","formatNumber","formatTime","formatDate","formatCurrency","formatPercent","formatScientific","bordersOuter","bordersClear","borderTop","borderRight","borderBottom","borderLeft","insertLink","insertNote","insertComment","openHyperlink","openValidationList","pasteSpecial","fillDown","fillRight","fillSelection","insertDate","insertTime","hideRows","hideColumns","unhideRows","unhideColumns","increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth","formatGeneral","bordersAll","pasteFormats","pasteFormulas","pasteAdd","pasteSubtract","pasteMultiply","pasteDivide","multiplyBy100","multiplyBy1000","divideBy100","divideBy1000","signReversal","fillColorYellow","fillColorBlue","fillColorGreen","fillColorRed","fillColorCustom1","fillColorCustom2","fillColorCustom3","fillColorCustom4","fillColorCustom5","fontColorYellow","fontColorBlue","fontColorGreen","fontColorRed","fontColorCustom1","fontColorCustom2","fontColorCustom3","fontColorCustom4","fontColorCustom5","toggleRowHighlight","toggleColumnHighlight","toggleBothHighlight","toggleIntersectionHighlight"],Wh=/^[A-Z]$/,Vh=/^[A-Za-z]$/,Yh=/^Key([A-Z])$/,$a=new Set([...Array.from({length:10},(e,t)=>`Digit${t}`),...Array.from({length:10},(e,t)=>`Numpad${t}`),"NumpadAdd","NumpadSubtract","NumpadMultiply","NumpadDivide","NumpadDecimal","NumpadEnter",...Array.from({length:12},(e,t)=>`F${t+1}`),"Semicolon","Quote","Comma","Period","Slash","Backslash","BracketLeft","BracketRight","Backquote","Minus","Equal","IntlYen","IntlRo","IntlBackslash","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Kh=e=>Wh.test(e)||$a.has(e),Yt=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!Kh(l))throw new RangeError(`[spreadsheet] shortcut ${JSON.stringify(e)} is not canonical (expected Ctrl+Alt+Shift+KEY with used modifiers only, KEY = A-Z or a code name such as Digit1 / Semicolon / F2)`);return{ctrl:r,alt:o,shift:s,key:l}},Uh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,La=e=>{if(Vh.test(e.key))return e.key.toUpperCase();const t=Yh.exec(e.code);return t!==null?t[1]:$a.has(e.code)?e.code:null},pr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:La(t)===e.key,Re=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),Ee=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Xh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(Re(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(Re(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(Re(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(Re(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Gh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(Re(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(Re(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},Lr=[...Xh(),Re("Home","idle","row start (first visible column)"),Re("Ctrl+Home","idle","first visible cell"),Re("Shift+Home","idle","extend to row start"),Re("Ctrl+Shift+Home","idle","extend to first visible cell"),Re("End","idle","row end (last visible column)"),Re("Ctrl+End","idle","last visible cell"),Re("Shift+End","idle","extend to row end"),Re("Ctrl+Shift+End","idle","extend to last visible cell"),Re("PageUp","both","page up (idle) / commit + page up (editing)"),Re("PageDown","both","page down (idle) / commit + page down (editing)"),Re("Shift+PageUp","idle","extend one page up"),Re("Shift+PageDown","idle","extend one page down"),Re("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),Re("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),Re("Tab","both","cycle right (idle) / commit + cycle right (editing)"),Re("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),Re("Enter","both","cycle down (idle) / commit + cycle down (editing)"),Re("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),Re("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),Re("F2","both","start editing (idle) / toggle the pointing arm (editing)"),Re("F4","editing","cycle the reference anchor under the caret (formula session)"),Re("Delete","idle","clear every selected cell"),Re("Backspace","idle","clear every selected cell"),Re("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),Re("Ctrl+A","idle","select all"),Re("Ctrl+Z","idle","undo request"),Re("Ctrl+Y","idle","redo request"),Re("Ctrl+Shift+Z","idle","redo request"),Re("Shift+F10","idle","keyboard context menu"),Re("ContextMenu","idle","keyboard context menu"),Re("Ctrl+Space","idle","column bands"),Re("Shift+Space","idle","row bands"),Re("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),Re("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),Re("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),Re("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...Gh(),Ee("bold","Ctrl+B","both","toggle bold"),Ee("italic","Ctrl+I","both","toggle italic"),Ee("underline","Ctrl+U","both","toggle underline"),Ee("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),Ee("clearFormatting","Ctrl+Backslash","idle","clear formatting"),Ee("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),Ee("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),Ee("alignLeft","Ctrl+Shift+L","both","align left"),Ee("alignCenter","Ctrl+Shift+E","both","align center"),Ee("alignRight","Ctrl+Shift+R","both","align right"),Ee("formatNumber","Ctrl+Shift+Digit1","both","number format"),Ee("formatTime","Ctrl+Shift+Digit2","both","time format"),Ee("formatDate","Ctrl+Shift+Digit3","both","date format"),Ee("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),Ee("formatPercent","Ctrl+Shift+Digit5","both","percent format"),Ee("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),Ee("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),Ee("bordersClear","Alt+Shift+Digit6","idle","clear borders"),Ee("borderTop","Alt+Shift+Digit1","idle","top border"),Ee("borderRight","Alt+Shift+Digit2","idle","right border"),Ee("borderBottom","Alt+Shift+Digit3","idle","bottom border"),Ee("borderLeft","Alt+Shift+Digit4","idle","left border"),Ee("insertLink","Ctrl+K","idle","insert / edit hyperlink"),Ee("insertNote","Shift+F2","idle","insert / edit note"),Ee("insertComment","Ctrl+Alt+M","idle","insert comment"),Ee("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),Ee("openValidationList","Alt+ArrowDown","idle","open the validation list"),Ee("fillDown","Ctrl+D","idle","fill down"),Ee("fillRight","Ctrl+R","idle","fill right"),Ee("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),Ee("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),Ee("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),Ee("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),Ee("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),Ee("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),Ee("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),Ee("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),Ee("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),Ee("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),Ee("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],ss=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),vi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Zh=e=>{const t=Yt(e);if(t.key==="IntlYen"||t.key==="IntlRo"||t.key==="IntlBackslash")return null;const n=/^(?:Digit|Numpad)(\d)$/u.exec(t.key),r=n!==null?n[1]:t.key in vi?vi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},mo=(e,t)=>e.column==="both"||e.column===t,Jh=Array.from(new Set(Lr.filter(e=>!e.rebindable&&mo(e,"idle")).map(e=>e.chord))),go=new Set(Lr.filter(e=>e.command!==void 0&&mo(e,"editing")).map(e=>e.command)),Qh=new Set(Lr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Da=e=>{const t={};for(const n of Eo)t[n]=e(n);return t},za=Da(e=>Lr.filter(t=>t.command===e).map(t=>t.chord)),em=e=>{const t=new Map;for(const n of Eo){const r=e[n];if(r!=null)for(const o of r){const s=t.get(o);s===void 0?t.set(o,[n]):s.includes(n)||s.push(n)}}return t},tm=e=>{const t=new Set(Eo);for(const n of Object.keys(e)){if(!t.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not a SpreadsheetCommand`);const r=e[n];if(r!==void 0){if(Qh.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},nm=(e,t)=>{const n=Yt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=go.has(e);for(const o of Lr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(mo(o,"idle")||r&&mo(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},rm=e=>{e!==void 0&&tm(e);const t=Da(r=>{const o=e===void 0?void 0:e[r];return o===void 0?za[r]:o===null?[]:o});for(const r of Eo)for(const o of t[r])nm(r,o);const n=new Map;for(const[r,o]of em(t)){if(o.length>1)throw new RangeError(`[spreadsheet] shortcut ${r} bound to ${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`);n.set(r,o[0])}return n},Ts=(e,t)=>{const n=La(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=Uh({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}),s=e.get(o);return s===void 0?null:{command:s,chord:o}},om=(e,t)=>{const n=Ts(e,t);return n===null?null:n.command},sm=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","NumpadEnter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),lm=/^F(?:[1-9]|1[0-2])$/,im=e=>{const t=Yt(e);return t.alt||sm.has(t.key)?!1:t.ctrl||lm.test(t.key)},Zs=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],Si=[...rt.VIRTUAL_SCROLL_LABEL_KEYS,...Zs],$s=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),Ma=Object.freeze({en:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...$s.en}),ja:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...$s.ja})}),vn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,ki=e=>e==="commentCount"||e==="listMore",cm=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${vn(t)}`);for(const n of Zs){const r=e[n];if(!(ki(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=ki(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${vn(r)}`)}}},am=e=>{const t={};let n=!1;for(const r of rt.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},um=(e,t,n)=>{e[t]=n},Na=(e,t)=>{const n=rt.resolveVirtualScrollLocale(e);if(t===void 0)return Ma[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${vn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!Si.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Si.join(", ")}`);const s={...rt.resolveVirtualScrollLabels(n,am(t)),...$s[n]};for(const l of Zs){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&um(s,l,c)}return cm(s),Object.freeze(s)},dm=e=>{const t={};for(const n of rt.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},_e=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},Ei={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},fm={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},pm=(e,t,n,r)=>{switch(e){case"gt":case"gte":case"lt":case"lte":return`${r[e]} ${t}`;case"eq":return`equal to ${t}`;case"neq":return`not equal to ${t}`;case"between":return`between ${t} and ${n}`;default:return`not between ${t} and ${n}`}},ls=(e,t)=>{const n=r=>(o,s)=>`${e} ${pm(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},hm=Object.freeze({list:"Value must be one of the list items.",number:ls("Value must be a number",Ei),textLength:ls("Text length must be",Ei),date:ls("Value must be a date",fm),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),mm=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),is=Object.freeze({en:hm,ja:mm}),gm=Object.freeze({ok:!0}),wm="TRUE",Cm="FALSE",bm=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),ym=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Rm=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,vm=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Sm=/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/,Oi=e=>{const t=e.trim();if(!(Rm.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),a=c<0?s:s.slice(0,c),p=c<0?"":s.slice(c+1),g=a+p,y=g.search(/[^0]/);return y<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:g.slice(y).replace(/0+$/,""),point:a.length+l-y}},km=e=>e===1?-1:e===-1?1:0,Em=(e,t)=>{if(e.sign!==t.sign)return e.sign<t.sign?-1:1;if(e.sign===0)return 0;const n=e.point!==t.point?e.point<t.point?-1:1:e.digits===t.digits?0:e.digits<t.digits?-1:1;return e.sign===1?n:km(n)},Om=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Ai=e=>{const t=vm.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>Om(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Am=(e,t)=>{const n=[e.year,e.month,e.day,e.hour,e.minute,e.second],r=[t.year,t.month,t.day,t.hour,t.minute,t.second];for(let o=0;o<n.length;o+=1)if(n[o]!==r[o])return n[o]<r[o]?-1:1;return 0},xm=(e,t)=>e<t?-1:e>t?1:0,Tm=e=>e==="between"||e==="notBetween",$m=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Tm(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Lm=(e,t,n)=>{switch(e){case"gt":return t===1;case"gte":return t!==-1;case"lt":return t===-1;case"lte":return t!==1;case"eq":return t===0;case"neq":return t!==0;case"between":return t!==-1&&n!==1;default:return t===-1||n===1}},cs=(e,t,n,r,o,s)=>{const l=$m(e,t,n,r);return l===null?!0:o===null?!1:Lm(e,s(o,l.a),l.b===null?0:s(o,l.b))},Dm=e=>Number.isFinite(e)?e:null,zm=e=>{let t=0;for(const n of e)t+=1;return t},Mm=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Nm=(e,t)=>{switch(e.op){case"isEmail":return Sm.test(t);case"isUrl":return Mm(t)}if(e.value===void 0)return!0;switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);default:return t.endsWith(e.value)}},Fm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Fa=e=>({checked:e.checked===void 0?wm:e.checked,unchecked:e.unchecked===void 0?Cm:e.unchecked}),Pm=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!bm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${vn(e.op)} for type "${e.type}"`);return;case"text":if(!ym.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${vn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${vn(e.type)}`)}},_m=(e,t,n)=>{switch(e.type){case"list":return Im(e).has(t);case"number":return cs(e.op,e.a,e.b,Oi,Oi(t),Em);case"textLength":return cs(e.op,e.a,e.b,Dm,zm(t),xm);case"date":return cs(e.op,e.a,e.b,Ai,Ai(t),Am);case"text":return Nm(e,t);case"checkbox":{const r=Fa(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Fm(n(e.formula))}},Pa=(e,t,n)=>(Pm(e),t===""||_m(e,t,n)),xi=e=>e===void 0?void 0:e.trim(),qm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),xi(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),xi(e.b));case"text":return jm(e,t.text);case"checkbox":{const n=Fa(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},jm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},Ti=new WeakMap,Im=e=>{const t=Ti.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Ti.set(e,n),n},_a=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(is,n)){const o=Object.keys(is).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${vn(n)}`)}return Pa(e,t,r)?gm:{ok:!1,message:e.errorMessage===void 0?qm(e,is[n]):e.errorMessage}},Hm=e=>e.type!=="custom",Bm=(e,t)=>Hm(e)&&!Pa(e,t,void 0),qa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),ja=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Ia=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,Ha=(e,t,{scroll:n,frozenSize:r,trailingSize:o,extent:s})=>r>0&&t<r?e.indexAt(t):o>0&&s>0&&t>=s-o?e.indexAt(e.totalSize()-(s-t)):e.indexAt(t+n),Ba=(e,t)=>qa(e,t),Wa=(e,t)=>qa(e,t),Va=(e,t)=>ja(e,t),Ya=(e,t)=>ja(e,t),Sn=(e,t,n)=>Ia(e,t,n),kn=(e,t,n)=>Ia(e,t,n),Dr=(e,t,n)=>Ha(e,t,n),zr=(e,t,n)=>Ha(e,t,n),Wm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Ft=1,yr=3,Ur=e=>`${-Math.min(yr,Math.max(0,Math.floor(e)))}px`,Vm=(e,t,n)=>{const r=Math.min(e.endRow,t-1),o=Math.min(e.endCol,n-1);return e.startRow>r||e.startCol>o?null:{startRow:e.startRow,startCol:e.startCol,endRow:r,endCol:o}},$i=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,Li=(e,t)=>t===null?e:Math.min(e,t),Di=e=>e===null?"100%":`min(100%, ${e}px)`,zi=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,Mi=(e,t,n,r)=>{switch(e){case"f":return[0,n-1];case"s":return[n,t-r-1];case"t":return[t-r,t-1];case"m":return[0,t-1]}},Ni=Object.freeze([0,-1]),Fi=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const a=-c*Ft,p=c*(1+Ft),g=t>=r,y=n<=o,N=g?s:a,F=y?l:p;return F<=a||N>=p?!1:(e.near=Math.max(N,a),e.far=Math.min(F,p),e.nearOpen=!g||N<a,e.farOpen=!y||F>p,!0)},Xr=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),Pi=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,_i=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Ym=Object.freeze(["top","right","bottom","left"]),Km=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Um=e=>Ym.filter((t,n)=>(e&1<<n)!==0).join(" "),Ka=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Xm=16,Gm=450,Zm=e=>e>4?Math.floor(Gm/(5*e)):Xm,hr=(e,t)=>{const n=document.createElement("div");return n.className="aqsp-band",n.setAttribute("data-aqsp-band",e),t!==null&&n.setAttribute("data-aqsp-band-edge",t),n.style.display="none",n},qi=()=>({rowLeft:hr("row","left"),rowRight:hr("row","right"),colAbove:hr("column","above"),colBelow:hr("column","below"),cross:hr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Ls=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Gr=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},Zr=(e,t)=>Math.min(Math.max(e,0),t),ji="inset(100%)",Yn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Jm=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Yn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const N=`${t.height}px`;e.rowLeft.style.height=N,e.rowRight.style.height=N}const g=`translate(${Zr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;g!==s.rowLeftTransform&&(s.rowLeftTransform=g,e.rowLeft.style.transform=g);const y=`translate(${Zr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;y!==s.rowRightTransform&&(s.rowRightTransform=y,e.rowRight.style.transform=y)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Yn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const N=`${t.width}px`;e.colAbove.style.width=N,e.colBelow.style.width=N}const g=`translate(${t.left}px, ${Zr(t.top,n.clampHeight)-n.clampHeight}px)`;g!==s.colAboveTransform&&(s.colAboveTransform=g,e.colAbove.style.transform=g);const y=`translate(${t.left}px, ${Zr(t.top+t.height,n.clampHeight)}px)`;y!==s.colBelowTransform&&(s.colBelowTransform=y,e.colBelow.style.transform=y)}const a=r.intersection?"intersection":l!==c?l?"row":"column":null,p=a!==null;if(p!==s.crossShown&&(s.crossShown=p,Yn([e.cross],p)),a!==null){a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--_aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const g=`translate(${t.left}px, ${t.top}px)`;g!==s.crossTransform&&(s.crossTransform=g,e.cross.style.transform=g)}},Ii=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Yn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Yn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Yn([e.cross],!1))},Jr=e=>{for(const t of Ls(e))t.remove()},Qm=(e,t)=>{const n=e-1-t.lineBoxPx;return t.verticalAlign==="top"?0:t.verticalAlign==="bottom"?Math.max(0,n):Math.max(0,n/2)},eg=Object.freeze([]),Hi=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},Bi=e=>e.chrome[0]??e.active,Wi=e=>{e.chrome.length=0;for(const t of e.dividerSlots)t!==null&&e.chrome.push(t);e.frame!==null&&e.chrome.push(e.frame.node)},tg={left:"0px",right:"0px",width:""},ng={top:"0px",bottom:"0px",height:""},Vi=()=>({container:null,active:null,dragRect:null,marquee:null,fillPreview:null,resizeGuide:null,fillPool:[],bandPool:[],dragBand:null,bandClampWidth:-1,bandClampHeight:-1,dividerSlots:[null,null,null,null],dividerShown:[!1,!1,!1,!1],dividerEnd:["0px","0px","0px","0px"],frame:null,bandClip:null,bandClipWidth:"",bandClipHeight:"",chrome:[]}),Yi=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Ki=6,rg=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:a,getClip:p,getIsDraggingAny:g,getIsFillDragging:y,fillFrameRef:N,resizeGuideFrameRef:F,fillHandleNodeRef:M,enableFillHandle:q,frozenCols:X,frozenRows:K,trailingCols:T,trailingRows:$,sinkAriaLabel:P,sinkReadOnly:I,sinkKeyShortcuts:z,onSinkMouseDown:W,editPaintRef:D,highlightRef:m,frameRange:f,highlightColors:C,popoverAnchors:v,interactiveAnchorRef:A,tipAnchorRef:R})=>{const j=i.useRef(null),b=i.useRef(f);b.current=f;const E=f!==void 0,B=i.useRef(null),d=i.useRef(null),L=i.useRef(new Map(Yi.map(S=>[S,Vi()]))),O=i.useCallback(S=>{const x=L.current.get(S);if(x!==void 0)return x;const V=Vi();return L.current.set(S,V),V},[]),u=i.useCallback((S,x,V)=>{if(S===null)return;const _=S.style;_.left!==x.left&&(_.left=x.left),_.right!==x.right&&(_.right=x.right),_.width!==x.width&&(_.width=x.width),_.top!==V.top&&(_.top=V.top),_.bottom!==V.bottom&&(_.bottom=V.bottom),_.height!==V.height&&(_.height=V.height)},[]),h=i.useCallback((S,x,V)=>{if(!(S.bandClampWidth===x&&S.bandClampHeight===V)){S.bandClampWidth=x,S.bandClampHeight=V;for(const _ of S.bandPool)Gr(_,x,V);S.dragBand!==null&&Gr(S.dragBand,x,V)}},[]),k=i.useRef({rowAxis:e,colAxis:t});k.current={rowAxis:e,colAxis:t};const Y=i.useCallback((S,x,V)=>{const _=S.dividerSlots[x];_===null||S.dividerShown[x]===V||(S.dividerShown[x]=V,_.style.display=V?"":"none")},[]),G=i.useCallback((S,x,V)=>{const _=S.bandClip;_!==null&&(S.bandClipWidth!==x&&(S.bandClipWidth=x,_.style.width=x),S.bandClipHeight!==V&&(S.bandClipHeight=V,_.style.height=V))},[]),Q=i.useCallback((S,x,V)=>{const _=S.dividerSlots[x];_===null||S.dividerEnd[x]===V||(S.dividerEnd[x]=V,x<2?_.style.bottom=V:_.style.right=V)},[]),J=i.useRef({x:0,y:0}),re=i.useRef(null),te=i.useCallback((S,x)=>{const V=n.current,_=V?.getFrozenSize()??Wm,ee=V?.getViewportSize(),se=ee?.width??-1,ce=ee?.height??-1,pe=J.current;pe.x=S,pe.y=x;const xe=b.current!==void 0,he=k.current,Ie=xe?he.rowAxis.count:-1,Be=xe?he.colAxis.count:-1,qe=xe?he.rowAxis.totalSize():-1,oe=xe?he.colAxis.totalSize():-1;let ie=re.current;if(ie===null||ie.framed!==xe||ie.rowCount!==Ie||ie.colCount!==Be||ie.rowsTotal!==qe||ie.colsTotal!==oe||ie.frozenCols!==_.cols||ie.frozenWidth!==_.width||ie.frozenRows!==_.rows||ie.frozenHeight!==_.height||ie.trailingCols!==_.trailingCols||ie.trailingWidth!==_.trailingWidth||ie.trailingVisibleWidth!==_.trailingVisibleWidth||ie.trailingRows!==_.trailingRows||ie.trailingHeight!==_.trailingHeight||ie.trailingVisibleHeight!==_.trailingVisibleHeight||ie.bodyWidth!==se||ie.bodyHeight!==ce){const de=_.trailingVisibleWidth,Te=_.trailingVisibleHeight,et=_.cols<=0&&_.trailingCols<=0?[{kind:"m",map:Oe=>Oe-pe.x,clamp:se,style:tg,seamLead:!1,seamTrail:!1}]:[..._.cols>0?[{kind:"f",map:Oe=>Oe,clamp:_.width,style:{left:"0px",width:`${_.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Oe=>Oe-pe.x-_.width,clamp:Math.max(0,se-_.width-de),style:{left:`${_.width}px`,right:`${de}px`,width:""},seamLead:_.cols>0,seamTrail:_.trailingCols>0},..._.trailingCols>0?[{kind:"t",map:Oe=>Oe-k.current.colAxis.totalSize()+de,clamp:de,style:{left:"",right:"0px",width:`${de}px`},seamLead:!0,seamTrail:!1}]:[]],Ue=_.rows<=0&&_.trailingRows<=0?[{kind:"m",map:Oe=>Oe-pe.y,clamp:ce,style:ng,seamLead:!1,seamTrail:!1}]:[..._.rows>0?[{kind:"f",map:Oe=>Oe,clamp:_.height,style:{top:"0px",height:`${_.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Oe=>Oe-pe.y-_.height,clamp:Math.max(0,ce-_.height-Te),style:{top:`${_.height}px`,bottom:`${Te}px`,height:""},seamLead:_.rows>0,seamTrail:_.trailingRows>0},..._.trailingRows>0?[{kind:"t",map:Oe=>Oe-k.current.rowAxis.totalSize()+Te,clamp:Te,style:{top:"",bottom:"0px",height:`${Te}px`},seamLead:!0,seamTrail:!1}]:[]],Xe=[];for(const Oe of et){const dt=xe?$i(Oe.kind,oe,_.width,_.trailingWidth):null,[ft,yt]=xe?Mi(Oe.kind,Be,_.cols,_.trailingCols):Ni;for(const Pe of Ue){const Ge=xe?$i(Pe.kind,qe,_.height,_.trailingHeight):null,[$o,Lo]=xe?Mi(Pe.kind,Ie,_.rows,_.trailingRows):Ni;Xe.push({nodes:O(`${Oe.kind}${Pe.kind}`),xKind:Oe.kind,yKind:Pe.kind,mapX:Oe.map,clampWidth:Oe.clamp,xStyle:Oe.style,xSeamLead:Oe.seamLead,xSeamTrail:Oe.seamTrail,xFirst:ft,xLast:yt,mapY:Pe.map,clampHeight:Pe.clamp,yStyle:Pe.style,ySeamLead:Pe.seamLead,ySeamTrail:Pe.seamTrail,yFirst:$o,yLast:Lo,cells:{clampWidth:Li(Oe.clamp,dt),clampHeight:Li(Pe.clamp,Ge)},xCellsSizeCss:Di(dt),yCellsSizeCss:Di(Ge),xCellsEndCss:zi(dt),yCellsEndCss:zi(Ge)})}}ie={frozenCols:_.cols,frozenWidth:_.width,frozenRows:_.rows,frozenHeight:_.height,trailingCols:_.trailingCols,trailingWidth:_.trailingWidth,trailingVisibleWidth:_.trailingVisibleWidth,trailingRows:_.trailingRows,trailingHeight:_.trailingHeight,trailingVisibleHeight:_.trailingVisibleHeight,bodyWidth:se,bodyHeight:ce,framed:xe,rowCount:Ie,colCount:Be,rowsTotal:qe,colsTotal:oe,ctxs:Xe},re.current=ie}const ve=_.width>0,Se=_.trailingWidth>0,ye=_.height>0,st=_.trailingHeight>0;for(const de of ie.ctxs)u(de.nodes.container,de.xStyle,de.yStyle),h(de.nodes,de.clampWidth,de.clampHeight),Y(de.nodes,0,ve),Y(de.nodes,1,Se),Y(de.nodes,2,ye),Y(de.nodes,3,st),Q(de.nodes,0,de.yCellsEndCss),Q(de.nodes,1,de.yCellsEndCss),Q(de.nodes,2,de.xCellsEndCss),Q(de.nodes,3,de.xCellsEndCss),G(de.nodes,de.xCellsSizeCss,de.yCellsSizeCss);return ie.ctxs},[n,O,u,h,Y,Q,G]),ue=i.useCallback((S,x,V)=>{S.dividerSlots[x]=V,S.dividerShown[x]=!1,S.dividerEnd[x]="0px",Wi(S)},[]),ae=i.useCallback((S,x)=>{S.frame=x===null?null:{node:x,x:Xr(),y:Xr(),drawnX:Xr(),drawnY:Xr(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},Wi(S)},[]),Ae=i.useCallback((S,x)=>{for(const _ of S.bandPool)Jr(_);S.bandPool.length=0,S.dragBand!==null&&(Jr(S.dragBand),S.dragBand=null),S.bandClampWidth=-1,S.bandClampHeight=-1,S.bandClip=x,S.bandClipWidth="",S.bandClipHeight="";const V=x===null?null:x.parentElement;x!==null&&V!==null&&V.firstChild!==x&&V.insertBefore(x,V.firstChild)},[]),$e=i.useCallback(S=>{const x=()=>O(S);return{container:V=>{const _=x();_.container=V,V===null&&(_.fillPool.length=0,_.bandPool.length=0,_.dragBand=null,_.bandClampWidth=-1,_.bandClampHeight=-1)},dividerXLeading:V=>ue(x(),0,V),dividerXTrailing:V=>ue(x(),1,V),dividerYLeading:V=>ue(x(),2,V),dividerYTrailing:V=>ue(x(),3,V),frame:V=>ae(x(),V),bandClip:V=>Ae(x(),V),active:V=>{x().active=V},dragRect:V=>{x().dragRect=V},marquee:V=>{x().marquee=V},fillPreview:V=>{x().fillPreview=V},resizeGuide:V=>{x().resizeGuide=V}}},[O,ue,ae,Ae]),Ne=i.useMemo(()=>Object.fromEntries(Yi.map(S=>[S,$e(S)])),[$e]),Fe=Math.min(Math.max(0,X),t.count),Tt=Ba(t,Fe),Ce=Math.min(Math.max(0,K),e.count),We=Wa(e,Ce),ot=T===void 0?0:Math.min(Math.max(0,T),t.count-Fe),$t=Va(t,ot),ut=$===void 0?0:Math.min(Math.max(0,$),e.count-Ce),Zt=Ya(e,ut),Qe=i.useRef(null),Ct=i.useRef("add"),_t=i.useRef(s);_t.current=s;const Mr=i.useRef(!1),Qn=rt.useWheelBridge(n,{enableBridge:!s}),Oo=i.useCallback(S=>(r.current=S,Qn(S)),[r,Qn]),En=i.useCallback((S,x)=>({top:x.mapY(e.offsetOf(S.startRow)),bottom:x.mapY(e.offsetOf(S.endRow)+e.sizeOf(S.endRow)),left:x.mapX(t.offsetOf(S.startCol)),right:x.mapX(t.offsetOf(S.endCol)+t.sizeOf(S.endCol))}),[e,t]),le=i.useCallback((S,x)=>{if(x.clampHeight<=0||x.clampWidth<=0)return null;const{top:V,bottom:_,left:ee,right:se}=En(S,x),ce=-x.clampHeight*Ft,pe=x.clampHeight*(1+Ft),xe=-x.clampWidth*Ft,he=x.clampWidth*(1+Ft);if(_<ce||V>pe||se<xe||ee>he)return null;const Ie=Math.max(V,ce),Be=Math.max(ee,xe);return{top:Ie,left:Be,width:Math.min(se,he)-Be,height:Math.min(_,pe)-Ie}},[En]),be=i.useCallback((S,x)=>{if(x.clampHeight<=0||x.clampWidth<=0)return null;const V=En(S,x),_=-x.clampHeight*Ft,ee=x.clampHeight*(1+Ft),se=-x.clampWidth*Ft,ce=x.clampWidth*(1+Ft),pe=Math.min(Math.max(V.top,_),ee),xe=Math.min(Math.max(V.left,se),ce);return{top:pe,left:xe,width:Math.min(Math.max(V.right,se),ce)-xe,height:Math.min(Math.max(V.bottom,_),ee)-pe}},[En]),ge=i.useCallback(()=>{if(m===void 0)return null;const S=m.current;return S.row||S.column||S.intersection?S:null},[m]),Jt=i.useCallback((S,x,V)=>{if(x.bandClip!==null){for(const ee of Ls(V))x.bandClip.appendChild(ee);return}const _=x.fillPool[0]?.node??Bi(x);for(const ee of Ls(V))S.insertBefore(ee,_)},[]),De=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),On=i.useCallback(S=>{const x=S.nodes.frame;if(x===null)return;const V=De.current,_=b.current;(V.range!==_||V.rows!==e.count||V.cols!==t.count)&&(V.range=_,V.rows=e.count,V.cols=t.count,V.within=_===void 0?null:Vm(_,e.count,t.count));const ee=V.within,se=x.last,ce=x.node.style;if(!(ee!==null&&Fi(x.x,ee.startCol,ee.endCol,S.xFirst,S.xLast,S.mapX(t.offsetOf(ee.startCol)),S.mapX(t.offsetOf(ee.endCol)+t.sizeOf(ee.endCol)),S.clampWidth)&&Fi(x.y,ee.startRow,ee.endRow,S.yFirst,S.yLast,S.mapY(e.offsetOf(ee.startRow)),S.mapY(e.offsetOf(ee.endRow)+e.sizeOf(ee.endRow)),S.clampHeight))){se.shown&&(se.shown=!1,ce.display="none");return}if(se.shown||(se.shown=!0,ce.display="block"),!Pi(x.x,x.drawnX)){_i(x.drawnX,x.x);const he=Hi(x.x);he.start!==se.left&&(se.left=he.start,ce.left=he.start),he.end!==se.right&&(se.right=he.end,ce.right=he.end),he.size!==se.width&&(se.width=he.size,ce.width=he.size)}if(!Pi(x.y,x.drawnY)){_i(x.drawnY,x.y);const he=Hi(x.y);he.start!==se.top&&(se.top=he.start,ce.top=he.start),he.end!==se.bottom&&(se.bottom=he.end,ce.bottom=he.end),he.size!==se.height&&(se.height=he.size,ce.height=he.size)}const xe=Km(x.x,x.y);xe!==se.open&&(se.open=xe,xe===0?x.node.removeAttribute("data-aqsp-frame-open"):x.node.setAttribute("data-aqsp-frame-open",Um(xe)))},[e,t]),bt=i.useCallback((S,x,V,_)=>{const ee=be(x,V);if(ee===null){Ii(S);return}Jm(S,ee,V,_,Ic(x,t.count)||Hc(x,e.count))},[be,e,t]),Nr=i.useCallback((S,x,V,_)=>{const ee=S.nodes.bandPool;for(;ee.length>V.length;){const se=ee.pop();se!==void 0&&Jr(se)}if(_===null){S.nodes.dragBand!==null&&(Jr(S.nodes.dragBand),S.nodes.dragBand=null);return}for(let se=0;se<V.length;se+=1){let ce=ee[se];ce===void 0&&(ce=qi(),Gr(ce,S.clampWidth,S.clampHeight),Jt(x,S.nodes,ce),ee.push(ce)),bt(ce,V[se],S,_)}},[Jt,bt]),qt=i.useCallback((S,x,V)=>{const _=S.nodes.container;if(_===null)return;if(x===null||V===null){S.nodes.dragBand!==null&&Ii(S.nodes.dragBand);return}let ee=S.nodes.dragBand;ee===null&&(ee=qi(),Gr(ee,S.clampWidth,S.clampHeight),Jt(_,S.nodes,ee),S.nodes.dragBand=ee),bt(ee,x,S,V)},[Jt,bt]),Qt=i.useCallback((S,x)=>{if(S!==null){if(x===null){S.style.display="none";return}S.style.display="block",S.style.transform=`translate(${x.left}px, ${x.top}px)`,S.style.width=`${x.width}px`,S.style.height=`${x.height}px`}},[]),An=i.useCallback((S,x,V,_)=>{const ee=_==="point"?null:ge();for(const se of te(V,x))Qt(se.nodes.dragRect,le(S,se)),qt(se,S,ee)},[le,te,Qt,ge,qt]),xn=i.useCallback((S,x,V)=>{for(const _ of te(V,x))Qt(_.nodes.fillPreview,S===null?null:le(S,_))},[le,te,Qt]),hn=i.useCallback((S,x,V)=>{for(const _ of te(V,x)){const ee=_.nodes.resizeGuide;if(ee===null)continue;if(S===null){ee.style.display="none";continue}const se=S.anchor==="trailing";if(S.axis==="col"){if(se&&_.xKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ce=_.mapX(S.position);ee.style.transform=`translate(${se?Math.max(0,ce):ce}px, 0px)`,ee.style.width="1px",ee.style.height="100%"}else{if(se&&_.yKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ce=_.mapY(S.position);ee.style.transform=`translate(0px, ${se?Math.max(0,ce):ce}px)`,ee.style.width="100%",ee.style.height="1px"}}},[te]),er=i.useCallback((S,x,V,_,ee,se,ce)=>{if(S===null)return;if(x===null||ce<=0||se<=0){S.style.clipPath=ji;return}const pe=kn(e,x.row,_),xe=Sn(t,x.col,V),he=t.sizeOf(x.col),Ie=e.sizeOf(x.row),Be=xe>=se||pe>=ce,qe=x.col>=ee.cols&&xe<ee.width,oe=x.row>=ee.rows&&pe<ee.height,ie=ee.trailingWidth>0&&x.col<t.count-ee.trailingCols&&xe+he>se-ee.trailingVisibleWidth,ve=ee.trailingHeight>0&&x.row<e.count-ee.trailingRows&&pe+Ie>ce-ee.trailingVisibleHeight;if(Be||qe||oe||ie||ve){S.style.clipPath=ji;return}S.style.clipPath="",S.style.transform=`translate(${xe}px, ${pe}px)`;const Se=`${he} ${Ie}`;S.dataset.aqspAnchorSig!==Se&&(S.dataset.aqspAnchorSig=Se,S.style.width=`${he}px`,S.style.height=`${Ie}px`)},[e,t]),Ao=i.useCallback((S,x,V)=>{if(v===void 0)return;const _=v.current,{width:ee,height:se}=S.getViewportSize(),ce=S.getFrozenSize(),pe={scroll:V,frozenCount:ce.cols,trailingCount:ce.trailingCols,extent:ee},xe={scroll:x,frozenCount:ce.rows,trailingCount:ce.trailingRows,extent:se};er(A===void 0?null:A.current,_.interactive,pe,xe,ce,ee,se),er(R===void 0?null:R.current,_.tip,pe,xe,ce,ee,se)},[v,A,R,er]),tr=i.useCallback(()=>{const S=j.current,x=n.current;if(S===null||x===null)return;const V=x.getScrollPosition(),_=Math.max(0,V.y),ee=Math.max(0,V.x),se=o(),ce=te(ee,_),pe=ge(),xe=pe===null?eg:se.ranges.slice(-Zm(ce.length));for(const oe of ce){const ie=oe.nodes.container;if(ie===null)continue;const ve=oe.nodes.fillPool;for(let Se=0;Se<Math.max(ve.length,se.ranges.length);Se+=1){let ye=ve[Se];if(ye===void 0){const Te=document.createElement("div");Te.className="aqsp-selection-fill",Te.setAttribute("data-aqsp-fill",""),Te.style.display="none",ie.insertBefore(Te,Bi(oe.nodes)),ye={node:Te,last:{shown:!1,width:-1,height:-1,transform:""}},ve.push(ye)}const st=se.ranges[Se],de=st===void 0?null:le(st,oe);if(de===null)ye.last.shown&&(ye.last.shown=!1,ye.node.style.display="none");else{ye.last.shown||(ye.last.shown=!0,ye.node.style.display="block");const Te=`translate(${de.left}px, ${de.top}px)`;Te!==ye.last.transform&&(ye.last.transform=Te,ye.node.style.transform=Te),de.width!==ye.last.width&&(ye.last.width=de.width,ye.node.style.width=`${de.width}px`),de.height!==ye.last.height&&(ye.last.height=de.height,ye.node.style.height=`${de.height}px`)}}for(;ve.length>se.ranges.length;)ve.pop()?.node.remove();Qt(oe.nodes.active,le(me(se.active,se.active),oe)),On(oe),Nr(oe,ie,xe,pe)}const he=p(),Ie=he===null||he.foreign?null:he;for(const oe of ce){const ie=oe.nodes.marquee;if(ie===null)continue;const ve=Ie===null?null:le(Ie.range,oe),Se=ve!==null&&(oe.xSeamTrail&&ve.left>=oe.clampWidth&&ve.left<oe.clampWidth+yr||oe.xSeamLead&&ve.left+ve.width<=0&&ve.left+ve.width>-yr||oe.ySeamTrail&&ve.top>=oe.clampHeight&&ve.top<oe.clampHeight+yr||oe.ySeamLead&&ve.top+ve.height<=0&&ve.top+ve.height>-yr)?null:ve;if(Se===null)ie.style.display="none";else{ie.style.display="block",ie.style.transform=`translate(${Se.left}px, ${Se.top}px)`,ie.style.width=`${Se.width}px`,ie.style.height=`${Se.height}px`;const de=Ur(Se.top),Te=Ur(Se.left),et=Ur(oe.cells.clampHeight-(Se.top+Se.height)),Ue=Ur(oe.cells.clampWidth-(Se.left+Se.width)),Xe=`${de} ${Ue} ${et} ${Te}`;Xe!==ie.dataset.aqspOutsetSig&&(ie.dataset.aqspOutsetSig=Xe,ie.style.setProperty("--aqsp-clip-outset-top",de),ie.style.setProperty("--aqsp-clip-outset-right",Ue),ie.style.setProperty("--aqsp-clip-outset-bottom",et),ie.style.setProperty("--aqsp-clip-outset-left",Te))}const ye=Se===null?null:Ie?.kind??null,st=ie.dataset.aqspClipKindLast??null;ye!==st&&(ye===null?(delete ie.dataset.aqspClipKindLast,ie.removeAttribute("data-aqsp-clip-kind")):(ie.dataset.aqspClipKindLast=ye,ie.setAttribute("data-aqsp-clip-kind",ye)))}Qe.current!==null&&An(Qe.current,_,ee,Ct.current),d.current!==null&&hn(d.current,_,ee),B.current!==null&&xn(B.current,_,ee);const Be=M.current;if(Be!==null&&!y()){const{width:oe,height:ie}=x.getViewportSize(),ve=se.ranges[se.ranges.length-1];if(!(se.ranges.length===1&&!_t.current&&!g())||ie<=0||oe<=0)Be.style.display="none";else{const ye=x.getFrozenSize(),st={scroll:ee,frozenCount:ye.cols,trailingCount:ye.trailingCols,extent:oe},de={scroll:_,frozenCount:ye.rows,trailingCount:ye.trailingRows,extent:ie},Te=ve.endCol<ye.cols,et=ve.endRow<ye.rows,Ue=ve.endCol>=t.count-ye.trailingCols,Xe=ve.endRow>=e.count-ye.trailingRows,Oe=Sn(t,ve.endCol,st)+t.sizeOf(ve.endCol),dt=kn(e,ve.endRow,de)+e.sizeOf(ve.endRow),ft=Te||Ue?0:ye.width,yt=et||Xe?0:ye.height,Pe=Ue?oe:oe-ye.trailingVisibleWidth,Ge=Xe?ie:ie-ye.trailingVisibleHeight;dt<=yt||dt>Ge||Oe<=ft||Oe>Pe?Be.style.display="none":(Be.style.display="block",Be.style.transform=`translate(${Oe-Ki+1}px, ${dt-Ki+1}px)`)}}const qe=r.current;if(qe!==null){const oe=se.active,{width:ie,height:ve}=x.getViewportSize(),Se=x.getFrozenSize(),ye={scroll:ee,frozenCount:Se.cols,trailingCount:Se.trailingCols,extent:ie},st={scroll:_,frozenCount:Se.rows,trailingCount:Se.trailingRows,extent:ve},de=kn(e,oe.row,st),Te=Sn(t,oe.col,ye),et=ve>0?Math.min(Math.max(de,0),Math.max(0,ve-1)):0,Ue=ie>0?Math.min(Math.max(Te,0),Math.max(0,ie-1)):0;qe.style.top=`${et}px`,qe.style.left=`${Ue}px`,_t.current?(qe.style.width=`${t.sizeOf(oe.col)}px`,qe.style.height=`${e.sizeOf(oe.row)}px`,qe.style.paddingTop=`${Qm(e.sizeOf(oe.row),D===void 0?Vt:D.current)}px`):(qe.style.width="1px",qe.style.height="1px",qe.style.paddingTop="0px");const Xe=oe.col>=Se.cols&&Te<Se.width,Oe=oe.row>=Se.rows&&de<Se.height,dt=Se.trailingWidth>0&&oe.col<t.count-Se.trailingCols&&Te+t.sizeOf(oe.col)>ie-Se.trailingVisibleWidth,ft=Se.trailingHeight>0&&oe.row<e.count-Se.trailingRows&&de+e.sizeOf(oe.row)>ve-Se.trailingVisibleHeight,yt=_t.current&&de===et&&Te===Ue&&!Xe&&!Oe&&!dt&&!ft;yt!==Mr.current&&(Mr.current=yt,yt?qe.setAttribute("data-aqsp-editing",""):qe.removeAttribute("data-aqsp-editing"))}Ao(x,_,ee)},[n,le,te,Qt,An,hn,xn,p,o,g,y,M,r,e,t,ge,Nr,On,D,Ao]),nr=i.useCallback((S,x)=>{Qe.current=S,Ct.current=x;const V=S===null?"add":x;for(const se of te(0,0)){const ce=se.nodes.dragRect;if(ce===null)continue;const pe=ce.dataset.aqspDragModeLast??"add";V!==pe&&(ce.dataset.aqspDragModeLast=V,V==="add"?ce.removeAttribute("data-aqsp-drag-mode"):ce.setAttribute("data-aqsp-drag-mode",V))}const _=n.current;if(S===null||_===null){for(const se of te(0,0))se.nodes.dragRect!==null&&(se.nodes.dragRect.style.display="none"),qt(se,null,null);return}const ee=_.getScrollPosition();An(S,Math.max(0,ee.y),Math.max(0,ee.x),x)},[n,An,te,qt]),Tn=i.useCallback(S=>{B.current=S;const x=n.current;if(x===null){for(const _ of te(0,0))_.nodes.fillPreview!==null&&(_.nodes.fillPreview.style.display="none");return}const V=x.getScrollPosition();xn(S,Math.max(0,V.y),Math.max(0,V.x))},[n,xn,te]),rr=i.useCallback(S=>{d.current=S;const x=n.current;if(x===null){for(const _ of te(0,0))_.nodes.resizeGuide!==null&&(_.nodes.resizeGuide.style.display="none");return}const V=x.getScrollPosition();hn(S,Math.max(0,V.y),Math.max(0,V.x))},[n,hn,te]);i.useLayoutEffect(()=>{const S=j.current;if(!(S===null||C===void 0))return S.style.setProperty("--aqsp-band-row",C.row),S.style.setProperty("--aqsp-band-column",C.column),S.style.setProperty("--aqsp-band-intersection",C.intersection),S.style.setProperty("--aqsp-band-opacity",String(C.opacity)),()=>{S.style.removeProperty("--aqsp-band-row"),S.style.removeProperty("--aqsp-band-column"),S.style.removeProperty("--aqsp-band-intersection"),S.style.removeProperty("--aqsp-band-opacity")}},[C]),i.useEffect(()=>(c.current=tr,a.current=nr,N.current=Tn,F.current=rr,()=>{c.current=null,a.current=null,N.current=null,F.current=null})),i.useEffect(()=>{tr()},[tr,s,Fe,Ce,ot,ut]),i.useEffect(()=>{const S=r.current;if(S===null)return;const x=V=>W(V);return S.addEventListener("mousedown",x),()=>S.removeEventListener("mousedown",x)},[r,W]);const or=Fe>0||ot>0?[...Fe>0?[{k:"f",style:{left:0,width:Tt}}]:[],{k:"s",style:{left:Tt,right:$t}},...ot>0?[{k:"t",style:{right:0,width:$t}}]:[]]:[{k:"m",style:{left:0,right:0}}],en=Ce>0||ut>0?[...Ce>0?[{k:"f",style:{top:0,height:We}}]:[],{k:"s",style:{top:We,bottom:Zt}},...ut>0?[{k:"t",style:{bottom:0,height:Zt}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],He=S=>S==="m"?0:S==="s"?1:S==="t"?2:3,xo=or.flatMap(S=>en.map(x=>({xk:S.k,yk:x.k,key:`${S.k}${x.k}`,style:{...S.style,...x.style}}))).sort((S,x)=>He(S.key[0])+He(S.key[1])-(He(x.key[0])+He(x.key[1]))),To=S=>S==="mm"?{"data-aqsp-overlay-main":""}:S==="fm"?{"data-aqsp-overlay-frozen":""}:S==="sm"?{"data-aqsp-overlay-scroll":""}:{};return U.jsxs("div",{ref:j,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:ze.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:ze.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[xo.map(({xk:S,yk:x,key:V,style:_})=>{const ee=Ne[V];return U.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":V,...To(V),style:_,ref:ee.container,children:[E?U.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:ee.bandClip}):null,S==="s"&&Fe>0?U.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:ee.dividerXLeading}):null,S==="s"&&ot>0?U.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:ee.dividerXTrailing}):null,x==="s"&&Ce>0?U.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:ee.dividerYLeading}):null,x==="s"&&ut>0?U.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:ee.dividerYTrailing}):null,E?U.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:ee.frame}):null,U.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:ee.active}),U.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:ee.dragRect}),U.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:ee.marquee}),U.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:ee.fillPreview}),U.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:ee.resizeGuide})]},V)}),U.jsx("textarea",{ref:Oo,className:"aqsp-sink","aria-label":P,"aria-readonly":I?"true":void 0,"aria-keyshortcuts":z,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),q?U.jsx("div",{ref:M,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ua=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=y=>{l.current=!0;try{y()}finally{l.current=!1}},a=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},p=y=>{if(y.key==="Escape"){y.preventDefault(),c(e.close);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&!y.altKey&&!y.shiftKey&&(y.preventDefault(),a())},g=y=>{l.current||y.relatedTarget instanceof Node&&y.currentTarget.contains(y.relatedTarget)||e.rejected||c(e.close)};return U.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:g,children:[U.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[_e(t,"commentTitle"),U.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:_e(t,"commentCount",e.current.length)})]}),U.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(y=>U.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":y.id,children:[U.jsx("span",{className:"aqsp-popover-comment-author",children:y.author}),U.jsx("time",{className:"aqsp-popover-comment-time",dateTime:y.createdAt,children:y.createdAt}),U.jsx("p",{className:"aqsp-popover-comment-text",children:y.text})]},y.id))}),U.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":_e(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:y=>r(y.currentTarget.value),onKeyDown:p}),U.jsxs("div",{className:"aqsp-popover-actions",children:[U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:a,children:_e(t,"commentPost")}),U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Xa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),a=i.useRef(!1),p=o.trim()===""?null:fn(o),g=o.trim()!==""&&p===null,y=q=>{a.current=!0;try{q()}finally{a.current=!1}},N=()=>{l||g||y(()=>e.commit({text:n===""&&p!==null?p:n,url:p}))},F=q=>{if(q.key==="Escape"){q.preventDefault(),y(e.close);return}q.key==="Enter"&&!q.altKey&&!q.shiftKey&&(q.preventDefault(),N())},M=q=>{a.current||q.relatedTarget instanceof Node&&q.currentTarget.contains(q.relatedTarget)||e.rejected||y(e.close)};return U.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":g?"":void 0,role:"dialog","aria-labelledby":c,onBlur:M,children:[U.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:_e(t,"linkTitle")}),U.jsxs("label",{className:"aqsp-popover-field",children:[U.jsx("span",{className:"aqsp-popover-field-label",children:_e(t,"linkTextField")}),U.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:q=>r(q.currentTarget.value),onKeyDown:F})]}),U.jsxs("label",{className:"aqsp-popover-field",children:[U.jsx("span",{className:"aqsp-popover-field-label",children:_e(t,"linkUrlField")}),U.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":g||e.rejected?!0:void 0,onChange:q=>s(q.currentTarget.value),onKeyDown:F})]}),U.jsxs("div",{className:"aqsp-popover-actions",children:[U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:g||l,"aria-disabled":l?"true":void 0,onClick:N,children:_e(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:_e(t,"linkOpen")}):null,U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>y(e.close),children:"×"})]})]})},Ui=500,Ga=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),a=i.useMemo(()=>{const K=n.toLowerCase();return e.current.filter(T=>T.toLowerCase().startsWith(K))},[e.current,n]),p=i.useMemo(()=>a.length>Ui?a.slice(0,Ui):a,[a]),g=a.length-p.length,y=p.length===0?-1:Math.min(o,p.length-1),N=K=>{c.current=!0;try{K()}finally{c.current=!1}},F=()=>{y<0||N(()=>e.commit(p[y]))},M=K=>{if(K.key==="Escape"){K.preventDefault(),N(e.close);return}if(K.key==="Enter"){K.preventDefault(),F();return}if(K.key==="ArrowDown"){K.preventDefault(),s(y+1);return}K.key==="ArrowUp"&&(K.preventDefault(),s(Math.max(y-1,0)))},q=K=>{c.current||K.relatedTarget instanceof Node&&K.currentTarget.contains(K.relatedTarget)||N(e.close)},X=K=>`${l}-${K}`;return U.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:q,children:[U.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":_e(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":y<0?void 0:X(y),value:n,onChange:K=>{r(K.currentTarget.value),s(0)},onKeyDown:M}),U.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":_e(t,"listTitle"),children:[p.length===0?U.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:_e(t,"listEmpty")}):p.map((K,T)=>U.jsx("div",{className:"aqsp-popover-option",id:X(T),role:"option",tabIndex:-1,"aria-selected":T===y,"data-aqsp-list-option":K,onPointerDown:$=>$.preventDefault(),onClick:()=>N(()=>e.commit(K)),children:K},X(T))),g>0?U.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:_e(t,"listMore",g)}):null]})]})},Za=({ctx:e,labels:t})=>U.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[U.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),U.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ja=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),a=i.useRef(!1),p=M=>{a.current=!0;try{M()}finally{a.current=!1}},g=()=>{s||p(()=>e.commit(r===""?null:r))},y=()=>{r!==n&&!s?g():p(e.close)},N=M=>{if(M.key==="Escape"){M.preventDefault(),e.rejected?p(e.close):y();return}M.key==="Enter"&&(M.ctrlKey||M.metaKey)&&!M.altKey&&!M.shiftKey&&(M.preventDefault(),g())},F=M=>{a.current||M.relatedTarget instanceof Node&&M.currentTarget.contains(M.relatedTarget)||e.rejected||y()};return U.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:F,children:[U.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:_e(t,"noteTitle")}),U.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:M=>o(M.currentTarget.value),onKeyDown:N}),U.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:_e(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),U.jsxs("div",{className:"aqsp-popover-actions",children:[U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:g,children:_e(t,"noteSave")}),U.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>p(e.close),children:"×"})]})]})},Qa=({ctx:e})=>U.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Bt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),Xi=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],eu=Object.freeze({all:Bt(Xi),values:Bt(["text"]),formats:Bt(["format","borders","cf"]),formulas:Bt(["text","formula"]),noBorders:Bt(Xi.filter(e=>e!=="borders")),columnWidths:Bt(["sizes"]),validation:Bt(["validation"]),conditionalFormats:Bt(["cf"]),commentsAndNotes:Bt(["note","comments"])}),Gi=Object.freeze({mode:"all"}),Ds=Object.freeze({t:""}),Zi=Object.freeze({row:1<<30,col:1<<30}),og=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),sg=e=>e.t===""&&e.f===void 0,lg=e=>e.length>1&&e.startsWith("="),ig=(e,t,n)=>{switch(n){case"add":return e+t;case"subtract":return e-t;case"multiply":return e*t;case"divide":return e/t}},Ji=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,cg=(e,t,n,r)=>{const o=lg(e),s=e===""?"0":gt(e);if(!o&&s===null)return null;const l=og[n];if(t.f!==void 0){const p=$r(t.f,r),g=p.startsWith("=")?p.slice(1):p;return`=(${o?e.slice(1):s})${l}(${g})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Ji(Number(s));const c=gt(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${l}(${c})`:Ji(ig(Number(s),a,n))},Qi=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),ag=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:Qi(e.start),end:Qi(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},ug=e=>{const t=$r(e,Zi),n=Tr(t);let r="",o=0,s=!1;for(const l of n){const c=ag(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${cn(c)}`,o=l.end,s=!0)}return s?vo(`${r}${t.slice(o)}`,Zi):e},dg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Ds;const o=r[n];return o===void 0?Ds:o},fg=e=>{const{rows:t,cols:n}=e,r=ta(ug);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let p=0;p<t;p+=1){const g=dg(e,p,c);let y=g;if(g.f!==void 0){const N=r(g.f);y=N===g.f?g:{...g,f:N}}(y!==g||g===Ds)&&(o=!1),a.push(y)}s.push(a)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},pg=(e,t)=>!t.formula&&e.f!==void 0||!t.format&&e.fmt!==void 0||!t.validation&&e.val!==void 0||!t.note&&e.note!==void 0||!t.comments&&e.comments!==void 0||!t.hyperlink&&e.link!==void 0,hg=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},ec=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const p=[];for(const g of c)pg(g,t)?(p.push(hg(g,t)),a=!0):p.push(g);a&&(n=!0),r.push(a?p:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},tc=new WeakMap,tu=e=>{const t=tc.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>xt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:xt({...s,borders:void 0})),o={canonical:n,borderless:r};return tc.set(e,o),o},wo=(e,t)=>t===void 0?void 0:e[t],mg=(e,t,n,r)=>{const o=tu(e);if(n){const p=wo(o.canonical,t.fmt);return p===void 0?null:p}const s=wo(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const a=xt(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},gg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?cg(n.readText(),o,r,n):o.f===void 0?o.t:$r(o.f,n)},nc=(e,t,n,r,o)=>{const s=eu[r.mode];if(r.skipBlanks===!0&&sg(e))return null;const l={};let c=!1;if(s.text){const a=gg(e,s.formula&&o.formula,n,r.operation);a!==null&&(l.text=a,c=!0)}if(o.format){if(s.format)l.format=mg(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=wo(tu(t).canonical,e.fmt);a!==void 0&&(l.format=a,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const a=wo(t.validations,e.val);l.validation=a===void 0?null:a,c=!0}return c?l:null},rc=(e,t)=>e.length===0?e:t.length===0?[]:e.map(n=>{const r=[];for(const o of t)for(const s of n.ranges)r.push({startRow:o.row+s.startRow,startCol:o.col+s.startCol,endRow:o.row+s.endRow,endCol:o.col+s.endCol});return{...n,ranges:r}}),wg=["text/html","text/plain"],Cg=(e,t,n)=>{if(e===0||t===0)return 0;const r=wt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},bg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,yg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Rg=e=>{const t=Array.from(e.types),n=new Map;return{types:t,getData:r=>{const o=n.get(r);if(o!==void 0)return o;const s=e.getData(r);return n.set(r,s),s}}},oc=e=>{const t=e.clipboardData;return t??null},vg=(e,t)=>{const n=Math.max(e.startRow,t.startRow),r=Math.min(e.endRow,t.endRow),o=Math.max(e.startCol,t.startCol),s=Math.min(e.endCol,t.endCol);return n>r||o>s?null:{startRow:n,startCol:o,endRow:r,endCol:s}},Sg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=vg(l,t);c!==null&&o.push({startRow:c.startRow-t.startRow,startCol:c.startCol-t.startCol,endRow:c.endRow-t.startRow,endCol:c.endCol-t.startCol})}if(o.length===0)continue;const s={sourceRuleId:r.id,ranges:o,condition:r.condition,style:r.style};r.stopIfTrue!==void 0&&(s.stopIfTrue=r.stopIfTrue),n.push(s)}return n},kg=(e,t,n,r,o)=>{const s=Zn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=vo(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(l.fmt=a)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:a,author:p,createdAt:g})=>({text:a,author:p,createdAt:g})))}if(e.getCellHyperlink!==void 0){const c=Jn(e.getCellHyperlink(r,o));c!==void 0&&(l.link=c)}if(e.getCellValidation!==void 0){const c=e.getCellValidation(r,o);c!==void 0&&(l.val=n.intern(c))}return l},nu=(e,t)=>{const n=jc(),r=yf(),o=[];for(let s=t.startRow;s<=t.endRow;s+=1){const l=[];for(let c=t.startCol;c<=t.endCol;c+=1)l.push(kg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Sg(e.getConditionalFormats(),t)}},sc=e=>e.kind==="cut"?{...e.payload,...nu(e.sourceAdapter,e.range)}:e.payload,Eg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:js(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Og=e=>{let t=!1;const n=[];for(const r of e.cells){let o=!1;const s=[];for(const l of r){if(l.link===void 0){s.push(l);continue}const c=fn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:a,...p}=l;s.push(p)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Ag=(e,t,n)=>{const r={row:e,col:t,text:""};return n.format&&(r.format=null),n.note&&(r.note=null),n.comments&&(r.comments=null),n.hyperlink&&(r.hyperlink=null),n.validation&&(r.validation=null),r},xg=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return me({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Tg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(T=>{const $=n.current;if($===null||T==="format"||T==="annotate")return;const P=r.current;P==="own"||P==="foreign"&&$.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const T=n.current;if(T===null)return;if(T.kind==="copy"){o();return}const $=t.current;$.repaintOverlay(),$.onClipChange?.({kind:"cut",range:T.range,foreign:T.sourceAdapter!==$.adapter})},[o]),c=i.useCallback((T,$,P)=>{const I=t.current;n.current={kind:T,range:$,clipId:P.clipId,sourceAdapter:I.adapter,payload:P},I.repaintOverlay(),I.onClipChange?.({kind:T,range:$,foreign:!1})},[]),a=i.useCallback(T=>{const $=t.current,P=$.adapter,I=wt(T),z={v:1,rows:I.rows,cols:I.cols,clipId:js(),...nu(P,T),wholeRows:Ic(T,P.colCount),wholeCols:Hc(T,P.rowCount)};if($.resize!==void 0){if(z.wholeCols){const W=[];for(let D=T.startCol;D<=T.endCol;D+=1)W.push(Math.min($.resize.colAxis.sizeOf(D),dn));z.colWidths=W}if(z.wholeRows){const W=[];for(let D=T.startRow;D<=T.endRow;D+=1)W.push(Math.min($.resize.rowAxis.sizeOf(D),dn));z.rowHeights=W}}return z},[]),p=i.useCallback((T,$)=>{const P=t.current,I=P.getSelection(),z=I.ranges[I.ranges.length-1],W=mt([z]);if(W>P.maxOperationCells)return T.preventDefault(),P.onOperationRejected?.($,W,"limit"),null;if($==="cut"&&br(P.adapter,z))return T.preventDefault(),P.rejectReadOnly({kind:"operation",op:"cut",cellCount:W}),null;I.ranges.length>1&&P.onCopyMultiRange?.();const D=a(z),m=Tc(D),f=oc(T);return f!==null&&(f.setData("text/plain",Ut.serializeClipboardTsv(D.cells.map(C=>C.map(v=>v.t)))),f.setData("text/html",ba(D,m)),f.setData(po,m)),T.preventDefault(),{payload:D,range:z}},[a]),g=i.useCallback((T,$)=>t.current.commitPaste(T,$)!==null,[]),y=i.useCallback((T,$,P)=>{const I=t.current;if(!P.sizes||I.resize===void 0)return;const{rowAxis:z,colAxis:W,resizeTracks:D}=I.resize;if(D===void 0)return;const m=(f,C,v)=>{const A=Fs(C,v,null,{maxOperationCells:I.maxOperationCells,rowHiddenLimit:Ms,axisKind:f});if(!A.ok){I.onOperationRejected?.("resize",A.count,A.reason);return}D(f,A.entries)};if(T.colWidths!==void 0){const f=[];for(let C=$.startCol;C<=$.endCol;C+=1)f.push({index:C,size:T.colWidths[(C-$.startCol)%T.cols]});m("col",W,f)}if(T.rowHeights!==void 0){const f=[];for(let C=$.startRow;C<=$.endRow;C+=1)f.push({index:C,size:T.rowHeights[(C-$.startRow)%T.rows]});m("row",z,f)}},[]),N=i.useCallback((T,$)=>{const P=t.current,I=P.adapter,z=T.payload,W={row:$.startRow,col:$.startCol},D=z.rows*z.cols+mt([T.range]);if(D>P.maxOperationCells)return P.onOperationRejected?.("paste",D,"limit"),"rejected";if(W.row+z.rows>I.rowCount||W.col+z.cols>I.colCount||T.range.endRow>=T.sourceAdapter.rowCount||T.range.endCol>=T.sourceAdapter.colCount)return P.onOperationRejected?.("paste",D,"bounds"),"rejected";const m=xs({rows:z.rows,cols:z.cols},me(W,W),W,I.rowCount,I.colCount);if(m!==null&&br(I,m))return P.rejectReadOnly({kind:"operation",op:"paste",cellCount:z.rows*z.cols}),"rejected";if(br(T.sourceAdapter,T.range))return P.rejectReadOnly({kind:"operation",op:"cut",cellCount:mt([T.range])}),"rejected";const f=sc(T),C=uo(I),v=ec(f,C),A={row:0,col:0,readText:()=>Zn(I,A.row,A.col).text,readFormat:()=>I.getCellFormat===void 0?void 0:I.getCellFormat(A.row,A.col)},{edits:R,tiles:j}=Ri(v.cells,me(W,W),W,I.rowCount,I.colCount,(B,d,L)=>(A.row=T.range.startRow+(d-W.row),A.col=T.range.startCol+(L-W.col),nc(B,v,A,Gi,C))),b=uo(T.sourceAdapter),E=[];if(sn([T.range],B=>{E.push(Ag(B.row,B.col,b))}),T.sourceAdapter===I){if(!g([...E,...R],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const B=P.commitPaste(R,{sameSheet:!1,conditionalFormats:rc(v.conditionalFormats,j)});if(B===null)return"rejected";try{T.sourceAdapter.applyEdits(E,{transaction:B,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){P.onEditRejected?.(d,{source:"paste"})}}return P.setSelection({ranges:[me(W,{row:W.row+f.rows-1,col:W.col+f.cols-1})],anchor:W,active:W}),"applied"},[g]),F=i.useCallback((T,$,P)=>{const I=t.current,z=I.adapter,W=Y=>(I.onClipboardUnavailable?.(Y),"rejected"),D=Dc(T,$);if(D==="none")return $==="menu"?W("empty"):"empty";const m=I.getSelection(),f=m.ranges[m.ranges.length-1],C=P.transpose===!0,v=(Y,G)=>{const Q=Cg(C?G:Y,C?Y:G,f);return Q>I.maxOperationCells?(I.onOperationRejected?.("paste",Q,"limit"),!0):!1};let A,R=null;if(D==="aqsp"){const Y=Yd(T,$);if(Y===null)return W("unreadable");const G=n.current;if(G!==null&&Y.clipId===G.clipId&&(R=G),R!==null&&R.kind==="cut"&&bg(P))return N(R,f);if(v(Y.rows,Y.cols))return"rejected";if(R!==null){if(R.kind==="cut"&&(R.range.endRow>=R.sourceAdapter.rowCount||R.range.endCol>=R.sourceAdapter.colCount))return I.onOperationRejected?.("paste",R.payload.rows*R.payload.cols,"bounds"),"rejected";A=sc(R)}else{const Q=Kd(T,$);if(Q===null)return W("unreadable");if(v(Q.rows,Q.cols))return"rejected";A=Og(Q)}}else if(D==="tsv"){const Y=T.getData("text/plain"),G=Ut.measureTsv(Y);if(v(G.rows,G.cols))return"rejected";A=Eg(Ut.parseTsv(Y))}else{const Y=T.getData("text/html"),G=bf(Y);if(G.cols===0&&G.rows>I.maxOperationCells)return I.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(v(G.rows,G.cols))return"rejected";const Q=Sa(Y,D,I.formats===void 0?{}:{currency:I.formats.currency,locale:I.formats.locale},I.maxOperationCells);if(Q.outcome==="none")return W("unreadable");if(Q.outcome==="limit")return I.onOperationRejected?.("paste",Q.cells,"limit"),"rejected";if(v(Q.payload.rows,Q.payload.cols))return"rejected";A=Q.payload}const j=uo(z),b=ec(C?fg(A):A,j),E=eu[P.mode];if(yg(E)){const Y=xs({rows:b.rows,cols:b.cols},f,m.active,z.rowCount,z.colCount);if(Y!==null&&br(z,Y))return I.rejectReadOnly({kind:"operation",op:"paste",cellCount:mt([Y])}),"rejected"}const B={row:0,col:0,readText:()=>Zn(z,B.row,B.col).text,readFormat:()=>z.getCellFormat===void 0?void 0:z.getCellFormat(B.row,B.col)},{edits:d,tiles:L}=Ri(b.cells,f,m.active,z.rowCount,z.colCount,(Y,G,Q)=>(B.row=G,B.col=Q,nc(Y,b,B,P,j))),O=xg(L,b.rows,b.cols,z.rowCount,z.colCount);if(O===null)return"empty";if(E.cf&&b.conditionalFormats.length>0){let Y=0;for(const Q of b.conditionalFormats)Y+=Q.ranges.length;const G=L.length*Y;if(G>I.maxOperationCells)return I.onOperationRejected?.("paste",G,"limit"),"rejected"}const u=E.cf?rc(b.conditionalFormats,L):[];if(d.length===0&&u.length===0)return y(b,O,E),"empty";r.current=R===null?"foreign":"own";let h=!1;try{h=g(d,{sameSheet:R!==null&&R.sourceAdapter===z,conditionalFormats:u})}finally{r.current="none"}if(!h)return"rejected";y(b,O,E);const k={row:O.startRow,col:O.startCol};return I.setSelection({ranges:[O],anchor:k,active:k}),"applied"},[N,g,y]),M=i.useCallback(async T=>{const $=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),P=navigator;if(P.clipboard===void 0)return $("insecure-origin");let I;try{I=await P.clipboard.read({unsanitized:["text/html"]})}catch{return $("permission-denied")}if(I.length===0)return $("empty");const z=I[0],W=Array.from(z.types),D=new Map;try{for(const C of wg)W.includes(C)&&D.set(C,await(await z.getType(C)).text())}catch{return $("unreadable")}const m={types:W,getData:C=>{const v=D.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},f=t.current;return!f.enabled||f.isDragging()||f.isEditing()?"rejected":F(m,"menu",T)},[F]),q=i.useCallback(async T=>{const $=await M(T);return t.current.onPasteResolved?.($,"menu"),$},[M]),{enabled:X,sinkRef:K}=e;return i.useEffect(()=>{const T=K.current;if(!X||T===null)return;const $=W=>t.current.isDragging()?(W.preventDefault(),!0):!1,P=W=>{const D=t.current;if($(W)||D.isEditing())return;const m=p(W,"copy");m!==null&&c("copy",m.range,m.payload)},I=W=>{const D=t.current;if($(W)||D.isEditing())return;const m=p(W,"cut");m!==null&&c("cut",m.range,m.payload)},z=W=>{const D=t.current;if($(W)||D.isEditing())return;W.preventDefault();let m=Gi;const f=D.pendingPasteOptionsRef;f!==void 0&&f.current!==null&&(m=f.current,f.current=null);const C=oc(W);if(C===null)return;const v=F(Rg(C),"event",m);D.onPasteResolved?.(v,"event")};return T.addEventListener("copy",P),T.addEventListener("cut",I),T.addEventListener("paste",z),()=>{T.removeEventListener("copy",P),T.removeEventListener("cut",I),T.removeEventListener("paste",z)}},[X,K,p,c,F]),i.useMemo(()=>({getClip:()=>{const T=n.current;return T===null?null:{kind:T.kind,range:T.range,foreign:T.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:q}),[o,s,l,q])},ru=e=>{if(e!==2&&e!==3&&e!==-2&&e!==-3)throw new RangeError(`[spreadsheet] self-calc exponent must be 2, 3, -2 or -3; got ${String(e)}`)},ou=e=>{let t=e,n=!1;t.startsWith("-")?(n=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));const r=t.search(/[eE]/);let o=null;r>=0&&(o=Number(t.slice(r+1)),t=t.slice(0,r));const s=t.indexOf("."),l=s<0?t:t.slice(0,s),c=s<0?"":t.slice(s+1);return{negative:n,digits:l+c,point:l.length,exponent:o}},lc=(e,t,n)=>{let r,o;return n<=0?(r="0",o="0".repeat(-n)+t):n>=t.length?(r=t+"0".repeat(n-t.length),o=""):(r=t.slice(0,n),o=t.slice(n)),r=r.replace(/^0+(?=\d)/,""),o=o.replace(/0+$/,""),r==="0"&&o===""?"0":`${e?"-":""}${r}${o===""?"":`.${o}`}`},su=(e,t)=>{let n;if(e.exponent===null)n=lc(e.negative,e.digits,e.point+t);else{const r=lc(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return gt(n)===null?null:n},$g=(e,t)=>{ru(t);const n=gt(e);return n===null?null:su(ou(n),t)},Lg=e=>{const t=gt(e);if(t!==null){const r=ou(t);return su({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},lu=e=>{if(!e.startsWith("=")||e.length===1)throw new RangeError(`[spreadsheet] self-calc expects a formula ("=" followed by a body); got ${JSON.stringify(e)}`);return e.slice(1)},Dg=e=>{let t=0,n=null;for(let r=0;r<e.length;r++){const o=e[r];if(n!==null){o===n&&(n=null);continue}if(o==='"'||o==="'")n=o;else if(o==="(")t++;else if(o===")"&&(t--,t<0))return!1}return n===null&&t===0},iu=(e,t,n)=>{if(e.length<=t.length+n.length||!e.startsWith(t)||!e.endsWith(n))return null;const r=e.slice(t.length,e.length-n.length);return Dg(r)?r:null},zg=(e,t)=>{ru(t);const n=lu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=iu(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},Mg=e=>{const t=lu(e),n=iu(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},mr=(e,t,n,r)=>{const o=mt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Qr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},eo={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},ic={bold:{kind:"toggle",key:"bold"},italic:{kind:"toggle",key:"italic"},underline:{kind:"toggle",key:"underline"},strikethrough:{kind:"toggle",key:"strikethrough"},clearFormatting:{kind:"clear"},alignLeft:{kind:"patch",patch:{align:"left"}},alignCenter:{kind:"patch",patch:{align:"center"}},alignRight:{kind:"patch",patch:{align:"right"}},formatNumber:{kind:"value",value:"number"},formatTime:{kind:"value",value:"time"},formatDate:{kind:"value",value:"date"},formatCurrency:{kind:"value",value:"currency"},formatPercent:{kind:"value",value:"percent"},formatScientific:{kind:"value",value:"scientific"},bordersOuter:{kind:"borders",preset:"outer"},bordersClear:{kind:"borders",preset:"clear"},borderTop:{kind:"borders",preset:"top"},borderRight:{kind:"borders",preset:"right"},borderBottom:{kind:"borders",preset:"bottom"},borderLeft:{kind:"borders",preset:"left"},insertLink:{kind:"popover",popover:"link"},insertNote:{kind:"popover",popover:"note"},insertComment:{kind:"popover",popover:"comment"},openHyperlink:{kind:"openHyperlink"},openValidationList:{kind:"popover",popover:"list"},pasteSpecial:{kind:"pasteSpecial"},fillDown:{kind:"fill",direction:"down"},fillRight:{kind:"fill",direction:"right"},fillSelection:{kind:"fill",direction:"selection"},insertDate:{kind:"insertNow",unit:"date"},insertTime:{kind:"insertNow",unit:"time"},hideRows:{kind:"hide",axis:"row",hide:!0},hideColumns:{kind:"hide",axis:"col",hide:!0},unhideRows:{kind:"hide",axis:"row",hide:!1},unhideColumns:{kind:"hide",axis:"col",hide:!1},formatGeneral:{kind:"patch",patch:{value:null}},bordersAll:{kind:"borders",preset:"all"},pasteFormats:{kind:"paste",options:{mode:"formats"}},pasteFormulas:{kind:"paste",options:{mode:"formulas"}},pasteAdd:{kind:"paste",options:{mode:"all",operation:"add"}},pasteSubtract:{kind:"paste",options:{mode:"all",operation:"subtract"}},pasteMultiply:{kind:"paste",options:{mode:"all",operation:"multiply"}},pasteDivide:{kind:"paste",options:{mode:"all",operation:"divide"}},multiplyBy100:{kind:"calc",exponent:2},multiplyBy1000:{kind:"calc",exponent:3},divideBy100:{kind:"calc",exponent:-2},divideBy1000:{kind:"calc",exponent:-3},signReversal:{kind:"sign"},fillColorYellow:{kind:"color",key:"background",preset:Qr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Qr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Qr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Qr.Red,custom:null},fillColorCustom1:{kind:"color",key:"background",preset:null,custom:0},fillColorCustom2:{kind:"color",key:"background",preset:null,custom:1},fillColorCustom3:{kind:"color",key:"background",preset:null,custom:2},fillColorCustom4:{kind:"color",key:"background",preset:null,custom:3},fillColorCustom5:{kind:"color",key:"background",preset:null,custom:4},fontColorYellow:{kind:"color",key:"color",preset:eo.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:eo.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:eo.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:eo.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},Ng={down:"fillDown",right:"fillRight",selection:"fillSelection"},Fg={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},kr=e=>e<10?`0${e}`:String(e),Pg=e=>{const t=new Date(e);return`${t.getFullYear()}-${kr(t.getMonth()+1)}-${kr(t.getDate())}`},_g=e=>{const t=new Date(e);return`${kr(t.getHours())}:${kr(t.getMinutes())}:${kr(t.getSeconds())}`},qg=(e,t)=>(e.row===t.startRow?1:0)|(e.col===t.endCol?2:0)|(e.row===t.endRow?4:0)|(e.col===t.startCol?8:0),jg=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Ig=e=>e===void 0||e.borders===void 0?{}:e.borders,Hg={top:1,right:2,bottom:4,left:8},Bg={style:"thin",color:Ps},Wg=(e,t)=>{if(e===void 0)return!1;const n=nt(e);return n!==null&&n===nt(t)},Vg=(e,t)=>{const n=t===void 0||t.locale===void 0?{}:{locale:t.locale};switch(e){case"number":return{type:"number",decimals:2,grouping:!0,...n};case"time":return{type:"date",pattern:"HH:mm:ss"};case"date":return{type:"date"};case"currency":if(t===void 0)throw new RangeError("[spreadsheet] formatCurrency requires the formats prop (currency)");return{type:"currency",currency:t.currency,decimals:2,...n};case"percent":return{type:"percent",decimals:2,...n};default:return{type:"scientific",decimals:2,...n}}},Yg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const m=t.current;if(m.isEditing()){const f=m.getActive();return[me(f,f)]}return m.getSelection().ranges},[]),r=i.useCallback(()=>{const m=t.current,f=m.getActive();return m.adapter.getCellFormat===void 0?void 0:m.adapter.getCellFormat(f.row,f.col)},[]),o=i.useCallback(m=>{const f=t.current,C=n();if(!mr("format",C,f.maxOperationCells,f.onOperationRejected))return!1;if(Bn(f.adapter,C))return f.rejectReadOnly({kind:"operation",op:"format",cellCount:mt(C)}),!1;const v=new Map,A=[],R=f.adapter.getCellFormat;for(const j of C)sn([j],b=>{const E=R===void 0?void 0:R(b.row,b.col),{bucket:B,patch:d}=m(b,j,E);let L=v.get(B);L===void 0&&(L=new Map,v.set(B,L));let O;L.has(E)?O=L.get(E):(O=qs(E,d),L.set(E,O)),O!==E&&A.push({row:b.row,col:b.col,format:O===void 0?null:O})});return A.length===0?!0:f.commitEdits(A,{source:"format"})===null?!1:(f.isEditing()&&f.refreshEditPaint(),!0)},[n]),s=i.useCallback(m=>o(()=>({bucket:0,patch:m})),[o]),l=i.useCallback((m,f)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:m,state:f}))},[]),c=i.useCallback((m,f=Bg)=>{if(m==="clear")return s({borders:null});if(m==="all")return s({borders:{top:f,right:f,bottom:f,left:f}});const C=m==="outer"?15:Hg[m];return o((v,A,R)=>{const j=qg(v,A)&C;return{bucket:j,patch:{borders:{...Ig(R),...jg(j,f)}}}})},[s,o]),a=i.useCallback((m,f,C)=>{const v=xa(t.current.adapter,m.row,m.col);for(const A of f)C.push(Ta(v,m,A))},[]),p=i.useCallback(m=>{const f=t.current,C=f.getSelection();if(!mr("fill",C.ranges,f.maxOperationCells,f.onOperationRejected))return!1;const v=[],A=[],R=[];if(m==="selection"){const b=C.active,E=[];sn(C.ranges,B=>{(B.row!==b.row||B.col!==b.col)&&E.push(B)}),v.push({source:b,targets:E}),A.push(me(b,b));for(const B of C.ranges)R.push(...Dh(B,b))}else for(const b of C.ranges)if(m==="down"){const E=b.startRow===b.endRow;if(E&&b.startRow===0)continue;const B=E?b.startRow-1:b.startRow,d=E?b.startRow:b.startRow+1;A.push(me({row:B,col:b.startCol},{row:B,col:b.endCol})),R.push(me({row:d,col:b.startCol},{row:b.endRow,col:b.endCol}));for(let L=b.startCol;L<=b.endCol;L+=1){const O=[];for(let u=d;u<=b.endRow;u+=1)O.push({row:u,col:L});v.push({source:{row:B,col:L},targets:O})}}else{const E=b.startCol===b.endCol;if(E&&b.startCol===0)continue;const B=E?b.startCol-1:b.startCol,d=E?b.startCol:b.startCol+1;A.push(me({row:b.startRow,col:B},{row:b.endRow,col:B})),R.push(me({row:b.startRow,col:d},{row:b.endRow,col:b.endCol}));for(let L=b.startRow;L<=b.endRow;L+=1){const O=[];for(let u=d;u<=b.endCol;u+=1)O.push({row:L,col:u});v.push({source:{row:L,col:B},targets:O})}}for(const b of v)for(const E of b.targets)if(Je(f.adapter,E.row,E.col))return f.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(R),gesture:Ng[m],sources:A,targets:R}),!1;const j=[];for(const b of v)a(b.source,b.targets,j);return j.length===0?!0:f.commitEdits(j,{source:"fill"})!==null},[a]),g=i.useCallback(()=>{const m=t.current,f=m.getSessionText();if(f===null)return!1;const C=m.getSelection();if(!mr("fill",C.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(Bn(m.adapter,C.ranges))return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(C.ranges),gesture:"fillSelection",sources:[],targets:C.ranges}),!1;const v=[];let A=!1;return sn(C.ranges,R=>{if(!A){if(!m.validateCommit(R,f).ok){A=!0;return}v.push({row:R.row,col:R.col,text:f})}}),A||m.commitEdits(v,{source:"fill"})===null?!1:(m.cancelEdit(),!0)},[]),y=i.useCallback(m=>{const f=t.current,C=f.getSelection();if(!mr("calc",C.ranges,f.maxOperationCells,f.onOperationRejected))return!1;if(Bn(f.adapter,C.ranges))return f.rejectReadOnly({kind:"operation",op:"calc",cellCount:mt(C.ranges)}),!1;const v=[],A=f.adapter;return sn(C.ranges,R=>{const j=A.getCellFormula===void 0?void 0:A.getCellFormula(R.row,R.col),b=j===void 0?m.text(A.getCellText(R.row,R.col)):m.formula(j);b!==null&&v.push({row:R.row,col:R.col,text:b})}),v.length===0?!0:f.commitEdits(v,{source:"calc"})!==null},[]),N=i.useCallback((m,f)=>{const C=t.current,v=C.resizeTracks;if(v===void 0)return!1;const A=m==="row"?C.rowAxis:C.colAxis,R=C.getSelection(),j=m==="row"?Math.floor(C.maxOperationCells/Ns):C.maxOperationCells;let b=0;for(const O of R.ranges)b+=m==="row"?O.endRow-O.startRow+1:O.endCol-O.startCol+1;if(b>j)return C.onOperationRejected?.("resize",b,"limit"),!1;const E=new Set,B=[],d=f?0:m==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const O of R.ranges){const u=m==="row"?O.startRow:O.startCol,h=m==="row"?O.endRow:O.endCol;for(let k=u;k<=h;k+=1){if(E.has(k))continue;E.add(k),A.sizeOf(k)===0!==f&&B.push({index:k,size:d})}}const L=Fs(A,B,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:Ms,axisKind:m});return L.ok?(L.entries.length>0&&v(m,L.entries),!0):(C.onOperationRejected?.("resize",L.count,L.reason),!1)},[]),F=i.useCallback(()=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)return;const f=m.getActive();return Jn(m.adapter.getCellHyperlink(f.row,f.col))},[]),M=i.useCallback(m=>{const f=t.current,C=f.adapter,v=ic[m],A=C.getCellFormat!==void 0,R=j=>f.popovers===void 0?!0:f.popovers[j]!==!1;switch(v.kind){case"resize":return f.trackResize!==void 0;case"hide":return f.resizeTracks!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return A;case"value":return A&&(v.value!=="currency"||f.formats!==void 0);case"popover":switch(v.popover){case"link":return C.getCellHyperlink!==void 0&&R("link");case"note":return C.getCellNote!==void 0&&R("note");case"comment":return C.getCellComments!==void 0&&R("comment");default:return C.getCellValidation!==void 0&&R("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(f.onHyperlinkOpen!==void 0?F()!==void 0:R("link"));case"paste":return v.options.mode==="formats"?A:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[F]),q=i.useCallback(m=>{const f=t.current,C=m.kind==="popover"?m.popover:m.kind==="openHyperlink"&&f.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=f.getActive();if(!Je(f.adapter,v.row,v.col))return!0;if(C==="list")return f.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let A;if(C==="link")A=F()!==void 0;else if(C==="note"){const R=f.adapter.getCellNote===void 0?void 0:f.adapter.getCellNote(v.row,v.col);A=R!==void 0&&R!==""}else{const R=f.adapter.getCellComments===void 0?void 0:f.adapter.getCellComments(v.row,v.col);A=R!==void 0&&R.length>0}return A?!0:(f.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[F]),X=i.useCallback((m,f,C)=>{const v=t.current,A=v.trackResize;if(A===void 0)return!1;const R=v.getActive(),j=f==="col"?R.col:R.row,b=C==="fit"?A.autofitColumn(j):A.stepTrack(f,j,C),E=(f==="col"?v.colAxis:v.rowAxis).sizeOf(j);return b&&E>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:m,axis:f==="col"?"column":"row",index:j,size:E})),b},[]),K=i.useCallback(m=>{const f=t.current;if(!M(m))return!1;const C=ic[m];if(!q(C))return!1;const v=f.isEditing();if(v&&!go.has(m)&&!f.requestCommit())return!1;switch(C.kind){case"toggle":{const A=r(),R=A!==void 0&&A[C.key]===!0;return s({[C.key]:R?null:!0})?(l(m,!R),!0):!1}case"patch":return s(C.patch)?(l(m,null),!0):!1;case"clear":return s(Fg)?(l(m,null),!0):!1;case"value":return s({value:Vg(C.value,f.formats)})?(l(m,null),!0):!1;case"borders":return c(C.preset)?(l(m,null),!0):!1;case"color":{const A=C.key==="background"?f.colors.fill:f.colors.font,R=C.preset!==null?C.preset:C.custom!==null&&C.custom<A.length?A[C.custom]:void 0;if(R===void 0)return!1;const j=r(),b=Wg(j===void 0?void 0:j[C.key],R);return s({[C.key]:b?null:R})?(l(m,!b),!0):!1}case"calc":return y({text:A=>$g(A,C.exponent),formula:A=>zg(A,C.exponent)});case"sign":return y({text:Lg,formula:Mg});case"fill":return v&&C.direction==="selection"?g():p(C.direction);case"popover":return f.openPopover(C.popover),!0;case"openHyperlink":{if(f.onHyperlinkOpen!==void 0){const A=F();return A===void 0?!1:(f.onHyperlinkOpen(A,f.getActive()),!0)}return f.openPopover("link"),!0}case"pasteSpecial":return f.onPasteSpecialRequest!==void 0?(f.onPasteSpecialRequest({kind:"keyboard",cellRect:f.keyboardCellRect()}),!0):(f.paste({mode:"formats"}),!0);case"paste":return f.paste(C.options),!0;case"insertNow":{const A=C.unit==="date"?Pg(f.now()):_g(f.now());if(v)return f.insertAtCaret(A),!0;const R=f.getActive();return Je(f.adapter,R.row,R.col)?(f.rejectReadOnly({kind:"edit",cell:R,editSession:"none"}),!1):f.validateCommit(R,A).ok?f.commitEdits([{row:R.row,col:R.col,text:A}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return X(m,C.axis,C.step);default:{const A=f.getHighlight();switch(C.target){case"row":return f.setHighlight({...A,row:!A.row}),!0;case"column":return f.setHighlight({...A,column:!A.column}),!0;case"both":{const R=A.row&&A.column;return f.setHighlight({...A,row:!R,column:!R}),!0}default:return f.setHighlight({...A,intersection:!A.intersection}),!0}}}},[M,q,F,r,s,l,c,y,p,g,N,X]),T=i.useCallback(()=>{const m=t.current;return!(m.isEditing()&&!m.requestCommit())},[]),$=i.useCallback(m=>{const f=t.current;if(f.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=m===null?null:fn(m);if(m!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(m)}`);if(!T())return!1;const v=f.getActive();return Je(f.adapter,v.row,v.col)?(f.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):f.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[T]),P=i.useCallback(m=>{const f=t.current;if(f.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!T())return!1;const C=f.getActive();return Je(f.adapter,C.row,C.col)?(f.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):f.commitEdits([{row:C.row,col:C.col,note:m}],{source:"annotate"})!==null},[T]),I=i.useCallback(m=>{const f=t.current,C=f.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!T())return!1;const v=f.getActive();if(Je(f.adapter,v.row,v.col))return f.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const A=C(v.row,v.col),R=A===void 0?[m]:[...A,m];return f.commitEdits([{row:v.row,col:v.col,comments:R}],{source:"annotate"})!==null},[T]),z=i.useCallback(m=>{const f=t.current;if(f.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!T())return!1;const C=f.getSelection().ranges;if(!mr("annotate",C,f.maxOperationCells,f.onOperationRejected))return!1;if(Bn(f.adapter,C))return f.rejectReadOnly({kind:"operation",op:"annotate",cellCount:mt(C)}),!1;const v=[];return sn(C,A=>{v.push({row:A.row,col:A.col,validation:m})}),f.commitEdits(v,{source:"annotate"})!==null},[T]),W=i.useCallback(m=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(m)},[s]),D=i.useCallback((m,f)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(m,f)},[c]);return i.useMemo(()=>({executeCommand:K,applyFormat:W,setBorders:D,setHyperlink:$,setNote:P,addComment:I,setValidation:z,isCommandAvailable:M}),[K,W,D,$,P,I,z,M])},to="data-aqsp-pointing",Kg=(e,t)=>{const n=la(e,t);return n!==null&&"insertAt"in n},Ug=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Xg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(null),p=i.useRef(Vt),g=i.useCallback(()=>{const b=t.current,E=b.sinkRef.current;if(b.adapter.getCellFormula===void 0||n.current===null||!c.current||E===null)return null;const B=la(E.value,E.selectionStart);return B===null?null:{sink:E,target:B}},[]),y=i.useCallback(()=>{const b=t.current.sinkRef.current;if(b===null)return;const E=g()!==null;E!==b.hasAttribute(to)&&(E?b.setAttribute(to,""):b.removeAttribute(to))},[g]),N=i.useCallback((b,E)=>{const B=t.current;if(B.resolveEditPaint===void 0)return;const d=B.resolveEditPaint(E),L=d===null?Vt:d;L!==Vt&&Object.assign(b.style,L.style),p.current=L,B.editPaintRef!==void 0&&(B.editPaintRef.current=L)},[]),F=i.useCallback(b=>{Ug(b,Object.keys(p.current.style)),p.current=Vt;const E=t.current.editPaintRef;E!==void 0&&(E.current=Vt)},[]),M=i.useCallback(b=>{const E=t.current,B=n.current;if(B===null)return!0;const d=()=>{n.current=null,a.current=null;const L=E.sinkRef.current;L!==null&&(L.style.removeProperty("text-align"),F(L),L.removeAttribute(to)),o(!1),E.onSessionChange?.(null)};if(b.commit){const L=E.sinkRef.current,O=L===null?"":L.value,u=Zn(E.adapter,B.cell.row,B.cell.col).text.replace(/\r\n?/g,`
13
- `),h=O===u;let k;if(h)k=!0;else if(Je(E.adapter,B.cell.row,B.cell.col))E.rejectReadOnly({kind:"edit",cell:B.cell,editSession:b.onReject==="keep"?"kept":"discarded"}),k=!1;else{const Y={source:"edit",editSession:b.onReject==="keep"?"kept":"discarded"};k=(E.validateCommit===void 0||E.validateCommit(B.cell,O).ok)&&E.commitEdits([{row:B.cell.row,col:B.cell.col,text:O}],Y)!==null}if(!k)return b.onReject==="discard"&&(d(),E.rearmSink()),!1}return d(),b.rearm&&E.rearmSink(),!0},[F]),q=i.useCallback((b,E)=>{const B=t.current;if(B.isDragging()||n.current!==null)return;const d=B.sinkRef.current;if(d===null)return;const L=B.getActive();if(Je(B.adapter,L.row,L.col)){B.rejectReadOnly({kind:"edit",cell:L,editSession:"none"});return}if(B.discardClip(),B.ensureCellVisible(L),b==="edit"){const{text:h,isFormula:k}=Zn(B.adapter,L.row,L.col);d.value=h;const Y=E===void 0||k?h.length:Math.min(E,h.length);d.setSelectionRange(Y,Y)}else d.value="";const O=B.resolveEditAlign(L);O!==null&&(d.style.textAlign=O),N(d,L),c.current=!1,a.current=null;const u={cell:L,mode:b};n.current=u,o(!0),B.onSessionChange?.(u)},[N]),X=i.useCallback(()=>{M({rearm:!0,commit:!1})},[M]),K=i.useCallback(()=>{const b=t.current;if(n.current===null)return!0;const E=b.sinkRef.current;if(s.current&&E!==null){l.current=!0;try{E.blur()}finally{l.current=!1}return M({rearm:!1,commit:!0,onReject:"keep"})?(b.focusSink(),b.rearmSink(),!0):(b.focusSink(),!1)}return M({rearm:!0,commit:!0,onReject:"keep"})},[M]),T=i.useCallback(()=>g()!==null,[g]),$=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,y(),!0),[y]),P=i.useCallback(()=>{const b=g(),E=n.current;if(b===null||E===null)return null;if("insertAt"in b.target)return a.current=E.cell,{origin:E.cell,cursor:E.cell,axis:"cells"};const B=sa(b.sink.value,b.sink.selectionStart);if(B===null)return null;const d=B.token,L=a.current;switch(d.kind){case"cell":{const O={row:d.row,col:d.col};return a.current=O,{origin:O,cursor:O,axis:"cells"}}case"range":{const O=L!==null&&(L.row===d.start.row||L.row===d.end.row)&&(L.col===d.start.col||L.col===d.end.col)?{row:L.row,col:L.col}:{row:d.start.row,col:d.start.col};return a.current=O,{origin:O,cursor:{row:O.row===d.start.row?d.end.row:d.start.row,col:O.col===d.start.col?d.end.col:d.start.col},axis:"cells"}}case"column":{const O=L!==null&&(L.col===d.start.col||L.col===d.end.col)?L.col:d.start.col,u={row:E.cell.row,col:O};return a.current=u,{origin:u,cursor:{row:E.cell.row,col:O===d.start.col?d.end.col:d.start.col},axis:"columns"}}case"row":{const O=L!==null&&(L.row===d.start.row||L.row===d.end.row)?L.row:d.start.row,u={row:O,col:E.cell.col};return a.current=u,{origin:u,cursor:{row:O===d.start.row?d.end.row:d.start.row,col:E.cell.col},axis:"rows"}}}},[g]),I=i.useCallback((b,E)=>{const B=g();if(B===null)return;const d=Qf(b,E),{sink:L}=B,[O,u]="replace"in B.target?B.target.replace:[B.target.insertAt,B.target.insertAt],h=L.value;L.value=`${h.slice(0,O)}${d}${h.slice(u)}`;const k=O+d.length;L.setSelectionRange(k,k),"row"in b&&(a.current={row:b.row,col:b.col}),y()},[g,y]),z=i.useCallback(()=>{const b=t.current.sinkRef.current;return b===null?null:{value:b.value,selectionStart:b.selectionStart,selectionEnd:b.selectionEnd}},[]),W=i.useCallback(b=>{const E=t.current.sinkRef.current;E!==null&&(E.value=b.value,E.setSelectionRange(b.selectionStart,b.selectionEnd),a.current=null,y())},[y]),D=i.useCallback(()=>{const b=t.current,E=b.sinkRef.current;if(b.adapter.getCellFormula===void 0||n.current===null||E===null)return!1;const B=ap(E.value,E.selectionStart);return B===null?!1:(E.value=B.text,E.setSelectionRange(B.caret,B.caret),y(),!0)},[y]),m=i.useCallback(b=>{const E=t.current.sinkRef.current;if(n.current===null||E===null)return;const B=E.selectionStart,d=E.selectionEnd;E.value=`${E.value.slice(0,B)}${b}${E.value.slice(d)}`;const L=B+b.length;E.setSelectionRange(L,L),a.current=null,y()},[y]),f=i.useCallback(()=>{const b=t.current.sinkRef.current;return n.current===null||b===null?null:b.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>n.current,[]),A=i.useCallback(()=>{const b=t.current,E=n.current,B=b.sinkRef.current;E===null||B===null||(F(B),N(B,E.cell),b.repaintOverlay?.())},[F,N]),{enabled:R,sinkRef:j}=e;return i.useEffect(()=>{const b=j.current;if(!R||b===null)return;const E=()=>{s.current=!0},B=()=>{s.current=!1},d=u=>{const h=t.current;if(l.current||n.current===null)return;const k=h.rootRef.current,Y=u.relatedTarget;k!==null&&Y instanceof Node&&k.contains(Y)||M({rearm:!1,commit:!0,onReject:"discard"})},L=()=>{const u=t.current;a.current=null,u.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Kg(b.value,b.selectionStart)&&(c.current=!0),y()},O=()=>{n.current!==null&&y()};return b.addEventListener("compositionstart",E),b.addEventListener("compositionend",B),b.addEventListener("focusout",d),b.addEventListener("input",L),document.addEventListener("selectionchange",O),()=>{b.removeEventListener("compositionstart",E),b.removeEventListener("compositionend",B),b.removeEventListener("focusout",d),b.removeEventListener("input",L),document.removeEventListener("selectionchange",O)}},[R,j,M,y]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:K,cancelEdit:X,startEdit:q,getPointing:T,togglePointingArm:$,getReferenceCursor:P,insertReference:I,captureSink:z,restoreSink:W,cycleAnchorAtCaret:D,insertAtCaret:m,getSessionText:f,getSessionCell:C,getSession:v,refreshPaint:A,editing:r}),[K,X,q,T,$,P,I,z,W,D,m,f,C,v,A,r])},Gg=(e,t,n)=>{const r=new rt.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},Zg=(e,t,n)=>{const{tree:r,initialHidden:o}=Gg(e,t,n);let s=o;const a={count:e,sizeOf:p=>r.get(p),offsetOf:p=>{const{cumulative:g,currentValue:y}=r.prefixSum(p);return g-y},indexAt:p=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const g=Math.floor(p),y=Math.min(Math.max(g,0),r.getTotal()-1);return r.findIndexAtOrAfter(y+.5).index},totalSize:()=>r.getTotal(),resize:(p,g)=>{if(!(Number.isFinite(g)&&g>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${g}`);const y=Math.round(g);r.get(p)===0!=(y===0)&&(s+=y===0?1:-1),r.update(p,y)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},an=(e,t,n)=>{if(n>0){const o=e.offsetOf(t)+e.sizeOf(t);return o>=e.totalSize()?null:e.indexAt(o)}const r=e.offsetOf(t)-1;return r<0?null:e.indexAt(r)},Kn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:an(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=an(e,o,1);return r},cc=(e,t,n)=>{if(!(Number.isInteger(t)&&t>0))throw new TypeError(`[spreadsheet] useAxisModel requires a positive integer defaultSize, received ${t}`);const r=i.useRef(n).current,o=i.useRef(null),s=`${e}:${t}`;return(o.current===null||o.current.key!==s)&&(o.current=Zg(e,t,r)),o.current.model},Un=256,as=256,Jg=2**32,Qg=4096,cu=Object.freeze([]),au=["background","color","bold","italic","underline","strikethrough"],uu=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},un=(e,t,n)=>(e.size>=Qg&&e.clear(),e.set(t,n),n),du=e=>(uu(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),fu=(e,t,n,r,o)=>{for(const s of e)if(s.startRow<=n&&s.endRow>=t&&s.startCol<=o&&s.endCol>=r)return!0;return!1},ew=(e,t,n)=>{const r=Math.floor(t/Un),o=Math.floor(n/as),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Un,a=o*as,p=[];for(const g of e.rules)fu(g.ranges,c,c+Un-1,a,a+as-1)&&p.push(g);return un(e.buckets,s,p.length===0?cu:p)},tw=(e,t,n)=>{const r=Math.floor(t/Un),o=r*Jg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=ew(e,t,n),c=r*Un,a=[];for(const p of l)fu(p.ranges,c,c+Un-1,n,n)&&a.push(p);return un(e.columns,o,a.length===0?cu:a)},nw=(e,t)=>{for(const n of e)if(Pt(n,t))return!0;return!1},Js=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),no=(e,t)=>e<t?-1:e>t?1:0,ac=(e,t,n)=>{switch(e){case"eq":return t===0;case"neq":return t!==0;case"gt":return t>0;case"gte":return t>=0;case"lt":return t<0;case"lte":return t<=0;case"between":return n!==null&&t>=0&&n<=0;case"notBetween":return n!==null&&(t<0||n>0);default:return!1}},uc=new WeakMap,zs=e=>e===null?null:Number(e),rw=e=>{const t=uc.get(e);if(t!==void 0)return t;const n=e.b,r={a:zs(gt(e.a)),b:n===void 0?null:zs(gt(n))};return uc.set(e,r),r},pu=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:un(e.numbers,r,zs(gt(n())))},ow=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=rw(e),l=pu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return ac(e.op,no(l,s.a),c===null?null:no(l,c));const a=n(),p=e.b;return ac(e.op,no(a,e.a),p===void 0?null:no(a,p))},sw=(e,t)=>{switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);case"endsWith":return t.endsWith(e.value);default:return!1}},us=e=>{const t=nt(e);if(t===null)return null;const n=r=>Number.parseInt(t.slice(r,r+2),16);return[n(1),n(3),n(5),t.length===9?n(7):255]},ro=e=>e.toString(16).padStart(2,"0"),ds=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${ro(r(0))}${ro(r(1))}${ro(r(2))}`,s=r(3);return s===255?o:`${o}${ro(s)}`},fs=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),lw=(e,t,n,r,o)=>{let s=t.value===void 0?o.min:t.value,l=r.value===void 0?o.max:r.value,c=us(t.color),a=us(r.color);const p=n===void 0?void 0:us(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||a===null||p===null)return null;if(s>l){const y=s;s=l,l=y;const N=c;c=a,a=N}if(n!==void 0&&p!==void 0){const y=n.value===void 0?(s+l)/2:n.value;if(s<y&&y<l)return e<=y?ds(c,p,fs(e,s,y)):ds(p,a,fs(e,y,l))}return ds(c,a,fs(e,s,l))},iw=(e,t,n,r)=>{const o=r.extrema.get(e.id);if(o!==void 0)return o;const{min:s,max:l}=t;if(s.value!==void 0&&l.value!==void 0)return un(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const p of e.ranges){const g=n.getRangeExtrema(p);if(g===null)return un(r.extrema,e.id,null);c=Math.min(c,g.min),a=Math.max(a,g.max)}return un(r.extrema,e.id,{min:c,max:a})},cw=(e,t,n,r,o,s)=>{const l=pu(s,n,r);if(l===null)return null;const c=iw(e,t,o,s);return c===null?null:lw(l,t.min,t.mid,t.max,c)},aw=(e,t,n,r,o)=>{if(r.evaluateFormula===void 0)return!1;const s=`${e.id}\0${n.row}\0${n.col}`,l=o.formulas.get(s),c=l!==void 0?l:un(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},uw=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return ow(s,t,n,o)?e.style:null;case"text":return sw(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=cw(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return aw(e,s,t,r,o)?e.style:null;default:return null}},dc=(e,t)=>qs(e,t),dw=(e,t,n)=>{e[t]=n},fw=(e,t)=>{let n=e;for(const r of au)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),dw(n,r,t[r]));return n},pw=e=>{let t="";for(const n of au){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},fc=new WeakMap,hw=Object.freeze({}),mw=e=>{const t=e===void 0?hw:e,n=fc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return fc.set(t,r),r},gw=(e,t,n)=>{const r=mw(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=dc(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=pw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=dc(e,t);return l!==void 0&&un(r.byKey,o,l),l},Qs=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const l=e.getCellFormat(r,o);if(t===null)return l;const c=tw(t,r,o);if(c.length===0)return l;const a={row:r,col:o};let p=null,g=!0;for(const y of c){if(!nw(y.ranges,a))continue;const N=uw(y,a,s,e,n);if(N!==null){if(N!==y.style&&(g=!1),p===null)p=N;else{const F=fw(p,N);F!==p&&(g=!1,p=F)}if(y.stopIfTrue===!0)break}}return p===null?l:gw(l,p,g)},pc=new WeakMap,ww=e=>{uu(e,"widthRelevantRules");const t=pc.get(e);if(t!==void 0)return t;const n=e.filter(o=>o.style.bold!==void 0||o.style.italic!==void 0||o.stopIfTrue===!0),r=n.length===e.length?e:n;return pc.set(e,r),r},Cw=({row:e,col:t,text:n,display:r,renderCell:o,__onCellRender:s})=>{const l=i.useRef(!1);if(i.useEffect(()=>{const c=l.current?"update":"mount";l.current=!0,s?.(`cell-${e}-${t}`,c,0,0,0,0)}),o!==void 0){const c=o({row:e,col:t,text:n,displayText:r});return c===void 0?r:c}return r},bw=i.memo(Cw),yw=Object.freeze({left:Object.freeze({justifyContent:Rr("left")}),center:Object.freeze({justifyContent:Rr("center")}),right:Object.freeze({justifyContent:Rr("right")})}),Rw=Object.freeze({role:"rowgroup"}),vw=4096,hc=new WeakMap,oo=new Map,Sw=(e,t)=>{if(e===null)return yw[t];let n=hc.get(e);n===void 0&&(n={},hc.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:Rr(t)},s=JSON.stringify(o);let l=oo.get(s);return l===void 0&&(oo.size>=vw&&oo.clear(),l=Object.freeze(o),oo.set(s,l)),n[t]=l,l},kw=Js(),Ew=(e,t,n)=>{if(e.row!==t||e.col!==n)throw new RangeError(`[spreadsheet] cell renderer (${t}, ${n}) ran without its getCellProps (latched ${e.row}, ${e.col})`);return e.value},Ow=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0&&e.getCellNote===void 0&&e.getCellComments===void 0&&e.getCellHyperlink===void 0&&e.getCellValidation===void 0)return null;const l=ao(e,o,s),c={};let a=null,p;if(e.getCellFormat!==void 0){const g=Qs(e,r===null?null:r.indexRef.current,r===null?kw:r.memoRef.current,o,s,l);p=g===void 0?void 0:g.value;const y=ka(g,l),N=an(n,s,1),F=an(t,o,1),M=$f(g,N===null?void 0:e.getCellFormat(o,N),F===null?void 0:e.getCellFormat(F,s),n.offsetOf(s)===0,t.offsetOf(o)===0);M!==null&&Object.assign(c,M.attrs),c["data-aqsp-align"]=y,a=Sw(M,y)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const g=e.getCellComments(o,s);g!==void 0&&g.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Jn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&Bm(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:p}},Aw=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:a,frozenRows:p,frozenTrailingColumns:g,frozenTrailingRows:y,headerRows:N,labelledBy:F,gridLabel:M,readOnly:q,renderCell:X,onScroll:K,onRangeChange:T,focusSink:$,isEditing:P,requestCommit:I,testId:z,__onCellRender:W,__maxRenderedCells:D,cfIndexRef:m,cfMemoRef:f,isPointing:C,tapScrollCircleOptions:v,showArrowButtons:A,enableThumbDrag:R,enableTrackClick:j,overscanRows:b,overscanCols:E,background:B,onRenderTruncated:d,locale:L,scrollLabels:O})=>{const u=i.useRef(null),h=s??u;if(m===void 0!=(f===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const k=i.useMemo(()=>m===void 0||f===void 0?null:{indexRef:m,memoRef:f},[m,f]),Y=i.useCallback(()=>r.get().editVersion,[r]),G=i.useCallback(Ce=>r.subscribeCoalesced(Ce),[r]),J=i.useSyncExternalStore(G,Y,Y)+(l??0),re=i.useCallback(Ce=>t.sizeOf(Ce),[t]),te=i.useCallback(Ce=>n.sizeOf(Ce),[n]),ue=i.useCallback((Ce,We)=>e.getCellText(Ce,We),[e]),ae=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),Ae=i.useMemo(()=>({width:ze.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1,showArrowButtons:A,enableThumbDrag:R,enableTrackClick:j}),[v,A,R,j]),$e=i.useRef({row:-1,col:-1,value:void 0}),Ne=i.useCallback((Ce,We)=>{const ot=Ce<N,$t={role:ot?"columnheader":"gridcell","aria-rowindex":Ce+1,"aria-colindex":We+1,"data-aqsp-cell":"","data-row":Ce,"data-col":We,className:"aqsp-cell",...Je(e,Ce,We)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...ot?{"data-aqsp-header-row":""}:{}},ut=_h(e,Ce,We),Zt=ut===null?$t:{...$t,...ut},Qe=Ow(e,t,n,k,Ce,We),Ct=$e.current;return Ct.row=Ce,Ct.col=We,Ct.value=Qe===null?void 0:Qe.value,Qe===null?Zt:Qe.style===null?{...Zt,...Qe.attrs}:{...Zt,...Qe.attrs,style:Qe.style}},[e,t,n,k,N]),Fe=i.useCallback(Ce=>({role:"row","aria-rowindex":Ce+1,"data-aqsp-row":Ce,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Tt=i.useCallback((Ce,We,ot)=>{let $t=Ce;return e.getCellFormat!==void 0&&($t=Xn(Ce,Ew($e.current,We,ot))),U.jsx(bw,{row:We,col:ot,text:Ce,display:$t,renderCell:X,__onCellRender:W})},[J,X,W,e]);return U.jsx("div",{ref:h,className:"aqsp-body","data-aqsp-body":"","data-testid":z?`${z}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":M,"aria-labelledby":F,"aria-readonly":q?"true":void 0,onPointerDownCapture:Ce=>{if(!(Ce.target instanceof Element&&Ce.target.closest("[data-aqsp-cells]")!==null)&&Ce.pointerType==="mouse"){if(Ce.button!==0){Ce.preventDefault();return}if(Ce.preventDefault(),C?.()===!0){Ce.stopPropagation(),$();return}if(P()&&!I()){Ce.stopPropagation(),$();return}$()}},children:U.jsx(rt.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:p,frozenTrailingCols:g,frozenTrailingRows:y,getRowHeight:re,getColWidth:te,getCell:ue,getCellProps:Ne,getRowProps:Fe,contentProps:Rw,behaviorOptions:ae,scrollBarOptions:Ae,overscanRows:b,overscanCols:E,background:B,onRenderTruncated:d,__maxRenderedCells:D,locale:L,labels:O,callbackThrottleMs:0,onScroll:K,onRangeChange:T,testId:z,children:Tt})})},xw=i.memo(Aw),Wn=6,ht=3,Co=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=t[0];o>0&&e.sizeOf(o-1)===0&&r.push({kind:"unhide",index:o-1,start:e.offsetOf(o),length:ht});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,a=an(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-Wn,length:ht}),r.push({kind:"unhide",index:s+1,start:c-ht,length:ht})):l>=2*Wn?n.push({kind:"resize",index:s,start:c-Wn,length:Wn}):n.push({kind:"resize",index:s,start:c-ht,length:ht})}return[...n,...r]},hu=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const a=e.sizeOf(c),p=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:p,length:ht}),n.push({kind:"resize",index:c,start:p+ht,length:ht})):a>=2*Wn?n.push({kind:"resize",index:c,start:p,length:Wn}):n.push({kind:"resize",index:c,start:p,length:ht})}const l=t[t.length-1];return l<e.count-1&&e.sizeOf(l+1)===0&&r.push({kind:"unhide",index:l+1,start:s-ht,length:ht}),[...n.reverse(),...r]},Tw=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:a,selectionRanges:p,enableResizeUI:g,dividerLeadingRef:y,dividerTrailingRef:N})=>{const F=rt.useWheelBridge(o),M=i.useCallback(d=>(s.current=d,F(d)),[s,F]),q=i.useCallback(()=>{const{colStart:d,colEnd:L,colVersion:O}=e.get();return`${d}:${L}:${O}`},[e]),X=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(X,q,q);const{colStart:K,colEnd:T}=e.get(),$=t.count===0?0:t.offsetOf(Math.min(K,t.count-1));i.useLayoutEffect(()=>{c.current=$,a()},[$,c,a]);const P=d=>p.some(L=>d>=L.startCol&&d<=L.endCol),I=Math.min(Math.max(0,n),t.count),z=Ba(t,I),W=I>0?Kn(t,0,I-1):[],D=Math.min(Math.max(0,r),t.count-I),m=Va(t,D),f=t.totalSize()-m,C=D>0?Kn(t,t.count-D,t.count-1):[],v=Kn(t,Math.max(K,I),Math.min(T,Math.max(0,t.count-1)-D)),A=[];for(const d of v)A.push(U.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d)-$,width:t.sizeOf(d)},children:ze.columnIndexToName(d)},d));const R=g?Co(t,v):null,j=R===null?null:R.filter(d=>!(d.kind==="unhide"&&d.index<I&&z>0||d.kind==="unhide"&&d.index>=t.count-D&&m>0)),b=g&&I>0?Co(t,W):null,E=g&&D>0?hu(t,C):null,B=U.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[A,j?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-$,width:d.length}},`r${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-$,width:d.length}},`u${d.index}`))]});return U.jsx("div",{ref:M,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:I===0&&D===0?B:U.jsxs(U.Fragment,{children:[W.map(d=>U.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:ze.columnIndexToName(d)},d)),b?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),U.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:z,right:D>0?`calc(${ze.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${ze.SPREADSHEET_SCROLLBAR_SIZE_PX+z}px)))`:void 0},children:[B,I>0?U.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,D>0?U.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),D>0?U.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${z}px, calc(100% - ${m+ze.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:ze.SPREADSHEET_SCROLLBAR_SIZE_PX},children:U.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[C.map(d=>U.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d)-f,width:t.sizeOf(d)},children:ze.columnIndexToName(d)},d)),E?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},$w=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:a,frozenRows:p,frozenTrailingRows:g,dividerLeadingRef:y,dividerTrailingRef:N})=>{const F=rt.useWheelBridge(n),M=i.useCallback(d=>(r.current=d,F(d)),[r,F]),q=d=>o.some(L=>d>=L.startRow&&d<=L.endRow),X=i.useCallback(()=>{const{rowStart:d,rowEnd:L,rowGeomVersion:O}=e.get();return`${d}:${L}:${O}`},[e]),K=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(K,X,X);const{rowStart:T,rowEnd:$}=e.get(),P=t.count===0?0:t.offsetOf(Math.min(T,t.count-1));i.useLayoutEffect(()=>{l.current=P,c()},[P,l,c]);const I=Math.min(Math.max(0,p),t.count),z=Wa(t,I),W=I>0?Kn(t,0,I-1):[],D=Math.min(Math.max(0,g),t.count-I),m=Ya(t,D),f=t.totalSize()-m,C=D>0?Kn(t,t.count-D,t.count-1):[],v=Kn(t,Math.max(T,I),Math.min($,Math.max(0,t.count-1)-D)),A=[];for(const d of v)A.push(U.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d)-P,height:t.sizeOf(d)},children:d+1},d));const R=a?Co(t,v):null,j=R===null?null:R.filter(d=>!(d.kind==="unhide"&&d.index<I&&z>0||d.kind==="unhide"&&d.index>=t.count-D&&m>0)),b=a&&I>0?Co(t,W):null,E=a&&D>0?hu(t,C):null,B=U.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[A,j?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-P,height:d.length}},`r${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-P,height:d.length}},`u${d.index}`))]});return U.jsx("div",{ref:M,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:ze.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I===0&&D===0?B:U.jsxs(U.Fragment,{children:[W.map(d=>U.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),b?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),U.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:z,bottom:D>0?`calc(min(${m}px, max(0px, 100% - ${z}px)))`:void 0},children:[B,I>0?U.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,D>0?U.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),D>0?U.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${z}px, calc(100% - ${m}px))`},children:U.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[C.map(d=>U.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d)-f,height:t.sizeOf(d)},children:d+1},d)),E?.map(d=>d.kind==="resize"?U.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):U.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},Lw=9,Dw=4,mc=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,a=`${o} ${s} ${l} ${c}`;return t.set(e,a),a},gc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,zw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),a=i.useRef(null),p=i.useRef(""),g=i.useRef(null),y=i.useCallback(m=>s.current!==null?m.pointerId===s.current:m.pointerType==="mouse",[]),N=i.useCallback(()=>{const m=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),m.writeResizeGuide(null);const f=g.current;f!==null&&(window.removeEventListener("pointermove",f.move),window.removeEventListener("pointerup",f.up),g.current=null);const C=c.current;C!==null&&s.current!==null&&C.hasPointerCapture?.(s.current)&&C.releasePointerCapture(s.current),c.current=null,s.current=null,m.repaintOverlay()},[]),F=i.useCallback((m,f)=>{const C=t.current;return m==="col"?f.startRow===0&&f.endRow===C.rowAxis.count-1:f.startCol===0&&f.endCol===C.colAxis.count-1},[]),M=i.useCallback((m,f)=>{const C=t.current,v=C.getSelection().ranges.filter(E=>F(m,E));if(!v.some(E=>m==="col"?f>=E.startCol&&f<=E.endCol:f>=E.startRow&&f<=E.endRow))return[f];const R=v.reduce((E,B)=>E+(m==="col"?B.endCol-B.startCol+1:B.endRow-B.startRow+1),0),j=m==="row"?Math.floor(C.maxOperationCells/Ns):C.maxOperationCells;if(R>j)return C.onOperationRejected?.("resize",R,"limit"),null;const b=new Set;for(const E of v){const B=m==="col"?E.startCol:E.startRow,d=m==="col"?E.endCol:E.endRow;for(let L=B;L<=d;L+=1)b.add(L)}return[...b]},[F]),q=i.useCallback((m,f,C)=>{const v=t.current,A=m==="col"?v.colAxis:v.rowAxis,R=Fs(A,f,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:Ms,axisKind:m});return R.ok?(v.resizeTracks(m,R.entries),!0):(v.onOperationRejected?.("resize",R.count,R.reason),!1)},[]),X=i.useCallback((m,f)=>{if(f===m.initialSize)return;const C=m.kind==="unhide"?[m.index]:M(m.axis,m.index);C!==null&&q(m.axis,C.map(v=>({index:v,size:f})),m.index)},[M,q]),K=i.useCallback((m,f,C,v)=>{const A=t.current,R=A.fontSourceRef.current;if(R===null)return!1;if(f.length===0)return!0;const j=m.length*f.length;if(j>C)return A.onOperationRejected?.("resize",j,"limit"),!1;const b=document.createElement("canvas").getContext("2d");if(b===null)return!0;const E=getComputedStyle(R),B=`${E.fontStyle} ${E.fontWeight} ${E.fontSize} ${E.fontFamily}`,d=E.getPropertyValue("--_aqsp-header-row-font-weight").trim(),L={fontStyle:E.fontStyle,fontWeight:d===""?E.fontWeight:d,fontSize:E.fontSize,fontFamily:E.fontFamily},O=`${L.fontStyle} ${L.fontWeight} ${L.fontSize} ${L.fontFamily}`,u=A.adapter.getConditionalFormats===void 0?null:ww(A.adapter.getConditionalFormats()),h=Js(),k=new WeakMap,Y=new WeakMap,G=new Map;for(const te of m){const ue=u===null?null:du(u.filter(ae=>ae.ranges.some(Ae=>te>=Ae.startCol&&te<=Ae.endCol)));for(const ae of f){const Ae=A.adapter.getCellText(ae,te),$e=A.adapter.getCellFormat===void 0?void 0:Qs(A.adapter,ue,h,ae,te,()=>Ae),Ne=ae<A.headerRows,Fe=$e===void 0?Ne?O:B:Ne?mc($e,Y,L):mc($e,k,E),Tt=Xn(Ae,$e===void 0?void 0:$e.value),Ce=G.get(Fe);Ce===void 0?G.set(Fe,[{col:te,text:Tt}]):Ce.push({col:te,text:Tt})}}const Q=R.ownerDocument.createElement("span");Q.setAttribute("aria-hidden","true"),Q.style.position="absolute",Q.style.visibility="hidden",R.append(Q);const J=new Map;for(const[te,ue]of G){b.font=te,Q.style.font=te;const ae=getComputedStyle(Q);b.letterSpacing=ae.letterSpacing==="normal"?"0px":ae.letterSpacing,b.wordSpacing=ae.wordSpacing==="normal"?"0px":ae.wordSpacing;for(const Ae of ue){const $e=b.measureText(Ae.text).width,Ne=J.get(Ae.col);(Ne===void 0||$e>Ne)&&J.set(Ae.col,$e)}}Q.remove();const re=[];for(const te of m){const ue=J.get(te);ue!==void 0&&ue>0&&re.push({index:te,size:Math.ceil(ue)+Lw})}return re.length===0?!0:q("col",re,v)},[q]),T=i.useCallback(m=>{const f=t.current,C=M("col",m);if(C===null)return!1;const v=f.handleRef.current,A=v===null?null:v.getFrozenSize(),R=A===null?0:A.rows,j=A===null?0:A.trailingRows,{rowStart:b,rowEnd:E}=f.viewStore.get(),B=Math.min(E,f.rowAxis.count-1),d=[],L=new Set,O=u=>{!L.has(u)&&f.rowAxis.sizeOf(u)>0&&(L.add(u),d.push(u))};for(let u=0;u<R;u+=1)O(u);for(let u=b;u<=B;u+=1)O(u);for(let u=f.rowAxis.count-j;u<f.rowAxis.count;u+=1)O(u);return K(C,d,Math.floor(f.maxOperationCells/Dw),m)},[M,K]),$=i.useCallback((m,f,C)=>{const v=m==="col"?t.current.colAxis:t.current.rowAxis,A=td(v.sizeOf(f),C);if(A===v.sizeOf(f))return!0;const R=M(m,f);return R===null?!1:q(m,R.map(j=>({index:j,size:A})),f)},[M,q]),P=i.useCallback(m=>{const f=t.current;return f.autofitEnabled?f.colAxis.sizeOf(m)===0?!0:T(m):!1},[T]),I=i.useCallback(m=>{const f=t.current;if(!f.autofitEnabled)return!1;const C=[...new Set(m)].filter(A=>f.colAxis.sizeOf(A)>0);if(C.length===0)return!0;const v=[];for(let A=0;A<f.rowAxis.count;A+=1)f.rowAxis.sizeOf(A)>0&&v.push(A);return K(C,v,f.maxOperationCells,null)},[K]),{enabled:z,colBandRef:W,rowBandRef:D}=e;return i.useEffect(()=>{const m=W.current,f=D.current;if(!z||m===null||f===null)return;const C=k=>k==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(k,Y)=>{if(!(Y instanceof Element))return null;const G=Y.closest(C(k));if(G===null)return null;const Q=G.hasAttribute("data-aqsp-unhide"),J=Number(G.getAttribute(Q?"data-aqsp-unhide":k==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),re=G.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:Q?"unhide":"resize",index:J,anchor:re}},A=k=>{if(!(n.current&&y(k)))return;const Y=r.current;if(Y===null)return;const G=(Y.axis==="col"?k.clientX-Y.startClientX:k.clientY-Y.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(Y.anchor==="trailing"?Y.initialSize-G:Y.initialSize+G)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const Q=r.current;if(!n.current||Q===null)return;const J=t.current,re=Q.axis==="col"?J.colAxis:J.rowAxis;J.writeResizeGuide({axis:Q.axis,position:gc(Q,re,o.current),anchor:Q.anchor})}))},R=()=>{const k=r.current,Y=o.current;N(),k!==null&&X(k,Y)},j=k=>{A(k),n.current&&y(k)&&(l.current&1)!==0&&(k.buttons&1)===0&&R()},b=k=>{k.button!==0||!(n.current&&y(k))||R()},E=(k,Y)=>G=>{const Q=t.current;if(p.current=G.pointerType,G.pointerType!=="mouse")return;if(G.button!==0){G.preventDefault();return}const J=v(k,G.target);if(J===null)return;if(G.stopPropagation(),G.preventDefault(),Q.isPointing()){Q.focusSink();return}if(Q.isEditing()&&!Q.requestCommit()){Q.focusSink();return}Q.focusSink();const re=k==="col"?Q.colAxis:Q.rowAxis,te={axis:k,kind:J.kind,index:J.index,anchor:J.anchor,initialSize:re.sizeOf(J.index),startClientX:G.clientX,startClientY:G.clientY};r.current=te,o.current=te.initialSize,l.current=G.buttons,n.current=!0,Q.repaintOverlay(),s.current=G.pointerId,c.current=Y;try{Y.setPointerCapture(G.pointerId)}catch{s.current=null}const ue=j,ae=b;g.current={move:ue,up:ae},window.addEventListener("pointermove",ue),window.addEventListener("pointerup",ae),Q.writeResizeGuide({axis:k,position:gc(te,re,o.current),anchor:te.anchor})},B=(k,Y)=>G=>{const Q=t.current;if(p.current!=="mouse")return;const J=Y.getRootNode(),re=J instanceof ShadowRoot?J:Y.ownerDocument,te=G.target instanceof Element&&G.target.closest(C(k))!==null?G.target:typeof re.elementFromPoint=="function"?re.elementFromPoint(G.clientX,G.clientY):null,ue=v(k,te);if(ue!==null){if(G.stopPropagation(),Q.isEditing()){Q.focusSink();return}if(ue.kind==="unhide"){q(k,[{index:ue.index,size:k==="col"?Q.defaultColumnWidth:Q.defaultRowHeight}],null);return}if(Q.autofitEnabled){if(k==="row"){const ae=M("row",ue.index);ae!==null&&q("row",ae.map(Ae=>({index:Ae,size:Q.defaultRowHeight})),ue.index);return}T(ue.index)}}},d=k=>{!n.current||s.current===null||k.pointerId!==s.current||N()},L=E("col",m),O=E("row",f),u=B("col",m),h=B("row",f);return m.addEventListener("pointerdown",L,{capture:!0}),f.addEventListener("pointerdown",O,{capture:!0}),m.addEventListener("dblclick",u),f.addEventListener("dblclick",h),m.addEventListener("lostpointercapture",d),f.addEventListener("lostpointercapture",d),()=>{m.removeEventListener("pointerdown",L,{capture:!0}),f.removeEventListener("pointerdown",O,{capture:!0}),m.removeEventListener("dblclick",u),f.removeEventListener("dblclick",h),m.removeEventListener("lostpointercapture",d),f.removeEventListener("lostpointercapture",d),N()}},[z,W,D,y,N,X,q,M,T]),i.useMemo(()=>({stepTrack:$,autofitColumn:P,autofitColumnsInAllRows:I,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,$,P,I])},el=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Mw=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>el(n,t.ranges[r]))&&Xt(e.anchor,t.anchor)&&Xt(e.active,t.active),Nw=(e,t,n)=>{const r=l=>l.row<t&&l.col<n,o=l=>l.endRow<t&&l.endCol<n;if(r(e.anchor)&&r(e.active)&&e.ranges.every(o))return e;const s=l=>pn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:me(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},ps=(e,t)=>{if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the ${t} must be an object (got ${String(e)})`);return e},Fw=(e,t,n)=>{const r=ps(e,"selection"),o=r.ranges;if(!Array.isArray(o)||o.length===0)throw new RangeError("[spreadsheet] setSelection: the selection must have at least one range");const s=`${t} x ${n} grid`,l=(y,N)=>typeof y=="number"&&Number.isInteger(y)&&y>=0&&y<N,c=(y,N)=>{const{row:F,col:M}=ps(y,N);if(!(l(F,t)&&l(M,n)))throw new RangeError(`[spreadsheet] setSelection: the ${N} {row: ${String(F)}, col: ${String(M)}} is not a cell of the ${s}`);return{row:F,col:M}},a=o.map((y,N)=>{const{startRow:F,startCol:M,endRow:q,endCol:X}=ps(y,`range ${N}`);if(!(l(F,t)&&l(q,t)&&l(M,n)&&l(X,n)&&F<=q&&M<=X))throw new RangeError(`[spreadsheet] setSelection: range ${N} {startRow: ${String(F)}, startCol: ${String(M)}, endRow: ${String(q)}, endCol: ${String(X)}} is not a range of the ${s} with each start at most its end`);return{startRow:F,startCol:M,endRow:q,endCol:X}}),p=c(r.anchor,"anchor"),g=c(r.active,"active cell");if(!Pt(a[a.length-1],p))throw new RangeError(`[spreadsheet] setSelection: the anchor {row: ${p.row}, col: ${p.col}} must lie in the last range`);if(!a.some(y=>Pt(y,g)))throw new RangeError(`[spreadsheet] setSelection: the active cell {row: ${g.row}, col: ${g.col}} must lie in one of the ranges`);return{ranges:a,anchor:p,active:g}},Pw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return el(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Ar=(e,t,n)=>n.extend?Rn(e,t):n.append?{ranges:[...e.ranges,me(t,t)],anchor:t,active:t}:e.ranges.length===1&&Xt(e.anchor,t)&&Xt(e.active,t)&&el(e.ranges[0],me(t,t))?e:{ranges:[me(t,t)],anchor:t,active:t},_w=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Rn=(e,t)=>{const n=Pw(e,me(e.anchor,t));return n.ranges.some(r=>Pt(r,n.active))?n:{...n,active:_w(n.active,n.ranges[n.ranges.length-1])}},mu=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(me({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(me({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const a=Math.max(c.startRow,t.startRow),p=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(me({row:a,col:c.startCol},{row:p,col:t.startCol-1})),t.endCol<c.endCol&&o.push(me({row:a,col:t.endCol+1},{row:p,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[me(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Pt(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},qw=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},gu=(e,t)=>{const n=e.ranges.findIndex(o=>Pt(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=qw(e.ranges,r.rangeIndex,r.cell,t),!Xt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Wt=24,wc=32,bo=4,_n=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),a=i.useRef(null),p=i.useRef(null),g=i.useRef(null),y=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,g.current=null,p.current=null},[]),N=i.useCallback(()=>{const M=a.current,q=e.current,X=g.current;if(M===null||q===null||X===null){c.current=null;return}const{clientX:K,clientY:T}=M.getPointerPosition(),$=l.current,P=(K-X.left)/$,I=(T-X.top)/$,z=q.getViewportSize(),W=z.width,D=z.height;if(W<=0||D<=0){c.current=requestAnimationFrame(N);return}const m=j=>Math.min(wc,Math.ceil(j/Wt*wc));let f=0,C=0;if(s!=="x"){const j=q.getFrozenSize(),b=j.trailingVisibleHeight;I>D-b-Wt?M.anchorRow!==void 0&&j.trailingRows>0&&M.anchorRow>=t.count-j.trailingRows&&b>0&&I>=D-b||(f=m(I-(D-b-Wt))):I<j.height+Wt&&(M.anchorRow!==void 0&&M.anchorRow<j.rows&&j.height>0&&I<j.height||(f=-m(j.height+Wt-I)))}if(s!=="y"){const j=q.getFrozenSize(),b=j.trailingVisibleWidth;P>W-b-Wt?M.anchorCol!==void 0&&j.trailingCols>0&&M.anchorCol>=n.count-j.trailingCols&&b>0&&P>=W-b||(C=m(P-(W-b-Wt))):P<j.width+Wt&&(M.anchorCol!==void 0&&M.anchorCol<j.cols&&j.width>0&&P<j.width||(C=-m(j.width+Wt-P)))}const v=C!==0||f!==0?q.scrollBy({x:C!==0?C:void 0,y:f!==0?f:void 0}):q.getScrollPosition(),A=v.y,R=v.x;if(A>=0&&R>=0&&t.totalSize()>0&&n.totalSize()>0){const j=q.getFrozenSize(),b=pn({row:zr(t,I,{scroll:A,frozenSize:j.height,trailingSize:j.trailingHeight,extent:z.height}),col:Dr(n,P,{scroll:R,frozenSize:j.width,trailingSize:j.trailingWidth,extent:z.width})},t.count,n.count),E=p.current;(f!==0||C!==0||E===null||E.row!==b.row||E.col!==b.col)&&(p.current=b,o(M.buildRange(b)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),F=i.useCallback(M=>{y(),a.current=M,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[y,N,r]);return i.useEffect(()=>{const M=()=>{document.visibilityState==="hidden"&&y()};return document.addEventListener("visibilitychange",M),()=>{document.removeEventListener("visibilitychange",M),y()}},[y]),i.useMemo(()=>({start:F,stop:y}),[F,y])},Cc=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),p=i.useRef(0),g=i.useRef(null),y=i.useRef(!1),N=i.useRef(0),F=i.useCallback((z,W)=>{const{axis:D,mainAxis:m,handleRef:f,zoomRef:C}=t.current,v=s.current;if(v===null||m.totalSize()===0)return null;const A=C.current,R=f.current;if(R===null)return null;if(D==="col"){const B=R.getScrollPosition().x;if(B<0)return null;const d=R.getFrozenSize(),L=R.getViewportSize();return Math.min(Math.max(Dr(m,(z-v.left)/A,{scroll:B,frozenSize:d.width,trailingSize:d.trailingWidth,extent:L.width}),0),m.count-1)}const j=R.getScrollPosition().y;if(j<0)return null;const b=R.getFrozenSize(),E=R.getViewportSize();return Math.min(Math.max(zr(m,(W-v.top)/A,{scroll:j,frozenSize:b.height,trailingSize:b.trailingHeight,extent:E.height}),0),m.count-1)},[]),M=i.useCallback((z,W)=>{const{axis:D,crossCount:m}=t.current;return D==="col"?{press:{row:0,col:z},extend:{row:m-1,col:W}}:{press:{row:z,col:0},extend:{row:W,col:m-1}}},[]),q=i.useCallback((z,W)=>{const{axis:D,crossCount:m}=t.current;return z.ranges.some(f=>D==="col"?f.startRow===0&&f.endRow===m-1&&W>=f.startCol&&W<=f.endCol:f.startCol===0&&f.endCol===m-1&&W>=f.startRow&&W<=f.endRow)},[]),X=i.useRef(!1),K=i.useRef({clientX:0,clientY:0}),T=i.useCallback(()=>{X.current=!1;const{autoScroller:z,headerRef:W,onDragFrame:D}=t.current;n.current=!1,r.current=null,g.current=null,y.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),z.stop();const m=W.current;m!==null&&a.current!==null&&m.hasPointerCapture?.(a.current)&&m.releasePointerCapture(a.current),a.current=null,D(null),t.current.repaintOverlay()},[]),$=i.useCallback(()=>{if(!n.current)return;const z=r.current;z!==null&&t.current.setSelection(z),T()},[T]),{enabled:P,headerRef:I}=e;return i.useEffect(()=>{const z=I.current;if(!P||z===null)return;const W=R=>{const j=t.current;if(R.pointerType!=="mouse")return;if(R.button!==0){R.preventDefault();return}if(y.current=!1,j.pointing?.getPointing()){s.current=z.getBoundingClientRect();const d=F(R.clientX,R.clientY);if(d===null)return;R.preventDefault(),j.focusSink(),j.pointing.insertReference(j.axis==="col"?{row:0,col:d}:{row:d,col:0},j.axis==="col"?"columns":"rows");return}if(j.isEditing()&&!j.requestCommit()){R.preventDefault(),j.focusSink();return}s.current=z.getBoundingClientRect();const b=F(R.clientX,R.clientY);if(b===null)return;R.preventDefault(),j.focusSink();const E=j.getSelection();r.current=E;const B=R.ctrlKey||R.metaKey;if(R.shiftKey){const d=j.axis==="col"?{row:0,col:E.anchor.col}:{row:E.anchor.row,col:0},{extend:L}=M(b,b),O={...E,anchor:d};j.setSelection(Rn(O,L)),o.current=j.axis==="col"?d.col:d.row}else if(B&&q(E,b))y.current=!0,N.current=b,o.current=b;else{const{press:d,extend:L}=M(b,b),O=Ar(E,d,{extend:!1,append:B});j.setSelection(Rn(O,L)),o.current=b}n.current=!0,j.repaintOverlay(),l.current={clientX:R.clientX,clientY:R.clientY},a.current=R.pointerId,p.current=R.buttons;try{z.setPointerCapture(R.pointerId)}catch{a.current=null}g.current=d=>{const L=t.current.axis==="col"?d.col:d.row,{press:O}=M(o.current,o.current),{extend:u}=M(o.current,L);return me(O,u)},j.autoScroller.stop(),X.current=!1,K.current={clientX:R.clientX,clientY:R.clientY}},D=R=>a.current!==null?R.pointerId===a.current:R.pointerType==="mouse",m=R=>{if(n.current&&D(R)){if(y.current){const j=R.clientX!==l.current.clientX||R.clientY!==l.current.clientY;if(l.current={clientX:R.clientX,clientY:R.clientY},!j)return;const b=F(R.clientX,R.clientY);if(b===null||b===N.current)return;y.current=!1;const E=t.current,{press:B,extend:d}=M(N.current,N.current),L=Ar(E.getSelection(),B,{extend:!1,append:!0});E.setSelection(Rn(L,d));const O=g.current,u=Math.abs(R.clientX-K.current.clientX),h=Math.abs(R.clientY-K.current.clientY);O!==null&&Math.max(u,h)>=bo&&(X.current=!0,E.autoScroller.start({getPointerPosition:()=>l.current,buildRange:O,anchorCol:E.axis==="col"?o.current:void 0,anchorRow:E.axis==="row"?o.current:void 0}))}else if(l.current={clientX:R.clientX,clientY:R.clientY},!X.current&&g.current!==null){const j=Math.abs(R.clientX-K.current.clientX),b=Math.abs(R.clientY-K.current.clientY);Math.max(j,b)>=bo&&(X.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:g.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const j=g.current;if(!n.current||j===null)return;const b=F(l.current.clientX,l.current.clientY);b!==null&&t.current.onDragFrame(j(t.current.axis==="col"?{row:0,col:b}:{row:b,col:0}))}))}},f=R=>{m(R),n.current&&D(R)&&(p.current&1)!==0&&(R.buttons&1)===0&&v(R)},C=R=>{R.button!==0||!(n.current&&D(R))||v(R)},v=R=>{const j=t.current;if(y.current){const{press:E,extend:B}=M(N.current,N.current);j.setSelection(mu(j.getSelection(),me(E,B),E)),T();return}const b=F(R.clientX,R.clientY);if(b!==null){const{extend:E}=M(o.current,b);j.setSelection(Rn(j.getSelection(),E))}T()},A=R=>{!n.current||a.current===null||R.pointerId!==a.current||$()};return z.addEventListener("pointerdown",W),z.addEventListener("pointermove",f),z.addEventListener("pointerup",C),z.addEventListener("lostpointercapture",A),()=>{z.removeEventListener("pointerdown",W),z.removeEventListener("pointermove",f),z.removeEventListener("pointerup",C),z.removeEventListener("lostpointercapture",A),T()}},[P,I,F,M,T,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:$,cancelDrag:T}),[$,T])},jw=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(l<0||s<0)return;const p=o.getFrozenSize();if(a>0&&r.row>=p.rows&&r.row<t.count-p.trailingRows){const g=t.offsetOf(r.row),y=g+t.sizeOf(r.row);g<p.height+l?o.scrollBy({y:g-(p.height+l)}):y>l+a-p.trailingVisibleHeight&&o.scrollBy({y:y-(l+a-p.trailingVisibleHeight)})}if(c>0){if(r.col<p.cols||r.col>=n.count-p.trailingCols)return;const g=n.offsetOf(r.col),y=g+n.sizeOf(r.col);g<p.width+s?o.scrollBy({x:g-(p.width+s)}):y>s+c-p.trailingVisibleWidth&&o.scrollBy({x:y-(s+c-p.trailingVisibleWidth)})}},Iw=50,Hw=100,wu=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Iw:!1,gr={selectAll:Yt("Ctrl+A"),undo:Yt("Ctrl+Z"),redo:Yt("Ctrl+Y"),redoShiftZ:Yt("Ctrl+Shift+Z"),pasteValues:Yt("Ctrl+Shift+V")},Bw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Ww={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Vw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Yw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(null),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(e);a.current=e;const{enabled:p,sinkRef:g,rootRef:y,handleRef:N}=e;i.useEffect(()=>{const F=g.current,M=y.current;if(!p||F===null||M===null)return;const q=()=>{c.current&&(c.current=!1,a.current.onPointFrame?.(null))},X=(u,h,k)=>an(u,h,k)??h,K=(u,h)=>{const k=a.current;return h==="left"||h==="right"?{row:u.row,col:X(k.colAxis,u.col,h==="right"?1:-1)}:{row:X(k.rowAxis,u.row,h==="down"?1:-1),col:u.col}},T=u=>u.indexAt(0),$=u=>u.indexAt(u.totalSize()-1),P=(u,h,k,Y)=>{if(u.sizeOf(h)>0)return h;const G=an(u,h,k);if(G!==null)return G;const Q=an(u,h,k===1?-1:1);return Q!==null?Q:Y},I=()=>{const u=a.current.getSelection(),h=u.ranges[u.ranges.length-1];return{row:u.anchor.row===h.startRow?h.endRow:h.startRow,col:u.anchor.col===h.startCol?h.endCol:h.startCol}},z=u=>K(I(),u),W=(u,h)=>{const k=a.current,Y=h==="left"||h==="right",G=h==="right"||h==="down"?1:-1;let Q;return k.findDataEdge!==void 0?(Q=k.findDataEdge({row:u.row,col:u.col},h),D(Q,u,h)):Q={row:h==="down"?k.rowAxis.count-1:h==="up"?0:u.row,col:h==="right"?k.colAxis.count-1:h==="left"?0:u.col},Y?{row:Q.row,col:P(k.colAxis,Q.col,G,u.col)}:{row:P(k.rowAxis,Q.row,G,u.row),col:Q.col}},D=(u,h,k)=>{const Y=a.current;if(!(Number.isInteger(u.row)&&Number.isInteger(u.col)&&u.row>=0&&u.row<Y.rowAxis.count&&u.col>=0&&u.col<Y.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${u.row}, col: ${u.col}} for a ${Y.rowAxis.count} x ${Y.colAxis.count} grid`);const G=k==="left"||k==="right";if(G?u.row!==h.row:u.col!==h.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${G?"row":"column"} (received {row: ${u.row}, col: ${u.col}} from {row: ${h.row}, col: ${h.col}})`)},m=(u,h,k)=>{if(!(Number.isInteger(u)&&u>=0&&u<h))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${k} component ${u} (count ${h})`)},f=u=>{const h=a.current,k=h.getSelection();if(gu(k,u)===k){h.moveActive({mode:"reset",cell:K(k.active,u)});return}h.moveActive({mode:"cycle",direction:u})},C=u=>{const h=a.current,k=h.commands;if(k===void 0||!h.isEditing())return null;const Y=Ts(k.table,u);return Y!==null&&Y.command==="fillSelection"&&k.isAvailable("fillSelection")?k:null},v=()=>{s.current=null;const u=a.current,h=u.commands;h===void 0||!u.isEditing()||!h.isAvailable("fillSelection")||h.execute("fillSelection")},A=u=>{const h=C(u);if(r.current){o.current=h!==null;return}h!==null&&t.current!==null&&(u.preventDefault(),h.execute("fillSelection"))},R=()=>{const u=g.current;if(u===null)return;const h=u.selectionStart??u.value.length,k=u.selectionEnd??h;u.value=`${u.value.slice(0,h)}
14
- ${u.value.slice(k)}`,u.setSelectionRange(h+1,h+1)},j=(u,h)=>{const k=a.current,Y=k.pageExtent();if(Y<=0)return X(k.rowAxis,u,h==="down"?1:-1);const G=k.rowAxis.indexAt(k.rowAxis.offsetOf(u)+(h==="down"?Y:-Y));return G===u?X(k.rowAxis,u,h==="down"?1:-1):G},b=u=>{const h=a.current;if(l.current=!1,wu(u,t.current)){A(u);return}const k=u.ctrlKey||u.metaKey,Y=u.altKey,G=Ww[u.key];if(c.current&&!Bw.has(u.key)&&!h.isDragging()&&q(),h.isEditing()){const J=h.getEditingMode();if(h.isDragging()){u.preventDefault(),u.key==="Escape"&&!k&&!u.shiftKey&&!Y&&h.abortDrag();return}const re=h.pointing;if(re!==void 0){if(G!==void 0&&!Y){const ae=re.getReferenceCursor();if(ae!==null){u.preventDefault();const Ae=pn(ae.cursor,h.rowAxis.count,h.colAxis.count),$e=pn(ae.origin,h.rowAxis.count,h.colAxis.count),Ne=k?W(Ae,G):K(Ae,G);if(h.ensureCellVisible(Ne),re.insertReference(u.shiftKey?me($e,Ne):Ne,ae.axis),h.onPointFrame!==void 0){const Fe=u.shiftKey?me($e,Ne):me(Ne,Ne);h.onPointFrame(ae.axis==="columns"?me({row:0,col:Fe.startCol},{row:h.rowAxis.count-1,col:Fe.endCol}):ae.axis==="rows"?me({row:Fe.startRow,col:0},{row:Fe.endRow,col:h.colAxis.count-1}):Fe),c.current=!0}return}}if(u.key==="F2"&&!k&&!u.shiftKey&&!Y&&re.togglePointingArm()){u.preventDefault();return}if(u.key==="F4"&&!k&&!u.shiftKey&&!Y&&re.cycleAnchorAtCaret()){u.preventDefault();return}}const te=h.commands,ue=te===void 0?null:Ts(te.table,u);if(te!==void 0&&ue!==null&&go.has(ue.command)&&te.isAvailable(ue.command)){u.preventDefault(),te.execute(ue.command);return}if(G!==void 0&&!Y){if(k&&u.shiftKey){u.preventDefault();return}if(k)return;if(J==="replace"){if(u.preventDefault(),!h.requestCommit())return;u.shiftKey?h.moveActive({mode:"extend",cell:z(G)}):h.moveActive({mode:"reset",cell:K(h.getSelection().active,G)});return}return}if(u.key==="Enter"&&Y&&!k&&!u.shiftKey){u.preventDefault(),R();return}if((u.key==="Enter"||u.key==="Tab")&&!k&&!Y){if(u.preventDefault(),!h.requestCommit())return;const ae=!u.shiftKey;f(u.key==="Tab"?ae?"right":"left":ae?"down":"up");return}if((u.key==="PageUp"||u.key==="PageDown")&&!u.shiftKey&&!k&&!Y){if(u.preventDefault(),!h.requestCommit())return;const ae=h.getSelection().active;h.moveActive({mode:"reset",cell:{row:j(ae.row,u.key==="PageDown"?"down":"up"),col:ae.col}});return}if(u.key==="Escape"&&!k&&!u.shiftKey&&!Y){u.preventDefault(),h.cancelEdit();return}if(te!==void 0&&ue!==null&&!go.has(ue.command)&&im(ue.chord)&&te.isAvailable(ue.command)){u.preventDefault(),h.onCommandBlockedWhileEditing?.(ue);return}return}if(u.defaultPrevented)return;if(h.isDragging()&&u.key!=="Escape"){u.preventDefault();return}const Q=h.commands;if(Q!==void 0){const J=om(Q.table,u);if(J!==null&&Q.isAvailable(J)){u.preventDefault(),Q.execute(J);return}}if(G!==void 0&&!Y){const J=G==="left"||G==="right",re=G==="right"||G==="down"?1:-1;if(k&&u.shiftKey){u.preventDefault();const te=h.getSelection(),ue=I();let ae;if(h.findDataEdge!==void 0){const Ae=J?{row:te.active.row,col:ue.col}:{row:ue.row,col:te.active.col},$e=h.findDataEdge(Ae,G);ae=J?$e.col:$e.row,m(ae,J?h.colAxis.count:h.rowAxis.count,J?"col":"row"),ae=P(J?h.colAxis:h.rowAxis,ae,re,J?ue.col:ue.row)}else{const Ae=J?h.colAxis:h.rowAxis;ae=re===1?$(Ae):T(Ae)}h.moveActive({mode:"extend",cell:J?{row:ue.row,col:ae}:{row:ae,col:ue.col}});return}if(k){u.preventDefault(),h.moveActive({mode:"reset",cell:W(h.getSelection().active,G)});return}if(u.shiftKey){u.preventDefault(),h.moveActive({mode:"extend",cell:z(G)});return}u.preventDefault(),h.moveActive({mode:"reset",cell:K(h.getSelection().active,G)});return}if(Vw(u)){u.preventDefault();return}if((u.key==="Tab"||u.key==="Enter")&&!k&&!Y){u.preventDefault();const J=!u.shiftKey;f(u.key==="Tab"?J?"right":"left":J?"down":"up");return}if(u.key==="Home"&&!Y){if(u.preventDefault(),u.shiftKey){const re=I();h.moveActive({mode:"extend",cell:{row:k?T(h.rowAxis):re.row,col:T(h.colAxis)}});return}const J=h.getSelection().active;h.moveActive({mode:"reset",cell:{row:k?T(h.rowAxis):J.row,col:T(h.colAxis)}});return}if(u.key==="End"&&!Y){if(u.preventDefault(),u.shiftKey){const re=I();h.moveActive({mode:"extend",cell:{row:k?$(h.rowAxis):re.row,col:$(h.colAxis)}});return}const J=h.getSelection().active;h.moveActive({mode:"reset",cell:{row:k?$(h.rowAxis):J.row,col:$(h.colAxis)}});return}if((u.key==="PageUp"||u.key==="PageDown")&&!k&&!Y){u.preventDefault();const J=u.key==="PageDown"?"down":"up";if(u.shiftKey){const te=I();h.moveActive({mode:"extend",cell:{row:j(te.row,J),col:te.col}});return}const re=h.getSelection().active;h.moveActive({mode:"reset",cell:{row:j(re.row,J),col:re.col}});return}if(u.key==="F2"&&!k&&!u.shiftKey&&!Y){u.preventDefault(),h.startEdit("edit");return}if((u.key==="Delete"||u.key==="Backspace")&&!k&&!u.shiftKey&&!Y){u.preventDefault();const J=h.getSelection(),re=mt(J.ranges);if(re>h.maxOperationCells){h.onOperationRejected?.("delete",re,"limit");return}if(h.adapter!==void 0&&Bn(h.adapter,J.ranges)){h.rejectReadOnly({kind:"operation",op:"delete",cellCount:re});return}const te=[],ue=h.adapter!==void 0&&uo(h.adapter).hyperlink;sn(J.ranges,ae=>{te.push(ue?{row:ae.row,col:ae.col,text:"",hyperlink:null}:{row:ae.row,col:ae.col,text:""})}),h.commitEdits(te,{source:"delete"});return}if(u.key==="Escape"){if(h.isDragging()){u.preventDefault(),h.abortDrag();return}if(k||u.shiftKey||Y||(u.preventDefault(),h.hideNoteTip?.())||h.closeRejectedMessage?.())return;if(h.getClip()!==null){h.discardClip();return}h.handOffFocusToRoot();return}if(pr(gr.selectAll,u)){u.preventDefault();const J=h.getSelection(),re=me({row:0,col:0},{row:h.rowAxis.count-1,col:h.colAxis.count-1});h.setSelection({ranges:[re],anchor:J.anchor,active:J.active});return}if(pr(gr.undo,u)){u.preventDefault(),h.onUndoRequest?.();return}if(pr(gr.redo,u)||pr(gr.redoShiftZ,u)){u.preventDefault(),h.onRedoRequest?.();return}if(u.key==="F10"&&u.shiftKey&&!k&&!Y||u.key==="ContextMenu"&&!k&&!u.shiftKey&&!Y){u.preventDefault();const J=h.getSelection().active;h.ensureCellVisible(J);const re=N.current,te=re===null?{x:0,y:0}:re.getScrollPosition(),ue=Math.max(0,te.y),ae=Math.max(0,te.x),Ae=re===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:re.getFrozenSize(),$e=re===null?{width:0,height:0}:re.getViewportSize(),Ne=h.zoomRef.current;h.onCellContextMenu?.(J,{kind:"keyboard",cellRect:{top:kn(h.rowAxis,J.row,{scroll:ue,frozenCount:Ae.rows,trailingCount:Ae.trailingRows,extent:$e.height})*Ne,left:Sn(h.colAxis,J.col,{scroll:ae,frozenCount:Ae.cols,trailingCount:Ae.trailingCols,extent:$e.width})*Ne,width:h.colAxis.sizeOf(J.col)*Ne,height:h.rowAxis.sizeOf(J.row)*Ne}});return}if(u.key===" "&&!Y&&k!==u.shiftKey){u.preventDefault();const J=h.getSelection(),re=J.ranges.map(te=>k?me({row:0,col:te.startCol},{row:h.rowAxis.count-1,col:te.endCol}):me({row:te.startRow,col:0},{row:te.endRow,col:h.colAxis.count-1}));h.setSelection({ranges:re,anchor:J.anchor,active:J.active});return}if(h.pendingPasteOptionsRef!==void 0&&pr(gr.pasteValues,u)){h.pendingPasteOptionsRef.current={mode:"values"};return}if(u.key.length===1&&!u.metaKey&&u.ctrlKey===u.altKey){if(u.ctrlKey&&u.altKey){l.current=!0;return}h.startEdit("replace");return}},E=()=>{const u=a.current;r.current=!0,o.current=!1,u.isEditing()||u.startEdit("replace")},B=u=>{r.current=!1,t.current=u.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Hw),o.current&&(o.current=!1,u.data!==""&&(s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(v,0)))},d=()=>{const u=a.current;if(q(),!u.isEditing()){if(l.current){l.current=!1;const h=F.value;if(h!==""&&(u.startEdit("replace"),u.isEditing())){F.value=h,F.setSelectionRange(h.length,h.length);return}}u.rearmSink()}},L=()=>{l.current=!1;const u=a.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null)},O=()=>{l.current=!1;const u=a.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null),q()};return F.addEventListener("keydown",b),F.addEventListener("keyup",L),F.addEventListener("blur",O),F.addEventListener("compositionstart",E),F.addEventListener("compositionend",B),F.addEventListener("input",d),()=>{F.removeEventListener("keydown",b),F.removeEventListener("keyup",L),F.removeEventListener("blur",O),F.removeEventListener("compositionstart",E),F.removeEventListener("compositionend",B),F.removeEventListener("input",d),n.current!==null&&window.clearTimeout(n.current),s.current!==null&&(window.clearTimeout(s.current),s.current=null),r.current=!1,o.current=!1,q()}},[p,g,y,N])},Kw=()=>{let e={vy:0,rowStart:0,rowEnd:0,colStart:0,colEnd:0,colVersion:0,rowGeomVersion:0,editVersion:0};const t=new Set;let n=null;const r=()=>{n=null;for(const l of[...t])l()},o=()=>{t.size!==0&&n===null&&(n=requestAnimationFrame(r))},s=l=>{e={...e,...l},o()};return{get:()=>e,setVy:l=>{l!==e.vy&&s({vy:l})},setRowRange:(l,c)=>{(l!==e.rowStart||c!==e.rowEnd)&&s({rowStart:l,rowEnd:c})},setColRange:(l,c)=>{(l!==e.colStart||c!==e.colEnd)&&s({colStart:l,colEnd:c})},bumpColVersion:()=>s({colVersion:e.colVersion+1}),bumpRowGeometry:()=>s({rowGeomVersion:e.rowGeomVersion+1}),bumpEdit:()=>s({editVersion:e.editVersion+1}),subscribeCoalesced:l=>(t.add(l),()=>{t.delete(l),t.size===0&&n!==null&&(cancelAnimationFrame(n),n=null)})}},Uw=4,Xw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Gw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),a=i.useRef(!1),p=i.useRef({dx:0,dy:0}),g=i.useRef(null),y=i.useRef(0),N=i.useRef(null),F=i.useRef(null),M=i.useRef(!1),q=i.useCallback(z=>g.current!==null?z.pointerId===g.current:z.pointerType==="mouse",[]),X=i.useCallback((z,W)=>{const{handleRef:D,rowAxis:m,colAxis:f}=t.current,C=D.current,v=s.current;if(C===null||v===null)return null;const{x:A,y:R}=C.getScrollPosition();if(R<0||A<0||m.totalSize()===0||f.totalSize()===0)return null;const j=t.current.zoomRef.current,b=C.getFrozenSize(),E=C.getViewportSize();return pn({row:zr(m,(W-v.top)/j,{scroll:R,frozenSize:b.height,trailingSize:b.trailingHeight,extent:E.height}),col:Dr(f,(z-v.left)/j,{scroll:A,frozenSize:b.width,trailingSize:b.trailingWidth,extent:E.width})},m.count,f.count)},[]),K=i.useCallback(z=>{const W=r.current;if(W===null)return me(z,z);const D=me({row:Math.min(W.startRow,z.row),col:Math.min(W.startCol,z.col)},{row:Math.max(W.endRow,z.row),col:Math.max(W.endCol,z.col)}),m=D.startRow!==W.startRow||D.endRow!==W.endRow||D.startCol!==W.startCol||D.endCol!==W.endCol;return o.current=m?D:null,m?D:W},[]),T=i.useCallback(()=>{const z=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),z.xAutoScroller.stop(),z.yAutoScroller.stop(),M.current=!1,a.current=!1,p.current={dx:0,dy:0},z.writeFillPreview(null);const W=F.current;W!==null&&(window.removeEventListener("pointermove",W.move),window.removeEventListener("pointerup",W.up),F.current=null);const D=t.current.handleNodeRef.current;D!==null&&g.current!==null&&D.hasPointerCapture?.(g.current)&&D.releasePointerCapture(g.current),g.current=null,z.repaintOverlay()},[]),$=i.useCallback(()=>{const z=t.current,W=r.current,D=o.current;if(T(),W===null||D===null)return;const m=Ih(W,D);if(m>z.maxOperationCells){z.onOperationRejected?.("fill",m,"limit");return}const f=Hh(W,D);if(Bn(z.adapter,f)){z.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(f),gesture:"fillHandle",sources:[W],targets:f});return}const C=Bh((A,R)=>xa(z.adapter,A,R),W,D,Ta);if(z.commitEdits(C,{source:"fill"})===null)return;const v=z.getSelection();z.setSelection({ranges:[D],anchor:v.anchor,active:v.active})},[T]),{enabled:P,handleNodeRef:I}=e;return i.useEffect(()=>{const z=I.current;if(!P||z===null)return;const W=v=>{D(v),n.current&&q(v)&&(y.current&1)!==0&&(v.buttons&1)===0&&$()},D=v=>{if(!(n.current&&q(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const A=Math.abs(v.clientX-c.current.clientX),R=Math.abs(v.clientY-c.current.clientY);if(!a.current&&Math.max(A,R)>=Uw&&(a.current=!0),!!a.current){if(!M.current){const j=t.current,b={getPointerPosition:()=>({clientX:l.current.clientX-p.current.dx,clientY:l.current.clientY-p.current.dy}),buildRange:K,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};j.xAutoScroller.start(b),j.yAutoScroller.start(b),M.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&a.current))return;const j=X(l.current.clientX-p.current.dx,l.current.clientY-p.current.dy);j!==null&&t.current.writeFillPreview(K(j))}))}},m=v=>{v.button!==0||!(n.current&&q(v))||$()},f=v=>{const A=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),A.focusSink();const R=A.getSelection(),j=R.ranges[R.ranges.length-1];r.current=j,o.current=null,a.current=!1,A.xAutoScroller.stop(),A.yAutoScroller.stop(),M.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,y.current=v.buttons,n.current=!0,A.repaintOverlay(),s.current=A.bodyRef.current?.getBoundingClientRect()??null;const b=s.current,E=A.handleRef.current?.getScrollPosition()??{x:-1,y:-1},B=E.y;if(b!==null&&B>=0&&E.x>=0){const O=E.x,u=A.zoomRef.current,h=A.handleRef.current?.getFrozenSize()??Xw,k=A.handleRef.current?.getViewportSize()??{width:0,height:0},Y={scroll:O,frozenCount:h.cols,trailingCount:h.trailingCols,extent:k.width},G={scroll:B,frozenCount:h.rows,trailingCount:h.trailingRows,extent:k.height},Q=Sn(A.colAxis,j.endCol,Y)+A.colAxis.sizeOf(j.endCol),J=kn(A.rowAxis,j.endRow,G)+A.rowAxis.sizeOf(j.endRow),re=Q-1,te=j.endCol>=h.cols&&h.width>0?Math.max(re,h.width):re,ae=!(j.endCol>=A.colAxis.count-h.trailingCols)&&h.trailingWidth>0?Math.min(te,k.width-h.trailingVisibleWidth-1):te,Ae=J-1,$e=j.endRow>=h.rows&&h.height>0?Math.max(Ae,h.height):Ae,Fe=!(j.endRow>=A.rowAxis.count-h.trailingRows)&&h.trailingHeight>0?Math.min($e,k.height-h.trailingVisibleHeight-1):$e;p.current={dx:v.clientX-(b.left+ae*u),dy:v.clientY-(b.top+Fe*u)}}else p.current={dx:0,dy:0};g.current=v.pointerId;try{z.setPointerCapture(v.pointerId)}catch{g.current=null}const d=W,L=m;F.current={move:d,up:L},window.addEventListener("pointermove",d),window.addEventListener("pointerup",L),A.writeFillPreview(r.current)},C=v=>{!n.current||g.current===null||v.pointerId!==g.current||T()};return z.addEventListener("pointerdown",f),z.addEventListener("lostpointercapture",C),()=>{z.removeEventListener("pointerdown",f),z.removeEventListener("lostpointercapture",C),T()}},[P,I,q,X,K,T,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&T()},cancelDrag:T}),[T])},Zw=320,fo=8,Jw=64,Qw=150,Cu=e=>Math.max(0,Math.min(Zw,e.width-ze.SPREADSHEET_SCROLLBAR_SIZE_PX-fo)),e0=(e,t,n)=>{const r=n.width-ze.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-ze.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Cu(n),l=Math.max(0,Math.min(t,o-fo)),c=e.left+e.width,a=e.top+e.height,p=q=>q>=0&&q+s<=r,g=[e.left,c-s],y=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const q of y)if(p(q.left)&&q.top>=0&&q.top+l<=o)return{left:q.left,top:q.top,width:s,height:l};const N=o-a,F=e.top,M=Math.min(l,Math.max(N,F));if(M>=Jw){const q=N>=F?a:e.top-M;for(const X of g)if(p(X))return{left:X,top:q,width:s,height:M}}return{left:fo,top:fo,width:s,height:l}},t0=(e,t,n,r)=>t===null||e!==null&&Xt(e,t)||n?!1:r(t),n0=(e,t)=>{switch(e.kind){case"note":return U.jsx(Ja,{ctx:e,labels:t});case"note-tip":return U.jsx(Qa,{ctx:e,labels:t});case"comment":return U.jsx(Ua,{ctx:e,labels:t});case"link":return U.jsx(Xa,{ctx:e,labels:t});case"list":return U.jsx(Ga,{ctx:e,labels:t});default:return U.jsx(Za,{ctx:e,labels:t})}},hs=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,r0=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),a=i.useRef(null),p=i.useRef(l);p.current=l;const g=i.useRef(e);g.current=e;const y=hs(s),N=hs(l),F=i.useRef(null),M=($,P)=>{const I=g.current.getLayerSize();$.style.width=`${Cu(I)}px`,$.style.maxHeight="";const z=e0(P,$.offsetHeight,I);$.style.left=`${z.left-P.left}px`,$.style.top=`${z.top-P.top}px`,$.style.maxHeight=`${z.height}px`};i.useLayoutEffect(()=>{const $=c.current;if($===null||s===null){F.current=null;return}if(M($,s.anchorRect),s.kind==="message")return;const P=hs(s);if(F.current===P)return;F.current=P;const I=$.querySelector("[data-aqsp-popover-autofocus]");I!==null?I.focus({preventScroll:!0}):$.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const $=a.current,P=p.current;$===null||P===null||M($,P.anchorRect)},[N]);const q=$=>t===void 0?n0($,n):t($),X=$=>{e.isCompositionKey($.nativeEvent)&&$.stopPropagation()},K=$=>{$.key==="Escape"&&!$.defaultPrevented&&($.preventDefault(),e.close())},T=$=>{e.registerCompositionEnd($.timeStamp)};return U.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:X,onKeyDown:K,onCompositionEnd:T,children:[U.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:U.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:q(s)},y)}),U.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:U.jsx("div",{ref:a,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:q(l)})})]})},o0=["note","note-tip","comment","link","list","message"],s0=(e,t)=>{switch(t){case"note":case"note-tip":return e.getCellNote!==void 0;case"comment":return e.getCellComments!==void 0;case"link":return e.getCellHyperlink!==void 0;default:return e.getCellValidation!==void 0}},wr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&s0(e,n),l0=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),a=i.useRef(null),p=i.useRef(!1),g=i.useRef(null),y=i.useRef(null),N=i.useRef(null),F=i.useRef(null),M=i.useId(),q=i.useCallback(O=>{const u=t.current,h=u.handleRef.current,k=h===null?{x:0,y:0}:h.getScrollPosition(),Y=h===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:h.getFrozenSize(),G=h===null?{width:0,height:0}:h.getViewportSize();return{top:kn(u.rowAxis,O.row,{scroll:Math.max(0,k.y),frozenCount:Y.rows,trailingCount:Y.trailingRows,extent:G.height}),left:Sn(u.colAxis,O.col,{scroll:Math.max(0,k.x),frozenCount:Y.cols,trailingCount:Y.trailingCols,extent:G.width}),width:u.colAxis.sizeOf(O.col),height:u.rowAxis.sizeOf(O.row)}},[]),X=i.useCallback(O=>{const u=t.current;u.anchors.current={...u.anchors.current,...O},u.repaintOverlay()},[]),K=i.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),T=i.useCallback(()=>{const O=t.current.sinkRef.current;if(O===null)return;const u=c.current;u!==null&&Xt(u,t.current.getActive())?O.setAttribute("aria-describedby",M):O.getAttribute("aria-describedby")===M&&O.removeAttribute("aria-describedby")},[M]),$=i.useCallback(()=>(K(),p.current=!1,c.current===null?!1:(c.current=null,s(null),X({tip:null}),T(),!0)),[K,X,T]),P=i.useCallback(()=>{K(),g.current=window.setTimeout(()=>{g.current=null,$()},Qw)},[K,$]),I=i.useCallback(O=>{const u=t.current;K();const h=u.adapter.getCellNote===void 0?void 0:u.adapter.getCellNote(O.row,O.col);h===void 0||h===""||(c.current=O,s({kind:"note-tip",cell:O,anchorRect:q(O),current:h,close:$}),X({tip:O}),T())},[q,K,$,X,T]),z=i.useCallback(O=>{const u=t.current;if(O===null&&p.current)return;const h=a.current;a.current=O;const k=c.current;if(k!==null&&O!==null&&Xt(k,O)){K();return}const Y=G=>{const Q=u.adapter.getCellNote===void 0?void 0:u.adapter.getCellNote(G.row,G.col);return Q!==void 0&&Q!==""};if(t0(h,O,u.isDraggingAny(),Y)){O!==null&&I(O);return}k!==null&&P()},[I,K,P]),W=i.useCallback((O,u)=>{const h=t.current,k=h.bodyRef.current,Y=h.handleRef.current;if(k===null||Y===null)return null;const G=k.getBoundingClientRect(),Q=h.zoomRef.current,J=Y.getScrollPosition(),re=Y.getFrozenSize(),te=Y.getViewportSize();return pn({row:zr(h.rowAxis,(u-G.top)/Q,{scroll:Math.max(0,J.y),frozenSize:re.height,trailingSize:re.trailingHeight,extent:te.height}),col:Dr(h.colAxis,(O-G.left)/Q,{scroll:Math.max(0,J.x),frozenSize:re.width,trailingSize:re.trailingWidth,extent:te.width})},h.rowAxis.count,h.colAxis.count)},[]),D=i.useCallback(O=>{N.current=O,y.current===null&&(y.current=requestAnimationFrame(()=>{y.current=null;const u=N.current;z(u===null?null:"cell"in u?u.cell:W(u.clientX,u.clientY))}))},[z,W]),m=i.useCallback(O=>D({cell:O}),[D]),f=i.useCallback(()=>$(),[$]),C=i.useCallback(O=>{if(l.current===null)return;const u=t.current;l.current=null,r(null),X({interactive:null}),(O===void 0||O.restoreFocus)&&u.focusSink({preventScroll:!0}),u.isEditing()||u.rearmSink()},[X]),v=i.useCallback(O=>{l.current=O.kind,r(O),X({interactive:O.cell})},[X]),A=i.useCallback(O=>{const u=t.current;return Ea(u.adapter)?{cellReadOnly:Je(u.adapter,O.row,O.col)}:{}},[]),R=i.useCallback((O,u)=>{const h=t.current;if(Je(h.adapter,O.cell.row,O.cell.col)){h.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...O,...A(O.cell)});return}if(h.commitEdits(u,{source:"annotate"})===null){v({...O,rejected:!0});return}C()},[v,C,A]),j=i.useCallback((O,u)=>{const h=t.current;if(!wr(h.adapter,h.popovers,O))throw new RangeError(`[spreadsheet] openPopover("${O}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const k=h.getActive();if(O==="list"&&Je(h.adapter,k.row,k.col)){h.rejectReadOnly({kind:"edit",cell:k,editSession:"none"});return}if(O==="note-tip"){I(k);return}if(O==="message"){if(l.current!==null&&l.current!=="message")return;const J=u!==void 0&&u.message!==void 0?u.message:void 0,re=h.adapter.getCellValidation===void 0?void 0:h.adapter.getCellValidation(k.row,k.col),te=J!==void 0?J:re===void 0?void 0:re.inputMessage;if(te===void 0)return;const ue=u!==void 0&&u.rejected===!0;v({kind:"message",cell:k,anchorRect:q(k),current:{title:_e(h.labels,"messageTitle"),message:te,rejected:ue},close:C});return}if(h.isEditing()&&!h.requestCommit())return;if(O==="list"){const J=h.adapter.getCellValidation===void 0?void 0:h.adapter.getCellValidation(k.row,k.col);if(J===void 0||J.type!=="list")return;const re=u!==void 0&&u.typed!==void 0?u.typed:"";$(),h.focusSink({preventScroll:!0}),v({kind:"list",cell:k,anchorRect:q(k),current:J.values,typed:re,commit:te=>{if(Je(t.current.adapter,k.row,k.col)){t.current.rejectReadOnly({kind:"edit",cell:k,editSession:"none"}),C();return}t.current.commitEdits([{row:k.row,col:k.col,text:te}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if($(),h.focusSink({preventScroll:!0}),O==="note"){const J=h.adapter.getCellNote===void 0?void 0:h.adapter.getCellNote(k.row,k.col),re={kind:"note",cell:k,anchorRect:q(k),current:J,commit:te=>{R(re,[{row:k.row,col:k.col,note:te}])},close:C,rejected:!1,...A(k)};v(re);return}if(O==="comment"){const J=h.adapter.getCellComments===void 0?void 0:h.adapter.getCellComments(k.row,k.col),re={kind:"comment",cell:k,anchorRect:q(k),current:J===void 0?[]:J,commit:te=>{R(re,[{row:k.row,col:k.col,comments:te}])},close:C,rejected:!1,...A(k)};v(re);return}const Y=h.adapter.getCellHyperlink===void 0?void 0:Jn(h.adapter.getCellHyperlink(k.row,k.col)),G=h.adapter.getCellText(k.row,k.col),Q={kind:"link",cell:k,anchorRect:q(k),current:{text:G,url:Y},commit:J=>{const re=J.url===null?null:fn(J.url);if(re===null&&J.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(J.url)}`);const te=J.text===G?{row:k.row,col:k.col,hyperlink:re}:{row:k.row,col:k.col,text:J.text,hyperlink:re};R(Q,[te])},close:C,canOpen:h.onHyperlinkOpen!==void 0,open:()=>{const J=t.current.onHyperlinkOpen;J!==void 0&&Y!==void 0&&J(Y,k)},rejected:!1,...A(k)};v(Q)},[q,C,R,$,v,I,A]),{enabled:b,bodyRef:E}=e;i.useEffect(()=>{const O=E.current;if(!b||O===null)return;const u=k=>{const Y=t.current;wr(Y.adapter,Y.popovers,"note-tip")&&D({clientX:k.clientX,clientY:k.clientY})},h=()=>{wr(t.current.adapter,t.current.popovers,"note-tip")&&D({cell:null})};return O.addEventListener("pointermove",u),O.addEventListener("pointerleave",h),()=>{O.removeEventListener("pointermove",u),O.removeEventListener("pointerleave",h)}},[b,E,D]),i.useEffect(()=>()=>{y.current!==null&&cancelAnimationFrame(y.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:B,popovers:d}=e,L=i.useMemo(()=>o0.some(O=>wr(B,d,O)),[B,d]);return i.useMemo(()=>({layerEnabled:L,isKindEnabled:O=>wr(t.current.adapter,t.current.popovers,O),open:j,close:C,isOpen:()=>l.current,onCellHover:m,hideTip:f,onTipPointerEnter:()=>{p.current=!0,K()},onTipPointerLeave:()=>{p.current=!1,c.current!==null&&P()},syncTipAriaDescribedBy:T,context:n,tipContext:o,registerCompositionEnd:O=>{F.current=O},isCompositionKey:O=>wu(O,F.current),getLayerSize:()=>{const O=t.current.handleRef.current;return O===null?{width:0,height:0}:O.getViewportSize()},tipId:M}),[L,j,C,m,f,K,P,T,n,o,M])},i0=(e,t,n)=>{let r=null,o=0;if(typeof document.caretPositionFromPoint=="function"){const l=document.caretPositionFromPoint(e,t);if(l===null)return;r=l.offsetNode,o=l.offset}else if(typeof document.caretRangeFromPoint=="function"){const l=document.caretRangeFromPoint(e,t);if(l===null)return;r=l.startContainer,o=l.startOffset}else return;if(r===null||r.nodeType!==Node.TEXT_NODE)return;const s=r.parentElement?.closest("[data-aqsp-cell]")??null;if(!(s===null||Number(s.getAttribute("data-row"))!==n.row||Number(s.getAttribute("data-col"))!==n.col))return o},bu=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const p=e.getFrozenSize(),g=e.getViewportSize();return pn({row:zr(n,(l-t.top)/o,{scroll:a,frozenSize:p.height,trailingSize:p.trailingHeight,extent:g.height}),col:Dr(r,(s-t.left)/o,{scroll:c,frozenSize:p.width,trailingSize:p.trailingWidth,extent:g.width})},n.count,r.count)},c0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),a=i.useRef(0),p=i.useRef(null),g=i.useRef(!1),y=i.useRef(null),N=i.useRef(""),F=i.useRef(!1),M=i.useRef(!1),q=i.useCallback((D,m)=>{const{handleRef:f,rowAxis:C,colAxis:v,zoomRef:A}=t.current;return bu(f.current,o.current,C,v,A.current,D,m)},[]),X=i.useRef(!1),K=i.useRef(null),T=i.useRef(null),$=i.useRef({clientX:0,clientY:0}),P=i.useCallback(()=>{const{autoScroller:D,bodyRef:m,onDragFrame:f}=t.current;n.current=!1,r.current=null,p.current=null,X.current=!1,K.current=null,T.current=null,g.current=!1,y.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),D.stop();const C=m.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,f(null),t.current.repaintOverlay()},[]),I=i.useCallback(()=>{if(!n.current)return;const D=r.current;D!==null&&t.current.setSelection(D),P()},[P]),{enabled:z,bodyRef:W}=e;return i.useEffect(()=>{const D=W.current;if(!z||D===null)return;const m=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,f=d=>{const L=t.current;if(d.pointerType==="mouse"&&d.button===0&&(g.current=!1,y.current=null,M.current=!1),F.current=m(d.target),!F.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(L.getPointing?.()){L.focusSink();return}if(L.isEditing()&&!L.requestCommit()){d.stopPropagation(),L.focusSink();return}L.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((L.pointDragRef===void 0?null:L.pointDragRef.current)?.onPointerDown(d))return;if(L.isEditing()&&!L.requestCommit()){d.preventDefault(),L.focusSink();return}o.current=D.getBoundingClientRect();const u=q(d.clientX,d.clientY);if(u===null)return;if(d.preventDefault(),L.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&L.openHyperlinkAt?.(u)===!0){M.current=!0;return}const h=L.getSelection();r.current=h;const k=d.shiftKey,Y=d.ctrlKey||d.metaKey,G=Y&&!k&&h.ranges.some(J=>Pt(J,u));g.current=G,y.current=G?u:null,G||L.setSelection(Ar(h,u,{extend:k,append:Y})),n.current=!0,L.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,a.current=d.buttons;try{D.setPointerCapture(d.pointerId)}catch{c.current=null}const Q=G?u:L.getSelection().anchor;p.current=J=>me(Q,J),K.current=Q.col,T.current=Q.row,L.autoScroller.stop(),X.current=!1,$.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",v=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!X.current&&p.current!==null){const L=Math.abs(d.clientX-$.current.clientX),O=Math.abs(d.clientY-$.current.clientY);Math.max(L,O)>=bo&&(X.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:p.current,anchorCol:K.current??void 0,anchorRow:T.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const L=p.current;if(!n.current||L===null)return;const O=t.current,u=q(s.current.clientX,s.current.clientY);u!==null&&O.onDragFrame(L(u))}))}},A=d=>{v(d),n.current&&C(d)&&(a.current&1)!==0&&(d.buttons&1)===0&&j(d)},R=d=>{d.button!==0||!(n.current&&C(d))||j(d)},j=d=>{const L=t.current,O=q(d.clientX,d.clientY);if(O!==null){const u=y.current;g.current&&u!==null?L.setSelection(mu(L.getSelection(),me(u,O),u)):L.setSelection(Rn(L.getSelection(),O))}P()},b=d=>{!n.current||c.current===null||d.pointerId!==c.current||I()},E=d=>{const L=t.current;if(!m(d.target)||N.current!=="mouse"||L.isAnyDragging())return;if(L.isEditing()&&!L.requestCommit()){L.focusSink();return}L.focusSink(),o.current=D.getBoundingClientRect();const O=q(d.clientX,d.clientY);if(O===null)return;const u=L.getSelection();u.ranges.some(k=>Pt(k,O))||L.setSelection(Ar(u,O,{extend:!1,append:!1})),L.onContextMenuSelect(O,d)},B=d=>{const L=t.current;if(!F.current||N.current!=="mouse"||L.getPointing?.()||M.current)return;o.current=D.getBoundingClientRect();const O=q(d.clientX,d.clientY);O!==null&&Xt(L.getSelection().active,O)&&L.onRequestEdit(O,L.caretFromPointEnabled(O)?i0(d.clientX,d.clientY,O):void 0)};return D.addEventListener("pointerdown",f),D.addEventListener("pointermove",A),D.addEventListener("pointerup",R),D.addEventListener("lostpointercapture",b),D.addEventListener("contextmenu",E),D.addEventListener("dblclick",B),()=>{D.removeEventListener("pointerdown",f),D.removeEventListener("pointermove",A),D.removeEventListener("pointerup",R),D.removeEventListener("lostpointercapture",b),D.removeEventListener("contextmenu",E),D.removeEventListener("dblclick",B),P()}},[z,W,q,P,I]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:I,cancelDrag:P}),[I,P])},a0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),p=i.useRef(0),g=i.useRef(null),y=i.useRef(null),N=i.useRef(!1),F=i.useCallback(($,P)=>{const{handleRef:I,rowAxis:z,colAxis:W,zoomRef:D}=t.current;return bu(I.current,o.current,z,W,D.current,$,P)},[]),M=i.useCallback(()=>{const{autoScroller:$,bodyRef:P,onDragFrame:I}=t.current;n.current=!1,r.current=null,g.current=null,y.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),$.stop();const z=P.current;z!==null&&a.current!==null&&z.hasPointerCapture?.(a.current)&&z.releasePointerCapture(a.current),a.current=null,I(null)},[]),q=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.restoreSink($),M()},[M]),X=i.useCallback($=>{const P=t.current,I=P.bodyRef.current;if(!P.enabled||I===null||!P.getPointing())return!1;o.current=I.getBoundingClientRect();const z=F($.clientX,$.clientY);if(z===null)return o.current=null,!1;const W=P.captureSink();if(W===null)return o.current=null,!1;$.preventDefault(),P.focusSink(),r.current=W,y.current=z,P.insertReference(z,"cells"),n.current=!0,s.current={clientX:$.clientX,clientY:$.clientY},l.current={clientX:$.clientX,clientY:$.clientY},a.current=$.pointerId,p.current=$.buttons;try{I.setPointerCapture($.pointerId)}catch{a.current=null}return g.current=D=>{const m=me(z,D);return t.current.insertReference(m,"cells"),m},P.autoScroller.stop(),N.current=!1,P.onDragFrame(me(z,z)),!0},[F]),{enabled:K,bodyRef:T}=e;return i.useEffect(()=>{const $=T.current;if(!K||$===null)return;const P=D=>a.current!==null?D.pointerId===a.current:D.pointerType==="mouse",I=D=>{if(!(n.current&&P(D)))return;s.current={clientX:D.clientX,clientY:D.clientY};const m=g.current,f=y.current;if(!N.current&&m!==null&&f!==null){const C=Math.abs(D.clientX-l.current.clientX),v=Math.abs(D.clientY-l.current.clientY);Math.max(C,v)>=bo&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m,anchorCol:f.col,anchorRow:f.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=g.current;if(!n.current||C===null)return;const v=F(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(p.current&1)!==0&&(D.buttons&1)===0&&M()},z=D=>{D.button!==0||!(n.current&&P(D))||M()},W=D=>{!n.current||a.current===null||D.pointerId!==a.current||M()};return $.addEventListener("pointermove",I),$.addEventListener("pointerup",z),$.addEventListener("lostpointercapture",W),()=>{$.removeEventListener("pointermove",I),$.removeEventListener("pointerup",z),$.removeEventListener("lostpointercapture",W),M()}},[K,T,F,M]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:q,cancelDrag:M,onPointerDown:X}),[q,M,X])},u0=Object.freeze({width:0,height:0}),ms=33,d0=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,f0=(e,t,n)=>{const r=(n-t)/(ms-1);let o=-1,s=-1;for(let c=0;c<ms;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,a)=>{let p=c,g=a;for(;Math.abs(g-p)>1;){const y=(p+g)/2;e(y)?g=y:p=y}return g};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===ms-1?n:l(t+r*(s+1),t+r*s)}},p0=e=>{if(e===void 0)return!1;if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the options must be an object (got ${String(e)})`);const{scroll:t}=e;if(t!==void 0&&t!==!0&&t!==!1)throw new RangeError(`[spreadsheet] setSelection: options.scroll must be true, false or absent (got ${String(t)})`);return t===!0},h0=(e,t)=>{if(!Number.isInteger(e)||e<0||e>0&&e>t)throw new RangeError(`[spreadsheet] headerRows must be a whole number from 0 to frozenRows = ${t} (got ${e})`)},m0=e=>{if(e!==void 0&&(typeof e!="string"||e===""||/\s/u.test(e)))throw new RangeError(`[spreadsheet] labelledBy must be one non-empty id without whitespace (got ${JSON.stringify(e)})`)},g0=e=>{if(e===void 0)return;if(![e.startRow,e.startCol,e.endRow,e.endCol].every(n=>Number.isInteger(n)&&n>=0)||e.startRow>e.endRow||e.startCol>e.endCol)throw new RangeError(`[spreadsheet] frame must hold non-negative integer bounds with each start at most its end (got startRow ${String(e.startRow)}, startCol ${String(e.startCol)}, endRow ${String(e.endRow)}, endCol ${String(e.endCol)})`)},w0=Object.freeze({showArrowButtons:!0,enableThumbDrag:!0,enableTrackClick:!0}),C0=e=>{if(e!==void 0){if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] scrollBarControls must be an object or absent (got ${typeof e=="string"?JSON.stringify(e):String(e)})`);for(const t of Object.keys(w0)){const n=e[t];if(n!==void 0&&typeof n!="boolean")throw new RangeError(`[spreadsheet] scrollBarControls.${t} must be true, false or absent (got ${typeof n=="string"?JSON.stringify(n):String(n)})`)}}},bc=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${typeof t=="string"?JSON.stringify(t):String(t)})`);return t},b0=24,y0=200,yu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),yc=5,R0=/^#[0-9A-Fa-f]{6}$/,v0=Object.freeze({row:!1,column:!1,intersection:!1}),Rc=Object.freeze({ok:!0}),vc=(e,t)=>{if(t===void 0)return yu;if(t.length!==yc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${yc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!R0.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},S0=e=>{for(const t of["row","column","intersection"])if(nt(e[t])===null)throw new RangeError(`[spreadsheet] highlightColors.${t} is not a colour (got ${JSON.stringify(e[t])})`);if(!(Number.isFinite(e.opacity)&&e.opacity>=0&&e.opacity<=1))throw new RangeError(`[spreadsheet] highlightColors.opacity must be a number in [0, 1] (got ${e.opacity})`);return e},k0=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Ka},E0=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},O0=e=>{const t=i.useRef(null),n=t.current;return n!==null&&rt.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},qn={ranges:[me({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},A0=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=b0,defaultColumnWidth:l=ze.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:a=0,frozenTrailingColumns:p=0,frozenTrailingRows:g=0,tapScrollCircleOptions:y,scrollBarControls:N,overscanRows:F,overscanCols:M,background:q,onRenderTruncated:X,renderCell:K,onSelectionChange:T,onEditSessionChange:$,onCellContextMenu:P,onUndoRequest:I,onRedoRequest:z,onCopyMultiRange:W,onOperationRejected:D,onEditRejected:m,onReadOnlyRejected:f,formatReadOnlyAnnouncement:C,dataVersion:v,maxOperationCells:A=ze.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:R=!0,enableResizeUI:j=!0,headings:b=!0,onContentSizeChange:E,frame:B,formatCellAnnouncement:d,formatSelectionAnnouncement:L,formatCommandAnnouncement:O,formatResizeAnnouncement:u,locale:h,labels:k,shortcuts:Y,onCommandBlockedWhileEditing:G,colors:Q,formats:J,highlight:re,defaultHighlight:te,onHighlightChange:ue,highlightColors:ae,popovers:Ae,renderPopover:$e,onClipChange:Ne,onHyperlinkOpen:Fe,onValidationRejected:Tt,onPasteSpecialRequest:Ce,onClipboardUnavailable:We,onPasteResolved:ot,now:$t=Date.now,zoom:ut,defaultZoom:Zt,onZoomChange:Qe,testId:Ct,className:_t,__onCellRender:Mr,__onVirtualKeyboardRaise:Qn,__maxRenderedCells:Oo},En){const le=i.useMemo(()=>r?Nh(t):t,[t,r]),be=cc(le.rowCount,s),ge=cc(le.colCount,l),Jt=i.useRef(null);Jt.current===null&&(Jt.current=Kw());const De=Jt.current,On=rt.resolveVirtualScrollLocale(h),bt=i.useMemo(()=>Na(h,k),[h,k]),Nr=O0(dm(bt)),qt=i.useMemo(()=>rm(Y),[Y]),Qt=i.useMemo(()=>{if(!j)return;const H=[...qt].filter(([,Z])=>ss.includes(Z)).sort(([,Z],[,ne])=>ss.indexOf(Z)-ss.indexOf(ne)).map(([Z])=>Zh(Z)).filter(Z=>Z!==null);return H.length===0?void 0:H.join(" ")},[qt,j]),An=i.useMemo(()=>({fill:vc("fill",Q===void 0?void 0:Q.fill),font:vc("font",Q===void 0?void 0:Q.font)}),[Q]),xn=i.useMemo(()=>ae===void 0?void 0:S0(ae),[ae]);if(le.getConditionalFormats!==void 0&&le.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");h0(n,a),m0(o),g0(B),C0(N);const hn=i.useCallback(()=>De.get().editVersion,[De]),er=i.useCallback(w=>De.subscribeCoalesced(w),[De]),tr=i.useSyncExternalStore(er,hn,hn)+(v===void 0?0:v),nr=le.getConditionalFormats===void 0?null:le.getConditionalFormats(),Tn=i.useMemo(()=>({index:nr===null?null:du(nr),memo:Js()}),[le,nr,tr]),rr=i.useRef(Tn.index);rr.current=Tn.index;const or=i.useRef(Tn.memo);or.current=Tn.memo;const en=i.useCallback((w,H,Z)=>Qs(le,rr.current,or.current,w,H,Z),[le]),He=i.useRef(null),[xo,To]=i.useState(()=>ze.clampSpreadsheetZoom(Zt??1)),S=ze.clampSpreadsheetZoom(ut??xo),x=i.useRef(S);x.current=S;const V=i.useRef(S);V.current=S;const _=i.useRef(null),ee=i.useRef(Qe);ee.current=Qe;const se=i.useRef(ut!==void 0);se.current=ut!==void 0;const ce=i.useCallback(w=>{const H=ze.clampSpreadsheetZoom(w);H!==V.current&&(V.current=H,se.current||To(H),ee.current?.(H))},[]),pe=le.rowCount===0||le.colCount===0,xe=!pe;i.useEffect(()=>{const w=He.current;if(!xe||w===null)return;const H=ne=>{ne.defaultPrevented||!ne.altKey||ne.ctrlKey||ne.metaKey||ne.shiftKey||ne.deltaY!==0&&(ne.preventDefault(),ne.stopPropagation(),!_.current?.()&&ce(ze.stepSpreadsheetZoom(V.current,ne.deltaY<0?1:-1)))},Z=ne=>{if(ne.defaultPrevented||!(ne.ctrlKey&&ne.altKey)||ne.metaKey||ne.getModifierState("AltGraph"))return;const we=ne.key==="="||ne.key==="+"?ze.stepSpreadsheetZoom(V.current,1):ne.key==="-"?ze.stepSpreadsheetZoom(V.current,-1):ne.key==="0"?1:null;we!==null&&(ne.preventDefault(),ne.stopPropagation(),!_.current?.()&&ce(we))};return w.addEventListener("wheel",H,{passive:!1,capture:!0}),w.addEventListener("keydown",Z,!0),()=>{w.removeEventListener("wheel",H,{capture:!0}),w.removeEventListener("keydown",Z,!0)}},[ce,xe]);const he=i.useRef(null),Ie=i.useRef(null),Be=i.useRef(null),qe=i.useRef(null),oe=i.useRef(null),ie=i.useRef(null),ve=i.useRef(null),Se=i.useRef(0),ye=i.useRef(null),st=i.useRef(0),de=i.useRef(null),Te=i.useRef(null),et=i.useRef(null),Ue=i.useRef(null),Xe=i.useRef(null),Oe=i.useRef(null),dt=i.useRef(null),[ft,yt]=i.useState(qn),Pe=i.useRef(ft),Ge=i.useCallback(()=>Pe.current,[]),[$o,Lo]=i.useState(()=>te===void 0?v0:te),$n=re!==void 0?re:$o,Do=i.useRef($n);Do.current=$n;const Ru=k0(xn,$n),tl=i.useRef(re!==void 0);tl.current=re!==void 0;const nl=i.useRef(ue);nl.current=ue;const vu=i.useCallback(w=>{tl.current||Lo(w),nl.current?.(w)},[]),rl=i.useRef(null),zo=i.useRef(null),jt=i.useRef(null),Mo=i.useRef(()=>!1),ol=i.useRef(()=>{}),sl=i.useRef(()=>null),ll=i.useRef(()=>{}),mn=i.useCallback(()=>Mo.current(),[]),No=i.useMemo(()=>({getPointing:()=>Mo.current(),insertReference:(w,H)=>ol.current(w,H)}),[]),il=i.useRef(Vt),cl=i.useRef(null),Fo=i.useRef({interactive:null,tip:null}),al=i.useRef(null),ul=i.useRef(null),Fr=i.useRef(()=>{}),dl=i.useRef(()=>!1),tn=i.useRef(null),sr=i.useCallback(()=>{const w=tn.current;if(w===null||w.isOpen()!=="message")return!1;const H=w.context;return H===null||H.kind!=="message"||!H.current.rejected?!1:(w.close(),!0)},[]),Po=i.useRef(()=>!1),fl=i.useRef(()=>!1),pl=i.useRef(null),_o=i.useRef(()=>Promise.resolve("rejected")),Le=i.useCallback(()=>{rl.current?.()},[]),It=i.useCallback(w=>{ie.current?.focus(w)},[]),Ve=i.useCallback(()=>{It({preventScroll:!0})},[It]),qo=i.useRef(!1),Su=i.useCallback(()=>{const w=He.current;if(w!==null){qo.current=!0;try{w.focus()}finally{qo.current=!1}}},[]),lt=i.useCallback(()=>{const w=ie.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),Ln=i.useCallback((w,H)=>{if(w===null)return;const Z=H?"":"none";w.style.display!==Z&&(w.style.display=Z)},[]),Rt=i.useCallback(()=>{const w=ve.current;if(w!==null){const Z=Math.max(0,oe.current?.getScrollPosition().y??0),ne=oe.current?.getFrozenSize().height??0;w.style.transform=`translateY(${Se.current-Z-ne}px)`}const H=oe.current;if(H!==null&&(Xe.current!==null||Oe.current!==null)){const Z=H.getFrozenSize();Ln(Xe.current,Z.height>0),Ln(Oe.current,Z.trailingHeight>0)}},[Ln]),vt=i.useCallback(()=>{const w=ye.current;if(w!==null){const Z=Math.max(0,oe.current?.getScrollPosition().x??0),ne=oe.current?.getFrozenSize().width??0;w.style.transform=`translateX(${st.current-Z-ne}px)`}const H=oe.current;if(H!==null&&(et.current!==null||Ue.current!==null)){const Z=H.getFrozenSize();Ln(et.current,Z.width>0),Ln(Ue.current,Z.trailingWidth>0)}},[Ln]),lr=i.useRef(null),Dn=i.useCallback(()=>{et.current===null&&Ue.current===null&&Xe.current===null&&Oe.current===null||lr.current===null&&(lr.current=requestAnimationFrame(()=>{lr.current=null,Rt(),vt(),Le()}))},[Rt,vt,Le]);i.useEffect(()=>()=>{lr.current!==null&&cancelAnimationFrame(lr.current)},[]);const jo=i.useRef(null),Io=i.useRef(null);(jo.current===null||Io.current?.rowAxis!==be||Io.current?.colAxis!==ge)&&(Io.current={rowAxis:be,colAxis:ge},jo.current=jw({handleRef:oe,rowAxis:be,colAxis:ge}));const Pr=i.useCallback(w=>{const H=oe.current,Z=H===null?{x:0,y:0}:H.getScrollPosition(),ne=H===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:H.getFrozenSize(),we=H===null?{width:0,height:0}:H.getViewportSize(),ke=x.current;return{top:kn(be,w.row,{scroll:Math.max(0,Z.y),frozenCount:ne.rows,trailingCount:ne.trailingRows,extent:we.height})*ke,left:Sn(ge,w.col,{scroll:Math.max(0,Z.x),frozenCount:ne.cols,trailingCount:ne.trailingCols,extent:we.width})*ke,width:ge.sizeOf(w.col)*ke,height:be.sizeOf(w.row)*ke}},[be,ge]),hl=i.useCallback(w=>{const H=qe.current,Z=He.current,ne=Ie.current;if(H===null||Z===null||ne===null||oe.current===null)return;const we=x.current,ke=Pr(w),Ze=ne.offsetTop*we+ke.top,at=ne.offsetLeft*we+ke.left,Ke=Math.max(0,Ze),Nt=Math.max(0,at),on=Math.min(Z.clientHeight,Ze+ke.height),Ir=Math.min(Z.clientWidth,at+ke.width);if(on<=Ke||Ir<=Nt)return;H.style.top=`${Ke}px`,H.style.left=`${Nt}px`,H.style.width=`${Ir-Nt}px`,H.style.height=`${on-Ke}px`;const Fn=H.getBoundingClientRect();Fn.width===0&&Fn.height===0||H.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Pr]),Lt=i.useCallback(w=>{jo.current?.(w),hl(w)},[hl]),ku=i.useCallback(()=>{const w=oe.current,H=w===null?-1:w.getViewportSize().height,Z=he.current,ne=He.current;if(H<=0||Z===null||ne===null)return H;const we=Z.getBoundingClientRect(),ke=ne.getRootNode();if(we.height<=0||Z.offsetHeight<=0||!d0(ke))return H;const Ze=ne.ownerDocument.documentElement,at=Math.max(we.left,0),Ke=Math.min(we.right,Ze.clientWidth),Nt=Math.max(we.top,0)+.5,on=Math.min(we.bottom,Ze.clientHeight)-.5,Ir=(at+Ke)/2,Fn=Ke>at&&on>=Nt?f0(ed=>{const Kl=ke.elementFromPoint(Ir,ed);return Kl!==null&&ne.contains(Kl)},Nt,on):null,Qu=Fn===null?Ze.clientHeight:Fn.bottom-Fn.top+1;return Math.min(H,Qu*(Z.offsetHeight/we.height))},[]),ml=i.useRef(E);ml.current=E;const Ho=i.useRef(null),Ht=i.useCallback(()=>{const w=ml.current;if(w===void 0)return;const H=Ie.current;let Z;if(H===null)Z=u0;else{if(H.getClientRects().length===0)return;{const we=Be.current,ke=x.current;Z={width:((we===null?0:we.offsetWidth)+ge.totalSize()+ze.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke,height:((we===null?0:we.offsetHeight)+be.totalSize()+ze.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke}}}const ne=Ho.current;ne!==null&&ne.width===Z.width&&ne.height===Z.height||(Ho.current=Z,w(Z))},[be,ge]);i.useLayoutEffect(()=>{if(E===void 0){Ho.current=null;return}Ht()});const gl=E!==void 0;i.useEffect(()=>{const w=Ie.current;if(!gl||w===null)return;const H=new ResizeObserver(()=>Ht());return H.observe(w),()=>H.disconnect()},[gl,Ht,pe]);const zn=i.useRef(null),gn=i.useRef(null),Mn=i.useCallback(w=>{zn.current!==null&&window.clearTimeout(zn.current),gn.current!==null&&(cancelAnimationFrame(gn.current),gn.current=null),zn.current=window.setTimeout(()=>{zn.current=null;const H=dt.current;H!==null&&(H.textContent="",gn.current=requestAnimationFrame(()=>{gn.current=null,H.textContent=w}))},y0)},[]);i.useEffect(()=>()=>{zn.current!==null&&window.clearTimeout(zn.current),gn.current!==null&&cancelAnimationFrame(gn.current)},[]);const Nn=i.useCallback(w=>{f?.(w),C!==void 0&&Mn(C(w))},[f,C,Mn]),wl=i.useCallback((w,H)=>{if(d===void 0&&L===void 0)return;const Z=H.ranges[H.ranges.length-1],ne=wt(Z),we=H.ranges.length===1&&ne.rows===1&&ne.cols===1,ke=w.ranges[w.ranges.length-1],Ze=w.ranges.length!==H.ranges.length||ke.startRow!==Z.startRow||ke.startCol!==Z.startCol||ke.endRow!==Z.endRow||ke.endCol!==Z.endCol,at=()=>{if(d!==void 0){const Ke=H.active,Nt=le.getCellText(Ke.row,Ke.col),on=le.getCellFormat===void 0?void 0:en(Ke.row,Ke.col,()=>Nt);Mn(d({row:Ke.row,col:Ke.col,text:Nt,displayText:Xn(Nt,on===void 0?void 0:on.value),columnName:ze.columnIndexToName(Ke.col),...Ea(le)?{readOnly:Je(le,Ke.row,Ke.col)}:{}}))}};if(we){at();return}if(Ze){L!==void 0&&Mn(L({range:Z,anchor:H.anchor,active:H.active,rangeRowCount:ne.rows,rangeColCount:ne.cols,rangeCount:H.ranges.length}));return}at()},[le,d,L,Mn,en]),nn=i.useCallback((w,H)=>{const Z=Pe.current;Object.is(w,Z)||Mw(w,Z)||(Pe.current=w,yt(w),T?.(w,H),wl(Z,w),(jt.current?.()??!1)||lt())},[T,wl,lt]),St=i.useCallback(w=>nn(w,"user"),[nn]),Eu=i.useCallback(w=>{const H=Pe.current;if(w.mode==="cycle"){const ne=gu(H,w.direction);St(ne),Lt(ne.active);return}const Z=pn(w.cell,be.count,ge.count);if(w.mode==="extend"){St(Rn(H,Z)),Lt(Z);return}St(Ar(H,Z,{extend:!1,append:!1})),Lt(Z)},[St,Lt,be,ge]),Ye=i.useCallback(()=>jt.current?.()??!1,[]),Cl=i.useRef(null),it=i.useCallback(()=>Cl.current?.()??!0,[]),bl=i.useRef(null),ir=i.useCallback((w,H)=>{const Z=jt.current?.()??!1;bl.current?.(w,H),!Z&&(jt.current?.()??!1)&&sr()},[sr]),[Ou,Bo]=i.useState(!1),yl=i.useCallback(()=>{Qn?.(),Bo(!0)},[Qn]),Au=i.useCallback((w,H)=>{Je(le,w.row,w.col)||yl(),ir("edit",H)},[le,yl,ir]),Rl=i.useRef(null),_r=i.useCallback(()=>Rl.current?.()??null,[]),vl=i.useRef(null),Dt=i.useCallback(()=>{vl.current?.()},[]),Sl=i.useRef(null),kl=i.useCallback(w=>{Sl.current?.(w)},[]),El=i.useRef(()=>{}),qr=i.useRef(0),wn=i.useCallback((w,H,Z)=>{let ne;if(H.source==="paste"){const we=E0(Z);if(w.length===0&&we.conditionalFormats.length===0)return null;qr.current+=1,ne={transaction:qr.current,source:"paste",sameSheet:we.sameSheet,conditionalFormats:we.conditionalFormats}}else{if(w.length===0)return null;qr.current+=1,ne={transaction:qr.current,source:H.source}}try{le.applyEdits(w,ne)}catch(we){return m?.(we,H),null}return De.bumpEdit(),kl(H.source),ne.transaction},[le,De,m,kl]),xu=i.useCallback((w,H)=>wn(w,{source:"paste"},H),[wn]),Tu=i.useCallback(w=>{De.setVy(w.y),Rt(),vt(),Le()},[De,Rt,vt,Le]),Ol=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),$u=i.useCallback(w=>{De.setRowRange(w.renderingRowStart,w.renderingRowEnd),De.setColRange(w.renderingColStart,w.renderingColEnd);const H=Ol.current;(H.rowStart!==w.renderingRowStart||H.rowEnd!==w.renderingRowEnd||H.colStart!==w.renderingColStart||H.colEnd!==w.renderingColEnd)&&(Ol.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},Le())},[De,Le]),Al=i.useRef(()=>"add"),rn=i.useCallback(w=>{zo.current?.(w,Al.current())},[]),Lu=i.useCallback(w=>{zo.current?.(w,"point")},[]),xl=i.useRef(null),Wo=i.useCallback(w=>{xl.current?.(w)},[]),Tl=i.useRef(null),Du=i.useCallback(w=>{Tl.current?.(w)},[]),$l=i.useRef(null),Ll=i.useCallback((w,H)=>{if(H.length===0)return;const Z=oe.current;if(w==="col"){for(const ne of H){const we=Math.round(ne.size);ge.resize(ne.index,we),Z?.updateColSize(ne.index,we)}De.bumpColVersion(),vt(),Le(),Dn(),Ht();return}for(const ne of H){const we=Math.round(ne.size);be.resize(ne.index,we),Z?.updateRowSize(ne.index,we)}De.bumpRowGeometry(),Rt(),Le(),Dn(),Ht()},[be,ge,De,vt,Rt,Le,Dn,Ht]),Dl=j?Ll:void 0,zu=i.useCallback((w,H)=>{P?.(w,{kind:"pointer",event:H})},[P]),Mu=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:rn,axis:"both",zoomRef:x}),Nu=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:rn,axis:"x",zoomRef:x}),Fu=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:rn,axis:"y",zoomRef:x}),Pu=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:Wo,axis:"x",zoomRef:x}),_u=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:Wo,axis:"y",zoomRef:x}),qu=_n({handleRef:oe,rowAxis:be,colAxis:ge,bodyRef:he,onDragFrame:rn,axis:"both",zoomRef:x}),zl=i.useRef(null),Ml=i.useRef(()=>!1),cr=i.useCallback(()=>Ml.current(),[]),kt=c0({zoomRef:x,enabled:!pe,rowAxis:be,colAxis:ge,handleRef:oe,bodyRef:he,isEditing:Ye,requestCommit:it,getSelection:Ge,setSelection:St,focusSink:Ve,onDragFrame:rn,onContextMenuSelect:zu,onRequestEdit:Au,caretFromPointEnabled:w=>{if(K!==void 0||le.getCellFormula!==void 0&&le.getCellFormula(w.row,w.col)!==void 0)return!1;if(le.getCellFormat===void 0)return!0;const H=le.getCellText(w.row,w.col);return Xn(H,le.getCellFormat(w.row,w.col)?.value)===H},isAnyDragging:cr,autoScroller:Mu,repaintOverlay:Le,pointDragRef:zl,getPointing:mn,openHyperlinkAt:Fe===void 0||le.getCellHyperlink===void 0?void 0:w=>{const H=le.getCellHyperlink===void 0?void 0:Jn(le.getCellHyperlink(w.row,w.col));return H===void 0?!1:(Fe(H,w),!0)}}),zt=Cc({zoomRef:x,enabled:!pe&&b,axis:"col",headerRef:de,mainAxis:ge,crossCount:le.rowCount,handleRef:oe,isEditing:Ye,requestCommit:it,getSelection:Ge,setSelection:St,focusSink:Ve,onDragFrame:rn,autoScroller:Nu,repaintOverlay:Le,pointing:No}),Mt=Cc({zoomRef:x,enabled:!pe&&b,axis:"row",headerRef:Te,mainAxis:be,crossCount:le.colCount,handleRef:oe,isEditing:Ye,requestCommit:it,getSelection:Ge,setSelection:St,focusSink:Ve,onDragFrame:rn,autoScroller:Fu,repaintOverlay:Le,pointing:No}),ct=zw({zoomRef:x,enabled:!pe&&j&&b,colBandRef:de,rowBandRef:Te,fontSourceRef:he,colAxis:ge,rowAxis:be,viewStore:De,handleRef:oe,isEditing:Ye,requestCommit:it,focusSink:Ve,getSelection:Ge,adapter:le,autofitEnabled:K===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:A,onOperationRejected:D,resizeTracks:Ll,writeResizeGuide:Du,repaintOverlay:Le,isPointing:mn}),Et=Gw({zoomRef:x,enabled:!pe&&R,handleNodeRef:$l,bodyRef:he,rowAxis:be,colAxis:ge,handleRef:oe,getSelection:Ge,setSelection:St,focusSink:Ve,adapter:le,commitEdits:wn,maxOperationCells:A,onOperationRejected:D,rejectReadOnly:Nn,writeFillPreview:Wo,repaintOverlay:Le,xAutoScroller:Pu,yAutoScroller:_u}),pt=a0({zoomRef:x,enabled:!pe,bodyRef:he,handleRef:oe,rowAxis:be,colAxis:ge,getPointing:mn,insertReference:No.insertReference,captureSink:()=>sl.current(),restoreSink:w=>ll.current(w),focusSink:Ve,autoScroller:qu,onDragFrame:rn});zl.current=pt;const ar=i.useCallback(()=>kt.isDragging()||zt.isDragging()||Mt.isDragging()||ct.isDragging()||Et.isDragging()||pt.isDragging(),[kt,zt,Mt,ct,Et,pt]);_.current=ar,Ml.current=ar,Al.current=()=>pt.isDragging()?"point":kt.getDragMode();const ju=i.useCallback(()=>{kt.abortDrag(),zt.abortDrag(),Mt.abortDrag(),ct.abortDrag(),Et.abortDrag(),pt.abortDrag()},[kt,zt,Mt,ct,Et,pt]),Vo=i.useCallback(()=>Pe.current.active,[]),Nl=i.useCallback((w,H)=>{const Z=le.getCellValidation===void 0?void 0:le.getCellValidation(w.row,w.col);if(Z===void 0)return Rc;const ne=le.evaluateFormula,we=_a(Z,H,On,ne===void 0?void 0:ke=>ne(ke,w));return we.ok||Z.strict!==!0?Rc:(Tt?.({cell:w,rule:Z,text:H,message:we.message}),tn.current?.isKindEnabled("message")&&Fr.current("message",{message:we.message,rejected:!0}),we)},[le,Tt,On]),je=Xg({enabled:!pe,sinkRef:ie,rootRef:He,adapter:le,commitEdits:wn,getActive:Vo,ensureCellVisible:Lt,focusSink:It,rearmSink:lt,discardClip:Dt,isDragging:cr,rejectReadOnly:Nn,resolveEditAlign:w=>{if(le.getCellFormat===void 0)return null;const H=ao(le,w.row,w.col);return ka(en(w.row,w.col,H),H)},resolveEditPaint:w=>le.getCellFormat===void 0?null:Lf(en(w.row,w.col,ao(le,w.row,w.col))),editPaintRef:il,repaintOverlay:Le,validateCommit:Nl,onSessionChange:$});jt.current=je.isEditing,Cl.current=je.requestCommit,bl.current=je.startEdit,Mo.current=je.getPointing,ol.current=je.insertReference,sl.current=je.captureSink,ll.current=je.restoreSink;const Fl=i.useCallback(()=>{je.cancelEdit(),sr()},[je.cancelEdit,sr]),ur=Tg({enabled:!pe,sinkRef:ie,adapter:le,isEditing:Ye,getSelection:Ge,setSelection:St,commitPaste:xu,maxOperationCells:A,onOperationRejected:D,onCopyMultiRange:W,repaintOverlay:Le,isDragging:cr,resize:{rowAxis:be,colAxis:ge,resizeTracks:Dl},pendingPasteOptionsRef:cl,formats:J,onClipChange:Ne,onClipboardUnavailable:We,onEditRejected:m,rejectReadOnly:Nn,onPasteResolved:ot});Rl.current=ur.getClip,vl.current=ur.discardClip,Sl.current=ur.discardClipOnCommit,El.current=ur.onAdapterSwitch,_o.current=ur.paste;const dr=l0({enabled:!pe,adapter:le,popovers:Ae,sinkRef:ie,bodyRef:he,handleRef:oe,rowAxis:be,colAxis:ge,zoomRef:x,getActive:Vo,isEditing:Ye,requestCommit:it,focusSink:It,rearmSink:lt,isDraggingAny:ar,commitEdits:wn,labels:bt,onHyperlinkOpen:Fe,anchors:Fo,repaintOverlay:Le,rejectReadOnly:Nn});tn.current=dr,Fr.current=dr.open,dl.current=dr.hideTip;const Iu=i.useCallback(()=>{const w=Pe.current.active;return Lt(w),Pr(w)},[Lt,Pr]),Yo=Yg({adapter:le,trackResize:j&&!pe?ct:void 0,getSelection:Ge,commitEdits:wn,getActive:Vo,isEditing:Ye,requestCommit:it,cancelEdit:Fl,getSessionText:je.getSessionText,validateCommit:Nl,insertAtCaret:je.insertAtCaret,refreshEditPaint:je.refreshPaint,maxOperationCells:A,onOperationRejected:D,colors:An,formats:J,getHighlight:()=>Do.current,setHighlight:vu,popovers:Ae,openPopover:w=>Fr.current(w),onHyperlinkOpen:Fe,onPasteSpecialRequest:Ce,paste:w=>_o.current(w),rowAxis:be,colAxis:ge,resizeTracks:Dl,defaultRowHeight:s,defaultColumnWidth:l,now:$t,announce:Mn,formatCommandAnnouncement:O,formatResizeAnnouncement:u,keyboardCellRect:Iu,rejectReadOnly:Nn});pl.current=Yo,Po.current=Yo.executeCommand,fl.current=Yo.isCommandAvailable;const Hu=i.useMemo(()=>({table:qt,execute:w=>Po.current(w),isAvailable:w=>fl.current(w)}),[qt]),Bu=i.useCallback(()=>{Dt(),I?.()},[Dt,I]),Wu=i.useCallback(()=>{Dt(),z?.()},[Dt,z]);Yw({zoomRef:x,enabled:!pe,sinkRef:ie,rootRef:He,handOffFocusToRoot:Su,getSelection:Ge,setSelection:St,moveActive:Eu,ensureCellVisible:Lt,pageExtent:ku,isEditing:Ye,requestCommit:it,startEdit:ir,commitEdits:wn,maxOperationCells:A,onOperationRejected:D,rejectReadOnly:Nn,getClip:_r,discardClip:Dt,isDragging:ar,abortDrag:ju,findDataEdge:le.findDataEdge,getEditingMode:je.getEditingMode,cancelEdit:Fl,onUndoRequest:Bu,onRedoRequest:Wu,onCellContextMenu:P,rowAxis:be,colAxis:ge,handleRef:oe,rearmSink:lt,commands:Hu,onCommandBlockedWhileEditing:G,pointing:je,adapter:le,hideNoteTip:()=>dl.current(),closeRejectedMessage:sr,pendingPasteOptionsRef:cl,onPointFrame:Lu});const Vu=ft.active.row,Yu=ft.active.col;i.useLayoutEffect(()=>{const w=tn.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[Vu,Yu]),i.useLayoutEffect(()=>{Le()},[Le,$n.row,$n.column,$n.intersection]),i.useLayoutEffect(()=>{Le()},[Le,B?.startRow,B?.startCol,B?.endRow,B?.endCol]);const Ku=i.useCallback(w=>{(jt.current?.()??!1)||(w.preventDefault(),Ve(),lt())},[Ve,lt]),Uu=i.useCallback(w=>{const H=He.current,Z=w.relatedTarget,ne=H!==null&&!H.matches(":focus-visible");if(H!==null&&Z instanceof Node&&H.contains(Z)){w.target===H&&Z===ie.current&&!qo.current&&It({preventScroll:ne});return}(jt.current?.()??!1)||(It({preventScroll:ne}),lt())},[It,lt]),Xu=i.useCallback(w=>{const H=He.current,Z=w.relatedTarget;H!==null&&Z instanceof Node&&H.contains(Z)||je.isFocusoutSuppressed()||Bo(!1)},[je]),jr=i.useRef(null),fr=i.useCallback(()=>{const w=jr.current;w!==null&&(jr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Ko=i.useCallback(()=>{if(jr.current!==null)return;const w=Z=>{Z.pointerType==="mouse"&&(fr(),Z.button===1&&Z.preventDefault())},H=Z=>{Z.pointerType==="mouse"&&fr()};jr.current={up:w,cancel:H},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",H,!0)},[fr]);i.useEffect(()=>fr,[fr]),i.useEffect(()=>{const w=He.current;if(pe||w===null)return;let H=0;const Z=ke=>{if(ke.pointerType!=="mouse"){(jt.current?.()??!1)||Bo(!1);return}H=ke.buttons,ke.button===1&&(ke.target===ie.current&&(jt.current?.()??!1)||Ko())},ne=ke=>{ke.pointerType==="mouse"&&(H=ke.buttons)},we=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===H)return;const Ze=ke.buttons&~H;H=ke.buttons,ke.preventDefault(),(Ze&4)!==0&&Ko()};return w.addEventListener("pointerdown",Z,!0),w.addEventListener("pointerup",ne,!0),w.addEventListener("pointermove",we,!0),()=>{w.removeEventListener("pointerdown",Z,!0),w.removeEventListener("pointerup",ne,!0),w.removeEventListener("pointermove",we,!0)}},[pe,Ko]);const Gu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(mn()){Ve();return}if(Ye()&&!it()){Ve();return}Ve()}},[Ve,Ye,it,mn]),Uo=i.useRef(!1);i.useLayoutEffect(()=>{if(pe){Uo.current=!1;return}if(Uo.current)return;Uo.current=!0,lt();const w=(He.current?.clientHeight??0)/x.current;w>0&&be.totalSize()>0&&De.setRowRange(0,be.indexAt(Math.min(w-1,be.totalSize()-1)));const H=(He.current?.clientWidth??0)/x.current;H>0&&ge.totalSize()>0&&De.setColRange(0,ge.indexAt(Math.min(H-1,ge.totalSize()-1)))},[pe,lt,De,be,ge]);const Pl=i.useRef(t);i.useLayoutEffect(()=>{Pl.current!==t&&(Pl.current=t,kt.cancelDrag(),zt.cancelDrag(),Mt.cancelDrag(),ct.cancelDrag(),Et.cancelDrag(),pt.cancelDrag(),je.cancelEdit(),tn.current?.hideTip(),tn.current?.close(),pe?(Pe.current=qn,yt(qn)):nn(qn,"sheetSwitch"),El.current())},[t,pe,nn,kt,zt,Mt,ct,Et,pt,De,je.cancelEdit]);const _l=i.useRef({adapter:le,rows:be.count,cols:ge.count}),{getSessionCell:ql,getSession:jl,cancelEdit:Il}=je;i.useLayoutEffect(()=>{const w=_l.current,H=be.count,Z=ge.count;if(_l.current={adapter:le,rows:H,cols:Z},w.adapter!==le||H>=w.rows&&Z>=w.cols)return;pe?(Pe.current=qn,yt(qn)):nn(Nw(Pe.current,H,Z),"countShrink"),kt.cancelDrag(),zt.cancelDrag(),Mt.cancelDrag(),ct.cancelDrag(),Et.cancelDrag(),pt.cancelDrag();const ne=at=>pe||at.row>=H||at.col>=Z,we=ql();we!==null&&ne(we)&&Il();const ke=Fo.current;if(ke.tip!==null&&ne(ke.tip)&&tn.current?.hideTip(),ke.interactive!==null&&ne(ke.interactive)){const at=He.current?.contains(document.activeElement)===!0;tn.current?.close({restoreFocus:at})}const Ze=_r();Ze!==null&&!Ze.foreign&&ne({row:Ze.range.endRow,col:Ze.range.endCol})&&Dt()},[le,be.count,ge.count,pe,nn,kt,zt,Mt,ct,Et,pt,ql,Il,_r,Dt]);const Hl=i.useRef(c),Bl=i.useRef(a),Wl=i.useRef(p),Vl=i.useRef(g);i.useLayoutEffect(()=>{(Hl.current!==c||Bl.current!==a||Wl.current!==p||Vl.current!==g)&&(Hl.current=c,Bl.current=a,Wl.current=p,Vl.current=g,kt.cancelDrag(),zt.cancelDrag(),Mt.cancelDrag(),ct.cancelDrag(),Et.cancelDrag(),pt.cancelDrag())},[c,a,p,g,kt,zt,Mt,ct,Et,pt]),i.useLayoutEffect(()=>{Rt(),vt(),Le()},[c,a,p,g,Rt,vt,Le]);const Yl=i.useRef(v);i.useLayoutEffect(()=>{Yl.current!==v&&(Yl.current=v,Dt())},[v,Dt]),i.useLayoutEffect(()=>{Le()},[Le,ft]);const Cn=i.useCallback(()=>{const w=pl.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(En,()=>({resizeRow:(w,H)=>{const Z=Math.round(H);be.resize(w,Z),oe.current?.updateRowSize(w,Z),De.bumpRowGeometry(),Rt(),Le(),Dn(),Ht()},resizeColumn:(w,H)=>{const Z=Math.round(H);ge.resize(w,Z),oe.current?.updateColSize(w,Z),De.bumpColVersion(),vt(),Le(),Dn(),Ht()},autoFitColumns:w=>{for(const H of w)if(!Number.isInteger(H)||H<0||H>=ge.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${ge.count-1} (got ${String(H)})`);return ct.autofitColumnsInAllRows(w)},scrollToCell:(w,H)=>{oe.current?.scrollToCell(w.row,w.col,H)},focus:w=>{It(w),Ye()||lt()},executeCommand:w=>Po.current(w),applyFormat:w=>Cn().applyFormat(w),setBorders:(w,H)=>Cn().setBorders(w,H),setHyperlink:w=>Cn().setHyperlink(w),setNote:w=>Cn().setNote(w),addComment:w=>Cn().addComment(w),setValidation:w=>Cn().setValidation(w),paste:w=>_o.current(w),getSelection:()=>Pe.current,setSelection:(w,H)=>{const Z=Fw(w,be.count,ge.count),ne=p0(H);return Ye()||cr()?!1:(nn(Z,"setSelection"),ne&&Lt(Z.active),!0)},getEditSession:jl,commitEdit:()=>Ye()?it()?"committed":"rejected":"idle",getBaseFormat:w=>le.getCellFormat===void 0?void 0:le.getCellFormat(w.row,w.col),getPaintedFormat:w=>le.getCellFormat===void 0?void 0:en(w.row,w.col,ao(le,w.row,w.col)),startEdit:w=>{ir(w)},openPopover:w=>{Fr.current(w)}}),[be,ge,De,vt,Rt,Le,Dn,Ht,ct,It,Ye,lt,le,en,ir,Cn,nn,cr,Lt,jl,it]),pe)return U.jsx("div",{className:_t?`aqsp-root ${_t}`:"aqsp-root","data-aqsp-empty":"","data-testid":Ct});const Zu=d!==void 0||L!==void 0||O!==void 0||C!==void 0||u!==void 0,Ju=o===void 0?{"aria-label":bt.rootAriaLabel}:{"aria-labelledby":o};return U.jsxs("div",{ref:He,className:_t?`aqsp-root ${_t}`:"aqsp-root",role:"group",...Ju,tabIndex:0,onFocus:Uu,onBlur:Xu,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-aqsp-framed":B===void 0?void 0:"","data-testid":Ct,children:[U.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":S,onPointerDown:Gu,style:S===1?void 0:{width:`${100/S}%`,height:`${100/S}%`,transform:`scale(${S})`,"--_aqsp-zoom":String(S)},children:[b?U.jsxs(U.Fragment,{children:[U.jsx("div",{ref:Be,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(mn()){Ve();return}if(Ye()&&!it()){Ve();return}Ve(),St({ranges:[me({row:0,col:0},{row:le.rowCount-1,col:le.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),U.jsx(Tw,{viewStore:De,colAxis:ge,frozenCols:c,frozenTrailingCols:p,handleRef:oe,bandRef:de,colTrackRef:ye,windowOriginXRef:st,repaintColHeaders:vt,selectionRanges:ft.ranges,enableResizeUI:j,dividerLeadingRef:et,dividerTrailingRef:Ue}),U.jsx($w,{viewStore:De,rowAxis:be,handleRef:oe,bandRef:Te,selectionRanges:ft.ranges,rowTrackRef:ve,windowOriginYRef:Se,repaintHeaders:Rt,enableResizeUI:j,frozenRows:a,frozenTrailingRows:g,dividerLeadingRef:Xe,dividerTrailingRef:Oe})]}):null,U.jsxs("div",{ref:Ie,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[U.jsx(xw,{adapter:le,rowAxis:be,colAxis:ge,viewStore:De,handleRef:oe,bodyRef:he,dataVersion:v,defaultColumnWidth:l,frozenColumns:c,frozenRows:a,frozenTrailingColumns:p,frozenTrailingRows:g,headerRows:n,labelledBy:o,gridLabel:o===void 0?bt.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:y,showArrowButtons:N?.showArrowButtons,enableThumbDrag:N?.enableThumbDrag,enableTrackClick:N?.enableTrackClick,overscanRows:bc("overscanRows",F),overscanCols:bc("overscanCols",M),background:q,onRenderTruncated:X,renderCell:K,onScroll:Tu,onRangeChange:$u,focusSink:Ve,isEditing:Ye,requestCommit:it,testId:Ct?`${Ct}-vs`:void 0,__onCellRender:Mr,__maxRenderedCells:Oo,cfIndexRef:rr,cfMemoRef:or,isPointing:mn,locale:On,scrollLabels:Nr}),U.jsx(rg,{rowAxis:be,colAxis:ge,handleRef:oe,sinkRef:ie,getSelection:Ge,editing:je.editing,virtualKeyboard:Ou,repaintRef:rl,dragFrameRef:zo,getClip:_r,getIsDraggingAny:ar,getIsFillDragging:Et.isDragging,fillFrameRef:xl,resizeGuideFrameRef:Tl,fillHandleNodeRef:$l,enableFillHandle:R,frozenCols:c,frozenRows:a,trailingCols:p,trailingRows:g,sinkAriaLabel:bt.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Qt,onSinkMouseDown:Ku,editPaintRef:il,highlightRef:Do,frameRange:B,highlightColors:Ru,popoverAnchors:Fo,interactiveAnchorRef:al,tipAnchorRef:ul}),dr.layerEnabled?U.jsx(r0,{controller:dr,labels:bt,renderPopover:$e,interactiveAnchorRef:al,tipAnchorRef:ul}):null]}),Zu?U.jsx("div",{ref:dt,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),U.jsx("div",{ref:qe,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=Ut.iterateTsvPrefixRows;exports.iterateTsvRows=Ut.iterateTsvRows;exports.measureTsv=Ut.measureTsv;exports.parseTsv=Ut.parseTsv;exports.serializeClipboardTsv=Ut.serializeClipboardTsv;exports.serializeTsv=Ut.serializeTsv;exports.columnIndexToName=ze.columnIndexToName;exports.columnNameToIndex=ze.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Ps;exports.CommentPopover=Ua;exports.DEFAULT_CUSTOM_COLORS=yu;exports.DEFAULT_HIGHLIGHT_COLORS=Ka;exports.DEFAULT_SHORTCUTS=za;exports.LinkPopover=Xa;exports.ListPopover=Ga;exports.MessagePopover=Za;exports.NotePopover=Ja;exports.NoteTip=Qa;exports.SPREADSHEET_LABEL_CATALOGS=Ma;exports.SPREADSHEET_RESERVED_SHORTCUTS=Jh;exports.Spreadsheet=A0;exports.canonicalizeFormat=xt;exports.detectClipSource=Dc;exports.enumerateRangeCells=sn;exports.estimatePasteCellCount=qh;exports.expandPaste=jh;exports.formatCellValue=Xn;exports.formatEquals=dd;exports.fromR1C1=$r;exports.makeRange=me;exports.mergeFormat=qs;exports.normalizeHyperlink=fn;exports.parseChord=Yt;exports.parseClipPayload=Cs;exports.parseHtmlTable=Sa;exports.rangeContains=Pt;exports.rangeSize=wt;exports.resolveLabel=_e;exports.resolveLabels=Na;exports.serializeClipPayload=Tc;exports.serializeHtmlTable=ba;exports.shiftFormula=na;exports.toR1C1=vo;exports.validateCellText=_a;
12
+ `)},Gh=(e,t,n,r)=>{const o=e.localName;if(o==="b"||o==="strong")t.set("font-weight","bold");else if(o==="i"||o==="em")t.set("font-style","italic");else if(o==="u")n.underline=!0;else if(o==="s"||o==="strike"||o==="del")n.strikethrough=!0;else if(o==="font"){const s=e.getAttribute("color"),l=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),l!==null&&l.trim()!==""&&t.set("font-family",l)}Ps(t,Ia(e,r))},Zh=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?Da(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<Fi.length?Fi[l]:null}return null},Ha=(e,t,n)=>t!==void 0&&Pa(t)?sh(e,t,n):e,Jh=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&vt(c)!==null)if(n!==void 0&&n.type==="date"){const a=Da(Number(c));if(a!==null)return a}else return c;return Ha(t,n,r)},Qh=(e,t,n,r)=>{const o=Ia(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Bh(o)};for(const m of rm(e))Yh(m,l);Xh(l,o,s,r.rules);const c=Uh(l.text,l.mode),a=Wh(o,s,r.kind),u={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),C=m===null?void 0:Jp(m,r.options);C!==void 0&&(a.value=C);const L=e.getAttribute("data-sheets-value"),M=L===null?null:Zh(L,C);u.t=M===null?Ha(c,C,Ma):M;const $=e.getAttribute("data-sheets-formula");$?.startsWith("=")&&(u.f=$);const _=e.getAttribute("data-sheets-hyperlink"),G=_!==null?_:l.href,Z=G===null?null:yn(G);Z!==null&&(u.link=Z);const O=e.getAttribute("data-sheets-note");O!==null&&O!==""&&(u.note=O)}else{const m=o.get("mso-number-format"),C=m===void 0?void 0:ll(Fs(Oo(m)),r.options);C!==void 0&&(a.value=C),u.t=Jh(e,c,C,r.separators);const L=e.getAttribute("x:fmla");L?.startsWith("=")&&(u.f=Do(L,{row:t,col:n}));const M=l.href===null?null:yn(l.href);M!==null&&(u.link=M)}return{cell:u,format:a}},qs=(e,t,n)=>{const r=e.getAttribute(t);if(r===null)return 1;const o=/^\s*\+?(\d+)/.exec(r);if(o===null)return 1;const s=Number(o[1]);return s<1?1:s>n?n:s},em=e=>{const t=/^(\d*\.?\d+)(px|pt)$/i.exec(e.trim());if(t===null)return null;const n=Number(t[1]);return t[2].toLowerCase()==="pt"?Math.round(n*4/3):Math.round(n)},tm=(e,t)=>{const n=e.getAttribute(t);if(n===null)return null;const r=/^\s*\+?(\d*\.?\d+)/.exec(n);return r===null?null:Math.round(Number(r[1]))},Ba=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Po(n);if(r!==null){const s=r.get("display");if(s!==void 0&&s.toLowerCase()==="none")return 0;const l=r.get(t),c=l===void 0?null:em(l);if(c!==null)return Math.min(c,Cn)}const o=tm(e,t);return o===null?null:Math.min(o,Cn)},nm=(e,t)=>{const n=[],r=o=>{const s=Ba(o,"width");for(let l=qs(o,"span",el);l>0&&n.length<t;l-=1)n.push(s)};for(const o of zr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of zr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*zr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*rm(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*om(e){for(const t of["thead","tbody","tfoot"])for(const n of zr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of zr(n))o.localName==="tr"&&(yield o)}}const ms=()=>({t:""}),sm=(e,t,n)=>{const r=ia(),o=[],s=[],l=[];let c=0;for(const M of om(e)){const $=o.length,_=($+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const G=[];for(let O=0;O<l.length;O+=1)l[O]>0&&(G[O]=ms(),l[O]-=1);let Z=0;for(const O of zr(M)){const F=O.localName;if(F!=="td"&&F!=="th")continue;for(;G[Z]!==void 0;)Z+=1;const V=qs(O,"colspan",el),H=qs(O,"rowspan",ea),S=($+1)*Math.max(c,Z+V);if(S>n)return{outcome:"limit",cells:S};const P=Qh(O,$,Z,t),j=r.intern(P.format);j!==void 0&&(P.cell.fmt=j),G[Z]=P.cell;for(let w=1;w<V;w+=1)G[Z+w]===void 0&&(G[Z+w]=ms());if(H>1)for(let w=0;w<V;w+=1){const d=H-1,b=Z+w;l[b]=l[b]===void 0||l[b]<d?d:l[b]}Z+=V}G.length>c&&(c=G.length),o.push(G),s.push(Ba(M,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map(M=>{const $=[];for(let _=0;_<c;_+=1){const G=M[_];$.push(G===void 0?ms():G)}return $}),u=nm(e,c),m=u.length===c&&u.every(M=>M!==null)?u.map(M=>M===null?0:M):void 0,C=s.every(M=>M!==null)?s.map(M=>M===null?0:M):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:Js(),formats:[...r.entries],validations:[],cells:a,...m===void 0?{}:{colWidths:m},...C===void 0?{}:{rowHeights:C},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Va=(e,t,n,r)=>{if(!Number.isInteger(r)||r<=0)throw new RangeError(`[spreadsheet] parseHtmlTable requires a positive integer maxCells, received ${r}`);let o;try{o=new DOMParser().parseFromString(e,"text/html")}catch{return{outcome:"none"}}const s=o.querySelector("table");if(s===null)return{outcome:"none"};const l=yh(o);return sm(s,{kind:t,rules:l,options:n,separators:l.separators},r)},he=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),Wt=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,Rt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),bt=e=>e.reduce((t,n)=>t+Rt(n).rows*Rt(n).cols,0),lm=(e,t)=>{if(!Wt(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(he({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(he({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(he({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(he({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},dn=(e,t)=>{if(e.length===1){const r=e[0];for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1)t({row:o,col:s});return}const n=new Set;for(const r of e)for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1){const l=`${o}:${s}`;n.has(l)||(n.add(l),t({row:o,col:s}))}},bn=(e,t,n)=>{if(t<=0||n<=0)throw new RangeError(`[spreadsheet] clampCoord requires a non-empty grid, received ${t} x ${n}`);return{row:Math.min(Math.max(Math.trunc(e.row),0),t-1),col:Math.min(Math.max(Math.trunc(e.col),0),n-1)}},Kt=(e,t)=>e.row===t.row&&e.col===t.col,Wa=(e,t)=>e===void 0?hi(void 0,void 0,t()):hi(e.align,e.value,e.align===void 0?t():""),Ro=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},ir=(e,t,n)=>{if(e.getCellFormula!==void 0){const r=e.getCellFormula(t,n);if(r!==void 0){if(typeof r!="string"||!r.startsWith("="))throw new RangeError(`[spreadsheet] getCellFormula(${t}, ${n}) must return a string starting with "=", received ${JSON.stringify(r)}`);return{text:r,isFormula:!0}}}return{text:e.getCellText(t,n),isFormula:!1}},So=e=>({format:e.getCellFormat!==void 0,note:e.getCellNote!==void 0,comments:e.getCellComments!==void 0,hyperlink:e.getCellHyperlink!==void 0,validation:e.getCellValidation!==void 0,cf:e.getConditionalFormats!==void 0,formula:e.getCellFormula!==void 0}),Ka=e=>e.isCellReadOnly!==void 0,et=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,im=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],cm=()=>!0,am=e=>{const t=new WeakMap,n={};for(const r of im)r!=="isCellReadOnly"&&Object.defineProperty(n,r,{enumerable:!0,get:()=>{const o=Reflect.get(e,r,e);if(typeof o!="function")return o;const s=t.get(o);if(s!==void 0)return s;const l=o.bind(e);return t.set(o,l),l}});return Object.defineProperty(n,"isCellReadOnly",{enumerable:!0,value:cm}),n},um=/^data-[a-z0-9-]+$/,dm=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},fm=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!dm(r))throw new RangeError(`[spreadsheet] getCellAttributes must return a plain data-* record or null (got ${Object.prototype.toString.call(r)})`);for(const[o,s]of Object.entries(r)){if(!um.test(o))throw new RangeError(`[spreadsheet] getCellAttributes key must be a lowercase data-* name (got ${JSON.stringify(o)})`);if(o.startsWith("data-aqsp")||o.startsWith("data-aqvs")||o==="data-row"||o==="data-col")throw new RangeError(`[spreadsheet] getCellAttributes key ${JSON.stringify(o)} shadows a package- or engine-emitted cell attribute`);if(typeof s!="string")throw new RangeError(`[spreadsheet] getCellAttributes value for ${JSON.stringify(o)} must be a string (got ${typeof s})`)}return r},Or=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},Qn=(e,t)=>{for(const n of t)if(Or(e,n))return!0;return!1},pm=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=Rt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},_s=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=Rt(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,a=c?s.rows:e.rows,u=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},C=Math.min(a,r-m.row),L=Math.min(u,o-m.col);return C<=0||L<=0?null:he(m,{row:m.row+C-1,col:m.col+L-1})},Ya=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,a=_s({rows:l,cols:c},t,n,r,o);if(a===null)return[];const u={row:a.startRow,col:a.startCol},m=a.endRow-a.startRow+1,C=a.endCol-a.startCol+1,L=[];for(let M=0;M<m;M+=l){const $=[];for(let G=0;G<C;G+=c){const Z={row:u.row+M,col:u.col+G};$.push(Z),L.push(Z)}const _=Math.min(l,m-M);for(let G=0;G<_;G+=1){const Z=u.row+M+G,O=e[G];for(let F=0;F<$.length;F+=1){const V=F*c,H=Math.min(c,C-V);for(let S=0;S<H;S+=1)s(Z,u.col+V+S,O[S],$[F])}}}return L},hm=(e,t,n,r,o)=>{const s=[];return Ya(e,t,n,r,o,(l,c,a)=>{s.push({row:l,col:c,text:a})}),s},_i=(e,t,n,r,o,s)=>{const l=[],c=Ya(e,t,n,r,o,(a,u,m,C)=>{const L=s(m,a,u,C);L!==null&&l.push({...L,row:a,col:u})});return{edits:l,tiles:c}},Xa=(e,t)=>{const n=t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol,r=t.startRow!==e.startRow||t.endRow!==e.endRow||t.startCol!==e.startCol||t.endCol!==e.endCol;if(!(n&&r))throw new RangeError(`[spreadsheet] expandFill requires a box strictly containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`)},mm=(e,t)=>{Xa(e,t);const n=Rt(t),r=Rt(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},gm=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(he({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(he({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(he({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(he({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},wm=(e,t,n,r)=>{Xa(t,n);const o=Rt(t).rows,s=Rt(t).cols,l=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const u=t.startRow+((a-t.startRow)%o+o)%o,m=a>=t.startRow&&a<=t.endRow;for(let C=n.startCol;C<=n.endCol;C+=1){if(m&&C>=t.startCol&&C<=t.endCol)continue;const L=t.startCol+((C-t.startCol)%s+s)%s,M=u*2**21+L;let $=c.get(M);$===void 0&&($={value:e(u,L),origin:{row:u,col:L}},c.set(M,$)),l.push(r($.value,$.origin,{row:a,col:C}))}}return l},Ua=(e,t,n)=>{const r=ir(e,t,n),o={text:r.text,isFormula:r.isFormula};if(e.getCellFormat!==void 0){const s=e.getCellFormat(t,n);o.format=s===void 0?null:Dt(s)}if(e.getCellValidation!==void 0){const s=e.getCellValidation(t,n);o.validation=s===void 0?null:s}if(e.getCellHyperlink!==void 0){const s=cr(e.getCellHyperlink(t,n));o.hyperlink=s===void 0?null:s}if(e.getCellNote!==void 0){const s=e.getCellNote(t,n);o.note=s===void 0?null:s}return o},Ga=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Sa(e.text,n.row-t.row,n.col-t.col):e.text};return e.format!==void 0&&(r.format=e.format),e.validation!==void 0&&(r.validation=e.validation),e.hyperlink!==void 0&&(r.hyperlink=e.hyperlink),e.note!==void 0&&(r.note=e.note),r},qo=["bold","italic","underline","strikethrough","clearFormatting","alignLeft","alignCenter","alignRight","formatNumber","formatTime","formatDate","formatCurrency","formatPercent","formatScientific","bordersOuter","bordersClear","borderTop","borderRight","borderBottom","borderLeft","insertLink","insertNote","insertComment","openHyperlink","openValidationList","pasteSpecial","fillDown","fillRight","fillSelection","insertDate","insertTime","hideRows","hideColumns","unhideRows","unhideColumns","increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth","formatGeneral","bordersAll","pasteFormats","pasteFormulas","pasteAdd","pasteSubtract","pasteMultiply","pasteDivide","multiplyBy100","multiplyBy1000","divideBy100","divideBy1000","signReversal","fillColorYellow","fillColorBlue","fillColorGreen","fillColorRed","fillColorCustom1","fillColorCustom2","fillColorCustom3","fillColorCustom4","fillColorCustom5","fontColorYellow","fontColorBlue","fontColorGreen","fontColorRed","fontColorCustom1","fontColorCustom2","fontColorCustom3","fontColorCustom4","fontColorCustom5","toggleRowHighlight","toggleColumnHighlight","toggleBothHighlight","toggleIntersectionHighlight"],Cm=/^[A-Z]$/,ym=/^[A-Za-z]$/,bm=/^Key([A-Z])$/,Za=new Set([...Array.from({length:10},(e,t)=>`Digit${t}`),...Array.from({length:10},(e,t)=>`Numpad${t}`),"NumpadAdd","NumpadSubtract","NumpadMultiply","NumpadDivide","NumpadDecimal","NumpadEnter",...Array.from({length:12},(e,t)=>`F${t+1}`),"Semicolon","Quote","Comma","Period","Slash","Backslash","BracketLeft","BracketRight","Backquote","Minus","Equal","IntlYen","IntlRo","IntlBackslash","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),vm=e=>Cm.test(e)||Za.has(e),tn=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!vm(l))throw new RangeError(`[spreadsheet] shortcut ${JSON.stringify(e)} is not canonical (expected Ctrl+Alt+Shift+KEY with used modifiers only, KEY = A-Z or a code name such as Digit1 / Semicolon / F2)`);return{ctrl:r,alt:o,shift:s,key:l}},Rm=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Ja=e=>{if(ym.test(e.key))return e.key.toUpperCase();const t=bm.exec(e.code);return t!==null?t[1]:Za.has(e.code)?e.code:null},br=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Ja(t)===e.key,Se=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),xe=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Sm=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(Se(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(Se(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(Se(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(Se(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Em=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(Se(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(Se(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},qr=[...Sm(),Se("Home","idle","row start (first visible column)"),Se("Ctrl+Home","idle","first visible cell"),Se("Shift+Home","idle","extend to row start"),Se("Ctrl+Shift+Home","idle","extend to first visible cell"),Se("End","idle","row end (last visible column)"),Se("Ctrl+End","idle","last visible cell"),Se("Shift+End","idle","extend to row end"),Se("Ctrl+Shift+End","idle","extend to last visible cell"),Se("PageUp","both","page up (idle) / commit + page up (editing)"),Se("PageDown","both","page down (idle) / commit + page down (editing)"),Se("Shift+PageUp","idle","extend one page up"),Se("Shift+PageDown","idle","extend one page down"),Se("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),Se("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),Se("Tab","both","cycle right (idle) / commit + cycle right (editing)"),Se("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),Se("Enter","both","cycle down (idle) / commit + cycle down (editing)"),Se("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),Se("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),Se("F2","both","start editing (idle) / toggle the pointing arm (editing)"),Se("F4","editing","cycle the reference anchor under the caret (formula session)"),Se("Delete","idle","clear every selected cell"),Se("Backspace","idle","clear every selected cell"),Se("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),Se("Ctrl+A","idle","select all"),Se("Ctrl+Z","idle","undo request"),Se("Ctrl+Y","idle","redo request"),Se("Ctrl+Shift+Z","idle","redo request"),Se("Shift+F10","idle","keyboard context menu"),Se("ContextMenu","idle","keyboard context menu"),Se("Ctrl+Space","idle","column bands"),Se("Shift+Space","idle","row bands"),Se("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),Se("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),Se("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),Se("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...Em(),xe("bold","Ctrl+B","both","toggle bold"),xe("italic","Ctrl+I","both","toggle italic"),xe("underline","Ctrl+U","both","toggle underline"),xe("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),xe("clearFormatting","Ctrl+Backslash","idle","clear formatting"),xe("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),xe("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),xe("alignLeft","Ctrl+Shift+L","both","align left"),xe("alignCenter","Ctrl+Shift+E","both","align center"),xe("alignRight","Ctrl+Shift+R","both","align right"),xe("formatNumber","Ctrl+Shift+Digit1","both","number format"),xe("formatTime","Ctrl+Shift+Digit2","both","time format"),xe("formatDate","Ctrl+Shift+Digit3","both","date format"),xe("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),xe("formatPercent","Ctrl+Shift+Digit5","both","percent format"),xe("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),xe("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),xe("bordersClear","Alt+Shift+Digit6","idle","clear borders"),xe("borderTop","Alt+Shift+Digit1","idle","top border"),xe("borderRight","Alt+Shift+Digit2","idle","right border"),xe("borderBottom","Alt+Shift+Digit3","idle","bottom border"),xe("borderLeft","Alt+Shift+Digit4","idle","left border"),xe("insertLink","Ctrl+K","idle","insert / edit hyperlink"),xe("insertNote","Shift+F2","idle","insert / edit note"),xe("insertComment","Ctrl+Alt+M","idle","insert comment"),xe("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),xe("openValidationList","Alt+ArrowDown","idle","open the validation list"),xe("fillDown","Ctrl+D","idle","fill down"),xe("fillRight","Ctrl+R","idle","fill right"),xe("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),xe("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),xe("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),xe("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),xe("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),xe("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),xe("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),xe("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),xe("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),xe("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),xe("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],gs=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),ji=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),km=e=>{const t=tn(e);if(t.key==="IntlYen"||t.key==="IntlRo"||t.key==="IntlBackslash")return null;const n=/^(?:Digit|Numpad)(\d)$/u.exec(t.key),r=n!==null?n[1]:t.key in ji?ji[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},xo=(e,t)=>e.column==="both"||e.column===t,Om=Array.from(new Set(qr.filter(e=>!e.rebindable&&xo(e,"idle")).map(e=>e.chord))),Ao=new Set(qr.filter(e=>e.command!==void 0&&xo(e,"editing")).map(e=>e.command)),xm=new Set(qr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Qa=e=>{const t={};for(const n of qo)t[n]=e(n);return t},eu=Qa(e=>qr.filter(t=>t.command===e).map(t=>t.chord)),Am=e=>{const t=new Map;for(const n of qo){const r=e[n];if(r!=null)for(const o of r){const s=t.get(o);s===void 0?t.set(o,[n]):s.includes(n)||s.push(n)}}return t},Tm=e=>{const t=new Set(qo);for(const n of Object.keys(e)){if(!t.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not a SpreadsheetCommand`);const r=e[n];if(r!==void 0){if(xm.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},$m=(e,t)=>{const n=tn(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Ao.has(e);for(const o of qr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(xo(o,"idle")||r&&xo(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Mm=e=>{e!==void 0&&Tm(e);const t=Qa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?eu[r]:o===null?[]:o});for(const r of qo)for(const o of t[r])$m(r,o);const n=new Map;for(const[r,o]of Am(t)){if(o.length>1)throw new RangeError(`[spreadsheet] shortcut ${r} bound to ${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`);n.set(r,o[0])}return n},js=(e,t)=>{const n=Ja(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=Rm({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}),s=e.get(o);return s===void 0?null:{command:s,chord:o}},Lm=(e,t)=>{const n=js(e,t);return n===null?null:n.command},zm=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","NumpadEnter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Nm=/^F(?:[1-9]|1[0-2])$/,Dm=e=>{const t=tn(e);return t.alt||zm.has(t.key)?!1:t.ctrl||Nm.test(t.key)},al=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose","columnMenu","columnMenuFiltered","sortAscending","sortDescending","sortClear","filterMatchMode","filterModeExact","filterModeFuzzy","filterSearchValues","filterSelectAll","filterSelectNone","filterBlank","filterLoading","filterLoadFailed","filterQuery","filterApply","filterClearColumn","filterClearAll"],Ii=[...ot.VIRTUAL_SCROLL_LABEL_KEYS,...al],Is=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close",columnMenu:"Sort and filter",columnMenuFiltered:"filtered",sortAscending:"Sort ascending",sortDescending:"Sort descending",sortClear:"Clear sort",filterMatchMode:"Match",filterModeExact:"Exact match",filterModeFuzzy:"Fuzzy search",filterSearchValues:"Search values",filterSelectAll:"Select all",filterSelectNone:"Clear all",filterBlank:"(Blanks)",filterLoading:"Loading…",filterLoadFailed:"Could not load the values",filterQuery:"Search text",filterApply:"Apply",filterClearColumn:"Clear this column's filter",filterClearAll:"Clear all filters"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる",columnMenu:"並べ替えと絞り込み",columnMenuFiltered:"絞り込み中",sortAscending:"昇順で並べ替え",sortDescending:"降順で並べ替え",sortClear:"並べ替えを外す",filterMatchMode:"検索方法",filterModeExact:"完全一致",filterModeFuzzy:"あいまい検索",filterSearchValues:"値を探す",filterSelectAll:"すべて選ぶ",filterSelectNone:"すべて外す",filterBlank:"(空白)",filterLoading:"読み込み中…",filterLoadFailed:"値を読めませんでした",filterQuery:"探す語",filterApply:"当てる",filterClearColumn:"この列の絞り込みを外す",filterClearAll:"すべての絞り込みを外す"})}),tu=Object.freeze({en:Object.freeze({...ot.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Is.en}),ja:Object.freeze({...ot.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Is.ja})}),Tn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Hi=e=>e==="commentCount"||e==="listMore",Fm=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${Tn(t)}`);for(const n of al){const r=e[n];if(!(Hi(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Hi(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${Tn(r)}`)}}},Pm=e=>{const t={};let n=!1;for(const r of ot.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},qm=(e,t,n)=>{e[t]=n},nu=(e,t)=>{const n=ot.resolveVirtualScrollLocale(e);if(t===void 0)return tu[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${Tn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!Ii.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Ii.join(", ")}`);const s={...ot.resolveVirtualScrollLabels(n,Pm(t)),...Is[n]};for(const l of al){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&qm(s,l,c)}return Fm(s),Object.freeze(s)},_m=e=>{const t={};for(const n of ot.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},ye=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},Bi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},jm={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Im=(e,t,n,r)=>{switch(e){case"gt":case"gte":case"lt":case"lte":return`${r[e]} ${t}`;case"eq":return`equal to ${t}`;case"neq":return`not equal to ${t}`;case"between":return`between ${t} and ${n}`;default:return`not between ${t} and ${n}`}},ws=(e,t)=>{const n=r=>(o,s)=>`${e} ${Im(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},Hm=Object.freeze({list:"Value must be one of the list items.",number:ws("Value must be a number",Bi),textLength:ws("Text length must be",Bi),date:ws("Value must be a date",jm),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),Bm=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),Cs=Object.freeze({en:Hm,ja:Bm}),Vm=Object.freeze({ok:!0}),Wm="TRUE",Km="FALSE",Ym=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Xm=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Um=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Gm=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Zm=/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/,Vi=e=>{const t=e.trim();if(!(Um.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),a=c<0?s:s.slice(0,c),u=c<0?"":s.slice(c+1),m=a+u,C=m.search(/[^0]/);return C<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(C).replace(/0+$/,""),point:a.length+l-C}},Jm=e=>e===1?-1:e===-1?1:0,Qm=(e,t)=>{if(e.sign!==t.sign)return e.sign<t.sign?-1:1;if(e.sign===0)return 0;const n=e.point!==t.point?e.point<t.point?-1:1:e.digits===t.digits?0:e.digits<t.digits?-1:1;return e.sign===1?n:Jm(n)},eg=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Wi=e=>{const t=Gm.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>eg(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},tg=(e,t)=>{const n=[e.year,e.month,e.day,e.hour,e.minute,e.second],r=[t.year,t.month,t.day,t.hour,t.minute,t.second];for(let o=0;o<n.length;o+=1)if(n[o]!==r[o])return n[o]<r[o]?-1:1;return 0},ng=(e,t)=>e<t?-1:e>t?1:0,rg=e=>e==="between"||e==="notBetween",og=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!rg(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},sg=(e,t,n)=>{switch(e){case"gt":return t===1;case"gte":return t!==-1;case"lt":return t===-1;case"lte":return t!==1;case"eq":return t===0;case"neq":return t!==0;case"between":return t!==-1&&n!==1;default:return t===-1||n===1}},ys=(e,t,n,r,o,s)=>{const l=og(e,t,n,r);return l===null?!0:o===null?!1:sg(e,s(o,l.a),l.b===null?0:s(o,l.b))},lg=e=>Number.isFinite(e)?e:null,ig=e=>{let t=0;for(const n of e)t+=1;return t},cg=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),ag=(e,t)=>{switch(e.op){case"isEmail":return Zm.test(t);case"isUrl":return cg(t)}if(e.value===void 0)return!0;switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);default:return t.endsWith(e.value)}},ug=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,ru=e=>({checked:e.checked===void 0?Wm:e.checked,unchecked:e.unchecked===void 0?Km:e.unchecked}),dg=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Ym.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Tn(e.op)} for type "${e.type}"`);return;case"text":if(!Xm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Tn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${Tn(e.type)}`)}},fg=(e,t,n)=>{switch(e.type){case"list":return mg(e).has(t);case"number":return ys(e.op,e.a,e.b,Vi,Vi(t),Qm);case"textLength":return ys(e.op,e.a,e.b,lg,ig(t),ng);case"date":return ys(e.op,e.a,e.b,Wi,Wi(t),tg);case"text":return ag(e,t);case"checkbox":{const r=ru(e);return t===r.checked||t===r.unchecked}default:return n===void 0||ug(n(e.formula))}},ou=(e,t,n)=>(dg(e),t===""||fg(e,t,n)),Ki=e=>e===void 0?void 0:e.trim(),pg=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Ki(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),Ki(e.b));case"text":return hg(e,t.text);case"checkbox":{const n=ru(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},hg=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},Yi=new WeakMap,mg=e=>{const t=Yi.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Yi.set(e,n),n},su=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Cs,n)){const o=Object.keys(Cs).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${Tn(n)}`)}return ou(e,t,r)?Vm:{ok:!1,message:e.errorMessage===void 0?pg(e,Cs[n]):e.errorMessage}},gg=e=>e.type!=="custom",wg=(e,t)=>gg(e)&&!ou(e,t,void 0),lu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),iu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),cu=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,au=(e,t,{scroll:n,frozenSize:r,trailingSize:o,extent:s})=>r>0&&t<r?e.indexAt(t):o>0&&s>0&&t>=s-o?e.indexAt(e.totalSize()-(s-t)):e.indexAt(t+n),uu=(e,t)=>lu(e,t),du=(e,t)=>lu(e,t),fu=(e,t)=>iu(e,t),pu=(e,t)=>iu(e,t),$n=(e,t,n)=>cu(e,t,n),Mn=(e,t,n)=>cu(e,t,n),_r=(e,t,n)=>au(e,t,n),jr=(e,t,n)=>au(e,t,n),Cg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Vt=1,xr=3,so=e=>`${-Math.min(xr,Math.max(0,Math.floor(e)))}px`,yg=(e,t,n)=>{const r=Math.min(e.endRow,t-1),o=Math.min(e.endCol,n-1);return e.startRow>r||e.startCol>o?null:{startRow:e.startRow,startCol:e.startCol,endRow:r,endCol:o}},Xi=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,Ui=(e,t)=>t===null?e:Math.min(e,t),Gi=e=>e===null?"100%":`min(100%, ${e}px)`,Zi=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,Ji=(e,t,n,r)=>{switch(e){case"f":return[0,n-1];case"s":return[n,t-r-1];case"t":return[t-r,t-1];case"m":return[0,t-1]}},Qi=Object.freeze([0,-1]),ec=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const a=-c*Vt,u=c*(1+Vt),m=t>=r,C=n<=o,L=m?s:a,M=C?l:u;return M<=a||L>=u?!1:(e.near=Math.max(L,a),e.far=Math.min(M,u),e.nearOpen=!m||L<a,e.farOpen=!C||M>u,!0)},lo=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),tc=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,nc=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},bg=Object.freeze(["top","right","bottom","left"]),vg=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Rg=e=>bg.filter((t,n)=>(e&1<<n)!==0).join(" "),hu=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Sg=16,Eg=450,kg=e=>e>4?Math.floor(Eg/(5*e)):Sg,vr=(e,t)=>{const n=document.createElement("div");return n.className="aqsp-band",n.setAttribute("data-aqsp-band",e),t!==null&&n.setAttribute("data-aqsp-band-edge",t),n.style.display="none",n},rc=()=>({rowLeft:vr("row","left"),rowRight:vr("row","right"),colAbove:vr("column","above"),colBelow:vr("column","below"),cross:vr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Hs=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],io=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},co=(e,t)=>Math.min(Math.max(e,0),t),oc="inset(100%)",nr=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Og=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,nr([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const L=`${t.height}px`;e.rowLeft.style.height=L,e.rowRight.style.height=L}const m=`translate(${co(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const C=`translate(${co(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;C!==s.rowRightTransform&&(s.rowRightTransform=C,e.rowRight.style.transform=C)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,nr([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const L=`${t.width}px`;e.colAbove.style.width=L,e.colBelow.style.width=L}const m=`translate(${t.left}px, ${co(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const C=`translate(${t.left}px, ${co(t.top+t.height,n.clampHeight)}px)`;C!==s.colBelowTransform&&(s.colBelowTransform=C,e.colBelow.style.transform=C)}const a=r.intersection?"intersection":l!==c?l?"row":"column":null,u=a!==null;if(u!==s.crossShown&&(s.crossShown=u,nr([e.cross],u)),a!==null){a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--_aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const m=`translate(${t.left}px, ${t.top}px)`;m!==s.crossTransform&&(s.crossTransform=m,e.cross.style.transform=m)}},sc=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,nr([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,nr([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,nr([e.cross],!1))},ao=e=>{for(const t of Hs(e))t.remove()},xg=(e,t)=>{const n=e-1-t.lineBoxPx;return t.verticalAlign==="top"?0:t.verticalAlign==="bottom"?Math.max(0,n):Math.max(0,n/2)},Ag=Object.freeze([]),lc=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},ic=e=>e.chrome[0]??e.active,cc=e=>{e.chrome.length=0;for(const t of e.dividerSlots)t!==null&&e.chrome.push(t);e.frame!==null&&e.chrome.push(e.frame.node)},Tg={left:"0px",right:"0px",width:""},$g={top:"0px",bottom:"0px",height:""},ac=()=>({container:null,active:null,dragRect:null,marquee:null,fillPreview:null,resizeGuide:null,fillPool:[],bandPool:[],dragBand:null,bandClampWidth:-1,bandClampHeight:-1,dividerSlots:[null,null,null,null],dividerShown:[!1,!1,!1,!1],dividerEnd:["0px","0px","0px","0px"],frame:null,bandClip:null,bandClipWidth:"",bandClipHeight:"",chrome:[]}),uc=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],dc=6,Mg=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:a,getClip:u,getIsDraggingAny:m,getIsFillDragging:C,fillFrameRef:L,resizeGuideFrameRef:M,fillHandleNodeRef:$,enableFillHandle:_,frozenCols:G,frozenRows:Z,trailingCols:O,trailingRows:F,sinkAriaLabel:V,sinkReadOnly:H,sinkKeyShortcuts:S,onSinkMouseDown:P,editPaintRef:j,highlightRef:w,frameRange:d,highlightColors:b,popoverAnchors:E,interactiveAnchorRef:k,tipAnchorRef:R})=>{const W=i.useRef(null),v=i.useRef(d);v.current=d;const x=d!==void 0,K=i.useRef(null),y=i.useRef(null),X=i.useRef(new Map(uc.map(T=>[T,ac()]))),Q=i.useCallback(T=>{const z=X.current.get(T);if(z!==void 0)return z;const Y=ac();return X.current.set(T,Y),Y},[]),p=i.useCallback((T,z,Y)=>{if(T===null)return;const I=T.style;I.left!==z.left&&(I.left=z.left),I.right!==z.right&&(I.right=z.right),I.width!==z.width&&(I.width=z.width),I.top!==Y.top&&(I.top=Y.top),I.bottom!==Y.bottom&&(I.bottom=Y.bottom),I.height!==Y.height&&(I.height=Y.height)},[]),f=i.useCallback((T,z,Y)=>{if(!(T.bandClampWidth===z&&T.bandClampHeight===Y)){T.bandClampWidth=z,T.bandClampHeight=Y;for(const I of T.bandPool)io(I,z,Y);T.dragBand!==null&&io(T.dragBand,z,Y)}},[]),g=i.useRef({rowAxis:e,colAxis:t});g.current={rowAxis:e,colAxis:t};const A=i.useCallback((T,z,Y)=>{const I=T.dividerSlots[z];I===null||T.dividerShown[z]===Y||(T.dividerShown[z]=Y,I.style.display=Y?"":"none")},[]),D=i.useCallback((T,z,Y)=>{const I=T.bandClip;I!==null&&(T.bandClipWidth!==z&&(T.bandClipWidth=z,I.style.width=z),T.bandClipHeight!==Y&&(T.bandClipHeight=Y,I.style.height=Y))},[]),B=i.useCallback((T,z,Y)=>{const I=T.dividerSlots[z];I===null||T.dividerEnd[z]===Y||(T.dividerEnd[z]=Y,z<2?I.style.bottom=Y:I.style.right=Y)},[]),ee=i.useRef({x:0,y:0}),le=i.useRef(null),ne=i.useCallback((T,z)=>{const Y=n.current,I=Y?.getFrozenSize()??Cg,te=Y?.getViewportSize(),se=te?.width??-1,fe=te?.height??-1,Le=ee.current;Le.x=T,Le.y=z;const ue=v.current!==void 0,Ae=g.current,Ye=ue?Ae.rowAxis.count:-1,Me=ue?Ae.colAxis.count:-1,Ie=ue?Ae.rowAxis.totalSize():-1,me=ue?Ae.colAxis.totalSize():-1;let ie=le.current;if(ie===null||ie.framed!==ue||ie.rowCount!==Ye||ie.colCount!==Me||ie.rowsTotal!==Ie||ie.colsTotal!==me||ie.frozenCols!==I.cols||ie.frozenWidth!==I.width||ie.frozenRows!==I.rows||ie.frozenHeight!==I.height||ie.trailingCols!==I.trailingCols||ie.trailingWidth!==I.trailingWidth||ie.trailingVisibleWidth!==I.trailingVisibleWidth||ie.trailingRows!==I.trailingRows||ie.trailingHeight!==I.trailingHeight||ie.trailingVisibleHeight!==I.trailingVisibleHeight||ie.bodyWidth!==se||ie.bodyHeight!==fe){const de=I.trailingVisibleWidth,De=I.trailingVisibleHeight,ht=I.cols<=0&&I.trailingCols<=0?[{kind:"m",map:Te=>Te-Le.x,clamp:se,style:Tg,seamLead:!1,seamTrail:!1}]:[...I.cols>0?[{kind:"f",map:Te=>Te,clamp:I.width,style:{left:"0px",width:`${I.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Te=>Te-Le.x-I.width,clamp:Math.max(0,se-I.width-de),style:{left:`${I.width}px`,right:`${de}px`,width:""},seamLead:I.cols>0,seamTrail:I.trailingCols>0},...I.trailingCols>0?[{kind:"t",map:Te=>Te-g.current.colAxis.totalSize()+de,clamp:de,style:{left:"",right:"0px",width:`${de}px`},seamLead:!0,seamTrail:!1}]:[]],it=I.rows<=0&&I.trailingRows<=0?[{kind:"m",map:Te=>Te-Le.y,clamp:fe,style:$g,seamLead:!1,seamTrail:!1}]:[...I.rows>0?[{kind:"f",map:Te=>Te,clamp:I.height,style:{top:"0px",height:`${I.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Te=>Te-Le.y-I.height,clamp:Math.max(0,fe-I.height-De),style:{top:`${I.height}px`,bottom:`${De}px`,height:""},seamLead:I.rows>0,seamTrail:I.trailingRows>0},...I.trailingRows>0?[{kind:"t",map:Te=>Te-g.current.rowAxis.totalSize()+De,clamp:De,style:{top:"",bottom:"0px",height:`${De}px`},seamLead:!0,seamTrail:!1}]:[]],ct=[];for(const Te of ht){const at=ue?Xi(Te.kind,me,I.width,I.trailingWidth):null,[Pt,mt]=ue?Ji(Te.kind,Me,I.cols,I.trailingCols):Qi;for(const Xe of it){const qt=ue?Xi(Xe.kind,Ie,I.height,I.trailingHeight):null,[Wr,ln]=ue?Ji(Xe.kind,Ye,I.rows,I.trailingRows):Qi;ct.push({nodes:Q(`${Te.kind}${Xe.kind}`),xKind:Te.kind,yKind:Xe.kind,mapX:Te.map,clampWidth:Te.clamp,xStyle:Te.style,xSeamLead:Te.seamLead,xSeamTrail:Te.seamTrail,xFirst:Pt,xLast:mt,mapY:Xe.map,clampHeight:Xe.clamp,yStyle:Xe.style,ySeamLead:Xe.seamLead,ySeamTrail:Xe.seamTrail,yFirst:Wr,yLast:ln,cells:{clampWidth:Ui(Te.clamp,at),clampHeight:Ui(Xe.clamp,qt)},xCellsSizeCss:Gi(at),yCellsSizeCss:Gi(qt),xCellsEndCss:Zi(at),yCellsEndCss:Zi(qt)})}}ie={frozenCols:I.cols,frozenWidth:I.width,frozenRows:I.rows,frozenHeight:I.height,trailingCols:I.trailingCols,trailingWidth:I.trailingWidth,trailingVisibleWidth:I.trailingVisibleWidth,trailingRows:I.trailingRows,trailingHeight:I.trailingHeight,trailingVisibleHeight:I.trailingVisibleHeight,bodyWidth:se,bodyHeight:fe,framed:ue,rowCount:Ye,colCount:Me,rowsTotal:Ie,colsTotal:me,ctxs:ct},le.current=ie}const be=I.width>0,Ee=I.trailingWidth>0,ve=I.height>0,Re=I.trailingHeight>0;for(const de of ie.ctxs)p(de.nodes.container,de.xStyle,de.yStyle),f(de.nodes,de.clampWidth,de.clampHeight),A(de.nodes,0,be),A(de.nodes,1,Ee),A(de.nodes,2,ve),A(de.nodes,3,Re),B(de.nodes,0,de.yCellsEndCss),B(de.nodes,1,de.yCellsEndCss),B(de.nodes,2,de.xCellsEndCss),B(de.nodes,3,de.xCellsEndCss),D(de.nodes,de.xCellsSizeCss,de.yCellsSizeCss);return ie.ctxs},[n,Q,p,f,A,B,D]),oe=i.useCallback((T,z,Y)=>{T.dividerSlots[z]=Y,T.dividerShown[z]=!1,T.dividerEnd[z]="0px",cc(T)},[]),U=i.useCallback((T,z)=>{T.frame=z===null?null:{node:z,x:lo(),y:lo(),drawnX:lo(),drawnY:lo(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},cc(T)},[]),ce=i.useCallback((T,z)=>{for(const I of T.bandPool)ao(I);T.bandPool.length=0,T.dragBand!==null&&(ao(T.dragBand),T.dragBand=null),T.bandClampWidth=-1,T.bandClampHeight=-1,T.bandClip=z,T.bandClipWidth="",T.bandClipHeight="";const Y=z===null?null:z.parentElement;z!==null&&Y!==null&&Y.firstChild!==z&&Y.insertBefore(z,Y.firstChild)},[]),$e=i.useCallback(T=>{const z=()=>Q(T);return{container:Y=>{const I=z();I.container=Y,Y===null&&(I.fillPool.length=0,I.bandPool.length=0,I.dragBand=null,I.bandClampWidth=-1,I.bandClampHeight=-1)},dividerXLeading:Y=>oe(z(),0,Y),dividerXTrailing:Y=>oe(z(),1,Y),dividerYLeading:Y=>oe(z(),2,Y),dividerYTrailing:Y=>oe(z(),3,Y),frame:Y=>U(z(),Y),bandClip:Y=>ce(z(),Y),active:Y=>{z().active=Y},dragRect:Y=>{z().dragRect=Y},marquee:Y=>{z().marquee=Y},fillPreview:Y=>{z().fillPreview=Y},resizeGuide:Y=>{z().resizeGuide=Y}}},[Q,oe,U,ce]),ze=i.useMemo(()=>Object.fromEntries(uc.map(T=>[T,$e(T)])),[$e]),je=Math.min(Math.max(0,G),t.count),pt=uu(t,je),tt=Math.min(Math.max(0,Z),e.count),Ln=du(e,tt),Oe=O===void 0?0:Math.min(Math.max(0,O),t.count-je),He=fu(t,Oe),Ve=F===void 0?0:Math.min(Math.max(0,F),e.count-tt),st=pu(e,Ve),St=i.useRef(null),Yt=i.useRef("add"),We=i.useRef(s);We.current=s;const Et=i.useRef(!1),Ir=ot.useWheelBridge(n,{enableBridge:!s}),Hr=i.useCallback(T=>(r.current=T,Ir(T)),[r,Ir]),zn=i.useCallback((T,z)=>({top:z.mapY(e.offsetOf(T.startRow)),bottom:z.mapY(e.offsetOf(T.endRow)+e.sizeOf(T.endRow)),left:z.mapX(t.offsetOf(T.startCol)),right:z.mapX(t.offsetOf(T.endCol)+t.sizeOf(T.endCol))}),[e,t]),Ft=i.useCallback((T,z)=>{if(z.clampHeight<=0||z.clampWidth<=0)return null;const{top:Y,bottom:I,left:te,right:se}=zn(T,z),fe=-z.clampHeight*Vt,Le=z.clampHeight*(1+Vt),ue=-z.clampWidth*Vt,Ae=z.clampWidth*(1+Vt);if(I<fe||Y>Le||se<ue||te>Ae)return null;const Ye=Math.max(Y,fe),Me=Math.max(te,ue);return{top:Ye,left:Me,width:Math.min(se,Ae)-Me,height:Math.min(I,Le)-Ye}},[zn]),ae=i.useCallback((T,z)=>{if(z.clampHeight<=0||z.clampWidth<=0)return null;const Y=zn(T,z),I=-z.clampHeight*Vt,te=z.clampHeight*(1+Vt),se=-z.clampWidth*Vt,fe=z.clampWidth*(1+Vt),Le=Math.min(Math.max(Y.top,I),te),ue=Math.min(Math.max(Y.left,se),fe);return{top:Le,left:ue,width:Math.min(Math.max(Y.right,se),fe)-ue,height:Math.min(Math.max(Y.bottom,I),te)-Le}},[zn]),Ce=i.useCallback(()=>{if(w===void 0)return null;const T=w.current;return T.row||T.column||T.intersection?T:null},[w]),we=i.useCallback((T,z,Y)=>{if(z.bandClip!==null){for(const te of Hs(Y))z.bandClip.appendChild(te);return}const I=z.fillPool[0]?.node??ic(z);for(const te of Hs(Y))T.insertBefore(te,I)},[]),ar=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),Ne=i.useCallback(T=>{const z=T.nodes.frame;if(z===null)return;const Y=ar.current,I=v.current;(Y.range!==I||Y.rows!==e.count||Y.cols!==t.count)&&(Y.range=I,Y.rows=e.count,Y.cols=t.count,Y.within=I===void 0?null:yg(I,e.count,t.count));const te=Y.within,se=z.last,fe=z.node.style;if(!(te!==null&&ec(z.x,te.startCol,te.endCol,T.xFirst,T.xLast,T.mapX(t.offsetOf(te.startCol)),T.mapX(t.offsetOf(te.endCol)+t.sizeOf(te.endCol)),T.clampWidth)&&ec(z.y,te.startRow,te.endRow,T.yFirst,T.yLast,T.mapY(e.offsetOf(te.startRow)),T.mapY(e.offsetOf(te.endRow)+e.sizeOf(te.endRow)),T.clampHeight))){se.shown&&(se.shown=!1,fe.display="none");return}if(se.shown||(se.shown=!0,fe.display="block"),!tc(z.x,z.drawnX)){nc(z.drawnX,z.x);const Ae=lc(z.x);Ae.start!==se.left&&(se.left=Ae.start,fe.left=Ae.start),Ae.end!==se.right&&(se.right=Ae.end,fe.right=Ae.end),Ae.size!==se.width&&(se.width=Ae.size,fe.width=Ae.size)}if(!tc(z.y,z.drawnY)){nc(z.drawnY,z.y);const Ae=lc(z.y);Ae.start!==se.top&&(se.top=Ae.start,fe.top=Ae.start),Ae.end!==se.bottom&&(se.bottom=Ae.end,fe.bottom=Ae.end),Ae.size!==se.height&&(se.height=Ae.size,fe.height=Ae.size)}const ue=vg(z.x,z.y);ue!==se.open&&(se.open=ue,ue===0?z.node.removeAttribute("data-aqsp-frame-open"):z.node.setAttribute("data-aqsp-frame-open",Rg(ue)))},[e,t]),sn=i.useCallback((T,z,Y,I)=>{const te=ae(z,Y);if(te===null){sc(T);return}Og(T,te,Y,I,ca(z,t.count)||aa(z,e.count))},[ae,e,t]),lt=i.useCallback((T,z,Y,I)=>{const te=T.nodes.bandPool;for(;te.length>Y.length;){const se=te.pop();se!==void 0&&ao(se)}if(I===null){T.nodes.dragBand!==null&&(ao(T.nodes.dragBand),T.nodes.dragBand=null);return}for(let se=0;se<Y.length;se+=1){let fe=te[se];fe===void 0&&(fe=rc(),io(fe,T.clampWidth,T.clampHeight),we(z,T.nodes,fe),te.push(fe)),sn(fe,Y[se],T,I)}},[we,sn]),Nn=i.useCallback((T,z,Y)=>{const I=T.nodes.container;if(I===null)return;if(z===null||Y===null){T.nodes.dragBand!==null&&sc(T.nodes.dragBand);return}let te=T.nodes.dragBand;te===null&&(te=rc(),io(te,T.clampWidth,T.clampHeight),we(I,T.nodes,te),T.nodes.dragBand=te),sn(te,z,T,Y)},[we,sn]),kt=i.useCallback((T,z)=>{if(T!==null){if(z===null){T.style.display="none";return}T.style.display="block",T.style.transform=`translate(${z.left}px, ${z.top}px)`,T.style.width=`${z.width}px`,T.style.height=`${z.height}px`}},[]),Dn=i.useCallback((T,z,Y,I)=>{const te=I==="point"?null:Ce();for(const se of ne(Y,z))kt(se.nodes.dragRect,Ft(T,se)),Nn(se,T,te)},[Ft,ne,kt,Ce,Nn]),Fn=i.useCallback((T,z,Y)=>{for(const I of ne(Y,z))kt(I.nodes.fillPreview,T===null?null:Ft(T,I))},[Ft,ne,kt]),Pn=i.useCallback((T,z,Y)=>{for(const I of ne(Y,z)){const te=I.nodes.resizeGuide;if(te===null)continue;if(T===null){te.style.display="none";continue}const se=T.anchor==="trailing";if(T.axis==="col"){if(se&&I.xKind!=="t"){te.style.display="none";continue}te.style.display="block";const fe=I.mapX(T.position);te.style.transform=`translate(${se?Math.max(0,fe):fe}px, 0px)`,te.style.width="1px",te.style.height="100%"}else{if(se&&I.yKind!=="t"){te.style.display="none";continue}te.style.display="block";const fe=I.mapY(T.position);te.style.transform=`translate(0px, ${se?Math.max(0,fe):fe}px)`,te.style.width="100%",te.style.height="1px"}}},[ne]),qn=i.useCallback((T,z,Y,I,te,se,fe)=>{if(T===null)return;if(z===null||fe<=0||se<=0){T.style.clipPath=oc;return}const Le=Mn(e,z.row,I),ue=$n(t,z.col,Y),Ae=t.sizeOf(z.col),Ye=e.sizeOf(z.row),Me=ue>=se||Le>=fe,Ie=z.col>=te.cols&&ue<te.width,me=z.row>=te.rows&&Le<te.height,ie=te.trailingWidth>0&&z.col<t.count-te.trailingCols&&ue+Ae>se-te.trailingVisibleWidth,be=te.trailingHeight>0&&z.row<e.count-te.trailingRows&&Le+Ye>fe-te.trailingVisibleHeight;if(Me||Ie||me||ie||be){T.style.clipPath=oc;return}T.style.clipPath="",T.style.transform=`translate(${ue}px, ${Le}px)`;const Ee=`${Ae} ${Ye}`;T.dataset.aqspAnchorSig!==Ee&&(T.dataset.aqspAnchorSig=Ee,T.style.width=`${Ae}px`,T.style.height=`${Ye}px`)},[e,t]),Br=i.useCallback((T,z,Y)=>{if(E===void 0)return;const I=E.current,{width:te,height:se}=T.getViewportSize(),fe=T.getFrozenSize(),Le={scroll:Y,frozenCount:fe.cols,trailingCount:fe.trailingCols,extent:te},ue={scroll:z,frozenCount:fe.rows,trailingCount:fe.trailingRows,extent:se};qn(k===void 0?null:k.current,I.interactive,Le,ue,fe,te,se),qn(R===void 0?null:R.current,I.tip,Le,ue,fe,te,se)},[E,k,R,qn]),Vr=i.useCallback(()=>{const T=W.current,z=n.current;if(T===null||z===null)return;const Y=z.getScrollPosition(),I=Math.max(0,Y.y),te=Math.max(0,Y.x),se=o(),fe=ne(te,I),Le=Ce(),ue=Le===null?Ag:se.ranges.slice(-kg(fe.length));for(const me of fe){const ie=me.nodes.container;if(ie===null)continue;const be=me.nodes.fillPool;for(let Ee=0;Ee<Math.max(be.length,se.ranges.length);Ee+=1){let ve=be[Ee];if(ve===void 0){const De=document.createElement("div");De.className="aqsp-selection-fill",De.setAttribute("data-aqsp-fill",""),De.style.display="none",ie.insertBefore(De,ic(me.nodes)),ve={node:De,last:{shown:!1,width:-1,height:-1,transform:""}},be.push(ve)}const Re=se.ranges[Ee],de=Re===void 0?null:Ft(Re,me);if(de===null)ve.last.shown&&(ve.last.shown=!1,ve.node.style.display="none");else{ve.last.shown||(ve.last.shown=!0,ve.node.style.display="block");const De=`translate(${de.left}px, ${de.top}px)`;De!==ve.last.transform&&(ve.last.transform=De,ve.node.style.transform=De),de.width!==ve.last.width&&(ve.last.width=de.width,ve.node.style.width=`${de.width}px`),de.height!==ve.last.height&&(ve.last.height=de.height,ve.node.style.height=`${de.height}px`)}}for(;be.length>se.ranges.length;)be.pop()?.node.remove();kt(me.nodes.active,Ft(he(se.active,se.active),me)),Ne(me),lt(me,ie,ue,Le)}const Ae=u(),Ye=Ae===null||Ae.foreign?null:Ae;for(const me of fe){const ie=me.nodes.marquee;if(ie===null)continue;const be=Ye===null?null:Ft(Ye.range,me),Ee=be!==null&&(me.xSeamTrail&&be.left>=me.clampWidth&&be.left<me.clampWidth+xr||me.xSeamLead&&be.left+be.width<=0&&be.left+be.width>-xr||me.ySeamTrail&&be.top>=me.clampHeight&&be.top<me.clampHeight+xr||me.ySeamLead&&be.top+be.height<=0&&be.top+be.height>-xr)?null:be;if(Ee===null)ie.style.display="none";else{ie.style.display="block",ie.style.transform=`translate(${Ee.left}px, ${Ee.top}px)`,ie.style.width=`${Ee.width}px`,ie.style.height=`${Ee.height}px`;const de=so(Ee.top),De=so(Ee.left),ht=so(me.cells.clampHeight-(Ee.top+Ee.height)),it=so(me.cells.clampWidth-(Ee.left+Ee.width)),ct=`${de} ${it} ${ht} ${De}`;ct!==ie.dataset.aqspOutsetSig&&(ie.dataset.aqspOutsetSig=ct,ie.style.setProperty("--aqsp-clip-outset-top",de),ie.style.setProperty("--aqsp-clip-outset-right",it),ie.style.setProperty("--aqsp-clip-outset-bottom",ht),ie.style.setProperty("--aqsp-clip-outset-left",De))}const ve=Ee===null?null:Ye?.kind??null,Re=ie.dataset.aqspClipKindLast??null;ve!==Re&&(ve===null?(delete ie.dataset.aqspClipKindLast,ie.removeAttribute("data-aqsp-clip-kind")):(ie.dataset.aqspClipKindLast=ve,ie.setAttribute("data-aqsp-clip-kind",ve)))}St.current!==null&&Dn(St.current,I,te,Yt.current),y.current!==null&&Pn(y.current,I,te),K.current!==null&&Fn(K.current,I,te);const Me=$.current;if(Me!==null&&!C()){const{width:me,height:ie}=z.getViewportSize(),be=se.ranges[se.ranges.length-1];if(!(se.ranges.length===1&&!We.current&&!m())||ie<=0||me<=0)Me.style.display="none";else{const ve=z.getFrozenSize(),Re={scroll:te,frozenCount:ve.cols,trailingCount:ve.trailingCols,extent:me},de={scroll:I,frozenCount:ve.rows,trailingCount:ve.trailingRows,extent:ie},De=be.endCol<ve.cols,ht=be.endRow<ve.rows,it=be.endCol>=t.count-ve.trailingCols,ct=be.endRow>=e.count-ve.trailingRows,Te=$n(t,be.endCol,Re)+t.sizeOf(be.endCol),at=Mn(e,be.endRow,de)+e.sizeOf(be.endRow),Pt=De||it?0:ve.width,mt=ht||ct?0:ve.height,Xe=it?me:me-ve.trailingVisibleWidth,qt=ct?ie:ie-ve.trailingVisibleHeight;at<=mt||at>qt||Te<=Pt||Te>Xe?Me.style.display="none":(Me.style.display="block",Me.style.transform=`translate(${Te-dc+1}px, ${at-dc+1}px)`)}}const Ie=r.current;if(Ie!==null){const me=se.active,{width:ie,height:be}=z.getViewportSize(),Ee=z.getFrozenSize(),ve={scroll:te,frozenCount:Ee.cols,trailingCount:Ee.trailingCols,extent:ie},Re={scroll:I,frozenCount:Ee.rows,trailingCount:Ee.trailingRows,extent:be},de=Mn(e,me.row,Re),De=$n(t,me.col,ve),ht=be>0?Math.min(Math.max(de,0),Math.max(0,be-1)):0,it=ie>0?Math.min(Math.max(De,0),Math.max(0,ie-1)):0;Ie.style.top=`${ht}px`,Ie.style.left=`${it}px`,We.current?(Ie.style.width=`${t.sizeOf(me.col)}px`,Ie.style.height=`${e.sizeOf(me.row)}px`,Ie.style.paddingTop=`${xg(e.sizeOf(me.row),j===void 0?en:j.current)}px`):(Ie.style.width="1px",Ie.style.height="1px",Ie.style.paddingTop="0px");const ct=me.col>=Ee.cols&&De<Ee.width,Te=me.row>=Ee.rows&&de<Ee.height,at=Ee.trailingWidth>0&&me.col<t.count-Ee.trailingCols&&De+t.sizeOf(me.col)>ie-Ee.trailingVisibleWidth,Pt=Ee.trailingHeight>0&&me.row<e.count-Ee.trailingRows&&de+e.sizeOf(me.row)>be-Ee.trailingVisibleHeight,mt=We.current&&de===ht&&De===it&&!ct&&!Te&&!at&&!Pt;mt!==Et.current&&(Et.current=mt,mt?Ie.setAttribute("data-aqsp-editing",""):Ie.removeAttribute("data-aqsp-editing"))}Br(z,I,te)},[n,Ft,ne,kt,Dn,Pn,Fn,u,o,m,C,$,r,e,t,Ce,lt,Ne,j,Br]),_o=i.useCallback((T,z)=>{St.current=T,Yt.current=z;const Y=T===null?"add":z;for(const se of ne(0,0)){const fe=se.nodes.dragRect;if(fe===null)continue;const Le=fe.dataset.aqspDragModeLast??"add";Y!==Le&&(fe.dataset.aqspDragModeLast=Y,Y==="add"?fe.removeAttribute("data-aqsp-drag-mode"):fe.setAttribute("data-aqsp-drag-mode",Y))}const I=n.current;if(T===null||I===null){for(const se of ne(0,0))se.nodes.dragRect!==null&&(se.nodes.dragRect.style.display="none"),Nn(se,null,null);return}const te=I.getScrollPosition();Dn(T,Math.max(0,te.y),Math.max(0,te.x),z)},[n,Dn,ne,Nn]),ur=i.useCallback(T=>{K.current=T;const z=n.current;if(z===null){for(const I of ne(0,0))I.nodes.fillPreview!==null&&(I.nodes.fillPreview.style.display="none");return}const Y=z.getScrollPosition();Fn(T,Math.max(0,Y.y),Math.max(0,Y.x))},[n,Fn,ne]),_n=i.useCallback(T=>{y.current=T;const z=n.current;if(z===null){for(const I of ne(0,0))I.nodes.resizeGuide!==null&&(I.nodes.resizeGuide.style.display="none");return}const Y=z.getScrollPosition();Pn(T,Math.max(0,Y.y),Math.max(0,Y.x))},[n,Pn,ne]);i.useLayoutEffect(()=>{const T=W.current;if(!(T===null||b===void 0))return T.style.setProperty("--aqsp-band-row",b.row),T.style.setProperty("--aqsp-band-column",b.column),T.style.setProperty("--aqsp-band-intersection",b.intersection),T.style.setProperty("--aqsp-band-opacity",String(b.opacity)),()=>{T.style.removeProperty("--aqsp-band-row"),T.style.removeProperty("--aqsp-band-column"),T.style.removeProperty("--aqsp-band-intersection"),T.style.removeProperty("--aqsp-band-opacity")}},[b]),i.useEffect(()=>(c.current=Vr,a.current=_o,L.current=ur,M.current=_n,()=>{c.current=null,a.current=null,L.current=null,M.current=null})),i.useEffect(()=>{Vr()},[Vr,s,je,tt,Oe,Ve]),i.useEffect(()=>{const T=r.current;if(T===null)return;const z=Y=>P(Y);return T.addEventListener("mousedown",z),()=>T.removeEventListener("mousedown",z)},[r,P]);const dr=je>0||Oe>0?[...je>0?[{k:"f",style:{left:0,width:pt}}]:[],{k:"s",style:{left:pt,right:He}},...Oe>0?[{k:"t",style:{right:0,width:He}}]:[]]:[{k:"m",style:{left:0,right:0}}],fr=tt>0||Ve>0?[...tt>0?[{k:"f",style:{top:0,height:Ln}}]:[],{k:"s",style:{top:Ln,bottom:st}},...Ve>0?[{k:"t",style:{bottom:0,height:st}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Ot=T=>T==="m"?0:T==="s"?1:T==="t"?2:3,Ke=dr.flatMap(T=>fr.map(z=>({xk:T.k,yk:z.k,key:`${T.k}${z.k}`,style:{...T.style,...z.style}}))).sort((T,z)=>Ot(T.key[0])+Ot(T.key[1])-(Ot(z.key[0])+Ot(z.key[1]))),jo=T=>T==="mm"?{"data-aqsp-overlay-main":""}:T==="fm"?{"data-aqsp-overlay-frozen":""}:T==="sm"?{"data-aqsp-overlay-scroll":""}:{};return q.jsxs("div",{ref:W,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Pe.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Pe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[Ke.map(({xk:T,yk:z,key:Y,style:I})=>{const te=ze[Y];return q.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":Y,...jo(Y),style:I,ref:te.container,children:[x?q.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:te.bandClip}):null,T==="s"&&je>0?q.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:te.dividerXLeading}):null,T==="s"&&Oe>0?q.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:te.dividerXTrailing}):null,z==="s"&&tt>0?q.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:te.dividerYLeading}):null,z==="s"&&Ve>0?q.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:te.dividerYTrailing}):null,x?q.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:te.frame}):null,q.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:te.active}),q.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:te.dragRect}),q.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:te.marquee}),q.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:te.fillPreview}),q.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:te.resizeGuide})]},Y)}),q.jsx("textarea",{ref:Hr,className:"aqsp-sink","aria-label":V,"aria-readonly":H?"true":void 0,"aria-keyshortcuts":S,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?q.jsx("div",{ref:$,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},mu=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=C=>{l.current=!0;try{C()}finally{l.current=!1}},a=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},u=C=>{if(C.key==="Escape"){C.preventDefault(),c(e.close);return}C.key==="Enter"&&(C.ctrlKey||C.metaKey)&&!C.altKey&&!C.shiftKey&&(C.preventDefault(),a())},m=C=>{l.current||C.relatedTarget instanceof Node&&C.currentTarget.contains(C.relatedTarget)||e.rejected||c(e.close)};return q.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:m,children:[q.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[ye(t,"commentTitle"),q.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:ye(t,"commentCount",e.current.length)})]}),q.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(C=>q.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":C.id,children:[q.jsx("span",{className:"aqsp-popover-comment-author",children:C.author}),q.jsx("time",{className:"aqsp-popover-comment-time",dateTime:C.createdAt,children:C.createdAt}),q.jsx("p",{className:"aqsp-popover-comment-text",children:C.text})]},C.id))}),q.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":ye(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:C=>r(C.currentTarget.value),onKeyDown:u}),q.jsxs("div",{className:"aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:a,children:ye(t,"commentPost")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ye(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},gu=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),a=i.useRef(!1),u=o.trim()===""?null:yn(o),m=o.trim()!==""&&u===null,C=_=>{a.current=!0;try{_()}finally{a.current=!1}},L=()=>{l||m||C(()=>e.commit({text:n===""&&u!==null?u:n,url:u}))},M=_=>{if(_.key==="Escape"){_.preventDefault(),C(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),L())},$=_=>{a.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||C(e.close)};return q.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:$,children:[q.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:ye(t,"linkTitle")}),q.jsxs("label",{className:"aqsp-popover-field",children:[q.jsx("span",{className:"aqsp-popover-field-label",children:ye(t,"linkTextField")}),q.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:M})]}),q.jsxs("label",{className:"aqsp-popover-field",children:[q.jsx("span",{className:"aqsp-popover-field-label",children:ye(t,"linkUrlField")}),q.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown:M})]}),q.jsxs("div",{className:"aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:L,children:ye(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:ye(t,"linkOpen")}):null,q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ye(t,"popoverClose"),onClick:()=>C(e.close),children:"×"})]})]})},To=500,wu=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),a=i.useMemo(()=>{const Z=n.toLowerCase();return e.current.filter(O=>O.toLowerCase().startsWith(Z))},[e.current,n]),u=i.useMemo(()=>a.length>To?a.slice(0,To):a,[a]),m=a.length-u.length,C=u.length===0?-1:Math.min(o,u.length-1),L=Z=>{c.current=!0;try{Z()}finally{c.current=!1}},M=()=>{C<0||L(()=>e.commit(u[C]))},$=Z=>{if(Z.key==="Escape"){Z.preventDefault(),L(e.close);return}if(Z.key==="Enter"){Z.preventDefault(),M();return}if(Z.key==="ArrowDown"){Z.preventDefault(),s(C+1);return}Z.key==="ArrowUp"&&(Z.preventDefault(),s(Math.max(C-1,0)))},_=Z=>{c.current||Z.relatedTarget instanceof Node&&Z.currentTarget.contains(Z.relatedTarget)||L(e.close)},G=Z=>`${l}-${Z}`;return q.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[q.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":ye(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":C<0?void 0:G(C),value:n,onChange:Z=>{r(Z.currentTarget.value),s(0)},onKeyDown:$}),q.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":ye(t,"listTitle"),children:[u.length===0?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:ye(t,"listEmpty")}):u.map((Z,O)=>q.jsx("div",{className:"aqsp-popover-option",id:G(O),role:"option",tabIndex:-1,"aria-selected":O===C,"data-aqsp-list-option":Z,onPointerDown:F=>F.preventDefault(),onClick:()=>L(()=>e.commit(Z)),children:Z},G(O))),m>0?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:ye(t,"listMore",m)}):null]})]})},Cu=({ctx:e,labels:t})=>q.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[q.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),q.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ye(t,"popoverClose"),onClick:e.close,children:"×"})]}),yu=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),a=i.useRef(!1),u=$=>{a.current=!0;try{$()}finally{a.current=!1}},m=()=>{s||u(()=>e.commit(r===""?null:r))},C=()=>{r!==n&&!s?m():u(e.close)},L=$=>{if($.key==="Escape"){$.preventDefault(),e.rejected?u(e.close):C();return}$.key==="Enter"&&($.ctrlKey||$.metaKey)&&!$.altKey&&!$.shiftKey&&($.preventDefault(),m())},M=$=>{a.current||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||e.rejected||C()};return q.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:M,children:[q.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:ye(t,"noteTitle")}),q.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:$=>o($.currentTarget.value),onKeyDown:L}),q.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:ye(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),q.jsxs("div",{className:"aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:ye(t,"noteSave")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ye(t,"popoverClose"),onClick:()=>u(e.close),children:"×"})]})]})},bu=({ctx:e})=>q.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Jt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),fc=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],vu=Object.freeze({all:Jt(fc),values:Jt(["text"]),formats:Jt(["format","borders","cf"]),formulas:Jt(["text","formula"]),noBorders:Jt(fc.filter(e=>e!=="borders")),columnWidths:Jt(["sizes"]),validation:Jt(["validation"]),conditionalFormats:Jt(["cf"]),commentsAndNotes:Jt(["note","comments"])}),pc=Object.freeze({mode:"all"}),Bs=Object.freeze({t:""}),hc=Object.freeze({row:1<<30,col:1<<30}),Lg=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),zg=e=>e.t===""&&e.f===void 0,Ng=e=>e.length>1&&e.startsWith("="),Dg=(e,t,n)=>{switch(n){case"add":return e+t;case"subtract":return e-t;case"multiply":return e*t;case"divide":return e/t}},mc=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Fg=(e,t,n,r)=>{const o=Ng(e),s=e===""?"0":vt(e);if(!o&&s===null)return null;const l=Lg[n];if(t.f!==void 0){const u=Pr(t.f,r),m=u.startsWith("=")?u.slice(1):u;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:mc(Number(s));const c=vt(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${l}(${c})`:mc(Dg(Number(s),a,n))},gc=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Pg=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:gc(e.start),end:gc(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},qg=e=>{const t=Pr(e,hc),n=Fr(t);let r="",o=0,s=!1;for(const l of n){const c=Pg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${pn(c)}`,o=l.end,s=!0)}return s?Do(`${r}${t.slice(o)}`,hc):e},_g=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Bs;const o=r[n];return o===void 0?Bs:o},jg=e=>{const{rows:t,cols:n}=e,r=Ra(qg);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let u=0;u<t;u+=1){const m=_g(e,u,c);let C=m;if(m.f!==void 0){const L=r(m.f);C=L===m.f?m:{...m,f:L}}(C!==m||m===Bs)&&(o=!1),a.push(C)}s.push(a)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},Ig=(e,t)=>!t.formula&&e.f!==void 0||!t.format&&e.fmt!==void 0||!t.validation&&e.val!==void 0||!t.note&&e.note!==void 0||!t.comments&&e.comments!==void 0||!t.hyperlink&&e.link!==void 0,Hg=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},wc=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const u=[];for(const m of c)Ig(m,t)?(u.push(Hg(m,t)),a=!0):u.push(m);a&&(n=!0),r.push(a?u:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},Cc=new WeakMap,Ru=e=>{const t=Cc.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>Dt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:Dt({...s,borders:void 0})),o={canonical:n,borderless:r};return Cc.set(e,o),o},$o=(e,t)=>t===void 0?void 0:e[t],Bg=(e,t,n,r)=>{const o=Ru(e);if(n){const u=$o(o.canonical,t.fmt);return u===void 0?null:u}const s=$o(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const a=Dt(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},Vg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Fg(n.readText(),o,r,n):o.f===void 0?o.t:Pr(o.f,n)},yc=(e,t,n,r,o)=>{const s=vu[r.mode];if(r.skipBlanks===!0&&zg(e))return null;const l={};let c=!1;if(s.text){const a=Vg(e,s.formula&&o.formula,n,r.operation);a!==null&&(l.text=a,c=!0)}if(o.format){if(s.format)l.format=Bg(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=$o(Ru(t).canonical,e.fmt);a!==void 0&&(l.format=a,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const a=$o(t.validations,e.val);l.validation=a===void 0?null:a,c=!0}return c?l:null},bc=(e,t)=>e.length===0?e:t.length===0?[]:e.map(n=>{const r=[];for(const o of t)for(const s of n.ranges)r.push({startRow:o.row+s.startRow,startCol:o.col+s.startCol,endRow:o.row+s.endRow,endCol:o.col+s.endCol});return{...n,ranges:r}}),Wg=["text/html","text/plain"],Kg=(e,t,n)=>{if(e===0||t===0)return 0;const r=Rt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Yg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Xg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Ug=e=>{const t=Array.from(e.types),n=new Map;return{types:t,getData:r=>{const o=n.get(r);if(o!==void 0)return o;const s=e.getData(r);return n.set(r,s),s}}},vc=e=>{const t=e.clipboardData;return t??null},Gg=(e,t)=>{const n=Math.max(e.startRow,t.startRow),r=Math.min(e.endRow,t.endRow),o=Math.max(e.startCol,t.startCol),s=Math.min(e.endCol,t.endCol);return n>r||o>s?null:{startRow:n,startCol:o,endRow:r,endCol:s}},Zg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Gg(l,t);c!==null&&o.push({startRow:c.startRow-t.startRow,startCol:c.startCol-t.startCol,endRow:c.endRow-t.startRow,endCol:c.endCol-t.startCol})}if(o.length===0)continue;const s={sourceRuleId:r.id,ranges:o,condition:r.condition,style:r.style};r.stopIfTrue!==void 0&&(s.stopIfTrue=r.stopIfTrue),n.push(s)}return n},Jg=(e,t,n,r,o)=>{const s=ir(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Do(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(l.fmt=a)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:a,author:u,createdAt:m})=>({text:a,author:u,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=cr(e.getCellHyperlink(r,o));c!==void 0&&(l.link=c)}if(e.getCellValidation!==void 0){const c=e.getCellValidation(r,o);c!==void 0&&(l.val=n.intern(c))}return l},Su=(e,t)=>{const n=ia(),r=Xf(),o=[];for(let s=t.startRow;s<=t.endRow;s+=1){const l=[];for(let c=t.startCol;c<=t.endCol;c+=1)l.push(Jg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Zg(e.getConditionalFormats(),t)}},Rc=e=>e.kind==="cut"?{...e.payload,...Su(e.sourceAdapter,e.range)}:e.payload,Qg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:Js(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),ew=e=>{let t=!1;const n=[];for(const r of e.cells){let o=!1;const s=[];for(const l of r){if(l.link===void 0){s.push(l);continue}const c=yn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:a,...u}=l;s.push(u)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},tw=(e,t,n)=>{const r={row:e,col:t,text:""};return n.format&&(r.format=null),n.note&&(r.note=null),n.comments&&(r.comments=null),n.hyperlink&&(r.hyperlink=null),n.validation&&(r.validation=null),r},nw=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return he({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},rw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(O=>{const F=n.current;if(F===null||O==="format"||O==="annotate")return;const V=r.current;V==="own"||V==="foreign"&&F.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const O=n.current;if(O===null)return;if(O.kind==="copy"){o();return}const F=t.current;F.repaintOverlay(),F.onClipChange?.({kind:"cut",range:O.range,foreign:O.sourceAdapter!==F.adapter})},[o]),c=i.useCallback((O,F,V)=>{const H=t.current;n.current={kind:O,range:F,clipId:V.clipId,sourceAdapter:H.adapter,payload:V},H.repaintOverlay(),H.onClipChange?.({kind:O,range:F,foreign:!1})},[]),a=i.useCallback(O=>{const F=t.current,V=F.adapter,H=Rt(O),S={v:1,rows:H.rows,cols:H.cols,clipId:Js(),...Su(V,O),wholeRows:ca(O,V.colCount),wholeCols:aa(O,V.rowCount)};if(F.resize!==void 0){if(S.wholeCols){const P=[];for(let j=O.startCol;j<=O.endCol;j+=1)P.push(Math.min(F.resize.colAxis.sizeOf(j),Cn));S.colWidths=P}if(S.wholeRows){const P=[];for(let j=O.startRow;j<=O.endRow;j+=1)P.push(Math.min(F.resize.rowAxis.sizeOf(j),Cn));S.rowHeights=P}}return S},[]),u=i.useCallback((O,F)=>{const V=t.current,H=V.getSelection(),S=H.ranges[H.ranges.length-1],P=bt([S]);if(P>V.maxOperationCells)return O.preventDefault(),V.onOperationRejected?.(F,P,"limit"),null;if(F==="cut"&&Or(V.adapter,S))return O.preventDefault(),V.rejectReadOnly({kind:"operation",op:"cut",cellCount:P}),null;H.ranges.length>1&&V.onCopyMultiRange?.();const j=a(S),w=Gc(j),d=vc(O);return d!==null&&(d.setData("text/plain",rn.serializeClipboardTsv(j.cells.map(b=>b.map(E=>E.t)))),d.setData("text/html",ja(j,w)),d.setData(ko,w)),O.preventDefault(),{payload:j,range:S}},[a]),m=i.useCallback((O,F)=>t.current.commitPaste(O,F)!==null,[]),C=i.useCallback((O,F,V)=>{const H=t.current;if(!V.sizes||H.resize===void 0)return;const{rowAxis:S,colAxis:P,resizeTracks:j}=H.resize;if(j===void 0)return;const w=(d,b,E)=>{const k=Xs(b,E,null,{maxOperationCells:H.maxOperationCells,rowHiddenLimit:Ks,axisKind:d});if(!k.ok){H.onOperationRejected?.("resize",k.count,k.reason);return}j(d,k.entries)};if(O.colWidths!==void 0){const d=[];for(let b=F.startCol;b<=F.endCol;b+=1)d.push({index:b,size:O.colWidths[(b-F.startCol)%O.cols]});w("col",P,d)}if(O.rowHeights!==void 0){const d=[];for(let b=F.startRow;b<=F.endRow;b+=1)d.push({index:b,size:O.rowHeights[(b-F.startRow)%O.rows]});w("row",S,d)}},[]),L=i.useCallback((O,F)=>{const V=t.current,H=V.adapter,S=O.payload,P={row:F.startRow,col:F.startCol},j=S.rows*S.cols+bt([O.range]);if(j>V.maxOperationCells)return V.onOperationRejected?.("paste",j,"limit"),"rejected";if(P.row+S.rows>H.rowCount||P.col+S.cols>H.colCount||O.range.endRow>=O.sourceAdapter.rowCount||O.range.endCol>=O.sourceAdapter.colCount)return V.onOperationRejected?.("paste",j,"bounds"),"rejected";const w=_s({rows:S.rows,cols:S.cols},he(P,P),P,H.rowCount,H.colCount);if(w!==null&&Or(H,w))return V.rejectReadOnly({kind:"operation",op:"paste",cellCount:S.rows*S.cols}),"rejected";if(Or(O.sourceAdapter,O.range))return V.rejectReadOnly({kind:"operation",op:"cut",cellCount:bt([O.range])}),"rejected";const d=Rc(O),b=So(H),E=wc(d,b),k={row:0,col:0,readText:()=>ir(H,k.row,k.col).text,readFormat:()=>H.getCellFormat===void 0?void 0:H.getCellFormat(k.row,k.col)},{edits:R,tiles:W}=_i(E.cells,he(P,P),P,H.rowCount,H.colCount,(K,y,X)=>(k.row=O.range.startRow+(y-P.row),k.col=O.range.startCol+(X-P.col),yc(K,E,k,pc,b))),v=So(O.sourceAdapter),x=[];if(dn([O.range],K=>{x.push(tw(K.row,K.col,v))}),O.sourceAdapter===H){if(!m([...x,...R],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const K=V.commitPaste(R,{sameSheet:!1,conditionalFormats:bc(E.conditionalFormats,W)});if(K===null)return"rejected";try{O.sourceAdapter.applyEdits(x,{transaction:K,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(y){V.onEditRejected?.(y,{source:"paste"})}}return V.setSelection({ranges:[he(P,{row:P.row+d.rows-1,col:P.col+d.cols-1})],anchor:P,active:P}),"applied"},[m]),M=i.useCallback((O,F,V)=>{const H=t.current,S=H.adapter,P=A=>(H.onClipboardUnavailable?.(A),"rejected"),j=Qc(O,F);if(j==="none")return F==="menu"?P("empty"):"empty";const w=H.getSelection(),d=w.ranges[w.ranges.length-1],b=V.transpose===!0,E=(A,D)=>{const B=Kg(b?D:A,b?A:D,d);return B>H.maxOperationCells?(H.onOperationRejected?.("paste",B,"limit"),!0):!1};let k,R=null;if(j==="aqsp"){const A=vf(O,F);if(A===null)return P("unreadable");const D=n.current;if(D!==null&&A.clipId===D.clipId&&(R=D),R!==null&&R.kind==="cut"&&Yg(V))return L(R,d);if(E(A.rows,A.cols))return"rejected";if(R!==null){if(R.kind==="cut"&&(R.range.endRow>=R.sourceAdapter.rowCount||R.range.endCol>=R.sourceAdapter.colCount))return H.onOperationRejected?.("paste",R.payload.rows*R.payload.cols,"bounds"),"rejected";k=Rc(R)}else{const B=Rf(O,F);if(B===null)return P("unreadable");if(E(B.rows,B.cols))return"rejected";k=ew(B)}}else if(j==="tsv"){const A=O.getData("text/plain"),D=rn.measureTsv(A);if(E(D.rows,D.cols))return"rejected";k=Qg(rn.parseTsv(A))}else{const A=O.getData("text/html"),D=Yf(A);if(D.cols===0&&D.rows>H.maxOperationCells)return H.onOperationRejected?.("paste",D.rows,"limit"),"rejected";if(E(D.rows,D.cols))return"rejected";const B=Va(A,j,H.formats===void 0?{}:{currency:H.formats.currency,locale:H.formats.locale},H.maxOperationCells);if(B.outcome==="none")return P("unreadable");if(B.outcome==="limit")return H.onOperationRejected?.("paste",B.cells,"limit"),"rejected";if(E(B.payload.rows,B.payload.cols))return"rejected";k=B.payload}const W=So(S),v=wc(b?jg(k):k,W),x=vu[V.mode];if(Xg(x)){const A=_s({rows:v.rows,cols:v.cols},d,w.active,S.rowCount,S.colCount);if(A!==null&&Or(S,A))return H.rejectReadOnly({kind:"operation",op:"paste",cellCount:bt([A])}),"rejected"}const K={row:0,col:0,readText:()=>ir(S,K.row,K.col).text,readFormat:()=>S.getCellFormat===void 0?void 0:S.getCellFormat(K.row,K.col)},{edits:y,tiles:X}=_i(v.cells,d,w.active,S.rowCount,S.colCount,(A,D,B)=>(K.row=D,K.col=B,yc(A,v,K,V,W))),Q=nw(X,v.rows,v.cols,S.rowCount,S.colCount);if(Q===null)return"empty";if(x.cf&&v.conditionalFormats.length>0){let A=0;for(const B of v.conditionalFormats)A+=B.ranges.length;const D=X.length*A;if(D>H.maxOperationCells)return H.onOperationRejected?.("paste",D,"limit"),"rejected"}const p=x.cf?bc(v.conditionalFormats,X):[];if(y.length===0&&p.length===0)return C(v,Q,x),"empty";r.current=R===null?"foreign":"own";let f=!1;try{f=m(y,{sameSheet:R!==null&&R.sourceAdapter===S,conditionalFormats:p})}finally{r.current="none"}if(!f)return"rejected";C(v,Q,x);const g={row:Q.startRow,col:Q.startCol};return H.setSelection({ranges:[Q],anchor:g,active:g}),"applied"},[L,m,C]),$=i.useCallback(async O=>{const F=b=>(t.current.onClipboardUnavailable?.(b),"rejected"),V=navigator;if(V.clipboard===void 0)return F("insecure-origin");let H;try{H=await V.clipboard.read({unsanitized:["text/html"]})}catch{return F("permission-denied")}if(H.length===0)return F("empty");const S=H[0],P=Array.from(S.types),j=new Map;try{for(const b of Wg)P.includes(b)&&j.set(b,await(await S.getType(b)).text())}catch{return F("unreadable")}const w={types:P,getData:b=>{const E=j.get(b);if(E===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${b} was not materialised for the menu path`);return E}},d=t.current;return!d.enabled||d.isDragging()||d.isEditing()?"rejected":M(w,"menu",O)},[M]),_=i.useCallback(async O=>{const F=await $(O);return t.current.onPasteResolved?.(F,"menu"),F},[$]),{enabled:G,sinkRef:Z}=e;return i.useEffect(()=>{const O=Z.current;if(!G||O===null)return;const F=P=>t.current.isDragging()?(P.preventDefault(),!0):!1,V=P=>{const j=t.current;if(F(P)||j.isEditing())return;const w=u(P,"copy");w!==null&&c("copy",w.range,w.payload)},H=P=>{const j=t.current;if(F(P)||j.isEditing())return;const w=u(P,"cut");w!==null&&c("cut",w.range,w.payload)},S=P=>{const j=t.current;if(F(P)||j.isEditing())return;P.preventDefault();let w=pc;const d=j.pendingPasteOptionsRef;d!==void 0&&d.current!==null&&(w=d.current,d.current=null);const b=vc(P);if(b===null)return;const E=M(Ug(b),"event",w);j.onPasteResolved?.(E,"event")};return O.addEventListener("copy",V),O.addEventListener("cut",H),O.addEventListener("paste",S),()=>{O.removeEventListener("copy",V),O.removeEventListener("cut",H),O.removeEventListener("paste",S)}},[G,Z,u,c,M]),i.useMemo(()=>({getClip:()=>{const O=n.current;return O===null?null:{kind:O.kind,range:O.range,foreign:O.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},Eu=e=>{if(e!==2&&e!==3&&e!==-2&&e!==-3)throw new RangeError(`[spreadsheet] self-calc exponent must be 2, 3, -2 or -3; got ${String(e)}`)},ku=e=>{let t=e,n=!1;t.startsWith("-")?(n=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));const r=t.search(/[eE]/);let o=null;r>=0&&(o=Number(t.slice(r+1)),t=t.slice(0,r));const s=t.indexOf("."),l=s<0?t:t.slice(0,s),c=s<0?"":t.slice(s+1);return{negative:n,digits:l+c,point:l.length,exponent:o}},Sc=(e,t,n)=>{let r,o;return n<=0?(r="0",o="0".repeat(-n)+t):n>=t.length?(r=t+"0".repeat(n-t.length),o=""):(r=t.slice(0,n),o=t.slice(n)),r=r.replace(/^0+(?=\d)/,""),o=o.replace(/0+$/,""),r==="0"&&o===""?"0":`${e?"-":""}${r}${o===""?"":`.${o}`}`},Ou=(e,t)=>{let n;if(e.exponent===null)n=Sc(e.negative,e.digits,e.point+t);else{const r=Sc(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return vt(n)===null?null:n},ow=(e,t)=>{Eu(t);const n=vt(e);return n===null?null:Ou(ku(n),t)},sw=e=>{const t=vt(e);if(t!==null){const r=ku(t);return Ou({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},xu=e=>{if(!e.startsWith("=")||e.length===1)throw new RangeError(`[spreadsheet] self-calc expects a formula ("=" followed by a body); got ${JSON.stringify(e)}`);return e.slice(1)},lw=e=>{let t=0,n=null;for(let r=0;r<e.length;r++){const o=e[r];if(n!==null){o===n&&(n=null);continue}if(o==='"'||o==="'")n=o;else if(o==="(")t++;else if(o===")"&&(t--,t<0))return!1}return n===null&&t===0},Au=(e,t,n)=>{if(e.length<=t.length+n.length||!e.startsWith(t)||!e.endsWith(n))return null;const r=e.slice(t.length,e.length-n.length);return lw(r)?r:null},iw=(e,t)=>{Eu(t);const n=xu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Au(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},cw=e=>{const t=xu(e),n=Au(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Rr=(e,t,n,r)=>{const o=bt(t);return o>n?(r?.(e,o,"limit"),!1):!0},uo={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},fo={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Ec={bold:{kind:"toggle",key:"bold"},italic:{kind:"toggle",key:"italic"},underline:{kind:"toggle",key:"underline"},strikethrough:{kind:"toggle",key:"strikethrough"},clearFormatting:{kind:"clear"},alignLeft:{kind:"patch",patch:{align:"left"}},alignCenter:{kind:"patch",patch:{align:"center"}},alignRight:{kind:"patch",patch:{align:"right"}},formatNumber:{kind:"value",value:"number"},formatTime:{kind:"value",value:"time"},formatDate:{kind:"value",value:"date"},formatCurrency:{kind:"value",value:"currency"},formatPercent:{kind:"value",value:"percent"},formatScientific:{kind:"value",value:"scientific"},bordersOuter:{kind:"borders",preset:"outer"},bordersClear:{kind:"borders",preset:"clear"},borderTop:{kind:"borders",preset:"top"},borderRight:{kind:"borders",preset:"right"},borderBottom:{kind:"borders",preset:"bottom"},borderLeft:{kind:"borders",preset:"left"},insertLink:{kind:"popover",popover:"link"},insertNote:{kind:"popover",popover:"note"},insertComment:{kind:"popover",popover:"comment"},openHyperlink:{kind:"openHyperlink"},openValidationList:{kind:"popover",popover:"list"},pasteSpecial:{kind:"pasteSpecial"},fillDown:{kind:"fill",direction:"down"},fillRight:{kind:"fill",direction:"right"},fillSelection:{kind:"fill",direction:"selection"},insertDate:{kind:"insertNow",unit:"date"},insertTime:{kind:"insertNow",unit:"time"},hideRows:{kind:"hide",axis:"row",hide:!0},hideColumns:{kind:"hide",axis:"col",hide:!0},unhideRows:{kind:"hide",axis:"row",hide:!1},unhideColumns:{kind:"hide",axis:"col",hide:!1},formatGeneral:{kind:"patch",patch:{value:null}},bordersAll:{kind:"borders",preset:"all"},pasteFormats:{kind:"paste",options:{mode:"formats"}},pasteFormulas:{kind:"paste",options:{mode:"formulas"}},pasteAdd:{kind:"paste",options:{mode:"all",operation:"add"}},pasteSubtract:{kind:"paste",options:{mode:"all",operation:"subtract"}},pasteMultiply:{kind:"paste",options:{mode:"all",operation:"multiply"}},pasteDivide:{kind:"paste",options:{mode:"all",operation:"divide"}},multiplyBy100:{kind:"calc",exponent:2},multiplyBy1000:{kind:"calc",exponent:3},divideBy100:{kind:"calc",exponent:-2},divideBy1000:{kind:"calc",exponent:-3},signReversal:{kind:"sign"},fillColorYellow:{kind:"color",key:"background",preset:uo.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:uo.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:uo.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:uo.Red,custom:null},fillColorCustom1:{kind:"color",key:"background",preset:null,custom:0},fillColorCustom2:{kind:"color",key:"background",preset:null,custom:1},fillColorCustom3:{kind:"color",key:"background",preset:null,custom:2},fillColorCustom4:{kind:"color",key:"background",preset:null,custom:3},fillColorCustom5:{kind:"color",key:"background",preset:null,custom:4},fontColorYellow:{kind:"color",key:"color",preset:fo.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:fo.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:fo.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:fo.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},aw={down:"fillDown",right:"fillRight",selection:"fillSelection"},uw={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},Mr=e=>e<10?`0${e}`:String(e),dw=e=>{const t=new Date(e);return`${t.getFullYear()}-${Mr(t.getMonth()+1)}-${Mr(t.getDate())}`},fw=e=>{const t=new Date(e);return`${Mr(t.getHours())}:${Mr(t.getMinutes())}:${Mr(t.getSeconds())}`},pw=(e,t)=>(e.row===t.startRow?1:0)|(e.col===t.endCol?2:0)|(e.row===t.endRow?4:0)|(e.col===t.startCol?8:0),hw=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),mw=e=>e===void 0||e.borders===void 0?{}:e.borders,gw={top:1,right:2,bottom:4,left:8},ww={style:"thin",color:Us},Cw=(e,t)=>{if(e===void 0)return!1;const n=rt(e);return n!==null&&n===rt(t)},yw=(e,t)=>{const n=t===void 0||t.locale===void 0?{}:{locale:t.locale};switch(e){case"number":return{type:"number",decimals:2,grouping:!0,...n};case"time":return{type:"date",pattern:"HH:mm:ss"};case"date":return{type:"date"};case"currency":if(t===void 0)throw new RangeError("[spreadsheet] formatCurrency requires the formats prop (currency)");return{type:"currency",currency:t.currency,decimals:2,...n};case"percent":return{type:"percent",decimals:2,...n};default:return{type:"scientific",decimals:2,...n}}},bw=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const w=t.current;if(w.isEditing()){const d=w.getActive();return[he(d,d)]}return w.getSelection().ranges},[]),r=i.useCallback(()=>{const w=t.current,d=w.getActive();return w.adapter.getCellFormat===void 0?void 0:w.adapter.getCellFormat(d.row,d.col)},[]),o=i.useCallback(w=>{const d=t.current,b=n();if(!Rr("format",b,d.maxOperationCells,d.onOperationRejected))return!1;if(Qn(d.adapter,b))return d.rejectReadOnly({kind:"operation",op:"format",cellCount:bt(b)}),!1;const E=new Map,k=[],R=d.adapter.getCellFormat;for(const W of b)dn([W],v=>{const x=R===void 0?void 0:R(v.row,v.col),{bucket:K,patch:y}=w(v,W,x);let X=E.get(K);X===void 0&&(X=new Map,E.set(K,X));let Q;X.has(x)?Q=X.get(x):(Q=Zs(x,y),X.set(x,Q)),Q!==x&&k.push({row:v.row,col:v.col,format:Q===void 0?null:Q})});return k.length===0?!0:d.commitEdits(k,{source:"format"})===null?!1:(d.isEditing()&&d.refreshEditPaint(),!0)},[n]),s=i.useCallback(w=>o(()=>({bucket:0,patch:w})),[o]),l=i.useCallback((w,d)=>{const b=t.current;b.formatCommandAnnouncement!==void 0&&b.announce(b.formatCommandAnnouncement({command:w,state:d}))},[]),c=i.useCallback((w,d=ww)=>{if(w==="clear")return s({borders:null});if(w==="all")return s({borders:{top:d,right:d,bottom:d,left:d}});const b=w==="outer"?15:gw[w];return o((E,k,R)=>{const W=pw(E,k)&b;return{bucket:W,patch:{borders:{...mw(R),...hw(W,d)}}}})},[s,o]),a=i.useCallback((w,d,b)=>{const E=Ua(t.current.adapter,w.row,w.col);for(const k of d)b.push(Ga(E,w,k))},[]),u=i.useCallback(w=>{const d=t.current,b=d.getSelection();if(!Rr("fill",b.ranges,d.maxOperationCells,d.onOperationRejected))return!1;const E=[],k=[],R=[];if(w==="selection"){const v=b.active,x=[];dn(b.ranges,K=>{(K.row!==v.row||K.col!==v.col)&&x.push(K)}),E.push({source:v,targets:x}),k.push(he(v,v));for(const K of b.ranges)R.push(...lm(K,v))}else for(const v of b.ranges)if(w==="down"){const x=v.startRow===v.endRow;if(x&&v.startRow===0)continue;const K=x?v.startRow-1:v.startRow,y=x?v.startRow:v.startRow+1;k.push(he({row:K,col:v.startCol},{row:K,col:v.endCol})),R.push(he({row:y,col:v.startCol},{row:v.endRow,col:v.endCol}));for(let X=v.startCol;X<=v.endCol;X+=1){const Q=[];for(let p=y;p<=v.endRow;p+=1)Q.push({row:p,col:X});E.push({source:{row:K,col:X},targets:Q})}}else{const x=v.startCol===v.endCol;if(x&&v.startCol===0)continue;const K=x?v.startCol-1:v.startCol,y=x?v.startCol:v.startCol+1;k.push(he({row:v.startRow,col:K},{row:v.endRow,col:K})),R.push(he({row:v.startRow,col:y},{row:v.endRow,col:v.endCol}));for(let X=v.startRow;X<=v.endRow;X+=1){const Q=[];for(let p=y;p<=v.endCol;p+=1)Q.push({row:X,col:p});E.push({source:{row:X,col:K},targets:Q})}}for(const v of E)for(const x of v.targets)if(et(d.adapter,x.row,x.col))return d.rejectReadOnly({kind:"operation",op:"fill",cellCount:bt(R),gesture:aw[w],sources:k,targets:R}),!1;const W=[];for(const v of E)a(v.source,v.targets,W);return W.length===0?!0:d.commitEdits(W,{source:"fill"})!==null},[a]),m=i.useCallback(()=>{const w=t.current,d=w.getSessionText();if(d===null)return!1;const b=w.getSelection();if(!Rr("fill",b.ranges,w.maxOperationCells,w.onOperationRejected))return!1;if(Qn(w.adapter,b.ranges))return w.rejectReadOnly({kind:"operation",op:"fill",cellCount:bt(b.ranges),gesture:"fillSelection",sources:[],targets:b.ranges}),!1;const E=[];let k=!1;return dn(b.ranges,R=>{if(!k){if(!w.validateCommit(R,d).ok){k=!0;return}E.push({row:R.row,col:R.col,text:d})}}),k||w.commitEdits(E,{source:"fill"})===null?!1:(w.cancelEdit(),!0)},[]),C=i.useCallback(w=>{const d=t.current,b=d.getSelection();if(!Rr("calc",b.ranges,d.maxOperationCells,d.onOperationRejected))return!1;if(Qn(d.adapter,b.ranges))return d.rejectReadOnly({kind:"operation",op:"calc",cellCount:bt(b.ranges)}),!1;const E=[],k=d.adapter;return dn(b.ranges,R=>{const W=k.getCellFormula===void 0?void 0:k.getCellFormula(R.row,R.col),v=W===void 0?w.text(k.getCellText(R.row,R.col)):w.formula(W);v!==null&&E.push({row:R.row,col:R.col,text:v})}),E.length===0?!0:d.commitEdits(E,{source:"calc"})!==null},[]),L=i.useCallback((w,d)=>{const b=t.current,E=b.resizeTracks;if(E===void 0)return!1;const k=w==="row"?b.rowAxis:b.colAxis,R=b.getSelection(),W=w==="row"?Math.floor(b.maxOperationCells/Ys):b.maxOperationCells;let v=0;for(const Q of R.ranges)v+=w==="row"?Q.endRow-Q.startRow+1:Q.endCol-Q.startCol+1;if(v>W)return b.onOperationRejected?.("resize",v,"limit"),!1;const x=new Set,K=[],y=d?0:w==="row"?b.defaultRowHeight:b.defaultColumnWidth;for(const Q of R.ranges){const p=w==="row"?Q.startRow:Q.startCol,f=w==="row"?Q.endRow:Q.endCol;for(let g=p;g<=f;g+=1){if(x.has(g))continue;x.add(g),k.sizeOf(g)===0!==d&&K.push({index:g,size:y})}}const X=Xs(k,K,null,{maxOperationCells:b.maxOperationCells,rowHiddenLimit:Ks,axisKind:w});return X.ok?(X.entries.length>0&&E(w,X.entries),!0):(b.onOperationRejected?.("resize",X.count,X.reason),!1)},[]),M=i.useCallback(()=>{const w=t.current;if(w.adapter.getCellHyperlink===void 0)return;const d=w.getActive();return cr(w.adapter.getCellHyperlink(d.row,d.col))},[]),$=i.useCallback(w=>{const d=t.current,b=d.adapter,E=Ec[w],k=b.getCellFormat!==void 0,R=W=>d.popovers===void 0?!0:d.popovers[W]!==!1;if(E.kind==="popover"&&E.popover==="list"&&d.columnMenu?.isColumnMenuCell(d.getActive())===!0)return!0;switch(E.kind){case"resize":return d.trackResize!==void 0;case"hide":return d.resizeTracks!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return k;case"value":return k&&(E.value!=="currency"||d.formats!==void 0);case"popover":switch(E.popover){case"link":return b.getCellHyperlink!==void 0&&R("link");case"note":return b.getCellNote!==void 0&&R("note");case"comment":return b.getCellComments!==void 0&&R("comment");default:return b.getCellValidation!==void 0&&R("list")}case"openHyperlink":return b.getCellHyperlink!==void 0&&(d.onHyperlinkOpen!==void 0?M()!==void 0:R("link"));case"paste":return E.options.mode==="formats"?k:E.options.mode==="formulas"?b.getCellFormula!==void 0:!0;default:return!0}},[M]),_=i.useCallback(w=>{const d=t.current,b=w.kind==="popover"?w.popover:w.kind==="openHyperlink"&&d.onHyperlinkOpen===void 0?"link":void 0;if(b===void 0)return!0;const E=d.getActive();if(!et(d.adapter,E.row,E.col))return!0;if(b==="list")return d.rejectReadOnly({kind:"edit",cell:E,editSession:"none"}),!1;let k;if(b==="link")k=M()!==void 0;else if(b==="note"){const R=d.adapter.getCellNote===void 0?void 0:d.adapter.getCellNote(E.row,E.col);k=R!==void 0&&R!==""}else{const R=d.adapter.getCellComments===void 0?void 0:d.adapter.getCellComments(E.row,E.col);k=R!==void 0&&R.length>0}return k?!0:(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[M]),G=i.useCallback((w,d,b)=>{const E=t.current,k=E.trackResize;if(k===void 0)return!1;const R=E.getActive(),W=d==="col"?R.col:R.row,v=b==="fit"?k.autofitColumn(W):k.stepTrack(d,W,b),x=(d==="col"?E.colAxis:E.rowAxis).sizeOf(W);return v&&x>0&&E.formatResizeAnnouncement!==void 0&&E.announce(E.formatResizeAnnouncement({command:w,axis:d==="col"?"column":"row",index:W,size:x})),v},[]),Z=i.useCallback(w=>{const d=t.current;if(!$(w))return!1;const b=Ec[w];if(b.kind==="popover"&&b.popover==="list"&&d.columnMenu!==void 0){const k=d.getActive();if(d.columnMenu.isColumnMenuCell(k))return d.columnMenu.open(k)}if(!_(b))return!1;const E=d.isEditing();if(E&&!Ao.has(w)&&!d.requestCommit())return!1;switch(b.kind){case"toggle":{const k=r(),R=k!==void 0&&k[b.key]===!0;return s({[b.key]:R?null:!0})?(l(w,!R),!0):!1}case"patch":return s(b.patch)?(l(w,null),!0):!1;case"clear":return s(uw)?(l(w,null),!0):!1;case"value":return s({value:yw(b.value,d.formats)})?(l(w,null),!0):!1;case"borders":return c(b.preset)?(l(w,null),!0):!1;case"color":{const k=b.key==="background"?d.colors.fill:d.colors.font,R=b.preset!==null?b.preset:b.custom!==null&&b.custom<k.length?k[b.custom]:void 0;if(R===void 0)return!1;const W=r(),v=Cw(W===void 0?void 0:W[b.key],R);return s({[b.key]:v?null:R})?(l(w,!v),!0):!1}case"calc":return C({text:k=>ow(k,b.exponent),formula:k=>iw(k,b.exponent)});case"sign":return C({text:sw,formula:cw});case"fill":return E&&b.direction==="selection"?m():u(b.direction);case"popover":return d.openPopover(b.popover),!0;case"openHyperlink":{if(d.onHyperlinkOpen!==void 0){const k=M();return k===void 0?!1:(d.onHyperlinkOpen(k,d.getActive()),!0)}return d.openPopover("link"),!0}case"pasteSpecial":return d.onPasteSpecialRequest!==void 0?(d.onPasteSpecialRequest({kind:"keyboard",cellRect:d.keyboardCellRect()}),!0):(d.paste({mode:"formats"}),!0);case"paste":return d.paste(b.options),!0;case"insertNow":{const k=b.unit==="date"?dw(d.now()):fw(d.now());if(E)return d.insertAtCaret(k),!0;const R=d.getActive();return et(d.adapter,R.row,R.col)?(d.rejectReadOnly({kind:"edit",cell:R,editSession:"none"}),!1):d.validateCommit(R,k).ok?d.commitEdits([{row:R.row,col:R.col,text:k}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return L(b.axis,b.hide);case"resize":return G(w,b.axis,b.step);default:{const k=d.getHighlight();switch(b.target){case"row":return d.setHighlight({...k,row:!k.row}),!0;case"column":return d.setHighlight({...k,column:!k.column}),!0;case"both":{const R=k.row&&k.column;return d.setHighlight({...k,row:!R,column:!R}),!0}default:return d.setHighlight({...k,intersection:!k.intersection}),!0}}}},[$,_,M,r,s,l,c,C,u,m,L,G]),O=i.useCallback(()=>{const w=t.current;return!(w.isEditing()&&!w.requestCommit())},[]),F=i.useCallback(w=>{const d=t.current;if(d.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const b=w===null?null:yn(w);if(w!==null&&b===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(w)}`);if(!O())return!1;const E=d.getActive();return et(d.adapter,E.row,E.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:E.row,col:E.col,hyperlink:b}],{source:"annotate"})!==null},[O]),V=i.useCallback(w=>{const d=t.current;if(d.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!O())return!1;const b=d.getActive();return et(d.adapter,b.row,b.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:b.row,col:b.col,note:w}],{source:"annotate"})!==null},[O]),H=i.useCallback(w=>{const d=t.current,b=d.adapter.getCellComments;if(b===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!O())return!1;const E=d.getActive();if(et(d.adapter,E.row,E.col))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const k=b(E.row,E.col),R=k===void 0?[w]:[...k,w];return d.commitEdits([{row:E.row,col:E.col,comments:R}],{source:"annotate"})!==null},[O]),S=i.useCallback(w=>{const d=t.current;if(d.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!O())return!1;const b=d.getSelection().ranges;if(!Rr("annotate",b,d.maxOperationCells,d.onOperationRejected))return!1;if(Qn(d.adapter,b))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:bt(b)}),!1;const E=[];return dn(b,k=>{E.push({row:k.row,col:k.col,validation:w})}),d.commitEdits(E,{source:"annotate"})!==null},[O]),P=i.useCallback(w=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(w)},[s]),j=i.useCallback((w,d)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(w,d)},[c]);return i.useMemo(()=>({executeCommand:Z,applyFormat:P,setBorders:j,setHyperlink:F,setNote:V,addComment:H,setValidation:S,isCommandAvailable:$}),[Z,P,j,F,V,H,S,$])},po="data-aqsp-pointing",vw=(e,t)=>{const n=xa(e,t);return n!==null&&"insertAt"in n},Rw=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Sw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(null),u=i.useRef(en),m=i.useCallback(()=>{const v=t.current,x=v.sinkRef.current;if(v.adapter.getCellFormula===void 0||n.current===null||!c.current||x===null)return null;const K=xa(x.value,x.selectionStart);return K===null?null:{sink:x,target:K}},[]),C=i.useCallback(()=>{const v=t.current.sinkRef.current;if(v===null)return;const x=m()!==null;x!==v.hasAttribute(po)&&(x?v.setAttribute(po,""):v.removeAttribute(po))},[m]),L=i.useCallback((v,x)=>{const K=t.current;if(K.resolveEditPaint===void 0)return;const y=K.resolveEditPaint(x),X=y===null?en:y;X!==en&&Object.assign(v.style,X.style),u.current=X,K.editPaintRef!==void 0&&(K.editPaintRef.current=X)},[]),M=i.useCallback(v=>{Rw(v,Object.keys(u.current.style)),u.current=en;const x=t.current.editPaintRef;x!==void 0&&(x.current=en)},[]),$=i.useCallback(v=>{const x=t.current,K=n.current;if(K===null)return!0;const y=()=>{n.current=null,a.current=null;const X=x.sinkRef.current;X!==null&&(X.style.removeProperty("text-align"),M(X),X.removeAttribute(po)),o(!1),x.onSessionChange?.(null)};if(v.commit){const X=x.sinkRef.current,Q=X===null?"":X.value,p=ir(x.adapter,K.cell.row,K.cell.col).text.replace(/\r\n?/g,`
13
+ `),f=Q===p;let g;if(f)g=!0;else if(et(x.adapter,K.cell.row,K.cell.col))x.rejectReadOnly({kind:"edit",cell:K.cell,editSession:v.onReject==="keep"?"kept":"discarded"}),g=!1;else{const A={source:"edit",editSession:v.onReject==="keep"?"kept":"discarded"};g=(x.validateCommit===void 0||x.validateCommit(K.cell,Q).ok)&&x.commitEdits([{row:K.cell.row,col:K.cell.col,text:Q}],A)!==null}if(!g)return v.onReject==="discard"&&(y(),x.rearmSink()),!1}return y(),v.rearm&&x.rearmSink(),!0},[M]),_=i.useCallback((v,x)=>{const K=t.current;if(K.isDragging()||n.current!==null)return;const y=K.sinkRef.current;if(y===null)return;const X=K.getActive();if(et(K.adapter,X.row,X.col)){K.rejectReadOnly({kind:"edit",cell:X,editSession:"none"});return}if(K.discardClip(),K.ensureCellVisible(X),v==="edit"){const{text:f,isFormula:g}=ir(K.adapter,X.row,X.col);y.value=f;const A=x===void 0||g?f.length:Math.min(x,f.length);y.setSelectionRange(A,A)}else y.value="";const Q=K.resolveEditAlign(X);Q!==null&&(y.style.textAlign=Q),L(y,X),c.current=!1,a.current=null;const p={cell:X,mode:v};n.current=p,o(!0),K.onSessionChange?.(p)},[L]),G=i.useCallback(()=>{$({rearm:!0,commit:!1})},[$]),Z=i.useCallback(()=>{const v=t.current;if(n.current===null)return!0;const x=v.sinkRef.current;if(s.current&&x!==null){l.current=!0;try{x.blur()}finally{l.current=!1}return $({rearm:!1,commit:!0,onReject:"keep"})?(v.focusSink(),v.rearmSink(),!0):(v.focusSink(),!1)}return $({rearm:!0,commit:!0,onReject:"keep"})},[$]),O=i.useCallback(()=>m()!==null,[m]),F=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,C(),!0),[C]),V=i.useCallback(()=>{const v=m(),x=n.current;if(v===null||x===null)return null;if("insertAt"in v.target)return a.current=x.cell,{origin:x.cell,cursor:x.cell,axis:"cells"};const K=Oa(v.sink.value,v.sink.selectionStart);if(K===null)return null;const y=K.token,X=a.current;switch(y.kind){case"cell":{const Q={row:y.row,col:y.col};return a.current=Q,{origin:Q,cursor:Q,axis:"cells"}}case"range":{const Q=X!==null&&(X.row===y.start.row||X.row===y.end.row)&&(X.col===y.start.col||X.col===y.end.col)?{row:X.row,col:X.col}:{row:y.start.row,col:y.start.col};return a.current=Q,{origin:Q,cursor:{row:Q.row===y.start.row?y.end.row:y.start.row,col:Q.col===y.start.col?y.end.col:y.start.col},axis:"cells"}}case"column":{const Q=X!==null&&(X.col===y.start.col||X.col===y.end.col)?X.col:y.start.col,p={row:x.cell.row,col:Q};return a.current=p,{origin:p,cursor:{row:x.cell.row,col:Q===y.start.col?y.end.col:y.start.col},axis:"columns"}}case"row":{const Q=X!==null&&(X.row===y.start.row||X.row===y.end.row)?X.row:y.start.row,p={row:Q,col:x.cell.col};return a.current=p,{origin:p,cursor:{row:Q===y.start.row?y.end.row:y.start.row,col:x.cell.col},axis:"rows"}}}},[m]),H=i.useCallback((v,x)=>{const K=m();if(K===null)return;const y=xp(v,x),{sink:X}=K,[Q,p]="replace"in K.target?K.target.replace:[K.target.insertAt,K.target.insertAt],f=X.value;X.value=`${f.slice(0,Q)}${y}${f.slice(p)}`;const g=Q+y.length;X.setSelectionRange(g,g),"row"in v&&(a.current={row:v.row,col:v.col}),C()},[m,C]),S=i.useCallback(()=>{const v=t.current.sinkRef.current;return v===null?null:{value:v.value,selectionStart:v.selectionStart,selectionEnd:v.selectionEnd}},[]),P=i.useCallback(v=>{const x=t.current.sinkRef.current;x!==null&&(x.value=v.value,x.setSelectionRange(v.selectionStart,v.selectionEnd),a.current=null,C())},[C]),j=i.useCallback(()=>{const v=t.current,x=v.sinkRef.current;if(v.adapter.getCellFormula===void 0||n.current===null||x===null)return!1;const K=Pp(x.value,x.selectionStart);return K===null?!1:(x.value=K.text,x.setSelectionRange(K.caret,K.caret),C(),!0)},[C]),w=i.useCallback(v=>{const x=t.current.sinkRef.current;if(n.current===null||x===null)return;const K=x.selectionStart,y=x.selectionEnd;x.value=`${x.value.slice(0,K)}${v}${x.value.slice(y)}`;const X=K+v.length;x.setSelectionRange(X,X),a.current=null,C()},[C]),d=i.useCallback(()=>{const v=t.current.sinkRef.current;return n.current===null||v===null?null:v.value},[]),b=i.useCallback(()=>n.current===null?null:n.current.cell,[]),E=i.useCallback(()=>n.current,[]),k=i.useCallback(()=>{const v=t.current,x=n.current,K=v.sinkRef.current;x===null||K===null||(M(K),L(K,x.cell),v.repaintOverlay?.())},[M,L]),{enabled:R,sinkRef:W}=e;return i.useEffect(()=>{const v=W.current;if(!R||v===null)return;const x=()=>{s.current=!0},K=()=>{s.current=!1},y=p=>{const f=t.current;if(l.current||n.current===null)return;const g=f.rootRef.current,A=p.relatedTarget;g!==null&&A instanceof Node&&g.contains(A)||$({rearm:!1,commit:!0,onReject:"discard"})},X=()=>{const p=t.current;a.current=null,p.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&vw(v.value,v.selectionStart)&&(c.current=!0),C()},Q=()=>{n.current!==null&&C()};return v.addEventListener("compositionstart",x),v.addEventListener("compositionend",K),v.addEventListener("focusout",y),v.addEventListener("input",X),document.addEventListener("selectionchange",Q),()=>{v.removeEventListener("compositionstart",x),v.removeEventListener("compositionend",K),v.removeEventListener("focusout",y),v.removeEventListener("input",X),document.removeEventListener("selectionchange",Q)}},[R,W,$,C]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Z,cancelEdit:G,startEdit:_,getPointing:O,togglePointingArm:F,getReferenceCursor:V,insertReference:H,captureSink:S,restoreSink:P,cycleAnchorAtCaret:j,insertAtCaret:w,getSessionText:d,getSessionCell:b,getSession:E,refreshPaint:k,editing:r}),[Z,G,_,O,F,V,H,S,P,j,w,d,b,E,k,r])},Ew=(e,t,n)=>{const r=new ot.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},kw=(e,t,n)=>{const{tree:r,initialHidden:o}=Ew(e,t,n);let s=o;const a={count:e,sizeOf:u=>r.get(u),offsetOf:u=>{const{cumulative:m,currentValue:C}=r.prefixSum(u);return m-C},indexAt:u=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(u),C=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(C+.5).index},totalSize:()=>r.getTotal(),resize:(u,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const C=Math.round(m);r.get(u)===0!=(C===0)&&(s+=C===0?1:-1),r.update(u,C)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},gn=(e,t,n)=>{if(n>0){const o=e.offsetOf(t)+e.sizeOf(t);return o>=e.totalSize()?null:e.indexAt(o)}const r=e.offsetOf(t)-1;return r<0?null:e.indexAt(r)},rr=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:gn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=gn(e,o,1);return r},kc=(e,t,n)=>{if(!(Number.isInteger(t)&&t>0))throw new TypeError(`[spreadsheet] useAxisModel requires a positive integer defaultSize, received ${t}`);const r=i.useRef(n).current,o=i.useRef(null),s=`${e}:${t}`;return(o.current===null||o.current.key!==s)&&(o.current=kw(e,t,r)),o.current.model},or=256,bs=256,Ow=2**32,xw=4096,Tu=Object.freeze([]),$u=["background","color","bold","italic","underline","strikethrough"],Mu=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},wn=(e,t,n)=>(e.size>=xw&&e.clear(),e.set(t,n),n),Lu=e=>(Mu(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),zu=(e,t,n,r,o)=>{for(const s of e)if(s.startRow<=n&&s.endRow>=t&&s.startCol<=o&&s.endCol>=r)return!0;return!1},Aw=(e,t,n)=>{const r=Math.floor(t/or),o=Math.floor(n/bs),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*or,a=o*bs,u=[];for(const m of e.rules)zu(m.ranges,c,c+or-1,a,a+bs-1)&&u.push(m);return wn(e.buckets,s,u.length===0?Tu:u)},Tw=(e,t,n)=>{const r=Math.floor(t/or),o=r*Ow+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Aw(e,t,n),c=r*or,a=[];for(const u of l)zu(u.ranges,c,c+or-1,n,n)&&a.push(u);return wn(e.columns,o,a.length===0?Tu:a)},$w=(e,t)=>{for(const n of e)if(Wt(n,t))return!0;return!1},ul=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),ho=(e,t)=>e<t?-1:e>t?1:0,Oc=(e,t,n)=>{switch(e){case"eq":return t===0;case"neq":return t!==0;case"gt":return t>0;case"gte":return t>=0;case"lt":return t<0;case"lte":return t<=0;case"between":return n!==null&&t>=0&&n<=0;case"notBetween":return n!==null&&(t<0||n>0);default:return!1}},xc=new WeakMap,Vs=e=>e===null?null:Number(e),Mw=e=>{const t=xc.get(e);if(t!==void 0)return t;const n=e.b,r={a:Vs(vt(e.a)),b:n===void 0?null:Vs(vt(n))};return xc.set(e,r),r},Nu=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:wn(e.numbers,r,Vs(vt(n())))},Lw=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Mw(e),l=Nu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Oc(e.op,ho(l,s.a),c===null?null:ho(l,c));const a=n(),u=e.b;return Oc(e.op,ho(a,e.a),u===void 0?null:ho(a,u))},zw=(e,t)=>{switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);case"endsWith":return t.endsWith(e.value);default:return!1}},vs=e=>{const t=rt(e);if(t===null)return null;const n=r=>Number.parseInt(t.slice(r,r+2),16);return[n(1),n(3),n(5),t.length===9?n(7):255]},mo=e=>e.toString(16).padStart(2,"0"),Rs=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${mo(r(0))}${mo(r(1))}${mo(r(2))}`,s=r(3);return s===255?o:`${o}${mo(s)}`},Ss=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Nw=(e,t,n,r,o)=>{let s=t.value===void 0?o.min:t.value,l=r.value===void 0?o.max:r.value,c=vs(t.color),a=vs(r.color);const u=n===void 0?void 0:vs(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||a===null||u===null)return null;if(s>l){const C=s;s=l,l=C;const L=c;c=a,a=L}if(n!==void 0&&u!==void 0){const C=n.value===void 0?(s+l)/2:n.value;if(s<C&&C<l)return e<=C?Rs(c,u,Ss(e,s,C)):Rs(u,a,Ss(e,C,l))}return Rs(c,a,Ss(e,s,l))},Dw=(e,t,n,r)=>{const o=r.extrema.get(e.id);if(o!==void 0)return o;const{min:s,max:l}=t;if(s.value!==void 0&&l.value!==void 0)return wn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const u of e.ranges){const m=n.getRangeExtrema(u);if(m===null)return wn(r.extrema,e.id,null);c=Math.min(c,m.min),a=Math.max(a,m.max)}return wn(r.extrema,e.id,{min:c,max:a})},Fw=(e,t,n,r,o,s)=>{const l=Nu(s,n,r);if(l===null)return null;const c=Dw(e,t,o,s);return c===null?null:Nw(l,t.min,t.mid,t.max,c)},Pw=(e,t,n,r,o)=>{if(r.evaluateFormula===void 0)return!1;const s=`${e.id}\0${n.row}\0${n.col}`,l=o.formulas.get(s),c=l!==void 0?l:wn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},qw=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Lw(s,t,n,o)?e.style:null;case"text":return zw(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Fw(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Pw(e,s,t,r,o)?e.style:null;default:return null}},Ac=(e,t)=>Zs(e,t),_w=(e,t,n)=>{e[t]=n},jw=(e,t)=>{let n=e;for(const r of $u)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),_w(n,r,t[r]));return n},Iw=e=>{let t="";for(const n of $u){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Tc=new WeakMap,Hw=Object.freeze({}),Bw=e=>{const t=e===void 0?Hw:e,n=Tc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Tc.set(t,r),r},Vw=(e,t,n)=>{const r=Bw(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=Ac(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=Iw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Ac(e,t);return l!==void 0&&wn(r.byKey,o,l),l},dl=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const l=e.getCellFormat(r,o);if(t===null)return l;const c=Tw(t,r,o);if(c.length===0)return l;const a={row:r,col:o};let u=null,m=!0;for(const C of c){if(!$w(C.ranges,a))continue;const L=qw(C,a,s,e,n);if(L!==null){if(L!==C.style&&(m=!1),u===null)u=L;else{const M=jw(u,L);M!==u&&(m=!1,u=M)}if(C.stopIfTrue===!0)break}}return u===null?l:Vw(l,u,m)},$c=new WeakMap,Ww=e=>{Mu(e,"widthRelevantRules");const t=$c.get(e);if(t!==void 0)return t;const n=e.filter(o=>o.style.bold!==void 0||o.style.italic!==void 0||o.stopIfTrue===!0),r=n.length===e.length?e:n;return $c.set(e,r),r},Kw=(e,t,n,r)=>{const o=e.trim()===""?t:`${e} ${t}`;return r?`${o} (${n})`:o},Yw=({col:e,direction:t,filtered:n,expanded:r,columnName:o,menuLabel:s,filteredLabel:l,onToggle:c})=>{const a=i.useRef(null);return i.useEffect(()=>{const u=a.current;if(u===null)return;const m=L=>{L.stopPropagation(),L.preventDefault()},C=L=>{L.stopPropagation()};return u.addEventListener("pointerdown",m),u.addEventListener("dblclick",C),u.addEventListener("contextmenu",C),()=>{u.removeEventListener("pointerdown",m),u.removeEventListener("dblclick",C),u.removeEventListener("contextmenu",C)}},[]),q.jsxs("button",{ref:a,type:"button",className:"aqsp-column-menu-button","data-aqsp-column-menu-button":"",tabIndex:-1,"aria-haspopup":"dialog","aria-expanded":r,"aria-label":Kw(o,s,l,n),onClick:()=>c(e),children:[t===null?null:q.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":t,viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:q.jsx("path",{d:t==="asc"?"M5 1.5 9 8.5H1Z":"M5 8.5 1 1.5h8Z",fill:"currentColor"})}),n?q.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"filter",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:q.jsx("path",{d:"M.5 1h9L6 5.25V9.5L4 8.25v-3Z",fill:"currentColor"})}):q.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"menu",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:q.jsx("path",{d:"M1.5 3.25 5 6.75l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]})},Xw=i.memo(Yw),Uw=Object.freeze({state:!0,onStateChange:!0,getColumnKey:!0,defaults:!0,getColumnOptions:!0,getFilterValues:!0}),Mc=Object.freeze({sortable:!0,filterable:!0,matchModes:!0,defaultMatchMode:!0}),Gw=Object.freeze({sort:!0,filters:!0}),Zw=Object.freeze({columnKey:!0,direction:!0}),Jw=Object.freeze({value:!0,label:!0,count:!0}),Du=Object.freeze(["exact","fuzzy"]),Qw=Object.freeze(["asc","desc"]),_e=e=>typeof e=="string"?JSON.stringify(e):e==null||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):Array.isArray(e)?"an array":typeof e=="function"?"a function":typeof e=="symbol"?"a symbol":"an object",hn=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},mn=(e,t,n)=>{for(const r of Object.keys(e))if(!Object.hasOwn(t,r))throw new RangeError(`[spreadsheet] ${n} has an unknown member ${JSON.stringify(r)}; expected ${Object.keys(t).join(", ")}`)},Lc=(e,t)=>{const{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}=e;if(typeof n!="boolean")throw new RangeError(`[spreadsheet] ${t}.sortable must be true or false (got ${_e(n)})`);if(typeof r!="boolean")throw new RangeError(`[spreadsheet] ${t}.filterable must be true or false (got ${_e(r)})`);if(!Array.isArray(o))throw new RangeError(`[spreadsheet] ${t}.matchModes must be an array of "exact" / "fuzzy" (got ${_e(o)})`);if(o.length===0)throw new RangeError(`[spreadsheet] ${t}.matchModes must not be empty`);const l=new Set;for(const c of o){if(!Du.includes(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds an unknown match mode ${_e(c)}; expected "exact" or "fuzzy"`);if(l.has(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds ${JSON.stringify(c)} twice`);l.add(c)}if(!l.has(s))throw new RangeError(`[spreadsheet] ${t}.defaultMatchMode ${_e(s)} is not one of ${t}.matchModes (${[...l].map(c=>JSON.stringify(c)).join(", ")})`);return{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}},e0=(e,t)=>{if(!hn(e))throw new RangeError(`[spreadsheet] sortFilter.state must be an object with sort and filters (got ${_e(e)})`);mn(e,Gw,"sortFilter.state");const n=(c,a)=>{const u=t.get(c);if(u===void 0)throw new RangeError(`[spreadsheet] ${a} names ${JSON.stringify(c)}, which is not the key of any column`);return u},r=e.sort;let o=null;if(r!==null){if(!hn(r))throw new RangeError(`[spreadsheet] sortFilter.state.sort must be null or { columnKey, direction } (got ${_e(r)})`);mn(r,Zw,"sortFilter.state.sort");const{columnKey:c,direction:a}=r;if(typeof c!="string")throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey must be a string (got ${_e(c)})`);if(!Qw.includes(a))throw new RangeError(`[spreadsheet] sortFilter.state.sort.direction must be "asc" or "desc" (got ${_e(a)})`);const{col:u,column:m}=n(c,"sortFilter.state.sort.columnKey");if(!m.sortable)throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey ${JSON.stringify(c)} names column ${u}, which cannot sort`);o={col:u,direction:a}}const s=e.filters;if(!hn(s))throw new RangeError(`[spreadsheet] sortFilter.state.filters must be an object keyed by column key (got ${_e(s)})`);const l=new Set;for(const c of Object.keys(s)){const a=`sortFilter.state.filters[${JSON.stringify(c)}]`,{col:u,column:m}=n(c,"sortFilter.state.filters");if(!m.filterable)throw new RangeError(`[spreadsheet] ${a} names column ${u}, which cannot filter`);const C=s[c];if(!hn(C))throw new RangeError(`[spreadsheet] ${a} must be { mode: "exact", values } or { mode: "fuzzy", query } (got ${_e(C)})`);const L=C.mode;if(L==="exact"){mn(C,{mode:!0,values:!0},a);const M=C.values;if(!(Array.isArray(M)&&M.every($=>typeof $=="string")))throw new RangeError(`[spreadsheet] ${a}.values must be an array of strings (got ${_e(M)})`)}else if(L==="fuzzy"){if(mn(C,{mode:!0,query:!0},a),typeof C.query!="string")throw new RangeError(`[spreadsheet] ${a}.query must be a string (got ${_e(C.query)})`)}else throw new RangeError(`[spreadsheet] ${a}.mode must be "exact" or "fuzzy" (got ${_e(L)})`);if(!m.matchModes.includes(L))throw new RangeError(`[spreadsheet] ${a}.mode ${JSON.stringify(L)} is not offered by column ${u} (match modes ${m.matchModes.map(M=>JSON.stringify(M)).join(", ")})`);l.add(u)}return{sort:o,filteredColumns:l}},t0=(e,t,n)=>{const r=e;if(!hn(r))throw new RangeError(`[spreadsheet] sortFilter must be an object or absent (got ${_e(r)})`);if(n<1)throw new RangeError(`[spreadsheet] sortFilter needs headerRows of 1 or more: the sort and filter controls sit on the last header row (got headerRows ${n})`);mn(r,Uw,"sortFilter");for(const M of["onStateChange","getColumnKey"])if(typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function (got ${_e(r[M])})`);for(const M of["getColumnOptions","getFilterValues"])if(r[M]!==void 0&&typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function or absent (got ${_e(r[M])})`);const o=r.defaults;if(!hn(o))throw new RangeError(`[spreadsheet] sortFilter.defaults must be an object (got ${_e(o)})`);mn(o,Mc,"sortFilter.defaults");const s=Lc(o,"sortFilter.defaults"),l=[],c=new Map;let a=null,u=!1;for(let M=0;M<t;M++){const $=e.getColumnKey(M);if($===null){l.push(null);continue}if(typeof $!="string"||$==="")throw new RangeError(`[spreadsheet] sortFilter.getColumnKey(${M}) must return a non-empty string or null (got ${_e($)})`);const _=c.get($);if(_!==void 0)throw new RangeError(`[spreadsheet] sortFilter.getColumnKey returned ${JSON.stringify($)} for columns ${_.col} and ${M}; column keys must be unique`);let G=s;if(e.getColumnOptions!==void 0){const O=`sortFilter.getColumnOptions(${JSON.stringify($)})`,F=e.getColumnOptions($);if(!hn(F))throw new RangeError(`[spreadsheet] ${O} must return an object (got ${_e(F)})`);mn(F,Mc,O);const V={...s};for(const H of Object.keys(F))F[H]!==void 0&&(V[H]=F[H]);G=Lc(V,O)}const Z={key:$,...G};l.push(Z),c.set($,{col:M,column:Z}),(G.sortable||G.filterable)&&(u=!0),a===null&&G.filterable&&G.matchModes.includes("exact")&&(a={col:M,column:Z})}if(a!==null&&e.getFilterValues===void 0)throw new RangeError(`[spreadsheet] sortFilter.getFilterValues is required: column ${a.col} (${JSON.stringify(a.column.key)}) can filter by exact match`);const{sort:m,filteredColumns:C}=e0(r.state,c),L=new Map;for(const[M,$]of c)L.set(M,$.col);return{columns:l,columnOfKey:L,headerRow:n-1,sort:m,filteredColumns:C,hasControls:u}},sr=(e,t)=>{const n=e.columns[t];return n!=null&&(n.sortable||n.filterable)?n:null},n0=(e,t)=>e.key===t.key&&e.sortable===t.sortable&&e.filterable===t.filterable&&e.defaultMatchMode===t.defaultMatchMode&&e.matchModes.length===t.matchModes.length&&e.matchModes.every((n,r)=>n===t.matchModes[r]),r0=(e,t)=>e.sort===null||e.sort.columnKey!==t?{sort:{columnKey:t,direction:"asc"},filters:e.filters}:e.sort.direction==="asc"?{sort:{columnKey:t,direction:"desc"},filters:e.filters}:{sort:null,filters:e.filters},o0=(e,t,n)=>n!==null?{sort:{columnKey:t,direction:n},filters:e.filters}:e.sort!==null&&e.sort.columnKey===t?{sort:null,filters:e.filters}:e,fl=(e,t)=>{if(!Object.hasOwn(e.filters,t))return e;const n={};for(const r of Object.keys(e.filters))r!==t&&(n[r]=e.filters[r]);return{sort:e.sort,filters:n}},s0=e=>Object.keys(e.filters).length===0?e:{sort:e.sort,filters:{}},l0=(e,t,n,r)=>{const o=r.filter(s=>n.has(s));return o.length===r.length?fl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"exact",values:o}}}},i0=(e,t,n)=>n.trim()===""?fl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"fuzzy",query:n}}},c0=(e,t)=>e.mode==="fuzzy"||t.mode==="fuzzy"?e.mode==="fuzzy"&&t.mode==="fuzzy"&&e.query===t.query:e.values.length===t.values.length&&e.values.every((n,r)=>n===t.values[r]),a0=(e,t)=>{if(e===t)return!0;if(e.sort===null||t.sort===null?e.sort!==t.sort:e.sort.columnKey!==t.sort.columnKey||e.sort.direction!==t.sort.direction)return!1;const n=Object.keys(e.filters);return n.length!==Object.keys(t.filters).length?!1:n.every(r=>Object.hasOwn(t.filters,r)&&c0(e.filters[r],t.filters[r]))},u0=e=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] sortFilter.getFilterValues must resolve with an array (got ${_e(e)})`);const t=new Set;for(const[n,r]of e.entries()){const o=`sortFilter.getFilterValues()[${n}]`;if(!hn(r))throw new RangeError(`[spreadsheet] ${o} must be { value, label, count } (got ${_e(r)})`);if(mn(r,Jw,o),typeof r.value!="string")throw new RangeError(`[spreadsheet] ${o}.value must be a string (got ${_e(r.value)})`);if(typeof r.label!="string")throw new RangeError(`[spreadsheet] ${o}.label must be a string (got ${_e(r.label)})`);if(!(Number.isInteger(r.count)&&r.count>=0))throw new RangeError(`[spreadsheet] ${o}.count must be a non-negative integer (got ${_e(r.count)})`);if(t.has(r.value))throw new RangeError(`[spreadsheet] ${o}.value ${JSON.stringify(r.value)} repeats an earlier value`);t.add(r.value)}return e},zc=e=>e.normalize("NFKC").toLowerCase(),d0=(e,t)=>zc(e).includes(zc(t)),Fu=e=>e.replace(/\r\n|\r|\n/g," "),f0=({row:e,col:t,text:n,display:r,renderCell:o,__onCellRender:s})=>{const l=i.useRef(!1);if(i.useEffect(()=>{const c=l.current?"update":"mount";l.current=!0,s?.(`cell-${e}-${t}`,c,0,0,0,0)}),o!==void 0){const c=o({row:e,col:t,text:n,displayText:r});return c===void 0?r:c}return r},p0=i.memo(f0),h0=Object.freeze({left:Object.freeze({justifyContent:Ar("left")}),center:Object.freeze({justifyContent:Ar("center")}),right:Object.freeze({justifyContent:Ar("right")})}),m0=Object.freeze({role:"rowgroup"}),g0=4096,Nc=new WeakMap,go=new Map,w0=(e,t)=>{if(e===null)return h0[t];let n=Nc.get(e);n===void 0&&(n={},Nc.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:Ar(t)},s=JSON.stringify(o);let l=go.get(s);return l===void 0&&(go.size>=g0&&go.clear(),l=Object.freeze(o),go.set(s,l)),n[t]=l,l},C0=ul(),y0=(e,t,n)=>{if(e.row!==t||e.col!==n)throw new RangeError(`[spreadsheet] cell renderer (${t}, ${n}) ran without its getCellProps (latched ${e.row}, ${e.col})`);return e.value},b0=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0&&e.getCellNote===void 0&&e.getCellComments===void 0&&e.getCellHyperlink===void 0&&e.getCellValidation===void 0)return null;const l=Ro(e,o,s),c={};let a=null,u;if(e.getCellFormat!==void 0){const m=dl(e,r===null?null:r.indexRef.current,r===null?C0:r.memoRef.current,o,s,l);u=m===void 0?void 0:m.value;const C=Wa(m,l),L=gn(n,s,1),M=gn(t,o,1),$=op(m,L===null?void 0:e.getCellFormat(o,L),M===null?void 0:e.getCellFormat(M,s),n.offsetOf(s)===0,t.offsetOf(o)===0);$!==null&&Object.assign(c,$.attrs),c["data-aqsp-align"]=C,a=w0($,C)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&cr(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&wg(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:u}},v0=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:m,frozenTrailingRows:C,headerRows:L,labelledBy:M,gridLabel:$,readOnly:_,renderCell:G,onScroll:Z,onRangeChange:O,focusSink:F,isEditing:V,requestCommit:H,testId:S,__onCellRender:P,__maxRenderedCells:j,cfIndexRef:w,cfMemoRef:d,isPointing:b,tapScrollCircleOptions:E,showArrowButtons:k,enableThumbDrag:R,enableTrackClick:W,overscanRows:v,overscanCols:x,background:K,onRenderTruncated:y,locale:X,scrollLabels:Q,sortFilter:p,columnMenu:f})=>{const g=i.useRef(null),A=s??g;if(w===void 0!=(d===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const D=i.useMemo(()=>w===void 0||d===void 0?null:{indexRef:w,memoRef:d},[w,d]),B=i.useCallback(()=>r.get().editVersion,[r]),ee=i.useCallback(Oe=>r.subscribeCoalesced(Oe),[r]),ne=i.useSyncExternalStore(ee,B,B)+(l??0),oe=i.useCallback(Oe=>t.sizeOf(Oe),[t]),U=i.useCallback(Oe=>n.sizeOf(Oe),[n]),ce=i.useCallback((Oe,He)=>e.getCellText(Oe,He),[e]),$e=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),ze=i.useMemo(()=>({width:Pe.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:E,enableArrowButtonTabStops:!1,showArrowButtons:k,enableThumbDrag:R,enableTrackClick:W}),[E,k,R,W]),je=i.useRef({row:-1,col:-1,value:void 0}),pt=i.useCallback((Oe,He)=>{const Ve=Oe<L,st={role:Ve?"columnheader":"gridcell","aria-rowindex":Oe+1,"aria-colindex":He+1,"data-aqsp-cell":"","data-row":Oe,"data-col":He,className:"aqsp-cell",...et(e,Oe,He)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Ve?{"data-aqsp-header-row":""}:{},...p==null||Oe!==p.headerRow||sr(p,He)===null?{}:{"data-aqsp-column-controls":"",...p.sort!==null&&p.sort.col===He?{"aria-sort":p.sort.direction==="asc"?"ascending":"descending","data-aqsp-sort":p.sort.direction}:{},...p.filteredColumns.has(He)?{"data-aqsp-filtered":""}:{}}},St=fm(e,Oe,He),Yt=St===null?st:{...st,...St},We=b0(e,t,n,D,Oe,He),Et=je.current;return Et.row=Oe,Et.col=He,Et.value=We===null?void 0:We.value,We===null?Yt:We.style===null?{...Yt,...We.attrs}:{...Yt,...We.attrs,style:We.style}},[e,t,n,D,L,p]),tt=i.useCallback(Oe=>({role:"row","aria-rowindex":Oe+1,"data-aqsp-row":Oe,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Ln=i.useCallback((Oe,He,Ve)=>{let st=Oe;e.getCellFormat!==void 0&&(st=An(Oe,y0(je.current,He,Ve)));const St=q.jsx(p0,{row:He,col:Ve,text:Oe,display:st,renderCell:G,__onCellRender:P});return p==null||f===void 0||f===null||He!==p.headerRow||sr(p,Ve)===null?St:q.jsxs(q.Fragment,{children:[St,q.jsx(Xw,{col:Ve,direction:p.sort!==null&&p.sort.col===Ve?p.sort.direction:null,filtered:p.filteredColumns.has(Ve),expanded:f.openCol===Ve,columnName:Fu(st),menuLabel:f.menuLabel,filteredLabel:f.filteredLabel,onToggle:f.onToggle})]})},[ne,G,P,e,p,f]);return q.jsx("div",{ref:A,className:"aqsp-body","data-aqsp-body":"","data-testid":S?`${S}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":$,"aria-labelledby":M,"aria-readonly":_?"true":void 0,onPointerDownCapture:Oe=>{if(!(Oe.target instanceof Element&&Oe.target.closest("[data-aqsp-cells]")!==null)&&Oe.pointerType==="mouse"){if(Oe.button!==0){Oe.preventDefault();return}if(Oe.preventDefault(),b?.()===!0){Oe.stopPropagation(),F();return}if(V()&&!H()){Oe.stopPropagation(),F();return}F()}},children:q.jsx(ot.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:u,frozenTrailingCols:m,frozenTrailingRows:C,getRowHeight:oe,getColWidth:U,getCell:ce,getCellProps:pt,getRowProps:tt,contentProps:m0,behaviorOptions:$e,scrollBarOptions:ze,overscanRows:v,overscanCols:x,background:K,onRenderTruncated:y,__maxRenderedCells:j,locale:X,labels:Q,callbackThrottleMs:0,onScroll:Z,onRangeChange:O,testId:S,children:Ln})})},R0=i.memo(v0),er=6,yt=3,Mo=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=t[0];o>0&&e.sizeOf(o-1)===0&&r.push({kind:"unhide",index:o-1,start:e.offsetOf(o),length:yt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,a=gn(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-er,length:yt}),r.push({kind:"unhide",index:s+1,start:c-yt,length:yt})):l>=2*er?n.push({kind:"resize",index:s,start:c-er,length:er}):n.push({kind:"resize",index:s,start:c-yt,length:yt})}return[...n,...r]},Pu=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const a=e.sizeOf(c),u=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:u,length:yt}),n.push({kind:"resize",index:c,start:u+yt,length:yt})):a>=2*er?n.push({kind:"resize",index:c,start:u,length:er}):n.push({kind:"resize",index:c,start:u,length:yt})}const l=t[t.length-1];return l<e.count-1&&e.sizeOf(l+1)===0&&r.push({kind:"unhide",index:l+1,start:s-yt,length:yt}),[...n.reverse(),...r]},S0=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:a,selectionRanges:u,enableResizeUI:m,dividerLeadingRef:C,dividerTrailingRef:L})=>{const M=ot.useWheelBridge(o),$=i.useCallback(y=>(s.current=y,M(y)),[s,M]),_=i.useCallback(()=>{const{colStart:y,colEnd:X,colVersion:Q}=e.get();return`${y}:${X}:${Q}`},[e]),G=i.useCallback(y=>e.subscribeCoalesced(y),[e]);i.useSyncExternalStore(G,_,_);const{colStart:Z,colEnd:O}=e.get(),F=t.count===0?0:t.offsetOf(Math.min(Z,t.count-1));i.useLayoutEffect(()=>{c.current=F,a()},[F,c,a]);const V=y=>u.some(X=>y>=X.startCol&&y<=X.endCol),H=Math.min(Math.max(0,n),t.count),S=uu(t,H),P=H>0?rr(t,0,H-1):[],j=Math.min(Math.max(0,r),t.count-H),w=fu(t,j),d=t.totalSize()-w,b=j>0?rr(t,t.count-j,t.count-1):[],E=rr(t,Math.max(Z,H),Math.min(O,Math.max(0,t.count-1)-j)),k=[];for(const y of E)k.push(q.jsx("div",{className:"aqsp-col-header-cell","data-col":y,"data-aqsp-in-selection":V(y)?"":void 0,style:{left:t.offsetOf(y)-F,width:t.sizeOf(y)},children:Pe.columnIndexToName(y)},y));const R=m?Mo(t,E):null,W=R===null?null:R.filter(y=>!(y.kind==="unhide"&&y.index<H&&S>0||y.kind==="unhide"&&y.index>=t.count-j&&w>0)),v=m&&H>0?Mo(t,P):null,x=m&&j>0?Pu(t,b):null,K=q.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,W?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":y.index,style:{left:y.start-F,width:y.length}},`r${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,style:{left:y.start-F,width:y.length}},`u${y.index}`))]});return q.jsx("div",{ref:$,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:H===0&&j===0?K:q.jsxs(q.Fragment,{children:[P.map(y=>q.jsx("div",{className:"aqsp-col-header-cell","data-col":y,"data-aqsp-frozen-header":"","data-aqsp-in-selection":V(y)?"":void 0,style:{left:t.offsetOf(y),width:t.sizeOf(y)},children:Pe.columnIndexToName(y)},y)),v?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":y.index,style:{left:y.start,width:y.length}},`fr${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,style:{left:y.start,width:y.length}},`fu${y.index}`)),q.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:S,right:j>0?`calc(${Pe.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${w}px, max(0px, 100% - ${Pe.SPREADSHEET_SCROLLBAR_SIZE_PX+S}px)))`:void 0},children:[K,H>0?q.jsx("div",{ref:C,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,j>0?q.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),j>0?q.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${S}px, calc(100% - ${w+Pe.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Pe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:q.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:w},children:[b.map(y=>q.jsx("div",{className:"aqsp-col-header-cell","data-col":y,"data-aqsp-trailing-header":"","data-aqsp-in-selection":V(y)?"":void 0,style:{left:t.offsetOf(y)-d,width:t.sizeOf(y)},children:Pe.columnIndexToName(y)},y)),x?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":y.index,"data-aqsp-resize-anchor":"trailing",style:{left:y.start,width:y.length}},`tr${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,"data-aqsp-resize-anchor":"trailing",style:{left:y.start,width:y.length}},`tu${y.index}`))]})}):null]})})},E0=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:a,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:C,dividerTrailingRef:L})=>{const M=ot.useWheelBridge(n),$=i.useCallback(y=>(r.current=y,M(y)),[r,M]),_=y=>o.some(X=>y>=X.startRow&&y<=X.endRow),G=i.useCallback(()=>{const{rowStart:y,rowEnd:X,rowGeomVersion:Q}=e.get();return`${y}:${X}:${Q}`},[e]),Z=i.useCallback(y=>e.subscribeCoalesced(y),[e]);i.useSyncExternalStore(Z,G,G);const{rowStart:O,rowEnd:F}=e.get(),V=t.count===0?0:t.offsetOf(Math.min(O,t.count-1));i.useLayoutEffect(()=>{l.current=V,c()},[V,l,c]);const H=Math.min(Math.max(0,u),t.count),S=du(t,H),P=H>0?rr(t,0,H-1):[],j=Math.min(Math.max(0,m),t.count-H),w=pu(t,j),d=t.totalSize()-w,b=j>0?rr(t,t.count-j,t.count-1):[],E=rr(t,Math.max(O,H),Math.min(F,Math.max(0,t.count-1)-j)),k=[];for(const y of E)k.push(q.jsx("div",{className:"aqsp-row-header-cell","data-row":y,"data-aqsp-in-selection":_(y)?"":void 0,style:{top:t.offsetOf(y)-V,height:t.sizeOf(y)},children:y+1},y));const R=a?Mo(t,E):null,W=R===null?null:R.filter(y=>!(y.kind==="unhide"&&y.index<H&&S>0||y.kind==="unhide"&&y.index>=t.count-j&&w>0)),v=a&&H>0?Mo(t,P):null,x=a&&j>0?Pu(t,b):null,K=q.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,W?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":y.index,style:{top:y.start-V,height:y.length}},`r${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,style:{top:y.start-V,height:y.length}},`u${y.index}`))]});return q.jsx("div",{ref:$,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Pe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:H===0&&j===0?K:q.jsxs(q.Fragment,{children:[P.map(y=>q.jsx("div",{className:"aqsp-row-header-cell","data-row":y,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(y)?"":void 0,style:{top:t.offsetOf(y),height:t.sizeOf(y)},children:y+1},y)),v?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":y.index,style:{top:y.start,height:y.length}},`fr${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,style:{top:y.start,height:y.length}},`fu${y.index}`)),q.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:S,bottom:j>0?`calc(min(${w}px, max(0px, 100% - ${S}px)))`:void 0},children:[K,H>0?q.jsx("div",{ref:C,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,j>0?q.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),j>0?q.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${S}px, calc(100% - ${w}px))`},children:q.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:w},children:[b.map(y=>q.jsx("div",{className:"aqsp-row-header-cell","data-row":y,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(y)?"":void 0,style:{top:t.offsetOf(y)-d,height:t.sizeOf(y)},children:y+1},y)),x?.map(y=>y.kind==="resize"?q.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":y.index,"data-aqsp-resize-anchor":"trailing",style:{top:y.start,height:y.length}},`tr${y.index}`):q.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":y.index,"data-aqsp-resize-anchor":"trailing",style:{top:y.start,height:y.length}},`tu${y.index}`))]})}):null]})})},k0=9,O0=4,Dc=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,a=`${o} ${s} ${l} ${c}`;return t.set(e,a),a},Fc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,x0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),a=i.useRef(null),u=i.useRef(""),m=i.useRef(null),C=i.useCallback(w=>s.current!==null?w.pointerId===s.current:w.pointerType==="mouse",[]),L=i.useCallback(()=>{const w=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),w.writeResizeGuide(null);const d=m.current;d!==null&&(window.removeEventListener("pointermove",d.move),window.removeEventListener("pointerup",d.up),m.current=null);const b=c.current;b!==null&&s.current!==null&&b.hasPointerCapture?.(s.current)&&b.releasePointerCapture(s.current),c.current=null,s.current=null,w.repaintOverlay()},[]),M=i.useCallback((w,d)=>{const b=t.current;return w==="col"?d.startRow===0&&d.endRow===b.rowAxis.count-1:d.startCol===0&&d.endCol===b.colAxis.count-1},[]),$=i.useCallback((w,d)=>{const b=t.current,E=b.getSelection().ranges.filter(x=>M(w,x));if(!E.some(x=>w==="col"?d>=x.startCol&&d<=x.endCol:d>=x.startRow&&d<=x.endRow))return[d];const R=E.reduce((x,K)=>x+(w==="col"?K.endCol-K.startCol+1:K.endRow-K.startRow+1),0),W=w==="row"?Math.floor(b.maxOperationCells/Ys):b.maxOperationCells;if(R>W)return b.onOperationRejected?.("resize",R,"limit"),null;const v=new Set;for(const x of E){const K=w==="col"?x.startCol:x.startRow,y=w==="col"?x.endCol:x.endRow;for(let X=K;X<=y;X+=1)v.add(X)}return[...v]},[M]),_=i.useCallback((w,d,b)=>{const E=t.current,k=w==="col"?E.colAxis:E.rowAxis,R=Xs(k,d,b,{maxOperationCells:E.maxOperationCells,rowHiddenLimit:Ks,axisKind:w});return R.ok?(E.resizeTracks(w,R.entries),!0):(E.onOperationRejected?.("resize",R.count,R.reason),!1)},[]),G=i.useCallback((w,d)=>{if(d===w.initialSize)return;const b=w.kind==="unhide"?[w.index]:$(w.axis,w.index);b!==null&&_(w.axis,b.map(E=>({index:E,size:d})),w.index)},[$,_]),Z=i.useCallback((w,d,b,E)=>{const k=t.current,R=k.fontSourceRef.current;if(R===null)return!1;if(d.length===0)return!0;const W=w.length*d.length;if(W>b)return k.onOperationRejected?.("resize",W,"limit"),!1;const v=document.createElement("canvas").getContext("2d");if(v===null)return!0;const x=getComputedStyle(R),K=`${x.fontStyle} ${x.fontWeight} ${x.fontSize} ${x.fontFamily}`,y=x.getPropertyValue("--_aqsp-header-row-font-weight").trim(),X={fontStyle:x.fontStyle,fontWeight:y===""?x.fontWeight:y,fontSize:x.fontSize,fontFamily:x.fontFamily},Q=`${X.fontStyle} ${X.fontWeight} ${X.fontSize} ${X.fontFamily}`,p=k.adapter.getConditionalFormats===void 0?null:Ww(k.adapter.getConditionalFormats()),f=ul(),g=new WeakMap,A=new WeakMap,D=new Map;for(const ne of w){const oe=p===null?null:Lu(p.filter(U=>U.ranges.some(ce=>ne>=ce.startCol&&ne<=ce.endCol)));for(const U of d){const ce=k.adapter.getCellText(U,ne),$e=k.adapter.getCellFormat===void 0?void 0:dl(k.adapter,oe,f,U,ne,()=>ce),ze=U<k.headerRows,je=$e===void 0?ze?Q:K:ze?Dc($e,A,X):Dc($e,g,x),pt=An(ce,$e===void 0?void 0:$e.value),tt=D.get(je);tt===void 0?D.set(je,[{col:ne,text:pt}]):tt.push({col:ne,text:pt})}}const B=R.ownerDocument.createElement("span");B.setAttribute("aria-hidden","true"),B.style.position="absolute",B.style.visibility="hidden",R.append(B);const ee=new Map;for(const[ne,oe]of D){v.font=ne,B.style.font=ne;const U=getComputedStyle(B);v.letterSpacing=U.letterSpacing==="normal"?"0px":U.letterSpacing,v.wordSpacing=U.wordSpacing==="normal"?"0px":U.wordSpacing;for(const ce of oe){const $e=v.measureText(ce.text).width,ze=ee.get(ce.col);(ze===void 0||$e>ze)&&ee.set(ce.col,$e)}}B.remove();const le=[];for(const ne of w){const oe=ee.get(ne);oe!==void 0&&oe>0&&le.push({index:ne,size:Math.ceil(oe)+k0})}return le.length===0?!0:_("col",le,E)},[_]),O=i.useCallback(w=>{const d=t.current,b=$("col",w);if(b===null)return!1;const E=d.handleRef.current,k=E===null?null:E.getFrozenSize(),R=k===null?0:k.rows,W=k===null?0:k.trailingRows,{rowStart:v,rowEnd:x}=d.viewStore.get(),K=Math.min(x,d.rowAxis.count-1),y=[],X=new Set,Q=p=>{!X.has(p)&&d.rowAxis.sizeOf(p)>0&&(X.add(p),y.push(p))};for(let p=0;p<R;p+=1)Q(p);for(let p=v;p<=K;p+=1)Q(p);for(let p=d.rowAxis.count-W;p<d.rowAxis.count;p+=1)Q(p);return Z(b,y,Math.floor(d.maxOperationCells/O0),w)},[$,Z]),F=i.useCallback((w,d,b)=>{const E=w==="col"?t.current.colAxis:t.current.rowAxis,k=Td(E.sizeOf(d),b);if(k===E.sizeOf(d))return!0;const R=$(w,d);return R===null?!1:_(w,R.map(W=>({index:W,size:k})),d)},[$,_]),V=i.useCallback(w=>{const d=t.current;return d.autofitEnabled?d.colAxis.sizeOf(w)===0?!0:O(w):!1},[O]),H=i.useCallback(w=>{const d=t.current;if(!d.autofitEnabled)return!1;const b=[...new Set(w)].filter(k=>d.colAxis.sizeOf(k)>0);if(b.length===0)return!0;const E=[];for(let k=0;k<d.rowAxis.count;k+=1)d.rowAxis.sizeOf(k)>0&&E.push(k);return Z(b,E,d.maxOperationCells,null)},[Z]),{enabled:S,colBandRef:P,rowBandRef:j}=e;return i.useEffect(()=>{const w=P.current,d=j.current;if(!S||w===null||d===null)return;const b=g=>g==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",E=(g,A)=>{if(!(A instanceof Element))return null;const D=A.closest(b(g));if(D===null)return null;const B=D.hasAttribute("data-aqsp-unhide"),ee=Number(D.getAttribute(B?"data-aqsp-unhide":g==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),le=D.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:B?"unhide":"resize",index:ee,anchor:le}},k=g=>{if(!(n.current&&C(g)))return;const A=r.current;if(A===null)return;const D=(A.axis==="col"?g.clientX-A.startClientX:g.clientY-A.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(A.anchor==="trailing"?A.initialSize-D:A.initialSize+D)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const B=r.current;if(!n.current||B===null)return;const ee=t.current,le=B.axis==="col"?ee.colAxis:ee.rowAxis;ee.writeResizeGuide({axis:B.axis,position:Fc(B,le,o.current),anchor:B.anchor})}))},R=()=>{const g=r.current,A=o.current;L(),g!==null&&G(g,A)},W=g=>{k(g),n.current&&C(g)&&(l.current&1)!==0&&(g.buttons&1)===0&&R()},v=g=>{g.button!==0||!(n.current&&C(g))||R()},x=(g,A)=>D=>{const B=t.current;if(u.current=D.pointerType,D.pointerType!=="mouse")return;if(D.button!==0){D.preventDefault();return}const ee=E(g,D.target);if(ee===null)return;if(D.stopPropagation(),D.preventDefault(),B.isPointing()){B.focusSink();return}if(B.isEditing()&&!B.requestCommit()){B.focusSink();return}B.focusSink();const le=g==="col"?B.colAxis:B.rowAxis,ne={axis:g,kind:ee.kind,index:ee.index,anchor:ee.anchor,initialSize:le.sizeOf(ee.index),startClientX:D.clientX,startClientY:D.clientY};r.current=ne,o.current=ne.initialSize,l.current=D.buttons,n.current=!0,B.repaintOverlay(),s.current=D.pointerId,c.current=A;try{A.setPointerCapture(D.pointerId)}catch{s.current=null}const oe=W,U=v;m.current={move:oe,up:U},window.addEventListener("pointermove",oe),window.addEventListener("pointerup",U),B.writeResizeGuide({axis:g,position:Fc(ne,le,o.current),anchor:ne.anchor})},K=(g,A)=>D=>{const B=t.current;if(u.current!=="mouse")return;const ee=A.getRootNode(),le=ee instanceof ShadowRoot?ee:A.ownerDocument,ne=D.target instanceof Element&&D.target.closest(b(g))!==null?D.target:typeof le.elementFromPoint=="function"?le.elementFromPoint(D.clientX,D.clientY):null,oe=E(g,ne);if(oe!==null){if(D.stopPropagation(),B.isEditing()){B.focusSink();return}if(oe.kind==="unhide"){_(g,[{index:oe.index,size:g==="col"?B.defaultColumnWidth:B.defaultRowHeight}],null);return}if(B.autofitEnabled){if(g==="row"){const U=$("row",oe.index);U!==null&&_("row",U.map(ce=>({index:ce,size:B.defaultRowHeight})),oe.index);return}O(oe.index)}}},y=g=>{!n.current||s.current===null||g.pointerId!==s.current||L()},X=x("col",w),Q=x("row",d),p=K("col",w),f=K("row",d);return w.addEventListener("pointerdown",X,{capture:!0}),d.addEventListener("pointerdown",Q,{capture:!0}),w.addEventListener("dblclick",p),d.addEventListener("dblclick",f),w.addEventListener("lostpointercapture",y),d.addEventListener("lostpointercapture",y),()=>{w.removeEventListener("pointerdown",X,{capture:!0}),d.removeEventListener("pointerdown",Q,{capture:!0}),w.removeEventListener("dblclick",p),d.removeEventListener("dblclick",f),w.removeEventListener("lostpointercapture",y),d.removeEventListener("lostpointercapture",y),L()}},[S,P,j,C,L,G,_,$,O]),i.useMemo(()=>({stepTrack:F,autofitColumn:V,autofitColumnsInAllRows:H,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L,F,V,H])},pl=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,A0=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>pl(n,t.ranges[r]))&&Kt(e.anchor,t.anchor)&&Kt(e.active,t.active),T0=(e,t,n)=>{const r=l=>l.row<t&&l.col<n,o=l=>l.endRow<t&&l.endCol<n;if(r(e.anchor)&&r(e.active)&&e.ranges.every(o))return e;const s=l=>bn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:he(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},Es=(e,t)=>{if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the ${t} must be an object (got ${String(e)})`);return e},$0=(e,t,n)=>{const r=Es(e,"selection"),o=r.ranges;if(!Array.isArray(o)||o.length===0)throw new RangeError("[spreadsheet] setSelection: the selection must have at least one range");const s=`${t} x ${n} grid`,l=(C,L)=>typeof C=="number"&&Number.isInteger(C)&&C>=0&&C<L,c=(C,L)=>{const{row:M,col:$}=Es(C,L);if(!(l(M,t)&&l($,n)))throw new RangeError(`[spreadsheet] setSelection: the ${L} {row: ${String(M)}, col: ${String($)}} is not a cell of the ${s}`);return{row:M,col:$}},a=o.map((C,L)=>{const{startRow:M,startCol:$,endRow:_,endCol:G}=Es(C,`range ${L}`);if(!(l(M,t)&&l(_,t)&&l($,n)&&l(G,n)&&M<=_&&$<=G))throw new RangeError(`[spreadsheet] setSelection: range ${L} {startRow: ${String(M)}, startCol: ${String($)}, endRow: ${String(_)}, endCol: ${String(G)}} is not a range of the ${s} with each start at most its end`);return{startRow:M,startCol:$,endRow:_,endCol:G}}),u=c(r.anchor,"anchor"),m=c(r.active,"active cell");if(!Wt(a[a.length-1],u))throw new RangeError(`[spreadsheet] setSelection: the anchor {row: ${u.row}, col: ${u.col}} must lie in the last range`);if(!a.some(C=>Wt(C,m)))throw new RangeError(`[spreadsheet] setSelection: the active cell {row: ${m.row}, col: ${m.col}} must lie in one of the ranges`);return{ranges:a,anchor:u,active:m}},M0=(e,t)=>{const n=e.ranges[e.ranges.length-1];return pl(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Nr=(e,t,n)=>n.extend?xn(e,t):n.append?{ranges:[...e.ranges,he(t,t)],anchor:t,active:t}:e.ranges.length===1&&Kt(e.anchor,t)&&Kt(e.active,t)&&pl(e.ranges[0],he(t,t))?e:{ranges:[he(t,t)],anchor:t,active:t},L0=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),xn=(e,t)=>{const n=M0(e,he(e.anchor,t));return n.ranges.some(r=>Wt(r,n.active))?n:{...n,active:L0(n.active,n.ranges[n.ranges.length-1])}},qu=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(he({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(he({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const a=Math.max(c.startRow,t.startRow),u=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(he({row:a,col:c.startCol},{row:u,col:t.startCol-1})),t.endCol<c.endCol&&o.push(he({row:a,col:t.endCol+1},{row:u,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[he(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Wt(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},z0=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},_u=(e,t)=>{const n=e.ranges.findIndex(o=>Wt(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=z0(e.ranges,r.rangeIndex,r.cell,t),!Kt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Qt=24,Pc=32,Lo=4,Xn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),a=i.useRef(null),u=i.useRef(null),m=i.useRef(null),C=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,m.current=null,u.current=null},[]),L=i.useCallback(()=>{const $=a.current,_=e.current,G=m.current;if($===null||_===null||G===null){c.current=null;return}const{clientX:Z,clientY:O}=$.getPointerPosition(),F=l.current,V=(Z-G.left)/F,H=(O-G.top)/F,S=_.getViewportSize(),P=S.width,j=S.height;if(P<=0||j<=0){c.current=requestAnimationFrame(L);return}const w=W=>Math.min(Pc,Math.ceil(W/Qt*Pc));let d=0,b=0;if(s!=="x"){const W=_.getFrozenSize(),v=W.trailingVisibleHeight;H>j-v-Qt?$.anchorRow!==void 0&&W.trailingRows>0&&$.anchorRow>=t.count-W.trailingRows&&v>0&&H>=j-v||(d=w(H-(j-v-Qt))):H<W.height+Qt&&($.anchorRow!==void 0&&$.anchorRow<W.rows&&W.height>0&&H<W.height||(d=-w(W.height+Qt-H)))}if(s!=="y"){const W=_.getFrozenSize(),v=W.trailingVisibleWidth;V>P-v-Qt?$.anchorCol!==void 0&&W.trailingCols>0&&$.anchorCol>=n.count-W.trailingCols&&v>0&&V>=P-v||(b=w(V-(P-v-Qt))):V<W.width+Qt&&($.anchorCol!==void 0&&$.anchorCol<W.cols&&W.width>0&&V<W.width||(b=-w(W.width+Qt-V)))}const E=b!==0||d!==0?_.scrollBy({x:b!==0?b:void 0,y:d!==0?d:void 0}):_.getScrollPosition(),k=E.y,R=E.x;if(k>=0&&R>=0&&t.totalSize()>0&&n.totalSize()>0){const W=_.getFrozenSize(),v=bn({row:jr(t,H,{scroll:k,frozenSize:W.height,trailingSize:W.trailingHeight,extent:S.height}),col:_r(n,V,{scroll:R,frozenSize:W.width,trailingSize:W.trailingWidth,extent:S.width})},t.count,n.count),x=u.current;(d!==0||b!==0||x===null||x.row!==v.row||x.col!==v.col)&&(u.current=v,o($.buildRange(v)))}c.current=requestAnimationFrame(L)},[e,t,n,s,o]),M=i.useCallback($=>{C(),a.current=$,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(L)},[C,L,r]);return i.useEffect(()=>{const $=()=>{document.visibilityState==="hidden"&&C()};return document.addEventListener("visibilitychange",$),()=>{document.removeEventListener("visibilitychange",$),C()}},[C]),i.useMemo(()=>({start:M,stop:C}),[M,C])},qc=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),m=i.useRef(null),C=i.useRef(!1),L=i.useRef(0),M=i.useCallback((S,P)=>{const{axis:j,mainAxis:w,handleRef:d,zoomRef:b}=t.current,E=s.current;if(E===null||w.totalSize()===0)return null;const k=b.current,R=d.current;if(R===null)return null;if(j==="col"){const K=R.getScrollPosition().x;if(K<0)return null;const y=R.getFrozenSize(),X=R.getViewportSize();return Math.min(Math.max(_r(w,(S-E.left)/k,{scroll:K,frozenSize:y.width,trailingSize:y.trailingWidth,extent:X.width}),0),w.count-1)}const W=R.getScrollPosition().y;if(W<0)return null;const v=R.getFrozenSize(),x=R.getViewportSize();return Math.min(Math.max(jr(w,(P-E.top)/k,{scroll:W,frozenSize:v.height,trailingSize:v.trailingHeight,extent:x.height}),0),w.count-1)},[]),$=i.useCallback((S,P)=>{const{axis:j,crossCount:w}=t.current;return j==="col"?{press:{row:0,col:S},extend:{row:w-1,col:P}}:{press:{row:S,col:0},extend:{row:P,col:w-1}}},[]),_=i.useCallback((S,P)=>{const{axis:j,crossCount:w}=t.current;return S.ranges.some(d=>j==="col"?d.startRow===0&&d.endRow===w-1&&P>=d.startCol&&P<=d.endCol:d.startCol===0&&d.endCol===w-1&&P>=d.startRow&&P<=d.endRow)},[]),G=i.useRef(!1),Z=i.useRef({clientX:0,clientY:0}),O=i.useCallback(()=>{G.current=!1;const{autoScroller:S,headerRef:P,onDragFrame:j}=t.current;n.current=!1,r.current=null,m.current=null,C.current=!1,L.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),S.stop();const w=P.current;w!==null&&a.current!==null&&w.hasPointerCapture?.(a.current)&&w.releasePointerCapture(a.current),a.current=null,j(null),t.current.repaintOverlay()},[]),F=i.useCallback(()=>{if(!n.current)return;const S=r.current;S!==null&&t.current.setSelection(S),O()},[O]),{enabled:V,headerRef:H}=e;return i.useEffect(()=>{const S=H.current;if(!V||S===null)return;const P=R=>{const W=t.current;if(R.pointerType!=="mouse")return;if(R.button!==0){R.preventDefault();return}if(C.current=!1,W.pointing?.getPointing()){s.current=S.getBoundingClientRect();const y=M(R.clientX,R.clientY);if(y===null)return;R.preventDefault(),W.focusSink(),W.pointing.insertReference(W.axis==="col"?{row:0,col:y}:{row:y,col:0},W.axis==="col"?"columns":"rows");return}if(W.isEditing()&&!W.requestCommit()){R.preventDefault(),W.focusSink();return}s.current=S.getBoundingClientRect();const v=M(R.clientX,R.clientY);if(v===null)return;R.preventDefault(),W.focusSink();const x=W.getSelection();r.current=x;const K=R.ctrlKey||R.metaKey;if(R.shiftKey){const y=W.axis==="col"?{row:0,col:x.anchor.col}:{row:x.anchor.row,col:0},{extend:X}=$(v,v),Q={...x,anchor:y};W.setSelection(xn(Q,X)),o.current=W.axis==="col"?y.col:y.row}else if(K&&_(x,v))C.current=!0,L.current=v,o.current=v;else{const{press:y,extend:X}=$(v,v),Q=Nr(x,y,{extend:!1,append:K});W.setSelection(xn(Q,X)),o.current=v}n.current=!0,W.repaintOverlay(),l.current={clientX:R.clientX,clientY:R.clientY},a.current=R.pointerId,u.current=R.buttons;try{S.setPointerCapture(R.pointerId)}catch{a.current=null}m.current=y=>{const X=t.current.axis==="col"?y.col:y.row,{press:Q}=$(o.current,o.current),{extend:p}=$(o.current,X);return he(Q,p)},W.autoScroller.stop(),G.current=!1,Z.current={clientX:R.clientX,clientY:R.clientY}},j=R=>a.current!==null?R.pointerId===a.current:R.pointerType==="mouse",w=R=>{if(n.current&&j(R)){if(C.current){const W=R.clientX!==l.current.clientX||R.clientY!==l.current.clientY;if(l.current={clientX:R.clientX,clientY:R.clientY},!W)return;const v=M(R.clientX,R.clientY);if(v===null||v===L.current)return;C.current=!1;const x=t.current,{press:K,extend:y}=$(L.current,L.current),X=Nr(x.getSelection(),K,{extend:!1,append:!0});x.setSelection(xn(X,y));const Q=m.current,p=Math.abs(R.clientX-Z.current.clientX),f=Math.abs(R.clientY-Z.current.clientY);Q!==null&&Math.max(p,f)>=Lo&&(G.current=!0,x.autoScroller.start({getPointerPosition:()=>l.current,buildRange:Q,anchorCol:x.axis==="col"?o.current:void 0,anchorRow:x.axis==="row"?o.current:void 0}))}else if(l.current={clientX:R.clientX,clientY:R.clientY},!G.current&&m.current!==null){const W=Math.abs(R.clientX-Z.current.clientX),v=Math.abs(R.clientY-Z.current.clientY);Math.max(W,v)>=Lo&&(G.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const W=m.current;if(!n.current||W===null)return;const v=M(l.current.clientX,l.current.clientY);v!==null&&t.current.onDragFrame(W(t.current.axis==="col"?{row:0,col:v}:{row:v,col:0}))}))}},d=R=>{w(R),n.current&&j(R)&&(u.current&1)!==0&&(R.buttons&1)===0&&E(R)},b=R=>{R.button!==0||!(n.current&&j(R))||E(R)},E=R=>{const W=t.current;if(C.current){const{press:x,extend:K}=$(L.current,L.current);W.setSelection(qu(W.getSelection(),he(x,K),x)),O();return}const v=M(R.clientX,R.clientY);if(v!==null){const{extend:x}=$(o.current,v);W.setSelection(xn(W.getSelection(),x))}O()},k=R=>{!n.current||a.current===null||R.pointerId!==a.current||F()};return S.addEventListener("pointerdown",P),S.addEventListener("pointermove",d),S.addEventListener("pointerup",b),S.addEventListener("lostpointercapture",k),()=>{S.removeEventListener("pointerdown",P),S.removeEventListener("pointermove",d),S.removeEventListener("pointerup",b),S.removeEventListener("lostpointercapture",k),O()}},[V,H,M,$,O,F]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:F,cancelDrag:O}),[F,O])},N0=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(l<0||s<0)return;const u=o.getFrozenSize();if(a>0&&r.row>=u.rows&&r.row<t.count-u.trailingRows){const m=t.offsetOf(r.row),C=m+t.sizeOf(r.row);m<u.height+l?o.scrollBy({y:m-(u.height+l)}):C>l+a-u.trailingVisibleHeight&&o.scrollBy({y:C-(l+a-u.trailingVisibleHeight)})}if(c>0){if(r.col<u.cols||r.col>=n.count-u.trailingCols)return;const m=n.offsetOf(r.col),C=m+n.sizeOf(r.col);m<u.width+s?o.scrollBy({x:m-(u.width+s)}):C>s+c-u.trailingVisibleWidth&&o.scrollBy({x:C-(s+c-u.trailingVisibleWidth)})}},D0=50,F0=100,ju=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<D0:!1,Sr={selectAll:tn("Ctrl+A"),undo:tn("Ctrl+Z"),redo:tn("Ctrl+Y"),redoShiftZ:tn("Ctrl+Shift+Z"),pasteValues:tn("Ctrl+Shift+V")},P0=new Set(["Shift","Control","Alt","Meta","AltGraph"]),q0={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},_0=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",j0=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(null),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(e);a.current=e;const{enabled:u,sinkRef:m,rootRef:C,handleRef:L}=e;i.useEffect(()=>{const M=m.current,$=C.current;if(!u||M===null||$===null)return;const _=()=>{c.current&&(c.current=!1,a.current.onPointFrame?.(null))},G=(p,f,g)=>gn(p,f,g)??f,Z=(p,f)=>{const g=a.current;return f==="left"||f==="right"?{row:p.row,col:G(g.colAxis,p.col,f==="right"?1:-1)}:{row:G(g.rowAxis,p.row,f==="down"?1:-1),col:p.col}},O=p=>p.indexAt(0),F=p=>p.indexAt(p.totalSize()-1),V=(p,f,g,A)=>{if(p.sizeOf(f)>0)return f;const D=gn(p,f,g);if(D!==null)return D;const B=gn(p,f,g===1?-1:1);return B!==null?B:A},H=()=>{const p=a.current.getSelection(),f=p.ranges[p.ranges.length-1];return{row:p.anchor.row===f.startRow?f.endRow:f.startRow,col:p.anchor.col===f.startCol?f.endCol:f.startCol}},S=p=>Z(H(),p),P=(p,f)=>{const g=a.current,A=f==="left"||f==="right",D=f==="right"||f==="down"?1:-1;let B;return g.findDataEdge!==void 0?(B=g.findDataEdge({row:p.row,col:p.col},f),j(B,p,f)):B={row:f==="down"?g.rowAxis.count-1:f==="up"?0:p.row,col:f==="right"?g.colAxis.count-1:f==="left"?0:p.col},A?{row:B.row,col:V(g.colAxis,B.col,D,p.col)}:{row:V(g.rowAxis,B.row,D,p.row),col:B.col}},j=(p,f,g)=>{const A=a.current;if(!(Number.isInteger(p.row)&&Number.isInteger(p.col)&&p.row>=0&&p.row<A.rowAxis.count&&p.col>=0&&p.col<A.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${p.row}, col: ${p.col}} for a ${A.rowAxis.count} x ${A.colAxis.count} grid`);const D=g==="left"||g==="right";if(D?p.row!==f.row:p.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${D?"row":"column"} (received {row: ${p.row}, col: ${p.col}} from {row: ${f.row}, col: ${f.col}})`)},w=(p,f,g)=>{if(!(Number.isInteger(p)&&p>=0&&p<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${g} component ${p} (count ${f})`)},d=p=>{const f=a.current,g=f.getSelection();if(_u(g,p)===g){f.moveActive({mode:"reset",cell:Z(g.active,p)});return}f.moveActive({mode:"cycle",direction:p})},b=p=>{const f=a.current,g=f.commands;if(g===void 0||!f.isEditing())return null;const A=js(g.table,p);return A!==null&&A.command==="fillSelection"&&g.isAvailable("fillSelection")?g:null},E=()=>{s.current=null;const p=a.current,f=p.commands;f===void 0||!p.isEditing()||!f.isAvailable("fillSelection")||f.execute("fillSelection")},k=p=>{const f=b(p);if(r.current){o.current=f!==null;return}f!==null&&t.current!==null&&(p.preventDefault(),f.execute("fillSelection"))},R=()=>{const p=m.current;if(p===null)return;const f=p.selectionStart??p.value.length,g=p.selectionEnd??f;p.value=`${p.value.slice(0,f)}
14
+ ${p.value.slice(g)}`,p.setSelectionRange(f+1,f+1)},W=(p,f)=>{const g=a.current,A=g.pageExtent();if(A<=0)return G(g.rowAxis,p,f==="down"?1:-1);const D=g.rowAxis.indexAt(g.rowAxis.offsetOf(p)+(f==="down"?A:-A));return D===p?G(g.rowAxis,p,f==="down"?1:-1):D},v=p=>{const f=a.current;if(l.current=!1,ju(p,t.current)){k(p);return}const g=p.ctrlKey||p.metaKey,A=p.altKey,D=q0[p.key];if(c.current&&!P0.has(p.key)&&!f.isDragging()&&_(),f.isEditing()){const ee=f.getEditingMode();if(f.isDragging()){p.preventDefault(),p.key==="Escape"&&!g&&!p.shiftKey&&!A&&f.abortDrag();return}const le=f.pointing;if(le!==void 0){if(D!==void 0&&!A){const U=le.getReferenceCursor();if(U!==null){p.preventDefault();const ce=bn(U.cursor,f.rowAxis.count,f.colAxis.count),$e=bn(U.origin,f.rowAxis.count,f.colAxis.count),ze=g?P(ce,D):Z(ce,D);if(f.ensureCellVisible(ze),le.insertReference(p.shiftKey?he($e,ze):ze,U.axis),f.onPointFrame!==void 0){const je=p.shiftKey?he($e,ze):he(ze,ze);f.onPointFrame(U.axis==="columns"?he({row:0,col:je.startCol},{row:f.rowAxis.count-1,col:je.endCol}):U.axis==="rows"?he({row:je.startRow,col:0},{row:je.endRow,col:f.colAxis.count-1}):je),c.current=!0}return}}if(p.key==="F2"&&!g&&!p.shiftKey&&!A&&le.togglePointingArm()){p.preventDefault();return}if(p.key==="F4"&&!g&&!p.shiftKey&&!A&&le.cycleAnchorAtCaret()){p.preventDefault();return}}const ne=f.commands,oe=ne===void 0?null:js(ne.table,p);if(ne!==void 0&&oe!==null&&Ao.has(oe.command)&&ne.isAvailable(oe.command)){p.preventDefault(),ne.execute(oe.command);return}if(D!==void 0&&!A){if(g&&p.shiftKey){p.preventDefault();return}if(g)return;if(ee==="replace"){if(p.preventDefault(),!f.requestCommit())return;p.shiftKey?f.moveActive({mode:"extend",cell:S(D)}):f.moveActive({mode:"reset",cell:Z(f.getSelection().active,D)});return}return}if(p.key==="Enter"&&A&&!g&&!p.shiftKey){p.preventDefault(),R();return}if((p.key==="Enter"||p.key==="Tab")&&!g&&!A){if(p.preventDefault(),!f.requestCommit())return;const U=!p.shiftKey;d(p.key==="Tab"?U?"right":"left":U?"down":"up");return}if((p.key==="PageUp"||p.key==="PageDown")&&!p.shiftKey&&!g&&!A){if(p.preventDefault(),!f.requestCommit())return;const U=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:W(U.row,p.key==="PageDown"?"down":"up"),col:U.col}});return}if(p.key==="Escape"&&!g&&!p.shiftKey&&!A){p.preventDefault(),f.cancelEdit();return}if(ne!==void 0&&oe!==null&&!Ao.has(oe.command)&&Dm(oe.chord)&&ne.isAvailable(oe.command)){p.preventDefault(),f.onCommandBlockedWhileEditing?.(oe);return}return}if(p.defaultPrevented)return;if(f.isDragging()&&p.key!=="Escape"){p.preventDefault();return}const B=f.commands;if(B!==void 0){const ee=Lm(B.table,p);if(ee!==null&&B.isAvailable(ee)){p.preventDefault(),B.execute(ee);return}}if(D!==void 0&&!A){const ee=D==="left"||D==="right",le=D==="right"||D==="down"?1:-1;if(g&&p.shiftKey){p.preventDefault();const ne=f.getSelection(),oe=H();let U;if(f.findDataEdge!==void 0){const ce=ee?{row:ne.active.row,col:oe.col}:{row:oe.row,col:ne.active.col},$e=f.findDataEdge(ce,D);U=ee?$e.col:$e.row,w(U,ee?f.colAxis.count:f.rowAxis.count,ee?"col":"row"),U=V(ee?f.colAxis:f.rowAxis,U,le,ee?oe.col:oe.row)}else{const ce=ee?f.colAxis:f.rowAxis;U=le===1?F(ce):O(ce)}f.moveActive({mode:"extend",cell:ee?{row:oe.row,col:U}:{row:U,col:oe.col}});return}if(g){p.preventDefault(),f.moveActive({mode:"reset",cell:P(f.getSelection().active,D)});return}if(p.shiftKey){p.preventDefault(),f.moveActive({mode:"extend",cell:S(D)});return}p.preventDefault(),f.moveActive({mode:"reset",cell:Z(f.getSelection().active,D)});return}if(_0(p)){p.preventDefault();return}if((p.key==="Tab"||p.key==="Enter")&&!g&&!A){p.preventDefault();const ee=!p.shiftKey;d(p.key==="Tab"?ee?"right":"left":ee?"down":"up");return}if(p.key==="Home"&&!A){if(p.preventDefault(),p.shiftKey){const le=H();f.moveActive({mode:"extend",cell:{row:g?O(f.rowAxis):le.row,col:O(f.colAxis)}});return}const ee=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g?O(f.rowAxis):ee.row,col:O(f.colAxis)}});return}if(p.key==="End"&&!A){if(p.preventDefault(),p.shiftKey){const le=H();f.moveActive({mode:"extend",cell:{row:g?F(f.rowAxis):le.row,col:F(f.colAxis)}});return}const ee=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g?F(f.rowAxis):ee.row,col:F(f.colAxis)}});return}if((p.key==="PageUp"||p.key==="PageDown")&&!g&&!A){p.preventDefault();const ee=p.key==="PageDown"?"down":"up";if(p.shiftKey){const ne=H();f.moveActive({mode:"extend",cell:{row:W(ne.row,ee),col:ne.col}});return}const le=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:W(le.row,ee),col:le.col}});return}if(p.key==="F2"&&!g&&!p.shiftKey&&!A){p.preventDefault(),f.startEdit("edit");return}if((p.key==="Delete"||p.key==="Backspace")&&!g&&!p.shiftKey&&!A){p.preventDefault();const ee=f.getSelection(),le=bt(ee.ranges);if(le>f.maxOperationCells){f.onOperationRejected?.("delete",le,"limit");return}if(f.adapter!==void 0&&Qn(f.adapter,ee.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:le});return}const ne=[],oe=f.adapter!==void 0&&So(f.adapter).hyperlink;dn(ee.ranges,U=>{ne.push(oe?{row:U.row,col:U.col,text:"",hyperlink:null}:{row:U.row,col:U.col,text:""})}),f.commitEdits(ne,{source:"delete"});return}if(p.key==="Escape"){if(f.isDragging()){p.preventDefault(),f.abortDrag();return}if(g||p.shiftKey||A||(p.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(br(Sr.selectAll,p)){p.preventDefault();const ee=f.getSelection(),le=he({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[le],anchor:ee.anchor,active:ee.active});return}if(br(Sr.undo,p)){p.preventDefault(),f.onUndoRequest?.();return}if(br(Sr.redo,p)||br(Sr.redoShiftZ,p)){p.preventDefault(),f.onRedoRequest?.();return}if(p.key==="F10"&&p.shiftKey&&!g&&!A||p.key==="ContextMenu"&&!g&&!p.shiftKey&&!A){p.preventDefault();const ee=f.getSelection().active;f.ensureCellVisible(ee);const le=L.current,ne=le===null?{x:0,y:0}:le.getScrollPosition(),oe=Math.max(0,ne.y),U=Math.max(0,ne.x),ce=le===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:le.getFrozenSize(),$e=le===null?{width:0,height:0}:le.getViewportSize(),ze=f.zoomRef.current;f.onCellContextMenu?.(ee,{kind:"keyboard",cellRect:{top:Mn(f.rowAxis,ee.row,{scroll:oe,frozenCount:ce.rows,trailingCount:ce.trailingRows,extent:$e.height})*ze,left:$n(f.colAxis,ee.col,{scroll:U,frozenCount:ce.cols,trailingCount:ce.trailingCols,extent:$e.width})*ze,width:f.colAxis.sizeOf(ee.col)*ze,height:f.rowAxis.sizeOf(ee.row)*ze}});return}if(p.key===" "&&!A&&g!==p.shiftKey){p.preventDefault();const ee=f.getSelection(),le=ee.ranges.map(ne=>g?he({row:0,col:ne.startCol},{row:f.rowAxis.count-1,col:ne.endCol}):he({row:ne.startRow,col:0},{row:ne.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:le,anchor:ee.anchor,active:ee.active});return}if(f.pendingPasteOptionsRef!==void 0&&br(Sr.pasteValues,p)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(p.key.length===1&&!p.metaKey&&p.ctrlKey===p.altKey){if(p.ctrlKey&&p.altKey){l.current=!0;return}f.startEdit("replace");return}},x=()=>{const p=a.current;r.current=!0,o.current=!1,p.isEditing()||p.startEdit("replace")},K=p=>{r.current=!1,t.current=p.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},F0),o.current&&(o.current=!1,p.data!==""&&(s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(E,0)))},y=()=>{const p=a.current;if(_(),!p.isEditing()){if(l.current){l.current=!1;const f=M.value;if(f!==""&&(p.startEdit("replace"),p.isEditing())){M.value=f,M.setSelectionRange(f.length,f.length);return}}p.rearmSink()}},X=()=>{l.current=!1;const p=a.current.pendingPasteOptionsRef;p!==void 0&&(p.current=null)},Q=()=>{l.current=!1;const p=a.current.pendingPasteOptionsRef;p!==void 0&&(p.current=null),_()};return M.addEventListener("keydown",v),M.addEventListener("keyup",X),M.addEventListener("blur",Q),M.addEventListener("compositionstart",x),M.addEventListener("compositionend",K),M.addEventListener("input",y),()=>{M.removeEventListener("keydown",v),M.removeEventListener("keyup",X),M.removeEventListener("blur",Q),M.removeEventListener("compositionstart",x),M.removeEventListener("compositionend",K),M.removeEventListener("input",y),n.current!==null&&window.clearTimeout(n.current),s.current!==null&&(window.clearTimeout(s.current),s.current=null),r.current=!1,o.current=!1,_()}},[u,m,C,L])},I0=()=>{let e={vy:0,rowStart:0,rowEnd:0,colStart:0,colEnd:0,colVersion:0,rowGeomVersion:0,editVersion:0};const t=new Set;let n=null;const r=()=>{n=null;for(const l of[...t])l()},o=()=>{t.size!==0&&n===null&&(n=requestAnimationFrame(r))},s=l=>{e={...e,...l},o()};return{get:()=>e,setVy:l=>{l!==e.vy&&s({vy:l})},setRowRange:(l,c)=>{(l!==e.rowStart||c!==e.rowEnd)&&s({rowStart:l,rowEnd:c})},setColRange:(l,c)=>{(l!==e.colStart||c!==e.colEnd)&&s({colStart:l,colEnd:c})},bumpColVersion:()=>s({colVersion:e.colVersion+1}),bumpRowGeometry:()=>s({rowGeomVersion:e.rowGeomVersion+1}),bumpEdit:()=>s({editVersion:e.editVersion+1}),subscribeCoalesced:l=>(t.add(l),()=>{t.delete(l),t.size===0&&n!==null&&(cancelAnimationFrame(n),n=null)})}},H0=4,B0=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),V0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),a=i.useRef(!1),u=i.useRef({dx:0,dy:0}),m=i.useRef(null),C=i.useRef(0),L=i.useRef(null),M=i.useRef(null),$=i.useRef(!1),_=i.useCallback(S=>m.current!==null?S.pointerId===m.current:S.pointerType==="mouse",[]),G=i.useCallback((S,P)=>{const{handleRef:j,rowAxis:w,colAxis:d}=t.current,b=j.current,E=s.current;if(b===null||E===null)return null;const{x:k,y:R}=b.getScrollPosition();if(R<0||k<0||w.totalSize()===0||d.totalSize()===0)return null;const W=t.current.zoomRef.current,v=b.getFrozenSize(),x=b.getViewportSize();return bn({row:jr(w,(P-E.top)/W,{scroll:R,frozenSize:v.height,trailingSize:v.trailingHeight,extent:x.height}),col:_r(d,(S-E.left)/W,{scroll:k,frozenSize:v.width,trailingSize:v.trailingWidth,extent:x.width})},w.count,d.count)},[]),Z=i.useCallback(S=>{const P=r.current;if(P===null)return he(S,S);const j=he({row:Math.min(P.startRow,S.row),col:Math.min(P.startCol,S.col)},{row:Math.max(P.endRow,S.row),col:Math.max(P.endCol,S.col)}),w=j.startRow!==P.startRow||j.endRow!==P.endRow||j.startCol!==P.startCol||j.endCol!==P.endCol;return o.current=w?j:null,w?j:P},[]),O=i.useCallback(()=>{const S=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,L.current!==null&&(cancelAnimationFrame(L.current),L.current=null),S.xAutoScroller.stop(),S.yAutoScroller.stop(),$.current=!1,a.current=!1,u.current={dx:0,dy:0},S.writeFillPreview(null);const P=M.current;P!==null&&(window.removeEventListener("pointermove",P.move),window.removeEventListener("pointerup",P.up),M.current=null);const j=t.current.handleNodeRef.current;j!==null&&m.current!==null&&j.hasPointerCapture?.(m.current)&&j.releasePointerCapture(m.current),m.current=null,S.repaintOverlay()},[]),F=i.useCallback(()=>{const S=t.current,P=r.current,j=o.current;if(O(),P===null||j===null)return;const w=mm(P,j);if(w>S.maxOperationCells){S.onOperationRejected?.("fill",w,"limit");return}const d=gm(P,j);if(Qn(S.adapter,d)){S.rejectReadOnly({kind:"operation",op:"fill",cellCount:bt(d),gesture:"fillHandle",sources:[P],targets:d});return}const b=wm((k,R)=>Ua(S.adapter,k,R),P,j,Ga);if(S.commitEdits(b,{source:"fill"})===null)return;const E=S.getSelection();S.setSelection({ranges:[j],anchor:E.anchor,active:E.active})},[O]),{enabled:V,handleNodeRef:H}=e;return i.useEffect(()=>{const S=H.current;if(!V||S===null)return;const P=E=>{j(E),n.current&&_(E)&&(C.current&1)!==0&&(E.buttons&1)===0&&F()},j=E=>{if(!(n.current&&_(E)))return;l.current={clientX:E.clientX,clientY:E.clientY};const k=Math.abs(E.clientX-c.current.clientX),R=Math.abs(E.clientY-c.current.clientY);if(!a.current&&Math.max(k,R)>=H0&&(a.current=!0),!!a.current){if(!$.current){const W=t.current,v={getPointerPosition:()=>({clientX:l.current.clientX-u.current.dx,clientY:l.current.clientY-u.current.dy}),buildRange:Z,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};W.xAutoScroller.start(v),W.yAutoScroller.start(v),$.current=!0}L.current===null&&(L.current=requestAnimationFrame(()=>{if(L.current=null,!(n.current&&a.current))return;const W=G(l.current.clientX-u.current.dx,l.current.clientY-u.current.dy);W!==null&&t.current.writeFillPreview(Z(W))}))}},w=E=>{E.button!==0||!(n.current&&_(E))||F()},d=E=>{const k=t.current;if(E.pointerType!=="mouse")return;if(E.button!==0){E.preventDefault();return}E.preventDefault(),E.stopPropagation(),k.focusSink();const R=k.getSelection(),W=R.ranges[R.ranges.length-1];r.current=W,o.current=null,a.current=!1,k.xAutoScroller.stop(),k.yAutoScroller.stop(),$.current=!1,c.current={clientX:E.clientX,clientY:E.clientY},l.current=c.current,C.current=E.buttons,n.current=!0,k.repaintOverlay(),s.current=k.bodyRef.current?.getBoundingClientRect()??null;const v=s.current,x=k.handleRef.current?.getScrollPosition()??{x:-1,y:-1},K=x.y;if(v!==null&&K>=0&&x.x>=0){const Q=x.x,p=k.zoomRef.current,f=k.handleRef.current?.getFrozenSize()??B0,g=k.handleRef.current?.getViewportSize()??{width:0,height:0},A={scroll:Q,frozenCount:f.cols,trailingCount:f.trailingCols,extent:g.width},D={scroll:K,frozenCount:f.rows,trailingCount:f.trailingRows,extent:g.height},B=$n(k.colAxis,W.endCol,A)+k.colAxis.sizeOf(W.endCol),ee=Mn(k.rowAxis,W.endRow,D)+k.rowAxis.sizeOf(W.endRow),le=B-1,ne=W.endCol>=f.cols&&f.width>0?Math.max(le,f.width):le,U=!(W.endCol>=k.colAxis.count-f.trailingCols)&&f.trailingWidth>0?Math.min(ne,g.width-f.trailingVisibleWidth-1):ne,ce=ee-1,$e=W.endRow>=f.rows&&f.height>0?Math.max(ce,f.height):ce,je=!(W.endRow>=k.rowAxis.count-f.trailingRows)&&f.trailingHeight>0?Math.min($e,g.height-f.trailingVisibleHeight-1):$e;u.current={dx:E.clientX-(v.left+U*p),dy:E.clientY-(v.top+je*p)}}else u.current={dx:0,dy:0};m.current=E.pointerId;try{S.setPointerCapture(E.pointerId)}catch{m.current=null}const y=P,X=w;M.current={move:y,up:X},window.addEventListener("pointermove",y),window.addEventListener("pointerup",X),k.writeFillPreview(r.current)},b=E=>{!n.current||m.current===null||E.pointerId!==m.current||O()};return S.addEventListener("pointerdown",d),S.addEventListener("lostpointercapture",b),()=>{S.removeEventListener("pointerdown",d),S.removeEventListener("lostpointercapture",b),O()}},[V,H,_,G,Z,O,F]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&O()},cancelDrag:O}),[O])},W0=(e,t,n)=>{const r=Object.hasOwn(e.filters,t)?e.filters[t]:void 0;return new Set(r!==void 0&&r.mode==="exact"?r.values:n.map(o=>o.value))},K0=({column:e,columnName:t,state:n,getFilterValues:r,changeState:o,close:s,isInsideGrid:l,relayout:c,labels:a})=>{const u=e.key,m=Object.hasOwn(n.filters,u)?n.filters[u]:void 0,C=n.sort!==null&&n.sort.columnKey===u?n.sort.direction:null,[L,M]=i.useState(()=>m===void 0?e.defaultMatchMode:m.mode),[$,_]=i.useState(()=>m!==void 0&&m.mode==="fuzzy"?m.query:""),[G,Z]=i.useState(""),[O,F]=i.useState({status:"idle"}),[V,H]=i.useState(()=>new Set),S=i.useRef(!1),P=i.useRef(n);P.current=n;const j=i.useId(),w=i.useId(),d=e.filterable&&L==="exact",b=d||O.status!=="idle";i.useEffect(()=>{if(!b)return;if(r===void 0){F({status:"failed"});return}const U=new AbortController;let ce;try{ce=Promise.resolve(r(u,P.current,U.signal))}catch{return F({status:"failed"}),()=>U.abort()}return F({status:"loading"}),ce.then($e=>{if(U.signal.aborted)return;let ze;try{ze=u0($e)}catch{F({status:"failed"});return}F({status:"loaded",values:ze}),H(W0(P.current,u,ze))},()=>{U.signal.aborted||F({status:"failed"})}),()=>U.abort()},[b]);const E=O.status==="loaded"||O.status==="failed"?O.status:"pending",k=i.useRef(!1);i.useLayoutEffect(()=>{if(!k.current){k.current=!0;return}c()},[L,E]);const R=O.status==="loaded"?O.values:null,W=U=>U.label===""?ye(a,"filterBlank"):U.label,v=i.useMemo(()=>R===null?[]:R.filter(U=>d0(U.label===""?ye(a,"filterBlank"):U.label,G)),[R,G,a]),x=v.length>To?v.slice(0,To):v,K=v.length-x.length,y=R===null?0:R.filter(U=>V.has(U.value)).length,X=U=>{S.current=!0;try{U()}finally{S.current=!1}},Q=U=>X(()=>{o(U)}),p=U=>Q(o0(n,u,U)),f=()=>{if(L==="fuzzy"){Q(i0(n,u,$));return}R===null||y===0||Q(l0(n,u,V,R.map(U=>U.value)))},g=U=>{const ce=new Set(V);for(const $e of v)U?ce.add($e.value):ce.delete($e.value);H(ce)},A=U=>{const ce=new Set(V);ce.has(U)?ce.delete(U):ce.add(U),H(ce)},D=U=>{U.key==="Escape"&&(U.preventDefault(),X(()=>s()))},B=U=>{const ce=U.relatedTarget;S.current||ce instanceof Node&&U.currentTarget.contains(ce)||X(()=>s({restoreFocus:ce instanceof Node&&l(ce)}))},ee=e.filterable&&e.matchModes.length===2,le=e.sortable?"sort":ee?"mode":L==="exact"?"search":"query",ne=U=>le===U?{"data-aqsp-popover-autofocus":""}:{},oe=Object.keys(n.filters).length>0;return q.jsxs("div",{className:"aqsp-popover-column-menu","data-aqsp-popover":"columnMenu",role:"dialog","aria-labelledby":w,onKeyDown:D,onBlur:B,children:[q.jsx("div",{className:"aqsp-popover-title",id:w,children:t.trim()===""?ye(a,"columnMenu"):`${t} ${ye(a,"columnMenu")}`}),e.sortable?q.jsxs("div",{className:"aqsp-popover-section aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortAsc","aria-pressed":C==="asc",onClick:()=>p("asc"),...ne("sort"),children:ye(a,"sortAscending")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortDesc","aria-pressed":C==="desc",onClick:()=>p("desc"),children:ye(a,"sortDescending")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortClear",disabled:C===null,onClick:()=>p(null),children:ye(a,"sortClear")})]}):null,ee?q.jsxs("fieldset",{className:"aqsp-popover-section aqsp-popover-fieldset",children:[q.jsx("legend",{className:"aqsp-popover-field-label",children:ye(a,"filterMatchMode")}),Du.map(U=>q.jsxs("label",{className:"aqsp-popover-radio",children:[q.jsx("input",{type:"radio",name:j,value:U,"data-aqsp-column-menu-mode":U,checked:L===U,onChange:()=>M(U),...L===U?ne("mode"):{}}),ye(a,U==="exact"?"filterModeExact":"filterModeFuzzy")]},U))]}):null,d?q.jsxs("div",{className:"aqsp-popover-section",children:[q.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"search","aria-label":ye(a,"filterSearchValues"),placeholder:ye(a,"filterSearchValues"),value:G,onChange:U=>Z(U.currentTarget.value),...ne("search")}),q.jsxs("div",{className:"aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkAll",disabled:v.length===0,onClick:()=>g(!0),children:ye(a,"filterSelectAll")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkNone",disabled:v.length===0,onClick:()=>g(!1),children:ye(a,"filterSelectNone")})]}),q.jsxs("fieldset",{className:"aqsp-popover-values","data-aqsp-column-menu-values":"","aria-label":ye(a,"filterModeExact"),"aria-busy":O.status==="loading"||O.status==="idle"?"true":void 0,children:[O.status==="failed"?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"failed",role:"alert",children:ye(a,"filterLoadFailed")}):R===null?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"loading",children:ye(a,"filterLoading")}):x.length===0?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"empty",children:ye(a,"listEmpty")}):x.map(U=>q.jsxs("label",{className:"aqsp-popover-value",children:[q.jsx("input",{type:"checkbox","data-aqsp-column-menu-value":U.value,checked:V.has(U.value),onChange:()=>A(U.value)}),q.jsx("span",{className:"aqsp-popover-value-text",children:W(U)}),q.jsx("span",{className:"aqsp-popover-value-count",children:U.count})]},U.value)),K>0?q.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"more",children:ye(a,"listMore",K)}):null]})]}):null,e.filterable&&L==="fuzzy"?q.jsx("div",{className:"aqsp-popover-section",children:q.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"query","aria-label":ye(a,"filterQuery"),placeholder:ye(a,"filterQuery"),value:$,onChange:U=>_(U.currentTarget.value),onKeyDown:U=>{U.key==="Enter"&&(U.preventDefault(),f())},...ne("query")})}):null,e.filterable?q.jsxs("div",{className:"aqsp-popover-actions",children:[q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"apply",disabled:L==="exact"&&y===0,onClick:f,children:ye(a,"filterApply")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clear",disabled:m===void 0,onClick:()=>Q(fl(n,u)),children:ye(a,"filterClearColumn")}),q.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clearAll",disabled:!oe,onClick:()=>Q(s0(n)),children:ye(a,"filterClearAll")})]}):null]})},Y0=320,Eo=8,X0=64,U0=150,Iu=e=>Math.max(0,Math.min(Y0,e.width-Pe.SPREADSHEET_SCROLLBAR_SIZE_PX-Eo)),G0=(e,t,n)=>{const r=n.width-Pe.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Pe.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Iu(n),l=Math.max(0,Math.min(t,o-Eo)),c=e.left+e.width,a=e.top+e.height,u=_=>_>=0&&_+s<=r,m=[e.left,c-s],C=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of C)if(u(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const L=o-a,M=e.top,$=Math.min(l,Math.max(L,M));if($>=X0){const _=L>=M?a:e.top-$;for(const G of m)if(u(G))return{left:G,top:_,width:s,height:$}}return{left:Eo,top:Eo,width:s,height:l}},Z0=(e,t,n,r)=>t===null||e!==null&&Kt(e,t)||n?!1:r(t),J0=(e,t)=>{switch(e.kind){case"note":return q.jsx(yu,{ctx:e,labels:t});case"note-tip":return q.jsx(bu,{ctx:e,labels:t});case"comment":return q.jsx(mu,{ctx:e,labels:t});case"link":return q.jsx(gu,{ctx:e,labels:t});case"list":return q.jsx(wu,{ctx:e,labels:t});default:return q.jsx(Cu,{ctx:e,labels:t})}},ks=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Q0=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o,columnMenu:s})=>{const{context:l,tipContext:c}=e,a=i.useRef(null),u=i.useRef(null),m=i.useRef(c);m.current=c;const C=i.useRef(e);C.current=e;const L=ks(l),M=ks(c),$=i.useRef(null),_=(S,P)=>{const j=C.current.getLayerSize();S.style.width=`${Iu(j)}px`,S.style.maxHeight="";const w=G0(P,S.offsetHeight,j);S.style.left=`${w.left-P.left}px`,S.style.top=`${w.top-P.top}px`,S.style.maxHeight=`${w.height}px`};i.useLayoutEffect(()=>{const S=a.current;if(S===null||l===null){$.current=null;return}if(_(S,l.anchorRect),l.kind==="message")return;const P=ks(l);if($.current===P)return;$.current=P;const j=S.querySelector("[data-aqsp-popover-autofocus]");j!==null?j.focus({preventScroll:!0}):S.focus({preventScroll:!0})},[l]),i.useLayoutEffect(()=>{const S=u.current,P=m.current;S===null||P===null||_(S,P.anchorRect)},[M]);const G=S=>t===void 0?J0(S,n):t(S),Z=()=>{const S=a.current,P=C.current.context;S!==null&&P!==null&&_(S,P.anchorRect)},O=S=>{if(s==null||S.cell.row!==s.resolved.headerRow)return null;const P=sr(s.resolved,S.cell.col);return P===null?null:q.jsx(K0,{column:P,columnName:s.columnNameOf(S.cell),state:s.state,getFilterValues:s.getFilterValues,changeState:s.changeState,close:e.close,isInsideGrid:s.isInsideGrid,relayout:Z,labels:n})},F=S=>{e.isCompositionKey(S.nativeEvent)&&S.stopPropagation()},V=S=>{S.key==="Escape"&&!S.defaultPrevented&&(S.preventDefault(),e.close())},H=S=>{e.registerCompositionEnd(S.timeStamp)};return q.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:F,onKeyDown:V,onCompositionEnd:H,children:[q.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,children:l===null?null:q.jsx("div",{ref:a,className:"aqsp-popover","data-aqsp-popover-frame":l.kind,tabIndex:-1,children:l.kind==="columnMenu"?O(l):G(l)},L)}),q.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":c===null?void 0:"",inert:c===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:c===null?null:q.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:G(c)})})]})},eC=["note","note-tip","comment","link","list","message"],tC=(e,t)=>{switch(t){case"note":case"note-tip":return e.getCellNote!==void 0;case"comment":return e.getCellComments!==void 0;case"link":return e.getCellHyperlink!==void 0;default:return e.getCellValidation!==void 0}},Er=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&tC(e,n),nC=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),a=i.useRef(null),u=i.useRef(!1),m=i.useRef(null),C=i.useRef(null),L=i.useRef(null),M=i.useRef(null),$=i.useId(),_=i.useCallback(g=>{const A=t.current,D=A.handleRef.current,B=D===null?{x:0,y:0}:D.getScrollPosition(),ee=D===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:D.getFrozenSize(),le=D===null?{width:0,height:0}:D.getViewportSize();return{top:Mn(A.rowAxis,g.row,{scroll:Math.max(0,B.y),frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:le.height}),left:$n(A.colAxis,g.col,{scroll:Math.max(0,B.x),frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:le.width}),width:A.colAxis.sizeOf(g.col),height:A.rowAxis.sizeOf(g.row)}},[]),G=i.useCallback(g=>{const A=t.current;A.anchors.current={...A.anchors.current,...g},A.repaintOverlay()},[]),Z=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),O=i.useCallback(()=>{const g=t.current.sinkRef.current;if(g===null)return;const A=c.current;A!==null&&Kt(A,t.current.getActive())?g.setAttribute("aria-describedby",$):g.getAttribute("aria-describedby")===$&&g.removeAttribute("aria-describedby")},[$]),F=i.useCallback(()=>(Z(),u.current=!1,c.current===null?!1:(c.current=null,s(null),G({tip:null}),O(),!0)),[Z,G,O]),V=i.useCallback(()=>{Z(),m.current=window.setTimeout(()=>{m.current=null,F()},U0)},[Z,F]),H=i.useCallback(g=>{const A=t.current;Z();const D=A.adapter.getCellNote===void 0?void 0:A.adapter.getCellNote(g.row,g.col);D===void 0||D===""||(c.current=g,s({kind:"note-tip",cell:g,anchorRect:_(g),current:D,close:F}),G({tip:g}),O())},[_,Z,F,G,O]),S=i.useCallback(g=>{const A=t.current;if(g===null&&u.current)return;const D=a.current;a.current=g;const B=c.current;if(B!==null&&g!==null&&Kt(B,g)){Z();return}const ee=le=>{const ne=A.adapter.getCellNote===void 0?void 0:A.adapter.getCellNote(le.row,le.col);return ne!==void 0&&ne!==""};if(Z0(D,g,A.isDraggingAny(),ee)){g!==null&&H(g);return}B!==null&&V()},[H,Z,V]),P=i.useCallback((g,A)=>{const D=t.current,B=D.bodyRef.current,ee=D.handleRef.current;if(B===null||ee===null)return null;const le=B.getBoundingClientRect(),ne=D.zoomRef.current,oe=ee.getScrollPosition(),U=ee.getFrozenSize(),ce=ee.getViewportSize();return bn({row:jr(D.rowAxis,(A-le.top)/ne,{scroll:Math.max(0,oe.y),frozenSize:U.height,trailingSize:U.trailingHeight,extent:ce.height}),col:_r(D.colAxis,(g-le.left)/ne,{scroll:Math.max(0,oe.x),frozenSize:U.width,trailingSize:U.trailingWidth,extent:ce.width})},D.rowAxis.count,D.colAxis.count)},[]),j=i.useCallback(g=>{L.current=g,C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null;const A=L.current;S(A===null?null:"cell"in A?A.cell:P(A.clientX,A.clientY))}))},[S,P]),w=i.useCallback(g=>j({cell:g}),[j]),d=i.useCallback(()=>F(),[F]),b=i.useCallback(g=>{if(l.current===null)return;const A=t.current;l.current=null,r(null),G({interactive:null}),(g===void 0||g.restoreFocus)&&A.focusSink({preventScroll:!0}),A.isEditing()||A.rearmSink()},[G]),E=i.useCallback(g=>{l.current=g.kind,r(g),G({interactive:g.cell})},[G]),k=i.useCallback(g=>{const A=t.current;return Ka(A.adapter)?{cellReadOnly:et(A.adapter,g.row,g.col)}:{}},[]),R=i.useCallback((g,A)=>{const D=t.current;if(et(D.adapter,g.cell.row,g.cell.col)){D.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),E({...g,...k(g.cell)});return}if(D.commitEdits(A,{source:"annotate"})===null){E({...g,rejected:!0});return}b()},[E,b,k]),W=i.useCallback((g,A)=>{const D=t.current;if(!Er(D.adapter,D.popovers,g))throw new RangeError(`[spreadsheet] openPopover("${g}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const B=D.getActive();if(g==="list"&&et(D.adapter,B.row,B.col)){D.rejectReadOnly({kind:"edit",cell:B,editSession:"none"});return}if(g==="note-tip"){H(B);return}if(g==="message"){if(l.current!==null&&l.current!=="message")return;const oe=A!==void 0&&A.message!==void 0?A.message:void 0,U=D.adapter.getCellValidation===void 0?void 0:D.adapter.getCellValidation(B.row,B.col),ce=oe!==void 0?oe:U===void 0?void 0:U.inputMessage;if(ce===void 0)return;const $e=A!==void 0&&A.rejected===!0;E({kind:"message",cell:B,anchorRect:_(B),current:{title:ye(D.labels,"messageTitle"),message:ce,rejected:$e},close:b});return}if(D.isEditing()&&!D.requestCommit())return;if(g==="list"){const oe=D.adapter.getCellValidation===void 0?void 0:D.adapter.getCellValidation(B.row,B.col);if(oe===void 0||oe.type!=="list")return;const U=A!==void 0&&A.typed!==void 0?A.typed:"";F(),D.focusSink({preventScroll:!0}),E({kind:"list",cell:B,anchorRect:_(B),current:oe.values,typed:U,commit:ce=>{if(et(t.current.adapter,B.row,B.col)){t.current.rejectReadOnly({kind:"edit",cell:B,editSession:"none"}),b();return}t.current.commitEdits([{row:B.row,col:B.col,text:ce}],{source:"edit",editSession:"discarded"}),b()},close:b});return}if(F(),D.focusSink({preventScroll:!0}),g==="note"){const oe=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(B.row,B.col),U={kind:"note",cell:B,anchorRect:_(B),current:oe,commit:ce=>{R(U,[{row:B.row,col:B.col,note:ce}])},close:b,rejected:!1,...k(B)};E(U);return}if(g==="comment"){const oe=D.adapter.getCellComments===void 0?void 0:D.adapter.getCellComments(B.row,B.col),U={kind:"comment",cell:B,anchorRect:_(B),current:oe===void 0?[]:oe,commit:ce=>{R(U,[{row:B.row,col:B.col,comments:ce}])},close:b,rejected:!1,...k(B)};E(U);return}const ee=D.adapter.getCellHyperlink===void 0?void 0:cr(D.adapter.getCellHyperlink(B.row,B.col)),le=D.adapter.getCellText(B.row,B.col),ne={kind:"link",cell:B,anchorRect:_(B),current:{text:le,url:ee},commit:oe=>{const U=oe.url===null?null:yn(oe.url);if(U===null&&oe.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(oe.url)}`);const ce=oe.text===le?{row:B.row,col:B.col,hyperlink:U}:{row:B.row,col:B.col,text:oe.text,hyperlink:U};R(ne,[ce])},close:b,canOpen:D.onHyperlinkOpen!==void 0,open:()=>{const oe=t.current.onHyperlinkOpen;oe!==void 0&&ee!==void 0&&oe(ee,B)},rejected:!1,...k(B)};E(ne)},[_,b,R,F,E,H,k]),v=i.useCallback(g=>{const A=t.current,D=A.columnMenuAt===void 0?null:A.columnMenuAt(g);return D===null||A.isEditing()&&!A.requestCommit()?!1:(F(),A.focusSink({preventScroll:!0}),E({kind:"columnMenu",cell:g,anchorRect:_(g),column:D}),!0)},[_,F,E]),x=i.useCallback(g=>{l.current==="columnMenu"&&b(g)},[b]),{enabled:K,bodyRef:y}=e;i.useEffect(()=>{const g=y.current;if(!K||g===null)return;const A=B=>{const ee=t.current;Er(ee.adapter,ee.popovers,"note-tip")&&j({clientX:B.clientX,clientY:B.clientY})},D=()=>{Er(t.current.adapter,t.current.popovers,"note-tip")&&j({cell:null})};return g.addEventListener("pointermove",A),g.addEventListener("pointerleave",D),()=>{g.removeEventListener("pointermove",A),g.removeEventListener("pointerleave",D)}},[K,y,j]),i.useEffect(()=>()=>{C.current!==null&&cancelAnimationFrame(C.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:X,popovers:Q}=e,p=e.columnMenuAt!==void 0,f=i.useMemo(()=>p||eC.some(g=>Er(X,Q,g)),[X,Q,p]);return i.useMemo(()=>({layerEnabled:f,isKindEnabled:g=>Er(t.current.adapter,t.current.popovers,g),open:W,close:b,isOpen:()=>l.current,openColumnMenu:v,closeColumnMenu:x,onCellHover:w,hideTip:d,onTipPointerEnter:()=>{u.current=!0,Z()},onTipPointerLeave:()=>{u.current=!1,c.current!==null&&V()},syncTipAriaDescribedBy:O,context:n,tipContext:o,registerCompositionEnd:g=>{M.current=g},isCompositionKey:g=>ju(g,M.current),getLayerSize:()=>{const g=t.current.handleRef.current;return g===null?{width:0,height:0}:g.getViewportSize()},tipId:$}),[f,W,b,v,x,w,d,Z,V,O,n,o,$])},rC=6,wo=(e,t)=>Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))>=rC,_c=(e,t)=>e!==null&&Kt(e,t),oC=(e,t,n)=>{let r=null,o=0;if(typeof document.caretPositionFromPoint=="function"){const l=document.caretPositionFromPoint(e,t);if(l===null)return;r=l.offsetNode,o=l.offset}else if(typeof document.caretRangeFromPoint=="function"){const l=document.caretRangeFromPoint(e,t);if(l===null)return;r=l.startContainer,o=l.startOffset}else return;if(r===null||r.nodeType!==Node.TEXT_NODE)return;const s=r.parentElement?.closest("[data-aqsp-cell]")??null;if(!(s===null||Number(s.getAttribute("data-row"))!==n.row||Number(s.getAttribute("data-col"))!==n.col))return o},Ws=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const u=e.getFrozenSize(),m=e.getViewportSize();return bn({row:jr(n,(l-t.top)/o,{scroll:a,frozenSize:u.height,trailingSize:u.trailingHeight,extent:m.height}),col:_r(r,(s-t.left)/o,{scroll:c,frozenSize:u.width,trailingSize:u.trailingWidth,extent:m.width})},n.count,r.count)},sC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),a=i.useRef(0),u=i.useRef(null),m=i.useRef(!1),C=i.useRef(null),L=i.useRef(""),M=i.useRef(!1),$=i.useRef(!1),_=i.useRef(null),G=i.useRef(null),Z=i.useCallback((d,b)=>{const{handleRef:E,rowAxis:k,colAxis:R,zoomRef:W}=t.current;return Ws(E.current,o.current,k,R,W.current,d,b)},[]),O=i.useRef(!1),F=i.useRef(null),V=i.useRef(null),H=i.useRef({clientX:0,clientY:0}),S=i.useCallback(()=>{const{autoScroller:d,bodyRef:b,onDragFrame:E}=t.current;n.current=!1,r.current=null,u.current=null,O.current=!1,F.current=null,V.current=null,m.current=!1,C.current=null,_.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),d.stop();const k=b.current;k!==null&&c.current!==null&&k.hasPointerCapture?.(c.current)&&k.releasePointerCapture(c.current),c.current=null,E(null),t.current.repaintOverlay()},[]),P=i.useCallback(()=>{if(!n.current)return;const d=r.current;d!==null&&t.current.setSelection(d),S()},[S]),{enabled:j,bodyRef:w}=e;return i.useEffect(()=>{const d=w.current;if(!j||d===null)return;const b=f=>f instanceof Element&&f.closest("[data-aqsp-cells]")!==null,E=(f,g)=>{const{handleRef:A,rowAxis:D,colAxis:B,zoomRef:ee}=t.current;return Ws(A.current,d.getBoundingClientRect(),D,B,ee.current,f,g)},k=f=>{const g=t.current;if(G.current=null,f.pointerType==="mouse"&&f.button===0&&(m.current=!1,C.current=null,$.current=!1,_.current=null),M.current=b(f.target),!M.current){if(f.pointerType==="mouse"){if(f.preventDefault(),f.button!==0)return;if(g.getPointing?.()){g.focusSink();return}if(g.isEditing()&&!g.requestCommit()){f.stopPropagation(),g.focusSink();return}g.focusSink()}return}if(L.current=f.pointerType,f.pointerType!=="mouse"){if(g.isSortHeaderCell!==void 0){const U=E(f.clientX,f.clientY);U!==null&&g.isSortHeaderCell(U)&&(f.preventDefault(),G.current={pointerId:f.pointerId,pointerType:f.pointerType,cell:U,clientX:f.clientX,clientY:f.clientY})}return}if(f.button!==0){f.preventDefault();return}if((g.pointDragRef===void 0?null:g.pointDragRef.current)?.onPointerDown(f))return;if(g.isEditing()&&!g.requestCommit()){f.preventDefault(),g.focusSink();return}o.current=d.getBoundingClientRect();const D=Z(f.clientX,f.clientY);if(D===null)return;if(f.preventDefault(),g.focusSink(),(f.ctrlKey||f.metaKey)&&!f.shiftKey&&g.openHyperlinkAt?.(D)===!0){$.current=!0;return}const B=g.getSelection();r.current=B;const ee=f.shiftKey,le=f.ctrlKey||f.metaKey,ne=le&&!ee&&B.ranges.some(U=>Wt(U,D));m.current=ne,C.current=ne?D:null,ne||g.setSelection(Nr(B,D,{extend:ee,append:le})),!(ee||le||f.altKey)&&g.isSortHeaderCell?.(D)===!0&&(_.current={cell:D,clientX:f.clientX,clientY:f.clientY}),n.current=!0,g.repaintOverlay(),s.current={clientX:f.clientX,clientY:f.clientY},c.current=f.pointerId,a.current=f.buttons;try{d.setPointerCapture(f.pointerId)}catch{c.current=null}const oe=ne?D:g.getSelection().anchor;u.current=U=>he(oe,U),F.current=oe.col,V.current=oe.row,g.autoScroller.stop(),O.current=!1,H.current={clientX:f.clientX,clientY:f.clientY}},R=f=>c.current!==null?f.pointerId===c.current:f.pointerType==="mouse",W=f=>{if(!(n.current&&R(f)))return;s.current={clientX:f.clientX,clientY:f.clientY};const g=_.current;if(g!==null&&wo(g,f)&&(_.current=null),!O.current&&u.current!==null){const A=Math.abs(f.clientX-H.current.clientX),D=Math.abs(f.clientY-H.current.clientY);Math.max(A,D)>=Lo&&(O.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:u.current,anchorCol:F.current??void 0,anchorRow:V.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const A=u.current;if(!n.current||A===null)return;const D=t.current,B=Z(s.current.clientX,s.current.clientY);B!==null&&D.onDragFrame(A(B))}))},v=f=>{const g=G.current;g!==null&&f.pointerId===g.pointerId&&wo(g,f)&&(G.current=null),W(f),n.current&&R(f)&&(a.current&1)!==0&&(f.buttons&1)===0&&y(f)},x=f=>{const g=G.current;if(g!==null&&f.pointerId===g.pointerId&&(G.current=null,!wo(g,f)&&_c(E(f.clientX,f.clientY),g.cell)&&t.current.onHeaderSortPress?.(g.cell.col,g.pointerType)),f.button!==0||!(n.current&&R(f)))return;const A=_.current,D=A!==null&&!wo(A,f)&&_c(Z(f.clientX,f.clientY),A.cell);y(f),D&&t.current.onHeaderSortPress?.(A.cell.col,f.pointerType)},K=f=>{const g=G.current;g!==null&&f.pointerId===g.pointerId&&(G.current=null)},y=f=>{const g=t.current,A=Z(f.clientX,f.clientY);if(A!==null){const D=C.current;m.current&&D!==null?g.setSelection(qu(g.getSelection(),he(D,A),D)):g.setSelection(xn(g.getSelection(),A))}S()},X=f=>{!n.current||c.current===null||f.pointerId!==c.current||P()},Q=f=>{const g=t.current;if(!b(f.target)||L.current!=="mouse"||g.isAnyDragging())return;if(g.isEditing()&&!g.requestCommit()){g.focusSink();return}g.focusSink(),o.current=d.getBoundingClientRect();const A=Z(f.clientX,f.clientY);if(A===null)return;const D=g.getSelection();D.ranges.some(ee=>Wt(ee,A))||g.setSelection(Nr(D,A,{extend:!1,append:!1})),g.onContextMenuSelect(A,f)},p=f=>{const g=t.current;if(!M.current||L.current!=="mouse"||g.getPointing?.()||$.current)return;o.current=d.getBoundingClientRect();const A=Z(f.clientX,f.clientY);A!==null&&Kt(g.getSelection().active,A)&&g.onRequestEdit(A,g.caretFromPointEnabled(A)?oC(f.clientX,f.clientY,A):void 0)};return d.addEventListener("pointerdown",k),d.addEventListener("pointermove",v),d.addEventListener("pointerup",x),d.addEventListener("pointercancel",K),d.addEventListener("lostpointercapture",X),d.addEventListener("contextmenu",Q),d.addEventListener("dblclick",p),()=>{d.removeEventListener("pointerdown",k),d.removeEventListener("pointermove",v),d.removeEventListener("pointerup",x),d.removeEventListener("pointercancel",K),d.removeEventListener("lostpointercapture",X),d.removeEventListener("contextmenu",Q),d.removeEventListener("dblclick",p),S()}},[j,w,Z,S,P]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:P,cancelDrag:S}),[P,S])},lC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),m=i.useRef(null),C=i.useRef(null),L=i.useRef(!1),M=i.useCallback((F,V)=>{const{handleRef:H,rowAxis:S,colAxis:P,zoomRef:j}=t.current;return Ws(H.current,o.current,S,P,j.current,F,V)},[]),$=i.useCallback(()=>{const{autoScroller:F,bodyRef:V,onDragFrame:H}=t.current;n.current=!1,r.current=null,m.current=null,C.current=null,L.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),F.stop();const S=V.current;S!==null&&a.current!==null&&S.hasPointerCapture?.(a.current)&&S.releasePointerCapture(a.current),a.current=null,H(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const F=r.current;F!==null&&t.current.restoreSink(F),$()},[$]),G=i.useCallback(F=>{const V=t.current,H=V.bodyRef.current;if(!V.enabled||H===null||!V.getPointing())return!1;o.current=H.getBoundingClientRect();const S=M(F.clientX,F.clientY);if(S===null)return o.current=null,!1;const P=V.captureSink();if(P===null)return o.current=null,!1;F.preventDefault(),V.focusSink(),r.current=P,C.current=S,V.insertReference(S,"cells"),n.current=!0,s.current={clientX:F.clientX,clientY:F.clientY},l.current={clientX:F.clientX,clientY:F.clientY},a.current=F.pointerId,u.current=F.buttons;try{H.setPointerCapture(F.pointerId)}catch{a.current=null}return m.current=j=>{const w=he(S,j);return t.current.insertReference(w,"cells"),w},V.autoScroller.stop(),L.current=!1,V.onDragFrame(he(S,S)),!0},[M]),{enabled:Z,bodyRef:O}=e;return i.useEffect(()=>{const F=O.current;if(!Z||F===null)return;const V=j=>a.current!==null?j.pointerId===a.current:j.pointerType==="mouse",H=j=>{if(!(n.current&&V(j)))return;s.current={clientX:j.clientX,clientY:j.clientY};const w=m.current,d=C.current;if(!L.current&&w!==null&&d!==null){const b=Math.abs(j.clientX-l.current.clientX),E=Math.abs(j.clientY-l.current.clientY);Math.max(b,E)>=Lo&&(L.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:w,anchorCol:d.col,anchorRow:d.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const b=m.current;if(!n.current||b===null)return;const E=M(s.current.clientX,s.current.clientY);E!==null&&t.current.onDragFrame(b(E))})),(u.current&1)!==0&&(j.buttons&1)===0&&$()},S=j=>{j.button!==0||!(n.current&&V(j))||$()},P=j=>{!n.current||a.current===null||j.pointerId!==a.current||$()};return F.addEventListener("pointermove",H),F.addEventListener("pointerup",S),F.addEventListener("lostpointercapture",P),()=>{F.removeEventListener("pointermove",H),F.removeEventListener("pointerup",S),F.removeEventListener("lostpointercapture",P),$()}},[Z,O,M,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:$,onPointerDown:G}),[_,$,G])},iC=Object.freeze({width:0,height:0}),Os=33,cC=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,aC=(e,t,n)=>{const r=(n-t)/(Os-1);let o=-1,s=-1;for(let c=0;c<Os;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,a)=>{let u=c,m=a;for(;Math.abs(m-u)>1;){const C=(u+m)/2;e(C)?m=C:u=C}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===Os-1?n:l(t+r*(s+1),t+r*s)}},uC=e=>{if(e===void 0)return!1;if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the options must be an object (got ${String(e)})`);const{scroll:t}=e;if(t!==void 0&&t!==!0&&t!==!1)throw new RangeError(`[spreadsheet] setSelection: options.scroll must be true, false or absent (got ${String(t)})`);return t===!0},dC=(e,t)=>{if(!Number.isInteger(e)||e<0||e>0&&e>t)throw new RangeError(`[spreadsheet] headerRows must be a whole number from 0 to frozenRows = ${t} (got ${e})`)},fC=e=>{if(e!==void 0&&(typeof e!="string"||e===""||/\s/u.test(e)))throw new RangeError(`[spreadsheet] labelledBy must be one non-empty id without whitespace (got ${JSON.stringify(e)})`)},pC=e=>{if(e===void 0)return;if(![e.startRow,e.startCol,e.endRow,e.endCol].every(n=>Number.isInteger(n)&&n>=0)||e.startRow>e.endRow||e.startCol>e.endCol)throw new RangeError(`[spreadsheet] frame must hold non-negative integer bounds with each start at most its end (got startRow ${String(e.startRow)}, startCol ${String(e.startCol)}, endRow ${String(e.endRow)}, endCol ${String(e.endCol)})`)},hC=Object.freeze({showArrowButtons:!0,enableThumbDrag:!0,enableTrackClick:!0}),mC=e=>{if(e!==void 0){if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] scrollBarControls must be an object or absent (got ${typeof e=="string"?JSON.stringify(e):String(e)})`);for(const t of Object.keys(hC)){const n=e[t];if(n!==void 0&&typeof n!="boolean")throw new RangeError(`[spreadsheet] scrollBarControls.${t} must be true, false or absent (got ${typeof n=="string"?JSON.stringify(n):String(n)})`)}}},jc=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${typeof t=="string"?JSON.stringify(t):String(t)})`);return t},gC=24,wC=200,Hu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Ic=5,CC=/^#[0-9A-Fa-f]{6}$/,yC=Object.freeze({row:!1,column:!1,intersection:!1}),Hc=Object.freeze({ok:!0}),Bc=(e,t)=>{if(t===void 0)return Hu;if(t.length!==Ic)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Ic} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!CC.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},bC=e=>{for(const t of["row","column","intersection"])if(rt(e[t])===null)throw new RangeError(`[spreadsheet] highlightColors.${t} is not a colour (got ${JSON.stringify(e[t])})`);if(!(Number.isFinite(e.opacity)&&e.opacity>=0&&e.opacity<=1))throw new RangeError(`[spreadsheet] highlightColors.opacity must be a number in [0, 1] (got ${e.opacity})`);return e},vC=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return hu},RC=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},SC=e=>{const t=i.useRef(null),n=t.current;return n!==null&&ot.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Un={ranges:[he({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},EC=i.forwardRef(function({adapter:t,headerRows:n=0,sortFilter:r,readOnly:o=!1,labelledBy:s,defaultRowHeight:l=gC,defaultColumnWidth:c=Pe.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:a=0,frozenRows:u=0,frozenTrailingColumns:m=0,frozenTrailingRows:C=0,tapScrollCircleOptions:L,scrollBarControls:M,overscanRows:$,overscanCols:_,background:G,onRenderTruncated:Z,renderCell:O,onSelectionChange:F,onEditSessionChange:V,onCellContextMenu:H,onUndoRequest:S,onRedoRequest:P,onCopyMultiRange:j,onOperationRejected:w,onEditRejected:d,onReadOnlyRejected:b,formatReadOnlyAnnouncement:E,dataVersion:k,maxOperationCells:R=Pe.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:W=!0,enableResizeUI:v=!0,headings:x=!0,onContentSizeChange:K,frame:y,formatCellAnnouncement:X,formatSelectionAnnouncement:Q,formatCommandAnnouncement:p,formatResizeAnnouncement:f,locale:g,labels:A,shortcuts:D,onCommandBlockedWhileEditing:B,colors:ee,formats:le,highlight:ne,defaultHighlight:oe,onHighlightChange:U,highlightColors:ce,popovers:$e,renderPopover:ze,onClipChange:je,onHyperlinkOpen:pt,onValidationRejected:tt,onPasteSpecialRequest:Ln,onClipboardUnavailable:Oe,onPasteResolved:He,now:Ve=Date.now,zoom:st,defaultZoom:St,onZoomChange:Yt,testId:We,className:Et,__onCellRender:Ir,__onVirtualKeyboardRaise:Hr,__maxRenderedCells:zn},Ft){const ae=i.useMemo(()=>o?am(t):t,[t,o]),Ce=kc(ae.rowCount,l),we=kc(ae.colCount,c),ar=i.useRef(null);ar.current===null&&(ar.current=I0());const Ne=ar.current,sn=ot.resolveVirtualScrollLocale(g),lt=i.useMemo(()=>nu(g,A),[g,A]),Nn=SC(_m(lt)),kt=i.useMemo(()=>Mm(D),[D]),Dn=i.useMemo(()=>{if(!v)return;const N=[...kt].filter(([,J])=>gs.includes(J)).sort(([,J],[,re])=>gs.indexOf(J)-gs.indexOf(re)).map(([J])=>km(J)).filter(J=>J!==null);return N.length===0?void 0:N.join(" ")},[kt,v]),Fn=i.useMemo(()=>({fill:Bc("fill",ee===void 0?void 0:ee.fill),font:Bc("font",ee===void 0?void 0:ee.font)}),[ee]),Pn=i.useMemo(()=>ce===void 0?void 0:bC(ce),[ce]);if(ae.getConditionalFormats!==void 0&&ae.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");dC(n,u),fC(s),pC(y),mC(M);const qn=i.useCallback(()=>Ne.get().editVersion,[Ne]),Br=i.useCallback(h=>Ne.subscribeCoalesced(h),[Ne]),_o=i.useSyncExternalStore(Br,qn,qn)+(k===void 0?0:k),ur=ae.getConditionalFormats===void 0?null:ae.getConditionalFormats(),_n=i.useMemo(()=>({index:ur===null?null:Lu(ur),memo:ul()}),[ae,ur,_o]),dr=i.useRef(_n.index);dr.current=_n.index;const fr=i.useRef(_n.memo);fr.current=_n.memo;const Ot=i.useCallback((h,N,J)=>dl(ae,dr.current,fr.current,h,N,J),[ae]),Ke=i.useRef(null),[jo,T]=i.useState(()=>Pe.clampSpreadsheetZoom(St??1)),z=Pe.clampSpreadsheetZoom(st??jo),Y=i.useRef(z);Y.current=z;const I=i.useRef(z);I.current=z;const te=i.useRef(null),se=i.useRef(Yt);se.current=Yt;const fe=i.useRef(st!==void 0);fe.current=st!==void 0;const Le=i.useCallback(h=>{const N=Pe.clampSpreadsheetZoom(h);N!==I.current&&(I.current=N,fe.current||T(N),se.current?.(N))},[]),ue=ae.rowCount===0||ae.colCount===0,Ae=!ue,Ye=ae.colCount,Me=i.useMemo(()=>r===void 0||ue?null:t0(r,Ye,n),[r,ue,Ye,n]),Ie=i.useRef(r);Ie.current=r;const me=i.useRef(Me);me.current=Me,i.useEffect(()=>{const h=Ke.current;if(!Ae||h===null)return;const N=re=>{re.defaultPrevented||!re.altKey||re.ctrlKey||re.metaKey||re.shiftKey||re.deltaY!==0&&(re.preventDefault(),re.stopPropagation(),!te.current?.()&&Le(Pe.stepSpreadsheetZoom(I.current,re.deltaY<0?1:-1)))},J=re=>{if(re.defaultPrevented||!(re.ctrlKey&&re.altKey)||re.metaKey||re.getModifierState("AltGraph"))return;const ge=re.key==="="||re.key==="+"?Pe.stepSpreadsheetZoom(I.current,1):re.key==="-"?Pe.stepSpreadsheetZoom(I.current,-1):re.key==="0"?1:null;ge!==null&&(re.preventDefault(),re.stopPropagation(),!te.current?.()&&Le(ge))};return h.addEventListener("wheel",N,{passive:!1,capture:!0}),h.addEventListener("keydown",J,!0),()=>{h.removeEventListener("wheel",N,{capture:!0}),h.removeEventListener("keydown",J,!0)}},[Le,Ae]);const ie=i.useRef(null),be=i.useRef(null),Ee=i.useRef(null),ve=i.useRef(null),Re=i.useRef(null),de=i.useRef(null),De=i.useRef(null),ht=i.useRef(0),it=i.useRef(null),ct=i.useRef(0),Te=i.useRef(null),at=i.useRef(null),Pt=i.useRef(null),mt=i.useRef(null),Xe=i.useRef(null),qt=i.useRef(null),Wr=i.useRef(null),[ln,Io]=i.useState(Un),_t=i.useRef(ln),Xt=i.useCallback(()=>_t.current,[]),[Bu,Vu]=i.useState(()=>oe===void 0?yC:oe),jn=ne!==void 0?ne:Bu,Ho=i.useRef(jn);Ho.current=jn;const Wu=vC(Pn,jn),hl=i.useRef(ne!==void 0);hl.current=ne!==void 0;const ml=i.useRef(U);ml.current=U;const Ku=i.useCallback(h=>{hl.current||Vu(h),ml.current?.(h)},[]),gl=i.useRef(null),Bo=i.useRef(null),Ut=i.useRef(null),Vo=i.useRef(()=>!1),wl=i.useRef(()=>{}),Cl=i.useRef(()=>null),yl=i.useRef(()=>{}),vn=i.useCallback(()=>Vo.current(),[]),Wo=i.useMemo(()=>({getPointing:()=>Vo.current(),insertReference:(h,N)=>wl.current(h,N)}),[]),bl=i.useRef(en),vl=i.useRef(null),Ko=i.useRef({interactive:null,tip:null}),Rl=i.useRef(null),Sl=i.useRef(null),Kr=i.useRef(()=>{}),El=i.useRef(()=>!1),gt=i.useRef(null),pr=i.useCallback(()=>{const h=gt.current;if(h===null||h.isOpen()!=="message")return!1;const N=h.context;return N===null||N.kind!=="message"||!N.current.rejected?!1:(h.close(),!0)},[]),Yo=i.useRef(()=>!1),kl=i.useRef(()=>!1),Ol=i.useRef(null),Xo=i.useRef(()=>Promise.resolve("rejected")),Fe=i.useCallback(()=>{gl.current?.()},[]),xt=i.useCallback(h=>{de.current?.focus(h)},[]),Ue=i.useCallback(()=>{xt({preventScroll:!0})},[xt]),Uo=i.useRef(!1),Yu=i.useCallback(()=>{const h=Ke.current;if(h!==null){Uo.current=!0;try{h.focus()}finally{Uo.current=!1}}},[]),ut=i.useCallback(()=>{const h=de.current;h!==null&&(h.value=" ",h.setSelectionRange(0,1))},[]),In=i.useCallback((h,N)=>{if(h===null)return;const J=N?"":"none";h.style.display!==J&&(h.style.display=J)},[]),At=i.useCallback(()=>{const h=De.current;if(h!==null){const J=Math.max(0,Re.current?.getScrollPosition().y??0),re=Re.current?.getFrozenSize().height??0;h.style.transform=`translateY(${ht.current-J-re}px)`}const N=Re.current;if(N!==null&&(Xe.current!==null||qt.current!==null)){const J=N.getFrozenSize();In(Xe.current,J.height>0),In(qt.current,J.trailingHeight>0)}},[In]),Tt=i.useCallback(()=>{const h=it.current;if(h!==null){const J=Math.max(0,Re.current?.getScrollPosition().x??0),re=Re.current?.getFrozenSize().width??0;h.style.transform=`translateX(${ct.current-J-re}px)`}const N=Re.current;if(N!==null&&(Pt.current!==null||mt.current!==null)){const J=N.getFrozenSize();In(Pt.current,J.width>0),In(mt.current,J.trailingWidth>0)}},[In]),hr=i.useRef(null),Hn=i.useCallback(()=>{Pt.current===null&&mt.current===null&&Xe.current===null&&qt.current===null||hr.current===null&&(hr.current=requestAnimationFrame(()=>{hr.current=null,At(),Tt(),Fe()}))},[At,Tt,Fe]);i.useEffect(()=>()=>{hr.current!==null&&cancelAnimationFrame(hr.current)},[]);const Go=i.useRef(null),Zo=i.useRef(null);(Go.current===null||Zo.current?.rowAxis!==Ce||Zo.current?.colAxis!==we)&&(Zo.current={rowAxis:Ce,colAxis:we},Go.current=N0({handleRef:Re,rowAxis:Ce,colAxis:we}));const Yr=i.useCallback(h=>{const N=Re.current,J=N===null?{x:0,y:0}:N.getScrollPosition(),re=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),ge=N===null?{width:0,height:0}:N.getViewportSize(),ke=Y.current;return{top:Mn(Ce,h.row,{scroll:Math.max(0,J.y),frozenCount:re.rows,trailingCount:re.trailingRows,extent:ge.height})*ke,left:$n(we,h.col,{scroll:Math.max(0,J.x),frozenCount:re.cols,trailingCount:re.trailingCols,extent:ge.width})*ke,width:we.sizeOf(h.col)*ke,height:Ce.sizeOf(h.row)*ke}},[Ce,we]),xl=i.useCallback(h=>{const N=ve.current,J=Ke.current,re=be.current;if(N===null||J===null||re===null||Re.current===null)return;const ge=Y.current,ke=Yr(h),Qe=re.offsetTop*ge+ke.top,ft=re.offsetLeft*ge+ke.left,Ze=Math.max(0,Qe),Bt=Math.max(0,ft),un=Math.min(J.clientHeight,Qe+ke.height),Jr=Math.min(J.clientWidth,ft+ke.width);if(un<=Ze||Jr<=Bt)return;N.style.top=`${Ze}px`,N.style.left=`${Bt}px`,N.style.width=`${Jr-Bt}px`,N.style.height=`${un-Ze}px`;const Kn=N.getBoundingClientRect();Kn.width===0&&Kn.height===0||N.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Yr]),jt=i.useCallback(h=>{Go.current?.(h),xl(h)},[xl]),Xu=i.useCallback(()=>{const h=Re.current,N=h===null?-1:h.getViewportSize().height,J=ie.current,re=Ke.current;if(N<=0||J===null||re===null)return N;const ge=J.getBoundingClientRect(),ke=re.getRootNode();if(ge.height<=0||J.offsetHeight<=0||!cC(ke))return N;const Qe=re.ownerDocument.documentElement,ft=Math.max(ge.left,0),Ze=Math.min(ge.right,Qe.clientWidth),Bt=Math.max(ge.top,0)+.5,un=Math.min(ge.bottom,Qe.clientHeight)-.5,Jr=(ft+Ze)/2,Kn=Ze>ft&&un>=Bt?aC(Ad=>{const di=ke.elementFromPoint(Jr,Ad);return di!==null&&re.contains(di)},Bt,un):null,xd=Kn===null?Qe.clientHeight:Kn.bottom-Kn.top+1;return Math.min(N,xd*(J.offsetHeight/ge.height))},[]),Al=i.useRef(K);Al.current=K;const Jo=i.useRef(null),Gt=i.useCallback(()=>{const h=Al.current;if(h===void 0)return;const N=be.current;let J;if(N===null)J=iC;else{if(N.getClientRects().length===0)return;{const ge=Ee.current,ke=Y.current;J={width:((ge===null?0:ge.offsetWidth)+we.totalSize()+Pe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke,height:((ge===null?0:ge.offsetHeight)+Ce.totalSize()+Pe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke}}}const re=Jo.current;re!==null&&re.width===J.width&&re.height===J.height||(Jo.current=J,h(J))},[Ce,we]);i.useLayoutEffect(()=>{if(K===void 0){Jo.current=null;return}Gt()});const Tl=K!==void 0;i.useEffect(()=>{const h=be.current;if(!Tl||h===null)return;const N=new ResizeObserver(()=>Gt());return N.observe(h),()=>N.disconnect()},[Tl,Gt,ue]);const Bn=i.useRef(null),Rn=i.useRef(null),Vn=i.useCallback(h=>{Bn.current!==null&&window.clearTimeout(Bn.current),Rn.current!==null&&(cancelAnimationFrame(Rn.current),Rn.current=null),Bn.current=window.setTimeout(()=>{Bn.current=null;const N=Wr.current;N!==null&&(N.textContent="",Rn.current=requestAnimationFrame(()=>{Rn.current=null,N.textContent=h}))},wC)},[]);i.useEffect(()=>()=>{Bn.current!==null&&window.clearTimeout(Bn.current),Rn.current!==null&&cancelAnimationFrame(Rn.current)},[]);const Wn=i.useCallback(h=>{b?.(h),E!==void 0&&Vn(E(h))},[b,E,Vn]),$l=i.useCallback((h,N)=>{if(X===void 0&&Q===void 0)return;const J=N.ranges[N.ranges.length-1],re=Rt(J),ge=N.ranges.length===1&&re.rows===1&&re.cols===1,ke=h.ranges[h.ranges.length-1],Qe=h.ranges.length!==N.ranges.length||ke.startRow!==J.startRow||ke.startCol!==J.startCol||ke.endRow!==J.endRow||ke.endCol!==J.endCol,ft=()=>{if(X!==void 0){const Ze=N.active,Bt=ae.getCellText(Ze.row,Ze.col),un=ae.getCellFormat===void 0?void 0:Ot(Ze.row,Ze.col,()=>Bt);Vn(X({row:Ze.row,col:Ze.col,text:Bt,displayText:An(Bt,un===void 0?void 0:un.value),columnName:Pe.columnIndexToName(Ze.col),...Ka(ae)?{readOnly:et(ae,Ze.row,Ze.col)}:{}}))}};if(ge){ft();return}if(Qe){Q!==void 0&&Vn(Q({range:J,anchor:N.anchor,active:N.active,rangeRowCount:re.rows,rangeColCount:re.cols,rangeCount:N.ranges.length}));return}ft()},[ae,X,Q,Vn,Ot]),cn=i.useCallback((h,N)=>{const J=_t.current;Object.is(h,J)||A0(h,J)||(_t.current=h,Io(h),F?.(h,N),$l(J,h),(Ut.current?.()??!1)||ut())},[F,$l,ut]),$t=i.useCallback(h=>cn(h,"user"),[cn]),Uu=i.useCallback(h=>{const N=_t.current;if(h.mode==="cycle"){const re=_u(N,h.direction);$t(re),jt(re.active);return}const J=bn(h.cell,Ce.count,we.count);if(h.mode==="extend"){$t(xn(N,J)),jt(J);return}$t(Nr(N,J,{extend:!1,append:!1})),jt(J)},[$t,jt,Ce,we]),Ge=i.useCallback(()=>Ut.current?.()??!1,[]),Ml=i.useRef(null),Je=i.useCallback(()=>Ml.current?.()??!0,[]),Ll=i.useRef(null),mr=i.useCallback((h,N)=>{const J=Ut.current?.()??!1;Ll.current?.(h,N),!J&&(Ut.current?.()??!1)&&pr()},[pr]),[Gu,Qo]=i.useState(!1),zl=i.useCallback(()=>{Hr?.(),Qo(!0)},[Hr]),Zu=i.useCallback((h,N)=>{et(ae,h.row,h.col)||zl(),mr("edit",N)},[ae,zl,mr]),Nl=i.useRef(null),Xr=i.useCallback(()=>Nl.current?.()??null,[]),Dl=i.useRef(null),wt=i.useCallback(()=>{Dl.current?.()},[]),Fl=i.useRef(null),Pl=i.useCallback(h=>{Fl.current?.(h)},[]),ql=i.useRef(()=>{}),Ur=i.useCallback(h=>{const N=Ie.current;return N===void 0||!Je()?!1:(gt.current?.hideTip(),gt.current?.close(),wt(),a0(N.state,h)||N.onStateChange(h),!0)},[Je,wt]),Ju=i.useCallback((h,N)=>{const J=Ie.current,re=me.current,ge=re===null?null:sr(re,h);J!==void 0&&ge?.sortable===!0&&Ur(r0(J.state,ge.key)),N!=="mouse"&&xt({preventScroll:!0})},[Ur,xt]),_l=i.useCallback(h=>{const N=gt.current,J=me.current;if(N===null||J===null)return;const re=N.context;if(re!==null&&re.kind==="columnMenu"&&re.cell.col===h){N.close();return}N.openColumnMenu({row:J.headerRow,col:h})},[]),jl=i.useCallback(h=>{const N=ae.getCellText(h.row,h.col);return Fu(ae.getCellFormat===void 0?N:An(N,ae.getCellFormat(h.row,h.col)?.value))},[ae]),Il=i.useCallback(h=>Ke.current?.contains(h)===!0,[]),Qu=i.useMemo(()=>{if(Me===null||!Me.columns.some(N=>N?.sortable===!0))return;const h=Me;return N=>N.row===h.headerRow&&h.columns[N.col]?.sortable===!0},[Me]),es=i.useMemo(()=>{if(Me===null||!Me.hasControls)return;const h=Me;return N=>N.row===h.headerRow?sr(h,N.col):null},[Me]),Gr=i.useRef(0),Sn=i.useCallback((h,N,J)=>{let re;if(N.source==="paste"){const ge=RC(J);if(h.length===0&&ge.conditionalFormats.length===0)return null;Gr.current+=1,re={transaction:Gr.current,source:"paste",sameSheet:ge.sameSheet,conditionalFormats:ge.conditionalFormats}}else{if(h.length===0)return null;Gr.current+=1,re={transaction:Gr.current,source:N.source}}try{ae.applyEdits(h,re)}catch(ge){return d?.(ge,N),null}return Ne.bumpEdit(),Pl(N.source),re.transaction},[ae,Ne,d,Pl]),ed=i.useCallback((h,N)=>Sn(h,{source:"paste"},N),[Sn]),td=i.useCallback(h=>{Ne.setVy(h.y),At(),Tt(),Fe()},[Ne,At,Tt,Fe]),Hl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),nd=i.useCallback(h=>{Ne.setRowRange(h.renderingRowStart,h.renderingRowEnd),Ne.setColRange(h.renderingColStart,h.renderingColEnd);const N=Hl.current;(N.rowStart!==h.renderingRowStart||N.rowEnd!==h.renderingRowEnd||N.colStart!==h.renderingColStart||N.colEnd!==h.renderingColEnd)&&(Hl.current={rowStart:h.renderingRowStart,rowEnd:h.renderingRowEnd,colStart:h.renderingColStart,colEnd:h.renderingColEnd},Fe())},[Ne,Fe]),Bl=i.useRef(()=>"add"),an=i.useCallback(h=>{Bo.current?.(h,Bl.current())},[]),rd=i.useCallback(h=>{Bo.current?.(h,"point")},[]),Vl=i.useRef(null),ts=i.useCallback(h=>{Vl.current?.(h)},[]),Wl=i.useRef(null),od=i.useCallback(h=>{Wl.current?.(h)},[]),Kl=i.useRef(null),Yl=i.useCallback((h,N)=>{if(N.length===0)return;const J=Re.current;if(h==="col"){for(const re of N){const ge=Math.round(re.size);we.resize(re.index,ge),J?.updateColSize(re.index,ge)}Ne.bumpColVersion(),Tt(),Fe(),Hn(),Gt();return}for(const re of N){const ge=Math.round(re.size);Ce.resize(re.index,ge),J?.updateRowSize(re.index,ge)}Ne.bumpRowGeometry(),At(),Fe(),Hn(),Gt()},[Ce,we,Ne,Tt,At,Fe,Hn,Gt]),Xl=v?Yl:void 0,sd=i.useCallback((h,N)=>{H?.(h,{kind:"pointer",event:N})},[H]),ld=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:an,axis:"both",zoomRef:Y}),id=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:an,axis:"x",zoomRef:Y}),cd=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:an,axis:"y",zoomRef:Y}),ad=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:ts,axis:"x",zoomRef:Y}),ud=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:ts,axis:"y",zoomRef:Y}),dd=Xn({handleRef:Re,rowAxis:Ce,colAxis:we,bodyRef:ie,onDragFrame:an,axis:"both",zoomRef:Y}),Ul=i.useRef(null),Gl=i.useRef(()=>!1),gr=i.useCallback(()=>Gl.current(),[]),Mt=sC({zoomRef:Y,enabled:!ue,rowAxis:Ce,colAxis:we,handleRef:Re,bodyRef:ie,isEditing:Ge,requestCommit:Je,getSelection:Xt,setSelection:$t,focusSink:Ue,onDragFrame:an,onContextMenuSelect:sd,onRequestEdit:Zu,caretFromPointEnabled:h=>{if(O!==void 0||ae.getCellFormula!==void 0&&ae.getCellFormula(h.row,h.col)!==void 0)return!1;if(ae.getCellFormat===void 0)return!0;const N=ae.getCellText(h.row,h.col);return An(N,ae.getCellFormat(h.row,h.col)?.value)===N},isAnyDragging:gr,autoScroller:ld,repaintOverlay:Fe,pointDragRef:Ul,getPointing:vn,openHyperlinkAt:pt===void 0||ae.getCellHyperlink===void 0?void 0:h=>{const N=ae.getCellHyperlink===void 0?void 0:cr(ae.getCellHyperlink(h.row,h.col));return N===void 0?!1:(pt(N,h),!0)},isSortHeaderCell:Qu,onHeaderSortPress:Ju}),It=qc({zoomRef:Y,enabled:!ue&&x,axis:"col",headerRef:Te,mainAxis:we,crossCount:ae.rowCount,handleRef:Re,isEditing:Ge,requestCommit:Je,getSelection:Xt,setSelection:$t,focusSink:Ue,onDragFrame:an,autoScroller:id,repaintOverlay:Fe,pointing:Wo}),Ht=qc({zoomRef:Y,enabled:!ue&&x,axis:"row",headerRef:at,mainAxis:Ce,crossCount:ae.colCount,handleRef:Re,isEditing:Ge,requestCommit:Je,getSelection:Xt,setSelection:$t,focusSink:Ue,onDragFrame:an,autoScroller:cd,repaintOverlay:Fe,pointing:Wo}),dt=x0({zoomRef:Y,enabled:!ue&&v&&x,colBandRef:Te,rowBandRef:at,fontSourceRef:ie,colAxis:we,rowAxis:Ce,viewStore:Ne,handleRef:Re,isEditing:Ge,requestCommit:Je,focusSink:Ue,getSelection:Xt,adapter:ae,autofitEnabled:O===void 0,headerRows:n,defaultRowHeight:l,defaultColumnWidth:c,maxOperationCells:R,onOperationRejected:w,resizeTracks:Yl,writeResizeGuide:od,repaintOverlay:Fe,isPointing:vn}),Lt=V0({zoomRef:Y,enabled:!ue&&W,handleNodeRef:Kl,bodyRef:ie,rowAxis:Ce,colAxis:we,handleRef:Re,getSelection:Xt,setSelection:$t,focusSink:Ue,adapter:ae,commitEdits:Sn,maxOperationCells:R,onOperationRejected:w,rejectReadOnly:Wn,writeFillPreview:ts,repaintOverlay:Fe,xAutoScroller:ad,yAutoScroller:ud}),Ct=lC({zoomRef:Y,enabled:!ue,bodyRef:ie,handleRef:Re,rowAxis:Ce,colAxis:we,getPointing:vn,insertReference:Wo.insertReference,captureSink:()=>Cl.current(),restoreSink:h=>yl.current(h),focusSink:Ue,autoScroller:dd,onDragFrame:an});Ul.current=Ct;const wr=i.useCallback(()=>Mt.isDragging()||It.isDragging()||Ht.isDragging()||dt.isDragging()||Lt.isDragging()||Ct.isDragging(),[Mt,It,Ht,dt,Lt,Ct]);te.current=wr,Gl.current=wr,Bl.current=()=>Ct.isDragging()?"point":Mt.getDragMode();const fd=i.useCallback(()=>{Mt.abortDrag(),It.abortDrag(),Ht.abortDrag(),dt.abortDrag(),Lt.abortDrag(),Ct.abortDrag()},[Mt,It,Ht,dt,Lt,Ct]),ns=i.useCallback(()=>_t.current.active,[]),Zl=i.useCallback((h,N)=>{const J=ae.getCellValidation===void 0?void 0:ae.getCellValidation(h.row,h.col);if(J===void 0)return Hc;const re=ae.evaluateFormula,ge=su(J,N,sn,re===void 0?void 0:ke=>re(ke,h));return ge.ok||J.strict!==!0?Hc:(tt?.({cell:h,rule:J,text:N,message:ge.message}),gt.current?.isKindEnabled("message")&&Kr.current("message",{message:ge.message,rejected:!0}),ge)},[ae,tt,sn]),Be=Sw({enabled:!ue,sinkRef:de,rootRef:Ke,adapter:ae,commitEdits:Sn,getActive:ns,ensureCellVisible:jt,focusSink:xt,rearmSink:ut,discardClip:wt,isDragging:gr,rejectReadOnly:Wn,resolveEditAlign:h=>{if(ae.getCellFormat===void 0)return null;const N=Ro(ae,h.row,h.col);return Wa(Ot(h.row,h.col,N),N)},resolveEditPaint:h=>ae.getCellFormat===void 0?null:sp(Ot(h.row,h.col,Ro(ae,h.row,h.col))),editPaintRef:bl,repaintOverlay:Fe,validateCommit:Zl,onSessionChange:V});Ut.current=Be.isEditing,Ml.current=Be.requestCommit,Ll.current=Be.startEdit,Vo.current=Be.getPointing,wl.current=Be.insertReference,Cl.current=Be.captureSink,yl.current=Be.restoreSink;const Jl=i.useCallback(()=>{Be.cancelEdit(),pr()},[Be.cancelEdit,pr]),Cr=rw({enabled:!ue,sinkRef:de,adapter:ae,isEditing:Ge,getSelection:Xt,setSelection:$t,commitPaste:ed,maxOperationCells:R,onOperationRejected:w,onCopyMultiRange:j,repaintOverlay:Fe,isDragging:gr,resize:{rowAxis:Ce,colAxis:we,resizeTracks:Xl},pendingPasteOptionsRef:vl,formats:le,onClipChange:je,onClipboardUnavailable:Oe,onEditRejected:d,rejectReadOnly:Wn,onPasteResolved:He});Nl.current=Cr.getClip,Dl.current=Cr.discardClip,Fl.current=Cr.discardClipOnCommit,ql.current=Cr.onAdapterSwitch,Xo.current=Cr.paste;const Zt=nC({enabled:!ue,adapter:ae,popovers:$e,sinkRef:de,bodyRef:ie,handleRef:Re,rowAxis:Ce,colAxis:we,zoomRef:Y,getActive:ns,isEditing:Ge,requestCommit:Je,focusSink:xt,rearmSink:ut,isDraggingAny:wr,commitEdits:Sn,labels:lt,onHyperlinkOpen:pt,anchors:Ko,repaintOverlay:Fe,rejectReadOnly:Wn,columnMenuAt:es});gt.current=Zt,Kr.current=Zt.open,El.current=Zt.hideTip;const pd=i.useCallback(()=>{const h=_t.current.active;return jt(h),Yr(h)},[jt,Yr]),rs=bw({adapter:ae,trackResize:v&&!ue?dt:void 0,getSelection:Xt,commitEdits:Sn,getActive:ns,isEditing:Ge,requestCommit:Je,cancelEdit:Jl,getSessionText:Be.getSessionText,validateCommit:Zl,insertAtCaret:Be.insertAtCaret,refreshEditPaint:Be.refreshPaint,maxOperationCells:R,onOperationRejected:w,colors:Fn,formats:le,getHighlight:()=>Ho.current,setHighlight:Ku,popovers:$e,openPopover:h=>Kr.current(h),onHyperlinkOpen:pt,onPasteSpecialRequest:Ln,paste:h=>Xo.current(h),rowAxis:Ce,colAxis:we,resizeTracks:Xl,defaultRowHeight:l,defaultColumnWidth:c,now:Ve,announce:Vn,formatCommandAnnouncement:p,formatResizeAnnouncement:f,keyboardCellRect:pd,rejectReadOnly:Wn,columnMenu:es===void 0?void 0:{isColumnMenuCell:h=>es(h)!==null,open:Zt.openColumnMenu}});Ol.current=rs,Yo.current=rs.executeCommand,kl.current=rs.isCommandAvailable;const hd=i.useMemo(()=>({table:kt,execute:h=>Yo.current(h),isAvailable:h=>kl.current(h)}),[kt]),md=i.useCallback(()=>{wt(),S?.()},[wt,S]),gd=i.useCallback(()=>{wt(),P?.()},[wt,P]);j0({zoomRef:Y,enabled:!ue,sinkRef:de,rootRef:Ke,handOffFocusToRoot:Yu,getSelection:Xt,setSelection:$t,moveActive:Uu,ensureCellVisible:jt,pageExtent:Xu,isEditing:Ge,requestCommit:Je,startEdit:mr,commitEdits:Sn,maxOperationCells:R,onOperationRejected:w,rejectReadOnly:Wn,getClip:Xr,discardClip:wt,isDragging:wr,abortDrag:fd,findDataEdge:ae.findDataEdge,getEditingMode:Be.getEditingMode,cancelEdit:Jl,onUndoRequest:md,onRedoRequest:gd,onCellContextMenu:H,rowAxis:Ce,colAxis:we,handleRef:Re,rearmSink:ut,commands:hd,onCommandBlockedWhileEditing:B,pointing:Be,adapter:ae,hideNoteTip:()=>El.current(),closeRejectedMessage:pr,pendingPasteOptionsRef:vl,onPointFrame:rd});const Ql=Me?.hasControls===!0,ei=Zt.context!==null&&Zt.context.kind==="columnMenu"?Zt.context.cell.col:null,wd=i.useMemo(()=>Ql?{openCol:ei,menuLabel:lt.columnMenu,filteredLabel:lt.columnMenuFiltered,onToggle:_l}:null,[Ql,ei,lt.columnMenu,lt.columnMenuFiltered,_l]),Cd=i.useMemo(()=>r===void 0||Me===null||!Me.hasControls?null:{resolved:Me,state:r.state,getFilterValues:r.getFilterValues,changeState:Ur,columnNameOf:jl,isInsideGrid:Il},[r,Me,Ur,jl,Il]);i.useLayoutEffect(()=>{const h=gt.current,N=h===null?null:h.context;if(h===null||N===null||N.kind!=="columnMenu")return;const J=Me===null||N.cell.row!==Me.headerRow?null:sr(Me,N.cell.col);(J===null||!n0(J,N.column))&&h.closeColumnMenu({restoreFocus:Ke.current?.contains(document.activeElement)===!0})},[Me]);const yd=ln.active.row,bd=ln.active.col;i.useLayoutEffect(()=>{const h=gt.current;h!==null&&(h.syncTipAriaDescribedBy(),h.isKindEnabled("message")&&(h.isOpen()==="message"&&h.close(),h.open("message")))},[yd,bd]),i.useLayoutEffect(()=>{Fe()},[Fe,jn.row,jn.column,jn.intersection]),i.useLayoutEffect(()=>{Fe()},[Fe,y?.startRow,y?.startCol,y?.endRow,y?.endCol]);const vd=i.useCallback(h=>{(Ut.current?.()??!1)||(h.preventDefault(),Ue(),ut())},[Ue,ut]),Rd=i.useCallback(h=>{const N=Ke.current,J=h.relatedTarget,re=N!==null&&!N.matches(":focus-visible");if(N!==null&&J instanceof Node&&N.contains(J)){h.target===N&&J===de.current&&!Uo.current&&xt({preventScroll:re});return}(Ut.current?.()??!1)||(xt({preventScroll:re}),ut())},[xt,ut]),Sd=i.useCallback(h=>{const N=Ke.current,J=h.relatedTarget;N!==null&&J instanceof Node&&N.contains(J)||Be.isFocusoutSuppressed()||Qo(!1)},[Be]),Zr=i.useRef(null),yr=i.useCallback(()=>{const h=Zr.current;h!==null&&(Zr.current=null,window.removeEventListener("pointerup",h.up,!0),window.removeEventListener("pointercancel",h.cancel,!0))},[]),os=i.useCallback(()=>{if(Zr.current!==null)return;const h=J=>{J.pointerType==="mouse"&&(yr(),J.button===1&&J.preventDefault())},N=J=>{J.pointerType==="mouse"&&yr()};Zr.current={up:h,cancel:N},window.addEventListener("pointerup",h,!0),window.addEventListener("pointercancel",N,!0)},[yr]);i.useEffect(()=>yr,[yr]),i.useEffect(()=>{const h=Ke.current;if(ue||h===null)return;let N=0;const J=ke=>{if(ke.pointerType!=="mouse"){(Ut.current?.()??!1)||Qo(!1);return}N=ke.buttons,ke.button===1&&(ke.target===de.current&&(Ut.current?.()??!1)||os())},re=ke=>{ke.pointerType==="mouse"&&(N=ke.buttons)},ge=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===N)return;const Qe=ke.buttons&~N;N=ke.buttons,ke.preventDefault(),(Qe&4)!==0&&os()};return h.addEventListener("pointerdown",J,!0),h.addEventListener("pointerup",re,!0),h.addEventListener("pointermove",ge,!0),()=>{h.removeEventListener("pointerdown",J,!0),h.removeEventListener("pointerup",re,!0),h.removeEventListener("pointermove",ge,!0)}},[ue,os]);const Ed=i.useCallback(h=>{if(!(h.target!==h.currentTarget||h.pointerType!=="mouse")&&(h.preventDefault(),h.button===0)){if(vn()){Ue();return}if(Ge()&&!Je()){Ue();return}Ue()}},[Ue,Ge,Je,vn]),ss=i.useRef(!1);i.useLayoutEffect(()=>{if(ue){ss.current=!1;return}if(ss.current)return;ss.current=!0,ut();const h=(Ke.current?.clientHeight??0)/Y.current;h>0&&Ce.totalSize()>0&&Ne.setRowRange(0,Ce.indexAt(Math.min(h-1,Ce.totalSize()-1)));const N=(Ke.current?.clientWidth??0)/Y.current;N>0&&we.totalSize()>0&&Ne.setColRange(0,we.indexAt(Math.min(N-1,we.totalSize()-1)))},[ue,ut,Ne,Ce,we]);const ti=i.useRef(t);i.useLayoutEffect(()=>{ti.current!==t&&(ti.current=t,Mt.cancelDrag(),It.cancelDrag(),Ht.cancelDrag(),dt.cancelDrag(),Lt.cancelDrag(),Ct.cancelDrag(),Be.cancelEdit(),gt.current?.hideTip(),gt.current?.close(),ue?(_t.current=Un,Io(Un)):cn(Un,"sheetSwitch"),ql.current())},[t,ue,cn,Mt,It,Ht,dt,Lt,Ct,Ne,Be.cancelEdit]);const ni=i.useRef({adapter:ae,rows:Ce.count,cols:we.count}),{getSessionCell:ri,getSession:oi,cancelEdit:si}=Be;i.useLayoutEffect(()=>{const h=ni.current,N=Ce.count,J=we.count;if(ni.current={adapter:ae,rows:N,cols:J},h.adapter!==ae||N>=h.rows&&J>=h.cols)return;ue?(_t.current=Un,Io(Un)):cn(T0(_t.current,N,J),"countShrink"),Mt.cancelDrag(),It.cancelDrag(),Ht.cancelDrag(),dt.cancelDrag(),Lt.cancelDrag(),Ct.cancelDrag();const re=ft=>ue||ft.row>=N||ft.col>=J,ge=ri();ge!==null&&re(ge)&&si();const ke=Ko.current;if(ke.tip!==null&&re(ke.tip)&&gt.current?.hideTip(),ke.interactive!==null&&re(ke.interactive)){const ft=Ke.current?.contains(document.activeElement)===!0;gt.current?.close({restoreFocus:ft})}const Qe=Xr();Qe!==null&&!Qe.foreign&&re({row:Qe.range.endRow,col:Qe.range.endCol})&&wt()},[ae,Ce.count,we.count,ue,cn,Mt,It,Ht,dt,Lt,Ct,ri,si,Xr,wt]);const li=i.useRef(a),ii=i.useRef(u),ci=i.useRef(m),ai=i.useRef(C);i.useLayoutEffect(()=>{(li.current!==a||ii.current!==u||ci.current!==m||ai.current!==C)&&(li.current=a,ii.current=u,ci.current=m,ai.current=C,Mt.cancelDrag(),It.cancelDrag(),Ht.cancelDrag(),dt.cancelDrag(),Lt.cancelDrag(),Ct.cancelDrag())},[a,u,m,C,Mt,It,Ht,dt,Lt,Ct]),i.useLayoutEffect(()=>{At(),Tt(),Fe()},[a,u,m,C,At,Tt,Fe]);const ui=i.useRef(k);i.useLayoutEffect(()=>{ui.current!==k&&(ui.current=k,wt())},[k,wt]),i.useLayoutEffect(()=>{Fe()},[Fe,ln]);const En=i.useCallback(()=>{const h=Ol.current;if(h===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return h},[]);if(i.useImperativeHandle(Ft,()=>({resizeRow:(h,N)=>{const J=Math.round(N);Ce.resize(h,J),Re.current?.updateRowSize(h,J),Ne.bumpRowGeometry(),At(),Fe(),Hn(),Gt()},resizeColumn:(h,N)=>{const J=Math.round(N);we.resize(h,J),Re.current?.updateColSize(h,J),Ne.bumpColVersion(),Tt(),Fe(),Hn(),Gt()},autoFitColumns:h=>{for(const N of h)if(!Number.isInteger(N)||N<0||N>=we.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${we.count-1} (got ${String(N)})`);return dt.autofitColumnsInAllRows(h)},scrollToCell:(h,N)=>{Re.current?.scrollToCell(h.row,h.col,N)},focus:h=>{xt(h),Ge()||ut()},executeCommand:h=>Yo.current(h),applyFormat:h=>En().applyFormat(h),setBorders:(h,N)=>En().setBorders(h,N),setHyperlink:h=>En().setHyperlink(h),setNote:h=>En().setNote(h),addComment:h=>En().addComment(h),setValidation:h=>En().setValidation(h),paste:h=>Xo.current(h),getSelection:()=>_t.current,setSelection:(h,N)=>{const J=$0(h,Ce.count,we.count),re=uC(N);return Ge()||gr()?!1:(cn(J,"setSelection"),re&&jt(J.active),!0)},getEditSession:oi,commitEdit:()=>Ge()?Je()?"committed":"rejected":"idle",getBaseFormat:h=>ae.getCellFormat===void 0?void 0:ae.getCellFormat(h.row,h.col),getPaintedFormat:h=>ae.getCellFormat===void 0?void 0:Ot(h.row,h.col,Ro(ae,h.row,h.col)),startEdit:h=>{mr(h)},openPopover:h=>{Kr.current(h)}}),[Ce,we,Ne,Tt,At,Fe,Hn,Gt,dt,xt,Ge,ut,ae,Ot,mr,En,cn,gr,jt,oi,Je]),ue)return q.jsx("div",{className:Et?`aqsp-root ${Et}`:"aqsp-root","data-aqsp-empty":"","data-testid":We});const kd=X!==void 0||Q!==void 0||p!==void 0||E!==void 0||f!==void 0,Od=s===void 0?{"aria-label":lt.rootAriaLabel}:{"aria-labelledby":s};return q.jsxs("div",{ref:Ke,className:Et?`aqsp-root ${Et}`:"aqsp-root",role:"group",...Od,tabIndex:0,onFocus:Rd,onBlur:Sd,"data-aqsp-root":"","data-aqsp-headings-hidden":x?void 0:"","data-aqsp-framed":y===void 0?void 0:"","data-testid":We,children:[q.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":z,onPointerDown:Ed,style:z===1?void 0:{width:`${100/z}%`,height:`${100/z}%`,transform:`scale(${z})`,"--_aqsp-zoom":String(z)},children:[x?q.jsxs(q.Fragment,{children:[q.jsx("div",{ref:Ee,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:h=>{if(h.pointerType==="mouse"&&(h.preventDefault(),h.button===0)){if(vn()){Ue();return}if(Ge()&&!Je()){Ue();return}Ue(),$t({ranges:[he({row:0,col:0},{row:ae.rowCount-1,col:ae.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),q.jsx(S0,{viewStore:Ne,colAxis:we,frozenCols:a,frozenTrailingCols:m,handleRef:Re,bandRef:Te,colTrackRef:it,windowOriginXRef:ct,repaintColHeaders:Tt,selectionRanges:ln.ranges,enableResizeUI:v,dividerLeadingRef:Pt,dividerTrailingRef:mt}),q.jsx(E0,{viewStore:Ne,rowAxis:Ce,handleRef:Re,bandRef:at,selectionRanges:ln.ranges,rowTrackRef:De,windowOriginYRef:ht,repaintHeaders:At,enableResizeUI:v,frozenRows:u,frozenTrailingRows:C,dividerLeadingRef:Xe,dividerTrailingRef:qt})]}):null,q.jsxs("div",{ref:be,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[q.jsx(R0,{adapter:ae,rowAxis:Ce,colAxis:we,viewStore:Ne,handleRef:Re,bodyRef:ie,dataVersion:k,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:m,frozenTrailingRows:C,headerRows:n,labelledBy:s,gridLabel:s===void 0?lt.rootAriaLabel:void 0,readOnly:o,tapScrollCircleOptions:L,showArrowButtons:M?.showArrowButtons,enableThumbDrag:M?.enableThumbDrag,enableTrackClick:M?.enableTrackClick,overscanRows:jc("overscanRows",$),overscanCols:jc("overscanCols",_),background:G,onRenderTruncated:Z,renderCell:O,onScroll:td,onRangeChange:nd,focusSink:Ue,isEditing:Ge,requestCommit:Je,testId:We?`${We}-vs`:void 0,__onCellRender:Ir,__maxRenderedCells:zn,cfIndexRef:dr,cfMemoRef:fr,isPointing:vn,locale:sn,scrollLabels:Nn,sortFilter:Me,columnMenu:wd}),q.jsx(Mg,{rowAxis:Ce,colAxis:we,handleRef:Re,sinkRef:de,getSelection:Xt,editing:Be.editing,virtualKeyboard:Gu,repaintRef:gl,dragFrameRef:Bo,getClip:Xr,getIsDraggingAny:wr,getIsFillDragging:Lt.isDragging,fillFrameRef:Vl,resizeGuideFrameRef:Wl,fillHandleNodeRef:Kl,enableFillHandle:W,frozenCols:a,frozenRows:u,trailingCols:m,trailingRows:C,sinkAriaLabel:lt.sinkAriaLabel,sinkReadOnly:o,sinkKeyShortcuts:Dn,onSinkMouseDown:vd,editPaintRef:bl,highlightRef:Ho,frameRange:y,highlightColors:Wu,popoverAnchors:Ko,interactiveAnchorRef:Rl,tipAnchorRef:Sl}),Zt.layerEnabled?q.jsx(Q0,{controller:Zt,labels:lt,renderPopover:ze,interactiveAnchorRef:Rl,tipAnchorRef:Sl,columnMenu:Cd}):null]}),kd?q.jsx("div",{ref:Wr,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),q.jsx("div",{ref:ve,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=rn.iterateTsvPrefixRows;exports.iterateTsvRows=rn.iterateTsvRows;exports.measureTsv=rn.measureTsv;exports.parseTsv=rn.parseTsv;exports.serializeClipboardTsv=rn.serializeClipboardTsv;exports.serializeTsv=rn.serializeTsv;exports.columnIndexToName=Pe.columnIndexToName;exports.columnNameToIndex=Pe.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Us;exports.CommentPopover=mu;exports.DEFAULT_CUSTOM_COLORS=Hu;exports.DEFAULT_HIGHLIGHT_COLORS=hu;exports.DEFAULT_SHORTCUTS=eu;exports.LinkPopover=gu;exports.ListPopover=wu;exports.MessagePopover=Cu;exports.NotePopover=yu;exports.NoteTip=bu;exports.SPREADSHEET_LABEL_CATALOGS=tu;exports.SPREADSHEET_RESERVED_SHORTCUTS=Om;exports.Spreadsheet=EC;exports.canonicalizeFormat=Dt;exports.detectClipSource=Qc;exports.enumerateRangeCells=dn;exports.estimatePasteCellCount=pm;exports.expandPaste=hm;exports.formatCellValue=An;exports.formatEquals=_d;exports.fromR1C1=Pr;exports.makeRange=he;exports.mergeFormat=Zs;exports.normalizeHyperlink=yn;exports.parseChord=tn;exports.parseClipPayload=Ts;exports.parseHtmlTable=Va;exports.rangeContains=Wt;exports.rangeSize=Rt;exports.resolveLabel=ye;exports.resolveLabels=nu;exports.serializeClipPayload=Gc;exports.serializeHtmlTable=ja;exports.shiftFormula=Sa;exports.toR1C1=Do;exports.validateCellText=su;