@aiquants/spreadsheet 0.21.0 → 0.21.2
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/CHANGELOG.md +50 -0
- package/README.md +26 -0
- package/dist/index.cjs +8 -8
- package/dist/index.js +658 -657
- package/dist/styles/spreadsheet.css +1 -1
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/package.json +5 -2
- package/src/keyboard/compositionGuard.ts +15 -9
- package/src/styles/spreadsheet.css +34 -0
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nn=require("./tsv.cjs"),Fe=require("./view-BkwCUzTl.cjs"),rt=require("@aiquants/virtualscroll"),I=require("react/jsx-runtime"),i=require("react"),Pd=require("react-dom"),Gs=1e3,yn=1e4,Js=10,Ci=2**(1/4),_d=(e,t)=>e<=0?e:t>0?e>=yn?e:Math.min(yn,Math.max(e+1,Math.round(e*Ci))):Math.max(1,Math.min(e-1,Math.round(e/Ci))),yi=(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),Zs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Js):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),yn))}let l=[...s].map(([a,u])=>({index:a,size:u}));if(e.count-e.hiddenCount()-yi(e,l)===0){const a=n===null?l[0].index:n;l=l.map(u=>u.index===a?{index:u.index,size:1}:u)}if(r.axisKind==="row"){const a=e.hiddenCount()+yi(e,l);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:l}},Qs="#000000",no=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},jd=20,Id=256,ro=new Map,as=new WeakMap,Rt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Hd=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},Bd=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:jd}:no(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...no(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...no(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...no(e.decimals)};default:return null}},Vd=e=>{const t=as.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=ro.get(n);if(r!==void 0)return as.set(e,r),r;ro.size>=Id&&ro.clear();const o=Bd(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return ro.set(n,s),as.set(e,s),s},Wd=(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}},Jc=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>Wd(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Kd=(e,t)=>{const n=Jc(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)}})},Ln=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Kd(e,t.pattern??"yyyy/MM/dd");const n=Rt(e);if(n===null)return e;const r=Vd(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Hd(n,-2):n)},bi=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Jc(n)!==null?"right":"left":Rt(n)!==null?"right":"left",zr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Zc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Yd=["bottom","left","right","top"],Qc=(e,t,n)=>{e[t]=n},ea=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Xd=e=>{if(e===void 0)return;const t={};for(const n of Yd){const r=e[n];r!==void 0&&(t[n]=ea(r))}return Object.keys(t).length===0?void 0:t},Nt=e=>{const t={};for(const n of Zc){const r=n==="borders"?Xd(e.borders):n==="value"?e.value===void 0?void 0:ea(e.value):e[n];r!==void 0&&r!==!1&&Qc(t,n,r)}return Object.keys(t).length===0?void 0:t},el=(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]||!el(o[c],s[c]))return!1}return!0},Ud=(e,t)=>e===t?!0:el(e===void 0?void 0:Nt(e),t===void 0?void 0:Nt(t)),tl=(e,t)=>{const n={};for(const o of Zc){const s=t[o];Qc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=Nt(n);return el(r,e===void 0?void 0:Nt(e))?e:r},ta="data-aqsp-clip",xo="application/x-aqsp-clip",Ms=512,vi=16*1024,Ls=`${ta}=`,Gd=16,nl=()=>{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(Gd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},_r=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),he=e=>typeof e=="string",st=e=>typeof e=="boolean",pn=e=>typeof e=="number"&&Number.isFinite(e),zt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Ri=e=>zt(e)&&e>=1,Jd=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=yn,tn=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Zd=e=>t=>Array.isArray(t)&&t.every(e),qe=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),rn=(e,t)=>{if(!_r(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},rl=e=>t=>{if(!_r(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&rn(t,n)},Qd=["left","center","right"],ef=["top","middle","bottom"],tf=["thin","medium","thick","dashed","dotted","double","hair"],us=["gt","gte","lt","lte","eq","neq","between","notBetween"],nf=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],rf=["eq","neq","gt","gte","lt","lte","between","notBetween"],of=["contains","notContains","startsWith","endsWith"],sf=new Map([["number",qe({type:he,decimals:pn,grouping:st,locale:he},["type"])],["percent",qe({type:he,decimals:pn,scale:st,locale:he},["type"])],["currency",qe({type:he,currency:he,decimals:pn,locale:he},["type","currency"])],["scientific",qe({type:he,decimals:pn,locale:he},["type"])],["date",qe({type:he,pattern:he},["type"])],["text",qe({type:he},["type"])]]),lf=qe({style:tn(tf),color:he},["style"]),oo=e=>rn(e,lf),cf=qe({top:oo,right:oo,bottom:oo,left:oo},[]),af=qe({value:rl(sf),align:tn(Qd),verticalAlign:tn(ef),wrap:st,background:he,color:he,bold:st,italic:st,underline:st,strikethrough:st,fontFamily:he,fontSize:pn,borders:e=>rn(e,cf)},[]),uf=e=>rn(e,af),Tn={strict:st,inputMessage:he,errorMessage:he},df=new Map([["list",qe({...Tn,type:he,values:Zd(he),showDropdown:st},["type","values"])],["number",qe({...Tn,type:he,op:tn(us),a:he,b:he},["type","op","a"])],["textLength",qe({...Tn,type:he,op:tn(us),a:pn,b:pn},["type","op","a"])],["date",qe({...Tn,type:he,op:tn(us),a:he,b:he},["type","op","a"])],["text",qe({...Tn,type:he,op:tn(nf),value:he},["type","op"])],["checkbox",qe({...Tn,type:he,checked:he,unchecked:he},["type"])],["custom",qe({...Tn,type:he,formula:he},["type","formula"])]]),ff=rl(df),pf=qe({startRow:zt,startCol:zt,endRow:zt,endCol:zt},["startRow","startCol","endRow","endCol"]),hf=e=>{if(!rn(e,pf))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return zt(t)&&zt(r)&&zt(n)&&zt(o)&&t<=r&&n<=o},mf=qe({color:he,value:pn},["color"]),ds=e=>rn(e,mf),gf=new Map([["cellValue",qe({type:he,op:tn(rf),a:he,b:he},["type","op","a"])],["text",qe({type:he,op:tn(of),value:he},["type","op","value"])],["empty",qe({type:he},["type"])],["notEmpty",qe({type:he},["type"])],["colorScale",qe({type:he,min:ds,mid:ds,max:ds},["type","min","max"])],["customFormula",qe({type:he,formula:he},["type","formula"])]]),wf=qe({background:he,color:he,bold:st,italic:st,underline:st,strikethrough:st},[]),Cf=qe({sourceRuleId:he,ranges:Array.isArray,condition:rl(gf),style:e=>rn(e,wf),stopIfTrue:st},["sourceRuleId","ranges","condition","style"]),yf=(e,t,n)=>{if(!rn(e,Cf))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!hf(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},bf=qe({text:he,author:he,createdAt:he},["text","author","createdAt"]),vf=e=>rn(e,bf),Rf=(e,t,n)=>{if(!_r(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(!zt(o)||o>=t)return!1;break;case"val":if(!zt(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(vf)))return!1;break;default:return!1}}return!0},Si=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Jd),Sf=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),na=e=>{if(!_r(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Sf.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Ri(t)&&Ri(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(uf)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(ff)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!Rf(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Si(e.colWidths,n)||e.rowHeights!==void 0&&!Si(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>yf(c,t,n))},qr=e=>Array.isArray(e)?`[${e.map(qr).join(",")}]`:_r(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${qr(e[n])}`).join(",")}}`:JSON.stringify(e),Ef=e=>{const t=Nt(e);return t===void 0?"{}":JSON.stringify(t)},kf=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Of=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(kf).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},ra=e=>{if(!na(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(Ef).join(","),r=e.validations.map(qr).join(","),o=e.cells.map(a=>`[${a.map(Of).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(qr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},zs=e=>{let t;try{t=JSON.parse(e)}catch{return null}return na(t)?t:null},xf=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Af=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),oa=e=>e.includes("&")?e.replace(xf,t=>Af[t]):e,Tf=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Ei=e=>{const t=e.length>Ms?e.slice(0,Ms):e,n=Tf.exec(oa(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},$f=e=>{const t=e.indexOf(Ls);if(t===-1)return null;const n=t+Ls.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},sa=(e,t)=>{if(t==="event"&&e.types.includes(xo))return{kind:"mime",json:e.getData(xo)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=$f(n);return r===null?null:{kind:"attribute",html:n,at:r}},Mf=(e,t)=>{const n=sa(e,t);return n===null?null:n.kind==="mime"?Ei(n.json):Ei(n.html.slice(n.at.start,n.at.start+Ms))},Lf=(e,t)=>{const n=sa(e,t);if(n===null)return null;if(n.kind==="mime")return zs(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:zs(oa(n.html.slice(n.at.start,r)))},zf=/<google-sheets-html-origin[\s>]/,Nf='data-sheets-root="1"',Df=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ff="mso-",qf=/\.xl\d+\s*\{/,Pf="<table",_f=e=>e.includes(Ls)?"aqsp":zf.test(e)&&e.includes(Nf)?"sheets":Df.test(e)||e.includes(Ff)||qf.test(e)?"excel":null,la=(e,t)=>{if(t==="event"&&e.types.includes(xo))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>vi?n.slice(0,vi):n,o=_f(r);if(o==="aqsp")return"aqsp";if(n.includes(Pf))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},ol=1e3,ia=65534,jf=9,If=10,Hf=12,Bf=13,Vf=32,ca=34,aa=39,Wf=43,sl=47,ki=48,Kf=57,Yf=61,Xf=62,Uf=97,Gf=98,Jf=100,Zf=102,ua=104,da=114,fa=116,Qf=["able","body","head","foot"],Nr=e=>e===Vf||e===jf||e===If||e===Bf||e===Hf,Ns=e=>e===Xf||e===sl||Nr(e),ep=e=>Nr(e)||e===sl||e===ca||e===aa,tp=(e,t,n,r)=>{if(t===0||!ep(e.charCodeAt(t-1)))return null;let o=t+n;for(;Nr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Yf)return 1;for(o+=1;Nr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===ca||s===aa)&&(o+=1);Nr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Wf&&(o+=1);let l=0,c=0;for(let a=e.charCodeAt(o);a>=ki&&a<=Kf;a=e.charCodeAt(o))l=l*10+(a-ki),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Oi=(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=tp(e,r,t.length,n);if(l!==null)return l}return 1}},np=(e,t)=>{if(e.charCodeAt(t+2)!==fa)return!1;const n=e.charCodeAt(t+3);if(n===da)return Ns(e.charCodeAt(t+4));if(n!==Uf&&n!==Gf&&n!==ua&&n!==Zf)return!1;for(const r of Qf)if(e.startsWith(r,t+3)&&Ns(e.charCodeAt(t+3+r.length)))return!0;return!1},rp=e=>{const t=e.toLowerCase(),n=Oi(t,"colspan",ol),r=Oi(t,"rowspan",ia);let o=0;const s=H=>(o!==-1&&o<H&&(o=t.indexOf(">",H)),o===-1?t.length:o);let l=0,c=0,a=0,u=0,h=!1;const g=new Map,L=(H,Z)=>{const Q=g.get(H);g.set(H,Q===void 0?Z:Q+Z)},M=()=>{h&&a+u>c&&(c=a+u),h=!1},$=()=>{M(),l+=1,h=!0,a=0;const H=g.get(l-1);H!==void 0&&(u+=H)};for(let H=t.indexOf("<");H!==-1;H=t.indexOf("<",H+1)){const Z=t.charCodeAt(H+1);if(Z===sl){np(t,H)&&M();continue}if(Z!==fa||!Ns(t.charCodeAt(H+3)))continue;const Q=t.charCodeAt(H+2);if(Q===da)$();else if(Q===Jf||Q===ua){h||$();const O=H+3,D=s(O),W=n(O,D);a+=W;const K=r(O,D);K>1&&(L(l,W),L(l-1+K,-W))}}return M(),{rows:l,cols:c}},pa=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}},ha=()=>{const e=new WeakMap,t=pa(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=Nt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},op=()=>{const e=new WeakMap,t=pa(qr);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}},sp=new Set(["http:","https:","mailto:","tel:"]),bn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return sp.has(n.protocol)?n.href:null},fr=e=>{if(e===void 0)return;const t=bn(e);return t===null?void 0:t},ma=(e,t)=>e.startCol===0&&e.endCol===t-1,ga=(e,t)=>e.startRow===0&&e.endRow===t-1,Ds=13,Qt=Object.freeze({style:Object.freeze({}),lineBoxPx:Ds,verticalAlign:"middle"}),lp={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"},ip=new Map(Object.entries(lp)),cp=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,ap=/^rgba?\((.*)\)$/,wa=/^(\d+(?:\.\d+)?)%$/,so=e=>e.toString(16).padStart(2,"0"),fs=e=>{const t=wa.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},up=e=>{const t=wa.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},dp=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=fs(t[0]),r=fs(t[1]),o=fs(t[2]);if(n===null||r===null||o===null)return null;const s=`#${so(n)}${so(r)}${so(o)}`;if(t.length===3)return s;const l=up(t[3]);return l===null?null:l===255?s:`${s}${so(l)}`},lt=e=>{const t=e.trim().toLowerCase(),n=cp.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=ap.exec(t);if(r!==null)return dp(r[1]);const o=ip.get(t);return o===void 0?null:o},xi={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"}},Ai=e=>{if(!Object.hasOwn(xi,e.style))return null;const t=xi[e.style],n=e.color===void 0?Qs:lt(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},fp={top:"flex-start",middle:"center",bottom:"flex-end"},pp=e=>e==="left"||e==="center"||e==="right",Ca=e=>e==="top"||e==="middle"||e==="bottom",ya=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,ba=(e,t)=>{if(typeof e.background=="string"){const s=lt(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=lt(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=ya(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},lo=(e,t)=>{const n=e===void 0?null:Ai(e);return n!==null?n:t===void 0?null:Ai(t)},ps=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(pp(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=zr(e.align)),Ca(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=fp[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),ba(e,s));const c=e?.borders,a=lo(c?.right,t);a!==null&&(s.borderRight=a);const u=lo(c?.bottom,n);if(u!==null&&(s.borderBottom=u),r){const h=lo(c?.left,void 0);h!==null&&(s.borderLeft=h)}if(o){const h=lo(c?.top,void 0);h!==null&&(s.borderTop=h)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Ti=new WeakMap,hp=(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:ps(void 0,s,l,r,o);if(!c)return ps(e,s,l,r,o);const a=Ti.get(e);if(a!==void 0)return a;const u=ps(e,void 0,void 0,!1,!1);return Ti.set(e,u),u},mp=e=>{if(e===void 0)return Qt;const t={};ba(e,t);const n=ya(e.fontSize),r=n===null?Ds:Math.round(n),o=Ca(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Ds&&o==="middle"?Qt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},gp="#REF!",wp=11,Cp=15,yp=4096,bo=33,Dr=34,ll=36,bp=38,Fs=39,va=40,vp=42,Rp=43,Sp=44,Ra=45,Ep=46,kp=47,or=58,Op=59,xp=60,Sa=61,Ap=62,Tp=67,$p=82,Do=91,Ea=93,Mp=94,Lp=95,ka=e=>e>=65&&e<=90||e>=97&&e<=122,Oa=e=>e>=48&&e<=57,il=e=>ka(e)||Oa(e)||e===Lp||e===Ep||e===ll||e>=128,zp=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,Np=e=>e===Sa||e===va||e===Sp||e===Op||e===Rp||e===Ra||e===vp||e===kp||e===Mp||e===bp||e===xp||e===Ap||e===or,xa=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(il(n)||n===va||n===bo||n===Do)},$i=(e,t)=>{let n=t;for(;n<e.length&&il(e.charCodeAt(n));)n+=1;return n},qs=(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},Dp=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Fs){r+=2;continue}if(o===Do)n+=1;else if(o===Ea&&(n-=1,n===0))return r+1;r+=1}return e.length},Mi=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&xa(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Aa=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Dr){o=qs(e,o,Dr);continue}if(s===Fs){const a=qs(e,o,Fs);o=e.charCodeAt(a)===bo?Mi(e,o,a,t,n):a;continue}if(s===Do){o=Dp(e,o);continue}if(!il(s)){o+=1;continue}const l=t(e,o);if(l!==null&&xa(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=$i(e,o);if(e.charCodeAt(c)===or){const a=$i(e,c+1);a>c+1&&e.charCodeAt(a)===bo&&(c=a)}o=e.charCodeAt(c)===bo?Mi(e,o,c,t,n):c}return n},hs=(e,t)=>{let n=t;const r=e.charCodeAt(n)===ll;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!ka(l))break;if(s+=1,s>wp)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Ps=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Oa(o))break;if(n-t>=Cp)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},io=(e,t)=>{const n=e.charCodeAt(t)===ll,r=Ps(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Fp=(e,t)=>{const n=hs(e,t);if(n!==null){const o=io(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===or){const s=hs(e,o.end+1);if(s!==null){const l=io(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)===or){const s=hs(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=io(e,t);if(r!==null&&e.charCodeAt(r.end)===or){const o=io(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},jr=e=>Aa(e,Fp),Ta=(e,t=yp)=>{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}},_s=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},ms=e=>`${e.absCol?"$":""}${_s(e.col)}${e.absRow?"$":""}${e.row+1}`,cl=e=>e.sheet===void 0?"":`${e.sheet}!`,hn=e=>{const t=cl(e);switch(e.kind){case"cell":return`${t}${ms(e)}`;case"range":return`${t}${ms(e.start)}:${ms(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${_s(e.start.col)}:${e.end.abs?"$":""}${_s(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Qn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},qp=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Qn(n.startRow,"formatRangeReference startRow"),Qn(n.startCol,"formatRangeReference startCol"),Qn(n.endRow,"formatRangeReference endRow"),Qn(n.endCol,"formatRangeReference endCol"),t){case"columns":return hn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return hn({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?hn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):hn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},al=(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?`${cl(s.token)}${gp}`:l),o=s.end}return r+e.slice(o)},Fo=e=>e.charCodeAt(0)===Sa,gs=(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}},Pp=(e,t,n)=>{switch(e.kind){case"cell":{const r=gs(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=gs(e.start,t,n),o=gs(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}}}}},$a=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Fo(e)?al(e,jr(e),r=>{const o=Pp(r,t,n);return o===null?null:hn(o)}):e},Ma=(e,t)=>{Qn(e.row,`${t} origin.row`),Qn(e.col,`${t} origin.col`)},er=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,ws=(e,t)=>`${er("R",e.row,e.absRow,t.row)}${er("C",e.col,e.absCol,t.col)}`,_p=(e,t)=>{const n=cl(e);switch(e.kind){case"cell":return`${n}${ws(e,t)}`;case"range":return`${n}${ws(e.start,t)}:${ws(e.end,t)}`;case"column":return`${n}${er("C",e.start.col,e.start.abs,t.col)}:${er("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${er("R",e.start.row,e.start.abs,t.row)}:${er("R",e.end.row,e.end.abs,t.row)}`}},qo=(e,t)=>(Ma(t,"toR1C1"),Fo(e)?al(e,jr(e),n=>_p(n,t)):e),Li=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Do){const l=e.charCodeAt(o+1)===Ra,c=Ps(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Ea?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Ps(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}}},zi=(e,t)=>{const n=Li(e,t,$p),r=Li(e,n===null?t:n.end,Tp);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}},jp=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}}},Ip=(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,Hp=(e,t)=>{const n=zi(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===or){const r=zi(e,n.end+1);if(r!==null){const o=Ip(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:jp(n)}},Bp=e=>Aa(e,Hp),Vp=Ta(Bp),tr=(e,t)=>e.rel?t+e.n:e.n-1,Ni=(e,t)=>{const n=tr(e.row,t.row),r=tr(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Wp=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Ni(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Ni(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=tr(e.start,t.row),s=tr(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=tr(e.start,t.col),s=tr(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}}}},Ir=(e,t)=>(Ma(t,"fromR1C1"),Fo(e)?al(e,Vp(e),n=>{const r=Wp(n,t);return r===null?null:hn(r)}):e),Di=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Kp=e=>{switch(e.kind){case"cell":return{...e,...Di(e.absCol,e.absRow)};case"range":{const t=Di(e.start.absCol,e.start.absRow);return{...e,start:{...e.start,...t},end:{...e.end,...t}}}case"column":{const t=!e.start.abs;return{...e,start:{col:e.start.col,abs:t},end:{col:e.end.col,abs:t}}}case"row":{const t=!e.start.abs;return{...e,start:{row:e.start.row,abs:t},end:{row:e.end.row,abs:t}}}}},La=(e,t)=>Fo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,za=(e,t)=>{if(!La(e,t))return null;for(const n of jr(e))if(n.start<=t&&t<=n.end)return n;return null},Yp=(e,t)=>{const n=za(e,t);if(n===null)return null;const r=hn(Kp(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Fi=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Dr){const s=qs(e,r,Dr);if(s>t)return!1;n=Dr,r=s;continue}zp(o)||(n=o),r+=1}return Np(n)},Na=(e,t)=>{if(!La(e,t))return null;for(const n of jr(e))if(n.start<=t&&t<=n.end)return Fi(e,n.start)?{replace:[n.start,n.end]}:null;return Fi(e,t)?{insertAt:t}:null},ur=[{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}],Po=(e,t)=>`[$${e}-${t}]`,Xp=new Map(ur.map(e=>[Po(e.symbol,e.lcid),e])),Up=new Map(ur.filter((e,t)=>ur.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(ur.map(e=>[Po(e.symbol,e.lcid),e.code]));const Gp=new Set([...ur.map(e=>e.symbol),...ur.map(e=>e.code),"¥"]),Jp=20,Zp="yyyy/MM/dd",Da=/yyyy|MM|dd|HH|mm|ss/g,Fa=" -+/():!^&'~{}<>=",Qp="$¥€£₩₹¥",js=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},eh=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},th=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),a=c.lastIndexOf("-"),u=a<0?c:c.slice(0,a),h=a<0?null:c.slice(a+1);if(h!==null&&!/^[0-9a-fA-F]{1,8}$/.test(h)||u===""&&h===null)return null;const g=h===null?null:Number.parseInt(h,16).toString(16);t.push(u===""?{kind:"locale"}:{kind:"currency",symbol:u,lcid:g}),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(Fa.includes(o)||Qp.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},Lt=e=>e===void 0?{}:{locale:e},nh=/^(0|#,##0)(?:\.(0+))?$/,qi=(e,t,n,r)=>{if(t!==null){const o=Xp.get(Po(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Gp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...Lt(r.locale)}},rh=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",a="";for(const $ of e)switch($.kind){case"locale":break;case"literal":r?a+=$.text:c+=$.text;break;case"digits":if(r)return;n=$.text,r=!0;break;case"currency":if(o!==null)return;o=$;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const u=nh.exec(n);if(u===null)return;const h=u[1]==="#,##0",g=u[2]===void 0?0:u[2].length,L=c.trim(),M=a.trim();if(s)return l===0&&o===null&&!h&&L===""&&M===""?{type:"scientific",decimals:g,...Lt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&L===""&&M===""?{type:"percent",decimals:g,...Lt(t.locale)}:void 0;if(M==="%"&&L===""&&o===null)return{type:"percent",decimals:g,scale:!1,...Lt(t.locale)};if(o!==null)return L===""&&M===""?qi(o.symbol,o.lcid,g,t):void 0;if(!(L!==""&&M!==""))return L!==""||M!==""?qi(L+M,null,g,t):{type:"number",decimals:g,...h?{grouping:!0}:{},...Lt(t.locale)}},oh=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),sh=(e,t)=>{const n=[...e.matchAll(Da)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},lh=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":oh.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&sh(r,n)?{type:"date",pattern:r}:void 0},ih=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...Lt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...Lt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...Lt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...Lt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...Lt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...Lt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),ul=(e,t)=>{const n=eh(e).trim(),r=ih.get(n);if(r!==void 0)return r(t);const o=th(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return rh(o,t);if(o.some(s=>s.kind==="date"))return lh(o)}},ch=(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:ul(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},$r=e=>e===0?"":`.${"0".repeat(e)}`,vo=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Jp,ah=`${Fa}.,`,Pi=e=>e.includes('"')?null:[...e].every(t=>ah.includes(t))?e:`"${e}"`,uh=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Da)){const a=Pi(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=Pi(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=ul(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},dh=e=>{const t=Up.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!vo(n))return null;const r=`#,##0${$r(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Po(t.symbol,t.lcid)}${r}`},qa=e=>{switch(e.type){case"text":return"@";case"date":return uh(e.pattern===void 0?Zp:e.pattern);case"number":return vo(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${$r(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return vo(t)?e.scale===!1?`0${$r(t)}"%"`:`0${$r(t)}%`:null}case"scientific":return vo(e.decimals)?`0${$r(e.decimals)}E+00`:null;case"currency":return dh(e);default:return null}},_i="-−",fh=(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("")},ph=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const u=fh(c[0],t);return u===null?null:{integer:u,fraction:a,exponent:l}},hh=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const a=c===""?l:`${l}.${c}`;return r&&a!=="0"?`-${a}`:a},mh=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",a=W=>W>="0"&&W<="9"||l!==""&&l.includes(W)||n.decimal.includes(W)||c&&(W==="e"||W==="E");let u=0;for(;u<o.length&&!a(o[u]);)u+=1;let h=o.length;for(;h>u&&!a(o[h-1]);)h-=1;let g=0,L=0,M=0,$="";for(const W of o.slice(0,u))_i.includes(W)?g+=1:W==="("?L+=1:$+=W;for(const W of o.slice(h))_i.includes(W)?g+=1:W===")"?M+=1:$+=W;const H=g+L;if(L!==M||H>1||H===1&&s||(s=s||H===1,r!=="currency"&&$.trim()!==""))return e;const Z=ph(o.slice(u,h).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(Z===null)return e;const Q=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,O=Z.exponent+Q;if(O>330||O<-330)return e;const D=hh(Z.integer,Z.fraction,O,s);return Number.isFinite(Number(D))?D:e},ji="google-sheets-html-origin",Pa=Object.freeze({group:",",decimal:"."}),Ii=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"}),_a=["top","right","bottom","left"],gh=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),wh=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Ch=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),Hi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],yh=Object.freeze({number:2,percent:3,currency:4,scientific:8}),bh=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),vh=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"]),Rh=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Sh=3,Eh=1,ja=-25569,Ro=86400,kh=-693959,Oh=2958465,xh=" ",_o=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),a=c.indexOf(":");if(a>0){const u=c.slice(0,a).trim().toLowerCase(),h=c.slice(a+1).trim();u!==""&&h!==""&&t.set(u,h)}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},Ao=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},dl=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},Ah=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Th=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const a=l.indexOf("{",c);if(a===-1)break;const u=l.indexOf("}",a+1);if(u===-1)break;const h=l.slice(c,a),g=l.slice(a+1,u);if(c=u+1,h.trim().startsWith("@"))continue;const L=_o(g);for(const M of h.split(",")){const $=M.trim(),H=Ah.exec($);if(H!==null){const Z=t.get(H[1]);if(Z===void 0)t.set(H[1],new Map(L));else for(const[Q,O]of L)Z.set(Q,O)}else if($.toLowerCase()==="table"){const Z=L.get("mso-displayed-decimal-separator"),Q=L.get("mso-displayed-thousand-separator");Z!==void 0&&(n=js(Ao(Z))),Q!==void 0&&(r=js(Ao(Q)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Pa}},$h="%_-*? ",Mh=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||$h.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Lh=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},Ia=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,a=l<10?l+3:l-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},Un=(e,t)=>String(e).padStart(t,"0"),Ha=e=>{if(e<kh||e>Oh)return null;let t=Math.floor(e),n=Math.round((e-t)*Ro);n>=Ro&&(t+=1,n-=Ro);const r=Ia(t+ja),o=`${Un(r.year,4)}-${Un(r.month,2)}-${Un(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Un(s,2)}:${Un(l,2)}:${Un(n%60,2)}`},zh=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Nh=e=>{const t=zh.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const a=Lh(n,r,o),u=Ia(a);return u.year!==n||u.month!==r||u.day!==o?null:a-ja+(s*3600+l*60+c)/Ro},fl=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),$n=e=>fl(e).replaceAll('"',"""),Ba=e=>fl(e).replaceAll("'","'"),Dh=e=>fl(e).replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nn=require("./tsv.cjs"),Fe=require("./view-BkwCUzTl.cjs"),rt=require("@aiquants/virtualscroll"),I=require("react/jsx-runtime"),i=require("react"),Pd=require("react-dom"),_d=require("@aiquants/input-method"),Gs=1e3,yn=1e4,Js=10,Ci=2**(1/4),jd=(e,t)=>e<=0?e:t>0?e>=yn?e:Math.min(yn,Math.max(e+1,Math.round(e*Ci))):Math.max(1,Math.min(e-1,Math.round(e/Ci))),yi=(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),Zs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Js):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),yn))}let l=[...s].map(([a,u])=>({index:a,size:u}));if(e.count-e.hiddenCount()-yi(e,l)===0){const a=n===null?l[0].index:n;l=l.map(u=>u.index===a?{index:u.index,size:1}:u)}if(r.axisKind==="row"){const a=e.hiddenCount()+yi(e,l);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:l}},Qs="#000000",no=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Id=20,Hd=256,ro=new Map,as=new WeakMap,Rt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Bd=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},Vd=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Id}:no(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...no(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...no(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...no(e.decimals)};default:return null}},Wd=e=>{const t=as.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=ro.get(n);if(r!==void 0)return as.set(e,r),r;ro.size>=Hd&&ro.clear();const o=Vd(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return ro.set(n,s),as.set(e,s),s},Kd=(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}},Jc=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>Kd(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Yd=(e,t)=>{const n=Jc(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)}})},Ln=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Yd(e,t.pattern??"yyyy/MM/dd");const n=Rt(e);if(n===null)return e;const r=Wd(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Bd(n,-2):n)},bi=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Jc(n)!==null?"right":"left":Rt(n)!==null?"right":"left",zr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Zc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Xd=["bottom","left","right","top"],Qc=(e,t,n)=>{e[t]=n},ea=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Ud=e=>{if(e===void 0)return;const t={};for(const n of Xd){const r=e[n];r!==void 0&&(t[n]=ea(r))}return Object.keys(t).length===0?void 0:t},Nt=e=>{const t={};for(const n of Zc){const r=n==="borders"?Ud(e.borders):n==="value"?e.value===void 0?void 0:ea(e.value):e[n];r!==void 0&&r!==!1&&Qc(t,n,r)}return Object.keys(t).length===0?void 0:t},el=(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]||!el(o[c],s[c]))return!1}return!0},Gd=(e,t)=>e===t?!0:el(e===void 0?void 0:Nt(e),t===void 0?void 0:Nt(t)),tl=(e,t)=>{const n={};for(const o of Zc){const s=t[o];Qc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=Nt(n);return el(r,e===void 0?void 0:Nt(e))?e:r},ta="data-aqsp-clip",xo="application/x-aqsp-clip",Ms=512,vi=16*1024,Ls=`${ta}=`,Jd=16,nl=()=>{const e=globalThis.crypto;if(e===void 0||typeof e.getRandomValues!="function")throw new RangeError("[spreadsheet] newClipId requires crypto.getRandomValues — there is no counter or randomUUID substitute by design");const t=e.getRandomValues(new Uint8Array(Jd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},_r=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),he=e=>typeof e=="string",st=e=>typeof e=="boolean",pn=e=>typeof e=="number"&&Number.isFinite(e),zt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Ri=e=>zt(e)&&e>=1,Zd=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=yn,tn=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Qd=e=>t=>Array.isArray(t)&&t.every(e),qe=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),rn=(e,t)=>{if(!_r(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},rl=e=>t=>{if(!_r(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&rn(t,n)},ef=["left","center","right"],tf=["top","middle","bottom"],nf=["thin","medium","thick","dashed","dotted","double","hair"],us=["gt","gte","lt","lte","eq","neq","between","notBetween"],rf=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],of=["eq","neq","gt","gte","lt","lte","between","notBetween"],sf=["contains","notContains","startsWith","endsWith"],lf=new Map([["number",qe({type:he,decimals:pn,grouping:st,locale:he},["type"])],["percent",qe({type:he,decimals:pn,scale:st,locale:he},["type"])],["currency",qe({type:he,currency:he,decimals:pn,locale:he},["type","currency"])],["scientific",qe({type:he,decimals:pn,locale:he},["type"])],["date",qe({type:he,pattern:he},["type"])],["text",qe({type:he},["type"])]]),cf=qe({style:tn(nf),color:he},["style"]),oo=e=>rn(e,cf),af=qe({top:oo,right:oo,bottom:oo,left:oo},[]),uf=qe({value:rl(lf),align:tn(ef),verticalAlign:tn(tf),wrap:st,background:he,color:he,bold:st,italic:st,underline:st,strikethrough:st,fontFamily:he,fontSize:pn,borders:e=>rn(e,af)},[]),df=e=>rn(e,uf),Tn={strict:st,inputMessage:he,errorMessage:he},ff=new Map([["list",qe({...Tn,type:he,values:Qd(he),showDropdown:st},["type","values"])],["number",qe({...Tn,type:he,op:tn(us),a:he,b:he},["type","op","a"])],["textLength",qe({...Tn,type:he,op:tn(us),a:pn,b:pn},["type","op","a"])],["date",qe({...Tn,type:he,op:tn(us),a:he,b:he},["type","op","a"])],["text",qe({...Tn,type:he,op:tn(rf),value:he},["type","op"])],["checkbox",qe({...Tn,type:he,checked:he,unchecked:he},["type"])],["custom",qe({...Tn,type:he,formula:he},["type","formula"])]]),pf=rl(ff),hf=qe({startRow:zt,startCol:zt,endRow:zt,endCol:zt},["startRow","startCol","endRow","endCol"]),mf=e=>{if(!rn(e,hf))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return zt(t)&&zt(r)&&zt(n)&&zt(o)&&t<=r&&n<=o},gf=qe({color:he,value:pn},["color"]),ds=e=>rn(e,gf),wf=new Map([["cellValue",qe({type:he,op:tn(of),a:he,b:he},["type","op","a"])],["text",qe({type:he,op:tn(sf),value:he},["type","op","value"])],["empty",qe({type:he},["type"])],["notEmpty",qe({type:he},["type"])],["colorScale",qe({type:he,min:ds,mid:ds,max:ds},["type","min","max"])],["customFormula",qe({type:he,formula:he},["type","formula"])]]),Cf=qe({background:he,color:he,bold:st,italic:st,underline:st,strikethrough:st},[]),yf=qe({sourceRuleId:he,ranges:Array.isArray,condition:rl(wf),style:e=>rn(e,Cf),stopIfTrue:st},["sourceRuleId","ranges","condition","style"]),bf=(e,t,n)=>{if(!rn(e,yf))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!mf(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},vf=qe({text:he,author:he,createdAt:he},["text","author","createdAt"]),Rf=e=>rn(e,vf),Sf=(e,t,n)=>{if(!_r(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(!zt(o)||o>=t)return!1;break;case"val":if(!zt(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(Rf)))return!1;break;default:return!1}}return!0},Si=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Zd),Ef=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),na=e=>{if(!_r(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Ef.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Ri(t)&&Ri(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(df)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(pf)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!Sf(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Si(e.colWidths,n)||e.rowHeights!==void 0&&!Si(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>bf(c,t,n))},qr=e=>Array.isArray(e)?`[${e.map(qr).join(",")}]`:_r(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${qr(e[n])}`).join(",")}}`:JSON.stringify(e),kf=e=>{const t=Nt(e);return t===void 0?"{}":JSON.stringify(t)},Of=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,xf=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(Of).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},ra=e=>{if(!na(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(kf).join(","),r=e.validations.map(qr).join(","),o=e.cells.map(a=>`[${a.map(xf).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(qr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},zs=e=>{let t;try{t=JSON.parse(e)}catch{return null}return na(t)?t:null},Af=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Tf=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),oa=e=>e.includes("&")?e.replace(Af,t=>Tf[t]):e,$f=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Ei=e=>{const t=e.length>Ms?e.slice(0,Ms):e,n=$f.exec(oa(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Mf=e=>{const t=e.indexOf(Ls);if(t===-1)return null;const n=t+Ls.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},sa=(e,t)=>{if(t==="event"&&e.types.includes(xo))return{kind:"mime",json:e.getData(xo)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Mf(n);return r===null?null:{kind:"attribute",html:n,at:r}},Lf=(e,t)=>{const n=sa(e,t);return n===null?null:n.kind==="mime"?Ei(n.json):Ei(n.html.slice(n.at.start,n.at.start+Ms))},zf=(e,t)=>{const n=sa(e,t);if(n===null)return null;if(n.kind==="mime")return zs(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:zs(oa(n.html.slice(n.at.start,r)))},Nf=/<google-sheets-html-origin[\s>]/,Df='data-sheets-root="1"',Ff=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,qf="mso-",Pf=/\.xl\d+\s*\{/,_f="<table",jf=e=>e.includes(Ls)?"aqsp":Nf.test(e)&&e.includes(Df)?"sheets":Ff.test(e)||e.includes(qf)||Pf.test(e)?"excel":null,la=(e,t)=>{if(t==="event"&&e.types.includes(xo))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>vi?n.slice(0,vi):n,o=jf(r);if(o==="aqsp")return"aqsp";if(n.includes(_f))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},ol=1e3,ia=65534,If=9,Hf=10,Bf=12,Vf=13,Wf=32,ca=34,aa=39,Kf=43,sl=47,ki=48,Yf=57,Xf=61,Uf=62,Gf=97,Jf=98,Zf=100,Qf=102,ua=104,da=114,fa=116,ep=["able","body","head","foot"],Nr=e=>e===Wf||e===If||e===Hf||e===Vf||e===Bf,Ns=e=>e===Uf||e===sl||Nr(e),tp=e=>Nr(e)||e===sl||e===ca||e===aa,np=(e,t,n,r)=>{if(t===0||!tp(e.charCodeAt(t-1)))return null;let o=t+n;for(;Nr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Xf)return 1;for(o+=1;Nr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===ca||s===aa)&&(o+=1);Nr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Kf&&(o+=1);let l=0,c=0;for(let a=e.charCodeAt(o);a>=ki&&a<=Yf;a=e.charCodeAt(o))l=l*10+(a-ki),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Oi=(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=np(e,r,t.length,n);if(l!==null)return l}return 1}},rp=(e,t)=>{if(e.charCodeAt(t+2)!==fa)return!1;const n=e.charCodeAt(t+3);if(n===da)return Ns(e.charCodeAt(t+4));if(n!==Gf&&n!==Jf&&n!==ua&&n!==Qf)return!1;for(const r of ep)if(e.startsWith(r,t+3)&&Ns(e.charCodeAt(t+3+r.length)))return!0;return!1},op=e=>{const t=e.toLowerCase(),n=Oi(t,"colspan",ol),r=Oi(t,"rowspan",ia);let o=0;const s=H=>(o!==-1&&o<H&&(o=t.indexOf(">",H)),o===-1?t.length:o);let l=0,c=0,a=0,u=0,h=!1;const g=new Map,L=(H,Z)=>{const Q=g.get(H);g.set(H,Q===void 0?Z:Q+Z)},M=()=>{h&&a+u>c&&(c=a+u),h=!1},$=()=>{M(),l+=1,h=!0,a=0;const H=g.get(l-1);H!==void 0&&(u+=H)};for(let H=t.indexOf("<");H!==-1;H=t.indexOf("<",H+1)){const Z=t.charCodeAt(H+1);if(Z===sl){rp(t,H)&&M();continue}if(Z!==fa||!Ns(t.charCodeAt(H+3)))continue;const Q=t.charCodeAt(H+2);if(Q===da)$();else if(Q===Zf||Q===ua){h||$();const O=H+3,D=s(O),W=n(O,D);a+=W;const K=r(O,D);K>1&&(L(l,W),L(l-1+K,-W))}}return M(),{rows:l,cols:c}},pa=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}},ha=()=>{const e=new WeakMap,t=pa(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=Nt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},sp=()=>{const e=new WeakMap,t=pa(qr);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}},lp=new Set(["http:","https:","mailto:","tel:"]),bn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return lp.has(n.protocol)?n.href:null},fr=e=>{if(e===void 0)return;const t=bn(e);return t===null?void 0:t},ma=(e,t)=>e.startCol===0&&e.endCol===t-1,ga=(e,t)=>e.startRow===0&&e.endRow===t-1,Ds=13,Qt=Object.freeze({style:Object.freeze({}),lineBoxPx:Ds,verticalAlign:"middle"}),ip={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"},cp=new Map(Object.entries(ip)),ap=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,up=/^rgba?\((.*)\)$/,wa=/^(\d+(?:\.\d+)?)%$/,so=e=>e.toString(16).padStart(2,"0"),fs=e=>{const t=wa.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},dp=e=>{const t=wa.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},fp=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=fs(t[0]),r=fs(t[1]),o=fs(t[2]);if(n===null||r===null||o===null)return null;const s=`#${so(n)}${so(r)}${so(o)}`;if(t.length===3)return s;const l=dp(t[3]);return l===null?null:l===255?s:`${s}${so(l)}`},lt=e=>{const t=e.trim().toLowerCase(),n=ap.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=up.exec(t);if(r!==null)return fp(r[1]);const o=cp.get(t);return o===void 0?null:o},xi={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"}},Ai=e=>{if(!Object.hasOwn(xi,e.style))return null;const t=xi[e.style],n=e.color===void 0?Qs:lt(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},pp={top:"flex-start",middle:"center",bottom:"flex-end"},hp=e=>e==="left"||e==="center"||e==="right",Ca=e=>e==="top"||e==="middle"||e==="bottom",ya=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,ba=(e,t)=>{if(typeof e.background=="string"){const s=lt(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=lt(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=ya(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},lo=(e,t)=>{const n=e===void 0?null:Ai(e);return n!==null?n:t===void 0?null:Ai(t)},ps=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(hp(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=zr(e.align)),Ca(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=pp[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),ba(e,s));const c=e?.borders,a=lo(c?.right,t);a!==null&&(s.borderRight=a);const u=lo(c?.bottom,n);if(u!==null&&(s.borderBottom=u),r){const h=lo(c?.left,void 0);h!==null&&(s.borderLeft=h)}if(o){const h=lo(c?.top,void 0);h!==null&&(s.borderTop=h)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Ti=new WeakMap,mp=(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:ps(void 0,s,l,r,o);if(!c)return ps(e,s,l,r,o);const a=Ti.get(e);if(a!==void 0)return a;const u=ps(e,void 0,void 0,!1,!1);return Ti.set(e,u),u},gp=e=>{if(e===void 0)return Qt;const t={};ba(e,t);const n=ya(e.fontSize),r=n===null?Ds:Math.round(n),o=Ca(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Ds&&o==="middle"?Qt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},wp="#REF!",Cp=11,yp=15,bp=4096,bo=33,Dr=34,ll=36,vp=38,Fs=39,va=40,Rp=42,Sp=43,Ep=44,Ra=45,kp=46,Op=47,or=58,xp=59,Ap=60,Sa=61,Tp=62,$p=67,Mp=82,Do=91,Ea=93,Lp=94,zp=95,ka=e=>e>=65&&e<=90||e>=97&&e<=122,Oa=e=>e>=48&&e<=57,il=e=>ka(e)||Oa(e)||e===zp||e===kp||e===ll||e>=128,Np=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,Dp=e=>e===Sa||e===va||e===Ep||e===xp||e===Sp||e===Ra||e===Rp||e===Op||e===Lp||e===vp||e===Ap||e===Tp||e===or,xa=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(il(n)||n===va||n===bo||n===Do)},$i=(e,t)=>{let n=t;for(;n<e.length&&il(e.charCodeAt(n));)n+=1;return n},qs=(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},Fp=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Fs){r+=2;continue}if(o===Do)n+=1;else if(o===Ea&&(n-=1,n===0))return r+1;r+=1}return e.length},Mi=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&xa(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Aa=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Dr){o=qs(e,o,Dr);continue}if(s===Fs){const a=qs(e,o,Fs);o=e.charCodeAt(a)===bo?Mi(e,o,a,t,n):a;continue}if(s===Do){o=Fp(e,o);continue}if(!il(s)){o+=1;continue}const l=t(e,o);if(l!==null&&xa(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=$i(e,o);if(e.charCodeAt(c)===or){const a=$i(e,c+1);a>c+1&&e.charCodeAt(a)===bo&&(c=a)}o=e.charCodeAt(c)===bo?Mi(e,o,c,t,n):c}return n},hs=(e,t)=>{let n=t;const r=e.charCodeAt(n)===ll;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!ka(l))break;if(s+=1,s>Cp)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Ps=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Oa(o))break;if(n-t>=yp)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},io=(e,t)=>{const n=e.charCodeAt(t)===ll,r=Ps(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},qp=(e,t)=>{const n=hs(e,t);if(n!==null){const o=io(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===or){const s=hs(e,o.end+1);if(s!==null){const l=io(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)===or){const s=hs(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=io(e,t);if(r!==null&&e.charCodeAt(r.end)===or){const o=io(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},jr=e=>Aa(e,qp),Ta=(e,t=bp)=>{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}},_s=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},ms=e=>`${e.absCol?"$":""}${_s(e.col)}${e.absRow?"$":""}${e.row+1}`,cl=e=>e.sheet===void 0?"":`${e.sheet}!`,hn=e=>{const t=cl(e);switch(e.kind){case"cell":return`${t}${ms(e)}`;case"range":return`${t}${ms(e.start)}:${ms(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${_s(e.start.col)}:${e.end.abs?"$":""}${_s(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Qn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Pp=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Qn(n.startRow,"formatRangeReference startRow"),Qn(n.startCol,"formatRangeReference startCol"),Qn(n.endRow,"formatRangeReference endRow"),Qn(n.endCol,"formatRangeReference endCol"),t){case"columns":return hn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return hn({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?hn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):hn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},al=(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?`${cl(s.token)}${wp}`:l),o=s.end}return r+e.slice(o)},Fo=e=>e.charCodeAt(0)===Sa,gs=(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}},_p=(e,t,n)=>{switch(e.kind){case"cell":{const r=gs(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=gs(e.start,t,n),o=gs(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}}}}},$a=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Fo(e)?al(e,jr(e),r=>{const o=_p(r,t,n);return o===null?null:hn(o)}):e},Ma=(e,t)=>{Qn(e.row,`${t} origin.row`),Qn(e.col,`${t} origin.col`)},er=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,ws=(e,t)=>`${er("R",e.row,e.absRow,t.row)}${er("C",e.col,e.absCol,t.col)}`,jp=(e,t)=>{const n=cl(e);switch(e.kind){case"cell":return`${n}${ws(e,t)}`;case"range":return`${n}${ws(e.start,t)}:${ws(e.end,t)}`;case"column":return`${n}${er("C",e.start.col,e.start.abs,t.col)}:${er("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${er("R",e.start.row,e.start.abs,t.row)}:${er("R",e.end.row,e.end.abs,t.row)}`}},qo=(e,t)=>(Ma(t,"toR1C1"),Fo(e)?al(e,jr(e),n=>jp(n,t)):e),Li=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Do){const l=e.charCodeAt(o+1)===Ra,c=Ps(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Ea?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Ps(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}}},zi=(e,t)=>{const n=Li(e,t,Mp),r=Li(e,n===null?t:n.end,$p);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}},Ip=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}}},Hp=(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,Bp=(e,t)=>{const n=zi(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===or){const r=zi(e,n.end+1);if(r!==null){const o=Hp(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Ip(n)}},Vp=e=>Aa(e,Bp),Wp=Ta(Vp),tr=(e,t)=>e.rel?t+e.n:e.n-1,Ni=(e,t)=>{const n=tr(e.row,t.row),r=tr(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Kp=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Ni(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Ni(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=tr(e.start,t.row),s=tr(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=tr(e.start,t.col),s=tr(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}}}},Ir=(e,t)=>(Ma(t,"fromR1C1"),Fo(e)?al(e,Wp(e),n=>{const r=Kp(n,t);return r===null?null:hn(r)}):e),Di=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Yp=e=>{switch(e.kind){case"cell":return{...e,...Di(e.absCol,e.absRow)};case"range":{const t=Di(e.start.absCol,e.start.absRow);return{...e,start:{...e.start,...t},end:{...e.end,...t}}}case"column":{const t=!e.start.abs;return{...e,start:{col:e.start.col,abs:t},end:{col:e.end.col,abs:t}}}case"row":{const t=!e.start.abs;return{...e,start:{row:e.start.row,abs:t},end:{row:e.end.row,abs:t}}}}},La=(e,t)=>Fo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,za=(e,t)=>{if(!La(e,t))return null;for(const n of jr(e))if(n.start<=t&&t<=n.end)return n;return null},Xp=(e,t)=>{const n=za(e,t);if(n===null)return null;const r=hn(Yp(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Fi=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Dr){const s=qs(e,r,Dr);if(s>t)return!1;n=Dr,r=s;continue}Np(o)||(n=o),r+=1}return Dp(n)},Na=(e,t)=>{if(!La(e,t))return null;for(const n of jr(e))if(n.start<=t&&t<=n.end)return Fi(e,n.start)?{replace:[n.start,n.end]}:null;return Fi(e,t)?{insertAt:t}:null},ur=[{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}],Po=(e,t)=>`[$${e}-${t}]`,Up=new Map(ur.map(e=>[Po(e.symbol,e.lcid),e])),Gp=new Map(ur.filter((e,t)=>ur.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(ur.map(e=>[Po(e.symbol,e.lcid),e.code]));const Jp=new Set([...ur.map(e=>e.symbol),...ur.map(e=>e.code),"¥"]),Zp=20,Qp="yyyy/MM/dd",Da=/yyyy|MM|dd|HH|mm|ss/g,Fa=" -+/():!^&'~{}<>=",eh="$¥€£₩₹¥",js=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},th=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},nh=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),a=c.lastIndexOf("-"),u=a<0?c:c.slice(0,a),h=a<0?null:c.slice(a+1);if(h!==null&&!/^[0-9a-fA-F]{1,8}$/.test(h)||u===""&&h===null)return null;const g=h===null?null:Number.parseInt(h,16).toString(16);t.push(u===""?{kind:"locale"}:{kind:"currency",symbol:u,lcid:g}),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(Fa.includes(o)||eh.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},Lt=e=>e===void 0?{}:{locale:e},rh=/^(0|#,##0)(?:\.(0+))?$/,qi=(e,t,n,r)=>{if(t!==null){const o=Up.get(Po(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Jp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...Lt(r.locale)}},oh=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",a="";for(const $ of e)switch($.kind){case"locale":break;case"literal":r?a+=$.text:c+=$.text;break;case"digits":if(r)return;n=$.text,r=!0;break;case"currency":if(o!==null)return;o=$;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const u=rh.exec(n);if(u===null)return;const h=u[1]==="#,##0",g=u[2]===void 0?0:u[2].length,L=c.trim(),M=a.trim();if(s)return l===0&&o===null&&!h&&L===""&&M===""?{type:"scientific",decimals:g,...Lt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&L===""&&M===""?{type:"percent",decimals:g,...Lt(t.locale)}:void 0;if(M==="%"&&L===""&&o===null)return{type:"percent",decimals:g,scale:!1,...Lt(t.locale)};if(o!==null)return L===""&&M===""?qi(o.symbol,o.lcid,g,t):void 0;if(!(L!==""&&M!==""))return L!==""||M!==""?qi(L+M,null,g,t):{type:"number",decimals:g,...h?{grouping:!0}:{},...Lt(t.locale)}},sh=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),lh=(e,t)=>{const n=[...e.matchAll(Da)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},ih=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":sh.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&lh(r,n)?{type:"date",pattern:r}:void 0},ch=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...Lt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...Lt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...Lt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...Lt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...Lt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...Lt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),ul=(e,t)=>{const n=th(e).trim(),r=ch.get(n);if(r!==void 0)return r(t);const o=nh(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return oh(o,t);if(o.some(s=>s.kind==="date"))return ih(o)}},ah=(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:ul(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},$r=e=>e===0?"":`.${"0".repeat(e)}`,vo=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Zp,uh=`${Fa}.,`,Pi=e=>e.includes('"')?null:[...e].every(t=>uh.includes(t))?e:`"${e}"`,dh=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Da)){const a=Pi(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=Pi(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=ul(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},fh=e=>{const t=Gp.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!vo(n))return null;const r=`#,##0${$r(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Po(t.symbol,t.lcid)}${r}`},qa=e=>{switch(e.type){case"text":return"@";case"date":return dh(e.pattern===void 0?Qp:e.pattern);case"number":return vo(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${$r(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return vo(t)?e.scale===!1?`0${$r(t)}"%"`:`0${$r(t)}%`:null}case"scientific":return vo(e.decimals)?`0${$r(e.decimals)}E+00`:null;case"currency":return fh(e);default:return null}},_i="-−",ph=(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("")},hh=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const u=ph(c[0],t);return u===null?null:{integer:u,fraction:a,exponent:l}},mh=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const a=c===""?l:`${l}.${c}`;return r&&a!=="0"?`-${a}`:a},gh=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",a=W=>W>="0"&&W<="9"||l!==""&&l.includes(W)||n.decimal.includes(W)||c&&(W==="e"||W==="E");let u=0;for(;u<o.length&&!a(o[u]);)u+=1;let h=o.length;for(;h>u&&!a(o[h-1]);)h-=1;let g=0,L=0,M=0,$="";for(const W of o.slice(0,u))_i.includes(W)?g+=1:W==="("?L+=1:$+=W;for(const W of o.slice(h))_i.includes(W)?g+=1:W===")"?M+=1:$+=W;const H=g+L;if(L!==M||H>1||H===1&&s||(s=s||H===1,r!=="currency"&&$.trim()!==""))return e;const Z=hh(o.slice(u,h).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(Z===null)return e;const Q=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,O=Z.exponent+Q;if(O>330||O<-330)return e;const D=mh(Z.integer,Z.fraction,O,s);return Number.isFinite(Number(D))?D:e},ji="google-sheets-html-origin",Pa=Object.freeze({group:",",decimal:"."}),Ii=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"}),_a=["top","right","bottom","left"],wh=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Ch=new Set(["windowtext","currentcolor","inherit","initial","unset"]),yh=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"]),Hi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],bh=Object.freeze({number:2,percent:3,currency:4,scientific:8}),vh=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Rh=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"]),Sh=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Eh=3,kh=1,ja=-25569,Ro=86400,Oh=-693959,xh=2958465,Ah=" ",_o=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),a=c.indexOf(":");if(a>0){const u=c.slice(0,a).trim().toLowerCase(),h=c.slice(a+1).trim();u!==""&&h!==""&&t.set(u,h)}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},Ao=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},dl=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},Th=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,$h=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const a=l.indexOf("{",c);if(a===-1)break;const u=l.indexOf("}",a+1);if(u===-1)break;const h=l.slice(c,a),g=l.slice(a+1,u);if(c=u+1,h.trim().startsWith("@"))continue;const L=_o(g);for(const M of h.split(",")){const $=M.trim(),H=Th.exec($);if(H!==null){const Z=t.get(H[1]);if(Z===void 0)t.set(H[1],new Map(L));else for(const[Q,O]of L)Z.set(Q,O)}else if($.toLowerCase()==="table"){const Z=L.get("mso-displayed-decimal-separator"),Q=L.get("mso-displayed-thousand-separator");Z!==void 0&&(n=js(Ao(Z))),Q!==void 0&&(r=js(Ao(Q)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Pa}},Mh="%_-*? ",Lh=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Mh.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},zh=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},Ia=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,a=l<10?l+3:l-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},Un=(e,t)=>String(e).padStart(t,"0"),Ha=e=>{if(e<Oh||e>xh)return null;let t=Math.floor(e),n=Math.round((e-t)*Ro);n>=Ro&&(t+=1,n-=Ro);const r=Ia(t+ja),o=`${Un(r.year,4)}-${Un(r.month,2)}-${Un(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Un(s,2)}:${Un(l,2)}:${Un(n%60,2)}`},Nh=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Dh=e=>{const t=Nh.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const a=zh(n,r,o),u=Ia(a);return u.year!==n||u.month!==r||u.day!==o?null:a-ja+(s*3600+l*60+c)/Ro},fl=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),$n=e=>fl(e).replaceAll('"',"""),Ba=e=>fl(e).replaceAll("'","'"),Fh=e=>fl(e).replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).replaceAll("\r",`
|
|
4
4
|
`).replaceAll(`
|
|
5
|
-
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),So=(e,t)=>`${e}="${$n(JSON.stringify(t))}"`,Va=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",
|
|
5
|
+
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),So=(e,t)=>`${e}="${$n(JSON.stringify(t))}"`,Va=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",qh=e=>{if(Rt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Ph=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},_h=e=>{if(e.type==="text")return{1:1};const t=qa(e);return t===null?null:{1:e.type==="date"?Ph(e.pattern===void 0?"yyyy/MM/dd":e.pattern):bh[e.type],2:t,3:1}},jh=/[;"'{}<>&\\]/,Wa=e=>e==="left"||e==="center"||e==="right",Ka=e=>e==="top"||e==="middle"||e==="bottom",Ih=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"?lt(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?lt(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Wa(e.align)&&t.push(`text-align:${e.align}`),Ka(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!jh.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 _a){const l=e.borders[s];if(l===void 0||!Object.hasOwn(Ii,l.style))continue;const c=l.color===void 0?"windowtext":lt(l.color);c!==null&&t.push(`border-${s}:${Ii[l.style]} ${c}`)}if(e.value!==void 0){const s=qa(e.value);s!==null&&t.push(`mso-number-format:"${Lh(s)}"`)}return t},Hh={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Bh=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=Ba([n,...Ih(e)].join(";"));let o=null;if(t!==void 0){const s=_h(t);s!==null&&(o=So("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},Vh=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Ln(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Va(o)?qh(e.t):null,a=!l&&c===null&&o!==void 0&&o.type==="date"?Dh(e.t):null,u=[];if(l?u.push(So("data-sheets-value",{1:2,2:e.t})):c!==null?u.push(So("data-sheets-value",{1:3,3:c})):a!==null&&u.push(So("data-sheets-value",{1:3,3:a})),e.f!==void 0&&u.push(`data-sheets-formula="${$n(e.f)}"`),t.numberFormatAttribute!==null&&u.push(t.numberFormatAttribute),e.link!==void 0&&u.push(`data-sheets-hyperlink="${$n(e.link)}"`),e.note!==void 0&&u.push(`data-sheets-note="${$n(e.note)}"`),l?u.push("x:str"):c!==null?u.push(`x:num="${$n(e.t)}"`):a!==null&&u.push(`x:num="${a}"`),e.f!==void 0){const L=Ir(e.f,{row:n,col:r});L.includes("#REF!")||u.push(`x:fmla="${$n(L)}"`)}const h=Fh(s),g=e.link===void 0?h:`<a href="${$n(e.link)}">${h}</a>`;return`<td style='${t.style}'${u.map(L=>` ${L}`).join("")}>${g}</td>`},Ya=(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(Bh);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let a=0;a<e.cols;a+=1){const u=e.cells[s][a],h=u.fmt===void 0?void 0:r[u.fmt];c+=Vh(u,h===void 0?Hh:h,s,a)}o+=`<tr${l}>${c}</tr>`}return`<${ji}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${ta}='${Ba(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${ji}>`},Is=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Xa=(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&&Is(n,l)}const o=e.getAttribute("style");return o!==null&&Is(n,_o(o)),n},Wh=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"}},Kh=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"},Yh=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),Xh={pt:1.5,unit:"px"},Bi=e=>{let t=null,n=null;const r=[];for(const a of dl(e)){const u=a.toLowerCase(),h=Wh(a);wh.has(u)?n=u:h!==null?t=h:r.push(a)}if(n===null||n==="none"||n==="hidden")return null;const o=Yh.get(n),s=o===void 0?Kh(t===null?Xh:t):o,l=r.join(" ");if(l===""||Ch.has(l.toLowerCase()))return{style:s};const c=lt(l);return c===null||c.length===9?null:{style:s,color:c}},Uh=e=>e.style==="thin"&&e.color==="#cccccc",Gh=e=>{const t=lt(e);if(t!==null)return t;for(const n of dl(e)){const r=lt(n);if(r!==null)return r}return null},Jh=e=>{const t=Ao(dl(e.split(",")[0]).join(" ").trim()).trim();return t===""||yh.has(t.toLowerCase())?null:t},Zh=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},Qh=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},em=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"},tm=new Set(["normal","pre-wrap","pre-line"]),nm=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const P=o.toLowerCase();(P==="bold"||P==="bolder"||Number(P)>=600)&&(r.bold=!0)}const s=e.get("font-style");s!==void 0&&(s.toLowerCase()==="italic"||s.toLowerCase().startsWith("oblique"))&&(r.italic=!0);const l=Qh(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),a=c===void 0?null:lt(c);a!==null&&a.length!==9&&(r.color=a);const u=e.has("background-color")?e.get("background-color"):e.get("background"),h=u===void 0?null:Gh(u);h!==null&&h.length!==9&&(r.background=h);const g=e.get("text-align"),L=g===void 0?"":g.toLowerCase();Wa(L)&&(r.align=L);const M=e.get("vertical-align"),$=M===void 0?"":M.toLowerCase();Ka($)&&(r.verticalAlign=$);const H=e.get("font-family"),Z=H===void 0?null:Jh(H);Z!==null&&(r.fontFamily=Z);const Q=e.get("font-size"),O=Q===void 0?null:Zh(Q);O!==null&&(r.fontSize=O);const D=e.get("white-space");D!==void 0&&tm.has(D.toLowerCase())&&(r.wrap=!0);const W={},K=e.get("border"),E=K===void 0?null:Bi(K);for(const P of _a){const j=e.get(`border-${P}`),m=j===void 0?E:Bi(j);m!==null&&!(n==="sheets"&&Uh(m))&&(W[P]=m)}return Object.keys(W).length>0&&(r.borders=W),r},Vi=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
6
|
`)&&(e.text+=`
|
|
7
|
-
`)},
|
|
8
|
-
`);continue}if(o.nodeType!==
|
|
9
|
-
`;continue}const c=t.mode==="collapse"&&
|
|
7
|
+
`)},rm=e=>{const t=e.getAttribute("style");return t!==null&&_o(t).get("mso-spacerun")==="yes"},om=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Sh.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&Vi(t);continue}const o=r.node;if(o.nodeType===Eh){const a=o.data;t.text+=t.mode==="collapse"?a.replace(/[\r\n\t\f]/g," "):a.replace(/\r\n?/g,`
|
|
8
|
+
`);continue}if(o.nodeType!==kh)continue;const s=o,l=s.localName;if(vh.has(l)||rm(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&Rh.has(l);if(c&&Vi(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const a=s.getAttribute("href");a!==null&&(t.href=a)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let a=s.lastChild;a!==null;a=a.previousSibling)n.push({kind:"enter",node:a})}},sm=(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&&im(l.element,t,n,r)},lm=(e,t)=>{const n=e.replaceAll(Ah," ");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
|
-
`)},lm=(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)}Is(t,Xa(e,r))},im=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?Ha(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<Hi.length?Hi[l]:null}return null},Ua=(e,t,n)=>t!==void 0&&Va(t)?mh(e,t,n):e,cm=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&Rt(c)!==null)if(n!==void 0&&n.type==="date"){const a=Ha(Number(c));if(a!==null)return a}else return c;return Ua(t,n,r)},am=(e,t,n,r)=>{const o=Xa(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Qh(o)};for(const h of pm(e))rm(h,l);om(l,o,s,r.rules);const c=sm(l.text,l.mode),a=tm(o,s,r.kind),u={t:""};if(r.kind==="sheets"){const h=e.getAttribute("data-sheets-numberformat"),g=h===null?void 0:ch(h,r.options);g!==void 0&&(a.value=g);const L=e.getAttribute("data-sheets-value"),M=L===null?null:im(L,g);u.t=M===null?Ua(c,g,Pa):M;const $=e.getAttribute("data-sheets-formula");$?.startsWith("=")&&(u.f=$);const H=e.getAttribute("data-sheets-hyperlink"),Z=H!==null?H:l.href,Q=Z===null?null:bn(Z);Q!==null&&(u.link=Q);const O=e.getAttribute("data-sheets-note");O!==null&&O!==""&&(u.note=O)}else{const h=o.get("mso-number-format"),g=h===void 0?void 0:ul(js(Ao(h)),r.options);g!==void 0&&(a.value=g),u.t=cm(e,c,g,r.separators);const L=e.getAttribute("x:fmla");L?.startsWith("=")&&(u.f=qo(L,{row:t,col:n}));const M=l.href===null?null:bn(l.href);M!==null&&(u.link=M)}return{cell:u,format:a}},Hs=(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},um=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)},dm=(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]))},Ga=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:_o(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:um(l);if(c!==null)return Math.min(c,yn)}const o=dm(e,t);return o===null?null:Math.min(o,yn)},fm=(e,t)=>{const n=[],r=o=>{const s=Ga(o,"width");for(let l=Hs(o,"span",ol);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Pr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Pr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Pr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*pm(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*hm(e){for(const t of["thead","tbody","tfoot"])for(const n of Pr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Pr(n))o.localName==="tr"&&(yield o)}}const Cs=()=>({t:""}),mm=(e,t,n)=>{const r=ha(),o=[],s=[],l=[];let c=0;for(const M of hm(e)){const $=o.length,H=($+1)*Math.max(c,1);if(H>n)return{outcome:"limit",cells:H};const Z=[];for(let O=0;O<l.length;O+=1)l[O]>0&&(Z[O]=Cs(),l[O]-=1);let Q=0;for(const O of Pr(M)){const D=O.localName;if(D!=="td"&&D!=="th")continue;for(;Z[Q]!==void 0;)Q+=1;const W=Hs(O,"colspan",ol),K=Hs(O,"rowspan",ia),E=($+1)*Math.max(c,Q+W);if(E>n)return{outcome:"limit",cells:E};const P=am(O,$,Q,t),j=r.intern(P.format);j!==void 0&&(P.cell.fmt=j),Z[Q]=P.cell;for(let m=1;m<W;m+=1)Z[Q+m]===void 0&&(Z[Q+m]=Cs());if(K>1)for(let m=0;m<W;m+=1){const d=K-1,y=Q+m;l[y]=l[y]===void 0||l[y]<d?d:l[y]}Q+=W}Z.length>c&&(c=Z.length),o.push(Z),s.push(Ga(M,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map(M=>{const $=[];for(let H=0;H<c;H+=1){const Z=M[H];$.push(Z===void 0?Cs():Z)}return $}),u=fm(e,c),h=u.length===c&&u.every(M=>M!==null)?u.map(M=>M===null?0:M):void 0,g=s.every(M=>M!==null)?s.map(M=>M===null?0:M):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:nl(),formats:[...r.entries],validations:[],cells:a,...h===void 0?{}:{colWidths:h},...g===void 0?{}:{rowHeights:g},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Ja=(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=Th(o);return mm(s,{kind:t,rules:l,options:n,separators:l.separators},r)},me=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),Vt=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,St=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),vt=e=>e.reduce((t,n)=>t+St(n).rows*St(n).cols,0),gm=(e,t)=>{if(!Vt(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(me({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(me({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(me({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(me({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},fn=(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}))}},vn=(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)}},Dt=(e,t)=>e.row===t.row&&e.col===t.col,Za=(e,t)=>e===void 0?bi(void 0,void 0,t()):bi(e.align,e.value,e.align===void 0?t():""),Eo=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},dr=(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}},ko=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}),Qa=e=>e.isCellReadOnly!==void 0,nt=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,wm=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellInputMode","getCellAttributes","getRangeExtrema","evaluateFormula"],Wi=["text","decimal","numeric","tel","search","email","url"],Cm=(e,t,n)=>{if(e.getCellInputMode===void 0)return"text";const r=e.getCellInputMode(t,n),o=Wi.find(s=>s===r);if(o===void 0)throw new RangeError(`[Spreadsheet] getCellInputMode(${t}, ${n}) must return one of ${Wi.join(" / ")}; got ${typeof r=="string"?JSON.stringify(r):String(r)}`);return o},ym=()=>!0,bm=e=>{const t=new WeakMap,n={};for(const r of wm)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:ym}),n},vm=/^data-[a-z0-9-]+$/,Rm=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Sm=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Rm(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(!vm.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},Mr=(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},nr=(e,t)=>{for(const n of t)if(Mr(e,n))return!0;return!1},Em=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=St(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Bs=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=St(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,a=c?s.rows:e.rows,u=c?s.cols:e.cols,h=l?n:{row:t.startRow,col:t.startCol},g=Math.min(a,r-h.row),L=Math.min(u,o-h.col);return g<=0||L<=0?null:me(h,{row:h.row+g-1,col:h.col+L-1})},eu=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,a=Bs({rows:l,cols:c},t,n,r,o);if(a===null)return[];const u={row:a.startRow,col:a.startCol},h=a.endRow-a.startRow+1,g=a.endCol-a.startCol+1,L=[];for(let M=0;M<h;M+=l){const $=[];for(let Z=0;Z<g;Z+=c){const Q={row:u.row+M,col:u.col+Z};$.push(Q),L.push(Q)}const H=Math.min(l,h-M);for(let Z=0;Z<H;Z+=1){const Q=u.row+M+Z,O=e[Z];for(let D=0;D<$.length;D+=1){const W=D*c,K=Math.min(c,g-W);for(let E=0;E<K;E+=1)s(Q,u.col+W+E,O[E],$[D])}}}return L},km=(e,t,n,r,o)=>{const s=[];return eu(e,t,n,r,o,(l,c,a)=>{s.push({row:l,col:c,text:a})}),s},Ki=(e,t,n,r,o,s)=>{const l=[],c=eu(e,t,n,r,o,(a,u,h,g)=>{const L=s(h,a,u,g);L!==null&&l.push({...L,row:a,col:u})});return{edits:l,tiles:c}},tu=(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)})`)},Om=(e,t)=>{tu(e,t);const n=St(t),r=St(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},xm=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(me({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(me({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(me({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(me({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Am=(e,t,n,r)=>{tu(t,n);const o=St(t).rows,s=St(t).cols,l=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const u=t.startRow+((a-t.startRow)%o+o)%o,h=a>=t.startRow&&a<=t.endRow;for(let g=n.startCol;g<=n.endCol;g+=1){if(h&&g>=t.startCol&&g<=t.endCol)continue;const L=t.startCol+((g-t.startCol)%s+s)%s,M=u*2**21+L;let $=c.get(M);$===void 0&&($={value:e(u,L),origin:{row:u,col:L}},c.set(M,$)),l.push(r($.value,$.origin,{row:a,col:g}))}}return l},nu=(e,t,n)=>{const r=dr(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:Nt(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=fr(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},ru=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?$a(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},jo=["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"],Tm=/^[A-Z]$/,$m=/^[A-Za-z]$/,Mm=/^Key([A-Z])$/,ou=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"]),Lm=e=>Tm.test(e)||ou.has(e),en=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||!Lm(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}},zm=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,su=e=>{if($m.test(e.key))return e.key.toUpperCase();const t=Mm.exec(e.code);return t!==null?t[1]:ou.has(e.code)?e.code:null},kr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:su(t)===e.key,Ee=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),xe=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Nm=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(Ee(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(Ee(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(Ee(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(Ee(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Dm=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(Ee(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(Ee(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},Hr=[...Nm(),Ee("Home","idle","row start (first visible column)"),Ee("Ctrl+Home","idle","first visible cell"),Ee("Shift+Home","idle","extend to row start"),Ee("Ctrl+Shift+Home","idle","extend to first visible cell"),Ee("End","idle","row end (last visible column)"),Ee("Ctrl+End","idle","last visible cell"),Ee("Shift+End","idle","extend to row end"),Ee("Ctrl+Shift+End","idle","extend to last visible cell"),Ee("PageUp","both","page up (idle) / commit + page up (editing)"),Ee("PageDown","both","page down (idle) / commit + page down (editing)"),Ee("Shift+PageUp","idle","extend one page up"),Ee("Shift+PageDown","idle","extend one page down"),Ee("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),Ee("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),Ee("Tab","both","cycle right (idle) / commit + cycle right (editing)"),Ee("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),Ee("Enter","both","cycle down (idle) / commit + cycle down (editing)"),Ee("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),Ee("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),Ee("F2","both","start editing (idle) / toggle the pointing arm (editing)"),Ee("F4","editing","cycle the reference anchor under the caret (formula session)"),Ee("Delete","idle","clear every selected cell"),Ee("Backspace","idle","clear every selected cell"),Ee("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),Ee("Ctrl+A","idle","select all"),Ee("Ctrl+Z","idle","undo request"),Ee("Ctrl+Y","idle","redo request"),Ee("Ctrl+Shift+Z","idle","redo request"),Ee("Shift+F10","idle","keyboard context menu"),Ee("ContextMenu","idle","keyboard context menu"),Ee("Ctrl+Space","idle","column bands"),Ee("Shift+Space","idle","row bands"),Ee("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),Ee("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),Ee("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),Ee("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"},...Dm(),xe("bold","Ctrl+B","both","toggle bold"),xe("italic","Ctrl+I","both","toggle italic"),xe("underline","Ctrl+U","both","toggle underline"),xe("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),xe("clearFormatting","Ctrl+Backslash","idle","clear formatting"),xe("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),xe("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),xe("alignLeft","Ctrl+Shift+L","both","align left"),xe("alignCenter","Ctrl+Shift+E","both","align center"),xe("alignRight","Ctrl+Shift+R","both","align right"),xe("formatNumber","Ctrl+Shift+Digit1","both","number format"),xe("formatTime","Ctrl+Shift+Digit2","both","time format"),xe("formatDate","Ctrl+Shift+Digit3","both","date format"),xe("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),xe("formatPercent","Ctrl+Shift+Digit5","both","percent format"),xe("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),xe("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),xe("bordersClear","Alt+Shift+Digit6","idle","clear borders"),xe("borderTop","Alt+Shift+Digit1","idle","top border"),xe("borderRight","Alt+Shift+Digit2","idle","right border"),xe("borderBottom","Alt+Shift+Digit3","idle","bottom border"),xe("borderLeft","Alt+Shift+Digit4","idle","left border"),xe("insertLink","Ctrl+K","idle","insert / edit hyperlink"),xe("insertNote","Shift+F2","idle","insert / edit note"),xe("insertComment","Ctrl+Alt+M","idle","insert comment"),xe("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),xe("openValidationList","Alt+ArrowDown","idle","open the validation list"),xe("fillDown","Ctrl+D","idle","fill down"),xe("fillRight","Ctrl+R","idle","fill right"),xe("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),xe("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),xe("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),xe("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),xe("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),xe("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),xe("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),xe("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),xe("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),xe("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),xe("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],ys=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),Yi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Fm=e=>{const t=en(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 Yi?Yi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},To=(e,t)=>e.column==="both"||e.column===t,qm=Array.from(new Set(Hr.filter(e=>!e.rebindable&&To(e,"idle")).map(e=>e.chord))),$o=new Set(Hr.filter(e=>e.command!==void 0&&To(e,"editing")).map(e=>e.command)),Pm=new Set(Hr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),lu=e=>{const t={};for(const n of jo)t[n]=e(n);return t},iu=lu(e=>Hr.filter(t=>t.command===e).map(t=>t.chord)),_m=e=>{const t=new Map;for(const n of jo){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},jm=e=>{const t=new Set(jo);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(Pm.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`)}}}},Im=(e,t)=>{const n=en(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=$o.has(e);for(const o of Hr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(To(o,"idle")||r&&To(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Hm=e=>{e!==void 0&&jm(e);const t=lu(r=>{const o=e===void 0?void 0:e[r];return o===void 0?iu[r]:o===null?[]:o});for(const r of jo)for(const o of t[r])Im(r,o);const n=new Map;for(const[r,o]of _m(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},Vs=(e,t)=>{const n=su(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=zm({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}},Bm=(e,t)=>{const n=Vs(e,t);return n===null?null:n.command},Vm=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","NumpadEnter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Wm=/^F(?:[1-9]|1[0-2])$/,Km=e=>{const t=en(e);return t.alt||Vm.has(t.key)?!1:t.ctrl||Wm.test(t.key)},pl=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose","columnMenu","columnMenuFiltered","sortAscending","sortDescending","sortClear","filterMatchMode","filterModeExact","filterModeFuzzy","filterSearchValues","filterSelectAll","filterSelectNone","filterBlank","filterLoading","filterLoadFailed","filterQuery","filterApply","filterClearColumn","filterClearAll"],Xi=[...rt.VIRTUAL_SCROLL_LABEL_KEYS,...pl],Ws=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close",columnMenu:"Sort and filter",columnMenuFiltered:"filtered",sortAscending:"Sort ascending",sortDescending:"Sort descending",sortClear:"Clear sort",filterMatchMode:"Match",filterModeExact:"Exact match",filterModeFuzzy:"Fuzzy search",filterSearchValues:"Search values",filterSelectAll:"Select all",filterSelectNone:"Clear all",filterBlank:"(Blanks)",filterLoading:"Loading…",filterLoadFailed:"Could not load the values",filterQuery:"Search text",filterApply:"Apply",filterClearColumn:"Clear this column's filter",filterClearAll:"Clear all filters"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる",columnMenu:"並べ替えと絞り込み",columnMenuFiltered:"絞り込み中",sortAscending:"昇順で並べ替え",sortDescending:"降順で並べ替え",sortClear:"並べ替えを外す",filterMatchMode:"検索方法",filterModeExact:"完全一致",filterModeFuzzy:"あいまい検索",filterSearchValues:"値を探す",filterSelectAll:"すべて選ぶ",filterSelectNone:"すべて外す",filterBlank:"(空白)",filterLoading:"読み込み中…",filterLoadFailed:"値を読めませんでした",filterQuery:"探す語",filterApply:"当てる",filterClearColumn:"この列の絞り込みを外す",filterClearAll:"すべての絞り込みを外す"})}),cu=Object.freeze({en:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Ws.en}),ja:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Ws.ja})}),zn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Ui=e=>e==="commentCount"||e==="listMore",Ym=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 ${zn(t)}`);for(const n of pl){const r=e[n];if(!(Ui(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Ui(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${zn(r)}`)}}},Xm=e=>{const t={};let n=!1;for(const r of rt.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},Um=(e,t,n)=>{e[t]=n},au=(e,t)=>{const n=rt.resolveVirtualScrollLocale(e);if(t===void 0)return cu[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${zn(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(!Xi.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Xi.join(", ")}`);const s={...rt.resolveVirtualScrollLabels(n,Xm(t)),...Ws[n]};for(const l of pl){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&Um(s,l,c)}return Ym(s),Object.freeze(s)},Gm=e=>{const t={};for(const n of rt.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},be=(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},Gi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Jm={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Zm=(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}`}},bs=(e,t)=>{const n=r=>(o,s)=>`${e} ${Zm(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")})},Qm=Object.freeze({list:"Value must be one of the list items.",number:bs("Value must be a number",Gi),textLength:bs("Text length must be",Gi),date:bs("Value must be a date",Jm),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),eg=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} を満たす値を入力してください。`}),vs=Object.freeze({en:Qm,ja:eg}),tg=Object.freeze({ok:!0}),ng="TRUE",rg="FALSE",og=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),sg=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),lg=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,ig=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,cg=/^[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])?)+$/,Ji=e=>{const t=e.trim();if(!(lg.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),a=c<0?s:s.slice(0,c),u=c<0?"":s.slice(c+1),h=a+u,g=h.search(/[^0]/);return g<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:h.slice(g).replace(/0+$/,""),point:a.length+l-g}},ag=e=>e===1?-1:e===-1?1:0,ug=(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:ag(n)},dg=(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}},Zi=e=>{const t=ig.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>dg(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},fg=(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},pg=(e,t)=>e<t?-1:e>t?1:0,hg=e=>e==="between"||e==="notBetween",mg=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!hg(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},gg=(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}},Rs=(e,t,n,r,o,s)=>{const l=mg(e,t,n,r);return l===null?!0:o===null?!1:gg(e,s(o,l.a),l.b===null?0:s(o,l.b))},wg=e=>Number.isFinite(e)?e:null,Cg=e=>{let t=0;for(const n of e)t+=1;return t},yg=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),bg=(e,t)=>{switch(e.op){case"isEmail":return cg.test(t);case"isUrl":return yg(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)}},vg=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,uu=e=>({checked:e.checked===void 0?ng:e.checked,unchecked:e.unchecked===void 0?rg:e.unchecked}),Rg=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!og.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${zn(e.op)} for type "${e.type}"`);return;case"text":if(!sg.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${zn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${zn(e.type)}`)}},Sg=(e,t,n)=>{switch(e.type){case"list":return Og(e).has(t);case"number":return Rs(e.op,e.a,e.b,Ji,Ji(t),ug);case"textLength":return Rs(e.op,e.a,e.b,wg,Cg(t),pg);case"date":return Rs(e.op,e.a,e.b,Zi,Zi(t),fg);case"text":return bg(e,t);case"checkbox":{const r=uu(e);return t===r.checked||t===r.unchecked}default:return n===void 0||vg(n(e.formula))}},du=(e,t,n)=>(Rg(e),t===""||Sg(e,t,n)),Qi=e=>e===void 0?void 0:e.trim(),Eg=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Qi(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(),Qi(e.b));case"text":return kg(e,t.text);case"checkbox":{const n=uu(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},kg=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},ec=new WeakMap,Og=e=>{const t=ec.get(e);if(t!==void 0)return t;const n=new Set(e.values);return ec.set(e,n),n},fu=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(vs,n)){const o=Object.keys(vs).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${zn(n)}`)}return du(e,t,r)?tg:{ok:!1,message:e.errorMessage===void 0?Eg(e,vs[n]):e.errorMessage}},xg=e=>e.type!=="custom",Ag=(e,t)=>xg(e)&&!du(e,t,void 0),pu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),hu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),mu=(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,gu=(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),wu=(e,t)=>pu(e,t),Cu=(e,t)=>pu(e,t),yu=(e,t)=>hu(e,t),bu=(e,t)=>hu(e,t),Nn=(e,t,n)=>mu(e,t,n),Dn=(e,t,n)=>mu(e,t,n),Br=(e,t,n)=>gu(e,t,n),Vr=(e,t,n)=>gu(e,t,n),Tg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Bt=1,Lr=3,co=e=>`${-Math.min(Lr,Math.max(0,Math.floor(e)))}px`,$g=(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}},tc=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,nc=(e,t)=>t===null?e:Math.min(e,t),rc=e=>e===null?"100%":`min(100%, ${e}px)`,oc=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,sc=(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]}},lc=Object.freeze([0,-1]),ic=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const a=-c*Bt,u=c*(1+Bt),h=t>=r,g=n<=o,L=h?s:a,M=g?l:u;return M<=a||L>=u?!1:(e.near=Math.max(L,a),e.far=Math.min(M,u),e.nearOpen=!h||L<a,e.farOpen=!g||M>u,!0)},ao=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),cc=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,ac=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Mg=Object.freeze(["top","right","bottom","left"]),Lg=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),zg=e=>Mg.filter((t,n)=>(e&1<<n)!==0).join(" "),vu=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Ng=16,Dg=450,Fg=e=>e>4?Math.floor(Dg/(5*e)):Ng,Or=(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},uc=()=>({rowLeft:Or("row","left"),rowRight:Or("row","right"),colAbove:Or("column","above"),colBelow:Or("column","below"),cross:Or("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Ks=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],uo=(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},fo=(e,t)=>Math.min(Math.max(e,0),t),dc="inset(100%)",sr=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},qg=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,sr([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const L=`${t.height}px`;e.rowLeft.style.height=L,e.rowRight.style.height=L}const h=`translate(${fo(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;h!==s.rowLeftTransform&&(s.rowLeftTransform=h,e.rowLeft.style.transform=h);const g=`translate(${fo(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;g!==s.rowRightTransform&&(s.rowRightTransform=g,e.rowRight.style.transform=g)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,sr([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const L=`${t.width}px`;e.colAbove.style.width=L,e.colBelow.style.width=L}const h=`translate(${t.left}px, ${fo(t.top,n.clampHeight)-n.clampHeight}px)`;h!==s.colAboveTransform&&(s.colAboveTransform=h,e.colAbove.style.transform=h);const g=`translate(${t.left}px, ${fo(t.top+t.height,n.clampHeight)}px)`;g!==s.colBelowTransform&&(s.colBelowTransform=g,e.colBelow.style.transform=g)}const a=r.intersection?"intersection":l!==c?l?"row":"column":null,u=a!==null;if(u!==s.crossShown&&(s.crossShown=u,sr([e.cross],u)),a!==null){a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--_aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const h=`translate(${t.left}px, ${t.top}px)`;h!==s.crossTransform&&(s.crossTransform=h,e.cross.style.transform=h)}},fc=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,sr([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,sr([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,sr([e.cross],!1))},po=e=>{for(const t of Ks(e))t.remove()},Pg=(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)},_g=Object.freeze([]),pc=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},hc=e=>e.chrome[0]??e.active,mc=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)},jg={left:"0px",right:"0px",width:""},Ig={top:"0px",bottom:"0px",height:""},gc=()=>({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:[]}),wc=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Cc=6,Hg=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,sinkInputMode:l,repaintRef:c,dragFrameRef:a,getClip:u,getIsDraggingAny:h,getIsFillDragging:g,fillFrameRef:L,resizeGuideFrameRef:M,fillHandleNodeRef:$,enableFillHandle:H,frozenCols:Z,frozenRows:Q,trailingCols:O,trailingRows:D,sinkAriaLabel:W,sinkReadOnly:K,sinkKeyShortcuts:E,onSinkMouseDown:P,editPaintRef:j,highlightRef:m,frameRange:d,highlightColors:y,popoverAnchors:v,interactiveAnchorRef:x,tipAnchorRef:S})=>{const V=i.useRef(null),C=i.useRef(d);C.current=d;const A=d!==void 0,X=i.useRef(null),w=i.useRef(null),G=i.useRef(new Map(wc.map(T=>[T,gc()]))),te=i.useCallback(T=>{const F=G.current.get(T);if(F!==void 0)return F;const J=gc();return G.current.set(T,J),J},[]),f=i.useCallback((T,F,J)=>{if(T===null)return;const q=T.style;q.left!==F.left&&(q.left=F.left),q.right!==F.right&&(q.right=F.right),q.width!==F.width&&(q.width=F.width),q.top!==J.top&&(q.top=J.top),q.bottom!==J.bottom&&(q.bottom=J.bottom),q.height!==J.height&&(q.height=J.height)},[]),b=i.useCallback((T,F,J)=>{if(!(T.bandClampWidth===F&&T.bandClampHeight===J)){T.bandClampWidth=F,T.bandClampHeight=J;for(const q of T.bandPool)uo(q,F,J);T.dragBand!==null&&uo(T.dragBand,F,J)}},[]),R=i.useRef({rowAxis:e,colAxis:t});R.current={rowAxis:e,colAxis:t};const _=i.useCallback((T,F,J)=>{const q=T.dividerSlots[F];q===null||T.dividerShown[F]===J||(T.dividerShown[F]=J,q.style.display=J?"":"none")},[]),Y=i.useCallback((T,F,J)=>{const q=T.bandClip;q!==null&&(T.bandClipWidth!==F&&(T.bandClipWidth=F,q.style.width=F),T.bandClipHeight!==J&&(T.bandClipHeight=J,q.style.height=J))},[]),U=i.useCallback((T,F,J)=>{const q=T.dividerSlots[F];q===null||T.dividerEnd[F]===J||(T.dividerEnd[F]=J,F<2?q.style.bottom=J:q.style.right=J)},[]),oe=i.useRef({x:0,y:0}),ce=i.useRef(null),k=i.useCallback((T,F)=>{const J=n.current,q=J?.getFrozenSize()??Tg,ne=J?.getViewportSize(),ie=ne?.width??-1,fe=ne?.height??-1,Ne=oe.current;Ne.x=T,Ne.y=F;const $e=C.current!==void 0,ue=R.current,We=$e?ue.rowAxis.count:-1,Ke=$e?ue.colAxis.count:-1,Ae=$e?ue.rowAxis.totalSize():-1,we=$e?ue.colAxis.totalSize():-1;let de=ce.current;if(de===null||de.framed!==$e||de.rowCount!==We||de.colCount!==Ke||de.rowsTotal!==Ae||de.colsTotal!==we||de.frozenCols!==q.cols||de.frozenWidth!==q.width||de.frozenRows!==q.rows||de.frozenHeight!==q.height||de.trailingCols!==q.trailingCols||de.trailingWidth!==q.trailingWidth||de.trailingVisibleWidth!==q.trailingVisibleWidth||de.trailingRows!==q.trailingRows||de.trailingHeight!==q.trailingHeight||de.trailingVisibleHeight!==q.trailingVisibleHeight||de.bodyWidth!==ie||de.bodyHeight!==fe){const le=q.trailingVisibleWidth,Me=q.trailingVisibleHeight,mt=q.cols<=0&&q.trailingCols<=0?[{kind:"m",map:Le=>Le-Ne.x,clamp:ie,style:jg,seamLead:!1,seamTrail:!1}]:[...q.cols>0?[{kind:"f",map:Le=>Le,clamp:q.width,style:{left:"0px",width:`${q.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Le=>Le-Ne.x-q.width,clamp:Math.max(0,ie-q.width-le),style:{left:`${q.width}px`,right:`${le}px`,width:""},seamLead:q.cols>0,seamTrail:q.trailingCols>0},...q.trailingCols>0?[{kind:"t",map:Le=>Le-R.current.colAxis.totalSize()+le,clamp:le,style:{left:"",right:"0px",width:`${le}px`},seamLead:!0,seamTrail:!1}]:[]],at=q.rows<=0&&q.trailingRows<=0?[{kind:"m",map:Le=>Le-Ne.y,clamp:fe,style:Ig,seamLead:!1,seamTrail:!1}]:[...q.rows>0?[{kind:"f",map:Le=>Le,clamp:q.height,style:{top:"0px",height:`${q.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Le=>Le-Ne.y-q.height,clamp:Math.max(0,fe-q.height-Me),style:{top:`${q.height}px`,bottom:`${Me}px`,height:""},seamLead:q.rows>0,seamTrail:q.trailingRows>0},...q.trailingRows>0?[{kind:"t",map:Le=>Le-R.current.rowAxis.totalSize()+Me,clamp:Me,style:{top:"",bottom:"0px",height:`${Me}px`},seamLead:!0,seamTrail:!1}]:[]],ut=[];for(const Le of mt){const dt=$e?tc(Le.kind,we,q.width,q.trailingWidth):null,[Kt,gt]=$e?sc(Le.kind,Ke,q.cols,q.trailingCols):lc;for(const Ye of at){const qt=$e?tc(Ye.kind,Ae,q.height,q.trailingHeight):null,[In,Kr]=$e?sc(Ye.kind,We,q.rows,q.trailingRows):lc;ut.push({nodes:te(`${Le.kind}${Ye.kind}`),xKind:Le.kind,yKind:Ye.kind,mapX:Le.map,clampWidth:Le.clamp,xStyle:Le.style,xSeamLead:Le.seamLead,xSeamTrail:Le.seamTrail,xFirst:Kt,xLast:gt,mapY:Ye.map,clampHeight:Ye.clamp,yStyle:Ye.style,ySeamLead:Ye.seamLead,ySeamTrail:Ye.seamTrail,yFirst:In,yLast:Kr,cells:{clampWidth:nc(Le.clamp,dt),clampHeight:nc(Ye.clamp,qt)},xCellsSizeCss:rc(dt),yCellsSizeCss:rc(qt),xCellsEndCss:oc(dt),yCellsEndCss:oc(qt)})}}de={frozenCols:q.cols,frozenWidth:q.width,frozenRows:q.rows,frozenHeight:q.height,trailingCols:q.trailingCols,trailingWidth:q.trailingWidth,trailingVisibleWidth:q.trailingVisibleWidth,trailingRows:q.trailingRows,trailingHeight:q.trailingHeight,trailingVisibleHeight:q.trailingVisibleHeight,bodyWidth:ie,bodyHeight:fe,framed:$e,rowCount:We,colCount:Ke,rowsTotal:Ae,colsTotal:we,ctxs:ut},ce.current=de}const pe=q.width>0,Re=q.trailingWidth>0,Se=q.height>0,ct=q.trailingHeight>0;for(const le of de.ctxs)f(le.nodes.container,le.xStyle,le.yStyle),b(le.nodes,le.clampWidth,le.clampHeight),_(le.nodes,0,pe),_(le.nodes,1,Re),_(le.nodes,2,Se),_(le.nodes,3,ct),U(le.nodes,0,le.yCellsEndCss),U(le.nodes,1,le.yCellsEndCss),U(le.nodes,2,le.xCellsEndCss),U(le.nodes,3,le.xCellsEndCss),Y(le.nodes,le.xCellsSizeCss,le.yCellsSizeCss);return de.ctxs},[n,te,f,b,_,U,Y]),B=i.useCallback((T,F,J)=>{T.dividerSlots[F]=J,T.dividerShown[F]=!1,T.dividerEnd[F]="0px",mc(T)},[]),z=i.useCallback((T,F)=>{T.frame=F===null?null:{node:F,x:ao(),y:ao(),drawnX:ao(),drawnY:ao(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},mc(T)},[]),re=i.useCallback((T,F)=>{for(const q of T.bandPool)po(q);T.bandPool.length=0,T.dragBand!==null&&(po(T.dragBand),T.dragBand=null),T.bandClampWidth=-1,T.bandClampHeight=-1,T.bandClip=F,T.bandClipWidth="",T.bandClipHeight="";const J=F===null?null:F.parentElement;F!==null&&J!==null&&J.firstChild!==F&&J.insertBefore(F,J.firstChild)},[]),ge=i.useCallback(T=>{const F=()=>te(T);return{container:J=>{const q=F();q.container=J,J===null&&(q.fillPool.length=0,q.bandPool.length=0,q.dragBand=null,q.bandClampWidth=-1,q.bandClampHeight=-1)},dividerXLeading:J=>B(F(),0,J),dividerXTrailing:J=>B(F(),1,J),dividerYLeading:J=>B(F(),2,J),dividerYTrailing:J=>B(F(),3,J),frame:J=>z(F(),J),bandClip:J=>re(F(),J),active:J=>{F().active=J},dragRect:J=>{F().dragRect=J},marquee:J=>{F().marquee=J},fillPreview:J=>{F().fillPreview=J},resizeGuide:J=>{F().resizeGuide=J}}},[te,B,z,re]),Te=i.useMemo(()=>Object.fromEntries(wc.map(T=>[T,ge(T)])),[ge]),Pe=Math.min(Math.max(0,Z),t.count),ot=wu(t,Pe),je=Math.min(Math.max(0,Q),e.count),Xe=Cu(e,je),Oe=O===void 0?0:Math.min(Math.max(0,O),t.count-Pe),Ie=yu(t,Oe),Be=D===void 0?0:Math.min(Math.max(0,D),e.count-je),Et=bu(e,Be),it=i.useRef(null),on=i.useRef("add"),Ze=i.useRef(s);Ze.current=s;const kt=i.useRef(!1),Rn=rt.useWheelBridge(n,{enableBridge:!s}),Io=i.useCallback(T=>(r.current=T,Rn(T)),[r,Rn]),Sn=i.useCallback((T,F)=>({top:F.mapY(e.offsetOf(T.startRow)),bottom:F.mapY(e.offsetOf(T.endRow)+e.sizeOf(T.endRow)),left:F.mapX(t.offsetOf(T.startCol)),right:F.mapX(t.offsetOf(T.endCol)+t.sizeOf(T.endCol))}),[e,t]),Ft=i.useCallback((T,F)=>{if(F.clampHeight<=0||F.clampWidth<=0)return null;const{top:J,bottom:q,left:ne,right:ie}=Sn(T,F),fe=-F.clampHeight*Bt,Ne=F.clampHeight*(1+Bt),$e=-F.clampWidth*Bt,ue=F.clampWidth*(1+Bt);if(q<fe||J>Ne||ie<$e||ne>ue)return null;const We=Math.max(J,fe),Ke=Math.max(ne,$e);return{top:We,left:Ke,width:Math.min(ie,ue)-Ke,height:Math.min(q,Ne)-We}},[Sn]),Wr=i.useCallback((T,F)=>{if(F.clampHeight<=0||F.clampWidth<=0)return null;const J=Sn(T,F),q=-F.clampHeight*Bt,ne=F.clampHeight*(1+Bt),ie=-F.clampWidth*Bt,fe=F.clampWidth*(1+Bt),Ne=Math.min(Math.max(J.top,q),ne),$e=Math.min(Math.max(J.left,ie),fe);return{top:Ne,left:$e,width:Math.min(Math.max(J.right,ie),fe)-$e,height:Math.min(Math.max(J.bottom,q),ne)-Ne}},[Sn]),ae=i.useCallback(()=>{if(m===void 0)return null;const T=m.current;return T.row||T.column||T.intersection?T:null},[m]),ye=i.useCallback((T,F,J)=>{if(F.bandClip!==null){for(const ne of Ks(J))F.bandClip.appendChild(ne);return}const q=F.fillPool[0]?.node??hc(F);for(const ne of Ks(J))T.insertBefore(ne,q)},[]),ve=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),Fn=i.useCallback(T=>{const F=T.nodes.frame;if(F===null)return;const J=ve.current,q=C.current;(J.range!==q||J.rows!==e.count||J.cols!==t.count)&&(J.range=q,J.rows=e.count,J.cols=t.count,J.within=q===void 0?null:$g(q,e.count,t.count));const ne=J.within,ie=F.last,fe=F.node.style;if(!(ne!==null&&ic(F.x,ne.startCol,ne.endCol,T.xFirst,T.xLast,T.mapX(t.offsetOf(ne.startCol)),T.mapX(t.offsetOf(ne.endCol)+t.sizeOf(ne.endCol)),T.clampWidth)&&ic(F.y,ne.startRow,ne.endRow,T.yFirst,T.yLast,T.mapY(e.offsetOf(ne.startRow)),T.mapY(e.offsetOf(ne.endRow)+e.sizeOf(ne.endRow)),T.clampHeight))){ie.shown&&(ie.shown=!1,fe.display="none");return}if(ie.shown||(ie.shown=!0,fe.display="block"),!cc(F.x,F.drawnX)){ac(F.drawnX,F.x);const ue=pc(F.x);ue.start!==ie.left&&(ie.left=ue.start,fe.left=ue.start),ue.end!==ie.right&&(ie.right=ue.end,fe.right=ue.end),ue.size!==ie.width&&(ie.width=ue.size,fe.width=ue.size)}if(!cc(F.y,F.drawnY)){ac(F.drawnY,F.y);const ue=pc(F.y);ue.start!==ie.top&&(ie.top=ue.start,fe.top=ue.start),ue.end!==ie.bottom&&(ie.bottom=ue.end,fe.bottom=ue.end),ue.size!==ie.height&&(ie.height=ue.size,fe.height=ue.size)}const $e=Lg(F.x,F.y);$e!==ie.open&&(ie.open=$e,$e===0?F.node.removeAttribute("data-aqsp-frame-open"):F.node.setAttribute("data-aqsp-frame-open",zg($e)))},[e,t]),ze=i.useCallback((T,F,J,q)=>{const ne=Wr(F,J);if(ne===null){fc(T);return}qg(T,ne,J,q,ma(F,t.count)||ga(F,e.count))},[Wr,e,t]),qn=i.useCallback((T,F,J,q)=>{const ne=T.nodes.bandPool;for(;ne.length>J.length;){const ie=ne.pop();ie!==void 0&&po(ie)}if(q===null){T.nodes.dragBand!==null&&(po(T.nodes.dragBand),T.nodes.dragBand=null);return}for(let ie=0;ie<J.length;ie+=1){let fe=ne[ie];fe===void 0&&(fe=uc(),uo(fe,T.clampWidth,T.clampHeight),ye(F,T.nodes,fe),ne.push(fe)),ze(fe,J[ie],T,q)}},[ye,ze]),Qe=i.useCallback((T,F,J)=>{const q=T.nodes.container;if(q===null)return;if(F===null||J===null){T.nodes.dragBand!==null&&fc(T.nodes.dragBand);return}let ne=T.nodes.dragBand;ne===null&&(ne=uc(),uo(ne,T.clampWidth,T.clampHeight),ye(q,T.nodes,ne),T.nodes.dragBand=ne),ze(ne,F,T,J)},[ye,ze]),sn=i.useCallback((T,F)=>{if(T!==null){if(F===null){T.style.display="none";return}T.style.display="block",T.style.transform=`translate(${F.left}px, ${F.top}px)`,T.style.width=`${F.width}px`,T.style.height=`${F.height}px`}},[]),Wt=i.useCallback((T,F,J,q)=>{const ne=q==="point"?null:ae();for(const ie of k(J,F))sn(ie.nodes.dragRect,Ft(T,ie)),Qe(ie,T,ne)},[Ft,k,sn,ae,Qe]),Pn=i.useCallback((T,F,J)=>{for(const q of k(J,F))sn(q.nodes.fillPreview,T===null?null:Ft(T,q))},[Ft,k,sn]),_n=i.useCallback((T,F,J)=>{for(const q of k(J,F)){const ne=q.nodes.resizeGuide;if(ne===null)continue;if(T===null){ne.style.display="none";continue}const ie=T.anchor==="trailing";if(T.axis==="col"){if(ie&&q.xKind!=="t"){ne.style.display="none";continue}ne.style.display="block";const fe=q.mapX(T.position);ne.style.transform=`translate(${ie?Math.max(0,fe):fe}px, 0px)`,ne.style.width="1px",ne.style.height="100%"}else{if(ie&&q.yKind!=="t"){ne.style.display="none";continue}ne.style.display="block";const fe=q.mapY(T.position);ne.style.transform=`translate(0px, ${ie?Math.max(0,fe):fe}px)`,ne.style.width="100%",ne.style.height="1px"}}},[k]),pr=i.useCallback((T,F,J,q,ne,ie,fe)=>{if(T===null)return;if(F===null||fe<=0||ie<=0){T.style.clipPath=dc;return}const Ne=Dn(e,F.row,q),$e=Nn(t,F.col,J),ue=t.sizeOf(F.col),We=e.sizeOf(F.row),Ke=$e>=ie||Ne>=fe,Ae=F.col>=ne.cols&&$e<ne.width,we=F.row>=ne.rows&&Ne<ne.height,de=ne.trailingWidth>0&&F.col<t.count-ne.trailingCols&&$e+ue>ie-ne.trailingVisibleWidth,pe=ne.trailingHeight>0&&F.row<e.count-ne.trailingRows&&Ne+We>fe-ne.trailingVisibleHeight;if(Ke||Ae||we||de||pe){T.style.clipPath=dc;return}T.style.clipPath="",T.style.transform=`translate(${$e}px, ${Ne}px)`;const Re=`${ue} ${We}`;T.dataset.aqspAnchorSig!==Re&&(T.dataset.aqspAnchorSig=Re,T.style.width=`${ue}px`,T.style.height=`${We}px`)},[e,t]),hr=i.useCallback((T,F,J)=>{if(v===void 0)return;const q=v.current,{width:ne,height:ie}=T.getViewportSize(),fe=T.getFrozenSize(),Ne={scroll:J,frozenCount:fe.cols,trailingCount:fe.trailingCols,extent:ne},$e={scroll:F,frozenCount:fe.rows,trailingCount:fe.trailingRows,extent:ie};pr(x===void 0?null:x.current,q.interactive,Ne,$e,fe,ne,ie),pr(S===void 0?null:S.current,q.tip,Ne,$e,fe,ne,ie)},[v,x,S,pr]),mr=i.useCallback(()=>{const T=V.current,F=n.current;if(T===null||F===null)return;const J=F.getScrollPosition(),q=Math.max(0,J.y),ne=Math.max(0,J.x),ie=o(),fe=k(ne,q),Ne=ae(),$e=Ne===null?_g:ie.ranges.slice(-Fg(fe.length));for(const we of fe){const de=we.nodes.container;if(de===null)continue;const pe=we.nodes.fillPool;for(let Re=0;Re<Math.max(pe.length,ie.ranges.length);Re+=1){let Se=pe[Re];if(Se===void 0){const Me=document.createElement("div");Me.className="aqsp-selection-fill",Me.setAttribute("data-aqsp-fill",""),Me.style.display="none",de.insertBefore(Me,hc(we.nodes)),Se={node:Me,last:{shown:!1,width:-1,height:-1,transform:""}},pe.push(Se)}const ct=ie.ranges[Re],le=ct===void 0?null:Ft(ct,we);if(le===null)Se.last.shown&&(Se.last.shown=!1,Se.node.style.display="none");else{Se.last.shown||(Se.last.shown=!0,Se.node.style.display="block");const Me=`translate(${le.left}px, ${le.top}px)`;Me!==Se.last.transform&&(Se.last.transform=Me,Se.node.style.transform=Me),le.width!==Se.last.width&&(Se.last.width=le.width,Se.node.style.width=`${le.width}px`),le.height!==Se.last.height&&(Se.last.height=le.height,Se.node.style.height=`${le.height}px`)}}for(;pe.length>ie.ranges.length;)pe.pop()?.node.remove();sn(we.nodes.active,Ft(me(ie.active,ie.active),we)),Fn(we),qn(we,de,$e,Ne)}const ue=u(),We=ue===null||ue.foreign?null:ue;for(const we of fe){const de=we.nodes.marquee;if(de===null)continue;const pe=We===null?null:Ft(We.range,we),Re=pe!==null&&(we.xSeamTrail&&pe.left>=we.clampWidth&&pe.left<we.clampWidth+Lr||we.xSeamLead&&pe.left+pe.width<=0&&pe.left+pe.width>-Lr||we.ySeamTrail&&pe.top>=we.clampHeight&&pe.top<we.clampHeight+Lr||we.ySeamLead&&pe.top+pe.height<=0&&pe.top+pe.height>-Lr)?null:pe;if(Re===null)de.style.display="none";else{de.style.display="block",de.style.transform=`translate(${Re.left}px, ${Re.top}px)`,de.style.width=`${Re.width}px`,de.style.height=`${Re.height}px`;const le=co(Re.top),Me=co(Re.left),mt=co(we.cells.clampHeight-(Re.top+Re.height)),at=co(we.cells.clampWidth-(Re.left+Re.width)),ut=`${le} ${at} ${mt} ${Me}`;ut!==de.dataset.aqspOutsetSig&&(de.dataset.aqspOutsetSig=ut,de.style.setProperty("--aqsp-clip-outset-top",le),de.style.setProperty("--aqsp-clip-outset-right",at),de.style.setProperty("--aqsp-clip-outset-bottom",mt),de.style.setProperty("--aqsp-clip-outset-left",Me))}const Se=Re===null?null:We?.kind??null,ct=de.dataset.aqspClipKindLast??null;Se!==ct&&(Se===null?(delete de.dataset.aqspClipKindLast,de.removeAttribute("data-aqsp-clip-kind")):(de.dataset.aqspClipKindLast=Se,de.setAttribute("data-aqsp-clip-kind",Se)))}it.current!==null&&Wt(it.current,q,ne,on.current),w.current!==null&&_n(w.current,q,ne),X.current!==null&&Pn(X.current,q,ne);const Ke=$.current;if(Ke!==null&&!g()){const{width:we,height:de}=F.getViewportSize(),pe=ie.ranges[ie.ranges.length-1];if(!(ie.ranges.length===1&&!Ze.current&&!h())||de<=0||we<=0)Ke.style.display="none";else{const Se=F.getFrozenSize(),ct={scroll:ne,frozenCount:Se.cols,trailingCount:Se.trailingCols,extent:we},le={scroll:q,frozenCount:Se.rows,trailingCount:Se.trailingRows,extent:de},Me=pe.endCol<Se.cols,mt=pe.endRow<Se.rows,at=pe.endCol>=t.count-Se.trailingCols,ut=pe.endRow>=e.count-Se.trailingRows,Le=Nn(t,pe.endCol,ct)+t.sizeOf(pe.endCol),dt=Dn(e,pe.endRow,le)+e.sizeOf(pe.endRow),Kt=Me||at?0:Se.width,gt=mt||ut?0:Se.height,Ye=at?we:we-Se.trailingVisibleWidth,qt=ut?de:de-Se.trailingVisibleHeight;dt<=gt||dt>qt||Le<=Kt||Le>Ye?Ke.style.display="none":(Ke.style.display="block",Ke.style.transform=`translate(${Le-Cc+1}px, ${dt-Cc+1}px)`)}}const Ae=r.current;if(Ae!==null){const we=ie.active,{width:de,height:pe}=F.getViewportSize(),Re=F.getFrozenSize(),Se={scroll:ne,frozenCount:Re.cols,trailingCount:Re.trailingCols,extent:de},ct={scroll:q,frozenCount:Re.rows,trailingCount:Re.trailingRows,extent:pe},le=Dn(e,we.row,ct),Me=Nn(t,we.col,Se),mt=pe>0?Math.min(Math.max(le,0),Math.max(0,pe-1)):0,at=de>0?Math.min(Math.max(Me,0),Math.max(0,de-1)):0;Ae.style.top=`${mt}px`,Ae.style.left=`${at}px`,Ze.current?(Ae.style.width=`${t.sizeOf(we.col)}px`,Ae.style.height=`${e.sizeOf(we.row)}px`,Ae.style.paddingTop=`${Pg(e.sizeOf(we.row),j===void 0?Qt:j.current)}px`):(Ae.style.width="1px",Ae.style.height="1px",Ae.style.paddingTop="0px");const ut=we.col>=Re.cols&&Me<Re.width,Le=we.row>=Re.rows&&le<Re.height,dt=Re.trailingWidth>0&&we.col<t.count-Re.trailingCols&&Me+t.sizeOf(we.col)>de-Re.trailingVisibleWidth,Kt=Re.trailingHeight>0&&we.row<e.count-Re.trailingRows&&le+e.sizeOf(we.row)>pe-Re.trailingVisibleHeight,gt=Ze.current&&le===mt&&Me===at&&!ut&&!Le&&!dt&&!Kt;gt!==kt.current&&(kt.current=gt,gt?Ae.setAttribute("data-aqsp-editing",""):Ae.removeAttribute("data-aqsp-editing"))}hr(F,q,ne)},[n,Ft,k,sn,Wt,_n,Pn,u,o,h,g,$,r,e,t,ae,qn,Fn,j,hr]),Cl=i.useCallback((T,F)=>{it.current=T,on.current=F;const J=T===null?"add":F;for(const ie of k(0,0)){const fe=ie.nodes.dragRect;if(fe===null)continue;const Ne=fe.dataset.aqspDragModeLast??"add";J!==Ne&&(fe.dataset.aqspDragModeLast=J,J==="add"?fe.removeAttribute("data-aqsp-drag-mode"):fe.setAttribute("data-aqsp-drag-mode",J))}const q=n.current;if(T===null||q===null){for(const ie of k(0,0))ie.nodes.dragRect!==null&&(ie.nodes.dragRect.style.display="none"),Qe(ie,null,null);return}const ne=q.getScrollPosition();Wt(T,Math.max(0,ne.y),Math.max(0,ne.x),F)},[n,Wt,k,Qe]),Ho=i.useCallback(T=>{X.current=T;const F=n.current;if(F===null){for(const q of k(0,0))q.nodes.fillPreview!==null&&(q.nodes.fillPreview.style.display="none");return}const J=F.getScrollPosition();Pn(T,Math.max(0,J.y),Math.max(0,J.x))},[n,Pn,k]),gr=i.useCallback(T=>{w.current=T;const F=n.current;if(F===null){for(const q of k(0,0))q.nodes.resizeGuide!==null&&(q.nodes.resizeGuide.style.display="none");return}const J=F.getScrollPosition();_n(T,Math.max(0,J.y),Math.max(0,J.x))},[n,_n,k]);i.useLayoutEffect(()=>{const T=V.current;if(!(T===null||y===void 0))return T.style.setProperty("--aqsp-band-row",y.row),T.style.setProperty("--aqsp-band-column",y.column),T.style.setProperty("--aqsp-band-intersection",y.intersection),T.style.setProperty("--aqsp-band-opacity",String(y.opacity)),()=>{T.style.removeProperty("--aqsp-band-row"),T.style.removeProperty("--aqsp-band-column"),T.style.removeProperty("--aqsp-band-intersection"),T.style.removeProperty("--aqsp-band-opacity")}},[y]),i.useEffect(()=>(c.current=mr,a.current=Cl,L.current=Ho,M.current=gr,()=>{c.current=null,a.current=null,L.current=null,M.current=null})),i.useEffect(()=>{mr()},[mr,s,Pe,je,Oe,Be]),i.useEffect(()=>{const T=r.current;if(T===null)return;const F=J=>P(J);return T.addEventListener("mousedown",F),()=>T.removeEventListener("mousedown",F)},[r,P]);const jn=Pe>0||Oe>0?[...Pe>0?[{k:"f",style:{left:0,width:ot}}]:[],{k:"s",style:{left:ot,right:Ie}},...Oe>0?[{k:"t",style:{right:0,width:Ie}}]:[]]:[{k:"m",style:{left:0,right:0}}],wr=je>0||Be>0?[...je>0?[{k:"f",style:{top:0,height:Xe}}]:[],{k:"s",style:{top:Xe,bottom:Et}},...Be>0?[{k:"t",style:{bottom:0,height:Et}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],ln=T=>T==="m"?0:T==="s"?1:T==="t"?2:3,cn=jn.flatMap(T=>wr.map(F=>({xk:T.k,yk:F.k,key:`${T.k}${F.k}`,style:{...T.style,...F.style}}))).sort((T,F)=>ln(T.key[0])+ln(T.key[1])-(ln(F.key[0])+ln(F.key[1]))),Ve=T=>T==="mm"?{"data-aqsp-overlay-main":""}:T==="fm"?{"data-aqsp-overlay-frozen":""}:T==="sm"?{"data-aqsp-overlay-scroll":""}:{};return I.jsxs("div",{ref:V,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[cn.map(({xk:T,yk:F,key:J,style:q})=>{const ne=Te[J];return I.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":J,...Ve(J),style:q,ref:ne.container,children:[A?I.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:ne.bandClip}):null,T==="s"&&Pe>0?I.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:ne.dividerXLeading}):null,T==="s"&&Oe>0?I.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:ne.dividerXTrailing}):null,F==="s"&&je>0?I.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:ne.dividerYLeading}):null,F==="s"&&Be>0?I.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:ne.dividerYTrailing}):null,A?I.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:ne.frame}):null,I.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:ne.active}),I.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:ne.dragRect}),I.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:ne.marquee}),I.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:ne.fillPreview}),I.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:ne.resizeGuide})]},J)}),I.jsx("textarea",{ref:Io,className:"aqsp-sink","aria-label":W,"aria-readonly":K?"true":void 0,"aria-keyshortcuts":E,tabIndex:-1,defaultValue:" ",inputMode:l,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),H?I.jsx("div",{ref:$,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ru=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=g=>{l.current=!0;try{g()}finally{l.current=!1}},a=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},u=g=>{if(g.key==="Escape"){g.preventDefault(),c(e.close);return}g.key==="Enter"&&(g.ctrlKey||g.metaKey)&&!g.altKey&&!g.shiftKey&&(g.preventDefault(),a())},h=g=>{l.current||g.relatedTarget instanceof Node&&g.currentTarget.contains(g.relatedTarget)||e.rejected||c(e.close)};return I.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:h,children:[I.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[be(t,"commentTitle"),I.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:be(t,"commentCount",e.current.length)})]}),I.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(g=>I.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":g.id,children:[I.jsx("span",{className:"aqsp-popover-comment-author",children:g.author}),I.jsx("time",{className:"aqsp-popover-comment-time",dateTime:g.createdAt,children:g.createdAt}),I.jsx("p",{className:"aqsp-popover-comment-text",children:g.text})]},g.id))}),I.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":be(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:g=>r(g.currentTarget.value),onKeyDown:u}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:a,children:be(t,"commentPost")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Su=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),a=i.useRef(!1),u=o.trim()===""?null:bn(o),h=o.trim()!==""&&u===null,g=H=>{a.current=!0;try{H()}finally{a.current=!1}},L=()=>{l||h||g(()=>e.commit({text:n===""&&u!==null?u:n,url:u}))},M=H=>{if(H.key==="Escape"){H.preventDefault(),g(e.close);return}H.key==="Enter"&&!H.altKey&&!H.shiftKey&&(H.preventDefault(),L())},$=H=>{a.current||H.relatedTarget instanceof Node&&H.currentTarget.contains(H.relatedTarget)||e.rejected||g(e.close)};return I.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":h?"":void 0,role:"dialog","aria-labelledby":c,onBlur:$,children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:be(t,"linkTitle")}),I.jsxs("label",{className:"aqsp-popover-field",children:[I.jsx("span",{className:"aqsp-popover-field-label",children:be(t,"linkTextField")}),I.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:H=>r(H.currentTarget.value),onKeyDown:M})]}),I.jsxs("label",{className:"aqsp-popover-field",children:[I.jsx("span",{className:"aqsp-popover-field-label",children:be(t,"linkUrlField")}),I.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":h||e.rejected?!0:void 0,onChange:H=>s(H.currentTarget.value),onKeyDown:M})]}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:h||l,"aria-disabled":l?"true":void 0,onClick:L,children:be(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:be(t,"linkOpen")}):null,I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>g(e.close),children:"×"})]})]})},Mo=500,Eu=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),a=i.useMemo(()=>{const Q=n.toLowerCase();return e.current.filter(O=>O.toLowerCase().startsWith(Q))},[e.current,n]),u=i.useMemo(()=>a.length>Mo?a.slice(0,Mo):a,[a]),h=a.length-u.length,g=u.length===0?-1:Math.min(o,u.length-1),L=Q=>{c.current=!0;try{Q()}finally{c.current=!1}},M=()=>{g<0||L(()=>e.commit(u[g]))},$=Q=>{if(Q.key==="Escape"){Q.preventDefault(),L(e.close);return}if(Q.key==="Enter"){Q.preventDefault(),M();return}if(Q.key==="ArrowDown"){Q.preventDefault(),s(g+1);return}Q.key==="ArrowUp"&&(Q.preventDefault(),s(Math.max(g-1,0)))},H=Q=>{c.current||Q.relatedTarget instanceof Node&&Q.currentTarget.contains(Q.relatedTarget)||L(e.close)},Z=Q=>`${l}-${Q}`;return I.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:H,children:[I.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":be(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":g<0?void 0:Z(g),value:n,onChange:Q=>{r(Q.currentTarget.value),s(0)},onKeyDown:$}),I.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":be(t,"listTitle"),children:[u.length===0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:be(t,"listEmpty")}):u.map((Q,O)=>I.jsx("div",{className:"aqsp-popover-option",id:Z(O),role:"option",tabIndex:-1,"aria-selected":O===g,"data-aqsp-list-option":Q,onPointerDown:D=>D.preventDefault(),onClick:()=>L(()=>e.commit(Q)),children:Q},Z(O))),h>0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:be(t,"listMore",h)}):null]})]})},ku=({ctx:e,labels:t})=>I.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),I.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ou=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),a=i.useRef(!1),u=$=>{a.current=!0;try{$()}finally{a.current=!1}},h=()=>{s||u(()=>e.commit(r===""?null:r))},g=()=>{r!==n&&!s?h():u(e.close)},L=$=>{if($.key==="Escape"){$.preventDefault(),e.rejected?u(e.close):g();return}$.key==="Enter"&&($.ctrlKey||$.metaKey)&&!$.altKey&&!$.shiftKey&&($.preventDefault(),h())},M=$=>{a.current||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||e.rejected||g()};return I.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:M,children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:be(t,"noteTitle")}),I.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:$=>o($.currentTarget.value),onKeyDown:L}),I.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:be(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:h,children:be(t,"noteSave")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>u(e.close),children:"×"})]})]})},xu=({ctx:e})=>I.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Jt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),yc=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Au=Object.freeze({all:Jt(yc),values:Jt(["text"]),formats:Jt(["format","borders","cf"]),formulas:Jt(["text","formula"]),noBorders:Jt(yc.filter(e=>e!=="borders")),columnWidths:Jt(["sizes"]),validation:Jt(["validation"]),conditionalFormats:Jt(["cf"]),commentsAndNotes:Jt(["note","comments"])}),bc=Object.freeze({mode:"all"}),Ys=Object.freeze({t:""}),vc=Object.freeze({row:1<<30,col:1<<30}),Bg=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Vg=e=>e.t===""&&e.f===void 0,Wg=e=>e.length>1&&e.startsWith("="),Kg=(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}},Rc=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Yg=(e,t,n,r)=>{const o=Wg(e),s=e===""?"0":Rt(e);if(!o&&s===null)return null;const l=Bg[n];if(t.f!==void 0){const u=Ir(t.f,r),h=u.startsWith("=")?u.slice(1):u;return`=(${o?e.slice(1):s})${l}(${h})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Rc(Number(s));const c=Rt(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${l}(${c})`:Rc(Kg(Number(s),a,n))},Sc=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Xg=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:Sc(e.start),end:Sc(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},Ug=e=>{const t=Ir(e,vc),n=jr(t);let r="",o=0,s=!1;for(const l of n){const c=Xg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${hn(c)}`,o=l.end,s=!0)}return s?qo(`${r}${t.slice(o)}`,vc):e},Gg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Ys;const o=r[n];return o===void 0?Ys:o},Jg=e=>{const{rows:t,cols:n}=e,r=Ta(Ug);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let u=0;u<t;u+=1){const h=Gg(e,u,c);let g=h;if(h.f!==void 0){const L=r(h.f);g=L===h.f?h:{...h,f:L}}(g!==h||h===Ys)&&(o=!1),a.push(g)}s.push(a)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},Zg=(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,Qg=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},Ec=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const u=[];for(const h of c)Zg(h,t)?(u.push(Qg(h,t)),a=!0):u.push(h);a&&(n=!0),r.push(a?u:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},kc=new WeakMap,Tu=e=>{const t=kc.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>Nt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:Nt({...s,borders:void 0})),o={canonical:n,borderless:r};return kc.set(e,o),o},Lo=(e,t)=>t===void 0?void 0:e[t],ew=(e,t,n,r)=>{const o=Tu(e);if(n){const u=Lo(o.canonical,t.fmt);return u===void 0?null:u}const s=Lo(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const a=Nt(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},tw=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Yg(n.readText(),o,r,n):o.f===void 0?o.t:Ir(o.f,n)},Oc=(e,t,n,r,o)=>{const s=Au[r.mode];if(r.skipBlanks===!0&&Vg(e))return null;const l={};let c=!1;if(s.text){const a=tw(e,s.formula&&o.formula,n,r.operation);a!==null&&(l.text=a,c=!0)}if(o.format){if(s.format)l.format=ew(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=Lo(Tu(t).canonical,e.fmt);a!==void 0&&(l.format=a,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const a=Lo(t.validations,e.val);l.validation=a===void 0?null:a,c=!0}return c?l:null},xc=(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}}),nw=["text/html","text/plain"],rw=(e,t,n)=>{if(e===0||t===0)return 0;const r=St(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},ow=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,sw=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,lw=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}}},Ac=e=>{const t=e.clipboardData;return t??null},iw=(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}},cw=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=iw(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},aw=(e,t,n,r,o)=>{const s=dr(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=qo(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(l.fmt=a)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:a,author:u,createdAt:h})=>({text:a,author:u,createdAt:h})))}if(e.getCellHyperlink!==void 0){const c=fr(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},$u=(e,t)=>{const n=ha(),r=op(),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(aw(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:cw(e.getConditionalFormats(),t)}},Tc=e=>e.kind==="cut"?{...e.payload,...$u(e.sourceAdapter,e.range)}:e.payload,uw=e=>({v:1,rows:e.length,cols:e[0].length,clipId:nl(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),dw=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=bn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:a,...u}=l;s.push(u)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},fw=(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},pw=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return me({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},hw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(O=>{const D=n.current;if(D===null||O==="format"||O==="annotate")return;const W=r.current;W==="own"||W==="foreign"&&D.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const O=n.current;if(O===null)return;if(O.kind==="copy"){o();return}const D=t.current;D.repaintOverlay(),D.onClipChange?.({kind:"cut",range:O.range,foreign:O.sourceAdapter!==D.adapter})},[o]),c=i.useCallback((O,D,W)=>{const K=t.current;n.current={kind:O,range:D,clipId:W.clipId,sourceAdapter:K.adapter,payload:W},K.repaintOverlay(),K.onClipChange?.({kind:O,range:D,foreign:!1})},[]),a=i.useCallback(O=>{const D=t.current,W=D.adapter,K=St(O),E={v:1,rows:K.rows,cols:K.cols,clipId:nl(),...$u(W,O),wholeRows:ma(O,W.colCount),wholeCols:ga(O,W.rowCount)};if(D.resize!==void 0){if(E.wholeCols){const P=[];for(let j=O.startCol;j<=O.endCol;j+=1)P.push(Math.min(D.resize.colAxis.sizeOf(j),yn));E.colWidths=P}if(E.wholeRows){const P=[];for(let j=O.startRow;j<=O.endRow;j+=1)P.push(Math.min(D.resize.rowAxis.sizeOf(j),yn));E.rowHeights=P}}return E},[]),u=i.useCallback((O,D)=>{const W=t.current,K=W.getSelection(),E=K.ranges[K.ranges.length-1],P=vt([E]);if(P>W.maxOperationCells)return O.preventDefault(),W.onOperationRejected?.(D,P,"limit"),null;if(D==="cut"&&Mr(W.adapter,E))return O.preventDefault(),W.rejectReadOnly({kind:"operation",op:"cut",cellCount:P}),null;K.ranges.length>1&&W.onCopyMultiRange?.();const j=a(E),m=ra(j),d=Ac(O);return d!==null&&(d.setData("text/plain",nn.serializeClipboardTsv(j.cells.map(y=>y.map(v=>v.t)))),d.setData("text/html",Ya(j,m)),d.setData(xo,m)),O.preventDefault(),{payload:j,range:E}},[a]),h=i.useCallback((O,D)=>t.current.commitPaste(O,D)!==null,[]),g=i.useCallback((O,D,W)=>{const K=t.current;if(!W.sizes||K.resize===void 0)return;const{rowAxis:E,colAxis:P,resizeTracks:j}=K.resize;if(j===void 0)return;const m=(d,y,v)=>{const x=Zs(y,v,null,{maxOperationCells:K.maxOperationCells,rowHiddenLimit:Gs,axisKind:d});if(!x.ok){K.onOperationRejected?.("resize",x.count,x.reason);return}j(d,x.entries)};if(O.colWidths!==void 0){const d=[];for(let y=D.startCol;y<=D.endCol;y+=1)d.push({index:y,size:O.colWidths[(y-D.startCol)%O.cols]});m("col",P,d)}if(O.rowHeights!==void 0){const d=[];for(let y=D.startRow;y<=D.endRow;y+=1)d.push({index:y,size:O.rowHeights[(y-D.startRow)%O.rows]});m("row",E,d)}},[]),L=i.useCallback((O,D)=>{const W=t.current,K=W.adapter,E=O.payload,P={row:D.startRow,col:D.startCol},j=E.rows*E.cols+vt([O.range]);if(j>W.maxOperationCells)return W.onOperationRejected?.("paste",j,"limit"),"rejected";if(P.row+E.rows>K.rowCount||P.col+E.cols>K.colCount||O.range.endRow>=O.sourceAdapter.rowCount||O.range.endCol>=O.sourceAdapter.colCount)return W.onOperationRejected?.("paste",j,"bounds"),"rejected";const m=Bs({rows:E.rows,cols:E.cols},me(P,P),P,K.rowCount,K.colCount);if(m!==null&&Mr(K,m))return W.rejectReadOnly({kind:"operation",op:"paste",cellCount:E.rows*E.cols}),"rejected";if(Mr(O.sourceAdapter,O.range))return W.rejectReadOnly({kind:"operation",op:"cut",cellCount:vt([O.range])}),"rejected";const d=Tc(O),y=ko(K),v=Ec(d,y),x={row:0,col:0,readText:()=>dr(K,x.row,x.col).text,readFormat:()=>K.getCellFormat===void 0?void 0:K.getCellFormat(x.row,x.col)},{edits:S,tiles:V}=Ki(v.cells,me(P,P),P,K.rowCount,K.colCount,(X,w,G)=>(x.row=O.range.startRow+(w-P.row),x.col=O.range.startCol+(G-P.col),Oc(X,v,x,bc,y))),C=ko(O.sourceAdapter),A=[];if(fn([O.range],X=>{A.push(fw(X.row,X.col,C))}),O.sourceAdapter===K){if(!h([...A,...S],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const X=W.commitPaste(S,{sameSheet:!1,conditionalFormats:xc(v.conditionalFormats,V)});if(X===null)return"rejected";try{O.sourceAdapter.applyEdits(A,{transaction:X,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(w){W.onEditRejected?.(w,{source:"paste"})}}return W.setSelection({ranges:[me(P,{row:P.row+d.rows-1,col:P.col+d.cols-1})],anchor:P,active:P}),"applied"},[h]),M=i.useCallback((O,D,W)=>{const K=t.current,E=K.adapter,P=_=>(K.onClipboardUnavailable?.(_),"rejected"),j=la(O,D);if(j==="none")return D==="menu"?P("empty"):"empty";const m=K.getSelection(),d=m.ranges[m.ranges.length-1],y=W.transpose===!0,v=(_,Y)=>{const U=rw(y?Y:_,y?_:Y,d);return U>K.maxOperationCells?(K.onOperationRejected?.("paste",U,"limit"),!0):!1};let x,S=null;if(j==="aqsp"){const _=Mf(O,D);if(_===null)return P("unreadable");const Y=n.current;if(Y!==null&&_.clipId===Y.clipId&&(S=Y),S!==null&&S.kind==="cut"&&ow(W))return L(S,d);if(v(_.rows,_.cols))return"rejected";if(S!==null){if(S.kind==="cut"&&(S.range.endRow>=S.sourceAdapter.rowCount||S.range.endCol>=S.sourceAdapter.colCount))return K.onOperationRejected?.("paste",S.payload.rows*S.payload.cols,"bounds"),"rejected";x=Tc(S)}else{const U=Lf(O,D);if(U===null)return P("unreadable");if(v(U.rows,U.cols))return"rejected";x=dw(U)}}else if(j==="tsv"){const _=O.getData("text/plain"),Y=nn.measureTsv(_);if(v(Y.rows,Y.cols))return"rejected";x=uw(nn.parseTsv(_))}else{const _=O.getData("text/html"),Y=rp(_);if(Y.cols===0&&Y.rows>K.maxOperationCells)return K.onOperationRejected?.("paste",Y.rows,"limit"),"rejected";if(v(Y.rows,Y.cols))return"rejected";const U=Ja(_,j,K.formats===void 0?{}:{currency:K.formats.currency,locale:K.formats.locale},K.maxOperationCells);if(U.outcome==="none")return P("unreadable");if(U.outcome==="limit")return K.onOperationRejected?.("paste",U.cells,"limit"),"rejected";if(v(U.payload.rows,U.payload.cols))return"rejected";x=U.payload}const V=ko(E),C=Ec(y?Jg(x):x,V),A=Au[W.mode];if(sw(A)){const _=Bs({rows:C.rows,cols:C.cols},d,m.active,E.rowCount,E.colCount);if(_!==null&&Mr(E,_))return K.rejectReadOnly({kind:"operation",op:"paste",cellCount:vt([_])}),"rejected"}const X={row:0,col:0,readText:()=>dr(E,X.row,X.col).text,readFormat:()=>E.getCellFormat===void 0?void 0:E.getCellFormat(X.row,X.col)},{edits:w,tiles:G}=Ki(C.cells,d,m.active,E.rowCount,E.colCount,(_,Y,U)=>(X.row=Y,X.col=U,Oc(_,C,X,W,V))),te=pw(G,C.rows,C.cols,E.rowCount,E.colCount);if(te===null)return"empty";if(A.cf&&C.conditionalFormats.length>0){let _=0;for(const U of C.conditionalFormats)_+=U.ranges.length;const Y=G.length*_;if(Y>K.maxOperationCells)return K.onOperationRejected?.("paste",Y,"limit"),"rejected"}const f=A.cf?xc(C.conditionalFormats,G):[];if(w.length===0&&f.length===0)return g(C,te,A),"empty";r.current=S===null?"foreign":"own";let b=!1;try{b=h(w,{sameSheet:S!==null&&S.sourceAdapter===E,conditionalFormats:f})}finally{r.current="none"}if(!b)return"rejected";g(C,te,A);const R={row:te.startRow,col:te.startCol};return K.setSelection({ranges:[te],anchor:R,active:R}),"applied"},[L,h,g]),$=i.useCallback(async O=>{const D=y=>(t.current.onClipboardUnavailable?.(y),"rejected"),W=navigator;if(W.clipboard===void 0)return D("insecure-origin");let K;try{K=await W.clipboard.read({unsanitized:["text/html"]})}catch{return D("permission-denied")}if(K.length===0)return D("empty");const E=K[0],P=Array.from(E.types),j=new Map;try{for(const y of nw)P.includes(y)&&j.set(y,await(await E.getType(y)).text())}catch{return D("unreadable")}const m={types:P,getData:y=>{const v=j.get(y);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${y} was not materialised for the menu path`);return v}},d=t.current;return!d.enabled||d.isDragging()||d.isEditing()?"rejected":M(m,"menu",O)},[M]),H=i.useCallback(async O=>{const D=await $(O);return t.current.onPasteResolved?.(D,"menu"),D},[$]),{enabled:Z,sinkRef:Q}=e;return i.useEffect(()=>{const O=Q.current;if(!Z||O===null)return;const D=P=>t.current.isDragging()?(P.preventDefault(),!0):!1,W=P=>{const j=t.current;if(D(P)||j.isEditing())return;const m=u(P,"copy");m!==null&&c("copy",m.range,m.payload)},K=P=>{const j=t.current;if(D(P)||j.isEditing())return;const m=u(P,"cut");m!==null&&c("cut",m.range,m.payload)},E=P=>{const j=t.current;if(D(P)||j.isEditing())return;P.preventDefault();let m=bc;const d=j.pendingPasteOptionsRef;d!==void 0&&d.current!==null&&(m=d.current,d.current=null);const y=Ac(P);if(y===null)return;const v=M(lw(y),"event",m);j.onPasteResolved?.(v,"event")};return O.addEventListener("copy",W),O.addEventListener("cut",K),O.addEventListener("paste",E),()=>{O.removeEventListener("copy",W),O.removeEventListener("cut",K),O.removeEventListener("paste",E)}},[Z,Q,u,c,M]),i.useMemo(()=>({getClip:()=>{const O=n.current;return O===null?null:{kind:O.kind,range:O.range,foreign:O.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:H}),[o,s,l,H])},Mu=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)}`)},Lu=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}},$c=(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}`}`},zu=(e,t)=>{let n;if(e.exponent===null)n=$c(e.negative,e.digits,e.point+t);else{const r=$c(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Rt(n)===null?null:n},mw=(e,t)=>{Mu(t);const n=Rt(e);return n===null?null:zu(Lu(n),t)},gw=e=>{const t=Rt(e);if(t!==null){const r=Lu(t);return zu({...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)},ww=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},Du=(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 ww(r)?r:null},Cw=(e,t)=>{Mu(t);const n=Nu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Du(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},yw=e=>{const t=Nu(e),n=Du(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},xr=(e,t,n,r)=>{const o=vt(t);return o>n?(r?.(e,o,"limit"),!1):!0},ho={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},mo={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Mc={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:ho.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:ho.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:ho.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:ho.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:mo.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:mo.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:mo.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:mo.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"}},bw={down:"fillDown",right:"fillRight",selection:"fillSelection"},vw={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},Fr=e=>e<10?`0${e}`:String(e),Rw=e=>{const t=new Date(e);return`${t.getFullYear()}-${Fr(t.getMonth()+1)}-${Fr(t.getDate())}`},Sw=e=>{const t=new Date(e);return`${Fr(t.getHours())}:${Fr(t.getMinutes())}:${Fr(t.getSeconds())}`},Ew=(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),kw=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Ow=e=>e===void 0||e.borders===void 0?{}:e.borders,xw={top:1,right:2,bottom:4,left:8},Aw={style:"thin",color:Qs},Tw=(e,t)=>{if(e===void 0)return!1;const n=lt(e);return n!==null&&n===lt(t)},$w=(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}}},Mw=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const m=t.current;if(m.isEditing()){const d=m.getActive();return[me(d,d)]}return m.getSelection().ranges},[]),r=i.useCallback(()=>{const m=t.current,d=m.getActive();return m.adapter.getCellFormat===void 0?void 0:m.adapter.getCellFormat(d.row,d.col)},[]),o=i.useCallback(m=>{const d=t.current,y=n();if(!xr("format",y,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y))return d.rejectReadOnly({kind:"operation",op:"format",cellCount:vt(y)}),!1;const v=new Map,x=[],S=d.adapter.getCellFormat;for(const V of y)fn([V],C=>{const A=S===void 0?void 0:S(C.row,C.col),{bucket:X,patch:w}=m(C,V,A);let G=v.get(X);G===void 0&&(G=new Map,v.set(X,G));let te;G.has(A)?te=G.get(A):(te=tl(A,w),G.set(A,te)),te!==A&&x.push({row:C.row,col:C.col,format:te===void 0?null:te})});return x.length===0?!0:d.commitEdits(x,{source:"format"})===null?!1:(d.isEditing()&&d.refreshEditPaint(),!0)},[n]),s=i.useCallback(m=>o(()=>({bucket:0,patch:m})),[o]),l=i.useCallback((m,d)=>{const y=t.current;y.formatCommandAnnouncement!==void 0&&y.announce(y.formatCommandAnnouncement({command:m,state:d}))},[]),c=i.useCallback((m,d=Aw)=>{if(m==="clear")return s({borders:null});if(m==="all")return s({borders:{top:d,right:d,bottom:d,left:d}});const y=m==="outer"?15:xw[m];return o((v,x,S)=>{const V=Ew(v,x)&y;return{bucket:V,patch:{borders:{...Ow(S),...kw(V,d)}}}})},[s,o]),a=i.useCallback((m,d,y)=>{const v=nu(t.current.adapter,m.row,m.col);for(const x of d)y.push(ru(v,m,x))},[]),u=i.useCallback(m=>{const d=t.current,y=d.getSelection();if(!xr("fill",y.ranges,d.maxOperationCells,d.onOperationRejected))return!1;const v=[],x=[],S=[];if(m==="selection"){const C=y.active,A=[];fn(y.ranges,X=>{(X.row!==C.row||X.col!==C.col)&&A.push(X)}),v.push({source:C,targets:A}),x.push(me(C,C));for(const X of y.ranges)S.push(...gm(X,C))}else for(const C of y.ranges)if(m==="down"){const A=C.startRow===C.endRow;if(A&&C.startRow===0)continue;const X=A?C.startRow-1:C.startRow,w=A?C.startRow:C.startRow+1;x.push(me({row:X,col:C.startCol},{row:X,col:C.endCol})),S.push(me({row:w,col:C.startCol},{row:C.endRow,col:C.endCol}));for(let G=C.startCol;G<=C.endCol;G+=1){const te=[];for(let f=w;f<=C.endRow;f+=1)te.push({row:f,col:G});v.push({source:{row:X,col:G},targets:te})}}else{const A=C.startCol===C.endCol;if(A&&C.startCol===0)continue;const X=A?C.startCol-1:C.startCol,w=A?C.startCol:C.startCol+1;x.push(me({row:C.startRow,col:X},{row:C.endRow,col:X})),S.push(me({row:C.startRow,col:w},{row:C.endRow,col:C.endCol}));for(let G=C.startRow;G<=C.endRow;G+=1){const te=[];for(let f=w;f<=C.endCol;f+=1)te.push({row:G,col:f});v.push({source:{row:G,col:X},targets:te})}}for(const C of v)for(const A of C.targets)if(nt(d.adapter,A.row,A.col))return d.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(S),gesture:bw[m],sources:x,targets:S}),!1;const V=[];for(const C of v)a(C.source,C.targets,V);return V.length===0?!0:d.commitEdits(V,{source:"fill"})!==null},[a]),h=i.useCallback(()=>{const m=t.current,d=m.getSessionText();if(d===null)return!1;const y=m.getSelection();if(!xr("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(nr(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(y.ranges),gesture:"fillSelection",sources:[],targets:y.ranges}),!1;const v=[];let x=!1;return fn(y.ranges,S=>{if(!x){if(!m.validateCommit(S,d).ok){x=!0;return}v.push({row:S.row,col:S.col,text:d})}}),x||m.commitEdits(v,{source:"fill"})===null?!1:(m.cancelEdit(),!0)},[]),g=i.useCallback(m=>{const d=t.current,y=d.getSelection();if(!xr("calc",y.ranges,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y.ranges))return d.rejectReadOnly({kind:"operation",op:"calc",cellCount:vt(y.ranges)}),!1;const v=[],x=d.adapter;return fn(y.ranges,S=>{const V=x.getCellFormula===void 0?void 0:x.getCellFormula(S.row,S.col),C=V===void 0?m.text(x.getCellText(S.row,S.col)):m.formula(V);C!==null&&v.push({row:S.row,col:S.col,text:C})}),v.length===0?!0:d.commitEdits(v,{source:"calc"})!==null},[]),L=i.useCallback((m,d)=>{const y=t.current,v=y.resizeTracks;if(v===void 0)return!1;const x=m==="row"?y.rowAxis:y.colAxis,S=y.getSelection(),V=m==="row"?Math.floor(y.maxOperationCells/Js):y.maxOperationCells;let C=0;for(const te of S.ranges)C+=m==="row"?te.endRow-te.startRow+1:te.endCol-te.startCol+1;if(C>V)return y.onOperationRejected?.("resize",C,"limit"),!1;const A=new Set,X=[],w=d?0:m==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const te of S.ranges){const f=m==="row"?te.startRow:te.startCol,b=m==="row"?te.endRow:te.endCol;for(let R=f;R<=b;R+=1){if(A.has(R))continue;A.add(R),x.sizeOf(R)===0!==d&&X.push({index:R,size:w})}}const G=Zs(x,X,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:Gs,axisKind:m});return G.ok?(G.entries.length>0&&v(m,G.entries),!0):(y.onOperationRejected?.("resize",G.count,G.reason),!1)},[]),M=i.useCallback(()=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)return;const d=m.getActive();return fr(m.adapter.getCellHyperlink(d.row,d.col))},[]),$=i.useCallback(m=>{const d=t.current,y=d.adapter,v=Mc[m],x=y.getCellFormat!==void 0,S=V=>d.popovers===void 0?!0:d.popovers[V]!==!1;if(v.kind==="popover"&&v.popover==="list"&&d.columnMenu?.isColumnMenuCell(d.getActive())===!0)return!0;switch(v.kind){case"resize":return d.trackResize!==void 0;case"hide":return d.resizeTracks!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return x;case"value":return x&&(v.value!=="currency"||d.formats!==void 0);case"popover":switch(v.popover){case"link":return y.getCellHyperlink!==void 0&&S("link");case"note":return y.getCellNote!==void 0&&S("note");case"comment":return y.getCellComments!==void 0&&S("comment");default:return y.getCellValidation!==void 0&&S("list")}case"openHyperlink":return y.getCellHyperlink!==void 0&&(d.onHyperlinkOpen!==void 0?M()!==void 0:S("link"));case"paste":return v.options.mode==="formats"?x:v.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[M]),H=i.useCallback(m=>{const d=t.current,y=m.kind==="popover"?m.popover:m.kind==="openHyperlink"&&d.onHyperlinkOpen===void 0?"link":void 0;if(y===void 0)return!0;const v=d.getActive();if(!nt(d.adapter,v.row,v.col))return!0;if(y==="list")return d.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let x;if(y==="link")x=M()!==void 0;else if(y==="note"){const S=d.adapter.getCellNote===void 0?void 0:d.adapter.getCellNote(v.row,v.col);x=S!==void 0&&S!==""}else{const S=d.adapter.getCellComments===void 0?void 0:d.adapter.getCellComments(v.row,v.col);x=S!==void 0&&S.length>0}return x?!0:(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[M]),Z=i.useCallback((m,d,y)=>{const v=t.current,x=v.trackResize;if(x===void 0)return!1;const S=v.getActive(),V=d==="col"?S.col:S.row,C=y==="fit"?x.autofitColumn(V):x.stepTrack(d,V,y),A=(d==="col"?v.colAxis:v.rowAxis).sizeOf(V);return C&&A>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:m,axis:d==="col"?"column":"row",index:V,size:A})),C},[]),Q=i.useCallback(m=>{const d=t.current;if(!$(m))return!1;const y=Mc[m];if(y.kind==="popover"&&y.popover==="list"&&d.columnMenu!==void 0){const x=d.getActive();if(d.columnMenu.isColumnMenuCell(x))return d.columnMenu.open(x)}if(!H(y))return!1;const v=d.isEditing();if(v&&!$o.has(m)&&!d.requestCommit())return!1;switch(y.kind){case"toggle":{const x=r(),S=x!==void 0&&x[y.key]===!0;return s({[y.key]:S?null:!0})?(l(m,!S),!0):!1}case"patch":return s(y.patch)?(l(m,null),!0):!1;case"clear":return s(vw)?(l(m,null),!0):!1;case"value":return s({value:$w(y.value,d.formats)})?(l(m,null),!0):!1;case"borders":return c(y.preset)?(l(m,null),!0):!1;case"color":{const x=y.key==="background"?d.colors.fill:d.colors.font,S=y.preset!==null?y.preset:y.custom!==null&&y.custom<x.length?x[y.custom]:void 0;if(S===void 0)return!1;const V=r(),C=Tw(V===void 0?void 0:V[y.key],S);return s({[y.key]:C?null:S})?(l(m,!C),!0):!1}case"calc":return g({text:x=>mw(x,y.exponent),formula:x=>Cw(x,y.exponent)});case"sign":return g({text:gw,formula:yw});case"fill":return v&&y.direction==="selection"?h():u(y.direction);case"popover":return d.openPopover(y.popover),!0;case"openHyperlink":{if(d.onHyperlinkOpen!==void 0){const x=M();return x===void 0?!1:(d.onHyperlinkOpen(x,d.getActive()),!0)}return d.openPopover("link"),!0}case"pasteSpecial":return d.onPasteSpecialRequest!==void 0?(d.onPasteSpecialRequest({kind:"keyboard",cellRect:d.keyboardCellRect()}),!0):(d.paste({mode:"formats"}),!0);case"paste":return d.paste(y.options),!0;case"insertNow":{const x=y.unit==="date"?Rw(d.now()):Sw(d.now());if(v)return d.insertAtCaret(x),!0;const S=d.getActive();return nt(d.adapter,S.row,S.col)?(d.rejectReadOnly({kind:"edit",cell:S,editSession:"none"}),!1):d.validateCommit(S,x).ok?d.commitEdits([{row:S.row,col:S.col,text:x}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return L(y.axis,y.hide);case"resize":return Z(m,y.axis,y.step);default:{const x=d.getHighlight();switch(y.target){case"row":return d.setHighlight({...x,row:!x.row}),!0;case"column":return d.setHighlight({...x,column:!x.column}),!0;case"both":{const S=x.row&&x.column;return d.setHighlight({...x,row:!S,column:!S}),!0}default:return d.setHighlight({...x,intersection:!x.intersection}),!0}}}},[$,H,M,r,s,l,c,g,u,h,L,Z]),O=i.useCallback(()=>{const m=t.current;return!(m.isEditing()&&!m.requestCommit())},[]),D=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const y=m===null?null:bn(m);if(m!==null&&y===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(m)}`);if(!O())return!1;const v=d.getActive();return nt(d.adapter,v.row,v.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:v.row,col:v.col,hyperlink:y}],{source:"annotate"})!==null},[O]),W=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!O())return!1;const y=d.getActive();return nt(d.adapter,y.row,y.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:y.row,col:y.col,note:m}],{source:"annotate"})!==null},[O]),K=i.useCallback(m=>{const d=t.current,y=d.adapter.getCellComments;if(y===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!O())return!1;const v=d.getActive();if(nt(d.adapter,v.row,v.col))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const x=y(v.row,v.col),S=x===void 0?[m]:[...x,m];return d.commitEdits([{row:v.row,col:v.col,comments:S}],{source:"annotate"})!==null},[O]),E=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!O())return!1;const y=d.getSelection().ranges;if(!xr("annotate",y,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:vt(y)}),!1;const v=[];return fn(y,x=>{v.push({row:x.row,col:x.col,validation:m})}),d.commitEdits(v,{source:"annotate"})!==null},[O]),P=i.useCallback(m=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(m)},[s]),j=i.useCallback((m,d)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(m,d)},[c]);return i.useMemo(()=>({executeCommand:Q,applyFormat:P,setBorders:j,setHyperlink:D,setNote:W,addComment:K,setValidation:E,isCommandAvailable:$}),[Q,P,j,D,W,K,E,$])},go="data-aqsp-pointing",Lw=(e,t)=>{const n=Na(e,t);return n!==null&&"insertAt"in n},zw=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Nw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(null),u=i.useRef(Qt),h=i.useCallback(()=>{const C=t.current,A=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||!c.current||A===null)return null;const X=Na(A.value,A.selectionStart);return X===null?null:{sink:A,target:X}},[]),g=i.useCallback(()=>{const C=t.current.sinkRef.current;if(C===null)return;const A=h()!==null;A!==C.hasAttribute(go)&&(A?C.setAttribute(go,""):C.removeAttribute(go))},[h]),L=i.useCallback((C,A)=>{const X=t.current;if(X.resolveEditPaint===void 0)return;const w=X.resolveEditPaint(A),G=w===null?Qt:w;G!==Qt&&Object.assign(C.style,G.style),u.current=G,X.editPaintRef!==void 0&&(X.editPaintRef.current=G)},[]),M=i.useCallback(C=>{zw(C,Object.keys(u.current.style)),u.current=Qt;const A=t.current.editPaintRef;A!==void 0&&(A.current=Qt)},[]),$=i.useCallback(C=>{const A=t.current,X=n.current;if(X===null)return!0;const w=()=>{n.current=null,a.current=null;const G=A.sinkRef.current;G!==null&&(G.style.removeProperty("text-align"),M(G),G.removeAttribute(go)),o(!1),A.onSessionChange?.(null)};if(C.commit){const G=A.sinkRef.current,te=G===null?"":G.value,f=dr(A.adapter,X.cell.row,X.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
-
`),b=te===f;let R;if(b)R=!0;else if(nt(A.adapter,X.cell.row,X.cell.col))A.rejectReadOnly({kind:"edit",cell:X.cell,editSession:C.onReject==="keep"?"kept":"discarded"}),R=!1;else{const _={source:"edit",editSession:C.onReject==="keep"?"kept":"discarded"};R=(A.validateCommit===void 0||A.validateCommit(X.cell,te).ok)&&A.commitEdits([{row:X.cell.row,col:X.cell.col,text:te}],_)!==null}if(!R)return C.onReject==="discard"&&(w(),A.rearmSink()),!1}return w(),C.rearm&&A.rearmSink(),!0},[M]),H=i.useCallback((C,A)=>{const X=t.current;if(X.isDragging()||n.current!==null)return;const w=X.sinkRef.current;if(w===null)return;const G=X.getActive();if(nt(X.adapter,G.row,G.col)){X.rejectReadOnly({kind:"edit",cell:G,editSession:"none"});return}if(X.discardClip(),X.ensureCellVisible(G),C==="edit"){const{text:b,isFormula:R}=dr(X.adapter,G.row,G.col);w.value=b;const _=A===void 0||R?b.length:Math.min(A,b.length);w.setSelectionRange(_,_)}else w.value="";const te=X.resolveEditAlign(G);te!==null&&(w.style.textAlign=te),L(w,G),c.current=!1,a.current=null;const f={cell:G,mode:C};n.current=f,o(!0),X.onSessionChange?.(f)},[L]),Z=i.useCallback(()=>{$({rearm:!0,commit:!1})},[$]),Q=i.useCallback(()=>{const C=t.current;if(n.current===null)return!0;const A=C.sinkRef.current;if(s.current&&A!==null){l.current=!0;try{A.blur()}finally{l.current=!1}return $({rearm:!1,commit:!0,onReject:"keep"})?(C.focusSink(),C.rearmSink(),!0):(C.focusSink(),!1)}return $({rearm:!0,commit:!0,onReject:"keep"})},[$]),O=i.useCallback(()=>h()!==null,[h]),D=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,g(),!0),[g]),W=i.useCallback(()=>{const C=h(),A=n.current;if(C===null||A===null)return null;if("insertAt"in C.target)return a.current=A.cell,{origin:A.cell,cursor:A.cell,axis:"cells"};const X=za(C.sink.value,C.sink.selectionStart);if(X===null)return null;const w=X.token,G=a.current;switch(w.kind){case"cell":{const te={row:w.row,col:w.col};return a.current=te,{origin:te,cursor:te,axis:"cells"}}case"range":{const te=G!==null&&(G.row===w.start.row||G.row===w.end.row)&&(G.col===w.start.col||G.col===w.end.col)?{row:G.row,col:G.col}:{row:w.start.row,col:w.start.col};return a.current=te,{origin:te,cursor:{row:te.row===w.start.row?w.end.row:w.start.row,col:te.col===w.start.col?w.end.col:w.start.col},axis:"cells"}}case"column":{const te=G!==null&&(G.col===w.start.col||G.col===w.end.col)?G.col:w.start.col,f={row:A.cell.row,col:te};return a.current=f,{origin:f,cursor:{row:A.cell.row,col:te===w.start.col?w.end.col:w.start.col},axis:"columns"}}case"row":{const te=G!==null&&(G.row===w.start.row||G.row===w.end.row)?G.row:w.start.row,f={row:te,col:A.cell.col};return a.current=f,{origin:f,cursor:{row:te===w.start.row?w.end.row:w.start.row,col:A.cell.col},axis:"rows"}}}},[h]),K=i.useCallback((C,A)=>{const X=h();if(X===null)return;const w=qp(C,A),{sink:G}=X,[te,f]="replace"in X.target?X.target.replace:[X.target.insertAt,X.target.insertAt],b=G.value;G.value=`${b.slice(0,te)}${w}${b.slice(f)}`;const R=te+w.length;G.setSelectionRange(R,R),"row"in C&&(a.current={row:C.row,col:C.col}),g()},[h,g]),E=i.useCallback(()=>{const C=t.current.sinkRef.current;return C===null?null:{value:C.value,selectionStart:C.selectionStart,selectionEnd:C.selectionEnd}},[]),P=i.useCallback(C=>{const A=t.current.sinkRef.current;A!==null&&(A.value=C.value,A.setSelectionRange(C.selectionStart,C.selectionEnd),a.current=null,g())},[g]),j=i.useCallback(()=>{const C=t.current,A=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||A===null)return!1;const X=Yp(A.value,A.selectionStart);return X===null?!1:(A.value=X.text,A.setSelectionRange(X.caret,X.caret),g(),!0)},[g]),m=i.useCallback(C=>{const A=t.current.sinkRef.current;if(n.current===null||A===null)return;const X=A.selectionStart,w=A.selectionEnd;A.value=`${A.value.slice(0,X)}${C}${A.value.slice(w)}`;const G=X+C.length;A.setSelectionRange(G,G),a.current=null,g()},[g]),d=i.useCallback(()=>{const C=t.current.sinkRef.current;return n.current===null||C===null?null:C.value},[]),y=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>n.current,[]),x=i.useCallback(()=>{const C=t.current,A=n.current,X=C.sinkRef.current;A===null||X===null||(M(X),L(X,A.cell),C.repaintOverlay?.())},[M,L]),{enabled:S,sinkRef:V}=e;return i.useEffect(()=>{const C=V.current;if(!S||C===null)return;const A=()=>{s.current=!0},X=()=>{s.current=!1},w=f=>{const b=t.current;if(l.current||n.current===null)return;const R=b.rootRef.current,_=f.relatedTarget;R!==null&&_ instanceof Node&&R.contains(_)||$({rearm:!1,commit:!0,onReject:"discard"})},G=()=>{const f=t.current;a.current=null,f.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Lw(C.value,C.selectionStart)&&(c.current=!0),g()},te=()=>{n.current!==null&&g()};return C.addEventListener("compositionstart",A),C.addEventListener("compositionend",X),C.addEventListener("focusout",w),C.addEventListener("input",G),document.addEventListener("selectionchange",te),()=>{C.removeEventListener("compositionstart",A),C.removeEventListener("compositionend",X),C.removeEventListener("focusout",w),C.removeEventListener("input",G),document.removeEventListener("selectionchange",te)}},[S,V,$,g]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Q,cancelEdit:Z,startEdit:H,getPointing:O,togglePointingArm:D,getReferenceCursor:W,insertReference:K,captureSink:E,restoreSink:P,cycleAnchorAtCaret:j,insertAtCaret:m,getSessionText:d,getSessionCell:y,getSession:v,refreshPaint:x,editing:r}),[Q,Z,H,O,D,W,K,E,P,j,m,d,y,v,x,r])},Dw=(e,t,n)=>{const r=new rt.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},Fw=(e,t,n)=>{const{tree:r,initialHidden:o}=Dw(e,t,n);let s=o;const a={count:e,sizeOf:u=>r.get(u),offsetOf:u=>{const{cumulative:h,currentValue:g}=r.prefixSum(u);return h-g},indexAt:u=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const h=Math.floor(u),g=Math.min(Math.max(h,0),r.getTotal()-1);return r.findIndexAtOrAfter(g+.5).index},totalSize:()=>r.getTotal(),resize:(u,h)=>{if(!(Number.isFinite(h)&&h>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${h}`);const g=Math.round(h);r.get(u)===0!=(g===0)&&(s+=g===0?1:-1),r.update(u,g)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},wn=(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)},lr=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:wn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=wn(e,o,1);return r},Lc=(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=Fw(e,t,r)),o.current.model},ir=256,Ss=256,qw=2**32,Pw=4096,Fu=Object.freeze([]),qu=["background","color","bold","italic","underline","strikethrough"],Pu=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Cn=(e,t,n)=>(e.size>=Pw&&e.clear(),e.set(t,n),n),_u=e=>(Pu(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),ju=(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},_w=(e,t,n)=>{const r=Math.floor(t/ir),o=Math.floor(n/Ss),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*ir,a=o*Ss,u=[];for(const h of e.rules)ju(h.ranges,c,c+ir-1,a,a+Ss-1)&&u.push(h);return Cn(e.buckets,s,u.length===0?Fu:u)},jw=(e,t,n)=>{const r=Math.floor(t/ir),o=r*qw+n,s=e.columns.get(o);if(s!==void 0)return s;const l=_w(e,t,n),c=r*ir,a=[];for(const u of l)ju(u.ranges,c,c+ir-1,n,n)&&a.push(u);return Cn(e.columns,o,a.length===0?Fu:a)},Iw=(e,t)=>{for(const n of e)if(Vt(n,t))return!0;return!1},hl=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),wo=(e,t)=>e<t?-1:e>t?1:0,zc=(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}},Nc=new WeakMap,Xs=e=>e===null?null:Number(e),Hw=e=>{const t=Nc.get(e);if(t!==void 0)return t;const n=e.b,r={a:Xs(Rt(e.a)),b:n===void 0?null:Xs(Rt(n))};return Nc.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:Cn(e.numbers,r,Xs(Rt(n())))},Bw=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Hw(e),l=Iu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return zc(e.op,wo(l,s.a),c===null?null:wo(l,c));const a=n(),u=e.b;return zc(e.op,wo(a,e.a),u===void 0?null:wo(a,u))},Vw=(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}},Es=e=>{const t=lt(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]},Co=e=>e.toString(16).padStart(2,"0"),ks=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Co(r(0))}${Co(r(1))}${Co(r(2))}`,s=r(3);return s===255?o:`${o}${Co(s)}`},Os=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Ww=(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=Es(t.color),a=Es(r.color);const u=n===void 0?void 0:Es(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||a===null||u===null)return null;if(s>l){const g=s;s=l,l=g;const L=c;c=a,a=L}if(n!==void 0&&u!==void 0){const g=n.value===void 0?(s+l)/2:n.value;if(s<g&&g<l)return e<=g?ks(c,u,Os(e,s,g)):ks(u,a,Os(e,g,l))}return ks(c,a,Os(e,s,l))},Kw=(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 Cn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const u of e.ranges){const h=n.getRangeExtrema(u);if(h===null)return Cn(r.extrema,e.id,null);c=Math.min(c,h.min),a=Math.max(a,h.max)}return Cn(r.extrema,e.id,{min:c,max:a})},Yw=(e,t,n,r,o,s)=>{const l=Iu(s,n,r);if(l===null)return null;const c=Kw(e,t,o,s);return c===null?null:Ww(l,t.min,t.mid,t.max,c)},Xw=(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:Cn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Uw=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Bw(s,t,n,o)?e.style:null;case"text":return Vw(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Yw(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Xw(e,s,t,r,o)?e.style:null;default:return null}},Dc=(e,t)=>tl(e,t),Gw=(e,t,n)=>{e[t]=n},Jw=(e,t)=>{let n=e;for(const r of qu)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Gw(n,r,t[r]));return n},Zw=e=>{let t="";for(const n of qu){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Fc=new WeakMap,Qw=Object.freeze({}),e0=e=>{const t=e===void 0?Qw:e,n=Fc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Fc.set(t,r),r},t0=(e,t,n)=>{const r=e0(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=Dc(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=Zw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Dc(e,t);return l!==void 0&&Cn(r.byKey,o,l),l},ml=(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=jw(t,r,o);if(c.length===0)return l;const a={row:r,col:o};let u=null,h=!0;for(const g of c){if(!Iw(g.ranges,a))continue;const L=Uw(g,a,s,e,n);if(L!==null){if(L!==g.style&&(h=!1),u===null)u=L;else{const M=Jw(u,L);M!==u&&(h=!1,u=M)}if(g.stopIfTrue===!0)break}}return u===null?l:t0(l,u,h)},qc=new WeakMap,n0=e=>{Pu(e,"widthRelevantRules");const t=qc.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 qc.set(e,r),r},r0=(e,t,n,r)=>{const o=e.trim()===""?t:`${e} ${t}`;return r?`${o} (${n})`:o},o0=({col:e,direction:t,filtered:n,expanded:r,columnName:o,menuLabel:s,filteredLabel:l,onToggle:c})=>{const a=i.useRef(null);return i.useEffect(()=>{const u=a.current;if(u===null)return;const h=L=>{L.stopPropagation(),L.preventDefault()},g=L=>{L.stopPropagation()};return u.addEventListener("pointerdown",h),u.addEventListener("dblclick",g),u.addEventListener("contextmenu",g),()=>{u.removeEventListener("pointerdown",h),u.removeEventListener("dblclick",g),u.removeEventListener("contextmenu",g)}},[]),I.jsxs("button",{ref:a,type:"button",className:"aqsp-column-menu-button","data-aqsp-column-menu-button":"",tabIndex:-1,"aria-haspopup":"dialog","aria-expanded":r,"aria-label":r0(o,s,l,n),onClick:()=>c(e),children:[t===null?null:I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":t,viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:t==="asc"?"M5 1.5 9 8.5H1Z":"M5 8.5 1 1.5h8Z",fill:"currentColor"})}),n?I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"filter",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:"M.5 1h9L6 5.25V9.5L4 8.25v-3Z",fill:"currentColor"})}):I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"menu",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:"M1.5 3.25 5 6.75l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]})},s0=i.memo(o0),l0=Object.freeze({state:!0,onStateChange:!0,getColumnKey:!0,defaults:!0,getColumnOptions:!0,getFilterValues:!0}),Pc=Object.freeze({sortable:!0,filterable:!0,matchModes:!0,defaultMatchMode:!0}),i0=Object.freeze({sort:!0,filters:!0}),c0=Object.freeze({columnKey:!0,direction:!0}),a0=Object.freeze({value:!0,label:!0,count:!0}),Hu=Object.freeze(["exact","fuzzy"]),u0=Object.freeze(["asc","desc"]),_e=e=>typeof e=="string"?JSON.stringify(e):e==null||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):Array.isArray(e)?"an array":typeof e=="function"?"a function":typeof e=="symbol"?"a symbol":"an object",mn=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},gn=(e,t,n)=>{for(const r of Object.keys(e))if(!Object.hasOwn(t,r))throw new RangeError(`[spreadsheet] ${n} has an unknown member ${JSON.stringify(r)}; expected ${Object.keys(t).join(", ")}`)},_c=(e,t)=>{const{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}=e;if(typeof n!="boolean")throw new RangeError(`[spreadsheet] ${t}.sortable must be true or false (got ${_e(n)})`);if(typeof r!="boolean")throw new RangeError(`[spreadsheet] ${t}.filterable must be true or false (got ${_e(r)})`);if(!Array.isArray(o))throw new RangeError(`[spreadsheet] ${t}.matchModes must be an array of "exact" / "fuzzy" (got ${_e(o)})`);if(o.length===0)throw new RangeError(`[spreadsheet] ${t}.matchModes must not be empty`);const l=new Set;for(const c of o){if(!Hu.includes(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds an unknown match mode ${_e(c)}; expected "exact" or "fuzzy"`);if(l.has(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds ${JSON.stringify(c)} twice`);l.add(c)}if(!l.has(s))throw new RangeError(`[spreadsheet] ${t}.defaultMatchMode ${_e(s)} is not one of ${t}.matchModes (${[...l].map(c=>JSON.stringify(c)).join(", ")})`);return{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}},d0=(e,t)=>{if(!mn(e))throw new RangeError(`[spreadsheet] sortFilter.state must be an object with sort and filters (got ${_e(e)})`);gn(e,i0,"sortFilter.state");const n=(c,a)=>{const u=t.get(c);if(u===void 0)throw new RangeError(`[spreadsheet] ${a} names ${JSON.stringify(c)}, which is not the key of any column`);return u},r=e.sort;let o=null;if(r!==null){if(!mn(r))throw new RangeError(`[spreadsheet] sortFilter.state.sort must be null or { columnKey, direction } (got ${_e(r)})`);gn(r,c0,"sortFilter.state.sort");const{columnKey:c,direction:a}=r;if(typeof c!="string")throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey must be a string (got ${_e(c)})`);if(!u0.includes(a))throw new RangeError(`[spreadsheet] sortFilter.state.sort.direction must be "asc" or "desc" (got ${_e(a)})`);const{col:u,column:h}=n(c,"sortFilter.state.sort.columnKey");if(!h.sortable)throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey ${JSON.stringify(c)} names column ${u}, which cannot sort`);o={col:u,direction:a}}const s=e.filters;if(!mn(s))throw new RangeError(`[spreadsheet] sortFilter.state.filters must be an object keyed by column key (got ${_e(s)})`);const l=new Set;for(const c of Object.keys(s)){const a=`sortFilter.state.filters[${JSON.stringify(c)}]`,{col:u,column:h}=n(c,"sortFilter.state.filters");if(!h.filterable)throw new RangeError(`[spreadsheet] ${a} names column ${u}, which cannot filter`);const g=s[c];if(!mn(g))throw new RangeError(`[spreadsheet] ${a} must be { mode: "exact", values } or { mode: "fuzzy", query } (got ${_e(g)})`);const L=g.mode;if(L==="exact"){gn(g,{mode:!0,values:!0},a);const M=g.values;if(!(Array.isArray(M)&&M.every($=>typeof $=="string")))throw new RangeError(`[spreadsheet] ${a}.values must be an array of strings (got ${_e(M)})`)}else if(L==="fuzzy"){if(gn(g,{mode:!0,query:!0},a),typeof g.query!="string")throw new RangeError(`[spreadsheet] ${a}.query must be a string (got ${_e(g.query)})`)}else throw new RangeError(`[spreadsheet] ${a}.mode must be "exact" or "fuzzy" (got ${_e(L)})`);if(!h.matchModes.includes(L))throw new RangeError(`[spreadsheet] ${a}.mode ${JSON.stringify(L)} is not offered by column ${u} (match modes ${h.matchModes.map(M=>JSON.stringify(M)).join(", ")})`);l.add(u)}return{sort:o,filteredColumns:l}},f0=(e,t,n)=>{const r=e;if(!mn(r))throw new RangeError(`[spreadsheet] sortFilter must be an object or absent (got ${_e(r)})`);if(n<1)throw new RangeError(`[spreadsheet] sortFilter needs headerRows of 1 or more: the sort and filter controls sit on the last header row (got headerRows ${n})`);gn(r,l0,"sortFilter");for(const M of["onStateChange","getColumnKey"])if(typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function (got ${_e(r[M])})`);for(const M of["getColumnOptions","getFilterValues"])if(r[M]!==void 0&&typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function or absent (got ${_e(r[M])})`);const o=r.defaults;if(!mn(o))throw new RangeError(`[spreadsheet] sortFilter.defaults must be an object (got ${_e(o)})`);gn(o,Pc,"sortFilter.defaults");const s=_c(o,"sortFilter.defaults"),l=[],c=new Map;let a=null,u=!1;for(let M=0;M<t;M++){const $=e.getColumnKey(M);if($===null){l.push(null);continue}if(typeof $!="string"||$==="")throw new RangeError(`[spreadsheet] sortFilter.getColumnKey(${M}) must return a non-empty string or null (got ${_e($)})`);const H=c.get($);if(H!==void 0)throw new RangeError(`[spreadsheet] sortFilter.getColumnKey returned ${JSON.stringify($)} for columns ${H.col} and ${M}; column keys must be unique`);let Z=s;if(e.getColumnOptions!==void 0){const O=`sortFilter.getColumnOptions(${JSON.stringify($)})`,D=e.getColumnOptions($);if(!mn(D))throw new RangeError(`[spreadsheet] ${O} must return an object (got ${_e(D)})`);gn(D,Pc,O);const W={...s};for(const K of Object.keys(D))D[K]!==void 0&&(W[K]=D[K]);Z=_c(W,O)}const Q={key:$,...Z};l.push(Q),c.set($,{col:M,column:Q}),(Z.sortable||Z.filterable)&&(u=!0),a===null&&Z.filterable&&Z.matchModes.includes("exact")&&(a={col:M,column:Q})}if(a!==null&&e.getFilterValues===void 0)throw new RangeError(`[spreadsheet] sortFilter.getFilterValues is required: column ${a.col} (${JSON.stringify(a.column.key)}) can filter by exact match`);const{sort:h,filteredColumns:g}=d0(r.state,c),L=new Map;for(const[M,$]of c)L.set(M,$.col);return{columns:l,columnOfKey:L,headerRow:n-1,sort:h,filteredColumns:g,hasControls:u}},cr=(e,t)=>{const n=e.columns[t];return n!=null&&(n.sortable||n.filterable)?n:null},p0=(e,t)=>e.key===t.key&&e.sortable===t.sortable&&e.filterable===t.filterable&&e.defaultMatchMode===t.defaultMatchMode&&e.matchModes.length===t.matchModes.length&&e.matchModes.every((n,r)=>n===t.matchModes[r]),h0=(e,t)=>e.sort===null||e.sort.columnKey!==t?{sort:{columnKey:t,direction:"asc"},filters:e.filters}:e.sort.direction==="asc"?{sort:{columnKey:t,direction:"desc"},filters:e.filters}:{sort:null,filters:e.filters},m0=(e,t,n)=>n!==null?{sort:{columnKey:t,direction:n},filters:e.filters}:e.sort!==null&&e.sort.columnKey===t?{sort:null,filters:e.filters}:e,gl=(e,t)=>{if(!Object.hasOwn(e.filters,t))return e;const n={};for(const r of Object.keys(e.filters))r!==t&&(n[r]=e.filters[r]);return{sort:e.sort,filters:n}},g0=e=>Object.keys(e.filters).length===0?e:{sort:e.sort,filters:{}},w0=(e,t,n,r)=>{const o=r.filter(s=>n.has(s));return o.length===r.length?gl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"exact",values:o}}}},C0=(e,t,n)=>n.trim()===""?gl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"fuzzy",query:n}}},y0=(e,t)=>e.mode==="fuzzy"||t.mode==="fuzzy"?e.mode==="fuzzy"&&t.mode==="fuzzy"&&e.query===t.query:e.values.length===t.values.length&&e.values.every((n,r)=>n===t.values[r]),b0=(e,t)=>{if(e===t)return!0;if(e.sort===null||t.sort===null?e.sort!==t.sort:e.sort.columnKey!==t.sort.columnKey||e.sort.direction!==t.sort.direction)return!1;const n=Object.keys(e.filters);return n.length!==Object.keys(t.filters).length?!1:n.every(r=>Object.hasOwn(t.filters,r)&&y0(e.filters[r],t.filters[r]))},v0=e=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] sortFilter.getFilterValues must resolve with an array (got ${_e(e)})`);const t=new Set;for(const[n,r]of e.entries()){const o=`sortFilter.getFilterValues()[${n}]`;if(!mn(r))throw new RangeError(`[spreadsheet] ${o} must be { value, label, count } (got ${_e(r)})`);if(gn(r,a0,o),typeof r.value!="string")throw new RangeError(`[spreadsheet] ${o}.value must be a string (got ${_e(r.value)})`);if(typeof r.label!="string")throw new RangeError(`[spreadsheet] ${o}.label must be a string (got ${_e(r.label)})`);if(!(Number.isInteger(r.count)&&r.count>=0))throw new RangeError(`[spreadsheet] ${o}.count must be a non-negative integer (got ${_e(r.count)})`);if(t.has(r.value))throw new RangeError(`[spreadsheet] ${o}.value ${JSON.stringify(r.value)} repeats an earlier value`);t.add(r.value)}return e},jc=e=>e.normalize("NFKC").toLowerCase(),R0=(e,t)=>jc(e).includes(jc(t)),Bu=e=>e.replace(/\r\n|\r|\n/g," "),S0=({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},E0=i.memo(S0),k0=Object.freeze({left:Object.freeze({justifyContent:zr("left")}),center:Object.freeze({justifyContent:zr("center")}),right:Object.freeze({justifyContent:zr("right")})}),O0=Object.freeze({role:"rowgroup"}),x0=4096,Ic=new WeakMap,yo=new Map,A0=(e,t)=>{if(e===null)return k0[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:zr(t)},s=JSON.stringify(o);let l=yo.get(s);return l===void 0&&(yo.size>=x0&&yo.clear(),l=Object.freeze(o),yo.set(s,l)),n[t]=l,l},T0=hl(),$0=(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},M0=(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=Eo(e,o,s),c={};let a=null,u;if(e.getCellFormat!==void 0){const h=ml(e,r===null?null:r.indexRef.current,r===null?T0:r.memoRef.current,o,s,l);u=h===void 0?void 0:h.value;const g=Za(h,l),L=wn(n,s,1),M=wn(t,o,1),$=hp(h,L===null?void 0:e.getCellFormat(o,L),M===null?void 0:e.getCellFormat(M,s),n.offsetOf(s)===0,t.offsetOf(o)===0);$!==null&&Object.assign(c,$.attrs),c["data-aqsp-align"]=g,a=A0($,g)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const h=e.getCellComments(o,s);h!==void 0&&h.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&fr(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const h=e.getCellValidation(o,s);h!==void 0&&Ag(h,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:u}},L0=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:L,labelledBy:M,gridLabel:$,readOnly:H,renderCell:Z,onScroll:Q,onRangeChange:O,focusSink:D,isEditing:W,requestCommit:K,testId:E,__onCellRender:P,__maxRenderedCells:j,cfIndexRef:m,cfMemoRef:d,isPointing:y,tapScrollCircleOptions:v,showArrowButtons:x,enableThumbDrag:S,enableTrackClick:V,overscanRows:C,overscanCols:A,background:X,onRenderTruncated:w,locale:G,scrollLabels:te,sortFilter:f,columnMenu:b})=>{const R=i.useRef(null),_=s??R;if(m===void 0!=(d===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const Y=i.useMemo(()=>m===void 0||d===void 0?null:{indexRef:m,memoRef:d},[m,d]),U=i.useCallback(()=>r.get().editVersion,[r]),oe=i.useCallback(Oe=>r.subscribeCoalesced(Oe),[r]),k=i.useSyncExternalStore(oe,U,U)+(l??0),B=i.useCallback(Oe=>t.sizeOf(Oe),[t]),z=i.useCallback(Oe=>n.sizeOf(Oe),[n]),re=i.useCallback((Oe,Ie)=>e.getCellText(Oe,Ie),[e]),ge=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),Te=i.useMemo(()=>({width:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1,showArrowButtons:x,enableThumbDrag:S,enableTrackClick:V}),[v,x,S,V]),Pe=i.useRef({row:-1,col:-1,value:void 0}),ot=i.useCallback((Oe,Ie)=>{const Be=Oe<L,Et={role:Be?"columnheader":"gridcell","aria-rowindex":Oe+1,"aria-colindex":Ie+1,"data-aqsp-cell":"","data-row":Oe,"data-col":Ie,className:"aqsp-cell",...nt(e,Oe,Ie)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Be?{"data-aqsp-header-row":""}:{},...f==null||Oe!==f.headerRow||cr(f,Ie)===null?{}:{"data-aqsp-column-controls":"",...f.sort!==null&&f.sort.col===Ie?{"aria-sort":f.sort.direction==="asc"?"ascending":"descending","data-aqsp-sort":f.sort.direction}:{},...f.filteredColumns.has(Ie)?{"data-aqsp-filtered":""}:{}}},it=Sm(e,Oe,Ie),on=it===null?Et:{...Et,...it},Ze=M0(e,t,n,Y,Oe,Ie),kt=Pe.current;return kt.row=Oe,kt.col=Ie,kt.value=Ze===null?void 0:Ze.value,Ze===null?on:Ze.style===null?{...on,...Ze.attrs}:{...on,...Ze.attrs,style:Ze.style}},[e,t,n,Y,L,f]),je=i.useCallback(Oe=>({role:"row","aria-rowindex":Oe+1,"data-aqsp-row":Oe,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Xe=i.useCallback((Oe,Ie,Be)=>{let Et=Oe;e.getCellFormat!==void 0&&(Et=Ln(Oe,$0(Pe.current,Ie,Be)));const it=I.jsx(E0,{row:Ie,col:Be,text:Oe,display:Et,renderCell:Z,__onCellRender:P});return f==null||b===void 0||b===null||Ie!==f.headerRow||cr(f,Be)===null?it:I.jsxs(I.Fragment,{children:[it,I.jsx(s0,{col:Be,direction:f.sort!==null&&f.sort.col===Be?f.sort.direction:null,filtered:f.filteredColumns.has(Be),expanded:b.openCol===Be,columnName:Bu(Et),menuLabel:b.menuLabel,filteredLabel:b.filteredLabel,onToggle:b.onToggle})]})},[k,Z,P,e,f,b]);return I.jsx("div",{ref:_,className:"aqsp-body","data-aqsp-body":"","data-testid":E?`${E}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":$,"aria-labelledby":M,"aria-readonly":H?"true":void 0,onPointerDownCapture:Oe=>{if(!(Oe.target instanceof Element&&Oe.target.closest("[data-aqsp-cells]")!==null)&&Oe.pointerType==="mouse"){if(Oe.button!==0){Oe.preventDefault();return}if(Oe.preventDefault(),y?.()===!0){Oe.stopPropagation(),D();return}if(W()&&!K()){Oe.stopPropagation(),D();return}D()}},children:I.jsx(rt.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:u,frozenTrailingCols:h,frozenTrailingRows:g,getRowHeight:B,getColWidth:z,getCell:re,getCellProps:ot,getRowProps:je,contentProps:O0,behaviorOptions:ge,scrollBarOptions:Te,overscanRows:C,overscanCols:A,background:X,onRenderTruncated:w,__maxRenderedCells:j,locale:G,labels:te,callbackThrottleMs:0,onScroll:Q,onRangeChange:O,testId:E,children:Xe})})},z0=i.memo(L0),rr=6,bt=3,zo=(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:bt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,a=wn(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-rr,length:bt}),r.push({kind:"unhide",index:s+1,start:c-bt,length:bt})):l>=2*rr?n.push({kind:"resize",index:s,start:c-rr,length:rr}):n.push({kind:"resize",index:s,start:c-bt,length:bt})}return[...n,...r]},Vu=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const a=e.sizeOf(c),u=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:u,length:bt}),n.push({kind:"resize",index:c,start:u+bt,length:bt})):a>=2*rr?n.push({kind:"resize",index:c,start:u,length:rr}):n.push({kind:"resize",index:c,start:u,length:bt})}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-bt,length:bt}),[...n.reverse(),...r]},N0=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:a,selectionRanges:u,enableResizeUI:h,dividerLeadingRef:g,dividerTrailingRef:L})=>{const M=rt.useWheelBridge(o),$=i.useCallback(w=>(s.current=w,M(w)),[s,M]),H=i.useCallback(()=>{const{colStart:w,colEnd:G,colVersion:te}=e.get();return`${w}:${G}:${te}`},[e]),Z=i.useCallback(w=>e.subscribeCoalesced(w),[e]);i.useSyncExternalStore(Z,H,H);const{colStart:Q,colEnd:O}=e.get(),D=t.count===0?0:t.offsetOf(Math.min(Q,t.count-1));i.useLayoutEffect(()=>{c.current=D,a()},[D,c,a]);const W=w=>u.some(G=>w>=G.startCol&&w<=G.endCol),K=Math.min(Math.max(0,n),t.count),E=wu(t,K),P=K>0?lr(t,0,K-1):[],j=Math.min(Math.max(0,r),t.count-K),m=yu(t,j),d=t.totalSize()-m,y=j>0?lr(t,t.count-j,t.count-1):[],v=lr(t,Math.max(Q,K),Math.min(O,Math.max(0,t.count-1)-j)),x=[];for(const w of v)x.push(I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w)-D,width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w));const S=h?zo(t,v):null,V=S===null?null:S.filter(w=>!(w.kind==="unhide"&&w.index<K&&E>0||w.kind==="unhide"&&w.index>=t.count-j&&m>0)),C=h&&K>0?zo(t,P):null,A=h&&j>0?Vu(t,y):null,X=I.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[x,V?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,style:{left:w.start-D,width:w.length}},`r${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{left:w.start-D,width:w.length}},`u${w.index}`))]});return I.jsx("div",{ref:$,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:K===0&&j===0?X:I.jsxs(I.Fragment,{children:[P.map(w=>I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-frozen-header":"","data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w),width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w)),C?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,style:{left:w.start,width:w.length}},`fr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{left:w.start,width:w.length}},`fu${w.index}`)),I.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:E,right:j>0?`calc(${Fe.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${Fe.SPREADSHEET_SCROLLBAR_SIZE_PX+E}px)))`:void 0},children:[X,K>0?I.jsx("div",{ref:g,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,j>0?I.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),j>0?I.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${E}px, calc(100% - ${m+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[y.map(w=>I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-trailing-header":"","data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w)-d,width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w)),A?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,"data-aqsp-resize-anchor":"trailing",style:{left:w.start,width:w.length}},`tr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,"data-aqsp-resize-anchor":"trailing",style:{left:w.start,width:w.length}},`tu${w.index}`))]})}):null]})})},D0=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:a,frozenRows:u,frozenTrailingRows:h,dividerLeadingRef:g,dividerTrailingRef:L})=>{const M=rt.useWheelBridge(n),$=i.useCallback(w=>(r.current=w,M(w)),[r,M]),H=w=>o.some(G=>w>=G.startRow&&w<=G.endRow),Z=i.useCallback(()=>{const{rowStart:w,rowEnd:G,rowGeomVersion:te}=e.get();return`${w}:${G}:${te}`},[e]),Q=i.useCallback(w=>e.subscribeCoalesced(w),[e]);i.useSyncExternalStore(Q,Z,Z);const{rowStart:O,rowEnd:D}=e.get(),W=t.count===0?0:t.offsetOf(Math.min(O,t.count-1));i.useLayoutEffect(()=>{l.current=W,c()},[W,l,c]);const K=Math.min(Math.max(0,u),t.count),E=Cu(t,K),P=K>0?lr(t,0,K-1):[],j=Math.min(Math.max(0,h),t.count-K),m=bu(t,j),d=t.totalSize()-m,y=j>0?lr(t,t.count-j,t.count-1):[],v=lr(t,Math.max(O,K),Math.min(D,Math.max(0,t.count-1)-j)),x=[];for(const w of v)x.push(I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w)-W,height:t.sizeOf(w)},children:w+1},w));const S=a?zo(t,v):null,V=S===null?null:S.filter(w=>!(w.kind==="unhide"&&w.index<K&&E>0||w.kind==="unhide"&&w.index>=t.count-j&&m>0)),C=a&&K>0?zo(t,P):null,A=a&&j>0?Vu(t,y):null,X=I.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[x,V?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,style:{top:w.start-W,height:w.length}},`r${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{top:w.start-W,height:w.length}},`u${w.index}`))]});return I.jsx("div",{ref:$,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K===0&&j===0?X:I.jsxs(I.Fragment,{children:[P.map(w=>I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w),height:t.sizeOf(w)},children:w+1},w)),C?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,style:{top:w.start,height:w.length}},`fr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{top:w.start,height:w.length}},`fu${w.index}`)),I.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:E,bottom:j>0?`calc(min(${m}px, max(0px, 100% - ${E}px)))`:void 0},children:[X,K>0?I.jsx("div",{ref:g,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,j>0?I.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),j>0?I.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${E}px, calc(100% - ${m}px))`},children:I.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[y.map(w=>I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w)-d,height:t.sizeOf(w)},children:w+1},w)),A?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,"data-aqsp-resize-anchor":"trailing",style:{top:w.start,height:w.length}},`tr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,"data-aqsp-resize-anchor":"trailing",style:{top:w.start,height:w.length}},`tu${w.index}`))]})}):null]})})},F0=9,q0=4,Hc=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,a=`${o} ${s} ${l} ${c}`;return t.set(e,a),a},Bc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,P0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),a=i.useRef(null),u=i.useRef(""),h=i.useRef(null),g=i.useCallback(m=>s.current!==null?m.pointerId===s.current:m.pointerType==="mouse",[]),L=i.useCallback(()=>{const m=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),m.writeResizeGuide(null);const d=h.current;d!==null&&(window.removeEventListener("pointermove",d.move),window.removeEventListener("pointerup",d.up),h.current=null);const y=c.current;y!==null&&s.current!==null&&y.hasPointerCapture?.(s.current)&&y.releasePointerCapture(s.current),c.current=null,s.current=null,m.repaintOverlay()},[]),M=i.useCallback((m,d)=>{const y=t.current;return m==="col"?d.startRow===0&&d.endRow===y.rowAxis.count-1:d.startCol===0&&d.endCol===y.colAxis.count-1},[]),$=i.useCallback((m,d)=>{const y=t.current,v=y.getSelection().ranges.filter(A=>M(m,A));if(!v.some(A=>m==="col"?d>=A.startCol&&d<=A.endCol:d>=A.startRow&&d<=A.endRow))return[d];const S=v.reduce((A,X)=>A+(m==="col"?X.endCol-X.startCol+1:X.endRow-X.startRow+1),0),V=m==="row"?Math.floor(y.maxOperationCells/Js):y.maxOperationCells;if(S>V)return y.onOperationRejected?.("resize",S,"limit"),null;const C=new Set;for(const A of v){const X=m==="col"?A.startCol:A.startRow,w=m==="col"?A.endCol:A.endRow;for(let G=X;G<=w;G+=1)C.add(G)}return[...C]},[M]),H=i.useCallback((m,d,y)=>{const v=t.current,x=m==="col"?v.colAxis:v.rowAxis,S=Zs(x,d,y,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:Gs,axisKind:m});return S.ok?(v.resizeTracks(m,S.entries),!0):(v.onOperationRejected?.("resize",S.count,S.reason),!1)},[]),Z=i.useCallback((m,d)=>{if(d===m.initialSize)return;const y=m.kind==="unhide"?[m.index]:$(m.axis,m.index);y!==null&&H(m.axis,y.map(v=>({index:v,size:d})),m.index)},[$,H]),Q=i.useCallback((m,d,y,v)=>{const x=t.current,S=x.fontSourceRef.current;if(S===null)return!1;if(d.length===0)return!0;const V=m.length*d.length;if(V>y)return x.onOperationRejected?.("resize",V,"limit"),!1;const C=document.createElement("canvas").getContext("2d");if(C===null)return!0;const A=getComputedStyle(S),X=`${A.fontStyle} ${A.fontWeight} ${A.fontSize} ${A.fontFamily}`,w=A.getPropertyValue("--_aqsp-header-row-font-weight").trim(),G={fontStyle:A.fontStyle,fontWeight:w===""?A.fontWeight:w,fontSize:A.fontSize,fontFamily:A.fontFamily},te=`${G.fontStyle} ${G.fontWeight} ${G.fontSize} ${G.fontFamily}`,f=x.adapter.getConditionalFormats===void 0?null:n0(x.adapter.getConditionalFormats()),b=hl(),R=new WeakMap,_=new WeakMap,Y=new Map;for(const k of m){const B=f===null?null:_u(f.filter(z=>z.ranges.some(re=>k>=re.startCol&&k<=re.endCol)));for(const z of d){const re=x.adapter.getCellText(z,k),ge=x.adapter.getCellFormat===void 0?void 0:ml(x.adapter,B,b,z,k,()=>re),Te=z<x.headerRows,Pe=ge===void 0?Te?te:X:Te?Hc(ge,_,G):Hc(ge,R,A),ot=Ln(re,ge===void 0?void 0:ge.value),je=Y.get(Pe);je===void 0?Y.set(Pe,[{col:k,text:ot}]):je.push({col:k,text:ot})}}const U=S.ownerDocument.createElement("span");U.setAttribute("aria-hidden","true"),U.style.position="absolute",U.style.visibility="hidden",S.append(U);const oe=new Map;for(const[k,B]of Y){C.font=k,U.style.font=k;const z=getComputedStyle(U);C.letterSpacing=z.letterSpacing==="normal"?"0px":z.letterSpacing,C.wordSpacing=z.wordSpacing==="normal"?"0px":z.wordSpacing;for(const re of B){const ge=C.measureText(re.text).width,Te=oe.get(re.col);(Te===void 0||ge>Te)&&oe.set(re.col,ge)}}U.remove();const ce=[];for(const k of m){const B=oe.get(k);B!==void 0&&B>0&&ce.push({index:k,size:Math.ceil(B)+F0})}return ce.length===0?!0:H("col",ce,v)},[H]),O=i.useCallback(m=>{const d=t.current,y=$("col",m);if(y===null)return!1;const v=d.handleRef.current,x=v===null?null:v.getFrozenSize(),S=x===null?0:x.rows,V=x===null?0:x.trailingRows,{rowStart:C,rowEnd:A}=d.viewStore.get(),X=Math.min(A,d.rowAxis.count-1),w=[],G=new Set,te=f=>{!G.has(f)&&d.rowAxis.sizeOf(f)>0&&(G.add(f),w.push(f))};for(let f=0;f<S;f+=1)te(f);for(let f=C;f<=X;f+=1)te(f);for(let f=d.rowAxis.count-V;f<d.rowAxis.count;f+=1)te(f);return Q(y,w,Math.floor(d.maxOperationCells/q0),m)},[$,Q]),D=i.useCallback((m,d,y)=>{const v=m==="col"?t.current.colAxis:t.current.rowAxis,x=_d(v.sizeOf(d),y);if(x===v.sizeOf(d))return!0;const S=$(m,d);return S===null?!1:H(m,S.map(V=>({index:V,size:x})),d)},[$,H]),W=i.useCallback(m=>{const d=t.current;return d.autofitEnabled?d.colAxis.sizeOf(m)===0?!0:O(m):!1},[O]),K=i.useCallback(m=>{const d=t.current;if(!d.autofitEnabled)return!1;const y=[...new Set(m)].filter(x=>d.colAxis.sizeOf(x)>0);if(y.length===0)return!0;const v=[];for(let x=0;x<d.rowAxis.count;x+=1)d.rowAxis.sizeOf(x)>0&&v.push(x);return Q(y,v,d.maxOperationCells,null)},[Q]),{enabled:E,colBandRef:P,rowBandRef:j}=e;return i.useEffect(()=>{const m=P.current,d=j.current;if(!E||m===null||d===null)return;const y=R=>R==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(R,_)=>{if(!(_ instanceof Element))return null;const Y=_.closest(y(R));if(Y===null)return null;const U=Y.hasAttribute("data-aqsp-unhide"),oe=Number(Y.getAttribute(U?"data-aqsp-unhide":R==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ce=Y.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:U?"unhide":"resize",index:oe,anchor:ce}},x=R=>{if(!(n.current&&g(R)))return;const _=r.current;if(_===null)return;const Y=(_.axis==="col"?R.clientX-_.startClientX:R.clientY-_.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(_.anchor==="trailing"?_.initialSize-Y:_.initialSize+Y)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const U=r.current;if(!n.current||U===null)return;const oe=t.current,ce=U.axis==="col"?oe.colAxis:oe.rowAxis;oe.writeResizeGuide({axis:U.axis,position:Bc(U,ce,o.current),anchor:U.anchor})}))},S=()=>{const R=r.current,_=o.current;L(),R!==null&&Z(R,_)},V=R=>{x(R),n.current&&g(R)&&(l.current&1)!==0&&(R.buttons&1)===0&&S()},C=R=>{R.button!==0||!(n.current&&g(R))||S()},A=(R,_)=>Y=>{const U=t.current;if(u.current=Y.pointerType,Y.pointerType!=="mouse")return;if(Y.button!==0){Y.preventDefault();return}const oe=v(R,Y.target);if(oe===null)return;if(Y.stopPropagation(),Y.preventDefault(),U.isPointing()){U.focusSink();return}if(U.isEditing()&&!U.requestCommit()){U.focusSink();return}U.focusSink();const ce=R==="col"?U.colAxis:U.rowAxis,k={axis:R,kind:oe.kind,index:oe.index,anchor:oe.anchor,initialSize:ce.sizeOf(oe.index),startClientX:Y.clientX,startClientY:Y.clientY};r.current=k,o.current=k.initialSize,l.current=Y.buttons,n.current=!0,U.repaintOverlay(),s.current=Y.pointerId,c.current=_;try{_.setPointerCapture(Y.pointerId)}catch{s.current=null}const B=V,z=C;h.current={move:B,up:z},window.addEventListener("pointermove",B),window.addEventListener("pointerup",z),U.writeResizeGuide({axis:R,position:Bc(k,ce,o.current),anchor:k.anchor})},X=(R,_)=>Y=>{const U=t.current;if(u.current!=="mouse")return;const oe=_.getRootNode(),ce=oe instanceof ShadowRoot?oe:_.ownerDocument,k=Y.target instanceof Element&&Y.target.closest(y(R))!==null?Y.target:typeof ce.elementFromPoint=="function"?ce.elementFromPoint(Y.clientX,Y.clientY):null,B=v(R,k);if(B!==null){if(Y.stopPropagation(),U.isEditing()){U.focusSink();return}if(B.kind==="unhide"){H(R,[{index:B.index,size:R==="col"?U.defaultColumnWidth:U.defaultRowHeight}],null);return}if(U.autofitEnabled){if(R==="row"){const z=$("row",B.index);z!==null&&H("row",z.map(re=>({index:re,size:U.defaultRowHeight})),B.index);return}O(B.index)}}},w=R=>{!n.current||s.current===null||R.pointerId!==s.current||L()},G=A("col",m),te=A("row",d),f=X("col",m),b=X("row",d);return m.addEventListener("pointerdown",G,{capture:!0}),d.addEventListener("pointerdown",te,{capture:!0}),m.addEventListener("dblclick",f),d.addEventListener("dblclick",b),m.addEventListener("lostpointercapture",w),d.addEventListener("lostpointercapture",w),()=>{m.removeEventListener("pointerdown",G,{capture:!0}),d.removeEventListener("pointerdown",te,{capture:!0}),m.removeEventListener("dblclick",f),d.removeEventListener("dblclick",b),m.removeEventListener("lostpointercapture",w),d.removeEventListener("lostpointercapture",w),L()}},[E,P,j,g,L,Z,H,$,O]),i.useMemo(()=>({stepTrack:D,autofitColumn:W,autofitColumnsInAllRows:K,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L,D,W,K])},wl=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,_0=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>wl(n,t.ranges[r]))&&Dt(e.anchor,t.anchor)&&Dt(e.active,t.active),Vc=(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=>vn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:me(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},xs=(e,t)=>{if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the ${t} must be an object (got ${String(e)})`);return e},j0=(e,t,n)=>{const r=xs(e,"selection"),o=r.ranges;if(!Array.isArray(o)||o.length===0)throw new RangeError("[spreadsheet] setSelection: the selection must have at least one range");const s=`${t} x ${n} grid`,l=(g,L)=>typeof g=="number"&&Number.isInteger(g)&&g>=0&&g<L,c=(g,L)=>{const{row:M,col:$}=xs(g,L);if(!(l(M,t)&&l($,n)))throw new RangeError(`[spreadsheet] setSelection: the ${L} {row: ${String(M)}, col: ${String($)}} is not a cell of the ${s}`);return{row:M,col:$}},a=o.map((g,L)=>{const{startRow:M,startCol:$,endRow:H,endCol:Z}=xs(g,`range ${L}`);if(!(l(M,t)&&l(H,t)&&l($,n)&&l(Z,n)&&M<=H&&$<=Z))throw new RangeError(`[spreadsheet] setSelection: range ${L} {startRow: ${String(M)}, startCol: ${String($)}, endRow: ${String(H)}, endCol: ${String(Z)}} is not a range of the ${s} with each start at most its end`);return{startRow:M,startCol:$,endRow:H,endCol:Z}}),u=c(r.anchor,"anchor"),h=c(r.active,"active cell");if(!Vt(a[a.length-1],u))throw new RangeError(`[spreadsheet] setSelection: the anchor {row: ${u.row}, col: ${u.col}} must lie in the last range`);if(!a.some(g=>Vt(g,h)))throw new RangeError(`[spreadsheet] setSelection: the active cell {row: ${h.row}, col: ${h.col}} must lie in one of the ranges`);return{ranges:a,anchor:u,active:h}},I0=(e,t)=>{const n=e.ranges[e.ranges.length-1];return wl(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},ar=(e,t,n)=>n.extend?Mn(e,t):n.append?{ranges:[...e.ranges,me(t,t)],anchor:t,active:t}:e.ranges.length===1&&Dt(e.anchor,t)&&Dt(e.active,t)&&wl(e.ranges[0],me(t,t))?e:{ranges:[me(t,t)],anchor:t,active:t},H0=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Mn=(e,t)=>{const n=I0(e,me(e.anchor,t));return n.ranges.some(r=>Vt(r,n.active))?n:{...n,active:H0(n.active,n.ranges[n.ranges.length-1])}},Wu=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(me({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(me({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const a=Math.max(c.startRow,t.startRow),u=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(me({row:a,col:c.startCol},{row:u,col:t.startCol-1})),t.endCol<c.endCol&&o.push(me({row:a,col:t.endCol+1},{row:u,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[me(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Vt(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}},B0=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Ku=(e,t)=>{const n=e.ranges.findIndex(o=>Vt(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=B0(e.ranges,r.rangeIndex,r.cell,t),!Dt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Zt=24,Wc=32,No=4,Gn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),a=i.useRef(null),u=i.useRef(null),h=i.useRef(null),g=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,h.current=null,u.current=null},[]),L=i.useCallback(()=>{const $=a.current,H=e.current,Z=h.current;if($===null||H===null||Z===null){c.current=null;return}const{clientX:Q,clientY:O}=$.getPointerPosition(),D=l.current,W=(Q-Z.left)/D,K=(O-Z.top)/D,E=H.getViewportSize(),P=E.width,j=E.height;if(P<=0||j<=0){c.current=requestAnimationFrame(L);return}const m=V=>Math.min(Wc,Math.ceil(V/Zt*Wc));let d=0,y=0;if(s!=="x"){const V=H.getFrozenSize(),C=V.trailingVisibleHeight;K>j-C-Zt?$.anchorRow!==void 0&&V.trailingRows>0&&$.anchorRow>=t.count-V.trailingRows&&C>0&&K>=j-C||(d=m(K-(j-C-Zt))):K<V.height+Zt&&($.anchorRow!==void 0&&$.anchorRow<V.rows&&V.height>0&&K<V.height||(d=-m(V.height+Zt-K)))}if(s!=="y"){const V=H.getFrozenSize(),C=V.trailingVisibleWidth;W>P-C-Zt?$.anchorCol!==void 0&&V.trailingCols>0&&$.anchorCol>=n.count-V.trailingCols&&C>0&&W>=P-C||(y=m(W-(P-C-Zt))):W<V.width+Zt&&($.anchorCol!==void 0&&$.anchorCol<V.cols&&V.width>0&&W<V.width||(y=-m(V.width+Zt-W)))}const v=y!==0||d!==0?H.scrollBy({x:y!==0?y:void 0,y:d!==0?d:void 0}):H.getScrollPosition(),x=v.y,S=v.x;if(x>=0&&S>=0&&t.totalSize()>0&&n.totalSize()>0){const V=H.getFrozenSize(),C=vn({row:Vr(t,K,{scroll:x,frozenSize:V.height,trailingSize:V.trailingHeight,extent:E.height}),col:Br(n,W,{scroll:S,frozenSize:V.width,trailingSize:V.trailingWidth,extent:E.width})},t.count,n.count),A=u.current;(d!==0||y!==0||A===null||A.row!==C.row||A.col!==C.col)&&(u.current=C,o($.buildRange(C)))}c.current=requestAnimationFrame(L)},[e,t,n,s,o]),M=i.useCallback($=>{g(),a.current=$,h.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(L)},[g,L,r]);return i.useEffect(()=>{const $=()=>{document.visibilityState==="hidden"&&g()};return document.addEventListener("visibilitychange",$),()=>{document.removeEventListener("visibilitychange",$),g()}},[g]),i.useMemo(()=>({start:M,stop:g}),[M,g])},Kc=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),h=i.useRef(null),g=i.useRef(!1),L=i.useRef(0),M=i.useCallback((E,P)=>{const{axis:j,mainAxis:m,handleRef:d,zoomRef:y}=t.current,v=s.current;if(v===null||m.totalSize()===0)return null;const x=y.current,S=d.current;if(S===null)return null;if(j==="col"){const X=S.getScrollPosition().x;if(X<0)return null;const w=S.getFrozenSize(),G=S.getViewportSize();return Math.min(Math.max(Br(m,(E-v.left)/x,{scroll:X,frozenSize:w.width,trailingSize:w.trailingWidth,extent:G.width}),0),m.count-1)}const V=S.getScrollPosition().y;if(V<0)return null;const C=S.getFrozenSize(),A=S.getViewportSize();return Math.min(Math.max(Vr(m,(P-v.top)/x,{scroll:V,frozenSize:C.height,trailingSize:C.trailingHeight,extent:A.height}),0),m.count-1)},[]),$=i.useCallback((E,P)=>{const{axis:j,crossCount:m}=t.current;return j==="col"?{press:{row:0,col:E},extend:{row:m-1,col:P}}:{press:{row:E,col:0},extend:{row:P,col:m-1}}},[]),H=i.useCallback((E,P)=>{const{axis:j,crossCount:m}=t.current;return E.ranges.some(d=>j==="col"?d.startRow===0&&d.endRow===m-1&&P>=d.startCol&&P<=d.endCol:d.startCol===0&&d.endCol===m-1&&P>=d.startRow&&P<=d.endRow)},[]),Z=i.useRef(!1),Q=i.useRef({clientX:0,clientY:0}),O=i.useCallback(()=>{Z.current=!1;const{autoScroller:E,headerRef:P,onDragFrame:j}=t.current;n.current=!1,r.current=null,h.current=null,g.current=!1,L.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),E.stop();const m=P.current;m!==null&&a.current!==null&&m.hasPointerCapture?.(a.current)&&m.releasePointerCapture(a.current),a.current=null,j(null),t.current.repaintOverlay()},[]),D=i.useCallback(()=>{if(!n.current)return;const E=r.current;E!==null&&t.current.setSelection(E),O()},[O]),{enabled:W,headerRef:K}=e;return i.useEffect(()=>{const E=K.current;if(!W||E===null)return;const P=S=>{const V=t.current;if(S.pointerType!=="mouse")return;if(S.button!==0){S.preventDefault();return}if(g.current=!1,V.pointing?.getPointing()){s.current=E.getBoundingClientRect();const w=M(S.clientX,S.clientY);if(w===null)return;S.preventDefault(),V.focusSink(),V.pointing.insertReference(V.axis==="col"?{row:0,col:w}:{row:w,col:0},V.axis==="col"?"columns":"rows");return}if(V.isEditing()&&!V.requestCommit()){S.preventDefault(),V.focusSink();return}s.current=E.getBoundingClientRect();const C=M(S.clientX,S.clientY);if(C===null)return;S.preventDefault(),V.focusSink();const A=V.getSelection();r.current=A;const X=S.ctrlKey||S.metaKey;if(S.shiftKey){const w=V.axis==="col"?{row:0,col:A.anchor.col}:{row:A.anchor.row,col:0},{extend:G}=$(C,C),te={...A,anchor:w};V.setSelection(Mn(te,G)),o.current=V.axis==="col"?w.col:w.row}else if(X&&H(A,C))g.current=!0,L.current=C,o.current=C;else{const{press:w,extend:G}=$(C,C),te=ar(A,w,{extend:!1,append:X});V.setSelection(Mn(te,G)),o.current=C}n.current=!0,V.repaintOverlay(),l.current={clientX:S.clientX,clientY:S.clientY},a.current=S.pointerId,u.current=S.buttons;try{E.setPointerCapture(S.pointerId)}catch{a.current=null}h.current=w=>{const G=t.current.axis==="col"?w.col:w.row,{press:te}=$(o.current,o.current),{extend:f}=$(o.current,G);return me(te,f)},V.autoScroller.stop(),Z.current=!1,Q.current={clientX:S.clientX,clientY:S.clientY}},j=S=>a.current!==null?S.pointerId===a.current:S.pointerType==="mouse",m=S=>{if(n.current&&j(S)){if(g.current){const V=S.clientX!==l.current.clientX||S.clientY!==l.current.clientY;if(l.current={clientX:S.clientX,clientY:S.clientY},!V)return;const C=M(S.clientX,S.clientY);if(C===null||C===L.current)return;g.current=!1;const A=t.current,{press:X,extend:w}=$(L.current,L.current),G=ar(A.getSelection(),X,{extend:!1,append:!0});A.setSelection(Mn(G,w));const te=h.current,f=Math.abs(S.clientX-Q.current.clientX),b=Math.abs(S.clientY-Q.current.clientY);te!==null&&Math.max(f,b)>=No&&(Z.current=!0,A.autoScroller.start({getPointerPosition:()=>l.current,buildRange:te,anchorCol:A.axis==="col"?o.current:void 0,anchorRow:A.axis==="row"?o.current:void 0}))}else if(l.current={clientX:S.clientX,clientY:S.clientY},!Z.current&&h.current!==null){const V=Math.abs(S.clientX-Q.current.clientX),C=Math.abs(S.clientY-Q.current.clientY);Math.max(V,C)>=No&&(Z.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:h.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 V=h.current;if(!n.current||V===null)return;const C=M(l.current.clientX,l.current.clientY);C!==null&&t.current.onDragFrame(V(t.current.axis==="col"?{row:0,col:C}:{row:C,col:0}))}))}},d=S=>{m(S),n.current&&j(S)&&(u.current&1)!==0&&(S.buttons&1)===0&&v(S)},y=S=>{S.button!==0||!(n.current&&j(S))||v(S)},v=S=>{const V=t.current;if(g.current){const{press:A,extend:X}=$(L.current,L.current);V.setSelection(Wu(V.getSelection(),me(A,X),A)),O();return}const C=M(S.clientX,S.clientY);if(C!==null){const{extend:A}=$(o.current,C);V.setSelection(Mn(V.getSelection(),A))}O()},x=S=>{!n.current||a.current===null||S.pointerId!==a.current||D()};return E.addEventListener("pointerdown",P),E.addEventListener("pointermove",d),E.addEventListener("pointerup",y),E.addEventListener("lostpointercapture",x),()=>{E.removeEventListener("pointerdown",P),E.removeEventListener("pointermove",d),E.removeEventListener("pointerup",y),E.removeEventListener("lostpointercapture",x),O()}},[W,K,M,$,O,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:D,cancelDrag:O}),[D,O])},V0=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(l<0||s<0)return;const u=o.getFrozenSize();if(a>0&&r.row>=u.rows&&r.row<t.count-u.trailingRows){const h=t.offsetOf(r.row),g=h+t.sizeOf(r.row);h<u.height+l?o.scrollBy({y:h-(u.height+l)}):g>l+a-u.trailingVisibleHeight&&o.scrollBy({y:g-(l+a-u.trailingVisibleHeight)})}if(c>0){if(r.col<u.cols||r.col>=n.count-u.trailingCols)return;const h=n.offsetOf(r.col),g=h+n.sizeOf(r.col);h<u.width+s?o.scrollBy({x:h-(u.width+s)}):g>s+c-u.trailingVisibleWidth&&o.scrollBy({x:g-(s+c-u.trailingVisibleWidth)})}},W0=50,K0=100,Yu=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<W0:!1,Ar={selectAll:en("Ctrl+A"),undo:en("Ctrl+Z"),redo:en("Ctrl+Y"),redoShiftZ:en("Ctrl+Shift+Z"),pasteValues:en("Ctrl+Shift+V")},Y0=new Set(["Shift","Control","Alt","Meta","AltGraph"]),X0={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},U0=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",G0=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(null),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(e);a.current=e;const{enabled:u,sinkRef:h,rootRef:g,handleRef:L}=e;i.useEffect(()=>{const M=h.current,$=g.current;if(!u||M===null||$===null)return;const H=()=>{c.current&&(c.current=!1,a.current.onPointFrame?.(null))},Z=(f,b,R)=>wn(f,b,R)??b,Q=(f,b)=>{const R=a.current;return b==="left"||b==="right"?{row:f.row,col:Z(R.colAxis,f.col,b==="right"?1:-1)}:{row:Z(R.rowAxis,f.row,b==="down"?1:-1),col:f.col}},O=f=>f.indexAt(0),D=f=>f.indexAt(f.totalSize()-1),W=(f,b,R,_)=>{if(f.sizeOf(b)>0)return b;const Y=wn(f,b,R);if(Y!==null)return Y;const U=wn(f,b,R===1?-1:1);return U!==null?U:_},K=()=>{const f=a.current.getSelection(),b=f.ranges[f.ranges.length-1];return{row:f.anchor.row===b.startRow?b.endRow:b.startRow,col:f.anchor.col===b.startCol?b.endCol:b.startCol}},E=f=>Q(K(),f),P=(f,b)=>{const R=a.current,_=b==="left"||b==="right",Y=b==="right"||b==="down"?1:-1;let U;return R.findDataEdge!==void 0?(U=R.findDataEdge({row:f.row,col:f.col},b),j(U,f,b)):U={row:b==="down"?R.rowAxis.count-1:b==="up"?0:f.row,col:b==="right"?R.colAxis.count-1:b==="left"?0:f.col},_?{row:U.row,col:W(R.colAxis,U.col,Y,f.col)}:{row:W(R.rowAxis,U.row,Y,f.row),col:U.col}},j=(f,b,R)=>{const _=a.current;if(!(Number.isInteger(f.row)&&Number.isInteger(f.col)&&f.row>=0&&f.row<_.rowAxis.count&&f.col>=0&&f.col<_.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${f.row}, col: ${f.col}} for a ${_.rowAxis.count} x ${_.colAxis.count} grid`);const Y=R==="left"||R==="right";if(Y?f.row!==b.row:f.col!==b.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${Y?"row":"column"} (received {row: ${f.row}, col: ${f.col}} from {row: ${b.row}, col: ${b.col}})`)},m=(f,b,R)=>{if(!(Number.isInteger(f)&&f>=0&&f<b))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${R} component ${f} (count ${b})`)},d=f=>{const b=a.current,R=b.getSelection();if(Ku(R,f)===R){b.moveActive({mode:"reset",cell:Q(R.active,f)});return}b.moveActive({mode:"cycle",direction:f})},y=f=>{const b=a.current,R=b.commands;if(R===void 0||!b.isEditing())return null;const _=Vs(R.table,f);return _!==null&&_.command==="fillSelection"&&R.isAvailable("fillSelection")?R:null},v=()=>{s.current=null;const f=a.current,b=f.commands;b===void 0||!f.isEditing()||!b.isAvailable("fillSelection")||b.execute("fillSelection")},x=f=>{const b=y(f);if(r.current){o.current=b!==null;return}b!==null&&t.current!==null&&(f.preventDefault(),b.execute("fillSelection"))},S=()=>{const f=h.current;if(f===null)return;const b=f.selectionStart??f.value.length,R=f.selectionEnd??b;f.value=`${f.value.slice(0,b)}
|
|
14
|
-
${f.value.slice(R)}`,f.setSelectionRange(b+1,b+1)},V=(f,b)=>{const R=a.current,_=R.pageExtent();if(_<=0)return Z(R.rowAxis,f,b==="down"?1:-1);const Y=R.rowAxis.indexAt(R.rowAxis.offsetOf(f)+(b==="down"?_:-_));return Y===f?Z(R.rowAxis,f,b==="down"?1:-1):Y},C=f=>{const b=a.current;if(l.current=!1,Yu(f,t.current)){x(f);return}const R=f.ctrlKey||f.metaKey,_=f.altKey,Y=X0[f.key];if(c.current&&!Y0.has(f.key)&&!b.isDragging()&&H(),b.isEditing()){const oe=b.getEditingMode();if(b.isDragging()){f.preventDefault(),f.key==="Escape"&&!R&&!f.shiftKey&&!_&&b.abortDrag();return}const ce=b.pointing;if(ce!==void 0){if(Y!==void 0&&!_){const z=ce.getReferenceCursor();if(z!==null){f.preventDefault();const re=vn(z.cursor,b.rowAxis.count,b.colAxis.count),ge=vn(z.origin,b.rowAxis.count,b.colAxis.count),Te=R?P(re,Y):Q(re,Y);if(b.ensureCellVisible(Te),ce.insertReference(f.shiftKey?me(ge,Te):Te,z.axis),b.onPointFrame!==void 0){const Pe=f.shiftKey?me(ge,Te):me(Te,Te);b.onPointFrame(z.axis==="columns"?me({row:0,col:Pe.startCol},{row:b.rowAxis.count-1,col:Pe.endCol}):z.axis==="rows"?me({row:Pe.startRow,col:0},{row:Pe.endRow,col:b.colAxis.count-1}):Pe),c.current=!0}return}}if(f.key==="F2"&&!R&&!f.shiftKey&&!_&&ce.togglePointingArm()){f.preventDefault();return}if(f.key==="F4"&&!R&&!f.shiftKey&&!_&&ce.cycleAnchorAtCaret()){f.preventDefault();return}}const k=b.commands,B=k===void 0?null:Vs(k.table,f);if(k!==void 0&&B!==null&&$o.has(B.command)&&k.isAvailable(B.command)){f.preventDefault(),k.execute(B.command);return}if(Y!==void 0&&!_){if(R&&f.shiftKey){f.preventDefault();return}if(R)return;if(oe==="replace"){if(f.preventDefault(),!b.requestCommit())return;f.shiftKey?b.moveActive({mode:"extend",cell:E(Y)}):b.moveActive({mode:"reset",cell:Q(b.getSelection().active,Y)});return}return}if(f.key==="Enter"&&_&&!R&&!f.shiftKey){f.preventDefault(),S();return}if((f.key==="Enter"||f.key==="Tab")&&!R&&!_){if(f.preventDefault(),!b.requestCommit())return;const z=!f.shiftKey;d(f.key==="Tab"?z?"right":"left":z?"down":"up");return}if((f.key==="PageUp"||f.key==="PageDown")&&!f.shiftKey&&!R&&!_){if(f.preventDefault(),!b.requestCommit())return;const z=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:V(z.row,f.key==="PageDown"?"down":"up"),col:z.col}});return}if(f.key==="Escape"&&!R&&!f.shiftKey&&!_){f.preventDefault(),b.cancelEdit();return}if(k!==void 0&&B!==null&&!$o.has(B.command)&&Km(B.chord)&&k.isAvailable(B.command)){f.preventDefault(),b.onCommandBlockedWhileEditing?.(B);return}return}if(f.defaultPrevented)return;if(b.isDragging()&&f.key!=="Escape"){f.preventDefault();return}const U=b.commands;if(U!==void 0){const oe=Bm(U.table,f);if(oe!==null&&U.isAvailable(oe)){f.preventDefault(),U.execute(oe);return}}if(Y!==void 0&&!_){const oe=Y==="left"||Y==="right",ce=Y==="right"||Y==="down"?1:-1;if(R&&f.shiftKey){f.preventDefault();const k=b.getSelection(),B=K();let z;if(b.findDataEdge!==void 0){const re=oe?{row:k.active.row,col:B.col}:{row:B.row,col:k.active.col},ge=b.findDataEdge(re,Y);z=oe?ge.col:ge.row,m(z,oe?b.colAxis.count:b.rowAxis.count,oe?"col":"row"),z=W(oe?b.colAxis:b.rowAxis,z,ce,oe?B.col:B.row)}else{const re=oe?b.colAxis:b.rowAxis;z=ce===1?D(re):O(re)}b.moveActive({mode:"extend",cell:oe?{row:B.row,col:z}:{row:z,col:B.col}});return}if(R){f.preventDefault(),b.moveActive({mode:"reset",cell:P(b.getSelection().active,Y)});return}if(f.shiftKey){f.preventDefault(),b.moveActive({mode:"extend",cell:E(Y)});return}f.preventDefault(),b.moveActive({mode:"reset",cell:Q(b.getSelection().active,Y)});return}if(U0(f)){f.preventDefault();return}if((f.key==="Tab"||f.key==="Enter")&&!R&&!_){f.preventDefault();const oe=!f.shiftKey;d(f.key==="Tab"?oe?"right":"left":oe?"down":"up");return}if(f.key==="Home"&&!_){if(f.preventDefault(),f.shiftKey){const ce=K();b.moveActive({mode:"extend",cell:{row:R?O(b.rowAxis):ce.row,col:O(b.colAxis)}});return}const oe=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:R?O(b.rowAxis):oe.row,col:O(b.colAxis)}});return}if(f.key==="End"&&!_){if(f.preventDefault(),f.shiftKey){const ce=K();b.moveActive({mode:"extend",cell:{row:R?D(b.rowAxis):ce.row,col:D(b.colAxis)}});return}const oe=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:R?D(b.rowAxis):oe.row,col:D(b.colAxis)}});return}if((f.key==="PageUp"||f.key==="PageDown")&&!R&&!_){f.preventDefault();const oe=f.key==="PageDown"?"down":"up";if(f.shiftKey){const k=K();b.moveActive({mode:"extend",cell:{row:V(k.row,oe),col:k.col}});return}const ce=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:V(ce.row,oe),col:ce.col}});return}if(f.key==="F2"&&!R&&!f.shiftKey&&!_){f.preventDefault(),b.startEdit("edit");return}if((f.key==="Delete"||f.key==="Backspace")&&!R&&!f.shiftKey&&!_){f.preventDefault();const oe=b.getSelection(),ce=vt(oe.ranges);if(ce>b.maxOperationCells){b.onOperationRejected?.("delete",ce,"limit");return}if(b.adapter!==void 0&&nr(b.adapter,oe.ranges)){b.rejectReadOnly({kind:"operation",op:"delete",cellCount:ce});return}const k=[],B=b.adapter!==void 0&&ko(b.adapter).hyperlink;fn(oe.ranges,z=>{k.push(B?{row:z.row,col:z.col,text:"",hyperlink:null}:{row:z.row,col:z.col,text:""})}),b.commitEdits(k,{source:"delete"});return}if(f.key==="Escape"){if(b.isDragging()){f.preventDefault(),b.abortDrag();return}if(R||f.shiftKey||_||(f.preventDefault(),b.hideNoteTip?.())||b.closeRejectedMessage?.())return;if(b.getClip()!==null){b.discardClip();return}b.handOffFocusToRoot();return}if(kr(Ar.selectAll,f)){f.preventDefault();const oe=b.getSelection(),ce=me({row:0,col:0},{row:b.rowAxis.count-1,col:b.colAxis.count-1});b.setSelection({ranges:[ce],anchor:oe.anchor,active:oe.active});return}if(kr(Ar.undo,f)){f.preventDefault(),b.onUndoRequest?.();return}if(kr(Ar.redo,f)||kr(Ar.redoShiftZ,f)){f.preventDefault(),b.onRedoRequest?.();return}if(f.key==="F10"&&f.shiftKey&&!R&&!_||f.key==="ContextMenu"&&!R&&!f.shiftKey&&!_){f.preventDefault();const oe=b.getSelection().active;b.ensureCellVisible(oe);const ce=L.current,k=ce===null?{x:0,y:0}:ce.getScrollPosition(),B=Math.max(0,k.y),z=Math.max(0,k.x),re=ce===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:ce.getFrozenSize(),ge=ce===null?{width:0,height:0}:ce.getViewportSize(),Te=b.zoomRef.current;b.onCellContextMenu?.(oe,{kind:"keyboard",cellRect:{top:Dn(b.rowAxis,oe.row,{scroll:B,frozenCount:re.rows,trailingCount:re.trailingRows,extent:ge.height})*Te,left:Nn(b.colAxis,oe.col,{scroll:z,frozenCount:re.cols,trailingCount:re.trailingCols,extent:ge.width})*Te,width:b.colAxis.sizeOf(oe.col)*Te,height:b.rowAxis.sizeOf(oe.row)*Te}});return}if(f.key===" "&&!_&&R!==f.shiftKey){f.preventDefault();const oe=b.getSelection(),ce=oe.ranges.map(k=>R?me({row:0,col:k.startCol},{row:b.rowAxis.count-1,col:k.endCol}):me({row:k.startRow,col:0},{row:k.endRow,col:b.colAxis.count-1}));b.setSelection({ranges:ce,anchor:oe.anchor,active:oe.active});return}if(b.pendingPasteOptionsRef!==void 0&&kr(Ar.pasteValues,f)){b.pendingPasteOptionsRef.current={mode:"values"};return}if(f.key.length===1&&!f.metaKey&&f.ctrlKey===f.altKey){if(f.ctrlKey&&f.altKey){l.current=!0;return}b.startEdit("replace");return}},A=()=>{const f=a.current;r.current=!0,o.current=!1,f.isEditing()||f.startEdit("replace")},X=f=>{r.current=!1,t.current=f.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},K0),o.current&&(o.current=!1,f.data!==""&&(s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(v,0)))},w=()=>{const f=a.current;if(H(),!f.isEditing()){if(l.current){l.current=!1;const b=M.value;if(b!==""&&(f.startEdit("replace"),f.isEditing())){M.value=b,M.setSelectionRange(b.length,b.length);return}}f.rearmSink()}},G=()=>{l.current=!1;const f=a.current.pendingPasteOptionsRef;f!==void 0&&(f.current=null)},te=()=>{l.current=!1;const f=a.current.pendingPasteOptionsRef;f!==void 0&&(f.current=null),H()};return M.addEventListener("keydown",C),M.addEventListener("keyup",G),M.addEventListener("blur",te),M.addEventListener("compositionstart",A),M.addEventListener("compositionend",X),M.addEventListener("input",w),()=>{M.removeEventListener("keydown",C),M.removeEventListener("keyup",G),M.removeEventListener("blur",te),M.removeEventListener("compositionstart",A),M.removeEventListener("compositionend",X),M.removeEventListener("input",w),n.current!==null&&window.clearTimeout(n.current),s.current!==null&&(window.clearTimeout(s.current),s.current=null),r.current=!1,o.current=!1,H()}},[u,h,g,L])},J0=()=>{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)})}},Z0=4,Q0=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),eC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),a=i.useRef(!1),u=i.useRef({dx:0,dy:0}),h=i.useRef(null),g=i.useRef(0),L=i.useRef(null),M=i.useRef(null),$=i.useRef(!1),H=i.useCallback(E=>h.current!==null?E.pointerId===h.current:E.pointerType==="mouse",[]),Z=i.useCallback((E,P)=>{const{handleRef:j,rowAxis:m,colAxis:d}=t.current,y=j.current,v=s.current;if(y===null||v===null)return null;const{x,y:S}=y.getScrollPosition();if(S<0||x<0||m.totalSize()===0||d.totalSize()===0)return null;const V=t.current.zoomRef.current,C=y.getFrozenSize(),A=y.getViewportSize();return vn({row:Vr(m,(P-v.top)/V,{scroll:S,frozenSize:C.height,trailingSize:C.trailingHeight,extent:A.height}),col:Br(d,(E-v.left)/V,{scroll:x,frozenSize:C.width,trailingSize:C.trailingWidth,extent:A.width})},m.count,d.count)},[]),Q=i.useCallback(E=>{const P=r.current;if(P===null)return me(E,E);const j=me({row:Math.min(P.startRow,E.row),col:Math.min(P.startCol,E.col)},{row:Math.max(P.endRow,E.row),col:Math.max(P.endCol,E.col)}),m=j.startRow!==P.startRow||j.endRow!==P.endRow||j.startCol!==P.startCol||j.endCol!==P.endCol;return o.current=m?j:null,m?j:P},[]),O=i.useCallback(()=>{const E=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,L.current!==null&&(cancelAnimationFrame(L.current),L.current=null),E.xAutoScroller.stop(),E.yAutoScroller.stop(),$.current=!1,a.current=!1,u.current={dx:0,dy:0},E.writeFillPreview(null);const P=M.current;P!==null&&(window.removeEventListener("pointermove",P.move),window.removeEventListener("pointerup",P.up),M.current=null);const j=t.current.handleNodeRef.current;j!==null&&h.current!==null&&j.hasPointerCapture?.(h.current)&&j.releasePointerCapture(h.current),h.current=null,E.repaintOverlay()},[]),D=i.useCallback(()=>{const E=t.current,P=r.current,j=o.current;if(O(),P===null||j===null)return;const m=Om(P,j);if(m>E.maxOperationCells){E.onOperationRejected?.("fill",m,"limit");return}const d=xm(P,j);if(nr(E.adapter,d)){E.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(d),gesture:"fillHandle",sources:[P],targets:d});return}const y=Am((x,S)=>nu(E.adapter,x,S),P,j,ru);if(E.commitEdits(y,{source:"fill"})===null)return;const v=E.getSelection();E.setSelection({ranges:[j],anchor:v.anchor,active:v.active})},[O]),{enabled:W,handleNodeRef:K}=e;return i.useEffect(()=>{const E=K.current;if(!W||E===null)return;const P=v=>{j(v),n.current&&H(v)&&(g.current&1)!==0&&(v.buttons&1)===0&&D()},j=v=>{if(!(n.current&&H(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const x=Math.abs(v.clientX-c.current.clientX),S=Math.abs(v.clientY-c.current.clientY);if(!a.current&&Math.max(x,S)>=Z0&&(a.current=!0),!!a.current){if(!$.current){const V=t.current,C={getPointerPosition:()=>({clientX:l.current.clientX-u.current.dx,clientY:l.current.clientY-u.current.dy}),buildRange:Q,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};V.xAutoScroller.start(C),V.yAutoScroller.start(C),$.current=!0}L.current===null&&(L.current=requestAnimationFrame(()=>{if(L.current=null,!(n.current&&a.current))return;const V=Z(l.current.clientX-u.current.dx,l.current.clientY-u.current.dy);V!==null&&t.current.writeFillPreview(Q(V))}))}},m=v=>{v.button!==0||!(n.current&&H(v))||D()},d=v=>{const x=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),x.focusSink();const S=x.getSelection(),V=S.ranges[S.ranges.length-1];r.current=V,o.current=null,a.current=!1,x.xAutoScroller.stop(),x.yAutoScroller.stop(),$.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,g.current=v.buttons,n.current=!0,x.repaintOverlay(),s.current=x.bodyRef.current?.getBoundingClientRect()??null;const C=s.current,A=x.handleRef.current?.getScrollPosition()??{x:-1,y:-1},X=A.y;if(C!==null&&X>=0&&A.x>=0){const te=A.x,f=x.zoomRef.current,b=x.handleRef.current?.getFrozenSize()??Q0,R=x.handleRef.current?.getViewportSize()??{width:0,height:0},_={scroll:te,frozenCount:b.cols,trailingCount:b.trailingCols,extent:R.width},Y={scroll:X,frozenCount:b.rows,trailingCount:b.trailingRows,extent:R.height},U=Nn(x.colAxis,V.endCol,_)+x.colAxis.sizeOf(V.endCol),oe=Dn(x.rowAxis,V.endRow,Y)+x.rowAxis.sizeOf(V.endRow),ce=U-1,k=V.endCol>=b.cols&&b.width>0?Math.max(ce,b.width):ce,z=!(V.endCol>=x.colAxis.count-b.trailingCols)&&b.trailingWidth>0?Math.min(k,R.width-b.trailingVisibleWidth-1):k,re=oe-1,ge=V.endRow>=b.rows&&b.height>0?Math.max(re,b.height):re,Pe=!(V.endRow>=x.rowAxis.count-b.trailingRows)&&b.trailingHeight>0?Math.min(ge,R.height-b.trailingVisibleHeight-1):ge;u.current={dx:v.clientX-(C.left+z*f),dy:v.clientY-(C.top+Pe*f)}}else u.current={dx:0,dy:0};h.current=v.pointerId;try{E.setPointerCapture(v.pointerId)}catch{h.current=null}const w=P,G=m;M.current={move:w,up:G},window.addEventListener("pointermove",w),window.addEventListener("pointerup",G),x.writeFillPreview(r.current)},y=v=>{!n.current||h.current===null||v.pointerId!==h.current||O()};return E.addEventListener("pointerdown",d),E.addEventListener("lostpointercapture",y),()=>{E.removeEventListener("pointerdown",d),E.removeEventListener("lostpointercapture",y),O()}},[W,K,H,Z,Q,O,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&O()},cancelDrag:O}),[O])},tC=(e,t,n)=>{const r=Object.hasOwn(e.filters,t)?e.filters[t]:void 0;return new Set(r!==void 0&&r.mode==="exact"?r.values:n.map(o=>o.value))},nC=({column:e,columnName:t,state:n,getFilterValues:r,changeState:o,close:s,isInsideGrid:l,relayout:c,labels:a})=>{const u=e.key,h=Object.hasOwn(n.filters,u)?n.filters[u]:void 0,g=n.sort!==null&&n.sort.columnKey===u?n.sort.direction:null,[L,M]=i.useState(()=>h===void 0?e.defaultMatchMode:h.mode),[$,H]=i.useState(()=>h!==void 0&&h.mode==="fuzzy"?h.query:""),[Z,Q]=i.useState(""),[O,D]=i.useState({status:"idle"}),[W,K]=i.useState(()=>new Set),E=i.useRef(!1),P=i.useRef(n);P.current=n;const j=i.useId(),m=i.useId(),d=e.filterable&&L==="exact",y=d||O.status!=="idle";i.useEffect(()=>{if(!y)return;if(r===void 0){D({status:"failed"});return}const z=new AbortController;let re;try{re=Promise.resolve(r(u,P.current,z.signal))}catch{return D({status:"failed"}),()=>z.abort()}return D({status:"loading"}),re.then(ge=>{if(z.signal.aborted)return;let Te;try{Te=v0(ge)}catch{D({status:"failed"});return}D({status:"loaded",values:Te}),K(tC(P.current,u,Te))},()=>{z.signal.aborted||D({status:"failed"})}),()=>z.abort()},[y]);const v=O.status==="loaded"||O.status==="failed"?O.status:"pending",x=i.useRef(!1);i.useLayoutEffect(()=>{if(!x.current){x.current=!0;return}c()},[L,v]);const S=O.status==="loaded"?O.values:null,V=z=>z.label===""?be(a,"filterBlank"):z.label,C=i.useMemo(()=>S===null?[]:S.filter(z=>R0(z.label===""?be(a,"filterBlank"):z.label,Z)),[S,Z,a]),A=C.length>Mo?C.slice(0,Mo):C,X=C.length-A.length,w=S===null?0:S.filter(z=>W.has(z.value)).length,G=z=>{E.current=!0;try{z()}finally{E.current=!1}},te=z=>G(()=>{o(z)}),f=z=>te(m0(n,u,z)),b=()=>{if(L==="fuzzy"){te(C0(n,u,$));return}S===null||w===0||te(w0(n,u,W,S.map(z=>z.value)))},R=z=>{const re=new Set(W);for(const ge of C)z?re.add(ge.value):re.delete(ge.value);K(re)},_=z=>{const re=new Set(W);re.has(z)?re.delete(z):re.add(z),K(re)},Y=z=>{z.key==="Escape"&&(z.preventDefault(),G(()=>s()))},U=z=>{const re=z.relatedTarget;E.current||re instanceof Node&&z.currentTarget.contains(re)||G(()=>s({restoreFocus:re instanceof Node&&l(re)}))},oe=e.filterable&&e.matchModes.length===2,ce=e.sortable?"sort":oe?"mode":L==="exact"?"search":"query",k=z=>ce===z?{"data-aqsp-popover-autofocus":""}:{},B=Object.keys(n.filters).length>0;return I.jsxs("div",{className:"aqsp-popover-column-menu","data-aqsp-popover":"columnMenu",role:"dialog","aria-labelledby":m,onKeyDown:Y,onBlur:U,children:[I.jsx("div",{className:"aqsp-popover-title",id:m,children:t.trim()===""?be(a,"columnMenu"):`${t} ${be(a,"columnMenu")}`}),e.sortable?I.jsxs("div",{className:"aqsp-popover-section aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortAsc","aria-pressed":g==="asc",onClick:()=>f("asc"),...k("sort"),children:be(a,"sortAscending")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortDesc","aria-pressed":g==="desc",onClick:()=>f("desc"),children:be(a,"sortDescending")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortClear",disabled:g===null,onClick:()=>f(null),children:be(a,"sortClear")})]}):null,oe?I.jsxs("fieldset",{className:"aqsp-popover-section aqsp-popover-fieldset",children:[I.jsx("legend",{className:"aqsp-popover-field-label",children:be(a,"filterMatchMode")}),Hu.map(z=>I.jsxs("label",{className:"aqsp-popover-radio",children:[I.jsx("input",{type:"radio",name:j,value:z,"data-aqsp-column-menu-mode":z,checked:L===z,onChange:()=>M(z),...L===z?k("mode"):{}}),be(a,z==="exact"?"filterModeExact":"filterModeFuzzy")]},z))]}):null,d?I.jsxs("div",{className:"aqsp-popover-section",children:[I.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"search","aria-label":be(a,"filterSearchValues"),placeholder:be(a,"filterSearchValues"),value:Z,onChange:z=>Q(z.currentTarget.value),...k("search")}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkAll",disabled:C.length===0,onClick:()=>R(!0),children:be(a,"filterSelectAll")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkNone",disabled:C.length===0,onClick:()=>R(!1),children:be(a,"filterSelectNone")})]}),I.jsxs("fieldset",{className:"aqsp-popover-values","data-aqsp-column-menu-values":"","aria-label":be(a,"filterModeExact"),"aria-busy":O.status==="loading"||O.status==="idle"?"true":void 0,children:[O.status==="failed"?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"failed",role:"alert",children:be(a,"filterLoadFailed")}):S===null?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"loading",children:be(a,"filterLoading")}):A.length===0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"empty",children:be(a,"listEmpty")}):A.map(z=>I.jsxs("label",{className:"aqsp-popover-value",children:[I.jsx("input",{type:"checkbox","data-aqsp-column-menu-value":z.value,checked:W.has(z.value),onChange:()=>_(z.value)}),I.jsx("span",{className:"aqsp-popover-value-text",children:V(z)}),I.jsx("span",{className:"aqsp-popover-value-count",children:z.count})]},z.value)),X>0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"more",children:be(a,"listMore",X)}):null]})]}):null,e.filterable&&L==="fuzzy"?I.jsx("div",{className:"aqsp-popover-section",children:I.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"query","aria-label":be(a,"filterQuery"),placeholder:be(a,"filterQuery"),value:$,onChange:z=>H(z.currentTarget.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),b())},...k("query")})}):null,e.filterable?I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"apply",disabled:L==="exact"&&w===0,onClick:b,children:be(a,"filterApply")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clear",disabled:h===void 0,onClick:()=>te(gl(n,u)),children:be(a,"filterClearColumn")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clearAll",disabled:!B,onClick:()=>te(g0(n)),children:be(a,"filterClearAll")})]}):null]})},rC=320,Oo=8,oC=64,sC=150,Xu=e=>Math.max(0,Math.min(rC,e.width-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX-Oo)),lC=(e,t,n)=>{const r=n.width-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Xu(n),l=Math.max(0,Math.min(t,o-Oo)),c=e.left+e.width,a=e.top+e.height,u=H=>H>=0&&H+s<=r,h=[e.left,c-s],g=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const H of g)if(u(H.left)&&H.top>=0&&H.top+l<=o)return{left:H.left,top:H.top,width:s,height:l};const L=o-a,M=e.top,$=Math.min(l,Math.max(L,M));if($>=oC){const H=L>=M?a:e.top-$;for(const Z of h)if(u(Z))return{left:Z,top:H,width:s,height:$}}return{left:Oo,top:Oo,width:s,height:l}},iC=(e,t,n,r)=>t===null||e!==null&&Dt(e,t)||n?!1:r(t),cC=(e,t)=>{switch(e.kind){case"note":return I.jsx(Ou,{ctx:e,labels:t});case"note-tip":return I.jsx(xu,{ctx:e,labels:t});case"comment":return I.jsx(Ru,{ctx:e,labels:t});case"link":return I.jsx(Su,{ctx:e,labels:t});case"list":return I.jsx(Eu,{ctx:e,labels:t});default:return I.jsx(ku,{ctx:e,labels:t})}},As=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,aC=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o,columnMenu:s})=>{const{context:l,tipContext:c}=e,a=i.useRef(null),u=i.useRef(null),h=i.useRef(c);h.current=c;const g=i.useRef(e);g.current=e;const L=As(l),M=As(c),$=i.useRef(null),H=(E,P)=>{const j=g.current.getLayerSize();E.style.width=`${Xu(j)}px`,E.style.maxHeight="";const m=lC(P,E.offsetHeight,j);E.style.left=`${m.left-P.left}px`,E.style.top=`${m.top-P.top}px`,E.style.maxHeight=`${m.height}px`};i.useLayoutEffect(()=>{const E=a.current;if(E===null||l===null){$.current=null;return}if(H(E,l.anchorRect),l.kind==="message")return;const P=As(l);if($.current===P)return;$.current=P;const j=E.querySelector("[data-aqsp-popover-autofocus]");j!==null?j.focus({preventScroll:!0}):E.focus({preventScroll:!0})},[l]),i.useLayoutEffect(()=>{const E=u.current,P=h.current;E===null||P===null||H(E,P.anchorRect)},[M]);const Z=E=>t===void 0?cC(E,n):t(E),Q=()=>{const E=a.current,P=g.current.context;E!==null&&P!==null&&H(E,P.anchorRect)},O=E=>{if(s==null||E.cell.row!==s.resolved.headerRow)return null;const P=cr(s.resolved,E.cell.col);return P===null?null:I.jsx(nC,{column:P,columnName:s.columnNameOf(E.cell),state:s.state,getFilterValues:s.getFilterValues,changeState:s.changeState,close:e.close,isInsideGrid:s.isInsideGrid,relayout:Q,labels:n})},D=E=>{e.isCompositionKey(E.nativeEvent)&&E.stopPropagation()},W=E=>{E.key==="Escape"&&!E.defaultPrevented&&(E.preventDefault(),e.close())},K=E=>{e.registerCompositionEnd(E.timeStamp)};return I.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:D,onKeyDown:W,onCompositionEnd:K,children:[I.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,children:l===null?null:I.jsx("div",{ref:a,className:"aqsp-popover","data-aqsp-popover-frame":l.kind,tabIndex:-1,children:l.kind==="columnMenu"?O(l):Z(l)},L)}),I.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":c===null?void 0:"",inert:c===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:c===null?null:I.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:Z(c)})})]})},uC=["note","note-tip","comment","link","list","message"],dC=(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}},Tr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&dC(e,n),fC=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),a=i.useRef(null),u=i.useRef(!1),h=i.useRef(null),g=i.useRef(null),L=i.useRef(null),M=i.useRef(null),$=i.useId(),H=i.useCallback(R=>{const _=t.current,Y=_.handleRef.current,U=Y===null?{x:0,y:0}:Y.getScrollPosition(),oe=Y===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:Y.getFrozenSize(),ce=Y===null?{width:0,height:0}:Y.getViewportSize();return{top:Dn(_.rowAxis,R.row,{scroll:Math.max(0,U.y),frozenCount:oe.rows,trailingCount:oe.trailingRows,extent:ce.height}),left:Nn(_.colAxis,R.col,{scroll:Math.max(0,U.x),frozenCount:oe.cols,trailingCount:oe.trailingCols,extent:ce.width}),width:_.colAxis.sizeOf(R.col),height:_.rowAxis.sizeOf(R.row)}},[]),Z=i.useCallback(R=>{const _=t.current;_.anchors.current={..._.anchors.current,...R},_.repaintOverlay()},[]),Q=i.useCallback(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),O=i.useCallback(()=>{const R=t.current.sinkRef.current;if(R===null)return;const _=c.current;_!==null&&Dt(_,t.current.getActive())?R.setAttribute("aria-describedby",$):R.getAttribute("aria-describedby")===$&&R.removeAttribute("aria-describedby")},[$]),D=i.useCallback(()=>(Q(),u.current=!1,c.current===null?!1:(c.current=null,s(null),Z({tip:null}),O(),!0)),[Q,Z,O]),W=i.useCallback(()=>{Q(),h.current=window.setTimeout(()=>{h.current=null,D()},sC)},[Q,D]),K=i.useCallback(R=>{const _=t.current;Q();const Y=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(R.row,R.col);Y===void 0||Y===""||(c.current=R,s({kind:"note-tip",cell:R,anchorRect:H(R),current:Y,close:D}),Z({tip:R}),O())},[H,Q,D,Z,O]),E=i.useCallback(R=>{const _=t.current;if(R===null&&u.current)return;const Y=a.current;a.current=R;const U=c.current;if(U!==null&&R!==null&&Dt(U,R)){Q();return}const oe=ce=>{const k=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(ce.row,ce.col);return k!==void 0&&k!==""};if(iC(Y,R,_.isDraggingAny(),oe)){R!==null&&K(R);return}U!==null&&W()},[K,Q,W]),P=i.useCallback((R,_)=>{const Y=t.current,U=Y.bodyRef.current,oe=Y.handleRef.current;if(U===null||oe===null)return null;const ce=U.getBoundingClientRect(),k=Y.zoomRef.current,B=oe.getScrollPosition(),z=oe.getFrozenSize(),re=oe.getViewportSize();return vn({row:Vr(Y.rowAxis,(_-ce.top)/k,{scroll:Math.max(0,B.y),frozenSize:z.height,trailingSize:z.trailingHeight,extent:re.height}),col:Br(Y.colAxis,(R-ce.left)/k,{scroll:Math.max(0,B.x),frozenSize:z.width,trailingSize:z.trailingWidth,extent:re.width})},Y.rowAxis.count,Y.colAxis.count)},[]),j=i.useCallback(R=>{L.current=R,g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null;const _=L.current;E(_===null?null:"cell"in _?_.cell:P(_.clientX,_.clientY))}))},[E,P]),m=i.useCallback(R=>j({cell:R}),[j]),d=i.useCallback(()=>D(),[D]),y=i.useCallback(R=>{if(l.current===null)return;const _=t.current;l.current=null,r(null),Z({interactive:null}),(R===void 0||R.restoreFocus)&&_.focusSink({preventScroll:!0}),_.isEditing()||_.rearmSink()},[Z]),v=i.useCallback(R=>{l.current=R.kind,r(R),Z({interactive:R.cell})},[Z]),x=i.useCallback(R=>{const _=t.current;return Qa(_.adapter)?{cellReadOnly:nt(_.adapter,R.row,R.col)}:{}},[]),S=i.useCallback((R,_)=>{const Y=t.current;if(nt(Y.adapter,R.cell.row,R.cell.col)){Y.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...R,...x(R.cell)});return}if(Y.commitEdits(_,{source:"annotate"})===null){v({...R,rejected:!0});return}y()},[v,y,x]),V=i.useCallback((R,_)=>{const Y=t.current;if(!Tr(Y.adapter,Y.popovers,R))throw new RangeError(`[spreadsheet] openPopover("${R}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const U=Y.getActive();if(R==="list"&&nt(Y.adapter,U.row,U.col)){Y.rejectReadOnly({kind:"edit",cell:U,editSession:"none"});return}if(R==="note-tip"){K(U);return}if(R==="message"){if(l.current!==null&&l.current!=="message")return;const B=_!==void 0&&_.message!==void 0?_.message:void 0,z=Y.adapter.getCellValidation===void 0?void 0:Y.adapter.getCellValidation(U.row,U.col),re=B!==void 0?B:z===void 0?void 0:z.inputMessage;if(re===void 0)return;const ge=_!==void 0&&_.rejected===!0;v({kind:"message",cell:U,anchorRect:H(U),current:{title:be(Y.labels,"messageTitle"),message:re,rejected:ge},close:y});return}if(Y.isEditing()&&!Y.requestCommit())return;if(R==="list"){const B=Y.adapter.getCellValidation===void 0?void 0:Y.adapter.getCellValidation(U.row,U.col);if(B===void 0||B.type!=="list")return;const z=_!==void 0&&_.typed!==void 0?_.typed:"";D(),Y.focusSink({preventScroll:!0}),v({kind:"list",cell:U,anchorRect:H(U),current:B.values,typed:z,commit:re=>{if(nt(t.current.adapter,U.row,U.col)){t.current.rejectReadOnly({kind:"edit",cell:U,editSession:"none"}),y();return}t.current.commitEdits([{row:U.row,col:U.col,text:re}],{source:"edit",editSession:"discarded"}),y()},close:y});return}if(D(),Y.focusSink({preventScroll:!0}),R==="note"){const B=Y.adapter.getCellNote===void 0?void 0:Y.adapter.getCellNote(U.row,U.col),z={kind:"note",cell:U,anchorRect:H(U),current:B,commit:re=>{S(z,[{row:U.row,col:U.col,note:re}])},close:y,rejected:!1,...x(U)};v(z);return}if(R==="comment"){const B=Y.adapter.getCellComments===void 0?void 0:Y.adapter.getCellComments(U.row,U.col),z={kind:"comment",cell:U,anchorRect:H(U),current:B===void 0?[]:B,commit:re=>{S(z,[{row:U.row,col:U.col,comments:re}])},close:y,rejected:!1,...x(U)};v(z);return}const oe=Y.adapter.getCellHyperlink===void 0?void 0:fr(Y.adapter.getCellHyperlink(U.row,U.col)),ce=Y.adapter.getCellText(U.row,U.col),k={kind:"link",cell:U,anchorRect:H(U),current:{text:ce,url:oe},commit:B=>{const z=B.url===null?null:bn(B.url);if(z===null&&B.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(B.url)}`);const re=B.text===ce?{row:U.row,col:U.col,hyperlink:z}:{row:U.row,col:U.col,text:B.text,hyperlink:z};S(k,[re])},close:y,canOpen:Y.onHyperlinkOpen!==void 0,open:()=>{const B=t.current.onHyperlinkOpen;B!==void 0&&oe!==void 0&&B(oe,U)},rejected:!1,...x(U)};v(k)},[H,y,S,D,v,K,x]),C=i.useCallback(R=>{const _=t.current,Y=_.columnMenuAt===void 0?null:_.columnMenuAt(R);return Y===null||_.isEditing()&&!_.requestCommit()?!1:(D(),_.focusSink({preventScroll:!0}),v({kind:"columnMenu",cell:R,anchorRect:H(R),column:Y}),!0)},[H,D,v]),A=i.useCallback(R=>{l.current==="columnMenu"&&y(R)},[y]),{enabled:X,bodyRef:w}=e;i.useEffect(()=>{const R=w.current;if(!X||R===null)return;const _=U=>{const oe=t.current;Tr(oe.adapter,oe.popovers,"note-tip")&&j({clientX:U.clientX,clientY:U.clientY})},Y=()=>{Tr(t.current.adapter,t.current.popovers,"note-tip")&&j({cell:null})};return R.addEventListener("pointermove",_),R.addEventListener("pointerleave",Y),()=>{R.removeEventListener("pointermove",_),R.removeEventListener("pointerleave",Y)}},[X,w,j]),i.useEffect(()=>()=>{g.current!==null&&cancelAnimationFrame(g.current),h.current!==null&&window.clearTimeout(h.current)},[]);const{adapter:G,popovers:te}=e,f=e.columnMenuAt!==void 0,b=i.useMemo(()=>f||uC.some(R=>Tr(G,te,R)),[G,te,f]);return i.useMemo(()=>({layerEnabled:b,isKindEnabled:R=>Tr(t.current.adapter,t.current.popovers,R),open:V,close:y,isOpen:()=>l.current,openColumnMenu:C,closeColumnMenu:A,onCellHover:m,hideTip:d,onTipPointerEnter:()=>{u.current=!0,Q()},onTipPointerLeave:()=>{u.current=!1,c.current!==null&&W()},syncTipAriaDescribedBy:O,context:n,tipContext:o,registerCompositionEnd:R=>{M.current=R},isCompositionKey:R=>Yu(R,M.current),getLayerSize:()=>{const R=t.current.handleRef.current;return R===null?{width:0,height:0}:R.getViewportSize()},tipId:$}),[b,V,y,C,A,m,d,Q,W,O,n,o,$])},pC=6,hC=500,Jn=(e,t)=>Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))>=pC,Ts=(e,t)=>e!==null&&Dt(e,t),mC=(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},Us=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const u=e.getFrozenSize(),h=e.getViewportSize();return vn({row:Vr(n,(l-t.top)/o,{scroll:a,frozenSize:u.height,trailingSize:u.trailingHeight,extent:h.height}),col:Br(r,(s-t.left)/o,{scroll:c,frozenSize:u.width,trailingSize:u.trailingWidth,extent:h.width})},n.count,r.count)},gC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),a=i.useRef(0),u=i.useRef(null),h=i.useRef(!1),g=i.useRef(null),L=i.useRef(""),M=i.useRef(!1),$=i.useRef(!1),H=i.useRef(null),Z=i.useRef(null),Q=i.useRef(null),O=i.useRef(null),D=i.useCallback((v,x)=>{const{handleRef:S,rowAxis:V,colAxis:C,zoomRef:A}=t.current;return Us(S.current,o.current,V,C,A.current,v,x)},[]),W=i.useRef(!1),K=i.useRef(null),E=i.useRef(null),P=i.useRef({clientX:0,clientY:0}),j=i.useCallback(()=>{const{autoScroller:v,bodyRef:x,onDragFrame:S}=t.current;n.current=!1,r.current=null,u.current=null,W.current=!1,K.current=null,E.current=null,h.current=!1,g.current=null,H.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),v.stop();const V=x.current;V!==null&&c.current!==null&&V.hasPointerCapture?.(c.current)&&V.releasePointerCapture(c.current),c.current=null,S(null),t.current.repaintOverlay()},[]),m=i.useCallback(()=>{if(!n.current)return;const v=r.current;v!==null&&t.current.setSelection(v),j()},[j]),{enabled:d,bodyRef:y}=e;return i.useEffect(()=>{const v=y.current;if(!d||v===null)return;const x=k=>k instanceof Element&&k.closest("[data-aqsp-cells]")!==null,S=(k,B)=>{const{handleRef:z,rowAxis:re,colAxis:ge,zoomRef:Te}=t.current;return Us(z.current,v.getBoundingClientRect(),re,ge,Te.current,k,B)},V=()=>{Q.current=null,O.current!==null&&(window.clearTimeout(O.current),O.current=null)},C=(k,B)=>{const z=t.current,re=z.getSelection();re.ranges.some(Te=>Vt(Te,k))||z.setSelection(ar(re,k,{extend:!1,append:!1})),z.onContextMenuSelect(k,B)},A=(k,B)=>{const z=t.current;if(!z.isAnyDragging()){if(z.isEditing()&&!z.requestCommit()){z.focusSink();return}z.focusSink(),C(k,B)}},X=(k,B)=>{rt.didPressStopScrollMotion(k)||(k.preventDefault(),Q.current={pointerId:k.pointerId,cell:B,clientX:k.clientX,clientY:k.clientY,event:k},O.current=window.setTimeout(()=>{O.current=null;const z=Q.current;z!==null&&(Q.current=null,A(z.cell,z.event))},hC))},w=k=>{const B=t.current,z=B.onRequestTouchEdit;if(z===void 0||B.isAnyDragging())return;if(B.getPointing?.()){B.focusSink();return}const re=Dt(B.getSelection().active,k);if(B.isEditing()){if(re||!B.requestCommit()){B.focusSink();return}}else if(re){z(k);return}B.setSelection(ar(B.getSelection(),k,{extend:!1,append:!1})),B.focusSink()},G=k=>{const B=t.current;if(Z.current=null,V(),k.pointerType==="mouse"&&k.button===0&&(h.current=!1,g.current=null,$.current=!1,H.current=null),M.current=x(k.target),!M.current){if(k.pointerType==="mouse"){if(k.preventDefault(),k.button!==0)return;if(B.getPointing?.()){B.focusSink();return}if(B.isEditing()&&!B.requestCommit()){k.stopPropagation(),B.focusSink();return}B.focusSink()}return}if(L.current=k.pointerType,k.pointerType!=="mouse"){if(B.isSortHeaderCell===void 0&&B.onRequestTouchEdit===void 0)return;const Xe=S(k.clientX,k.clientY);if(Xe===null)return;if(B.isSortHeaderCell?.(Xe)===!0){k.preventDefault(),Z.current={pointerId:k.pointerId,pointerType:k.pointerType,cell:Xe,clientX:k.clientX,clientY:k.clientY};return}B.onRequestTouchEdit!==void 0&&X(k,Xe);return}if(k.button!==0){k.preventDefault();return}if((B.pointDragRef===void 0?null:B.pointDragRef.current)?.onPointerDown(k))return;if(B.isEditing()&&!B.requestCommit()){k.preventDefault(),B.focusSink();return}o.current=v.getBoundingClientRect();const re=D(k.clientX,k.clientY);if(re===null)return;if(k.preventDefault(),B.focusSink(),(k.ctrlKey||k.metaKey)&&!k.shiftKey&&B.openHyperlinkAt?.(re)===!0){$.current=!0;return}const ge=B.getSelection();r.current=ge;const Te=k.shiftKey,Pe=k.ctrlKey||k.metaKey,ot=Pe&&!Te&&ge.ranges.some(Xe=>Vt(Xe,re));h.current=ot,g.current=ot?re:null,ot||B.setSelection(ar(ge,re,{extend:Te,append:Pe})),!(Te||Pe||k.altKey)&&B.isSortHeaderCell?.(re)===!0&&(H.current={cell:re,clientX:k.clientX,clientY:k.clientY}),n.current=!0,B.repaintOverlay(),s.current={clientX:k.clientX,clientY:k.clientY},c.current=k.pointerId,a.current=k.buttons;try{v.setPointerCapture(k.pointerId)}catch{c.current=null}const je=ot?re:B.getSelection().anchor;u.current=Xe=>me(je,Xe),K.current=je.col,E.current=je.row,B.autoScroller.stop(),W.current=!1,P.current={clientX:k.clientX,clientY:k.clientY}},te=k=>c.current!==null?k.pointerId===c.current:k.pointerType==="mouse",f=k=>{if(!(n.current&&te(k)))return;s.current={clientX:k.clientX,clientY:k.clientY};const B=H.current;if(B!==null&&Jn(B,k)&&(H.current=null),!W.current&&u.current!==null){const z=Math.abs(k.clientX-P.current.clientX),re=Math.abs(k.clientY-P.current.clientY);Math.max(z,re)>=No&&(W.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:u.current,anchorCol:K.current??void 0,anchorRow:E.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const z=u.current;if(!n.current||z===null)return;const re=t.current,ge=D(s.current.clientX,s.current.clientY);ge!==null&&re.onDragFrame(z(ge))}))},b=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&Jn(B,k)&&(Z.current=null);const z=Q.current;z!==null&&k.pointerId===z.pointerId&&Jn(z,k)&&V(),f(k),n.current&&te(k)&&(a.current&1)!==0&&(k.buttons&1)===0&&Y(k)},R=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&(Z.current=null,!Jn(B,k)&&Ts(S(k.clientX,k.clientY),B.cell)&&t.current.onHeaderSortPress?.(B.cell.col,B.pointerType));const z=Q.current;if(z!==null&&k.pointerId===z.pointerId&&(V(),!Jn(z,k)&&Ts(S(k.clientX,k.clientY),z.cell)&&w(z.cell)),k.button!==0||!(n.current&&te(k)))return;const re=H.current,ge=re!==null&&!Jn(re,k)&&Ts(D(k.clientX,k.clientY),re.cell);Y(k),ge&&t.current.onHeaderSortPress?.(re.cell.col,k.pointerType)},_=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&(Z.current=null);const z=Q.current;z!==null&&k.pointerId===z.pointerId&&V()},Y=k=>{const B=t.current,z=D(k.clientX,k.clientY);if(z!==null){const re=g.current;h.current&&re!==null?B.setSelection(Wu(B.getSelection(),me(re,z),re)):B.setSelection(Mn(B.getSelection(),z))}j()},U=k=>{!n.current||c.current===null||k.pointerId!==c.current||m()},oe=k=>{const B=t.current;if(!x(k.target))return;if(L.current!=="mouse"){B.onRequestTouchEdit!==void 0&&k.preventDefault();return}if(B.isAnyDragging())return;if(B.isEditing()&&!B.requestCommit()){B.focusSink();return}B.focusSink(),o.current=v.getBoundingClientRect();const z=D(k.clientX,k.clientY);z!==null&&C(z,k)},ce=k=>{const B=t.current;if(!M.current||L.current!=="mouse"||B.getPointing?.()||$.current)return;o.current=v.getBoundingClientRect();const z=D(k.clientX,k.clientY);z!==null&&Dt(B.getSelection().active,z)&&B.onRequestEdit(z,B.caretFromPointEnabled(z)?mC(k.clientX,k.clientY,z):void 0)};return v.addEventListener("pointerdown",G),v.addEventListener("pointermove",b),v.addEventListener("pointerup",R),v.addEventListener("pointercancel",_),v.addEventListener("lostpointercapture",U),v.addEventListener("contextmenu",oe),v.addEventListener("dblclick",ce),()=>{v.removeEventListener("pointerdown",G),v.removeEventListener("pointermove",b),v.removeEventListener("pointerup",R),v.removeEventListener("pointercancel",_),v.removeEventListener("lostpointercapture",U),v.removeEventListener("contextmenu",oe),v.removeEventListener("dblclick",ce),V(),j()}},[d,y,D,j,m]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>h.current?"subtract":"add",abortDrag:m,cancelDrag:j}),[m,j])},wC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),h=i.useRef(null),g=i.useRef(null),L=i.useRef(!1),M=i.useCallback((D,W)=>{const{handleRef:K,rowAxis:E,colAxis:P,zoomRef:j}=t.current;return Us(K.current,o.current,E,P,j.current,D,W)},[]),$=i.useCallback(()=>{const{autoScroller:D,bodyRef:W,onDragFrame:K}=t.current;n.current=!1,r.current=null,h.current=null,g.current=null,L.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),D.stop();const E=W.current;E!==null&&a.current!==null&&E.hasPointerCapture?.(a.current)&&E.releasePointerCapture(a.current),a.current=null,K(null)},[]),H=i.useCallback(()=>{if(!n.current)return;const D=r.current;D!==null&&t.current.restoreSink(D),$()},[$]),Z=i.useCallback(D=>{const W=t.current,K=W.bodyRef.current;if(!W.enabled||K===null||!W.getPointing())return!1;o.current=K.getBoundingClientRect();const E=M(D.clientX,D.clientY);if(E===null)return o.current=null,!1;const P=W.captureSink();if(P===null)return o.current=null,!1;D.preventDefault(),W.focusSink(),r.current=P,g.current=E,W.insertReference(E,"cells"),n.current=!0,s.current={clientX:D.clientX,clientY:D.clientY},l.current={clientX:D.clientX,clientY:D.clientY},a.current=D.pointerId,u.current=D.buttons;try{K.setPointerCapture(D.pointerId)}catch{a.current=null}return h.current=j=>{const m=me(E,j);return t.current.insertReference(m,"cells"),m},W.autoScroller.stop(),L.current=!1,W.onDragFrame(me(E,E)),!0},[M]),{enabled:Q,bodyRef:O}=e;return i.useEffect(()=>{const D=O.current;if(!Q||D===null)return;const W=j=>a.current!==null?j.pointerId===a.current:j.pointerType==="mouse",K=j=>{if(!(n.current&&W(j)))return;s.current={clientX:j.clientX,clientY:j.clientY};const m=h.current,d=g.current;if(!L.current&&m!==null&&d!==null){const y=Math.abs(j.clientX-l.current.clientX),v=Math.abs(j.clientY-l.current.clientY);Math.max(y,v)>=No&&(L.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m,anchorCol:d.col,anchorRow:d.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=h.current;if(!n.current||y===null)return;const v=M(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(y(v))})),(u.current&1)!==0&&(j.buttons&1)===0&&$()},E=j=>{j.button!==0||!(n.current&&W(j))||$()},P=j=>{!n.current||a.current===null||j.pointerId!==a.current||$()};return D.addEventListener("pointermove",K),D.addEventListener("pointerup",E),D.addEventListener("lostpointercapture",P),()=>{D.removeEventListener("pointermove",K),D.removeEventListener("pointerup",E),D.removeEventListener("lostpointercapture",P),$()}},[Q,O,M,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:H,cancelDrag:$,onPointerDown:Z}),[H,$,Z])},CC=Object.freeze({width:0,height:0}),$s=33,yC=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,bC=(e,t,n)=>{const r=(n-t)/($s-1);let o=-1,s=-1;for(let c=0;c<$s;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,a)=>{let u=c,h=a;for(;Math.abs(h-u)>1;){const g=(u+h)/2;e(g)?h=g:u=g}return h};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===$s-1?n:l(t+r*(s+1),t+r*s)}},vC=e=>{if(e===void 0)return!1;if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the options must be an object (got ${String(e)})`);const{scroll:t}=e;if(t!==void 0&&t!==!0&&t!==!1)throw new RangeError(`[spreadsheet] setSelection: options.scroll must be true, false or absent (got ${String(t)})`);return t===!0},RC=(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})`)},SC=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)})`)},EC=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)})`)},kC=Object.freeze({showArrowButtons:!0,enableThumbDrag:!0,enableTrackClick:!0}),OC=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(kC)){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)})`)}}},Yc=(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},xC=24,AC=200,Uu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Xc=5,TC=/^#[0-9A-Fa-f]{6}$/,$C=Object.freeze({row:!1,column:!1,intersection:!1}),Uc=Object.freeze({ok:!0}),Gc=(e,t)=>{if(t===void 0)return Uu;if(t.length!==Xc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Xc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!TC.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},MC=e=>{for(const t of["row","column","intersection"])if(lt(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},LC=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return vu},zC=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},NC=e=>{const t=i.useRef(null),n=t.current;return n!==null&&rt.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Zn={ranges:[me({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},DC=i.forwardRef(function({adapter:t,headerRows:n=0,sortFilter:r,readOnly:o=!1,labelledBy:s,defaultRowHeight:l=xC,defaultColumnWidth:c=Fe.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:a=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:g=0,tapScrollCircleOptions:L,scrollBarControls:M,overscanRows:$,overscanCols:H,background:Z,onRenderTruncated:Q,renderCell:O,onSelectionChange:D,onEditSessionChange:W,onCellContextMenu:K,onUndoRequest:E,onRedoRequest:P,onCopyMultiRange:j,onOperationRejected:m,onEditRejected:d,onReadOnlyRejected:y,formatReadOnlyAnnouncement:v,dataVersion:x,maxOperationCells:S=Fe.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:V=!0,enableResizeUI:C=!0,touchEditing:A=!1,headings:X=!0,onContentSizeChange:w,frame:G,formatCellAnnouncement:te,formatSelectionAnnouncement:f,formatCommandAnnouncement:b,formatResizeAnnouncement:R,locale:_,labels:Y,shortcuts:U,onCommandBlockedWhileEditing:oe,colors:ce,formats:k,highlight:B,defaultHighlight:z,onHighlightChange:re,highlightColors:ge,popovers:Te,renderPopover:Pe,onClipChange:ot,onHyperlinkOpen:je,onValidationRejected:Xe,onPasteSpecialRequest:Oe,onClipboardUnavailable:Ie,onPasteResolved:Be,now:Et=Date.now,zoom:it,defaultZoom:on,onZoomChange:Ze,testId:kt,className:Rn,__onCellRender:Io,__onVirtualKeyboardRaise:Sn,__maxRenderedCells:Ft},Wr){const ae=i.useMemo(()=>o?bm(t):t,[t,o]),ye=Lc(ae.rowCount,l),ve=Lc(ae.colCount,c),Fn=i.useRef(null);Fn.current===null&&(Fn.current=J0());const ze=Fn.current,qn=rt.resolveVirtualScrollLocale(_),Qe=i.useMemo(()=>au(_,Y),[_,Y]),sn=NC(Gm(Qe)),Wt=i.useMemo(()=>Hm(U),[U]),Pn=i.useMemo(()=>{if(!C)return;const N=[...Wt].filter(([,ee])=>ys.includes(ee)).sort(([,ee],[,se])=>ys.indexOf(ee)-ys.indexOf(se)).map(([ee])=>Fm(ee)).filter(ee=>ee!==null);return N.length===0?void 0:N.join(" ")},[Wt,C]),_n=i.useMemo(()=>({fill:Gc("fill",ce===void 0?void 0:ce.fill),font:Gc("font",ce===void 0?void 0:ce.font)}),[ce]),pr=i.useMemo(()=>ge===void 0?void 0:MC(ge),[ge]);if(ae.getConditionalFormats!==void 0&&ae.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");RC(n,u),SC(s),EC(G),OC(M);const hr=i.useCallback(()=>ze.get().editVersion,[ze]),mr=i.useCallback(p=>ze.subscribeCoalesced(p),[ze]),Ho=i.useSyncExternalStore(mr,hr,hr)+(x===void 0?0:x),gr=ae.getConditionalFormats===void 0?null:ae.getConditionalFormats(),jn=i.useMemo(()=>({index:gr===null?null:_u(gr),memo:hl()}),[ae,gr,Ho]),wr=i.useRef(jn.index);wr.current=jn.index;const ln=i.useRef(jn.memo);ln.current=jn.memo;const cn=i.useCallback((p,N,ee)=>ml(ae,wr.current,ln.current,p,N,ee),[ae]),Ve=i.useRef(null),[T,F]=i.useState(()=>Fe.clampSpreadsheetZoom(on??1)),J=Fe.clampSpreadsheetZoom(it??T),q=i.useRef(J);q.current=J;const ne=i.useRef(J);ne.current=J;const ie=i.useRef(null),fe=i.useRef(Ze);fe.current=Ze;const Ne=i.useRef(it!==void 0);Ne.current=it!==void 0;const $e=i.useCallback(p=>{const N=Fe.clampSpreadsheetZoom(p);N!==ne.current&&(ne.current=N,Ne.current||F(N),fe.current?.(N))},[]),ue=ae.rowCount===0||ae.colCount===0,We=!ue,Ke=ae.colCount,Ae=i.useMemo(()=>r===void 0||ue?null:f0(r,Ke,n),[r,ue,Ke,n]),we=i.useRef(r);we.current=r;const de=i.useRef(Ae);de.current=Ae,i.useEffect(()=>{const p=Ve.current;if(!We||p===null)return;const N=se=>{se.defaultPrevented||!se.altKey||se.ctrlKey||se.metaKey||se.shiftKey||se.deltaY!==0&&(se.preventDefault(),se.stopPropagation(),!ie.current?.()&&$e(Fe.stepSpreadsheetZoom(ne.current,se.deltaY<0?1:-1)))},ee=se=>{if(se.defaultPrevented||!(se.ctrlKey&&se.altKey)||se.metaKey||se.getModifierState("AltGraph"))return;const Ce=se.key==="="||se.key==="+"?Fe.stepSpreadsheetZoom(ne.current,1):se.key==="-"?Fe.stepSpreadsheetZoom(ne.current,-1):se.key==="0"?1:null;Ce!==null&&(se.preventDefault(),se.stopPropagation(),!ie.current?.()&&$e(Ce))};return p.addEventListener("wheel",N,{passive:!1,capture:!0}),p.addEventListener("keydown",ee,!0),()=>{p.removeEventListener("wheel",N,{capture:!0}),p.removeEventListener("keydown",ee,!0)}},[$e,We]);const pe=i.useRef(null),Re=i.useRef(null),Se=i.useRef(null),ct=i.useRef(null),le=i.useRef(null),Me=i.useRef(null),mt=i.useRef(null),at=i.useRef(0),ut=i.useRef(null),Le=i.useRef(0),dt=i.useRef(null),Kt=i.useRef(null),gt=i.useRef(null),Ye=i.useRef(null),qt=i.useRef(null),In=i.useRef(null),Kr=i.useRef(null),[En,Bo]=i.useState(Zn),Pt=i.useRef(En),Yt=i.useCallback(()=>Pt.current,[]),[Gu,Ju]=i.useState(()=>z===void 0?$C:z),Hn=B!==void 0?B:Gu,Vo=i.useRef(Hn);Vo.current=Hn;const Zu=LC(pr,Hn),yl=i.useRef(B!==void 0);yl.current=B!==void 0;const bl=i.useRef(re);bl.current=re;const Qu=i.useCallback(p=>{yl.current||Ju(p),bl.current?.(p)},[]),vl=i.useRef(null),Wo=i.useRef(null),Xt=i.useRef(null),Ko=i.useRef(()=>!1),Rl=i.useRef(()=>{}),Sl=i.useRef(()=>null),El=i.useRef(()=>{}),kn=i.useCallback(()=>Ko.current(),[]),Yo=i.useMemo(()=>({getPointing:()=>Ko.current(),insertReference:(p,N)=>Rl.current(p,N)}),[]),kl=i.useRef(Qt),Ol=i.useRef(null),Xo=i.useRef({interactive:null,tip:null}),xl=i.useRef(null),Al=i.useRef(null),Yr=i.useRef(()=>{}),Tl=i.useRef(()=>!1),wt=i.useRef(null),Cr=i.useCallback(()=>{const p=wt.current;if(p===null||p.isOpen()!=="message")return!1;const N=p.context;return N===null||N.kind!=="message"||!N.current.rejected?!1:(p.close(),!0)},[]),Uo=i.useRef(()=>!1),$l=i.useRef(()=>!1),Ml=i.useRef(null),Go=i.useRef(()=>Promise.resolve("rejected")),De=i.useCallback(()=>{vl.current?.()},[]),Ot=i.useCallback(p=>{Me.current?.focus(p)},[]),Ue=i.useCallback(()=>{Ot({preventScroll:!0})},[Ot]),Jo=i.useRef(!1),ed=i.useCallback(()=>{const p=Ve.current;if(p!==null){Jo.current=!0;try{p.focus()}finally{Jo.current=!1}}},[]),ft=i.useCallback(()=>{const p=Me.current;p!==null&&(p.value=" ",p.setSelectionRange(0,1))},[]),Bn=i.useCallback((p,N)=>{if(p===null)return;const ee=N?"":"none";p.style.display!==ee&&(p.style.display=ee)},[]),xt=i.useCallback(()=>{const p=mt.current;if(p!==null){const ee=Math.max(0,le.current?.getScrollPosition().y??0),se=le.current?.getFrozenSize().height??0;p.style.transform=`translateY(${at.current-ee-se}px)`}const N=le.current;if(N!==null&&(qt.current!==null||In.current!==null)){const ee=N.getFrozenSize();Bn(qt.current,ee.height>0),Bn(In.current,ee.trailingHeight>0)}},[Bn]),At=i.useCallback(()=>{const p=ut.current;if(p!==null){const ee=Math.max(0,le.current?.getScrollPosition().x??0),se=le.current?.getFrozenSize().width??0;p.style.transform=`translateX(${Le.current-ee-se}px)`}const N=le.current;if(N!==null&&(gt.current!==null||Ye.current!==null)){const ee=N.getFrozenSize();Bn(gt.current,ee.width>0),Bn(Ye.current,ee.trailingWidth>0)}},[Bn]),yr=i.useRef(null),Vn=i.useCallback(()=>{gt.current===null&&Ye.current===null&&qt.current===null&&In.current===null||yr.current===null&&(yr.current=requestAnimationFrame(()=>{yr.current=null,xt(),At(),De()}))},[xt,At,De]);i.useEffect(()=>()=>{yr.current!==null&&cancelAnimationFrame(yr.current)},[]);const Zo=i.useRef(null),Qo=i.useRef(null);(Zo.current===null||Qo.current?.rowAxis!==ye||Qo.current?.colAxis!==ve)&&(Qo.current={rowAxis:ye,colAxis:ve},Zo.current=V0({handleRef:le,rowAxis:ye,colAxis:ve}));const Xr=i.useCallback(p=>{const N=le.current,ee=N===null?{x:0,y:0}:N.getScrollPosition(),se=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),Ce=N===null?{width:0,height:0}:N.getViewportSize(),ke=q.current;return{top:Dn(ye,p.row,{scroll:Math.max(0,ee.y),frozenCount:se.rows,trailingCount:se.trailingRows,extent:Ce.height})*ke,left:Nn(ve,p.col,{scroll:Math.max(0,ee.x),frozenCount:se.cols,trailingCount:se.trailingCols,extent:Ce.width})*ke,width:ve.sizeOf(p.col)*ke,height:ye.sizeOf(p.row)*ke}},[ye,ve]),Ll=i.useCallback(p=>{const N=ct.current,ee=Ve.current,se=Re.current;if(N===null||ee===null||se===null||le.current===null)return;const Ce=q.current,ke=Xr(p),tt=se.offsetTop*Ce+ke.top,ht=se.offsetLeft*Ce+ke.left,Je=Math.max(0,tt),Ht=Math.max(0,ht),dn=Math.min(ee.clientHeight,tt+ke.height),to=Math.min(ee.clientWidth,ht+ke.width);if(dn<=Je||to<=Ht)return;N.style.top=`${Je}px`,N.style.left=`${Ht}px`,N.style.width=`${to-Ht}px`,N.style.height=`${dn-Je}px`;const Xn=N.getBoundingClientRect();Xn.width===0&&Xn.height===0||N.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Xr]),_t=i.useCallback(p=>{Zo.current?.(p),Ll(p)},[Ll]),td=i.useCallback(()=>{const p=le.current,N=p===null?-1:p.getViewportSize().height,ee=pe.current,se=Ve.current;if(N<=0||ee===null||se===null)return N;const Ce=ee.getBoundingClientRect(),ke=se.getRootNode();if(Ce.height<=0||ee.offsetHeight<=0||!yC(ke))return N;const tt=se.ownerDocument.documentElement,ht=Math.max(Ce.left,0),Je=Math.min(Ce.right,tt.clientWidth),Ht=Math.max(Ce.top,0)+.5,dn=Math.min(Ce.bottom,tt.clientHeight)-.5,to=(ht+Je)/2,Xn=Je>ht&&dn>=Ht?bC(qd=>{const wi=ke.elementFromPoint(to,qd);return wi!==null&&se.contains(wi)},Ht,dn):null,Fd=Xn===null?tt.clientHeight:Xn.bottom-Xn.top+1;return Math.min(N,Fd*(ee.offsetHeight/Ce.height))},[]),zl=i.useRef(w);zl.current=w;const es=i.useRef(null),Ut=i.useCallback(()=>{const p=zl.current;if(p===void 0)return;const N=Re.current;let ee;if(N===null)ee=CC;else{if(N.getClientRects().length===0)return;{const Ce=Se.current,ke=q.current;ee={width:((Ce===null?0:Ce.offsetWidth)+ve.totalSize()+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke,height:((Ce===null?0:Ce.offsetHeight)+ye.totalSize()+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke}}}const se=es.current;se!==null&&se.width===ee.width&&se.height===ee.height||(es.current=ee,p(ee))},[ye,ve]);i.useLayoutEffect(()=>{if(w===void 0){es.current=null;return}Ut()});const Nl=w!==void 0;i.useEffect(()=>{const p=Re.current;if(!Nl||p===null)return;const N=new ResizeObserver(()=>Ut());return N.observe(p),()=>N.disconnect()},[Nl,Ut,ue]);const Wn=i.useRef(null),On=i.useRef(null),Kn=i.useCallback(p=>{Wn.current!==null&&window.clearTimeout(Wn.current),On.current!==null&&(cancelAnimationFrame(On.current),On.current=null),Wn.current=window.setTimeout(()=>{Wn.current=null;const N=Kr.current;N!==null&&(N.textContent="",On.current=requestAnimationFrame(()=>{On.current=null,N.textContent=p}))},AC)},[]);i.useEffect(()=>()=>{Wn.current!==null&&window.clearTimeout(Wn.current),On.current!==null&&cancelAnimationFrame(On.current)},[]);const Yn=i.useCallback(p=>{y?.(p),v!==void 0&&Kn(v(p))},[y,v,Kn]),Dl=i.useCallback((p,N)=>{if(te===void 0&&f===void 0)return;const ee=N.ranges[N.ranges.length-1],se=St(ee),Ce=N.ranges.length===1&&se.rows===1&&se.cols===1,ke=p.ranges[p.ranges.length-1],tt=p.ranges.length!==N.ranges.length||ke.startRow!==ee.startRow||ke.startCol!==ee.startCol||ke.endRow!==ee.endRow||ke.endCol!==ee.endCol,ht=()=>{if(te!==void 0){const Je=N.active,Ht=ae.getCellText(Je.row,Je.col),dn=ae.getCellFormat===void 0?void 0:cn(Je.row,Je.col,()=>Ht);Kn(te({row:Je.row,col:Je.col,text:Ht,displayText:Ln(Ht,dn===void 0?void 0:dn.value),columnName:Fe.columnIndexToName(Je.col),...Qa(ae)?{readOnly:nt(ae,Je.row,Je.col)}:{}}))}};if(Ce){ht();return}if(tt){f!==void 0&&Kn(f({range:ee,anchor:N.anchor,active:N.active,rangeRowCount:se.rows,rangeColCount:se.cols,rangeCount:N.ranges.length}));return}ht()},[ae,te,f,Kn,cn]),an=i.useCallback((p,N)=>{const ee=Pt.current;Object.is(p,ee)||_0(p,ee)||(Pt.current=p,Bo(p),D?.(p,N),Dl(ee,p),(Xt.current?.()??!1)||ft())},[D,Dl,ft]),Tt=i.useCallback(p=>an(p,"user"),[an]),nd=i.useCallback(p=>{const N=Pt.current;if(p.mode==="cycle"){const se=Ku(N,p.direction);Tt(se),_t(se.active);return}const ee=vn(p.cell,ye.count,ve.count);if(p.mode==="extend"){Tt(Mn(N,ee)),_t(ee);return}Tt(ar(N,ee,{extend:!1,append:!1})),_t(ee)},[Tt,_t,ye,ve]),Ge=i.useCallback(()=>Xt.current?.()??!1,[]),Fl=i.useRef(null),et=i.useCallback(()=>Fl.current?.()??!0,[]),ql=i.useRef(null),br=i.useCallback((p,N)=>{const ee=Xt.current?.()??!1;ql.current?.(p,N),!ee&&(Xt.current?.()??!1)&&Cr()},[Cr]),[rd,ts]=i.useState(!1),Ur=i.useCallback(()=>{Sn?.(),ts(!0)},[Sn]),ns=rd&&!ue?Vc(En,ae.rowCount,ae.colCount).active:null,od=ns===null?"none":Cm(ae,ns.row,ns.col),Pl=i.useCallback(()=>{Ve.current?.focus({preventScroll:!0})},[]),Gr=i.useCallback((p,N,ee)=>{nt(ae,p.row,p.col)||ee(),br("edit",N)},[ae,br]),sd=i.useCallback((p,N)=>{Gr(p,N,Ur)},[Gr,Ur]),_l=i.useCallback(()=>{Pd.flushSync(Ur),Pl()},[Ur,Pl]),ld=i.useCallback(p=>{Gr(p,void 0,_l)},[Gr,_l]),jl=i.useRef(null),Jr=i.useCallback(()=>jl.current?.()??null,[]),Il=i.useRef(null),Ct=i.useCallback(()=>{Il.current?.()},[]),Hl=i.useRef(null),Bl=i.useCallback(p=>{Hl.current?.(p)},[]),Vl=i.useRef(()=>{}),Zr=i.useCallback(p=>{const N=we.current;return N===void 0||!et()?!1:(wt.current?.hideTip(),wt.current?.close(),Ct(),b0(N.state,p)||N.onStateChange(p),!0)},[et,Ct]),id=i.useCallback((p,N)=>{const ee=we.current,se=de.current,Ce=se===null?null:cr(se,p);ee!==void 0&&Ce?.sortable===!0&&Zr(h0(ee.state,Ce.key)),N!=="mouse"&&Ot({preventScroll:!0})},[Zr,Ot]),Wl=i.useCallback(p=>{const N=wt.current,ee=de.current;if(N===null||ee===null)return;const se=N.context;if(se!==null&&se.kind==="columnMenu"&&se.cell.col===p){N.close();return}N.openColumnMenu({row:ee.headerRow,col:p})},[]),Kl=i.useCallback(p=>{const N=ae.getCellText(p.row,p.col);return Bu(ae.getCellFormat===void 0?N:Ln(N,ae.getCellFormat(p.row,p.col)?.value))},[ae]),Yl=i.useCallback(p=>Ve.current?.contains(p)===!0,[]),cd=i.useMemo(()=>{if(Ae===null||!Ae.columns.some(N=>N?.sortable===!0))return;const p=Ae;return N=>N.row===p.headerRow&&p.columns[N.col]?.sortable===!0},[Ae]),rs=i.useMemo(()=>{if(Ae===null||!Ae.hasControls)return;const p=Ae;return N=>N.row===p.headerRow?cr(p,N.col):null},[Ae]),Qr=i.useRef(0),xn=i.useCallback((p,N,ee)=>{let se;if(N.source==="paste"){const Ce=zC(ee);if(p.length===0&&Ce.conditionalFormats.length===0)return null;Qr.current+=1,se={transaction:Qr.current,source:"paste",sameSheet:Ce.sameSheet,conditionalFormats:Ce.conditionalFormats}}else{if(p.length===0)return null;Qr.current+=1,se={transaction:Qr.current,source:N.source}}try{ae.applyEdits(p,se)}catch(Ce){return d?.(Ce,N),null}return ze.bumpEdit(),Bl(N.source),se.transaction},[ae,ze,d,Bl]),ad=i.useCallback((p,N)=>xn(p,{source:"paste"},N),[xn]),ud=i.useCallback(p=>{ze.setVy(p.y),xt(),At(),De()},[ze,xt,At,De]),Xl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),dd=i.useCallback(p=>{ze.setRowRange(p.renderingRowStart,p.renderingRowEnd),ze.setColRange(p.renderingColStart,p.renderingColEnd);const N=Xl.current;(N.rowStart!==p.renderingRowStart||N.rowEnd!==p.renderingRowEnd||N.colStart!==p.renderingColStart||N.colEnd!==p.renderingColEnd)&&(Xl.current={rowStart:p.renderingRowStart,rowEnd:p.renderingRowEnd,colStart:p.renderingColStart,colEnd:p.renderingColEnd},De())},[ze,De]),Ul=i.useRef(()=>"add"),un=i.useCallback(p=>{Wo.current?.(p,Ul.current())},[]),fd=i.useCallback(p=>{Wo.current?.(p,"point")},[]),Gl=i.useRef(null),os=i.useCallback(p=>{Gl.current?.(p)},[]),Jl=i.useRef(null),pd=i.useCallback(p=>{Jl.current?.(p)},[]),Zl=i.useRef(null),Ql=i.useCallback((p,N)=>{if(N.length===0)return;const ee=le.current;if(p==="col"){for(const se of N){const Ce=Math.round(se.size);ve.resize(se.index,Ce),ee?.updateColSize(se.index,Ce)}ze.bumpColVersion(),At(),De(),Vn(),Ut();return}for(const se of N){const Ce=Math.round(se.size);ye.resize(se.index,Ce),ee?.updateRowSize(se.index,Ce)}ze.bumpRowGeometry(),xt(),De(),Vn(),Ut()},[ye,ve,ze,At,xt,De,Vn,Ut]),ei=C?Ql:void 0,hd=i.useCallback((p,N)=>{K?.(p,{kind:"pointer",event:N})},[K]),md=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"both",zoomRef:q}),gd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"x",zoomRef:q}),wd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"y",zoomRef:q}),Cd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:os,axis:"x",zoomRef:q}),yd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:os,axis:"y",zoomRef:q}),bd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"both",zoomRef:q}),ti=i.useRef(null),ni=i.useRef(()=>!1),vr=i.useCallback(()=>ni.current(),[]),$t=gC({zoomRef:q,enabled:!ue,rowAxis:ye,colAxis:ve,handleRef:le,bodyRef:pe,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,onContextMenuSelect:hd,onRequestEdit:sd,caretFromPointEnabled:p=>{if(O!==void 0||ae.getCellFormula!==void 0&&ae.getCellFormula(p.row,p.col)!==void 0)return!1;if(ae.getCellFormat===void 0)return!0;const N=ae.getCellText(p.row,p.col);return Ln(N,ae.getCellFormat(p.row,p.col)?.value)===N},isAnyDragging:vr,autoScroller:md,repaintOverlay:De,pointDragRef:ti,getPointing:kn,openHyperlinkAt:je===void 0||ae.getCellHyperlink===void 0?void 0:p=>{const N=ae.getCellHyperlink===void 0?void 0:fr(ae.getCellHyperlink(p.row,p.col));return N===void 0?!1:(je(N,p),!0)},isSortHeaderCell:cd,onHeaderSortPress:id,onRequestTouchEdit:A?ld:void 0}),jt=Kc({zoomRef:q,enabled:!ue&&X,axis:"col",headerRef:dt,mainAxis:ve,crossCount:ae.rowCount,handleRef:le,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,autoScroller:gd,repaintOverlay:De,pointing:Yo}),It=Kc({zoomRef:q,enabled:!ue&&X,axis:"row",headerRef:Kt,mainAxis:ye,crossCount:ae.colCount,handleRef:le,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,autoScroller:wd,repaintOverlay:De,pointing:Yo}),pt=P0({zoomRef:q,enabled:!ue&&C&&X,colBandRef:dt,rowBandRef:Kt,fontSourceRef:pe,colAxis:ve,rowAxis:ye,viewStore:ze,handleRef:le,isEditing:Ge,requestCommit:et,focusSink:Ue,getSelection:Yt,adapter:ae,autofitEnabled:O===void 0,headerRows:n,defaultRowHeight:l,defaultColumnWidth:c,maxOperationCells:S,onOperationRejected:m,resizeTracks:Ql,writeResizeGuide:pd,repaintOverlay:De,isPointing:kn}),Mt=eC({zoomRef:q,enabled:!ue&&V,handleNodeRef:Zl,bodyRef:pe,rowAxis:ye,colAxis:ve,handleRef:le,getSelection:Yt,setSelection:Tt,focusSink:Ue,adapter:ae,commitEdits:xn,maxOperationCells:S,onOperationRejected:m,rejectReadOnly:Yn,writeFillPreview:os,repaintOverlay:De,xAutoScroller:Cd,yAutoScroller:yd}),yt=wC({zoomRef:q,enabled:!ue,bodyRef:pe,handleRef:le,rowAxis:ye,colAxis:ve,getPointing:kn,insertReference:Yo.insertReference,captureSink:()=>Sl.current(),restoreSink:p=>El.current(p),focusSink:Ue,autoScroller:bd,onDragFrame:un});ti.current=yt;const Rr=i.useCallback(()=>$t.isDragging()||jt.isDragging()||It.isDragging()||pt.isDragging()||Mt.isDragging()||yt.isDragging(),[$t,jt,It,pt,Mt,yt]);ie.current=Rr,ni.current=Rr,Ul.current=()=>yt.isDragging()?"point":$t.getDragMode();const vd=i.useCallback(()=>{$t.abortDrag(),jt.abortDrag(),It.abortDrag(),pt.abortDrag(),Mt.abortDrag(),yt.abortDrag()},[$t,jt,It,pt,Mt,yt]),ss=i.useCallback(()=>Pt.current.active,[]),ri=i.useCallback((p,N)=>{const ee=ae.getCellValidation===void 0?void 0:ae.getCellValidation(p.row,p.col);if(ee===void 0)return Uc;const se=ae.evaluateFormula,Ce=fu(ee,N,qn,se===void 0?void 0:ke=>se(ke,p));return Ce.ok||ee.strict!==!0?Uc:(Xe?.({cell:p,rule:ee,text:N,message:Ce.message}),wt.current?.isKindEnabled("message")&&Yr.current("message",{message:Ce.message,rejected:!0}),Ce)},[ae,Xe,qn]),He=Nw({enabled:!ue,sinkRef:Me,rootRef:Ve,adapter:ae,commitEdits:xn,getActive:ss,ensureCellVisible:_t,focusSink:Ot,rearmSink:ft,discardClip:Ct,isDragging:vr,rejectReadOnly:Yn,resolveEditAlign:p=>{if(ae.getCellFormat===void 0)return null;const N=Eo(ae,p.row,p.col);return Za(cn(p.row,p.col,N),N)},resolveEditPaint:p=>ae.getCellFormat===void 0?null:mp(cn(p.row,p.col,Eo(ae,p.row,p.col))),editPaintRef:kl,repaintOverlay:De,validateCommit:ri,onSessionChange:W});Xt.current=He.isEditing,Fl.current=He.requestCommit,ql.current=He.startEdit,Ko.current=He.getPointing,Rl.current=He.insertReference,Sl.current=He.captureSink,El.current=He.restoreSink;const oi=i.useCallback(()=>{He.cancelEdit(),Cr()},[He.cancelEdit,Cr]),Sr=hw({enabled:!ue,sinkRef:Me,adapter:ae,isEditing:Ge,getSelection:Yt,setSelection:Tt,commitPaste:ad,maxOperationCells:S,onOperationRejected:m,onCopyMultiRange:j,repaintOverlay:De,isDragging:vr,resize:{rowAxis:ye,colAxis:ve,resizeTracks:ei},pendingPasteOptionsRef:Ol,formats:k,onClipChange:ot,onClipboardUnavailable:Ie,onEditRejected:d,rejectReadOnly:Yn,onPasteResolved:Be});jl.current=Sr.getClip,Il.current=Sr.discardClip,Hl.current=Sr.discardClipOnCommit,Vl.current=Sr.onAdapterSwitch,Go.current=Sr.paste;const Gt=fC({enabled:!ue,adapter:ae,popovers:Te,sinkRef:Me,bodyRef:pe,handleRef:le,rowAxis:ye,colAxis:ve,zoomRef:q,getActive:ss,isEditing:Ge,requestCommit:et,focusSink:Ot,rearmSink:ft,isDraggingAny:Rr,commitEdits:xn,labels:Qe,onHyperlinkOpen:je,anchors:Xo,repaintOverlay:De,rejectReadOnly:Yn,columnMenuAt:rs});wt.current=Gt,Yr.current=Gt.open,Tl.current=Gt.hideTip;const Rd=i.useCallback(()=>{const p=Pt.current.active;return _t(p),Xr(p)},[_t,Xr]),ls=Mw({adapter:ae,trackResize:C&&!ue?pt:void 0,getSelection:Yt,commitEdits:xn,getActive:ss,isEditing:Ge,requestCommit:et,cancelEdit:oi,getSessionText:He.getSessionText,validateCommit:ri,insertAtCaret:He.insertAtCaret,refreshEditPaint:He.refreshPaint,maxOperationCells:S,onOperationRejected:m,colors:_n,formats:k,getHighlight:()=>Vo.current,setHighlight:Qu,popovers:Te,openPopover:p=>Yr.current(p),onHyperlinkOpen:je,onPasteSpecialRequest:Oe,paste:p=>Go.current(p),rowAxis:ye,colAxis:ve,resizeTracks:ei,defaultRowHeight:l,defaultColumnWidth:c,now:Et,announce:Kn,formatCommandAnnouncement:b,formatResizeAnnouncement:R,keyboardCellRect:Rd,rejectReadOnly:Yn,columnMenu:rs===void 0?void 0:{isColumnMenuCell:p=>rs(p)!==null,open:Gt.openColumnMenu}});Ml.current=ls,Uo.current=ls.executeCommand,$l.current=ls.isCommandAvailable;const Sd=i.useMemo(()=>({table:Wt,execute:p=>Uo.current(p),isAvailable:p=>$l.current(p)}),[Wt]),Ed=i.useCallback(()=>{Ct(),E?.()},[Ct,E]),kd=i.useCallback(()=>{Ct(),P?.()},[Ct,P]);G0({zoomRef:q,enabled:!ue,sinkRef:Me,rootRef:Ve,handOffFocusToRoot:ed,getSelection:Yt,setSelection:Tt,moveActive:nd,ensureCellVisible:_t,pageExtent:td,isEditing:Ge,requestCommit:et,startEdit:br,commitEdits:xn,maxOperationCells:S,onOperationRejected:m,rejectReadOnly:Yn,getClip:Jr,discardClip:Ct,isDragging:Rr,abortDrag:vd,findDataEdge:ae.findDataEdge,getEditingMode:He.getEditingMode,cancelEdit:oi,onUndoRequest:Ed,onRedoRequest:kd,onCellContextMenu:K,rowAxis:ye,colAxis:ve,handleRef:le,rearmSink:ft,commands:Sd,onCommandBlockedWhileEditing:oe,pointing:He,adapter:ae,hideNoteTip:()=>Tl.current(),closeRejectedMessage:Cr,pendingPasteOptionsRef:Ol,onPointFrame:fd});const si=Ae?.hasControls===!0,li=Gt.context!==null&&Gt.context.kind==="columnMenu"?Gt.context.cell.col:null,Od=i.useMemo(()=>si?{openCol:li,menuLabel:Qe.columnMenu,filteredLabel:Qe.columnMenuFiltered,onToggle:Wl}:null,[si,li,Qe.columnMenu,Qe.columnMenuFiltered,Wl]),xd=i.useMemo(()=>r===void 0||Ae===null||!Ae.hasControls?null:{resolved:Ae,state:r.state,getFilterValues:r.getFilterValues,changeState:Zr,columnNameOf:Kl,isInsideGrid:Yl},[r,Ae,Zr,Kl,Yl]);i.useLayoutEffect(()=>{const p=wt.current,N=p===null?null:p.context;if(p===null||N===null||N.kind!=="columnMenu")return;const ee=Ae===null||N.cell.row!==Ae.headerRow?null:cr(Ae,N.cell.col);(ee===null||!p0(ee,N.column))&&p.closeColumnMenu({restoreFocus:Ve.current?.contains(document.activeElement)===!0})},[Ae]);const Ad=En.active.row,Td=En.active.col;i.useLayoutEffect(()=>{const p=wt.current;p!==null&&(p.syncTipAriaDescribedBy(),p.isKindEnabled("message")&&(p.isOpen()==="message"&&p.close(),p.open("message")))},[Ad,Td]),i.useLayoutEffect(()=>{De()},[De,Hn.row,Hn.column,Hn.intersection]),i.useLayoutEffect(()=>{De()},[De,G?.startRow,G?.startCol,G?.endRow,G?.endCol]);const $d=i.useCallback(p=>{(Xt.current?.()??!1)||(p.preventDefault(),Ue(),ft())},[Ue,ft]),Md=i.useCallback(p=>{const N=Ve.current,ee=p.relatedTarget,se=N!==null&&!N.matches(":focus-visible");if(N!==null&&ee instanceof Node&&N.contains(ee)){p.target===N&&ee===Me.current&&!Jo.current&&Ot({preventScroll:se});return}(Xt.current?.()??!1)||(Ot({preventScroll:se}),ft())},[Ot,ft]),Ld=i.useCallback(p=>{const N=Ve.current,ee=p.relatedTarget;N!==null&&ee instanceof Node&&N.contains(ee)||He.isFocusoutSuppressed()||ts(!1)},[He]),eo=i.useRef(null),Er=i.useCallback(()=>{const p=eo.current;p!==null&&(eo.current=null,window.removeEventListener("pointerup",p.up,!0),window.removeEventListener("pointercancel",p.cancel,!0))},[]),is=i.useCallback(()=>{if(eo.current!==null)return;const p=ee=>{ee.pointerType==="mouse"&&(Er(),ee.button===1&&ee.preventDefault())},N=ee=>{ee.pointerType==="mouse"&&Er()};eo.current={up:p,cancel:N},window.addEventListener("pointerup",p,!0),window.addEventListener("pointercancel",N,!0)},[Er]);i.useEffect(()=>Er,[Er]),i.useEffect(()=>{const p=Ve.current;if(ue||p===null)return;let N=0;const ee=ke=>{if(ke.pointerType!=="mouse"){(Xt.current?.()??!1)||ts(!1);return}N=ke.buttons,ke.button===1&&(ke.target===Me.current&&(Xt.current?.()??!1)||is())},se=ke=>{ke.pointerType==="mouse"&&(N=ke.buttons)},Ce=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===N)return;const tt=ke.buttons&~N;N=ke.buttons,ke.preventDefault(),(tt&4)!==0&&is()};return p.addEventListener("pointerdown",ee,!0),p.addEventListener("pointerup",se,!0),p.addEventListener("pointermove",Ce,!0),()=>{p.removeEventListener("pointerdown",ee,!0),p.removeEventListener("pointerup",se,!0),p.removeEventListener("pointermove",Ce,!0)}},[ue,is]);const zd=i.useCallback(p=>{if(!(p.target!==p.currentTarget||p.pointerType!=="mouse")&&(p.preventDefault(),p.button===0)){if(kn()){Ue();return}if(Ge()&&!et()){Ue();return}Ue()}},[Ue,Ge,et,kn]),cs=i.useRef(!1);i.useLayoutEffect(()=>{if(ue){cs.current=!1;return}if(cs.current)return;cs.current=!0,ft();const p=(Ve.current?.clientHeight??0)/q.current;p>0&&ye.totalSize()>0&&ze.setRowRange(0,ye.indexAt(Math.min(p-1,ye.totalSize()-1)));const N=(Ve.current?.clientWidth??0)/q.current;N>0&&ve.totalSize()>0&&ze.setColRange(0,ve.indexAt(Math.min(N-1,ve.totalSize()-1)))},[ue,ft,ze,ye,ve]);const ii=i.useRef(t);i.useLayoutEffect(()=>{ii.current!==t&&(ii.current=t,$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag(),He.cancelEdit(),wt.current?.hideTip(),wt.current?.close(),ue?(Pt.current=Zn,Bo(Zn)):an(Zn,"sheetSwitch"),Vl.current())},[t,ue,an,$t,jt,It,pt,Mt,yt,ze,He.cancelEdit]);const ci=i.useRef({adapter:ae,rows:ye.count,cols:ve.count}),{getSessionCell:ai,getSession:ui,cancelEdit:di}=He;i.useLayoutEffect(()=>{const p=ci.current,N=ye.count,ee=ve.count;if(ci.current={adapter:ae,rows:N,cols:ee},p.adapter!==ae||N>=p.rows&&ee>=p.cols)return;ue?(Pt.current=Zn,Bo(Zn)):an(Vc(Pt.current,N,ee),"countShrink"),$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag();const se=ht=>ue||ht.row>=N||ht.col>=ee,Ce=ai();Ce!==null&&se(Ce)&&di();const ke=Xo.current;if(ke.tip!==null&&se(ke.tip)&&wt.current?.hideTip(),ke.interactive!==null&&se(ke.interactive)){const ht=Ve.current?.contains(document.activeElement)===!0;wt.current?.close({restoreFocus:ht})}const tt=Jr();tt!==null&&!tt.foreign&&se({row:tt.range.endRow,col:tt.range.endCol})&&Ct()},[ae,ye.count,ve.count,ue,an,$t,jt,It,pt,Mt,yt,ai,di,Jr,Ct]);const fi=i.useRef(a),pi=i.useRef(u),hi=i.useRef(h),mi=i.useRef(g);i.useLayoutEffect(()=>{(fi.current!==a||pi.current!==u||hi.current!==h||mi.current!==g)&&(fi.current=a,pi.current=u,hi.current=h,mi.current=g,$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag())},[a,u,h,g,$t,jt,It,pt,Mt,yt]),i.useLayoutEffect(()=>{xt(),At(),De()},[a,u,h,g,xt,At,De]);const gi=i.useRef(x);i.useLayoutEffect(()=>{gi.current!==x&&(gi.current=x,Ct())},[x,Ct]),i.useLayoutEffect(()=>{De()},[De,En]);const An=i.useCallback(()=>{const p=Ml.current;if(p===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return p},[]);if(i.useImperativeHandle(Wr,()=>({resizeRow:(p,N)=>{const ee=Math.round(N);ye.resize(p,ee),le.current?.updateRowSize(p,ee),ze.bumpRowGeometry(),xt(),De(),Vn(),Ut()},resizeColumn:(p,N)=>{const ee=Math.round(N);ve.resize(p,ee),le.current?.updateColSize(p,ee),ze.bumpColVersion(),At(),De(),Vn(),Ut()},autoFitColumns:p=>{for(const N of p)if(!Number.isInteger(N)||N<0||N>=ve.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${ve.count-1} (got ${String(N)})`);return pt.autofitColumnsInAllRows(p)},scrollToCell:(p,N)=>{le.current?.scrollToCell(p.row,p.col,N)},focus:p=>{Ot(p),Ge()||ft()},executeCommand:p=>Uo.current(p),applyFormat:p=>An().applyFormat(p),setBorders:(p,N)=>An().setBorders(p,N),setHyperlink:p=>An().setHyperlink(p),setNote:p=>An().setNote(p),addComment:p=>An().addComment(p),setValidation:p=>An().setValidation(p),paste:p=>Go.current(p),getSelection:()=>Pt.current,setSelection:(p,N)=>{const ee=j0(p,ye.count,ve.count),se=vC(N);return Ge()||vr()?!1:(an(ee,"setSelection"),se&&_t(ee.active),!0)},getEditSession:ui,commitEdit:()=>Ge()?et()?"committed":"rejected":"idle",getBaseFormat:p=>ae.getCellFormat===void 0?void 0:ae.getCellFormat(p.row,p.col),getPaintedFormat:p=>ae.getCellFormat===void 0?void 0:cn(p.row,p.col,Eo(ae,p.row,p.col)),startEdit:p=>{br(p)},openPopover:p=>{Yr.current(p)}}),[ye,ve,ze,At,xt,De,Vn,Ut,pt,Ot,Ge,ft,ae,cn,br,An,an,vr,_t,ui,et]),ue)return I.jsx("div",{className:Rn?`aqsp-root ${Rn}`:"aqsp-root","data-aqsp-empty":"","data-testid":kt});const Nd=te!==void 0||f!==void 0||b!==void 0||v!==void 0||R!==void 0,Dd=s===void 0?{"aria-label":Qe.rootAriaLabel}:{"aria-labelledby":s};return I.jsxs("div",{ref:Ve,className:Rn?`aqsp-root ${Rn}`:"aqsp-root",role:"group",...Dd,tabIndex:0,onFocus:Md,onBlur:Ld,"data-aqsp-root":"","data-aqsp-headings-hidden":X?void 0:"","data-aqsp-framed":G===void 0?void 0:"","data-aqsp-touch-editing":A?"":void 0,"data-testid":kt,children:[I.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":J,onPointerDown:zd,style:J===1?void 0:{width:`${100/J}%`,height:`${100/J}%`,transform:`scale(${J})`,"--_aqsp-zoom":String(J)},children:[X?I.jsxs(I.Fragment,{children:[I.jsx("div",{ref:Se,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:p=>{if(p.pointerType==="mouse"&&(p.preventDefault(),p.button===0)){if(kn()){Ue();return}if(Ge()&&!et()){Ue();return}Ue(),Tt({ranges:[me({row:0,col:0},{row:ae.rowCount-1,col:ae.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),I.jsx(N0,{viewStore:ze,colAxis:ve,frozenCols:a,frozenTrailingCols:h,handleRef:le,bandRef:dt,colTrackRef:ut,windowOriginXRef:Le,repaintColHeaders:At,selectionRanges:En.ranges,enableResizeUI:C,dividerLeadingRef:gt,dividerTrailingRef:Ye}),I.jsx(D0,{viewStore:ze,rowAxis:ye,handleRef:le,bandRef:Kt,selectionRanges:En.ranges,rowTrackRef:mt,windowOriginYRef:at,repaintHeaders:xt,enableResizeUI:C,frozenRows:u,frozenTrailingRows:g,dividerLeadingRef:qt,dividerTrailingRef:In})]}):null,I.jsxs("div",{ref:Re,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[I.jsx(z0,{adapter:ae,rowAxis:ye,colAxis:ve,viewStore:ze,handleRef:le,bodyRef:pe,dataVersion:x,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:n,labelledBy:s,gridLabel:s===void 0?Qe.rootAriaLabel:void 0,readOnly:o,tapScrollCircleOptions:L,showArrowButtons:M?.showArrowButtons,enableThumbDrag:M?.enableThumbDrag,enableTrackClick:M?.enableTrackClick,overscanRows:Yc("overscanRows",$),overscanCols:Yc("overscanCols",H),background:Z,onRenderTruncated:Q,renderCell:O,onScroll:ud,onRangeChange:dd,focusSink:Ue,isEditing:Ge,requestCommit:et,testId:kt?`${kt}-vs`:void 0,__onCellRender:Io,__maxRenderedCells:Ft,cfIndexRef:wr,cfMemoRef:ln,isPointing:kn,locale:qn,scrollLabels:sn,sortFilter:Ae,columnMenu:Od}),I.jsx(Hg,{rowAxis:ye,colAxis:ve,handleRef:le,sinkRef:Me,getSelection:Yt,editing:He.editing,sinkInputMode:od,repaintRef:vl,dragFrameRef:Wo,getClip:Jr,getIsDraggingAny:Rr,getIsFillDragging:Mt.isDragging,fillFrameRef:Gl,resizeGuideFrameRef:Jl,fillHandleNodeRef:Zl,enableFillHandle:V,frozenCols:a,frozenRows:u,trailingCols:h,trailingRows:g,sinkAriaLabel:Qe.sinkAriaLabel,sinkReadOnly:o,sinkKeyShortcuts:Pn,onSinkMouseDown:$d,editPaintRef:kl,highlightRef:Vo,frameRange:G,highlightColors:Zu,popoverAnchors:Xo,interactiveAnchorRef:xl,tipAnchorRef:Al}),Gt.layerEnabled?I.jsx(aC,{controller:Gt,labels:Qe,renderPopover:Pe,interactiveAnchorRef:xl,tipAnchorRef:Al,columnMenu:xd}):null]}),Nd?I.jsx("div",{ref:Kr,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),I.jsx("div",{ref:ct,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=nn.iterateTsvPrefixRows;exports.iterateTsvRows=nn.iterateTsvRows;exports.measureTsv=nn.measureTsv;exports.parseTsv=nn.parseTsv;exports.serializeClipboardTsv=nn.serializeClipboardTsv;exports.serializeTsv=nn.serializeTsv;exports.columnIndexToName=Fe.columnIndexToName;exports.columnNameToIndex=Fe.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Qs;exports.CommentPopover=Ru;exports.DEFAULT_CUSTOM_COLORS=Uu;exports.DEFAULT_HIGHLIGHT_COLORS=vu;exports.DEFAULT_SHORTCUTS=iu;exports.LinkPopover=Su;exports.ListPopover=Eu;exports.MessagePopover=ku;exports.NotePopover=Ou;exports.NoteTip=xu;exports.SPREADSHEET_LABEL_CATALOGS=cu;exports.SPREADSHEET_RESERVED_SHORTCUTS=qm;exports.Spreadsheet=DC;exports.canonicalizeFormat=Nt;exports.detectClipSource=la;exports.enumerateRangeCells=fn;exports.estimatePasteCellCount=Em;exports.expandPaste=km;exports.formatCellValue=Ln;exports.formatEquals=Ud;exports.fromR1C1=Ir;exports.makeRange=me;exports.mergeFormat=tl;exports.normalizeHyperlink=bn;exports.parseChord=en;exports.parseClipPayload=zs;exports.parseHtmlTable=Ja;exports.rangeContains=Vt;exports.rangeSize=St;exports.resolveLabel=be;exports.resolveLabels=au;exports.serializeClipPayload=ra;exports.serializeHtmlTable=Ya;exports.shiftFormula=$a;exports.toR1C1=qo;exports.validateCellText=fu;
|
|
12
|
+
`)},im=(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)}Is(t,Xa(e,r))},cm=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?Ha(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<Hi.length?Hi[l]:null}return null},Ua=(e,t,n)=>t!==void 0&&Va(t)?gh(e,t,n):e,am=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&Rt(c)!==null)if(n!==void 0&&n.type==="date"){const a=Ha(Number(c));if(a!==null)return a}else return c;return Ua(t,n,r)},um=(e,t,n,r)=>{const o=Xa(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:em(o)};for(const h of hm(e))om(h,l);sm(l,o,s,r.rules);const c=lm(l.text,l.mode),a=nm(o,s,r.kind),u={t:""};if(r.kind==="sheets"){const h=e.getAttribute("data-sheets-numberformat"),g=h===null?void 0:ah(h,r.options);g!==void 0&&(a.value=g);const L=e.getAttribute("data-sheets-value"),M=L===null?null:cm(L,g);u.t=M===null?Ua(c,g,Pa):M;const $=e.getAttribute("data-sheets-formula");$?.startsWith("=")&&(u.f=$);const H=e.getAttribute("data-sheets-hyperlink"),Z=H!==null?H:l.href,Q=Z===null?null:bn(Z);Q!==null&&(u.link=Q);const O=e.getAttribute("data-sheets-note");O!==null&&O!==""&&(u.note=O)}else{const h=o.get("mso-number-format"),g=h===void 0?void 0:ul(js(Ao(h)),r.options);g!==void 0&&(a.value=g),u.t=am(e,c,g,r.separators);const L=e.getAttribute("x:fmla");L?.startsWith("=")&&(u.f=qo(L,{row:t,col:n}));const M=l.href===null?null:bn(l.href);M!==null&&(u.link=M)}return{cell:u,format:a}},Hs=(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},dm=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)},fm=(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]))},Ga=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:_o(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:dm(l);if(c!==null)return Math.min(c,yn)}const o=fm(e,t);return o===null?null:Math.min(o,yn)},pm=(e,t)=>{const n=[],r=o=>{const s=Ga(o,"width");for(let l=Hs(o,"span",ol);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Pr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Pr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Pr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*hm(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*mm(e){for(const t of["thead","tbody","tfoot"])for(const n of Pr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Pr(n))o.localName==="tr"&&(yield o)}}const Cs=()=>({t:""}),gm=(e,t,n)=>{const r=ha(),o=[],s=[],l=[];let c=0;for(const M of mm(e)){const $=o.length,H=($+1)*Math.max(c,1);if(H>n)return{outcome:"limit",cells:H};const Z=[];for(let O=0;O<l.length;O+=1)l[O]>0&&(Z[O]=Cs(),l[O]-=1);let Q=0;for(const O of Pr(M)){const D=O.localName;if(D!=="td"&&D!=="th")continue;for(;Z[Q]!==void 0;)Q+=1;const W=Hs(O,"colspan",ol),K=Hs(O,"rowspan",ia),E=($+1)*Math.max(c,Q+W);if(E>n)return{outcome:"limit",cells:E};const P=um(O,$,Q,t),j=r.intern(P.format);j!==void 0&&(P.cell.fmt=j),Z[Q]=P.cell;for(let m=1;m<W;m+=1)Z[Q+m]===void 0&&(Z[Q+m]=Cs());if(K>1)for(let m=0;m<W;m+=1){const d=K-1,y=Q+m;l[y]=l[y]===void 0||l[y]<d?d:l[y]}Q+=W}Z.length>c&&(c=Z.length),o.push(Z),s.push(Ga(M,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map(M=>{const $=[];for(let H=0;H<c;H+=1){const Z=M[H];$.push(Z===void 0?Cs():Z)}return $}),u=pm(e,c),h=u.length===c&&u.every(M=>M!==null)?u.map(M=>M===null?0:M):void 0,g=s.every(M=>M!==null)?s.map(M=>M===null?0:M):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:nl(),formats:[...r.entries],validations:[],cells:a,...h===void 0?{}:{colWidths:h},...g===void 0?{}:{rowHeights:g},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Ja=(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=$h(o);return gm(s,{kind:t,rules:l,options:n,separators:l.separators},r)},me=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),Vt=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,St=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),vt=e=>e.reduce((t,n)=>t+St(n).rows*St(n).cols,0),wm=(e,t)=>{if(!Vt(e,t))return[e];const n=[];return t.row>e.startRow&&n.push(me({row:e.startRow,col:e.startCol},{row:t.row-1,col:e.endCol})),t.col>e.startCol&&n.push(me({row:t.row,col:e.startCol},{row:t.row,col:t.col-1})),t.col<e.endCol&&n.push(me({row:t.row,col:t.col+1},{row:t.row,col:e.endCol})),t.row<e.endRow&&n.push(me({row:t.row+1,col:e.startCol},{row:e.endRow,col:e.endCol})),n},fn=(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}))}},vn=(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)}},Dt=(e,t)=>e.row===t.row&&e.col===t.col,Za=(e,t)=>e===void 0?bi(void 0,void 0,t()):bi(e.align,e.value,e.align===void 0?t():""),Eo=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},dr=(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}},ko=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}),Qa=e=>e.isCellReadOnly!==void 0,nt=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Cm=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellInputMode","getCellAttributes","getRangeExtrema","evaluateFormula"],Wi=["text","decimal","numeric","tel","search","email","url"],ym=(e,t,n)=>{if(e.getCellInputMode===void 0)return"text";const r=e.getCellInputMode(t,n),o=Wi.find(s=>s===r);if(o===void 0)throw new RangeError(`[Spreadsheet] getCellInputMode(${t}, ${n}) must return one of ${Wi.join(" / ")}; got ${typeof r=="string"?JSON.stringify(r):String(r)}`);return o},bm=()=>!0,vm=e=>{const t=new WeakMap,n={};for(const r of Cm)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:bm}),n},Rm=/^data-[a-z0-9-]+$/,Sm=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Em=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Sm(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(!Rm.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},Mr=(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},nr=(e,t)=>{for(const n of t)if(Mr(e,n))return!0;return!1},km=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=St(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Bs=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=St(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,a=c?s.rows:e.rows,u=c?s.cols:e.cols,h=l?n:{row:t.startRow,col:t.startCol},g=Math.min(a,r-h.row),L=Math.min(u,o-h.col);return g<=0||L<=0?null:me(h,{row:h.row+g-1,col:h.col+L-1})},eu=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,a=Bs({rows:l,cols:c},t,n,r,o);if(a===null)return[];const u={row:a.startRow,col:a.startCol},h=a.endRow-a.startRow+1,g=a.endCol-a.startCol+1,L=[];for(let M=0;M<h;M+=l){const $=[];for(let Z=0;Z<g;Z+=c){const Q={row:u.row+M,col:u.col+Z};$.push(Q),L.push(Q)}const H=Math.min(l,h-M);for(let Z=0;Z<H;Z+=1){const Q=u.row+M+Z,O=e[Z];for(let D=0;D<$.length;D+=1){const W=D*c,K=Math.min(c,g-W);for(let E=0;E<K;E+=1)s(Q,u.col+W+E,O[E],$[D])}}}return L},Om=(e,t,n,r,o)=>{const s=[];return eu(e,t,n,r,o,(l,c,a)=>{s.push({row:l,col:c,text:a})}),s},Ki=(e,t,n,r,o,s)=>{const l=[],c=eu(e,t,n,r,o,(a,u,h,g)=>{const L=s(h,a,u,g);L!==null&&l.push({...L,row:a,col:u})});return{edits:l,tiles:c}},tu=(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)})`)},xm=(e,t)=>{tu(e,t);const n=St(t),r=St(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},Am=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(me({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(me({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(me({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(me({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Tm=(e,t,n,r)=>{tu(t,n);const o=St(t).rows,s=St(t).cols,l=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const u=t.startRow+((a-t.startRow)%o+o)%o,h=a>=t.startRow&&a<=t.endRow;for(let g=n.startCol;g<=n.endCol;g+=1){if(h&&g>=t.startCol&&g<=t.endCol)continue;const L=t.startCol+((g-t.startCol)%s+s)%s,M=u*2**21+L;let $=c.get(M);$===void 0&&($={value:e(u,L),origin:{row:u,col:L}},c.set(M,$)),l.push(r($.value,$.origin,{row:a,col:g}))}}return l},nu=(e,t,n)=>{const r=dr(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:Nt(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=fr(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},ru=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?$a(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},jo=["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"],$m=/^[A-Z]$/,Mm=/^[A-Za-z]$/,Lm=/^Key([A-Z])$/,ou=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"]),zm=e=>$m.test(e)||ou.has(e),en=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||!zm(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}},Nm=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,su=e=>{if(Mm.test(e.key))return e.key.toUpperCase();const t=Lm.exec(e.code);return t!==null?t[1]:ou.has(e.code)?e.code:null},kr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:su(t)===e.key,Ee=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),xe=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Dm=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(Ee(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(Ee(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(Ee(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(Ee(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Fm=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(Ee(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(Ee(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},Hr=[...Dm(),Ee("Home","idle","row start (first visible column)"),Ee("Ctrl+Home","idle","first visible cell"),Ee("Shift+Home","idle","extend to row start"),Ee("Ctrl+Shift+Home","idle","extend to first visible cell"),Ee("End","idle","row end (last visible column)"),Ee("Ctrl+End","idle","last visible cell"),Ee("Shift+End","idle","extend to row end"),Ee("Ctrl+Shift+End","idle","extend to last visible cell"),Ee("PageUp","both","page up (idle) / commit + page up (editing)"),Ee("PageDown","both","page down (idle) / commit + page down (editing)"),Ee("Shift+PageUp","idle","extend one page up"),Ee("Shift+PageDown","idle","extend one page down"),Ee("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),Ee("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),Ee("Tab","both","cycle right (idle) / commit + cycle right (editing)"),Ee("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),Ee("Enter","both","cycle down (idle) / commit + cycle down (editing)"),Ee("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),Ee("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),Ee("F2","both","start editing (idle) / toggle the pointing arm (editing)"),Ee("F4","editing","cycle the reference anchor under the caret (formula session)"),Ee("Delete","idle","clear every selected cell"),Ee("Backspace","idle","clear every selected cell"),Ee("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),Ee("Ctrl+A","idle","select all"),Ee("Ctrl+Z","idle","undo request"),Ee("Ctrl+Y","idle","redo request"),Ee("Ctrl+Shift+Z","idle","redo request"),Ee("Shift+F10","idle","keyboard context menu"),Ee("ContextMenu","idle","keyboard context menu"),Ee("Ctrl+Space","idle","column bands"),Ee("Shift+Space","idle","row bands"),Ee("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),Ee("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),Ee("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),Ee("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"},...Fm(),xe("bold","Ctrl+B","both","toggle bold"),xe("italic","Ctrl+I","both","toggle italic"),xe("underline","Ctrl+U","both","toggle underline"),xe("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),xe("clearFormatting","Ctrl+Backslash","idle","clear formatting"),xe("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),xe("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),xe("alignLeft","Ctrl+Shift+L","both","align left"),xe("alignCenter","Ctrl+Shift+E","both","align center"),xe("alignRight","Ctrl+Shift+R","both","align right"),xe("formatNumber","Ctrl+Shift+Digit1","both","number format"),xe("formatTime","Ctrl+Shift+Digit2","both","time format"),xe("formatDate","Ctrl+Shift+Digit3","both","date format"),xe("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),xe("formatPercent","Ctrl+Shift+Digit5","both","percent format"),xe("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),xe("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),xe("bordersClear","Alt+Shift+Digit6","idle","clear borders"),xe("borderTop","Alt+Shift+Digit1","idle","top border"),xe("borderRight","Alt+Shift+Digit2","idle","right border"),xe("borderBottom","Alt+Shift+Digit3","idle","bottom border"),xe("borderLeft","Alt+Shift+Digit4","idle","left border"),xe("insertLink","Ctrl+K","idle","insert / edit hyperlink"),xe("insertNote","Shift+F2","idle","insert / edit note"),xe("insertComment","Ctrl+Alt+M","idle","insert comment"),xe("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),xe("openValidationList","Alt+ArrowDown","idle","open the validation list"),xe("fillDown","Ctrl+D","idle","fill down"),xe("fillRight","Ctrl+R","idle","fill right"),xe("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),xe("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),xe("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),xe("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),xe("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),xe("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),xe("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),xe("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),xe("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),xe("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),xe("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],ys=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),Yi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),qm=e=>{const t=en(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 Yi?Yi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},To=(e,t)=>e.column==="both"||e.column===t,Pm=Array.from(new Set(Hr.filter(e=>!e.rebindable&&To(e,"idle")).map(e=>e.chord))),$o=new Set(Hr.filter(e=>e.command!==void 0&&To(e,"editing")).map(e=>e.command)),_m=new Set(Hr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),lu=e=>{const t={};for(const n of jo)t[n]=e(n);return t},iu=lu(e=>Hr.filter(t=>t.command===e).map(t=>t.chord)),jm=e=>{const t=new Map;for(const n of jo){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},Im=e=>{const t=new Set(jo);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(_m.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`)}}}},Hm=(e,t)=>{const n=en(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=$o.has(e);for(const o of Hr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(To(o,"idle")||r&&To(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Bm=e=>{e!==void 0&&Im(e);const t=lu(r=>{const o=e===void 0?void 0:e[r];return o===void 0?iu[r]:o===null?[]:o});for(const r of jo)for(const o of t[r])Hm(r,o);const n=new Map;for(const[r,o]of jm(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},Vs=(e,t)=>{const n=su(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=Nm({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}},Vm=(e,t)=>{const n=Vs(e,t);return n===null?null:n.command},Wm=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","NumpadEnter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Km=/^F(?:[1-9]|1[0-2])$/,Ym=e=>{const t=en(e);return t.alt||Wm.has(t.key)?!1:t.ctrl||Km.test(t.key)},pl=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose","columnMenu","columnMenuFiltered","sortAscending","sortDescending","sortClear","filterMatchMode","filterModeExact","filterModeFuzzy","filterSearchValues","filterSelectAll","filterSelectNone","filterBlank","filterLoading","filterLoadFailed","filterQuery","filterApply","filterClearColumn","filterClearAll"],Xi=[...rt.VIRTUAL_SCROLL_LABEL_KEYS,...pl],Ws=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close",columnMenu:"Sort and filter",columnMenuFiltered:"filtered",sortAscending:"Sort ascending",sortDescending:"Sort descending",sortClear:"Clear sort",filterMatchMode:"Match",filterModeExact:"Exact match",filterModeFuzzy:"Fuzzy search",filterSearchValues:"Search values",filterSelectAll:"Select all",filterSelectNone:"Clear all",filterBlank:"(Blanks)",filterLoading:"Loading…",filterLoadFailed:"Could not load the values",filterQuery:"Search text",filterApply:"Apply",filterClearColumn:"Clear this column's filter",filterClearAll:"Clear all filters"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる",columnMenu:"並べ替えと絞り込み",columnMenuFiltered:"絞り込み中",sortAscending:"昇順で並べ替え",sortDescending:"降順で並べ替え",sortClear:"並べ替えを外す",filterMatchMode:"検索方法",filterModeExact:"完全一致",filterModeFuzzy:"あいまい検索",filterSearchValues:"値を探す",filterSelectAll:"すべて選ぶ",filterSelectNone:"すべて外す",filterBlank:"(空白)",filterLoading:"読み込み中…",filterLoadFailed:"値を読めませんでした",filterQuery:"探す語",filterApply:"当てる",filterClearColumn:"この列の絞り込みを外す",filterClearAll:"すべての絞り込みを外す"})}),cu=Object.freeze({en:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Ws.en}),ja:Object.freeze({...rt.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Ws.ja})}),zn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Ui=e=>e==="commentCount"||e==="listMore",Xm=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 ${zn(t)}`);for(const n of pl){const r=e[n];if(!(Ui(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Ui(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${zn(r)}`)}}},Um=e=>{const t={};let n=!1;for(const r of rt.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},Gm=(e,t,n)=>{e[t]=n},au=(e,t)=>{const n=rt.resolveVirtualScrollLocale(e);if(t===void 0)return cu[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${zn(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(!Xi.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Xi.join(", ")}`);const s={...rt.resolveVirtualScrollLabels(n,Um(t)),...Ws[n]};for(const l of pl){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&Gm(s,l,c)}return Xm(s),Object.freeze(s)},Jm=e=>{const t={};for(const n of rt.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},be=(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},Gi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Zm={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Qm=(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}`}},bs=(e,t)=>{const n=r=>(o,s)=>`${e} ${Qm(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")})},eg=Object.freeze({list:"Value must be one of the list items.",number:bs("Value must be a number",Gi),textLength:bs("Text length must be",Gi),date:bs("Value must be a date",Zm),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}.`}),tg=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} を満たす値を入力してください。`}),vs=Object.freeze({en:eg,ja:tg}),ng=Object.freeze({ok:!0}),rg="TRUE",og="FALSE",sg=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),lg=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),ig=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,cg=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,ag=/^[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])?)+$/,Ji=e=>{const t=e.trim();if(!(ig.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),a=c<0?s:s.slice(0,c),u=c<0?"":s.slice(c+1),h=a+u,g=h.search(/[^0]/);return g<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:h.slice(g).replace(/0+$/,""),point:a.length+l-g}},ug=e=>e===1?-1:e===-1?1:0,dg=(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:ug(n)},fg=(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}},Zi=e=>{const t=cg.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>fg(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},pg=(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},hg=(e,t)=>e<t?-1:e>t?1:0,mg=e=>e==="between"||e==="notBetween",gg=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!mg(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},wg=(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}},Rs=(e,t,n,r,o,s)=>{const l=gg(e,t,n,r);return l===null?!0:o===null?!1:wg(e,s(o,l.a),l.b===null?0:s(o,l.b))},Cg=e=>Number.isFinite(e)?e:null,yg=e=>{let t=0;for(const n of e)t+=1;return t},bg=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),vg=(e,t)=>{switch(e.op){case"isEmail":return ag.test(t);case"isUrl":return bg(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)}},Rg=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,uu=e=>({checked:e.checked===void 0?rg:e.checked,unchecked:e.unchecked===void 0?og:e.unchecked}),Sg=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!sg.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${zn(e.op)} for type "${e.type}"`);return;case"text":if(!lg.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${zn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${zn(e.type)}`)}},Eg=(e,t,n)=>{switch(e.type){case"list":return xg(e).has(t);case"number":return Rs(e.op,e.a,e.b,Ji,Ji(t),dg);case"textLength":return Rs(e.op,e.a,e.b,Cg,yg(t),hg);case"date":return Rs(e.op,e.a,e.b,Zi,Zi(t),pg);case"text":return vg(e,t);case"checkbox":{const r=uu(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Rg(n(e.formula))}},du=(e,t,n)=>(Sg(e),t===""||Eg(e,t,n)),Qi=e=>e===void 0?void 0:e.trim(),kg=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Qi(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(),Qi(e.b));case"text":return Og(e,t.text);case"checkbox":{const n=uu(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},Og=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},ec=new WeakMap,xg=e=>{const t=ec.get(e);if(t!==void 0)return t;const n=new Set(e.values);return ec.set(e,n),n},fu=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(vs,n)){const o=Object.keys(vs).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${zn(n)}`)}return du(e,t,r)?ng:{ok:!1,message:e.errorMessage===void 0?kg(e,vs[n]):e.errorMessage}},Ag=e=>e.type!=="custom",Tg=(e,t)=>Ag(e)&&!du(e,t,void 0),pu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),hu=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),mu=(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,gu=(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),wu=(e,t)=>pu(e,t),Cu=(e,t)=>pu(e,t),yu=(e,t)=>hu(e,t),bu=(e,t)=>hu(e,t),Nn=(e,t,n)=>mu(e,t,n),Dn=(e,t,n)=>mu(e,t,n),Br=(e,t,n)=>gu(e,t,n),Vr=(e,t,n)=>gu(e,t,n),$g=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Bt=1,Lr=3,co=e=>`${-Math.min(Lr,Math.max(0,Math.floor(e)))}px`,Mg=(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}},tc=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,nc=(e,t)=>t===null?e:Math.min(e,t),rc=e=>e===null?"100%":`min(100%, ${e}px)`,oc=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,sc=(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]}},lc=Object.freeze([0,-1]),ic=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const a=-c*Bt,u=c*(1+Bt),h=t>=r,g=n<=o,L=h?s:a,M=g?l:u;return M<=a||L>=u?!1:(e.near=Math.max(L,a),e.far=Math.min(M,u),e.nearOpen=!h||L<a,e.farOpen=!g||M>u,!0)},ao=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),cc=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,ac=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Lg=Object.freeze(["top","right","bottom","left"]),zg=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Ng=e=>Lg.filter((t,n)=>(e&1<<n)!==0).join(" "),vu=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Dg=16,Fg=450,qg=e=>e>4?Math.floor(Fg/(5*e)):Dg,Or=(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},uc=()=>({rowLeft:Or("row","left"),rowRight:Or("row","right"),colAbove:Or("column","above"),colBelow:Or("column","below"),cross:Or("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Ks=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],uo=(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},fo=(e,t)=>Math.min(Math.max(e,0),t),dc="inset(100%)",sr=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Pg=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,sr([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const L=`${t.height}px`;e.rowLeft.style.height=L,e.rowRight.style.height=L}const h=`translate(${fo(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;h!==s.rowLeftTransform&&(s.rowLeftTransform=h,e.rowLeft.style.transform=h);const g=`translate(${fo(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;g!==s.rowRightTransform&&(s.rowRightTransform=g,e.rowRight.style.transform=g)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,sr([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const L=`${t.width}px`;e.colAbove.style.width=L,e.colBelow.style.width=L}const h=`translate(${t.left}px, ${fo(t.top,n.clampHeight)-n.clampHeight}px)`;h!==s.colAboveTransform&&(s.colAboveTransform=h,e.colAbove.style.transform=h);const g=`translate(${t.left}px, ${fo(t.top+t.height,n.clampHeight)}px)`;g!==s.colBelowTransform&&(s.colBelowTransform=g,e.colBelow.style.transform=g)}const a=r.intersection?"intersection":l!==c?l?"row":"column":null,u=a!==null;if(u!==s.crossShown&&(s.crossShown=u,sr([e.cross],u)),a!==null){a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--_aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const h=`translate(${t.left}px, ${t.top}px)`;h!==s.crossTransform&&(s.crossTransform=h,e.cross.style.transform=h)}},fc=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,sr([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,sr([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,sr([e.cross],!1))},po=e=>{for(const t of Ks(e))t.remove()},_g=(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)},jg=Object.freeze([]),pc=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},hc=e=>e.chrome[0]??e.active,mc=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)},Ig={left:"0px",right:"0px",width:""},Hg={top:"0px",bottom:"0px",height:""},gc=()=>({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:[]}),wc=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Cc=6,Bg=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,sinkInputMode:l,repaintRef:c,dragFrameRef:a,getClip:u,getIsDraggingAny:h,getIsFillDragging:g,fillFrameRef:L,resizeGuideFrameRef:M,fillHandleNodeRef:$,enableFillHandle:H,frozenCols:Z,frozenRows:Q,trailingCols:O,trailingRows:D,sinkAriaLabel:W,sinkReadOnly:K,sinkKeyShortcuts:E,onSinkMouseDown:P,editPaintRef:j,highlightRef:m,frameRange:d,highlightColors:y,popoverAnchors:v,interactiveAnchorRef:x,tipAnchorRef:S})=>{const V=i.useRef(null),C=i.useRef(d);C.current=d;const A=d!==void 0,X=i.useRef(null),w=i.useRef(null),G=i.useRef(new Map(wc.map(T=>[T,gc()]))),te=i.useCallback(T=>{const F=G.current.get(T);if(F!==void 0)return F;const J=gc();return G.current.set(T,J),J},[]),f=i.useCallback((T,F,J)=>{if(T===null)return;const q=T.style;q.left!==F.left&&(q.left=F.left),q.right!==F.right&&(q.right=F.right),q.width!==F.width&&(q.width=F.width),q.top!==J.top&&(q.top=J.top),q.bottom!==J.bottom&&(q.bottom=J.bottom),q.height!==J.height&&(q.height=J.height)},[]),b=i.useCallback((T,F,J)=>{if(!(T.bandClampWidth===F&&T.bandClampHeight===J)){T.bandClampWidth=F,T.bandClampHeight=J;for(const q of T.bandPool)uo(q,F,J);T.dragBand!==null&&uo(T.dragBand,F,J)}},[]),R=i.useRef({rowAxis:e,colAxis:t});R.current={rowAxis:e,colAxis:t};const _=i.useCallback((T,F,J)=>{const q=T.dividerSlots[F];q===null||T.dividerShown[F]===J||(T.dividerShown[F]=J,q.style.display=J?"":"none")},[]),Y=i.useCallback((T,F,J)=>{const q=T.bandClip;q!==null&&(T.bandClipWidth!==F&&(T.bandClipWidth=F,q.style.width=F),T.bandClipHeight!==J&&(T.bandClipHeight=J,q.style.height=J))},[]),U=i.useCallback((T,F,J)=>{const q=T.dividerSlots[F];q===null||T.dividerEnd[F]===J||(T.dividerEnd[F]=J,F<2?q.style.bottom=J:q.style.right=J)},[]),oe=i.useRef({x:0,y:0}),ce=i.useRef(null),k=i.useCallback((T,F)=>{const J=n.current,q=J?.getFrozenSize()??$g,ne=J?.getViewportSize(),ie=ne?.width??-1,fe=ne?.height??-1,Ne=oe.current;Ne.x=T,Ne.y=F;const $e=C.current!==void 0,ue=R.current,We=$e?ue.rowAxis.count:-1,Ke=$e?ue.colAxis.count:-1,Ae=$e?ue.rowAxis.totalSize():-1,we=$e?ue.colAxis.totalSize():-1;let de=ce.current;if(de===null||de.framed!==$e||de.rowCount!==We||de.colCount!==Ke||de.rowsTotal!==Ae||de.colsTotal!==we||de.frozenCols!==q.cols||de.frozenWidth!==q.width||de.frozenRows!==q.rows||de.frozenHeight!==q.height||de.trailingCols!==q.trailingCols||de.trailingWidth!==q.trailingWidth||de.trailingVisibleWidth!==q.trailingVisibleWidth||de.trailingRows!==q.trailingRows||de.trailingHeight!==q.trailingHeight||de.trailingVisibleHeight!==q.trailingVisibleHeight||de.bodyWidth!==ie||de.bodyHeight!==fe){const le=q.trailingVisibleWidth,Me=q.trailingVisibleHeight,mt=q.cols<=0&&q.trailingCols<=0?[{kind:"m",map:Le=>Le-Ne.x,clamp:ie,style:Ig,seamLead:!1,seamTrail:!1}]:[...q.cols>0?[{kind:"f",map:Le=>Le,clamp:q.width,style:{left:"0px",width:`${q.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Le=>Le-Ne.x-q.width,clamp:Math.max(0,ie-q.width-le),style:{left:`${q.width}px`,right:`${le}px`,width:""},seamLead:q.cols>0,seamTrail:q.trailingCols>0},...q.trailingCols>0?[{kind:"t",map:Le=>Le-R.current.colAxis.totalSize()+le,clamp:le,style:{left:"",right:"0px",width:`${le}px`},seamLead:!0,seamTrail:!1}]:[]],at=q.rows<=0&&q.trailingRows<=0?[{kind:"m",map:Le=>Le-Ne.y,clamp:fe,style:Hg,seamLead:!1,seamTrail:!1}]:[...q.rows>0?[{kind:"f",map:Le=>Le,clamp:q.height,style:{top:"0px",height:`${q.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Le=>Le-Ne.y-q.height,clamp:Math.max(0,fe-q.height-Me),style:{top:`${q.height}px`,bottom:`${Me}px`,height:""},seamLead:q.rows>0,seamTrail:q.trailingRows>0},...q.trailingRows>0?[{kind:"t",map:Le=>Le-R.current.rowAxis.totalSize()+Me,clamp:Me,style:{top:"",bottom:"0px",height:`${Me}px`},seamLead:!0,seamTrail:!1}]:[]],ut=[];for(const Le of mt){const dt=$e?tc(Le.kind,we,q.width,q.trailingWidth):null,[Kt,gt]=$e?sc(Le.kind,Ke,q.cols,q.trailingCols):lc;for(const Ye of at){const qt=$e?tc(Ye.kind,Ae,q.height,q.trailingHeight):null,[In,Kr]=$e?sc(Ye.kind,We,q.rows,q.trailingRows):lc;ut.push({nodes:te(`${Le.kind}${Ye.kind}`),xKind:Le.kind,yKind:Ye.kind,mapX:Le.map,clampWidth:Le.clamp,xStyle:Le.style,xSeamLead:Le.seamLead,xSeamTrail:Le.seamTrail,xFirst:Kt,xLast:gt,mapY:Ye.map,clampHeight:Ye.clamp,yStyle:Ye.style,ySeamLead:Ye.seamLead,ySeamTrail:Ye.seamTrail,yFirst:In,yLast:Kr,cells:{clampWidth:nc(Le.clamp,dt),clampHeight:nc(Ye.clamp,qt)},xCellsSizeCss:rc(dt),yCellsSizeCss:rc(qt),xCellsEndCss:oc(dt),yCellsEndCss:oc(qt)})}}de={frozenCols:q.cols,frozenWidth:q.width,frozenRows:q.rows,frozenHeight:q.height,trailingCols:q.trailingCols,trailingWidth:q.trailingWidth,trailingVisibleWidth:q.trailingVisibleWidth,trailingRows:q.trailingRows,trailingHeight:q.trailingHeight,trailingVisibleHeight:q.trailingVisibleHeight,bodyWidth:ie,bodyHeight:fe,framed:$e,rowCount:We,colCount:Ke,rowsTotal:Ae,colsTotal:we,ctxs:ut},ce.current=de}const pe=q.width>0,Re=q.trailingWidth>0,Se=q.height>0,ct=q.trailingHeight>0;for(const le of de.ctxs)f(le.nodes.container,le.xStyle,le.yStyle),b(le.nodes,le.clampWidth,le.clampHeight),_(le.nodes,0,pe),_(le.nodes,1,Re),_(le.nodes,2,Se),_(le.nodes,3,ct),U(le.nodes,0,le.yCellsEndCss),U(le.nodes,1,le.yCellsEndCss),U(le.nodes,2,le.xCellsEndCss),U(le.nodes,3,le.xCellsEndCss),Y(le.nodes,le.xCellsSizeCss,le.yCellsSizeCss);return de.ctxs},[n,te,f,b,_,U,Y]),B=i.useCallback((T,F,J)=>{T.dividerSlots[F]=J,T.dividerShown[F]=!1,T.dividerEnd[F]="0px",mc(T)},[]),z=i.useCallback((T,F)=>{T.frame=F===null?null:{node:F,x:ao(),y:ao(),drawnX:ao(),drawnY:ao(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},mc(T)},[]),re=i.useCallback((T,F)=>{for(const q of T.bandPool)po(q);T.bandPool.length=0,T.dragBand!==null&&(po(T.dragBand),T.dragBand=null),T.bandClampWidth=-1,T.bandClampHeight=-1,T.bandClip=F,T.bandClipWidth="",T.bandClipHeight="";const J=F===null?null:F.parentElement;F!==null&&J!==null&&J.firstChild!==F&&J.insertBefore(F,J.firstChild)},[]),ge=i.useCallback(T=>{const F=()=>te(T);return{container:J=>{const q=F();q.container=J,J===null&&(q.fillPool.length=0,q.bandPool.length=0,q.dragBand=null,q.bandClampWidth=-1,q.bandClampHeight=-1)},dividerXLeading:J=>B(F(),0,J),dividerXTrailing:J=>B(F(),1,J),dividerYLeading:J=>B(F(),2,J),dividerYTrailing:J=>B(F(),3,J),frame:J=>z(F(),J),bandClip:J=>re(F(),J),active:J=>{F().active=J},dragRect:J=>{F().dragRect=J},marquee:J=>{F().marquee=J},fillPreview:J=>{F().fillPreview=J},resizeGuide:J=>{F().resizeGuide=J}}},[te,B,z,re]),Te=i.useMemo(()=>Object.fromEntries(wc.map(T=>[T,ge(T)])),[ge]),Pe=Math.min(Math.max(0,Z),t.count),ot=wu(t,Pe),je=Math.min(Math.max(0,Q),e.count),Xe=Cu(e,je),Oe=O===void 0?0:Math.min(Math.max(0,O),t.count-Pe),Ie=yu(t,Oe),Be=D===void 0?0:Math.min(Math.max(0,D),e.count-je),Et=bu(e,Be),it=i.useRef(null),on=i.useRef("add"),Ze=i.useRef(s);Ze.current=s;const kt=i.useRef(!1),Rn=rt.useWheelBridge(n,{enableBridge:!s}),Io=i.useCallback(T=>(r.current=T,Rn(T)),[r,Rn]),Sn=i.useCallback((T,F)=>({top:F.mapY(e.offsetOf(T.startRow)),bottom:F.mapY(e.offsetOf(T.endRow)+e.sizeOf(T.endRow)),left:F.mapX(t.offsetOf(T.startCol)),right:F.mapX(t.offsetOf(T.endCol)+t.sizeOf(T.endCol))}),[e,t]),Ft=i.useCallback((T,F)=>{if(F.clampHeight<=0||F.clampWidth<=0)return null;const{top:J,bottom:q,left:ne,right:ie}=Sn(T,F),fe=-F.clampHeight*Bt,Ne=F.clampHeight*(1+Bt),$e=-F.clampWidth*Bt,ue=F.clampWidth*(1+Bt);if(q<fe||J>Ne||ie<$e||ne>ue)return null;const We=Math.max(J,fe),Ke=Math.max(ne,$e);return{top:We,left:Ke,width:Math.min(ie,ue)-Ke,height:Math.min(q,Ne)-We}},[Sn]),Wr=i.useCallback((T,F)=>{if(F.clampHeight<=0||F.clampWidth<=0)return null;const J=Sn(T,F),q=-F.clampHeight*Bt,ne=F.clampHeight*(1+Bt),ie=-F.clampWidth*Bt,fe=F.clampWidth*(1+Bt),Ne=Math.min(Math.max(J.top,q),ne),$e=Math.min(Math.max(J.left,ie),fe);return{top:Ne,left:$e,width:Math.min(Math.max(J.right,ie),fe)-$e,height:Math.min(Math.max(J.bottom,q),ne)-Ne}},[Sn]),ae=i.useCallback(()=>{if(m===void 0)return null;const T=m.current;return T.row||T.column||T.intersection?T:null},[m]),ye=i.useCallback((T,F,J)=>{if(F.bandClip!==null){for(const ne of Ks(J))F.bandClip.appendChild(ne);return}const q=F.fillPool[0]?.node??hc(F);for(const ne of Ks(J))T.insertBefore(ne,q)},[]),ve=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),Fn=i.useCallback(T=>{const F=T.nodes.frame;if(F===null)return;const J=ve.current,q=C.current;(J.range!==q||J.rows!==e.count||J.cols!==t.count)&&(J.range=q,J.rows=e.count,J.cols=t.count,J.within=q===void 0?null:Mg(q,e.count,t.count));const ne=J.within,ie=F.last,fe=F.node.style;if(!(ne!==null&&ic(F.x,ne.startCol,ne.endCol,T.xFirst,T.xLast,T.mapX(t.offsetOf(ne.startCol)),T.mapX(t.offsetOf(ne.endCol)+t.sizeOf(ne.endCol)),T.clampWidth)&&ic(F.y,ne.startRow,ne.endRow,T.yFirst,T.yLast,T.mapY(e.offsetOf(ne.startRow)),T.mapY(e.offsetOf(ne.endRow)+e.sizeOf(ne.endRow)),T.clampHeight))){ie.shown&&(ie.shown=!1,fe.display="none");return}if(ie.shown||(ie.shown=!0,fe.display="block"),!cc(F.x,F.drawnX)){ac(F.drawnX,F.x);const ue=pc(F.x);ue.start!==ie.left&&(ie.left=ue.start,fe.left=ue.start),ue.end!==ie.right&&(ie.right=ue.end,fe.right=ue.end),ue.size!==ie.width&&(ie.width=ue.size,fe.width=ue.size)}if(!cc(F.y,F.drawnY)){ac(F.drawnY,F.y);const ue=pc(F.y);ue.start!==ie.top&&(ie.top=ue.start,fe.top=ue.start),ue.end!==ie.bottom&&(ie.bottom=ue.end,fe.bottom=ue.end),ue.size!==ie.height&&(ie.height=ue.size,fe.height=ue.size)}const $e=zg(F.x,F.y);$e!==ie.open&&(ie.open=$e,$e===0?F.node.removeAttribute("data-aqsp-frame-open"):F.node.setAttribute("data-aqsp-frame-open",Ng($e)))},[e,t]),ze=i.useCallback((T,F,J,q)=>{const ne=Wr(F,J);if(ne===null){fc(T);return}Pg(T,ne,J,q,ma(F,t.count)||ga(F,e.count))},[Wr,e,t]),qn=i.useCallback((T,F,J,q)=>{const ne=T.nodes.bandPool;for(;ne.length>J.length;){const ie=ne.pop();ie!==void 0&&po(ie)}if(q===null){T.nodes.dragBand!==null&&(po(T.nodes.dragBand),T.nodes.dragBand=null);return}for(let ie=0;ie<J.length;ie+=1){let fe=ne[ie];fe===void 0&&(fe=uc(),uo(fe,T.clampWidth,T.clampHeight),ye(F,T.nodes,fe),ne.push(fe)),ze(fe,J[ie],T,q)}},[ye,ze]),Qe=i.useCallback((T,F,J)=>{const q=T.nodes.container;if(q===null)return;if(F===null||J===null){T.nodes.dragBand!==null&&fc(T.nodes.dragBand);return}let ne=T.nodes.dragBand;ne===null&&(ne=uc(),uo(ne,T.clampWidth,T.clampHeight),ye(q,T.nodes,ne),T.nodes.dragBand=ne),ze(ne,F,T,J)},[ye,ze]),sn=i.useCallback((T,F)=>{if(T!==null){if(F===null){T.style.display="none";return}T.style.display="block",T.style.transform=`translate(${F.left}px, ${F.top}px)`,T.style.width=`${F.width}px`,T.style.height=`${F.height}px`}},[]),Wt=i.useCallback((T,F,J,q)=>{const ne=q==="point"?null:ae();for(const ie of k(J,F))sn(ie.nodes.dragRect,Ft(T,ie)),Qe(ie,T,ne)},[Ft,k,sn,ae,Qe]),Pn=i.useCallback((T,F,J)=>{for(const q of k(J,F))sn(q.nodes.fillPreview,T===null?null:Ft(T,q))},[Ft,k,sn]),_n=i.useCallback((T,F,J)=>{for(const q of k(J,F)){const ne=q.nodes.resizeGuide;if(ne===null)continue;if(T===null){ne.style.display="none";continue}const ie=T.anchor==="trailing";if(T.axis==="col"){if(ie&&q.xKind!=="t"){ne.style.display="none";continue}ne.style.display="block";const fe=q.mapX(T.position);ne.style.transform=`translate(${ie?Math.max(0,fe):fe}px, 0px)`,ne.style.width="1px",ne.style.height="100%"}else{if(ie&&q.yKind!=="t"){ne.style.display="none";continue}ne.style.display="block";const fe=q.mapY(T.position);ne.style.transform=`translate(0px, ${ie?Math.max(0,fe):fe}px)`,ne.style.width="100%",ne.style.height="1px"}}},[k]),pr=i.useCallback((T,F,J,q,ne,ie,fe)=>{if(T===null)return;if(F===null||fe<=0||ie<=0){T.style.clipPath=dc;return}const Ne=Dn(e,F.row,q),$e=Nn(t,F.col,J),ue=t.sizeOf(F.col),We=e.sizeOf(F.row),Ke=$e>=ie||Ne>=fe,Ae=F.col>=ne.cols&&$e<ne.width,we=F.row>=ne.rows&&Ne<ne.height,de=ne.trailingWidth>0&&F.col<t.count-ne.trailingCols&&$e+ue>ie-ne.trailingVisibleWidth,pe=ne.trailingHeight>0&&F.row<e.count-ne.trailingRows&&Ne+We>fe-ne.trailingVisibleHeight;if(Ke||Ae||we||de||pe){T.style.clipPath=dc;return}T.style.clipPath="",T.style.transform=`translate(${$e}px, ${Ne}px)`;const Re=`${ue} ${We}`;T.dataset.aqspAnchorSig!==Re&&(T.dataset.aqspAnchorSig=Re,T.style.width=`${ue}px`,T.style.height=`${We}px`)},[e,t]),hr=i.useCallback((T,F,J)=>{if(v===void 0)return;const q=v.current,{width:ne,height:ie}=T.getViewportSize(),fe=T.getFrozenSize(),Ne={scroll:J,frozenCount:fe.cols,trailingCount:fe.trailingCols,extent:ne},$e={scroll:F,frozenCount:fe.rows,trailingCount:fe.trailingRows,extent:ie};pr(x===void 0?null:x.current,q.interactive,Ne,$e,fe,ne,ie),pr(S===void 0?null:S.current,q.tip,Ne,$e,fe,ne,ie)},[v,x,S,pr]),mr=i.useCallback(()=>{const T=V.current,F=n.current;if(T===null||F===null)return;const J=F.getScrollPosition(),q=Math.max(0,J.y),ne=Math.max(0,J.x),ie=o(),fe=k(ne,q),Ne=ae(),$e=Ne===null?jg:ie.ranges.slice(-qg(fe.length));for(const we of fe){const de=we.nodes.container;if(de===null)continue;const pe=we.nodes.fillPool;for(let Re=0;Re<Math.max(pe.length,ie.ranges.length);Re+=1){let Se=pe[Re];if(Se===void 0){const Me=document.createElement("div");Me.className="aqsp-selection-fill",Me.setAttribute("data-aqsp-fill",""),Me.style.display="none",de.insertBefore(Me,hc(we.nodes)),Se={node:Me,last:{shown:!1,width:-1,height:-1,transform:""}},pe.push(Se)}const ct=ie.ranges[Re],le=ct===void 0?null:Ft(ct,we);if(le===null)Se.last.shown&&(Se.last.shown=!1,Se.node.style.display="none");else{Se.last.shown||(Se.last.shown=!0,Se.node.style.display="block");const Me=`translate(${le.left}px, ${le.top}px)`;Me!==Se.last.transform&&(Se.last.transform=Me,Se.node.style.transform=Me),le.width!==Se.last.width&&(Se.last.width=le.width,Se.node.style.width=`${le.width}px`),le.height!==Se.last.height&&(Se.last.height=le.height,Se.node.style.height=`${le.height}px`)}}for(;pe.length>ie.ranges.length;)pe.pop()?.node.remove();sn(we.nodes.active,Ft(me(ie.active,ie.active),we)),Fn(we),qn(we,de,$e,Ne)}const ue=u(),We=ue===null||ue.foreign?null:ue;for(const we of fe){const de=we.nodes.marquee;if(de===null)continue;const pe=We===null?null:Ft(We.range,we),Re=pe!==null&&(we.xSeamTrail&&pe.left>=we.clampWidth&&pe.left<we.clampWidth+Lr||we.xSeamLead&&pe.left+pe.width<=0&&pe.left+pe.width>-Lr||we.ySeamTrail&&pe.top>=we.clampHeight&&pe.top<we.clampHeight+Lr||we.ySeamLead&&pe.top+pe.height<=0&&pe.top+pe.height>-Lr)?null:pe;if(Re===null)de.style.display="none";else{de.style.display="block",de.style.transform=`translate(${Re.left}px, ${Re.top}px)`,de.style.width=`${Re.width}px`,de.style.height=`${Re.height}px`;const le=co(Re.top),Me=co(Re.left),mt=co(we.cells.clampHeight-(Re.top+Re.height)),at=co(we.cells.clampWidth-(Re.left+Re.width)),ut=`${le} ${at} ${mt} ${Me}`;ut!==de.dataset.aqspOutsetSig&&(de.dataset.aqspOutsetSig=ut,de.style.setProperty("--aqsp-clip-outset-top",le),de.style.setProperty("--aqsp-clip-outset-right",at),de.style.setProperty("--aqsp-clip-outset-bottom",mt),de.style.setProperty("--aqsp-clip-outset-left",Me))}const Se=Re===null?null:We?.kind??null,ct=de.dataset.aqspClipKindLast??null;Se!==ct&&(Se===null?(delete de.dataset.aqspClipKindLast,de.removeAttribute("data-aqsp-clip-kind")):(de.dataset.aqspClipKindLast=Se,de.setAttribute("data-aqsp-clip-kind",Se)))}it.current!==null&&Wt(it.current,q,ne,on.current),w.current!==null&&_n(w.current,q,ne),X.current!==null&&Pn(X.current,q,ne);const Ke=$.current;if(Ke!==null&&!g()){const{width:we,height:de}=F.getViewportSize(),pe=ie.ranges[ie.ranges.length-1];if(!(ie.ranges.length===1&&!Ze.current&&!h())||de<=0||we<=0)Ke.style.display="none";else{const Se=F.getFrozenSize(),ct={scroll:ne,frozenCount:Se.cols,trailingCount:Se.trailingCols,extent:we},le={scroll:q,frozenCount:Se.rows,trailingCount:Se.trailingRows,extent:de},Me=pe.endCol<Se.cols,mt=pe.endRow<Se.rows,at=pe.endCol>=t.count-Se.trailingCols,ut=pe.endRow>=e.count-Se.trailingRows,Le=Nn(t,pe.endCol,ct)+t.sizeOf(pe.endCol),dt=Dn(e,pe.endRow,le)+e.sizeOf(pe.endRow),Kt=Me||at?0:Se.width,gt=mt||ut?0:Se.height,Ye=at?we:we-Se.trailingVisibleWidth,qt=ut?de:de-Se.trailingVisibleHeight;dt<=gt||dt>qt||Le<=Kt||Le>Ye?Ke.style.display="none":(Ke.style.display="block",Ke.style.transform=`translate(${Le-Cc+1}px, ${dt-Cc+1}px)`)}}const Ae=r.current;if(Ae!==null){const we=ie.active,{width:de,height:pe}=F.getViewportSize(),Re=F.getFrozenSize(),Se={scroll:ne,frozenCount:Re.cols,trailingCount:Re.trailingCols,extent:de},ct={scroll:q,frozenCount:Re.rows,trailingCount:Re.trailingRows,extent:pe},le=Dn(e,we.row,ct),Me=Nn(t,we.col,Se),mt=pe>0?Math.min(Math.max(le,0),Math.max(0,pe-1)):0,at=de>0?Math.min(Math.max(Me,0),Math.max(0,de-1)):0;Ae.style.top=`${mt}px`,Ae.style.left=`${at}px`,Ze.current?(Ae.style.width=`${t.sizeOf(we.col)}px`,Ae.style.height=`${e.sizeOf(we.row)}px`,Ae.style.paddingTop=`${_g(e.sizeOf(we.row),j===void 0?Qt:j.current)}px`):(Ae.style.width="1px",Ae.style.height="1px",Ae.style.paddingTop="0px");const ut=we.col>=Re.cols&&Me<Re.width,Le=we.row>=Re.rows&&le<Re.height,dt=Re.trailingWidth>0&&we.col<t.count-Re.trailingCols&&Me+t.sizeOf(we.col)>de-Re.trailingVisibleWidth,Kt=Re.trailingHeight>0&&we.row<e.count-Re.trailingRows&&le+e.sizeOf(we.row)>pe-Re.trailingVisibleHeight,gt=Ze.current&&le===mt&&Me===at&&!ut&&!Le&&!dt&&!Kt;gt!==kt.current&&(kt.current=gt,gt?Ae.setAttribute("data-aqsp-editing",""):Ae.removeAttribute("data-aqsp-editing"))}hr(F,q,ne)},[n,Ft,k,sn,Wt,_n,Pn,u,o,h,g,$,r,e,t,ae,qn,Fn,j,hr]),Cl=i.useCallback((T,F)=>{it.current=T,on.current=F;const J=T===null?"add":F;for(const ie of k(0,0)){const fe=ie.nodes.dragRect;if(fe===null)continue;const Ne=fe.dataset.aqspDragModeLast??"add";J!==Ne&&(fe.dataset.aqspDragModeLast=J,J==="add"?fe.removeAttribute("data-aqsp-drag-mode"):fe.setAttribute("data-aqsp-drag-mode",J))}const q=n.current;if(T===null||q===null){for(const ie of k(0,0))ie.nodes.dragRect!==null&&(ie.nodes.dragRect.style.display="none"),Qe(ie,null,null);return}const ne=q.getScrollPosition();Wt(T,Math.max(0,ne.y),Math.max(0,ne.x),F)},[n,Wt,k,Qe]),Ho=i.useCallback(T=>{X.current=T;const F=n.current;if(F===null){for(const q of k(0,0))q.nodes.fillPreview!==null&&(q.nodes.fillPreview.style.display="none");return}const J=F.getScrollPosition();Pn(T,Math.max(0,J.y),Math.max(0,J.x))},[n,Pn,k]),gr=i.useCallback(T=>{w.current=T;const F=n.current;if(F===null){for(const q of k(0,0))q.nodes.resizeGuide!==null&&(q.nodes.resizeGuide.style.display="none");return}const J=F.getScrollPosition();_n(T,Math.max(0,J.y),Math.max(0,J.x))},[n,_n,k]);i.useLayoutEffect(()=>{const T=V.current;if(!(T===null||y===void 0))return T.style.setProperty("--aqsp-band-row",y.row),T.style.setProperty("--aqsp-band-column",y.column),T.style.setProperty("--aqsp-band-intersection",y.intersection),T.style.setProperty("--aqsp-band-opacity",String(y.opacity)),()=>{T.style.removeProperty("--aqsp-band-row"),T.style.removeProperty("--aqsp-band-column"),T.style.removeProperty("--aqsp-band-intersection"),T.style.removeProperty("--aqsp-band-opacity")}},[y]),i.useEffect(()=>(c.current=mr,a.current=Cl,L.current=Ho,M.current=gr,()=>{c.current=null,a.current=null,L.current=null,M.current=null})),i.useEffect(()=>{mr()},[mr,s,Pe,je,Oe,Be]),i.useEffect(()=>{const T=r.current;if(T===null)return;const F=J=>P(J);return T.addEventListener("mousedown",F),()=>T.removeEventListener("mousedown",F)},[r,P]);const jn=Pe>0||Oe>0?[...Pe>0?[{k:"f",style:{left:0,width:ot}}]:[],{k:"s",style:{left:ot,right:Ie}},...Oe>0?[{k:"t",style:{right:0,width:Ie}}]:[]]:[{k:"m",style:{left:0,right:0}}],wr=je>0||Be>0?[...je>0?[{k:"f",style:{top:0,height:Xe}}]:[],{k:"s",style:{top:Xe,bottom:Et}},...Be>0?[{k:"t",style:{bottom:0,height:Et}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],ln=T=>T==="m"?0:T==="s"?1:T==="t"?2:3,cn=jn.flatMap(T=>wr.map(F=>({xk:T.k,yk:F.k,key:`${T.k}${F.k}`,style:{...T.style,...F.style}}))).sort((T,F)=>ln(T.key[0])+ln(T.key[1])-(ln(F.key[0])+ln(F.key[1]))),Ve=T=>T==="mm"?{"data-aqsp-overlay-main":""}:T==="fm"?{"data-aqsp-overlay-frozen":""}:T==="sm"?{"data-aqsp-overlay-scroll":""}:{};return I.jsxs("div",{ref:V,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[cn.map(({xk:T,yk:F,key:J,style:q})=>{const ne=Te[J];return I.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":J,...Ve(J),style:q,ref:ne.container,children:[A?I.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:ne.bandClip}):null,T==="s"&&Pe>0?I.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:ne.dividerXLeading}):null,T==="s"&&Oe>0?I.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:ne.dividerXTrailing}):null,F==="s"&&je>0?I.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:ne.dividerYLeading}):null,F==="s"&&Be>0?I.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:ne.dividerYTrailing}):null,A?I.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:ne.frame}):null,I.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:ne.active}),I.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:ne.dragRect}),I.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:ne.marquee}),I.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:ne.fillPreview}),I.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:ne.resizeGuide})]},J)}),I.jsx("textarea",{ref:Io,className:"aqsp-sink","aria-label":W,"aria-readonly":K?"true":void 0,"aria-keyshortcuts":E,tabIndex:-1,defaultValue:" ",inputMode:l,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),H?I.jsx("div",{ref:$,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ru=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=g=>{l.current=!0;try{g()}finally{l.current=!1}},a=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},u=g=>{if(g.key==="Escape"){g.preventDefault(),c(e.close);return}g.key==="Enter"&&(g.ctrlKey||g.metaKey)&&!g.altKey&&!g.shiftKey&&(g.preventDefault(),a())},h=g=>{l.current||g.relatedTarget instanceof Node&&g.currentTarget.contains(g.relatedTarget)||e.rejected||c(e.close)};return I.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:h,children:[I.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[be(t,"commentTitle"),I.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:be(t,"commentCount",e.current.length)})]}),I.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(g=>I.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":g.id,children:[I.jsx("span",{className:"aqsp-popover-comment-author",children:g.author}),I.jsx("time",{className:"aqsp-popover-comment-time",dateTime:g.createdAt,children:g.createdAt}),I.jsx("p",{className:"aqsp-popover-comment-text",children:g.text})]},g.id))}),I.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":be(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:g=>r(g.currentTarget.value),onKeyDown:u}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:a,children:be(t,"commentPost")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Su=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),a=i.useRef(!1),u=o.trim()===""?null:bn(o),h=o.trim()!==""&&u===null,g=H=>{a.current=!0;try{H()}finally{a.current=!1}},L=()=>{l||h||g(()=>e.commit({text:n===""&&u!==null?u:n,url:u}))},M=H=>{if(H.key==="Escape"){H.preventDefault(),g(e.close);return}H.key==="Enter"&&!H.altKey&&!H.shiftKey&&(H.preventDefault(),L())},$=H=>{a.current||H.relatedTarget instanceof Node&&H.currentTarget.contains(H.relatedTarget)||e.rejected||g(e.close)};return I.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":h?"":void 0,role:"dialog","aria-labelledby":c,onBlur:$,children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:be(t,"linkTitle")}),I.jsxs("label",{className:"aqsp-popover-field",children:[I.jsx("span",{className:"aqsp-popover-field-label",children:be(t,"linkTextField")}),I.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:H=>r(H.currentTarget.value),onKeyDown:M})]}),I.jsxs("label",{className:"aqsp-popover-field",children:[I.jsx("span",{className:"aqsp-popover-field-label",children:be(t,"linkUrlField")}),I.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":h||e.rejected?!0:void 0,onChange:H=>s(H.currentTarget.value),onKeyDown:M})]}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:h||l,"aria-disabled":l?"true":void 0,onClick:L,children:be(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:be(t,"linkOpen")}):null,I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>g(e.close),children:"×"})]})]})},Mo=500,Eu=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),a=i.useMemo(()=>{const Q=n.toLowerCase();return e.current.filter(O=>O.toLowerCase().startsWith(Q))},[e.current,n]),u=i.useMemo(()=>a.length>Mo?a.slice(0,Mo):a,[a]),h=a.length-u.length,g=u.length===0?-1:Math.min(o,u.length-1),L=Q=>{c.current=!0;try{Q()}finally{c.current=!1}},M=()=>{g<0||L(()=>e.commit(u[g]))},$=Q=>{if(Q.key==="Escape"){Q.preventDefault(),L(e.close);return}if(Q.key==="Enter"){Q.preventDefault(),M();return}if(Q.key==="ArrowDown"){Q.preventDefault(),s(g+1);return}Q.key==="ArrowUp"&&(Q.preventDefault(),s(Math.max(g-1,0)))},H=Q=>{c.current||Q.relatedTarget instanceof Node&&Q.currentTarget.contains(Q.relatedTarget)||L(e.close)},Z=Q=>`${l}-${Q}`;return I.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:H,children:[I.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":be(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":g<0?void 0:Z(g),value:n,onChange:Q=>{r(Q.currentTarget.value),s(0)},onKeyDown:$}),I.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":be(t,"listTitle"),children:[u.length===0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:be(t,"listEmpty")}):u.map((Q,O)=>I.jsx("div",{className:"aqsp-popover-option",id:Z(O),role:"option",tabIndex:-1,"aria-selected":O===g,"data-aqsp-list-option":Q,onPointerDown:D=>D.preventDefault(),onClick:()=>L(()=>e.commit(Q)),children:Q},Z(O))),h>0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:be(t,"listMore",h)}):null]})]})},ku=({ctx:e,labels:t})=>I.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),I.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ou=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),a=i.useRef(!1),u=$=>{a.current=!0;try{$()}finally{a.current=!1}},h=()=>{s||u(()=>e.commit(r===""?null:r))},g=()=>{r!==n&&!s?h():u(e.close)},L=$=>{if($.key==="Escape"){$.preventDefault(),e.rejected?u(e.close):g();return}$.key==="Enter"&&($.ctrlKey||$.metaKey)&&!$.altKey&&!$.shiftKey&&($.preventDefault(),h())},M=$=>{a.current||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||e.rejected||g()};return I.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:M,children:[I.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:be(t,"noteTitle")}),I.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:$=>o($.currentTarget.value),onKeyDown:L}),I.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:be(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:h,children:be(t,"noteSave")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":be(t,"popoverClose"),onClick:()=>u(e.close),children:"×"})]})]})},xu=({ctx:e})=>I.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Jt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),yc=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Au=Object.freeze({all:Jt(yc),values:Jt(["text"]),formats:Jt(["format","borders","cf"]),formulas:Jt(["text","formula"]),noBorders:Jt(yc.filter(e=>e!=="borders")),columnWidths:Jt(["sizes"]),validation:Jt(["validation"]),conditionalFormats:Jt(["cf"]),commentsAndNotes:Jt(["note","comments"])}),bc=Object.freeze({mode:"all"}),Ys=Object.freeze({t:""}),vc=Object.freeze({row:1<<30,col:1<<30}),Vg=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Wg=e=>e.t===""&&e.f===void 0,Kg=e=>e.length>1&&e.startsWith("="),Yg=(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}},Rc=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Xg=(e,t,n,r)=>{const o=Kg(e),s=e===""?"0":Rt(e);if(!o&&s===null)return null;const l=Vg[n];if(t.f!==void 0){const u=Ir(t.f,r),h=u.startsWith("=")?u.slice(1):u;return`=(${o?e.slice(1):s})${l}(${h})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Rc(Number(s));const c=Rt(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${l}(${c})`:Rc(Yg(Number(s),a,n))},Sc=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Ug=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:Sc(e.start),end:Sc(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}}}},Gg=e=>{const t=Ir(e,vc),n=jr(t);let r="",o=0,s=!1;for(const l of n){const c=Ug(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${hn(c)}`,o=l.end,s=!0)}return s?qo(`${r}${t.slice(o)}`,vc):e},Jg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Ys;const o=r[n];return o===void 0?Ys:o},Zg=e=>{const{rows:t,cols:n}=e,r=Ta(Gg);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let u=0;u<t;u+=1){const h=Jg(e,u,c);let g=h;if(h.f!==void 0){const L=r(h.f);g=L===h.f?h:{...h,f:L}}(g!==h||h===Ys)&&(o=!1),a.push(g)}s.push(a)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},Qg=(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,ew=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},Ec=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const u=[];for(const h of c)Qg(h,t)?(u.push(ew(h,t)),a=!0):u.push(h);a&&(n=!0),r.push(a?u:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},kc=new WeakMap,Tu=e=>{const t=kc.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>Nt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:Nt({...s,borders:void 0})),o={canonical:n,borderless:r};return kc.set(e,o),o},Lo=(e,t)=>t===void 0?void 0:e[t],tw=(e,t,n,r)=>{const o=Tu(e);if(n){const u=Lo(o.canonical,t.fmt);return u===void 0?null:u}const s=Lo(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const a=Nt(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},nw=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Xg(n.readText(),o,r,n):o.f===void 0?o.t:Ir(o.f,n)},Oc=(e,t,n,r,o)=>{const s=Au[r.mode];if(r.skipBlanks===!0&&Wg(e))return null;const l={};let c=!1;if(s.text){const a=nw(e,s.formula&&o.formula,n,r.operation);a!==null&&(l.text=a,c=!0)}if(o.format){if(s.format)l.format=tw(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=Lo(Tu(t).canonical,e.fmt);a!==void 0&&(l.format=a,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const a=Lo(t.validations,e.val);l.validation=a===void 0?null:a,c=!0}return c?l:null},xc=(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}}),rw=["text/html","text/plain"],ow=(e,t,n)=>{if(e===0||t===0)return 0;const r=St(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},sw=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,lw=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,iw=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}}},Ac=e=>{const t=e.clipboardData;return t??null},cw=(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}},aw=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=cw(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},uw=(e,t,n,r,o)=>{const s=dr(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=qo(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(l.fmt=a)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:a,author:u,createdAt:h})=>({text:a,author:u,createdAt:h})))}if(e.getCellHyperlink!==void 0){const c=fr(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},$u=(e,t)=>{const n=ha(),r=sp(),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(uw(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:aw(e.getConditionalFormats(),t)}},Tc=e=>e.kind==="cut"?{...e.payload,...$u(e.sourceAdapter,e.range)}:e.payload,dw=e=>({v:1,rows:e.length,cols:e[0].length,clipId:nl(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),fw=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=bn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:a,...u}=l;s.push(u)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},pw=(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},hw=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return me({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},mw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(O=>{const D=n.current;if(D===null||O==="format"||O==="annotate")return;const W=r.current;W==="own"||W==="foreign"&&D.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const O=n.current;if(O===null)return;if(O.kind==="copy"){o();return}const D=t.current;D.repaintOverlay(),D.onClipChange?.({kind:"cut",range:O.range,foreign:O.sourceAdapter!==D.adapter})},[o]),c=i.useCallback((O,D,W)=>{const K=t.current;n.current={kind:O,range:D,clipId:W.clipId,sourceAdapter:K.adapter,payload:W},K.repaintOverlay(),K.onClipChange?.({kind:O,range:D,foreign:!1})},[]),a=i.useCallback(O=>{const D=t.current,W=D.adapter,K=St(O),E={v:1,rows:K.rows,cols:K.cols,clipId:nl(),...$u(W,O),wholeRows:ma(O,W.colCount),wholeCols:ga(O,W.rowCount)};if(D.resize!==void 0){if(E.wholeCols){const P=[];for(let j=O.startCol;j<=O.endCol;j+=1)P.push(Math.min(D.resize.colAxis.sizeOf(j),yn));E.colWidths=P}if(E.wholeRows){const P=[];for(let j=O.startRow;j<=O.endRow;j+=1)P.push(Math.min(D.resize.rowAxis.sizeOf(j),yn));E.rowHeights=P}}return E},[]),u=i.useCallback((O,D)=>{const W=t.current,K=W.getSelection(),E=K.ranges[K.ranges.length-1],P=vt([E]);if(P>W.maxOperationCells)return O.preventDefault(),W.onOperationRejected?.(D,P,"limit"),null;if(D==="cut"&&Mr(W.adapter,E))return O.preventDefault(),W.rejectReadOnly({kind:"operation",op:"cut",cellCount:P}),null;K.ranges.length>1&&W.onCopyMultiRange?.();const j=a(E),m=ra(j),d=Ac(O);return d!==null&&(d.setData("text/plain",nn.serializeClipboardTsv(j.cells.map(y=>y.map(v=>v.t)))),d.setData("text/html",Ya(j,m)),d.setData(xo,m)),O.preventDefault(),{payload:j,range:E}},[a]),h=i.useCallback((O,D)=>t.current.commitPaste(O,D)!==null,[]),g=i.useCallback((O,D,W)=>{const K=t.current;if(!W.sizes||K.resize===void 0)return;const{rowAxis:E,colAxis:P,resizeTracks:j}=K.resize;if(j===void 0)return;const m=(d,y,v)=>{const x=Zs(y,v,null,{maxOperationCells:K.maxOperationCells,rowHiddenLimit:Gs,axisKind:d});if(!x.ok){K.onOperationRejected?.("resize",x.count,x.reason);return}j(d,x.entries)};if(O.colWidths!==void 0){const d=[];for(let y=D.startCol;y<=D.endCol;y+=1)d.push({index:y,size:O.colWidths[(y-D.startCol)%O.cols]});m("col",P,d)}if(O.rowHeights!==void 0){const d=[];for(let y=D.startRow;y<=D.endRow;y+=1)d.push({index:y,size:O.rowHeights[(y-D.startRow)%O.rows]});m("row",E,d)}},[]),L=i.useCallback((O,D)=>{const W=t.current,K=W.adapter,E=O.payload,P={row:D.startRow,col:D.startCol},j=E.rows*E.cols+vt([O.range]);if(j>W.maxOperationCells)return W.onOperationRejected?.("paste",j,"limit"),"rejected";if(P.row+E.rows>K.rowCount||P.col+E.cols>K.colCount||O.range.endRow>=O.sourceAdapter.rowCount||O.range.endCol>=O.sourceAdapter.colCount)return W.onOperationRejected?.("paste",j,"bounds"),"rejected";const m=Bs({rows:E.rows,cols:E.cols},me(P,P),P,K.rowCount,K.colCount);if(m!==null&&Mr(K,m))return W.rejectReadOnly({kind:"operation",op:"paste",cellCount:E.rows*E.cols}),"rejected";if(Mr(O.sourceAdapter,O.range))return W.rejectReadOnly({kind:"operation",op:"cut",cellCount:vt([O.range])}),"rejected";const d=Tc(O),y=ko(K),v=Ec(d,y),x={row:0,col:0,readText:()=>dr(K,x.row,x.col).text,readFormat:()=>K.getCellFormat===void 0?void 0:K.getCellFormat(x.row,x.col)},{edits:S,tiles:V}=Ki(v.cells,me(P,P),P,K.rowCount,K.colCount,(X,w,G)=>(x.row=O.range.startRow+(w-P.row),x.col=O.range.startCol+(G-P.col),Oc(X,v,x,bc,y))),C=ko(O.sourceAdapter),A=[];if(fn([O.range],X=>{A.push(pw(X.row,X.col,C))}),O.sourceAdapter===K){if(!h([...A,...S],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const X=W.commitPaste(S,{sameSheet:!1,conditionalFormats:xc(v.conditionalFormats,V)});if(X===null)return"rejected";try{O.sourceAdapter.applyEdits(A,{transaction:X,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(w){W.onEditRejected?.(w,{source:"paste"})}}return W.setSelection({ranges:[me(P,{row:P.row+d.rows-1,col:P.col+d.cols-1})],anchor:P,active:P}),"applied"},[h]),M=i.useCallback((O,D,W)=>{const K=t.current,E=K.adapter,P=_=>(K.onClipboardUnavailable?.(_),"rejected"),j=la(O,D);if(j==="none")return D==="menu"?P("empty"):"empty";const m=K.getSelection(),d=m.ranges[m.ranges.length-1],y=W.transpose===!0,v=(_,Y)=>{const U=ow(y?Y:_,y?_:Y,d);return U>K.maxOperationCells?(K.onOperationRejected?.("paste",U,"limit"),!0):!1};let x,S=null;if(j==="aqsp"){const _=Lf(O,D);if(_===null)return P("unreadable");const Y=n.current;if(Y!==null&&_.clipId===Y.clipId&&(S=Y),S!==null&&S.kind==="cut"&&sw(W))return L(S,d);if(v(_.rows,_.cols))return"rejected";if(S!==null){if(S.kind==="cut"&&(S.range.endRow>=S.sourceAdapter.rowCount||S.range.endCol>=S.sourceAdapter.colCount))return K.onOperationRejected?.("paste",S.payload.rows*S.payload.cols,"bounds"),"rejected";x=Tc(S)}else{const U=zf(O,D);if(U===null)return P("unreadable");if(v(U.rows,U.cols))return"rejected";x=fw(U)}}else if(j==="tsv"){const _=O.getData("text/plain"),Y=nn.measureTsv(_);if(v(Y.rows,Y.cols))return"rejected";x=dw(nn.parseTsv(_))}else{const _=O.getData("text/html"),Y=op(_);if(Y.cols===0&&Y.rows>K.maxOperationCells)return K.onOperationRejected?.("paste",Y.rows,"limit"),"rejected";if(v(Y.rows,Y.cols))return"rejected";const U=Ja(_,j,K.formats===void 0?{}:{currency:K.formats.currency,locale:K.formats.locale},K.maxOperationCells);if(U.outcome==="none")return P("unreadable");if(U.outcome==="limit")return K.onOperationRejected?.("paste",U.cells,"limit"),"rejected";if(v(U.payload.rows,U.payload.cols))return"rejected";x=U.payload}const V=ko(E),C=Ec(y?Zg(x):x,V),A=Au[W.mode];if(lw(A)){const _=Bs({rows:C.rows,cols:C.cols},d,m.active,E.rowCount,E.colCount);if(_!==null&&Mr(E,_))return K.rejectReadOnly({kind:"operation",op:"paste",cellCount:vt([_])}),"rejected"}const X={row:0,col:0,readText:()=>dr(E,X.row,X.col).text,readFormat:()=>E.getCellFormat===void 0?void 0:E.getCellFormat(X.row,X.col)},{edits:w,tiles:G}=Ki(C.cells,d,m.active,E.rowCount,E.colCount,(_,Y,U)=>(X.row=Y,X.col=U,Oc(_,C,X,W,V))),te=hw(G,C.rows,C.cols,E.rowCount,E.colCount);if(te===null)return"empty";if(A.cf&&C.conditionalFormats.length>0){let _=0;for(const U of C.conditionalFormats)_+=U.ranges.length;const Y=G.length*_;if(Y>K.maxOperationCells)return K.onOperationRejected?.("paste",Y,"limit"),"rejected"}const f=A.cf?xc(C.conditionalFormats,G):[];if(w.length===0&&f.length===0)return g(C,te,A),"empty";r.current=S===null?"foreign":"own";let b=!1;try{b=h(w,{sameSheet:S!==null&&S.sourceAdapter===E,conditionalFormats:f})}finally{r.current="none"}if(!b)return"rejected";g(C,te,A);const R={row:te.startRow,col:te.startCol};return K.setSelection({ranges:[te],anchor:R,active:R}),"applied"},[L,h,g]),$=i.useCallback(async O=>{const D=y=>(t.current.onClipboardUnavailable?.(y),"rejected"),W=navigator;if(W.clipboard===void 0)return D("insecure-origin");let K;try{K=await W.clipboard.read({unsanitized:["text/html"]})}catch{return D("permission-denied")}if(K.length===0)return D("empty");const E=K[0],P=Array.from(E.types),j=new Map;try{for(const y of rw)P.includes(y)&&j.set(y,await(await E.getType(y)).text())}catch{return D("unreadable")}const m={types:P,getData:y=>{const v=j.get(y);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${y} was not materialised for the menu path`);return v}},d=t.current;return!d.enabled||d.isDragging()||d.isEditing()?"rejected":M(m,"menu",O)},[M]),H=i.useCallback(async O=>{const D=await $(O);return t.current.onPasteResolved?.(D,"menu"),D},[$]),{enabled:Z,sinkRef:Q}=e;return i.useEffect(()=>{const O=Q.current;if(!Z||O===null)return;const D=P=>t.current.isDragging()?(P.preventDefault(),!0):!1,W=P=>{const j=t.current;if(D(P)||j.isEditing())return;const m=u(P,"copy");m!==null&&c("copy",m.range,m.payload)},K=P=>{const j=t.current;if(D(P)||j.isEditing())return;const m=u(P,"cut");m!==null&&c("cut",m.range,m.payload)},E=P=>{const j=t.current;if(D(P)||j.isEditing())return;P.preventDefault();let m=bc;const d=j.pendingPasteOptionsRef;d!==void 0&&d.current!==null&&(m=d.current,d.current=null);const y=Ac(P);if(y===null)return;const v=M(iw(y),"event",m);j.onPasteResolved?.(v,"event")};return O.addEventListener("copy",W),O.addEventListener("cut",K),O.addEventListener("paste",E),()=>{O.removeEventListener("copy",W),O.removeEventListener("cut",K),O.removeEventListener("paste",E)}},[Z,Q,u,c,M]),i.useMemo(()=>({getClip:()=>{const O=n.current;return O===null?null:{kind:O.kind,range:O.range,foreign:O.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:H}),[o,s,l,H])},Mu=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)}`)},Lu=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}},$c=(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}`}`},zu=(e,t)=>{let n;if(e.exponent===null)n=$c(e.negative,e.digits,e.point+t);else{const r=$c(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Rt(n)===null?null:n},gw=(e,t)=>{Mu(t);const n=Rt(e);return n===null?null:zu(Lu(n),t)},ww=e=>{const t=Rt(e);if(t!==null){const r=Lu(t);return zu({...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)},Cw=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},Du=(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 Cw(r)?r:null},yw=(e,t)=>{Mu(t);const n=Nu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Du(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},bw=e=>{const t=Nu(e),n=Du(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},xr=(e,t,n,r)=>{const o=vt(t);return o>n?(r?.(e,o,"limit"),!1):!0},ho={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},mo={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Mc={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:ho.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:ho.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:ho.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:ho.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:mo.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:mo.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:mo.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:mo.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"}},vw={down:"fillDown",right:"fillRight",selection:"fillSelection"},Rw={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},Fr=e=>e<10?`0${e}`:String(e),Sw=e=>{const t=new Date(e);return`${t.getFullYear()}-${Fr(t.getMonth()+1)}-${Fr(t.getDate())}`},Ew=e=>{const t=new Date(e);return`${Fr(t.getHours())}:${Fr(t.getMinutes())}:${Fr(t.getSeconds())}`},kw=(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),Ow=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),xw=e=>e===void 0||e.borders===void 0?{}:e.borders,Aw={top:1,right:2,bottom:4,left:8},Tw={style:"thin",color:Qs},$w=(e,t)=>{if(e===void 0)return!1;const n=lt(e);return n!==null&&n===lt(t)},Mw=(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}}},Lw=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const m=t.current;if(m.isEditing()){const d=m.getActive();return[me(d,d)]}return m.getSelection().ranges},[]),r=i.useCallback(()=>{const m=t.current,d=m.getActive();return m.adapter.getCellFormat===void 0?void 0:m.adapter.getCellFormat(d.row,d.col)},[]),o=i.useCallback(m=>{const d=t.current,y=n();if(!xr("format",y,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y))return d.rejectReadOnly({kind:"operation",op:"format",cellCount:vt(y)}),!1;const v=new Map,x=[],S=d.adapter.getCellFormat;for(const V of y)fn([V],C=>{const A=S===void 0?void 0:S(C.row,C.col),{bucket:X,patch:w}=m(C,V,A);let G=v.get(X);G===void 0&&(G=new Map,v.set(X,G));let te;G.has(A)?te=G.get(A):(te=tl(A,w),G.set(A,te)),te!==A&&x.push({row:C.row,col:C.col,format:te===void 0?null:te})});return x.length===0?!0:d.commitEdits(x,{source:"format"})===null?!1:(d.isEditing()&&d.refreshEditPaint(),!0)},[n]),s=i.useCallback(m=>o(()=>({bucket:0,patch:m})),[o]),l=i.useCallback((m,d)=>{const y=t.current;y.formatCommandAnnouncement!==void 0&&y.announce(y.formatCommandAnnouncement({command:m,state:d}))},[]),c=i.useCallback((m,d=Tw)=>{if(m==="clear")return s({borders:null});if(m==="all")return s({borders:{top:d,right:d,bottom:d,left:d}});const y=m==="outer"?15:Aw[m];return o((v,x,S)=>{const V=kw(v,x)&y;return{bucket:V,patch:{borders:{...xw(S),...Ow(V,d)}}}})},[s,o]),a=i.useCallback((m,d,y)=>{const v=nu(t.current.adapter,m.row,m.col);for(const x of d)y.push(ru(v,m,x))},[]),u=i.useCallback(m=>{const d=t.current,y=d.getSelection();if(!xr("fill",y.ranges,d.maxOperationCells,d.onOperationRejected))return!1;const v=[],x=[],S=[];if(m==="selection"){const C=y.active,A=[];fn(y.ranges,X=>{(X.row!==C.row||X.col!==C.col)&&A.push(X)}),v.push({source:C,targets:A}),x.push(me(C,C));for(const X of y.ranges)S.push(...wm(X,C))}else for(const C of y.ranges)if(m==="down"){const A=C.startRow===C.endRow;if(A&&C.startRow===0)continue;const X=A?C.startRow-1:C.startRow,w=A?C.startRow:C.startRow+1;x.push(me({row:X,col:C.startCol},{row:X,col:C.endCol})),S.push(me({row:w,col:C.startCol},{row:C.endRow,col:C.endCol}));for(let G=C.startCol;G<=C.endCol;G+=1){const te=[];for(let f=w;f<=C.endRow;f+=1)te.push({row:f,col:G});v.push({source:{row:X,col:G},targets:te})}}else{const A=C.startCol===C.endCol;if(A&&C.startCol===0)continue;const X=A?C.startCol-1:C.startCol,w=A?C.startCol:C.startCol+1;x.push(me({row:C.startRow,col:X},{row:C.endRow,col:X})),S.push(me({row:C.startRow,col:w},{row:C.endRow,col:C.endCol}));for(let G=C.startRow;G<=C.endRow;G+=1){const te=[];for(let f=w;f<=C.endCol;f+=1)te.push({row:G,col:f});v.push({source:{row:G,col:X},targets:te})}}for(const C of v)for(const A of C.targets)if(nt(d.adapter,A.row,A.col))return d.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(S),gesture:vw[m],sources:x,targets:S}),!1;const V=[];for(const C of v)a(C.source,C.targets,V);return V.length===0?!0:d.commitEdits(V,{source:"fill"})!==null},[a]),h=i.useCallback(()=>{const m=t.current,d=m.getSessionText();if(d===null)return!1;const y=m.getSelection();if(!xr("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(nr(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(y.ranges),gesture:"fillSelection",sources:[],targets:y.ranges}),!1;const v=[];let x=!1;return fn(y.ranges,S=>{if(!x){if(!m.validateCommit(S,d).ok){x=!0;return}v.push({row:S.row,col:S.col,text:d})}}),x||m.commitEdits(v,{source:"fill"})===null?!1:(m.cancelEdit(),!0)},[]),g=i.useCallback(m=>{const d=t.current,y=d.getSelection();if(!xr("calc",y.ranges,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y.ranges))return d.rejectReadOnly({kind:"operation",op:"calc",cellCount:vt(y.ranges)}),!1;const v=[],x=d.adapter;return fn(y.ranges,S=>{const V=x.getCellFormula===void 0?void 0:x.getCellFormula(S.row,S.col),C=V===void 0?m.text(x.getCellText(S.row,S.col)):m.formula(V);C!==null&&v.push({row:S.row,col:S.col,text:C})}),v.length===0?!0:d.commitEdits(v,{source:"calc"})!==null},[]),L=i.useCallback((m,d)=>{const y=t.current,v=y.resizeTracks;if(v===void 0)return!1;const x=m==="row"?y.rowAxis:y.colAxis,S=y.getSelection(),V=m==="row"?Math.floor(y.maxOperationCells/Js):y.maxOperationCells;let C=0;for(const te of S.ranges)C+=m==="row"?te.endRow-te.startRow+1:te.endCol-te.startCol+1;if(C>V)return y.onOperationRejected?.("resize",C,"limit"),!1;const A=new Set,X=[],w=d?0:m==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const te of S.ranges){const f=m==="row"?te.startRow:te.startCol,b=m==="row"?te.endRow:te.endCol;for(let R=f;R<=b;R+=1){if(A.has(R))continue;A.add(R),x.sizeOf(R)===0!==d&&X.push({index:R,size:w})}}const G=Zs(x,X,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:Gs,axisKind:m});return G.ok?(G.entries.length>0&&v(m,G.entries),!0):(y.onOperationRejected?.("resize",G.count,G.reason),!1)},[]),M=i.useCallback(()=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)return;const d=m.getActive();return fr(m.adapter.getCellHyperlink(d.row,d.col))},[]),$=i.useCallback(m=>{const d=t.current,y=d.adapter,v=Mc[m],x=y.getCellFormat!==void 0,S=V=>d.popovers===void 0?!0:d.popovers[V]!==!1;if(v.kind==="popover"&&v.popover==="list"&&d.columnMenu?.isColumnMenuCell(d.getActive())===!0)return!0;switch(v.kind){case"resize":return d.trackResize!==void 0;case"hide":return d.resizeTracks!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return x;case"value":return x&&(v.value!=="currency"||d.formats!==void 0);case"popover":switch(v.popover){case"link":return y.getCellHyperlink!==void 0&&S("link");case"note":return y.getCellNote!==void 0&&S("note");case"comment":return y.getCellComments!==void 0&&S("comment");default:return y.getCellValidation!==void 0&&S("list")}case"openHyperlink":return y.getCellHyperlink!==void 0&&(d.onHyperlinkOpen!==void 0?M()!==void 0:S("link"));case"paste":return v.options.mode==="formats"?x:v.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[M]),H=i.useCallback(m=>{const d=t.current,y=m.kind==="popover"?m.popover:m.kind==="openHyperlink"&&d.onHyperlinkOpen===void 0?"link":void 0;if(y===void 0)return!0;const v=d.getActive();if(!nt(d.adapter,v.row,v.col))return!0;if(y==="list")return d.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let x;if(y==="link")x=M()!==void 0;else if(y==="note"){const S=d.adapter.getCellNote===void 0?void 0:d.adapter.getCellNote(v.row,v.col);x=S!==void 0&&S!==""}else{const S=d.adapter.getCellComments===void 0?void 0:d.adapter.getCellComments(v.row,v.col);x=S!==void 0&&S.length>0}return x?!0:(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[M]),Z=i.useCallback((m,d,y)=>{const v=t.current,x=v.trackResize;if(x===void 0)return!1;const S=v.getActive(),V=d==="col"?S.col:S.row,C=y==="fit"?x.autofitColumn(V):x.stepTrack(d,V,y),A=(d==="col"?v.colAxis:v.rowAxis).sizeOf(V);return C&&A>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:m,axis:d==="col"?"column":"row",index:V,size:A})),C},[]),Q=i.useCallback(m=>{const d=t.current;if(!$(m))return!1;const y=Mc[m];if(y.kind==="popover"&&y.popover==="list"&&d.columnMenu!==void 0){const x=d.getActive();if(d.columnMenu.isColumnMenuCell(x))return d.columnMenu.open(x)}if(!H(y))return!1;const v=d.isEditing();if(v&&!$o.has(m)&&!d.requestCommit())return!1;switch(y.kind){case"toggle":{const x=r(),S=x!==void 0&&x[y.key]===!0;return s({[y.key]:S?null:!0})?(l(m,!S),!0):!1}case"patch":return s(y.patch)?(l(m,null),!0):!1;case"clear":return s(Rw)?(l(m,null),!0):!1;case"value":return s({value:Mw(y.value,d.formats)})?(l(m,null),!0):!1;case"borders":return c(y.preset)?(l(m,null),!0):!1;case"color":{const x=y.key==="background"?d.colors.fill:d.colors.font,S=y.preset!==null?y.preset:y.custom!==null&&y.custom<x.length?x[y.custom]:void 0;if(S===void 0)return!1;const V=r(),C=$w(V===void 0?void 0:V[y.key],S);return s({[y.key]:C?null:S})?(l(m,!C),!0):!1}case"calc":return g({text:x=>gw(x,y.exponent),formula:x=>yw(x,y.exponent)});case"sign":return g({text:ww,formula:bw});case"fill":return v&&y.direction==="selection"?h():u(y.direction);case"popover":return d.openPopover(y.popover),!0;case"openHyperlink":{if(d.onHyperlinkOpen!==void 0){const x=M();return x===void 0?!1:(d.onHyperlinkOpen(x,d.getActive()),!0)}return d.openPopover("link"),!0}case"pasteSpecial":return d.onPasteSpecialRequest!==void 0?(d.onPasteSpecialRequest({kind:"keyboard",cellRect:d.keyboardCellRect()}),!0):(d.paste({mode:"formats"}),!0);case"paste":return d.paste(y.options),!0;case"insertNow":{const x=y.unit==="date"?Sw(d.now()):Ew(d.now());if(v)return d.insertAtCaret(x),!0;const S=d.getActive();return nt(d.adapter,S.row,S.col)?(d.rejectReadOnly({kind:"edit",cell:S,editSession:"none"}),!1):d.validateCommit(S,x).ok?d.commitEdits([{row:S.row,col:S.col,text:x}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return L(y.axis,y.hide);case"resize":return Z(m,y.axis,y.step);default:{const x=d.getHighlight();switch(y.target){case"row":return d.setHighlight({...x,row:!x.row}),!0;case"column":return d.setHighlight({...x,column:!x.column}),!0;case"both":{const S=x.row&&x.column;return d.setHighlight({...x,row:!S,column:!S}),!0}default:return d.setHighlight({...x,intersection:!x.intersection}),!0}}}},[$,H,M,r,s,l,c,g,u,h,L,Z]),O=i.useCallback(()=>{const m=t.current;return!(m.isEditing()&&!m.requestCommit())},[]),D=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const y=m===null?null:bn(m);if(m!==null&&y===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(m)}`);if(!O())return!1;const v=d.getActive();return nt(d.adapter,v.row,v.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:v.row,col:v.col,hyperlink:y}],{source:"annotate"})!==null},[O]),W=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!O())return!1;const y=d.getActive();return nt(d.adapter,y.row,y.col)?(d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):d.commitEdits([{row:y.row,col:y.col,note:m}],{source:"annotate"})!==null},[O]),K=i.useCallback(m=>{const d=t.current,y=d.adapter.getCellComments;if(y===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!O())return!1;const v=d.getActive();if(nt(d.adapter,v.row,v.col))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const x=y(v.row,v.col),S=x===void 0?[m]:[...x,m];return d.commitEdits([{row:v.row,col:v.col,comments:S}],{source:"annotate"})!==null},[O]),E=i.useCallback(m=>{const d=t.current;if(d.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!O())return!1;const y=d.getSelection().ranges;if(!xr("annotate",y,d.maxOperationCells,d.onOperationRejected))return!1;if(nr(d.adapter,y))return d.rejectReadOnly({kind:"operation",op:"annotate",cellCount:vt(y)}),!1;const v=[];return fn(y,x=>{v.push({row:x.row,col:x.col,validation:m})}),d.commitEdits(v,{source:"annotate"})!==null},[O]),P=i.useCallback(m=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(m)},[s]),j=i.useCallback((m,d)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(m,d)},[c]);return i.useMemo(()=>({executeCommand:Q,applyFormat:P,setBorders:j,setHyperlink:D,setNote:W,addComment:K,setValidation:E,isCommandAvailable:$}),[Q,P,j,D,W,K,E,$])},go="data-aqsp-pointing",zw=(e,t)=>{const n=Na(e,t);return n!==null&&"insertAt"in n},Nw=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Dw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(null),u=i.useRef(Qt),h=i.useCallback(()=>{const C=t.current,A=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||!c.current||A===null)return null;const X=Na(A.value,A.selectionStart);return X===null?null:{sink:A,target:X}},[]),g=i.useCallback(()=>{const C=t.current.sinkRef.current;if(C===null)return;const A=h()!==null;A!==C.hasAttribute(go)&&(A?C.setAttribute(go,""):C.removeAttribute(go))},[h]),L=i.useCallback((C,A)=>{const X=t.current;if(X.resolveEditPaint===void 0)return;const w=X.resolveEditPaint(A),G=w===null?Qt:w;G!==Qt&&Object.assign(C.style,G.style),u.current=G,X.editPaintRef!==void 0&&(X.editPaintRef.current=G)},[]),M=i.useCallback(C=>{Nw(C,Object.keys(u.current.style)),u.current=Qt;const A=t.current.editPaintRef;A!==void 0&&(A.current=Qt)},[]),$=i.useCallback(C=>{const A=t.current,X=n.current;if(X===null)return!0;const w=()=>{n.current=null,a.current=null;const G=A.sinkRef.current;G!==null&&(G.style.removeProperty("text-align"),M(G),G.removeAttribute(go)),o(!1),A.onSessionChange?.(null)};if(C.commit){const G=A.sinkRef.current,te=G===null?"":G.value,f=dr(A.adapter,X.cell.row,X.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
+
`),b=te===f;let R;if(b)R=!0;else if(nt(A.adapter,X.cell.row,X.cell.col))A.rejectReadOnly({kind:"edit",cell:X.cell,editSession:C.onReject==="keep"?"kept":"discarded"}),R=!1;else{const _={source:"edit",editSession:C.onReject==="keep"?"kept":"discarded"};R=(A.validateCommit===void 0||A.validateCommit(X.cell,te).ok)&&A.commitEdits([{row:X.cell.row,col:X.cell.col,text:te}],_)!==null}if(!R)return C.onReject==="discard"&&(w(),A.rearmSink()),!1}return w(),C.rearm&&A.rearmSink(),!0},[M]),H=i.useCallback((C,A)=>{const X=t.current;if(X.isDragging()||n.current!==null)return;const w=X.sinkRef.current;if(w===null)return;const G=X.getActive();if(nt(X.adapter,G.row,G.col)){X.rejectReadOnly({kind:"edit",cell:G,editSession:"none"});return}if(X.discardClip(),X.ensureCellVisible(G),C==="edit"){const{text:b,isFormula:R}=dr(X.adapter,G.row,G.col);w.value=b;const _=A===void 0||R?b.length:Math.min(A,b.length);w.setSelectionRange(_,_)}else w.value="";const te=X.resolveEditAlign(G);te!==null&&(w.style.textAlign=te),L(w,G),c.current=!1,a.current=null;const f={cell:G,mode:C};n.current=f,o(!0),X.onSessionChange?.(f)},[L]),Z=i.useCallback(()=>{$({rearm:!0,commit:!1})},[$]),Q=i.useCallback(()=>{const C=t.current;if(n.current===null)return!0;const A=C.sinkRef.current;if(s.current&&A!==null){l.current=!0;try{A.blur()}finally{l.current=!1}return $({rearm:!1,commit:!0,onReject:"keep"})?(C.focusSink(),C.rearmSink(),!0):(C.focusSink(),!1)}return $({rearm:!0,commit:!0,onReject:"keep"})},[$]),O=i.useCallback(()=>h()!==null,[h]),D=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,g(),!0),[g]),W=i.useCallback(()=>{const C=h(),A=n.current;if(C===null||A===null)return null;if("insertAt"in C.target)return a.current=A.cell,{origin:A.cell,cursor:A.cell,axis:"cells"};const X=za(C.sink.value,C.sink.selectionStart);if(X===null)return null;const w=X.token,G=a.current;switch(w.kind){case"cell":{const te={row:w.row,col:w.col};return a.current=te,{origin:te,cursor:te,axis:"cells"}}case"range":{const te=G!==null&&(G.row===w.start.row||G.row===w.end.row)&&(G.col===w.start.col||G.col===w.end.col)?{row:G.row,col:G.col}:{row:w.start.row,col:w.start.col};return a.current=te,{origin:te,cursor:{row:te.row===w.start.row?w.end.row:w.start.row,col:te.col===w.start.col?w.end.col:w.start.col},axis:"cells"}}case"column":{const te=G!==null&&(G.col===w.start.col||G.col===w.end.col)?G.col:w.start.col,f={row:A.cell.row,col:te};return a.current=f,{origin:f,cursor:{row:A.cell.row,col:te===w.start.col?w.end.col:w.start.col},axis:"columns"}}case"row":{const te=G!==null&&(G.row===w.start.row||G.row===w.end.row)?G.row:w.start.row,f={row:te,col:A.cell.col};return a.current=f,{origin:f,cursor:{row:te===w.start.row?w.end.row:w.start.row,col:A.cell.col},axis:"rows"}}}},[h]),K=i.useCallback((C,A)=>{const X=h();if(X===null)return;const w=Pp(C,A),{sink:G}=X,[te,f]="replace"in X.target?X.target.replace:[X.target.insertAt,X.target.insertAt],b=G.value;G.value=`${b.slice(0,te)}${w}${b.slice(f)}`;const R=te+w.length;G.setSelectionRange(R,R),"row"in C&&(a.current={row:C.row,col:C.col}),g()},[h,g]),E=i.useCallback(()=>{const C=t.current.sinkRef.current;return C===null?null:{value:C.value,selectionStart:C.selectionStart,selectionEnd:C.selectionEnd}},[]),P=i.useCallback(C=>{const A=t.current.sinkRef.current;A!==null&&(A.value=C.value,A.setSelectionRange(C.selectionStart,C.selectionEnd),a.current=null,g())},[g]),j=i.useCallback(()=>{const C=t.current,A=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||A===null)return!1;const X=Xp(A.value,A.selectionStart);return X===null?!1:(A.value=X.text,A.setSelectionRange(X.caret,X.caret),g(),!0)},[g]),m=i.useCallback(C=>{const A=t.current.sinkRef.current;if(n.current===null||A===null)return;const X=A.selectionStart,w=A.selectionEnd;A.value=`${A.value.slice(0,X)}${C}${A.value.slice(w)}`;const G=X+C.length;A.setSelectionRange(G,G),a.current=null,g()},[g]),d=i.useCallback(()=>{const C=t.current.sinkRef.current;return n.current===null||C===null?null:C.value},[]),y=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>n.current,[]),x=i.useCallback(()=>{const C=t.current,A=n.current,X=C.sinkRef.current;A===null||X===null||(M(X),L(X,A.cell),C.repaintOverlay?.())},[M,L]),{enabled:S,sinkRef:V}=e;return i.useEffect(()=>{const C=V.current;if(!S||C===null)return;const A=()=>{s.current=!0},X=()=>{s.current=!1},w=f=>{const b=t.current;if(l.current||n.current===null)return;const R=b.rootRef.current,_=f.relatedTarget;R!==null&&_ instanceof Node&&R.contains(_)||$({rearm:!1,commit:!0,onReject:"discard"})},G=()=>{const f=t.current;a.current=null,f.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&zw(C.value,C.selectionStart)&&(c.current=!0),g()},te=()=>{n.current!==null&&g()};return C.addEventListener("compositionstart",A),C.addEventListener("compositionend",X),C.addEventListener("focusout",w),C.addEventListener("input",G),document.addEventListener("selectionchange",te),()=>{C.removeEventListener("compositionstart",A),C.removeEventListener("compositionend",X),C.removeEventListener("focusout",w),C.removeEventListener("input",G),document.removeEventListener("selectionchange",te)}},[S,V,$,g]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Q,cancelEdit:Z,startEdit:H,getPointing:O,togglePointingArm:D,getReferenceCursor:W,insertReference:K,captureSink:E,restoreSink:P,cycleAnchorAtCaret:j,insertAtCaret:m,getSessionText:d,getSessionCell:y,getSession:v,refreshPaint:x,editing:r}),[Q,Z,H,O,D,W,K,E,P,j,m,d,y,v,x,r])},Fw=(e,t,n)=>{const r=new rt.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},qw=(e,t,n)=>{const{tree:r,initialHidden:o}=Fw(e,t,n);let s=o;const a={count:e,sizeOf:u=>r.get(u),offsetOf:u=>{const{cumulative:h,currentValue:g}=r.prefixSum(u);return h-g},indexAt:u=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const h=Math.floor(u),g=Math.min(Math.max(h,0),r.getTotal()-1);return r.findIndexAtOrAfter(g+.5).index},totalSize:()=>r.getTotal(),resize:(u,h)=>{if(!(Number.isFinite(h)&&h>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${h}`);const g=Math.round(h);r.get(u)===0!=(g===0)&&(s+=g===0?1:-1),r.update(u,g)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},wn=(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)},lr=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:wn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=wn(e,o,1);return r},Lc=(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=qw(e,t,r)),o.current.model},ir=256,Ss=256,Pw=2**32,_w=4096,Fu=Object.freeze([]),qu=["background","color","bold","italic","underline","strikethrough"],Pu=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Cn=(e,t,n)=>(e.size>=_w&&e.clear(),e.set(t,n),n),_u=e=>(Pu(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),ju=(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},jw=(e,t,n)=>{const r=Math.floor(t/ir),o=Math.floor(n/Ss),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*ir,a=o*Ss,u=[];for(const h of e.rules)ju(h.ranges,c,c+ir-1,a,a+Ss-1)&&u.push(h);return Cn(e.buckets,s,u.length===0?Fu:u)},Iw=(e,t,n)=>{const r=Math.floor(t/ir),o=r*Pw+n,s=e.columns.get(o);if(s!==void 0)return s;const l=jw(e,t,n),c=r*ir,a=[];for(const u of l)ju(u.ranges,c,c+ir-1,n,n)&&a.push(u);return Cn(e.columns,o,a.length===0?Fu:a)},Hw=(e,t)=>{for(const n of e)if(Vt(n,t))return!0;return!1},hl=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),wo=(e,t)=>e<t?-1:e>t?1:0,zc=(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}},Nc=new WeakMap,Xs=e=>e===null?null:Number(e),Bw=e=>{const t=Nc.get(e);if(t!==void 0)return t;const n=e.b,r={a:Xs(Rt(e.a)),b:n===void 0?null:Xs(Rt(n))};return Nc.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:Cn(e.numbers,r,Xs(Rt(n())))},Vw=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Bw(e),l=Iu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return zc(e.op,wo(l,s.a),c===null?null:wo(l,c));const a=n(),u=e.b;return zc(e.op,wo(a,e.a),u===void 0?null:wo(a,u))},Ww=(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}},Es=e=>{const t=lt(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]},Co=e=>e.toString(16).padStart(2,"0"),ks=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Co(r(0))}${Co(r(1))}${Co(r(2))}`,s=r(3);return s===255?o:`${o}${Co(s)}`},Os=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Kw=(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=Es(t.color),a=Es(r.color);const u=n===void 0?void 0:Es(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||a===null||u===null)return null;if(s>l){const g=s;s=l,l=g;const L=c;c=a,a=L}if(n!==void 0&&u!==void 0){const g=n.value===void 0?(s+l)/2:n.value;if(s<g&&g<l)return e<=g?ks(c,u,Os(e,s,g)):ks(u,a,Os(e,g,l))}return ks(c,a,Os(e,s,l))},Yw=(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 Cn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const u of e.ranges){const h=n.getRangeExtrema(u);if(h===null)return Cn(r.extrema,e.id,null);c=Math.min(c,h.min),a=Math.max(a,h.max)}return Cn(r.extrema,e.id,{min:c,max:a})},Xw=(e,t,n,r,o,s)=>{const l=Iu(s,n,r);if(l===null)return null;const c=Yw(e,t,o,s);return c===null?null:Kw(l,t.min,t.mid,t.max,c)},Uw=(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:Cn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Gw=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Vw(s,t,n,o)?e.style:null;case"text":return Ww(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Xw(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Uw(e,s,t,r,o)?e.style:null;default:return null}},Dc=(e,t)=>tl(e,t),Jw=(e,t,n)=>{e[t]=n},Zw=(e,t)=>{let n=e;for(const r of qu)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Jw(n,r,t[r]));return n},Qw=e=>{let t="";for(const n of qu){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Fc=new WeakMap,e0=Object.freeze({}),t0=e=>{const t=e===void 0?e0:e,n=Fc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Fc.set(t,r),r},n0=(e,t,n)=>{const r=t0(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=Dc(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=Qw(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Dc(e,t);return l!==void 0&&Cn(r.byKey,o,l),l},ml=(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=Iw(t,r,o);if(c.length===0)return l;const a={row:r,col:o};let u=null,h=!0;for(const g of c){if(!Hw(g.ranges,a))continue;const L=Gw(g,a,s,e,n);if(L!==null){if(L!==g.style&&(h=!1),u===null)u=L;else{const M=Zw(u,L);M!==u&&(h=!1,u=M)}if(g.stopIfTrue===!0)break}}return u===null?l:n0(l,u,h)},qc=new WeakMap,r0=e=>{Pu(e,"widthRelevantRules");const t=qc.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 qc.set(e,r),r},o0=(e,t,n,r)=>{const o=e.trim()===""?t:`${e} ${t}`;return r?`${o} (${n})`:o},s0=({col:e,direction:t,filtered:n,expanded:r,columnName:o,menuLabel:s,filteredLabel:l,onToggle:c})=>{const a=i.useRef(null);return i.useEffect(()=>{const u=a.current;if(u===null)return;const h=L=>{L.stopPropagation(),L.preventDefault()},g=L=>{L.stopPropagation()};return u.addEventListener("pointerdown",h),u.addEventListener("dblclick",g),u.addEventListener("contextmenu",g),()=>{u.removeEventListener("pointerdown",h),u.removeEventListener("dblclick",g),u.removeEventListener("contextmenu",g)}},[]),I.jsxs("button",{ref:a,type:"button",className:"aqsp-column-menu-button","data-aqsp-column-menu-button":"",tabIndex:-1,"aria-haspopup":"dialog","aria-expanded":r,"aria-label":o0(o,s,l,n),onClick:()=>c(e),children:[t===null?null:I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":t,viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:t==="asc"?"M5 1.5 9 8.5H1Z":"M5 8.5 1 1.5h8Z",fill:"currentColor"})}),n?I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"filter",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:"M.5 1h9L6 5.25V9.5L4 8.25v-3Z",fill:"currentColor"})}):I.jsx("svg",{className:"aqsp-column-menu-glyph","data-aqsp-glyph":"menu",viewBox:"0 0 10 10",width:"10",height:"10","aria-hidden":"true",focusable:"false",children:I.jsx("path",{d:"M1.5 3.25 5 6.75l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]})},l0=i.memo(s0),i0=Object.freeze({state:!0,onStateChange:!0,getColumnKey:!0,defaults:!0,getColumnOptions:!0,getFilterValues:!0}),Pc=Object.freeze({sortable:!0,filterable:!0,matchModes:!0,defaultMatchMode:!0}),c0=Object.freeze({sort:!0,filters:!0}),a0=Object.freeze({columnKey:!0,direction:!0}),u0=Object.freeze({value:!0,label:!0,count:!0}),Hu=Object.freeze(["exact","fuzzy"]),d0=Object.freeze(["asc","desc"]),_e=e=>typeof e=="string"?JSON.stringify(e):e==null||typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):Array.isArray(e)?"an array":typeof e=="function"?"a function":typeof e=="symbol"?"a symbol":"an object",mn=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},gn=(e,t,n)=>{for(const r of Object.keys(e))if(!Object.hasOwn(t,r))throw new RangeError(`[spreadsheet] ${n} has an unknown member ${JSON.stringify(r)}; expected ${Object.keys(t).join(", ")}`)},_c=(e,t)=>{const{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}=e;if(typeof n!="boolean")throw new RangeError(`[spreadsheet] ${t}.sortable must be true or false (got ${_e(n)})`);if(typeof r!="boolean")throw new RangeError(`[spreadsheet] ${t}.filterable must be true or false (got ${_e(r)})`);if(!Array.isArray(o))throw new RangeError(`[spreadsheet] ${t}.matchModes must be an array of "exact" / "fuzzy" (got ${_e(o)})`);if(o.length===0)throw new RangeError(`[spreadsheet] ${t}.matchModes must not be empty`);const l=new Set;for(const c of o){if(!Hu.includes(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds an unknown match mode ${_e(c)}; expected "exact" or "fuzzy"`);if(l.has(c))throw new RangeError(`[spreadsheet] ${t}.matchModes holds ${JSON.stringify(c)} twice`);l.add(c)}if(!l.has(s))throw new RangeError(`[spreadsheet] ${t}.defaultMatchMode ${_e(s)} is not one of ${t}.matchModes (${[...l].map(c=>JSON.stringify(c)).join(", ")})`);return{sortable:n,filterable:r,matchModes:o,defaultMatchMode:s}},f0=(e,t)=>{if(!mn(e))throw new RangeError(`[spreadsheet] sortFilter.state must be an object with sort and filters (got ${_e(e)})`);gn(e,c0,"sortFilter.state");const n=(c,a)=>{const u=t.get(c);if(u===void 0)throw new RangeError(`[spreadsheet] ${a} names ${JSON.stringify(c)}, which is not the key of any column`);return u},r=e.sort;let o=null;if(r!==null){if(!mn(r))throw new RangeError(`[spreadsheet] sortFilter.state.sort must be null or { columnKey, direction } (got ${_e(r)})`);gn(r,a0,"sortFilter.state.sort");const{columnKey:c,direction:a}=r;if(typeof c!="string")throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey must be a string (got ${_e(c)})`);if(!d0.includes(a))throw new RangeError(`[spreadsheet] sortFilter.state.sort.direction must be "asc" or "desc" (got ${_e(a)})`);const{col:u,column:h}=n(c,"sortFilter.state.sort.columnKey");if(!h.sortable)throw new RangeError(`[spreadsheet] sortFilter.state.sort.columnKey ${JSON.stringify(c)} names column ${u}, which cannot sort`);o={col:u,direction:a}}const s=e.filters;if(!mn(s))throw new RangeError(`[spreadsheet] sortFilter.state.filters must be an object keyed by column key (got ${_e(s)})`);const l=new Set;for(const c of Object.keys(s)){const a=`sortFilter.state.filters[${JSON.stringify(c)}]`,{col:u,column:h}=n(c,"sortFilter.state.filters");if(!h.filterable)throw new RangeError(`[spreadsheet] ${a} names column ${u}, which cannot filter`);const g=s[c];if(!mn(g))throw new RangeError(`[spreadsheet] ${a} must be { mode: "exact", values } or { mode: "fuzzy", query } (got ${_e(g)})`);const L=g.mode;if(L==="exact"){gn(g,{mode:!0,values:!0},a);const M=g.values;if(!(Array.isArray(M)&&M.every($=>typeof $=="string")))throw new RangeError(`[spreadsheet] ${a}.values must be an array of strings (got ${_e(M)})`)}else if(L==="fuzzy"){if(gn(g,{mode:!0,query:!0},a),typeof g.query!="string")throw new RangeError(`[spreadsheet] ${a}.query must be a string (got ${_e(g.query)})`)}else throw new RangeError(`[spreadsheet] ${a}.mode must be "exact" or "fuzzy" (got ${_e(L)})`);if(!h.matchModes.includes(L))throw new RangeError(`[spreadsheet] ${a}.mode ${JSON.stringify(L)} is not offered by column ${u} (match modes ${h.matchModes.map(M=>JSON.stringify(M)).join(", ")})`);l.add(u)}return{sort:o,filteredColumns:l}},p0=(e,t,n)=>{const r=e;if(!mn(r))throw new RangeError(`[spreadsheet] sortFilter must be an object or absent (got ${_e(r)})`);if(n<1)throw new RangeError(`[spreadsheet] sortFilter needs headerRows of 1 or more: the sort and filter controls sit on the last header row (got headerRows ${n})`);gn(r,i0,"sortFilter");for(const M of["onStateChange","getColumnKey"])if(typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function (got ${_e(r[M])})`);for(const M of["getColumnOptions","getFilterValues"])if(r[M]!==void 0&&typeof r[M]!="function")throw new RangeError(`[spreadsheet] sortFilter.${M} must be a function or absent (got ${_e(r[M])})`);const o=r.defaults;if(!mn(o))throw new RangeError(`[spreadsheet] sortFilter.defaults must be an object (got ${_e(o)})`);gn(o,Pc,"sortFilter.defaults");const s=_c(o,"sortFilter.defaults"),l=[],c=new Map;let a=null,u=!1;for(let M=0;M<t;M++){const $=e.getColumnKey(M);if($===null){l.push(null);continue}if(typeof $!="string"||$==="")throw new RangeError(`[spreadsheet] sortFilter.getColumnKey(${M}) must return a non-empty string or null (got ${_e($)})`);const H=c.get($);if(H!==void 0)throw new RangeError(`[spreadsheet] sortFilter.getColumnKey returned ${JSON.stringify($)} for columns ${H.col} and ${M}; column keys must be unique`);let Z=s;if(e.getColumnOptions!==void 0){const O=`sortFilter.getColumnOptions(${JSON.stringify($)})`,D=e.getColumnOptions($);if(!mn(D))throw new RangeError(`[spreadsheet] ${O} must return an object (got ${_e(D)})`);gn(D,Pc,O);const W={...s};for(const K of Object.keys(D))D[K]!==void 0&&(W[K]=D[K]);Z=_c(W,O)}const Q={key:$,...Z};l.push(Q),c.set($,{col:M,column:Q}),(Z.sortable||Z.filterable)&&(u=!0),a===null&&Z.filterable&&Z.matchModes.includes("exact")&&(a={col:M,column:Q})}if(a!==null&&e.getFilterValues===void 0)throw new RangeError(`[spreadsheet] sortFilter.getFilterValues is required: column ${a.col} (${JSON.stringify(a.column.key)}) can filter by exact match`);const{sort:h,filteredColumns:g}=f0(r.state,c),L=new Map;for(const[M,$]of c)L.set(M,$.col);return{columns:l,columnOfKey:L,headerRow:n-1,sort:h,filteredColumns:g,hasControls:u}},cr=(e,t)=>{const n=e.columns[t];return n!=null&&(n.sortable||n.filterable)?n:null},h0=(e,t)=>e.key===t.key&&e.sortable===t.sortable&&e.filterable===t.filterable&&e.defaultMatchMode===t.defaultMatchMode&&e.matchModes.length===t.matchModes.length&&e.matchModes.every((n,r)=>n===t.matchModes[r]),m0=(e,t)=>e.sort===null||e.sort.columnKey!==t?{sort:{columnKey:t,direction:"asc"},filters:e.filters}:e.sort.direction==="asc"?{sort:{columnKey:t,direction:"desc"},filters:e.filters}:{sort:null,filters:e.filters},g0=(e,t,n)=>n!==null?{sort:{columnKey:t,direction:n},filters:e.filters}:e.sort!==null&&e.sort.columnKey===t?{sort:null,filters:e.filters}:e,gl=(e,t)=>{if(!Object.hasOwn(e.filters,t))return e;const n={};for(const r of Object.keys(e.filters))r!==t&&(n[r]=e.filters[r]);return{sort:e.sort,filters:n}},w0=e=>Object.keys(e.filters).length===0?e:{sort:e.sort,filters:{}},C0=(e,t,n,r)=>{const o=r.filter(s=>n.has(s));return o.length===r.length?gl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"exact",values:o}}}},y0=(e,t,n)=>n.trim()===""?gl(e,t):{sort:e.sort,filters:{...e.filters,[t]:{mode:"fuzzy",query:n}}},b0=(e,t)=>e.mode==="fuzzy"||t.mode==="fuzzy"?e.mode==="fuzzy"&&t.mode==="fuzzy"&&e.query===t.query:e.values.length===t.values.length&&e.values.every((n,r)=>n===t.values[r]),v0=(e,t)=>{if(e===t)return!0;if(e.sort===null||t.sort===null?e.sort!==t.sort:e.sort.columnKey!==t.sort.columnKey||e.sort.direction!==t.sort.direction)return!1;const n=Object.keys(e.filters);return n.length!==Object.keys(t.filters).length?!1:n.every(r=>Object.hasOwn(t.filters,r)&&b0(e.filters[r],t.filters[r]))},R0=e=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] sortFilter.getFilterValues must resolve with an array (got ${_e(e)})`);const t=new Set;for(const[n,r]of e.entries()){const o=`sortFilter.getFilterValues()[${n}]`;if(!mn(r))throw new RangeError(`[spreadsheet] ${o} must be { value, label, count } (got ${_e(r)})`);if(gn(r,u0,o),typeof r.value!="string")throw new RangeError(`[spreadsheet] ${o}.value must be a string (got ${_e(r.value)})`);if(typeof r.label!="string")throw new RangeError(`[spreadsheet] ${o}.label must be a string (got ${_e(r.label)})`);if(!(Number.isInteger(r.count)&&r.count>=0))throw new RangeError(`[spreadsheet] ${o}.count must be a non-negative integer (got ${_e(r.count)})`);if(t.has(r.value))throw new RangeError(`[spreadsheet] ${o}.value ${JSON.stringify(r.value)} repeats an earlier value`);t.add(r.value)}return e},jc=e=>e.normalize("NFKC").toLowerCase(),S0=(e,t)=>jc(e).includes(jc(t)),Bu=e=>e.replace(/\r\n|\r|\n/g," "),E0=({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},k0=i.memo(E0),O0=Object.freeze({left:Object.freeze({justifyContent:zr("left")}),center:Object.freeze({justifyContent:zr("center")}),right:Object.freeze({justifyContent:zr("right")})}),x0=Object.freeze({role:"rowgroup"}),A0=4096,Ic=new WeakMap,yo=new Map,T0=(e,t)=>{if(e===null)return O0[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:zr(t)},s=JSON.stringify(o);let l=yo.get(s);return l===void 0&&(yo.size>=A0&&yo.clear(),l=Object.freeze(o),yo.set(s,l)),n[t]=l,l},$0=hl(),M0=(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},L0=(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=Eo(e,o,s),c={};let a=null,u;if(e.getCellFormat!==void 0){const h=ml(e,r===null?null:r.indexRef.current,r===null?$0:r.memoRef.current,o,s,l);u=h===void 0?void 0:h.value;const g=Za(h,l),L=wn(n,s,1),M=wn(t,o,1),$=mp(h,L===null?void 0:e.getCellFormat(o,L),M===null?void 0:e.getCellFormat(M,s),n.offsetOf(s)===0,t.offsetOf(o)===0);$!==null&&Object.assign(c,$.attrs),c["data-aqsp-align"]=g,a=T0($,g)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const h=e.getCellComments(o,s);h!==void 0&&h.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&fr(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const h=e.getCellValidation(o,s);h!==void 0&&Tg(h,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:u}},z0=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:L,labelledBy:M,gridLabel:$,readOnly:H,renderCell:Z,onScroll:Q,onRangeChange:O,focusSink:D,isEditing:W,requestCommit:K,testId:E,__onCellRender:P,__maxRenderedCells:j,cfIndexRef:m,cfMemoRef:d,isPointing:y,tapScrollCircleOptions:v,showArrowButtons:x,enableThumbDrag:S,enableTrackClick:V,overscanRows:C,overscanCols:A,background:X,onRenderTruncated:w,locale:G,scrollLabels:te,sortFilter:f,columnMenu:b})=>{const R=i.useRef(null),_=s??R;if(m===void 0!=(d===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const Y=i.useMemo(()=>m===void 0||d===void 0?null:{indexRef:m,memoRef:d},[m,d]),U=i.useCallback(()=>r.get().editVersion,[r]),oe=i.useCallback(Oe=>r.subscribeCoalesced(Oe),[r]),k=i.useSyncExternalStore(oe,U,U)+(l??0),B=i.useCallback(Oe=>t.sizeOf(Oe),[t]),z=i.useCallback(Oe=>n.sizeOf(Oe),[n]),re=i.useCallback((Oe,Ie)=>e.getCellText(Oe,Ie),[e]),ge=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),Te=i.useMemo(()=>({width:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1,showArrowButtons:x,enableThumbDrag:S,enableTrackClick:V}),[v,x,S,V]),Pe=i.useRef({row:-1,col:-1,value:void 0}),ot=i.useCallback((Oe,Ie)=>{const Be=Oe<L,Et={role:Be?"columnheader":"gridcell","aria-rowindex":Oe+1,"aria-colindex":Ie+1,"data-aqsp-cell":"","data-row":Oe,"data-col":Ie,className:"aqsp-cell",...nt(e,Oe,Ie)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Be?{"data-aqsp-header-row":""}:{},...f==null||Oe!==f.headerRow||cr(f,Ie)===null?{}:{"data-aqsp-column-controls":"",...f.sort!==null&&f.sort.col===Ie?{"aria-sort":f.sort.direction==="asc"?"ascending":"descending","data-aqsp-sort":f.sort.direction}:{},...f.filteredColumns.has(Ie)?{"data-aqsp-filtered":""}:{}}},it=Em(e,Oe,Ie),on=it===null?Et:{...Et,...it},Ze=L0(e,t,n,Y,Oe,Ie),kt=Pe.current;return kt.row=Oe,kt.col=Ie,kt.value=Ze===null?void 0:Ze.value,Ze===null?on:Ze.style===null?{...on,...Ze.attrs}:{...on,...Ze.attrs,style:Ze.style}},[e,t,n,Y,L,f]),je=i.useCallback(Oe=>({role:"row","aria-rowindex":Oe+1,"data-aqsp-row":Oe,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Xe=i.useCallback((Oe,Ie,Be)=>{let Et=Oe;e.getCellFormat!==void 0&&(Et=Ln(Oe,M0(Pe.current,Ie,Be)));const it=I.jsx(k0,{row:Ie,col:Be,text:Oe,display:Et,renderCell:Z,__onCellRender:P});return f==null||b===void 0||b===null||Ie!==f.headerRow||cr(f,Be)===null?it:I.jsxs(I.Fragment,{children:[it,I.jsx(l0,{col:Be,direction:f.sort!==null&&f.sort.col===Be?f.sort.direction:null,filtered:f.filteredColumns.has(Be),expanded:b.openCol===Be,columnName:Bu(Et),menuLabel:b.menuLabel,filteredLabel:b.filteredLabel,onToggle:b.onToggle})]})},[k,Z,P,e,f,b]);return I.jsx("div",{ref:_,className:"aqsp-body","data-aqsp-body":"","data-testid":E?`${E}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":$,"aria-labelledby":M,"aria-readonly":H?"true":void 0,onPointerDownCapture:Oe=>{if(!(Oe.target instanceof Element&&Oe.target.closest("[data-aqsp-cells]")!==null)&&Oe.pointerType==="mouse"){if(Oe.button!==0){Oe.preventDefault();return}if(Oe.preventDefault(),y?.()===!0){Oe.stopPropagation(),D();return}if(W()&&!K()){Oe.stopPropagation(),D();return}D()}},children:I.jsx(rt.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:u,frozenTrailingCols:h,frozenTrailingRows:g,getRowHeight:B,getColWidth:z,getCell:re,getCellProps:ot,getRowProps:je,contentProps:x0,behaviorOptions:ge,scrollBarOptions:Te,overscanRows:C,overscanCols:A,background:X,onRenderTruncated:w,__maxRenderedCells:j,locale:G,labels:te,callbackThrottleMs:0,onScroll:Q,onRangeChange:O,testId:E,children:Xe})})},N0=i.memo(z0),rr=6,bt=3,zo=(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:bt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,a=wn(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-rr,length:bt}),r.push({kind:"unhide",index:s+1,start:c-bt,length:bt})):l>=2*rr?n.push({kind:"resize",index:s,start:c-rr,length:rr}):n.push({kind:"resize",index:s,start:c-bt,length:bt})}return[...n,...r]},Vu=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const a=e.sizeOf(c),u=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:u,length:bt}),n.push({kind:"resize",index:c,start:u+bt,length:bt})):a>=2*rr?n.push({kind:"resize",index:c,start:u,length:rr}):n.push({kind:"resize",index:c,start:u,length:bt})}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-bt,length:bt}),[...n.reverse(),...r]},D0=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:a,selectionRanges:u,enableResizeUI:h,dividerLeadingRef:g,dividerTrailingRef:L})=>{const M=rt.useWheelBridge(o),$=i.useCallback(w=>(s.current=w,M(w)),[s,M]),H=i.useCallback(()=>{const{colStart:w,colEnd:G,colVersion:te}=e.get();return`${w}:${G}:${te}`},[e]),Z=i.useCallback(w=>e.subscribeCoalesced(w),[e]);i.useSyncExternalStore(Z,H,H);const{colStart:Q,colEnd:O}=e.get(),D=t.count===0?0:t.offsetOf(Math.min(Q,t.count-1));i.useLayoutEffect(()=>{c.current=D,a()},[D,c,a]);const W=w=>u.some(G=>w>=G.startCol&&w<=G.endCol),K=Math.min(Math.max(0,n),t.count),E=wu(t,K),P=K>0?lr(t,0,K-1):[],j=Math.min(Math.max(0,r),t.count-K),m=yu(t,j),d=t.totalSize()-m,y=j>0?lr(t,t.count-j,t.count-1):[],v=lr(t,Math.max(Q,K),Math.min(O,Math.max(0,t.count-1)-j)),x=[];for(const w of v)x.push(I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w)-D,width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w));const S=h?zo(t,v):null,V=S===null?null:S.filter(w=>!(w.kind==="unhide"&&w.index<K&&E>0||w.kind==="unhide"&&w.index>=t.count-j&&m>0)),C=h&&K>0?zo(t,P):null,A=h&&j>0?Vu(t,y):null,X=I.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[x,V?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,style:{left:w.start-D,width:w.length}},`r${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{left:w.start-D,width:w.length}},`u${w.index}`))]});return I.jsx("div",{ref:$,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:K===0&&j===0?X:I.jsxs(I.Fragment,{children:[P.map(w=>I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-frozen-header":"","data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w),width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w)),C?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,style:{left:w.start,width:w.length}},`fr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{left:w.start,width:w.length}},`fu${w.index}`)),I.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:E,right:j>0?`calc(${Fe.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${Fe.SPREADSHEET_SCROLLBAR_SIZE_PX+E}px)))`:void 0},children:[X,K>0?I.jsx("div",{ref:g,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,j>0?I.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),j>0?I.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${E}px, calc(100% - ${m+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[y.map(w=>I.jsx("div",{className:"aqsp-col-header-cell","data-col":w,"data-aqsp-trailing-header":"","data-aqsp-in-selection":W(w)?"":void 0,style:{left:t.offsetOf(w)-d,width:t.sizeOf(w)},children:Fe.columnIndexToName(w)},w)),A?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":w.index,"data-aqsp-resize-anchor":"trailing",style:{left:w.start,width:w.length}},`tr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,"data-aqsp-resize-anchor":"trailing",style:{left:w.start,width:w.length}},`tu${w.index}`))]})}):null]})})},F0=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:a,frozenRows:u,frozenTrailingRows:h,dividerLeadingRef:g,dividerTrailingRef:L})=>{const M=rt.useWheelBridge(n),$=i.useCallback(w=>(r.current=w,M(w)),[r,M]),H=w=>o.some(G=>w>=G.startRow&&w<=G.endRow),Z=i.useCallback(()=>{const{rowStart:w,rowEnd:G,rowGeomVersion:te}=e.get();return`${w}:${G}:${te}`},[e]),Q=i.useCallback(w=>e.subscribeCoalesced(w),[e]);i.useSyncExternalStore(Q,Z,Z);const{rowStart:O,rowEnd:D}=e.get(),W=t.count===0?0:t.offsetOf(Math.min(O,t.count-1));i.useLayoutEffect(()=>{l.current=W,c()},[W,l,c]);const K=Math.min(Math.max(0,u),t.count),E=Cu(t,K),P=K>0?lr(t,0,K-1):[],j=Math.min(Math.max(0,h),t.count-K),m=bu(t,j),d=t.totalSize()-m,y=j>0?lr(t,t.count-j,t.count-1):[],v=lr(t,Math.max(O,K),Math.min(D,Math.max(0,t.count-1)-j)),x=[];for(const w of v)x.push(I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w)-W,height:t.sizeOf(w)},children:w+1},w));const S=a?zo(t,v):null,V=S===null?null:S.filter(w=>!(w.kind==="unhide"&&w.index<K&&E>0||w.kind==="unhide"&&w.index>=t.count-j&&m>0)),C=a&&K>0?zo(t,P):null,A=a&&j>0?Vu(t,y):null,X=I.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[x,V?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,style:{top:w.start-W,height:w.length}},`r${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{top:w.start-W,height:w.length}},`u${w.index}`))]});return I.jsx("div",{ref:$,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Fe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K===0&&j===0?X:I.jsxs(I.Fragment,{children:[P.map(w=>I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w),height:t.sizeOf(w)},children:w+1},w)),C?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,style:{top:w.start,height:w.length}},`fr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,style:{top:w.start,height:w.length}},`fu${w.index}`)),I.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:E,bottom:j>0?`calc(min(${m}px, max(0px, 100% - ${E}px)))`:void 0},children:[X,K>0?I.jsx("div",{ref:g,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,j>0?I.jsx("div",{ref:L,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),j>0?I.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${E}px, calc(100% - ${m}px))`},children:I.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[y.map(w=>I.jsx("div",{className:"aqsp-row-header-cell","data-row":w,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":H(w)?"":void 0,style:{top:t.offsetOf(w)-d,height:t.sizeOf(w)},children:w+1},w)),A?.map(w=>w.kind==="resize"?I.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":w.index,"data-aqsp-resize-anchor":"trailing",style:{top:w.start,height:w.length}},`tr${w.index}`):I.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":w.index,"data-aqsp-resize-anchor":"trailing",style:{top:w.start,height:w.length}},`tu${w.index}`))]})}):null]})})},q0=9,P0=4,Hc=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,a=`${o} ${s} ${l} ${c}`;return t.set(e,a),a},Bc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,_0=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),a=i.useRef(null),u=i.useRef(""),h=i.useRef(null),g=i.useCallback(m=>s.current!==null?m.pointerId===s.current:m.pointerType==="mouse",[]),L=i.useCallback(()=>{const m=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),m.writeResizeGuide(null);const d=h.current;d!==null&&(window.removeEventListener("pointermove",d.move),window.removeEventListener("pointerup",d.up),h.current=null);const y=c.current;y!==null&&s.current!==null&&y.hasPointerCapture?.(s.current)&&y.releasePointerCapture(s.current),c.current=null,s.current=null,m.repaintOverlay()},[]),M=i.useCallback((m,d)=>{const y=t.current;return m==="col"?d.startRow===0&&d.endRow===y.rowAxis.count-1:d.startCol===0&&d.endCol===y.colAxis.count-1},[]),$=i.useCallback((m,d)=>{const y=t.current,v=y.getSelection().ranges.filter(A=>M(m,A));if(!v.some(A=>m==="col"?d>=A.startCol&&d<=A.endCol:d>=A.startRow&&d<=A.endRow))return[d];const S=v.reduce((A,X)=>A+(m==="col"?X.endCol-X.startCol+1:X.endRow-X.startRow+1),0),V=m==="row"?Math.floor(y.maxOperationCells/Js):y.maxOperationCells;if(S>V)return y.onOperationRejected?.("resize",S,"limit"),null;const C=new Set;for(const A of v){const X=m==="col"?A.startCol:A.startRow,w=m==="col"?A.endCol:A.endRow;for(let G=X;G<=w;G+=1)C.add(G)}return[...C]},[M]),H=i.useCallback((m,d,y)=>{const v=t.current,x=m==="col"?v.colAxis:v.rowAxis,S=Zs(x,d,y,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:Gs,axisKind:m});return S.ok?(v.resizeTracks(m,S.entries),!0):(v.onOperationRejected?.("resize",S.count,S.reason),!1)},[]),Z=i.useCallback((m,d)=>{if(d===m.initialSize)return;const y=m.kind==="unhide"?[m.index]:$(m.axis,m.index);y!==null&&H(m.axis,y.map(v=>({index:v,size:d})),m.index)},[$,H]),Q=i.useCallback((m,d,y,v)=>{const x=t.current,S=x.fontSourceRef.current;if(S===null)return!1;if(d.length===0)return!0;const V=m.length*d.length;if(V>y)return x.onOperationRejected?.("resize",V,"limit"),!1;const C=document.createElement("canvas").getContext("2d");if(C===null)return!0;const A=getComputedStyle(S),X=`${A.fontStyle} ${A.fontWeight} ${A.fontSize} ${A.fontFamily}`,w=A.getPropertyValue("--_aqsp-header-row-font-weight").trim(),G={fontStyle:A.fontStyle,fontWeight:w===""?A.fontWeight:w,fontSize:A.fontSize,fontFamily:A.fontFamily},te=`${G.fontStyle} ${G.fontWeight} ${G.fontSize} ${G.fontFamily}`,f=x.adapter.getConditionalFormats===void 0?null:r0(x.adapter.getConditionalFormats()),b=hl(),R=new WeakMap,_=new WeakMap,Y=new Map;for(const k of m){const B=f===null?null:_u(f.filter(z=>z.ranges.some(re=>k>=re.startCol&&k<=re.endCol)));for(const z of d){const re=x.adapter.getCellText(z,k),ge=x.adapter.getCellFormat===void 0?void 0:ml(x.adapter,B,b,z,k,()=>re),Te=z<x.headerRows,Pe=ge===void 0?Te?te:X:Te?Hc(ge,_,G):Hc(ge,R,A),ot=Ln(re,ge===void 0?void 0:ge.value),je=Y.get(Pe);je===void 0?Y.set(Pe,[{col:k,text:ot}]):je.push({col:k,text:ot})}}const U=S.ownerDocument.createElement("span");U.setAttribute("aria-hidden","true"),U.style.position="absolute",U.style.visibility="hidden",S.append(U);const oe=new Map;for(const[k,B]of Y){C.font=k,U.style.font=k;const z=getComputedStyle(U);C.letterSpacing=z.letterSpacing==="normal"?"0px":z.letterSpacing,C.wordSpacing=z.wordSpacing==="normal"?"0px":z.wordSpacing;for(const re of B){const ge=C.measureText(re.text).width,Te=oe.get(re.col);(Te===void 0||ge>Te)&&oe.set(re.col,ge)}}U.remove();const ce=[];for(const k of m){const B=oe.get(k);B!==void 0&&B>0&&ce.push({index:k,size:Math.ceil(B)+q0})}return ce.length===0?!0:H("col",ce,v)},[H]),O=i.useCallback(m=>{const d=t.current,y=$("col",m);if(y===null)return!1;const v=d.handleRef.current,x=v===null?null:v.getFrozenSize(),S=x===null?0:x.rows,V=x===null?0:x.trailingRows,{rowStart:C,rowEnd:A}=d.viewStore.get(),X=Math.min(A,d.rowAxis.count-1),w=[],G=new Set,te=f=>{!G.has(f)&&d.rowAxis.sizeOf(f)>0&&(G.add(f),w.push(f))};for(let f=0;f<S;f+=1)te(f);for(let f=C;f<=X;f+=1)te(f);for(let f=d.rowAxis.count-V;f<d.rowAxis.count;f+=1)te(f);return Q(y,w,Math.floor(d.maxOperationCells/P0),m)},[$,Q]),D=i.useCallback((m,d,y)=>{const v=m==="col"?t.current.colAxis:t.current.rowAxis,x=jd(v.sizeOf(d),y);if(x===v.sizeOf(d))return!0;const S=$(m,d);return S===null?!1:H(m,S.map(V=>({index:V,size:x})),d)},[$,H]),W=i.useCallback(m=>{const d=t.current;return d.autofitEnabled?d.colAxis.sizeOf(m)===0?!0:O(m):!1},[O]),K=i.useCallback(m=>{const d=t.current;if(!d.autofitEnabled)return!1;const y=[...new Set(m)].filter(x=>d.colAxis.sizeOf(x)>0);if(y.length===0)return!0;const v=[];for(let x=0;x<d.rowAxis.count;x+=1)d.rowAxis.sizeOf(x)>0&&v.push(x);return Q(y,v,d.maxOperationCells,null)},[Q]),{enabled:E,colBandRef:P,rowBandRef:j}=e;return i.useEffect(()=>{const m=P.current,d=j.current;if(!E||m===null||d===null)return;const y=R=>R==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(R,_)=>{if(!(_ instanceof Element))return null;const Y=_.closest(y(R));if(Y===null)return null;const U=Y.hasAttribute("data-aqsp-unhide"),oe=Number(Y.getAttribute(U?"data-aqsp-unhide":R==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ce=Y.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:U?"unhide":"resize",index:oe,anchor:ce}},x=R=>{if(!(n.current&&g(R)))return;const _=r.current;if(_===null)return;const Y=(_.axis==="col"?R.clientX-_.startClientX:R.clientY-_.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(_.anchor==="trailing"?_.initialSize-Y:_.initialSize+Y)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const U=r.current;if(!n.current||U===null)return;const oe=t.current,ce=U.axis==="col"?oe.colAxis:oe.rowAxis;oe.writeResizeGuide({axis:U.axis,position:Bc(U,ce,o.current),anchor:U.anchor})}))},S=()=>{const R=r.current,_=o.current;L(),R!==null&&Z(R,_)},V=R=>{x(R),n.current&&g(R)&&(l.current&1)!==0&&(R.buttons&1)===0&&S()},C=R=>{R.button!==0||!(n.current&&g(R))||S()},A=(R,_)=>Y=>{const U=t.current;if(u.current=Y.pointerType,Y.pointerType!=="mouse")return;if(Y.button!==0){Y.preventDefault();return}const oe=v(R,Y.target);if(oe===null)return;if(Y.stopPropagation(),Y.preventDefault(),U.isPointing()){U.focusSink();return}if(U.isEditing()&&!U.requestCommit()){U.focusSink();return}U.focusSink();const ce=R==="col"?U.colAxis:U.rowAxis,k={axis:R,kind:oe.kind,index:oe.index,anchor:oe.anchor,initialSize:ce.sizeOf(oe.index),startClientX:Y.clientX,startClientY:Y.clientY};r.current=k,o.current=k.initialSize,l.current=Y.buttons,n.current=!0,U.repaintOverlay(),s.current=Y.pointerId,c.current=_;try{_.setPointerCapture(Y.pointerId)}catch{s.current=null}const B=V,z=C;h.current={move:B,up:z},window.addEventListener("pointermove",B),window.addEventListener("pointerup",z),U.writeResizeGuide({axis:R,position:Bc(k,ce,o.current),anchor:k.anchor})},X=(R,_)=>Y=>{const U=t.current;if(u.current!=="mouse")return;const oe=_.getRootNode(),ce=oe instanceof ShadowRoot?oe:_.ownerDocument,k=Y.target instanceof Element&&Y.target.closest(y(R))!==null?Y.target:typeof ce.elementFromPoint=="function"?ce.elementFromPoint(Y.clientX,Y.clientY):null,B=v(R,k);if(B!==null){if(Y.stopPropagation(),U.isEditing()){U.focusSink();return}if(B.kind==="unhide"){H(R,[{index:B.index,size:R==="col"?U.defaultColumnWidth:U.defaultRowHeight}],null);return}if(U.autofitEnabled){if(R==="row"){const z=$("row",B.index);z!==null&&H("row",z.map(re=>({index:re,size:U.defaultRowHeight})),B.index);return}O(B.index)}}},w=R=>{!n.current||s.current===null||R.pointerId!==s.current||L()},G=A("col",m),te=A("row",d),f=X("col",m),b=X("row",d);return m.addEventListener("pointerdown",G,{capture:!0}),d.addEventListener("pointerdown",te,{capture:!0}),m.addEventListener("dblclick",f),d.addEventListener("dblclick",b),m.addEventListener("lostpointercapture",w),d.addEventListener("lostpointercapture",w),()=>{m.removeEventListener("pointerdown",G,{capture:!0}),d.removeEventListener("pointerdown",te,{capture:!0}),m.removeEventListener("dblclick",f),d.removeEventListener("dblclick",b),m.removeEventListener("lostpointercapture",w),d.removeEventListener("lostpointercapture",w),L()}},[E,P,j,g,L,Z,H,$,O]),i.useMemo(()=>({stepTrack:D,autofitColumn:W,autofitColumnsInAllRows:K,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L,D,W,K])},wl=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,j0=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>wl(n,t.ranges[r]))&&Dt(e.anchor,t.anchor)&&Dt(e.active,t.active),Vc=(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=>vn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:me(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},xs=(e,t)=>{if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the ${t} must be an object (got ${String(e)})`);return e},I0=(e,t,n)=>{const r=xs(e,"selection"),o=r.ranges;if(!Array.isArray(o)||o.length===0)throw new RangeError("[spreadsheet] setSelection: the selection must have at least one range");const s=`${t} x ${n} grid`,l=(g,L)=>typeof g=="number"&&Number.isInteger(g)&&g>=0&&g<L,c=(g,L)=>{const{row:M,col:$}=xs(g,L);if(!(l(M,t)&&l($,n)))throw new RangeError(`[spreadsheet] setSelection: the ${L} {row: ${String(M)}, col: ${String($)}} is not a cell of the ${s}`);return{row:M,col:$}},a=o.map((g,L)=>{const{startRow:M,startCol:$,endRow:H,endCol:Z}=xs(g,`range ${L}`);if(!(l(M,t)&&l(H,t)&&l($,n)&&l(Z,n)&&M<=H&&$<=Z))throw new RangeError(`[spreadsheet] setSelection: range ${L} {startRow: ${String(M)}, startCol: ${String($)}, endRow: ${String(H)}, endCol: ${String(Z)}} is not a range of the ${s} with each start at most its end`);return{startRow:M,startCol:$,endRow:H,endCol:Z}}),u=c(r.anchor,"anchor"),h=c(r.active,"active cell");if(!Vt(a[a.length-1],u))throw new RangeError(`[spreadsheet] setSelection: the anchor {row: ${u.row}, col: ${u.col}} must lie in the last range`);if(!a.some(g=>Vt(g,h)))throw new RangeError(`[spreadsheet] setSelection: the active cell {row: ${h.row}, col: ${h.col}} must lie in one of the ranges`);return{ranges:a,anchor:u,active:h}},H0=(e,t)=>{const n=e.ranges[e.ranges.length-1];return wl(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},ar=(e,t,n)=>n.extend?Mn(e,t):n.append?{ranges:[...e.ranges,me(t,t)],anchor:t,active:t}:e.ranges.length===1&&Dt(e.anchor,t)&&Dt(e.active,t)&&wl(e.ranges[0],me(t,t))?e:{ranges:[me(t,t)],anchor:t,active:t},B0=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Mn=(e,t)=>{const n=H0(e,me(e.anchor,t));return n.ranges.some(r=>Vt(r,n.active))?n:{...n,active:B0(n.active,n.ranges[n.ranges.length-1])}},Wu=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(me({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(me({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const a=Math.max(c.startRow,t.startRow),u=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(me({row:a,col:c.startCol},{row:u,col:t.startCol-1})),t.endCol<c.endCol&&o.push(me({row:a,col:t.endCol+1},{row:u,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[me(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Vt(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}},V0=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Ku=(e,t)=>{const n=e.ranges.findIndex(o=>Vt(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=V0(e.ranges,r.rangeIndex,r.cell,t),!Dt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Zt=24,Wc=32,No=4,Gn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),a=i.useRef(null),u=i.useRef(null),h=i.useRef(null),g=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,h.current=null,u.current=null},[]),L=i.useCallback(()=>{const $=a.current,H=e.current,Z=h.current;if($===null||H===null||Z===null){c.current=null;return}const{clientX:Q,clientY:O}=$.getPointerPosition(),D=l.current,W=(Q-Z.left)/D,K=(O-Z.top)/D,E=H.getViewportSize(),P=E.width,j=E.height;if(P<=0||j<=0){c.current=requestAnimationFrame(L);return}const m=V=>Math.min(Wc,Math.ceil(V/Zt*Wc));let d=0,y=0;if(s!=="x"){const V=H.getFrozenSize(),C=V.trailingVisibleHeight;K>j-C-Zt?$.anchorRow!==void 0&&V.trailingRows>0&&$.anchorRow>=t.count-V.trailingRows&&C>0&&K>=j-C||(d=m(K-(j-C-Zt))):K<V.height+Zt&&($.anchorRow!==void 0&&$.anchorRow<V.rows&&V.height>0&&K<V.height||(d=-m(V.height+Zt-K)))}if(s!=="y"){const V=H.getFrozenSize(),C=V.trailingVisibleWidth;W>P-C-Zt?$.anchorCol!==void 0&&V.trailingCols>0&&$.anchorCol>=n.count-V.trailingCols&&C>0&&W>=P-C||(y=m(W-(P-C-Zt))):W<V.width+Zt&&($.anchorCol!==void 0&&$.anchorCol<V.cols&&V.width>0&&W<V.width||(y=-m(V.width+Zt-W)))}const v=y!==0||d!==0?H.scrollBy({x:y!==0?y:void 0,y:d!==0?d:void 0}):H.getScrollPosition(),x=v.y,S=v.x;if(x>=0&&S>=0&&t.totalSize()>0&&n.totalSize()>0){const V=H.getFrozenSize(),C=vn({row:Vr(t,K,{scroll:x,frozenSize:V.height,trailingSize:V.trailingHeight,extent:E.height}),col:Br(n,W,{scroll:S,frozenSize:V.width,trailingSize:V.trailingWidth,extent:E.width})},t.count,n.count),A=u.current;(d!==0||y!==0||A===null||A.row!==C.row||A.col!==C.col)&&(u.current=C,o($.buildRange(C)))}c.current=requestAnimationFrame(L)},[e,t,n,s,o]),M=i.useCallback($=>{g(),a.current=$,h.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(L)},[g,L,r]);return i.useEffect(()=>{const $=()=>{document.visibilityState==="hidden"&&g()};return document.addEventListener("visibilitychange",$),()=>{document.removeEventListener("visibilitychange",$),g()}},[g]),i.useMemo(()=>({start:M,stop:g}),[M,g])},Kc=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),h=i.useRef(null),g=i.useRef(!1),L=i.useRef(0),M=i.useCallback((E,P)=>{const{axis:j,mainAxis:m,handleRef:d,zoomRef:y}=t.current,v=s.current;if(v===null||m.totalSize()===0)return null;const x=y.current,S=d.current;if(S===null)return null;if(j==="col"){const X=S.getScrollPosition().x;if(X<0)return null;const w=S.getFrozenSize(),G=S.getViewportSize();return Math.min(Math.max(Br(m,(E-v.left)/x,{scroll:X,frozenSize:w.width,trailingSize:w.trailingWidth,extent:G.width}),0),m.count-1)}const V=S.getScrollPosition().y;if(V<0)return null;const C=S.getFrozenSize(),A=S.getViewportSize();return Math.min(Math.max(Vr(m,(P-v.top)/x,{scroll:V,frozenSize:C.height,trailingSize:C.trailingHeight,extent:A.height}),0),m.count-1)},[]),$=i.useCallback((E,P)=>{const{axis:j,crossCount:m}=t.current;return j==="col"?{press:{row:0,col:E},extend:{row:m-1,col:P}}:{press:{row:E,col:0},extend:{row:P,col:m-1}}},[]),H=i.useCallback((E,P)=>{const{axis:j,crossCount:m}=t.current;return E.ranges.some(d=>j==="col"?d.startRow===0&&d.endRow===m-1&&P>=d.startCol&&P<=d.endCol:d.startCol===0&&d.endCol===m-1&&P>=d.startRow&&P<=d.endRow)},[]),Z=i.useRef(!1),Q=i.useRef({clientX:0,clientY:0}),O=i.useCallback(()=>{Z.current=!1;const{autoScroller:E,headerRef:P,onDragFrame:j}=t.current;n.current=!1,r.current=null,h.current=null,g.current=!1,L.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),E.stop();const m=P.current;m!==null&&a.current!==null&&m.hasPointerCapture?.(a.current)&&m.releasePointerCapture(a.current),a.current=null,j(null),t.current.repaintOverlay()},[]),D=i.useCallback(()=>{if(!n.current)return;const E=r.current;E!==null&&t.current.setSelection(E),O()},[O]),{enabled:W,headerRef:K}=e;return i.useEffect(()=>{const E=K.current;if(!W||E===null)return;const P=S=>{const V=t.current;if(S.pointerType!=="mouse")return;if(S.button!==0){S.preventDefault();return}if(g.current=!1,V.pointing?.getPointing()){s.current=E.getBoundingClientRect();const w=M(S.clientX,S.clientY);if(w===null)return;S.preventDefault(),V.focusSink(),V.pointing.insertReference(V.axis==="col"?{row:0,col:w}:{row:w,col:0},V.axis==="col"?"columns":"rows");return}if(V.isEditing()&&!V.requestCommit()){S.preventDefault(),V.focusSink();return}s.current=E.getBoundingClientRect();const C=M(S.clientX,S.clientY);if(C===null)return;S.preventDefault(),V.focusSink();const A=V.getSelection();r.current=A;const X=S.ctrlKey||S.metaKey;if(S.shiftKey){const w=V.axis==="col"?{row:0,col:A.anchor.col}:{row:A.anchor.row,col:0},{extend:G}=$(C,C),te={...A,anchor:w};V.setSelection(Mn(te,G)),o.current=V.axis==="col"?w.col:w.row}else if(X&&H(A,C))g.current=!0,L.current=C,o.current=C;else{const{press:w,extend:G}=$(C,C),te=ar(A,w,{extend:!1,append:X});V.setSelection(Mn(te,G)),o.current=C}n.current=!0,V.repaintOverlay(),l.current={clientX:S.clientX,clientY:S.clientY},a.current=S.pointerId,u.current=S.buttons;try{E.setPointerCapture(S.pointerId)}catch{a.current=null}h.current=w=>{const G=t.current.axis==="col"?w.col:w.row,{press:te}=$(o.current,o.current),{extend:f}=$(o.current,G);return me(te,f)},V.autoScroller.stop(),Z.current=!1,Q.current={clientX:S.clientX,clientY:S.clientY}},j=S=>a.current!==null?S.pointerId===a.current:S.pointerType==="mouse",m=S=>{if(n.current&&j(S)){if(g.current){const V=S.clientX!==l.current.clientX||S.clientY!==l.current.clientY;if(l.current={clientX:S.clientX,clientY:S.clientY},!V)return;const C=M(S.clientX,S.clientY);if(C===null||C===L.current)return;g.current=!1;const A=t.current,{press:X,extend:w}=$(L.current,L.current),G=ar(A.getSelection(),X,{extend:!1,append:!0});A.setSelection(Mn(G,w));const te=h.current,f=Math.abs(S.clientX-Q.current.clientX),b=Math.abs(S.clientY-Q.current.clientY);te!==null&&Math.max(f,b)>=No&&(Z.current=!0,A.autoScroller.start({getPointerPosition:()=>l.current,buildRange:te,anchorCol:A.axis==="col"?o.current:void 0,anchorRow:A.axis==="row"?o.current:void 0}))}else if(l.current={clientX:S.clientX,clientY:S.clientY},!Z.current&&h.current!==null){const V=Math.abs(S.clientX-Q.current.clientX),C=Math.abs(S.clientY-Q.current.clientY);Math.max(V,C)>=No&&(Z.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:h.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 V=h.current;if(!n.current||V===null)return;const C=M(l.current.clientX,l.current.clientY);C!==null&&t.current.onDragFrame(V(t.current.axis==="col"?{row:0,col:C}:{row:C,col:0}))}))}},d=S=>{m(S),n.current&&j(S)&&(u.current&1)!==0&&(S.buttons&1)===0&&v(S)},y=S=>{S.button!==0||!(n.current&&j(S))||v(S)},v=S=>{const V=t.current;if(g.current){const{press:A,extend:X}=$(L.current,L.current);V.setSelection(Wu(V.getSelection(),me(A,X),A)),O();return}const C=M(S.clientX,S.clientY);if(C!==null){const{extend:A}=$(o.current,C);V.setSelection(Mn(V.getSelection(),A))}O()},x=S=>{!n.current||a.current===null||S.pointerId!==a.current||D()};return E.addEventListener("pointerdown",P),E.addEventListener("pointermove",d),E.addEventListener("pointerup",y),E.addEventListener("lostpointercapture",x),()=>{E.removeEventListener("pointerdown",P),E.removeEventListener("pointermove",d),E.removeEventListener("pointerup",y),E.removeEventListener("lostpointercapture",x),O()}},[W,K,M,$,O,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:D,cancelDrag:O}),[D,O])},W0=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(l<0||s<0)return;const u=o.getFrozenSize();if(a>0&&r.row>=u.rows&&r.row<t.count-u.trailingRows){const h=t.offsetOf(r.row),g=h+t.sizeOf(r.row);h<u.height+l?o.scrollBy({y:h-(u.height+l)}):g>l+a-u.trailingVisibleHeight&&o.scrollBy({y:g-(l+a-u.trailingVisibleHeight)})}if(c>0){if(r.col<u.cols||r.col>=n.count-u.trailingCols)return;const h=n.offsetOf(r.col),g=h+n.sizeOf(r.col);h<u.width+s?o.scrollBy({x:h-(u.width+s)}):g>s+c-u.trailingVisibleWidth&&o.scrollBy({x:g-(s+c-u.trailingVisibleWidth)})}},K0=50,Y0=100,Yu=(e,t)=>_d.isInputMethodKey(e)?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<K0:!1,Ar={selectAll:en("Ctrl+A"),undo:en("Ctrl+Z"),redo:en("Ctrl+Y"),redoShiftZ:en("Ctrl+Shift+Z"),pasteValues:en("Ctrl+Shift+V")},X0=new Set(["Shift","Control","Alt","Meta","AltGraph"]),U0={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},G0=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",J0=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(null),l=i.useRef(!1),c=i.useRef(!1),a=i.useRef(e);a.current=e;const{enabled:u,sinkRef:h,rootRef:g,handleRef:L}=e;i.useEffect(()=>{const M=h.current,$=g.current;if(!u||M===null||$===null)return;const H=()=>{c.current&&(c.current=!1,a.current.onPointFrame?.(null))},Z=(f,b,R)=>wn(f,b,R)??b,Q=(f,b)=>{const R=a.current;return b==="left"||b==="right"?{row:f.row,col:Z(R.colAxis,f.col,b==="right"?1:-1)}:{row:Z(R.rowAxis,f.row,b==="down"?1:-1),col:f.col}},O=f=>f.indexAt(0),D=f=>f.indexAt(f.totalSize()-1),W=(f,b,R,_)=>{if(f.sizeOf(b)>0)return b;const Y=wn(f,b,R);if(Y!==null)return Y;const U=wn(f,b,R===1?-1:1);return U!==null?U:_},K=()=>{const f=a.current.getSelection(),b=f.ranges[f.ranges.length-1];return{row:f.anchor.row===b.startRow?b.endRow:b.startRow,col:f.anchor.col===b.startCol?b.endCol:b.startCol}},E=f=>Q(K(),f),P=(f,b)=>{const R=a.current,_=b==="left"||b==="right",Y=b==="right"||b==="down"?1:-1;let U;return R.findDataEdge!==void 0?(U=R.findDataEdge({row:f.row,col:f.col},b),j(U,f,b)):U={row:b==="down"?R.rowAxis.count-1:b==="up"?0:f.row,col:b==="right"?R.colAxis.count-1:b==="left"?0:f.col},_?{row:U.row,col:W(R.colAxis,U.col,Y,f.col)}:{row:W(R.rowAxis,U.row,Y,f.row),col:U.col}},j=(f,b,R)=>{const _=a.current;if(!(Number.isInteger(f.row)&&Number.isInteger(f.col)&&f.row>=0&&f.row<_.rowAxis.count&&f.col>=0&&f.col<_.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${f.row}, col: ${f.col}} for a ${_.rowAxis.count} x ${_.colAxis.count} grid`);const Y=R==="left"||R==="right";if(Y?f.row!==b.row:f.col!==b.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${Y?"row":"column"} (received {row: ${f.row}, col: ${f.col}} from {row: ${b.row}, col: ${b.col}})`)},m=(f,b,R)=>{if(!(Number.isInteger(f)&&f>=0&&f<b))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${R} component ${f} (count ${b})`)},d=f=>{const b=a.current,R=b.getSelection();if(Ku(R,f)===R){b.moveActive({mode:"reset",cell:Q(R.active,f)});return}b.moveActive({mode:"cycle",direction:f})},y=f=>{const b=a.current,R=b.commands;if(R===void 0||!b.isEditing())return null;const _=Vs(R.table,f);return _!==null&&_.command==="fillSelection"&&R.isAvailable("fillSelection")?R:null},v=()=>{s.current=null;const f=a.current,b=f.commands;b===void 0||!f.isEditing()||!b.isAvailable("fillSelection")||b.execute("fillSelection")},x=f=>{const b=y(f);if(r.current){o.current=b!==null;return}b!==null&&t.current!==null&&(f.preventDefault(),b.execute("fillSelection"))},S=()=>{const f=h.current;if(f===null)return;const b=f.selectionStart??f.value.length,R=f.selectionEnd??b;f.value=`${f.value.slice(0,b)}
|
|
14
|
+
${f.value.slice(R)}`,f.setSelectionRange(b+1,b+1)},V=(f,b)=>{const R=a.current,_=R.pageExtent();if(_<=0)return Z(R.rowAxis,f,b==="down"?1:-1);const Y=R.rowAxis.indexAt(R.rowAxis.offsetOf(f)+(b==="down"?_:-_));return Y===f?Z(R.rowAxis,f,b==="down"?1:-1):Y},C=f=>{const b=a.current;if(l.current=!1,Yu(f,t.current)){x(f);return}const R=f.ctrlKey||f.metaKey,_=f.altKey,Y=U0[f.key];if(c.current&&!X0.has(f.key)&&!b.isDragging()&&H(),b.isEditing()){const oe=b.getEditingMode();if(b.isDragging()){f.preventDefault(),f.key==="Escape"&&!R&&!f.shiftKey&&!_&&b.abortDrag();return}const ce=b.pointing;if(ce!==void 0){if(Y!==void 0&&!_){const z=ce.getReferenceCursor();if(z!==null){f.preventDefault();const re=vn(z.cursor,b.rowAxis.count,b.colAxis.count),ge=vn(z.origin,b.rowAxis.count,b.colAxis.count),Te=R?P(re,Y):Q(re,Y);if(b.ensureCellVisible(Te),ce.insertReference(f.shiftKey?me(ge,Te):Te,z.axis),b.onPointFrame!==void 0){const Pe=f.shiftKey?me(ge,Te):me(Te,Te);b.onPointFrame(z.axis==="columns"?me({row:0,col:Pe.startCol},{row:b.rowAxis.count-1,col:Pe.endCol}):z.axis==="rows"?me({row:Pe.startRow,col:0},{row:Pe.endRow,col:b.colAxis.count-1}):Pe),c.current=!0}return}}if(f.key==="F2"&&!R&&!f.shiftKey&&!_&&ce.togglePointingArm()){f.preventDefault();return}if(f.key==="F4"&&!R&&!f.shiftKey&&!_&&ce.cycleAnchorAtCaret()){f.preventDefault();return}}const k=b.commands,B=k===void 0?null:Vs(k.table,f);if(k!==void 0&&B!==null&&$o.has(B.command)&&k.isAvailable(B.command)){f.preventDefault(),k.execute(B.command);return}if(Y!==void 0&&!_){if(R&&f.shiftKey){f.preventDefault();return}if(R)return;if(oe==="replace"){if(f.preventDefault(),!b.requestCommit())return;f.shiftKey?b.moveActive({mode:"extend",cell:E(Y)}):b.moveActive({mode:"reset",cell:Q(b.getSelection().active,Y)});return}return}if(f.key==="Enter"&&_&&!R&&!f.shiftKey){f.preventDefault(),S();return}if((f.key==="Enter"||f.key==="Tab")&&!R&&!_){if(f.preventDefault(),!b.requestCommit())return;const z=!f.shiftKey;d(f.key==="Tab"?z?"right":"left":z?"down":"up");return}if((f.key==="PageUp"||f.key==="PageDown")&&!f.shiftKey&&!R&&!_){if(f.preventDefault(),!b.requestCommit())return;const z=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:V(z.row,f.key==="PageDown"?"down":"up"),col:z.col}});return}if(f.key==="Escape"&&!R&&!f.shiftKey&&!_){f.preventDefault(),b.cancelEdit();return}if(k!==void 0&&B!==null&&!$o.has(B.command)&&Ym(B.chord)&&k.isAvailable(B.command)){f.preventDefault(),b.onCommandBlockedWhileEditing?.(B);return}return}if(f.defaultPrevented)return;if(b.isDragging()&&f.key!=="Escape"){f.preventDefault();return}const U=b.commands;if(U!==void 0){const oe=Vm(U.table,f);if(oe!==null&&U.isAvailable(oe)){f.preventDefault(),U.execute(oe);return}}if(Y!==void 0&&!_){const oe=Y==="left"||Y==="right",ce=Y==="right"||Y==="down"?1:-1;if(R&&f.shiftKey){f.preventDefault();const k=b.getSelection(),B=K();let z;if(b.findDataEdge!==void 0){const re=oe?{row:k.active.row,col:B.col}:{row:B.row,col:k.active.col},ge=b.findDataEdge(re,Y);z=oe?ge.col:ge.row,m(z,oe?b.colAxis.count:b.rowAxis.count,oe?"col":"row"),z=W(oe?b.colAxis:b.rowAxis,z,ce,oe?B.col:B.row)}else{const re=oe?b.colAxis:b.rowAxis;z=ce===1?D(re):O(re)}b.moveActive({mode:"extend",cell:oe?{row:B.row,col:z}:{row:z,col:B.col}});return}if(R){f.preventDefault(),b.moveActive({mode:"reset",cell:P(b.getSelection().active,Y)});return}if(f.shiftKey){f.preventDefault(),b.moveActive({mode:"extend",cell:E(Y)});return}f.preventDefault(),b.moveActive({mode:"reset",cell:Q(b.getSelection().active,Y)});return}if(G0(f)){f.preventDefault();return}if((f.key==="Tab"||f.key==="Enter")&&!R&&!_){f.preventDefault();const oe=!f.shiftKey;d(f.key==="Tab"?oe?"right":"left":oe?"down":"up");return}if(f.key==="Home"&&!_){if(f.preventDefault(),f.shiftKey){const ce=K();b.moveActive({mode:"extend",cell:{row:R?O(b.rowAxis):ce.row,col:O(b.colAxis)}});return}const oe=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:R?O(b.rowAxis):oe.row,col:O(b.colAxis)}});return}if(f.key==="End"&&!_){if(f.preventDefault(),f.shiftKey){const ce=K();b.moveActive({mode:"extend",cell:{row:R?D(b.rowAxis):ce.row,col:D(b.colAxis)}});return}const oe=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:R?D(b.rowAxis):oe.row,col:D(b.colAxis)}});return}if((f.key==="PageUp"||f.key==="PageDown")&&!R&&!_){f.preventDefault();const oe=f.key==="PageDown"?"down":"up";if(f.shiftKey){const k=K();b.moveActive({mode:"extend",cell:{row:V(k.row,oe),col:k.col}});return}const ce=b.getSelection().active;b.moveActive({mode:"reset",cell:{row:V(ce.row,oe),col:ce.col}});return}if(f.key==="F2"&&!R&&!f.shiftKey&&!_){f.preventDefault(),b.startEdit("edit");return}if((f.key==="Delete"||f.key==="Backspace")&&!R&&!f.shiftKey&&!_){f.preventDefault();const oe=b.getSelection(),ce=vt(oe.ranges);if(ce>b.maxOperationCells){b.onOperationRejected?.("delete",ce,"limit");return}if(b.adapter!==void 0&&nr(b.adapter,oe.ranges)){b.rejectReadOnly({kind:"operation",op:"delete",cellCount:ce});return}const k=[],B=b.adapter!==void 0&&ko(b.adapter).hyperlink;fn(oe.ranges,z=>{k.push(B?{row:z.row,col:z.col,text:"",hyperlink:null}:{row:z.row,col:z.col,text:""})}),b.commitEdits(k,{source:"delete"});return}if(f.key==="Escape"){if(b.isDragging()){f.preventDefault(),b.abortDrag();return}if(R||f.shiftKey||_||(f.preventDefault(),b.hideNoteTip?.())||b.closeRejectedMessage?.())return;if(b.getClip()!==null){b.discardClip();return}b.handOffFocusToRoot();return}if(kr(Ar.selectAll,f)){f.preventDefault();const oe=b.getSelection(),ce=me({row:0,col:0},{row:b.rowAxis.count-1,col:b.colAxis.count-1});b.setSelection({ranges:[ce],anchor:oe.anchor,active:oe.active});return}if(kr(Ar.undo,f)){f.preventDefault(),b.onUndoRequest?.();return}if(kr(Ar.redo,f)||kr(Ar.redoShiftZ,f)){f.preventDefault(),b.onRedoRequest?.();return}if(f.key==="F10"&&f.shiftKey&&!R&&!_||f.key==="ContextMenu"&&!R&&!f.shiftKey&&!_){f.preventDefault();const oe=b.getSelection().active;b.ensureCellVisible(oe);const ce=L.current,k=ce===null?{x:0,y:0}:ce.getScrollPosition(),B=Math.max(0,k.y),z=Math.max(0,k.x),re=ce===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:ce.getFrozenSize(),ge=ce===null?{width:0,height:0}:ce.getViewportSize(),Te=b.zoomRef.current;b.onCellContextMenu?.(oe,{kind:"keyboard",cellRect:{top:Dn(b.rowAxis,oe.row,{scroll:B,frozenCount:re.rows,trailingCount:re.trailingRows,extent:ge.height})*Te,left:Nn(b.colAxis,oe.col,{scroll:z,frozenCount:re.cols,trailingCount:re.trailingCols,extent:ge.width})*Te,width:b.colAxis.sizeOf(oe.col)*Te,height:b.rowAxis.sizeOf(oe.row)*Te}});return}if(f.key===" "&&!_&&R!==f.shiftKey){f.preventDefault();const oe=b.getSelection(),ce=oe.ranges.map(k=>R?me({row:0,col:k.startCol},{row:b.rowAxis.count-1,col:k.endCol}):me({row:k.startRow,col:0},{row:k.endRow,col:b.colAxis.count-1}));b.setSelection({ranges:ce,anchor:oe.anchor,active:oe.active});return}if(b.pendingPasteOptionsRef!==void 0&&kr(Ar.pasteValues,f)){b.pendingPasteOptionsRef.current={mode:"values"};return}if(f.key.length===1&&!f.metaKey&&f.ctrlKey===f.altKey){if(f.ctrlKey&&f.altKey){l.current=!0;return}b.startEdit("replace");return}},A=()=>{const f=a.current;r.current=!0,o.current=!1,f.isEditing()||f.startEdit("replace")},X=f=>{r.current=!1,t.current=f.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Y0),o.current&&(o.current=!1,f.data!==""&&(s.current!==null&&window.clearTimeout(s.current),s.current=window.setTimeout(v,0)))},w=()=>{const f=a.current;if(H(),!f.isEditing()){if(l.current){l.current=!1;const b=M.value;if(b!==""&&(f.startEdit("replace"),f.isEditing())){M.value=b,M.setSelectionRange(b.length,b.length);return}}f.rearmSink()}},G=()=>{l.current=!1;const f=a.current.pendingPasteOptionsRef;f!==void 0&&(f.current=null)},te=()=>{l.current=!1;const f=a.current.pendingPasteOptionsRef;f!==void 0&&(f.current=null),H()};return M.addEventListener("keydown",C),M.addEventListener("keyup",G),M.addEventListener("blur",te),M.addEventListener("compositionstart",A),M.addEventListener("compositionend",X),M.addEventListener("input",w),()=>{M.removeEventListener("keydown",C),M.removeEventListener("keyup",G),M.removeEventListener("blur",te),M.removeEventListener("compositionstart",A),M.removeEventListener("compositionend",X),M.removeEventListener("input",w),n.current!==null&&window.clearTimeout(n.current),s.current!==null&&(window.clearTimeout(s.current),s.current=null),r.current=!1,o.current=!1,H()}},[u,h,g,L])},Z0=()=>{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)})}},Q0=4,eC=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),tC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),a=i.useRef(!1),u=i.useRef({dx:0,dy:0}),h=i.useRef(null),g=i.useRef(0),L=i.useRef(null),M=i.useRef(null),$=i.useRef(!1),H=i.useCallback(E=>h.current!==null?E.pointerId===h.current:E.pointerType==="mouse",[]),Z=i.useCallback((E,P)=>{const{handleRef:j,rowAxis:m,colAxis:d}=t.current,y=j.current,v=s.current;if(y===null||v===null)return null;const{x,y:S}=y.getScrollPosition();if(S<0||x<0||m.totalSize()===0||d.totalSize()===0)return null;const V=t.current.zoomRef.current,C=y.getFrozenSize(),A=y.getViewportSize();return vn({row:Vr(m,(P-v.top)/V,{scroll:S,frozenSize:C.height,trailingSize:C.trailingHeight,extent:A.height}),col:Br(d,(E-v.left)/V,{scroll:x,frozenSize:C.width,trailingSize:C.trailingWidth,extent:A.width})},m.count,d.count)},[]),Q=i.useCallback(E=>{const P=r.current;if(P===null)return me(E,E);const j=me({row:Math.min(P.startRow,E.row),col:Math.min(P.startCol,E.col)},{row:Math.max(P.endRow,E.row),col:Math.max(P.endCol,E.col)}),m=j.startRow!==P.startRow||j.endRow!==P.endRow||j.startCol!==P.startCol||j.endCol!==P.endCol;return o.current=m?j:null,m?j:P},[]),O=i.useCallback(()=>{const E=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,L.current!==null&&(cancelAnimationFrame(L.current),L.current=null),E.xAutoScroller.stop(),E.yAutoScroller.stop(),$.current=!1,a.current=!1,u.current={dx:0,dy:0},E.writeFillPreview(null);const P=M.current;P!==null&&(window.removeEventListener("pointermove",P.move),window.removeEventListener("pointerup",P.up),M.current=null);const j=t.current.handleNodeRef.current;j!==null&&h.current!==null&&j.hasPointerCapture?.(h.current)&&j.releasePointerCapture(h.current),h.current=null,E.repaintOverlay()},[]),D=i.useCallback(()=>{const E=t.current,P=r.current,j=o.current;if(O(),P===null||j===null)return;const m=xm(P,j);if(m>E.maxOperationCells){E.onOperationRejected?.("fill",m,"limit");return}const d=Am(P,j);if(nr(E.adapter,d)){E.rejectReadOnly({kind:"operation",op:"fill",cellCount:vt(d),gesture:"fillHandle",sources:[P],targets:d});return}const y=Tm((x,S)=>nu(E.adapter,x,S),P,j,ru);if(E.commitEdits(y,{source:"fill"})===null)return;const v=E.getSelection();E.setSelection({ranges:[j],anchor:v.anchor,active:v.active})},[O]),{enabled:W,handleNodeRef:K}=e;return i.useEffect(()=>{const E=K.current;if(!W||E===null)return;const P=v=>{j(v),n.current&&H(v)&&(g.current&1)!==0&&(v.buttons&1)===0&&D()},j=v=>{if(!(n.current&&H(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const x=Math.abs(v.clientX-c.current.clientX),S=Math.abs(v.clientY-c.current.clientY);if(!a.current&&Math.max(x,S)>=Q0&&(a.current=!0),!!a.current){if(!$.current){const V=t.current,C={getPointerPosition:()=>({clientX:l.current.clientX-u.current.dx,clientY:l.current.clientY-u.current.dy}),buildRange:Q,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};V.xAutoScroller.start(C),V.yAutoScroller.start(C),$.current=!0}L.current===null&&(L.current=requestAnimationFrame(()=>{if(L.current=null,!(n.current&&a.current))return;const V=Z(l.current.clientX-u.current.dx,l.current.clientY-u.current.dy);V!==null&&t.current.writeFillPreview(Q(V))}))}},m=v=>{v.button!==0||!(n.current&&H(v))||D()},d=v=>{const x=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),x.focusSink();const S=x.getSelection(),V=S.ranges[S.ranges.length-1];r.current=V,o.current=null,a.current=!1,x.xAutoScroller.stop(),x.yAutoScroller.stop(),$.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,g.current=v.buttons,n.current=!0,x.repaintOverlay(),s.current=x.bodyRef.current?.getBoundingClientRect()??null;const C=s.current,A=x.handleRef.current?.getScrollPosition()??{x:-1,y:-1},X=A.y;if(C!==null&&X>=0&&A.x>=0){const te=A.x,f=x.zoomRef.current,b=x.handleRef.current?.getFrozenSize()??eC,R=x.handleRef.current?.getViewportSize()??{width:0,height:0},_={scroll:te,frozenCount:b.cols,trailingCount:b.trailingCols,extent:R.width},Y={scroll:X,frozenCount:b.rows,trailingCount:b.trailingRows,extent:R.height},U=Nn(x.colAxis,V.endCol,_)+x.colAxis.sizeOf(V.endCol),oe=Dn(x.rowAxis,V.endRow,Y)+x.rowAxis.sizeOf(V.endRow),ce=U-1,k=V.endCol>=b.cols&&b.width>0?Math.max(ce,b.width):ce,z=!(V.endCol>=x.colAxis.count-b.trailingCols)&&b.trailingWidth>0?Math.min(k,R.width-b.trailingVisibleWidth-1):k,re=oe-1,ge=V.endRow>=b.rows&&b.height>0?Math.max(re,b.height):re,Pe=!(V.endRow>=x.rowAxis.count-b.trailingRows)&&b.trailingHeight>0?Math.min(ge,R.height-b.trailingVisibleHeight-1):ge;u.current={dx:v.clientX-(C.left+z*f),dy:v.clientY-(C.top+Pe*f)}}else u.current={dx:0,dy:0};h.current=v.pointerId;try{E.setPointerCapture(v.pointerId)}catch{h.current=null}const w=P,G=m;M.current={move:w,up:G},window.addEventListener("pointermove",w),window.addEventListener("pointerup",G),x.writeFillPreview(r.current)},y=v=>{!n.current||h.current===null||v.pointerId!==h.current||O()};return E.addEventListener("pointerdown",d),E.addEventListener("lostpointercapture",y),()=>{E.removeEventListener("pointerdown",d),E.removeEventListener("lostpointercapture",y),O()}},[W,K,H,Z,Q,O,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&O()},cancelDrag:O}),[O])},nC=(e,t,n)=>{const r=Object.hasOwn(e.filters,t)?e.filters[t]:void 0;return new Set(r!==void 0&&r.mode==="exact"?r.values:n.map(o=>o.value))},rC=({column:e,columnName:t,state:n,getFilterValues:r,changeState:o,close:s,isInsideGrid:l,relayout:c,labels:a})=>{const u=e.key,h=Object.hasOwn(n.filters,u)?n.filters[u]:void 0,g=n.sort!==null&&n.sort.columnKey===u?n.sort.direction:null,[L,M]=i.useState(()=>h===void 0?e.defaultMatchMode:h.mode),[$,H]=i.useState(()=>h!==void 0&&h.mode==="fuzzy"?h.query:""),[Z,Q]=i.useState(""),[O,D]=i.useState({status:"idle"}),[W,K]=i.useState(()=>new Set),E=i.useRef(!1),P=i.useRef(n);P.current=n;const j=i.useId(),m=i.useId(),d=e.filterable&&L==="exact",y=d||O.status!=="idle";i.useEffect(()=>{if(!y)return;if(r===void 0){D({status:"failed"});return}const z=new AbortController;let re;try{re=Promise.resolve(r(u,P.current,z.signal))}catch{return D({status:"failed"}),()=>z.abort()}return D({status:"loading"}),re.then(ge=>{if(z.signal.aborted)return;let Te;try{Te=R0(ge)}catch{D({status:"failed"});return}D({status:"loaded",values:Te}),K(nC(P.current,u,Te))},()=>{z.signal.aborted||D({status:"failed"})}),()=>z.abort()},[y]);const v=O.status==="loaded"||O.status==="failed"?O.status:"pending",x=i.useRef(!1);i.useLayoutEffect(()=>{if(!x.current){x.current=!0;return}c()},[L,v]);const S=O.status==="loaded"?O.values:null,V=z=>z.label===""?be(a,"filterBlank"):z.label,C=i.useMemo(()=>S===null?[]:S.filter(z=>S0(z.label===""?be(a,"filterBlank"):z.label,Z)),[S,Z,a]),A=C.length>Mo?C.slice(0,Mo):C,X=C.length-A.length,w=S===null?0:S.filter(z=>W.has(z.value)).length,G=z=>{E.current=!0;try{z()}finally{E.current=!1}},te=z=>G(()=>{o(z)}),f=z=>te(g0(n,u,z)),b=()=>{if(L==="fuzzy"){te(y0(n,u,$));return}S===null||w===0||te(C0(n,u,W,S.map(z=>z.value)))},R=z=>{const re=new Set(W);for(const ge of C)z?re.add(ge.value):re.delete(ge.value);K(re)},_=z=>{const re=new Set(W);re.has(z)?re.delete(z):re.add(z),K(re)},Y=z=>{z.key==="Escape"&&(z.preventDefault(),G(()=>s()))},U=z=>{const re=z.relatedTarget;E.current||re instanceof Node&&z.currentTarget.contains(re)||G(()=>s({restoreFocus:re instanceof Node&&l(re)}))},oe=e.filterable&&e.matchModes.length===2,ce=e.sortable?"sort":oe?"mode":L==="exact"?"search":"query",k=z=>ce===z?{"data-aqsp-popover-autofocus":""}:{},B=Object.keys(n.filters).length>0;return I.jsxs("div",{className:"aqsp-popover-column-menu","data-aqsp-popover":"columnMenu",role:"dialog","aria-labelledby":m,onKeyDown:Y,onBlur:U,children:[I.jsx("div",{className:"aqsp-popover-title",id:m,children:t.trim()===""?be(a,"columnMenu"):`${t} ${be(a,"columnMenu")}`}),e.sortable?I.jsxs("div",{className:"aqsp-popover-section aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortAsc","aria-pressed":g==="asc",onClick:()=>f("asc"),...k("sort"),children:be(a,"sortAscending")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortDesc","aria-pressed":g==="desc",onClick:()=>f("desc"),children:be(a,"sortDescending")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"sortClear",disabled:g===null,onClick:()=>f(null),children:be(a,"sortClear")})]}):null,oe?I.jsxs("fieldset",{className:"aqsp-popover-section aqsp-popover-fieldset",children:[I.jsx("legend",{className:"aqsp-popover-field-label",children:be(a,"filterMatchMode")}),Hu.map(z=>I.jsxs("label",{className:"aqsp-popover-radio",children:[I.jsx("input",{type:"radio",name:j,value:z,"data-aqsp-column-menu-mode":z,checked:L===z,onChange:()=>M(z),...L===z?k("mode"):{}}),be(a,z==="exact"?"filterModeExact":"filterModeFuzzy")]},z))]}):null,d?I.jsxs("div",{className:"aqsp-popover-section",children:[I.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"search","aria-label":be(a,"filterSearchValues"),placeholder:be(a,"filterSearchValues"),value:Z,onChange:z=>Q(z.currentTarget.value),...k("search")}),I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkAll",disabled:C.length===0,onClick:()=>R(!0),children:be(a,"filterSelectAll")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"checkNone",disabled:C.length===0,onClick:()=>R(!1),children:be(a,"filterSelectNone")})]}),I.jsxs("fieldset",{className:"aqsp-popover-values","data-aqsp-column-menu-values":"","aria-label":be(a,"filterModeExact"),"aria-busy":O.status==="loading"||O.status==="idle"?"true":void 0,children:[O.status==="failed"?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"failed",role:"alert",children:be(a,"filterLoadFailed")}):S===null?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"loading",children:be(a,"filterLoading")}):A.length===0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"empty",children:be(a,"listEmpty")}):A.map(z=>I.jsxs("label",{className:"aqsp-popover-value",children:[I.jsx("input",{type:"checkbox","data-aqsp-column-menu-value":z.value,checked:W.has(z.value),onChange:()=>_(z.value)}),I.jsx("span",{className:"aqsp-popover-value-text",children:V(z)}),I.jsx("span",{className:"aqsp-popover-value-count",children:z.count})]},z.value)),X>0?I.jsx("div",{className:"aqsp-popover-empty","data-aqsp-column-menu-status":"more",children:be(a,"listMore",X)}):null]})]}):null,e.filterable&&L==="fuzzy"?I.jsx("div",{className:"aqsp-popover-section",children:I.jsx("input",{type:"search",className:"aqsp-popover-input","data-aqsp-column-menu-input":"query","aria-label":be(a,"filterQuery"),placeholder:be(a,"filterQuery"),value:$,onChange:z=>H(z.currentTarget.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),b())},...k("query")})}):null,e.filterable?I.jsxs("div",{className:"aqsp-popover-actions",children:[I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"apply",disabled:L==="exact"&&w===0,onClick:b,children:be(a,"filterApply")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clear",disabled:h===void 0,onClick:()=>te(gl(n,u)),children:be(a,"filterClearColumn")}),I.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-column-menu-action":"clearAll",disabled:!B,onClick:()=>te(w0(n)),children:be(a,"filterClearAll")})]}):null]})},oC=320,Oo=8,sC=64,lC=150,Xu=e=>Math.max(0,Math.min(oC,e.width-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX-Oo)),iC=(e,t,n)=>{const r=n.width-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Fe.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Xu(n),l=Math.max(0,Math.min(t,o-Oo)),c=e.left+e.width,a=e.top+e.height,u=H=>H>=0&&H+s<=r,h=[e.left,c-s],g=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const H of g)if(u(H.left)&&H.top>=0&&H.top+l<=o)return{left:H.left,top:H.top,width:s,height:l};const L=o-a,M=e.top,$=Math.min(l,Math.max(L,M));if($>=sC){const H=L>=M?a:e.top-$;for(const Z of h)if(u(Z))return{left:Z,top:H,width:s,height:$}}return{left:Oo,top:Oo,width:s,height:l}},cC=(e,t,n,r)=>t===null||e!==null&&Dt(e,t)||n?!1:r(t),aC=(e,t)=>{switch(e.kind){case"note":return I.jsx(Ou,{ctx:e,labels:t});case"note-tip":return I.jsx(xu,{ctx:e,labels:t});case"comment":return I.jsx(Ru,{ctx:e,labels:t});case"link":return I.jsx(Su,{ctx:e,labels:t});case"list":return I.jsx(Eu,{ctx:e,labels:t});default:return I.jsx(ku,{ctx:e,labels:t})}},As=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,uC=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o,columnMenu:s})=>{const{context:l,tipContext:c}=e,a=i.useRef(null),u=i.useRef(null),h=i.useRef(c);h.current=c;const g=i.useRef(e);g.current=e;const L=As(l),M=As(c),$=i.useRef(null),H=(E,P)=>{const j=g.current.getLayerSize();E.style.width=`${Xu(j)}px`,E.style.maxHeight="";const m=iC(P,E.offsetHeight,j);E.style.left=`${m.left-P.left}px`,E.style.top=`${m.top-P.top}px`,E.style.maxHeight=`${m.height}px`};i.useLayoutEffect(()=>{const E=a.current;if(E===null||l===null){$.current=null;return}if(H(E,l.anchorRect),l.kind==="message")return;const P=As(l);if($.current===P)return;$.current=P;const j=E.querySelector("[data-aqsp-popover-autofocus]");j!==null?j.focus({preventScroll:!0}):E.focus({preventScroll:!0})},[l]),i.useLayoutEffect(()=>{const E=u.current,P=h.current;E===null||P===null||H(E,P.anchorRect)},[M]);const Z=E=>t===void 0?aC(E,n):t(E),Q=()=>{const E=a.current,P=g.current.context;E!==null&&P!==null&&H(E,P.anchorRect)},O=E=>{if(s==null||E.cell.row!==s.resolved.headerRow)return null;const P=cr(s.resolved,E.cell.col);return P===null?null:I.jsx(rC,{column:P,columnName:s.columnNameOf(E.cell),state:s.state,getFilterValues:s.getFilterValues,changeState:s.changeState,close:e.close,isInsideGrid:s.isInsideGrid,relayout:Q,labels:n})},D=E=>{e.isCompositionKey(E.nativeEvent)&&E.stopPropagation()},W=E=>{E.key==="Escape"&&!E.defaultPrevented&&(E.preventDefault(),e.close())},K=E=>{e.registerCompositionEnd(E.timeStamp)};return I.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:D,onKeyDown:W,onCompositionEnd:K,children:[I.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,children:l===null?null:I.jsx("div",{ref:a,className:"aqsp-popover","data-aqsp-popover-frame":l.kind,tabIndex:-1,children:l.kind==="columnMenu"?O(l):Z(l)},L)}),I.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":c===null?void 0:"",inert:c===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:c===null?null:I.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:Z(c)})})]})},dC=["note","note-tip","comment","link","list","message"],fC=(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}},Tr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&fC(e,n),pC=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),a=i.useRef(null),u=i.useRef(!1),h=i.useRef(null),g=i.useRef(null),L=i.useRef(null),M=i.useRef(null),$=i.useId(),H=i.useCallback(R=>{const _=t.current,Y=_.handleRef.current,U=Y===null?{x:0,y:0}:Y.getScrollPosition(),oe=Y===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:Y.getFrozenSize(),ce=Y===null?{width:0,height:0}:Y.getViewportSize();return{top:Dn(_.rowAxis,R.row,{scroll:Math.max(0,U.y),frozenCount:oe.rows,trailingCount:oe.trailingRows,extent:ce.height}),left:Nn(_.colAxis,R.col,{scroll:Math.max(0,U.x),frozenCount:oe.cols,trailingCount:oe.trailingCols,extent:ce.width}),width:_.colAxis.sizeOf(R.col),height:_.rowAxis.sizeOf(R.row)}},[]),Z=i.useCallback(R=>{const _=t.current;_.anchors.current={..._.anchors.current,...R},_.repaintOverlay()},[]),Q=i.useCallback(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),O=i.useCallback(()=>{const R=t.current.sinkRef.current;if(R===null)return;const _=c.current;_!==null&&Dt(_,t.current.getActive())?R.setAttribute("aria-describedby",$):R.getAttribute("aria-describedby")===$&&R.removeAttribute("aria-describedby")},[$]),D=i.useCallback(()=>(Q(),u.current=!1,c.current===null?!1:(c.current=null,s(null),Z({tip:null}),O(),!0)),[Q,Z,O]),W=i.useCallback(()=>{Q(),h.current=window.setTimeout(()=>{h.current=null,D()},lC)},[Q,D]),K=i.useCallback(R=>{const _=t.current;Q();const Y=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(R.row,R.col);Y===void 0||Y===""||(c.current=R,s({kind:"note-tip",cell:R,anchorRect:H(R),current:Y,close:D}),Z({tip:R}),O())},[H,Q,D,Z,O]),E=i.useCallback(R=>{const _=t.current;if(R===null&&u.current)return;const Y=a.current;a.current=R;const U=c.current;if(U!==null&&R!==null&&Dt(U,R)){Q();return}const oe=ce=>{const k=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(ce.row,ce.col);return k!==void 0&&k!==""};if(cC(Y,R,_.isDraggingAny(),oe)){R!==null&&K(R);return}U!==null&&W()},[K,Q,W]),P=i.useCallback((R,_)=>{const Y=t.current,U=Y.bodyRef.current,oe=Y.handleRef.current;if(U===null||oe===null)return null;const ce=U.getBoundingClientRect(),k=Y.zoomRef.current,B=oe.getScrollPosition(),z=oe.getFrozenSize(),re=oe.getViewportSize();return vn({row:Vr(Y.rowAxis,(_-ce.top)/k,{scroll:Math.max(0,B.y),frozenSize:z.height,trailingSize:z.trailingHeight,extent:re.height}),col:Br(Y.colAxis,(R-ce.left)/k,{scroll:Math.max(0,B.x),frozenSize:z.width,trailingSize:z.trailingWidth,extent:re.width})},Y.rowAxis.count,Y.colAxis.count)},[]),j=i.useCallback(R=>{L.current=R,g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null;const _=L.current;E(_===null?null:"cell"in _?_.cell:P(_.clientX,_.clientY))}))},[E,P]),m=i.useCallback(R=>j({cell:R}),[j]),d=i.useCallback(()=>D(),[D]),y=i.useCallback(R=>{if(l.current===null)return;const _=t.current;l.current=null,r(null),Z({interactive:null}),(R===void 0||R.restoreFocus)&&_.focusSink({preventScroll:!0}),_.isEditing()||_.rearmSink()},[Z]),v=i.useCallback(R=>{l.current=R.kind,r(R),Z({interactive:R.cell})},[Z]),x=i.useCallback(R=>{const _=t.current;return Qa(_.adapter)?{cellReadOnly:nt(_.adapter,R.row,R.col)}:{}},[]),S=i.useCallback((R,_)=>{const Y=t.current;if(nt(Y.adapter,R.cell.row,R.cell.col)){Y.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...R,...x(R.cell)});return}if(Y.commitEdits(_,{source:"annotate"})===null){v({...R,rejected:!0});return}y()},[v,y,x]),V=i.useCallback((R,_)=>{const Y=t.current;if(!Tr(Y.adapter,Y.popovers,R))throw new RangeError(`[spreadsheet] openPopover("${R}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const U=Y.getActive();if(R==="list"&&nt(Y.adapter,U.row,U.col)){Y.rejectReadOnly({kind:"edit",cell:U,editSession:"none"});return}if(R==="note-tip"){K(U);return}if(R==="message"){if(l.current!==null&&l.current!=="message")return;const B=_!==void 0&&_.message!==void 0?_.message:void 0,z=Y.adapter.getCellValidation===void 0?void 0:Y.adapter.getCellValidation(U.row,U.col),re=B!==void 0?B:z===void 0?void 0:z.inputMessage;if(re===void 0)return;const ge=_!==void 0&&_.rejected===!0;v({kind:"message",cell:U,anchorRect:H(U),current:{title:be(Y.labels,"messageTitle"),message:re,rejected:ge},close:y});return}if(Y.isEditing()&&!Y.requestCommit())return;if(R==="list"){const B=Y.adapter.getCellValidation===void 0?void 0:Y.adapter.getCellValidation(U.row,U.col);if(B===void 0||B.type!=="list")return;const z=_!==void 0&&_.typed!==void 0?_.typed:"";D(),Y.focusSink({preventScroll:!0}),v({kind:"list",cell:U,anchorRect:H(U),current:B.values,typed:z,commit:re=>{if(nt(t.current.adapter,U.row,U.col)){t.current.rejectReadOnly({kind:"edit",cell:U,editSession:"none"}),y();return}t.current.commitEdits([{row:U.row,col:U.col,text:re}],{source:"edit",editSession:"discarded"}),y()},close:y});return}if(D(),Y.focusSink({preventScroll:!0}),R==="note"){const B=Y.adapter.getCellNote===void 0?void 0:Y.adapter.getCellNote(U.row,U.col),z={kind:"note",cell:U,anchorRect:H(U),current:B,commit:re=>{S(z,[{row:U.row,col:U.col,note:re}])},close:y,rejected:!1,...x(U)};v(z);return}if(R==="comment"){const B=Y.adapter.getCellComments===void 0?void 0:Y.adapter.getCellComments(U.row,U.col),z={kind:"comment",cell:U,anchorRect:H(U),current:B===void 0?[]:B,commit:re=>{S(z,[{row:U.row,col:U.col,comments:re}])},close:y,rejected:!1,...x(U)};v(z);return}const oe=Y.adapter.getCellHyperlink===void 0?void 0:fr(Y.adapter.getCellHyperlink(U.row,U.col)),ce=Y.adapter.getCellText(U.row,U.col),k={kind:"link",cell:U,anchorRect:H(U),current:{text:ce,url:oe},commit:B=>{const z=B.url===null?null:bn(B.url);if(z===null&&B.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(B.url)}`);const re=B.text===ce?{row:U.row,col:U.col,hyperlink:z}:{row:U.row,col:U.col,text:B.text,hyperlink:z};S(k,[re])},close:y,canOpen:Y.onHyperlinkOpen!==void 0,open:()=>{const B=t.current.onHyperlinkOpen;B!==void 0&&oe!==void 0&&B(oe,U)},rejected:!1,...x(U)};v(k)},[H,y,S,D,v,K,x]),C=i.useCallback(R=>{const _=t.current,Y=_.columnMenuAt===void 0?null:_.columnMenuAt(R);return Y===null||_.isEditing()&&!_.requestCommit()?!1:(D(),_.focusSink({preventScroll:!0}),v({kind:"columnMenu",cell:R,anchorRect:H(R),column:Y}),!0)},[H,D,v]),A=i.useCallback(R=>{l.current==="columnMenu"&&y(R)},[y]),{enabled:X,bodyRef:w}=e;i.useEffect(()=>{const R=w.current;if(!X||R===null)return;const _=U=>{const oe=t.current;Tr(oe.adapter,oe.popovers,"note-tip")&&j({clientX:U.clientX,clientY:U.clientY})},Y=()=>{Tr(t.current.adapter,t.current.popovers,"note-tip")&&j({cell:null})};return R.addEventListener("pointermove",_),R.addEventListener("pointerleave",Y),()=>{R.removeEventListener("pointermove",_),R.removeEventListener("pointerleave",Y)}},[X,w,j]),i.useEffect(()=>()=>{g.current!==null&&cancelAnimationFrame(g.current),h.current!==null&&window.clearTimeout(h.current)},[]);const{adapter:G,popovers:te}=e,f=e.columnMenuAt!==void 0,b=i.useMemo(()=>f||dC.some(R=>Tr(G,te,R)),[G,te,f]);return i.useMemo(()=>({layerEnabled:b,isKindEnabled:R=>Tr(t.current.adapter,t.current.popovers,R),open:V,close:y,isOpen:()=>l.current,openColumnMenu:C,closeColumnMenu:A,onCellHover:m,hideTip:d,onTipPointerEnter:()=>{u.current=!0,Q()},onTipPointerLeave:()=>{u.current=!1,c.current!==null&&W()},syncTipAriaDescribedBy:O,context:n,tipContext:o,registerCompositionEnd:R=>{M.current=R},isCompositionKey:R=>Yu(R,M.current),getLayerSize:()=>{const R=t.current.handleRef.current;return R===null?{width:0,height:0}:R.getViewportSize()},tipId:$}),[b,V,y,C,A,m,d,Q,W,O,n,o,$])},hC=6,mC=500,Jn=(e,t)=>Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))>=hC,Ts=(e,t)=>e!==null&&Dt(e,t),gC=(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},Us=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const u=e.getFrozenSize(),h=e.getViewportSize();return vn({row:Vr(n,(l-t.top)/o,{scroll:a,frozenSize:u.height,trailingSize:u.trailingHeight,extent:h.height}),col:Br(r,(s-t.left)/o,{scroll:c,frozenSize:u.width,trailingSize:u.trailingWidth,extent:h.width})},n.count,r.count)},wC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),a=i.useRef(0),u=i.useRef(null),h=i.useRef(!1),g=i.useRef(null),L=i.useRef(""),M=i.useRef(!1),$=i.useRef(!1),H=i.useRef(null),Z=i.useRef(null),Q=i.useRef(null),O=i.useRef(null),D=i.useCallback((v,x)=>{const{handleRef:S,rowAxis:V,colAxis:C,zoomRef:A}=t.current;return Us(S.current,o.current,V,C,A.current,v,x)},[]),W=i.useRef(!1),K=i.useRef(null),E=i.useRef(null),P=i.useRef({clientX:0,clientY:0}),j=i.useCallback(()=>{const{autoScroller:v,bodyRef:x,onDragFrame:S}=t.current;n.current=!1,r.current=null,u.current=null,W.current=!1,K.current=null,E.current=null,h.current=!1,g.current=null,H.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),v.stop();const V=x.current;V!==null&&c.current!==null&&V.hasPointerCapture?.(c.current)&&V.releasePointerCapture(c.current),c.current=null,S(null),t.current.repaintOverlay()},[]),m=i.useCallback(()=>{if(!n.current)return;const v=r.current;v!==null&&t.current.setSelection(v),j()},[j]),{enabled:d,bodyRef:y}=e;return i.useEffect(()=>{const v=y.current;if(!d||v===null)return;const x=k=>k instanceof Element&&k.closest("[data-aqsp-cells]")!==null,S=(k,B)=>{const{handleRef:z,rowAxis:re,colAxis:ge,zoomRef:Te}=t.current;return Us(z.current,v.getBoundingClientRect(),re,ge,Te.current,k,B)},V=()=>{Q.current=null,O.current!==null&&(window.clearTimeout(O.current),O.current=null)},C=(k,B)=>{const z=t.current,re=z.getSelection();re.ranges.some(Te=>Vt(Te,k))||z.setSelection(ar(re,k,{extend:!1,append:!1})),z.onContextMenuSelect(k,B)},A=(k,B)=>{const z=t.current;if(!z.isAnyDragging()){if(z.isEditing()&&!z.requestCommit()){z.focusSink();return}z.focusSink(),C(k,B)}},X=(k,B)=>{rt.didPressStopScrollMotion(k)||(k.preventDefault(),Q.current={pointerId:k.pointerId,cell:B,clientX:k.clientX,clientY:k.clientY,event:k},O.current=window.setTimeout(()=>{O.current=null;const z=Q.current;z!==null&&(Q.current=null,A(z.cell,z.event))},mC))},w=k=>{const B=t.current,z=B.onRequestTouchEdit;if(z===void 0||B.isAnyDragging())return;if(B.getPointing?.()){B.focusSink();return}const re=Dt(B.getSelection().active,k);if(B.isEditing()){if(re||!B.requestCommit()){B.focusSink();return}}else if(re){z(k);return}B.setSelection(ar(B.getSelection(),k,{extend:!1,append:!1})),B.focusSink()},G=k=>{const B=t.current;if(Z.current=null,V(),k.pointerType==="mouse"&&k.button===0&&(h.current=!1,g.current=null,$.current=!1,H.current=null),M.current=x(k.target),!M.current){if(k.pointerType==="mouse"){if(k.preventDefault(),k.button!==0)return;if(B.getPointing?.()){B.focusSink();return}if(B.isEditing()&&!B.requestCommit()){k.stopPropagation(),B.focusSink();return}B.focusSink()}return}if(L.current=k.pointerType,k.pointerType!=="mouse"){if(B.isSortHeaderCell===void 0&&B.onRequestTouchEdit===void 0)return;const Xe=S(k.clientX,k.clientY);if(Xe===null)return;if(B.isSortHeaderCell?.(Xe)===!0){k.preventDefault(),Z.current={pointerId:k.pointerId,pointerType:k.pointerType,cell:Xe,clientX:k.clientX,clientY:k.clientY};return}B.onRequestTouchEdit!==void 0&&X(k,Xe);return}if(k.button!==0){k.preventDefault();return}if((B.pointDragRef===void 0?null:B.pointDragRef.current)?.onPointerDown(k))return;if(B.isEditing()&&!B.requestCommit()){k.preventDefault(),B.focusSink();return}o.current=v.getBoundingClientRect();const re=D(k.clientX,k.clientY);if(re===null)return;if(k.preventDefault(),B.focusSink(),(k.ctrlKey||k.metaKey)&&!k.shiftKey&&B.openHyperlinkAt?.(re)===!0){$.current=!0;return}const ge=B.getSelection();r.current=ge;const Te=k.shiftKey,Pe=k.ctrlKey||k.metaKey,ot=Pe&&!Te&&ge.ranges.some(Xe=>Vt(Xe,re));h.current=ot,g.current=ot?re:null,ot||B.setSelection(ar(ge,re,{extend:Te,append:Pe})),!(Te||Pe||k.altKey)&&B.isSortHeaderCell?.(re)===!0&&(H.current={cell:re,clientX:k.clientX,clientY:k.clientY}),n.current=!0,B.repaintOverlay(),s.current={clientX:k.clientX,clientY:k.clientY},c.current=k.pointerId,a.current=k.buttons;try{v.setPointerCapture(k.pointerId)}catch{c.current=null}const je=ot?re:B.getSelection().anchor;u.current=Xe=>me(je,Xe),K.current=je.col,E.current=je.row,B.autoScroller.stop(),W.current=!1,P.current={clientX:k.clientX,clientY:k.clientY}},te=k=>c.current!==null?k.pointerId===c.current:k.pointerType==="mouse",f=k=>{if(!(n.current&&te(k)))return;s.current={clientX:k.clientX,clientY:k.clientY};const B=H.current;if(B!==null&&Jn(B,k)&&(H.current=null),!W.current&&u.current!==null){const z=Math.abs(k.clientX-P.current.clientX),re=Math.abs(k.clientY-P.current.clientY);Math.max(z,re)>=No&&(W.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:u.current,anchorCol:K.current??void 0,anchorRow:E.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const z=u.current;if(!n.current||z===null)return;const re=t.current,ge=D(s.current.clientX,s.current.clientY);ge!==null&&re.onDragFrame(z(ge))}))},b=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&Jn(B,k)&&(Z.current=null);const z=Q.current;z!==null&&k.pointerId===z.pointerId&&Jn(z,k)&&V(),f(k),n.current&&te(k)&&(a.current&1)!==0&&(k.buttons&1)===0&&Y(k)},R=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&(Z.current=null,!Jn(B,k)&&Ts(S(k.clientX,k.clientY),B.cell)&&t.current.onHeaderSortPress?.(B.cell.col,B.pointerType));const z=Q.current;if(z!==null&&k.pointerId===z.pointerId&&(V(),!Jn(z,k)&&Ts(S(k.clientX,k.clientY),z.cell)&&w(z.cell)),k.button!==0||!(n.current&&te(k)))return;const re=H.current,ge=re!==null&&!Jn(re,k)&&Ts(D(k.clientX,k.clientY),re.cell);Y(k),ge&&t.current.onHeaderSortPress?.(re.cell.col,k.pointerType)},_=k=>{const B=Z.current;B!==null&&k.pointerId===B.pointerId&&(Z.current=null);const z=Q.current;z!==null&&k.pointerId===z.pointerId&&V()},Y=k=>{const B=t.current,z=D(k.clientX,k.clientY);if(z!==null){const re=g.current;h.current&&re!==null?B.setSelection(Wu(B.getSelection(),me(re,z),re)):B.setSelection(Mn(B.getSelection(),z))}j()},U=k=>{!n.current||c.current===null||k.pointerId!==c.current||m()},oe=k=>{const B=t.current;if(!x(k.target))return;if(L.current!=="mouse"){B.onRequestTouchEdit!==void 0&&k.preventDefault();return}if(B.isAnyDragging())return;if(B.isEditing()&&!B.requestCommit()){B.focusSink();return}B.focusSink(),o.current=v.getBoundingClientRect();const z=D(k.clientX,k.clientY);z!==null&&C(z,k)},ce=k=>{const B=t.current;if(!M.current||L.current!=="mouse"||B.getPointing?.()||$.current)return;o.current=v.getBoundingClientRect();const z=D(k.clientX,k.clientY);z!==null&&Dt(B.getSelection().active,z)&&B.onRequestEdit(z,B.caretFromPointEnabled(z)?gC(k.clientX,k.clientY,z):void 0)};return v.addEventListener("pointerdown",G),v.addEventListener("pointermove",b),v.addEventListener("pointerup",R),v.addEventListener("pointercancel",_),v.addEventListener("lostpointercapture",U),v.addEventListener("contextmenu",oe),v.addEventListener("dblclick",ce),()=>{v.removeEventListener("pointerdown",G),v.removeEventListener("pointermove",b),v.removeEventListener("pointerup",R),v.removeEventListener("pointercancel",_),v.removeEventListener("lostpointercapture",U),v.removeEventListener("contextmenu",oe),v.removeEventListener("dblclick",ce),V(),j()}},[d,y,D,j,m]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>h.current?"subtract":"add",abortDrag:m,cancelDrag:j}),[m,j])},CC=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),a=i.useRef(null),u=i.useRef(0),h=i.useRef(null),g=i.useRef(null),L=i.useRef(!1),M=i.useCallback((D,W)=>{const{handleRef:K,rowAxis:E,colAxis:P,zoomRef:j}=t.current;return Us(K.current,o.current,E,P,j.current,D,W)},[]),$=i.useCallback(()=>{const{autoScroller:D,bodyRef:W,onDragFrame:K}=t.current;n.current=!1,r.current=null,h.current=null,g.current=null,L.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),D.stop();const E=W.current;E!==null&&a.current!==null&&E.hasPointerCapture?.(a.current)&&E.releasePointerCapture(a.current),a.current=null,K(null)},[]),H=i.useCallback(()=>{if(!n.current)return;const D=r.current;D!==null&&t.current.restoreSink(D),$()},[$]),Z=i.useCallback(D=>{const W=t.current,K=W.bodyRef.current;if(!W.enabled||K===null||!W.getPointing())return!1;o.current=K.getBoundingClientRect();const E=M(D.clientX,D.clientY);if(E===null)return o.current=null,!1;const P=W.captureSink();if(P===null)return o.current=null,!1;D.preventDefault(),W.focusSink(),r.current=P,g.current=E,W.insertReference(E,"cells"),n.current=!0,s.current={clientX:D.clientX,clientY:D.clientY},l.current={clientX:D.clientX,clientY:D.clientY},a.current=D.pointerId,u.current=D.buttons;try{K.setPointerCapture(D.pointerId)}catch{a.current=null}return h.current=j=>{const m=me(E,j);return t.current.insertReference(m,"cells"),m},W.autoScroller.stop(),L.current=!1,W.onDragFrame(me(E,E)),!0},[M]),{enabled:Q,bodyRef:O}=e;return i.useEffect(()=>{const D=O.current;if(!Q||D===null)return;const W=j=>a.current!==null?j.pointerId===a.current:j.pointerType==="mouse",K=j=>{if(!(n.current&&W(j)))return;s.current={clientX:j.clientX,clientY:j.clientY};const m=h.current,d=g.current;if(!L.current&&m!==null&&d!==null){const y=Math.abs(j.clientX-l.current.clientX),v=Math.abs(j.clientY-l.current.clientY);Math.max(y,v)>=No&&(L.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m,anchorCol:d.col,anchorRow:d.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=h.current;if(!n.current||y===null)return;const v=M(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(y(v))})),(u.current&1)!==0&&(j.buttons&1)===0&&$()},E=j=>{j.button!==0||!(n.current&&W(j))||$()},P=j=>{!n.current||a.current===null||j.pointerId!==a.current||$()};return D.addEventListener("pointermove",K),D.addEventListener("pointerup",E),D.addEventListener("lostpointercapture",P),()=>{D.removeEventListener("pointermove",K),D.removeEventListener("pointerup",E),D.removeEventListener("lostpointercapture",P),$()}},[Q,O,M,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:H,cancelDrag:$,onPointerDown:Z}),[H,$,Z])},yC=Object.freeze({width:0,height:0}),$s=33,bC=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,vC=(e,t,n)=>{const r=(n-t)/($s-1);let o=-1,s=-1;for(let c=0;c<$s;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,a)=>{let u=c,h=a;for(;Math.abs(h-u)>1;){const g=(u+h)/2;e(g)?h=g:u=g}return h};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===$s-1?n:l(t+r*(s+1),t+r*s)}},RC=e=>{if(e===void 0)return!1;if(typeof e!="object"||e===null)throw new RangeError(`[spreadsheet] setSelection: the options must be an object (got ${String(e)})`);const{scroll:t}=e;if(t!==void 0&&t!==!0&&t!==!1)throw new RangeError(`[spreadsheet] setSelection: options.scroll must be true, false or absent (got ${String(t)})`);return t===!0},SC=(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})`)},EC=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)})`)},kC=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)})`)},OC=Object.freeze({showArrowButtons:!0,enableThumbDrag:!0,enableTrackClick:!0}),xC=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(OC)){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)})`)}}},Yc=(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},AC=24,TC=200,Uu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Xc=5,$C=/^#[0-9A-Fa-f]{6}$/,MC=Object.freeze({row:!1,column:!1,intersection:!1}),Uc=Object.freeze({ok:!0}),Gc=(e,t)=>{if(t===void 0)return Uu;if(t.length!==Xc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Xc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!$C.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},LC=e=>{for(const t of["row","column","intersection"])if(lt(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},zC=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return vu},NC=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},DC=e=>{const t=i.useRef(null),n=t.current;return n!==null&&rt.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Zn={ranges:[me({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},FC=i.forwardRef(function({adapter:t,headerRows:n=0,sortFilter:r,readOnly:o=!1,labelledBy:s,defaultRowHeight:l=AC,defaultColumnWidth:c=Fe.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:a=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:g=0,tapScrollCircleOptions:L,scrollBarControls:M,overscanRows:$,overscanCols:H,background:Z,onRenderTruncated:Q,renderCell:O,onSelectionChange:D,onEditSessionChange:W,onCellContextMenu:K,onUndoRequest:E,onRedoRequest:P,onCopyMultiRange:j,onOperationRejected:m,onEditRejected:d,onReadOnlyRejected:y,formatReadOnlyAnnouncement:v,dataVersion:x,maxOperationCells:S=Fe.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:V=!0,enableResizeUI:C=!0,touchEditing:A=!1,headings:X=!0,onContentSizeChange:w,frame:G,formatCellAnnouncement:te,formatSelectionAnnouncement:f,formatCommandAnnouncement:b,formatResizeAnnouncement:R,locale:_,labels:Y,shortcuts:U,onCommandBlockedWhileEditing:oe,colors:ce,formats:k,highlight:B,defaultHighlight:z,onHighlightChange:re,highlightColors:ge,popovers:Te,renderPopover:Pe,onClipChange:ot,onHyperlinkOpen:je,onValidationRejected:Xe,onPasteSpecialRequest:Oe,onClipboardUnavailable:Ie,onPasteResolved:Be,now:Et=Date.now,zoom:it,defaultZoom:on,onZoomChange:Ze,testId:kt,className:Rn,__onCellRender:Io,__onVirtualKeyboardRaise:Sn,__maxRenderedCells:Ft},Wr){const ae=i.useMemo(()=>o?vm(t):t,[t,o]),ye=Lc(ae.rowCount,l),ve=Lc(ae.colCount,c),Fn=i.useRef(null);Fn.current===null&&(Fn.current=Z0());const ze=Fn.current,qn=rt.resolveVirtualScrollLocale(_),Qe=i.useMemo(()=>au(_,Y),[_,Y]),sn=DC(Jm(Qe)),Wt=i.useMemo(()=>Bm(U),[U]),Pn=i.useMemo(()=>{if(!C)return;const N=[...Wt].filter(([,ee])=>ys.includes(ee)).sort(([,ee],[,se])=>ys.indexOf(ee)-ys.indexOf(se)).map(([ee])=>qm(ee)).filter(ee=>ee!==null);return N.length===0?void 0:N.join(" ")},[Wt,C]),_n=i.useMemo(()=>({fill:Gc("fill",ce===void 0?void 0:ce.fill),font:Gc("font",ce===void 0?void 0:ce.font)}),[ce]),pr=i.useMemo(()=>ge===void 0?void 0:LC(ge),[ge]);if(ae.getConditionalFormats!==void 0&&ae.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");SC(n,u),EC(s),kC(G),xC(M);const hr=i.useCallback(()=>ze.get().editVersion,[ze]),mr=i.useCallback(p=>ze.subscribeCoalesced(p),[ze]),Ho=i.useSyncExternalStore(mr,hr,hr)+(x===void 0?0:x),gr=ae.getConditionalFormats===void 0?null:ae.getConditionalFormats(),jn=i.useMemo(()=>({index:gr===null?null:_u(gr),memo:hl()}),[ae,gr,Ho]),wr=i.useRef(jn.index);wr.current=jn.index;const ln=i.useRef(jn.memo);ln.current=jn.memo;const cn=i.useCallback((p,N,ee)=>ml(ae,wr.current,ln.current,p,N,ee),[ae]),Ve=i.useRef(null),[T,F]=i.useState(()=>Fe.clampSpreadsheetZoom(on??1)),J=Fe.clampSpreadsheetZoom(it??T),q=i.useRef(J);q.current=J;const ne=i.useRef(J);ne.current=J;const ie=i.useRef(null),fe=i.useRef(Ze);fe.current=Ze;const Ne=i.useRef(it!==void 0);Ne.current=it!==void 0;const $e=i.useCallback(p=>{const N=Fe.clampSpreadsheetZoom(p);N!==ne.current&&(ne.current=N,Ne.current||F(N),fe.current?.(N))},[]),ue=ae.rowCount===0||ae.colCount===0,We=!ue,Ke=ae.colCount,Ae=i.useMemo(()=>r===void 0||ue?null:p0(r,Ke,n),[r,ue,Ke,n]),we=i.useRef(r);we.current=r;const de=i.useRef(Ae);de.current=Ae,i.useEffect(()=>{const p=Ve.current;if(!We||p===null)return;const N=se=>{se.defaultPrevented||!se.altKey||se.ctrlKey||se.metaKey||se.shiftKey||se.deltaY!==0&&(se.preventDefault(),se.stopPropagation(),!ie.current?.()&&$e(Fe.stepSpreadsheetZoom(ne.current,se.deltaY<0?1:-1)))},ee=se=>{if(se.defaultPrevented||!(se.ctrlKey&&se.altKey)||se.metaKey||se.getModifierState("AltGraph"))return;const Ce=se.key==="="||se.key==="+"?Fe.stepSpreadsheetZoom(ne.current,1):se.key==="-"?Fe.stepSpreadsheetZoom(ne.current,-1):se.key==="0"?1:null;Ce!==null&&(se.preventDefault(),se.stopPropagation(),!ie.current?.()&&$e(Ce))};return p.addEventListener("wheel",N,{passive:!1,capture:!0}),p.addEventListener("keydown",ee,!0),()=>{p.removeEventListener("wheel",N,{capture:!0}),p.removeEventListener("keydown",ee,!0)}},[$e,We]);const pe=i.useRef(null),Re=i.useRef(null),Se=i.useRef(null),ct=i.useRef(null),le=i.useRef(null),Me=i.useRef(null),mt=i.useRef(null),at=i.useRef(0),ut=i.useRef(null),Le=i.useRef(0),dt=i.useRef(null),Kt=i.useRef(null),gt=i.useRef(null),Ye=i.useRef(null),qt=i.useRef(null),In=i.useRef(null),Kr=i.useRef(null),[En,Bo]=i.useState(Zn),Pt=i.useRef(En),Yt=i.useCallback(()=>Pt.current,[]),[Gu,Ju]=i.useState(()=>z===void 0?MC:z),Hn=B!==void 0?B:Gu,Vo=i.useRef(Hn);Vo.current=Hn;const Zu=zC(pr,Hn),yl=i.useRef(B!==void 0);yl.current=B!==void 0;const bl=i.useRef(re);bl.current=re;const Qu=i.useCallback(p=>{yl.current||Ju(p),bl.current?.(p)},[]),vl=i.useRef(null),Wo=i.useRef(null),Xt=i.useRef(null),Ko=i.useRef(()=>!1),Rl=i.useRef(()=>{}),Sl=i.useRef(()=>null),El=i.useRef(()=>{}),kn=i.useCallback(()=>Ko.current(),[]),Yo=i.useMemo(()=>({getPointing:()=>Ko.current(),insertReference:(p,N)=>Rl.current(p,N)}),[]),kl=i.useRef(Qt),Ol=i.useRef(null),Xo=i.useRef({interactive:null,tip:null}),xl=i.useRef(null),Al=i.useRef(null),Yr=i.useRef(()=>{}),Tl=i.useRef(()=>!1),wt=i.useRef(null),Cr=i.useCallback(()=>{const p=wt.current;if(p===null||p.isOpen()!=="message")return!1;const N=p.context;return N===null||N.kind!=="message"||!N.current.rejected?!1:(p.close(),!0)},[]),Uo=i.useRef(()=>!1),$l=i.useRef(()=>!1),Ml=i.useRef(null),Go=i.useRef(()=>Promise.resolve("rejected")),De=i.useCallback(()=>{vl.current?.()},[]),Ot=i.useCallback(p=>{Me.current?.focus(p)},[]),Ue=i.useCallback(()=>{Ot({preventScroll:!0})},[Ot]),Jo=i.useRef(!1),ed=i.useCallback(()=>{const p=Ve.current;if(p!==null){Jo.current=!0;try{p.focus()}finally{Jo.current=!1}}},[]),ft=i.useCallback(()=>{const p=Me.current;p!==null&&(p.value=" ",p.setSelectionRange(0,1))},[]),Bn=i.useCallback((p,N)=>{if(p===null)return;const ee=N?"":"none";p.style.display!==ee&&(p.style.display=ee)},[]),xt=i.useCallback(()=>{const p=mt.current;if(p!==null){const ee=Math.max(0,le.current?.getScrollPosition().y??0),se=le.current?.getFrozenSize().height??0;p.style.transform=`translateY(${at.current-ee-se}px)`}const N=le.current;if(N!==null&&(qt.current!==null||In.current!==null)){const ee=N.getFrozenSize();Bn(qt.current,ee.height>0),Bn(In.current,ee.trailingHeight>0)}},[Bn]),At=i.useCallback(()=>{const p=ut.current;if(p!==null){const ee=Math.max(0,le.current?.getScrollPosition().x??0),se=le.current?.getFrozenSize().width??0;p.style.transform=`translateX(${Le.current-ee-se}px)`}const N=le.current;if(N!==null&&(gt.current!==null||Ye.current!==null)){const ee=N.getFrozenSize();Bn(gt.current,ee.width>0),Bn(Ye.current,ee.trailingWidth>0)}},[Bn]),yr=i.useRef(null),Vn=i.useCallback(()=>{gt.current===null&&Ye.current===null&&qt.current===null&&In.current===null||yr.current===null&&(yr.current=requestAnimationFrame(()=>{yr.current=null,xt(),At(),De()}))},[xt,At,De]);i.useEffect(()=>()=>{yr.current!==null&&cancelAnimationFrame(yr.current)},[]);const Zo=i.useRef(null),Qo=i.useRef(null);(Zo.current===null||Qo.current?.rowAxis!==ye||Qo.current?.colAxis!==ve)&&(Qo.current={rowAxis:ye,colAxis:ve},Zo.current=W0({handleRef:le,rowAxis:ye,colAxis:ve}));const Xr=i.useCallback(p=>{const N=le.current,ee=N===null?{x:0,y:0}:N.getScrollPosition(),se=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),Ce=N===null?{width:0,height:0}:N.getViewportSize(),ke=q.current;return{top:Dn(ye,p.row,{scroll:Math.max(0,ee.y),frozenCount:se.rows,trailingCount:se.trailingRows,extent:Ce.height})*ke,left:Nn(ve,p.col,{scroll:Math.max(0,ee.x),frozenCount:se.cols,trailingCount:se.trailingCols,extent:Ce.width})*ke,width:ve.sizeOf(p.col)*ke,height:ye.sizeOf(p.row)*ke}},[ye,ve]),Ll=i.useCallback(p=>{const N=ct.current,ee=Ve.current,se=Re.current;if(N===null||ee===null||se===null||le.current===null)return;const Ce=q.current,ke=Xr(p),tt=se.offsetTop*Ce+ke.top,ht=se.offsetLeft*Ce+ke.left,Je=Math.max(0,tt),Ht=Math.max(0,ht),dn=Math.min(ee.clientHeight,tt+ke.height),to=Math.min(ee.clientWidth,ht+ke.width);if(dn<=Je||to<=Ht)return;N.style.top=`${Je}px`,N.style.left=`${Ht}px`,N.style.width=`${to-Ht}px`,N.style.height=`${dn-Je}px`;const Xn=N.getBoundingClientRect();Xn.width===0&&Xn.height===0||N.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Xr]),_t=i.useCallback(p=>{Zo.current?.(p),Ll(p)},[Ll]),td=i.useCallback(()=>{const p=le.current,N=p===null?-1:p.getViewportSize().height,ee=pe.current,se=Ve.current;if(N<=0||ee===null||se===null)return N;const Ce=ee.getBoundingClientRect(),ke=se.getRootNode();if(Ce.height<=0||ee.offsetHeight<=0||!bC(ke))return N;const tt=se.ownerDocument.documentElement,ht=Math.max(Ce.left,0),Je=Math.min(Ce.right,tt.clientWidth),Ht=Math.max(Ce.top,0)+.5,dn=Math.min(Ce.bottom,tt.clientHeight)-.5,to=(ht+Je)/2,Xn=Je>ht&&dn>=Ht?vC(qd=>{const wi=ke.elementFromPoint(to,qd);return wi!==null&&se.contains(wi)},Ht,dn):null,Fd=Xn===null?tt.clientHeight:Xn.bottom-Xn.top+1;return Math.min(N,Fd*(ee.offsetHeight/Ce.height))},[]),zl=i.useRef(w);zl.current=w;const es=i.useRef(null),Ut=i.useCallback(()=>{const p=zl.current;if(p===void 0)return;const N=Re.current;let ee;if(N===null)ee=yC;else{if(N.getClientRects().length===0)return;{const Ce=Se.current,ke=q.current;ee={width:((Ce===null?0:Ce.offsetWidth)+ve.totalSize()+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke,height:((Ce===null?0:Ce.offsetHeight)+ye.totalSize()+Fe.SPREADSHEET_SCROLLBAR_SIZE_PX)*ke}}}const se=es.current;se!==null&&se.width===ee.width&&se.height===ee.height||(es.current=ee,p(ee))},[ye,ve]);i.useLayoutEffect(()=>{if(w===void 0){es.current=null;return}Ut()});const Nl=w!==void 0;i.useEffect(()=>{const p=Re.current;if(!Nl||p===null)return;const N=new ResizeObserver(()=>Ut());return N.observe(p),()=>N.disconnect()},[Nl,Ut,ue]);const Wn=i.useRef(null),On=i.useRef(null),Kn=i.useCallback(p=>{Wn.current!==null&&window.clearTimeout(Wn.current),On.current!==null&&(cancelAnimationFrame(On.current),On.current=null),Wn.current=window.setTimeout(()=>{Wn.current=null;const N=Kr.current;N!==null&&(N.textContent="",On.current=requestAnimationFrame(()=>{On.current=null,N.textContent=p}))},TC)},[]);i.useEffect(()=>()=>{Wn.current!==null&&window.clearTimeout(Wn.current),On.current!==null&&cancelAnimationFrame(On.current)},[]);const Yn=i.useCallback(p=>{y?.(p),v!==void 0&&Kn(v(p))},[y,v,Kn]),Dl=i.useCallback((p,N)=>{if(te===void 0&&f===void 0)return;const ee=N.ranges[N.ranges.length-1],se=St(ee),Ce=N.ranges.length===1&&se.rows===1&&se.cols===1,ke=p.ranges[p.ranges.length-1],tt=p.ranges.length!==N.ranges.length||ke.startRow!==ee.startRow||ke.startCol!==ee.startCol||ke.endRow!==ee.endRow||ke.endCol!==ee.endCol,ht=()=>{if(te!==void 0){const Je=N.active,Ht=ae.getCellText(Je.row,Je.col),dn=ae.getCellFormat===void 0?void 0:cn(Je.row,Je.col,()=>Ht);Kn(te({row:Je.row,col:Je.col,text:Ht,displayText:Ln(Ht,dn===void 0?void 0:dn.value),columnName:Fe.columnIndexToName(Je.col),...Qa(ae)?{readOnly:nt(ae,Je.row,Je.col)}:{}}))}};if(Ce){ht();return}if(tt){f!==void 0&&Kn(f({range:ee,anchor:N.anchor,active:N.active,rangeRowCount:se.rows,rangeColCount:se.cols,rangeCount:N.ranges.length}));return}ht()},[ae,te,f,Kn,cn]),an=i.useCallback((p,N)=>{const ee=Pt.current;Object.is(p,ee)||j0(p,ee)||(Pt.current=p,Bo(p),D?.(p,N),Dl(ee,p),(Xt.current?.()??!1)||ft())},[D,Dl,ft]),Tt=i.useCallback(p=>an(p,"user"),[an]),nd=i.useCallback(p=>{const N=Pt.current;if(p.mode==="cycle"){const se=Ku(N,p.direction);Tt(se),_t(se.active);return}const ee=vn(p.cell,ye.count,ve.count);if(p.mode==="extend"){Tt(Mn(N,ee)),_t(ee);return}Tt(ar(N,ee,{extend:!1,append:!1})),_t(ee)},[Tt,_t,ye,ve]),Ge=i.useCallback(()=>Xt.current?.()??!1,[]),Fl=i.useRef(null),et=i.useCallback(()=>Fl.current?.()??!0,[]),ql=i.useRef(null),br=i.useCallback((p,N)=>{const ee=Xt.current?.()??!1;ql.current?.(p,N),!ee&&(Xt.current?.()??!1)&&Cr()},[Cr]),[rd,ts]=i.useState(!1),Ur=i.useCallback(()=>{Sn?.(),ts(!0)},[Sn]),ns=rd&&!ue?Vc(En,ae.rowCount,ae.colCount).active:null,od=ns===null?"none":ym(ae,ns.row,ns.col),Pl=i.useCallback(()=>{Ve.current?.focus({preventScroll:!0})},[]),Gr=i.useCallback((p,N,ee)=>{nt(ae,p.row,p.col)||ee(),br("edit",N)},[ae,br]),sd=i.useCallback((p,N)=>{Gr(p,N,Ur)},[Gr,Ur]),_l=i.useCallback(()=>{Pd.flushSync(Ur),Pl()},[Ur,Pl]),ld=i.useCallback(p=>{Gr(p,void 0,_l)},[Gr,_l]),jl=i.useRef(null),Jr=i.useCallback(()=>jl.current?.()??null,[]),Il=i.useRef(null),Ct=i.useCallback(()=>{Il.current?.()},[]),Hl=i.useRef(null),Bl=i.useCallback(p=>{Hl.current?.(p)},[]),Vl=i.useRef(()=>{}),Zr=i.useCallback(p=>{const N=we.current;return N===void 0||!et()?!1:(wt.current?.hideTip(),wt.current?.close(),Ct(),v0(N.state,p)||N.onStateChange(p),!0)},[et,Ct]),id=i.useCallback((p,N)=>{const ee=we.current,se=de.current,Ce=se===null?null:cr(se,p);ee!==void 0&&Ce?.sortable===!0&&Zr(m0(ee.state,Ce.key)),N!=="mouse"&&Ot({preventScroll:!0})},[Zr,Ot]),Wl=i.useCallback(p=>{const N=wt.current,ee=de.current;if(N===null||ee===null)return;const se=N.context;if(se!==null&&se.kind==="columnMenu"&&se.cell.col===p){N.close();return}N.openColumnMenu({row:ee.headerRow,col:p})},[]),Kl=i.useCallback(p=>{const N=ae.getCellText(p.row,p.col);return Bu(ae.getCellFormat===void 0?N:Ln(N,ae.getCellFormat(p.row,p.col)?.value))},[ae]),Yl=i.useCallback(p=>Ve.current?.contains(p)===!0,[]),cd=i.useMemo(()=>{if(Ae===null||!Ae.columns.some(N=>N?.sortable===!0))return;const p=Ae;return N=>N.row===p.headerRow&&p.columns[N.col]?.sortable===!0},[Ae]),rs=i.useMemo(()=>{if(Ae===null||!Ae.hasControls)return;const p=Ae;return N=>N.row===p.headerRow?cr(p,N.col):null},[Ae]),Qr=i.useRef(0),xn=i.useCallback((p,N,ee)=>{let se;if(N.source==="paste"){const Ce=NC(ee);if(p.length===0&&Ce.conditionalFormats.length===0)return null;Qr.current+=1,se={transaction:Qr.current,source:"paste",sameSheet:Ce.sameSheet,conditionalFormats:Ce.conditionalFormats}}else{if(p.length===0)return null;Qr.current+=1,se={transaction:Qr.current,source:N.source}}try{ae.applyEdits(p,se)}catch(Ce){return d?.(Ce,N),null}return ze.bumpEdit(),Bl(N.source),se.transaction},[ae,ze,d,Bl]),ad=i.useCallback((p,N)=>xn(p,{source:"paste"},N),[xn]),ud=i.useCallback(p=>{ze.setVy(p.y),xt(),At(),De()},[ze,xt,At,De]),Xl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),dd=i.useCallback(p=>{ze.setRowRange(p.renderingRowStart,p.renderingRowEnd),ze.setColRange(p.renderingColStart,p.renderingColEnd);const N=Xl.current;(N.rowStart!==p.renderingRowStart||N.rowEnd!==p.renderingRowEnd||N.colStart!==p.renderingColStart||N.colEnd!==p.renderingColEnd)&&(Xl.current={rowStart:p.renderingRowStart,rowEnd:p.renderingRowEnd,colStart:p.renderingColStart,colEnd:p.renderingColEnd},De())},[ze,De]),Ul=i.useRef(()=>"add"),un=i.useCallback(p=>{Wo.current?.(p,Ul.current())},[]),fd=i.useCallback(p=>{Wo.current?.(p,"point")},[]),Gl=i.useRef(null),os=i.useCallback(p=>{Gl.current?.(p)},[]),Jl=i.useRef(null),pd=i.useCallback(p=>{Jl.current?.(p)},[]),Zl=i.useRef(null),Ql=i.useCallback((p,N)=>{if(N.length===0)return;const ee=le.current;if(p==="col"){for(const se of N){const Ce=Math.round(se.size);ve.resize(se.index,Ce),ee?.updateColSize(se.index,Ce)}ze.bumpColVersion(),At(),De(),Vn(),Ut();return}for(const se of N){const Ce=Math.round(se.size);ye.resize(se.index,Ce),ee?.updateRowSize(se.index,Ce)}ze.bumpRowGeometry(),xt(),De(),Vn(),Ut()},[ye,ve,ze,At,xt,De,Vn,Ut]),ei=C?Ql:void 0,hd=i.useCallback((p,N)=>{K?.(p,{kind:"pointer",event:N})},[K]),md=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"both",zoomRef:q}),gd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"x",zoomRef:q}),wd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"y",zoomRef:q}),Cd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:os,axis:"x",zoomRef:q}),yd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:os,axis:"y",zoomRef:q}),bd=Gn({handleRef:le,rowAxis:ye,colAxis:ve,bodyRef:pe,onDragFrame:un,axis:"both",zoomRef:q}),ti=i.useRef(null),ni=i.useRef(()=>!1),vr=i.useCallback(()=>ni.current(),[]),$t=wC({zoomRef:q,enabled:!ue,rowAxis:ye,colAxis:ve,handleRef:le,bodyRef:pe,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,onContextMenuSelect:hd,onRequestEdit:sd,caretFromPointEnabled:p=>{if(O!==void 0||ae.getCellFormula!==void 0&&ae.getCellFormula(p.row,p.col)!==void 0)return!1;if(ae.getCellFormat===void 0)return!0;const N=ae.getCellText(p.row,p.col);return Ln(N,ae.getCellFormat(p.row,p.col)?.value)===N},isAnyDragging:vr,autoScroller:md,repaintOverlay:De,pointDragRef:ti,getPointing:kn,openHyperlinkAt:je===void 0||ae.getCellHyperlink===void 0?void 0:p=>{const N=ae.getCellHyperlink===void 0?void 0:fr(ae.getCellHyperlink(p.row,p.col));return N===void 0?!1:(je(N,p),!0)},isSortHeaderCell:cd,onHeaderSortPress:id,onRequestTouchEdit:A?ld:void 0}),jt=Kc({zoomRef:q,enabled:!ue&&X,axis:"col",headerRef:dt,mainAxis:ve,crossCount:ae.rowCount,handleRef:le,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,autoScroller:gd,repaintOverlay:De,pointing:Yo}),It=Kc({zoomRef:q,enabled:!ue&&X,axis:"row",headerRef:Kt,mainAxis:ye,crossCount:ae.colCount,handleRef:le,isEditing:Ge,requestCommit:et,getSelection:Yt,setSelection:Tt,focusSink:Ue,onDragFrame:un,autoScroller:wd,repaintOverlay:De,pointing:Yo}),pt=_0({zoomRef:q,enabled:!ue&&C&&X,colBandRef:dt,rowBandRef:Kt,fontSourceRef:pe,colAxis:ve,rowAxis:ye,viewStore:ze,handleRef:le,isEditing:Ge,requestCommit:et,focusSink:Ue,getSelection:Yt,adapter:ae,autofitEnabled:O===void 0,headerRows:n,defaultRowHeight:l,defaultColumnWidth:c,maxOperationCells:S,onOperationRejected:m,resizeTracks:Ql,writeResizeGuide:pd,repaintOverlay:De,isPointing:kn}),Mt=tC({zoomRef:q,enabled:!ue&&V,handleNodeRef:Zl,bodyRef:pe,rowAxis:ye,colAxis:ve,handleRef:le,getSelection:Yt,setSelection:Tt,focusSink:Ue,adapter:ae,commitEdits:xn,maxOperationCells:S,onOperationRejected:m,rejectReadOnly:Yn,writeFillPreview:os,repaintOverlay:De,xAutoScroller:Cd,yAutoScroller:yd}),yt=CC({zoomRef:q,enabled:!ue,bodyRef:pe,handleRef:le,rowAxis:ye,colAxis:ve,getPointing:kn,insertReference:Yo.insertReference,captureSink:()=>Sl.current(),restoreSink:p=>El.current(p),focusSink:Ue,autoScroller:bd,onDragFrame:un});ti.current=yt;const Rr=i.useCallback(()=>$t.isDragging()||jt.isDragging()||It.isDragging()||pt.isDragging()||Mt.isDragging()||yt.isDragging(),[$t,jt,It,pt,Mt,yt]);ie.current=Rr,ni.current=Rr,Ul.current=()=>yt.isDragging()?"point":$t.getDragMode();const vd=i.useCallback(()=>{$t.abortDrag(),jt.abortDrag(),It.abortDrag(),pt.abortDrag(),Mt.abortDrag(),yt.abortDrag()},[$t,jt,It,pt,Mt,yt]),ss=i.useCallback(()=>Pt.current.active,[]),ri=i.useCallback((p,N)=>{const ee=ae.getCellValidation===void 0?void 0:ae.getCellValidation(p.row,p.col);if(ee===void 0)return Uc;const se=ae.evaluateFormula,Ce=fu(ee,N,qn,se===void 0?void 0:ke=>se(ke,p));return Ce.ok||ee.strict!==!0?Uc:(Xe?.({cell:p,rule:ee,text:N,message:Ce.message}),wt.current?.isKindEnabled("message")&&Yr.current("message",{message:Ce.message,rejected:!0}),Ce)},[ae,Xe,qn]),He=Dw({enabled:!ue,sinkRef:Me,rootRef:Ve,adapter:ae,commitEdits:xn,getActive:ss,ensureCellVisible:_t,focusSink:Ot,rearmSink:ft,discardClip:Ct,isDragging:vr,rejectReadOnly:Yn,resolveEditAlign:p=>{if(ae.getCellFormat===void 0)return null;const N=Eo(ae,p.row,p.col);return Za(cn(p.row,p.col,N),N)},resolveEditPaint:p=>ae.getCellFormat===void 0?null:gp(cn(p.row,p.col,Eo(ae,p.row,p.col))),editPaintRef:kl,repaintOverlay:De,validateCommit:ri,onSessionChange:W});Xt.current=He.isEditing,Fl.current=He.requestCommit,ql.current=He.startEdit,Ko.current=He.getPointing,Rl.current=He.insertReference,Sl.current=He.captureSink,El.current=He.restoreSink;const oi=i.useCallback(()=>{He.cancelEdit(),Cr()},[He.cancelEdit,Cr]),Sr=mw({enabled:!ue,sinkRef:Me,adapter:ae,isEditing:Ge,getSelection:Yt,setSelection:Tt,commitPaste:ad,maxOperationCells:S,onOperationRejected:m,onCopyMultiRange:j,repaintOverlay:De,isDragging:vr,resize:{rowAxis:ye,colAxis:ve,resizeTracks:ei},pendingPasteOptionsRef:Ol,formats:k,onClipChange:ot,onClipboardUnavailable:Ie,onEditRejected:d,rejectReadOnly:Yn,onPasteResolved:Be});jl.current=Sr.getClip,Il.current=Sr.discardClip,Hl.current=Sr.discardClipOnCommit,Vl.current=Sr.onAdapterSwitch,Go.current=Sr.paste;const Gt=pC({enabled:!ue,adapter:ae,popovers:Te,sinkRef:Me,bodyRef:pe,handleRef:le,rowAxis:ye,colAxis:ve,zoomRef:q,getActive:ss,isEditing:Ge,requestCommit:et,focusSink:Ot,rearmSink:ft,isDraggingAny:Rr,commitEdits:xn,labels:Qe,onHyperlinkOpen:je,anchors:Xo,repaintOverlay:De,rejectReadOnly:Yn,columnMenuAt:rs});wt.current=Gt,Yr.current=Gt.open,Tl.current=Gt.hideTip;const Rd=i.useCallback(()=>{const p=Pt.current.active;return _t(p),Xr(p)},[_t,Xr]),ls=Lw({adapter:ae,trackResize:C&&!ue?pt:void 0,getSelection:Yt,commitEdits:xn,getActive:ss,isEditing:Ge,requestCommit:et,cancelEdit:oi,getSessionText:He.getSessionText,validateCommit:ri,insertAtCaret:He.insertAtCaret,refreshEditPaint:He.refreshPaint,maxOperationCells:S,onOperationRejected:m,colors:_n,formats:k,getHighlight:()=>Vo.current,setHighlight:Qu,popovers:Te,openPopover:p=>Yr.current(p),onHyperlinkOpen:je,onPasteSpecialRequest:Oe,paste:p=>Go.current(p),rowAxis:ye,colAxis:ve,resizeTracks:ei,defaultRowHeight:l,defaultColumnWidth:c,now:Et,announce:Kn,formatCommandAnnouncement:b,formatResizeAnnouncement:R,keyboardCellRect:Rd,rejectReadOnly:Yn,columnMenu:rs===void 0?void 0:{isColumnMenuCell:p=>rs(p)!==null,open:Gt.openColumnMenu}});Ml.current=ls,Uo.current=ls.executeCommand,$l.current=ls.isCommandAvailable;const Sd=i.useMemo(()=>({table:Wt,execute:p=>Uo.current(p),isAvailable:p=>$l.current(p)}),[Wt]),Ed=i.useCallback(()=>{Ct(),E?.()},[Ct,E]),kd=i.useCallback(()=>{Ct(),P?.()},[Ct,P]);J0({zoomRef:q,enabled:!ue,sinkRef:Me,rootRef:Ve,handOffFocusToRoot:ed,getSelection:Yt,setSelection:Tt,moveActive:nd,ensureCellVisible:_t,pageExtent:td,isEditing:Ge,requestCommit:et,startEdit:br,commitEdits:xn,maxOperationCells:S,onOperationRejected:m,rejectReadOnly:Yn,getClip:Jr,discardClip:Ct,isDragging:Rr,abortDrag:vd,findDataEdge:ae.findDataEdge,getEditingMode:He.getEditingMode,cancelEdit:oi,onUndoRequest:Ed,onRedoRequest:kd,onCellContextMenu:K,rowAxis:ye,colAxis:ve,handleRef:le,rearmSink:ft,commands:Sd,onCommandBlockedWhileEditing:oe,pointing:He,adapter:ae,hideNoteTip:()=>Tl.current(),closeRejectedMessage:Cr,pendingPasteOptionsRef:Ol,onPointFrame:fd});const si=Ae?.hasControls===!0,li=Gt.context!==null&&Gt.context.kind==="columnMenu"?Gt.context.cell.col:null,Od=i.useMemo(()=>si?{openCol:li,menuLabel:Qe.columnMenu,filteredLabel:Qe.columnMenuFiltered,onToggle:Wl}:null,[si,li,Qe.columnMenu,Qe.columnMenuFiltered,Wl]),xd=i.useMemo(()=>r===void 0||Ae===null||!Ae.hasControls?null:{resolved:Ae,state:r.state,getFilterValues:r.getFilterValues,changeState:Zr,columnNameOf:Kl,isInsideGrid:Yl},[r,Ae,Zr,Kl,Yl]);i.useLayoutEffect(()=>{const p=wt.current,N=p===null?null:p.context;if(p===null||N===null||N.kind!=="columnMenu")return;const ee=Ae===null||N.cell.row!==Ae.headerRow?null:cr(Ae,N.cell.col);(ee===null||!h0(ee,N.column))&&p.closeColumnMenu({restoreFocus:Ve.current?.contains(document.activeElement)===!0})},[Ae]);const Ad=En.active.row,Td=En.active.col;i.useLayoutEffect(()=>{const p=wt.current;p!==null&&(p.syncTipAriaDescribedBy(),p.isKindEnabled("message")&&(p.isOpen()==="message"&&p.close(),p.open("message")))},[Ad,Td]),i.useLayoutEffect(()=>{De()},[De,Hn.row,Hn.column,Hn.intersection]),i.useLayoutEffect(()=>{De()},[De,G?.startRow,G?.startCol,G?.endRow,G?.endCol]);const $d=i.useCallback(p=>{(Xt.current?.()??!1)||(p.preventDefault(),Ue(),ft())},[Ue,ft]),Md=i.useCallback(p=>{const N=Ve.current,ee=p.relatedTarget,se=N!==null&&!N.matches(":focus-visible");if(N!==null&&ee instanceof Node&&N.contains(ee)){p.target===N&&ee===Me.current&&!Jo.current&&Ot({preventScroll:se});return}(Xt.current?.()??!1)||(Ot({preventScroll:se}),ft())},[Ot,ft]),Ld=i.useCallback(p=>{const N=Ve.current,ee=p.relatedTarget;N!==null&&ee instanceof Node&&N.contains(ee)||He.isFocusoutSuppressed()||ts(!1)},[He]),eo=i.useRef(null),Er=i.useCallback(()=>{const p=eo.current;p!==null&&(eo.current=null,window.removeEventListener("pointerup",p.up,!0),window.removeEventListener("pointercancel",p.cancel,!0))},[]),is=i.useCallback(()=>{if(eo.current!==null)return;const p=ee=>{ee.pointerType==="mouse"&&(Er(),ee.button===1&&ee.preventDefault())},N=ee=>{ee.pointerType==="mouse"&&Er()};eo.current={up:p,cancel:N},window.addEventListener("pointerup",p,!0),window.addEventListener("pointercancel",N,!0)},[Er]);i.useEffect(()=>Er,[Er]),i.useEffect(()=>{const p=Ve.current;if(ue||p===null)return;let N=0;const ee=ke=>{if(ke.pointerType!=="mouse"){(Xt.current?.()??!1)||ts(!1);return}N=ke.buttons,ke.button===1&&(ke.target===Me.current&&(Xt.current?.()??!1)||is())},se=ke=>{ke.pointerType==="mouse"&&(N=ke.buttons)},Ce=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===N)return;const tt=ke.buttons&~N;N=ke.buttons,ke.preventDefault(),(tt&4)!==0&&is()};return p.addEventListener("pointerdown",ee,!0),p.addEventListener("pointerup",se,!0),p.addEventListener("pointermove",Ce,!0),()=>{p.removeEventListener("pointerdown",ee,!0),p.removeEventListener("pointerup",se,!0),p.removeEventListener("pointermove",Ce,!0)}},[ue,is]);const zd=i.useCallback(p=>{if(!(p.target!==p.currentTarget||p.pointerType!=="mouse")&&(p.preventDefault(),p.button===0)){if(kn()){Ue();return}if(Ge()&&!et()){Ue();return}Ue()}},[Ue,Ge,et,kn]),cs=i.useRef(!1);i.useLayoutEffect(()=>{if(ue){cs.current=!1;return}if(cs.current)return;cs.current=!0,ft();const p=(Ve.current?.clientHeight??0)/q.current;p>0&&ye.totalSize()>0&&ze.setRowRange(0,ye.indexAt(Math.min(p-1,ye.totalSize()-1)));const N=(Ve.current?.clientWidth??0)/q.current;N>0&&ve.totalSize()>0&&ze.setColRange(0,ve.indexAt(Math.min(N-1,ve.totalSize()-1)))},[ue,ft,ze,ye,ve]);const ii=i.useRef(t);i.useLayoutEffect(()=>{ii.current!==t&&(ii.current=t,$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag(),He.cancelEdit(),wt.current?.hideTip(),wt.current?.close(),ue?(Pt.current=Zn,Bo(Zn)):an(Zn,"sheetSwitch"),Vl.current())},[t,ue,an,$t,jt,It,pt,Mt,yt,ze,He.cancelEdit]);const ci=i.useRef({adapter:ae,rows:ye.count,cols:ve.count}),{getSessionCell:ai,getSession:ui,cancelEdit:di}=He;i.useLayoutEffect(()=>{const p=ci.current,N=ye.count,ee=ve.count;if(ci.current={adapter:ae,rows:N,cols:ee},p.adapter!==ae||N>=p.rows&&ee>=p.cols)return;ue?(Pt.current=Zn,Bo(Zn)):an(Vc(Pt.current,N,ee),"countShrink"),$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag();const se=ht=>ue||ht.row>=N||ht.col>=ee,Ce=ai();Ce!==null&&se(Ce)&&di();const ke=Xo.current;if(ke.tip!==null&&se(ke.tip)&&wt.current?.hideTip(),ke.interactive!==null&&se(ke.interactive)){const ht=Ve.current?.contains(document.activeElement)===!0;wt.current?.close({restoreFocus:ht})}const tt=Jr();tt!==null&&!tt.foreign&&se({row:tt.range.endRow,col:tt.range.endCol})&&Ct()},[ae,ye.count,ve.count,ue,an,$t,jt,It,pt,Mt,yt,ai,di,Jr,Ct]);const fi=i.useRef(a),pi=i.useRef(u),hi=i.useRef(h),mi=i.useRef(g);i.useLayoutEffect(()=>{(fi.current!==a||pi.current!==u||hi.current!==h||mi.current!==g)&&(fi.current=a,pi.current=u,hi.current=h,mi.current=g,$t.cancelDrag(),jt.cancelDrag(),It.cancelDrag(),pt.cancelDrag(),Mt.cancelDrag(),yt.cancelDrag())},[a,u,h,g,$t,jt,It,pt,Mt,yt]),i.useLayoutEffect(()=>{xt(),At(),De()},[a,u,h,g,xt,At,De]);const gi=i.useRef(x);i.useLayoutEffect(()=>{gi.current!==x&&(gi.current=x,Ct())},[x,Ct]),i.useLayoutEffect(()=>{De()},[De,En]);const An=i.useCallback(()=>{const p=Ml.current;if(p===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return p},[]);if(i.useImperativeHandle(Wr,()=>({resizeRow:(p,N)=>{const ee=Math.round(N);ye.resize(p,ee),le.current?.updateRowSize(p,ee),ze.bumpRowGeometry(),xt(),De(),Vn(),Ut()},resizeColumn:(p,N)=>{const ee=Math.round(N);ve.resize(p,ee),le.current?.updateColSize(p,ee),ze.bumpColVersion(),At(),De(),Vn(),Ut()},autoFitColumns:p=>{for(const N of p)if(!Number.isInteger(N)||N<0||N>=ve.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${ve.count-1} (got ${String(N)})`);return pt.autofitColumnsInAllRows(p)},scrollToCell:(p,N)=>{le.current?.scrollToCell(p.row,p.col,N)},focus:p=>{Ot(p),Ge()||ft()},executeCommand:p=>Uo.current(p),applyFormat:p=>An().applyFormat(p),setBorders:(p,N)=>An().setBorders(p,N),setHyperlink:p=>An().setHyperlink(p),setNote:p=>An().setNote(p),addComment:p=>An().addComment(p),setValidation:p=>An().setValidation(p),paste:p=>Go.current(p),getSelection:()=>Pt.current,setSelection:(p,N)=>{const ee=I0(p,ye.count,ve.count),se=RC(N);return Ge()||vr()?!1:(an(ee,"setSelection"),se&&_t(ee.active),!0)},getEditSession:ui,commitEdit:()=>Ge()?et()?"committed":"rejected":"idle",getBaseFormat:p=>ae.getCellFormat===void 0?void 0:ae.getCellFormat(p.row,p.col),getPaintedFormat:p=>ae.getCellFormat===void 0?void 0:cn(p.row,p.col,Eo(ae,p.row,p.col)),startEdit:p=>{br(p)},openPopover:p=>{Yr.current(p)}}),[ye,ve,ze,At,xt,De,Vn,Ut,pt,Ot,Ge,ft,ae,cn,br,An,an,vr,_t,ui,et]),ue)return I.jsx("div",{className:Rn?`aqsp-root ${Rn}`:"aqsp-root","data-aqsp-empty":"","data-testid":kt});const Nd=te!==void 0||f!==void 0||b!==void 0||v!==void 0||R!==void 0,Dd=s===void 0?{"aria-label":Qe.rootAriaLabel}:{"aria-labelledby":s};return I.jsxs("div",{ref:Ve,className:Rn?`aqsp-root ${Rn}`:"aqsp-root",role:"group",...Dd,tabIndex:0,onFocus:Md,onBlur:Ld,"data-aqsp-root":"","data-aqsp-headings-hidden":X?void 0:"","data-aqsp-framed":G===void 0?void 0:"","data-aqsp-touch-editing":A?"":void 0,"data-testid":kt,children:[I.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":J,onPointerDown:zd,style:J===1?void 0:{width:`${100/J}%`,height:`${100/J}%`,transform:`scale(${J})`,"--_aqsp-zoom":String(J)},children:[X?I.jsxs(I.Fragment,{children:[I.jsx("div",{ref:Se,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:p=>{if(p.pointerType==="mouse"&&(p.preventDefault(),p.button===0)){if(kn()){Ue();return}if(Ge()&&!et()){Ue();return}Ue(),Tt({ranges:[me({row:0,col:0},{row:ae.rowCount-1,col:ae.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),I.jsx(D0,{viewStore:ze,colAxis:ve,frozenCols:a,frozenTrailingCols:h,handleRef:le,bandRef:dt,colTrackRef:ut,windowOriginXRef:Le,repaintColHeaders:At,selectionRanges:En.ranges,enableResizeUI:C,dividerLeadingRef:gt,dividerTrailingRef:Ye}),I.jsx(F0,{viewStore:ze,rowAxis:ye,handleRef:le,bandRef:Kt,selectionRanges:En.ranges,rowTrackRef:mt,windowOriginYRef:at,repaintHeaders:xt,enableResizeUI:C,frozenRows:u,frozenTrailingRows:g,dividerLeadingRef:qt,dividerTrailingRef:In})]}):null,I.jsxs("div",{ref:Re,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[I.jsx(N0,{adapter:ae,rowAxis:ye,colAxis:ve,viewStore:ze,handleRef:le,bodyRef:pe,dataVersion:x,defaultColumnWidth:c,frozenColumns:a,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:n,labelledBy:s,gridLabel:s===void 0?Qe.rootAriaLabel:void 0,readOnly:o,tapScrollCircleOptions:L,showArrowButtons:M?.showArrowButtons,enableThumbDrag:M?.enableThumbDrag,enableTrackClick:M?.enableTrackClick,overscanRows:Yc("overscanRows",$),overscanCols:Yc("overscanCols",H),background:Z,onRenderTruncated:Q,renderCell:O,onScroll:ud,onRangeChange:dd,focusSink:Ue,isEditing:Ge,requestCommit:et,testId:kt?`${kt}-vs`:void 0,__onCellRender:Io,__maxRenderedCells:Ft,cfIndexRef:wr,cfMemoRef:ln,isPointing:kn,locale:qn,scrollLabels:sn,sortFilter:Ae,columnMenu:Od}),I.jsx(Bg,{rowAxis:ye,colAxis:ve,handleRef:le,sinkRef:Me,getSelection:Yt,editing:He.editing,sinkInputMode:od,repaintRef:vl,dragFrameRef:Wo,getClip:Jr,getIsDraggingAny:Rr,getIsFillDragging:Mt.isDragging,fillFrameRef:Gl,resizeGuideFrameRef:Jl,fillHandleNodeRef:Zl,enableFillHandle:V,frozenCols:a,frozenRows:u,trailingCols:h,trailingRows:g,sinkAriaLabel:Qe.sinkAriaLabel,sinkReadOnly:o,sinkKeyShortcuts:Pn,onSinkMouseDown:$d,editPaintRef:kl,highlightRef:Vo,frameRange:G,highlightColors:Zu,popoverAnchors:Xo,interactiveAnchorRef:xl,tipAnchorRef:Al}),Gt.layerEnabled?I.jsx(uC,{controller:Gt,labels:Qe,renderPopover:Pe,interactiveAnchorRef:xl,tipAnchorRef:Al,columnMenu:xd}):null]}),Nd?I.jsx("div",{ref:Kr,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),I.jsx("div",{ref:ct,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=nn.iterateTsvPrefixRows;exports.iterateTsvRows=nn.iterateTsvRows;exports.measureTsv=nn.measureTsv;exports.parseTsv=nn.parseTsv;exports.serializeClipboardTsv=nn.serializeClipboardTsv;exports.serializeTsv=nn.serializeTsv;exports.columnIndexToName=Fe.columnIndexToName;exports.columnNameToIndex=Fe.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Qs;exports.CommentPopover=Ru;exports.DEFAULT_CUSTOM_COLORS=Uu;exports.DEFAULT_HIGHLIGHT_COLORS=vu;exports.DEFAULT_SHORTCUTS=iu;exports.LinkPopover=Su;exports.ListPopover=Eu;exports.MessagePopover=ku;exports.NotePopover=Ou;exports.NoteTip=xu;exports.SPREADSHEET_LABEL_CATALOGS=cu;exports.SPREADSHEET_RESERVED_SHORTCUTS=Pm;exports.Spreadsheet=FC;exports.canonicalizeFormat=Nt;exports.detectClipSource=la;exports.enumerateRangeCells=fn;exports.estimatePasteCellCount=km;exports.expandPaste=Om;exports.formatCellValue=Ln;exports.formatEquals=Gd;exports.fromR1C1=Ir;exports.makeRange=me;exports.mergeFormat=tl;exports.normalizeHyperlink=bn;exports.parseChord=en;exports.parseClipPayload=zs;exports.parseHtmlTable=Ja;exports.rangeContains=Vt;exports.rangeSize=St;exports.resolveLabel=be;exports.resolveLabels=au;exports.serializeClipPayload=ra;exports.serializeHtmlTable=Ya;exports.shiftFormula=$a;exports.toR1C1=qo;exports.validateCellText=fu;
|