@aiquants/spreadsheet 0.19.0 → 0.20.1

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 Ht=require("./tsv.cjs"),De=require("./view-BkwCUzTl.cjs"),ot=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),$s=1e3,cn=1e4,Ls=10,jl=2**(1/4),Xu=(e,t)=>e<=0?e:t>0?e>=cn?e:Math.min(cn,Math.max(e+1,Math.round(e*jl))):Math.max(1,Math.min(e-1,Math.round(e/jl))),Hl=(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),Ds=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Ls):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),cn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Hl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Hl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},Ms="#000000",Wr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Gu=20,Zu=256,Vr=new Map,Ko=new WeakMap,Ct=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Ju=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},Qu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Gu}:Wr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Wr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Wr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Wr(e.decimals)};default:return null}},ed=e=>{const t=Ko.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=Vr.get(n);if(r!==void 0)return Ko.set(e,r),r;Vr.size>=Zu&&Vr.clear();const o=Qu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Vr.set(n,s),Ko.set(e,s),s},td=(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}},gc=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>td(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},nd=(e,t)=>{const n=gc(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)}})},Gn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return nd(e,t.pattern??"yyyy/MM/dd");const n=Ct(e);if(n===null)return e;const r=ed(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Ju(n,-2):n)},Bl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?gc(n)!==null?"right":"left":Ct(n)!==null?"right":"left",yr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",wc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],rd=["bottom","left","right","top"],Cc=(e,t,n)=>{e[t]=n},bc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},od=e=>{if(e===void 0)return;const t={};for(const n of rd){const r=e[n];r!==void 0&&(t[n]=bc(r))}return Object.keys(t).length===0?void 0:t},At=e=>{const t={};for(const n of wc){const r=n==="borders"?od(e.borders):n==="value"?e.value===void 0?void 0:bc(e.value):e[n];r!==void 0&&r!==!1&&Cc(t,n,r)}return Object.keys(t).length===0?void 0:t},zs=(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]||!zs(o[c],s[c]))return!1}return!0},sd=(e,t)=>e===t?!0:zs(e===void 0?void 0:At(e),t===void 0?void 0:At(t)),Ns=(e,t)=>{const n={};for(const o of wc){const s=t[o];Cc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=At(n);return zs(r,e===void 0?void 0:At(e))?e:r},yc="data-aqsp-clip",mo="application/x-aqsp-clip",ps=512,Wl=16*1024,hs=`${yc}=`,ld=16,Fs=()=>{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(ld));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",nt=e=>typeof e=="boolean",rn=e=>typeof e=="number"&&Number.isFinite(e),Ot=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Vl=e=>Ot(e)&&e>=1,id=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=cn,jt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},cd=e=>t=>Array.isArray(t)&&t.every(e),Me=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),Wt=(e,t)=>{if(!Ar(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},Ps=e=>t=>{if(!Ar(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&Wt(t,n)},ad=["left","center","right"],ud=["top","middle","bottom"],dd=["thin","medium","thick","dashed","dotted","double","hair"],Uo=["gt","gte","lt","lte","eq","neq","between","notBetween"],fd=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],pd=["eq","neq","gt","gte","lt","lte","between","notBetween"],hd=["contains","notContains","startsWith","endsWith"],md=new Map([["number",Me({type:ae,decimals:rn,grouping:nt,locale:ae},["type"])],["percent",Me({type:ae,decimals:rn,scale:nt,locale:ae},["type"])],["currency",Me({type:ae,currency:ae,decimals:rn,locale:ae},["type","currency"])],["scientific",Me({type:ae,decimals:rn,locale:ae},["type"])],["date",Me({type:ae,pattern:ae},["type"])],["text",Me({type:ae},["type"])]]),gd=Me({style:jt(dd),color:ae},["style"]),Yr=e=>Wt(e,gd),wd=Me({top:Yr,right:Yr,bottom:Yr,left:Yr},[]),Cd=Me({value:Ps(md),align:jt(ad),verticalAlign:jt(ud),wrap:nt,background:ae,color:ae,bold:nt,italic:nt,underline:nt,strikethrough:nt,fontFamily:ae,fontSize:rn,borders:e=>Wt(e,wd)},[]),bd=e=>Wt(e,Cd),Rn={strict:nt,inputMessage:ae,errorMessage:ae},yd=new Map([["list",Me({...Rn,type:ae,values:cd(ae),showDropdown:nt},["type","values"])],["number",Me({...Rn,type:ae,op:jt(Uo),a:ae,b:ae},["type","op","a"])],["textLength",Me({...Rn,type:ae,op:jt(Uo),a:rn,b:rn},["type","op","a"])],["date",Me({...Rn,type:ae,op:jt(Uo),a:ae,b:ae},["type","op","a"])],["text",Me({...Rn,type:ae,op:jt(fd),value:ae},["type","op"])],["checkbox",Me({...Rn,type:ae,checked:ae,unchecked:ae},["type"])],["custom",Me({...Rn,type:ae,formula:ae},["type","formula"])]]),Rd=Ps(yd),vd=Me({startRow:Ot,startCol:Ot,endRow:Ot,endCol:Ot},["startRow","startCol","endRow","endCol"]),Sd=e=>{if(!Wt(e,vd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return Ot(t)&&Ot(r)&&Ot(n)&&Ot(o)&&t<=r&&n<=o},kd=Me({color:ae,value:rn},["color"]),Xo=e=>Wt(e,kd),Ed=new Map([["cellValue",Me({type:ae,op:jt(pd),a:ae,b:ae},["type","op","a"])],["text",Me({type:ae,op:jt(hd),value:ae},["type","op","value"])],["empty",Me({type:ae},["type"])],["notEmpty",Me({type:ae},["type"])],["colorScale",Me({type:ae,min:Xo,mid:Xo,max:Xo},["type","min","max"])],["customFormula",Me({type:ae,formula:ae},["type","formula"])]]),Od=Me({background:ae,color:ae,bold:nt,italic:nt,underline:nt,strikethrough:nt},[]),Ad=Me({sourceRuleId:ae,ranges:Array.isArray,condition:Ps(Ed),style:e=>Wt(e,Od),stopIfTrue:nt},["sourceRuleId","ranges","condition","style"]),xd=(e,t,n)=>{if(!Wt(e,Ad))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Sd(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Td=Me({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),$d=e=>Wt(e,Td),Ld=(e,t,n)=>{if(!Ar(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(!Ot(o)||o>=t)return!1;break;case"val":if(!Ot(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($d)))return!1;break;default:return!1}}return!0},Yl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(id),Dd=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Rc=e=>{if(!Ar(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Dd.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Vl(t)&&Vl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(bd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Rd)))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 u of c)if(!Ld(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Yl(e.colWidths,n)||e.rowHeights!==void 0&&!Yl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>xd(c,t,n))},kr=e=>Array.isArray(e)?`[${e.map(kr).join(",")}]`:Ar(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${kr(e[n])}`).join(",")}}`:JSON.stringify(e),Md=e=>{const t=At(e);return t===void 0?"{}":JSON.stringify(t)},zd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Nd=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(zd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},vc=e=>{if(!Rc(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(Md).join(","),r=e.validations.map(kr).join(","),o=e.cells.map(u=>`[${u.map(Nd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(kr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},ms=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Rc(t)?t:null},Fd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Pd=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),Sc=e=>e.includes("&")?e.replace(Fd,t=>Pd[t]):e,_d=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Kl=e=>{const t=e.length>ps?e.slice(0,ps):e,n=_d.exec(Sc(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},qd=e=>{const t=e.indexOf(hs);if(t===-1)return null;const n=t+hs.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},kc=(e,t)=>{if(t==="event"&&e.types.includes(mo))return{kind:"mime",json:e.getData(mo)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=qd(n);return r===null?null:{kind:"attribute",html:n,at:r}},Id=(e,t)=>{const n=kc(e,t);return n===null?null:n.kind==="mime"?Kl(n.json):Kl(n.html.slice(n.at.start,n.at.start+ps))},jd=(e,t)=>{const n=kc(e,t);if(n===null)return null;if(n.kind==="mime")return ms(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:ms(Sc(n.html.slice(n.at.start,r)))},Hd=/<google-sheets-html-origin[\s>]/,Bd='data-sheets-root="1"',Wd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Vd="mso-",Yd=/\.xl\d+\s*\{/,Kd="<table",Ud=e=>e.includes(hs)?"aqsp":Hd.test(e)&&e.includes(Bd)?"sheets":Wd.test(e)||e.includes(Vd)||Yd.test(e)?"excel":null,Ec=(e,t)=>{if(t==="event"&&e.types.includes(mo))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Wl?n.slice(0,Wl):n,o=Ud(r);if(o==="aqsp")return"aqsp";if(n.includes(Kd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},_s=1e3,Oc=65534,Xd=9,Gd=10,Zd=12,Jd=13,Qd=32,Ac=34,xc=39,ef=43,qs=47,Ul=48,tf=57,nf=61,rf=62,of=97,sf=98,lf=100,cf=102,Tc=104,$c=114,Lc=116,af=["able","body","head","foot"],Rr=e=>e===Qd||e===Xd||e===Gd||e===Jd||e===Zd,gs=e=>e===rf||e===qs||Rr(e),uf=e=>Rr(e)||e===qs||e===Ac||e===xc,df=(e,t,n,r)=>{if(t===0||!uf(e.charCodeAt(t-1)))return null;let o=t+n;for(;Rr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==nf)return 1;for(o+=1;Rr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Ac||s===xc)&&(o+=1);Rr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===ef&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=Ul&&u<=tf;u=e.charCodeAt(o))l=l*10+(u-Ul),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Xl=(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=df(e,r,t.length,n);if(l!==null)return l}return 1}},ff=(e,t)=>{if(e.charCodeAt(t+2)!==Lc)return!1;const n=e.charCodeAt(t+3);if(n===$c)return gs(e.charCodeAt(t+4));if(n!==of&&n!==sf&&n!==Tc&&n!==cf)return!1;for(const r of af)if(e.startsWith(r,t+3)&&gs(e.charCodeAt(t+3+r.length)))return!0;return!1},pf=e=>{const t=e.toLowerCase(),n=Xl(t,"colspan",_s),r=Xl(t,"rowspan",Oc);let o=0;const s=q=>(o!==-1&&o<q&&(o=t.indexOf(">",q)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const b=new Map,N=(q,U)=>{const Y=b.get(q);b.set(q,Y===void 0?U:Y+U)},W=()=>{m&&u+h>c&&(c=u+h),m=!1},z=()=>{W(),l+=1,m=!0,u=0;const q=b.get(l-1);q!==void 0&&(h+=q)};for(let q=t.indexOf("<");q!==-1;q=t.indexOf("<",q+1)){const U=t.charCodeAt(q+1);if(U===qs){ff(t,q)&&W();continue}if(U!==Lc||!gs(t.charCodeAt(q+3)))continue;const Y=t.charCodeAt(q+2);if(Y===$c)z();else if(Y===lf||Y===Tc){m||z();const A=q+3,T=s(A),F=n(A,T);u+=F;const j=r(A,T);j>1&&(N(l,F),N(l-1+j,-F))}}return W(),{rows:l,cols:c}},Dc=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}},Mc=()=>{const e=new WeakMap,t=Dc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=At(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},hf=()=>{const e=new WeakMap,t=Dc(kr);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}},mf=new Set(["http:","https:","mailto:","tel:"]),an=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return mf.has(n.protocol)?n.href:null},Qn=e=>{if(e===void 0)return;const t=an(e);return t===null?void 0:t},zc=(e,t)=>e.startCol===0&&e.endCol===t-1,Nc=(e,t)=>e.startRow===0&&e.endRow===t-1,ws=13,qt=Object.freeze({style:Object.freeze({}),lineBoxPx:ws,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"},wf=new Map(Object.entries(gf)),Cf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,bf=/^rgba?\((.*)\)$/,Fc=/^(\d+(?:\.\d+)?)%$/,Kr=e=>e.toString(16).padStart(2,"0"),Go=e=>{const t=Fc.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},yf=e=>{const t=Fc.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},Rf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Go(t[0]),r=Go(t[1]),o=Go(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Kr(n)}${Kr(r)}${Kr(o)}`;if(t.length===3)return s;const l=yf(t[3]);return l===null?null:l===255?s:`${s}${Kr(l)}`},rt=e=>{const t=e.trim().toLowerCase(),n=Cf.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=bf.exec(t);if(r!==null)return Rf(r[1]);const o=wf.get(t);return o===void 0?null:o},Gl={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"}},Zl=e=>{if(!Object.hasOwn(Gl,e.style))return null;const t=Gl[e.style],n=e.color===void 0?Ms:rt(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},vf={top:"flex-start",middle:"center",bottom:"flex-end"},Sf=e=>e==="left"||e==="center"||e==="right",Pc=e=>e==="top"||e==="middle"||e==="bottom",_c=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,qc=(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=_c(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Ur=(e,t)=>{const n=e===void 0?null:Zl(e);return n!==null?n:t===void 0?null:Zl(t)},Zo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Sf(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=yr(e.align)),Pc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=vf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),qc(e,s));const c=e?.borders,u=Ur(c?.right,t);u!==null&&(s.borderRight=u);const h=Ur(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=Ur(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=Ur(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)})},Jl=new WeakMap,kf=(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:Zo(void 0,s,l,r,o);if(!c)return Zo(e,s,l,r,o);const u=Jl.get(e);if(u!==void 0)return u;const h=Zo(e,void 0,void 0,!1,!1);return Jl.set(e,h),h},Ef=e=>{if(e===void 0)return qt;const t={};qc(e,t);const n=_c(e.fontSize),r=n===null?ws:Math.round(n),o=Pc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===ws&&o==="middle"?qt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Of="#REF!",Af=11,xf=15,Tf=4096,io=33,vr=34,Is=36,$f=38,Cs=39,Ic=40,Lf=42,Df=43,Mf=44,jc=45,zf=46,Nf=47,Yn=58,Ff=59,Pf=60,Hc=61,_f=62,qf=67,If=82,vo=91,Bc=93,jf=94,Hf=95,Wc=e=>e>=65&&e<=90||e>=97&&e<=122,Vc=e=>e>=48&&e<=57,js=e=>Wc(e)||Vc(e)||e===Hf||e===zf||e===Is||e>=128,Bf=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,Wf=e=>e===Hc||e===Ic||e===Mf||e===Ff||e===Df||e===jc||e===Lf||e===Nf||e===jf||e===$f||e===Pf||e===_f||e===Yn,Yc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(js(n)||n===Ic||n===io||n===vo)},Ql=(e,t)=>{let n=t;for(;n<e.length&&js(e.charCodeAt(n));)n+=1;return n},bs=(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},Vf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Cs){r+=2;continue}if(o===vo)n+=1;else if(o===Bc&&(n-=1,n===0))return r+1;r+=1}return e.length},ei=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Yc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Kc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===vr){o=bs(e,o,vr);continue}if(s===Cs){const u=bs(e,o,Cs);o=e.charCodeAt(u)===io?ei(e,o,u,t,n):u;continue}if(s===vo){o=Vf(e,o);continue}if(!js(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Yc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Ql(e,o);if(e.charCodeAt(c)===Yn){const u=Ql(e,c+1);u>c+1&&e.charCodeAt(u)===io&&(c=u)}o=e.charCodeAt(c)===io?ei(e,o,c,t,n):c}return n},Jo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===Is;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Wc(l))break;if(s+=1,s>Af)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},ys=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Vc(o))break;if(n-t>=xf)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Xr=(e,t)=>{const n=e.charCodeAt(t)===Is,r=ys(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Yf=(e,t)=>{const n=Jo(e,t);if(n!==null){const o=Xr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Yn){const s=Jo(e,o.end+1);if(s!==null){const l=Xr(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)===Yn){const s=Jo(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=Xr(e,t);if(r!==null&&e.charCodeAt(r.end)===Yn){const o=Xr(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},xr=e=>Kc(e,Yf),Uc=(e,t=Tf)=>{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}},Rs=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},Qo=e=>`${e.absCol?"$":""}${Rs(e.col)}${e.absRow?"$":""}${e.row+1}`,Hs=e=>e.sheet===void 0?"":`${e.sheet}!`,on=e=>{const t=Hs(e);switch(e.kind){case"cell":return`${t}${Qo(e)}`;case"range":return`${t}${Qo(e.start)}:${Qo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Rs(e.start.col)}:${e.end.abs?"$":""}${Rs(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}`)},Kf=(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 on({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return on({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?on({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):on({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Bs=(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?`${Hs(s.token)}${Of}`:l),o=s.end}return r+e.slice(o)},So=e=>e.charCodeAt(0)===Hc,es=(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}},Uf=(e,t,n)=>{switch(e.kind){case"cell":{const r=es(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=es(e.start,t,n),o=es(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}}}}},Xc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return So(e)?Bs(e,xr(e),r=>{const o=Uf(r,t,n);return o===null?null:on(o)}):e},Gc=(e,t)=>{jn(e.row,`${t} origin.row`),jn(e.col,`${t} origin.col`)},Hn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,ts=(e,t)=>`${Hn("R",e.row,e.absRow,t.row)}${Hn("C",e.col,e.absCol,t.col)}`,Xf=(e,t)=>{const n=Hs(e);switch(e.kind){case"cell":return`${n}${ts(e,t)}`;case"range":return`${n}${ts(e.start,t)}:${ts(e.end,t)}`;case"column":return`${n}${Hn("C",e.start.col,e.start.abs,t.col)}:${Hn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Hn("R",e.start.row,e.start.abs,t.row)}:${Hn("R",e.end.row,e.end.abs,t.row)}`}},ko=(e,t)=>(Gc(t,"toR1C1"),So(e)?Bs(e,xr(e),n=>Xf(n,t)):e),ti=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===vo){const l=e.charCodeAt(o+1)===jc,c=ys(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Bc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=ys(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}}},ni=(e,t)=>{const n=ti(e,t,If),r=ti(e,n===null?t:n.end,qf);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}},Gf=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}}},Zf=(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,Jf=(e,t)=>{const n=ni(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Yn){const r=ni(e,n.end+1);if(r!==null){const o=Zf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Gf(n)}},Qf=e=>Kc(e,Jf),ep=Uc(Qf),Bn=(e,t)=>e.rel?t+e.n:e.n-1,ri=(e,t)=>{const n=Bn(e.row,t.row),r=Bn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},tp=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=ri(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=ri(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=Bn(e.start,t.row),s=Bn(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=Bn(e.start,t.col),s=Bn(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}}}},Tr=(e,t)=>(Gc(t,"fromR1C1"),So(e)?Bs(e,ep(e),n=>{const r=tp(n,t);return r===null?null:on(r)}):e),oi=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},np=e=>{switch(e.kind){case"cell":return{...e,...oi(e.absCol,e.absRow)};case"range":{const t=oi(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}}}}},Zc=(e,t)=>So(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Jc=(e,t)=>{if(!Zc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return n;return null},rp=(e,t)=>{const n=Jc(e,t);if(n===null)return null;const r=on(np(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},si=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===vr){const s=bs(e,r,vr);if(s>t)return!1;n=vr,r=s;continue}Bf(o)||(n=o),r+=1}return Wf(n)},Qc=(e,t)=>{if(!Zc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return si(e,n.start)?{replace:[n.start,n.end]}:null;return si(e,t)?{insertAt:t}:null},Zn=[{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}],Eo=(e,t)=>`[$${e}-${t}]`,op=new Map(Zn.map(e=>[Eo(e.symbol,e.lcid),e])),sp=new Map(Zn.filter((e,t)=>Zn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Zn.map(e=>[Eo(e.symbol,e.lcid),e.code]));const lp=new Set([...Zn.map(e=>e.symbol),...Zn.map(e=>e.code),"¥"]),ip=20,cp="yyyy/MM/dd",ea=/yyyy|MM|dd|HH|mm|ss/g,ta=" -+/():!^&'~{}<>=",ap="$¥€£₩₹¥",vs=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},up=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},dp=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),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const b=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:b}),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)||ap.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},Et=e=>e===void 0?{}:{locale:e},fp=/^(0|#,##0)(?:\.(0+))?$/,li=(e,t,n,r)=>{if(t!==null){const o=op.get(Eo(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!lp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...Et(r.locale)}},pp=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const z of e)switch(z.kind){case"locale":break;case"literal":r?u+=z.text:c+=z.text;break;case"digits":if(r)return;n=z.text,r=!0;break;case"currency":if(o!==null)return;o=z;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=fp.exec(n);if(h===null)return;const m=h[1]==="#,##0",b=h[2]===void 0?0:h[2].length,N=c.trim(),W=u.trim();if(s)return l===0&&o===null&&!m&&N===""&&W===""?{type:"scientific",decimals:b,...Et(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&W===""?{type:"percent",decimals:b,...Et(t.locale)}:void 0;if(W==="%"&&N===""&&o===null)return{type:"percent",decimals:b,scale:!1,...Et(t.locale)};if(o!==null)return N===""&&W===""?li(o.symbol,o.lcid,b,t):void 0;if(!(N!==""&&W!==""))return N!==""||W!==""?li(N+W,null,b,t):{type:"number",decimals:b,...m?{grouping:!0}:{},...Et(t.locale)}},hp=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),mp=(e,t)=>{const n=[...e.matchAll(ea)];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":hp.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&mp(r,n)?{type:"date",pattern:r}:void 0},wp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...Et(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...Et(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...Et(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...Et(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...Et(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...Et(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Ws=(e,t)=>{const n=up(e).trim(),r=wp.get(n);if(r!==void 0)return r(t);const o=dp(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return pp(o,t);if(o.some(s=>s.kind==="date"))return gp(o)}},Cp=(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:Ws(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},wr=e=>e===0?"":`.${"0".repeat(e)}`,co=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=ip,bp=`${ta}.,`,ii=e=>e.includes('"')?null:[...e].every(t=>bp.includes(t))?e:`"${e}"`,yp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(ea)){const u=ii(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=ii(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Ws(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Rp=e=>{const t=sp.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!co(n))return null;const r=`#,##0${wr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Eo(t.symbol,t.lcid)}${r}`},na=e=>{switch(e.type){case"text":return"@";case"date":return yp(e.pattern===void 0?cp:e.pattern);case"number":return co(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${wr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return co(t)?e.scale===!1?`0${wr(t)}"%"`:`0${wr(t)}%`:null}case"scientific":return co(e.decimals)?`0${wr(e.decimals)}E+00`:null;case"currency":return Rp(e);default:return null}},ci="-−",vp=(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("")},Sp=(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 u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=vp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},kp=(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 u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},Ep=(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",u=F=>F>="0"&&F<="9"||l!==""&&l.includes(F)||n.decimal.includes(F)||c&&(F==="e"||F==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let b=0,N=0,W=0,z="";for(const F of o.slice(0,h))ci.includes(F)?b+=1:F==="("?N+=1:z+=F;for(const F of o.slice(m))ci.includes(F)?b+=1:F===")"?W+=1:z+=F;const q=b+N;if(N!==W||q>1||q===1&&s||(s=s||q===1,r!=="currency"&&z.trim()!==""))return e;const U=Sp(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(U===null)return e;const Y=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,A=U.exponent+Y;if(A>330||A<-330)return e;const T=kp(U.integer,U.fraction,A,s);return Number.isFinite(Number(T))?T:e},ai="google-sheets-html-origin",ra=Object.freeze({group:",",decimal:"."}),ui=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"}),oa=["top","right","bottom","left"],Op=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Ap=new Set(["windowtext","currentcolor","inherit","initial","unset"]),xp=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"]),di=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Tp=Object.freeze({number:2,percent:3,currency:4,scientific:8}),$p=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Lp=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"]),Dp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Mp=3,zp=1,sa=-25569,ao=86400,Np=-693959,Fp=2958465,Pp=" ",Oo=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,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},go=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Vs=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},_p=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,qp=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 u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),b=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const N=Oo(b);for(const W of m.split(",")){const z=W.trim(),q=_p.exec(z);if(q!==null){const U=t.get(q[1]);if(U===void 0)t.set(q[1],new Map(N));else for(const[Y,A]of N)U.set(Y,A)}else if(z.toLowerCase()==="table"){const U=N.get("mso-displayed-decimal-separator"),Y=N.get("mso-displayed-thousand-separator");U!==void 0&&(n=vs(go(U))),Y!==void 0&&(r=vs(go(Y)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:ra}},Ip="%_-*? ",jp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Ip.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Hp=(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,u=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+u-719468},la=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,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},_n=(e,t)=>String(e).padStart(t,"0"),ia=e=>{if(e<Np||e>Fp)return null;let t=Math.floor(e),n=Math.round((e-t)*ao);n>=ao&&(t+=1,n-=ao);const r=la(t+sa),o=`${_n(r.year,4)}-${_n(r.month,2)}-${_n(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${_n(s,2)}:${_n(l,2)}:${_n(n%60,2)}`},Bp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Wp=e=>{const t=Bp.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 u=Hp(n,r,o),h=la(u);return h.year!==n||h.month!==r||h.day!==o?null:u-sa+(s*3600+l*60+c)/ao},Ys=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),vn=e=>Ys(e).replaceAll('"',"&quot;"),ca=e=>Ys(e).replaceAll("'","&#39;"),Vp=e=>Ys(e).replaceAll(`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Vt=require("./tsv.cjs"),Le=require("./view-BkwCUzTl.cjs"),lt=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),$s=1e3,cn=1e4,Ls=10,Bl=2**(1/4),Zu=(e,t)=>e<=0?e:t>0?e>=cn?e:Math.min(cn,Math.max(e+1,Math.round(e*Bl))):Math.max(1,Math.min(e-1,Math.round(e/Bl))),Wl=(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),Ds=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Ls):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),cn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Wl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Wl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},zs="#000000",Hr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Ju=20,Qu=256,Br=new Map,Ko=new WeakMap,gt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},ed=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},td=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Ju}: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}},nd=e=>{const t=Ko.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 Ko.set(e,r),r;Br.size>=Qu&&Br.clear();const o=td(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Br.set(n,s),Ko.set(e,s),s},rd=(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}},Cc=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>rd(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},od=(e,t)=>{const n=Cc(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)}})},Zn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return od(e,t.pattern??"yyyy/MM/dd");const n=gt(e);if(n===null)return e;const r=nd(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?ed(n,-2):n)},Vl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Cc(n)!==null?"right":"left":gt(n)!==null?"right":"left",yr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",bc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],sd=["bottom","left","right","top"],yc=(e,t,n)=>{e[t]=n},Rc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},ld=e=>{if(e===void 0)return;const t={};for(const n of sd){const r=e[n];r!==void 0&&(t[n]=Rc(r))}return Object.keys(t).length===0?void 0:t},Ot=e=>{const t={};for(const n of bc){const r=n==="borders"?ld(e.borders):n==="value"?e.value===void 0?void 0:Rc(e.value):e[n];r!==void 0&&r!==!1&&yc(t,n,r)}return Object.keys(t).length===0?void 0:t},Ms=(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]||!Ms(o[c],s[c]))return!1}return!0},id=(e,t)=>e===t?!0:Ms(e===void 0?void 0:Ot(e),t===void 0?void 0:Ot(t)),Ns=(e,t)=>{const n={};for(const o of bc){const s=t[o];yc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=Ot(n);return Ms(r,e===void 0?void 0:Ot(e))?e:r},vc="data-aqsp-clip",po="application/x-aqsp-clip",ps=512,Yl=16*1024,hs=`${vc}=`,cd=16,Fs=()=>{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(cd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ue=e=>typeof e=="string",ot=e=>typeof e=="boolean",rn=e=>typeof e=="number"&&Number.isFinite(e),Et=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Kl=e=>Et(e)&&e>=1,ad=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=cn,Wt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},ud=e=>t=>Array.isArray(t)&&t.every(e),De=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),Kt=(e,t)=>{if(!Ar(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},Ps=e=>t=>{if(!Ar(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&Kt(t,n)},dd=["left","center","right"],fd=["top","middle","bottom"],pd=["thin","medium","thick","dashed","dotted","double","hair"],Uo=["gt","gte","lt","lte","eq","neq","between","notBetween"],hd=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],md=["eq","neq","gt","gte","lt","lte","between","notBetween"],gd=["contains","notContains","startsWith","endsWith"],wd=new Map([["number",De({type:ue,decimals:rn,grouping:ot,locale:ue},["type"])],["percent",De({type:ue,decimals:rn,scale:ot,locale:ue},["type"])],["currency",De({type:ue,currency:ue,decimals:rn,locale:ue},["type","currency"])],["scientific",De({type:ue,decimals:rn,locale:ue},["type"])],["date",De({type:ue,pattern:ue},["type"])],["text",De({type:ue},["type"])]]),Cd=De({style:Wt(pd),color:ue},["style"]),Wr=e=>Kt(e,Cd),bd=De({top:Wr,right:Wr,bottom:Wr,left:Wr},[]),yd=De({value:Ps(wd),align:Wt(dd),verticalAlign:Wt(fd),wrap:ot,background:ue,color:ue,bold:ot,italic:ot,underline:ot,strikethrough:ot,fontFamily:ue,fontSize:rn,borders:e=>Kt(e,bd)},[]),Rd=e=>Kt(e,yd),yn={strict:ot,inputMessage:ue,errorMessage:ue},vd=new Map([["list",De({...yn,type:ue,values:ud(ue),showDropdown:ot},["type","values"])],["number",De({...yn,type:ue,op:Wt(Uo),a:ue,b:ue},["type","op","a"])],["textLength",De({...yn,type:ue,op:Wt(Uo),a:rn,b:rn},["type","op","a"])],["date",De({...yn,type:ue,op:Wt(Uo),a:ue,b:ue},["type","op","a"])],["text",De({...yn,type:ue,op:Wt(hd),value:ue},["type","op"])],["checkbox",De({...yn,type:ue,checked:ue,unchecked:ue},["type"])],["custom",De({...yn,type:ue,formula:ue},["type","formula"])]]),Sd=Ps(vd),kd=De({startRow:Et,startCol:Et,endRow:Et,endCol:Et},["startRow","startCol","endRow","endCol"]),Ed=e=>{if(!Kt(e,kd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return Et(t)&&Et(r)&&Et(n)&&Et(o)&&t<=r&&n<=o},Od=De({color:ue,value:rn},["color"]),Xo=e=>Kt(e,Od),Ad=new Map([["cellValue",De({type:ue,op:Wt(md),a:ue,b:ue},["type","op","a"])],["text",De({type:ue,op:Wt(gd),value:ue},["type","op","value"])],["empty",De({type:ue},["type"])],["notEmpty",De({type:ue},["type"])],["colorScale",De({type:ue,min:Xo,mid:Xo,max:Xo},["type","min","max"])],["customFormula",De({type:ue,formula:ue},["type","formula"])]]),xd=De({background:ue,color:ue,bold:ot,italic:ot,underline:ot,strikethrough:ot},[]),Td=De({sourceRuleId:ue,ranges:Array.isArray,condition:Ps(Ad),style:e=>Kt(e,xd),stopIfTrue:ot},["sourceRuleId","ranges","condition","style"]),$d=(e,t,n)=>{if(!Kt(e,Td))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Ed(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Ld=De({text:ue,author:ue,createdAt:ue},["text","author","createdAt"]),Dd=e=>Kt(e,Ld),zd=(e,t,n)=>{if(!Ar(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(!Et(o)||o>=t)return!1;break;case"val":if(!Et(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(Dd)))return!1;break;default:return!1}}return!0},Ul=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(ad),Md=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Sc=e=>{if(!Ar(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Md.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Kl(t)&&Kl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Rd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Sd)))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 u of c)if(!zd(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Ul(e.colWidths,n)||e.rowHeights!==void 0&&!Ul(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>$d(c,t,n))},kr=e=>Array.isArray(e)?`[${e.map(kr).join(",")}]`:Ar(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${kr(e[n])}`).join(",")}}`:JSON.stringify(e),Nd=e=>{const t=Ot(e);return t===void 0?"{}":JSON.stringify(t)},Fd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Pd=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(Fd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},kc=e=>{if(!Sc(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(Nd).join(","),r=e.validations.map(kr).join(","),o=e.cells.map(u=>`[${u.map(Pd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(kr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},ms=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Sc(t)?t:null},_d=/&(?:amp|lt|gt|quot|#39|nbsp);/g,qd=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),Ec=e=>e.includes("&")?e.replace(_d,t=>qd[t]):e,Id=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Xl=e=>{const t=e.length>ps?e.slice(0,ps):e,n=Id.exec(Ec(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},jd=e=>{const t=e.indexOf(hs);if(t===-1)return null;const n=t+hs.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Oc=(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=jd(n);return r===null?null:{kind:"attribute",html:n,at:r}},Hd=(e,t)=>{const n=Oc(e,t);return n===null?null:n.kind==="mime"?Xl(n.json):Xl(n.html.slice(n.at.start,n.at.start+ps))},Bd=(e,t)=>{const n=Oc(e,t);if(n===null)return null;if(n.kind==="mime")return ms(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:ms(Ec(n.html.slice(n.at.start,r)))},Wd=/<google-sheets-html-origin[\s>]/,Vd='data-sheets-root="1"',Yd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Kd="mso-",Ud=/\.xl\d+\s*\{/,Xd="<table",Gd=e=>e.includes(hs)?"aqsp":Wd.test(e)&&e.includes(Vd)?"sheets":Yd.test(e)||e.includes(Kd)||Ud.test(e)?"excel":null,Ac=(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>Yl?n.slice(0,Yl):n,o=Gd(r);if(o==="aqsp")return"aqsp";if(n.includes(Xd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},_s=1e3,xc=65534,Zd=9,Jd=10,Qd=12,ef=13,tf=32,Tc=34,$c=39,nf=43,qs=47,Gl=48,rf=57,of=61,sf=62,lf=97,cf=98,af=100,uf=102,Lc=104,Dc=114,zc=116,df=["able","body","head","foot"],Rr=e=>e===tf||e===Zd||e===Jd||e===ef||e===Qd,gs=e=>e===sf||e===qs||Rr(e),ff=e=>Rr(e)||e===qs||e===Tc||e===$c,pf=(e,t,n,r)=>{if(t===0||!ff(e.charCodeAt(t-1)))return null;let o=t+n;for(;Rr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==of)return 1;for(o+=1;Rr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Tc||s===$c)&&(o+=1);Rr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===nf&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=Gl&&u<=rf;u=e.charCodeAt(o))l=l*10+(u-Gl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Zl=(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=pf(e,r,t.length,n);if(l!==null)return l}return 1}},hf=(e,t)=>{if(e.charCodeAt(t+2)!==zc)return!1;const n=e.charCodeAt(t+3);if(n===Dc)return gs(e.charCodeAt(t+4));if(n!==lf&&n!==cf&&n!==Lc&&n!==uf)return!1;for(const r of df)if(e.startsWith(r,t+3)&&gs(e.charCodeAt(t+3+r.length)))return!0;return!1},mf=e=>{const t=e.toLowerCase(),n=Zl(t,"colspan",_s),r=Zl(t,"rowspan",xc);let o=0;const s=j=>(o!==-1&&o<j&&(o=t.indexOf(">",j)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const b=new Map,N=(j,U)=>{const Y=b.get(j);b.set(j,Y===void 0?U:Y+U)},B=()=>{m&&u+h>c&&(c=u+h),m=!1},M=()=>{B(),l+=1,m=!0,u=0;const j=b.get(l-1);j!==void 0&&(h+=j)};for(let j=t.indexOf("<");j!==-1;j=t.indexOf("<",j+1)){const U=t.charCodeAt(j+1);if(U===qs){hf(t,j)&&B();continue}if(U!==zc||!gs(t.charCodeAt(j+3)))continue;const Y=t.charCodeAt(j+2);if(Y===Dc)M();else if(Y===af||Y===Lc){m||M();const A=j+3,T=s(A),F=n(A,T);u+=F;const H=r(A,T);H>1&&(N(l,F),N(l-1+H,-F))}}return B(),{rows:l,cols:c}},Mc=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}},Nc=()=>{const e=new WeakMap,t=Mc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=Ot(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},gf=()=>{const e=new WeakMap,t=Mc(kr);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}},wf=new Set(["http:","https:","mailto:","tel:"]),an=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return wf.has(n.protocol)?n.href:null},er=e=>{if(e===void 0)return;const t=an(e);return t===null?void 0:t},Fc=(e,t)=>e.startCol===0&&e.endCol===t-1,Pc=(e,t)=>e.startRow===0&&e.endRow===t-1,ws=13,Ht=Object.freeze({style:Object.freeze({}),lineBoxPx:ws,verticalAlign:"middle"}),Cf={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"},bf=new Map(Object.entries(Cf)),yf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Rf=/^rgba?\((.*)\)$/,_c=/^(\d+(?:\.\d+)?)%$/,Vr=e=>e.toString(16).padStart(2,"0"),Go=e=>{const t=_c.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},vf=e=>{const t=_c.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},Sf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Go(t[0]),r=Go(t[1]),o=Go(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=vf(t[3]);return l===null?null:l===255?s:`${s}${Vr(l)}`},st=e=>{const t=e.trim().toLowerCase(),n=yf.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=Rf.exec(t);if(r!==null)return Sf(r[1]);const o=bf.get(t);return o===void 0?null:o},Jl={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"}},Ql=e=>{if(!Object.hasOwn(Jl,e.style))return null;const t=Jl[e.style],n=e.color===void 0?zs:st(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},kf={top:"flex-start",middle:"center",bottom:"flex-end"},Ef=e=>e==="left"||e==="center"||e==="right",qc=e=>e==="top"||e==="middle"||e==="bottom",Ic=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,jc=(e,t)=>{if(typeof e.background=="string"){const s=st(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=st(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=Ic(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Yr=(e,t)=>{const n=e===void 0?null:Ql(e);return n!==null?n:t===void 0?null:Ql(t)},Zo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Ef(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=yr(e.align)),qc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=kf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),jc(e,s));const c=e?.borders,u=Yr(c?.right,t);u!==null&&(s.borderRight=u);const h=Yr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=Yr(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=Yr(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)})},ei=new WeakMap,Of=(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:Zo(void 0,s,l,r,o);if(!c)return Zo(e,s,l,r,o);const u=ei.get(e);if(u!==void 0)return u;const h=Zo(e,void 0,void 0,!1,!1);return ei.set(e,h),h},Af=e=>{if(e===void 0)return Ht;const t={};jc(e,t);const n=Ic(e.fontSize),r=n===null?ws:Math.round(n),o=qc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===ws&&o==="middle"?Ht:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},xf="#REF!",Tf=11,$f=15,Lf=4096,so=33,vr=34,Is=36,Df=38,Cs=39,Hc=40,zf=42,Mf=43,Nf=44,Bc=45,Ff=46,Pf=47,Kn=58,_f=59,qf=60,Wc=61,If=62,jf=67,Hf=82,yo=91,Vc=93,Bf=94,Wf=95,Yc=e=>e>=65&&e<=90||e>=97&&e<=122,Kc=e=>e>=48&&e<=57,js=e=>Yc(e)||Kc(e)||e===Wf||e===Ff||e===Is||e>=128,Vf=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,Yf=e=>e===Wc||e===Hc||e===Nf||e===_f||e===Mf||e===Bc||e===zf||e===Pf||e===Bf||e===Df||e===qf||e===If||e===Kn,Uc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(js(n)||n===Hc||n===so||n===yo)},ti=(e,t)=>{let n=t;for(;n<e.length&&js(e.charCodeAt(n));)n+=1;return n},bs=(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},Kf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Cs){r+=2;continue}if(o===yo)n+=1;else if(o===Vc&&(n-=1,n===0))return r+1;r+=1}return e.length},ni=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Uc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Xc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===vr){o=bs(e,o,vr);continue}if(s===Cs){const u=bs(e,o,Cs);o=e.charCodeAt(u)===so?ni(e,o,u,t,n):u;continue}if(s===yo){o=Kf(e,o);continue}if(!js(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Uc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=ti(e,o);if(e.charCodeAt(c)===Kn){const u=ti(e,c+1);u>c+1&&e.charCodeAt(u)===so&&(c=u)}o=e.charCodeAt(c)===so?ni(e,o,c,t,n):c}return n},Jo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===Is;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Yc(l))break;if(s+=1,s>Tf)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},ys=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Kc(o))break;if(n-t>=$f)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)===Is,r=ys(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Uf=(e,t)=>{const n=Jo(e,t);if(n!==null){const o=Kr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Kn){const s=Jo(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)===Kn){const s=Jo(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)===Kn){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},xr=e=>Xc(e,Uf),Gc=(e,t=Lf)=>{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}},Rs=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},Qo=e=>`${e.absCol?"$":""}${Rs(e.col)}${e.absRow?"$":""}${e.row+1}`,Hs=e=>e.sheet===void 0?"":`${e.sheet}!`,on=e=>{const t=Hs(e);switch(e.kind){case"cell":return`${t}${Qo(e)}`;case"range":return`${t}${Qo(e.start)}:${Qo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Rs(e.start.col)}:${e.end.abs?"$":""}${Rs(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Hn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Xf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Hn(n.startRow,"formatRangeReference startRow"),Hn(n.startCol,"formatRangeReference startCol"),Hn(n.endRow,"formatRangeReference endRow"),Hn(n.endCol,"formatRangeReference endCol"),t){case"columns":return on({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return on({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?on({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):on({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Bs=(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?`${Hs(s.token)}${xf}`:l),o=s.end}return r+e.slice(o)},Ro=e=>e.charCodeAt(0)===Wc,es=(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}},Gf=(e,t,n)=>{switch(e.kind){case"cell":{const r=es(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=es(e.start,t,n),o=es(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}}}}},Zc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Ro(e)?Bs(e,xr(e),r=>{const o=Gf(r,t,n);return o===null?null:on(o)}):e},Jc=(e,t)=>{Hn(e.row,`${t} origin.row`),Hn(e.col,`${t} origin.col`)},Bn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,ts=(e,t)=>`${Bn("R",e.row,e.absRow,t.row)}${Bn("C",e.col,e.absCol,t.col)}`,Zf=(e,t)=>{const n=Hs(e);switch(e.kind){case"cell":return`${n}${ts(e,t)}`;case"range":return`${n}${ts(e.start,t)}:${ts(e.end,t)}`;case"column":return`${n}${Bn("C",e.start.col,e.start.abs,t.col)}:${Bn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Bn("R",e.start.row,e.start.abs,t.row)}:${Bn("R",e.end.row,e.end.abs,t.row)}`}},vo=(e,t)=>(Jc(t,"toR1C1"),Ro(e)?Bs(e,xr(e),n=>Zf(n,t)):e),ri=(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)===Bc,c=ys(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Vc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=ys(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}}},oi=(e,t)=>{const n=ri(e,t,Hf),r=ri(e,n===null?t:n.end,jf);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}},Jf=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}}},Qf=(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,ep=(e,t)=>{const n=oi(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Kn){const r=oi(e,n.end+1);if(r!==null){const o=Qf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Jf(n)}},tp=e=>Xc(e,ep),np=Gc(tp),Wn=(e,t)=>e.rel?t+e.n:e.n-1,si=(e,t)=>{const n=Wn(e.row,t.row),r=Wn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},rp=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=si(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=si(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=Wn(e.start,t.row),s=Wn(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=Wn(e.start,t.col),s=Wn(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}}}},Tr=(e,t)=>(Jc(t,"fromR1C1"),Ro(e)?Bs(e,np(e),n=>{const r=rp(n,t);return r===null?null:on(r)}):e),li=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},op=e=>{switch(e.kind){case"cell":return{...e,...li(e.absCol,e.absRow)};case"range":{const t=li(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}}}}},Qc=(e,t)=>Ro(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,ea=(e,t)=>{if(!Qc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return n;return null},sp=(e,t)=>{const n=ea(e,t);if(n===null)return null;const r=on(op(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},ii=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===vr){const s=bs(e,r,vr);if(s>t)return!1;n=vr,r=s;continue}Vf(o)||(n=o),r+=1}return Yf(n)},ta=(e,t)=>{if(!Qc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return ii(e,n.start)?{replace:[n.start,n.end]}:null;return ii(e,t)?{insertAt:t}:null},Jn=[{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}]`,lp=new Map(Jn.map(e=>[So(e.symbol,e.lcid),e])),ip=new Map(Jn.filter((e,t)=>Jn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Jn.map(e=>[So(e.symbol,e.lcid),e.code]));const cp=new Set([...Jn.map(e=>e.symbol),...Jn.map(e=>e.code),"¥"]),ap=20,up="yyyy/MM/dd",na=/yyyy|MM|dd|HH|mm|ss/g,ra=" -+/():!^&'~{}<>=",dp="$¥€£₩₹¥",vs=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},fp=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},pp=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),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const b=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:b}),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(ra.includes(o)||dp.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},kt=e=>e===void 0?{}:{locale:e},hp=/^(0|#,##0)(?:\.(0+))?$/,ci=(e,t,n,r)=>{if(t!==null){const o=lp.get(So(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!cp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...kt(r.locale)}},mp=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const M of e)switch(M.kind){case"locale":break;case"literal":r?u+=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 h=hp.exec(n);if(h===null)return;const m=h[1]==="#,##0",b=h[2]===void 0?0:h[2].length,N=c.trim(),B=u.trim();if(s)return l===0&&o===null&&!m&&N===""&&B===""?{type:"scientific",decimals:b,...kt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&B===""?{type:"percent",decimals:b,...kt(t.locale)}:void 0;if(B==="%"&&N===""&&o===null)return{type:"percent",decimals:b,scale:!1,...kt(t.locale)};if(o!==null)return N===""&&B===""?ci(o.symbol,o.lcid,b,t):void 0;if(!(N!==""&&B!==""))return N!==""||B!==""?ci(N+B,null,b,t):{type:"number",decimals:b,...m?{grouping:!0}:{},...kt(t.locale)}},gp=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),wp=(e,t)=>{const n=[...e.matchAll(na)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Cp=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":gp.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&wp(r,n)?{type:"date",pattern:r}:void 0},bp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...kt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...kt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...kt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...kt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...kt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...kt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Ws=(e,t)=>{const n=fp(e).trim(),r=bp.get(n);if(r!==void 0)return r(t);const o=pp(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return mp(o,t);if(o.some(s=>s.kind==="date"))return Cp(o)}},yp=(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:Ws(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},wr=e=>e===0?"":`.${"0".repeat(e)}`,lo=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=ap,Rp=`${ra}.,`,ai=e=>e.includes('"')?null:[...e].every(t=>Rp.includes(t))?e:`"${e}"`,vp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(na)){const u=ai(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=ai(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Ws(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Sp=e=>{const t=ip.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${wr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${So(t.symbol,t.lcid)}${r}`},oa=e=>{switch(e.type){case"text":return"@";case"date":return vp(e.pattern===void 0?up:e.pattern);case"number":return lo(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${wr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return lo(t)?e.scale===!1?`0${wr(t)}"%"`:`0${wr(t)}%`:null}case"scientific":return lo(e.decimals)?`0${wr(e.decimals)}E+00`:null;case"currency":return Sp(e);default:return null}},ui="-−",kp=(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("")},Ep=(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 u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=kp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},Op=(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 u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},Ap=(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",u=F=>F>="0"&&F<="9"||l!==""&&l.includes(F)||n.decimal.includes(F)||c&&(F==="e"||F==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let b=0,N=0,B=0,M="";for(const F of o.slice(0,h))ui.includes(F)?b+=1:F==="("?N+=1:M+=F;for(const F of o.slice(m))ui.includes(F)?b+=1:F===")"?B+=1:M+=F;const j=b+N;if(N!==B||j>1||j===1&&s||(s=s||j===1,r!=="currency"&&M.trim()!==""))return e;const U=Ep(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(U===null)return e;const Y=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,A=U.exponent+Y;if(A>330||A<-330)return e;const T=Op(U.integer,U.fraction,A,s);return Number.isFinite(Number(T))?T:e},di="google-sheets-html-origin",sa=Object.freeze({group:",",decimal:"."}),fi=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"],xp=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Tp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),$p=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"]),pi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Lp=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Dp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),zp=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"]),Mp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Np=3,Fp=1,ia=-25569,io=86400,Pp=-693959,_p=2958465,qp=" ",ko=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,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},ho=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Vs=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},Ip=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,jp=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 u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),b=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const N=ko(b);for(const B of m.split(",")){const M=B.trim(),j=Ip.exec(M);if(j!==null){const U=t.get(j[1]);if(U===void 0)t.set(j[1],new Map(N));else for(const[Y,A]of N)U.set(Y,A)}else if(M.toLowerCase()==="table"){const U=N.get("mso-displayed-decimal-separator"),Y=N.get("mso-displayed-thousand-separator");U!==void 0&&(n=vs(ho(U))),Y!==void 0&&(r=vs(ho(Y)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:sa}},Hp="%_-*? ",Bp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Hp.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Wp=(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,u=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+u-719468},ca=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,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},qn=(e,t)=>String(e).padStart(t,"0"),aa=e=>{if(e<Pp||e>_p)return null;let t=Math.floor(e),n=Math.round((e-t)*io);n>=io&&(t+=1,n-=io);const r=ca(t+ia),o=`${qn(r.year,4)}-${qn(r.month,2)}-${qn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${qn(s,2)}:${qn(l,2)}:${qn(n%60,2)}`},Vp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Yp=e=>{const t=Vp.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 u=Wp(n,r,o),h=ca(u);return h.year!==n||h.month!==r||h.day!==o?null:u-ia+(s*3600+l*60+c)/io},Ys=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),Rn=e=>Ys(e).replaceAll('"',"&quot;"),ua=e=>Ys(e).replaceAll("'","&#39;"),Kp=e=>Ys(e).replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
4
  `).replaceAll(`
5
- `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),uo=(e,t)=>`${e}="${vn(JSON.stringify(t))}"`,aa=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Yp=e=>{if(Ct(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Kp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Up=e=>{if(e.type==="text")return{1:1};const t=na(e);return t===null?null:{1:e.type==="date"?Kp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Tp[e.type],2:t,3:1}},Xp=/[;"'{}<>&\\]/,ua=e=>e==="left"||e==="center"||e==="right",da=e=>e==="top"||e==="middle"||e==="bottom",Gp=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}`),ua(e.align)&&t.push(`text-align:${e.align}`),da(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Xp.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 oa){const l=e.borders[s];if(l===void 0||!Object.hasOwn(ui,l.style))continue;const c=l.color===void 0?"windowtext":rt(l.color);c!==null&&t.push(`border-${s}:${ui[l.style]} ${c}`)}if(e.value!==void 0){const s=na(e.value);s!==null&&t.push(`mso-number-format:"${jp(s)}"`)}return t},Zp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Jp=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=ca([n,...Gp(e)].join(";"));let o=null;if(t!==void 0){const s=Up(t);s!==null&&(o=uo("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},Qp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Gn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&aa(o)?Yp(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Wp(e.t):null,h=[];if(l?h.push(uo("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(uo("data-sheets-value",{1:3,3:c})):u!==null&&h.push(uo("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${vn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${vn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${vn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${vn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const N=Tr(e.f,{row:n,col:r});N.includes("#REF!")||h.push(`x:fmla="${vn(N)}"`)}const m=Vp(s),b=e.link===void 0?m:`<a href="${vn(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(N=>` ${N}`).join("")}>${b}</td>`},fa=(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(Jp);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 u=0;u<e.cols;u+=1){const h=e.cells[s][u],m=h.fmt===void 0?void 0:r[h.fmt];c+=Qp(h,m===void 0?Zp:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${ai}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${yc}='${ca(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${ai}>`},Ss=(e,t)=>{for(const[n,r]of t)e.set(n,r)},pa=(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&&Ss(n,l)}const o=e.getAttribute("style");return o!==null&&Ss(n,Oo(o)),n},eh=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"}},th=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"},nh=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),rh={pt:1.5,unit:"px"},fi=e=>{let t=null,n=null;const r=[];for(const u of Vs(e)){const h=u.toLowerCase(),m=eh(u);Op.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=nh.get(n),s=o===void 0?th(t===null?rh:t):o,l=r.join(" ");if(l===""||Ap.has(l.toLowerCase()))return{style:s};const c=rt(l);return c===null||c.length===9?null:{style:s,color:c}},oh=e=>e.style==="thin"&&e.color==="#cccccc",sh=e=>{const t=rt(e);if(t!==null)return t;for(const n of Vs(e)){const r=rt(n);if(r!==null)return r}return null},lh=e=>{const t=go(Vs(e.split(",")[0]).join(" ").trim()).trim();return t===""||xp.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},ch=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},ah=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"},uh=new Set(["normal","pre-wrap","pre-line"]),dh=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const I=o.toLowerCase();(I==="bold"||I==="bolder"||Number(I)>=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=ch(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:rt(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),m=h===void 0?null:sh(h);m!==null&&m.length!==9&&(r.background=m);const b=e.get("text-align"),N=b===void 0?"":b.toLowerCase();ua(N)&&(r.align=N);const W=e.get("vertical-align"),z=W===void 0?"":W.toLowerCase();da(z)&&(r.verticalAlign=z);const q=e.get("font-family"),U=q===void 0?null:lh(q);U!==null&&(r.fontFamily=U);const Y=e.get("font-size"),A=Y===void 0?null:ih(Y);A!==null&&(r.fontSize=A);const T=e.get("white-space");T!==void 0&&uh.has(T.toLowerCase())&&(r.wrap=!0);const F={},j=e.get("border"),$=j===void 0?null:fi(j);for(const I of oa){const L=e.get(`border-${I}`),g=L===void 0?$:fi(L);g!==null&&!(n==="sheets"&&oh(g))&&(F[I]=g)}return Object.keys(F).length>0&&(r.borders=F),r},pi=e=>{e.text!==""&&!e.text.endsWith(`
5
+ `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),co=(e,t)=>`${e}="${Rn(JSON.stringify(t))}"`,da=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Up=e=>{if(gt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Xp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Gp=e=>{if(e.type==="text")return{1:1};const t=oa(e);return t===null?null:{1:e.type==="date"?Xp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Lp[e.type],2:t,3:1}},Zp=/[;"'{}<>&\\]/,fa=e=>e==="left"||e==="center"||e==="right",pa=e=>e==="top"||e==="middle"||e==="bottom",Jp=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"?st(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?st(e.background):null;if(o!==null&&t.push(`background-color:${o}`),fa(e.align)&&t.push(`text-align:${e.align}`),pa(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Zp.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(fi,l.style))continue;const c=l.color===void 0?"windowtext":st(l.color);c!==null&&t.push(`border-${s}:${fi[l.style]} ${c}`)}if(e.value!==void 0){const s=oa(e.value);s!==null&&t.push(`mso-number-format:"${Bp(s)}"`)}return t},Qp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},eh=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=ua([n,...Jp(e)].join(";"));let o=null;if(t!==void 0){const s=Gp(t);s!==null&&(o=co("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},th=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Zn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&da(o)?Up(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Yp(e.t):null,h=[];if(l?h.push(co("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(co("data-sheets-value",{1:3,3:c})):u!==null&&h.push(co("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${Rn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${Rn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${Rn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${Rn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const N=Tr(e.f,{row:n,col:r});N.includes("#REF!")||h.push(`x:fmla="${Rn(N)}"`)}const m=Kp(s),b=e.link===void 0?m:`<a href="${Rn(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(N=>` ${N}`).join("")}>${b}</td>`},ha=(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(eh);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 u=0;u<e.cols;u+=1){const h=e.cells[s][u],m=h.fmt===void 0?void 0:r[h.fmt];c+=th(h,m===void 0?Qp:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${di}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${vc}='${ua(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${di}>`},Ss=(e,t)=>{for(const[n,r]of t)e.set(n,r)},ma=(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&&Ss(n,l)}const o=e.getAttribute("style");return o!==null&&Ss(n,ko(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"}},rh=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"},oh=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),sh={pt:1.5,unit:"px"},hi=e=>{let t=null,n=null;const r=[];for(const u of Vs(e)){const h=u.toLowerCase(),m=nh(u);xp.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=oh.get(n),s=o===void 0?rh(t===null?sh:t):o,l=r.join(" ");if(l===""||Tp.has(l.toLowerCase()))return{style:s};const c=st(l);return c===null||c.length===9?null:{style:s,color:c}},lh=e=>e.style==="thin"&&e.color==="#cccccc",ih=e=>{const t=st(e);if(t!==null)return t;for(const n of Vs(e)){const r=st(n);if(r!==null)return r}return null},ch=e=>{const t=ho(Vs(e.split(",")[0]).join(" ").trim()).trim();return t===""||$p.has(t.toLowerCase())?null:t},ah=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},uh=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},dh=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"},fh=new Set(["normal","pre-wrap","pre-line"]),ph=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const q=o.toLowerCase();(q==="bold"||q==="bolder"||Number(q)>=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=uh(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:st(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),m=h===void 0?null:ih(h);m!==null&&m.length!==9&&(r.background=m);const b=e.get("text-align"),N=b===void 0?"":b.toLowerCase();fa(N)&&(r.align=N);const B=e.get("vertical-align"),M=B===void 0?"":B.toLowerCase();pa(M)&&(r.verticalAlign=M);const j=e.get("font-family"),U=j===void 0?null:ch(j);U!==null&&(r.fontFamily=U);const Y=e.get("font-size"),A=Y===void 0?null:ah(Y);A!==null&&(r.fontSize=A);const T=e.get("white-space");T!==void 0&&fh.has(T.toLowerCase())&&(r.wrap=!0);const F={},H=e.get("border"),z=H===void 0?null:hi(H);for(const q of la){const $=e.get(`border-${q}`),g=$===void 0?z:hi($);g!==null&&!(n==="sheets"&&lh(g))&&(F[q]=g)}return Object.keys(F).length>0&&(r.borders=F),r},mi=e=>{e.text!==""&&!e.text.endsWith(`
6
6
  `)&&(e.text+=`
7
- `)},fh=e=>{const t=e.getAttribute("style");return t!==null&&Oo(t).get("mso-spacerun")==="yes"},ph=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Dp.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&pi(t);continue}const o=r.node;if(o.nodeType===Mp){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
8
- `);continue}if(o.nodeType!==zp)continue;const s=o,l=s.localName;if($p.has(l)||fh(s))continue;if(l==="br"){t.text+=`
9
- `;continue}const c=t.mode==="collapse"&&Lp.has(l);if(c&&pi(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const u=s.getAttribute("href");u!==null&&(t.href=u)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let u=s.lastChild;u!==null;u=u.previousSibling)n.push({kind:"enter",node:u})}},hh=(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)},mh=(e,t)=>{const n=e.replaceAll(Pp," ");if(t==="pre")return n;const r=n.split(`
7
+ `)},hh=e=>{const t=e.getAttribute("style");return t!==null&&ko(t).get("mso-spacerun")==="yes"},mh=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Mp.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&mi(t);continue}const o=r.node;if(o.nodeType===Np){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
8
+ `);continue}if(o.nodeType!==Fp)continue;const s=o,l=s.localName;if(Dp.has(l)||hh(s))continue;if(l==="br"){t.text+=`
9
+ `;continue}const c=t.mode==="collapse"&&zp.has(l);if(c&&mi(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const u=s.getAttribute("href");u!==null&&(t.href=u)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let u=s.lastChild;u!==null;u=u.previousSibling)n.push({kind:"enter",node:u})}},gh=(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&&Ch(l.element,t,n,r)},wh=(e,t)=>{const n=e.replaceAll(qp," ");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
- `)},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)}Ss(t,pa(e,r))},wh=(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"?ia(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<di.length?di[l]:null}return null},ha=(e,t,n)=>t!==void 0&&aa(t)?Ep(e,t,n):e,Ch=(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 u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&Ct(c)!==null)if(n!==void 0&&n.type==="date"){const u=ia(Number(c));if(u!==null)return u}else return c;return ha(t,n,r)},bh=(e,t,n,r)=>{const o=pa(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:ah(o)};for(const m of Sh(e))ph(m,l);hh(l,o,s,r.rules);const c=mh(l.text,l.mode),u=dh(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),b=m===null?void 0:Cp(m,r.options);b!==void 0&&(u.value=b);const N=e.getAttribute("data-sheets-value"),W=N===null?null:wh(N,b);h.t=W===null?ha(c,b,ra):W;const z=e.getAttribute("data-sheets-formula");z?.startsWith("=")&&(h.f=z);const q=e.getAttribute("data-sheets-hyperlink"),U=q!==null?q:l.href,Y=U===null?null:an(U);Y!==null&&(h.link=Y);const A=e.getAttribute("data-sheets-note");A!==null&&A!==""&&(h.note=A)}else{const m=o.get("mso-number-format"),b=m===void 0?void 0:Ws(vs(go(m)),r.options);b!==void 0&&(u.value=b),h.t=Ch(e,c,b,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(h.f=ko(N,{row:t,col:n}));const W=l.href===null?null:an(l.href);W!==null&&(h.link=W)}return{cell:h,format:u}},ks=(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},yh=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)},Rh=(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]))},ma=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Oo(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:yh(l);if(c!==null)return Math.min(c,cn)}const o=Rh(e,t);return o===null?null:Math.min(o,cn)},vh=(e,t)=>{const n=[],r=o=>{const s=ma(o,"width");for(let l=ks(o,"span",_s);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Er(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Er(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Er(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Sh(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*kh(e){for(const t of["thead","tbody","tfoot"])for(const n of Er(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Er(n))o.localName==="tr"&&(yield o)}}const ns=()=>({t:""}),Eh=(e,t,n)=>{const r=Mc(),o=[],s=[],l=[];let c=0;for(const W of kh(e)){const z=o.length,q=(z+1)*Math.max(c,1);if(q>n)return{outcome:"limit",cells:q};const U=[];for(let A=0;A<l.length;A+=1)l[A]>0&&(U[A]=ns(),l[A]-=1);let Y=0;for(const A of Er(W)){const T=A.localName;if(T!=="td"&&T!=="th")continue;for(;U[Y]!==void 0;)Y+=1;const F=ks(A,"colspan",_s),j=ks(A,"rowspan",Oc),$=(z+1)*Math.max(c,Y+F);if($>n)return{outcome:"limit",cells:$};const I=bh(A,z,Y,t),L=r.intern(I.format);L!==void 0&&(I.cell.fmt=L),U[Y]=I.cell;for(let g=1;g<F;g+=1)U[Y+g]===void 0&&(U[Y+g]=ns());if(j>1)for(let g=0;g<F;g+=1){const p=j-1,C=Y+g;l[C]=l[C]===void 0||l[C]<p?p:l[C]}Y+=F}U.length>c&&(c=U.length),o.push(U),s.push(ma(W,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(W=>{const z=[];for(let q=0;q<c;q+=1){const U=W[q];z.push(U===void 0?ns():U)}return z}),h=vh(e,c),m=h.length===c&&h.every(W=>W!==null)?h.map(W=>W===null?0:W):void 0,b=s.every(W=>W!==null)?s.map(W=>W===null?0:W):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:Fs(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...b===void 0?{}:{rowHeights:b},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},ga=(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=qp(o);return Eh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},de=(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)}),un=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,bt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),wt=e=>e.reduce((t,n)=>t+bt(n).rows*bt(n).cols,0),Oh=(e,t)=>{if(!un(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(de({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(de({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(de({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(de({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},nn=(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}))}},dn=(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)}},Bt=(e,t)=>e.row===t.row&&e.col===t.col,wa=(e,t)=>e===void 0?Bl(void 0,void 0,t()):Bl(e.align,e.value,e.align===void 0?t():""),fo=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Jn=(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}},po=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}),Ca=e=>e.isCellReadOnly!==void 0,Ze=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Ah=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],xh=()=>!0,Th=e=>{const t=new WeakMap,n={};for(const r of Ah)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:xh}),n},$h=/^data-[a-z0-9-]+$/,Lh=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Dh=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Lh(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(!$h.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},Cr=(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},Wn=(e,t)=>{for(const n of t)if(Cr(e,n))return!0;return!1},Mh=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=bt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Es=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=bt(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},b=Math.min(u,r-m.row),N=Math.min(h,o-m.col);return b<=0||N<=0?null:de(m,{row:m.row+b-1,col:m.col+N-1})},ba=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=Es({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,b=u.endCol-u.startCol+1,N=[];for(let W=0;W<m;W+=l){const z=[];for(let U=0;U<b;U+=c){const Y={row:h.row+W,col:h.col+U};z.push(Y),N.push(Y)}const q=Math.min(l,m-W);for(let U=0;U<q;U+=1){const Y=h.row+W+U,A=e[U];for(let T=0;T<z.length;T+=1){const F=T*c,j=Math.min(c,b-F);for(let $=0;$<j;$+=1)s(Y,h.col+F+$,A[$],z[T])}}}return N},zh=(e,t,n,r,o)=>{const s=[];return ba(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},hi=(e,t,n,r,o,s)=>{const l=[],c=ba(e,t,n,r,o,(u,h,m,b)=>{const N=s(m,u,h,b);N!==null&&l.push({...N,row:u,col:h})});return{edits:l,tiles:c}},ya=(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)})`)},Nh=(e,t)=>{ya(e,t);const n=bt(t),r=bt(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},Fh=(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(de({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(de({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(de({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(de({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Ph=(e,t,n,r)=>{ya(t,n);const o=bt(t).rows,s=bt(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let b=n.startCol;b<=n.endCol;b+=1){if(m&&b>=t.startCol&&b<=t.endCol)continue;const N=t.startCol+((b-t.startCol)%s+s)%s,W=h*2**21+N;let z=c.get(W);z===void 0&&(z={value:e(h,N),origin:{row:h,col:N}},c.set(W,z)),l.push(r(z.value,z.origin,{row:u,col:b}))}}return l},Ra=(e,t,n)=>{const r=Jn(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:At(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=Qn(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},va=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Xc(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},Ao=["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"],_h=/^[A-Z]$/,qh=/^[A-Za-z]$/,Ih=/^Key([A-Z])$/,Sa=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"]),jh=e=>_h.test(e)||Sa.has(e),It=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||!jh(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}},Hh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,ka=e=>{if(qh.test(e.key))return e.key.toUpperCase();const t=Ih.exec(e.code);return t!==null?t[1]:Sa.has(e.code)?e.code:null},fr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:ka(t)===e.key,Ce=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),Se=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Bh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(Ce(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(Ce(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(Ce(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(Ce(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Wh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(Ce(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(Ce(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},$r=[...Bh(),Ce("Home","idle","row start (first visible column)"),Ce("Ctrl+Home","idle","first visible cell"),Ce("Shift+Home","idle","extend to row start"),Ce("Ctrl+Shift+Home","idle","extend to first visible cell"),Ce("End","idle","row end (last visible column)"),Ce("Ctrl+End","idle","last visible cell"),Ce("Shift+End","idle","extend to row end"),Ce("Ctrl+Shift+End","idle","extend to last visible cell"),Ce("PageUp","both","page up (idle) / commit + page up (editing)"),Ce("PageDown","both","page down (idle) / commit + page down (editing)"),Ce("Shift+PageUp","idle","extend one page up"),Ce("Shift+PageDown","idle","extend one page down"),Ce("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),Ce("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),Ce("Tab","both","cycle right (idle) / commit + cycle right (editing)"),Ce("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),Ce("Enter","both","cycle down (idle) / commit + cycle down (editing)"),Ce("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),Ce("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),Ce("F2","both","start editing (idle) / toggle the pointing arm (editing)"),Ce("F4","editing","cycle the reference anchor under the caret (formula session)"),Ce("Delete","idle","clear every selected cell"),Ce("Backspace","idle","clear every selected cell"),Ce("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),Ce("Ctrl+A","idle","select all"),Ce("Ctrl+Z","idle","undo request"),Ce("Ctrl+Y","idle","redo request"),Ce("Ctrl+Shift+Z","idle","redo request"),Ce("Shift+F10","idle","keyboard context menu"),Ce("ContextMenu","idle","keyboard context menu"),Ce("Ctrl+Space","idle","column bands"),Ce("Shift+Space","idle","row bands"),Ce("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),Ce("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),Ce("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),Ce("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"},...Wh(),Se("bold","Ctrl+B","both","toggle bold"),Se("italic","Ctrl+I","both","toggle italic"),Se("underline","Ctrl+U","both","toggle underline"),Se("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),Se("clearFormatting","Ctrl+Backslash","idle","clear formatting"),Se("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),Se("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),Se("alignLeft","Ctrl+Shift+L","both","align left"),Se("alignCenter","Ctrl+Shift+E","both","align center"),Se("alignRight","Ctrl+Shift+R","both","align right"),Se("formatNumber","Ctrl+Shift+Digit1","both","number format"),Se("formatTime","Ctrl+Shift+Digit2","both","time format"),Se("formatDate","Ctrl+Shift+Digit3","both","date format"),Se("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),Se("formatPercent","Ctrl+Shift+Digit5","both","percent format"),Se("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),Se("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),Se("bordersClear","Alt+Shift+Digit6","idle","clear borders"),Se("borderTop","Alt+Shift+Digit1","idle","top border"),Se("borderRight","Alt+Shift+Digit2","idle","right border"),Se("borderBottom","Alt+Shift+Digit3","idle","bottom border"),Se("borderLeft","Alt+Shift+Digit4","idle","left border"),Se("insertLink","Ctrl+K","idle","insert / edit hyperlink"),Se("insertNote","Shift+F2","idle","insert / edit note"),Se("insertComment","Ctrl+Alt+M","idle","insert comment"),Se("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),Se("openValidationList","Alt+ArrowDown","idle","open the validation list"),Se("fillDown","Ctrl+D","idle","fill down"),Se("fillRight","Ctrl+R","idle","fill right"),Se("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),Se("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),Se("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),Se("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),Se("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),Se("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),Se("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),Se("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),Se("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),Se("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),Se("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],rs=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),mi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Vh=e=>{const t=It(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 mi?mi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},wo=(e,t)=>e.column==="both"||e.column===t,Yh=Array.from(new Set($r.filter(e=>!e.rebindable&&wo(e,"idle")).map(e=>e.chord))),Co=new Set($r.filter(e=>e.command!==void 0&&wo(e,"editing")).map(e=>e.command)),Kh=new Set($r.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Ea=e=>{const t={};for(const n of Ao)t[n]=e(n);return t},Oa=Ea(e=>$r.filter(t=>t.command===e).map(t=>t.chord)),Uh=e=>{const t=new Map;for(const n of Ao){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},Xh=e=>{const t=new Set(Ao);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(Kh.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`)}}}},Gh=(e,t)=>{const n=It(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Co.has(e);for(const o of $r)if(!(o.rebindable||o.command===e||o.chord!==t)&&(wo(o,"idle")||r&&wo(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Zh=e=>{e!==void 0&&Xh(e);const t=Ea(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Oa[r]:o===null?[]:o});for(const r of Ao)for(const o of t[r])Gh(r,o);const n=new Map;for(const[r,o]of Uh(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},Aa=(e,t)=>{const n=ka(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=Hh({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}},Jh=(e,t)=>{const n=Aa(e,t);return n===null?null:n.command},Qh=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","NumpadEnter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),em=/^F(?:[1-9]|1[0-2])$/,tm=e=>{const t=It(e);return t.alt||Qh.has(t.key)?!1:t.ctrl||em.test(t.key)},Ks=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],gi=[...ot.VIRTUAL_SCROLL_LABEL_KEYS,...Ks],Os=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:"閉じる"})}),xa=Object.freeze({en:Object.freeze({...ot.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Os.en}),ja:Object.freeze({...ot.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Os.ja})}),kn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,wi=e=>e==="commentCount"||e==="listMore",nm=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 ${kn(t)}`);for(const n of Ks){const r=e[n];if(!(wi(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=wi(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${kn(r)}`)}}},rm=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},om=(e,t,n)=>{e[t]=n},Ta=(e,t)=>{const n=ot.resolveVirtualScrollLocale(e);if(t===void 0)return xa[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${kn(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(!gi.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${gi.join(", ")}`);const s={...ot.resolveVirtualScrollLabels(n,rm(t)),...Os[n]};for(const l of Ks){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&om(s,l,c)}return nm(s),Object.freeze(s)},sm=e=>{const t={};for(const n of ot.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Pe=(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},Ci={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},lm={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}`}},os=(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")})},cm=Object.freeze({list:"Value must be one of the list items.",number:os("Value must be a number",Ci),textLength:os("Text length must be",Ci),date:os("Value must be a date",lm),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}.`}),am=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} を満たす値を入力してください。`}),ss=Object.freeze({en:cm,ja:am}),um=Object.freeze({ok:!0}),dm="TRUE",fm="FALSE",pm=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),hm=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),mm=/^[+-]?(?:\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}))?)?$/,wm=/^[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])?)+$/,bi=e=>{const t=e.trim();if(!(mm.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("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,b=m.search(/[^0]/);return b<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(b).replace(/0+$/,""),point:u.length+l-b}},Cm=e=>e===1?-1:e===-1?1:0,bm=(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:Cm(n)},ym=(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}},yi=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>ym(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Rm=(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},vm=(e,t)=>e<t?-1:e>t?1:0,Sm=e=>e==="between"||e==="notBetween",km=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Sm(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Em=(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}},ls=(e,t,n,r,o,s)=>{const l=km(e,t,n,r);return l===null?!0:o===null?!1:Em(e,s(o,l.a),l.b===null?0:s(o,l.b))},Om=e=>Number.isFinite(e)?e:null,Am=e=>{let t=0;for(const n of e)t+=1;return t},xm=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Tm=(e,t)=>{switch(e.op){case"isEmail":return wm.test(t);case"isUrl":return xm(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)}},$m=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,$a=e=>({checked:e.checked===void 0?dm:e.checked,unchecked:e.unchecked===void 0?fm:e.unchecked}),Lm=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!pm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${kn(e.op)} for type "${e.type}"`);return;case"text":if(!hm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${kn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${kn(e.type)}`)}},Dm=(e,t,n)=>{switch(e.type){case"list":return Nm(e).has(t);case"number":return ls(e.op,e.a,e.b,bi,bi(t),bm);case"textLength":return ls(e.op,e.a,e.b,Om,Am(t),vm);case"date":return ls(e.op,e.a,e.b,yi,yi(t),Rm);case"text":return Tm(e,t);case"checkbox":{const r=$a(e);return t===r.checked||t===r.unchecked}default:return n===void 0||$m(n(e.formula))}},La=(e,t,n)=>(Lm(e),t===""||Dm(e,t,n)),Ri=e=>e===void 0?void 0:e.trim(),Mm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Ri(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(),Ri(e.b));case"text":return zm(e,t.text);case"checkbox":{const n=$a(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},zm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},vi=new WeakMap,Nm=e=>{const t=vi.get(e);if(t!==void 0)return t;const n=new Set(e.values);return vi.set(e,n),n},Da=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(ss,n)){const o=Object.keys(ss).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${kn(n)}`)}return La(e,t,r)?um:{ok:!1,message:e.errorMessage===void 0?Mm(e,ss[n]):e.errorMessage}},Fm=e=>e.type!=="custom",Pm=(e,t)=>Fm(e)&&!La(e,t,void 0),Ma=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),za=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Na=(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,Fa=(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),Pa=(e,t)=>Ma(e,t),_a=(e,t)=>Ma(e,t),qa=(e,t)=>za(e,t),Ia=(e,t)=>za(e,t),En=(e,t,n)=>Na(e,t,n),On=(e,t,n)=>Na(e,t,n),Lr=(e,t,n)=>Fa(e,t,n),Dr=(e,t,n)=>Fa(e,t,n),_m=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Dt=1,br=3,Gr=e=>`${-Math.min(br,Math.max(0,Math.floor(e)))}px`,qm=(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}},Si=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,ki=(e,t)=>t===null?e:Math.min(e,t),Ei=e=>e===null?"100%":`min(100%, ${e}px)`,Oi=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,Ai=(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]}},xi=Object.freeze([0,-1]),Ti=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const u=-c*Dt,h=c*(1+Dt),m=t>=r,b=n<=o,N=m?s:u,W=b?l:h;return W<=u||N>=h?!1:(e.near=Math.max(N,u),e.far=Math.min(W,h),e.nearOpen=!m||N<u,e.farOpen=!b||W>h,!0)},Zr=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),$i=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,Li=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Im=Object.freeze(["top","right","bottom","left"]),jm=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Hm=e=>Im.filter((t,n)=>(e&1<<n)!==0).join(" "),ja=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Bm=16,Wm=450,Vm=e=>e>4?Math.floor(Wm/(5*e)):Bm,pr=(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},Di=()=>({rowLeft:pr("row","left"),rowRight:pr("row","right"),colAbove:pr("column","above"),colBelow:pr("column","below"),cross:pr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),As=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Jr=(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},Qr=(e,t)=>Math.min(Math.max(e,0),t),Mi="inset(100%)",Kn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Ym=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Kn([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 m=`translate(${Qr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const b=`translate(${Qr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;b!==s.rowRightTransform&&(s.rowRightTransform=b,e.rowRight.style.transform=b)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Kn([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 m=`translate(${t.left}px, ${Qr(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const b=`translate(${t.left}px, ${Qr(t.top+t.height,n.clampHeight)}px)`;b!==s.colBelowTransform&&(s.colBelowTransform=b,e.colBelow.style.transform=b)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Kn([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--_aqsp-band-${u})`),(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)}},zi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Kn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Kn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Kn([e.cross],!1))},eo=e=>{for(const t of As(e))t.remove()},Km=(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)},Um=Object.freeze([]),Ni=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},Fi=e=>e.chrome[0]??e.active,Pi=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)},Xm={left:"0px",right:"0px",width:""},Gm={top:"0px",bottom:"0px",height:""},_i=()=>({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:[]}),qi=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Ii=6,Zm=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:b,fillFrameRef:N,resizeGuideFrameRef:W,fillHandleNodeRef:z,enableFillHandle:q,frozenCols:U,frozenRows:Y,trailingCols:A,trailingRows:T,sinkAriaLabel:F,sinkReadOnly:j,sinkKeyShortcuts:$,onSinkMouseDown:I,editPaintRef:L,highlightRef:g,frameRange:p,highlightColors:C,popoverAnchors:v,interactiveAnchorRef:E,tipAnchorRef:R})=>{const y=i.useRef(null),a=i.useRef(p);a.current=p;const f=p!==void 0,k=i.useRef(null),d=i.useRef(null),x=i.useRef(new Map(qi.map(S=>[S,_i()]))),O=i.useCallback(S=>{const D=x.current.get(S);if(D!==void 0)return D;const V=_i();return x.current.set(S,V),V},[]),M=i.useCallback((S,D,V)=>{if(S===null)return;const P=S.style;P.left!==D.left&&(P.left=D.left),P.right!==D.right&&(P.right=D.right),P.width!==D.width&&(P.width=D.width),P.top!==V.top&&(P.top=V.top),P.bottom!==V.bottom&&(P.bottom=V.bottom),P.height!==V.height&&(P.height=V.height)},[]),H=i.useCallback((S,D,V)=>{if(!(S.bandClampWidth===D&&S.bandClampHeight===V)){S.bandClampWidth=D,S.bandClampHeight=V;for(const P of S.bandPool)Jr(P,D,V);S.dragBand!==null&&Jr(S.dragBand,D,V)}},[]),B=i.useRef({rowAxis:e,colAxis:t});B.current={rowAxis:e,colAxis:t};const G=i.useCallback((S,D,V)=>{const P=S.dividerSlots[D];P===null||S.dividerShown[D]===V||(S.dividerShown[D]=V,P.style.display=V?"":"none")},[]),X=i.useCallback((S,D,V)=>{const P=S.bandClip;P!==null&&(S.bandClipWidth!==D&&(S.bandClipWidth=D,P.style.width=D),S.bandClipHeight!==V&&(S.bandClipHeight=V,P.style.height=V))},[]),ee=i.useCallback((S,D,V)=>{const P=S.dividerSlots[D];P===null||S.dividerEnd[D]===V||(S.dividerEnd[D]=V,D<2?P.style.bottom=V:P.style.right=V)},[]),ne=i.useRef({x:0,y:0}),le=i.useRef(null),re=i.useCallback((S,D)=>{const V=n.current,P=V?.getFrozenSize()??_m,Z=V?.getViewportSize(),J=Z?.width??-1,ie=Z?.height??-1,ve=ne.current;ve.x=S,ve.y=D;const Oe=a.current!==void 0,Ee=B.current,He=Oe?Ee.rowAxis.count:-1,fe=Oe?Ee.colAxis.count:-1,Le=Oe?Ee.rowAxis.totalSize():-1,pe=Oe?Ee.colAxis.totalSize():-1;let se=le.current;if(se===null||se.framed!==Oe||se.rowCount!==He||se.colCount!==fe||se.rowsTotal!==Le||se.colsTotal!==pe||se.frozenCols!==P.cols||se.frozenWidth!==P.width||se.frozenRows!==P.rows||se.frozenHeight!==P.height||se.trailingCols!==P.trailingCols||se.trailingWidth!==P.trailingWidth||se.trailingVisibleWidth!==P.trailingVisibleWidth||se.trailingRows!==P.trailingRows||se.trailingHeight!==P.trailingHeight||se.trailingVisibleHeight!==P.trailingVisibleHeight||se.bodyWidth!==J||se.bodyHeight!==ie){const ce=P.trailingVisibleWidth,Te=P.trailingVisibleHeight,Qe=P.cols<=0&&P.trailingCols<=0?[{kind:"m",map:ke=>ke-ve.x,clamp:J,style:Xm,seamLead:!1,seamTrail:!1}]:[...P.cols>0?[{kind:"f",map:ke=>ke,clamp:P.width,style:{left:"0px",width:`${P.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ke=>ke-ve.x-P.width,clamp:Math.max(0,J-P.width-ce),style:{left:`${P.width}px`,right:`${ce}px`,width:""},seamLead:P.cols>0,seamTrail:P.trailingCols>0},...P.trailingCols>0?[{kind:"t",map:ke=>ke-B.current.colAxis.totalSize()+ce,clamp:ce,style:{left:"",right:"0px",width:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],Ue=P.rows<=0&&P.trailingRows<=0?[{kind:"m",map:ke=>ke-ve.y,clamp:ie,style:Gm,seamLead:!1,seamTrail:!1}]:[...P.rows>0?[{kind:"f",map:ke=>ke,clamp:P.height,style:{top:"0px",height:`${P.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ke=>ke-ve.y-P.height,clamp:Math.max(0,ie-P.height-Te),style:{top:`${P.height}px`,bottom:`${Te}px`,height:""},seamLead:P.rows>0,seamTrail:P.trailingRows>0},...P.trailingRows>0?[{kind:"t",map:ke=>ke-B.current.rowAxis.totalSize()+Te,clamp:Te,style:{top:"",bottom:"0px",height:`${Te}px`},seamLead:!0,seamTrail:!1}]:[]],it=[];for(const ke of Qe){const ct=Oe?Si(ke.kind,pe,P.width,P.trailingWidth):null,[We,Be]=Oe?Ai(ke.kind,fe,P.cols,P.trailingCols):xi;for(const et of Ue){const gn=Oe?Si(et.kind,Le,P.height,P.trailingHeight):null,[Zt,or]=Oe?Ai(et.kind,He,P.rows,P.trailingRows):xi;it.push({nodes:O(`${ke.kind}${et.kind}`),xKind:ke.kind,yKind:et.kind,mapX:ke.map,clampWidth:ke.clamp,xStyle:ke.style,xSeamLead:ke.seamLead,xSeamTrail:ke.seamTrail,xFirst:We,xLast:Be,mapY:et.map,clampHeight:et.clamp,yStyle:et.style,ySeamLead:et.seamLead,ySeamTrail:et.seamTrail,yFirst:Zt,yLast:or,cells:{clampWidth:ki(ke.clamp,ct),clampHeight:ki(et.clamp,gn)},xCellsSizeCss:Ei(ct),yCellsSizeCss:Ei(gn),xCellsEndCss:Oi(ct),yCellsEndCss:Oi(gn)})}}se={frozenCols:P.cols,frozenWidth:P.width,frozenRows:P.rows,frozenHeight:P.height,trailingCols:P.trailingCols,trailingWidth:P.trailingWidth,trailingVisibleWidth:P.trailingVisibleWidth,trailingRows:P.trailingRows,trailingHeight:P.trailingHeight,trailingVisibleHeight:P.trailingVisibleHeight,bodyWidth:J,bodyHeight:ie,framed:Oe,rowCount:He,colCount:fe,rowsTotal:Le,colsTotal:pe,ctxs:it},le.current=se}const be=P.width>0,ye=P.trailingWidth>0,ge=P.height>0,Je=P.trailingHeight>0;for(const ce of se.ctxs)M(ce.nodes.container,ce.xStyle,ce.yStyle),H(ce.nodes,ce.clampWidth,ce.clampHeight),G(ce.nodes,0,be),G(ce.nodes,1,ye),G(ce.nodes,2,ge),G(ce.nodes,3,Je),ee(ce.nodes,0,ce.yCellsEndCss),ee(ce.nodes,1,ce.yCellsEndCss),ee(ce.nodes,2,ce.xCellsEndCss),ee(ce.nodes,3,ce.xCellsEndCss),X(ce.nodes,ce.xCellsSizeCss,ce.yCellsSizeCss);return se.ctxs},[n,O,M,H,G,ee,X]),Ae=i.useCallback((S,D,V)=>{S.dividerSlots[D]=V,S.dividerShown[D]=!1,S.dividerEnd[D]="0px",Pi(S)},[]),ze=i.useCallback((S,D)=>{S.frame=D===null?null:{node:D,x:Zr(),y:Zr(),drawnX:Zr(),drawnY:Zr(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},Pi(S)},[]),_e=i.useCallback((S,D)=>{for(const P of S.bandPool)eo(P);S.bandPool.length=0,S.dragBand!==null&&(eo(S.dragBand),S.dragBand=null),S.bandClampWidth=-1,S.bandClampHeight=-1,S.bandClip=D,S.bandClipWidth="",S.bandClipHeight="";const V=D===null?null:D.parentElement;D!==null&&V!==null&&V.firstChild!==D&&V.insertBefore(D,V.firstChild)},[]),qe=i.useCallback(S=>{const D=()=>O(S);return{container:V=>{const P=D();P.container=V,V===null&&(P.fillPool.length=0,P.bandPool.length=0,P.dragBand=null,P.bandClampWidth=-1,P.bandClampHeight=-1)},dividerXLeading:V=>Ae(D(),0,V),dividerXTrailing:V=>Ae(D(),1,V),dividerYLeading:V=>Ae(D(),2,V),dividerYTrailing:V=>Ae(D(),3,V),frame:V=>ze(D(),V),bandClip:V=>_e(D(),V),active:V=>{D().active=V},dragRect:V=>{D().dragRect=V},marquee:V=>{D().marquee=V},fillPreview:V=>{D().fillPreview=V},resizeGuide:V=>{D().resizeGuide=V}}},[O,Ae,ze,_e]),we=i.useMemo(()=>Object.fromEntries(qi.map(S=>[S,qe(S)])),[qe]),Ne=Math.min(Math.max(0,U),t.count),st=Pa(t,Ne),je=Math.min(Math.max(0,Y),e.count),fn=_a(e,je),lt=A===void 0?0:Math.min(Math.max(0,A),t.count-Ne),ft=qa(t,lt),pt=T===void 0?0:Math.min(Math.max(0,T),e.count-je),pn=Ia(e,pt),Vt=i.useRef(null),Mr=i.useRef("add"),hn=i.useRef(s);hn.current=s;const zr=i.useRef(!1),Nr=ot.useWheelBridge(n,{enableBridge:!s}),oe=i.useCallback(S=>(r.current=S,Nr(S)),[r,Nr]),me=i.useCallback((S,D)=>({top:D.mapY(e.offsetOf(S.startRow)),bottom:D.mapY(e.offsetOf(S.endRow)+e.sizeOf(S.endRow)),left:D.mapX(t.offsetOf(S.startCol)),right:D.mapX(t.offsetOf(S.endCol)+t.sizeOf(S.endCol))}),[e,t]),ue=i.useCallback((S,D)=>{if(D.clampHeight<=0||D.clampWidth<=0)return null;const{top:V,bottom:P,left:Z,right:J}=me(S,D),ie=-D.clampHeight*Dt,ve=D.clampHeight*(1+Dt),Oe=-D.clampWidth*Dt,Ee=D.clampWidth*(1+Dt);if(P<ie||V>ve||J<Oe||Z>Ee)return null;const He=Math.max(V,ie),fe=Math.max(Z,Oe);return{top:He,left:fe,width:Math.min(J,Ee)-fe,height:Math.min(P,ve)-He}},[me]),An=i.useCallback((S,D)=>{if(D.clampHeight<=0||D.clampWidth<=0)return null;const V=me(S,D),P=-D.clampHeight*Dt,Z=D.clampHeight*(1+Dt),J=-D.clampWidth*Dt,ie=D.clampWidth*(1+Dt),ve=Math.min(Math.max(V.top,P),Z),Oe=Math.min(Math.max(V.left,J),ie);return{top:ve,left:Oe,width:Math.min(Math.max(V.right,J),ie)-Oe,height:Math.min(Math.max(V.bottom,P),Z)-ve}},[me]),xe=i.useCallback(()=>{if(g===void 0)return null;const S=g.current;return S.row||S.column||S.intersection?S:null},[g]),Yt=i.useCallback((S,D,V)=>{if(D.bandClip!==null){for(const Z of As(V))D.bandClip.appendChild(Z);return}const P=D.fillPool[0]?.node??Fi(D);for(const Z of As(V))S.insertBefore(Z,P)},[]),Kt=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),Fr=i.useCallback(S=>{const D=S.nodes.frame;if(D===null)return;const V=Kt.current,P=a.current;(V.range!==P||V.rows!==e.count||V.cols!==t.count)&&(V.range=P,V.rows=e.count,V.cols=t.count,V.within=P===void 0?null:qm(P,e.count,t.count));const Z=V.within,J=D.last,ie=D.node.style;if(!(Z!==null&&Ti(D.x,Z.startCol,Z.endCol,S.xFirst,S.xLast,S.mapX(t.offsetOf(Z.startCol)),S.mapX(t.offsetOf(Z.endCol)+t.sizeOf(Z.endCol)),S.clampWidth)&&Ti(D.y,Z.startRow,Z.endRow,S.yFirst,S.yLast,S.mapY(e.offsetOf(Z.startRow)),S.mapY(e.offsetOf(Z.endRow)+e.sizeOf(Z.endRow)),S.clampHeight))){J.shown&&(J.shown=!1,ie.display="none");return}if(J.shown||(J.shown=!0,ie.display="block"),!$i(D.x,D.drawnX)){Li(D.drawnX,D.x);const Ee=Ni(D.x);Ee.start!==J.left&&(J.left=Ee.start,ie.left=Ee.start),Ee.end!==J.right&&(J.right=Ee.end,ie.right=Ee.end),Ee.size!==J.width&&(J.width=Ee.size,ie.width=Ee.size)}if(!$i(D.y,D.drawnY)){Li(D.drawnY,D.y);const Ee=Ni(D.y);Ee.start!==J.top&&(J.top=Ee.start,ie.top=Ee.start),Ee.end!==J.bottom&&(J.bottom=Ee.end,ie.bottom=Ee.end),Ee.size!==J.height&&(J.height=Ee.size,ie.height=Ee.size)}const Oe=jm(D.x,D.y);Oe!==J.open&&(J.open=Oe,Oe===0?D.node.removeAttribute("data-aqsp-frame-open"):D.node.setAttribute("data-aqsp-frame-open",Hm(Oe)))},[e,t]),Mt=i.useCallback((S,D,V,P)=>{const Z=An(D,V);if(Z===null){zi(S);return}Ym(S,Z,V,P,zc(D,t.count)||Nc(D,e.count))},[An,e,t]),Pr=i.useCallback((S,D,V,P)=>{const Z=S.nodes.bandPool;for(;Z.length>V.length;){const J=Z.pop();J!==void 0&&eo(J)}if(P===null){S.nodes.dragBand!==null&&(eo(S.nodes.dragBand),S.nodes.dragBand=null);return}for(let J=0;J<V.length;J+=1){let ie=Z[J];ie===void 0&&(ie=Di(),Jr(ie,S.clampWidth,S.clampHeight),Yt(D,S.nodes,ie),Z.push(ie)),Mt(ie,V[J],S,P)}},[Yt,Mt]),xn=i.useCallback((S,D,V)=>{const P=S.nodes.container;if(P===null)return;if(D===null||V===null){S.nodes.dragBand!==null&&zi(S.nodes.dragBand);return}let Z=S.nodes.dragBand;Z===null&&(Z=Di(),Jr(Z,S.clampWidth,S.clampHeight),Yt(P,S.nodes,Z),S.nodes.dragBand=Z),Mt(Z,D,S,V)},[Yt,Mt]),Ut=i.useCallback((S,D)=>{if(S!==null){if(D===null){S.style.display="none";return}S.style.display="block",S.style.transform=`translate(${D.left}px, ${D.top}px)`,S.style.width=`${D.width}px`,S.style.height=`${D.height}px`}},[]),mn=i.useCallback((S,D,V,P)=>{const Z=P==="point"?null:xe();for(const J of re(V,D))Ut(J.nodes.dragRect,ue(S,J)),xn(J,S,Z)},[ue,re,Ut,xe,xn]),Tn=i.useCallback((S,D,V)=>{for(const P of re(V,D))Ut(P.nodes.fillPreview,S===null?null:ue(S,P))},[ue,re,Ut]),er=i.useCallback((S,D,V)=>{for(const P of re(V,D)){const Z=P.nodes.resizeGuide;if(Z===null)continue;if(S===null){Z.style.display="none";continue}const J=S.anchor==="trailing";if(S.axis==="col"){if(J&&P.xKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const ie=P.mapX(S.position);Z.style.transform=`translate(${J?Math.max(0,ie):ie}px, 0px)`,Z.style.width="1px",Z.style.height="100%"}else{if(J&&P.yKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const ie=P.mapY(S.position);Z.style.transform=`translate(0px, ${J?Math.max(0,ie):ie}px)`,Z.style.width="100%",Z.style.height="1px"}}},[re]),tr=i.useCallback((S,D,V,P,Z,J,ie)=>{if(S===null)return;if(D===null||ie<=0||J<=0){S.style.clipPath=Mi;return}const ve=On(e,D.row,P),Oe=En(t,D.col,V),Ee=t.sizeOf(D.col),He=e.sizeOf(D.row),fe=Oe>=J||ve>=ie,Le=D.col>=Z.cols&&Oe<Z.width,pe=D.row>=Z.rows&&ve<Z.height,se=Z.trailingWidth>0&&D.col<t.count-Z.trailingCols&&Oe+Ee>J-Z.trailingVisibleWidth,be=Z.trailingHeight>0&&D.row<e.count-Z.trailingRows&&ve+He>ie-Z.trailingVisibleHeight;if(fe||Le||pe||se||be){S.style.clipPath=Mi;return}S.style.clipPath="",S.style.transform=`translate(${Oe}px, ${ve}px)`;const ye=`${Ee} ${He}`;S.dataset.aqspAnchorSig!==ye&&(S.dataset.aqspAnchorSig=ye,S.style.width=`${Ee}px`,S.style.height=`${He}px`)},[e,t]),$n=i.useCallback((S,D,V)=>{if(v===void 0)return;const P=v.current,{width:Z,height:J}=S.getViewportSize(),ie=S.getFrozenSize(),ve={scroll:V,frozenCount:ie.cols,trailingCount:ie.trailingCols,extent:Z},Oe={scroll:D,frozenCount:ie.rows,trailingCount:ie.trailingRows,extent:J};tr(E===void 0?null:E.current,P.interactive,ve,Oe,ie,Z,J),tr(R===void 0?null:R.current,P.tip,ve,Oe,ie,Z,J)},[v,E,R,tr]),Xt=i.useCallback(()=>{const S=y.current,D=n.current;if(S===null||D===null)return;const V=D.getScrollPosition(),P=Math.max(0,V.y),Z=Math.max(0,V.x),J=o(),ie=re(Z,P),ve=xe(),Oe=ve===null?Um:J.ranges.slice(-Vm(ie.length));for(const pe of ie){const se=pe.nodes.container;if(se===null)continue;const be=pe.nodes.fillPool;for(let ye=0;ye<Math.max(be.length,J.ranges.length);ye+=1){let ge=be[ye];if(ge===void 0){const Te=document.createElement("div");Te.className="aqsp-selection-fill",Te.setAttribute("data-aqsp-fill",""),Te.style.display="none",se.insertBefore(Te,Fi(pe.nodes)),ge={node:Te,last:{shown:!1,width:-1,height:-1,transform:""}},be.push(ge)}const Je=J.ranges[ye],ce=Je===void 0?null:ue(Je,pe);if(ce===null)ge.last.shown&&(ge.last.shown=!1,ge.node.style.display="none");else{ge.last.shown||(ge.last.shown=!0,ge.node.style.display="block");const Te=`translate(${ce.left}px, ${ce.top}px)`;Te!==ge.last.transform&&(ge.last.transform=Te,ge.node.style.transform=Te),ce.width!==ge.last.width&&(ge.last.width=ce.width,ge.node.style.width=`${ce.width}px`),ce.height!==ge.last.height&&(ge.last.height=ce.height,ge.node.style.height=`${ce.height}px`)}}for(;be.length>J.ranges.length;)be.pop()?.node.remove();Ut(pe.nodes.active,ue(de(J.active,J.active),pe)),Fr(pe),Pr(pe,se,Oe,ve)}const Ee=h(),He=Ee===null||Ee.foreign?null:Ee;for(const pe of ie){const se=pe.nodes.marquee;if(se===null)continue;const be=He===null?null:ue(He.range,pe),ye=be!==null&&(pe.xSeamTrail&&be.left>=pe.clampWidth&&be.left<pe.clampWidth+br||pe.xSeamLead&&be.left+be.width<=0&&be.left+be.width>-br||pe.ySeamTrail&&be.top>=pe.clampHeight&&be.top<pe.clampHeight+br||pe.ySeamLead&&be.top+be.height<=0&&be.top+be.height>-br)?null:be;if(ye===null)se.style.display="none";else{se.style.display="block",se.style.transform=`translate(${ye.left}px, ${ye.top}px)`,se.style.width=`${ye.width}px`,se.style.height=`${ye.height}px`;const ce=Gr(ye.top),Te=Gr(ye.left),Qe=Gr(pe.cells.clampHeight-(ye.top+ye.height)),Ue=Gr(pe.cells.clampWidth-(ye.left+ye.width)),it=`${ce} ${Ue} ${Qe} ${Te}`;it!==se.dataset.aqspOutsetSig&&(se.dataset.aqspOutsetSig=it,se.style.setProperty("--aqsp-clip-outset-top",ce),se.style.setProperty("--aqsp-clip-outset-right",Ue),se.style.setProperty("--aqsp-clip-outset-bottom",Qe),se.style.setProperty("--aqsp-clip-outset-left",Te))}const ge=ye===null?null:He?.kind??null,Je=se.dataset.aqspClipKindLast??null;ge!==Je&&(ge===null?(delete se.dataset.aqspClipKindLast,se.removeAttribute("data-aqsp-clip-kind")):(se.dataset.aqspClipKindLast=ge,se.setAttribute("data-aqsp-clip-kind",ge)))}Vt.current!==null&&mn(Vt.current,P,Z,Mr.current),d.current!==null&&er(d.current,P,Z),k.current!==null&&Tn(k.current,P,Z);const fe=z.current;if(fe!==null&&!b()){const{width:pe,height:se}=D.getViewportSize(),be=J.ranges[J.ranges.length-1];if(!(J.ranges.length===1&&!hn.current&&!m())||se<=0||pe<=0)fe.style.display="none";else{const ge=D.getFrozenSize(),Je={scroll:Z,frozenCount:ge.cols,trailingCount:ge.trailingCols,extent:pe},ce={scroll:P,frozenCount:ge.rows,trailingCount:ge.trailingRows,extent:se},Te=be.endCol<ge.cols,Qe=be.endRow<ge.rows,Ue=be.endCol>=t.count-ge.trailingCols,it=be.endRow>=e.count-ge.trailingRows,ke=En(t,be.endCol,Je)+t.sizeOf(be.endCol),ct=On(e,be.endRow,ce)+e.sizeOf(be.endRow),We=Te||Ue?0:ge.width,Be=Qe||it?0:ge.height,et=Ue?pe:pe-ge.trailingVisibleWidth,gn=it?se:se-ge.trailingVisibleHeight;ct<=Be||ct>gn||ke<=We||ke>et?fe.style.display="none":(fe.style.display="block",fe.style.transform=`translate(${ke-Ii+1}px, ${ct-Ii+1}px)`)}}const Le=r.current;if(Le!==null){const pe=J.active,{width:se,height:be}=D.getViewportSize(),ye=D.getFrozenSize(),ge={scroll:Z,frozenCount:ye.cols,trailingCount:ye.trailingCols,extent:se},Je={scroll:P,frozenCount:ye.rows,trailingCount:ye.trailingRows,extent:be},ce=On(e,pe.row,Je),Te=En(t,pe.col,ge),Qe=be>0?Math.min(Math.max(ce,0),Math.max(0,be-1)):0,Ue=se>0?Math.min(Math.max(Te,0),Math.max(0,se-1)):0;Le.style.top=`${Qe}px`,Le.style.left=`${Ue}px`,hn.current?(Le.style.width=`${t.sizeOf(pe.col)}px`,Le.style.height=`${e.sizeOf(pe.row)}px`,Le.style.paddingTop=`${Km(e.sizeOf(pe.row),L===void 0?qt:L.current)}px`):(Le.style.width="1px",Le.style.height="1px",Le.style.paddingTop="0px");const it=pe.col>=ye.cols&&Te<ye.width,ke=pe.row>=ye.rows&&ce<ye.height,ct=ye.trailingWidth>0&&pe.col<t.count-ye.trailingCols&&Te+t.sizeOf(pe.col)>se-ye.trailingVisibleWidth,We=ye.trailingHeight>0&&pe.row<e.count-ye.trailingRows&&ce+e.sizeOf(pe.row)>be-ye.trailingVisibleHeight,Be=hn.current&&ce===Qe&&Te===Ue&&!it&&!ke&&!ct&&!We;Be!==zr.current&&(zr.current=Be,Be?Le.setAttribute("data-aqsp-editing",""):Le.removeAttribute("data-aqsp-editing"))}$n(D,P,Z)},[n,ue,re,Ut,mn,er,Tn,h,o,m,b,z,r,e,t,xe,Pr,Fr,L,$n]),nr=i.useCallback((S,D)=>{Vt.current=S,Mr.current=D;const V=S===null?"add":D;for(const J of re(0,0)){const ie=J.nodes.dragRect;if(ie===null)continue;const ve=ie.dataset.aqspDragModeLast??"add";V!==ve&&(ie.dataset.aqspDragModeLast=V,V==="add"?ie.removeAttribute("data-aqsp-drag-mode"):ie.setAttribute("data-aqsp-drag-mode",V))}const P=n.current;if(S===null||P===null){for(const J of re(0,0))J.nodes.dragRect!==null&&(J.nodes.dragRect.style.display="none"),xn(J,null,null);return}const Z=P.getScrollPosition();mn(S,Math.max(0,Z.y),Math.max(0,Z.x),D)},[n,mn,re,xn]),rr=i.useCallback(S=>{k.current=S;const D=n.current;if(D===null){for(const P of re(0,0))P.nodes.fillPreview!==null&&(P.nodes.fillPreview.style.display="none");return}const V=D.getScrollPosition();Tn(S,Math.max(0,V.y),Math.max(0,V.x))},[n,Tn,re]),Gt=i.useCallback(S=>{d.current=S;const D=n.current;if(D===null){for(const P of re(0,0))P.nodes.resizeGuide!==null&&(P.nodes.resizeGuide.style.display="none");return}const V=D.getScrollPosition();er(S,Math.max(0,V.y),Math.max(0,V.x))},[n,er,re]);i.useLayoutEffect(()=>{const S=y.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=Xt,u.current=nr,N.current=rr,W.current=Gt,()=>{c.current=null,u.current=null,N.current=null,W.current=null})),i.useEffect(()=>{Xt()},[Xt,s,Ne,je,lt,pt]),i.useEffect(()=>{const S=r.current;if(S===null)return;const D=V=>I(V);return S.addEventListener("mousedown",D),()=>S.removeEventListener("mousedown",D)},[r,I]);const Ke=Ne>0||lt>0?[...Ne>0?[{k:"f",style:{left:0,width:st}}]:[],{k:"s",style:{left:st,right:ft}},...lt>0?[{k:"t",style:{right:0,width:ft}}]:[]]:[{k:"m",style:{left:0,right:0}}],xo=je>0||pt>0?[...je>0?[{k:"f",style:{top:0,height:fn}}]:[],{k:"s",style:{top:fn,bottom:pn}},...pt>0?[{k:"t",style:{bottom:0,height:pn}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Ln=S=>S==="m"?0:S==="s"?1:S==="t"?2:3,ht=Ke.flatMap(S=>xo.map(D=>({xk:S.k,yk:D.k,key:`${S.k}${D.k}`,style:{...S.style,...D.style}}))).sort((S,D)=>Ln(S.key[0])+Ln(S.key[1])-(Ln(D.key[0])+Ln(D.key[1]))),Fe=S=>S==="mm"?{"data-aqsp-overlay-main":""}:S==="fm"?{"data-aqsp-overlay-frozen":""}:S==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:y,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:De.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:De.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[ht.map(({xk:S,yk:D,key:V,style:P})=>{const Z=we[V];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":V,...Fe(V),style:P,ref:Z.container,children:[f?K.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:Z.bandClip}):null,S==="s"&&Ne>0?K.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:Z.dividerXLeading}):null,S==="s"&&lt>0?K.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:Z.dividerXTrailing}):null,D==="s"&&je>0?K.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:Z.dividerYLeading}):null,D==="s"&&pt>0?K.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:Z.dividerYTrailing}):null,f?K.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:Z.frame}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:Z.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:Z.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:Z.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:Z.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:Z.resizeGuide})]},V)}),K.jsx("textarea",{ref:oe,className:"aqsp-sink","aria-label":F,"aria-readonly":j?"true":void 0,"aria-keyshortcuts":$,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),q?K.jsx("div",{ref:z,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ha=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=b=>{l.current=!0;try{b()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=b=>{if(b.key==="Escape"){b.preventDefault(),c(e.close);return}b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&!b.altKey&&!b.shiftKey&&(b.preventDefault(),u())},m=b=>{l.current||b.relatedTarget instanceof Node&&b.currentTarget.contains(b.relatedTarget)||e.rejected||c(e.close)};return K.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:[K.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[Pe(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Pe(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(b=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":b.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:b.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:b.createdAt,children:b.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:b.text})]},b.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Pe(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:b=>r(b.currentTarget.value),onKeyDown:h}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:Pe(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Pe(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Ba=({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(),u=i.useRef(!1),h=o.trim()===""?null:an(o),m=o.trim()!==""&&h===null,b=q=>{u.current=!0;try{q()}finally{u.current=!1}},N=()=>{l||m||b(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},W=q=>{if(q.key==="Escape"){q.preventDefault(),b(e.close);return}q.key==="Enter"&&!q.altKey&&!q.shiftKey&&(q.preventDefault(),N())},z=q=>{u.current||q.relatedTarget instanceof Node&&q.currentTarget.contains(q.relatedTarget)||e.rejected||b(e.close)};return K.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:z,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Pe(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Pe(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:q=>r(q.currentTarget.value),onKeyDown:W})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Pe(t,"linkUrlField")}),K.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:q=>s(q.currentTarget.value),onKeyDown:W})]}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:N,children:Pe(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:Pe(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Pe(t,"popoverClose"),onClick:()=>b(e.close),children:"×"})]})]})},ji=500,Wa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),u=i.useMemo(()=>{const Y=n.toLowerCase();return e.current.filter(A=>A.toLowerCase().startsWith(Y))},[e.current,n]),h=i.useMemo(()=>u.length>ji?u.slice(0,ji):u,[u]),m=u.length-h.length,b=h.length===0?-1:Math.min(o,h.length-1),N=Y=>{c.current=!0;try{Y()}finally{c.current=!1}},W=()=>{b<0||N(()=>e.commit(h[b]))},z=Y=>{if(Y.key==="Escape"){Y.preventDefault(),N(e.close);return}if(Y.key==="Enter"){Y.preventDefault(),W();return}if(Y.key==="ArrowDown"){Y.preventDefault(),s(b+1);return}Y.key==="ArrowUp"&&(Y.preventDefault(),s(Math.max(b-1,0)))},q=Y=>{c.current||Y.relatedTarget instanceof Node&&Y.currentTarget.contains(Y.relatedTarget)||N(e.close)},U=Y=>`${l}-${Y}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:q,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Pe(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":b<0?void 0:U(b),value:n,onChange:Y=>{r(Y.currentTarget.value),s(0)},onKeyDown:z}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Pe(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Pe(t,"listEmpty")}):h.map((Y,A)=>K.jsx("div",{className:"aqsp-popover-option",id:U(A),role:"option",tabIndex:-1,"aria-selected":A===b,"data-aqsp-list-option":Y,onPointerDown:T=>T.preventDefault(),onClick:()=>N(()=>e.commit(Y)),children:Y},U(A))),m>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Pe(t,"listMore",m)}):null]})]})},Va=({ctx:e,labels:t})=>K.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),K.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Pe(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ya=({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(),u=i.useRef(!1),h=z=>{u.current=!0;try{z()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},b=()=>{r!==n&&!s?m():h(e.close)},N=z=>{if(z.key==="Escape"){z.preventDefault(),e.rejected?h(e.close):b();return}z.key==="Enter"&&(z.ctrlKey||z.metaKey)&&!z.altKey&&!z.shiftKey&&(z.preventDefault(),m())},W=z=>{u.current||z.relatedTarget instanceof Node&&z.currentTarget.contains(z.relatedTarget)||e.rejected||b()};return K.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:W,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:Pe(t,"noteTitle")}),K.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:z=>o(z.currentTarget.value),onKeyDown:N}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Pe(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:Pe(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Pe(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},Ka=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Pt=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")}),Hi=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Ua=Object.freeze({all:Pt(Hi),values:Pt(["text"]),formats:Pt(["format","borders","cf"]),formulas:Pt(["text","formula"]),noBorders:Pt(Hi.filter(e=>e!=="borders")),columnWidths:Pt(["sizes"]),validation:Pt(["validation"]),conditionalFormats:Pt(["cf"]),commentsAndNotes:Pt(["note","comments"])}),Bi=Object.freeze({mode:"all"}),xs=Object.freeze({t:""}),Wi=Object.freeze({row:1<<30,col:1<<30}),Jm=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Qm=e=>e.t===""&&e.f===void 0,eg=e=>e.length>1&&e.startsWith("="),tg=(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}},Vi=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,ng=(e,t,n,r)=>{const o=eg(e),s=e===""?"0":Ct(e);if(!o&&s===null)return null;const l=Jm[n];if(t.f!==void 0){const h=Tr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Vi(Number(s));const c=Ct(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Vi(tg(Number(s),u,n))},Yi=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),rg=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:Yi(e.start),end:Yi(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}}}},og=e=>{const t=Tr(e,Wi),n=xr(t);let r="",o=0,s=!1;for(const l of n){const c=rg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${on(c)}`,o=l.end,s=!0)}return s?ko(`${r}${t.slice(o)}`,Wi):e},sg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return xs;const o=r[n];return o===void 0?xs:o},lg=e=>{const{rows:t,cols:n}=e,r=Uc(og);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 u=[];for(let h=0;h<t;h+=1){const m=sg(e,h,c);let b=m;if(m.f!==void 0){const N=r(m.f);b=N===m.f?m:{...m,f:N}}(b!==m||m===xs)&&(o=!1),u.push(b)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.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,cg=(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},Ki=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)ig(m,t)?(h.push(cg(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h: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},Ui=new WeakMap,Xa=e=>{const t=Ui.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>At(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:At({...s,borders:void 0})),o={canonical:n,borderless:r};return Ui.set(e,o),o},bo=(e,t)=>t===void 0?void 0:e[t],ag=(e,t,n,r)=>{const o=Xa(e);if(n){const h=bo(o.canonical,t.fmt);return h===void 0?null:h}const s=bo(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 u=At(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},ug=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?ng(n.readText(),o,r,n):o.f===void 0?o.t:Tr(o.f,n)},Xi=(e,t,n,r,o)=>{const s=Ua[r.mode];if(r.skipBlanks===!0&&Qm(e))return null;const l={};let c=!1;if(s.text){const u=ug(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=ag(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=bo(Xa(t).canonical,e.fmt);u!==void 0&&(l.format=u,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 u=bo(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},Gi=(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}}),dg=["text/html","text/plain"],fg=(e,t,n)=>{if(e===0||t===0)return 0;const r=bt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},pg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,hg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,mg=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}}},Zi=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}},wg=(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},Cg=(e,t,n,r,o)=>{const s=Jn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=ko(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}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:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=Qn(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},Ga=(e,t)=>{const n=Mc(),r=hf(),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(Cg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:wg(e.getConditionalFormats(),t)}},Ji=e=>e.kind==="cut"?{...e.payload,...Ga(e.sourceAdapter,e.range)}:e.payload,bg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:Fs(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),yg=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=an(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Rg=(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},vg=(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 de({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Sg=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(A=>{const T=n.current;if(T===null||A==="format"||A==="annotate")return;const F=r.current;F==="own"||F==="foreign"&&T.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const A=n.current;if(A===null)return;if(A.kind==="copy"){o();return}const T=t.current;T.repaintOverlay(),T.onClipChange?.({kind:"cut",range:A.range,foreign:A.sourceAdapter!==T.adapter})},[o]),c=i.useCallback((A,T,F)=>{const j=t.current;n.current={kind:A,range:T,clipId:F.clipId,sourceAdapter:j.adapter,payload:F},j.repaintOverlay(),j.onClipChange?.({kind:A,range:T,foreign:!1})},[]),u=i.useCallback(A=>{const T=t.current,F=T.adapter,j=bt(A),$={v:1,rows:j.rows,cols:j.cols,clipId:Fs(),...Ga(F,A),wholeRows:zc(A,F.colCount),wholeCols:Nc(A,F.rowCount)};if(T.resize!==void 0){if($.wholeCols){const I=[];for(let L=A.startCol;L<=A.endCol;L+=1)I.push(Math.min(T.resize.colAxis.sizeOf(L),cn));$.colWidths=I}if($.wholeRows){const I=[];for(let L=A.startRow;L<=A.endRow;L+=1)I.push(Math.min(T.resize.rowAxis.sizeOf(L),cn));$.rowHeights=I}}return $},[]),h=i.useCallback((A,T)=>{const F=t.current,j=F.getSelection(),$=j.ranges[j.ranges.length-1],I=wt([$]);if(I>F.maxOperationCells)return A.preventDefault(),F.onOperationRejected?.(T,I,"limit"),null;if(T==="cut"&&Cr(F.adapter,$))return A.preventDefault(),F.rejectReadOnly({kind:"operation",op:"cut",cellCount:I}),null;j.ranges.length>1&&F.onCopyMultiRange?.();const L=u($),g=vc(L),p=Zi(A);return p!==null&&(p.setData("text/plain",Ht.serializeClipboardTsv(L.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",fa(L,g)),p.setData(mo,g)),A.preventDefault(),{payload:L,range:$}},[u]),m=i.useCallback((A,T)=>t.current.commitPaste(A,T)!==null,[]),b=i.useCallback((A,T,F)=>{const j=t.current;if(!F.sizes||j.resize===void 0)return;const{rowAxis:$,colAxis:I,resizeTracks:L}=j.resize,g=(p,C,v)=>{const E=Ds(C,v,null,{maxOperationCells:j.maxOperationCells,rowHiddenLimit:$s,axisKind:p});if(!E.ok){j.onOperationRejected?.("resize",E.count,E.reason);return}L(p,E.entries)};if(A.colWidths!==void 0){const p=[];for(let C=T.startCol;C<=T.endCol;C+=1)p.push({index:C,size:A.colWidths[(C-T.startCol)%A.cols]});g("col",I,p)}if(A.rowHeights!==void 0){const p=[];for(let C=T.startRow;C<=T.endRow;C+=1)p.push({index:C,size:A.rowHeights[(C-T.startRow)%A.rows]});g("row",$,p)}},[]),N=i.useCallback((A,T)=>{const F=t.current,j=F.adapter,$=A.payload,I={row:T.startRow,col:T.startCol},L=$.rows*$.cols+wt([A.range]);if(L>F.maxOperationCells)return F.onOperationRejected?.("paste",L,"limit"),"rejected";if(I.row+$.rows>j.rowCount||I.col+$.cols>j.colCount||A.range.endRow>=A.sourceAdapter.rowCount||A.range.endCol>=A.sourceAdapter.colCount)return F.onOperationRejected?.("paste",L,"bounds"),"rejected";const g=Es({rows:$.rows,cols:$.cols},de(I,I),I,j.rowCount,j.colCount);if(g!==null&&Cr(j,g))return F.rejectReadOnly({kind:"operation",op:"paste",cellCount:$.rows*$.cols}),"rejected";if(Cr(A.sourceAdapter,A.range))return F.rejectReadOnly({kind:"operation",op:"cut",cellCount:wt([A.range])}),"rejected";const p=Ji(A),C=po(j),v=Ki(p,C),E={row:0,col:0,readText:()=>Jn(j,E.row,E.col).text,readFormat:()=>j.getCellFormat===void 0?void 0:j.getCellFormat(E.row,E.col)},{edits:R,tiles:y}=hi(v.cells,de(I,I),I,j.rowCount,j.colCount,(k,d,x)=>(E.row=A.range.startRow+(d-I.row),E.col=A.range.startCol+(x-I.col),Xi(k,v,E,Bi,C))),a=po(A.sourceAdapter),f=[];if(nn([A.range],k=>{f.push(Rg(k.row,k.col,a))}),A.sourceAdapter===j){if(!m([...f,...R],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const k=F.commitPaste(R,{sameSheet:!1,conditionalFormats:Gi(v.conditionalFormats,y)});if(k===null)return"rejected";try{A.sourceAdapter.applyEdits(f,{transaction:k,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){F.onEditRejected?.(d,{source:"paste"})}}return F.setSelection({ranges:[de(I,{row:I.row+p.rows-1,col:I.col+p.cols-1})],anchor:I,active:I}),"applied"},[m]),W=i.useCallback((A,T,F)=>{const j=t.current,$=j.adapter,I=G=>(j.onClipboardUnavailable?.(G),"rejected"),L=Ec(A,T);if(L==="none")return T==="menu"?I("empty"):"empty";const g=j.getSelection(),p=g.ranges[g.ranges.length-1],C=F.transpose===!0,v=(G,X)=>{const ee=fg(C?X:G,C?G:X,p);return ee>j.maxOperationCells?(j.onOperationRejected?.("paste",ee,"limit"),!0):!1};let E,R=null;if(L==="aqsp"){const G=Id(A,T);if(G===null)return I("unreadable");const X=n.current;if(X!==null&&G.clipId===X.clipId&&(R=X),R!==null&&R.kind==="cut"&&pg(F))return N(R,p);if(v(G.rows,G.cols))return"rejected";if(R!==null){if(R.kind==="cut"&&(R.range.endRow>=R.sourceAdapter.rowCount||R.range.endCol>=R.sourceAdapter.colCount))return j.onOperationRejected?.("paste",R.payload.rows*R.payload.cols,"bounds"),"rejected";E=Ji(R)}else{const ee=jd(A,T);if(ee===null)return I("unreadable");if(v(ee.rows,ee.cols))return"rejected";E=yg(ee)}}else if(L==="tsv"){const G=A.getData("text/plain"),X=Ht.measureTsv(G);if(v(X.rows,X.cols))return"rejected";E=bg(Ht.parseTsv(G))}else{const G=A.getData("text/html"),X=pf(G);if(X.cols===0&&X.rows>j.maxOperationCells)return j.onOperationRejected?.("paste",X.rows,"limit"),"rejected";if(v(X.rows,X.cols))return"rejected";const ee=ga(G,L,j.formats===void 0?{}:{currency:j.formats.currency,locale:j.formats.locale},j.maxOperationCells);if(ee.outcome==="none")return I("unreadable");if(ee.outcome==="limit")return j.onOperationRejected?.("paste",ee.cells,"limit"),"rejected";if(v(ee.payload.rows,ee.payload.cols))return"rejected";E=ee.payload}const y=po($),a=Ki(C?lg(E):E,y),f=Ua[F.mode];if(hg(f)){const G=Es({rows:a.rows,cols:a.cols},p,g.active,$.rowCount,$.colCount);if(G!==null&&Cr($,G))return j.rejectReadOnly({kind:"operation",op:"paste",cellCount:wt([G])}),"rejected"}const k={row:0,col:0,readText:()=>Jn($,k.row,k.col).text,readFormat:()=>$.getCellFormat===void 0?void 0:$.getCellFormat(k.row,k.col)},{edits:d,tiles:x}=hi(a.cells,p,g.active,$.rowCount,$.colCount,(G,X,ee)=>(k.row=X,k.col=ee,Xi(G,a,k,F,y))),O=vg(x,a.rows,a.cols,$.rowCount,$.colCount);if(O===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let G=0;for(const ee of a.conditionalFormats)G+=ee.ranges.length;const X=x.length*G;if(X>j.maxOperationCells)return j.onOperationRejected?.("paste",X,"limit"),"rejected"}const M=f.cf?Gi(a.conditionalFormats,x):[];if(d.length===0&&M.length===0)return b(a,O,f),"empty";r.current=R===null?"foreign":"own";let H=!1;try{H=m(d,{sameSheet:R!==null&&R.sourceAdapter===$,conditionalFormats:M})}finally{r.current="none"}if(!H)return"rejected";b(a,O,f);const B={row:O.startRow,col:O.startCol};return j.setSelection({ranges:[O],anchor:B,active:B}),"applied"},[N,m,b]),z=i.useCallback(async A=>{const T=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),F=navigator;if(F.clipboard===void 0)return T("insecure-origin");let j;try{j=await F.clipboard.read({unsanitized:["text/html"]})}catch{return T("permission-denied")}if(j.length===0)return T("empty");const $=j[0],I=Array.from($.types),L=new Map;try{for(const C of dg)I.includes(C)&&L.set(C,await(await $.getType(C)).text())}catch{return T("unreadable")}const g={types:I,getData:C=>{const v=L.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":W(g,"menu",A)},[W]),q=i.useCallback(async A=>{const T=await z(A);return t.current.onPasteResolved?.(T,"menu"),T},[z]),{enabled:U,sinkRef:Y}=e;return i.useEffect(()=>{const A=Y.current;if(!U||A===null)return;const T=I=>t.current.isDragging()?(I.preventDefault(),!0):!1,F=I=>{const L=t.current;if(T(I)||L.isEditing())return;const g=h(I,"copy");g!==null&&c("copy",g.range,g.payload)},j=I=>{const L=t.current;if(T(I)||L.isEditing())return;const g=h(I,"cut");g!==null&&c("cut",g.range,g.payload)},$=I=>{const L=t.current;if(T(I)||L.isEditing())return;I.preventDefault();let g=Bi;const p=L.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(g=p.current,p.current=null);const C=Zi(I);if(C===null)return;const v=W(mg(C),"event",g);L.onPasteResolved?.(v,"event")};return A.addEventListener("copy",F),A.addEventListener("cut",j),A.addEventListener("paste",$),()=>{A.removeEventListener("copy",F),A.removeEventListener("cut",j),A.removeEventListener("paste",$)}},[U,Y,h,c,W]),i.useMemo(()=>({getClip:()=>{const A=n.current;return A===null?null:{kind:A.kind,range:A.range,foreign:A.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:q}),[o,s,l,q])},Za=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)}`)},Ja=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}},Qi=(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}`}`},Qa=(e,t)=>{let n;if(e.exponent===null)n=Qi(e.negative,e.digits,e.point+t);else{const r=Qi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Ct(n)===null?null:n},kg=(e,t)=>{Za(t);const n=Ct(e);return n===null?null:Qa(Ja(n),t)},Eg=e=>{const t=Ct(e);if(t!==null){const r=Ja(t);return Qa({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},eu=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)},Og=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},tu=(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 Og(r)?r:null},Ag=(e,t)=>{Za(t);const n=eu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=tu(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},xg=e=>{const t=eu(e),n=tu(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},hr=(e,t,n,r)=>{const o=wt(t);return o>n?(r?.(e,o,"limit"),!1):!0},to={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},no={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:to.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:to.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:to.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:to.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:no.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:no.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:no.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:no.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"}},Tg={down:"fillDown",right:"fillRight",selection:"fillSelection"},$g={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},Sr=e=>e<10?`0${e}`:String(e),Lg=e=>{const t=new Date(e);return`${t.getFullYear()}-${Sr(t.getMonth()+1)}-${Sr(t.getDate())}`},Dg=e=>{const t=new Date(e);return`${Sr(t.getHours())}:${Sr(t.getMinutes())}:${Sr(t.getSeconds())}`},Mg=(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),zg=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Ng=e=>e===void 0||e.borders===void 0?{}:e.borders,Fg={top:1,right:2,bottom:4,left:8},Pg={style:"thin",color:Ms},_g=(e,t)=>{if(e===void 0)return!1;const n=rt(e);return n!==null&&n===rt(t)},qg=(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}}},Ig=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const p=g.getActive();return[de(p,p)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,p=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(g=>{const p=t.current,C=n();if(!hr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:wt(C)}),!1;const v=new Map,E=[],R=p.adapter.getCellFormat;for(const y of C)nn([y],a=>{const f=R===void 0?void 0:R(a.row,a.col),{bucket:k,patch:d}=g(a,y,f);let x=v.get(k);x===void 0&&(x=new Map,v.set(k,x));let O;x.has(f)?O=x.get(f):(O=Ns(f,d),x.set(f,O)),O!==f&&E.push({row:a.row,col:a.col,format:O===void 0?null:O})});return E.length===0?!0:p.commitEdits(E,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:g,state:p}))},[]),c=i.useCallback((g,p=Pg)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=g==="outer"?15:Fg[g];return o((v,E,R)=>{const y=Mg(v,E)&C;return{bucket:y,patch:{borders:{...Ng(R),...zg(y,p)}}}})},[s,o]),u=i.useCallback((g,p,C)=>{const v=Ra(t.current.adapter,g.row,g.col);for(const E of p)C.push(va(v,g,E))},[]),h=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[],E=[],R=[];if(g==="selection"){const a=C.active,f=[];nn(C.ranges,k=>{(k.row!==a.row||k.col!==a.col)&&f.push(k)}),v.push({source:a,targets:f}),E.push(de(a,a));for(const k of C.ranges)R.push(...Oh(k,a))}else for(const a of C.ranges)if(g==="down"){const f=a.startRow===a.endRow;if(f&&a.startRow===0)continue;const k=f?a.startRow-1:a.startRow,d=f?a.startRow:a.startRow+1;E.push(de({row:k,col:a.startCol},{row:k,col:a.endCol})),R.push(de({row:d,col:a.startCol},{row:a.endRow,col:a.endCol}));for(let x=a.startCol;x<=a.endCol;x+=1){const O=[];for(let M=d;M<=a.endRow;M+=1)O.push({row:M,col:x});v.push({source:{row:k,col:x},targets:O})}}else{const f=a.startCol===a.endCol;if(f&&a.startCol===0)continue;const k=f?a.startCol-1:a.startCol,d=f?a.startCol:a.startCol+1;E.push(de({row:a.startRow,col:k},{row:a.endRow,col:k})),R.push(de({row:a.startRow,col:d},{row:a.endRow,col:a.endCol}));for(let x=a.startRow;x<=a.endRow;x+=1){const O=[];for(let M=d;M<=a.endCol;M+=1)O.push({row:x,col:M});v.push({source:{row:x,col:k},targets:O})}}for(const a of v)for(const f of a.targets)if(Ze(p.adapter,f.row,f.col))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:wt(R),gesture:Tg[g],sources:E,targets:R}),!1;const y=[];for(const a of v)u(a.source,a.targets,y);return y.length===0?!0:p.commitEdits(y,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const g=t.current,p=g.getSessionText();if(p===null)return!1;const C=g.getSelection();if(!hr("fill",C.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(Wn(g.adapter,C.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:wt(C.ranges),gesture:"fillSelection",sources:[],targets:C.ranges}),!1;const v=[];let E=!1;return nn(C.ranges,R=>{if(!E){if(!g.validateCommit(R,p).ok){E=!0;return}v.push({row:R.row,col:R.col,text:p})}}),E||g.commitEdits(v,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),b=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:wt(C.ranges)}),!1;const v=[],E=p.adapter;return nn(C.ranges,R=>{const y=E.getCellFormula===void 0?void 0:E.getCellFormula(R.row,R.col),a=y===void 0?g.text(E.getCellText(R.row,R.col)):g.formula(y);a!==null&&v.push({row:R.row,col:R.col,text:a})}),v.length===0?!0:p.commitEdits(v,{source:"calc"})!==null},[]),N=i.useCallback((g,p)=>{const C=t.current,v=g==="row"?C.rowAxis:C.colAxis,E=C.getSelection(),R=g==="row"?Math.floor(C.maxOperationCells/Ls):C.maxOperationCells;let y=0;for(const x of E.ranges)y+=g==="row"?x.endRow-x.startRow+1:x.endCol-x.startCol+1;if(y>R)return C.onOperationRejected?.("resize",y,"limit"),!1;const a=new Set,f=[],k=p?0:g==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const x of E.ranges){const O=g==="row"?x.startRow:x.startCol,M=g==="row"?x.endRow:x.endCol;for(let H=O;H<=M;H+=1){if(a.has(H))continue;a.add(H),v.sizeOf(H)===0!==p&&f.push({index:H,size:k})}}const d=Ds(v,f,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:$s,axisKind:g});return d.ok?(d.entries.length>0&&C.resizeTracks(g,d.entries),!0):(C.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),W=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const p=g.getActive();return Qn(g.adapter.getCellHyperlink(p.row,p.col))},[]),z=i.useCallback(g=>{const p=t.current,C=p.adapter,v=ec[g],E=C.getCellFormat!==void 0,R=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(v.kind){case"resize":return p.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return E;case"value":return E&&(v.value!=="currency"||p.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&&(p.onHyperlinkOpen!==void 0?W()!==void 0:R("link"));case"paste":return v.options.mode==="formats"?E:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[W]),q=i.useCallback(g=>{const p=t.current,C=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=p.getActive();if(!Ze(p.adapter,v.row,v.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let E;if(C==="link")E=W()!==void 0;else if(C==="note"){const R=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(v.row,v.col);E=R!==void 0&&R!==""}else{const R=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(v.row,v.col);E=R!==void 0&&R.length>0}return E?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[W]),U=i.useCallback((g,p,C)=>{const v=t.current,E=v.trackResize;if(E===void 0)return!1;const R=v.getActive(),y=p==="col"?R.col:R.row,a=C==="fit"?E.autofitColumn(y):E.stepTrack(p,y,C),f=(p==="col"?v.colAxis:v.rowAxis).sizeOf(y);return a&&f>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:g,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),Y=i.useCallback(g=>{const p=t.current;if(!z(g))return!1;const C=ec[g];if(!q(C))return!1;const v=p.isEditing();if(v&&!Co.has(g)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const E=r(),R=E!==void 0&&E[C.key]===!0;return s({[C.key]:R?null:!0})?(l(g,!R),!0):!1}case"patch":return s(C.patch)?(l(g,null),!0):!1;case"clear":return s($g)?(l(g,null),!0):!1;case"value":return s({value:qg(C.value,p.formats)})?(l(g,null),!0):!1;case"borders":return c(C.preset)?(l(g,null),!0):!1;case"color":{const E=C.key==="background"?p.colors.fill:p.colors.font,R=C.preset!==null?C.preset:C.custom!==null&&C.custom<E.length?E[C.custom]:void 0;if(R===void 0)return!1;const y=r(),a=_g(y===void 0?void 0:y[C.key],R);return s({[C.key]:a?null:R})?(l(g,!a),!0):!1}case"calc":return b({text:E=>kg(E,C.exponent),formula:E=>Ag(E,C.exponent)});case"sign":return b({text:Eg,formula:xg});case"fill":return v&&C.direction==="selection"?m():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const E=W();return E===void 0?!1:(p.onHyperlinkOpen(E,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const E=C.unit==="date"?Lg(p.now()):Dg(p.now());if(v)return p.insertAtCaret(E),!0;const R=p.getActive();return Ze(p.adapter,R.row,R.col)?(p.rejectReadOnly({kind:"edit",cell:R,editSession:"none"}),!1):p.validateCommit(R,E).ok?p.commitEdits([{row:R.row,col:R.col,text:E}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return U(g,C.axis,C.step);default:{const E=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...E,row:!E.row}),!0;case"column":return p.setHighlight({...E,column:!E.column}),!0;case"both":{const R=E.row&&E.column;return p.setHighlight({...E,row:!R,column:!R}),!0}default:return p.setHighlight({...E,intersection:!E.intersection}),!0}}}},[z,q,W,r,s,l,c,b,h,m,N,U]),A=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),T=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=g===null?null:an(g);if(g!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!A())return!1;const v=p.getActive();return Ze(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[A]),F=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!A())return!1;const C=p.getActive();return Ze(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:g}],{source:"annotate"})!==null},[A]),j=i.useCallback(g=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!A())return!1;const v=p.getActive();if(Ze(p.adapter,v.row,v.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const E=C(v.row,v.col),R=E===void 0?[g]:[...E,g];return p.commitEdits([{row:v.row,col:v.col,comments:R}],{source:"annotate"})!==null},[A]),$=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!A())return!1;const C=p.getSelection().ranges;if(!hr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:wt(C)}),!1;const v=[];return nn(C,E=>{v.push({row:E.row,col:E.col,validation:g})}),p.commitEdits(v,{source:"annotate"})!==null},[A]),I=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),L=i.useCallback((g,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,p)},[c]);return i.useMemo(()=>({executeCommand:Y,applyFormat:I,setBorders:L,setHyperlink:T,setNote:F,addComment:j,setValidation:$,isCommandAvailable:z}),[Y,I,L,T,F,j,$,z])},ro="data-aqsp-pointing",jg=(e,t)=>{const n=Qc(e,t);return n!==null&&"insertAt"in n},Hg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Bg=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),u=i.useRef(null),h=i.useRef(qt),m=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=Qc(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),b=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=m()!==null;a!==y.hasAttribute(ro)&&(a?y.setAttribute(ro,""):y.removeAttribute(ro))},[m]),N=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const k=f.resolveEditPaint(a),d=k===null?qt:k;d!==qt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),W=i.useCallback(y=>{Hg(y,Object.keys(h.current.style)),h.current=qt;const a=t.current.editPaintRef;a!==void 0&&(a.current=qt)},[]),z=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const k=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),W(d),d.removeAttribute(ro)),o(!1)};if(y.commit){const d=a.sinkRef.current,x=d===null?"":d.value,O=Jn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
13
- `),M=x===O;let H;if(M)H=!0;else if(Ze(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),H=!1;else{const B={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};H=(a.validateCommit===void 0||a.validateCommit(f.cell,x).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:x}],B)!==null}if(!H)return y.onReject==="discard"&&(k(),a.rearmSink()),!1}return k(),y.rearm&&a.rearmSink(),!0},[W]),q=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const k=f.sinkRef.current;if(k===null)return;const d=f.getActive();if(Ze(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:O,isFormula:M}=Jn(f.adapter,d.row,d.col);k.value=O;const H=a===void 0||M?O.length:Math.min(a,O.length);k.setSelectionRange(H,H)}else k.value="";const x=f.resolveEditAlign(d);x!==null&&(k.style.textAlign=x),N(k,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[N]),U=i.useCallback(()=>{z({rearm:!0,commit:!1})},[z]),Y=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return z({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return z({rearm:!0,commit:!0,onReject:"keep"})},[z]),A=i.useCallback(()=>m()!==null,[m]),T=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,b(),!0),[b]),F=i.useCallback(()=>{const y=m(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=Jc(y.sink.value,y.sink.selectionStart);if(f===null)return null;const k=f.token,d=u.current;switch(k.kind){case"cell":{const x={row:k.row,col:k.col};return u.current=x,{origin:x,cursor:x,axis:"cells"}}case"range":{const x=d!==null&&(d.row===k.start.row||d.row===k.end.row)&&(d.col===k.start.col||d.col===k.end.col)?{row:d.row,col:d.col}:{row:k.start.row,col:k.start.col};return u.current=x,{origin:x,cursor:{row:x.row===k.start.row?k.end.row:k.start.row,col:x.col===k.start.col?k.end.col:k.start.col},axis:"cells"}}case"column":{const x=d!==null&&(d.col===k.start.col||d.col===k.end.col)?d.col:k.start.col,O={row:a.cell.row,col:x};return u.current=O,{origin:O,cursor:{row:a.cell.row,col:x===k.start.col?k.end.col:k.start.col},axis:"columns"}}case"row":{const x=d!==null&&(d.row===k.start.row||d.row===k.end.row)?d.row:k.start.row,O={row:x,col:a.cell.col};return u.current=O,{origin:O,cursor:{row:x===k.start.row?k.end.row:k.start.row,col:a.cell.col},axis:"rows"}}}},[m]),j=i.useCallback((y,a)=>{const f=m();if(f===null)return;const k=Kf(y,a),{sink:d}=f,[x,O]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],M=d.value;d.value=`${M.slice(0,x)}${k}${M.slice(O)}`;const H=x+k.length;d.setSelectionRange(H,H),"row"in y&&(u.current={row:y.row,col:y.col}),b()},[m,b]),$=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),I=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,b())},[b]),L=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=rp(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),b(),!0)},[b]),g=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,k=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(k)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,b()},[b]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(W(f),N(f,a.cell),y.repaintOverlay?.())},[W,N]),{enabled:E,sinkRef:R}=e;return i.useEffect(()=>{const y=R.current;if(!E||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},k=O=>{const M=t.current;if(l.current||n.current===null)return;const H=M.rootRef.current,B=O.relatedTarget;H!==null&&B instanceof Node&&H.contains(B)||z({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const O=t.current;u.current=null,O.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&jg(y.value,y.selectionStart)&&(c.current=!0),b()},x=()=>{n.current!==null&&b()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",k),y.addEventListener("input",d),document.addEventListener("selectionchange",x),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",k),y.removeEventListener("input",d),document.removeEventListener("selectionchange",x)}},[E,R,z,b]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Y,cancelEdit:U,startEdit:q,getPointing:A,togglePointingArm:T,getReferenceCursor:F,insertReference:j,captureSink:$,restoreSink:I,cycleAnchorAtCaret:L,insertAtCaret:g,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[Y,U,q,A,T,F,j,$,I,L,g,p,C,v,r])},Wg=(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}},Vg=(e,t,n)=>{const{tree:r,initialHidden:o}=Wg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:b}=r.prefixSum(h);return m-b},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),b=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(b+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const b=Math.round(m);r.get(h)===0!=(b===0)&&(s+=b===0?1:-1),r.update(h,b)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},sn=(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)},Un=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:sn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=sn(e,o,1);return r},tc=(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=Vg(e,t,r)),o.current.model},Xn=256,is=256,Yg=2**32,Kg=4096,nu=Object.freeze([]),ru=["background","color","bold","italic","underline","strikethrough"],ou=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},ln=(e,t,n)=>(e.size>=Kg&&e.clear(),e.set(t,n),n),su=e=>(ou(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),lu=(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},Ug=(e,t,n)=>{const r=Math.floor(t/Xn),o=Math.floor(n/is),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Xn,u=o*is,h=[];for(const m of e.rules)lu(m.ranges,c,c+Xn-1,u,u+is-1)&&h.push(m);return ln(e.buckets,s,h.length===0?nu:h)},Xg=(e,t,n)=>{const r=Math.floor(t/Xn),o=r*Yg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Ug(e,t,n),c=r*Xn,u=[];for(const h of l)lu(h.ranges,c,c+Xn-1,n,n)&&u.push(h);return ln(e.columns,o,u.length===0?nu:u)},Gg=(e,t)=>{for(const n of e)if(un(n,t))return!0;return!1},Us=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),oo=(e,t)=>e<t?-1:e>t?1:0,nc=(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}},rc=new WeakMap,Ts=e=>e===null?null:Number(e),Zg=e=>{const t=rc.get(e);if(t!==void 0)return t;const n=e.b,r={a:Ts(Ct(e.a)),b:n===void 0?null:Ts(Ct(n))};return rc.set(e,r),r},iu=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:ln(e.numbers,r,Ts(Ct(n())))},Jg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Zg(e),l=iu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return nc(e.op,oo(l,s.a),c===null?null:oo(l,c));const u=n(),h=e.b;return nc(e.op,oo(u,e.a),h===void 0?null:oo(u,h))},Qg=(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}},cs=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]},so=e=>e.toString(16).padStart(2,"0"),as=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${so(r(0))}${so(r(1))}${so(r(2))}`,s=r(3);return s===255?o:`${o}${so(s)}`},us=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),ew=(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=cs(t.color),u=cs(r.color);const h=n===void 0?void 0:cs(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const b=s;s=l,l=b;const N=c;c=u,u=N}if(n!==void 0&&h!==void 0){const b=n.value===void 0?(s+l)/2:n.value;if(s<b&&b<l)return e<=b?as(c,h,us(e,s,b)):as(h,u,us(e,b,l))}return as(c,u,us(e,s,l))},tw=(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 ln(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return ln(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return ln(r.extrema,e.id,{min:c,max:u})},nw=(e,t,n,r,o,s)=>{const l=iu(s,n,r);if(l===null)return null;const c=tw(e,t,o,s);return c===null?null:ew(l,t.min,t.mid,t.max,c)},rw=(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:ln(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},ow=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Jg(s,t,n,o)?e.style:null;case"text":return Qg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=nw(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return rw(e,s,t,r,o)?e.style:null;default:return null}},oc=(e,t)=>Ns(e,t),sw=(e,t,n)=>{e[t]=n},lw=(e,t)=>{let n=e;for(const r of ru)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),sw(n,r,t[r]));return n},iw=e=>{let t="";for(const n of ru){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},sc=new WeakMap,cw=Object.freeze({}),aw=e=>{const t=e===void 0?cw:e,n=sc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return sc.set(t,r),r},uw=(e,t,n)=>{const r=aw(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=oc(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=iw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=oc(e,t);return l!==void 0&&ln(r.byKey,o,l),l},Xs=(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=Xg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const b of c){if(!Gg(b.ranges,u))continue;const N=ow(b,u,s,e,n);if(N!==null){if(N!==b.style&&(m=!1),h===null)h=N;else{const W=lw(h,N);W!==h&&(m=!1,h=W)}if(b.stopIfTrue===!0)break}}return h===null?l:uw(l,h,m)},lc=new WeakMap,dw=e=>{ou(e,"widthRelevantRules");const t=lc.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 lc.set(e,r),r},fw=({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},pw=i.memo(fw),hw=Object.freeze({left:Object.freeze({justifyContent:yr("left")}),center:Object.freeze({justifyContent:yr("center")}),right:Object.freeze({justifyContent:yr("right")})}),mw=Object.freeze({role:"rowgroup"}),gw=4096,ic=new WeakMap,lo=new Map,ww=(e,t)=>{if(e===null)return hw[t];let n=ic.get(e);n===void 0&&(n={},ic.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:yr(t)},s=JSON.stringify(o);let l=lo.get(s);return l===void 0&&(lo.size>=gw&&lo.clear(),l=Object.freeze(o),lo.set(s,l)),n[t]=l,l},Cw=Us(),bw=(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},yw=(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=fo(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=Xs(e,r===null?null:r.indexRef.current,r===null?Cw:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const b=wa(m,l),N=sn(n,s,1),W=sn(t,o,1),z=kf(m,N===null?void 0:e.getCellFormat(o,N),W===null?void 0:e.getCellFormat(W,s),n.offsetOf(s)===0,t.offsetOf(o)===0);z!==null&&Object.assign(c,z.attrs),c["data-aqsp-align"]=b,u=ww(z,b)}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&&Qn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&Pm(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Rw=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:b,headerRows:N,labelledBy:W,gridLabel:z,readOnly:q,renderCell:U,onScroll:Y,onRangeChange:A,focusSink:T,isEditing:F,requestCommit:j,testId:$,__onCellRender:I,__maxRenderedCells:L,cfIndexRef:g,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:v,overscanRows:E,overscanCols:R,background:y,onRenderTruncated:a,locale:f,scrollLabels:k})=>{const d=i.useRef(null),x=s??d;if(g===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const O=i.useMemo(()=>g===void 0||p===void 0?null:{indexRef:g,memoRef:p},[g,p]),M=i.useCallback(()=>r.get().editVersion,[r]),H=i.useCallback(we=>r.subscribeCoalesced(we),[r]),G=i.useSyncExternalStore(H,M,M)+(l??0),X=i.useCallback(we=>t.sizeOf(we),[t]),ee=i.useCallback(we=>n.sizeOf(we),[n]),ne=i.useCallback((we,Ne)=>e.getCellText(we,Ne),[e]),le=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),re=i.useMemo(()=>({width:De.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Ae=i.useRef({row:-1,col:-1,value:void 0}),ze=i.useCallback((we,Ne)=>{const st=we<N,je={role:st?"columnheader":"gridcell","aria-rowindex":we+1,"aria-colindex":Ne+1,"data-aqsp-cell":"","data-row":we,"data-col":Ne,className:"aqsp-cell",...Ze(e,we,Ne)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...st?{"data-aqsp-header-row":""}:{}},fn=Dh(e,we,Ne),lt=fn===null?je:{...je,...fn},ft=yw(e,t,n,O,we,Ne),pt=Ae.current;return pt.row=we,pt.col=Ne,pt.value=ft===null?void 0:ft.value,ft===null?lt:ft.style===null?{...lt,...ft.attrs}:{...lt,...ft.attrs,style:ft.style}},[e,t,n,O,N]),_e=i.useCallback(we=>({role:"row","aria-rowindex":we+1,"data-aqsp-row":we,"data-aqsp-cells":"",className:"aqsp-row"}),[]),qe=i.useCallback((we,Ne,st)=>{let je=we;return e.getCellFormat!==void 0&&(je=Gn(we,bw(Ae.current,Ne,st))),K.jsx(pw,{row:Ne,col:st,text:we,display:je,renderCell:U,__onCellRender:I})},[G,U,I,e]);return K.jsx("div",{ref:x,className:"aqsp-body","data-aqsp-body":"","data-testid":$?`${$}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":z,"aria-labelledby":W,"aria-readonly":q?"true":void 0,onPointerDownCapture:we=>{if(!(we.target instanceof Element&&we.target.closest("[data-aqsp-cells]")!==null)&&we.pointerType==="mouse"){if(we.button!==0){we.preventDefault();return}if(we.preventDefault(),C?.()===!0){we.stopPropagation(),T();return}if(F()&&!j()){we.stopPropagation(),T();return}T()}},children:K.jsx(ot.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:b,getRowHeight:X,getColWidth:ee,getCell:ne,getCellProps:ze,getRowProps:_e,contentProps:mw,behaviorOptions:le,scrollBarOptions:re,overscanRows:E,overscanCols:R,background:y,onRenderTruncated:a,__maxRenderedCells:L,locale:f,labels:k,callbackThrottleMs:0,onScroll:Y,onRangeChange:A,testId:$,children:qe})})},vw=i.memo(Rw),Vn=6,gt=3,yo=(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:gt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=sn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-Vn,length:gt}),r.push({kind:"unhide",index:s+1,start:c-gt,length:gt})):l>=2*Vn?n.push({kind:"resize",index:s,start:c-Vn,length:Vn}):n.push({kind:"resize",index:s,start:c-gt,length:gt})}return[...n,...r]},cu=(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 u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:gt}),n.push({kind:"resize",index:c,start:h+gt,length:gt})):u>=2*Vn?n.push({kind:"resize",index:c,start:h,length:Vn}):n.push({kind:"resize",index:c,start:h,length:gt})}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-gt,length:gt}),[...n.reverse(),...r]},Sw=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:b,dividerTrailingRef:N})=>{const W=ot.useWheelBridge(o),z=i.useCallback(d=>(s.current=d,W(d)),[s,W]),q=i.useCallback(()=>{const{colStart:d,colEnd:x,colVersion:O}=e.get();return`${d}:${x}:${O}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,q,q);const{colStart:Y,colEnd:A}=e.get(),T=t.count===0?0:t.offsetOf(Math.min(Y,t.count-1));i.useLayoutEffect(()=>{c.current=T,u()},[T,c,u]);const F=d=>h.some(x=>d>=x.startCol&&d<=x.endCol),j=Math.min(Math.max(0,n),t.count),$=Pa(t,j),I=j>0?Un(t,0,j-1):[],L=Math.min(Math.max(0,r),t.count-j),g=qa(t,L),p=t.totalSize()-g,C=L>0?Un(t,t.count-L,t.count-1):[],v=Un(t,Math.max(Y,j),Math.min(A,Math.max(0,t.count-1)-L)),E=[];for(const d of v)E.push(K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-T,width:t.sizeOf(d)},children:De.columnIndexToName(d)},d));const R=m?yo(t,v):null,y=R===null?null:R.filter(d=>!(d.kind==="unhide"&&d.index<j&&$>0||d.kind==="unhide"&&d.index>=t.count-L&&g>0)),a=m&&j>0?yo(t,I):null,f=m&&L>0?cu(t,C):null,k=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[E,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-T,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-T,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:j===0&&L===0?k:K.jsxs(K.Fragment,{children:[I.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:De.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:$,right:L>0?`calc(${De.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${De.SPREADSHEET_SCROLLBAR_SIZE_PX+$}px)))`:void 0},children:[k,j>0?K.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,L>0?K.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]}),L>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${$}px, calc(100% - ${g+De.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:De.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[C.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:De.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?K.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}`):K.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]})})},kw=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:b,dividerTrailingRef:N})=>{const W=ot.useWheelBridge(n),z=i.useCallback(d=>(r.current=d,W(d)),[r,W]),q=d=>o.some(x=>d>=x.startRow&&d<=x.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:x,rowGeomVersion:O}=e.get();return`${d}:${x}:${O}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,U,U);const{rowStart:A,rowEnd:T}=e.get(),F=t.count===0?0:t.offsetOf(Math.min(A,t.count-1));i.useLayoutEffect(()=>{l.current=F,c()},[F,l,c]);const j=Math.min(Math.max(0,h),t.count),$=_a(t,j),I=j>0?Un(t,0,j-1):[],L=Math.min(Math.max(0,m),t.count-j),g=Ia(t,L),p=t.totalSize()-g,C=L>0?Un(t,t.count-L,t.count-1):[],v=Un(t,Math.max(A,j),Math.min(T,Math.max(0,t.count-1)-L)),E=[];for(const d of v)E.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d)-F,height:t.sizeOf(d)},children:d+1},d));const R=u?yo(t,v):null,y=R===null?null:R.filter(d=>!(d.kind==="unhide"&&d.index<j&&$>0||d.kind==="unhide"&&d.index>=t.count-L&&g>0)),a=u&&j>0?yo(t,I):null,f=u&&L>0?cu(t,C):null,k=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[E,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-F,height:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-F,height:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:De.SPREADSHEET_SCROLLBAR_SIZE_PX},children:j===0&&L===0?k:K.jsxs(K.Fragment,{children:[I.map(d=>K.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)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:$,bottom:L>0?`calc(min(${g}px, max(0px, 100% - ${$}px)))`:void 0},children:[k,j>0?K.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,L>0?K.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]}),L>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${$}px, calc(100% - ${g}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[C.map(d=>K.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)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?K.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}`):K.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]})})},Ew=9,Ow=4,cc=(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,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},ac=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Aw=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),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),b=i.useCallback(g=>s.current!==null?g.pointerId===s.current:g.pointerType==="mouse",[]),N=i.useCallback(()=>{const g=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),g.writeResizeGuide(null);const p=m.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),m.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,g.repaintOverlay()},[]),W=i.useCallback((g,p)=>{const C=t.current;return g==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),z=i.useCallback((g,p)=>{const C=t.current,v=C.getSelection().ranges.filter(f=>W(g,f));if(!v.some(f=>g==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const R=v.reduce((f,k)=>f+(g==="col"?k.endCol-k.startCol+1:k.endRow-k.startRow+1),0),y=g==="row"?Math.floor(C.maxOperationCells/Ls):C.maxOperationCells;if(R>y)return C.onOperationRejected?.("resize",R,"limit"),null;const a=new Set;for(const f of v){const k=g==="col"?f.startCol:f.startRow,d=g==="col"?f.endCol:f.endRow;for(let x=k;x<=d;x+=1)a.add(x)}return[...a]},[W]),q=i.useCallback((g,p,C)=>{const v=t.current,E=g==="col"?v.colAxis:v.rowAxis,R=Ds(E,p,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:$s,axisKind:g});return R.ok?(v.resizeTracks(g,R.entries),!0):(v.onOperationRejected?.("resize",R.count,R.reason),!1)},[]),U=i.useCallback((g,p)=>{if(p===g.initialSize)return;const C=g.kind==="unhide"?[g.index]:z(g.axis,g.index);C!==null&&q(g.axis,C.map(v=>({index:v,size:p})),g.index)},[z,q]),Y=i.useCallback((g,p,C,v)=>{const E=t.current,R=E.fontSourceRef.current;if(R===null)return!1;if(p.length===0)return!0;const y=g.length*p.length;if(y>C)return E.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(R),k=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),x={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},O=`${x.fontStyle} ${x.fontWeight} ${x.fontSize} ${x.fontFamily}`,M=E.adapter.getConditionalFormats===void 0?null:dw(E.adapter.getConditionalFormats()),H=Us(),B=new WeakMap,G=new WeakMap,X=new Map;for(const re of g){const Ae=M===null?null:su(M.filter(ze=>ze.ranges.some(_e=>re>=_e.startCol&&re<=_e.endCol)));for(const ze of p){const _e=E.adapter.getCellText(ze,re),qe=E.adapter.getCellFormat===void 0?void 0:Xs(E.adapter,Ae,H,ze,re,()=>_e),we=ze<E.headerRows,Ne=qe===void 0?we?O:k:we?cc(qe,G,x):cc(qe,B,f),st=Gn(_e,qe===void 0?void 0:qe.value),je=X.get(Ne);je===void 0?X.set(Ne,[{col:re,text:st}]):je.push({col:re,text:st})}}const ee=R.ownerDocument.createElement("span");ee.setAttribute("aria-hidden","true"),ee.style.position="absolute",ee.style.visibility="hidden",R.append(ee);const ne=new Map;for(const[re,Ae]of X){a.font=re,ee.style.font=re;const ze=getComputedStyle(ee);a.letterSpacing=ze.letterSpacing==="normal"?"0px":ze.letterSpacing,a.wordSpacing=ze.wordSpacing==="normal"?"0px":ze.wordSpacing;for(const _e of Ae){const qe=a.measureText(_e.text).width,we=ne.get(_e.col);(we===void 0||qe>we)&&ne.set(_e.col,qe)}}ee.remove();const le=[];for(const re of g){const Ae=ne.get(re);Ae!==void 0&&Ae>0&&le.push({index:re,size:Math.ceil(Ae)+Ew})}return le.length===0?!0:q("col",le,v)},[q]),A=i.useCallback(g=>{const p=t.current,C=z("col",g);if(C===null)return!1;const v=p.handleRef.current,E=v===null?null:v.getFrozenSize(),R=E===null?0:E.rows,y=E===null?0:E.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),k=Math.min(f,p.rowAxis.count-1),d=[],x=new Set,O=M=>{!x.has(M)&&p.rowAxis.sizeOf(M)>0&&(x.add(M),d.push(M))};for(let M=0;M<R;M+=1)O(M);for(let M=a;M<=k;M+=1)O(M);for(let M=p.rowAxis.count-y;M<p.rowAxis.count;M+=1)O(M);return Y(C,d,Math.floor(p.maxOperationCells/Ow),g)},[z,Y]),T=i.useCallback((g,p,C)=>{const v=g==="col"?t.current.colAxis:t.current.rowAxis,E=Xu(v.sizeOf(p),C);if(E===v.sizeOf(p))return!0;const R=z(g,p);return R===null?!1:q(g,R.map(y=>({index:y,size:E})),p)},[z,q]),F=i.useCallback(g=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(g)===0?!0:A(g):!1},[A]),j=i.useCallback(g=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(g)].filter(E=>p.colAxis.sizeOf(E)>0);if(C.length===0)return!0;const v=[];for(let E=0;E<p.rowAxis.count;E+=1)p.rowAxis.sizeOf(E)>0&&v.push(E);return Y(C,v,p.maxOperationCells,null)},[Y]),{enabled:$,colBandRef:I,rowBandRef:L}=e;return i.useEffect(()=>{const g=I.current,p=L.current;if(!$||g===null||p===null)return;const C=B=>B==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(B,G)=>{if(!(G instanceof Element))return null;const X=G.closest(C(B));if(X===null)return null;const ee=X.hasAttribute("data-aqsp-unhide"),ne=Number(X.getAttribute(ee?"data-aqsp-unhide":B==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),le=X.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:ee?"unhide":"resize",index:ne,anchor:le}},E=B=>{if(!(n.current&&b(B)))return;const G=r.current;if(G===null)return;const X=(G.axis==="col"?B.clientX-G.startClientX:B.clientY-G.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(G.anchor==="trailing"?G.initialSize-X:G.initialSize+X)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const ee=r.current;if(!n.current||ee===null)return;const ne=t.current,le=ee.axis==="col"?ne.colAxis:ne.rowAxis;ne.writeResizeGuide({axis:ee.axis,position:ac(ee,le,o.current),anchor:ee.anchor})}))},R=()=>{const B=r.current,G=o.current;N(),B!==null&&U(B,G)},y=B=>{E(B),n.current&&b(B)&&(l.current&1)!==0&&(B.buttons&1)===0&&R()},a=B=>{B.button!==0||!(n.current&&b(B))||R()},f=(B,G)=>X=>{const ee=t.current;if(h.current=X.pointerType,X.pointerType!=="mouse")return;if(X.button!==0){X.preventDefault();return}const ne=v(B,X.target);if(ne===null)return;if(X.stopPropagation(),X.preventDefault(),ee.isPointing()){ee.focusSink();return}if(ee.isEditing()&&!ee.requestCommit()){ee.focusSink();return}ee.focusSink();const le=B==="col"?ee.colAxis:ee.rowAxis,re={axis:B,kind:ne.kind,index:ne.index,anchor:ne.anchor,initialSize:le.sizeOf(ne.index),startClientX:X.clientX,startClientY:X.clientY};r.current=re,o.current=re.initialSize,l.current=X.buttons,n.current=!0,ee.repaintOverlay(),s.current=X.pointerId,c.current=G;try{G.setPointerCapture(X.pointerId)}catch{s.current=null}const Ae=y,ze=a;m.current={move:Ae,up:ze},window.addEventListener("pointermove",Ae),window.addEventListener("pointerup",ze),ee.writeResizeGuide({axis:B,position:ac(re,le,o.current),anchor:re.anchor})},k=(B,G)=>X=>{const ee=t.current;if(h.current!=="mouse")return;const ne=G.getRootNode(),le=ne instanceof ShadowRoot?ne:G.ownerDocument,re=X.target instanceof Element&&X.target.closest(C(B))!==null?X.target:typeof le.elementFromPoint=="function"?le.elementFromPoint(X.clientX,X.clientY):null,Ae=v(B,re);if(Ae!==null){if(X.stopPropagation(),ee.isEditing()){ee.focusSink();return}if(Ae.kind==="unhide"){q(B,[{index:Ae.index,size:B==="col"?ee.defaultColumnWidth:ee.defaultRowHeight}],null);return}if(ee.autofitEnabled){if(B==="row"){const ze=z("row",Ae.index);ze!==null&&q("row",ze.map(_e=>({index:_e,size:ee.defaultRowHeight})),Ae.index);return}A(Ae.index)}}},d=B=>{!n.current||s.current===null||B.pointerId!==s.current||N()},x=f("col",g),O=f("row",p),M=k("col",g),H=k("row",p);return g.addEventListener("pointerdown",x,{capture:!0}),p.addEventListener("pointerdown",O,{capture:!0}),g.addEventListener("dblclick",M),p.addEventListener("dblclick",H),g.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{g.removeEventListener("pointerdown",x,{capture:!0}),p.removeEventListener("pointerdown",O,{capture:!0}),g.removeEventListener("dblclick",M),p.removeEventListener("dblclick",H),g.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),N()}},[$,I,L,b,N,U,q,z,A]),i.useMemo(()=>({stepTrack:T,autofitColumn:F,autofitColumnsInAllRows:j,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,T,F,j])},Gs=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,xw=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Gs(n,t.ranges[r]))&&Bt(e.anchor,t.anchor)&&Bt(e.active,t.active),Tw=(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=>dn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:de(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)}},$w=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Gs(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Or=(e,t,n)=>n.extend?Sn(e,t):n.append?{ranges:[...e.ranges,de(t,t)],anchor:t,active:t}:e.ranges.length===1&&Bt(e.anchor,t)&&Bt(e.active,t)&&Gs(e.ranges[0],de(t,t))?e:{ranges:[de(t,t)],anchor:t,active:t},Lw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Sn=(e,t)=>{const n=$w(e,de(e.anchor,t));return n.ranges.some(r=>un(r,n.active))?n:{...n,active:Lw(n.active,n.ranges[n.ranges.length-1])}},au=(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(de({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(de({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(de({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(de({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[de(n,n)],anchor:n,active:n};const s=o.findIndex(c=>un(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}},Dw=(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,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},uu=(e,t)=>{const n=e.ranges.findIndex(o=>un(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=Dw(e.ranges,r.rangeIndex,r.cell,t),!Bt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},_t=24,uc=32,Ro=4,qn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),b=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),N=i.useCallback(()=>{const z=u.current,q=e.current,U=m.current;if(z===null||q===null||U===null){c.current=null;return}const{clientX:Y,clientY:A}=z.getPointerPosition(),T=l.current,F=(Y-U.left)/T,j=(A-U.top)/T,$=q.getViewportSize(),I=$.width,L=$.height;if(I<=0||L<=0){c.current=requestAnimationFrame(N);return}const g=y=>Math.min(uc,Math.ceil(y/_t*uc));let p=0,C=0;if(s!=="x"){const y=q.getFrozenSize(),a=y.trailingVisibleHeight;j>L-a-_t?z.anchorRow!==void 0&&y.trailingRows>0&&z.anchorRow>=t.count-y.trailingRows&&a>0&&j>=L-a||(p=g(j-(L-a-_t))):j<y.height+_t&&(z.anchorRow!==void 0&&z.anchorRow<y.rows&&y.height>0&&j<y.height||(p=-g(y.height+_t-j)))}if(s!=="y"){const y=q.getFrozenSize(),a=y.trailingVisibleWidth;F>I-a-_t?z.anchorCol!==void 0&&y.trailingCols>0&&z.anchorCol>=n.count-y.trailingCols&&a>0&&F>=I-a||(C=g(F-(I-a-_t))):F<y.width+_t&&(z.anchorCol!==void 0&&z.anchorCol<y.cols&&y.width>0&&F<y.width||(C=-g(y.width+_t-F)))}const v=C!==0||p!==0?q.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):q.getScrollPosition(),E=v.y,R=v.x;if(E>=0&&R>=0&&t.totalSize()>0&&n.totalSize()>0){const y=q.getFrozenSize(),a=dn({row:Dr(t,j,{scroll:E,frozenSize:y.height,trailingSize:y.trailingHeight,extent:$.height}),col:Lr(n,F,{scroll:R,frozenSize:y.width,trailingSize:y.trailingWidth,extent:$.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(z.buildRange(a)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),W=i.useCallback(z=>{b(),u.current=z,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[b,N,r]);return i.useEffect(()=>{const z=()=>{document.visibilityState==="hidden"&&b()};return document.addEventListener("visibilitychange",z),()=>{document.removeEventListener("visibilitychange",z),b()}},[b]),i.useMemo(()=>({start:W,stop:b}),[W,b])},dc=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),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),b=i.useRef(!1),N=i.useRef(0),W=i.useCallback(($,I)=>{const{axis:L,mainAxis:g,handleRef:p,zoomRef:C}=t.current,v=s.current;if(v===null||g.totalSize()===0)return null;const E=C.current,R=p.current;if(R===null)return null;if(L==="col"){const k=R.getScrollPosition().x;if(k<0)return null;const d=R.getFrozenSize(),x=R.getViewportSize();return Math.min(Math.max(Lr(g,($-v.left)/E,{scroll:k,frozenSize:d.width,trailingSize:d.trailingWidth,extent:x.width}),0),g.count-1)}const y=R.getScrollPosition().y;if(y<0)return null;const a=R.getFrozenSize(),f=R.getViewportSize();return Math.min(Math.max(Dr(g,(I-v.top)/E,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),z=i.useCallback(($,I)=>{const{axis:L,crossCount:g}=t.current;return L==="col"?{press:{row:0,col:$},extend:{row:g-1,col:I}}:{press:{row:$,col:0},extend:{row:I,col:g-1}}},[]),q=i.useCallback(($,I)=>{const{axis:L,crossCount:g}=t.current;return $.ranges.some(p=>L==="col"?p.startRow===0&&p.endRow===g-1&&I>=p.startCol&&I<=p.endCol:p.startCol===0&&p.endCol===g-1&&I>=p.startRow&&I<=p.endRow)},[]),U=i.useRef(!1),Y=i.useRef({clientX:0,clientY:0}),A=i.useCallback(()=>{U.current=!1;const{autoScroller:$,headerRef:I,onDragFrame:L}=t.current;n.current=!1,r.current=null,m.current=null,b.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),$.stop();const g=I.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,L(null),t.current.repaintOverlay()},[]),T=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.setSelection($),A()},[A]),{enabled:F,headerRef:j}=e;return i.useEffect(()=>{const $=j.current;if(!F||$===null)return;const I=R=>{const y=t.current;if(R.pointerType!=="mouse")return;if(R.button!==0){R.preventDefault();return}if(b.current=!1,y.pointing?.getPointing()){s.current=$.getBoundingClientRect();const d=W(R.clientX,R.clientY);if(d===null)return;R.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){R.preventDefault(),y.focusSink();return}s.current=$.getBoundingClientRect();const a=W(R.clientX,R.clientY);if(a===null)return;R.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const k=R.ctrlKey||R.metaKey;if(R.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:x}=z(a,a),O={...f,anchor:d};y.setSelection(Sn(O,x)),o.current=y.axis==="col"?d.col:d.row}else if(k&&q(f,a))b.current=!0,N.current=a,o.current=a;else{const{press:d,extend:x}=z(a,a),O=Or(f,d,{extend:!1,append:k});y.setSelection(Sn(O,x)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:R.clientX,clientY:R.clientY},u.current=R.pointerId,h.current=R.buttons;try{$.setPointerCapture(R.pointerId)}catch{u.current=null}m.current=d=>{const x=t.current.axis==="col"?d.col:d.row,{press:O}=z(o.current,o.current),{extend:M}=z(o.current,x);return de(O,M)},y.autoScroller.stop(),U.current=!1,Y.current={clientX:R.clientX,clientY:R.clientY}},L=R=>u.current!==null?R.pointerId===u.current:R.pointerType==="mouse",g=R=>{if(n.current&&L(R)){if(b.current){const y=R.clientX!==l.current.clientX||R.clientY!==l.current.clientY;if(l.current={clientX:R.clientX,clientY:R.clientY},!y)return;const a=W(R.clientX,R.clientY);if(a===null||a===N.current)return;b.current=!1;const f=t.current,{press:k,extend:d}=z(N.current,N.current),x=Or(f.getSelection(),k,{extend:!1,append:!0});f.setSelection(Sn(x,d));const O=m.current,M=Math.abs(R.clientX-Y.current.clientX),H=Math.abs(R.clientY-Y.current.clientY);O!==null&&Math.max(M,H)>=Ro&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:O,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:R.clientX,clientY:R.clientY},!U.current&&m.current!==null){const y=Math.abs(R.clientX-Y.current.clientX),a=Math.abs(R.clientY-Y.current.clientY);Math.max(y,a)>=Ro&&(U.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 y=m.current;if(!n.current||y===null)return;const a=W(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=R=>{g(R),n.current&&L(R)&&(h.current&1)!==0&&(R.buttons&1)===0&&v(R)},C=R=>{R.button!==0||!(n.current&&L(R))||v(R)},v=R=>{const y=t.current;if(b.current){const{press:f,extend:k}=z(N.current,N.current);y.setSelection(au(y.getSelection(),de(f,k),f)),A();return}const a=W(R.clientX,R.clientY);if(a!==null){const{extend:f}=z(o.current,a);y.setSelection(Sn(y.getSelection(),f))}A()},E=R=>{!n.current||u.current===null||R.pointerId!==u.current||T()};return $.addEventListener("pointerdown",I),$.addEventListener("pointermove",p),$.addEventListener("pointerup",C),$.addEventListener("lostpointercapture",E),()=>{$.removeEventListener("pointerdown",I),$.removeEventListener("pointermove",p),$.removeEventListener("pointerup",C),$.removeEventListener("lostpointercapture",E),A()}},[F,j,W,z,A,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:T,cancelDrag:A}),[T,A])},Mw=({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:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),b=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):b>l+u-h.trailingVisibleHeight&&o.scrollBy({y:b-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),b=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):b>s+c-h.trailingVisibleWidth&&o.scrollBy({x:b-(s+c-h.trailingVisibleWidth)})}},zw=50,Nw=100,du=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<zw:!1,mr={selectAll:It("Ctrl+A"),undo:It("Ctrl+Z"),redo:It("Ctrl+Y"),redoShiftZ:It("Ctrl+Shift+Z"),pasteValues:It("Ctrl+Shift+V")},Fw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Pw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},_w=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",qw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,b=u.current;if(!l||m===null||b===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},W=(a,f,k)=>sn(a,f,k)??f,z=(a,f)=>{const k=s.current;return f==="left"||f==="right"?{row:a.row,col:W(k.colAxis,a.col,f==="right"?1:-1)}:{row:W(k.rowAxis,a.row,f==="down"?1:-1),col:a.col}},q=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),Y=(a,f,k,d)=>{if(a.sizeOf(f)>0)return f;const x=sn(a,f,k);if(x!==null)return x;const O=sn(a,f,k===1?-1:1);return O!==null?O:d},A=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},T=a=>z(A(),a),F=(a,f)=>{const k=s.current,d=f==="left"||f==="right",x=f==="right"||f==="down"?1:-1;let O;return k.findDataEdge!==void 0?(O=k.findDataEdge({row:a.row,col:a.col},f),j(O,a,f)):O={row:f==="down"?k.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?k.colAxis.count-1:f==="left"?0:a.col},d?{row:O.row,col:Y(k.colAxis,O.col,x,a.col)}:{row:Y(k.rowAxis,O.row,x,a.row),col:O.col}},j=(a,f,k)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const x=k==="left"||k==="right";if(x?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${x?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},$=(a,f,k)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${k} component ${a} (count ${f})`)},I=a=>{const f=s.current,k=f.getSelection();if(uu(k,a)===k){f.moveActive({mode:"reset",cell:z(k.active,a)});return}f.moveActive({mode:"cycle",direction:a})},L=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,k=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
14
- ${a.value.slice(k)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const k=s.current,d=k.pageExtent();if(d<=0)return W(k.rowAxis,a,f==="down"?1:-1);const x=k.rowAxis.indexAt(k.rowAxis.offsetOf(a)+(f==="down"?d:-d));return x===a?W(k.rowAxis,a,f==="down"?1:-1):x},p=a=>{const f=s.current;if(r.current=!1,du(a,t.current))return;const k=a.ctrlKey||a.metaKey,d=a.altKey,x=Pw[a.key];if(o.current&&!Fw.has(a.key)&&!f.isDragging()&&N(),f.isEditing()){const M=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!k&&!a.shiftKey&&!d&&f.abortDrag();return}const H=f.pointing;if(H!==void 0){if(x!==void 0&&!d){const X=H.getReferenceCursor();if(X!==null){a.preventDefault();const ee=dn(X.cursor,f.rowAxis.count,f.colAxis.count),ne=dn(X.origin,f.rowAxis.count,f.colAxis.count),le=k?F(ee,x):z(ee,x);if(f.ensureCellVisible(le),H.insertReference(a.shiftKey?de(ne,le):le,X.axis),f.onPointFrame!==void 0){const re=a.shiftKey?de(ne,le):de(le,le);f.onPointFrame(X.axis==="columns"?de({row:0,col:re.startCol},{row:f.rowAxis.count-1,col:re.endCol}):X.axis==="rows"?de({row:re.startRow,col:0},{row:re.endRow,col:f.colAxis.count-1}):re),o.current=!0}return}}if(a.key==="F2"&&!k&&!a.shiftKey&&!d&&H.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!k&&!a.shiftKey&&!d&&H.cycleAnchorAtCaret()){a.preventDefault();return}}const B=f.commands,G=B===void 0?null:Aa(B.table,a);if(B!==void 0&&G!==null&&Co.has(G.command)&&B.isAvailable(G.command)){a.preventDefault(),B.execute(G.command);return}if(x!==void 0&&!d){if(k&&a.shiftKey){a.preventDefault();return}if(k)return;if(M==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:T(x)}):f.moveActive({mode:"reset",cell:z(f.getSelection().active,x)});return}return}if(a.key==="Enter"&&d&&!k&&!a.shiftKey){a.preventDefault(),L();return}if((a.key==="Enter"||a.key==="Tab")&&!k&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=!a.shiftKey;I(a.key==="Tab"?X?"right":"left":X?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!k&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(X.row,a.key==="PageDown"?"down":"up"),col:X.col}});return}if(a.key==="Escape"&&!k&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}if(B!==void 0&&G!==null&&!Co.has(G.command)&&tm(G.chord)&&B.isAvailable(G.command)){a.preventDefault(),f.onCommandBlockedWhileEditing?.(G);return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const O=f.commands;if(O!==void 0){const M=Jh(O.table,a);if(M!==null&&O.isAvailable(M)){a.preventDefault(),O.execute(M);return}}if(x!==void 0&&!d){const M=x==="left"||x==="right",H=x==="right"||x==="down"?1:-1;if(k&&a.shiftKey){a.preventDefault();const B=f.getSelection(),G=A();let X;if(f.findDataEdge!==void 0){const ee=M?{row:B.active.row,col:G.col}:{row:G.row,col:B.active.col},ne=f.findDataEdge(ee,x);X=M?ne.col:ne.row,$(X,M?f.colAxis.count:f.rowAxis.count,M?"col":"row"),X=Y(M?f.colAxis:f.rowAxis,X,H,M?G.col:G.row)}else{const ee=M?f.colAxis:f.rowAxis;X=H===1?U(ee):q(ee)}f.moveActive({mode:"extend",cell:M?{row:G.row,col:X}:{row:X,col:G.col}});return}if(k){a.preventDefault(),f.moveActive({mode:"reset",cell:F(f.getSelection().active,x)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:T(x)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,x)});return}if(_w(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!k&&!d){a.preventDefault();const M=!a.shiftKey;I(a.key==="Tab"?M?"right":"left":M?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const H=A();f.moveActive({mode:"extend",cell:{row:k?q(f.rowAxis):H.row,col:q(f.colAxis)}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:k?q(f.rowAxis):M.row,col:q(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const H=A();f.moveActive({mode:"extend",cell:{row:k?U(f.rowAxis):H.row,col:U(f.colAxis)}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:k?U(f.rowAxis):M.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!k&&!d){a.preventDefault();const M=a.key==="PageDown"?"down":"up";if(a.shiftKey){const B=A();f.moveActive({mode:"extend",cell:{row:g(B.row,M),col:B.col}});return}const H=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(H.row,M),col:H.col}});return}if(a.key==="F2"&&!k&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!k&&!a.shiftKey&&!d){a.preventDefault();const M=f.getSelection(),H=wt(M.ranges);if(H>f.maxOperationCells){f.onOperationRejected?.("delete",H,"limit");return}if(f.adapter!==void 0&&Wn(f.adapter,M.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:H});return}const B=[],G=f.adapter!==void 0&&po(f.adapter).hyperlink;nn(M.ranges,X=>{B.push(G?{row:X.row,col:X.col,text:"",hyperlink:null}:{row:X.row,col:X.col,text:""})}),f.commitEdits(B,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(k||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(fr(mr.selectAll,a)){a.preventDefault();const M=f.getSelection(),H=de({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[H],anchor:M.anchor,active:M.active});return}if(fr(mr.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(fr(mr.redo,a)||fr(mr.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!k&&!d||a.key==="ContextMenu"&&!k&&!a.shiftKey&&!d){a.preventDefault();const M=f.getSelection().active;f.ensureCellVisible(M);const H=h.current,B=H===null?{x:0,y:0}:H.getScrollPosition(),G=Math.max(0,B.y),X=Math.max(0,B.x),ee=H===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:H.getFrozenSize(),ne=H===null?{width:0,height:0}:H.getViewportSize(),le=f.zoomRef.current;f.onCellContextMenu?.(M,{kind:"keyboard",cellRect:{top:On(f.rowAxis,M.row,{scroll:G,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:ne.height})*le,left:En(f.colAxis,M.col,{scroll:X,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:ne.width})*le,width:f.colAxis.sizeOf(M.col)*le,height:f.rowAxis.sizeOf(M.row)*le}});return}if(a.key===" "&&!d&&k!==a.shiftKey){a.preventDefault();const M=f.getSelection(),H=M.ranges.map(B=>k?de({row:0,col:B.startCol},{row:f.rowAxis.count-1,col:B.endCol}):de({row:B.startRow,col:0},{row:B.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:H,anchor:M.anchor,active:M.active});return}if(f.pendingPasteOptionsRef!==void 0&&fr(mr.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},v=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Nw)},E=()=>{const a=s.current;if(N(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},R=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),N()};return m.addEventListener("keydown",p),m.addEventListener("keyup",R),m.addEventListener("blur",y),m.addEventListener("compositionstart",C),m.addEventListener("compositionend",v),m.addEventListener("input",E),()=>{m.removeEventListener("keydown",p),m.removeEventListener("keyup",R),m.removeEventListener("blur",y),m.removeEventListener("compositionstart",C),m.removeEventListener("compositionend",v),m.removeEventListener("input",E),n.current!==null&&window.clearTimeout(n.current),N()}},[l,c,u,h])},Iw=()=>{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)})}},jw=4,Hw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Bw=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}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),b=i.useRef(0),N=i.useRef(null),W=i.useRef(null),z=i.useRef(!1),q=i.useCallback($=>m.current!==null?$.pointerId===m.current:$.pointerType==="mouse",[]),U=i.useCallback(($,I)=>{const{handleRef:L,rowAxis:g,colAxis:p}=t.current,C=L.current,v=s.current;if(C===null||v===null)return null;const{x:E,y:R}=C.getScrollPosition();if(R<0||E<0||g.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return dn({row:Dr(g,(I-v.top)/y,{scroll:R,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Lr(p,($-v.left)/y,{scroll:E,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,p.count)},[]),Y=i.useCallback($=>{const I=r.current;if(I===null)return de($,$);const L=de({row:Math.min(I.startRow,$.row),col:Math.min(I.startCol,$.col)},{row:Math.max(I.endRow,$.row),col:Math.max(I.endCol,$.col)}),g=L.startRow!==I.startRow||L.endRow!==I.endRow||L.startCol!==I.startCol||L.endCol!==I.endCol;return o.current=g?L:null,g?L:I},[]),A=i.useCallback(()=>{const $=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),$.xAutoScroller.stop(),$.yAutoScroller.stop(),z.current=!1,u.current=!1,h.current={dx:0,dy:0},$.writeFillPreview(null);const I=W.current;I!==null&&(window.removeEventListener("pointermove",I.move),window.removeEventListener("pointerup",I.up),W.current=null);const L=t.current.handleNodeRef.current;L!==null&&m.current!==null&&L.hasPointerCapture?.(m.current)&&L.releasePointerCapture(m.current),m.current=null,$.repaintOverlay()},[]),T=i.useCallback(()=>{const $=t.current,I=r.current,L=o.current;if(A(),I===null||L===null)return;const g=Nh(I,L);if(g>$.maxOperationCells){$.onOperationRejected?.("fill",g,"limit");return}const p=Fh(I,L);if(Wn($.adapter,p)){$.rejectReadOnly({kind:"operation",op:"fill",cellCount:wt(p),gesture:"fillHandle",sources:[I],targets:p});return}const C=Ph((E,R)=>Ra($.adapter,E,R),I,L,va);if($.commitEdits(C,{source:"fill"})===null)return;const v=$.getSelection();$.setSelection({ranges:[L],anchor:v.anchor,active:v.active})},[A]),{enabled:F,handleNodeRef:j}=e;return i.useEffect(()=>{const $=j.current;if(!F||$===null)return;const I=v=>{L(v),n.current&&q(v)&&(b.current&1)!==0&&(v.buttons&1)===0&&T()},L=v=>{if(!(n.current&&q(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const E=Math.abs(v.clientX-c.current.clientX),R=Math.abs(v.clientY-c.current.clientY);if(!u.current&&Math.max(E,R)>=jw&&(u.current=!0),!!u.current){if(!z.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:Y,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),z.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&u.current))return;const y=U(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(Y(y))}))}},g=v=>{v.button!==0||!(n.current&&q(v))||T()},p=v=>{const E=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),E.focusSink();const R=E.getSelection(),y=R.ranges[R.ranges.length-1];r.current=y,o.current=null,u.current=!1,E.xAutoScroller.stop(),E.yAutoScroller.stop(),z.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,b.current=v.buttons,n.current=!0,E.repaintOverlay(),s.current=E.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=E.handleRef.current?.getScrollPosition()??{x:-1,y:-1},k=f.y;if(a!==null&&k>=0&&f.x>=0){const O=f.x,M=E.zoomRef.current,H=E.handleRef.current?.getFrozenSize()??Hw,B=E.handleRef.current?.getViewportSize()??{width:0,height:0},G={scroll:O,frozenCount:H.cols,trailingCount:H.trailingCols,extent:B.width},X={scroll:k,frozenCount:H.rows,trailingCount:H.trailingRows,extent:B.height},ee=En(E.colAxis,y.endCol,G)+E.colAxis.sizeOf(y.endCol),ne=On(E.rowAxis,y.endRow,X)+E.rowAxis.sizeOf(y.endRow),le=ee-1,re=y.endCol>=H.cols&&H.width>0?Math.max(le,H.width):le,ze=!(y.endCol>=E.colAxis.count-H.trailingCols)&&H.trailingWidth>0?Math.min(re,B.width-H.trailingVisibleWidth-1):re,_e=ne-1,qe=y.endRow>=H.rows&&H.height>0?Math.max(_e,H.height):_e,Ne=!(y.endRow>=E.rowAxis.count-H.trailingRows)&&H.trailingHeight>0?Math.min(qe,B.height-H.trailingVisibleHeight-1):qe;h.current={dx:v.clientX-(a.left+ze*M),dy:v.clientY-(a.top+Ne*M)}}else h.current={dx:0,dy:0};m.current=v.pointerId;try{$.setPointerCapture(v.pointerId)}catch{m.current=null}const d=I,x=g;W.current={move:d,up:x},window.addEventListener("pointermove",d),window.addEventListener("pointerup",x),E.writeFillPreview(r.current)},C=v=>{!n.current||m.current===null||v.pointerId!==m.current||A()};return $.addEventListener("pointerdown",p),$.addEventListener("lostpointercapture",C),()=>{$.removeEventListener("pointerdown",p),$.removeEventListener("lostpointercapture",C),A()}},[F,j,q,U,Y,A,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&A()},cancelDrag:A}),[A])},Ww=320,ho=8,Vw=64,Yw=150,fu=e=>Math.max(0,Math.min(Ww,e.width-De.SPREADSHEET_SCROLLBAR_SIZE_PX-ho)),Kw=(e,t,n)=>{const r=n.width-De.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-De.SPREADSHEET_SCROLLBAR_SIZE_PX,s=fu(n),l=Math.max(0,Math.min(t,o-ho)),c=e.left+e.width,u=e.top+e.height,h=q=>q>=0&&q+s<=r,m=[e.left,c-s],b=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const q of b)if(h(q.left)&&q.top>=0&&q.top+l<=o)return{left:q.left,top:q.top,width:s,height:l};const N=o-u,W=e.top,z=Math.min(l,Math.max(N,W));if(z>=Vw){const q=N>=W?u:e.top-z;for(const U of m)if(h(U))return{left:U,top:q,width:s,height:z}}return{left:ho,top:ho,width:s,height:l}},Uw=(e,t,n,r)=>t===null||e!==null&&Bt(e,t)||n?!1:r(t),Xw=(e,t)=>{switch(e.kind){case"note":return K.jsx(Ya,{ctx:e,labels:t});case"note-tip":return K.jsx(Ka,{ctx:e,labels:t});case"comment":return K.jsx(Ha,{ctx:e,labels:t});case"link":return K.jsx(Ba,{ctx:e,labels:t});case"list":return K.jsx(Wa,{ctx:e,labels:t});default:return K.jsx(Va,{ctx:e,labels:t})}},ds=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Gw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const b=ds(s),N=ds(l),W=i.useRef(null),z=(T,F)=>{const j=m.current.getLayerSize();T.style.width=`${fu(j)}px`,T.style.maxHeight="";const $=Kw(F,T.offsetHeight,j);T.style.left=`${$.left-F.left}px`,T.style.top=`${$.top-F.top}px`,T.style.maxHeight=`${$.height}px`};i.useLayoutEffect(()=>{const T=c.current;if(T===null||s===null){W.current=null;return}if(z(T,s.anchorRect),s.kind==="message")return;const F=ds(s);if(W.current===F)return;W.current=F;const j=T.querySelector("[data-aqsp-popover-autofocus]");j!==null?j.focus({preventScroll:!0}):T.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const T=u.current,F=h.current;T===null||F===null||z(T,F.anchorRect)},[N]);const q=T=>t===void 0?Xw(T,n):t(T),U=T=>{e.isCompositionKey(T.nativeEvent)&&T.stopPropagation()},Y=T=>{T.key==="Escape"&&!T.defaultPrevented&&(T.preventDefault(),e.close())},A=T=>{e.registerCompositionEnd(T.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:Y,onCompositionEnd:A,children:[K.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:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:q(s)},b)}),K.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:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:q(l)})})]})},Zw=["note","note-tip","comment","link","list","message"],Jw=(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}},gr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Jw(e,n),Qw=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),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),b=i.useRef(null),N=i.useRef(null),W=i.useRef(null),z=i.useId(),q=i.useCallback(O=>{const M=t.current,H=M.handleRef.current,B=H===null?{x:0,y:0}:H.getScrollPosition(),G=H===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:H.getFrozenSize(),X=H===null?{width:0,height:0}:H.getViewportSize();return{top:On(M.rowAxis,O.row,{scroll:Math.max(0,B.y),frozenCount:G.rows,trailingCount:G.trailingRows,extent:X.height}),left:En(M.colAxis,O.col,{scroll:Math.max(0,B.x),frozenCount:G.cols,trailingCount:G.trailingCols,extent:X.width}),width:M.colAxis.sizeOf(O.col),height:M.rowAxis.sizeOf(O.row)}},[]),U=i.useCallback(O=>{const M=t.current;M.anchors.current={...M.anchors.current,...O},M.repaintOverlay()},[]),Y=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),A=i.useCallback(()=>{const O=t.current.sinkRef.current;if(O===null)return;const M=c.current;M!==null&&Bt(M,t.current.getActive())?O.setAttribute("aria-describedby",z):O.getAttribute("aria-describedby")===z&&O.removeAttribute("aria-describedby")},[z]),T=i.useCallback(()=>(Y(),h.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),A(),!0)),[Y,U,A]),F=i.useCallback(()=>{Y(),m.current=window.setTimeout(()=>{m.current=null,T()},Yw)},[Y,T]),j=i.useCallback(O=>{const M=t.current;Y();const H=M.adapter.getCellNote===void 0?void 0:M.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:T}),U({tip:O}),A())},[q,Y,T,U,A]),$=i.useCallback(O=>{const M=t.current;if(O===null&&h.current)return;const H=u.current;u.current=O;const B=c.current;if(B!==null&&O!==null&&Bt(B,O)){Y();return}const G=X=>{const ee=M.adapter.getCellNote===void 0?void 0:M.adapter.getCellNote(X.row,X.col);return ee!==void 0&&ee!==""};if(Uw(H,O,M.isDraggingAny(),G)){O!==null&&j(O);return}B!==null&&F()},[j,Y,F]),I=i.useCallback((O,M)=>{const H=t.current,B=H.bodyRef.current,G=H.handleRef.current;if(B===null||G===null)return null;const X=B.getBoundingClientRect(),ee=H.zoomRef.current,ne=G.getScrollPosition(),le=G.getFrozenSize(),re=G.getViewportSize();return dn({row:Dr(H.rowAxis,(M-X.top)/ee,{scroll:Math.max(0,ne.y),frozenSize:le.height,trailingSize:le.trailingHeight,extent:re.height}),col:Lr(H.colAxis,(O-X.left)/ee,{scroll:Math.max(0,ne.x),frozenSize:le.width,trailingSize:le.trailingWidth,extent:re.width})},H.rowAxis.count,H.colAxis.count)},[]),L=i.useCallback(O=>{N.current=O,b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const M=N.current;$(M===null?null:"cell"in M?M.cell:I(M.clientX,M.clientY))}))},[$,I]),g=i.useCallback(O=>L({cell:O}),[L]),p=i.useCallback(()=>T(),[T]),C=i.useCallback(O=>{if(l.current===null)return;const M=t.current;l.current=null,r(null),U({interactive:null}),(O===void 0||O.restoreFocus)&&M.focusSink({preventScroll:!0}),M.isEditing()||M.rearmSink()},[U]),v=i.useCallback(O=>{l.current=O.kind,r(O),U({interactive:O.cell})},[U]),E=i.useCallback(O=>{const M=t.current;return Ca(M.adapter)?{cellReadOnly:Ze(M.adapter,O.row,O.col)}:{}},[]),R=i.useCallback((O,M)=>{const H=t.current;if(Ze(H.adapter,O.cell.row,O.cell.col)){H.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...O,...E(O.cell)});return}if(H.commitEdits(M,{source:"annotate"})===null){v({...O,rejected:!0});return}C()},[v,C,E]),y=i.useCallback((O,M)=>{const H=t.current;if(!gr(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 B=H.getActive();if(O==="list"&&Ze(H.adapter,B.row,B.col)){H.rejectReadOnly({kind:"edit",cell:B,editSession:"none"});return}if(O==="note-tip"){j(B);return}if(O==="message"){if(l.current!==null&&l.current!=="message")return;const ne=M!==void 0&&M.message!==void 0?M.message:void 0,le=H.adapter.getCellValidation===void 0?void 0:H.adapter.getCellValidation(B.row,B.col),re=ne!==void 0?ne:le===void 0?void 0:le.inputMessage;if(re===void 0)return;const Ae=M!==void 0&&M.rejected===!0;v({kind:"message",cell:B,anchorRect:q(B),current:{title:Pe(H.labels,"messageTitle"),message:re,rejected:Ae},close:C});return}if(H.isEditing()&&!H.requestCommit())return;if(O==="list"){const ne=H.adapter.getCellValidation===void 0?void 0:H.adapter.getCellValidation(B.row,B.col);if(ne===void 0||ne.type!=="list")return;const le=M!==void 0&&M.typed!==void 0?M.typed:"";T(),H.focusSink({preventScroll:!0}),v({kind:"list",cell:B,anchorRect:q(B),current:ne.values,typed:le,commit:re=>{if(Ze(t.current.adapter,B.row,B.col)){t.current.rejectReadOnly({kind:"edit",cell:B,editSession:"none"}),C();return}t.current.commitEdits([{row:B.row,col:B.col,text:re}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(T(),H.focusSink({preventScroll:!0}),O==="note"){const ne=H.adapter.getCellNote===void 0?void 0:H.adapter.getCellNote(B.row,B.col),le={kind:"note",cell:B,anchorRect:q(B),current:ne,commit:re=>{R(le,[{row:B.row,col:B.col,note:re}])},close:C,rejected:!1,...E(B)};v(le);return}if(O==="comment"){const ne=H.adapter.getCellComments===void 0?void 0:H.adapter.getCellComments(B.row,B.col),le={kind:"comment",cell:B,anchorRect:q(B),current:ne===void 0?[]:ne,commit:re=>{R(le,[{row:B.row,col:B.col,comments:re}])},close:C,rejected:!1,...E(B)};v(le);return}const G=H.adapter.getCellHyperlink===void 0?void 0:Qn(H.adapter.getCellHyperlink(B.row,B.col)),X=H.adapter.getCellText(B.row,B.col),ee={kind:"link",cell:B,anchorRect:q(B),current:{text:X,url:G},commit:ne=>{const le=ne.url===null?null:an(ne.url);if(le===null&&ne.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ne.url)}`);const re=ne.text===X?{row:B.row,col:B.col,hyperlink:le}:{row:B.row,col:B.col,text:ne.text,hyperlink:le};R(ee,[re])},close:C,canOpen:H.onHyperlinkOpen!==void 0,open:()=>{const ne=t.current.onHyperlinkOpen;ne!==void 0&&G!==void 0&&ne(G,B)},rejected:!1,...E(B)};v(ee)},[q,C,R,T,v,j,E]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const O=f.current;if(!a||O===null)return;const M=B=>{const G=t.current;gr(G.adapter,G.popovers,"note-tip")&&L({clientX:B.clientX,clientY:B.clientY})},H=()=>{gr(t.current.adapter,t.current.popovers,"note-tip")&&L({cell:null})};return O.addEventListener("pointermove",M),O.addEventListener("pointerleave",H),()=>{O.removeEventListener("pointermove",M),O.removeEventListener("pointerleave",H)}},[a,f,L]),i.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:k,popovers:d}=e,x=i.useMemo(()=>Zw.some(O=>gr(k,d,O)),[k,d]);return i.useMemo(()=>({layerEnabled:x,isKindEnabled:O=>gr(t.current.adapter,t.current.popovers,O),open:y,close:C,isOpen:()=>l.current,onCellHover:g,hideTip:p,onTipPointerEnter:()=>{h.current=!0,Y()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&F()},syncTipAriaDescribedBy:A,context:n,tipContext:o,registerCompositionEnd:O=>{W.current=O},isCompositionKey:O=>du(O,W.current),getLayerSize:()=>{const O=t.current.handleRef.current;return O===null?{width:0,height:0}:O.getViewportSize()},tipId:z}),[x,y,C,g,p,Y,F,A,n,o,z])},e0=(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},pu=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return dn({row:Dr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:Lr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},t0=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),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),b=i.useRef(null),N=i.useRef(""),W=i.useRef(!1),z=i.useRef(!1),q=i.useCallback((L,g)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:E}=t.current;return pu(p.current,o.current,C,v,E.current,L,g)},[]),U=i.useRef(!1),Y=i.useRef(null),A=i.useRef(null),T=i.useRef({clientX:0,clientY:0}),F=i.useCallback(()=>{const{autoScroller:L,bodyRef:g,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,U.current=!1,Y.current=null,A.current=null,m.current=!1,b.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),L.stop();const C=g.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),j=i.useCallback(()=>{if(!n.current)return;const L=r.current;L!==null&&t.current.setSelection(L),F()},[F]),{enabled:$,bodyRef:I}=e;return i.useEffect(()=>{const L=I.current;if(!$||L===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const x=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,b.current=null,z.current=!1),W.current=g(d.target),!W.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(x.getPointing?.()){x.focusSink();return}if(x.isEditing()&&!x.requestCommit()){d.stopPropagation(),x.focusSink();return}x.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((x.pointDragRef===void 0?null:x.pointDragRef.current)?.onPointerDown(d))return;if(x.isEditing()&&!x.requestCommit()){d.preventDefault(),x.focusSink();return}o.current=L.getBoundingClientRect();const M=q(d.clientX,d.clientY);if(M===null)return;if(d.preventDefault(),x.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&x.openHyperlinkAt?.(M)===!0){z.current=!0;return}const H=x.getSelection();r.current=H;const B=d.shiftKey,G=d.ctrlKey||d.metaKey,X=G&&!B&&H.ranges.some(ne=>un(ne,M));m.current=X,b.current=X?M:null,X||x.setSelection(Or(H,M,{extend:B,append:G})),n.current=!0,x.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{L.setPointerCapture(d.pointerId)}catch{c.current=null}const ee=X?M:x.getSelection().anchor;h.current=ne=>de(ee,ne),Y.current=ee.col,A.current=ee.row,x.autoScroller.stop(),U.current=!1,T.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},!U.current&&h.current!==null){const x=Math.abs(d.clientX-T.current.clientX),O=Math.abs(d.clientY-T.current.clientY);Math.max(x,O)>=Ro&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:Y.current??void 0,anchorRow:A.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const x=h.current;if(!n.current||x===null)return;const O=t.current,M=q(s.current.clientX,s.current.clientY);M!==null&&O.onDragFrame(x(M))}))}},E=d=>{v(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},R=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const x=t.current,O=q(d.clientX,d.clientY);if(O!==null){const M=b.current;m.current&&M!==null?x.setSelection(au(x.getSelection(),de(M,O),M)):x.setSelection(Sn(x.getSelection(),O))}F()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||j()},f=d=>{const x=t.current;if(!g(d.target)||N.current!=="mouse"||x.isAnyDragging())return;if(x.isEditing()&&!x.requestCommit()){x.focusSink();return}x.focusSink(),o.current=L.getBoundingClientRect();const O=q(d.clientX,d.clientY);if(O===null)return;const M=x.getSelection();M.ranges.some(B=>un(B,O))||x.setSelection(Or(M,O,{extend:!1,append:!1})),x.onContextMenuSelect(O,d)},k=d=>{const x=t.current;if(!W.current||N.current!=="mouse"||x.getPointing?.()||z.current)return;o.current=L.getBoundingClientRect();const O=q(d.clientX,d.clientY);O!==null&&Bt(x.getSelection().active,O)&&x.onRequestEdit(O,x.caretFromPointEnabled(O)?e0(d.clientX,d.clientY,O):void 0)};return L.addEventListener("pointerdown",p),L.addEventListener("pointermove",E),L.addEventListener("pointerup",R),L.addEventListener("lostpointercapture",a),L.addEventListener("contextmenu",f),L.addEventListener("dblclick",k),()=>{L.removeEventListener("pointerdown",p),L.removeEventListener("pointermove",E),L.removeEventListener("pointerup",R),L.removeEventListener("lostpointercapture",a),L.removeEventListener("contextmenu",f),L.removeEventListener("dblclick",k),F()}},[$,I,q,F,j]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:j,cancelDrag:F}),[j,F])},n0=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),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),b=i.useRef(null),N=i.useRef(!1),W=i.useCallback((T,F)=>{const{handleRef:j,rowAxis:$,colAxis:I,zoomRef:L}=t.current;return pu(j.current,o.current,$,I,L.current,T,F)},[]),z=i.useCallback(()=>{const{autoScroller:T,bodyRef:F,onDragFrame:j}=t.current;n.current=!1,r.current=null,m.current=null,b.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const $=F.current;$!==null&&u.current!==null&&$.hasPointerCapture?.(u.current)&&$.releasePointerCapture(u.current),u.current=null,j(null)},[]),q=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.restoreSink(T),z()},[z]),U=i.useCallback(T=>{const F=t.current,j=F.bodyRef.current;if(!F.enabled||j===null||!F.getPointing())return!1;o.current=j.getBoundingClientRect();const $=W(T.clientX,T.clientY);if($===null)return o.current=null,!1;const I=F.captureSink();if(I===null)return o.current=null,!1;T.preventDefault(),F.focusSink(),r.current=I,b.current=$,F.insertReference($,"cells"),n.current=!0,s.current={clientX:T.clientX,clientY:T.clientY},l.current={clientX:T.clientX,clientY:T.clientY},u.current=T.pointerId,h.current=T.buttons;try{j.setPointerCapture(T.pointerId)}catch{u.current=null}return m.current=L=>{const g=de($,L);return t.current.insertReference(g,"cells"),g},F.autoScroller.stop(),N.current=!1,F.onDragFrame(de($,$)),!0},[W]),{enabled:Y,bodyRef:A}=e;return i.useEffect(()=>{const T=A.current;if(!Y||T===null)return;const F=L=>u.current!==null?L.pointerId===u.current:L.pointerType==="mouse",j=L=>{if(!(n.current&&F(L)))return;s.current={clientX:L.clientX,clientY:L.clientY};const g=m.current,p=b.current;if(!N.current&&g!==null&&p!==null){const C=Math.abs(L.clientX-l.current.clientX),v=Math.abs(L.clientY-l.current.clientY);Math.max(C,v)>=Ro&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=m.current;if(!n.current||C===null)return;const v=W(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(h.current&1)!==0&&(L.buttons&1)===0&&z()},$=L=>{L.button!==0||!(n.current&&F(L))||z()},I=L=>{!n.current||u.current===null||L.pointerId!==u.current||z()};return T.addEventListener("pointermove",j),T.addEventListener("pointerup",$),T.addEventListener("lostpointercapture",I),()=>{T.removeEventListener("pointermove",j),T.removeEventListener("pointerup",$),T.removeEventListener("lostpointercapture",I),z()}},[Y,A,W,z]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:q,cancelDrag:z,onPointerDown:U}),[q,z,U])},r0=Object.freeze({width:0,height:0}),fs=33,o0=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,s0=(e,t,n)=>{const r=(n-t)/(fs-1);let o=-1,s=-1;for(let c=0;c<fs;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,u)=>{let h=c,m=u;for(;Math.abs(m-h)>1;){const b=(h+m)/2;e(b)?m=b:h=b}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===fs-1?n:l(t+r*(s+1),t+r*s)}},l0=(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})`)},i0=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)})`)},c0=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)})`)},fc=(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},a0=24,u0=200,hu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),pc=5,d0=/^#[0-9A-Fa-f]{6}$/,f0=Object.freeze({row:!1,column:!1,intersection:!1}),hc=Object.freeze({ok:!0}),mc=(e,t)=>{if(t===void 0)return hu;if(t.length!==pc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${pc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!d0.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},p0=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},h0=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ja},m0=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},g0=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)},In={ranges:[de({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},w0=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=a0,defaultColumnWidth:l=De.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:m=0,tapScrollCircleOptions:b,overscanRows:N,overscanCols:W,background:z,onRenderTruncated:q,renderCell:U,onSelectionChange:Y,onCellContextMenu:A,onUndoRequest:T,onRedoRequest:F,onCopyMultiRange:j,onOperationRejected:$,onEditRejected:I,onReadOnlyRejected:L,formatReadOnlyAnnouncement:g,dataVersion:p,maxOperationCells:C=De.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:v=!0,enableResizeUI:E=!0,headings:R=!0,onContentSizeChange:y,frame:a,formatCellAnnouncement:f,formatSelectionAnnouncement:k,formatCommandAnnouncement:d,formatResizeAnnouncement:x,locale:O,labels:M,shortcuts:H,onCommandBlockedWhileEditing:B,colors:G,formats:X,highlight:ee,defaultHighlight:ne,onHighlightChange:le,highlightColors:re,popovers:Ae,renderPopover:ze,onClipChange:_e,onHyperlinkOpen:qe,onValidationRejected:we,onPasteSpecialRequest:Ne,onClipboardUnavailable:st,onPasteResolved:je,now:fn=Date.now,zoom:lt,defaultZoom:ft,onZoomChange:pt,testId:pn,className:Vt,__onCellRender:Mr,__onVirtualKeyboardRaise:hn,__maxRenderedCells:zr},Nr){const oe=i.useMemo(()=>r?Th(t):t,[t,r]),me=tc(oe.rowCount,s),ue=tc(oe.colCount,l),An=i.useRef(null);An.current===null&&(An.current=Iw());const xe=An.current,Yt=ot.resolveVirtualScrollLocale(O),Kt=i.useMemo(()=>Ta(O,M),[O,M]),Fr=g0(sm(Kt)),Mt=i.useMemo(()=>Zh(H),[H]),Pr=i.useMemo(()=>{if(!E)return;const _=[...Mt].filter(([,Q])=>rs.includes(Q)).sort(([,Q],[,te])=>rs.indexOf(Q)-rs.indexOf(te)).map(([Q])=>Vh(Q)).filter(Q=>Q!==null);return _.length===0?void 0:_.join(" ")},[Mt,E]),xn=i.useMemo(()=>({fill:mc("fill",G===void 0?void 0:G.fill),font:mc("font",G===void 0?void 0:G.font)}),[G]),Ut=i.useMemo(()=>re===void 0?void 0:p0(re),[re]);if(oe.getConditionalFormats!==void 0&&oe.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");l0(n,u),i0(o),c0(a);const mn=i.useCallback(()=>xe.get().editVersion,[xe]),Tn=i.useCallback(w=>xe.subscribeCoalesced(w),[xe]),tr=i.useSyncExternalStore(Tn,mn,mn)+(p===void 0?0:p),$n=oe.getConditionalFormats===void 0?null:oe.getConditionalFormats(),Xt=i.useMemo(()=>({index:$n===null?null:su($n),memo:Us()}),[oe,$n,tr]),nr=i.useRef(Xt.index);nr.current=Xt.index;const rr=i.useRef(Xt.memo);rr.current=Xt.memo;const Gt=i.useCallback((w,_,Q)=>Xs(oe,nr.current,rr.current,w,_,Q),[oe]),Ke=i.useRef(null),[xo,Ln]=i.useState(()=>De.clampSpreadsheetZoom(ft??1)),ht=De.clampSpreadsheetZoom(lt??xo),Fe=i.useRef(ht);Fe.current=ht;const S=i.useRef(ht);S.current=ht;const D=i.useRef(null),V=i.useRef(pt);V.current=pt;const P=i.useRef(lt!==void 0);P.current=lt!==void 0;const Z=i.useCallback(w=>{const _=De.clampSpreadsheetZoom(w);_!==S.current&&(S.current=_,P.current||Ln(_),V.current?.(_))},[]),J=oe.rowCount===0||oe.colCount===0,ie=!J;i.useEffect(()=>{const w=Ke.current;if(!ie||w===null)return;const _=te=>{te.defaultPrevented||!te.altKey||te.ctrlKey||te.metaKey||te.shiftKey||te.deltaY!==0&&(te.preventDefault(),te.stopPropagation(),!D.current?.()&&Z(De.stepSpreadsheetZoom(S.current,te.deltaY<0?1:-1)))},Q=te=>{if(te.defaultPrevented||!(te.ctrlKey&&te.altKey)||te.metaKey||te.getModifierState("AltGraph"))return;const he=te.key==="="||te.key==="+"?De.stepSpreadsheetZoom(S.current,1):te.key==="-"?De.stepSpreadsheetZoom(S.current,-1):te.key==="0"?1:null;he!==null&&(te.preventDefault(),te.stopPropagation(),!D.current?.()&&Z(he))};return w.addEventListener("wheel",_,{passive:!1,capture:!0}),w.addEventListener("keydown",Q,!0),()=>{w.removeEventListener("wheel",_,{capture:!0}),w.removeEventListener("keydown",Q,!0)}},[Z,ie]);const ve=i.useRef(null),Oe=i.useRef(null),Ee=i.useRef(null),He=i.useRef(null),fe=i.useRef(null),Le=i.useRef(null),pe=i.useRef(null),se=i.useRef(0),be=i.useRef(null),ye=i.useRef(0),ge=i.useRef(null),Je=i.useRef(null),ce=i.useRef(null),Te=i.useRef(null),Qe=i.useRef(null),Ue=i.useRef(null),it=i.useRef(null),[ke,ct]=i.useState(In),We=i.useRef(ke),Be=i.useCallback(()=>We.current,[]),[et,gn]=i.useState(()=>ne===void 0?f0:ne),Zt=ee!==void 0?ee:et,or=i.useRef(Zt);or.current=Zt;const mu=h0(Ut,Zt),Zs=i.useRef(ee!==void 0);Zs.current=ee!==void 0;const Js=i.useRef(le);Js.current=le;const gu=i.useCallback(w=>{Zs.current||gn(w),Js.current?.(w)},[]),Qs=i.useRef(null),To=i.useRef(null),zt=i.useRef(null),$o=i.useRef(()=>!1),el=i.useRef(()=>{}),tl=i.useRef(()=>null),nl=i.useRef(()=>{}),wn=i.useCallback(()=>$o.current(),[]),Lo=i.useMemo(()=>({getPointing:()=>$o.current(),insertReference:(w,_)=>el.current(w,_)}),[]),rl=i.useRef(qt),ol=i.useRef(null),Do=i.useRef({interactive:null,tip:null}),sl=i.useRef(null),ll=i.useRef(null),_r=i.useRef(()=>{}),il=i.useRef(()=>!1),Jt=i.useRef(null),sr=i.useCallback(()=>{const w=Jt.current;if(w===null||w.isOpen()!=="message")return!1;const _=w.context;return _===null||_.kind!=="message"||!_.current.rejected?!1:(w.close(),!0)},[]),Mo=i.useRef(()=>!1),cl=i.useRef(()=>!1),al=i.useRef(null),zo=i.useRef(()=>Promise.resolve("rejected")),$e=i.useCallback(()=>{Qs.current?.()},[]),Nt=i.useCallback(w=>{Le.current?.focus(w)},[]),Ve=i.useCallback(()=>{Nt({preventScroll:!0})},[Nt]),No=i.useRef(!1),wu=i.useCallback(()=>{const w=Ke.current;if(w!==null){No.current=!0;try{w.focus()}finally{No.current=!1}}},[]),at=i.useCallback(()=>{const w=Le.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),Dn=i.useCallback((w,_)=>{if(w===null)return;const Q=_?"":"none";w.style.display!==Q&&(w.style.display=Q)},[]),yt=i.useCallback(()=>{const w=pe.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().y??0),te=fe.current?.getFrozenSize().height??0;w.style.transform=`translateY(${se.current-Q-te}px)`}const _=fe.current;if(_!==null&&(Qe.current!==null||Ue.current!==null)){const Q=_.getFrozenSize();Dn(Qe.current,Q.height>0),Dn(Ue.current,Q.trailingHeight>0)}},[Dn]),Rt=i.useCallback(()=>{const w=be.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().x??0),te=fe.current?.getFrozenSize().width??0;w.style.transform=`translateX(${ye.current-Q-te}px)`}const _=fe.current;if(_!==null&&(ce.current!==null||Te.current!==null)){const Q=_.getFrozenSize();Dn(ce.current,Q.width>0),Dn(Te.current,Q.trailingWidth>0)}},[Dn]),lr=i.useRef(null),Mn=i.useCallback(()=>{ce.current===null&&Te.current===null&&Qe.current===null&&Ue.current===null||lr.current===null&&(lr.current=requestAnimationFrame(()=>{lr.current=null,yt(),Rt(),$e()}))},[yt,Rt,$e]);i.useEffect(()=>()=>{lr.current!==null&&cancelAnimationFrame(lr.current)},[]);const Fo=i.useRef(null),Po=i.useRef(null);(Fo.current===null||Po.current?.rowAxis!==me||Po.current?.colAxis!==ue)&&(Po.current={rowAxis:me,colAxis:ue},Fo.current=Mw({handleRef:fe,rowAxis:me,colAxis:ue}));const qr=i.useCallback(w=>{const _=fe.current,Q=_===null?{x:0,y:0}:_.getScrollPosition(),te=_===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:_.getFrozenSize(),he=_===null?{width:0,height:0}:_.getViewportSize(),Re=Fe.current;return{top:On(me,w.row,{scroll:Math.max(0,Q.y),frozenCount:te.rows,trailingCount:te.trailingRows,extent:he.height})*Re,left:En(ue,w.col,{scroll:Math.max(0,Q.x),frozenCount:te.cols,trailingCount:te.trailingCols,extent:he.width})*Re,width:ue.sizeOf(w.col)*Re,height:me.sizeOf(w.row)*Re}},[me,ue]),ul=i.useCallback(w=>{const _=He.current,Q=Ke.current,te=Oe.current;if(_===null||Q===null||te===null||fe.current===null)return;const he=Fe.current,Re=qr(w),Ge=te.offsetTop*he+Re.top,dt=te.offsetLeft*he+Re.left,Ye=Math.max(0,Ge),Lt=Math.max(0,dt),tn=Math.min(Q.clientHeight,Ge+Re.height),Br=Math.min(Q.clientWidth,dt+Re.width);if(tn<=Ye||Br<=Lt)return;_.style.top=`${Ye}px`,_.style.left=`${Lt}px`,_.style.width=`${Br-Lt}px`,_.style.height=`${tn-Ye}px`;const Pn=_.getBoundingClientRect();Pn.width===0&&Pn.height===0||_.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[qr]),Qt=i.useCallback(w=>{Fo.current?.(w),ul(w)},[ul]),Cu=i.useCallback(()=>{const w=fe.current,_=w===null?-1:w.getViewportSize().height,Q=ve.current,te=Ke.current;if(_<=0||Q===null||te===null)return _;const he=Q.getBoundingClientRect(),Re=te.getRootNode();if(he.height<=0||Q.offsetHeight<=0||!o0(Re))return _;const Ge=te.ownerDocument.documentElement,dt=Math.max(he.left,0),Ye=Math.min(he.right,Ge.clientWidth),Lt=Math.max(he.top,0)+.5,tn=Math.min(he.bottom,Ge.clientHeight)-.5,Br=(dt+Ye)/2,Pn=Ye>dt&&tn>=Lt?s0(Uu=>{const Il=Re.elementFromPoint(Br,Uu);return Il!==null&&te.contains(Il)},Lt,tn):null,Ku=Pn===null?Ge.clientHeight:Pn.bottom-Pn.top+1;return Math.min(_,Ku*(Q.offsetHeight/he.height))},[]),dl=i.useRef(y);dl.current=y;const _o=i.useRef(null),Ft=i.useCallback(()=>{const w=dl.current;if(w===void 0)return;const _=Oe.current;let Q;if(_===null)Q=r0;else{if(_.getClientRects().length===0)return;{const he=Ee.current,Re=Fe.current;Q={width:((he===null?0:he.offsetWidth)+ue.totalSize()+De.SPREADSHEET_SCROLLBAR_SIZE_PX)*Re,height:((he===null?0:he.offsetHeight)+me.totalSize()+De.SPREADSHEET_SCROLLBAR_SIZE_PX)*Re}}}const te=_o.current;te!==null&&te.width===Q.width&&te.height===Q.height||(_o.current=Q,w(Q))},[me,ue]);i.useLayoutEffect(()=>{if(y===void 0){_o.current=null;return}Ft()});const fl=y!==void 0;i.useEffect(()=>{const w=Oe.current;if(!fl||w===null)return;const _=new ResizeObserver(()=>Ft());return _.observe(w),()=>_.disconnect()},[fl,Ft,J]);const zn=i.useRef(null),Cn=i.useRef(null),Nn=i.useCallback(w=>{zn.current!==null&&window.clearTimeout(zn.current),Cn.current!==null&&(cancelAnimationFrame(Cn.current),Cn.current=null),zn.current=window.setTimeout(()=>{zn.current=null;const _=it.current;_!==null&&(_.textContent="",Cn.current=requestAnimationFrame(()=>{Cn.current=null,_.textContent=w}))},u0)},[]);i.useEffect(()=>()=>{zn.current!==null&&window.clearTimeout(zn.current),Cn.current!==null&&cancelAnimationFrame(Cn.current)},[]);const Fn=i.useCallback(w=>{L?.(w),g!==void 0&&Nn(g(w))},[L,g,Nn]),pl=i.useCallback((w,_)=>{if(f===void 0&&k===void 0)return;const Q=_.ranges[_.ranges.length-1],te=bt(Q),he=_.ranges.length===1&&te.rows===1&&te.cols===1,Re=w.ranges[w.ranges.length-1],Ge=w.ranges.length!==_.ranges.length||Re.startRow!==Q.startRow||Re.startCol!==Q.startCol||Re.endRow!==Q.endRow||Re.endCol!==Q.endCol,dt=()=>{if(f!==void 0){const Ye=_.active,Lt=oe.getCellText(Ye.row,Ye.col),tn=oe.getCellFormat===void 0?void 0:Gt(Ye.row,Ye.col,()=>Lt);Nn(f({row:Ye.row,col:Ye.col,text:Lt,displayText:Gn(Lt,tn===void 0?void 0:tn.value),columnName:De.columnIndexToName(Ye.col),...Ca(oe)?{readOnly:Ze(oe,Ye.row,Ye.col)}:{}}))}};if(he){dt();return}if(Ge){k!==void 0&&Nn(k({range:Q,anchor:_.anchor,active:_.active,rangeRowCount:te.rows,rangeColCount:te.cols,rangeCount:_.ranges.length}));return}dt()},[oe,f,k,Nn,Gt]),Xe=i.useCallback(w=>{const _=We.current;Object.is(w,_)||xw(w,_)||(We.current=w,ct(w),Y?.(w),pl(_,w),(zt.current?.()??!1)||at())},[Y,pl,at]),bu=i.useCallback(w=>{const _=We.current;if(w.mode==="cycle"){const te=uu(_,w.direction);Xe(te),Qt(te.active);return}const Q=dn(w.cell,me.count,ue.count);if(w.mode==="extend"){Xe(Sn(_,Q)),Qt(Q);return}Xe(Or(_,Q,{extend:!1,append:!1})),Qt(Q)},[Xe,Qt,me,ue]),tt=i.useCallback(()=>zt.current?.()??!1,[]),hl=i.useRef(null),vt=i.useCallback(()=>hl.current?.()??!0,[]),ml=i.useRef(null),ir=i.useCallback((w,_)=>{const Q=zt.current?.()??!1;ml.current?.(w,_),!Q&&(zt.current?.()??!1)&&sr()},[sr]),[yu,qo]=i.useState(!1),gl=i.useCallback(()=>{hn?.(),qo(!0)},[hn]),Ru=i.useCallback((w,_)=>{Ze(oe,w.row,w.col)||gl(),ir("edit",_)},[oe,gl,ir]),wl=i.useRef(null),Ir=i.useCallback(()=>wl.current?.()??null,[]),Cl=i.useRef(null),xt=i.useCallback(()=>{Cl.current?.()},[]),bl=i.useRef(null),yl=i.useCallback(w=>{bl.current?.(w)},[]),Rl=i.useRef(()=>{}),jr=i.useRef(0),bn=i.useCallback((w,_,Q)=>{let te;if(_.source==="paste"){const he=m0(Q);if(w.length===0&&he.conditionalFormats.length===0)return null;jr.current+=1,te={transaction:jr.current,source:"paste",sameSheet:he.sameSheet,conditionalFormats:he.conditionalFormats}}else{if(w.length===0)return null;jr.current+=1,te={transaction:jr.current,source:_.source}}try{oe.applyEdits(w,te)}catch(he){return I?.(he,_),null}return xe.bumpEdit(),yl(_.source),te.transaction},[oe,xe,I,yl]),vu=i.useCallback((w,_)=>bn(w,{source:"paste"},_),[bn]),Su=i.useCallback(w=>{xe.setVy(w.y),yt(),Rt(),$e()},[xe,yt,Rt,$e]),vl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),ku=i.useCallback(w=>{xe.setRowRange(w.renderingRowStart,w.renderingRowEnd),xe.setColRange(w.renderingColStart,w.renderingColEnd);const _=vl.current;(_.rowStart!==w.renderingRowStart||_.rowEnd!==w.renderingRowEnd||_.colStart!==w.renderingColStart||_.colEnd!==w.renderingColEnd)&&(vl.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},$e())},[xe,$e]),Sl=i.useRef(()=>"add"),en=i.useCallback(w=>{To.current?.(w,Sl.current())},[]),Eu=i.useCallback(w=>{To.current?.(w,"point")},[]),kl=i.useRef(null),Io=i.useCallback(w=>{kl.current?.(w)},[]),El=i.useRef(null),Ou=i.useCallback(w=>{El.current?.(w)},[]),Ol=i.useRef(null),jo=i.useCallback((w,_)=>{if(_.length===0)return;const Q=fe.current;if(w==="col"){for(const te of _){const he=Math.round(te.size);ue.resize(te.index,he),Q?.updateColSize(te.index,he)}xe.bumpColVersion(),Rt(),$e(),Mn(),Ft();return}for(const te of _){const he=Math.round(te.size);me.resize(te.index,he),Q?.updateRowSize(te.index,he)}xe.bumpRowGeometry(),yt(),$e(),Mn(),Ft()},[me,ue,xe,Rt,yt,$e,Mn,Ft]),Au=i.useCallback((w,_)=>{A?.(w,{kind:"pointer",event:_})},[A]),xu=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:en,axis:"both",zoomRef:Fe}),Tu=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:en,axis:"x",zoomRef:Fe}),$u=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:en,axis:"y",zoomRef:Fe}),Lu=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:Io,axis:"x",zoomRef:Fe}),Du=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:Io,axis:"y",zoomRef:Fe}),Mu=qn({handleRef:fe,rowAxis:me,colAxis:ue,bodyRef:ve,onDragFrame:en,axis:"both",zoomRef:Fe}),Al=i.useRef(null),xl=i.useRef(()=>!1),Ho=i.useCallback(()=>xl.current(),[]),St=t0({zoomRef:Fe,enabled:!J,rowAxis:me,colAxis:ue,handleRef:fe,bodyRef:ve,isEditing:tt,requestCommit:vt,getSelection:Be,setSelection:Xe,focusSink:Ve,onDragFrame:en,onContextMenuSelect:Au,onRequestEdit:Ru,caretFromPointEnabled:w=>{if(U!==void 0||oe.getCellFormula!==void 0&&oe.getCellFormula(w.row,w.col)!==void 0)return!1;if(oe.getCellFormat===void 0)return!0;const _=oe.getCellText(w.row,w.col);return Gn(_,oe.getCellFormat(w.row,w.col)?.value)===_},isAnyDragging:Ho,autoScroller:xu,repaintOverlay:$e,pointDragRef:Al,getPointing:wn,openHyperlinkAt:qe===void 0||oe.getCellHyperlink===void 0?void 0:w=>{const _=oe.getCellHyperlink===void 0?void 0:Qn(oe.getCellHyperlink(w.row,w.col));return _===void 0?!1:(qe(_,w),!0)}}),Tt=dc({zoomRef:Fe,enabled:!J&&R,axis:"col",headerRef:ge,mainAxis:ue,crossCount:oe.rowCount,handleRef:fe,isEditing:tt,requestCommit:vt,getSelection:Be,setSelection:Xe,focusSink:Ve,onDragFrame:en,autoScroller:Tu,repaintOverlay:$e,pointing:Lo}),$t=dc({zoomRef:Fe,enabled:!J&&R,axis:"row",headerRef:Je,mainAxis:me,crossCount:oe.colCount,handleRef:fe,isEditing:tt,requestCommit:vt,getSelection:Be,setSelection:Xe,focusSink:Ve,onDragFrame:en,autoScroller:$u,repaintOverlay:$e,pointing:Lo}),ut=Aw({zoomRef:Fe,enabled:!J&&E&&R,colBandRef:ge,rowBandRef:Je,fontSourceRef:ve,colAxis:ue,rowAxis:me,viewStore:xe,handleRef:fe,isEditing:tt,requestCommit:vt,focusSink:Ve,getSelection:Be,adapter:oe,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:$,resizeTracks:jo,writeResizeGuide:Ou,repaintOverlay:$e,isPointing:wn}),kt=Bw({zoomRef:Fe,enabled:!J&&v,handleNodeRef:Ol,bodyRef:ve,rowAxis:me,colAxis:ue,handleRef:fe,getSelection:Be,setSelection:Xe,focusSink:Ve,adapter:oe,commitEdits:bn,maxOperationCells:C,onOperationRejected:$,rejectReadOnly:Fn,writeFillPreview:Io,repaintOverlay:$e,xAutoScroller:Lu,yAutoScroller:Du}),mt=n0({zoomRef:Fe,enabled:!J,bodyRef:ve,handleRef:fe,rowAxis:me,colAxis:ue,getPointing:wn,insertReference:Lo.insertReference,captureSink:()=>tl.current(),restoreSink:w=>nl.current(w),focusSink:Ve,autoScroller:Mu,onDragFrame:en});Al.current=mt;const cr=i.useCallback(()=>St.isDragging()||Tt.isDragging()||$t.isDragging()||ut.isDragging()||kt.isDragging()||mt.isDragging(),[St,Tt,$t,ut,kt,mt]);D.current=cr,xl.current=cr,Sl.current=()=>mt.isDragging()?"point":St.getDragMode();const zu=i.useCallback(()=>{St.abortDrag(),Tt.abortDrag(),$t.abortDrag(),ut.abortDrag(),kt.abortDrag(),mt.abortDrag()},[St,Tt,$t,ut,kt,mt]),Bo=i.useCallback(()=>We.current.active,[]),Tl=i.useCallback((w,_)=>{const Q=oe.getCellValidation===void 0?void 0:oe.getCellValidation(w.row,w.col);if(Q===void 0)return hc;const te=oe.evaluateFormula,he=Da(Q,_,Yt,te===void 0?void 0:Re=>te(Re,w));return he.ok||Q.strict!==!0?hc:(we?.({cell:w,rule:Q,text:_,message:he.message}),Jt.current?.isKindEnabled("message")&&_r.current("message",{message:he.message,rejected:!0}),he)},[oe,we,Yt]),Ie=Bg({enabled:!J,sinkRef:Le,rootRef:Ke,adapter:oe,commitEdits:bn,getActive:Bo,ensureCellVisible:Qt,focusSink:Nt,rearmSink:at,discardClip:xt,isDragging:Ho,rejectReadOnly:Fn,resolveEditAlign:w=>{if(oe.getCellFormat===void 0)return null;const _=fo(oe,w.row,w.col);return wa(Gt(w.row,w.col,_),_)},resolveEditPaint:w=>oe.getCellFormat===void 0?null:Ef(Gt(w.row,w.col,fo(oe,w.row,w.col))),editPaintRef:rl,repaintOverlay:$e,validateCommit:Tl});zt.current=Ie.isEditing,hl.current=Ie.requestCommit,ml.current=Ie.startEdit,$o.current=Ie.getPointing,el.current=Ie.insertReference,tl.current=Ie.captureSink,nl.current=Ie.restoreSink;const $l=i.useCallback(()=>{Ie.cancelEdit(),sr()},[Ie.cancelEdit,sr]),ar=Sg({enabled:!J,sinkRef:Le,adapter:oe,isEditing:tt,getSelection:Be,setSelection:Xe,commitPaste:vu,maxOperationCells:C,onOperationRejected:$,onCopyMultiRange:j,repaintOverlay:$e,isDragging:Ho,resize:{rowAxis:me,colAxis:ue,resizeTracks:jo},pendingPasteOptionsRef:ol,formats:X,onClipChange:_e,onClipboardUnavailable:st,onEditRejected:I,rejectReadOnly:Fn,onPasteResolved:je});wl.current=ar.getClip,Cl.current=ar.discardClip,bl.current=ar.discardClipOnCommit,Rl.current=ar.onAdapterSwitch,zo.current=ar.paste;const ur=Qw({enabled:!J,adapter:oe,popovers:Ae,sinkRef:Le,bodyRef:ve,handleRef:fe,rowAxis:me,colAxis:ue,zoomRef:Fe,getActive:Bo,isEditing:tt,requestCommit:vt,focusSink:Nt,rearmSink:at,isDraggingAny:cr,commitEdits:bn,labels:Kt,onHyperlinkOpen:qe,anchors:Do,repaintOverlay:$e,rejectReadOnly:Fn});Jt.current=ur,_r.current=ur.open,il.current=ur.hideTip;const Nu=i.useCallback(()=>{const w=We.current.active;return Qt(w),qr(w)},[Qt,qr]),Wo=Ig({adapter:oe,trackResize:E&&!J?ut:void 0,getSelection:Be,commitEdits:bn,getActive:Bo,isEditing:tt,requestCommit:vt,cancelEdit:$l,getSessionText:Ie.getSessionText,validateCommit:Tl,insertAtCaret:Ie.insertAtCaret,refreshEditPaint:Ie.refreshPaint,maxOperationCells:C,onOperationRejected:$,colors:xn,formats:X,getHighlight:()=>or.current,setHighlight:gu,popovers:Ae,openPopover:w=>_r.current(w),onHyperlinkOpen:qe,onPasteSpecialRequest:Ne,paste:w=>zo.current(w),rowAxis:me,colAxis:ue,resizeTracks:jo,defaultRowHeight:s,defaultColumnWidth:l,now:fn,announce:Nn,formatCommandAnnouncement:d,formatResizeAnnouncement:x,keyboardCellRect:Nu,rejectReadOnly:Fn});al.current=Wo,Mo.current=Wo.executeCommand,cl.current=Wo.isCommandAvailable;const Fu=i.useMemo(()=>({table:Mt,execute:w=>Mo.current(w),isAvailable:w=>cl.current(w)}),[Mt]),Pu=i.useCallback(()=>{xt(),T?.()},[xt,T]),_u=i.useCallback(()=>{xt(),F?.()},[xt,F]);qw({zoomRef:Fe,enabled:!J,sinkRef:Le,rootRef:Ke,handOffFocusToRoot:wu,getSelection:Be,setSelection:Xe,moveActive:bu,ensureCellVisible:Qt,pageExtent:Cu,isEditing:tt,requestCommit:vt,startEdit:ir,commitEdits:bn,maxOperationCells:C,onOperationRejected:$,rejectReadOnly:Fn,getClip:Ir,discardClip:xt,isDragging:cr,abortDrag:zu,findDataEdge:oe.findDataEdge,getEditingMode:Ie.getEditingMode,cancelEdit:$l,onUndoRequest:Pu,onRedoRequest:_u,onCellContextMenu:A,rowAxis:me,colAxis:ue,handleRef:fe,rearmSink:at,commands:Fu,onCommandBlockedWhileEditing:B,pointing:Ie,adapter:oe,hideNoteTip:()=>il.current(),closeRejectedMessage:sr,pendingPasteOptionsRef:ol,onPointFrame:Eu});const qu=ke.active.row,Iu=ke.active.col;i.useLayoutEffect(()=>{const w=Jt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[qu,Iu]),i.useLayoutEffect(()=>{$e()},[$e,Zt.row,Zt.column,Zt.intersection]),i.useLayoutEffect(()=>{$e()},[$e,a?.startRow,a?.startCol,a?.endRow,a?.endCol]);const ju=i.useCallback(w=>{(zt.current?.()??!1)||(w.preventDefault(),Ve(),at())},[Ve,at]),Hu=i.useCallback(w=>{const _=Ke.current,Q=w.relatedTarget,te=_!==null&&!_.matches(":focus-visible");if(_!==null&&Q instanceof Node&&_.contains(Q)){w.target===_&&Q===Le.current&&!No.current&&Nt({preventScroll:te});return}(zt.current?.()??!1)||(Nt({preventScroll:te}),at())},[Nt,at]),Bu=i.useCallback(w=>{const _=Ke.current,Q=w.relatedTarget;_!==null&&Q instanceof Node&&_.contains(Q)||Ie.isFocusoutSuppressed()||qo(!1)},[Ie]),Hr=i.useRef(null),dr=i.useCallback(()=>{const w=Hr.current;w!==null&&(Hr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Vo=i.useCallback(()=>{if(Hr.current!==null)return;const w=Q=>{Q.pointerType==="mouse"&&(dr(),Q.button===1&&Q.preventDefault())},_=Q=>{Q.pointerType==="mouse"&&dr()};Hr.current={up:w,cancel:_},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",_,!0)},[dr]);i.useEffect(()=>dr,[dr]),i.useEffect(()=>{const w=Ke.current;if(J||w===null)return;let _=0;const Q=Re=>{if(Re.pointerType!=="mouse"){(zt.current?.()??!1)||qo(!1);return}_=Re.buttons,Re.button===1&&(Re.target===Le.current&&(zt.current?.()??!1)||Vo())},te=Re=>{Re.pointerType==="mouse"&&(_=Re.buttons)},he=Re=>{if(Re.pointerType!=="mouse"||Re.buttons===_)return;const Ge=Re.buttons&~_;_=Re.buttons,Re.preventDefault(),(Ge&4)!==0&&Vo()};return w.addEventListener("pointerdown",Q,!0),w.addEventListener("pointerup",te,!0),w.addEventListener("pointermove",he,!0),()=>{w.removeEventListener("pointerdown",Q,!0),w.removeEventListener("pointerup",te,!0),w.removeEventListener("pointermove",he,!0)}},[J,Vo]);const Wu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(wn()){Ve();return}if(tt()&&!vt()){Ve();return}Ve()}},[Ve,tt,vt,wn]),Yo=i.useRef(!1);i.useLayoutEffect(()=>{if(J){Yo.current=!1;return}if(Yo.current)return;Yo.current=!0,at();const w=(Ke.current?.clientHeight??0)/Fe.current;w>0&&me.totalSize()>0&&xe.setRowRange(0,me.indexAt(Math.min(w-1,me.totalSize()-1)));const _=(Ke.current?.clientWidth??0)/Fe.current;_>0&&ue.totalSize()>0&&xe.setColRange(0,ue.indexAt(Math.min(_-1,ue.totalSize()-1)))},[J,at,xe,me,ue]);const Ll=i.useRef(t);i.useLayoutEffect(()=>{Ll.current!==t&&(Ll.current=t,St.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),ut.cancelDrag(),kt.cancelDrag(),mt.cancelDrag(),Ie.cancelEdit(),Jt.current?.hideTip(),Jt.current?.close(),J?(We.current=In,ct(In)):Xe(In),Rl.current())},[t,J,Xe,St,Tt,$t,ut,kt,mt,xe,Ie.cancelEdit]);const Dl=i.useRef({adapter:oe,rows:me.count,cols:ue.count}),{getSessionCell:Ml,cancelEdit:zl}=Ie;i.useLayoutEffect(()=>{const w=Dl.current,_=me.count,Q=ue.count;if(Dl.current={adapter:oe,rows:_,cols:Q},w.adapter!==oe||_>=w.rows&&Q>=w.cols)return;J?(We.current=In,ct(In)):Xe(Tw(We.current,_,Q)),St.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),ut.cancelDrag(),kt.cancelDrag(),mt.cancelDrag();const te=dt=>J||dt.row>=_||dt.col>=Q,he=Ml();he!==null&&te(he)&&zl();const Re=Do.current;if(Re.tip!==null&&te(Re.tip)&&Jt.current?.hideTip(),Re.interactive!==null&&te(Re.interactive)){const dt=Ke.current?.contains(document.activeElement)===!0;Jt.current?.close({restoreFocus:dt})}const Ge=Ir();Ge!==null&&!Ge.foreign&&te({row:Ge.range.endRow,col:Ge.range.endCol})&&xt()},[oe,me.count,ue.count,J,Xe,St,Tt,$t,ut,kt,mt,Ml,zl,Ir,xt]);const Nl=i.useRef(c),Fl=i.useRef(u),Pl=i.useRef(h),_l=i.useRef(m);i.useLayoutEffect(()=>{(Nl.current!==c||Fl.current!==u||Pl.current!==h||_l.current!==m)&&(Nl.current=c,Fl.current=u,Pl.current=h,_l.current=m,St.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),ut.cancelDrag(),kt.cancelDrag(),mt.cancelDrag())},[c,u,h,m,St,Tt,$t,ut,kt,mt]),i.useLayoutEffect(()=>{yt(),Rt(),$e()},[c,u,h,m,yt,Rt,$e]);const ql=i.useRef(p);i.useLayoutEffect(()=>{ql.current!==p&&(ql.current=p,xt())},[p,xt]),i.useLayoutEffect(()=>{$e()},[$e,ke]);const yn=i.useCallback(()=>{const w=al.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(Nr,()=>({resizeRow:(w,_)=>{const Q=Math.round(_);me.resize(w,Q),fe.current?.updateRowSize(w,Q),xe.bumpRowGeometry(),yt(),$e(),Mn(),Ft()},resizeColumn:(w,_)=>{const Q=Math.round(_);ue.resize(w,Q),fe.current?.updateColSize(w,Q),xe.bumpColVersion(),Rt(),$e(),Mn(),Ft()},autoFitColumns:w=>{for(const _ of w)if(!Number.isInteger(_)||_<0||_>=ue.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${ue.count-1} (got ${String(_)})`);return ut.autofitColumnsInAllRows(w)},scrollToCell:(w,_)=>{fe.current?.scrollToCell(w.row,w.col,_)},focus:w=>{Nt(w),tt()||at()},executeCommand:w=>Mo.current(w),applyFormat:w=>yn().applyFormat(w),setBorders:(w,_)=>yn().setBorders(w,_),setHyperlink:w=>yn().setHyperlink(w),setNote:w=>yn().setNote(w),addComment:w=>yn().addComment(w),setValidation:w=>yn().setValidation(w),paste:w=>zo.current(w),getSelection:()=>We.current,getBaseFormat:w=>oe.getCellFormat===void 0?void 0:oe.getCellFormat(w.row,w.col),getPaintedFormat:w=>oe.getCellFormat===void 0?void 0:Gt(w.row,w.col,fo(oe,w.row,w.col)),startEdit:w=>{ir(w)},openPopover:w=>{_r.current(w)}}),[me,ue,xe,Rt,yt,$e,Mn,Ft,ut,Nt,tt,at,oe,Gt,ir,yn]),J)return K.jsx("div",{className:Vt?`aqsp-root ${Vt}`:"aqsp-root","data-aqsp-empty":"","data-testid":pn});const Vu=f!==void 0||k!==void 0||d!==void 0||g!==void 0||x!==void 0,Yu=o===void 0?{"aria-label":Kt.rootAriaLabel}:{"aria-labelledby":o};return K.jsxs("div",{ref:Ke,className:Vt?`aqsp-root ${Vt}`:"aqsp-root",role:"group",...Yu,tabIndex:0,onFocus:Hu,onBlur:Bu,"data-aqsp-root":"","data-aqsp-headings-hidden":R?void 0:"","data-aqsp-framed":a===void 0?void 0:"","data-testid":pn,children:[K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":ht,onPointerDown:Wu,style:ht===1?void 0:{width:`${100/ht}%`,height:`${100/ht}%`,transform:`scale(${ht})`,"--_aqsp-zoom":String(ht)},children:[R?K.jsxs(K.Fragment,{children:[K.jsx("div",{ref:Ee,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(wn()){Ve();return}if(tt()&&!vt()){Ve();return}Ve(),Xe({ranges:[de({row:0,col:0},{row:oe.rowCount-1,col:oe.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(Sw,{viewStore:xe,colAxis:ue,frozenCols:c,frozenTrailingCols:h,handleRef:fe,bandRef:ge,colTrackRef:be,windowOriginXRef:ye,repaintColHeaders:Rt,selectionRanges:ke.ranges,enableResizeUI:E,dividerLeadingRef:ce,dividerTrailingRef:Te}),K.jsx(kw,{viewStore:xe,rowAxis:me,handleRef:fe,bandRef:Je,selectionRanges:ke.ranges,rowTrackRef:pe,windowOriginYRef:se,repaintHeaders:yt,enableResizeUI:E,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:Qe,dividerTrailingRef:Ue})]}):null,K.jsxs("div",{ref:Oe,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(vw,{adapter:oe,rowAxis:me,colAxis:ue,viewStore:xe,handleRef:fe,bodyRef:ve,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:m,headerRows:n,labelledBy:o,gridLabel:o===void 0?Kt.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:b,overscanRows:fc("overscanRows",N),overscanCols:fc("overscanCols",W),background:z,onRenderTruncated:q,renderCell:U,onScroll:Su,onRangeChange:ku,focusSink:Ve,isEditing:tt,requestCommit:vt,testId:pn?`${pn}-vs`:void 0,__onCellRender:Mr,__maxRenderedCells:zr,cfIndexRef:nr,cfMemoRef:rr,isPointing:wn,locale:Yt,scrollLabels:Fr}),K.jsx(Zm,{rowAxis:me,colAxis:ue,handleRef:fe,sinkRef:Le,getSelection:Be,editing:Ie.editing,virtualKeyboard:yu,repaintRef:Qs,dragFrameRef:To,getClip:Ir,getIsDraggingAny:cr,getIsFillDragging:kt.isDragging,fillFrameRef:kl,resizeGuideFrameRef:El,fillHandleNodeRef:Ol,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:m,sinkAriaLabel:Kt.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Pr,onSinkMouseDown:ju,editPaintRef:rl,highlightRef:or,frameRange:a,highlightColors:mu,popoverAnchors:Do,interactiveAnchorRef:sl,tipAnchorRef:ll}),ur.layerEnabled?K.jsx(Gw,{controller:ur,labels:Kt,renderPopover:ze,interactiveAnchorRef:sl,tipAnchorRef:ll}):null]}),Vu?K.jsx("div",{ref:it,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),K.jsx("div",{ref:He,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=Ht.iterateTsvPrefixRows;exports.iterateTsvRows=Ht.iterateTsvRows;exports.measureTsv=Ht.measureTsv;exports.parseTsv=Ht.parseTsv;exports.serializeClipboardTsv=Ht.serializeClipboardTsv;exports.serializeTsv=Ht.serializeTsv;exports.columnIndexToName=De.columnIndexToName;exports.columnNameToIndex=De.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Ms;exports.CommentPopover=Ha;exports.DEFAULT_CUSTOM_COLORS=hu;exports.DEFAULT_HIGHLIGHT_COLORS=ja;exports.DEFAULT_SHORTCUTS=Oa;exports.LinkPopover=Ba;exports.ListPopover=Wa;exports.MessagePopover=Va;exports.NotePopover=Ya;exports.NoteTip=Ka;exports.SPREADSHEET_LABEL_CATALOGS=xa;exports.SPREADSHEET_RESERVED_SHORTCUTS=Yh;exports.Spreadsheet=w0;exports.canonicalizeFormat=At;exports.detectClipSource=Ec;exports.enumerateRangeCells=nn;exports.estimatePasteCellCount=Mh;exports.expandPaste=zh;exports.formatCellValue=Gn;exports.formatEquals=sd;exports.fromR1C1=Tr;exports.makeRange=de;exports.mergeFormat=Ns;exports.normalizeHyperlink=an;exports.parseChord=It;exports.parseClipPayload=ms;exports.parseHtmlTable=ga;exports.rangeContains=un;exports.rangeSize=bt;exports.resolveLabel=Pe;exports.resolveLabels=Ta;exports.serializeClipPayload=vc;exports.serializeHtmlTable=fa;exports.shiftFormula=Xc;exports.toR1C1=ko;exports.validateCellText=Da;
12
+ `)},Ch=(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)}Ss(t,ma(e,r))},bh=(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"?aa(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<pi.length?pi[l]:null}return null},ga=(e,t,n)=>t!==void 0&&da(t)?Ap(e,t,n):e,yh=(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 u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u: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 u=aa(Number(c));if(u!==null)return u}else return c;return ga(t,n,r)},Rh=(e,t,n,r)=>{const o=ma(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:dh(o)};for(const m of Eh(e))mh(m,l);gh(l,o,s,r.rules);const c=wh(l.text,l.mode),u=ph(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),b=m===null?void 0:yp(m,r.options);b!==void 0&&(u.value=b);const N=e.getAttribute("data-sheets-value"),B=N===null?null:bh(N,b);h.t=B===null?ga(c,b,sa):B;const M=e.getAttribute("data-sheets-formula");M?.startsWith("=")&&(h.f=M);const j=e.getAttribute("data-sheets-hyperlink"),U=j!==null?j:l.href,Y=U===null?null:an(U);Y!==null&&(h.link=Y);const A=e.getAttribute("data-sheets-note");A!==null&&A!==""&&(h.note=A)}else{const m=o.get("mso-number-format"),b=m===void 0?void 0:Ws(vs(ho(m)),r.options);b!==void 0&&(u.value=b),h.t=yh(e,c,b,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(h.f=vo(N,{row:t,col:n}));const B=l.href===null?null:an(l.href);B!==null&&(h.link=B)}return{cell:h,format:u}},ks=(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},vh=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)},Sh=(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]))},wa=(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:vh(l);if(c!==null)return Math.min(c,cn)}const o=Sh(e,t);return o===null?null:Math.min(o,cn)},kh=(e,t)=>{const n=[],r=o=>{const s=wa(o,"width");for(let l=ks(o,"span",_s);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Er(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Er(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Er(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Eh(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Oh(e){for(const t of["thead","tbody","tfoot"])for(const n of Er(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Er(n))o.localName==="tr"&&(yield o)}}const ns=()=>({t:""}),Ah=(e,t,n)=>{const r=Nc(),o=[],s=[],l=[];let c=0;for(const B of Oh(e)){const M=o.length,j=(M+1)*Math.max(c,1);if(j>n)return{outcome:"limit",cells:j};const U=[];for(let A=0;A<l.length;A+=1)l[A]>0&&(U[A]=ns(),l[A]-=1);let Y=0;for(const A of Er(B)){const T=A.localName;if(T!=="td"&&T!=="th")continue;for(;U[Y]!==void 0;)Y+=1;const F=ks(A,"colspan",_s),H=ks(A,"rowspan",xc),z=(M+1)*Math.max(c,Y+F);if(z>n)return{outcome:"limit",cells:z};const q=Rh(A,M,Y,t),$=r.intern(q.format);$!==void 0&&(q.cell.fmt=$),U[Y]=q.cell;for(let g=1;g<F;g+=1)U[Y+g]===void 0&&(U[Y+g]=ns());if(H>1)for(let g=0;g<F;g+=1){const p=H-1,C=Y+g;l[C]=l[C]===void 0||l[C]<p?p:l[C]}Y+=F}U.length>c&&(c=U.length),o.push(U),s.push(wa(B,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(B=>{const M=[];for(let j=0;j<c;j+=1){const U=B[j];M.push(U===void 0?ns():U)}return M}),h=kh(e,c),m=h.length===c&&h.every(B=>B!==null)?h.map(B=>B===null?0:B):void 0,b=s.every(B=>B!==null)?s.map(B=>B===null?0:B):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:Fs(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...b===void 0?{}:{rowHeights:b},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Ca=(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=jp(o);return Ah(s,{kind:t,rules:l,options:n,separators:l.separators},r)},fe=(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)}),un=(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),xh=(e,t)=>{if(!un(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(fe({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(fe({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(fe({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(fe({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},nn=(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}))}},dn=(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)}},Yt=(e,t)=>e.row===t.row&&e.col===t.col,ba=(e,t)=>e===void 0?Vl(void 0,void 0,t()):Vl(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)},Qn=(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}),ya=e=>e.isCellReadOnly!==void 0,et=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Th=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],$h=()=>!0,Lh=e=>{const t=new WeakMap,n={};for(const r of Th)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:$h}),n},Dh=/^data-[a-z0-9-]+$/,zh=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Mh=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!zh(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(!Dh.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},Cr=(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},Vn=(e,t)=>{for(const n of t)if(Cr(e,n))return!0;return!1},Nh=(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},Es=(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,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},b=Math.min(u,r-m.row),N=Math.min(h,o-m.col);return b<=0||N<=0?null:fe(m,{row:m.row+b-1,col:m.col+N-1})},Ra=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=Es({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,b=u.endCol-u.startCol+1,N=[];for(let B=0;B<m;B+=l){const M=[];for(let U=0;U<b;U+=c){const Y={row:h.row+B,col:h.col+U};M.push(Y),N.push(Y)}const j=Math.min(l,m-B);for(let U=0;U<j;U+=1){const Y=h.row+B+U,A=e[U];for(let T=0;T<M.length;T+=1){const F=T*c,H=Math.min(c,b-F);for(let z=0;z<H;z+=1)s(Y,h.col+F+z,A[z],M[T])}}}return N},Fh=(e,t,n,r,o)=>{const s=[];return Ra(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},gi=(e,t,n,r,o,s)=>{const l=[],c=Ra(e,t,n,r,o,(u,h,m,b)=>{const N=s(m,u,h,b);N!==null&&l.push({...N,row:u,col:h})});return{edits:l,tiles:c}},va=(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)})`)},Ph=(e,t)=>{va(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},_h=(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(fe({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(fe({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(fe({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(fe({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},qh=(e,t,n,r)=>{va(t,n);const o=wt(t).rows,s=wt(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let b=n.startCol;b<=n.endCol;b+=1){if(m&&b>=t.startCol&&b<=t.endCol)continue;const N=t.startCol+((b-t.startCol)%s+s)%s,B=h*2**21+N;let M=c.get(B);M===void 0&&(M={value:e(h,N),origin:{row:h,col:N}},c.set(B,M)),l.push(r(M.value,M.origin,{row:u,col:b}))}}return l},Sa=(e,t,n)=>{const r=Qn(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:Ot(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=er(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},ka=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Zc(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"],Ih=/^[A-Z]$/,jh=/^[A-Za-z]$/,Hh=/^Key([A-Z])$/,Ea=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"]),Bh=e=>Ih.test(e)||Ea.has(e),Bt=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||!Bh(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}},Wh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Oa=e=>{if(jh.test(e.key))return e.key.toUpperCase();const t=Hh.exec(e.code);return t!==null?t[1]:Ea.has(e.code)?e.code:null},fr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Oa(t)===e.key,be=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ke=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Vh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(be(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(be(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(be(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(be(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Yh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(be(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(be(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},$r=[...Vh(),be("Home","idle","row start (first visible column)"),be("Ctrl+Home","idle","first visible cell"),be("Shift+Home","idle","extend to row start"),be("Ctrl+Shift+Home","idle","extend to first visible cell"),be("End","idle","row end (last visible column)"),be("Ctrl+End","idle","last visible cell"),be("Shift+End","idle","extend to row end"),be("Ctrl+Shift+End","idle","extend to last visible cell"),be("PageUp","both","page up (idle) / commit + page up (editing)"),be("PageDown","both","page down (idle) / commit + page down (editing)"),be("Shift+PageUp","idle","extend one page up"),be("Shift+PageDown","idle","extend one page down"),be("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),be("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),be("Tab","both","cycle right (idle) / commit + cycle right (editing)"),be("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),be("Enter","both","cycle down (idle) / commit + cycle down (editing)"),be("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),be("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),be("F2","both","start editing (idle) / toggle the pointing arm (editing)"),be("F4","editing","cycle the reference anchor under the caret (formula session)"),be("Delete","idle","clear every selected cell"),be("Backspace","idle","clear every selected cell"),be("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),be("Ctrl+A","idle","select all"),be("Ctrl+Z","idle","undo request"),be("Ctrl+Y","idle","redo request"),be("Ctrl+Shift+Z","idle","redo request"),be("Shift+F10","idle","keyboard context menu"),be("ContextMenu","idle","keyboard context menu"),be("Ctrl+Space","idle","column bands"),be("Shift+Space","idle","row bands"),be("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),be("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),be("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),be("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"},...Yh(),ke("bold","Ctrl+B","both","toggle bold"),ke("italic","Ctrl+I","both","toggle italic"),ke("underline","Ctrl+U","both","toggle underline"),ke("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ke("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ke("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ke("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ke("alignLeft","Ctrl+Shift+L","both","align left"),ke("alignCenter","Ctrl+Shift+E","both","align center"),ke("alignRight","Ctrl+Shift+R","both","align right"),ke("formatNumber","Ctrl+Shift+Digit1","both","number format"),ke("formatTime","Ctrl+Shift+Digit2","both","time format"),ke("formatDate","Ctrl+Shift+Digit3","both","date format"),ke("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ke("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ke("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ke("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ke("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ke("borderTop","Alt+Shift+Digit1","idle","top border"),ke("borderRight","Alt+Shift+Digit2","idle","right border"),ke("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ke("borderLeft","Alt+Shift+Digit4","idle","left border"),ke("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ke("insertNote","Shift+F2","idle","insert / edit note"),ke("insertComment","Ctrl+Alt+M","idle","insert comment"),ke("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ke("openValidationList","Alt+ArrowDown","idle","open the validation list"),ke("fillDown","Ctrl+D","idle","fill down"),ke("fillRight","Ctrl+R","idle","fill right"),ke("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ke("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ke("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ke("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ke("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ke("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),ke("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),ke("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),ke("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),ke("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),ke("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],rs=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),wi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Kh=e=>{const t=Bt(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 wi?wi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},mo=(e,t)=>e.column==="both"||e.column===t,Uh=Array.from(new Set($r.filter(e=>!e.rebindable&&mo(e,"idle")).map(e=>e.chord))),go=new Set($r.filter(e=>e.command!==void 0&&mo(e,"editing")).map(e=>e.command)),Xh=new Set($r.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Aa=e=>{const t={};for(const n of Eo)t[n]=e(n);return t},xa=Aa(e=>$r.filter(t=>t.command===e).map(t=>t.chord)),Gh=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},Zh=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(Xh.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`)}}}},Jh=(e,t)=>{const n=Bt(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 $r)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})`)},Qh=e=>{e!==void 0&&Zh(e);const t=Aa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?xa[r]:o===null?[]:o});for(const r of Eo)for(const o of t[r])Jh(r,o);const n=new Map;for(const[r,o]of Gh(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},Ta=(e,t)=>{const n=Oa(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=Wh({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}},em=(e,t)=>{const n=Ta(e,t);return n===null?null:n.command},tm=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])$/,rm=e=>{const t=Bt(e);return t.alt||tm.has(t.key)?!1:t.ctrl||nm.test(t.key)},Ks=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],Ci=[...lt.VIRTUAL_SCROLL_LABEL_KEYS,...Ks],Os=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:"閉じる"})}),$a=Object.freeze({en:Object.freeze({...lt.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Os.en}),ja:Object.freeze({...lt.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Os.ja})}),Sn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,bi=e=>e==="commentCount"||e==="listMore",om=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 ${Sn(t)}`);for(const n of Ks){const r=e[n];if(!(bi(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=bi(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${Sn(r)}`)}}},sm=e=>{const t={};let n=!1;for(const r of lt.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},lm=(e,t,n)=>{e[t]=n},La=(e,t)=>{const n=lt.resolveVirtualScrollLocale(e);if(t===void 0)return $a[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${Sn(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(!Ci.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Ci.join(", ")}`);const s={...lt.resolveVirtualScrollLabels(n,sm(t)),...Os[n]};for(const l of Ks){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&lm(s,l,c)}return om(s),Object.freeze(s)},im=e=>{const t={};for(const n of lt.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Ne=(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},yi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},cm={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},am=(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}`}},os=(e,t)=>{const n=r=>(o,s)=>`${e} ${am(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")})},um=Object.freeze({list:"Value must be one of the list items.",number:os("Value must be a number",yi),textLength:os("Text length must be",yi),date:os("Value must be a date",cm),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}.`}),dm=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} を満たす値を入力してください。`}),ss=Object.freeze({en:um,ja:dm}),fm=Object.freeze({ok:!0}),pm="TRUE",hm="FALSE",mm=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),gm=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),wm=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Cm=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,bm=/^[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])?)+$/,Ri=e=>{const t=e.trim();if(!(wm.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("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,b=m.search(/[^0]/);return b<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(b).replace(/0+$/,""),point:u.length+l-b}},ym=e=>e===1?-1:e===-1?1:0,Rm=(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:ym(n)},vm=(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}},vi=e=>{const t=Cm.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>vm(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Sm=(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},km=(e,t)=>e<t?-1:e>t?1:0,Em=e=>e==="between"||e==="notBetween",Om=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Em(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Am=(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}},ls=(e,t,n,r,o,s)=>{const l=Om(e,t,n,r);return l===null?!0:o===null?!1:Am(e,s(o,l.a),l.b===null?0:s(o,l.b))},xm=e=>Number.isFinite(e)?e:null,Tm=e=>{let t=0;for(const n of e)t+=1;return t},$m=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Lm=(e,t)=>{switch(e.op){case"isEmail":return bm.test(t);case"isUrl":return $m(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)}},Dm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Da=e=>({checked:e.checked===void 0?pm:e.checked,unchecked:e.unchecked===void 0?hm:e.unchecked}),zm=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!mm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Sn(e.op)} for type "${e.type}"`);return;case"text":if(!gm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Sn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${Sn(e.type)}`)}},Mm=(e,t,n)=>{switch(e.type){case"list":return Pm(e).has(t);case"number":return ls(e.op,e.a,e.b,Ri,Ri(t),Rm);case"textLength":return ls(e.op,e.a,e.b,xm,Tm(t),km);case"date":return ls(e.op,e.a,e.b,vi,vi(t),Sm);case"text":return Lm(e,t);case"checkbox":{const r=Da(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Dm(n(e.formula))}},za=(e,t,n)=>(zm(e),t===""||Mm(e,t,n)),Si=e=>e===void 0?void 0:e.trim(),Nm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Si(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(),Si(e.b));case"text":return Fm(e,t.text);case"checkbox":{const n=Da(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},Fm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},ki=new WeakMap,Pm=e=>{const t=ki.get(e);if(t!==void 0)return t;const n=new Set(e.values);return ki.set(e,n),n},Ma=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(ss,n)){const o=Object.keys(ss).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${Sn(n)}`)}return za(e,t,r)?fm:{ok:!1,message:e.errorMessage===void 0?Nm(e,ss[n]):e.errorMessage}},_m=e=>e.type!=="custom",qm=(e,t)=>_m(e)&&!za(e,t,void 0),Na=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Fa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Pa=(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,_a=(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),qa=(e,t)=>Na(e,t),Ia=(e,t)=>Na(e,t),ja=(e,t)=>Fa(e,t),Ha=(e,t)=>Fa(e,t),kn=(e,t,n)=>Pa(e,t,n),En=(e,t,n)=>Pa(e,t,n),Lr=(e,t,n)=>_a(e,t,n),Dr=(e,t,n)=>_a(e,t,n),Im=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Dt=1,br=3,Ur=e=>`${-Math.min(br,Math.max(0,Math.floor(e)))}px`,jm=(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}},Ei=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,Oi=(e,t)=>t===null?e:Math.min(e,t),Ai=e=>e===null?"100%":`min(100%, ${e}px)`,xi=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,Ti=(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]}},$i=Object.freeze([0,-1]),Li=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const u=-c*Dt,h=c*(1+Dt),m=t>=r,b=n<=o,N=m?s:u,B=b?l:h;return B<=u||N>=h?!1:(e.near=Math.max(N,u),e.far=Math.min(B,h),e.nearOpen=!m||N<u,e.farOpen=!b||B>h,!0)},Xr=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),Di=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,zi=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Hm=Object.freeze(["top","right","bottom","left"]),Bm=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Wm=e=>Hm.filter((t,n)=>(e&1<<n)!==0).join(" "),Ba=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Vm=16,Ym=450,Km=e=>e>4?Math.floor(Ym/(5*e)):Vm,pr=(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},Mi=()=>({rowLeft:pr("row","left"),rowRight:pr("row","right"),colAbove:pr("column","above"),colBelow:pr("column","below"),cross:pr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),As=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),Ni="inset(100%)",Un=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Um=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Un([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 m=`translate(${Zr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const b=`translate(${Zr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;b!==s.rowRightTransform&&(s.rowRightTransform=b,e.rowRight.style.transform=b)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Un([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 m=`translate(${t.left}px, ${Zr(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const b=`translate(${t.left}px, ${Zr(t.top+t.height,n.clampHeight)}px)`;b!==s.colBelowTransform&&(s.colBelowTransform=b,e.colBelow.style.transform=b)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Un([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--_aqsp-band-${u})`),(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)}},Fi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Un([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Un([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Un([e.cross],!1))},Jr=e=>{for(const t of As(e))t.remove()},Xm=(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)},Gm=Object.freeze([]),Pi=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},_i=e=>e.chrome[0]??e.active,qi=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)},Zm={left:"0px",right:"0px",width:""},Jm={top:"0px",bottom:"0px",height:""},Ii=()=>({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:[]}),ji=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Hi=6,Qm=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:b,fillFrameRef:N,resizeGuideFrameRef:B,fillHandleNodeRef:M,enableFillHandle:j,frozenCols:U,frozenRows:Y,trailingCols:A,trailingRows:T,sinkAriaLabel:F,sinkReadOnly:H,sinkKeyShortcuts:z,onSinkMouseDown:q,editPaintRef:$,highlightRef:g,frameRange:p,highlightColors:C,popoverAnchors:S,interactiveAnchorRef:O,tipAnchorRef:v})=>{const y=i.useRef(null),a=i.useRef(p);a.current=p;const f=p!==void 0,k=i.useRef(null),d=i.useRef(null),x=i.useRef(new Map(ji.map(R=>[R,Ii()]))),E=i.useCallback(R=>{const L=x.current.get(R);if(L!==void 0)return L;const V=Ii();return x.current.set(R,V),V},[]),D=i.useCallback((R,L,V)=>{if(R===null)return;const _=R.style;_.left!==L.left&&(_.left=L.left),_.right!==L.right&&(_.right=L.right),_.width!==L.width&&(_.width=L.width),_.top!==V.top&&(_.top=V.top),_.bottom!==V.bottom&&(_.bottom=V.bottom),_.height!==V.height&&(_.height=V.height)},[]),W=i.useCallback((R,L,V)=>{if(!(R.bandClampWidth===L&&R.bandClampHeight===V)){R.bandClampWidth=L,R.bandClampHeight=V;for(const _ of R.bandPool)Gr(_,L,V);R.dragBand!==null&&Gr(R.dragBand,L,V)}},[]),P=i.useRef({rowAxis:e,colAxis:t});P.current={rowAxis:e,colAxis:t};const G=i.useCallback((R,L,V)=>{const _=R.dividerSlots[L];_===null||R.dividerShown[L]===V||(R.dividerShown[L]=V,_.style.display=V?"":"none")},[]),X=i.useCallback((R,L,V)=>{const _=R.bandClip;_!==null&&(R.bandClipWidth!==L&&(R.bandClipWidth=L,_.style.width=L),R.bandClipHeight!==V&&(R.bandClipHeight=V,_.style.height=V))},[]),Q=i.useCallback((R,L,V)=>{const _=R.dividerSlots[L];_===null||R.dividerEnd[L]===V||(R.dividerEnd[L]=V,L<2?_.style.bottom=V:_.style.right=V)},[]),re=i.useRef({x:0,y:0}),ie=i.useRef(null),oe=i.useCallback((R,L)=>{const V=n.current,_=V?.getFrozenSize()??Im,Z=V?.getViewportSize(),ne=Z?.width??-1,te=Z?.height??-1,Te=re.current;Te.x=R,Te.y=L;const he=a.current!==void 0,Se=P.current,Ie=he?Se.rowAxis.count:-1,je=he?Se.colAxis.count:-1,de=he?Se.rowAxis.totalSize():-1,ce=he?Se.colAxis.totalSize():-1;let le=ie.current;if(le===null||le.framed!==he||le.rowCount!==Ie||le.colCount!==je||le.rowsTotal!==de||le.colsTotal!==ce||le.frozenCols!==_.cols||le.frozenWidth!==_.width||le.frozenRows!==_.rows||le.frozenHeight!==_.height||le.trailingCols!==_.trailingCols||le.trailingWidth!==_.trailingWidth||le.trailingVisibleWidth!==_.trailingVisibleWidth||le.trailingRows!==_.trailingRows||le.trailingHeight!==_.trailingHeight||le.trailingVisibleHeight!==_.trailingVisibleHeight||le.bodyWidth!==ne||le.bodyHeight!==te){const ae=_.trailingVisibleWidth,xe=_.trailingVisibleHeight,nt=_.cols<=0&&_.trailingCols<=0?[{kind:"m",map:Ee=>Ee-Te.x,clamp:ne,style:Zm,seamLead:!1,seamTrail:!1}]:[..._.cols>0?[{kind:"f",map:Ee=>Ee,clamp:_.width,style:{left:"0px",width:`${_.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ee=>Ee-Te.x-_.width,clamp:Math.max(0,ne-_.width-ae),style:{left:`${_.width}px`,right:`${ae}px`,width:""},seamLead:_.cols>0,seamTrail:_.trailingCols>0},..._.trailingCols>0?[{kind:"t",map:Ee=>Ee-P.current.colAxis.totalSize()+ae,clamp:ae,style:{left:"",right:"0px",width:`${ae}px`},seamLead:!0,seamTrail:!1}]:[]],Ge=_.rows<=0&&_.trailingRows<=0?[{kind:"m",map:Ee=>Ee-Te.y,clamp:te,style:Jm,seamLead:!1,seamTrail:!1}]:[..._.rows>0?[{kind:"f",map:Ee=>Ee,clamp:_.height,style:{top:"0px",height:`${_.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ee=>Ee-Te.y-_.height,clamp:Math.max(0,te-_.height-xe),style:{top:`${_.height}px`,bottom:`${xe}px`,height:""},seamLead:_.rows>0,seamTrail:_.trailingRows>0},..._.trailingRows>0?[{kind:"t",map:Ee=>Ee-P.current.rowAxis.totalSize()+xe,clamp:xe,style:{top:"",bottom:"0px",height:`${xe}px`},seamLead:!0,seamTrail:!1}]:[]],Ze=[];for(const Ee of nt){const Ve=he?Ei(Ee.kind,ce,_.width,_.trailingWidth):null,[Ft,qe]=he?Ti(Ee.kind,je,_.cols,_.trailingCols):$i;for(const Me of Ge){const mn=he?Ei(Me.kind,de,_.height,_.trailingHeight):null,[xo,Zt]=he?Ti(Me.kind,Ie,_.rows,_.trailingRows):$i;Ze.push({nodes:E(`${Ee.kind}${Me.kind}`),xKind:Ee.kind,yKind:Me.kind,mapX:Ee.map,clampWidth:Ee.clamp,xStyle:Ee.style,xSeamLead:Ee.seamLead,xSeamTrail:Ee.seamTrail,xFirst:Ft,xLast:qe,mapY:Me.map,clampHeight:Me.clamp,yStyle:Me.style,ySeamLead:Me.seamLead,ySeamTrail:Me.seamTrail,yFirst:xo,yLast:Zt,cells:{clampWidth:Oi(Ee.clamp,Ve),clampHeight:Oi(Me.clamp,mn)},xCellsSizeCss:Ai(Ve),yCellsSizeCss:Ai(mn),xCellsEndCss:xi(Ve),yCellsEndCss:xi(mn)})}}le={frozenCols:_.cols,frozenWidth:_.width,frozenRows:_.rows,frozenHeight:_.height,trailingCols:_.trailingCols,trailingWidth:_.trailingWidth,trailingVisibleWidth:_.trailingVisibleWidth,trailingRows:_.trailingRows,trailingHeight:_.trailingHeight,trailingVisibleHeight:_.trailingVisibleHeight,bodyWidth:ne,bodyHeight:te,framed:he,rowCount:Ie,colCount:je,rowsTotal:de,colsTotal:ce,ctxs:Ze},ie.current=le}const ye=_.width>0,Re=_.trailingWidth>0,Ce=_.height>0,tt=_.trailingHeight>0;for(const ae of le.ctxs)D(ae.nodes.container,ae.xStyle,ae.yStyle),W(ae.nodes,ae.clampWidth,ae.clampHeight),G(ae.nodes,0,ye),G(ae.nodes,1,Re),G(ae.nodes,2,Ce),G(ae.nodes,3,tt),Q(ae.nodes,0,ae.yCellsEndCss),Q(ae.nodes,1,ae.yCellsEndCss),Q(ae.nodes,2,ae.xCellsEndCss),Q(ae.nodes,3,ae.xCellsEndCss),X(ae.nodes,ae.xCellsSizeCss,ae.yCellsSizeCss);return le.ctxs},[n,E,D,W,G,Q,X]),Oe=i.useCallback((R,L,V)=>{R.dividerSlots[L]=V,R.dividerShown[L]=!1,R.dividerEnd[L]="0px",qi(R)},[]),ze=i.useCallback((R,L)=>{R.frame=L===null?null:{node:L,x:Xr(),y:Xr(),drawnX:Xr(),drawnY:Xr(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},qi(R)},[]),Fe=i.useCallback((R,L)=>{for(const _ of R.bandPool)Jr(_);R.bandPool.length=0,R.dragBand!==null&&(Jr(R.dragBand),R.dragBand=null),R.bandClampWidth=-1,R.bandClampHeight=-1,R.bandClip=L,R.bandClipWidth="",R.bandClipHeight="";const V=L===null?null:L.parentElement;L!==null&&V!==null&&V.firstChild!==L&&V.insertBefore(L,V.firstChild)},[]),_e=i.useCallback(R=>{const L=()=>E(R);return{container:V=>{const _=L();_.container=V,V===null&&(_.fillPool.length=0,_.bandPool.length=0,_.dragBand=null,_.bandClampWidth=-1,_.bandClampHeight=-1)},dividerXLeading:V=>Oe(L(),0,V),dividerXTrailing:V=>Oe(L(),1,V),dividerYLeading:V=>Oe(L(),2,V),dividerYTrailing:V=>Oe(L(),3,V),frame:V=>ze(L(),V),bandClip:V=>Fe(L(),V),active:V=>{L().active=V},dragRect:V=>{L().dragRect=V},marquee:V=>{L().marquee=V},fillPreview:V=>{L().fillPreview=V},resizeGuide:V=>{L().resizeGuide=V}}},[E,Oe,ze,Fe]),Ue=i.useMemo(()=>Object.fromEntries(ji.map(R=>[R,_e(R)])),[_e]),He=Math.min(Math.max(0,U),t.count),zt=qa(t,He),we=Math.min(Math.max(0,Y),e.count),Be=Ia(e,we),it=A===void 0?0:Math.min(Math.max(0,A),t.count-He),dt=ja(t,it),At=T===void 0?0:Math.min(Math.max(0,T),e.count-we),Mt=Ha(e,At),We=i.useRef(null),Ct=i.useRef("add"),On=i.useRef(s);On.current=s;const tr=i.useRef(!1),zr=lt.useWheelBridge(n,{enableBridge:!s}),Oo=i.useCallback(R=>(r.current=R,zr(R)),[r,zr]),se=i.useCallback((R,L)=>({top:L.mapY(e.offsetOf(R.startRow)),bottom:L.mapY(e.offsetOf(R.endRow)+e.sizeOf(R.endRow)),left:L.mapX(t.offsetOf(R.startCol)),right:L.mapX(t.offsetOf(R.endCol)+t.sizeOf(R.endCol))}),[e,t]),pe=i.useCallback((R,L)=>{if(L.clampHeight<=0||L.clampWidth<=0)return null;const{top:V,bottom:_,left:Z,right:ne}=se(R,L),te=-L.clampHeight*Dt,Te=L.clampHeight*(1+Dt),he=-L.clampWidth*Dt,Se=L.clampWidth*(1+Dt);if(_<te||V>Te||ne<he||Z>Se)return null;const Ie=Math.max(V,te),je=Math.max(Z,he);return{top:Ie,left:je,width:Math.min(ne,Se)-je,height:Math.min(_,Te)-Ie}},[se]),ge=i.useCallback((R,L)=>{if(L.clampHeight<=0||L.clampWidth<=0)return null;const V=se(R,L),_=-L.clampHeight*Dt,Z=L.clampHeight*(1+Dt),ne=-L.clampWidth*Dt,te=L.clampWidth*(1+Dt),Te=Math.min(Math.max(V.top,_),Z),he=Math.min(Math.max(V.left,ne),te);return{top:Te,left:he,width:Math.min(Math.max(V.right,ne),te)-he,height:Math.min(Math.max(V.bottom,_),Z)-Te}},[se]),Ut=i.useCallback(()=>{if(g===void 0)return null;const R=g.current;return R.row||R.column||R.intersection?R:null},[g]),Ae=i.useCallback((R,L,V)=>{if(L.bandClip!==null){for(const Z of As(V))L.bandClip.appendChild(Z);return}const _=L.fillPool[0]?.node??_i(L);for(const Z of As(V))R.insertBefore(Z,_)},[]),nr=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),Nt=i.useCallback(R=>{const L=R.nodes.frame;if(L===null)return;const V=nr.current,_=a.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:jm(_,e.count,t.count));const Z=V.within,ne=L.last,te=L.node.style;if(!(Z!==null&&Li(L.x,Z.startCol,Z.endCol,R.xFirst,R.xLast,R.mapX(t.offsetOf(Z.startCol)),R.mapX(t.offsetOf(Z.endCol)+t.sizeOf(Z.endCol)),R.clampWidth)&&Li(L.y,Z.startRow,Z.endRow,R.yFirst,R.yLast,R.mapY(e.offsetOf(Z.startRow)),R.mapY(e.offsetOf(Z.endRow)+e.sizeOf(Z.endRow)),R.clampHeight))){ne.shown&&(ne.shown=!1,te.display="none");return}if(ne.shown||(ne.shown=!0,te.display="block"),!Di(L.x,L.drawnX)){zi(L.drawnX,L.x);const Se=Pi(L.x);Se.start!==ne.left&&(ne.left=Se.start,te.left=Se.start),Se.end!==ne.right&&(ne.right=Se.end,te.right=Se.end),Se.size!==ne.width&&(ne.width=Se.size,te.width=Se.size)}if(!Di(L.y,L.drawnY)){zi(L.drawnY,L.y);const Se=Pi(L.y);Se.start!==ne.top&&(ne.top=Se.start,te.top=Se.start),Se.end!==ne.bottom&&(ne.bottom=Se.end,te.bottom=Se.end),Se.size!==ne.height&&(ne.height=Se.size,te.height=Se.size)}const he=Bm(L.x,L.y);he!==ne.open&&(ne.open=he,he===0?L.node.removeAttribute("data-aqsp-frame-open"):L.node.setAttribute("data-aqsp-frame-open",Wm(he)))},[e,t]),An=i.useCallback((R,L,V,_)=>{const Z=ge(L,V);if(Z===null){Fi(R);return}Um(R,Z,V,_,Fc(L,t.count)||Pc(L,e.count))},[ge,e,t]),fn=i.useCallback((R,L,V,_)=>{const Z=R.nodes.bandPool;for(;Z.length>V.length;){const ne=Z.pop();ne!==void 0&&Jr(ne)}if(_===null){R.nodes.dragBand!==null&&(Jr(R.nodes.dragBand),R.nodes.dragBand=null);return}for(let ne=0;ne<V.length;ne+=1){let te=Z[ne];te===void 0&&(te=Mi(),Gr(te,R.clampWidth,R.clampHeight),Ae(L,R.nodes,te),Z.push(te)),An(te,V[ne],R,_)}},[Ae,An]),xn=i.useCallback((R,L,V)=>{const _=R.nodes.container;if(_===null)return;if(L===null||V===null){R.nodes.dragBand!==null&&Fi(R.nodes.dragBand);return}let Z=R.nodes.dragBand;Z===null&&(Z=Mi(),Gr(Z,R.clampWidth,R.clampHeight),Ae(_,R.nodes,Z),R.nodes.dragBand=Z),An(Z,L,R,V)},[Ae,An]),Xt=i.useCallback((R,L)=>{if(R!==null){if(L===null){R.style.display="none";return}R.style.display="block",R.style.transform=`translate(${L.left}px, ${L.top}px)`,R.style.width=`${L.width}px`,R.style.height=`${L.height}px`}},[]),Tn=i.useCallback((R,L,V,_)=>{const Z=_==="point"?null:Ut();for(const ne of oe(V,L))Xt(ne.nodes.dragRect,pe(R,ne)),xn(ne,R,Z)},[pe,oe,Xt,Ut,xn]),pn=i.useCallback((R,L,V)=>{for(const _ of oe(V,L))Xt(_.nodes.fillPreview,R===null?null:pe(R,_))},[pe,oe,Xt]),$n=i.useCallback((R,L,V)=>{for(const _ of oe(V,L)){const Z=_.nodes.resizeGuide;if(Z===null)continue;if(R===null){Z.style.display="none";continue}const ne=R.anchor==="trailing";if(R.axis==="col"){if(ne&&_.xKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const te=_.mapX(R.position);Z.style.transform=`translate(${ne?Math.max(0,te):te}px, 0px)`,Z.style.width="1px",Z.style.height="100%"}else{if(ne&&_.yKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const te=_.mapY(R.position);Z.style.transform=`translate(0px, ${ne?Math.max(0,te):te}px)`,Z.style.width="100%",Z.style.height="1px"}}},[oe]),Mr=i.useCallback((R,L,V,_,Z,ne,te)=>{if(R===null)return;if(L===null||te<=0||ne<=0){R.style.clipPath=Ni;return}const Te=En(e,L.row,_),he=kn(t,L.col,V),Se=t.sizeOf(L.col),Ie=e.sizeOf(L.row),je=he>=ne||Te>=te,de=L.col>=Z.cols&&he<Z.width,ce=L.row>=Z.rows&&Te<Z.height,le=Z.trailingWidth>0&&L.col<t.count-Z.trailingCols&&he+Se>ne-Z.trailingVisibleWidth,ye=Z.trailingHeight>0&&L.row<e.count-Z.trailingRows&&Te+Ie>te-Z.trailingVisibleHeight;if(je||de||ce||le||ye){R.style.clipPath=Ni;return}R.style.clipPath="",R.style.transform=`translate(${he}px, ${Te}px)`;const Re=`${Se} ${Ie}`;R.dataset.aqspAnchorSig!==Re&&(R.dataset.aqspAnchorSig=Re,R.style.width=`${Se}px`,R.style.height=`${Ie}px`)},[e,t]),Nr=i.useCallback((R,L,V)=>{if(S===void 0)return;const _=S.current,{width:Z,height:ne}=R.getViewportSize(),te=R.getFrozenSize(),Te={scroll:V,frozenCount:te.cols,trailingCount:te.trailingCols,extent:Z},he={scroll:L,frozenCount:te.rows,trailingCount:te.trailingRows,extent:ne};Mr(O===void 0?null:O.current,_.interactive,Te,he,te,Z,ne),Mr(v===void 0?null:v.current,_.tip,Te,he,te,Z,ne)},[S,O,v,Mr]),hn=i.useCallback(()=>{const R=y.current,L=n.current;if(R===null||L===null)return;const V=L.getScrollPosition(),_=Math.max(0,V.y),Z=Math.max(0,V.x),ne=o(),te=oe(Z,_),Te=Ut(),he=Te===null?Gm:ne.ranges.slice(-Km(te.length));for(const ce of te){const le=ce.nodes.container;if(le===null)continue;const ye=ce.nodes.fillPool;for(let Re=0;Re<Math.max(ye.length,ne.ranges.length);Re+=1){let Ce=ye[Re];if(Ce===void 0){const xe=document.createElement("div");xe.className="aqsp-selection-fill",xe.setAttribute("data-aqsp-fill",""),xe.style.display="none",le.insertBefore(xe,_i(ce.nodes)),Ce={node:xe,last:{shown:!1,width:-1,height:-1,transform:""}},ye.push(Ce)}const tt=ne.ranges[Re],ae=tt===void 0?null:pe(tt,ce);if(ae===null)Ce.last.shown&&(Ce.last.shown=!1,Ce.node.style.display="none");else{Ce.last.shown||(Ce.last.shown=!0,Ce.node.style.display="block");const xe=`translate(${ae.left}px, ${ae.top}px)`;xe!==Ce.last.transform&&(Ce.last.transform=xe,Ce.node.style.transform=xe),ae.width!==Ce.last.width&&(Ce.last.width=ae.width,Ce.node.style.width=`${ae.width}px`),ae.height!==Ce.last.height&&(Ce.last.height=ae.height,Ce.node.style.height=`${ae.height}px`)}}for(;ye.length>ne.ranges.length;)ye.pop()?.node.remove();Xt(ce.nodes.active,pe(fe(ne.active,ne.active),ce)),Nt(ce),fn(ce,le,he,Te)}const Se=h(),Ie=Se===null||Se.foreign?null:Se;for(const ce of te){const le=ce.nodes.marquee;if(le===null)continue;const ye=Ie===null?null:pe(Ie.range,ce),Re=ye!==null&&(ce.xSeamTrail&&ye.left>=ce.clampWidth&&ye.left<ce.clampWidth+br||ce.xSeamLead&&ye.left+ye.width<=0&&ye.left+ye.width>-br||ce.ySeamTrail&&ye.top>=ce.clampHeight&&ye.top<ce.clampHeight+br||ce.ySeamLead&&ye.top+ye.height<=0&&ye.top+ye.height>-br)?null:ye;if(Re===null)le.style.display="none";else{le.style.display="block",le.style.transform=`translate(${Re.left}px, ${Re.top}px)`,le.style.width=`${Re.width}px`,le.style.height=`${Re.height}px`;const ae=Ur(Re.top),xe=Ur(Re.left),nt=Ur(ce.cells.clampHeight-(Re.top+Re.height)),Ge=Ur(ce.cells.clampWidth-(Re.left+Re.width)),Ze=`${ae} ${Ge} ${nt} ${xe}`;Ze!==le.dataset.aqspOutsetSig&&(le.dataset.aqspOutsetSig=Ze,le.style.setProperty("--aqsp-clip-outset-top",ae),le.style.setProperty("--aqsp-clip-outset-right",Ge),le.style.setProperty("--aqsp-clip-outset-bottom",nt),le.style.setProperty("--aqsp-clip-outset-left",xe))}const Ce=Re===null?null:Ie?.kind??null,tt=le.dataset.aqspClipKindLast??null;Ce!==tt&&(Ce===null?(delete le.dataset.aqspClipKindLast,le.removeAttribute("data-aqsp-clip-kind")):(le.dataset.aqspClipKindLast=Ce,le.setAttribute("data-aqsp-clip-kind",Ce)))}We.current!==null&&Tn(We.current,_,Z,Ct.current),d.current!==null&&$n(d.current,_,Z),k.current!==null&&pn(k.current,_,Z);const je=M.current;if(je!==null&&!b()){const{width:ce,height:le}=L.getViewportSize(),ye=ne.ranges[ne.ranges.length-1];if(!(ne.ranges.length===1&&!On.current&&!m())||le<=0||ce<=0)je.style.display="none";else{const Ce=L.getFrozenSize(),tt={scroll:Z,frozenCount:Ce.cols,trailingCount:Ce.trailingCols,extent:ce},ae={scroll:_,frozenCount:Ce.rows,trailingCount:Ce.trailingRows,extent:le},xe=ye.endCol<Ce.cols,nt=ye.endRow<Ce.rows,Ge=ye.endCol>=t.count-Ce.trailingCols,Ze=ye.endRow>=e.count-Ce.trailingRows,Ee=kn(t,ye.endCol,tt)+t.sizeOf(ye.endCol),Ve=En(e,ye.endRow,ae)+e.sizeOf(ye.endRow),Ft=xe||Ge?0:Ce.width,qe=nt||Ze?0:Ce.height,Me=Ge?ce:ce-Ce.trailingVisibleWidth,mn=Ze?le:le-Ce.trailingVisibleHeight;Ve<=qe||Ve>mn||Ee<=Ft||Ee>Me?je.style.display="none":(je.style.display="block",je.style.transform=`translate(${Ee-Hi+1}px, ${Ve-Hi+1}px)`)}}const de=r.current;if(de!==null){const ce=ne.active,{width:le,height:ye}=L.getViewportSize(),Re=L.getFrozenSize(),Ce={scroll:Z,frozenCount:Re.cols,trailingCount:Re.trailingCols,extent:le},tt={scroll:_,frozenCount:Re.rows,trailingCount:Re.trailingRows,extent:ye},ae=En(e,ce.row,tt),xe=kn(t,ce.col,Ce),nt=ye>0?Math.min(Math.max(ae,0),Math.max(0,ye-1)):0,Ge=le>0?Math.min(Math.max(xe,0),Math.max(0,le-1)):0;de.style.top=`${nt}px`,de.style.left=`${Ge}px`,On.current?(de.style.width=`${t.sizeOf(ce.col)}px`,de.style.height=`${e.sizeOf(ce.row)}px`,de.style.paddingTop=`${Xm(e.sizeOf(ce.row),$===void 0?Ht:$.current)}px`):(de.style.width="1px",de.style.height="1px",de.style.paddingTop="0px");const Ze=ce.col>=Re.cols&&xe<Re.width,Ee=ce.row>=Re.rows&&ae<Re.height,Ve=Re.trailingWidth>0&&ce.col<t.count-Re.trailingCols&&xe+t.sizeOf(ce.col)>le-Re.trailingVisibleWidth,Ft=Re.trailingHeight>0&&ce.row<e.count-Re.trailingRows&&ae+e.sizeOf(ce.row)>ye-Re.trailingVisibleHeight,qe=On.current&&ae===nt&&xe===Ge&&!Ze&&!Ee&&!Ve&&!Ft;qe!==tr.current&&(tr.current=qe,qe?de.setAttribute("data-aqsp-editing",""):de.removeAttribute("data-aqsp-editing"))}Nr(L,_,Z)},[n,pe,oe,Xt,Tn,$n,pn,h,o,m,b,M,r,e,t,Ut,fn,Nt,$,Nr]),Ln=i.useCallback((R,L)=>{We.current=R,Ct.current=L;const V=R===null?"add":L;for(const ne of oe(0,0)){const te=ne.nodes.dragRect;if(te===null)continue;const Te=te.dataset.aqspDragModeLast??"add";V!==Te&&(te.dataset.aqspDragModeLast=V,V==="add"?te.removeAttribute("data-aqsp-drag-mode"):te.setAttribute("data-aqsp-drag-mode",V))}const _=n.current;if(R===null||_===null){for(const ne of oe(0,0))ne.nodes.dragRect!==null&&(ne.nodes.dragRect.style.display="none"),xn(ne,null,null);return}const Z=_.getScrollPosition();Tn(R,Math.max(0,Z.y),Math.max(0,Z.x),L)},[n,Tn,oe,xn]),rr=i.useCallback(R=>{k.current=R;const L=n.current;if(L===null){for(const _ of oe(0,0))_.nodes.fillPreview!==null&&(_.nodes.fillPreview.style.display="none");return}const V=L.getScrollPosition();pn(R,Math.max(0,V.y),Math.max(0,V.x))},[n,pn,oe]),or=i.useCallback(R=>{d.current=R;const L=n.current;if(L===null){for(const _ of oe(0,0))_.nodes.resizeGuide!==null&&(_.nodes.resizeGuide.style.display="none");return}const V=L.getScrollPosition();$n(R,Math.max(0,V.y),Math.max(0,V.x))},[n,$n,oe]);i.useLayoutEffect(()=>{const R=y.current;if(!(R===null||C===void 0))return R.style.setProperty("--aqsp-band-row",C.row),R.style.setProperty("--aqsp-band-column",C.column),R.style.setProperty("--aqsp-band-intersection",C.intersection),R.style.setProperty("--aqsp-band-opacity",String(C.opacity)),()=>{R.style.removeProperty("--aqsp-band-row"),R.style.removeProperty("--aqsp-band-column"),R.style.removeProperty("--aqsp-band-intersection"),R.style.removeProperty("--aqsp-band-opacity")}},[C]),i.useEffect(()=>(c.current=hn,u.current=Ln,N.current=rr,B.current=or,()=>{c.current=null,u.current=null,N.current=null,B.current=null})),i.useEffect(()=>{hn()},[hn,s,He,we,it,At]),i.useEffect(()=>{const R=r.current;if(R===null)return;const L=V=>q(V);return R.addEventListener("mousedown",L),()=>R.removeEventListener("mousedown",L)},[r,q]);const Gt=He>0||it>0?[...He>0?[{k:"f",style:{left:0,width:zt}}]:[],{k:"s",style:{left:zt,right:dt}},...it>0?[{k:"t",style:{right:0,width:dt}}]:[]]:[{k:"m",style:{left:0,right:0}}],Xe=we>0||At>0?[...we>0?[{k:"f",style:{top:0,height:Be}}]:[],{k:"s",style:{top:Be,bottom:Mt}},...At>0?[{k:"t",style:{bottom:0,height:Mt}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Dn=R=>R==="m"?0:R==="s"?1:R==="t"?2:3,Ao=Gt.flatMap(R=>Xe.map(L=>({xk:R.k,yk:L.k,key:`${R.k}${L.k}`,style:{...R.style,...L.style}}))).sort((R,L)=>Dn(R.key[0])+Dn(R.key[1])-(Dn(L.key[0])+Dn(L.key[1]))),ft=R=>R==="mm"?{"data-aqsp-overlay-main":""}:R==="fm"?{"data-aqsp-overlay-frozen":""}:R==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:y,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[Ao.map(({xk:R,yk:L,key:V,style:_})=>{const Z=Ue[V];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":V,...ft(V),style:_,ref:Z.container,children:[f?K.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:Z.bandClip}):null,R==="s"&&He>0?K.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:Z.dividerXLeading}):null,R==="s"&&it>0?K.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:Z.dividerXTrailing}):null,L==="s"&&we>0?K.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:Z.dividerYLeading}):null,L==="s"&&At>0?K.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:Z.dividerYTrailing}):null,f?K.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:Z.frame}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:Z.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:Z.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:Z.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:Z.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:Z.resizeGuide})]},V)}),K.jsx("textarea",{ref:Oo,className:"aqsp-sink","aria-label":F,"aria-readonly":H?"true":void 0,"aria-keyshortcuts":z,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),j?K.jsx("div",{ref:M,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Wa=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=b=>{l.current=!0;try{b()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=b=>{if(b.key==="Escape"){b.preventDefault(),c(e.close);return}b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&!b.altKey&&!b.shiftKey&&(b.preventDefault(),u())},m=b=>{l.current||b.relatedTarget instanceof Node&&b.currentTarget.contains(b.relatedTarget)||e.rejected||c(e.close)};return K.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:[K.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[Ne(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Ne(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(b=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":b.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:b.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:b.createdAt,children:b.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:b.text})]},b.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Ne(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:b=>r(b.currentTarget.value),onKeyDown:h}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:Ne(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Va=({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(),u=i.useRef(!1),h=o.trim()===""?null:an(o),m=o.trim()!==""&&h===null,b=j=>{u.current=!0;try{j()}finally{u.current=!1}},N=()=>{l||m||b(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},B=j=>{if(j.key==="Escape"){j.preventDefault(),b(e.close);return}j.key==="Enter"&&!j.altKey&&!j.shiftKey&&(j.preventDefault(),N())},M=j=>{u.current||j.relatedTarget instanceof Node&&j.currentTarget.contains(j.relatedTarget)||e.rejected||b(e.close)};return K.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:M,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Ne(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Ne(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:j=>r(j.currentTarget.value),onKeyDown:B})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Ne(t,"linkUrlField")}),K.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:j=>s(j.currentTarget.value),onKeyDown:B})]}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:N,children:Ne(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:Ne(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>b(e.close),children:"×"})]})]})},Bi=500,Ya=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),u=i.useMemo(()=>{const Y=n.toLowerCase();return e.current.filter(A=>A.toLowerCase().startsWith(Y))},[e.current,n]),h=i.useMemo(()=>u.length>Bi?u.slice(0,Bi):u,[u]),m=u.length-h.length,b=h.length===0?-1:Math.min(o,h.length-1),N=Y=>{c.current=!0;try{Y()}finally{c.current=!1}},B=()=>{b<0||N(()=>e.commit(h[b]))},M=Y=>{if(Y.key==="Escape"){Y.preventDefault(),N(e.close);return}if(Y.key==="Enter"){Y.preventDefault(),B();return}if(Y.key==="ArrowDown"){Y.preventDefault(),s(b+1);return}Y.key==="ArrowUp"&&(Y.preventDefault(),s(Math.max(b-1,0)))},j=Y=>{c.current||Y.relatedTarget instanceof Node&&Y.currentTarget.contains(Y.relatedTarget)||N(e.close)},U=Y=>`${l}-${Y}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:j,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Ne(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":b<0?void 0:U(b),value:n,onChange:Y=>{r(Y.currentTarget.value),s(0)},onKeyDown:M}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Ne(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Ne(t,"listEmpty")}):h.map((Y,A)=>K.jsx("div",{className:"aqsp-popover-option",id:U(A),role:"option",tabIndex:-1,"aria-selected":A===b,"data-aqsp-list-option":Y,onPointerDown:T=>T.preventDefault(),onClick:()=>N(()=>e.commit(Y)),children:Y},U(A))),m>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Ne(t,"listMore",m)}):null]})]})},Ka=({ctx:e,labels:t})=>K.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),K.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ua=({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(),u=i.useRef(!1),h=M=>{u.current=!0;try{M()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},b=()=>{r!==n&&!s?m():h(e.close)},N=M=>{if(M.key==="Escape"){M.preventDefault(),e.rejected?h(e.close):b();return}M.key==="Enter"&&(M.ctrlKey||M.metaKey)&&!M.altKey&&!M.shiftKey&&(M.preventDefault(),m())},B=M=>{u.current||M.relatedTarget instanceof Node&&M.currentTarget.contains(M.relatedTarget)||e.rejected||b()};return K.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:B,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:Ne(t,"noteTitle")}),K.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}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Ne(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:Ne(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},Xa=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),It=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")}),Wi=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Ga=Object.freeze({all:It(Wi),values:It(["text"]),formats:It(["format","borders","cf"]),formulas:It(["text","formula"]),noBorders:It(Wi.filter(e=>e!=="borders")),columnWidths:It(["sizes"]),validation:It(["validation"]),conditionalFormats:It(["cf"]),commentsAndNotes:It(["note","comments"])}),Vi=Object.freeze({mode:"all"}),xs=Object.freeze({t:""}),Yi=Object.freeze({row:1<<30,col:1<<30}),eg=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),tg=e=>e.t===""&&e.f===void 0,ng=e=>e.length>1&&e.startsWith("="),rg=(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}},Ki=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,og=(e,t,n,r)=>{const o=ng(e),s=e===""?"0":gt(e);if(!o&&s===null)return null;const l=eg[n];if(t.f!==void 0){const h=Tr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Ki(Number(s));const c=gt(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Ki(rg(Number(s),u,n))},Ui=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),sg=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:Ui(e.start),end:Ui(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}}}},lg=e=>{const t=Tr(e,Yi),n=xr(t);let r="",o=0,s=!1;for(const l of n){const c=sg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${on(c)}`,o=l.end,s=!0)}return s?vo(`${r}${t.slice(o)}`,Yi):e},ig=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return xs;const o=r[n];return o===void 0?xs:o},cg=e=>{const{rows:t,cols:n}=e,r=Gc(lg);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 u=[];for(let h=0;h<t;h+=1){const m=ig(e,h,c);let b=m;if(m.f!==void 0){const N=r(m.f);b=N===m.f?m:{...m,f:N}}(b!==m||m===xs)&&(o=!1),u.push(b)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.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}},ag=(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,ug=(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},Xi=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)ag(m,t)?(h.push(ug(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h: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},Gi=new WeakMap,Za=e=>{const t=Gi.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>Ot(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:Ot({...s,borders:void 0})),o={canonical:n,borderless:r};return Gi.set(e,o),o},wo=(e,t)=>t===void 0?void 0:e[t],dg=(e,t,n,r)=>{const o=Za(e);if(n){const h=wo(o.canonical,t.fmt);return h===void 0?null:h}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 u=Ot(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},fg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?og(n.readText(),o,r,n):o.f===void 0?o.t:Tr(o.f,n)},Zi=(e,t,n,r,o)=>{const s=Ga[r.mode];if(r.skipBlanks===!0&&tg(e))return null;const l={};let c=!1;if(s.text){const u=fg(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=dg(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=wo(Za(t).canonical,e.fmt);u!==void 0&&(l.format=u,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 u=wo(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},Ji=(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}}),pg=["text/html","text/plain"],hg=(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},mg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,gg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,wg=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}}},Qi=e=>{const t=e.clipboardData;return t??null},Cg=(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}},bg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Cg(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},yg=(e,t,n,r,o)=>{const s=Qn(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 u=t.intern(c);u!==void 0&&(l.fmt=u)}}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:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=er(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},Ja=(e,t)=>{const n=Nc(),r=gf(),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(yg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:bg(e.getConditionalFormats(),t)}},ec=e=>e.kind==="cut"?{...e.payload,...Ja(e.sourceAdapter,e.range)}:e.payload,Rg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:Fs(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),vg=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=an(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Sg=(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},kg=(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 fe({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Eg=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(A=>{const T=n.current;if(T===null||A==="format"||A==="annotate")return;const F=r.current;F==="own"||F==="foreign"&&T.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const A=n.current;if(A===null)return;if(A.kind==="copy"){o();return}const T=t.current;T.repaintOverlay(),T.onClipChange?.({kind:"cut",range:A.range,foreign:A.sourceAdapter!==T.adapter})},[o]),c=i.useCallback((A,T,F)=>{const H=t.current;n.current={kind:A,range:T,clipId:F.clipId,sourceAdapter:H.adapter,payload:F},H.repaintOverlay(),H.onClipChange?.({kind:A,range:T,foreign:!1})},[]),u=i.useCallback(A=>{const T=t.current,F=T.adapter,H=wt(A),z={v:1,rows:H.rows,cols:H.cols,clipId:Fs(),...Ja(F,A),wholeRows:Fc(A,F.colCount),wholeCols:Pc(A,F.rowCount)};if(T.resize!==void 0){if(z.wholeCols){const q=[];for(let $=A.startCol;$<=A.endCol;$+=1)q.push(Math.min(T.resize.colAxis.sizeOf($),cn));z.colWidths=q}if(z.wholeRows){const q=[];for(let $=A.startRow;$<=A.endRow;$+=1)q.push(Math.min(T.resize.rowAxis.sizeOf($),cn));z.rowHeights=q}}return z},[]),h=i.useCallback((A,T)=>{const F=t.current,H=F.getSelection(),z=H.ranges[H.ranges.length-1],q=mt([z]);if(q>F.maxOperationCells)return A.preventDefault(),F.onOperationRejected?.(T,q,"limit"),null;if(T==="cut"&&Cr(F.adapter,z))return A.preventDefault(),F.rejectReadOnly({kind:"operation",op:"cut",cellCount:q}),null;H.ranges.length>1&&F.onCopyMultiRange?.();const $=u(z),g=kc($),p=Qi(A);return p!==null&&(p.setData("text/plain",Vt.serializeClipboardTsv($.cells.map(C=>C.map(S=>S.t)))),p.setData("text/html",ha($,g)),p.setData(po,g)),A.preventDefault(),{payload:$,range:z}},[u]),m=i.useCallback((A,T)=>t.current.commitPaste(A,T)!==null,[]),b=i.useCallback((A,T,F)=>{const H=t.current;if(!F.sizes||H.resize===void 0)return;const{rowAxis:z,colAxis:q,resizeTracks:$}=H.resize;if($===void 0)return;const g=(p,C,S)=>{const O=Ds(C,S,null,{maxOperationCells:H.maxOperationCells,rowHiddenLimit:$s,axisKind:p});if(!O.ok){H.onOperationRejected?.("resize",O.count,O.reason);return}$(p,O.entries)};if(A.colWidths!==void 0){const p=[];for(let C=T.startCol;C<=T.endCol;C+=1)p.push({index:C,size:A.colWidths[(C-T.startCol)%A.cols]});g("col",q,p)}if(A.rowHeights!==void 0){const p=[];for(let C=T.startRow;C<=T.endRow;C+=1)p.push({index:C,size:A.rowHeights[(C-T.startRow)%A.rows]});g("row",z,p)}},[]),N=i.useCallback((A,T)=>{const F=t.current,H=F.adapter,z=A.payload,q={row:T.startRow,col:T.startCol},$=z.rows*z.cols+mt([A.range]);if($>F.maxOperationCells)return F.onOperationRejected?.("paste",$,"limit"),"rejected";if(q.row+z.rows>H.rowCount||q.col+z.cols>H.colCount||A.range.endRow>=A.sourceAdapter.rowCount||A.range.endCol>=A.sourceAdapter.colCount)return F.onOperationRejected?.("paste",$,"bounds"),"rejected";const g=Es({rows:z.rows,cols:z.cols},fe(q,q),q,H.rowCount,H.colCount);if(g!==null&&Cr(H,g))return F.rejectReadOnly({kind:"operation",op:"paste",cellCount:z.rows*z.cols}),"rejected";if(Cr(A.sourceAdapter,A.range))return F.rejectReadOnly({kind:"operation",op:"cut",cellCount:mt([A.range])}),"rejected";const p=ec(A),C=uo(H),S=Xi(p,C),O={row:0,col:0,readText:()=>Qn(H,O.row,O.col).text,readFormat:()=>H.getCellFormat===void 0?void 0:H.getCellFormat(O.row,O.col)},{edits:v,tiles:y}=gi(S.cells,fe(q,q),q,H.rowCount,H.colCount,(k,d,x)=>(O.row=A.range.startRow+(d-q.row),O.col=A.range.startCol+(x-q.col),Zi(k,S,O,Vi,C))),a=uo(A.sourceAdapter),f=[];if(nn([A.range],k=>{f.push(Sg(k.row,k.col,a))}),A.sourceAdapter===H){if(!m([...f,...v],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const k=F.commitPaste(v,{sameSheet:!1,conditionalFormats:Ji(S.conditionalFormats,y)});if(k===null)return"rejected";try{A.sourceAdapter.applyEdits(f,{transaction:k,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){F.onEditRejected?.(d,{source:"paste"})}}return F.setSelection({ranges:[fe(q,{row:q.row+p.rows-1,col:q.col+p.cols-1})],anchor:q,active:q}),"applied"},[m]),B=i.useCallback((A,T,F)=>{const H=t.current,z=H.adapter,q=G=>(H.onClipboardUnavailable?.(G),"rejected"),$=Ac(A,T);if($==="none")return T==="menu"?q("empty"):"empty";const g=H.getSelection(),p=g.ranges[g.ranges.length-1],C=F.transpose===!0,S=(G,X)=>{const Q=hg(C?X:G,C?G:X,p);return Q>H.maxOperationCells?(H.onOperationRejected?.("paste",Q,"limit"),!0):!1};let O,v=null;if($==="aqsp"){const G=Hd(A,T);if(G===null)return q("unreadable");const X=n.current;if(X!==null&&G.clipId===X.clipId&&(v=X),v!==null&&v.kind==="cut"&&mg(F))return N(v,p);if(S(G.rows,G.cols))return"rejected";if(v!==null){if(v.kind==="cut"&&(v.range.endRow>=v.sourceAdapter.rowCount||v.range.endCol>=v.sourceAdapter.colCount))return H.onOperationRejected?.("paste",v.payload.rows*v.payload.cols,"bounds"),"rejected";O=ec(v)}else{const Q=Bd(A,T);if(Q===null)return q("unreadable");if(S(Q.rows,Q.cols))return"rejected";O=vg(Q)}}else if($==="tsv"){const G=A.getData("text/plain"),X=Vt.measureTsv(G);if(S(X.rows,X.cols))return"rejected";O=Rg(Vt.parseTsv(G))}else{const G=A.getData("text/html"),X=mf(G);if(X.cols===0&&X.rows>H.maxOperationCells)return H.onOperationRejected?.("paste",X.rows,"limit"),"rejected";if(S(X.rows,X.cols))return"rejected";const Q=Ca(G,$,H.formats===void 0?{}:{currency:H.formats.currency,locale:H.formats.locale},H.maxOperationCells);if(Q.outcome==="none")return q("unreadable");if(Q.outcome==="limit")return H.onOperationRejected?.("paste",Q.cells,"limit"),"rejected";if(S(Q.payload.rows,Q.payload.cols))return"rejected";O=Q.payload}const y=uo(z),a=Xi(C?cg(O):O,y),f=Ga[F.mode];if(gg(f)){const G=Es({rows:a.rows,cols:a.cols},p,g.active,z.rowCount,z.colCount);if(G!==null&&Cr(z,G))return H.rejectReadOnly({kind:"operation",op:"paste",cellCount:mt([G])}),"rejected"}const k={row:0,col:0,readText:()=>Qn(z,k.row,k.col).text,readFormat:()=>z.getCellFormat===void 0?void 0:z.getCellFormat(k.row,k.col)},{edits:d,tiles:x}=gi(a.cells,p,g.active,z.rowCount,z.colCount,(G,X,Q)=>(k.row=X,k.col=Q,Zi(G,a,k,F,y))),E=kg(x,a.rows,a.cols,z.rowCount,z.colCount);if(E===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let G=0;for(const Q of a.conditionalFormats)G+=Q.ranges.length;const X=x.length*G;if(X>H.maxOperationCells)return H.onOperationRejected?.("paste",X,"limit"),"rejected"}const D=f.cf?Ji(a.conditionalFormats,x):[];if(d.length===0&&D.length===0)return b(a,E,f),"empty";r.current=v===null?"foreign":"own";let W=!1;try{W=m(d,{sameSheet:v!==null&&v.sourceAdapter===z,conditionalFormats:D})}finally{r.current="none"}if(!W)return"rejected";b(a,E,f);const P={row:E.startRow,col:E.startCol};return H.setSelection({ranges:[E],anchor:P,active:P}),"applied"},[N,m,b]),M=i.useCallback(async A=>{const T=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),F=navigator;if(F.clipboard===void 0)return T("insecure-origin");let H;try{H=await F.clipboard.read({unsanitized:["text/html"]})}catch{return T("permission-denied")}if(H.length===0)return T("empty");const z=H[0],q=Array.from(z.types),$=new Map;try{for(const C of pg)q.includes(C)&&$.set(C,await(await z.getType(C)).text())}catch{return T("unreadable")}const g={types:q,getData:C=>{const S=$.get(C);if(S===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return S}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":B(g,"menu",A)},[B]),j=i.useCallback(async A=>{const T=await M(A);return t.current.onPasteResolved?.(T,"menu"),T},[M]),{enabled:U,sinkRef:Y}=e;return i.useEffect(()=>{const A=Y.current;if(!U||A===null)return;const T=q=>t.current.isDragging()?(q.preventDefault(),!0):!1,F=q=>{const $=t.current;if(T(q)||$.isEditing())return;const g=h(q,"copy");g!==null&&c("copy",g.range,g.payload)},H=q=>{const $=t.current;if(T(q)||$.isEditing())return;const g=h(q,"cut");g!==null&&c("cut",g.range,g.payload)},z=q=>{const $=t.current;if(T(q)||$.isEditing())return;q.preventDefault();let g=Vi;const p=$.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(g=p.current,p.current=null);const C=Qi(q);if(C===null)return;const S=B(wg(C),"event",g);$.onPasteResolved?.(S,"event")};return A.addEventListener("copy",F),A.addEventListener("cut",H),A.addEventListener("paste",z),()=>{A.removeEventListener("copy",F),A.removeEventListener("cut",H),A.removeEventListener("paste",z)}},[U,Y,h,c,B]),i.useMemo(()=>({getClip:()=>{const A=n.current;return A===null?null:{kind:A.kind,range:A.range,foreign:A.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:j}),[o,s,l,j])},Qa=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)}`)},eu=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}},tc=(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}`}`},tu=(e,t)=>{let n;if(e.exponent===null)n=tc(e.negative,e.digits,e.point+t);else{const r=tc(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return gt(n)===null?null:n},Og=(e,t)=>{Qa(t);const n=gt(e);return n===null?null:tu(eu(n),t)},Ag=e=>{const t=gt(e);if(t!==null){const r=eu(t);return tu({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},nu=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)},xg=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},ru=(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 xg(r)?r:null},Tg=(e,t)=>{Qa(t);const n=nu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=ru(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},$g=e=>{const t=nu(e),n=ru(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},hr=(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"},nc={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"}},Lg={down:"fillDown",right:"fillRight",selection:"fillSelection"},Dg={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},Sr=e=>e<10?`0${e}`:String(e),zg=e=>{const t=new Date(e);return`${t.getFullYear()}-${Sr(t.getMonth()+1)}-${Sr(t.getDate())}`},Mg=e=>{const t=new Date(e);return`${Sr(t.getHours())}:${Sr(t.getMinutes())}:${Sr(t.getSeconds())}`},Ng=(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),Fg=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Pg=e=>e===void 0||e.borders===void 0?{}:e.borders,_g={top:1,right:2,bottom:4,left:8},qg={style:"thin",color:zs},Ig=(e,t)=>{if(e===void 0)return!1;const n=st(e);return n!==null&&n===st(t)},jg=(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}}},Hg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const p=g.getActive();return[fe(p,p)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,p=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(g=>{const p=t.current,C=n();if(!hr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Vn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:mt(C)}),!1;const S=new Map,O=[],v=p.adapter.getCellFormat;for(const y of C)nn([y],a=>{const f=v===void 0?void 0:v(a.row,a.col),{bucket:k,patch:d}=g(a,y,f);let x=S.get(k);x===void 0&&(x=new Map,S.set(k,x));let E;x.has(f)?E=x.get(f):(E=Ns(f,d),x.set(f,E)),E!==f&&O.push({row:a.row,col:a.col,format:E===void 0?null:E})});return O.length===0?!0:p.commitEdits(O,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:g,state:p}))},[]),c=i.useCallback((g,p=qg)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=g==="outer"?15:_g[g];return o((S,O,v)=>{const y=Ng(S,O)&C;return{bucket:y,patch:{borders:{...Pg(v),...Fg(y,p)}}}})},[s,o]),u=i.useCallback((g,p,C)=>{const S=Sa(t.current.adapter,g.row,g.col);for(const O of p)C.push(ka(S,g,O))},[]),h=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const S=[],O=[],v=[];if(g==="selection"){const a=C.active,f=[];nn(C.ranges,k=>{(k.row!==a.row||k.col!==a.col)&&f.push(k)}),S.push({source:a,targets:f}),O.push(fe(a,a));for(const k of C.ranges)v.push(...xh(k,a))}else for(const a of C.ranges)if(g==="down"){const f=a.startRow===a.endRow;if(f&&a.startRow===0)continue;const k=f?a.startRow-1:a.startRow,d=f?a.startRow:a.startRow+1;O.push(fe({row:k,col:a.startCol},{row:k,col:a.endCol})),v.push(fe({row:d,col:a.startCol},{row:a.endRow,col:a.endCol}));for(let x=a.startCol;x<=a.endCol;x+=1){const E=[];for(let D=d;D<=a.endRow;D+=1)E.push({row:D,col:x});S.push({source:{row:k,col:x},targets:E})}}else{const f=a.startCol===a.endCol;if(f&&a.startCol===0)continue;const k=f?a.startCol-1:a.startCol,d=f?a.startCol:a.startCol+1;O.push(fe({row:a.startRow,col:k},{row:a.endRow,col:k})),v.push(fe({row:a.startRow,col:d},{row:a.endRow,col:a.endCol}));for(let x=a.startRow;x<=a.endRow;x+=1){const E=[];for(let D=d;D<=a.endCol;D+=1)E.push({row:x,col:D});S.push({source:{row:x,col:k},targets:E})}}for(const a of S)for(const f of a.targets)if(et(p.adapter,f.row,f.col))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(v),gesture:Lg[g],sources:O,targets:v}),!1;const y=[];for(const a of S)u(a.source,a.targets,y);return y.length===0?!0:p.commitEdits(y,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const g=t.current,p=g.getSessionText();if(p===null)return!1;const C=g.getSelection();if(!hr("fill",C.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(Vn(g.adapter,C.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(C.ranges),gesture:"fillSelection",sources:[],targets:C.ranges}),!1;const S=[];let O=!1;return nn(C.ranges,v=>{if(!O){if(!g.validateCommit(v,p).ok){O=!0;return}S.push({row:v.row,col:v.col,text:p})}}),O||g.commitEdits(S,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),b=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Vn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:mt(C.ranges)}),!1;const S=[],O=p.adapter;return nn(C.ranges,v=>{const y=O.getCellFormula===void 0?void 0:O.getCellFormula(v.row,v.col),a=y===void 0?g.text(O.getCellText(v.row,v.col)):g.formula(y);a!==null&&S.push({row:v.row,col:v.col,text:a})}),S.length===0?!0:p.commitEdits(S,{source:"calc"})!==null},[]),N=i.useCallback((g,p)=>{const C=t.current,S=C.resizeTracks;if(S===void 0)return!1;const O=g==="row"?C.rowAxis:C.colAxis,v=C.getSelection(),y=g==="row"?Math.floor(C.maxOperationCells/Ls):C.maxOperationCells;let a=0;for(const E of v.ranges)a+=g==="row"?E.endRow-E.startRow+1:E.endCol-E.startCol+1;if(a>y)return C.onOperationRejected?.("resize",a,"limit"),!1;const f=new Set,k=[],d=p?0:g==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const E of v.ranges){const D=g==="row"?E.startRow:E.startCol,W=g==="row"?E.endRow:E.endCol;for(let P=D;P<=W;P+=1){if(f.has(P))continue;f.add(P),O.sizeOf(P)===0!==p&&k.push({index:P,size:d})}}const x=Ds(O,k,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:$s,axisKind:g});return x.ok?(x.entries.length>0&&S(g,x.entries),!0):(C.onOperationRejected?.("resize",x.count,x.reason),!1)},[]),B=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const p=g.getActive();return er(g.adapter.getCellHyperlink(p.row,p.col))},[]),M=i.useCallback(g=>{const p=t.current,C=p.adapter,S=nc[g],O=C.getCellFormat!==void 0,v=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(S.kind){case"resize":return p.trackResize!==void 0;case"hide":return p.resizeTracks!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return O;case"value":return O&&(S.value!=="currency"||p.formats!==void 0);case"popover":switch(S.popover){case"link":return C.getCellHyperlink!==void 0&&v("link");case"note":return C.getCellNote!==void 0&&v("note");case"comment":return C.getCellComments!==void 0&&v("comment");default:return C.getCellValidation!==void 0&&v("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(p.onHyperlinkOpen!==void 0?B()!==void 0:v("link"));case"paste":return S.options.mode==="formats"?O:S.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[B]),j=i.useCallback(g=>{const p=t.current,C=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const S=p.getActive();if(!et(p.adapter,S.row,S.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:S,editSession:"none"}),!1;let O;if(C==="link")O=B()!==void 0;else if(C==="note"){const v=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(S.row,S.col);O=v!==void 0&&v!==""}else{const v=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(S.row,S.col);O=v!==void 0&&v.length>0}return O?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[B]),U=i.useCallback((g,p,C)=>{const S=t.current,O=S.trackResize;if(O===void 0)return!1;const v=S.getActive(),y=p==="col"?v.col:v.row,a=C==="fit"?O.autofitColumn(y):O.stepTrack(p,y,C),f=(p==="col"?S.colAxis:S.rowAxis).sizeOf(y);return a&&f>0&&S.formatResizeAnnouncement!==void 0&&S.announce(S.formatResizeAnnouncement({command:g,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),Y=i.useCallback(g=>{const p=t.current;if(!M(g))return!1;const C=nc[g];if(!j(C))return!1;const S=p.isEditing();if(S&&!go.has(g)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const O=r(),v=O!==void 0&&O[C.key]===!0;return s({[C.key]:v?null:!0})?(l(g,!v),!0):!1}case"patch":return s(C.patch)?(l(g,null),!0):!1;case"clear":return s(Dg)?(l(g,null),!0):!1;case"value":return s({value:jg(C.value,p.formats)})?(l(g,null),!0):!1;case"borders":return c(C.preset)?(l(g,null),!0):!1;case"color":{const O=C.key==="background"?p.colors.fill:p.colors.font,v=C.preset!==null?C.preset:C.custom!==null&&C.custom<O.length?O[C.custom]:void 0;if(v===void 0)return!1;const y=r(),a=Ig(y===void 0?void 0:y[C.key],v);return s({[C.key]:a?null:v})?(l(g,!a),!0):!1}case"calc":return b({text:O=>Og(O,C.exponent),formula:O=>Tg(O,C.exponent)});case"sign":return b({text:Ag,formula:$g});case"fill":return S&&C.direction==="selection"?m():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const O=B();return O===void 0?!1:(p.onHyperlinkOpen(O,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const O=C.unit==="date"?zg(p.now()):Mg(p.now());if(S)return p.insertAtCaret(O),!0;const v=p.getActive();return et(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1):p.validateCommit(v,O).ok?p.commitEdits([{row:v.row,col:v.col,text:O}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return U(g,C.axis,C.step);default:{const O=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...O,row:!O.row}),!0;case"column":return p.setHighlight({...O,column:!O.column}),!0;case"both":{const v=O.row&&O.column;return p.setHighlight({...O,row:!v,column:!v}),!0}default:return p.setHighlight({...O,intersection:!O.intersection}),!0}}}},[M,j,B,r,s,l,c,b,h,m,N,U]),A=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),T=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=g===null?null:an(g);if(g!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!A())return!1;const S=p.getActive();return et(p.adapter,S.row,S.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:S.row,col:S.col,hyperlink:C}],{source:"annotate"})!==null},[A]),F=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!A())return!1;const C=p.getActive();return et(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:g}],{source:"annotate"})!==null},[A]),H=i.useCallback(g=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!A())return!1;const S=p.getActive();if(et(p.adapter,S.row,S.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const O=C(S.row,S.col),v=O===void 0?[g]:[...O,g];return p.commitEdits([{row:S.row,col:S.col,comments:v}],{source:"annotate"})!==null},[A]),z=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!A())return!1;const C=p.getSelection().ranges;if(!hr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Vn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:mt(C)}),!1;const S=[];return nn(C,O=>{S.push({row:O.row,col:O.col,validation:g})}),p.commitEdits(S,{source:"annotate"})!==null},[A]),q=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),$=i.useCallback((g,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,p)},[c]);return i.useMemo(()=>({executeCommand:Y,applyFormat:q,setBorders:$,setHyperlink:T,setNote:F,addComment:H,setValidation:z,isCommandAvailable:M}),[Y,q,$,T,F,H,z,M])},to="data-aqsp-pointing",Bg=(e,t)=>{const n=ta(e,t);return n!==null&&"insertAt"in n},Wg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Vg=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),u=i.useRef(null),h=i.useRef(Ht),m=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=ta(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),b=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=m()!==null;a!==y.hasAttribute(to)&&(a?y.setAttribute(to,""):y.removeAttribute(to))},[m]),N=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const k=f.resolveEditPaint(a),d=k===null?Ht:k;d!==Ht&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),B=i.useCallback(y=>{Wg(y,Object.keys(h.current.style)),h.current=Ht;const a=t.current.editPaintRef;a!==void 0&&(a.current=Ht)},[]),M=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const k=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),B(d),d.removeAttribute(to)),o(!1)};if(y.commit){const d=a.sinkRef.current,x=d===null?"":d.value,E=Qn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
13
+ `),D=x===E;let W;if(D)W=!0;else if(et(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),W=!1;else{const P={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};W=(a.validateCommit===void 0||a.validateCommit(f.cell,x).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:x}],P)!==null}if(!W)return y.onReject==="discard"&&(k(),a.rearmSink()),!1}return k(),y.rearm&&a.rearmSink(),!0},[B]),j=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const k=f.sinkRef.current;if(k===null)return;const d=f.getActive();if(et(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:E,isFormula:D}=Qn(f.adapter,d.row,d.col);k.value=E;const W=a===void 0||D?E.length:Math.min(a,E.length);k.setSelectionRange(W,W)}else k.value="";const x=f.resolveEditAlign(d);x!==null&&(k.style.textAlign=x),N(k,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[N]),U=i.useCallback(()=>{M({rearm:!0,commit:!1})},[M]),Y=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return M({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return M({rearm:!0,commit:!0,onReject:"keep"})},[M]),A=i.useCallback(()=>m()!==null,[m]),T=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,b(),!0),[b]),F=i.useCallback(()=>{const y=m(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=ea(y.sink.value,y.sink.selectionStart);if(f===null)return null;const k=f.token,d=u.current;switch(k.kind){case"cell":{const x={row:k.row,col:k.col};return u.current=x,{origin:x,cursor:x,axis:"cells"}}case"range":{const x=d!==null&&(d.row===k.start.row||d.row===k.end.row)&&(d.col===k.start.col||d.col===k.end.col)?{row:d.row,col:d.col}:{row:k.start.row,col:k.start.col};return u.current=x,{origin:x,cursor:{row:x.row===k.start.row?k.end.row:k.start.row,col:x.col===k.start.col?k.end.col:k.start.col},axis:"cells"}}case"column":{const x=d!==null&&(d.col===k.start.col||d.col===k.end.col)?d.col:k.start.col,E={row:a.cell.row,col:x};return u.current=E,{origin:E,cursor:{row:a.cell.row,col:x===k.start.col?k.end.col:k.start.col},axis:"columns"}}case"row":{const x=d!==null&&(d.row===k.start.row||d.row===k.end.row)?d.row:k.start.row,E={row:x,col:a.cell.col};return u.current=E,{origin:E,cursor:{row:x===k.start.row?k.end.row:k.start.row,col:a.cell.col},axis:"rows"}}}},[m]),H=i.useCallback((y,a)=>{const f=m();if(f===null)return;const k=Xf(y,a),{sink:d}=f,[x,E]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],D=d.value;d.value=`${D.slice(0,x)}${k}${D.slice(E)}`;const W=x+k.length;d.setSelectionRange(W,W),"row"in y&&(u.current={row:y.row,col:y.col}),b()},[m,b]),z=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),q=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,b())},[b]),$=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=sp(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),b(),!0)},[b]),g=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,k=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(k)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,b()},[b]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),S=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(B(f),N(f,a.cell),y.repaintOverlay?.())},[B,N]),{enabled:O,sinkRef:v}=e;return i.useEffect(()=>{const y=v.current;if(!O||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},k=E=>{const D=t.current;if(l.current||n.current===null)return;const W=D.rootRef.current,P=E.relatedTarget;W!==null&&P instanceof Node&&W.contains(P)||M({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const E=t.current;u.current=null,E.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Bg(y.value,y.selectionStart)&&(c.current=!0),b()},x=()=>{n.current!==null&&b()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",k),y.addEventListener("input",d),document.addEventListener("selectionchange",x),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",k),y.removeEventListener("input",d),document.removeEventListener("selectionchange",x)}},[O,v,M,b]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Y,cancelEdit:U,startEdit:j,getPointing:A,togglePointingArm:T,getReferenceCursor:F,insertReference:H,captureSink:z,restoreSink:q,cycleAnchorAtCaret:$,insertAtCaret:g,getSessionText:p,getSessionCell:C,refreshPaint:S,editing:r}),[Y,U,j,A,T,F,H,z,q,$,g,p,C,S,r])},Yg=(e,t,n)=>{const r=new lt.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}},Kg=(e,t,n)=>{const{tree:r,initialHidden:o}=Yg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:b}=r.prefixSum(h);return m-b},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),b=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(b+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const b=Math.round(m);r.get(h)===0!=(b===0)&&(s+=b===0?1:-1),r.update(h,b)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},sn=(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)},Xn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:sn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=sn(e,o,1);return r},rc=(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=Kg(e,t,r)),o.current.model},Gn=256,is=256,Ug=2**32,Xg=4096,ou=Object.freeze([]),su=["background","color","bold","italic","underline","strikethrough"],lu=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},ln=(e,t,n)=>(e.size>=Xg&&e.clear(),e.set(t,n),n),iu=e=>(lu(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),cu=(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},Gg=(e,t,n)=>{const r=Math.floor(t/Gn),o=Math.floor(n/is),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Gn,u=o*is,h=[];for(const m of e.rules)cu(m.ranges,c,c+Gn-1,u,u+is-1)&&h.push(m);return ln(e.buckets,s,h.length===0?ou:h)},Zg=(e,t,n)=>{const r=Math.floor(t/Gn),o=r*Ug+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Gg(e,t,n),c=r*Gn,u=[];for(const h of l)cu(h.ranges,c,c+Gn-1,n,n)&&u.push(h);return ln(e.columns,o,u.length===0?ou:u)},Jg=(e,t)=>{for(const n of e)if(un(n,t))return!0;return!1},Us=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),no=(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}},sc=new WeakMap,Ts=e=>e===null?null:Number(e),Qg=e=>{const t=sc.get(e);if(t!==void 0)return t;const n=e.b,r={a:Ts(gt(e.a)),b:n===void 0?null:Ts(gt(n))};return sc.set(e,r),r},au=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:ln(e.numbers,r,Ts(gt(n())))},ew=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Qg(e),l=au(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return oc(e.op,no(l,s.a),c===null?null:no(l,c));const u=n(),h=e.b;return oc(e.op,no(u,e.a),h===void 0?null:no(u,h))},tw=(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}},cs=e=>{const t=st(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"),as=(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)}`},us=(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=cs(t.color),u=cs(r.color);const h=n===void 0?void 0:cs(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const b=s;s=l,l=b;const N=c;c=u,u=N}if(n!==void 0&&h!==void 0){const b=n.value===void 0?(s+l)/2:n.value;if(s<b&&b<l)return e<=b?as(c,h,us(e,s,b)):as(h,u,us(e,b,l))}return as(c,u,us(e,s,l))},rw=(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 ln(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return ln(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return ln(r.extrema,e.id,{min:c,max:u})},ow=(e,t,n,r,o,s)=>{const l=au(s,n,r);if(l===null)return null;const c=rw(e,t,o,s);return c===null?null:nw(l,t.min,t.mid,t.max,c)},sw=(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:ln(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},lw=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return ew(s,t,n,o)?e.style:null;case"text":return tw(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=ow(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return sw(e,s,t,r,o)?e.style:null;default:return null}},lc=(e,t)=>Ns(e,t),iw=(e,t,n)=>{e[t]=n},cw=(e,t)=>{let n=e;for(const r of su)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),iw(n,r,t[r]));return n},aw=e=>{let t="";for(const n of su){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},ic=new WeakMap,uw=Object.freeze({}),dw=e=>{const t=e===void 0?uw:e,n=ic.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return ic.set(t,r),r},fw=(e,t,n)=>{const r=dw(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=lc(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=aw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=lc(e,t);return l!==void 0&&ln(r.byKey,o,l),l},Xs=(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=Zg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const b of c){if(!Jg(b.ranges,u))continue;const N=lw(b,u,s,e,n);if(N!==null){if(N!==b.style&&(m=!1),h===null)h=N;else{const B=cw(h,N);B!==h&&(m=!1,h=B)}if(b.stopIfTrue===!0)break}}return h===null?l:fw(l,h,m)},cc=new WeakMap,pw=e=>{lu(e,"widthRelevantRules");const t=cc.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 cc.set(e,r),r},hw=({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},mw=i.memo(hw),gw=Object.freeze({left:Object.freeze({justifyContent:yr("left")}),center:Object.freeze({justifyContent:yr("center")}),right:Object.freeze({justifyContent:yr("right")})}),ww=Object.freeze({role:"rowgroup"}),Cw=4096,ac=new WeakMap,oo=new Map,bw=(e,t)=>{if(e===null)return gw[t];let n=ac.get(e);n===void 0&&(n={},ac.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:yr(t)},s=JSON.stringify(o);let l=oo.get(s);return l===void 0&&(oo.size>=Cw&&oo.clear(),l=Object.freeze(o),oo.set(s,l)),n[t]=l,l},yw=Us(),Rw=(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},vw=(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 u=null,h;if(e.getCellFormat!==void 0){const m=Xs(e,r===null?null:r.indexRef.current,r===null?yw:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const b=ba(m,l),N=sn(n,s,1),B=sn(t,o,1),M=Of(m,N===null?void 0:e.getCellFormat(o,N),B===null?void 0:e.getCellFormat(B,s),n.offsetOf(s)===0,t.offsetOf(o)===0);M!==null&&Object.assign(c,M.attrs),c["data-aqsp-align"]=b,u=bw(M,b)}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&&er(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&qm(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Sw=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:b,headerRows:N,labelledBy:B,gridLabel:M,readOnly:j,renderCell:U,onScroll:Y,onRangeChange:A,focusSink:T,isEditing:F,requestCommit:H,testId:z,__onCellRender:q,__maxRenderedCells:$,cfIndexRef:g,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:S,showArrowButtons:O,enableThumbDrag:v,enableTrackClick:y,overscanRows:a,overscanCols:f,background:k,onRenderTruncated:d,locale:x,scrollLabels:E})=>{const D=i.useRef(null),W=s??D;if(g===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const P=i.useMemo(()=>g===void 0||p===void 0?null:{indexRef:g,memoRef:p},[g,p]),G=i.useCallback(()=>r.get().editVersion,[r]),X=i.useCallback(we=>r.subscribeCoalesced(we),[r]),re=i.useSyncExternalStore(X,G,G)+(l??0),ie=i.useCallback(we=>t.sizeOf(we),[t]),oe=i.useCallback(we=>n.sizeOf(we),[n]),Oe=i.useCallback((we,Be)=>e.getCellText(we,Be),[e]),ze=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),Fe=i.useMemo(()=>({width:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:S,enableArrowButtonTabStops:!1,showArrowButtons:O,enableThumbDrag:v,enableTrackClick:y}),[S,O,v,y]),_e=i.useRef({row:-1,col:-1,value:void 0}),Ue=i.useCallback((we,Be)=>{const it=we<N,dt={role:it?"columnheader":"gridcell","aria-rowindex":we+1,"aria-colindex":Be+1,"data-aqsp-cell":"","data-row":we,"data-col":Be,className:"aqsp-cell",...et(e,we,Be)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...it?{"data-aqsp-header-row":""}:{}},At=Mh(e,we,Be),Mt=At===null?dt:{...dt,...At},We=vw(e,t,n,P,we,Be),Ct=_e.current;return Ct.row=we,Ct.col=Be,Ct.value=We===null?void 0:We.value,We===null?Mt:We.style===null?{...Mt,...We.attrs}:{...Mt,...We.attrs,style:We.style}},[e,t,n,P,N]),He=i.useCallback(we=>({role:"row","aria-rowindex":we+1,"data-aqsp-row":we,"data-aqsp-cells":"",className:"aqsp-row"}),[]),zt=i.useCallback((we,Be,it)=>{let dt=we;return e.getCellFormat!==void 0&&(dt=Zn(we,Rw(_e.current,Be,it))),K.jsx(mw,{row:Be,col:it,text:we,display:dt,renderCell:U,__onCellRender:q})},[re,U,q,e]);return K.jsx("div",{ref:W,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":B,"aria-readonly":j?"true":void 0,onPointerDownCapture:we=>{if(!(we.target instanceof Element&&we.target.closest("[data-aqsp-cells]")!==null)&&we.pointerType==="mouse"){if(we.button!==0){we.preventDefault();return}if(we.preventDefault(),C?.()===!0){we.stopPropagation(),T();return}if(F()&&!H()){we.stopPropagation(),T();return}T()}},children:K.jsx(lt.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:b,getRowHeight:ie,getColWidth:oe,getCell:Oe,getCellProps:Ue,getRowProps:He,contentProps:ww,behaviorOptions:ze,scrollBarOptions:Fe,overscanRows:a,overscanCols:f,background:k,onRenderTruncated:d,__maxRenderedCells:$,locale:x,labels:E,callbackThrottleMs:0,onScroll:Y,onRangeChange:A,testId:z,children:zt})})},kw=i.memo(Sw),Yn=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,u=sn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-Yn,length:ht}),r.push({kind:"unhide",index:s+1,start:c-ht,length:ht})):l>=2*Yn?n.push({kind:"resize",index:s,start:c-Yn,length:Yn}):n.push({kind:"resize",index:s,start:c-ht,length:ht})}return[...n,...r]},uu=(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 u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:ht}),n.push({kind:"resize",index:c,start:h+ht,length:ht})):u>=2*Yn?n.push({kind:"resize",index:c,start:h,length:Yn}):n.push({kind:"resize",index:c,start:h,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]},Ew=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:b,dividerTrailingRef:N})=>{const B=lt.useWheelBridge(o),M=i.useCallback(d=>(s.current=d,B(d)),[s,B]),j=i.useCallback(()=>{const{colStart:d,colEnd:x,colVersion:E}=e.get();return`${d}:${x}:${E}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,j,j);const{colStart:Y,colEnd:A}=e.get(),T=t.count===0?0:t.offsetOf(Math.min(Y,t.count-1));i.useLayoutEffect(()=>{c.current=T,u()},[T,c,u]);const F=d=>h.some(x=>d>=x.startCol&&d<=x.endCol),H=Math.min(Math.max(0,n),t.count),z=qa(t,H),q=H>0?Xn(t,0,H-1):[],$=Math.min(Math.max(0,r),t.count-H),g=ja(t,$),p=t.totalSize()-g,C=$>0?Xn(t,t.count-$,t.count-1):[],S=Xn(t,Math.max(Y,H),Math.min(A,Math.max(0,t.count-1)-$)),O=[];for(const d of S)O.push(K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-T,width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d));const v=m?Co(t,S):null,y=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<H&&z>0||d.kind==="unhide"&&d.index>=t.count-$&&g>0)),a=m&&H>0?Co(t,q):null,f=m&&$>0?uu(t,C):null,k=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[O,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-T,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-T,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:M,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:H===0&&$===0?k:K.jsxs(K.Fragment,{children:[q.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:z,right:$>0?`calc(${Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${Le.SPREADSHEET_SCROLLBAR_SIZE_PX+z}px)))`:void 0},children:[k,H>0?K.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,$>0?K.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]}),$>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${z}px, calc(100% - ${g+Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[C.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?K.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}`):K.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]})})},Ow=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:b,dividerTrailingRef:N})=>{const B=lt.useWheelBridge(n),M=i.useCallback(d=>(r.current=d,B(d)),[r,B]),j=d=>o.some(x=>d>=x.startRow&&d<=x.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:x,rowGeomVersion:E}=e.get();return`${d}:${x}:${E}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,U,U);const{rowStart:A,rowEnd:T}=e.get(),F=t.count===0?0:t.offsetOf(Math.min(A,t.count-1));i.useLayoutEffect(()=>{l.current=F,c()},[F,l,c]);const H=Math.min(Math.max(0,h),t.count),z=Ia(t,H),q=H>0?Xn(t,0,H-1):[],$=Math.min(Math.max(0,m),t.count-H),g=Ha(t,$),p=t.totalSize()-g,C=$>0?Xn(t,t.count-$,t.count-1):[],S=Xn(t,Math.max(A,H),Math.min(T,Math.max(0,t.count-1)-$)),O=[];for(const d of S)O.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":j(d)?"":void 0,style:{top:t.offsetOf(d)-F,height:t.sizeOf(d)},children:d+1},d));const v=u?Co(t,S):null,y=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<H&&z>0||d.kind==="unhide"&&d.index>=t.count-$&&g>0)),a=u&&H>0?Co(t,q):null,f=u&&$>0?uu(t,C):null,k=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[O,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-F,height:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-F,height:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:M,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:H===0&&$===0?k:K.jsxs(K.Fragment,{children:[q.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":j(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:z,bottom:$>0?`calc(min(${g}px, max(0px, 100% - ${z}px)))`:void 0},children:[k,H>0?K.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,$>0?K.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]}),$>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${z}px, calc(100% - ${g}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[C.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":j(d)?"":void 0,style:{top:t.offsetOf(d)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?K.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}`):K.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]})})},Aw=9,xw=4,uc=(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,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},dc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Tw=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),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),b=i.useCallback(g=>s.current!==null?g.pointerId===s.current:g.pointerType==="mouse",[]),N=i.useCallback(()=>{const g=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),g.writeResizeGuide(null);const p=m.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),m.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,g.repaintOverlay()},[]),B=i.useCallback((g,p)=>{const C=t.current;return g==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),M=i.useCallback((g,p)=>{const C=t.current,S=C.getSelection().ranges.filter(f=>B(g,f));if(!S.some(f=>g==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const v=S.reduce((f,k)=>f+(g==="col"?k.endCol-k.startCol+1:k.endRow-k.startRow+1),0),y=g==="row"?Math.floor(C.maxOperationCells/Ls):C.maxOperationCells;if(v>y)return C.onOperationRejected?.("resize",v,"limit"),null;const a=new Set;for(const f of S){const k=g==="col"?f.startCol:f.startRow,d=g==="col"?f.endCol:f.endRow;for(let x=k;x<=d;x+=1)a.add(x)}return[...a]},[B]),j=i.useCallback((g,p,C)=>{const S=t.current,O=g==="col"?S.colAxis:S.rowAxis,v=Ds(O,p,C,{maxOperationCells:S.maxOperationCells,rowHiddenLimit:$s,axisKind:g});return v.ok?(S.resizeTracks(g,v.entries),!0):(S.onOperationRejected?.("resize",v.count,v.reason),!1)},[]),U=i.useCallback((g,p)=>{if(p===g.initialSize)return;const C=g.kind==="unhide"?[g.index]:M(g.axis,g.index);C!==null&&j(g.axis,C.map(S=>({index:S,size:p})),g.index)},[M,j]),Y=i.useCallback((g,p,C,S)=>{const O=t.current,v=O.fontSourceRef.current;if(v===null)return!1;if(p.length===0)return!0;const y=g.length*p.length;if(y>C)return O.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(v),k=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),x={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},E=`${x.fontStyle} ${x.fontWeight} ${x.fontSize} ${x.fontFamily}`,D=O.adapter.getConditionalFormats===void 0?null:pw(O.adapter.getConditionalFormats()),W=Us(),P=new WeakMap,G=new WeakMap,X=new Map;for(const oe of g){const Oe=D===null?null:iu(D.filter(ze=>ze.ranges.some(Fe=>oe>=Fe.startCol&&oe<=Fe.endCol)));for(const ze of p){const Fe=O.adapter.getCellText(ze,oe),_e=O.adapter.getCellFormat===void 0?void 0:Xs(O.adapter,Oe,W,ze,oe,()=>Fe),Ue=ze<O.headerRows,He=_e===void 0?Ue?E:k:Ue?uc(_e,G,x):uc(_e,P,f),zt=Zn(Fe,_e===void 0?void 0:_e.value),we=X.get(He);we===void 0?X.set(He,[{col:oe,text:zt}]):we.push({col:oe,text:zt})}}const Q=v.ownerDocument.createElement("span");Q.setAttribute("aria-hidden","true"),Q.style.position="absolute",Q.style.visibility="hidden",v.append(Q);const re=new Map;for(const[oe,Oe]of X){a.font=oe,Q.style.font=oe;const ze=getComputedStyle(Q);a.letterSpacing=ze.letterSpacing==="normal"?"0px":ze.letterSpacing,a.wordSpacing=ze.wordSpacing==="normal"?"0px":ze.wordSpacing;for(const Fe of Oe){const _e=a.measureText(Fe.text).width,Ue=re.get(Fe.col);(Ue===void 0||_e>Ue)&&re.set(Fe.col,_e)}}Q.remove();const ie=[];for(const oe of g){const Oe=re.get(oe);Oe!==void 0&&Oe>0&&ie.push({index:oe,size:Math.ceil(Oe)+Aw})}return ie.length===0?!0:j("col",ie,S)},[j]),A=i.useCallback(g=>{const p=t.current,C=M("col",g);if(C===null)return!1;const S=p.handleRef.current,O=S===null?null:S.getFrozenSize(),v=O===null?0:O.rows,y=O===null?0:O.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),k=Math.min(f,p.rowAxis.count-1),d=[],x=new Set,E=D=>{!x.has(D)&&p.rowAxis.sizeOf(D)>0&&(x.add(D),d.push(D))};for(let D=0;D<v;D+=1)E(D);for(let D=a;D<=k;D+=1)E(D);for(let D=p.rowAxis.count-y;D<p.rowAxis.count;D+=1)E(D);return Y(C,d,Math.floor(p.maxOperationCells/xw),g)},[M,Y]),T=i.useCallback((g,p,C)=>{const S=g==="col"?t.current.colAxis:t.current.rowAxis,O=Zu(S.sizeOf(p),C);if(O===S.sizeOf(p))return!0;const v=M(g,p);return v===null?!1:j(g,v.map(y=>({index:y,size:O})),p)},[M,j]),F=i.useCallback(g=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(g)===0?!0:A(g):!1},[A]),H=i.useCallback(g=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(g)].filter(O=>p.colAxis.sizeOf(O)>0);if(C.length===0)return!0;const S=[];for(let O=0;O<p.rowAxis.count;O+=1)p.rowAxis.sizeOf(O)>0&&S.push(O);return Y(C,S,p.maxOperationCells,null)},[Y]),{enabled:z,colBandRef:q,rowBandRef:$}=e;return i.useEffect(()=>{const g=q.current,p=$.current;if(!z||g===null||p===null)return;const C=P=>P==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",S=(P,G)=>{if(!(G instanceof Element))return null;const X=G.closest(C(P));if(X===null)return null;const Q=X.hasAttribute("data-aqsp-unhide"),re=Number(X.getAttribute(Q?"data-aqsp-unhide":P==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ie=X.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:Q?"unhide":"resize",index:re,anchor:ie}},O=P=>{if(!(n.current&&b(P)))return;const G=r.current;if(G===null)return;const X=(G.axis==="col"?P.clientX-G.startClientX:P.clientY-G.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(G.anchor==="trailing"?G.initialSize-X:G.initialSize+X)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const Q=r.current;if(!n.current||Q===null)return;const re=t.current,ie=Q.axis==="col"?re.colAxis:re.rowAxis;re.writeResizeGuide({axis:Q.axis,position:dc(Q,ie,o.current),anchor:Q.anchor})}))},v=()=>{const P=r.current,G=o.current;N(),P!==null&&U(P,G)},y=P=>{O(P),n.current&&b(P)&&(l.current&1)!==0&&(P.buttons&1)===0&&v()},a=P=>{P.button!==0||!(n.current&&b(P))||v()},f=(P,G)=>X=>{const Q=t.current;if(h.current=X.pointerType,X.pointerType!=="mouse")return;if(X.button!==0){X.preventDefault();return}const re=S(P,X.target);if(re===null)return;if(X.stopPropagation(),X.preventDefault(),Q.isPointing()){Q.focusSink();return}if(Q.isEditing()&&!Q.requestCommit()){Q.focusSink();return}Q.focusSink();const ie=P==="col"?Q.colAxis:Q.rowAxis,oe={axis:P,kind:re.kind,index:re.index,anchor:re.anchor,initialSize:ie.sizeOf(re.index),startClientX:X.clientX,startClientY:X.clientY};r.current=oe,o.current=oe.initialSize,l.current=X.buttons,n.current=!0,Q.repaintOverlay(),s.current=X.pointerId,c.current=G;try{G.setPointerCapture(X.pointerId)}catch{s.current=null}const Oe=y,ze=a;m.current={move:Oe,up:ze},window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",ze),Q.writeResizeGuide({axis:P,position:dc(oe,ie,o.current),anchor:oe.anchor})},k=(P,G)=>X=>{const Q=t.current;if(h.current!=="mouse")return;const re=G.getRootNode(),ie=re instanceof ShadowRoot?re:G.ownerDocument,oe=X.target instanceof Element&&X.target.closest(C(P))!==null?X.target:typeof ie.elementFromPoint=="function"?ie.elementFromPoint(X.clientX,X.clientY):null,Oe=S(P,oe);if(Oe!==null){if(X.stopPropagation(),Q.isEditing()){Q.focusSink();return}if(Oe.kind==="unhide"){j(P,[{index:Oe.index,size:P==="col"?Q.defaultColumnWidth:Q.defaultRowHeight}],null);return}if(Q.autofitEnabled){if(P==="row"){const ze=M("row",Oe.index);ze!==null&&j("row",ze.map(Fe=>({index:Fe,size:Q.defaultRowHeight})),Oe.index);return}A(Oe.index)}}},d=P=>{!n.current||s.current===null||P.pointerId!==s.current||N()},x=f("col",g),E=f("row",p),D=k("col",g),W=k("row",p);return g.addEventListener("pointerdown",x,{capture:!0}),p.addEventListener("pointerdown",E,{capture:!0}),g.addEventListener("dblclick",D),p.addEventListener("dblclick",W),g.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{g.removeEventListener("pointerdown",x,{capture:!0}),p.removeEventListener("pointerdown",E,{capture:!0}),g.removeEventListener("dblclick",D),p.removeEventListener("dblclick",W),g.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),N()}},[z,q,$,b,N,U,j,M,A]),i.useMemo(()=>({stepTrack:T,autofitColumn:F,autofitColumnsInAllRows:H,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,T,F,H])},Gs=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,$w=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Gs(n,t.ranges[r]))&&Yt(e.anchor,t.anchor)&&Yt(e.active,t.active),Lw=(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=>dn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:fe(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)}},Dw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Gs(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Or=(e,t,n)=>n.extend?vn(e,t):n.append?{ranges:[...e.ranges,fe(t,t)],anchor:t,active:t}:e.ranges.length===1&&Yt(e.anchor,t)&&Yt(e.active,t)&&Gs(e.ranges[0],fe(t,t))?e:{ranges:[fe(t,t)],anchor:t,active:t},zw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),vn=(e,t)=>{const n=Dw(e,fe(e.anchor,t));return n.ranges.some(r=>un(r,n.active))?n:{...n,active:zw(n.active,n.ranges[n.ranges.length-1])}},du=(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(fe({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(fe({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(fe({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(fe({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[fe(n,n)],anchor:n,active:n};const s=o.findIndex(c=>un(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}},Mw=(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,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},fu=(e,t)=>{const n=e.ranges.findIndex(o=>un(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=Mw(e.ranges,r.rangeIndex,r.cell,t),!Yt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},jt=24,fc=32,bo=4,In=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),b=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),N=i.useCallback(()=>{const M=u.current,j=e.current,U=m.current;if(M===null||j===null||U===null){c.current=null;return}const{clientX:Y,clientY:A}=M.getPointerPosition(),T=l.current,F=(Y-U.left)/T,H=(A-U.top)/T,z=j.getViewportSize(),q=z.width,$=z.height;if(q<=0||$<=0){c.current=requestAnimationFrame(N);return}const g=y=>Math.min(fc,Math.ceil(y/jt*fc));let p=0,C=0;if(s!=="x"){const y=j.getFrozenSize(),a=y.trailingVisibleHeight;H>$-a-jt?M.anchorRow!==void 0&&y.trailingRows>0&&M.anchorRow>=t.count-y.trailingRows&&a>0&&H>=$-a||(p=g(H-($-a-jt))):H<y.height+jt&&(M.anchorRow!==void 0&&M.anchorRow<y.rows&&y.height>0&&H<y.height||(p=-g(y.height+jt-H)))}if(s!=="y"){const y=j.getFrozenSize(),a=y.trailingVisibleWidth;F>q-a-jt?M.anchorCol!==void 0&&y.trailingCols>0&&M.anchorCol>=n.count-y.trailingCols&&a>0&&F>=q-a||(C=g(F-(q-a-jt))):F<y.width+jt&&(M.anchorCol!==void 0&&M.anchorCol<y.cols&&y.width>0&&F<y.width||(C=-g(y.width+jt-F)))}const S=C!==0||p!==0?j.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):j.getScrollPosition(),O=S.y,v=S.x;if(O>=0&&v>=0&&t.totalSize()>0&&n.totalSize()>0){const y=j.getFrozenSize(),a=dn({row:Dr(t,H,{scroll:O,frozenSize:y.height,trailingSize:y.trailingHeight,extent:z.height}),col:Lr(n,F,{scroll:v,frozenSize:y.width,trailingSize:y.trailingWidth,extent:z.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(M.buildRange(a)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),B=i.useCallback(M=>{b(),u.current=M,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[b,N,r]);return i.useEffect(()=>{const M=()=>{document.visibilityState==="hidden"&&b()};return document.addEventListener("visibilitychange",M),()=>{document.removeEventListener("visibilitychange",M),b()}},[b]),i.useMemo(()=>({start:B,stop:b}),[B,b])},pc=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),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),b=i.useRef(!1),N=i.useRef(0),B=i.useCallback((z,q)=>{const{axis:$,mainAxis:g,handleRef:p,zoomRef:C}=t.current,S=s.current;if(S===null||g.totalSize()===0)return null;const O=C.current,v=p.current;if(v===null)return null;if($==="col"){const k=v.getScrollPosition().x;if(k<0)return null;const d=v.getFrozenSize(),x=v.getViewportSize();return Math.min(Math.max(Lr(g,(z-S.left)/O,{scroll:k,frozenSize:d.width,trailingSize:d.trailingWidth,extent:x.width}),0),g.count-1)}const y=v.getScrollPosition().y;if(y<0)return null;const a=v.getFrozenSize(),f=v.getViewportSize();return Math.min(Math.max(Dr(g,(q-S.top)/O,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),M=i.useCallback((z,q)=>{const{axis:$,crossCount:g}=t.current;return $==="col"?{press:{row:0,col:z},extend:{row:g-1,col:q}}:{press:{row:z,col:0},extend:{row:q,col:g-1}}},[]),j=i.useCallback((z,q)=>{const{axis:$,crossCount:g}=t.current;return z.ranges.some(p=>$==="col"?p.startRow===0&&p.endRow===g-1&&q>=p.startCol&&q<=p.endCol:p.startCol===0&&p.endCol===g-1&&q>=p.startRow&&q<=p.endRow)},[]),U=i.useRef(!1),Y=i.useRef({clientX:0,clientY:0}),A=i.useCallback(()=>{U.current=!1;const{autoScroller:z,headerRef:q,onDragFrame:$}=t.current;n.current=!1,r.current=null,m.current=null,b.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),z.stop();const g=q.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,$(null),t.current.repaintOverlay()},[]),T=i.useCallback(()=>{if(!n.current)return;const z=r.current;z!==null&&t.current.setSelection(z),A()},[A]),{enabled:F,headerRef:H}=e;return i.useEffect(()=>{const z=H.current;if(!F||z===null)return;const q=v=>{const y=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}if(b.current=!1,y.pointing?.getPointing()){s.current=z.getBoundingClientRect();const d=B(v.clientX,v.clientY);if(d===null)return;v.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){v.preventDefault(),y.focusSink();return}s.current=z.getBoundingClientRect();const a=B(v.clientX,v.clientY);if(a===null)return;v.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const k=v.ctrlKey||v.metaKey;if(v.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:x}=M(a,a),E={...f,anchor:d};y.setSelection(vn(E,x)),o.current=y.axis==="col"?d.col:d.row}else if(k&&j(f,a))b.current=!0,N.current=a,o.current=a;else{const{press:d,extend:x}=M(a,a),E=Or(f,d,{extend:!1,append:k});y.setSelection(vn(E,x)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:v.clientX,clientY:v.clientY},u.current=v.pointerId,h.current=v.buttons;try{z.setPointerCapture(v.pointerId)}catch{u.current=null}m.current=d=>{const x=t.current.axis==="col"?d.col:d.row,{press:E}=M(o.current,o.current),{extend:D}=M(o.current,x);return fe(E,D)},y.autoScroller.stop(),U.current=!1,Y.current={clientX:v.clientX,clientY:v.clientY}},$=v=>u.current!==null?v.pointerId===u.current:v.pointerType==="mouse",g=v=>{if(n.current&&$(v)){if(b.current){const y=v.clientX!==l.current.clientX||v.clientY!==l.current.clientY;if(l.current={clientX:v.clientX,clientY:v.clientY},!y)return;const a=B(v.clientX,v.clientY);if(a===null||a===N.current)return;b.current=!1;const f=t.current,{press:k,extend:d}=M(N.current,N.current),x=Or(f.getSelection(),k,{extend:!1,append:!0});f.setSelection(vn(x,d));const E=m.current,D=Math.abs(v.clientX-Y.current.clientX),W=Math.abs(v.clientY-Y.current.clientY);E!==null&&Math.max(D,W)>=bo&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:E,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:v.clientX,clientY:v.clientY},!U.current&&m.current!==null){const y=Math.abs(v.clientX-Y.current.clientX),a=Math.abs(v.clientY-Y.current.clientY);Math.max(y,a)>=bo&&(U.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 y=m.current;if(!n.current||y===null)return;const a=B(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=v=>{g(v),n.current&&$(v)&&(h.current&1)!==0&&(v.buttons&1)===0&&S(v)},C=v=>{v.button!==0||!(n.current&&$(v))||S(v)},S=v=>{const y=t.current;if(b.current){const{press:f,extend:k}=M(N.current,N.current);y.setSelection(du(y.getSelection(),fe(f,k),f)),A();return}const a=B(v.clientX,v.clientY);if(a!==null){const{extend:f}=M(o.current,a);y.setSelection(vn(y.getSelection(),f))}A()},O=v=>{!n.current||u.current===null||v.pointerId!==u.current||T()};return z.addEventListener("pointerdown",q),z.addEventListener("pointermove",p),z.addEventListener("pointerup",C),z.addEventListener("lostpointercapture",O),()=>{z.removeEventListener("pointerdown",q),z.removeEventListener("pointermove",p),z.removeEventListener("pointerup",C),z.removeEventListener("lostpointercapture",O),A()}},[F,H,B,M,A,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:T,cancelDrag:A}),[T,A])},Nw=({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:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),b=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):b>l+u-h.trailingVisibleHeight&&o.scrollBy({y:b-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),b=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):b>s+c-h.trailingVisibleWidth&&o.scrollBy({x:b-(s+c-h.trailingVisibleWidth)})}},Fw=50,Pw=100,pu=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Fw:!1,mr={selectAll:Bt("Ctrl+A"),undo:Bt("Ctrl+Z"),redo:Bt("Ctrl+Y"),redoShiftZ:Bt("Ctrl+Shift+Z"),pasteValues:Bt("Ctrl+Shift+V")},_w=new Set(["Shift","Control","Alt","Meta","AltGraph"]),qw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Iw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",jw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,b=u.current;if(!l||m===null||b===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},B=(a,f,k)=>sn(a,f,k)??f,M=(a,f)=>{const k=s.current;return f==="left"||f==="right"?{row:a.row,col:B(k.colAxis,a.col,f==="right"?1:-1)}:{row:B(k.rowAxis,a.row,f==="down"?1:-1),col:a.col}},j=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),Y=(a,f,k,d)=>{if(a.sizeOf(f)>0)return f;const x=sn(a,f,k);if(x!==null)return x;const E=sn(a,f,k===1?-1:1);return E!==null?E:d},A=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},T=a=>M(A(),a),F=(a,f)=>{const k=s.current,d=f==="left"||f==="right",x=f==="right"||f==="down"?1:-1;let E;return k.findDataEdge!==void 0?(E=k.findDataEdge({row:a.row,col:a.col},f),H(E,a,f)):E={row:f==="down"?k.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?k.colAxis.count-1:f==="left"?0:a.col},d?{row:E.row,col:Y(k.colAxis,E.col,x,a.col)}:{row:Y(k.rowAxis,E.row,x,a.row),col:E.col}},H=(a,f,k)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const x=k==="left"||k==="right";if(x?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${x?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},z=(a,f,k)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${k} component ${a} (count ${f})`)},q=a=>{const f=s.current,k=f.getSelection();if(fu(k,a)===k){f.moveActive({mode:"reset",cell:M(k.active,a)});return}f.moveActive({mode:"cycle",direction:a})},$=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,k=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
14
+ ${a.value.slice(k)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const k=s.current,d=k.pageExtent();if(d<=0)return B(k.rowAxis,a,f==="down"?1:-1);const x=k.rowAxis.indexAt(k.rowAxis.offsetOf(a)+(f==="down"?d:-d));return x===a?B(k.rowAxis,a,f==="down"?1:-1):x},p=a=>{const f=s.current;if(r.current=!1,pu(a,t.current))return;const k=a.ctrlKey||a.metaKey,d=a.altKey,x=qw[a.key];if(o.current&&!_w.has(a.key)&&!f.isDragging()&&N(),f.isEditing()){const D=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!k&&!a.shiftKey&&!d&&f.abortDrag();return}const W=f.pointing;if(W!==void 0){if(x!==void 0&&!d){const X=W.getReferenceCursor();if(X!==null){a.preventDefault();const Q=dn(X.cursor,f.rowAxis.count,f.colAxis.count),re=dn(X.origin,f.rowAxis.count,f.colAxis.count),ie=k?F(Q,x):M(Q,x);if(f.ensureCellVisible(ie),W.insertReference(a.shiftKey?fe(re,ie):ie,X.axis),f.onPointFrame!==void 0){const oe=a.shiftKey?fe(re,ie):fe(ie,ie);f.onPointFrame(X.axis==="columns"?fe({row:0,col:oe.startCol},{row:f.rowAxis.count-1,col:oe.endCol}):X.axis==="rows"?fe({row:oe.startRow,col:0},{row:oe.endRow,col:f.colAxis.count-1}):oe),o.current=!0}return}}if(a.key==="F2"&&!k&&!a.shiftKey&&!d&&W.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!k&&!a.shiftKey&&!d&&W.cycleAnchorAtCaret()){a.preventDefault();return}}const P=f.commands,G=P===void 0?null:Ta(P.table,a);if(P!==void 0&&G!==null&&go.has(G.command)&&P.isAvailable(G.command)){a.preventDefault(),P.execute(G.command);return}if(x!==void 0&&!d){if(k&&a.shiftKey){a.preventDefault();return}if(k)return;if(D==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:T(x)}):f.moveActive({mode:"reset",cell:M(f.getSelection().active,x)});return}return}if(a.key==="Enter"&&d&&!k&&!a.shiftKey){a.preventDefault(),$();return}if((a.key==="Enter"||a.key==="Tab")&&!k&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=!a.shiftKey;q(a.key==="Tab"?X?"right":"left":X?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!k&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(X.row,a.key==="PageDown"?"down":"up"),col:X.col}});return}if(a.key==="Escape"&&!k&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}if(P!==void 0&&G!==null&&!go.has(G.command)&&rm(G.chord)&&P.isAvailable(G.command)){a.preventDefault(),f.onCommandBlockedWhileEditing?.(G);return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const E=f.commands;if(E!==void 0){const D=em(E.table,a);if(D!==null&&E.isAvailable(D)){a.preventDefault(),E.execute(D);return}}if(x!==void 0&&!d){const D=x==="left"||x==="right",W=x==="right"||x==="down"?1:-1;if(k&&a.shiftKey){a.preventDefault();const P=f.getSelection(),G=A();let X;if(f.findDataEdge!==void 0){const Q=D?{row:P.active.row,col:G.col}:{row:G.row,col:P.active.col},re=f.findDataEdge(Q,x);X=D?re.col:re.row,z(X,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),X=Y(D?f.colAxis:f.rowAxis,X,W,D?G.col:G.row)}else{const Q=D?f.colAxis:f.rowAxis;X=W===1?U(Q):j(Q)}f.moveActive({mode:"extend",cell:D?{row:G.row,col:X}:{row:X,col:G.col}});return}if(k){a.preventDefault(),f.moveActive({mode:"reset",cell:F(f.getSelection().active,x)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:T(x)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:M(f.getSelection().active,x)});return}if(Iw(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!k&&!d){a.preventDefault();const D=!a.shiftKey;q(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const W=A();f.moveActive({mode:"extend",cell:{row:k?j(f.rowAxis):W.row,col:j(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:k?j(f.rowAxis):D.row,col:j(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const W=A();f.moveActive({mode:"extend",cell:{row:k?U(f.rowAxis):W.row,col:U(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:k?U(f.rowAxis):D.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!k&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const P=A();f.moveActive({mode:"extend",cell:{row:g(P.row,D),col:P.col}});return}const W=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(W.row,D),col:W.col}});return}if(a.key==="F2"&&!k&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!k&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection(),W=mt(D.ranges);if(W>f.maxOperationCells){f.onOperationRejected?.("delete",W,"limit");return}if(f.adapter!==void 0&&Vn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:W});return}const P=[],G=f.adapter!==void 0&&uo(f.adapter).hyperlink;nn(D.ranges,X=>{P.push(G?{row:X.row,col:X.col,text:"",hyperlink:null}:{row:X.row,col:X.col,text:""})}),f.commitEdits(P,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(k||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(fr(mr.selectAll,a)){a.preventDefault();const D=f.getSelection(),W=fe({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[W],anchor:D.anchor,active:D.active});return}if(fr(mr.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(fr(mr.redo,a)||fr(mr.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!k&&!d||a.key==="ContextMenu"&&!k&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection().active;f.ensureCellVisible(D);const W=h.current,P=W===null?{x:0,y:0}:W.getScrollPosition(),G=Math.max(0,P.y),X=Math.max(0,P.x),Q=W===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:W.getFrozenSize(),re=W===null?{width:0,height:0}:W.getViewportSize(),ie=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:En(f.rowAxis,D.row,{scroll:G,frozenCount:Q.rows,trailingCount:Q.trailingRows,extent:re.height})*ie,left:kn(f.colAxis,D.col,{scroll:X,frozenCount:Q.cols,trailingCount:Q.trailingCols,extent:re.width})*ie,width:f.colAxis.sizeOf(D.col)*ie,height:f.rowAxis.sizeOf(D.row)*ie}});return}if(a.key===" "&&!d&&k!==a.shiftKey){a.preventDefault();const D=f.getSelection(),W=D.ranges.map(P=>k?fe({row:0,col:P.startCol},{row:f.rowAxis.count-1,col:P.endCol}):fe({row:P.startRow,col:0},{row:P.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:W,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&fr(mr.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},S=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Pw)},O=()=>{const a=s.current;if(N(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},v=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),N()};return m.addEventListener("keydown",p),m.addEventListener("keyup",v),m.addEventListener("blur",y),m.addEventListener("compositionstart",C),m.addEventListener("compositionend",S),m.addEventListener("input",O),()=>{m.removeEventListener("keydown",p),m.removeEventListener("keyup",v),m.removeEventListener("blur",y),m.removeEventListener("compositionstart",C),m.removeEventListener("compositionend",S),m.removeEventListener("input",O),n.current!==null&&window.clearTimeout(n.current),N()}},[l,c,u,h])},Hw=()=>{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)})}},Bw=4,Ww=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Vw=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}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),b=i.useRef(0),N=i.useRef(null),B=i.useRef(null),M=i.useRef(!1),j=i.useCallback(z=>m.current!==null?z.pointerId===m.current:z.pointerType==="mouse",[]),U=i.useCallback((z,q)=>{const{handleRef:$,rowAxis:g,colAxis:p}=t.current,C=$.current,S=s.current;if(C===null||S===null)return null;const{x:O,y:v}=C.getScrollPosition();if(v<0||O<0||g.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return dn({row:Dr(g,(q-S.top)/y,{scroll:v,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Lr(p,(z-S.left)/y,{scroll:O,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,p.count)},[]),Y=i.useCallback(z=>{const q=r.current;if(q===null)return fe(z,z);const $=fe({row:Math.min(q.startRow,z.row),col:Math.min(q.startCol,z.col)},{row:Math.max(q.endRow,z.row),col:Math.max(q.endCol,z.col)}),g=$.startRow!==q.startRow||$.endRow!==q.endRow||$.startCol!==q.startCol||$.endCol!==q.endCol;return o.current=g?$:null,g?$:q},[]),A=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,u.current=!1,h.current={dx:0,dy:0},z.writeFillPreview(null);const q=B.current;q!==null&&(window.removeEventListener("pointermove",q.move),window.removeEventListener("pointerup",q.up),B.current=null);const $=t.current.handleNodeRef.current;$!==null&&m.current!==null&&$.hasPointerCapture?.(m.current)&&$.releasePointerCapture(m.current),m.current=null,z.repaintOverlay()},[]),T=i.useCallback(()=>{const z=t.current,q=r.current,$=o.current;if(A(),q===null||$===null)return;const g=Ph(q,$);if(g>z.maxOperationCells){z.onOperationRejected?.("fill",g,"limit");return}const p=_h(q,$);if(Vn(z.adapter,p)){z.rejectReadOnly({kind:"operation",op:"fill",cellCount:mt(p),gesture:"fillHandle",sources:[q],targets:p});return}const C=qh((O,v)=>Sa(z.adapter,O,v),q,$,ka);if(z.commitEdits(C,{source:"fill"})===null)return;const S=z.getSelection();z.setSelection({ranges:[$],anchor:S.anchor,active:S.active})},[A]),{enabled:F,handleNodeRef:H}=e;return i.useEffect(()=>{const z=H.current;if(!F||z===null)return;const q=S=>{$(S),n.current&&j(S)&&(b.current&1)!==0&&(S.buttons&1)===0&&T()},$=S=>{if(!(n.current&&j(S)))return;l.current={clientX:S.clientX,clientY:S.clientY};const O=Math.abs(S.clientX-c.current.clientX),v=Math.abs(S.clientY-c.current.clientY);if(!u.current&&Math.max(O,v)>=Bw&&(u.current=!0),!!u.current){if(!M.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:Y,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),M.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&u.current))return;const y=U(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(Y(y))}))}},g=S=>{S.button!==0||!(n.current&&j(S))||T()},p=S=>{const O=t.current;if(S.pointerType!=="mouse")return;if(S.button!==0){S.preventDefault();return}S.preventDefault(),S.stopPropagation(),O.focusSink();const v=O.getSelection(),y=v.ranges[v.ranges.length-1];r.current=y,o.current=null,u.current=!1,O.xAutoScroller.stop(),O.yAutoScroller.stop(),M.current=!1,c.current={clientX:S.clientX,clientY:S.clientY},l.current=c.current,b.current=S.buttons,n.current=!0,O.repaintOverlay(),s.current=O.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=O.handleRef.current?.getScrollPosition()??{x:-1,y:-1},k=f.y;if(a!==null&&k>=0&&f.x>=0){const E=f.x,D=O.zoomRef.current,W=O.handleRef.current?.getFrozenSize()??Ww,P=O.handleRef.current?.getViewportSize()??{width:0,height:0},G={scroll:E,frozenCount:W.cols,trailingCount:W.trailingCols,extent:P.width},X={scroll:k,frozenCount:W.rows,trailingCount:W.trailingRows,extent:P.height},Q=kn(O.colAxis,y.endCol,G)+O.colAxis.sizeOf(y.endCol),re=En(O.rowAxis,y.endRow,X)+O.rowAxis.sizeOf(y.endRow),ie=Q-1,oe=y.endCol>=W.cols&&W.width>0?Math.max(ie,W.width):ie,ze=!(y.endCol>=O.colAxis.count-W.trailingCols)&&W.trailingWidth>0?Math.min(oe,P.width-W.trailingVisibleWidth-1):oe,Fe=re-1,_e=y.endRow>=W.rows&&W.height>0?Math.max(Fe,W.height):Fe,He=!(y.endRow>=O.rowAxis.count-W.trailingRows)&&W.trailingHeight>0?Math.min(_e,P.height-W.trailingVisibleHeight-1):_e;h.current={dx:S.clientX-(a.left+ze*D),dy:S.clientY-(a.top+He*D)}}else h.current={dx:0,dy:0};m.current=S.pointerId;try{z.setPointerCapture(S.pointerId)}catch{m.current=null}const d=q,x=g;B.current={move:d,up:x},window.addEventListener("pointermove",d),window.addEventListener("pointerup",x),O.writeFillPreview(r.current)},C=S=>{!n.current||m.current===null||S.pointerId!==m.current||A()};return z.addEventListener("pointerdown",p),z.addEventListener("lostpointercapture",C),()=>{z.removeEventListener("pointerdown",p),z.removeEventListener("lostpointercapture",C),A()}},[F,H,j,U,Y,A,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&A()},cancelDrag:A}),[A])},Yw=320,fo=8,Kw=64,Uw=150,hu=e=>Math.max(0,Math.min(Yw,e.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX-fo)),Xw=(e,t,n)=>{const r=n.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,s=hu(n),l=Math.max(0,Math.min(t,o-fo)),c=e.left+e.width,u=e.top+e.height,h=j=>j>=0&&j+s<=r,m=[e.left,c-s],b=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const j of b)if(h(j.left)&&j.top>=0&&j.top+l<=o)return{left:j.left,top:j.top,width:s,height:l};const N=o-u,B=e.top,M=Math.min(l,Math.max(N,B));if(M>=Kw){const j=N>=B?u:e.top-M;for(const U of m)if(h(U))return{left:U,top:j,width:s,height:M}}return{left:fo,top:fo,width:s,height:l}},Gw=(e,t,n,r)=>t===null||e!==null&&Yt(e,t)||n?!1:r(t),Zw=(e,t)=>{switch(e.kind){case"note":return K.jsx(Ua,{ctx:e,labels:t});case"note-tip":return K.jsx(Xa,{ctx:e,labels:t});case"comment":return K.jsx(Wa,{ctx:e,labels:t});case"link":return K.jsx(Va,{ctx:e,labels:t});case"list":return K.jsx(Ya,{ctx:e,labels:t});default:return K.jsx(Ka,{ctx:e,labels:t})}},ds=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Jw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const b=ds(s),N=ds(l),B=i.useRef(null),M=(T,F)=>{const H=m.current.getLayerSize();T.style.width=`${hu(H)}px`,T.style.maxHeight="";const z=Xw(F,T.offsetHeight,H);T.style.left=`${z.left-F.left}px`,T.style.top=`${z.top-F.top}px`,T.style.maxHeight=`${z.height}px`};i.useLayoutEffect(()=>{const T=c.current;if(T===null||s===null){B.current=null;return}if(M(T,s.anchorRect),s.kind==="message")return;const F=ds(s);if(B.current===F)return;B.current=F;const H=T.querySelector("[data-aqsp-popover-autofocus]");H!==null?H.focus({preventScroll:!0}):T.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const T=u.current,F=h.current;T===null||F===null||M(T,F.anchorRect)},[N]);const j=T=>t===void 0?Zw(T,n):t(T),U=T=>{e.isCompositionKey(T.nativeEvent)&&T.stopPropagation()},Y=T=>{T.key==="Escape"&&!T.defaultPrevented&&(T.preventDefault(),e.close())},A=T=>{e.registerCompositionEnd(T.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:Y,onCompositionEnd:A,children:[K.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:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:j(s)},b)}),K.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:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:j(l)})})]})},Qw=["note","note-tip","comment","link","list","message"],e0=(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}},gr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&e0(e,n),t0=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),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),b=i.useRef(null),N=i.useRef(null),B=i.useRef(null),M=i.useId(),j=i.useCallback(E=>{const D=t.current,W=D.handleRef.current,P=W===null?{x:0,y:0}:W.getScrollPosition(),G=W===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:W.getFrozenSize(),X=W===null?{width:0,height:0}:W.getViewportSize();return{top:En(D.rowAxis,E.row,{scroll:Math.max(0,P.y),frozenCount:G.rows,trailingCount:G.trailingRows,extent:X.height}),left:kn(D.colAxis,E.col,{scroll:Math.max(0,P.x),frozenCount:G.cols,trailingCount:G.trailingCols,extent:X.width}),width:D.colAxis.sizeOf(E.col),height:D.rowAxis.sizeOf(E.row)}},[]),U=i.useCallback(E=>{const D=t.current;D.anchors.current={...D.anchors.current,...E},D.repaintOverlay()},[]),Y=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),A=i.useCallback(()=>{const E=t.current.sinkRef.current;if(E===null)return;const D=c.current;D!==null&&Yt(D,t.current.getActive())?E.setAttribute("aria-describedby",M):E.getAttribute("aria-describedby")===M&&E.removeAttribute("aria-describedby")},[M]),T=i.useCallback(()=>(Y(),h.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),A(),!0)),[Y,U,A]),F=i.useCallback(()=>{Y(),m.current=window.setTimeout(()=>{m.current=null,T()},Uw)},[Y,T]),H=i.useCallback(E=>{const D=t.current;Y();const W=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(E.row,E.col);W===void 0||W===""||(c.current=E,s({kind:"note-tip",cell:E,anchorRect:j(E),current:W,close:T}),U({tip:E}),A())},[j,Y,T,U,A]),z=i.useCallback(E=>{const D=t.current;if(E===null&&h.current)return;const W=u.current;u.current=E;const P=c.current;if(P!==null&&E!==null&&Yt(P,E)){Y();return}const G=X=>{const Q=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(X.row,X.col);return Q!==void 0&&Q!==""};if(Gw(W,E,D.isDraggingAny(),G)){E!==null&&H(E);return}P!==null&&F()},[H,Y,F]),q=i.useCallback((E,D)=>{const W=t.current,P=W.bodyRef.current,G=W.handleRef.current;if(P===null||G===null)return null;const X=P.getBoundingClientRect(),Q=W.zoomRef.current,re=G.getScrollPosition(),ie=G.getFrozenSize(),oe=G.getViewportSize();return dn({row:Dr(W.rowAxis,(D-X.top)/Q,{scroll:Math.max(0,re.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:oe.height}),col:Lr(W.colAxis,(E-X.left)/Q,{scroll:Math.max(0,re.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:oe.width})},W.rowAxis.count,W.colAxis.count)},[]),$=i.useCallback(E=>{N.current=E,b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const D=N.current;z(D===null?null:"cell"in D?D.cell:q(D.clientX,D.clientY))}))},[z,q]),g=i.useCallback(E=>$({cell:E}),[$]),p=i.useCallback(()=>T(),[T]),C=i.useCallback(E=>{if(l.current===null)return;const D=t.current;l.current=null,r(null),U({interactive:null}),(E===void 0||E.restoreFocus)&&D.focusSink({preventScroll:!0}),D.isEditing()||D.rearmSink()},[U]),S=i.useCallback(E=>{l.current=E.kind,r(E),U({interactive:E.cell})},[U]),O=i.useCallback(E=>{const D=t.current;return ya(D.adapter)?{cellReadOnly:et(D.adapter,E.row,E.col)}:{}},[]),v=i.useCallback((E,D)=>{const W=t.current;if(et(W.adapter,E.cell.row,E.cell.col)){W.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),S({...E,...O(E.cell)});return}if(W.commitEdits(D,{source:"annotate"})===null){S({...E,rejected:!0});return}C()},[S,C,O]),y=i.useCallback((E,D)=>{const W=t.current;if(!gr(W.adapter,W.popovers,E))throw new RangeError(`[spreadsheet] openPopover("${E}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const P=W.getActive();if(E==="list"&&et(W.adapter,P.row,P.col)){W.rejectReadOnly({kind:"edit",cell:P,editSession:"none"});return}if(E==="note-tip"){H(P);return}if(E==="message"){if(l.current!==null&&l.current!=="message")return;const re=D!==void 0&&D.message!==void 0?D.message:void 0,ie=W.adapter.getCellValidation===void 0?void 0:W.adapter.getCellValidation(P.row,P.col),oe=re!==void 0?re:ie===void 0?void 0:ie.inputMessage;if(oe===void 0)return;const Oe=D!==void 0&&D.rejected===!0;S({kind:"message",cell:P,anchorRect:j(P),current:{title:Ne(W.labels,"messageTitle"),message:oe,rejected:Oe},close:C});return}if(W.isEditing()&&!W.requestCommit())return;if(E==="list"){const re=W.adapter.getCellValidation===void 0?void 0:W.adapter.getCellValidation(P.row,P.col);if(re===void 0||re.type!=="list")return;const ie=D!==void 0&&D.typed!==void 0?D.typed:"";T(),W.focusSink({preventScroll:!0}),S({kind:"list",cell:P,anchorRect:j(P),current:re.values,typed:ie,commit:oe=>{if(et(t.current.adapter,P.row,P.col)){t.current.rejectReadOnly({kind:"edit",cell:P,editSession:"none"}),C();return}t.current.commitEdits([{row:P.row,col:P.col,text:oe}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(T(),W.focusSink({preventScroll:!0}),E==="note"){const re=W.adapter.getCellNote===void 0?void 0:W.adapter.getCellNote(P.row,P.col),ie={kind:"note",cell:P,anchorRect:j(P),current:re,commit:oe=>{v(ie,[{row:P.row,col:P.col,note:oe}])},close:C,rejected:!1,...O(P)};S(ie);return}if(E==="comment"){const re=W.adapter.getCellComments===void 0?void 0:W.adapter.getCellComments(P.row,P.col),ie={kind:"comment",cell:P,anchorRect:j(P),current:re===void 0?[]:re,commit:oe=>{v(ie,[{row:P.row,col:P.col,comments:oe}])},close:C,rejected:!1,...O(P)};S(ie);return}const G=W.adapter.getCellHyperlink===void 0?void 0:er(W.adapter.getCellHyperlink(P.row,P.col)),X=W.adapter.getCellText(P.row,P.col),Q={kind:"link",cell:P,anchorRect:j(P),current:{text:X,url:G},commit:re=>{const ie=re.url===null?null:an(re.url);if(ie===null&&re.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(re.url)}`);const oe=re.text===X?{row:P.row,col:P.col,hyperlink:ie}:{row:P.row,col:P.col,text:re.text,hyperlink:ie};v(Q,[oe])},close:C,canOpen:W.onHyperlinkOpen!==void 0,open:()=>{const re=t.current.onHyperlinkOpen;re!==void 0&&G!==void 0&&re(G,P)},rejected:!1,...O(P)};S(Q)},[j,C,v,T,S,H,O]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const E=f.current;if(!a||E===null)return;const D=P=>{const G=t.current;gr(G.adapter,G.popovers,"note-tip")&&$({clientX:P.clientX,clientY:P.clientY})},W=()=>{gr(t.current.adapter,t.current.popovers,"note-tip")&&$({cell:null})};return E.addEventListener("pointermove",D),E.addEventListener("pointerleave",W),()=>{E.removeEventListener("pointermove",D),E.removeEventListener("pointerleave",W)}},[a,f,$]),i.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:k,popovers:d}=e,x=i.useMemo(()=>Qw.some(E=>gr(k,d,E)),[k,d]);return i.useMemo(()=>({layerEnabled:x,isKindEnabled:E=>gr(t.current.adapter,t.current.popovers,E),open:y,close:C,isOpen:()=>l.current,onCellHover:g,hideTip:p,onTipPointerEnter:()=>{h.current=!0,Y()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&F()},syncTipAriaDescribedBy:A,context:n,tipContext:o,registerCompositionEnd:E=>{B.current=E},isCompositionKey:E=>pu(E,B.current),getLayerSize:()=>{const E=t.current.handleRef.current;return E===null?{width:0,height:0}:E.getViewportSize()},tipId:M}),[x,y,C,g,p,Y,F,A,n,o,M])},n0=(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},mu=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return dn({row:Dr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:Lr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},r0=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),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),b=i.useRef(null),N=i.useRef(""),B=i.useRef(!1),M=i.useRef(!1),j=i.useCallback(($,g)=>{const{handleRef:p,rowAxis:C,colAxis:S,zoomRef:O}=t.current;return mu(p.current,o.current,C,S,O.current,$,g)},[]),U=i.useRef(!1),Y=i.useRef(null),A=i.useRef(null),T=i.useRef({clientX:0,clientY:0}),F=i.useCallback(()=>{const{autoScroller:$,bodyRef:g,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,U.current=!1,Y.current=null,A.current=null,m.current=!1,b.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),$.stop();const C=g.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),H=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.setSelection($),F()},[F]),{enabled:z,bodyRef:q}=e;return i.useEffect(()=>{const $=q.current;if(!z||$===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const x=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,b.current=null,M.current=!1),B.current=g(d.target),!B.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(x.getPointing?.()){x.focusSink();return}if(x.isEditing()&&!x.requestCommit()){d.stopPropagation(),x.focusSink();return}x.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((x.pointDragRef===void 0?null:x.pointDragRef.current)?.onPointerDown(d))return;if(x.isEditing()&&!x.requestCommit()){d.preventDefault(),x.focusSink();return}o.current=$.getBoundingClientRect();const D=j(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),x.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&x.openHyperlinkAt?.(D)===!0){M.current=!0;return}const W=x.getSelection();r.current=W;const P=d.shiftKey,G=d.ctrlKey||d.metaKey,X=G&&!P&&W.ranges.some(re=>un(re,D));m.current=X,b.current=X?D:null,X||x.setSelection(Or(W,D,{extend:P,append:G})),n.current=!0,x.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{$.setPointerCapture(d.pointerId)}catch{c.current=null}const Q=X?D:x.getSelection().anchor;h.current=re=>fe(Q,re),Y.current=Q.col,A.current=Q.row,x.autoScroller.stop(),U.current=!1,T.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",S=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!U.current&&h.current!==null){const x=Math.abs(d.clientX-T.current.clientX),E=Math.abs(d.clientY-T.current.clientY);Math.max(x,E)>=bo&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:Y.current??void 0,anchorRow:A.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const x=h.current;if(!n.current||x===null)return;const E=t.current,D=j(s.current.clientX,s.current.clientY);D!==null&&E.onDragFrame(x(D))}))}},O=d=>{S(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},v=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const x=t.current,E=j(d.clientX,d.clientY);if(E!==null){const D=b.current;m.current&&D!==null?x.setSelection(du(x.getSelection(),fe(D,E),D)):x.setSelection(vn(x.getSelection(),E))}F()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||H()},f=d=>{const x=t.current;if(!g(d.target)||N.current!=="mouse"||x.isAnyDragging())return;if(x.isEditing()&&!x.requestCommit()){x.focusSink();return}x.focusSink(),o.current=$.getBoundingClientRect();const E=j(d.clientX,d.clientY);if(E===null)return;const D=x.getSelection();D.ranges.some(P=>un(P,E))||x.setSelection(Or(D,E,{extend:!1,append:!1})),x.onContextMenuSelect(E,d)},k=d=>{const x=t.current;if(!B.current||N.current!=="mouse"||x.getPointing?.()||M.current)return;o.current=$.getBoundingClientRect();const E=j(d.clientX,d.clientY);E!==null&&Yt(x.getSelection().active,E)&&x.onRequestEdit(E,x.caretFromPointEnabled(E)?n0(d.clientX,d.clientY,E):void 0)};return $.addEventListener("pointerdown",p),$.addEventListener("pointermove",O),$.addEventListener("pointerup",v),$.addEventListener("lostpointercapture",a),$.addEventListener("contextmenu",f),$.addEventListener("dblclick",k),()=>{$.removeEventListener("pointerdown",p),$.removeEventListener("pointermove",O),$.removeEventListener("pointerup",v),$.removeEventListener("lostpointercapture",a),$.removeEventListener("contextmenu",f),$.removeEventListener("dblclick",k),F()}},[z,q,j,F,H]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:H,cancelDrag:F}),[H,F])},o0=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),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),b=i.useRef(null),N=i.useRef(!1),B=i.useCallback((T,F)=>{const{handleRef:H,rowAxis:z,colAxis:q,zoomRef:$}=t.current;return mu(H.current,o.current,z,q,$.current,T,F)},[]),M=i.useCallback(()=>{const{autoScroller:T,bodyRef:F,onDragFrame:H}=t.current;n.current=!1,r.current=null,m.current=null,b.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const z=F.current;z!==null&&u.current!==null&&z.hasPointerCapture?.(u.current)&&z.releasePointerCapture(u.current),u.current=null,H(null)},[]),j=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.restoreSink(T),M()},[M]),U=i.useCallback(T=>{const F=t.current,H=F.bodyRef.current;if(!F.enabled||H===null||!F.getPointing())return!1;o.current=H.getBoundingClientRect();const z=B(T.clientX,T.clientY);if(z===null)return o.current=null,!1;const q=F.captureSink();if(q===null)return o.current=null,!1;T.preventDefault(),F.focusSink(),r.current=q,b.current=z,F.insertReference(z,"cells"),n.current=!0,s.current={clientX:T.clientX,clientY:T.clientY},l.current={clientX:T.clientX,clientY:T.clientY},u.current=T.pointerId,h.current=T.buttons;try{H.setPointerCapture(T.pointerId)}catch{u.current=null}return m.current=$=>{const g=fe(z,$);return t.current.insertReference(g,"cells"),g},F.autoScroller.stop(),N.current=!1,F.onDragFrame(fe(z,z)),!0},[B]),{enabled:Y,bodyRef:A}=e;return i.useEffect(()=>{const T=A.current;if(!Y||T===null)return;const F=$=>u.current!==null?$.pointerId===u.current:$.pointerType==="mouse",H=$=>{if(!(n.current&&F($)))return;s.current={clientX:$.clientX,clientY:$.clientY};const g=m.current,p=b.current;if(!N.current&&g!==null&&p!==null){const C=Math.abs($.clientX-l.current.clientX),S=Math.abs($.clientY-l.current.clientY);Math.max(C,S)>=bo&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=m.current;if(!n.current||C===null)return;const S=B(s.current.clientX,s.current.clientY);S!==null&&t.current.onDragFrame(C(S))})),(h.current&1)!==0&&($.buttons&1)===0&&M()},z=$=>{$.button!==0||!(n.current&&F($))||M()},q=$=>{!n.current||u.current===null||$.pointerId!==u.current||M()};return T.addEventListener("pointermove",H),T.addEventListener("pointerup",z),T.addEventListener("lostpointercapture",q),()=>{T.removeEventListener("pointermove",H),T.removeEventListener("pointerup",z),T.removeEventListener("lostpointercapture",q),M()}},[Y,A,B,M]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:j,cancelDrag:M,onPointerDown:U}),[j,M,U])},s0=Object.freeze({width:0,height:0}),fs=33,l0=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,i0=(e,t,n)=>{const r=(n-t)/(fs-1);let o=-1,s=-1;for(let c=0;c<fs;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,u)=>{let h=c,m=u;for(;Math.abs(m-h)>1;){const b=(h+m)/2;e(b)?m=b:h=b}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===fs-1?n:l(t+r*(s+1),t+r*s)}},c0=(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})`)},a0=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)})`)},u0=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)})`)},d0=Object.freeze({showArrowButtons:!0,enableThumbDrag:!0,enableTrackClick:!0}),f0=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(d0)){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)})`)}}},hc=(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},p0=24,h0=200,gu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),mc=5,m0=/^#[0-9A-Fa-f]{6}$/,g0=Object.freeze({row:!1,column:!1,intersection:!1}),gc=Object.freeze({ok:!0}),wc=(e,t)=>{if(t===void 0)return gu;if(t.length!==mc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${mc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!m0.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},w0=e=>{for(const t of["row","column","intersection"])if(st(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},C0=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Ba},b0=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},y0=e=>{const t=i.useRef(null),n=t.current;return n!==null&&lt.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},jn={ranges:[fe({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},R0=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=p0,defaultColumnWidth:l=Le.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:m=0,tapScrollCircleOptions:b,scrollBarControls:N,overscanRows:B,overscanCols:M,background:j,onRenderTruncated:U,renderCell:Y,onSelectionChange:A,onCellContextMenu:T,onUndoRequest:F,onRedoRequest:H,onCopyMultiRange:z,onOperationRejected:q,onEditRejected:$,onReadOnlyRejected:g,formatReadOnlyAnnouncement:p,dataVersion:C,maxOperationCells:S=Le.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:O=!0,enableResizeUI:v=!0,headings:y=!0,onContentSizeChange:a,frame:f,formatCellAnnouncement:k,formatSelectionAnnouncement:d,formatCommandAnnouncement:x,formatResizeAnnouncement:E,locale:D,labels:W,shortcuts:P,onCommandBlockedWhileEditing:G,colors:X,formats:Q,highlight:re,defaultHighlight:ie,onHighlightChange:oe,highlightColors:Oe,popovers:ze,renderPopover:Fe,onClipChange:_e,onHyperlinkOpen:Ue,onValidationRejected:He,onPasteSpecialRequest:zt,onClipboardUnavailable:we,onPasteResolved:Be,now:it=Date.now,zoom:dt,defaultZoom:At,onZoomChange:Mt,testId:We,className:Ct,__onCellRender:On,__onVirtualKeyboardRaise:tr,__maxRenderedCells:zr},Oo){const se=i.useMemo(()=>r?Lh(t):t,[t,r]),pe=rc(se.rowCount,s),ge=rc(se.colCount,l),Ut=i.useRef(null);Ut.current===null&&(Ut.current=Hw());const Ae=Ut.current,nr=lt.resolveVirtualScrollLocale(D),Nt=i.useMemo(()=>La(D,W),[D,W]),An=y0(im(Nt)),fn=i.useMemo(()=>Qh(P),[P]),xn=i.useMemo(()=>{if(!v)return;const I=[...fn].filter(([,J])=>rs.includes(J)).sort(([,J],[,ee])=>rs.indexOf(J)-rs.indexOf(ee)).map(([J])=>Kh(J)).filter(J=>J!==null);return I.length===0?void 0:I.join(" ")},[fn,v]),Xt=i.useMemo(()=>({fill:wc("fill",X===void 0?void 0:X.fill),font:wc("font",X===void 0?void 0:X.font)}),[X]),Tn=i.useMemo(()=>Oe===void 0?void 0:w0(Oe),[Oe]);if(se.getConditionalFormats!==void 0&&se.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");c0(n,u),a0(o),u0(f),f0(N);const pn=i.useCallback(()=>Ae.get().editVersion,[Ae]),$n=i.useCallback(w=>Ae.subscribeCoalesced(w),[Ae]),Nr=i.useSyncExternalStore($n,pn,pn)+(C===void 0?0:C),hn=se.getConditionalFormats===void 0?null:se.getConditionalFormats(),Ln=i.useMemo(()=>({index:hn===null?null:iu(hn),memo:Us()}),[se,hn,Nr]),rr=i.useRef(Ln.index);rr.current=Ln.index;const or=i.useRef(Ln.memo);or.current=Ln.memo;const Gt=i.useCallback((w,I,J)=>Xs(se,rr.current,or.current,w,I,J),[se]),Xe=i.useRef(null),[Dn,Ao]=i.useState(()=>Le.clampSpreadsheetZoom(At??1)),ft=Le.clampSpreadsheetZoom(dt??Dn),R=i.useRef(ft);R.current=ft;const L=i.useRef(ft);L.current=ft;const V=i.useRef(null),_=i.useRef(Mt);_.current=Mt;const Z=i.useRef(dt!==void 0);Z.current=dt!==void 0;const ne=i.useCallback(w=>{const I=Le.clampSpreadsheetZoom(w);I!==L.current&&(L.current=I,Z.current||Ao(I),_.current?.(I))},[]),te=se.rowCount===0||se.colCount===0,Te=!te;i.useEffect(()=>{const w=Xe.current;if(!Te||w===null)return;const I=ee=>{ee.defaultPrevented||!ee.altKey||ee.ctrlKey||ee.metaKey||ee.shiftKey||ee.deltaY!==0&&(ee.preventDefault(),ee.stopPropagation(),!V.current?.()&&ne(Le.stepSpreadsheetZoom(L.current,ee.deltaY<0?1:-1)))},J=ee=>{if(ee.defaultPrevented||!(ee.ctrlKey&&ee.altKey)||ee.metaKey||ee.getModifierState("AltGraph"))return;const me=ee.key==="="||ee.key==="+"?Le.stepSpreadsheetZoom(L.current,1):ee.key==="-"?Le.stepSpreadsheetZoom(L.current,-1):ee.key==="0"?1:null;me!==null&&(ee.preventDefault(),ee.stopPropagation(),!V.current?.()&&ne(me))};return w.addEventListener("wheel",I,{passive:!1,capture:!0}),w.addEventListener("keydown",J,!0),()=>{w.removeEventListener("wheel",I,{capture:!0}),w.removeEventListener("keydown",J,!0)}},[ne,Te]);const he=i.useRef(null),Se=i.useRef(null),Ie=i.useRef(null),je=i.useRef(null),de=i.useRef(null),ce=i.useRef(null),le=i.useRef(null),ye=i.useRef(0),Re=i.useRef(null),Ce=i.useRef(0),tt=i.useRef(null),ae=i.useRef(null),xe=i.useRef(null),nt=i.useRef(null),Ge=i.useRef(null),Ze=i.useRef(null),Ee=i.useRef(null),[Ve,Ft]=i.useState(jn),qe=i.useRef(Ve),Me=i.useCallback(()=>qe.current,[]),[mn,xo]=i.useState(()=>ie===void 0?g0:ie),Zt=re!==void 0?re:mn,To=i.useRef(Zt);To.current=Zt;const wu=C0(Tn,Zt),Zs=i.useRef(re!==void 0);Zs.current=re!==void 0;const Js=i.useRef(oe);Js.current=oe;const Cu=i.useCallback(w=>{Zs.current||xo(w),Js.current?.(w)},[]),Qs=i.useRef(null),$o=i.useRef(null),Pt=i.useRef(null),Lo=i.useRef(()=>!1),el=i.useRef(()=>{}),tl=i.useRef(()=>null),nl=i.useRef(()=>{}),gn=i.useCallback(()=>Lo.current(),[]),Do=i.useMemo(()=>({getPointing:()=>Lo.current(),insertReference:(w,I)=>el.current(w,I)}),[]),rl=i.useRef(Ht),ol=i.useRef(null),zo=i.useRef({interactive:null,tip:null}),sl=i.useRef(null),ll=i.useRef(null),Fr=i.useRef(()=>{}),il=i.useRef(()=>!1),Jt=i.useRef(null),sr=i.useCallback(()=>{const w=Jt.current;if(w===null||w.isOpen()!=="message")return!1;const I=w.context;return I===null||I.kind!=="message"||!I.current.rejected?!1:(w.close(),!0)},[]),Mo=i.useRef(()=>!1),cl=i.useRef(()=>!1),al=i.useRef(null),No=i.useRef(()=>Promise.resolve("rejected")),$e=i.useCallback(()=>{Qs.current?.()},[]),_t=i.useCallback(w=>{ce.current?.focus(w)},[]),Ye=i.useCallback(()=>{_t({preventScroll:!0})},[_t]),Fo=i.useRef(!1),bu=i.useCallback(()=>{const w=Xe.current;if(w!==null){Fo.current=!0;try{w.focus()}finally{Fo.current=!1}}},[]),ct=i.useCallback(()=>{const w=ce.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),zn=i.useCallback((w,I)=>{if(w===null)return;const J=I?"":"none";w.style.display!==J&&(w.style.display=J)},[]),bt=i.useCallback(()=>{const w=le.current;if(w!==null){const J=Math.max(0,de.current?.getScrollPosition().y??0),ee=de.current?.getFrozenSize().height??0;w.style.transform=`translateY(${ye.current-J-ee}px)`}const I=de.current;if(I!==null&&(Ge.current!==null||Ze.current!==null)){const J=I.getFrozenSize();zn(Ge.current,J.height>0),zn(Ze.current,J.trailingHeight>0)}},[zn]),yt=i.useCallback(()=>{const w=Re.current;if(w!==null){const J=Math.max(0,de.current?.getScrollPosition().x??0),ee=de.current?.getFrozenSize().width??0;w.style.transform=`translateX(${Ce.current-J-ee}px)`}const I=de.current;if(I!==null&&(xe.current!==null||nt.current!==null)){const J=I.getFrozenSize();zn(xe.current,J.width>0),zn(nt.current,J.trailingWidth>0)}},[zn]),lr=i.useRef(null),Mn=i.useCallback(()=>{xe.current===null&&nt.current===null&&Ge.current===null&&Ze.current===null||lr.current===null&&(lr.current=requestAnimationFrame(()=>{lr.current=null,bt(),yt(),$e()}))},[bt,yt,$e]);i.useEffect(()=>()=>{lr.current!==null&&cancelAnimationFrame(lr.current)},[]);const Po=i.useRef(null),_o=i.useRef(null);(Po.current===null||_o.current?.rowAxis!==pe||_o.current?.colAxis!==ge)&&(_o.current={rowAxis:pe,colAxis:ge},Po.current=Nw({handleRef:de,rowAxis:pe,colAxis:ge}));const Pr=i.useCallback(w=>{const I=de.current,J=I===null?{x:0,y:0}:I.getScrollPosition(),ee=I===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:I.getFrozenSize(),me=I===null?{width:0,height:0}:I.getViewportSize(),ve=R.current;return{top:En(pe,w.row,{scroll:Math.max(0,J.y),frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:me.height})*ve,left:kn(ge,w.col,{scroll:Math.max(0,J.x),frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:me.width})*ve,width:ge.sizeOf(w.col)*ve,height:pe.sizeOf(w.row)*ve}},[pe,ge]),ul=i.useCallback(w=>{const I=je.current,J=Xe.current,ee=Se.current;if(I===null||J===null||ee===null||de.current===null)return;const me=R.current,ve=Pr(w),Qe=ee.offsetTop*me+ve.top,ut=ee.offsetLeft*me+ve.left,Ke=Math.max(0,Qe),Lt=Math.max(0,ut),tn=Math.min(J.clientHeight,Qe+ve.height),jr=Math.min(J.clientWidth,ut+ve.width);if(tn<=Ke||jr<=Lt)return;I.style.top=`${Ke}px`,I.style.left=`${Lt}px`,I.style.width=`${jr-Lt}px`,I.style.height=`${tn-Ke}px`;const _n=I.getBoundingClientRect();_n.width===0&&_n.height===0||I.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Pr]),Qt=i.useCallback(w=>{Po.current?.(w),ul(w)},[ul]),yu=i.useCallback(()=>{const w=de.current,I=w===null?-1:w.getViewportSize().height,J=he.current,ee=Xe.current;if(I<=0||J===null||ee===null)return I;const me=J.getBoundingClientRect(),ve=ee.getRootNode();if(me.height<=0||J.offsetHeight<=0||!l0(ve))return I;const Qe=ee.ownerDocument.documentElement,ut=Math.max(me.left,0),Ke=Math.min(me.right,Qe.clientWidth),Lt=Math.max(me.top,0)+.5,tn=Math.min(me.bottom,Qe.clientHeight)-.5,jr=(ut+Ke)/2,_n=Ke>ut&&tn>=Lt?i0(Gu=>{const Hl=ve.elementFromPoint(jr,Gu);return Hl!==null&&ee.contains(Hl)},Lt,tn):null,Xu=_n===null?Qe.clientHeight:_n.bottom-_n.top+1;return Math.min(I,Xu*(J.offsetHeight/me.height))},[]),dl=i.useRef(a);dl.current=a;const qo=i.useRef(null),qt=i.useCallback(()=>{const w=dl.current;if(w===void 0)return;const I=Se.current;let J;if(I===null)J=s0;else{if(I.getClientRects().length===0)return;{const me=Ie.current,ve=R.current;J={width:((me===null?0:me.offsetWidth)+ge.totalSize()+Le.SPREADSHEET_SCROLLBAR_SIZE_PX)*ve,height:((me===null?0:me.offsetHeight)+pe.totalSize()+Le.SPREADSHEET_SCROLLBAR_SIZE_PX)*ve}}}const ee=qo.current;ee!==null&&ee.width===J.width&&ee.height===J.height||(qo.current=J,w(J))},[pe,ge]);i.useLayoutEffect(()=>{if(a===void 0){qo.current=null;return}qt()});const fl=a!==void 0;i.useEffect(()=>{const w=Se.current;if(!fl||w===null)return;const I=new ResizeObserver(()=>qt());return I.observe(w),()=>I.disconnect()},[fl,qt,te]);const Nn=i.useRef(null),wn=i.useRef(null),Fn=i.useCallback(w=>{Nn.current!==null&&window.clearTimeout(Nn.current),wn.current!==null&&(cancelAnimationFrame(wn.current),wn.current=null),Nn.current=window.setTimeout(()=>{Nn.current=null;const I=Ee.current;I!==null&&(I.textContent="",wn.current=requestAnimationFrame(()=>{wn.current=null,I.textContent=w}))},h0)},[]);i.useEffect(()=>()=>{Nn.current!==null&&window.clearTimeout(Nn.current),wn.current!==null&&cancelAnimationFrame(wn.current)},[]);const Pn=i.useCallback(w=>{g?.(w),p!==void 0&&Fn(p(w))},[g,p,Fn]),pl=i.useCallback((w,I)=>{if(k===void 0&&d===void 0)return;const J=I.ranges[I.ranges.length-1],ee=wt(J),me=I.ranges.length===1&&ee.rows===1&&ee.cols===1,ve=w.ranges[w.ranges.length-1],Qe=w.ranges.length!==I.ranges.length||ve.startRow!==J.startRow||ve.startCol!==J.startCol||ve.endRow!==J.endRow||ve.endCol!==J.endCol,ut=()=>{if(k!==void 0){const Ke=I.active,Lt=se.getCellText(Ke.row,Ke.col),tn=se.getCellFormat===void 0?void 0:Gt(Ke.row,Ke.col,()=>Lt);Fn(k({row:Ke.row,col:Ke.col,text:Lt,displayText:Zn(Lt,tn===void 0?void 0:tn.value),columnName:Le.columnIndexToName(Ke.col),...ya(se)?{readOnly:et(se,Ke.row,Ke.col)}:{}}))}};if(me){ut();return}if(Qe){d!==void 0&&Fn(d({range:J,anchor:I.anchor,active:I.active,rangeRowCount:ee.rows,rangeColCount:ee.cols,rangeCount:I.ranges.length}));return}ut()},[se,k,d,Fn,Gt]),Je=i.useCallback(w=>{const I=qe.current;Object.is(w,I)||$w(w,I)||(qe.current=w,Ft(w),A?.(w),pl(I,w),(Pt.current?.()??!1)||ct())},[A,pl,ct]),Ru=i.useCallback(w=>{const I=qe.current;if(w.mode==="cycle"){const ee=fu(I,w.direction);Je(ee),Qt(ee.active);return}const J=dn(w.cell,pe.count,ge.count);if(w.mode==="extend"){Je(vn(I,J)),Qt(J);return}Je(Or(I,J,{extend:!1,append:!1})),Qt(J)},[Je,Qt,pe,ge]),rt=i.useCallback(()=>Pt.current?.()??!1,[]),hl=i.useRef(null),Rt=i.useCallback(()=>hl.current?.()??!0,[]),ml=i.useRef(null),ir=i.useCallback((w,I)=>{const J=Pt.current?.()??!1;ml.current?.(w,I),!J&&(Pt.current?.()??!1)&&sr()},[sr]),[vu,Io]=i.useState(!1),gl=i.useCallback(()=>{tr?.(),Io(!0)},[tr]),Su=i.useCallback((w,I)=>{et(se,w.row,w.col)||gl(),ir("edit",I)},[se,gl,ir]),wl=i.useRef(null),_r=i.useCallback(()=>wl.current?.()??null,[]),Cl=i.useRef(null),xt=i.useCallback(()=>{Cl.current?.()},[]),bl=i.useRef(null),yl=i.useCallback(w=>{bl.current?.(w)},[]),Rl=i.useRef(()=>{}),qr=i.useRef(0),Cn=i.useCallback((w,I,J)=>{let ee;if(I.source==="paste"){const me=b0(J);if(w.length===0&&me.conditionalFormats.length===0)return null;qr.current+=1,ee={transaction:qr.current,source:"paste",sameSheet:me.sameSheet,conditionalFormats:me.conditionalFormats}}else{if(w.length===0)return null;qr.current+=1,ee={transaction:qr.current,source:I.source}}try{se.applyEdits(w,ee)}catch(me){return $?.(me,I),null}return Ae.bumpEdit(),yl(I.source),ee.transaction},[se,Ae,$,yl]),ku=i.useCallback((w,I)=>Cn(w,{source:"paste"},I),[Cn]),Eu=i.useCallback(w=>{Ae.setVy(w.y),bt(),yt(),$e()},[Ae,bt,yt,$e]),vl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Ou=i.useCallback(w=>{Ae.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ae.setColRange(w.renderingColStart,w.renderingColEnd);const I=vl.current;(I.rowStart!==w.renderingRowStart||I.rowEnd!==w.renderingRowEnd||I.colStart!==w.renderingColStart||I.colEnd!==w.renderingColEnd)&&(vl.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},$e())},[Ae,$e]),Sl=i.useRef(()=>"add"),en=i.useCallback(w=>{$o.current?.(w,Sl.current())},[]),Au=i.useCallback(w=>{$o.current?.(w,"point")},[]),kl=i.useRef(null),jo=i.useCallback(w=>{kl.current?.(w)},[]),El=i.useRef(null),xu=i.useCallback(w=>{El.current?.(w)},[]),Ol=i.useRef(null),Al=i.useCallback((w,I)=>{if(I.length===0)return;const J=de.current;if(w==="col"){for(const ee of I){const me=Math.round(ee.size);ge.resize(ee.index,me),J?.updateColSize(ee.index,me)}Ae.bumpColVersion(),yt(),$e(),Mn(),qt();return}for(const ee of I){const me=Math.round(ee.size);pe.resize(ee.index,me),J?.updateRowSize(ee.index,me)}Ae.bumpRowGeometry(),bt(),$e(),Mn(),qt()},[pe,ge,Ae,yt,bt,$e,Mn,qt]),xl=v?Al:void 0,Tu=i.useCallback((w,I)=>{T?.(w,{kind:"pointer",event:I})},[T]),$u=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:en,axis:"both",zoomRef:R}),Lu=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:en,axis:"x",zoomRef:R}),Du=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:en,axis:"y",zoomRef:R}),zu=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:jo,axis:"x",zoomRef:R}),Mu=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:jo,axis:"y",zoomRef:R}),Nu=In({handleRef:de,rowAxis:pe,colAxis:ge,bodyRef:he,onDragFrame:en,axis:"both",zoomRef:R}),Tl=i.useRef(null),$l=i.useRef(()=>!1),Ho=i.useCallback(()=>$l.current(),[]),vt=r0({zoomRef:R,enabled:!te,rowAxis:pe,colAxis:ge,handleRef:de,bodyRef:he,isEditing:rt,requestCommit:Rt,getSelection:Me,setSelection:Je,focusSink:Ye,onDragFrame:en,onContextMenuSelect:Tu,onRequestEdit:Su,caretFromPointEnabled:w=>{if(Y!==void 0||se.getCellFormula!==void 0&&se.getCellFormula(w.row,w.col)!==void 0)return!1;if(se.getCellFormat===void 0)return!0;const I=se.getCellText(w.row,w.col);return Zn(I,se.getCellFormat(w.row,w.col)?.value)===I},isAnyDragging:Ho,autoScroller:$u,repaintOverlay:$e,pointDragRef:Tl,getPointing:gn,openHyperlinkAt:Ue===void 0||se.getCellHyperlink===void 0?void 0:w=>{const I=se.getCellHyperlink===void 0?void 0:er(se.getCellHyperlink(w.row,w.col));return I===void 0?!1:(Ue(I,w),!0)}}),Tt=pc({zoomRef:R,enabled:!te&&y,axis:"col",headerRef:tt,mainAxis:ge,crossCount:se.rowCount,handleRef:de,isEditing:rt,requestCommit:Rt,getSelection:Me,setSelection:Je,focusSink:Ye,onDragFrame:en,autoScroller:Lu,repaintOverlay:$e,pointing:Do}),$t=pc({zoomRef:R,enabled:!te&&y,axis:"row",headerRef:ae,mainAxis:pe,crossCount:se.colCount,handleRef:de,isEditing:rt,requestCommit:Rt,getSelection:Me,setSelection:Je,focusSink:Ye,onDragFrame:en,autoScroller:Du,repaintOverlay:$e,pointing:Do}),at=Tw({zoomRef:R,enabled:!te&&v&&y,colBandRef:tt,rowBandRef:ae,fontSourceRef:he,colAxis:ge,rowAxis:pe,viewStore:Ae,handleRef:de,isEditing:rt,requestCommit:Rt,focusSink:Ye,getSelection:Me,adapter:se,autofitEnabled:Y===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:S,onOperationRejected:q,resizeTracks:Al,writeResizeGuide:xu,repaintOverlay:$e,isPointing:gn}),St=Vw({zoomRef:R,enabled:!te&&O,handleNodeRef:Ol,bodyRef:he,rowAxis:pe,colAxis:ge,handleRef:de,getSelection:Me,setSelection:Je,focusSink:Ye,adapter:se,commitEdits:Cn,maxOperationCells:S,onOperationRejected:q,rejectReadOnly:Pn,writeFillPreview:jo,repaintOverlay:$e,xAutoScroller:zu,yAutoScroller:Mu}),pt=o0({zoomRef:R,enabled:!te,bodyRef:he,handleRef:de,rowAxis:pe,colAxis:ge,getPointing:gn,insertReference:Do.insertReference,captureSink:()=>tl.current(),restoreSink:w=>nl.current(w),focusSink:Ye,autoScroller:Nu,onDragFrame:en});Tl.current=pt;const cr=i.useCallback(()=>vt.isDragging()||Tt.isDragging()||$t.isDragging()||at.isDragging()||St.isDragging()||pt.isDragging(),[vt,Tt,$t,at,St,pt]);V.current=cr,$l.current=cr,Sl.current=()=>pt.isDragging()?"point":vt.getDragMode();const Fu=i.useCallback(()=>{vt.abortDrag(),Tt.abortDrag(),$t.abortDrag(),at.abortDrag(),St.abortDrag(),pt.abortDrag()},[vt,Tt,$t,at,St,pt]),Bo=i.useCallback(()=>qe.current.active,[]),Ll=i.useCallback((w,I)=>{const J=se.getCellValidation===void 0?void 0:se.getCellValidation(w.row,w.col);if(J===void 0)return gc;const ee=se.evaluateFormula,me=Ma(J,I,nr,ee===void 0?void 0:ve=>ee(ve,w));return me.ok||J.strict!==!0?gc:(He?.({cell:w,rule:J,text:I,message:me.message}),Jt.current?.isKindEnabled("message")&&Fr.current("message",{message:me.message,rejected:!0}),me)},[se,He,nr]),Pe=Vg({enabled:!te,sinkRef:ce,rootRef:Xe,adapter:se,commitEdits:Cn,getActive:Bo,ensureCellVisible:Qt,focusSink:_t,rearmSink:ct,discardClip:xt,isDragging:Ho,rejectReadOnly:Pn,resolveEditAlign:w=>{if(se.getCellFormat===void 0)return null;const I=ao(se,w.row,w.col);return ba(Gt(w.row,w.col,I),I)},resolveEditPaint:w=>se.getCellFormat===void 0?null:Af(Gt(w.row,w.col,ao(se,w.row,w.col))),editPaintRef:rl,repaintOverlay:$e,validateCommit:Ll});Pt.current=Pe.isEditing,hl.current=Pe.requestCommit,ml.current=Pe.startEdit,Lo.current=Pe.getPointing,el.current=Pe.insertReference,tl.current=Pe.captureSink,nl.current=Pe.restoreSink;const Dl=i.useCallback(()=>{Pe.cancelEdit(),sr()},[Pe.cancelEdit,sr]),ar=Eg({enabled:!te,sinkRef:ce,adapter:se,isEditing:rt,getSelection:Me,setSelection:Je,commitPaste:ku,maxOperationCells:S,onOperationRejected:q,onCopyMultiRange:z,repaintOverlay:$e,isDragging:Ho,resize:{rowAxis:pe,colAxis:ge,resizeTracks:xl},pendingPasteOptionsRef:ol,formats:Q,onClipChange:_e,onClipboardUnavailable:we,onEditRejected:$,rejectReadOnly:Pn,onPasteResolved:Be});wl.current=ar.getClip,Cl.current=ar.discardClip,bl.current=ar.discardClipOnCommit,Rl.current=ar.onAdapterSwitch,No.current=ar.paste;const ur=t0({enabled:!te,adapter:se,popovers:ze,sinkRef:ce,bodyRef:he,handleRef:de,rowAxis:pe,colAxis:ge,zoomRef:R,getActive:Bo,isEditing:rt,requestCommit:Rt,focusSink:_t,rearmSink:ct,isDraggingAny:cr,commitEdits:Cn,labels:Nt,onHyperlinkOpen:Ue,anchors:zo,repaintOverlay:$e,rejectReadOnly:Pn});Jt.current=ur,Fr.current=ur.open,il.current=ur.hideTip;const Pu=i.useCallback(()=>{const w=qe.current.active;return Qt(w),Pr(w)},[Qt,Pr]),Wo=Hg({adapter:se,trackResize:v&&!te?at:void 0,getSelection:Me,commitEdits:Cn,getActive:Bo,isEditing:rt,requestCommit:Rt,cancelEdit:Dl,getSessionText:Pe.getSessionText,validateCommit:Ll,insertAtCaret:Pe.insertAtCaret,refreshEditPaint:Pe.refreshPaint,maxOperationCells:S,onOperationRejected:q,colors:Xt,formats:Q,getHighlight:()=>To.current,setHighlight:Cu,popovers:ze,openPopover:w=>Fr.current(w),onHyperlinkOpen:Ue,onPasteSpecialRequest:zt,paste:w=>No.current(w),rowAxis:pe,colAxis:ge,resizeTracks:xl,defaultRowHeight:s,defaultColumnWidth:l,now:it,announce:Fn,formatCommandAnnouncement:x,formatResizeAnnouncement:E,keyboardCellRect:Pu,rejectReadOnly:Pn});al.current=Wo,Mo.current=Wo.executeCommand,cl.current=Wo.isCommandAvailable;const _u=i.useMemo(()=>({table:fn,execute:w=>Mo.current(w),isAvailable:w=>cl.current(w)}),[fn]),qu=i.useCallback(()=>{xt(),F?.()},[xt,F]),Iu=i.useCallback(()=>{xt(),H?.()},[xt,H]);jw({zoomRef:R,enabled:!te,sinkRef:ce,rootRef:Xe,handOffFocusToRoot:bu,getSelection:Me,setSelection:Je,moveActive:Ru,ensureCellVisible:Qt,pageExtent:yu,isEditing:rt,requestCommit:Rt,startEdit:ir,commitEdits:Cn,maxOperationCells:S,onOperationRejected:q,rejectReadOnly:Pn,getClip:_r,discardClip:xt,isDragging:cr,abortDrag:Fu,findDataEdge:se.findDataEdge,getEditingMode:Pe.getEditingMode,cancelEdit:Dl,onUndoRequest:qu,onRedoRequest:Iu,onCellContextMenu:T,rowAxis:pe,colAxis:ge,handleRef:de,rearmSink:ct,commands:_u,onCommandBlockedWhileEditing:G,pointing:Pe,adapter:se,hideNoteTip:()=>il.current(),closeRejectedMessage:sr,pendingPasteOptionsRef:ol,onPointFrame:Au});const ju=Ve.active.row,Hu=Ve.active.col;i.useLayoutEffect(()=>{const w=Jt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[ju,Hu]),i.useLayoutEffect(()=>{$e()},[$e,Zt.row,Zt.column,Zt.intersection]),i.useLayoutEffect(()=>{$e()},[$e,f?.startRow,f?.startCol,f?.endRow,f?.endCol]);const Bu=i.useCallback(w=>{(Pt.current?.()??!1)||(w.preventDefault(),Ye(),ct())},[Ye,ct]),Wu=i.useCallback(w=>{const I=Xe.current,J=w.relatedTarget,ee=I!==null&&!I.matches(":focus-visible");if(I!==null&&J instanceof Node&&I.contains(J)){w.target===I&&J===ce.current&&!Fo.current&&_t({preventScroll:ee});return}(Pt.current?.()??!1)||(_t({preventScroll:ee}),ct())},[_t,ct]),Vu=i.useCallback(w=>{const I=Xe.current,J=w.relatedTarget;I!==null&&J instanceof Node&&I.contains(J)||Pe.isFocusoutSuppressed()||Io(!1)},[Pe]),Ir=i.useRef(null),dr=i.useCallback(()=>{const w=Ir.current;w!==null&&(Ir.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Vo=i.useCallback(()=>{if(Ir.current!==null)return;const w=J=>{J.pointerType==="mouse"&&(dr(),J.button===1&&J.preventDefault())},I=J=>{J.pointerType==="mouse"&&dr()};Ir.current={up:w,cancel:I},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",I,!0)},[dr]);i.useEffect(()=>dr,[dr]),i.useEffect(()=>{const w=Xe.current;if(te||w===null)return;let I=0;const J=ve=>{if(ve.pointerType!=="mouse"){(Pt.current?.()??!1)||Io(!1);return}I=ve.buttons,ve.button===1&&(ve.target===ce.current&&(Pt.current?.()??!1)||Vo())},ee=ve=>{ve.pointerType==="mouse"&&(I=ve.buttons)},me=ve=>{if(ve.pointerType!=="mouse"||ve.buttons===I)return;const Qe=ve.buttons&~I;I=ve.buttons,ve.preventDefault(),(Qe&4)!==0&&Vo()};return w.addEventListener("pointerdown",J,!0),w.addEventListener("pointerup",ee,!0),w.addEventListener("pointermove",me,!0),()=>{w.removeEventListener("pointerdown",J,!0),w.removeEventListener("pointerup",ee,!0),w.removeEventListener("pointermove",me,!0)}},[te,Vo]);const Yu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(gn()){Ye();return}if(rt()&&!Rt()){Ye();return}Ye()}},[Ye,rt,Rt,gn]),Yo=i.useRef(!1);i.useLayoutEffect(()=>{if(te){Yo.current=!1;return}if(Yo.current)return;Yo.current=!0,ct();const w=(Xe.current?.clientHeight??0)/R.current;w>0&&pe.totalSize()>0&&Ae.setRowRange(0,pe.indexAt(Math.min(w-1,pe.totalSize()-1)));const I=(Xe.current?.clientWidth??0)/R.current;I>0&&ge.totalSize()>0&&Ae.setColRange(0,ge.indexAt(Math.min(I-1,ge.totalSize()-1)))},[te,ct,Ae,pe,ge]);const zl=i.useRef(t);i.useLayoutEffect(()=>{zl.current!==t&&(zl.current=t,vt.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),at.cancelDrag(),St.cancelDrag(),pt.cancelDrag(),Pe.cancelEdit(),Jt.current?.hideTip(),Jt.current?.close(),te?(qe.current=jn,Ft(jn)):Je(jn),Rl.current())},[t,te,Je,vt,Tt,$t,at,St,pt,Ae,Pe.cancelEdit]);const Ml=i.useRef({adapter:se,rows:pe.count,cols:ge.count}),{getSessionCell:Nl,cancelEdit:Fl}=Pe;i.useLayoutEffect(()=>{const w=Ml.current,I=pe.count,J=ge.count;if(Ml.current={adapter:se,rows:I,cols:J},w.adapter!==se||I>=w.rows&&J>=w.cols)return;te?(qe.current=jn,Ft(jn)):Je(Lw(qe.current,I,J)),vt.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),at.cancelDrag(),St.cancelDrag(),pt.cancelDrag();const ee=ut=>te||ut.row>=I||ut.col>=J,me=Nl();me!==null&&ee(me)&&Fl();const ve=zo.current;if(ve.tip!==null&&ee(ve.tip)&&Jt.current?.hideTip(),ve.interactive!==null&&ee(ve.interactive)){const ut=Xe.current?.contains(document.activeElement)===!0;Jt.current?.close({restoreFocus:ut})}const Qe=_r();Qe!==null&&!Qe.foreign&&ee({row:Qe.range.endRow,col:Qe.range.endCol})&&xt()},[se,pe.count,ge.count,te,Je,vt,Tt,$t,at,St,pt,Nl,Fl,_r,xt]);const Pl=i.useRef(c),_l=i.useRef(u),ql=i.useRef(h),Il=i.useRef(m);i.useLayoutEffect(()=>{(Pl.current!==c||_l.current!==u||ql.current!==h||Il.current!==m)&&(Pl.current=c,_l.current=u,ql.current=h,Il.current=m,vt.cancelDrag(),Tt.cancelDrag(),$t.cancelDrag(),at.cancelDrag(),St.cancelDrag(),pt.cancelDrag())},[c,u,h,m,vt,Tt,$t,at,St,pt]),i.useLayoutEffect(()=>{bt(),yt(),$e()},[c,u,h,m,bt,yt,$e]);const jl=i.useRef(C);i.useLayoutEffect(()=>{jl.current!==C&&(jl.current=C,xt())},[C,xt]),i.useLayoutEffect(()=>{$e()},[$e,Ve]);const bn=i.useCallback(()=>{const w=al.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(Oo,()=>({resizeRow:(w,I)=>{const J=Math.round(I);pe.resize(w,J),de.current?.updateRowSize(w,J),Ae.bumpRowGeometry(),bt(),$e(),Mn(),qt()},resizeColumn:(w,I)=>{const J=Math.round(I);ge.resize(w,J),de.current?.updateColSize(w,J),Ae.bumpColVersion(),yt(),$e(),Mn(),qt()},autoFitColumns:w=>{for(const I of w)if(!Number.isInteger(I)||I<0||I>=ge.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${ge.count-1} (got ${String(I)})`);return at.autofitColumnsInAllRows(w)},scrollToCell:(w,I)=>{de.current?.scrollToCell(w.row,w.col,I)},focus:w=>{_t(w),rt()||ct()},executeCommand:w=>Mo.current(w),applyFormat:w=>bn().applyFormat(w),setBorders:(w,I)=>bn().setBorders(w,I),setHyperlink:w=>bn().setHyperlink(w),setNote:w=>bn().setNote(w),addComment:w=>bn().addComment(w),setValidation:w=>bn().setValidation(w),paste:w=>No.current(w),getSelection:()=>qe.current,getBaseFormat:w=>se.getCellFormat===void 0?void 0:se.getCellFormat(w.row,w.col),getPaintedFormat:w=>se.getCellFormat===void 0?void 0:Gt(w.row,w.col,ao(se,w.row,w.col)),startEdit:w=>{ir(w)},openPopover:w=>{Fr.current(w)}}),[pe,ge,Ae,yt,bt,$e,Mn,qt,at,_t,rt,ct,se,Gt,ir,bn]),te)return K.jsx("div",{className:Ct?`aqsp-root ${Ct}`:"aqsp-root","data-aqsp-empty":"","data-testid":We});const Ku=k!==void 0||d!==void 0||x!==void 0||p!==void 0||E!==void 0,Uu=o===void 0?{"aria-label":Nt.rootAriaLabel}:{"aria-labelledby":o};return K.jsxs("div",{ref:Xe,className:Ct?`aqsp-root ${Ct}`:"aqsp-root",role:"group",...Uu,tabIndex:0,onFocus:Wu,onBlur:Vu,"data-aqsp-root":"","data-aqsp-headings-hidden":y?void 0:"","data-aqsp-framed":f===void 0?void 0:"","data-testid":We,children:[K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":ft,onPointerDown:Yu,style:ft===1?void 0:{width:`${100/ft}%`,height:`${100/ft}%`,transform:`scale(${ft})`,"--_aqsp-zoom":String(ft)},children:[y?K.jsxs(K.Fragment,{children:[K.jsx("div",{ref:Ie,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(gn()){Ye();return}if(rt()&&!Rt()){Ye();return}Ye(),Je({ranges:[fe({row:0,col:0},{row:se.rowCount-1,col:se.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(Ew,{viewStore:Ae,colAxis:ge,frozenCols:c,frozenTrailingCols:h,handleRef:de,bandRef:tt,colTrackRef:Re,windowOriginXRef:Ce,repaintColHeaders:yt,selectionRanges:Ve.ranges,enableResizeUI:v,dividerLeadingRef:xe,dividerTrailingRef:nt}),K.jsx(Ow,{viewStore:Ae,rowAxis:pe,handleRef:de,bandRef:ae,selectionRanges:Ve.ranges,rowTrackRef:le,windowOriginYRef:ye,repaintHeaders:bt,enableResizeUI:v,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:Ge,dividerTrailingRef:Ze})]}):null,K.jsxs("div",{ref:Se,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(kw,{adapter:se,rowAxis:pe,colAxis:ge,viewStore:Ae,handleRef:de,bodyRef:he,dataVersion:C,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:m,headerRows:n,labelledBy:o,gridLabel:o===void 0?Nt.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:b,showArrowButtons:N?.showArrowButtons,enableThumbDrag:N?.enableThumbDrag,enableTrackClick:N?.enableTrackClick,overscanRows:hc("overscanRows",B),overscanCols:hc("overscanCols",M),background:j,onRenderTruncated:U,renderCell:Y,onScroll:Eu,onRangeChange:Ou,focusSink:Ye,isEditing:rt,requestCommit:Rt,testId:We?`${We}-vs`:void 0,__onCellRender:On,__maxRenderedCells:zr,cfIndexRef:rr,cfMemoRef:or,isPointing:gn,locale:nr,scrollLabels:An}),K.jsx(Qm,{rowAxis:pe,colAxis:ge,handleRef:de,sinkRef:ce,getSelection:Me,editing:Pe.editing,virtualKeyboard:vu,repaintRef:Qs,dragFrameRef:$o,getClip:_r,getIsDraggingAny:cr,getIsFillDragging:St.isDragging,fillFrameRef:kl,resizeGuideFrameRef:El,fillHandleNodeRef:Ol,enableFillHandle:O,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:m,sinkAriaLabel:Nt.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:xn,onSinkMouseDown:Bu,editPaintRef:rl,highlightRef:To,frameRange:f,highlightColors:wu,popoverAnchors:zo,interactiveAnchorRef:sl,tipAnchorRef:ll}),ur.layerEnabled?K.jsx(Jw,{controller:ur,labels:Nt,renderPopover:Fe,interactiveAnchorRef:sl,tipAnchorRef:ll}):null]}),Ku?K.jsx("div",{ref:Ee,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),K.jsx("div",{ref:je,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=Vt.iterateTsvPrefixRows;exports.iterateTsvRows=Vt.iterateTsvRows;exports.measureTsv=Vt.measureTsv;exports.parseTsv=Vt.parseTsv;exports.serializeClipboardTsv=Vt.serializeClipboardTsv;exports.serializeTsv=Vt.serializeTsv;exports.columnIndexToName=Le.columnIndexToName;exports.columnNameToIndex=Le.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=zs;exports.CommentPopover=Wa;exports.DEFAULT_CUSTOM_COLORS=gu;exports.DEFAULT_HIGHLIGHT_COLORS=Ba;exports.DEFAULT_SHORTCUTS=xa;exports.LinkPopover=Va;exports.ListPopover=Ya;exports.MessagePopover=Ka;exports.NotePopover=Ua;exports.NoteTip=Xa;exports.SPREADSHEET_LABEL_CATALOGS=$a;exports.SPREADSHEET_RESERVED_SHORTCUTS=Uh;exports.Spreadsheet=R0;exports.canonicalizeFormat=Ot;exports.detectClipSource=Ac;exports.enumerateRangeCells=nn;exports.estimatePasteCellCount=Nh;exports.expandPaste=Fh;exports.formatCellValue=Zn;exports.formatEquals=id;exports.fromR1C1=Tr;exports.makeRange=fe;exports.mergeFormat=Ns;exports.normalizeHyperlink=an;exports.parseChord=Bt;exports.parseClipPayload=ms;exports.parseHtmlTable=Ca;exports.rangeContains=un;exports.rangeSize=wt;exports.resolveLabel=Ne;exports.resolveLabels=La;exports.serializeClipPayload=kc;exports.serializeHtmlTable=ha;exports.shiftFormula=Zc;exports.toR1C1=vo;exports.validateCellText=Ma;