@aiquants/spreadsheet 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _t=require("./tsv.cjs"),xe=require("./view-BkwCUzTl.cjs"),Ge=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),gs=1e3,rn=1e4,ws=10,$l=2**(1/4),Lu=(e,t)=>e<=0?e:t>0?e>=rn?e:Math.min(rn,Math.max(e+1,Math.round(e*$l))):Math.max(1,Math.min(e-1,Math.round(e/$l))),Dl=(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),Cs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/ws):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),rn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Dl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Dl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},bs="#000000",$r=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},$u=20,Du=256,Dr=new Map,Fo=new WeakMap,ot=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Mu=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},zu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:$u}:$r(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...$r(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...$r(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...$r(e.decimals)};default:return null}},Fu=e=>{const t=Fo.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=Dr.get(n);if(r!==void 0)return Fo.set(e,r),r;Dr.size>=Du&&Dr.clear();const o=zu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Dr.set(n,s),Fo.set(e,s),s},Nu=(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=/^(\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>Nu(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Pu=(e,t)=>{const n=Zi(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)}})},Bn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Pu(e,t.pattern??"yyyy/MM/dd");const n=ot(e);if(n===null)return e;const r=Fu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Mu(n,-2):n)},Ml=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Zi(n)!==null?"right":"left":ot(n)!==null?"right":"left",ur=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Ji=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],_u=["bottom","left","right","top"],Qi=(e,t,n)=>{e[t]=n},ec=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},qu=e=>{if(e===void 0)return;const t={};for(const n of _u){const r=e[n];r!==void 0&&(t[n]=ec(r))}return Object.keys(t).length===0?void 0:t},wt=e=>{const t={};for(const n of Ji){const r=n==="borders"?qu(e.borders):n==="value"?e.value===void 0?void 0:ec(e.value):e[n];r!==void 0&&r!==!1&&Qi(t,n,r)}return Object.keys(t).length===0?void 0:t},ys=(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]||!ys(o[c],s[c]))return!1}return!0},Iu=(e,t)=>e===t?!0:ys(e===void 0?void 0:wt(e),t===void 0?void 0:wt(t)),Rs=(e,t)=>{const n={};for(const o of Ji){const s=t[o];Qi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=wt(n);return ys(r,e===void 0?void 0:wt(e))?e:r},tc="data-aqsp-clip",Qr="application/x-aqsp-clip",es=512,zl=16*1024,ts=`${tc}=`,ju=16,vs=()=>{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(ju));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},wr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",Ue=e=>typeof e=="boolean",Qt=e=>typeof e=="number"&&Number.isFinite(e),gt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Fl=e=>gt(e)&&e>=1,Hu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=rn,Pt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Bu=e=>t=>Array.isArray(t)&&t.every(e),Te=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),It=(e,t)=>{if(!wr(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},ks=e=>t=>{if(!wr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&It(t,n)},Vu=["left","center","right"],Wu=["top","middle","bottom"],Yu=["thin","medium","thick","dashed","dotted","double","hair"],No=["gt","gte","lt","lte","eq","neq","between","notBetween"],Ku=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Uu=["eq","neq","gt","gte","lt","lte","between","notBetween"],Xu=["contains","notContains","startsWith","endsWith"],Gu=new Map([["number",Te({type:ae,decimals:Qt,grouping:Ue,locale:ae},["type"])],["percent",Te({type:ae,decimals:Qt,scale:Ue,locale:ae},["type"])],["currency",Te({type:ae,currency:ae,decimals:Qt,locale:ae},["type","currency"])],["scientific",Te({type:ae,decimals:Qt,locale:ae},["type"])],["date",Te({type:ae,pattern:ae},["type"])],["text",Te({type:ae},["type"])]]),Zu=Te({style:Pt(Yu),color:ae},["style"]),Mr=e=>It(e,Zu),Ju=Te({top:Mr,right:Mr,bottom:Mr,left:Mr},[]),Qu=Te({value:ks(Gu),align:Pt(Vu),verticalAlign:Pt(Wu),wrap:Ue,background:ae,color:ae,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue,fontFamily:ae,fontSize:Qt,borders:e=>It(e,Ju)},[]),ed=e=>It(e,Qu),dn={strict:Ue,inputMessage:ae,errorMessage:ae},td=new Map([["list",Te({...dn,type:ae,values:Bu(ae),showDropdown:Ue},["type","values"])],["number",Te({...dn,type:ae,op:Pt(No),a:ae,b:ae},["type","op","a"])],["textLength",Te({...dn,type:ae,op:Pt(No),a:Qt,b:Qt},["type","op","a"])],["date",Te({...dn,type:ae,op:Pt(No),a:ae,b:ae},["type","op","a"])],["text",Te({...dn,type:ae,op:Pt(Ku),value:ae},["type","op"])],["checkbox",Te({...dn,type:ae,checked:ae,unchecked:ae},["type"])],["custom",Te({...dn,type:ae,formula:ae},["type","formula"])]]),nd=ks(td),rd=Te({startRow:gt,startCol:gt,endRow:gt,endCol:gt},["startRow","startCol","endRow","endCol"]),od=e=>{if(!It(e,rd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return gt(t)&&gt(r)&&gt(n)&&gt(o)&&t<=r&&n<=o},sd=Te({color:ae,value:Qt},["color"]),Po=e=>It(e,sd),ld=new Map([["cellValue",Te({type:ae,op:Pt(Uu),a:ae,b:ae},["type","op","a"])],["text",Te({type:ae,op:Pt(Xu),value:ae},["type","op","value"])],["empty",Te({type:ae},["type"])],["notEmpty",Te({type:ae},["type"])],["colorScale",Te({type:ae,min:Po,mid:Po,max:Po},["type","min","max"])],["customFormula",Te({type:ae,formula:ae},["type","formula"])]]),id=Te({background:ae,color:ae,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue},[]),cd=Te({sourceRuleId:ae,ranges:Array.isArray,condition:ks(ld),style:e=>It(e,id),stopIfTrue:Ue},["sourceRuleId","ranges","condition","style"]),ad=(e,t,n)=>{if(!It(e,cd))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!od(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},ud=Te({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),dd=e=>It(e,ud),fd=(e,t,n)=>{if(!wr(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(!gt(o)||o>=t)return!1;break;case"val":if(!gt(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(dd)))return!1;break;default:return!1}}return!0},Nl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Hu),pd=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),nc=e=>{if(!wr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!pd.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Fl(t)&&Fl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(ed)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(nd)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const u of c)if(!fd(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Nl(e.colWidths,n)||e.rowHeights!==void 0&&!Nl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>ad(c,t,n))},hr=e=>Array.isArray(e)?`[${e.map(hr).join(",")}]`:wr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${hr(e[n])}`).join(",")}}`:JSON.stringify(e),hd=e=>{const t=wt(e);return t===void 0?"{}":JSON.stringify(t)},md=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,gd=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(md).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},rc=e=>{if(!nc(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(hd).join(","),r=e.validations.map(hr).join(","),o=e.cells.map(u=>`[${u.map(gd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(hr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},ns=e=>{let t;try{t=JSON.parse(e)}catch{return null}return nc(t)?t:null},wd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Cd=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),oc=e=>e.includes("&")?e.replace(wd,t=>Cd[t]):e,bd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Pl=e=>{const t=e.length>es?e.slice(0,es):e,n=bd.exec(oc(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},yd=e=>{const t=e.indexOf(ts);if(t===-1)return null;const n=t+ts.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},sc=(e,t)=>{if(t==="event"&&e.types.includes(Qr))return{kind:"mime",json:e.getData(Qr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=yd(n);return r===null?null:{kind:"attribute",html:n,at:r}},Rd=(e,t)=>{const n=sc(e,t);return n===null?null:n.kind==="mime"?Pl(n.json):Pl(n.html.slice(n.at.start,n.at.start+es))},vd=(e,t)=>{const n=sc(e,t);if(n===null)return null;if(n.kind==="mime")return ns(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:ns(oc(n.html.slice(n.at.start,r)))},kd=/<google-sheets-html-origin[\s>]/,Sd='data-sheets-root="1"',Ed=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ad="mso-",Od=/\.xl\d+\s*\{/,xd="<table",Td=e=>e.includes(ts)?"aqsp":kd.test(e)&&e.includes(Sd)?"sheets":Ed.test(e)||e.includes(Ad)||Od.test(e)?"excel":null,lc=(e,t)=>{if(t==="event"&&e.types.includes(Qr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>zl?n.slice(0,zl):n,o=Td(r);if(o==="aqsp")return"aqsp";if(n.includes(xd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Ss=1e3,ic=65534,Ld=9,$d=10,Dd=12,Md=13,zd=32,cc=34,ac=39,Fd=43,Es=47,_l=48,Nd=57,Pd=61,_d=62,qd=97,Id=98,jd=100,Hd=102,uc=104,dc=114,fc=116,Bd=["able","body","head","foot"],dr=e=>e===zd||e===Ld||e===$d||e===Md||e===Dd,rs=e=>e===_d||e===Es||dr(e),Vd=e=>dr(e)||e===Es||e===cc||e===ac,Wd=(e,t,n,r)=>{if(t===0||!Vd(e.charCodeAt(t-1)))return null;let o=t+n;for(;dr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Pd)return 1;for(o+=1;dr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===cc||s===ac)&&(o+=1);dr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Fd&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=_l&&u<=Nd;u=e.charCodeAt(o))l=l*10+(u-_l),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},ql=(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=Wd(e,r,t.length,n);if(l!==null)return l}return 1}},Yd=(e,t)=>{if(e.charCodeAt(t+2)!==fc)return!1;const n=e.charCodeAt(t+3);if(n===dc)return rs(e.charCodeAt(t+4));if(n!==qd&&n!==Id&&n!==uc&&n!==Hd)return!1;for(const r of Bd)if(e.startsWith(r,t+3)&&rs(e.charCodeAt(t+3+r.length)))return!0;return!1},Kd=e=>{const t=e.toLowerCase(),n=ql(t,"colspan",Ss),r=ql(t,"rowspan",ic);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,g=!1;const R=new Map,F=(_,U)=>{const W=R.get(_);R.set(_,W===void 0?U:W+U)},H=()=>{g&&u+h>c&&(c=u+h),g=!1},$=()=>{H(),l+=1,g=!0,u=0;const _=R.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const U=t.charCodeAt(_+1);if(U===Es){Yd(t,_)&&H();continue}if(U!==fc||!rs(t.charCodeAt(_+3)))continue;const W=t.charCodeAt(_+2);if(W===dc)$();else if(W===jd||W===uc){g||$();const S=_+3,x=s(S),z=n(S,x);u+=z;const I=r(S,x);I>1&&(F(l,z),F(l-1+I,-z))}}return H(),{rows:l,cols:c}},pc=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}},hc=()=>{const e=new WeakMap,t=pc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=wt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Ud=()=>{const e=new WeakMap,t=pc(hr);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}},Xd=new Set(["http:","https:","mailto:","tel:"]),on=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Xd.has(n.protocol)?n.href:null},Yn=e=>{if(e===void 0)return;const t=on(e);return t===null?void 0:t},mc=(e,t)=>e.startCol===0&&e.endCol===t-1,gc=(e,t)=>e.startRow===0&&e.endRow===t-1,os=13,Nt=Object.freeze({style:Object.freeze({}),lineBoxPx:os,verticalAlign:"middle"}),Gd={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"},Zd=new Map(Object.entries(Gd)),Jd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Qd=/^rgba?\((.*)\)$/,wc=/^(\d+(?:\.\d+)?)%$/,zr=e=>e.toString(16).padStart(2,"0"),_o=e=>{const t=wc.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},ef=e=>{const t=wc.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},tf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=_o(t[0]),r=_o(t[1]),o=_o(t[2]);if(n===null||r===null||o===null)return null;const s=`#${zr(n)}${zr(r)}${zr(o)}`;if(t.length===3)return s;const l=ef(t[3]);return l===null?null:l===255?s:`${s}${zr(l)}`},Xe=e=>{const t=e.trim().toLowerCase(),n=Jd.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=Qd.exec(t);if(r!==null)return tf(r[1]);const o=Zd.get(t);return o===void 0?null:o},Il={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"}},jl=e=>{if(!Object.hasOwn(Il,e.style))return null;const t=Il[e.style],n=e.color===void 0?bs:Xe(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},nf={top:"flex-start",middle:"center",bottom:"flex-end"},rf=e=>e==="left"||e==="center"||e==="right",Cc=e=>e==="top"||e==="middle"||e==="bottom",bc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,yc=(e,t)=>{if(typeof e.background=="string"){const s=Xe(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Xe(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=bc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Fr=(e,t)=>{const n=e===void 0?null:jl(e);return n!==null?n:t===void 0?null:jl(t)},qo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(rf(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=ur(e.align)),Cc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=nf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),yc(e,s));const c=e?.borders,u=Fr(c?.right,t);u!==null&&(s.borderRight=u);const h=Fr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const g=Fr(c?.left,void 0);g!==null&&(s.borderLeft=g)}if(o){const g=Fr(c?.top,void 0);g!==null&&(s.borderTop=g)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Hl=new WeakMap,of=(e,t,n,r,o)=>{const s=t?.borders?.left,l=n?.borders?.top,c=!(r||o)&&s===void 0&&l===void 0;if(e===void 0)return c?null:qo(void 0,s,l,r,o);if(!c)return qo(e,s,l,r,o);const u=Hl.get(e);if(u!==void 0)return u;const h=qo(e,void 0,void 0,!1,!1);return Hl.set(e,h),h},sf=e=>{if(e===void 0)return Nt;const t={};yc(e,t);const n=bc(e.fontSize),r=n===null?os:Math.round(n),o=Cc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===os&&o==="middle"?Nt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},lf="#REF!",cf=11,af=15,uf=4096,Yr=33,fr=34,As=36,df=38,ss=39,Rc=40,ff=42,pf=43,hf=44,vc=45,mf=46,gf=47,qn=58,wf=59,Cf=60,kc=61,bf=62,yf=67,Rf=82,so=91,Sc=93,vf=94,kf=95,Ec=e=>e>=65&&e<=90||e>=97&&e<=122,Ac=e=>e>=48&&e<=57,Os=e=>Ec(e)||Ac(e)||e===kf||e===mf||e===As||e>=128,Sf=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,Ef=e=>e===kc||e===Rc||e===hf||e===wf||e===pf||e===vc||e===ff||e===gf||e===vf||e===df||e===Cf||e===bf||e===qn,Oc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Os(n)||n===Rc||n===Yr||n===so)},Bl=(e,t)=>{let n=t;for(;n<e.length&&Os(e.charCodeAt(n));)n+=1;return n},ls=(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},Af=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===ss){r+=2;continue}if(o===so)n+=1;else if(o===Sc&&(n-=1,n===0))return r+1;r+=1}return e.length},Vl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Oc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},xc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===fr){o=ls(e,o,fr);continue}if(s===ss){const u=ls(e,o,ss);o=e.charCodeAt(u)===Yr?Vl(e,o,u,t,n):u;continue}if(s===so){o=Af(e,o);continue}if(!Os(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Oc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Bl(e,o);if(e.charCodeAt(c)===qn){const u=Bl(e,c+1);u>c+1&&e.charCodeAt(u)===Yr&&(c=u)}o=e.charCodeAt(c)===Yr?Vl(e,o,c,t,n):c}return n},Io=(e,t)=>{let n=t;const r=e.charCodeAt(n)===As;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Ec(l))break;if(s+=1,s>cf)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},is=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Ac(o))break;if(n-t>=af)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Nr=(e,t)=>{const n=e.charCodeAt(t)===As,r=is(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Of=(e,t)=>{const n=Io(e,t);if(n!==null){const o=Nr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===qn){const s=Io(e,o.end+1);if(s!==null){const l=Nr(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)===qn){const s=Io(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=Nr(e,t);if(r!==null&&e.charCodeAt(r.end)===qn){const o=Nr(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},Cr=e=>xc(e,Of),Tc=(e,t=uf)=>{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}},cs=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},jo=e=>`${e.absCol?"$":""}${cs(e.col)}${e.absRow?"$":""}${e.row+1}`,xs=e=>e.sheet===void 0?"":`${e.sheet}!`,en=e=>{const t=xs(e);switch(e.kind){case"cell":return`${t}${jo(e)}`;case"range":return`${t}${jo(e.start)}:${jo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${cs(e.start.col)}:${e.end.abs?"$":""}${cs(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},zn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},xf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(zn(n.startRow,"formatRangeReference startRow"),zn(n.startCol,"formatRangeReference startCol"),zn(n.endRow,"formatRangeReference endRow"),zn(n.endCol,"formatRangeReference endCol"),t){case"columns":return en({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return en({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?en({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):en({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Ts=(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?`${xs(s.token)}${lf}`:l),o=s.end}return r+e.slice(o)},lo=e=>e.charCodeAt(0)===kc,Ho=(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}},Tf=(e,t,n)=>{switch(e.kind){case"cell":{const r=Ho(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Ho(e.start,t,n),o=Ho(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}}}}},Lc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return lo(e)?Ts(e,Cr(e),r=>{const o=Tf(r,t,n);return o===null?null:en(o)}):e},$c=(e,t)=>{zn(e.row,`${t} origin.row`),zn(e.col,`${t} origin.col`)},Fn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Bo=(e,t)=>`${Fn("R",e.row,e.absRow,t.row)}${Fn("C",e.col,e.absCol,t.col)}`,Lf=(e,t)=>{const n=xs(e);switch(e.kind){case"cell":return`${n}${Bo(e,t)}`;case"range":return`${n}${Bo(e.start,t)}:${Bo(e.end,t)}`;case"column":return`${n}${Fn("C",e.start.col,e.start.abs,t.col)}:${Fn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Fn("R",e.start.row,e.start.abs,t.row)}:${Fn("R",e.end.row,e.end.abs,t.row)}`}},io=(e,t)=>($c(t,"toR1C1"),lo(e)?Ts(e,Cr(e),n=>Lf(n,t)):e),Wl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===so){const l=e.charCodeAt(o+1)===vc,c=is(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Sc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=is(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}}},Yl=(e,t)=>{const n=Wl(e,t,Rf),r=Wl(e,n===null?t:n.end,yf);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}},$f=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}}},Df=(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,Mf=(e,t)=>{const n=Yl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===qn){const r=Yl(e,n.end+1);if(r!==null){const o=Df(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:$f(n)}},zf=e=>xc(e,Mf),Ff=Tc(zf),Nn=(e,t)=>e.rel?t+e.n:e.n-1,Kl=(e,t)=>{const n=Nn(e.row,t.row),r=Nn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Nf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Kl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Kl(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=Nn(e.start,t.row),s=Nn(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=Nn(e.start,t.col),s=Nn(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}}}},br=(e,t)=>($c(t,"fromR1C1"),lo(e)?Ts(e,Ff(e),n=>{const r=Nf(n,t);return r===null?null:en(r)}):e),Ul=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Pf=e=>{switch(e.kind){case"cell":return{...e,...Ul(e.absCol,e.absRow)};case"range":{const t=Ul(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}}}}},Dc=(e,t)=>lo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Mc=(e,t)=>{if(!Dc(e,t))return null;for(const n of Cr(e))if(n.start<=t&&t<=n.end)return n;return null},_f=(e,t)=>{const n=Mc(e,t);if(n===null)return null;const r=en(Pf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Xl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===fr){const s=ls(e,r,fr);if(s>t)return!1;n=fr,r=s;continue}Sf(o)||(n=o),r+=1}return Ef(n)},zc=(e,t)=>{if(!Dc(e,t))return null;for(const n of Cr(e))if(n.start<=t&&t<=n.end)return Xl(e,n.start)?{replace:[n.start,n.end]}:null;return Xl(e,t)?{insertAt:t}:null},Vn=[{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}],co=(e,t)=>`[$${e}-${t}]`,qf=new Map(Vn.map(e=>[co(e.symbol,e.lcid),e])),If=new Map(Vn.filter((e,t)=>Vn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Vn.map(e=>[co(e.symbol,e.lcid),e.code]));const jf=new Set([...Vn.map(e=>e.symbol),...Vn.map(e=>e.code),"¥"]),Hf=20,Bf="yyyy/MM/dd",Fc=/yyyy|MM|dd|HH|mm|ss/g,Nc=" -+/():!^&'~{}<>=",Vf="$¥€£₩₹¥",as=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},Wf=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},Yf=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),g=u<0?null:c.slice(u+1);if(g!==null&&!/^[0-9a-fA-F]{1,8}$/.test(g)||h===""&&g===null)return null;const R=g===null?null:Number.parseInt(g,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:R}),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(Nc.includes(o)||Vf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},mt=e=>e===void 0?{}:{locale:e},Kf=/^(0|#,##0)(?:\.(0+))?$/,Gl=(e,t,n,r)=>{if(t!==null){const o=qf.get(co(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!jf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...mt(r.locale)}},Uf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const $ of e)switch($.kind){case"locale":break;case"literal":r?u+=$.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 h=Kf.exec(n);if(h===null)return;const g=h[1]==="#,##0",R=h[2]===void 0?0:h[2].length,F=c.trim(),H=u.trim();if(s)return l===0&&o===null&&!g&&F===""&&H===""?{type:"scientific",decimals:R,...mt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&F===""&&H===""?{type:"percent",decimals:R,...mt(t.locale)}:void 0;if(H==="%"&&F===""&&o===null)return{type:"percent",decimals:R,scale:!1,...mt(t.locale)};if(o!==null)return F===""&&H===""?Gl(o.symbol,o.lcid,R,t):void 0;if(!(F!==""&&H!==""))return F!==""||H!==""?Gl(F+H,null,R,t):{type:"number",decimals:R,...g?{grouping:!0}:{},...mt(t.locale)}},Xf=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Gf=(e,t)=>{const n=[...e.matchAll(Fc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Zf=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":Xf.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Gf(r,n)?{type:"date",pattern:r}:void 0},Jf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...mt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...mt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...mt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...mt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...mt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...mt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Ls=(e,t)=>{const n=Wf(e).trim(),r=Jf.get(n);if(r!==void 0)return r(t);const o=Yf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Uf(o,t);if(o.some(s=>s.kind==="date"))return Zf(o)}},Qf=(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:Ls(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},ir=e=>e===0?"":`.${"0".repeat(e)}`,Kr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Hf,ep=`${Nc}.,`,Zl=e=>e.includes('"')?null:[...e].every(t=>ep.includes(t))?e:`"${e}"`,tp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Fc)){const u=Zl(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=Zl(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Ls(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},np=e=>{const t=If.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Kr(n))return null;const r=`#,##0${ir(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${co(t.symbol,t.lcid)}${r}`},Pc=e=>{switch(e.type){case"text":return"@";case"date":return tp(e.pattern===void 0?Bf:e.pattern);case"number":return Kr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${ir(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Kr(t)?e.scale===!1?`0${ir(t)}"%"`:`0${ir(t)}%`:null}case"scientific":return Kr(e.decimals)?`0${ir(e.decimals)}E+00`:null;case"currency":return np(e);default:return null}},Jl="-−",rp=(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("")},op=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=rp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},sp=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},lp=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",u=z=>z>="0"&&z<="9"||l!==""&&l.includes(z)||n.decimal.includes(z)||c&&(z==="e"||z==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let g=o.length;for(;g>h&&!u(o[g-1]);)g-=1;let R=0,F=0,H=0,$="";for(const z of o.slice(0,h))Jl.includes(z)?R+=1:z==="("?F+=1:$+=z;for(const z of o.slice(g))Jl.includes(z)?R+=1:z===")"?H+=1:$+=z;const _=R+F;if(F!==H||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&$.trim()!==""))return e;const U=op(o.slice(h,g).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(U===null)return e;const W=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,S=U.exponent+W;if(S>330||S<-330)return e;const x=sp(U.integer,U.fraction,S,s);return Number.isFinite(Number(x))?x:e},Ql="google-sheets-html-origin",_c=Object.freeze({group:",",decimal:"."}),ei=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"}),qc=["top","right","bottom","left"],ip=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),cp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),ap=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"]),ti=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],up=Object.freeze({number:2,percent:3,currency:4,scientific:8}),dp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),fp=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"]),pp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),hp=3,mp=1,Ic=-25569,Ur=86400,gp=-693959,wp=2958465,Cp=" ",ao=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),g=c.slice(u+1).trim();h!==""&&g!==""&&t.set(h,g)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},eo=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},$s=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},bp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,yp=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const g=l.slice(c,u),R=l.slice(u+1,h);if(c=h+1,g.trim().startsWith("@"))continue;const F=ao(R);for(const H of g.split(",")){const $=H.trim(),_=bp.exec($);if(_!==null){const U=t.get(_[1]);if(U===void 0)t.set(_[1],new Map(F));else for(const[W,S]of F)U.set(W,S)}else if($.toLowerCase()==="table"){const U=F.get("mso-displayed-decimal-separator"),W=F.get("mso-displayed-thousand-separator");U!==void 0&&(n=as(eo(U))),W!==void 0&&(r=as(eo(W)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:_c}},Rp="%_-*? ",vp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Rp.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},kp=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,u=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+u-719468},jc=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},$n=(e,t)=>String(e).padStart(t,"0"),Hc=e=>{if(e<gp||e>wp)return null;let t=Math.floor(e),n=Math.round((e-t)*Ur);n>=Ur&&(t+=1,n-=Ur);const r=jc(t+Ic),o=`${$n(r.year,4)}-${$n(r.month,2)}-${$n(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${$n(s,2)}:${$n(l,2)}:${$n(n%60,2)}`},Sp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Ep=e=>{const t=Sp.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const u=kp(n,r,o),h=jc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-Ic+(s*3600+l*60+c)/Ur},Ds=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),fn=e=>Ds(e).replaceAll('"',"&quot;"),Bc=e=>Ds(e).replaceAll("'","&#39;"),Ap=e=>Ds(e).replaceAll(`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const qt=require("./tsv.cjs"),Te=require("./view-BkwCUzTl.cjs"),Je=require("@aiquants/virtualscroll"),Y=require("react/jsx-runtime"),i=require("react"),ys=1e3,on=1e4,Rs=10,zl=2**(1/4),Nu=(e,t)=>e<=0?e:t>0?e>=on?e:Math.min(on,Math.max(e+1,Math.round(e*zl))):Math.max(1,Math.min(e-1,Math.round(e/zl))),Nl=(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),vs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Rs):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),on))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Nl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Nl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},Ss="#000000",zr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Fu=20,Pu=256,Nr=new Map,_o=new WeakMap,ot=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},_u=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},qu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Fu}:zr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...zr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...zr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...zr(e.decimals)};default:return null}},Iu=e=>{const t=_o.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=Nr.get(n);if(r!==void 0)return _o.set(e,r),r;Nr.size>=Pu&&Nr.clear();const o=qu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Nr.set(n,s),_o.set(e,s),s},ju=(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}},ec=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>ju(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Hu=(e,t)=>{const n=ec(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)}})},Wn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Hu(e,t.pattern??"yyyy/MM/dd");const n=ot(e);if(n===null)return e;const r=Iu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?_u(n,-2):n)},Fl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?ec(n)!==null?"right":"left":ot(n)!==null?"right":"left",fr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",tc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Bu=["bottom","left","right","top"],nc=(e,t,n)=>{e[t]=n},rc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Vu=e=>{if(e===void 0)return;const t={};for(const n of Bu){const r=e[n];r!==void 0&&(t[n]=rc(r))}return Object.keys(t).length===0?void 0:t},gt=e=>{const t={};for(const n of tc){const r=n==="borders"?Vu(e.borders):n==="value"?e.value===void 0?void 0:rc(e.value):e[n];r!==void 0&&r!==!1&&nc(t,n,r)}return Object.keys(t).length===0?void 0:t},ks=(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]||!ks(o[c],s[c]))return!1}return!0},Wu=(e,t)=>e===t?!0:ks(e===void 0?void 0:gt(e),t===void 0?void 0:gt(t)),Es=(e,t)=>{const n={};for(const o of tc){const s=t[o];nc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=gt(n);return ks(r,e===void 0?void 0:gt(e))?e:r},oc="data-aqsp-clip",no="application/x-aqsp-clip",os=512,Pl=16*1024,ss=`${oc}=`,Ku=16,As=()=>{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(Ku));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},br=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",Ge=e=>typeof e=="boolean",en=e=>typeof e=="number"&&Number.isFinite(e),mt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,_l=e=>mt(e)&&e>=1,Yu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=on,_t=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Uu=e=>t=>Array.isArray(t)&&t.every(e),$e=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),jt=(e,t)=>{if(!br(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},Os=e=>t=>{if(!br(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&jt(t,n)},Xu=["left","center","right"],Gu=["top","middle","bottom"],Zu=["thin","medium","thick","dashed","dotted","double","hair"],qo=["gt","gte","lt","lte","eq","neq","between","notBetween"],Ju=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Qu=["eq","neq","gt","gte","lt","lte","between","notBetween"],ed=["contains","notContains","startsWith","endsWith"],td=new Map([["number",$e({type:ae,decimals:en,grouping:Ge,locale:ae},["type"])],["percent",$e({type:ae,decimals:en,scale:Ge,locale:ae},["type"])],["currency",$e({type:ae,currency:ae,decimals:en,locale:ae},["type","currency"])],["scientific",$e({type:ae,decimals:en,locale:ae},["type"])],["date",$e({type:ae,pattern:ae},["type"])],["text",$e({type:ae},["type"])]]),nd=$e({style:_t(Zu),color:ae},["style"]),Fr=e=>jt(e,nd),rd=$e({top:Fr,right:Fr,bottom:Fr,left:Fr},[]),od=$e({value:Os(td),align:_t(Xu),verticalAlign:_t(Gu),wrap:Ge,background:ae,color:ae,bold:Ge,italic:Ge,underline:Ge,strikethrough:Ge,fontFamily:ae,fontSize:en,borders:e=>jt(e,rd)},[]),sd=e=>jt(e,od),fn={strict:Ge,inputMessage:ae,errorMessage:ae},ld=new Map([["list",$e({...fn,type:ae,values:Uu(ae),showDropdown:Ge},["type","values"])],["number",$e({...fn,type:ae,op:_t(qo),a:ae,b:ae},["type","op","a"])],["textLength",$e({...fn,type:ae,op:_t(qo),a:en,b:en},["type","op","a"])],["date",$e({...fn,type:ae,op:_t(qo),a:ae,b:ae},["type","op","a"])],["text",$e({...fn,type:ae,op:_t(Ju),value:ae},["type","op"])],["checkbox",$e({...fn,type:ae,checked:ae,unchecked:ae},["type"])],["custom",$e({...fn,type:ae,formula:ae},["type","formula"])]]),id=Os(ld),cd=$e({startRow:mt,startCol:mt,endRow:mt,endCol:mt},["startRow","startCol","endRow","endCol"]),ad=e=>{if(!jt(e,cd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return mt(t)&&mt(r)&&mt(n)&&mt(o)&&t<=r&&n<=o},ud=$e({color:ae,value:en},["color"]),Io=e=>jt(e,ud),dd=new Map([["cellValue",$e({type:ae,op:_t(Qu),a:ae,b:ae},["type","op","a"])],["text",$e({type:ae,op:_t(ed),value:ae},["type","op","value"])],["empty",$e({type:ae},["type"])],["notEmpty",$e({type:ae},["type"])],["colorScale",$e({type:ae,min:Io,mid:Io,max:Io},["type","min","max"])],["customFormula",$e({type:ae,formula:ae},["type","formula"])]]),fd=$e({background:ae,color:ae,bold:Ge,italic:Ge,underline:Ge,strikethrough:Ge},[]),pd=$e({sourceRuleId:ae,ranges:Array.isArray,condition:Os(dd),style:e=>jt(e,fd),stopIfTrue:Ge},["sourceRuleId","ranges","condition","style"]),hd=(e,t,n)=>{if(!jt(e,pd))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!ad(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},md=$e({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),gd=e=>jt(e,md),wd=(e,t,n)=>{if(!br(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(!mt(o)||o>=t)return!1;break;case"val":if(!mt(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(gd)))return!1;break;default:return!1}}return!0},ql=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Yu),Cd=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),sc=e=>{if(!br(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Cd.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(_l(t)&&_l(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(sd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(id)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const u of c)if(!wd(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!ql(e.colWidths,n)||e.rowHeights!==void 0&&!ql(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>hd(c,t,n))},gr=e=>Array.isArray(e)?`[${e.map(gr).join(",")}]`:br(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${gr(e[n])}`).join(",")}}`:JSON.stringify(e),bd=e=>{const t=gt(e);return t===void 0?"{}":JSON.stringify(t)},yd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Rd=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(yd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},lc=e=>{if(!sc(e))throw new RangeError("[spreadsheet] serializeClipPayload received a payload outside the wire format v1 vocabulary");const t=`{"v":1,"rows":${e.rows},"cols":${e.cols},"clipId":${JSON.stringify(e.clipId)}`,n=e.formats.map(bd).join(","),r=e.validations.map(gr).join(","),o=e.cells.map(u=>`[${u.map(Rd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(gr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},ls=e=>{let t;try{t=JSON.parse(e)}catch{return null}return sc(t)?t:null},vd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Sd=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),ic=e=>e.includes("&")?e.replace(vd,t=>Sd[t]):e,kd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Il=e=>{const t=e.length>os?e.slice(0,os):e,n=kd.exec(ic(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Ed=e=>{const t=e.indexOf(ss);if(t===-1)return null;const n=t+ss.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},cc=(e,t)=>{if(t==="event"&&e.types.includes(no))return{kind:"mime",json:e.getData(no)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Ed(n);return r===null?null:{kind:"attribute",html:n,at:r}},Ad=(e,t)=>{const n=cc(e,t);return n===null?null:n.kind==="mime"?Il(n.json):Il(n.html.slice(n.at.start,n.at.start+os))},Od=(e,t)=>{const n=cc(e,t);if(n===null)return null;if(n.kind==="mime")return ls(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:ls(ic(n.html.slice(n.at.start,r)))},xd=/<google-sheets-html-origin[\s>]/,Td='data-sheets-root="1"',$d=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ld="mso-",Dd=/\.xl\d+\s*\{/,Md="<table",zd=e=>e.includes(ss)?"aqsp":xd.test(e)&&e.includes(Td)?"sheets":$d.test(e)||e.includes(Ld)||Dd.test(e)?"excel":null,ac=(e,t)=>{if(t==="event"&&e.types.includes(no))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Pl?n.slice(0,Pl):n,o=zd(r);if(o==="aqsp")return"aqsp";if(n.includes(Md))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},xs=1e3,uc=65534,Nd=9,Fd=10,Pd=12,_d=13,qd=32,dc=34,fc=39,Id=43,Ts=47,jl=48,jd=57,Hd=61,Bd=62,Vd=97,Wd=98,Kd=100,Yd=102,pc=104,hc=114,mc=116,Ud=["able","body","head","foot"],pr=e=>e===qd||e===Nd||e===Fd||e===_d||e===Pd,is=e=>e===Bd||e===Ts||pr(e),Xd=e=>pr(e)||e===Ts||e===dc||e===fc,Gd=(e,t,n,r)=>{if(t===0||!Xd(e.charCodeAt(t-1)))return null;let o=t+n;for(;pr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Hd)return 1;for(o+=1;pr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===dc||s===fc)&&(o+=1);pr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Id&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=jl&&u<=jd;u=e.charCodeAt(o))l=l*10+(u-jl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Hl=(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=Gd(e,r,t.length,n);if(l!==null)return l}return 1}},Zd=(e,t)=>{if(e.charCodeAt(t+2)!==mc)return!1;const n=e.charCodeAt(t+3);if(n===hc)return is(e.charCodeAt(t+4));if(n!==Vd&&n!==Wd&&n!==pc&&n!==Yd)return!1;for(const r of Ud)if(e.startsWith(r,t+3)&&is(e.charCodeAt(t+3+r.length)))return!0;return!1},Jd=e=>{const t=e.toLowerCase(),n=Hl(t,"colspan",xs),r=Hl(t,"rowspan",uc);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const R=new Map,N=(_,U)=>{const W=R.get(_);R.set(_,W===void 0?U:W+U)},H=()=>{m&&u+h>c&&(c=u+h),m=!1},L=()=>{H(),l+=1,m=!0,u=0;const _=R.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const U=t.charCodeAt(_+1);if(U===Ts){Zd(t,_)&&H();continue}if(U!==mc||!is(t.charCodeAt(_+3)))continue;const W=t.charCodeAt(_+2);if(W===hc)L();else if(W===Kd||W===pc){m||L();const k=_+3,x=s(k),z=n(k,x);u+=z;const I=r(k,x);I>1&&(N(l,z),N(l-1+I,-z))}}return H(),{rows:l,cols:c}},gc=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}},wc=()=>{const e=new WeakMap,t=gc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=gt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Qd=()=>{const e=new WeakMap,t=gc(gr);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}},ef=new Set(["http:","https:","mailto:","tel:"]),sn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return ef.has(n.protocol)?n.href:null},Un=e=>{if(e===void 0)return;const t=sn(e);return t===null?void 0:t},Cc=(e,t)=>e.startCol===0&&e.endCol===t-1,bc=(e,t)=>e.startRow===0&&e.endRow===t-1,cs=13,Pt=Object.freeze({style:Object.freeze({}),lineBoxPx:cs,verticalAlign:"middle"}),tf={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"},nf=new Map(Object.entries(tf)),rf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,of=/^rgba?\((.*)\)$/,yc=/^(\d+(?:\.\d+)?)%$/,Pr=e=>e.toString(16).padStart(2,"0"),jo=e=>{const t=yc.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},sf=e=>{const t=yc.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},lf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=jo(t[0]),r=jo(t[1]),o=jo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Pr(n)}${Pr(r)}${Pr(o)}`;if(t.length===3)return s;const l=sf(t[3]);return l===null?null:l===255?s:`${s}${Pr(l)}`},Ze=e=>{const t=e.trim().toLowerCase(),n=rf.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=of.exec(t);if(r!==null)return lf(r[1]);const o=nf.get(t);return o===void 0?null:o},Bl={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"}},Vl=e=>{if(!Object.hasOwn(Bl,e.style))return null;const t=Bl[e.style],n=e.color===void 0?Ss:Ze(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},cf={top:"flex-start",middle:"center",bottom:"flex-end"},af=e=>e==="left"||e==="center"||e==="right",Rc=e=>e==="top"||e==="middle"||e==="bottom",vc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Sc=(e,t)=>{if(typeof e.background=="string"){const s=Ze(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ze(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=vc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},_r=(e,t)=>{const n=e===void 0?null:Vl(e);return n!==null?n:t===void 0?null:Vl(t)},Ho=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(af(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=fr(e.align)),Rc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=cf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Sc(e,s));const c=e?.borders,u=_r(c?.right,t);u!==null&&(s.borderRight=u);const h=_r(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=_r(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=_r(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Wl=new WeakMap,uf=(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:Ho(void 0,s,l,r,o);if(!c)return Ho(e,s,l,r,o);const u=Wl.get(e);if(u!==void 0)return u;const h=Ho(e,void 0,void 0,!1,!1);return Wl.set(e,h),h},df=e=>{if(e===void 0)return Pt;const t={};Sc(e,t);const n=vc(e.fontSize),r=n===null?cs:Math.round(n),o=Rc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===cs&&o==="middle"?Pt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},ff="#REF!",pf=11,hf=15,mf=4096,Xr=33,hr=34,$s=36,gf=38,as=39,kc=40,wf=42,Cf=43,bf=44,Ec=45,yf=46,Rf=47,jn=58,vf=59,Sf=60,Ac=61,kf=62,Ef=67,Af=82,co=91,Oc=93,Of=94,xf=95,xc=e=>e>=65&&e<=90||e>=97&&e<=122,Tc=e=>e>=48&&e<=57,Ls=e=>xc(e)||Tc(e)||e===xf||e===yf||e===$s||e>=128,Tf=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,$f=e=>e===Ac||e===kc||e===bf||e===vf||e===Cf||e===Ec||e===wf||e===Rf||e===Of||e===gf||e===Sf||e===kf||e===jn,$c=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Ls(n)||n===kc||n===Xr||n===co)},Kl=(e,t)=>{let n=t;for(;n<e.length&&Ls(e.charCodeAt(n));)n+=1;return n},us=(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},Lf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===as){r+=2;continue}if(o===co)n+=1;else if(o===Oc&&(n-=1,n===0))return r+1;r+=1}return e.length},Yl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&$c(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Lc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===hr){o=us(e,o,hr);continue}if(s===as){const u=us(e,o,as);o=e.charCodeAt(u)===Xr?Yl(e,o,u,t,n):u;continue}if(s===co){o=Lf(e,o);continue}if(!Ls(s)){o+=1;continue}const l=t(e,o);if(l!==null&&$c(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Kl(e,o);if(e.charCodeAt(c)===jn){const u=Kl(e,c+1);u>c+1&&e.charCodeAt(u)===Xr&&(c=u)}o=e.charCodeAt(c)===Xr?Yl(e,o,c,t,n):c}return n},Bo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===$s;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!xc(l))break;if(s+=1,s>pf)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},ds=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Tc(o))break;if(n-t>=hf)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},qr=(e,t)=>{const n=e.charCodeAt(t)===$s,r=ds(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Df=(e,t)=>{const n=Bo(e,t);if(n!==null){const o=qr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===jn){const s=Bo(e,o.end+1);if(s!==null){const l=qr(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)===jn){const s=Bo(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=qr(e,t);if(r!==null&&e.charCodeAt(r.end)===jn){const o=qr(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},yr=e=>Lc(e,Df),Dc=(e,t=mf)=>{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}},fs=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},Vo=e=>`${e.absCol?"$":""}${fs(e.col)}${e.absRow?"$":""}${e.row+1}`,Ds=e=>e.sheet===void 0?"":`${e.sheet}!`,tn=e=>{const t=Ds(e);switch(e.kind){case"cell":return`${t}${Vo(e)}`;case"range":return`${t}${Vo(e.start)}:${Vo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${fs(e.start.col)}:${e.end.abs?"$":""}${fs(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Fn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Mf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Fn(n.startRow,"formatRangeReference startRow"),Fn(n.startCol,"formatRangeReference startCol"),Fn(n.endRow,"formatRangeReference endRow"),Fn(n.endCol,"formatRangeReference endCol"),t){case"columns":return tn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return tn({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?tn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):tn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Ms=(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?`${Ds(s.token)}${ff}`:l),o=s.end}return r+e.slice(o)},ao=e=>e.charCodeAt(0)===Ac,Wo=(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}},zf=(e,t,n)=>{switch(e.kind){case"cell":{const r=Wo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Wo(e.start,t,n),o=Wo(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}}}}},Mc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return ao(e)?Ms(e,yr(e),r=>{const o=zf(r,t,n);return o===null?null:tn(o)}):e},zc=(e,t)=>{Fn(e.row,`${t} origin.row`),Fn(e.col,`${t} origin.col`)},Pn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Ko=(e,t)=>`${Pn("R",e.row,e.absRow,t.row)}${Pn("C",e.col,e.absCol,t.col)}`,Nf=(e,t)=>{const n=Ds(e);switch(e.kind){case"cell":return`${n}${Ko(e,t)}`;case"range":return`${n}${Ko(e.start,t)}:${Ko(e.end,t)}`;case"column":return`${n}${Pn("C",e.start.col,e.start.abs,t.col)}:${Pn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Pn("R",e.start.row,e.start.abs,t.row)}:${Pn("R",e.end.row,e.end.abs,t.row)}`}},uo=(e,t)=>(zc(t,"toR1C1"),ao(e)?Ms(e,yr(e),n=>Nf(n,t)):e),Ul=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===co){const l=e.charCodeAt(o+1)===Ec,c=ds(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Oc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=ds(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}}},Xl=(e,t)=>{const n=Ul(e,t,Af),r=Ul(e,n===null?t:n.end,Ef);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}},Ff=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}}},Pf=(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,_f=(e,t)=>{const n=Xl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===jn){const r=Xl(e,n.end+1);if(r!==null){const o=Pf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Ff(n)}},qf=e=>Lc(e,_f),If=Dc(qf),_n=(e,t)=>e.rel?t+e.n:e.n-1,Gl=(e,t)=>{const n=_n(e.row,t.row),r=_n(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},jf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Gl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Gl(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=_n(e.start,t.row),s=_n(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=_n(e.start,t.col),s=_n(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}}}},Rr=(e,t)=>(zc(t,"fromR1C1"),ao(e)?Ms(e,If(e),n=>{const r=jf(n,t);return r===null?null:tn(r)}):e),Zl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Hf=e=>{switch(e.kind){case"cell":return{...e,...Zl(e.absCol,e.absRow)};case"range":{const t=Zl(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}}}}},Nc=(e,t)=>ao(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Fc=(e,t)=>{if(!Nc(e,t))return null;for(const n of yr(e))if(n.start<=t&&t<=n.end)return n;return null},Bf=(e,t)=>{const n=Fc(e,t);if(n===null)return null;const r=tn(Hf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Jl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===hr){const s=us(e,r,hr);if(s>t)return!1;n=hr,r=s;continue}Tf(o)||(n=o),r+=1}return $f(n)},Pc=(e,t)=>{if(!Nc(e,t))return null;for(const n of yr(e))if(n.start<=t&&t<=n.end)return Jl(e,n.start)?{replace:[n.start,n.end]}:null;return Jl(e,t)?{insertAt:t}:null},Kn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],fo=(e,t)=>`[$${e}-${t}]`,Vf=new Map(Kn.map(e=>[fo(e.symbol,e.lcid),e])),Wf=new Map(Kn.filter((e,t)=>Kn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Kn.map(e=>[fo(e.symbol,e.lcid),e.code]));const Kf=new Set([...Kn.map(e=>e.symbol),...Kn.map(e=>e.code),"¥"]),Yf=20,Uf="yyyy/MM/dd",_c=/yyyy|MM|dd|HH|mm|ss/g,qc=" -+/():!^&'~{}<>=",Xf="$¥€£₩₹¥",ps=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},Gf=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},Zf=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const R=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:R}),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(qc.includes(o)||Xf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ht=e=>e===void 0?{}:{locale:e},Jf=/^(0|#,##0)(?:\.(0+))?$/,Ql=(e,t,n,r)=>{if(t!==null){const o=Vf.get(fo(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Kf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ht(r.locale)}},Qf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const L of e)switch(L.kind){case"locale":break;case"literal":r?u+=L.text:c+=L.text;break;case"digits":if(r)return;n=L.text,r=!0;break;case"currency":if(o!==null)return;o=L;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=Jf.exec(n);if(h===null)return;const m=h[1]==="#,##0",R=h[2]===void 0?0:h[2].length,N=c.trim(),H=u.trim();if(s)return l===0&&o===null&&!m&&N===""&&H===""?{type:"scientific",decimals:R,...ht(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&H===""?{type:"percent",decimals:R,...ht(t.locale)}:void 0;if(H==="%"&&N===""&&o===null)return{type:"percent",decimals:R,scale:!1,...ht(t.locale)};if(o!==null)return N===""&&H===""?Ql(o.symbol,o.lcid,R,t):void 0;if(!(N!==""&&H!==""))return N!==""||H!==""?Ql(N+H,null,R,t):{type:"number",decimals:R,...m?{grouping:!0}:{},...ht(t.locale)}},ep=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),tp=(e,t)=>{const n=[...e.matchAll(_c)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},np=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":ep.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&tp(r,n)?{type:"date",pattern:r}:void 0},rp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ht(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ht(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ht(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ht(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ht(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ht(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),zs=(e,t)=>{const n=Gf(e).trim(),r=rp.get(n);if(r!==void 0)return r(t);const o=Zf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Qf(o,t);if(o.some(s=>s.kind==="date"))return np(o)}},op=(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:zs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},ar=e=>e===0?"":`.${"0".repeat(e)}`,Gr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Yf,sp=`${qc}.,`,ei=e=>e.includes('"')?null:[...e].every(t=>sp.includes(t))?e:`"${e}"`,lp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(_c)){const u=ei(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=ei(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=zs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},ip=e=>{const t=Wf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Gr(n))return null;const r=`#,##0${ar(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${fo(t.symbol,t.lcid)}${r}`},Ic=e=>{switch(e.type){case"text":return"@";case"date":return lp(e.pattern===void 0?Uf:e.pattern);case"number":return Gr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${ar(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Gr(t)?e.scale===!1?`0${ar(t)}"%"`:`0${ar(t)}%`:null}case"scientific":return Gr(e.decimals)?`0${ar(e.decimals)}E+00`:null;case"currency":return ip(e);default:return null}},ti="-−",cp=(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("")},ap=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=cp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},up=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},dp=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",u=z=>z>="0"&&z<="9"||l!==""&&l.includes(z)||n.decimal.includes(z)||c&&(z==="e"||z==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let R=0,N=0,H=0,L="";for(const z of o.slice(0,h))ti.includes(z)?R+=1:z==="("?N+=1:L+=z;for(const z of o.slice(m))ti.includes(z)?R+=1:z===")"?H+=1:L+=z;const _=R+N;if(N!==H||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&L.trim()!==""))return e;const U=ap(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(U===null)return e;const W=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,k=U.exponent+W;if(k>330||k<-330)return e;const x=up(U.integer,U.fraction,k,s);return Number.isFinite(Number(x))?x:e},ni="google-sheets-html-origin",jc=Object.freeze({group:",",decimal:"."}),ri=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"}),Hc=["top","right","bottom","left"],fp=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),pp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),hp=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"]),oi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],mp=Object.freeze({number:2,percent:3,currency:4,scientific:8}),gp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),wp=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"]),Cp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),bp=3,yp=1,Bc=-25569,Zr=86400,Rp=-693959,vp=2958465,Sp=" ",po=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,m)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},ro=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Ns=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},kp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Ep=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),R=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const N=po(R);for(const H of m.split(",")){const L=H.trim(),_=kp.exec(L);if(_!==null){const U=t.get(_[1]);if(U===void 0)t.set(_[1],new Map(N));else for(const[W,k]of N)U.set(W,k)}else if(L.toLowerCase()==="table"){const U=N.get("mso-displayed-decimal-separator"),W=N.get("mso-displayed-thousand-separator");U!==void 0&&(n=ps(ro(U))),W!==void 0&&(r=ps(ro(W)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:jc}},Ap="%_-*? ",Op=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Ap.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},xp=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,u=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+u-719468},Vc=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},Mn=(e,t)=>String(e).padStart(t,"0"),Wc=e=>{if(e<Rp||e>vp)return null;let t=Math.floor(e),n=Math.round((e-t)*Zr);n>=Zr&&(t+=1,n-=Zr);const r=Vc(t+Bc),o=`${Mn(r.year,4)}-${Mn(r.month,2)}-${Mn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Mn(s,2)}:${Mn(l,2)}:${Mn(n%60,2)}`},Tp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,$p=e=>{const t=Tp.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const u=xp(n,r,o),h=Vc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-Bc+(s*3600+l*60+c)/Zr},Fs=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),pn=e=>Fs(e).replaceAll('"',"&quot;"),Kc=e=>Fs(e).replaceAll("'","&#39;"),Lp=e=>Fs(e).replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
4
  `).replaceAll(`
5
- `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),Xr=(e,t)=>`${e}="${fn(JSON.stringify(t))}"`,Vc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Op=e=>{if(ot(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},xp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Tp=e=>{if(e.type==="text")return{1:1};const t=Pc(e);return t===null?null:{1:e.type==="date"?xp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):up[e.type],2:t,3:1}},Lp=/[;"'{}<>&\\]/,Wc=e=>e==="left"||e==="center"||e==="right",Yc=e=>e==="top"||e==="middle"||e==="bottom",$p=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"?Xe(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Xe(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Wc(e.align)&&t.push(`text-align:${e.align}`),Yc(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Lp.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 qc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(ei,l.style))continue;const c=l.color===void 0?"windowtext":Xe(l.color);c!==null&&t.push(`border-${s}:${ei[l.style]} ${c}`)}if(e.value!==void 0){const s=Pc(e.value);s!==null&&t.push(`mso-number-format:"${vp(s)}"`)}return t},Dp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Mp=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=Bc([n,...$p(e)].join(";"));let o=null;if(t!==void 0){const s=Tp(t);s!==null&&(o=Xr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},zp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Bn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Vc(o)?Op(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Ep(e.t):null,h=[];if(l?h.push(Xr("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(Xr("data-sheets-value",{1:3,3:c})):u!==null&&h.push(Xr("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${fn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${fn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${fn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${fn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const F=br(e.f,{row:n,col:r});F.includes("#REF!")||h.push(`x:fmla="${fn(F)}"`)}const g=Ap(s),R=e.link===void 0?g:`<a href="${fn(e.link)}">${g}</a>`;return`<td style='${t.style}'${h.map(F=>` ${F}`).join("")}>${R}</td>`},Kc=(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(Mp);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let u=0;u<e.cols;u+=1){const h=e.cells[s][u],g=h.fmt===void 0?void 0:r[h.fmt];c+=zp(h,g===void 0?Dp:g,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Ql}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${tc}='${Bc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Ql}>`},us=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Uc=(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&&us(n,l)}const o=e.getAttribute("style");return o!==null&&us(n,ao(o)),n},Fp=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"}},Np=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"},Pp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),_p={pt:1.5,unit:"px"},ni=e=>{let t=null,n=null;const r=[];for(const u of $s(e)){const h=u.toLowerCase(),g=Fp(u);ip.has(h)?n=h:g!==null?t=g:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=Pp.get(n),s=o===void 0?Np(t===null?_p:t):o,l=r.join(" ");if(l===""||cp.has(l.toLowerCase()))return{style:s};const c=Xe(l);return c===null||c.length===9?null:{style:s,color:c}},qp=e=>e.style==="thin"&&e.color==="#cccccc",Ip=e=>{const t=Xe(e);if(t!==null)return t;for(const n of $s(e)){const r=Xe(n);if(r!==null)return r}return null},jp=e=>{const t=eo($s(e.split(",")[0]).join(" ").trim()).trim();return t===""||ap.has(t.toLowerCase())?null:t},Hp=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},Bp=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},Vp=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"},Wp=new Set(["normal","pre-wrap","pre-line"]),Yp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const N=o.toLowerCase();(N==="bold"||N==="bolder"||Number(N)>=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=Bp(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:Xe(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),g=h===void 0?null:Ip(h);g!==null&&g.length!==9&&(r.background=g);const R=e.get("text-align"),F=R===void 0?"":R.toLowerCase();Wc(F)&&(r.align=F);const H=e.get("vertical-align"),$=H===void 0?"":H.toLowerCase();Yc($)&&(r.verticalAlign=$);const _=e.get("font-family"),U=_===void 0?null:jp(_);U!==null&&(r.fontFamily=U);const W=e.get("font-size"),S=W===void 0?null:Hp(W);S!==null&&(r.fontSize=S);const x=e.get("white-space");x!==void 0&&Wp.has(x.toLowerCase())&&(r.wrap=!0);const z={},I=e.get("border"),T=I===void 0?null:ni(I);for(const N of qc){const O=e.get(`border-${N}`),m=O===void 0?T:ni(O);m!==null&&!(n==="sheets"&&qp(m))&&(z[N]=m)}return Object.keys(z).length>0&&(r.borders=z),r},ri=e=>{e.text!==""&&!e.text.endsWith(`
5
+ `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),Jr=(e,t)=>`${e}="${pn(JSON.stringify(t))}"`,Yc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Dp=e=>{if(ot(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Mp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},zp=e=>{if(e.type==="text")return{1:1};const t=Ic(e);return t===null?null:{1:e.type==="date"?Mp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):mp[e.type],2:t,3:1}},Np=/[;"'{}<>&\\]/,Uc=e=>e==="left"||e==="center"||e==="right",Xc=e=>e==="top"||e==="middle"||e==="bottom",Fp=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"?Ze(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Ze(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Uc(e.align)&&t.push(`text-align:${e.align}`),Xc(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Np.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 Hc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(ri,l.style))continue;const c=l.color===void 0?"windowtext":Ze(l.color);c!==null&&t.push(`border-${s}:${ri[l.style]} ${c}`)}if(e.value!==void 0){const s=Ic(e.value);s!==null&&t.push(`mso-number-format:"${Op(s)}"`)}return t},Pp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},_p=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=Kc([n,...Fp(e)].join(";"));let o=null;if(t!==void 0){const s=zp(t);s!==null&&(o=Jr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},qp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Wn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Yc(o)?Dp(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?$p(e.t):null,h=[];if(l?h.push(Jr("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(Jr("data-sheets-value",{1:3,3:c})):u!==null&&h.push(Jr("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${pn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${pn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${pn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${pn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const N=Rr(e.f,{row:n,col:r});N.includes("#REF!")||h.push(`x:fmla="${pn(N)}"`)}const m=Lp(s),R=e.link===void 0?m:`<a href="${pn(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(N=>` ${N}`).join("")}>${R}</td>`},Gc=(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(_p);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let u=0;u<e.cols;u+=1){const h=e.cells[s][u],m=h.fmt===void 0?void 0:r[h.fmt];c+=qp(h,m===void 0?Pp:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${ni}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${oc}='${Kc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${ni}>`},hs=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Zc=(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&&hs(n,l)}const o=e.getAttribute("style");return o!==null&&hs(n,po(o)),n},Ip=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"}},jp=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"},Hp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),Bp={pt:1.5,unit:"px"},si=e=>{let t=null,n=null;const r=[];for(const u of Ns(e)){const h=u.toLowerCase(),m=Ip(u);fp.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=Hp.get(n),s=o===void 0?jp(t===null?Bp:t):o,l=r.join(" ");if(l===""||pp.has(l.toLowerCase()))return{style:s};const c=Ze(l);return c===null||c.length===9?null:{style:s,color:c}},Vp=e=>e.style==="thin"&&e.color==="#cccccc",Wp=e=>{const t=Ze(e);if(t!==null)return t;for(const n of Ns(e)){const r=Ze(n);if(r!==null)return r}return null},Kp=e=>{const t=ro(Ns(e.split(",")[0]).join(" ").trim()).trim();return t===""||hp.has(t.toLowerCase())?null:t},Yp=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},Up=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},Xp=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"},Gp=new Set(["normal","pre-wrap","pre-line"]),Zp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const F=o.toLowerCase();(F==="bold"||F==="bolder"||Number(F)>=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=Up(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:Ze(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),m=h===void 0?null:Wp(h);m!==null&&m.length!==9&&(r.background=m);const R=e.get("text-align"),N=R===void 0?"":R.toLowerCase();Uc(N)&&(r.align=N);const H=e.get("vertical-align"),L=H===void 0?"":H.toLowerCase();Xc(L)&&(r.verticalAlign=L);const _=e.get("font-family"),U=_===void 0?null:Kp(_);U!==null&&(r.fontFamily=U);const W=e.get("font-size"),k=W===void 0?null:Yp(W);k!==null&&(r.fontSize=k);const x=e.get("white-space");x!==void 0&&Gp.has(x.toLowerCase())&&(r.wrap=!0);const z={},I=e.get("border"),T=I===void 0?null:si(I);for(const F of Hc){const O=e.get(`border-${F}`),g=O===void 0?T:si(O);g!==null&&!(n==="sheets"&&Vp(g))&&(z[F]=g)}return Object.keys(z).length>0&&(r.borders=z),r},li=e=>{e.text!==""&&!e.text.endsWith(`
6
6
  `)&&(e.text+=`
7
- `)},Kp=e=>{const t=e.getAttribute("style");return t!==null&&ao(t).get("mso-spacerun")==="yes"},Up=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){pp.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&ri(t);continue}const o=r.node;if(o.nodeType===hp){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
8
- `);continue}if(o.nodeType!==mp)continue;const s=o,l=s.localName;if(dp.has(l)||Kp(s))continue;if(l==="br"){t.text+=`
9
- `;continue}const c=t.mode==="collapse"&&fp.has(l);if(c&&ri(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const u=s.getAttribute("href");u!==null&&(t.href=u)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let u=s.lastChild;u!==null;u=u.previousSibling)n.push({kind:"enter",node:u})}},Xp=(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&&Zp(l.element,t,n,r)},Gp=(e,t)=>{const n=e.replaceAll(Cp," ");if(t==="pre")return n;const r=n.split(`
7
+ `)},Jp=e=>{const t=e.getAttribute("style");return t!==null&&po(t).get("mso-spacerun")==="yes"},Qp=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Cp.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&li(t);continue}const o=r.node;if(o.nodeType===bp){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
8
+ `);continue}if(o.nodeType!==yp)continue;const s=o,l=s.localName;if(gp.has(l)||Jp(s))continue;if(l==="br"){t.text+=`
9
+ `;continue}const c=t.mode==="collapse"&&wp.has(l);if(c&&li(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const u=s.getAttribute("href");u!==null&&(t.href=u)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let u=s.lastChild;u!==null;u=u.previousSibling)n.push({kind:"enter",node:u})}},eh=(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&&nh(l.element,t,n,r)},th=(e,t)=>{const n=e.replaceAll(Sp," ");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
- `)},Zp=(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)}us(t,Uc(e,r))},Jp=(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"?Hc(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<ti.length?ti[l]:null}return null},Xc=(e,t,n)=>t!==void 0&&Vc(t)?lp(e,t,n):e,Qp=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&ot(c)!==null)if(n!==void 0&&n.type==="date"){const u=Hc(Number(c));if(u!==null)return u}else return c;return Xc(t,n,r)},eh=(e,t,n,r)=>{const o=Uc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Vp(o)};for(const g of oh(e))Up(g,l);Xp(l,o,s,r.rules);const c=Gp(l.text,l.mode),u=Yp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),R=g===null?void 0:Qf(g,r.options);R!==void 0&&(u.value=R);const F=e.getAttribute("data-sheets-value"),H=F===null?null:Jp(F,R);h.t=H===null?Xc(c,R,_c):H;const $=e.getAttribute("data-sheets-formula");$?.startsWith("=")&&(h.f=$);const _=e.getAttribute("data-sheets-hyperlink"),U=_!==null?_:l.href,W=U===null?null:on(U);W!==null&&(h.link=W);const S=e.getAttribute("data-sheets-note");S!==null&&S!==""&&(h.note=S)}else{const g=o.get("mso-number-format"),R=g===void 0?void 0:Ls(as(eo(g)),r.options);R!==void 0&&(u.value=R),h.t=Qp(e,c,R,r.separators);const F=e.getAttribute("x:fmla");F?.startsWith("=")&&(h.f=io(F,{row:t,col:n}));const H=l.href===null?null:on(l.href);H!==null&&(h.link=H)}return{cell:h,format:u}},ds=(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},th=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)},nh=(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]))},Gc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:ao(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:th(l);if(c!==null)return Math.min(c,rn)}const o=nh(e,t);return o===null?null:Math.min(o,rn)},rh=(e,t)=>{const n=[],r=o=>{const s=Gc(o,"width");for(let l=ds(o,"span",Ss);l>0&&n.length<t;l-=1)n.push(s)};for(const o of mr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of mr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*mr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*oh(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*sh(e){for(const t of["thead","tbody","tfoot"])for(const n of mr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of mr(n))o.localName==="tr"&&(yield o)}}const Vo=()=>({t:""}),lh=(e,t,n)=>{const r=hc(),o=[],s=[],l=[];let c=0;for(const H of sh(e)){const $=o.length,_=($+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const U=[];for(let S=0;S<l.length;S+=1)l[S]>0&&(U[S]=Vo(),l[S]-=1);let W=0;for(const S of mr(H)){const x=S.localName;if(x!=="td"&&x!=="th")continue;for(;U[W]!==void 0;)W+=1;const z=ds(S,"colspan",Ss),I=ds(S,"rowspan",ic),T=($+1)*Math.max(c,W+z);if(T>n)return{outcome:"limit",cells:T};const N=eh(S,$,W,t),O=r.intern(N.format);O!==void 0&&(N.cell.fmt=O),U[W]=N.cell;for(let m=1;m<z;m+=1)U[W+m]===void 0&&(U[W+m]=Vo());if(I>1)for(let m=0;m<z;m+=1){const p=I-1,C=W+m;l[C]=l[C]===void 0||l[C]<p?p:l[C]}W+=z}U.length>c&&(c=U.length),o.push(U),s.push(Gc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const $=[];for(let _=0;_<c;_+=1){const U=H[_];$.push(U===void 0?Vo():U)}return $}),h=rh(e,c),g=h.length===c&&h.every(H=>H!==null)?h.map(H=>H===null?0:H):void 0,R=s.every(H=>H!==null)?s.map(H=>H===null?0:H):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:vs(),formats:[...r.entries],validations:[],cells:u,...g===void 0?{}:{colWidths:g},...R===void 0?{}:{rowHeights:R},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Zc=(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=yp(o);return lh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},ye=(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)}),wn=(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}),At=e=>e.reduce((t,n)=>t+st(n).rows*st(n).cols,0),Zt=(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}))}},sn=(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)}},qt=(e,t)=>e.row===t.row&&e.col===t.col,Jc=(e,t)=>e===void 0?Ml(void 0,void 0,t()):Ml(e.align,e.value,e.align===void 0?t():""),Gr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Wn=(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}},Zr=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}),Qc=e=>e.isCellReadOnly!==void 0,We=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,ih=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],ch=()=>!0,ah=e=>{const t=new WeakMap,n={};for(const r of ih)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:ch}),n},uh=/^data-[a-z0-9-]+$/,dh=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},fh=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!dh(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(!uh.test(o))throw new RangeError(`[spreadsheet] getCellAttributes key must be a lowercase data-* name (got ${JSON.stringify(o)})`);if(o.startsWith("data-aqsp")||o.startsWith("data-aqvs")||o==="data-row"||o==="data-col")throw new RangeError(`[spreadsheet] getCellAttributes key ${JSON.stringify(o)} shadows a package- or engine-emitted cell attribute`);if(typeof s!="string")throw new RangeError(`[spreadsheet] getCellAttributes value for ${JSON.stringify(o)} must be a string (got ${typeof s})`)}return r},cr=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},Pn=(e,t)=>{for(const n of t)if(cr(e,n))return!0;return!1},ph=(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},fs=(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,u=c?s.rows:e.rows,h=c?s.cols:e.cols,g=l?n:{row:t.startRow,col:t.startCol},R=Math.min(u,r-g.row),F=Math.min(h,o-g.col);return R<=0||F<=0?null:ye(g,{row:g.row+R-1,col:g.col+F-1})},ea=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=fs({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},g=u.endRow-u.startRow+1,R=u.endCol-u.startCol+1,F=[];for(let H=0;H<g;H+=l){const $=[];for(let U=0;U<R;U+=c){const W={row:h.row+H,col:h.col+U};$.push(W),F.push(W)}const _=Math.min(l,g-H);for(let U=0;U<_;U+=1){const W=h.row+H+U,S=e[U];for(let x=0;x<$.length;x+=1){const z=x*c,I=Math.min(c,R-z);for(let T=0;T<I;T+=1)s(W,h.col+z+T,S[T],$[x])}}}return F},hh=(e,t,n,r,o)=>{const s=[];return ea(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},oi=(e,t,n,r,o,s)=>{const l=[],c=ea(e,t,n,r,o,(u,h,g,R)=>{const F=s(g,u,h,R);F!==null&&l.push({...F,row:u,col:h})});return{edits:l,tiles:c}},ta=(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)})`)},mh=(e,t)=>{ta(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},gh=(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(ye({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(ye({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(ye({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(ye({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},wh=(e,t,n,r)=>{ta(t,n);const o=st(t).rows,s=st(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,g=u>=t.startRow&&u<=t.endRow;for(let R=n.startCol;R<=n.endCol;R+=1){if(g&&R>=t.startCol&&R<=t.endCol)continue;const F=t.startCol+((R-t.startCol)%s+s)%s,H=h*2**21+F;let $=c.get(H);$===void 0&&($={value:e(h,F),origin:{row:h,col:F}},c.set(H,$)),l.push(r($.value,$.origin,{row:u,col:R}))}}return l},na=(e,t,n)=>{const r=Wn(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:wt(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=Yn(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},ra=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Lc(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},uo=["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"],Ch=/^[A-Z]$/,bh=/^[A-Za-z]$/,yh=/^Key([A-Z])$/,oa=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"]),Rh=e=>Ch.test(e)||oa.has(e),Jt=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||!Rh(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}},vh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,sa=e=>{if(bh.test(e.key))return e.key.toUpperCase();const t=yh.exec(e.code);return t!==null?t[1]:oa.has(e.code)?e.code:null},nr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:sa(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),be=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),kh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Sh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},yr=[...kh(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("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"},...Sh(),be("bold","Ctrl+B","both","toggle bold"),be("italic","Ctrl+I","both","toggle italic"),be("underline","Ctrl+U","both","toggle underline"),be("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),be("clearFormatting","Ctrl+Backslash","idle","clear formatting"),be("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),be("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),be("alignLeft","Ctrl+Shift+L","both","align left"),be("alignCenter","Ctrl+Shift+E","both","align center"),be("alignRight","Ctrl+Shift+R","both","align right"),be("formatNumber","Ctrl+Shift+Digit1","both","number format"),be("formatTime","Ctrl+Shift+Digit2","both","time format"),be("formatDate","Ctrl+Shift+Digit3","both","date format"),be("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),be("formatPercent","Ctrl+Shift+Digit5","both","percent format"),be("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),be("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),be("bordersClear","Alt+Shift+Digit6","idle","clear borders"),be("borderTop","Alt+Shift+Digit1","idle","top border"),be("borderRight","Alt+Shift+Digit2","idle","right border"),be("borderBottom","Alt+Shift+Digit3","idle","bottom border"),be("borderLeft","Alt+Shift+Digit4","idle","left border"),be("insertLink","Ctrl+K","idle","insert / edit hyperlink"),be("insertNote","Shift+F2","idle","insert / edit note"),be("insertComment","Ctrl+Alt+M","idle","insert comment"),be("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),be("openValidationList","Alt+ArrowDown","idle","open the validation list"),be("fillDown","Ctrl+D","idle","fill down"),be("fillRight","Ctrl+R","idle","fill right"),be("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),be("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),be("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),be("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),be("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),be("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),be("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),be("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),be("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),be("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),be("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],Wo=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),si=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Eh=e=>{const t=Jt(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 si?si[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},to=(e,t)=>e.column==="both"||e.column===t,Ah=Array.from(new Set(yr.filter(e=>!e.rebindable&&to(e,"idle")).map(e=>e.chord))),Ms=new Set(yr.filter(e=>e.command!==void 0&&to(e,"editing")).map(e=>e.command)),Oh=new Set(yr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),la=e=>{const t={};for(const n of uo)t[n]=e(n);return t},ia=la(e=>yr.filter(t=>t.command===e).map(t=>t.chord)),xh=e=>{const t=new Map;for(const n of uo){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},Th=e=>{const t=new Set(uo);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(Oh.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`)}}}},Lh=(e,t)=>{const n=Jt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Ms.has(e);for(const o of yr)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})`)},$h=e=>{e!==void 0&&Th(e);const t=la(r=>{const o=e===void 0?void 0:e[r];return o===void 0?ia[r]:o===null?[]:o});for(const r of uo)for(const o of t[r])Lh(r,o);const n=new Map;for(const[r,o]of xh(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},li=(e,t)=>{const n=sa(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(vh({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},zs=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],ii=[...Ge.VIRTUAL_SCROLL_LABEL_KEYS,...zs],ps=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),ca=Object.freeze({en:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ps.en}),ja:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ps.ja})}),hn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,ci=e=>e==="commentCount"||e==="listMore",Dh=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 ${hn(t)}`);for(const n of zs){const r=e[n];if(!(ci(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=ci(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${hn(r)}`)}}},Mh=e=>{const t={};let n=!1;for(const r of Ge.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},zh=(e,t,n)=>{e[t]=n},aa=(e,t)=>{const n=Ge.resolveVirtualScrollLocale(e);if(t===void 0)return ca[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${hn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!ii.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${ii.join(", ")}`);const s={...Ge.resolveVirtualScrollLabels(n,Mh(t)),...ps[n]};for(const l of zs){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&zh(s,l,c)}return Dh(s),Object.freeze(s)},Fh=e=>{const t={};for(const n of Ge.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Ne=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},ai={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Nh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Ph=(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}`}},Yo=(e,t)=>{const n=r=>(o,s)=>`${e} ${Ph(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")})},_h=Object.freeze({list:"Value must be one of the list items.",number:Yo("Value must be a number",ai),textLength:Yo("Text length must be",ai),date:Yo("Value must be a date",Nh),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}.`}),qh=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} を満たす値を入力してください。`}),Ko=Object.freeze({en:_h,ja:qh}),Ih=Object.freeze({ok:!0}),jh="TRUE",Hh="FALSE",Bh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Vh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Wh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Yh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Kh=/^[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])?)+$/,ui=e=>{const t=e.trim();if(!(Wh.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),g=u+h,R=g.search(/[^0]/);return R<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:g.slice(R).replace(/0+$/,""),point:u.length+l-R}},Uh=e=>e===1?-1:e===-1?1:0,Xh=(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:Uh(n)},Gh=(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}},di=e=>{const t=Yh.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>Gh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Zh=(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},Jh=(e,t)=>e<t?-1:e>t?1:0,Qh=e=>e==="between"||e==="notBetween",em=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Qh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},tm=(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}},Uo=(e,t,n,r,o,s)=>{const l=em(e,t,n,r);return l===null?!0:o===null?!1:tm(e,s(o,l.a),l.b===null?0:s(o,l.b))},nm=e=>Number.isFinite(e)?e:null,rm=e=>{let t=0;for(const n of e)t+=1;return t},om=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),sm=(e,t)=>{switch(e.op){case"isEmail":return Kh.test(t);case"isUrl":return om(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)}},lm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,ua=e=>({checked:e.checked===void 0?jh:e.checked,unchecked:e.unchecked===void 0?Hh:e.unchecked}),im=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Bh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${hn(e.op)} for type "${e.type}"`);return;case"text":if(!Vh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${hn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${hn(e.type)}`)}},cm=(e,t,n)=>{switch(e.type){case"list":return dm(e).has(t);case"number":return Uo(e.op,e.a,e.b,ui,ui(t),Xh);case"textLength":return Uo(e.op,e.a,e.b,nm,rm(t),Jh);case"date":return Uo(e.op,e.a,e.b,di,di(t),Zh);case"text":return sm(e,t);case"checkbox":{const r=ua(e);return t===r.checked||t===r.unchecked}default:return n===void 0||lm(n(e.formula))}},da=(e,t,n)=>(im(e),t===""||cm(e,t,n)),fi=e=>e===void 0?void 0:e.trim(),am=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),fi(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(),fi(e.b));case"text":return um(e,t.text);case"checkbox":{const n=ua(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},um=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},pi=new WeakMap,dm=e=>{const t=pi.get(e);if(t!==void 0)return t;const n=new Set(e.values);return pi.set(e,n),n},fa=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Ko,n)){const o=Object.keys(Ko).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${hn(n)}`)}return da(e,t,r)?Ih:{ok:!1,message:e.errorMessage===void 0?am(e,Ko[n]):e.errorMessage}},fm=e=>e.type!=="custom",pm=(e,t)=>fm(e)&&!da(e,t,void 0),pa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),ha=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),ma=(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,ga=(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),wa=(e,t)=>pa(e,t),Ca=(e,t)=>pa(e,t),ba=(e,t)=>ha(e,t),ya=(e,t)=>ha(e,t),mn=(e,t,n)=>ma(e,t,n),gn=(e,t,n)=>ma(e,t,n),Rr=(e,t,n)=>ga(e,t,n),vr=(e,t,n)=>ga(e,t,n),hm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Gt=1,ar=3,Pr=e=>`${-Math.min(ar,Math.max(0,Math.floor(e)))}px`,Ra=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),mm=16,gm=450,wm=e=>e>4?Math.floor(gm/(5*e)):mm,rr=(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},hi=()=>({rowLeft:rr("row","left"),rowRight:rr("row","right"),colAbove:rr("column","above"),colBelow:rr("column","below"),cross:rr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),va=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],_r=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},qr=(e,t)=>Math.min(Math.max(e,0),t),mi="inset(100%)",In=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Cm=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,In([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const F=`${t.height}px`;e.rowLeft.style.height=F,e.rowRight.style.height=F}const g=`translate(${qr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;g!==s.rowLeftTransform&&(s.rowLeftTransform=g,e.rowLeft.style.transform=g);const R=`translate(${qr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;R!==s.rowRightTransform&&(s.rowRightTransform=R,e.rowRight.style.transform=R)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,In([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const F=`${t.width}px`;e.colAbove.style.width=F,e.colBelow.style.width=F}const g=`translate(${t.left}px, ${qr(t.top,n.clampHeight)-n.clampHeight}px)`;g!==s.colAboveTransform&&(s.colAboveTransform=g,e.colAbove.style.transform=g);const R=`translate(${t.left}px, ${qr(t.top+t.height,n.clampHeight)}px)`;R!==s.colBelowTransform&&(s.colBelowTransform=R,e.colBelow.style.transform=R)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,In([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--_aqsp-band-${u})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const g=`translate(${t.left}px, ${t.top}px)`;g!==s.crossTransform&&(s.crossTransform=g,e.cross.style.transform=g)}},gi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,In([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,In([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,In([e.cross],!1))},wi=e=>{for(const t of va(e))t.remove()},bm=(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)},ym=Object.freeze([]),Ci=e=>e.dividers[0]??e.active,Rm={left:"0px",right:"0px",width:""},vm={top:"0px",bottom:"0px",height:""},bi=()=>({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],dividers:[]}),yi=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Ri=6,km=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:g,getIsFillDragging:R,fillFrameRef:F,resizeGuideFrameRef:H,fillHandleNodeRef:$,enableFillHandle:_,frozenCols:U,frozenRows:W,trailingCols:S,trailingRows:x,sinkAriaLabel:z,sinkReadOnly:I,sinkKeyShortcuts:T,onSinkMouseDown:N,editPaintRef:O,highlightRef:m,highlightColors:p,popoverAnchors:C,interactiveAnchorRef:v,tipAnchorRef:k})=>{const b=i.useRef(null),y=i.useRef(null),a=i.useRef(null),f=i.useRef(new Map(yi.map(M=>[M,bi()]))),E=i.useCallback(M=>{const B=f.current.get(M);if(B!==void 0)return B;const X=bi();return f.current.set(M,X),X},[]),d=i.useCallback((M,B,X)=>{if(M===null)return;const V=M.style;V.left!==B.left&&(V.left=B.left),V.right!==B.right&&(V.right=B.right),V.width!==B.width&&(V.width=B.width),V.top!==X.top&&(V.top=X.top),V.bottom!==X.bottom&&(V.bottom=X.bottom),V.height!==X.height&&(V.height=X.height)},[]),L=i.useCallback((M,B,X)=>{if(!(M.bandClampWidth===B&&M.bandClampHeight===X)){M.bandClampWidth=B,M.bandClampHeight=X;for(const V of M.bandPool)_r(V,B,X);M.dragBand!==null&&_r(M.dragBand,B,X)}},[]),A=i.useRef({rowAxis:e,colAxis:t});A.current={rowAxis:e,colAxis:t};const D=i.useCallback((M,B,X)=>{const V=M.dividerSlots[B];V===null||M.dividerShown[B]===X||(M.dividerShown[B]=X,V.style.display=X?"":"none")},[]),q=i.useRef({x:0,y:0}),j=i.useRef(null),Y=i.useCallback((M,B)=>{const X=n.current,V=X?.getFrozenSize()??hm,Q=X?.getViewportSize(),le=Q?.width??-1,re=Q?.height??-1,Oe=q.current;Oe.x=M,Oe.y=B;let ke=j.current;if(ke===null||ke.frozenCols!==V.cols||ke.frozenWidth!==V.width||ke.frozenRows!==V.rows||ke.frozenHeight!==V.height||ke.trailingCols!==V.trailingCols||ke.trailingWidth!==V.trailingWidth||ke.trailingVisibleWidth!==V.trailingVisibleWidth||ke.trailingRows!==V.trailingRows||ke.trailingHeight!==V.trailingHeight||ke.trailingVisibleHeight!==V.trailingVisibleHeight||ke.bodyWidth!==le||ke.bodyHeight!==re){const ie=V.trailingVisibleWidth,ce=V.trailingVisibleHeight,me=V.cols<=0&&V.trailingCols<=0?[{kind:"m",map:oe=>oe-Oe.x,clamp:le,style:Rm,seamLead:!1,seamTrail:!1}]:[...V.cols>0?[{kind:"f",map:oe=>oe,clamp:V.width,style:{left:"0px",width:`${V.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:oe=>oe-Oe.x-V.width,clamp:Math.max(0,le-V.width-ie),style:{left:`${V.width}px`,right:`${ie}px`,width:""},seamLead:V.cols>0,seamTrail:V.trailingCols>0},...V.trailingCols>0?[{kind:"t",map:oe=>oe-A.current.colAxis.totalSize()+ie,clamp:ie,style:{left:"",right:"0px",width:`${ie}px`},seamLead:!0,seamTrail:!1}]:[]],Ce=V.rows<=0&&V.trailingRows<=0?[{kind:"m",map:oe=>oe-Oe.y,clamp:re,style:vm,seamLead:!1,seamTrail:!1}]:[...V.rows>0?[{kind:"f",map:oe=>oe,clamp:V.height,style:{top:"0px",height:`${V.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:oe=>oe-Oe.y-V.height,clamp:Math.max(0,re-V.height-ce),style:{top:`${V.height}px`,bottom:`${ce}px`,height:""},seamLead:V.rows>0,seamTrail:V.trailingRows>0},...V.trailingRows>0?[{kind:"t",map:oe=>oe-A.current.rowAxis.totalSize()+ce,clamp:ce,style:{top:"",bottom:"0px",height:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],fe=[];for(const oe of me)for(const Se of Ce)fe.push({nodes:E(`${oe.kind}${Se.kind}`),xKind:oe.kind,yKind:Se.kind,mapX:oe.map,clampWidth:oe.clamp,xStyle:oe.style,xSeamLead:oe.seamLead,xSeamTrail:oe.seamTrail,mapY:Se.map,clampHeight:Se.clamp,yStyle:Se.style,ySeamLead:Se.seamLead,ySeamTrail:Se.seamTrail});ke={frozenCols:V.cols,frozenWidth:V.width,frozenRows:V.rows,frozenHeight:V.height,trailingCols:V.trailingCols,trailingWidth:V.trailingWidth,trailingVisibleWidth:V.trailingVisibleWidth,trailingRows:V.trailingRows,trailingHeight:V.trailingHeight,trailingVisibleHeight:V.trailingVisibleHeight,bodyWidth:le,bodyHeight:re,ctxs:fe},j.current=ke}const He=V.width>0,Be=V.trailingWidth>0,Ie=V.height>0,Re=V.trailingHeight>0;for(const ie of ke.ctxs)d(ie.nodes.container,ie.xStyle,ie.yStyle),L(ie.nodes,ie.clampWidth,ie.clampHeight),D(ie.nodes,0,He),D(ie.nodes,1,Be),D(ie.nodes,2,Ie),D(ie.nodes,3,Re);return ke.ctxs},[n,E,d,L,D]),G=i.useCallback((M,B,X)=>{M.dividerSlots[B]=X,M.dividerShown[B]=!1,M.dividers.length=0;for(const V of M.dividerSlots)V!==null&&M.dividers.push(V)},[]),J=i.useCallback(M=>{const B=()=>E(M);return{container:X=>{const V=B();V.container=X,X===null&&(V.fillPool.length=0,V.bandPool.length=0,V.dragBand=null,V.bandClampWidth=-1,V.bandClampHeight=-1)},dividerXLeading:X=>G(B(),0,X),dividerXTrailing:X=>G(B(),1,X),dividerYLeading:X=>G(B(),2,X),dividerYTrailing:X=>G(B(),3,X),active:X=>{B().active=X},dragRect:X=>{B().dragRect=X},marquee:X=>{B().marquee=X},fillPreview:X=>{B().fillPreview=X},resizeGuide:X=>{B().resizeGuide=X}}},[E,G]),te=i.useMemo(()=>Object.fromEntries(yi.map(M=>[M,J(M)])),[J]),ne=Math.min(Math.max(0,U),t.count),ve=wa(t,ne),Ee=Math.min(Math.max(0,W),e.count),Le=Ca(e,Ee),De=S===void 0?0:Math.min(Math.max(0,S),t.count-ne),et=ba(t,De),he=x===void 0?0:Math.min(Math.max(0,x),e.count-Ee),Pe=ya(e,he),Ye=i.useRef(null),tt=i.useRef("add"),Ot=i.useRef(s);Ot.current=s;const xt=i.useRef(!1),je=Ge.useWheelBridge(n,{enableBridge:!s}),Ct=i.useCallback(M=>(r.current=M,je(M)),[r,je]),Cn=i.useCallback((M,B)=>({top:B.mapY(e.offsetOf(M.startRow)),bottom:B.mapY(e.offsetOf(M.endRow)+e.sizeOf(M.endRow)),left:B.mapX(t.offsetOf(M.startCol)),right:B.mapX(t.offsetOf(M.endCol)+t.sizeOf(M.endCol))}),[e,t]),lt=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const{top:X,bottom:V,left:Q,right:le}=Cn(M,B),re=-B.clampHeight*Gt,Oe=B.clampHeight*(1+Gt),ke=-B.clampWidth*Gt,He=B.clampWidth*(1+Gt);if(V<re||X>Oe||le<ke||Q>He)return null;const Be=Math.max(X,re),Ie=Math.max(Q,ke);return{top:Be,left:Ie,width:Math.min(le,He)-Ie,height:Math.min(V,Oe)-Be}},[Cn]),kr=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const X=Cn(M,B),V=-B.clampHeight*Gt,Q=B.clampHeight*(1+Gt),le=-B.clampWidth*Gt,re=B.clampWidth*(1+Gt),Oe=Math.min(Math.max(X.top,V),Q),ke=Math.min(Math.max(X.left,le),re);return{top:Oe,left:ke,width:Math.min(Math.max(X.right,le),re)-ke,height:Math.min(Math.max(X.bottom,V),Q)-Oe}},[Cn]),bn=i.useCallback(()=>{if(m===void 0)return null;const M=m.current;return M.row||M.column||M.intersection?M:null},[m]),se=i.useCallback((M,B,X)=>{const V=B.fillPool[0]?.node??Ci(B);for(const Q of va(X))M.insertBefore(Q,V)},[]),ue=i.useCallback((M,B,X,V)=>{const Q=kr(B,X);if(Q===null){gi(M);return}Cm(M,Q,X,V,mc(B,t.count)||gc(B,e.count))},[kr,e,t]),de=i.useCallback((M,B,X,V)=>{const Q=M.nodes.bandPool;for(;Q.length>X.length;){const le=Q.pop();le!==void 0&&wi(le)}if(V===null){M.nodes.dragBand!==null&&(wi(M.nodes.dragBand),M.nodes.dragBand=null);return}for(let le=0;le<X.length;le+=1){let re=Q[le];re===void 0&&(re=hi(),_r(re,M.clampWidth,M.clampHeight),se(B,M.nodes,re),Q.push(re)),ue(re,X[le],M,V)}},[se,ue]),jt=i.useCallback((M,B,X)=>{const V=M.nodes.container;if(V===null)return;if(B===null||X===null){M.nodes.dragBand!==null&&gi(M.nodes.dragBand);return}let Q=M.nodes.dragBand;Q===null&&(Q=hi(),_r(Q,M.clampWidth,M.clampHeight),se(V,M.nodes,Q),M.nodes.dragBand=Q),ue(Q,B,M,X)},[se,ue]),Ae=i.useCallback((M,B)=>{if(M!==null){if(B===null){M.style.display="none";return}M.style.display="block",M.style.transform=`translate(${B.left}px, ${B.top}px)`,M.style.width=`${B.width}px`,M.style.height=`${B.height}px`}},[]),Ht=i.useCallback((M,B,X,V)=>{const Q=V==="point"?null:bn();for(const le of Y(X,B))Ae(le.nodes.dragRect,lt(M,le)),jt(le,M,Q)},[lt,Y,Ae,bn,jt]),it=i.useCallback((M,B,X)=>{for(const V of Y(X,B))Ae(V.nodes.fillPreview,M===null?null:lt(M,V))},[lt,Y,Ae]),yn=i.useCallback((M,B,X)=>{for(const V of Y(X,B)){const Q=V.nodes.resizeGuide;if(Q===null)continue;if(M===null){Q.style.display="none";continue}const le=M.anchor==="trailing";if(M.axis==="col"){if(le&&V.xKind!=="t"){Q.style.display="none";continue}Q.style.display="block";const re=V.mapX(M.position);Q.style.transform=`translate(${le?Math.max(0,re):re}px, 0px)`,Q.style.width="1px",Q.style.height="100%"}else{if(le&&V.yKind!=="t"){Q.style.display="none";continue}Q.style.display="block";const re=V.mapY(M.position);Q.style.transform=`translate(0px, ${le?Math.max(0,re):re}px)`,Q.style.width="100%",Q.style.height="1px"}}},[Y]),Bt=i.useCallback((M,B,X,V,Q,le,re)=>{if(M===null)return;if(B===null||re<=0||le<=0){M.style.clipPath=mi;return}const Oe=gn(e,B.row,V),ke=mn(t,B.col,X),He=t.sizeOf(B.col),Be=e.sizeOf(B.row),Ie=ke>=le||Oe>=re,Re=B.col>=Q.cols&&ke<Q.width,ie=B.row>=Q.rows&&Oe<Q.height,ce=Q.trailingWidth>0&&B.col<t.count-Q.trailingCols&&ke+He>le-Q.trailingVisibleWidth,me=Q.trailingHeight>0&&B.row<e.count-Q.trailingRows&&Oe+Be>re-Q.trailingVisibleHeight;if(Ie||Re||ie||ce||me){M.style.clipPath=mi;return}M.style.clipPath="",M.style.transform=`translate(${ke}px, ${Oe}px)`;const Ce=`${He} ${Be}`;M.dataset.aqspAnchorSig!==Ce&&(M.dataset.aqspAnchorSig=Ce,M.style.width=`${He}px`,M.style.height=`${Be}px`)},[e,t]),Sr=i.useCallback((M,B,X)=>{if(C===void 0)return;const V=C.current,{width:Q,height:le}=M.getViewportSize(),re=M.getFrozenSize(),Oe={scroll:X,frozenCount:re.cols,trailingCount:re.trailingCols,extent:Q},ke={scroll:B,frozenCount:re.rows,trailingCount:re.trailingRows,extent:le};Bt(v===void 0?null:v.current,V.interactive,Oe,ke,re,Q,le),Bt(k===void 0?null:k.current,V.tip,Oe,ke,re,Q,le)},[C,v,k,Bt]),Kn=i.useCallback(()=>{const M=b.current,B=n.current;if(M===null||B===null)return;const X=B.getScrollPosition(),V=Math.max(0,X.y),Q=Math.max(0,X.x),le=o(),re=Y(Q,V),Oe=bn(),ke=Oe===null?ym:le.ranges.slice(-wm(re.length));for(const ie of re){const ce=ie.nodes.container;if(ce===null)continue;const me=ie.nodes.fillPool;for(let Ce=0;Ce<Math.max(me.length,le.ranges.length);Ce+=1){let fe=me[Ce];if(fe===void 0){const Fe=document.createElement("div");Fe.className="aqsp-selection-fill",Fe.setAttribute("data-aqsp-fill",""),Fe.style.display="none",ce.insertBefore(Fe,Ci(ie.nodes)),fe={node:Fe,last:{shown:!1,width:-1,height:-1,transform:""}},me.push(fe)}const oe=le.ranges[Ce],Se=oe===void 0?null:lt(oe,ie);if(Se===null)fe.last.shown&&(fe.last.shown=!1,fe.node.style.display="none");else{fe.last.shown||(fe.last.shown=!0,fe.node.style.display="block");const Fe=`translate(${Se.left}px, ${Se.top}px)`;Fe!==fe.last.transform&&(fe.last.transform=Fe,fe.node.style.transform=Fe),Se.width!==fe.last.width&&(fe.last.width=Se.width,fe.node.style.width=`${Se.width}px`),Se.height!==fe.last.height&&(fe.last.height=Se.height,fe.node.style.height=`${Se.height}px`)}}for(;me.length>le.ranges.length;)me.pop()?.node.remove();Ae(ie.nodes.active,lt(ye(le.active,le.active),ie)),de(ie,ce,ke,Oe)}const He=h(),Be=He===null||He.foreign?null:He;for(const ie of re){const ce=ie.nodes.marquee;if(ce===null)continue;const me=Be===null?null:lt(Be.range,ie),Ce=me!==null&&(ie.xSeamTrail&&me.left>=ie.clampWidth&&me.left<ie.clampWidth+ar||ie.xSeamLead&&me.left+me.width<=0&&me.left+me.width>-ar||ie.ySeamTrail&&me.top>=ie.clampHeight&&me.top<ie.clampHeight+ar||ie.ySeamLead&&me.top+me.height<=0&&me.top+me.height>-ar)?null:me;if(Ce===null)ce.style.display="none";else{ce.style.display="block",ce.style.transform=`translate(${Ce.left}px, ${Ce.top}px)`,ce.style.width=`${Ce.width}px`,ce.style.height=`${Ce.height}px`;const Se=Pr(Ce.top),Fe=Pr(Ce.left),bt=Pr(ie.clampHeight-(Ce.top+Ce.height)),ct=Pr(ie.clampWidth-(Ce.left+Ce.width)),yt=`${Se} ${ct} ${bt} ${Fe}`;yt!==ce.dataset.aqspOutsetSig&&(ce.dataset.aqspOutsetSig=yt,ce.style.setProperty("--aqsp-clip-outset-top",Se),ce.style.setProperty("--aqsp-clip-outset-right",ct),ce.style.setProperty("--aqsp-clip-outset-bottom",bt),ce.style.setProperty("--aqsp-clip-outset-left",Fe))}const fe=Ce===null?null:Be?.kind??null,oe=ce.dataset.aqspClipKindLast??null;fe!==oe&&(fe===null?(delete ce.dataset.aqspClipKindLast,ce.removeAttribute("data-aqsp-clip-kind")):(ce.dataset.aqspClipKindLast=fe,ce.setAttribute("data-aqsp-clip-kind",fe)))}Ye.current!==null&&Ht(Ye.current,V,Q,tt.current),a.current!==null&&yn(a.current,V,Q),y.current!==null&&it(y.current,V,Q);const Ie=$.current;if(Ie!==null&&!R()){const{width:ie,height:ce}=B.getViewportSize(),me=le.ranges[le.ranges.length-1];if(!(le.ranges.length===1&&!Ot.current&&!g())||ce<=0||ie<=0)Ie.style.display="none";else{const fe=B.getFrozenSize(),oe={scroll:Q,frozenCount:fe.cols,trailingCount:fe.trailingCols,extent:ie},Se={scroll:V,frozenCount:fe.rows,trailingCount:fe.trailingRows,extent:ce},Fe=me.endCol<fe.cols,bt=me.endRow<fe.rows,ct=me.endCol>=t.count-fe.trailingCols,yt=me.endRow>=e.count-fe.trailingRows,Tt=mn(t,me.endCol,oe)+t.sizeOf(me.endCol),Lt=gn(e,me.endRow,Se)+e.sizeOf(me.endRow),Wt=Fe||ct?0:fe.width,Rt=bt||yt?0:fe.height,vn=ct?ie:ie-fe.trailingVisibleWidth,kn=yt?ce:ce-fe.trailingVisibleHeight;Lt<=Rt||Lt>kn||Tt<=Wt||Tt>vn?Ie.style.display="none":(Ie.style.display="block",Ie.style.transform=`translate(${Tt-Ri+1}px, ${Lt-Ri+1}px)`)}}const Re=r.current;if(Re!==null){const ie=le.active,{width:ce,height:me}=B.getViewportSize(),Ce=B.getFrozenSize(),fe={scroll:Q,frozenCount:Ce.cols,trailingCount:Ce.trailingCols,extent:ce},oe={scroll:V,frozenCount:Ce.rows,trailingCount:Ce.trailingRows,extent:me},Se=gn(e,ie.row,oe),Fe=mn(t,ie.col,fe),bt=me>0?Math.min(Math.max(Se,0),Math.max(0,me-1)):0,ct=ce>0?Math.min(Math.max(Fe,0),Math.max(0,ce-1)):0;Re.style.top=`${bt}px`,Re.style.left=`${ct}px`,Ot.current?(Re.style.width=`${t.sizeOf(ie.col)}px`,Re.style.height=`${e.sizeOf(ie.row)}px`,Re.style.paddingTop=`${bm(e.sizeOf(ie.row),O===void 0?Nt:O.current)}px`):(Re.style.width="1px",Re.style.height="1px",Re.style.paddingTop="0px");const yt=ie.col>=Ce.cols&&Fe<Ce.width,Tt=ie.row>=Ce.rows&&Se<Ce.height,Lt=Ce.trailingWidth>0&&ie.col<t.count-Ce.trailingCols&&Fe+t.sizeOf(ie.col)>ce-Ce.trailingVisibleWidth,Wt=Ce.trailingHeight>0&&ie.row<e.count-Ce.trailingRows&&Se+e.sizeOf(ie.row)>me-Ce.trailingVisibleHeight,Rt=Ot.current&&Se===bt&&Fe===ct&&!yt&&!Tt&&!Lt&&!Wt;Rt!==xt.current&&(xt.current=Rt,Rt?Re.setAttribute("data-aqsp-editing",""):Re.removeAttribute("data-aqsp-editing"))}Sr(B,V,Q)},[n,lt,Y,Ae,Ht,yn,it,h,o,g,R,$,r,e,t,bn,de,O,Sr]),fo=i.useCallback((M,B)=>{Ye.current=M,tt.current=B;const X=M===null?"add":B;for(const le of Y(0,0)){const re=le.nodes.dragRect;if(re===null)continue;const Oe=re.dataset.aqspDragModeLast??"add";X!==Oe&&(re.dataset.aqspDragModeLast=X,X==="add"?re.removeAttribute("data-aqsp-drag-mode"):re.setAttribute("data-aqsp-drag-mode",X))}const V=n.current;if(M===null||V===null){for(const le of Y(0,0))le.nodes.dragRect!==null&&(le.nodes.dragRect.style.display="none"),jt(le,null,null);return}const Q=V.getScrollPosition();Ht(M,Math.max(0,Q.y),Math.max(0,Q.x),B)},[n,Ht,Y,jt]),Er=i.useCallback(M=>{y.current=M;const B=n.current;if(B===null){for(const V of Y(0,0))V.nodes.fillPreview!==null&&(V.nodes.fillPreview.style.display="none");return}const X=B.getScrollPosition();it(M,Math.max(0,X.y),Math.max(0,X.x))},[n,it,Y]),po=i.useCallback(M=>{a.current=M;const B=n.current;if(B===null){for(const V of Y(0,0))V.nodes.resizeGuide!==null&&(V.nodes.resizeGuide.style.display="none");return}const X=B.getScrollPosition();yn(M,Math.max(0,X.y),Math.max(0,X.x))},[n,yn,Y]);i.useLayoutEffect(()=>{const M=b.current;if(!(M===null||p===void 0))return M.style.setProperty("--aqsp-band-row",p.row),M.style.setProperty("--aqsp-band-column",p.column),M.style.setProperty("--aqsp-band-intersection",p.intersection),M.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{M.style.removeProperty("--aqsp-band-row"),M.style.removeProperty("--aqsp-band-column"),M.style.removeProperty("--aqsp-band-intersection"),M.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Kn,u.current=fo,F.current=Er,H.current=po,()=>{c.current=null,u.current=null,F.current=null,H.current=null})),i.useEffect(()=>{Kn()},[Kn,s,ne,Ee,De,he]),i.useEffect(()=>{const M=r.current;if(M===null)return;const B=X=>N(X);return M.addEventListener("mousedown",B),()=>M.removeEventListener("mousedown",B)},[r,N]);const _s=ne>0||De>0?[...ne>0?[{k:"f",style:{left:0,width:ve}}]:[],{k:"s",style:{left:ve,right:et}},...De>0?[{k:"t",style:{right:0,width:et}}]:[]]:[{k:"m",style:{left:0,right:0}}],ho=Ee>0||he>0?[...Ee>0?[{k:"f",style:{top:0,height:Le}}]:[],{k:"s",style:{top:Le,bottom:Pe}},...he>0?[{k:"t",style:{bottom:0,height:Pe}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Vt=M=>M==="m"?0:M==="s"?1:M==="t"?2:3,Rn=_s.flatMap(M=>ho.map(B=>({xk:M.k,yk:B.k,key:`${M.k}${B.k}`,style:{...M.style,...B.style}}))).sort((M,B)=>Vt(M.key[0])+Vt(M.key[1])-(Vt(B.key[0])+Vt(B.key[1]))),Un=M=>M==="mm"?{"data-aqsp-overlay-main":""}:M==="fm"?{"data-aqsp-overlay-frozen":""}:M==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:b,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:xe.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:xe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[Rn.map(({xk:M,yk:B,key:X,style:V})=>{const Q=te[X];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Un(X),style:V,ref:Q.container,children:[M==="s"&&ne>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:Q.dividerXLeading}):null,M==="s"&&De>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:Q.dividerXTrailing}):null,B==="s"&&Ee>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:Q.dividerYLeading}):null,B==="s"&&he>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:Q.dividerYTrailing}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:Q.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:Q.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:Q.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:Q.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:Q.resizeGuide})]},X)}),K.jsx("textarea",{ref:Ct,className:"aqsp-sink","aria-label":z,"aria-readonly":I?"true":void 0,"aria-keyshortcuts":T,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?K.jsx("div",{ref:$,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},ka=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=R=>{l.current=!0;try{R()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=R=>{if(R.key==="Escape"){R.preventDefault(),c(e.close);return}R.key==="Enter"&&(R.ctrlKey||R.metaKey)&&!R.altKey&&!R.shiftKey&&(R.preventDefault(),u())},g=R=>{l.current||R.relatedTarget instanceof Node&&R.currentTarget.contains(R.relatedTarget)||e.rejected||c(e.close)};return K.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:g,children:[K.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[Ne(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Ne(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(R=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":R.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:R.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:R.createdAt,children:R.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:R.text})]},R.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Ne(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:R=>r(R.currentTarget.value),onKeyDown:h}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:Ne(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Sa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),u=i.useRef(!1),h=o.trim()===""?null:on(o),g=o.trim()!==""&&h===null,R=_=>{u.current=!0;try{_()}finally{u.current=!1}},F=()=>{l||g||R(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},H=_=>{if(_.key==="Escape"){_.preventDefault(),R(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),F())},$=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||R(e.close)};return K.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":g?"":void 0,role:"dialog","aria-labelledby":c,onBlur:$,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Ne(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Ne(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:H})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Ne(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":g||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown:H})]}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:g||l,"aria-disabled":l?"true":void 0,onClick:F,children:Ne(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:Ne(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>R(e.close),children:"×"})]})]})},vi=500,Ea=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),u=i.useMemo(()=>{const W=n.toLowerCase();return e.current.filter(S=>S.toLowerCase().startsWith(W))},[e.current,n]),h=i.useMemo(()=>u.length>vi?u.slice(0,vi):u,[u]),g=u.length-h.length,R=h.length===0?-1:Math.min(o,h.length-1),F=W=>{c.current=!0;try{W()}finally{c.current=!1}},H=()=>{R<0||F(()=>e.commit(h[R]))},$=W=>{if(W.key==="Escape"){W.preventDefault(),F(e.close);return}if(W.key==="Enter"){W.preventDefault(),H();return}if(W.key==="ArrowDown"){W.preventDefault(),s(R+1);return}W.key==="ArrowUp"&&(W.preventDefault(),s(Math.max(R-1,0)))},_=W=>{c.current||W.relatedTarget instanceof Node&&W.currentTarget.contains(W.relatedTarget)||F(e.close)},U=W=>`${l}-${W}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Ne(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":R<0?void 0:U(R),value:n,onChange:W=>{r(W.currentTarget.value),s(0)},onKeyDown:$}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Ne(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Ne(t,"listEmpty")}):h.map((W,S)=>K.jsx("div",{className:"aqsp-popover-option",id:U(S),role:"option",tabIndex:-1,"aria-selected":S===R,"data-aqsp-list-option":W,onPointerDown:x=>x.preventDefault(),onClick:()=>F(()=>e.commit(W)),children:W},U(S))),g>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Ne(t,"listMore",g)}):null]})]})},Aa=({ctx:e,labels:t})=>K.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),K.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:e.close,children:"×"})]}),Oa=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=$=>{u.current=!0;try{$()}finally{u.current=!1}},g=()=>{s||h(()=>e.commit(r===""?null:r))},R=()=>{r!==n&&!s?g():h(e.close)},F=$=>{if($.key==="Escape"){$.preventDefault(),e.rejected?h(e.close):R();return}$.key==="Enter"&&($.ctrlKey||$.metaKey)&&!$.altKey&&!$.shiftKey&&($.preventDefault(),g())},H=$=>{u.current||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||e.rejected||R()};return K.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:H,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:Ne(t,"noteTitle")}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:$=>o($.currentTarget.value),onKeyDown:F}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Ne(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:g,children:Ne(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Ne(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},xa=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),zt=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")}),ki=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Ta=Object.freeze({all:zt(ki),values:zt(["text"]),formats:zt(["format","borders","cf"]),formulas:zt(["text","formula"]),noBorders:zt(ki.filter(e=>e!=="borders")),columnWidths:zt(["sizes"]),validation:zt(["validation"]),conditionalFormats:zt(["cf"]),commentsAndNotes:zt(["note","comments"])}),Si=Object.freeze({mode:"all"}),hs=Object.freeze({t:""}),Ei=Object.freeze({row:1<<30,col:1<<30}),Sm=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Em=e=>e.t===""&&e.f===void 0,Am=e=>e.length>1&&e.startsWith("="),Om=(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}},Ai=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,xm=(e,t,n,r)=>{const o=Am(e),s=e===""?"0":ot(e);if(!o&&s===null)return null;const l=Sm[n];if(t.f!==void 0){const h=br(t.f,r),g=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${g})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Ai(Number(s));const c=ot(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Ai(Om(Number(s),u,n))},Oi=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Tm=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:Oi(e.start),end:Oi(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}}}},Lm=e=>{const t=br(e,Ei),n=Cr(t);let r="",o=0,s=!1;for(const l of n){const c=Tm(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${en(c)}`,o=l.end,s=!0)}return s?io(`${r}${t.slice(o)}`,Ei):e},$m=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return hs;const o=r[n];return o===void 0?hs:o},Dm=e=>{const{rows:t,cols:n}=e,r=Tc(Lm);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const u=[];for(let h=0;h<t;h+=1){const g=$m(e,h,c);let R=g;if(g.f!==void 0){const F=r(g.f);R=F===g.f?g:{...g,f:F}}(R!==g||g===hs)&&(o=!1),u.push(R)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},Mm=(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,zm=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},xi=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const g of c)Mm(g,t)?(h.push(zm(g,t)),u=!0):h.push(g);u&&(n=!0),r.push(u?h:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},Ti=new WeakMap,La=e=>{const t=Ti.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>wt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:wt({...s,borders:void 0})),o={canonical:n,borderless:r};return Ti.set(e,o),o},no=(e,t)=>t===void 0?void 0:e[t],Fm=(e,t,n,r)=>{const o=La(e);if(n){const h=no(o.canonical,t.fmt);return h===void 0?null:h}const s=no(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const u=wt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},Nm=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?xm(n.readText(),o,r,n):o.f===void 0?o.t:br(o.f,n)},Li=(e,t,n,r,o)=>{const s=Ta[r.mode];if(r.skipBlanks===!0&&Em(e))return null;const l={};let c=!1;if(s.text){const u=Nm(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Fm(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=no(La(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=no(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},$i=(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}}),Pm=["text/html","text/plain"],_m=(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},qm=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Im=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,jm=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}}},Di=e=>{const t=e.clipboardData;return t??null},Hm=(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}},Bm=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Hm(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},Vm=(e,t,n,r,o)=>{const s=Wn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=io(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:u,author:h,createdAt:g})=>({text:u,author:h,createdAt:g})))}if(e.getCellHyperlink!==void 0){const c=Yn(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},$a=(e,t)=>{const n=hc(),r=Ud(),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(Vm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Bm(e.getConditionalFormats(),t)}},Mi=e=>e.kind==="cut"?{...e.payload,...$a(e.sourceAdapter,e.range)}:e.payload,Wm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:vs(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Ym=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=on(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Km=(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},Um=(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 ye({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Xm=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(S=>{const x=n.current;if(x===null||S==="format"||S==="annotate")return;const z=r.current;z==="own"||z==="foreign"&&x.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const S=n.current;if(S===null)return;if(S.kind==="copy"){o();return}const x=t.current;x.repaintOverlay(),x.onClipChange?.({kind:"cut",range:S.range,foreign:S.sourceAdapter!==x.adapter})},[o]),c=i.useCallback((S,x,z)=>{const I=t.current;n.current={kind:S,range:x,clipId:z.clipId,sourceAdapter:I.adapter,payload:z},I.repaintOverlay(),I.onClipChange?.({kind:S,range:x,foreign:!1})},[]),u=i.useCallback(S=>{const x=t.current,z=x.adapter,I=st(S),T={v:1,rows:I.rows,cols:I.cols,clipId:vs(),...$a(z,S),wholeRows:mc(S,z.colCount),wholeCols:gc(S,z.rowCount)};if(x.resize!==void 0){if(T.wholeCols){const N=[];for(let O=S.startCol;O<=S.endCol;O+=1)N.push(Math.min(x.resize.colAxis.sizeOf(O),rn));T.colWidths=N}if(T.wholeRows){const N=[];for(let O=S.startRow;O<=S.endRow;O+=1)N.push(Math.min(x.resize.rowAxis.sizeOf(O),rn));T.rowHeights=N}}return T},[]),h=i.useCallback((S,x)=>{const z=t.current,I=z.getSelection(),T=I.ranges[I.ranges.length-1],N=At([T]);if(N>z.maxOperationCells)return S.preventDefault(),z.onOperationRejected?.(x,N,"limit"),null;if(x==="cut"&&cr(z.adapter,T))return S.preventDefault(),z.rejectReadOnly({kind:"operation",op:"cut",cellCount:N}),null;I.ranges.length>1&&z.onCopyMultiRange?.();const O=u(T),m=rc(O),p=Di(S);return p!==null&&(p.setData("text/plain",_t.serializeClipboardTsv(O.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",Kc(O,m)),p.setData(Qr,m)),S.preventDefault(),{payload:O,range:T}},[u]),g=i.useCallback((S,x)=>t.current.commitPaste(S,x)!==null,[]),R=i.useCallback((S,x,z)=>{const I=t.current;if(!z.sizes||I.resize===void 0)return;const{rowAxis:T,colAxis:N,resizeTracks:O}=I.resize,m=(p,C,v)=>{const k=Cs(C,v,null,{maxOperationCells:I.maxOperationCells,rowHiddenLimit:gs,axisKind:p});if(!k.ok){I.onOperationRejected?.("resize",k.count,k.reason);return}O(p,k.entries)};if(S.colWidths!==void 0){const p=[];for(let C=x.startCol;C<=x.endCol;C+=1)p.push({index:C,size:S.colWidths[(C-x.startCol)%S.cols]});m("col",N,p)}if(S.rowHeights!==void 0){const p=[];for(let C=x.startRow;C<=x.endRow;C+=1)p.push({index:C,size:S.rowHeights[(C-x.startRow)%S.rows]});m("row",T,p)}},[]),F=i.useCallback((S,x)=>{const z=t.current,I=z.adapter,T=S.payload,N={row:x.startRow,col:x.startCol},O=T.rows*T.cols+At([S.range]);if(O>z.maxOperationCells)return z.onOperationRejected?.("paste",O,"limit"),"rejected";if(N.row+T.rows>I.rowCount||N.col+T.cols>I.colCount||S.range.endRow>=S.sourceAdapter.rowCount||S.range.endCol>=S.sourceAdapter.colCount)return z.onOperationRejected?.("paste",O,"bounds"),"rejected";const m=fs({rows:T.rows,cols:T.cols},ye(N,N),N,I.rowCount,I.colCount);if(m!==null&&cr(I,m))return z.rejectReadOnly({kind:"operation",op:"paste",cellCount:T.rows*T.cols}),"rejected";if(cr(S.sourceAdapter,S.range))return z.rejectReadOnly({kind:"operation",op:"cut",cellCount:At([S.range])}),"rejected";const p=Mi(S),C=Zr(I),v=xi(p,C),k={row:0,col:0,readText:()=>Wn(I,k.row,k.col).text,readFormat:()=>I.getCellFormat===void 0?void 0:I.getCellFormat(k.row,k.col)},{edits:b,tiles:y}=oi(v.cells,ye(N,N),N,I.rowCount,I.colCount,(E,d,L)=>(k.row=S.range.startRow+(d-N.row),k.col=S.range.startCol+(L-N.col),Li(E,v,k,Si,C))),a=Zr(S.sourceAdapter),f=[];if(Zt([S.range],E=>{f.push(Km(E.row,E.col,a))}),S.sourceAdapter===I){if(!g([...f,...b],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const E=z.commitPaste(b,{sameSheet:!1,conditionalFormats:$i(v.conditionalFormats,y)});if(E===null)return"rejected";try{S.sourceAdapter.applyEdits(f,{transaction:E,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){z.onEditRejected?.(d,{source:"paste"})}}return z.setSelection({ranges:[ye(N,{row:N.row+p.rows-1,col:N.col+p.cols-1})],anchor:N,active:N}),"applied"},[g]),H=i.useCallback((S,x,z)=>{const I=t.current,T=I.adapter,N=Y=>(I.onClipboardUnavailable?.(Y),"rejected"),O=lc(S,x);if(O==="none")return x==="menu"?N("empty"):"empty";const m=I.getSelection(),p=m.ranges[m.ranges.length-1],C=z.transpose===!0,v=(Y,G)=>{const J=_m(C?G:Y,C?Y:G,p);return J>I.maxOperationCells?(I.onOperationRejected?.("paste",J,"limit"),!0):!1};let k,b=null;if(O==="aqsp"){const Y=Rd(S,x);if(Y===null)return N("unreadable");const G=n.current;if(G!==null&&Y.clipId===G.clipId&&(b=G),b!==null&&b.kind==="cut"&&qm(z))return F(b,p);if(v(Y.rows,Y.cols))return"rejected";if(b!==null){if(b.kind==="cut"&&(b.range.endRow>=b.sourceAdapter.rowCount||b.range.endCol>=b.sourceAdapter.colCount))return I.onOperationRejected?.("paste",b.payload.rows*b.payload.cols,"bounds"),"rejected";k=Mi(b)}else{const J=vd(S,x);if(J===null)return N("unreadable");if(v(J.rows,J.cols))return"rejected";k=Ym(J)}}else if(O==="tsv"){const Y=S.getData("text/plain"),G=_t.measureTsv(Y);if(v(G.rows,G.cols))return"rejected";k=Wm(_t.parseTsv(Y))}else{const Y=S.getData("text/html"),G=Kd(Y);if(G.cols===0&&G.rows>I.maxOperationCells)return I.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(v(G.rows,G.cols))return"rejected";const J=Zc(Y,O,I.formats===void 0?{}:{currency:I.formats.currency,locale:I.formats.locale},I.maxOperationCells);if(J.outcome==="none")return N("unreadable");if(J.outcome==="limit")return I.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(v(J.payload.rows,J.payload.cols))return"rejected";k=J.payload}const y=Zr(T),a=xi(C?Dm(k):k,y),f=Ta[z.mode];if(Im(f)){const Y=fs({rows:a.rows,cols:a.cols},p,m.active,T.rowCount,T.colCount);if(Y!==null&&cr(T,Y))return I.rejectReadOnly({kind:"operation",op:"paste",cellCount:At([Y])}),"rejected"}const E={row:0,col:0,readText:()=>Wn(T,E.row,E.col).text,readFormat:()=>T.getCellFormat===void 0?void 0:T.getCellFormat(E.row,E.col)},{edits:d,tiles:L}=oi(a.cells,p,m.active,T.rowCount,T.colCount,(Y,G,J)=>(E.row=G,E.col=J,Li(Y,a,E,z,y))),A=Um(L,a.rows,a.cols,T.rowCount,T.colCount);if(A===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let Y=0;for(const J of a.conditionalFormats)Y+=J.ranges.length;const G=L.length*Y;if(G>I.maxOperationCells)return I.onOperationRejected?.("paste",G,"limit"),"rejected"}const D=f.cf?$i(a.conditionalFormats,L):[];if(d.length===0&&D.length===0)return R(a,A,f),"empty";r.current=b===null?"foreign":"own";let q=!1;try{q=g(d,{sameSheet:b!==null&&b.sourceAdapter===T,conditionalFormats:D})}finally{r.current="none"}if(!q)return"rejected";R(a,A,f);const j={row:A.startRow,col:A.startCol};return I.setSelection({ranges:[A],anchor:j,active:j}),"applied"},[F,g,R]),$=i.useCallback(async S=>{const x=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),z=navigator;if(z.clipboard===void 0)return x("insecure-origin");let I;try{I=await z.clipboard.read({unsanitized:["text/html"]})}catch{return x("permission-denied")}if(I.length===0)return x("empty");const T=I[0],N=Array.from(T.types),O=new Map;try{for(const C of Pm)N.includes(C)&&O.set(C,await(await T.getType(C)).text())}catch{return x("unreadable")}const m={types:N,getData:C=>{const v=O.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":H(m,"menu",S)},[H]),_=i.useCallback(async S=>{const x=await $(S);return t.current.onPasteResolved?.(x,"menu"),x},[$]),{enabled:U,sinkRef:W}=e;return i.useEffect(()=>{const S=W.current;if(!U||S===null)return;const x=N=>t.current.isDragging()?(N.preventDefault(),!0):!1,z=N=>{const O=t.current;if(x(N)||O.isEditing())return;const m=h(N,"copy");m!==null&&c("copy",m.range,m.payload)},I=N=>{const O=t.current;if(x(N)||O.isEditing())return;const m=h(N,"cut");m!==null&&c("cut",m.range,m.payload)},T=N=>{const O=t.current;if(x(N)||O.isEditing())return;N.preventDefault();let m=Si;const p=O.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(m=p.current,p.current=null);const C=Di(N);if(C===null)return;const v=H(jm(C),"event",m);O.onPasteResolved?.(v,"event")};return S.addEventListener("copy",z),S.addEventListener("cut",I),S.addEventListener("paste",T),()=>{S.removeEventListener("copy",z),S.removeEventListener("cut",I),S.removeEventListener("paste",T)}},[U,W,h,c,H]),i.useMemo(()=>({getClip:()=>{const S=n.current;return S===null?null:{kind:S.kind,range:S.range,foreign:S.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},Da=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)}`)},Ma=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}},zi=(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}`}`},za=(e,t)=>{let n;if(e.exponent===null)n=zi(e.negative,e.digits,e.point+t);else{const r=zi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return ot(n)===null?null:n},Gm=(e,t)=>{Da(t);const n=ot(e);return n===null?null:za(Ma(n),t)},Zm=e=>{const t=ot(e);if(t!==null){const r=Ma(t);return za({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},Fa=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)},Jm=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},Na=(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 Jm(r)?r:null},Qm=(e,t)=>{Da(t);const n=Fa(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Na(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},eg=e=>{const t=Fa(e),n=Na(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},or=(e,t,n,r)=>{const o=At(t);return o>n?(r?.(e,o,"limit"),!1):!0},Ir={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},jr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Fi={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:Ir.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Ir.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Ir.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Ir.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:jr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:jr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:jr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:jr.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},tg={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},pr=e=>e<10?`0${e}`:String(e),ng=e=>{const t=new Date(e);return`${t.getFullYear()}-${pr(t.getMonth()+1)}-${pr(t.getDate())}`},rg=e=>{const t=new Date(e);return`${pr(t.getHours())}:${pr(t.getMinutes())}:${pr(t.getSeconds())}`},og=(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),sg=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),lg=e=>e===void 0||e.borders===void 0?{}:e.borders,ig={top:1,right:2,bottom:4,left:8},cg={style:"thin",color:bs},ag=(e,t)=>{if(e===void 0)return!1;const n=Xe(e);return n!==null&&n===Xe(t)},ug=(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}}},dg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const m=t.current;if(m.isEditing()){const p=m.getActive();return[ye(p,p)]}return m.getSelection().ranges},[]),r=i.useCallback(()=>{const m=t.current,p=m.getActive();return m.adapter.getCellFormat===void 0?void 0:m.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(m=>{const p=t.current,C=n();if(!or("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Pn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:At(C)}),!1;const v=new Map,k=[],b=p.adapter.getCellFormat;for(const y of C)Zt([y],a=>{const f=b===void 0?void 0:b(a.row,a.col),{bucket:E,patch:d}=m(a,y,f);let L=v.get(E);L===void 0&&(L=new Map,v.set(E,L));let A;L.has(f)?A=L.get(f):(A=Rs(f,d),L.set(f,A)),A!==f&&k.push({row:a.row,col:a.col,format:A===void 0?null:A})});return k.length===0?!0:p.commitEdits(k,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(m=>o(()=>({bucket:0,patch:m})),[o]),l=i.useCallback((m,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:m,state:p}))},[]),c=i.useCallback((m,p=cg)=>{if(m==="clear")return s({borders:null});if(m==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=m==="outer"?15:ig[m];return o((v,k,b)=>{const y=og(v,k)&C;return{bucket:y,patch:{borders:{...lg(b),...sg(y,p)}}}})},[s,o]),u=i.useCallback((m,p,C)=>{const v=na(t.current.adapter,m.row,m.col);for(const k of p)C.push(ra(v,m,k))},[]),h=i.useCallback(m=>{const p=t.current,C=p.getSelection();if(!or("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[];if(m==="selection"){const b=C.active,y=[];Zt(C.ranges,a=>{(a.row!==b.row||a.col!==b.col)&&y.push(a)}),v.push({source:b,targets:y})}else for(const b of C.ranges)if(m==="down"){const y=b.startRow===b.endRow;if(y&&b.startRow===0)continue;const a=y?b.startRow-1:b.startRow;for(let f=b.startCol;f<=b.endCol;f+=1){const E=[];for(let d=y?b.startRow:b.startRow+1;d<=b.endRow;d+=1)E.push({row:d,col:f});v.push({source:{row:a,col:f},targets:E})}}else{const y=b.startCol===b.endCol;if(y&&b.startCol===0)continue;const a=y?b.startCol-1:b.startCol;for(let f=b.startRow;f<=b.endRow;f+=1){const E=[];for(let d=y?b.startCol:b.startCol+1;d<=b.endCol;d+=1)E.push({row:f,col:d});v.push({source:{row:f,col:a},targets:E})}}for(const b of v)for(const y of b.targets)if(We(p.adapter,y.row,y.col)){let a=0;for(const f of v)a+=f.targets.length;return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:a}),!1}const k=[];for(const b of v)u(b.source,b.targets,k);return k.length===0?!0:p.commitEdits(k,{source:"fill"})!==null},[u]),g=i.useCallback(()=>{const m=t.current,p=m.getSessionText();if(p===null)return!1;const C=m.getSelection();if(!or("fill",C.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(Pn(m.adapter,C.ranges))return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:At(C.ranges)}),!1;const v=[];let k=!1;return Zt(C.ranges,b=>{if(!k){if(!m.validateCommit(b,p).ok){k=!0;return}v.push({row:b.row,col:b.col,text:p})}}),k||m.commitEdits(v,{source:"fill"})===null?!1:(m.cancelEdit(),!0)},[]),R=i.useCallback(m=>{const p=t.current,C=p.getSelection();if(!or("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Pn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:At(C.ranges)}),!1;const v=[],k=p.adapter;return Zt(C.ranges,b=>{const y=k.getCellFormula===void 0?void 0:k.getCellFormula(b.row,b.col),a=y===void 0?m.text(k.getCellText(b.row,b.col)):m.formula(y);a!==null&&v.push({row:b.row,col:b.col,text:a})}),v.length===0?!0:p.commitEdits(v,{source:"calc"})!==null},[]),F=i.useCallback((m,p)=>{const C=t.current,v=m==="row"?C.rowAxis:C.colAxis,k=C.getSelection(),b=m==="row"?Math.floor(C.maxOperationCells/ws):C.maxOperationCells;let y=0;for(const L of k.ranges)y+=m==="row"?L.endRow-L.startRow+1:L.endCol-L.startCol+1;if(y>b)return C.onOperationRejected?.("resize",y,"limit"),!1;const a=new Set,f=[],E=p?0:m==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const L of k.ranges){const A=m==="row"?L.startRow:L.startCol,D=m==="row"?L.endRow:L.endCol;for(let q=A;q<=D;q+=1){if(a.has(q))continue;a.add(q),v.sizeOf(q)===0!==p&&f.push({index:q,size:E})}}const d=Cs(v,f,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:gs,axisKind:m});return d.ok?(d.entries.length>0&&C.resizeTracks(m,d.entries),!0):(C.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),H=i.useCallback(()=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)return;const p=m.getActive();return Yn(m.adapter.getCellHyperlink(p.row,p.col))},[]),$=i.useCallback(m=>{const p=t.current,C=p.adapter,v=Fi[m],k=C.getCellFormat!==void 0,b=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(v.kind){case"resize":return p.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return k;case"value":return k&&(v.value!=="currency"||p.formats!==void 0);case"popover":switch(v.popover){case"link":return C.getCellHyperlink!==void 0&&b("link");case"note":return C.getCellNote!==void 0&&b("note");case"comment":return C.getCellComments!==void 0&&b("comment");default:return C.getCellValidation!==void 0&&b("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(p.onHyperlinkOpen!==void 0?H()!==void 0:b("link"));case"paste":return v.options.mode==="formats"?k:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[H]),_=i.useCallback(m=>{const p=t.current,C=m.kind==="popover"?m.popover:m.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=p.getActive();if(!We(p.adapter,v.row,v.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let k;if(C==="link")k=H()!==void 0;else if(C==="note"){const b=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(v.row,v.col);k=b!==void 0&&b!==""}else{const b=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(v.row,v.col);k=b!==void 0&&b.length>0}return k?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[H]),U=i.useCallback((m,p,C)=>{const v=t.current,k=v.trackResize;if(k===void 0)return!1;const b=v.getActive(),y=p==="col"?b.col:b.row,a=C==="fit"?k.autofitColumn(y):k.stepTrack(p,y,C),f=(p==="col"?v.colAxis:v.rowAxis).sizeOf(y);return a&&f>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:m,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),W=i.useCallback(m=>{const p=t.current;if(!$(m))return!1;const C=Fi[m];if(!_(C))return!1;const v=p.isEditing();if(v&&!Ms.has(m)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const k=r(),b=k!==void 0&&k[C.key]===!0;return s({[C.key]:b?null:!0})?(l(m,!b),!0):!1}case"patch":return s(C.patch)?(l(m,null),!0):!1;case"clear":return s(tg)?(l(m,null),!0):!1;case"value":return s({value:ug(C.value,p.formats)})?(l(m,null),!0):!1;case"borders":return c(C.preset)?(l(m,null),!0):!1;case"color":{const k=C.key==="background"?p.colors.fill:p.colors.font,b=C.preset!==null?C.preset:C.custom!==null&&C.custom<k.length?k[C.custom]:void 0;if(b===void 0)return!1;const y=r(),a=ag(y===void 0?void 0:y[C.key],b);return s({[C.key]:a?null:b})?(l(m,!a),!0):!1}case"calc":return R({text:k=>Gm(k,C.exponent),formula:k=>Qm(k,C.exponent)});case"sign":return R({text:Zm,formula:eg});case"fill":return v&&C.direction==="selection"?g():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const k=H();return k===void 0?!1:(p.onHyperlinkOpen(k,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const k=C.unit==="date"?ng(p.now()):rg(p.now());if(v)return p.insertAtCaret(k),!0;const b=p.getActive();return We(p.adapter,b.row,b.col)?(p.rejectReadOnly({kind:"edit",cell:b,editSession:"none"}),!1):p.validateCommit(b,k).ok?p.commitEdits([{row:b.row,col:b.col,text:k}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return F(C.axis,C.hide);case"resize":return U(m,C.axis,C.step);default:{const k=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...k,row:!k.row}),!0;case"column":return p.setHighlight({...k,column:!k.column}),!0;case"both":{const b=k.row&&k.column;return p.setHighlight({...k,row:!b,column:!b}),!0}default:return p.setHighlight({...k,intersection:!k.intersection}),!0}}}},[$,_,H,r,s,l,c,R,h,g,F,U]),S=i.useCallback(()=>{const m=t.current;return!(m.isEditing()&&!m.requestCommit())},[]),x=i.useCallback(m=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=m===null?null:on(m);if(m!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(m)}`);if(!S())return!1;const v=p.getActive();return We(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[S]),z=i.useCallback(m=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!S())return!1;const C=p.getActive();return We(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:m}],{source:"annotate"})!==null},[S]),I=i.useCallback(m=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!S())return!1;const v=p.getActive();if(We(p.adapter,v.row,v.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const k=C(v.row,v.col),b=k===void 0?[m]:[...k,m];return p.commitEdits([{row:v.row,col:v.col,comments:b}],{source:"annotate"})!==null},[S]),T=i.useCallback(m=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!S())return!1;const C=p.getSelection().ranges;if(!or("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Pn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:At(C)}),!1;const v=[];return Zt(C,k=>{v.push({row:k.row,col:k.col,validation:m})}),p.commitEdits(v,{source:"annotate"})!==null},[S]),N=i.useCallback(m=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(m)},[s]),O=i.useCallback((m,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(m,p)},[c]);return i.useMemo(()=>({executeCommand:W,applyFormat:N,setBorders:O,setHyperlink:x,setNote:z,addComment:I,setValidation:T,isCommandAvailable:$}),[W,N,O,x,z,I,T,$])},Hr="data-aqsp-pointing",fg=(e,t)=>{const n=zc(e,t);return n!==null&&"insertAt"in n},pg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},hg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),u=i.useRef(null),h=i.useRef(Nt),g=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=zc(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),R=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=g()!==null;a!==y.hasAttribute(Hr)&&(a?y.setAttribute(Hr,""):y.removeAttribute(Hr))},[g]),F=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const E=f.resolveEditPaint(a),d=E===null?Nt:E;d!==Nt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),H=i.useCallback(y=>{pg(y,Object.keys(h.current.style)),h.current=Nt;const a=t.current.editPaintRef;a!==void 0&&(a.current=Nt)},[]),$=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const E=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),H(d),d.removeAttribute(Hr)),o(!1)};if(y.commit){const d=a.sinkRef.current,L=d===null?"":d.value,A=Wn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
13
- `),D=L===A;let q;if(D)q=!0;else if(We(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),q=!1;else{const j={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};q=(a.validateCommit===void 0||a.validateCommit(f.cell,L).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:L}],j)!==null}if(!q)return y.onReject==="discard"&&(E(),a.rearmSink()),!1}return E(),y.rearm&&a.rearmSink(),!0},[H]),_=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const E=f.sinkRef.current;if(E===null)return;const d=f.getActive();if(We(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:A,isFormula:D}=Wn(f.adapter,d.row,d.col);E.value=A;const q=a===void 0||D?A.length:Math.min(a,A.length);E.setSelectionRange(q,q)}else E.value="";const L=f.resolveEditAlign(d);L!==null&&(E.style.textAlign=L),F(E,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[F]),U=i.useCallback(()=>{$({rearm:!0,commit:!1})},[$]),W=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return $({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return $({rearm:!0,commit:!0,onReject:"keep"})},[$]),S=i.useCallback(()=>g()!==null,[g]),x=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,R(),!0),[R]),z=i.useCallback(()=>{const y=g(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=Mc(y.sink.value,y.sink.selectionStart);if(f===null)return null;const E=f.token,d=u.current;switch(E.kind){case"cell":{const L={row:E.row,col:E.col};return u.current=L,{origin:L,cursor:L,axis:"cells"}}case"range":{const L=d!==null&&(d.row===E.start.row||d.row===E.end.row)&&(d.col===E.start.col||d.col===E.end.col)?{row:d.row,col:d.col}:{row:E.start.row,col:E.start.col};return u.current=L,{origin:L,cursor:{row:L.row===E.start.row?E.end.row:E.start.row,col:L.col===E.start.col?E.end.col:E.start.col},axis:"cells"}}case"column":{const L=d!==null&&(d.col===E.start.col||d.col===E.end.col)?d.col:E.start.col,A={row:a.cell.row,col:L};return u.current=A,{origin:A,cursor:{row:a.cell.row,col:L===E.start.col?E.end.col:E.start.col},axis:"columns"}}case"row":{const L=d!==null&&(d.row===E.start.row||d.row===E.end.row)?d.row:E.start.row,A={row:L,col:a.cell.col};return u.current=A,{origin:A,cursor:{row:L===E.start.row?E.end.row:E.start.row,col:a.cell.col},axis:"rows"}}}},[g]),I=i.useCallback((y,a)=>{const f=g();if(f===null)return;const E=xf(y,a),{sink:d}=f,[L,A]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],D=d.value;d.value=`${D.slice(0,L)}${E}${D.slice(A)}`;const q=L+E.length;d.setSelectionRange(q,q),"row"in y&&(u.current={row:y.row,col:y.col}),R()},[g,R]),T=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),N=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,R())},[R]),O=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=_f(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),R(),!0)},[R]),m=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,E=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(E)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,R()},[R]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(H(f),F(f,a.cell),y.repaintOverlay?.())},[H,F]),{enabled:k,sinkRef:b}=e;return i.useEffect(()=>{const y=b.current;if(!k||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},E=A=>{const D=t.current;if(l.current||n.current===null)return;const q=D.rootRef.current,j=A.relatedTarget;q!==null&&j instanceof Node&&q.contains(j)||$({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const A=t.current;u.current=null,A.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&fg(y.value,y.selectionStart)&&(c.current=!0),R()},L=()=>{n.current!==null&&R()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",E),y.addEventListener("input",d),document.addEventListener("selectionchange",L),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",E),y.removeEventListener("input",d),document.removeEventListener("selectionchange",L)}},[k,b,$,R]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:W,cancelEdit:U,startEdit:_,getPointing:S,togglePointingArm:x,getReferenceCursor:z,insertReference:I,captureSink:T,restoreSink:N,cycleAnchorAtCaret:O,insertAtCaret:m,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[W,U,_,S,x,z,I,T,N,O,m,p,C,v,r])},mg=(e,t,n)=>{const r=new Ge.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}},gg=(e,t,n)=>{const{tree:r,initialHidden:o}=mg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:g,currentValue:R}=r.prefixSum(h);return g-R},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const g=Math.floor(h),R=Math.min(Math.max(g,0),r.getTotal()-1);return r.findIndexAtOrAfter(R+.5).index},totalSize:()=>r.getTotal(),resize:(h,g)=>{if(!(Number.isFinite(g)&&g>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${g}`);const R=Math.round(g);r.get(h)===0!=(R===0)&&(s+=R===0?1:-1),r.update(h,R)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},tn=(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)},jn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:tn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=tn(e,o,1);return r},Ni=(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=gg(e,t,r)),o.current.model},Hn=256,Xo=256,wg=2**32,Cg=4096,Pa=Object.freeze([]),_a=["background","color","bold","italic","underline","strikethrough"],qa=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},nn=(e,t,n)=>(e.size>=Cg&&e.clear(),e.set(t,n),n),Ia=e=>(qa(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),ja=(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},bg=(e,t,n)=>{const r=Math.floor(t/Hn),o=Math.floor(n/Xo),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Hn,u=o*Xo,h=[];for(const g of e.rules)ja(g.ranges,c,c+Hn-1,u,u+Xo-1)&&h.push(g);return nn(e.buckets,s,h.length===0?Pa:h)},yg=(e,t,n)=>{const r=Math.floor(t/Hn),o=r*wg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=bg(e,t,n),c=r*Hn,u=[];for(const h of l)ja(h.ranges,c,c+Hn-1,n,n)&&u.push(h);return nn(e.columns,o,u.length===0?Pa:u)},Rg=(e,t)=>{for(const n of e)if(wn(n,t))return!0;return!1},Fs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Br=(e,t)=>e<t?-1:e>t?1:0,Pi=(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}},_i=new WeakMap,ms=e=>e===null?null:Number(e),vg=e=>{const t=_i.get(e);if(t!==void 0)return t;const n=e.b,r={a:ms(ot(e.a)),b:n===void 0?null:ms(ot(n))};return _i.set(e,r),r},Ha=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:nn(e.numbers,r,ms(ot(n())))},kg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=vg(e),l=Ha(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Pi(e.op,Br(l,s.a),c===null?null:Br(l,c));const u=n(),h=e.b;return Pi(e.op,Br(u,e.a),h===void 0?null:Br(u,h))},Sg=(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}},Go=e=>{const t=Xe(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]},Vr=e=>e.toString(16).padStart(2,"0"),Zo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Vr(r(0))}${Vr(r(1))}${Vr(r(2))}`,s=r(3);return s===255?o:`${o}${Vr(s)}`},Jo=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Eg=(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=Go(t.color),u=Go(r.color);const h=n===void 0?void 0:Go(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const R=s;s=l,l=R;const F=c;c=u,u=F}if(n!==void 0&&h!==void 0){const R=n.value===void 0?(s+l)/2:n.value;if(s<R&&R<l)return e<=R?Zo(c,h,Jo(e,s,R)):Zo(h,u,Jo(e,R,l))}return Zo(c,u,Jo(e,s,l))},Ag=(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 nn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const g=n.getRangeExtrema(h);if(g===null)return nn(r.extrema,e.id,null);c=Math.min(c,g.min),u=Math.max(u,g.max)}return nn(r.extrema,e.id,{min:c,max:u})},Og=(e,t,n,r,o,s)=>{const l=Ha(s,n,r);if(l===null)return null;const c=Ag(e,t,o,s);return c===null?null:Eg(l,t.min,t.mid,t.max,c)},xg=(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:nn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Tg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return kg(s,t,n,o)?e.style:null;case"text":return Sg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Og(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return xg(e,s,t,r,o)?e.style:null;default:return null}},qi=(e,t)=>Rs(e,t),Lg=(e,t,n)=>{e[t]=n},$g=(e,t)=>{let n=e;for(const r of _a)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Lg(n,r,t[r]));return n},Dg=e=>{let t="";for(const n of _a){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Ii=new WeakMap,Mg=Object.freeze({}),zg=e=>{const t=e===void 0?Mg:e,n=Ii.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Ii.set(t,r),r},Fg=(e,t,n)=>{const r=zg(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=qi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Dg(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=qi(e,t);return l!==void 0&&nn(r.byKey,o,l),l},Ns=(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=yg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,g=!0;for(const R of c){if(!Rg(R.ranges,u))continue;const F=Tg(R,u,s,e,n);if(F!==null){if(F!==R.style&&(g=!1),h===null)h=F;else{const H=$g(h,F);H!==h&&(g=!1,h=H)}if(R.stopIfTrue===!0)break}}return h===null?l:Fg(l,h,g)},ji=new WeakMap,Ng=e=>{qa(e,"widthRelevantRules");const t=ji.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 ji.set(e,r),r},Pg=({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},_g=i.memo(Pg),qg=Object.freeze({left:Object.freeze({justifyContent:ur("left")}),center:Object.freeze({justifyContent:ur("center")}),right:Object.freeze({justifyContent:ur("right")})}),Ig=Object.freeze({role:"rowgroup"}),jg=4096,Hi=new WeakMap,Wr=new Map,Hg=(e,t)=>{if(e===null)return qg[t];let n=Hi.get(e);n===void 0&&(n={},Hi.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:ur(t)},s=JSON.stringify(o);let l=Wr.get(s);return l===void 0&&(Wr.size>=jg&&Wr.clear(),l=Object.freeze(o),Wr.set(s,l)),n[t]=l,l},Bg=Fs(),Vg=(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},Wg=(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=Gr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const g=Ns(e,r===null?null:r.indexRef.current,r===null?Bg:r.memoRef.current,o,s,l);h=g===void 0?void 0:g.value;const R=Jc(g,l),F=tn(n,s,1),H=tn(t,o,1),$=of(g,F===null?void 0:e.getCellFormat(o,F),H===null?void 0:e.getCellFormat(H,s),n.offsetOf(s)===0,t.offsetOf(o)===0);$!==null&&Object.assign(c,$.attrs),c["data-aqsp-align"]=R,u=Hg($,R)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const g=e.getCellComments(o,s);g!==void 0&&g.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Yn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&pm(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Yg=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:g,frozenTrailingRows:R,headerRows:F,labelledBy:H,gridLabel:$,readOnly:_,renderCell:U,onScroll:W,onRangeChange:S,focusSink:x,isEditing:z,requestCommit:I,testId:T,__onCellRender:N,__maxRenderedCells:O,cfIndexRef:m,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:v,overscanRows:k,overscanCols:b,background:y,onRenderTruncated:a,locale:f,scrollLabels:E})=>{const d=i.useRef(null),L=s??d;if(m===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const A=i.useMemo(()=>m===void 0||p===void 0?null:{indexRef:m,memoRef:p},[m,p]),D=i.useCallback(()=>r.get().editVersion,[r]),q=i.useCallback(he=>r.subscribeCoalesced(he),[r]),Y=i.useSyncExternalStore(q,D,D)+(l??0),G=i.useCallback(he=>t.sizeOf(he),[t]),J=i.useCallback(he=>n.sizeOf(he),[n]),te=i.useCallback((he,Pe)=>e.getCellText(he,Pe),[e]),ne=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),ve=i.useMemo(()=>({width:xe.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Ee=i.useRef({row:-1,col:-1,value:void 0}),Le=i.useCallback((he,Pe)=>{const Ye=he<F,tt={role:Ye?"columnheader":"gridcell","aria-rowindex":he+1,"aria-colindex":Pe+1,"data-aqsp-cell":"","data-row":he,"data-col":Pe,className:"aqsp-cell",...We(e,he,Pe)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Ye?{"data-aqsp-header-row":""}:{}},Ot=fh(e,he,Pe),xt=Ot===null?tt:{...tt,...Ot},je=Wg(e,t,n,A,he,Pe),Ct=Ee.current;return Ct.row=he,Ct.col=Pe,Ct.value=je===null?void 0:je.value,je===null?xt:je.style===null?{...xt,...je.attrs}:{...xt,...je.attrs,style:je.style}},[e,t,n,A,F]),De=i.useCallback(he=>({role:"row","aria-rowindex":he+1,"data-aqsp-row":he,"data-aqsp-cells":"",className:"aqsp-row"}),[]),et=i.useCallback((he,Pe,Ye)=>{let tt=he;return e.getCellFormat!==void 0&&(tt=Bn(he,Vg(Ee.current,Pe,Ye))),K.jsx(_g,{row:Pe,col:Ye,text:he,display:tt,renderCell:U,__onCellRender:N})},[Y,U,N,e]);return K.jsx("div",{ref:L,className:"aqsp-body","data-aqsp-body":"","data-testid":T?`${T}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":$,"aria-labelledby":H,"aria-readonly":_?"true":void 0,onPointerDownCapture:he=>{if(!(he.target instanceof Element&&he.target.closest("[data-aqsp-cells]")!==null)&&he.pointerType==="mouse"){if(he.button!==0){he.preventDefault();return}if(he.preventDefault(),C?.()===!0){he.stopPropagation(),x();return}if(z()&&!I()){he.stopPropagation(),x();return}x()}},children:K.jsx(Ge.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:g,frozenTrailingRows:R,getRowHeight:G,getColWidth:J,getCell:te,getCellProps:Le,getRowProps:De,contentProps:Ig,behaviorOptions:ne,scrollBarOptions:ve,overscanRows:k,overscanCols:b,background:y,onRenderTruncated:a,__maxRenderedCells:O,locale:f,labels:E,callbackThrottleMs:0,onScroll:W,onRangeChange:S,testId:T,children:et})})},Kg=i.memo(Yg),_n=6,rt=3,ro=(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:rt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=tn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-_n,length:rt}),r.push({kind:"unhide",index:s+1,start:c-rt,length:rt})):l>=2*_n?n.push({kind:"resize",index:s,start:c-_n,length:_n}):n.push({kind:"resize",index:s,start:c-rt,length:rt})}return[...n,...r]},Ba=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:rt}),n.push({kind:"resize",index:c,start:h+rt,length:rt})):u>=2*_n?n.push({kind:"resize",index:c,start:h,length:_n}):n.push({kind:"resize",index:c,start:h,length:rt})}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-rt,length:rt}),[...n.reverse(),...r]},Ug=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:g,dividerLeadingRef:R,dividerTrailingRef:F})=>{const H=Ge.useWheelBridge(o),$=i.useCallback(d=>(s.current=d,H(d)),[s,H]),_=i.useCallback(()=>{const{colStart:d,colEnd:L,colVersion:A}=e.get();return`${d}:${L}:${A}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,_,_);const{colStart:W,colEnd:S}=e.get(),x=t.count===0?0:t.offsetOf(Math.min(W,t.count-1));i.useLayoutEffect(()=>{c.current=x,u()},[x,c,u]);const z=d=>h.some(L=>d>=L.startCol&&d<=L.endCol),I=Math.min(Math.max(0,n),t.count),T=wa(t,I),N=I>0?jn(t,0,I-1):[],O=Math.min(Math.max(0,r),t.count-I),m=ba(t,O),p=t.totalSize()-m,C=O>0?jn(t,t.count-O,t.count-1):[],v=jn(t,Math.max(W,I),Math.min(S,Math.max(0,t.count-1)-O)),k=[];for(const d of v)k.push(K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-x,width:t.sizeOf(d)},children:xe.columnIndexToName(d)},d));const b=g?ro(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&m>0)),a=g&&I>0?ro(t,N):null,f=g&&O>0?Ba(t,C):null,E=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-x,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-x,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:$,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:I===0&&O===0?E:K.jsxs(K.Fragment,{children:[N.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:xe.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:T,right:O>0?`calc(${xe.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${xe.SPREADSHEET_SCROLLBAR_SIZE_PX+T}px)))`:void 0},children:[E,I>0?K.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,O>0?K.jsx("div",{ref:F,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),O>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${T}px, calc(100% - ${m+xe.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:xe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[C.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:xe.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},Xg=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:g,dividerLeadingRef:R,dividerTrailingRef:F})=>{const H=Ge.useWheelBridge(n),$=i.useCallback(d=>(r.current=d,H(d)),[r,H]),_=d=>o.some(L=>d>=L.startRow&&d<=L.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:L,rowGeomVersion:A}=e.get();return`${d}:${L}:${A}`},[e]),W=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(W,U,U);const{rowStart:S,rowEnd:x}=e.get(),z=t.count===0?0:t.offsetOf(Math.min(S,t.count-1));i.useLayoutEffect(()=>{l.current=z,c()},[z,l,c]);const I=Math.min(Math.max(0,h),t.count),T=Ca(t,I),N=I>0?jn(t,0,I-1):[],O=Math.min(Math.max(0,g),t.count-I),m=ya(t,O),p=t.totalSize()-m,C=O>0?jn(t,t.count-O,t.count-1):[],v=jn(t,Math.max(S,I),Math.min(x,Math.max(0,t.count-1)-O)),k=[];for(const d of v)k.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-z,height:t.sizeOf(d)},children:d+1},d));const b=u?ro(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&m>0)),a=u&&I>0?ro(t,N):null,f=u&&O>0?Ba(t,C):null,E=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-z,height:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-z,height:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:$,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:xe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I===0&&O===0?E:K.jsxs(K.Fragment,{children:[N.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:T,bottom:O>0?`calc(min(${m}px, max(0px, 100% - ${T}px)))`:void 0},children:[E,I>0?K.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,O>0?K.jsx("div",{ref:F,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),O>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${T}px, calc(100% - ${m}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[C.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},Gg=9,Zg=4,Bi=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},Vi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Jg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),g=i.useRef(null),R=i.useCallback(m=>s.current!==null?m.pointerId===s.current:m.pointerType==="mouse",[]),F=i.useCallback(()=>{const m=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),m.writeResizeGuide(null);const p=g.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),g.current=null);const C=c.current;C!==null&&s.current!==null&&C.hasPointerCapture?.(s.current)&&C.releasePointerCapture(s.current),c.current=null,s.current=null,m.repaintOverlay()},[]),H=i.useCallback((m,p)=>{const C=t.current;return m==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),$=i.useCallback((m,p)=>{const C=t.current,v=C.getSelection().ranges.filter(f=>H(m,f));if(!v.some(f=>m==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const b=v.reduce((f,E)=>f+(m==="col"?E.endCol-E.startCol+1:E.endRow-E.startRow+1),0),y=m==="row"?Math.floor(C.maxOperationCells/ws):C.maxOperationCells;if(b>y)return C.onOperationRejected?.("resize",b,"limit"),null;const a=new Set;for(const f of v){const E=m==="col"?f.startCol:f.startRow,d=m==="col"?f.endCol:f.endRow;for(let L=E;L<=d;L+=1)a.add(L)}return[...a]},[H]),_=i.useCallback((m,p,C)=>{const v=t.current,k=m==="col"?v.colAxis:v.rowAxis,b=Cs(k,p,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:gs,axisKind:m});return b.ok?(v.resizeTracks(m,b.entries),!0):(v.onOperationRejected?.("resize",b.count,b.reason),!1)},[]),U=i.useCallback((m,p)=>{if(p===m.initialSize)return;const C=m.kind==="unhide"?[m.index]:$(m.axis,m.index);C!==null&&_(m.axis,C.map(v=>({index:v,size:p})),m.index)},[$,_]),W=i.useCallback((m,p,C,v)=>{const k=t.current,b=k.fontSourceRef.current;if(b===null)return!1;if(p.length===0)return!0;const y=m.length*p.length;if(y>C)return k.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(b);a.letterSpacing=f.letterSpacing==="normal"?"0px":f.letterSpacing,a.wordSpacing=f.wordSpacing==="normal"?"0px":f.wordSpacing;const E=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),L={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},A=`${L.fontStyle} ${L.fontWeight} ${L.fontSize} ${L.fontFamily}`,D=k.adapter.getConditionalFormats===void 0?null:Ng(k.adapter.getConditionalFormats()),q=Fs(),j=new WeakMap,Y=new WeakMap,G=new Map;for(const ne of m){const ve=D===null?null:Ia(D.filter(Ee=>Ee.ranges.some(Le=>ne>=Le.startCol&&ne<=Le.endCol)));for(const Ee of p){const Le=k.adapter.getCellText(Ee,ne),De=k.adapter.getCellFormat===void 0?void 0:Ns(k.adapter,ve,q,Ee,ne,()=>Le),et=Ee<k.headerRows,he=De===void 0?et?A:E:et?Bi(De,Y,L):Bi(De,j,f),Pe=Bn(Le,De===void 0?void 0:De.value),Ye=G.get(he);Ye===void 0?G.set(he,[{col:ne,text:Pe}]):Ye.push({col:ne,text:Pe})}}const J=new Map;for(const[ne,ve]of G){a.font=ne;for(const Ee of ve){const Le=a.measureText(Ee.text).width,De=J.get(Ee.col);(De===void 0||Le>De)&&J.set(Ee.col,Le)}}const te=[];for(const ne of m){const ve=J.get(ne);ve!==void 0&&ve>0&&te.push({index:ne,size:Math.ceil(ve)+Gg})}return te.length===0?!0:_("col",te,v)},[_]),S=i.useCallback(m=>{const p=t.current,C=$("col",m);if(C===null)return!1;const v=p.handleRef.current,k=v===null?null:v.getFrozenSize(),b=k===null?0:k.rows,y=k===null?0:k.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),E=Math.min(f,p.rowAxis.count-1),d=[],L=new Set,A=D=>{!L.has(D)&&p.rowAxis.sizeOf(D)>0&&(L.add(D),d.push(D))};for(let D=0;D<b;D+=1)A(D);for(let D=a;D<=E;D+=1)A(D);for(let D=p.rowAxis.count-y;D<p.rowAxis.count;D+=1)A(D);return W(C,d,Math.floor(p.maxOperationCells/Zg),m)},[$,W]),x=i.useCallback((m,p,C)=>{const v=m==="col"?t.current.colAxis:t.current.rowAxis,k=Lu(v.sizeOf(p),C);if(k===v.sizeOf(p))return!0;const b=$(m,p);return b===null?!1:_(m,b.map(y=>({index:y,size:k})),p)},[$,_]),z=i.useCallback(m=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(m)===0?!0:S(m):!1},[S]),I=i.useCallback(m=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(m)].filter(k=>p.colAxis.sizeOf(k)>0);if(C.length===0)return!0;const v=[];for(let k=0;k<p.rowAxis.count;k+=1)p.rowAxis.sizeOf(k)>0&&v.push(k);return W(C,v,p.maxOperationCells,null)},[W]),{enabled:T,colBandRef:N,rowBandRef:O}=e;return i.useEffect(()=>{const m=N.current,p=O.current;if(!T||m===null||p===null)return;const C=j=>j==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(j,Y)=>{if(!(Y instanceof Element))return null;const G=Y.closest(C(j));if(G===null)return null;const J=G.hasAttribute("data-aqsp-unhide"),te=Number(G.getAttribute(J?"data-aqsp-unhide":j==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ne=G.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:J?"unhide":"resize",index:te,anchor:ne}},k=j=>{if(!(n.current&&R(j)))return;const Y=r.current;if(Y===null)return;const G=(Y.axis==="col"?j.clientX-Y.startClientX:j.clientY-Y.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(Y.anchor==="trailing"?Y.initialSize-G:Y.initialSize+G)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const J=r.current;if(!n.current||J===null)return;const te=t.current,ne=J.axis==="col"?te.colAxis:te.rowAxis;te.writeResizeGuide({axis:J.axis,position:Vi(J,ne,o.current),anchor:J.anchor})}))},b=()=>{const j=r.current,Y=o.current;F(),j!==null&&U(j,Y)},y=j=>{k(j),n.current&&R(j)&&(l.current&1)!==0&&(j.buttons&1)===0&&b()},a=j=>{j.button!==0||!(n.current&&R(j))||b()},f=(j,Y)=>G=>{const J=t.current;if(h.current=G.pointerType,G.pointerType!=="mouse")return;if(G.button!==0){G.preventDefault();return}const te=v(j,G.target);if(te===null)return;if(G.stopPropagation(),G.preventDefault(),J.isPointing()){J.focusSink();return}if(J.isEditing()&&!J.requestCommit()){J.focusSink();return}J.focusSink();const ne=j==="col"?J.colAxis:J.rowAxis,ve={axis:j,kind:te.kind,index:te.index,anchor:te.anchor,initialSize:ne.sizeOf(te.index),startClientX:G.clientX,startClientY:G.clientY};r.current=ve,o.current=ve.initialSize,l.current=G.buttons,n.current=!0,J.repaintOverlay(),s.current=G.pointerId,c.current=Y;try{Y.setPointerCapture(G.pointerId)}catch{s.current=null}const Ee=y,Le=a;g.current={move:Ee,up:Le},window.addEventListener("pointermove",Ee),window.addEventListener("pointerup",Le),J.writeResizeGuide({axis:j,position:Vi(ve,ne,o.current),anchor:ve.anchor})},E=(j,Y)=>G=>{const J=t.current;if(h.current!=="mouse")return;const te=Y.getRootNode(),ne=te instanceof ShadowRoot?te:Y.ownerDocument,ve=G.target instanceof Element&&G.target.closest(C(j))!==null?G.target:typeof ne.elementFromPoint=="function"?ne.elementFromPoint(G.clientX,G.clientY):null,Ee=v(j,ve);if(Ee!==null){if(G.stopPropagation(),J.isEditing()){J.focusSink();return}if(Ee.kind==="unhide"){_(j,[{index:Ee.index,size:j==="col"?J.defaultColumnWidth:J.defaultRowHeight}],null);return}if(J.autofitEnabled){if(j==="row"){const Le=$("row",Ee.index);Le!==null&&_("row",Le.map(De=>({index:De,size:J.defaultRowHeight})),Ee.index);return}S(Ee.index)}}},d=j=>{!n.current||s.current===null||j.pointerId!==s.current||F()},L=f("col",m),A=f("row",p),D=E("col",m),q=E("row",p);return m.addEventListener("pointerdown",L,{capture:!0}),p.addEventListener("pointerdown",A,{capture:!0}),m.addEventListener("dblclick",D),p.addEventListener("dblclick",q),m.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{m.removeEventListener("pointerdown",L,{capture:!0}),p.removeEventListener("pointerdown",A,{capture:!0}),m.removeEventListener("dblclick",D),p.removeEventListener("dblclick",q),m.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),F()}},[T,N,O,R,F,U,_,$,S]),i.useMemo(()=>({stepTrack:x,autofitColumn:z,autofitColumnsInAllRows:I,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&F()},cancelDrag:F}),[F,x,z,I])},Ps=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Qg=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Ps(n,t.ranges[r]))&&qt(e.anchor,t.anchor)&&qt(e.active,t.active),ew=(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=>sn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:ye(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)}},tw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Ps(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},gr=(e,t,n)=>n.extend?pn(e,t):n.append?{ranges:[...e.ranges,ye(t,t)],anchor:t,active:t}:e.ranges.length===1&&qt(e.anchor,t)&&qt(e.active,t)&&Ps(e.ranges[0],ye(t,t))?e:{ranges:[ye(t,t)],anchor:t,active:t},nw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),pn=(e,t)=>{const n=tw(e,ye(e.anchor,t));return n.ranges.some(r=>wn(r,n.active))?n:{...n,active:nw(n.active,n.ranges[n.ranges.length-1])}},Va=(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(ye({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(ye({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(ye({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(ye({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[ye(n,n)],anchor:n,active:n};const s=o.findIndex(c=>wn(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}},rw=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Wa=(e,t)=>{const n=e.ranges.findIndex(o=>wn(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=rw(e.ranges,r.rangeIndex,r.cell,t),!qt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Ft=24,Wi=32,oo=4,Dn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),g=i.useRef(null),R=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,g.current=null,h.current=null},[]),F=i.useCallback(()=>{const $=u.current,_=e.current,U=g.current;if($===null||_===null||U===null){c.current=null;return}const{clientX:W,clientY:S}=$.getPointerPosition(),x=l.current,z=(W-U.left)/x,I=(S-U.top)/x,T=_.getViewportSize(),N=T.width,O=T.height;if(N<=0||O<=0){c.current=requestAnimationFrame(F);return}const m=y=>Math.min(Wi,Math.ceil(y/Ft*Wi));let p=0,C=0;if(s!=="x"){const y=_.getFrozenSize(),a=y.trailingVisibleHeight;I>O-a-Ft?$.anchorRow!==void 0&&y.trailingRows>0&&$.anchorRow>=t.count-y.trailingRows&&a>0&&I>=O-a||(p=m(I-(O-a-Ft))):I<y.height+Ft&&($.anchorRow!==void 0&&$.anchorRow<y.rows&&y.height>0&&I<y.height||(p=-m(y.height+Ft-I)))}if(s!=="y"){const y=_.getFrozenSize(),a=y.trailingVisibleWidth;z>N-a-Ft?$.anchorCol!==void 0&&y.trailingCols>0&&$.anchorCol>=n.count-y.trailingCols&&a>0&&z>=N-a||(C=m(z-(N-a-Ft))):z<y.width+Ft&&($.anchorCol!==void 0&&$.anchorCol<y.cols&&y.width>0&&z<y.width||(C=-m(y.width+Ft-z)))}const v=C!==0||p!==0?_.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):_.getScrollPosition(),k=v.y,b=v.x;if(k>=0&&b>=0&&t.totalSize()>0&&n.totalSize()>0){const y=_.getFrozenSize(),a=sn({row:vr(t,I,{scroll:k,frozenSize:y.height,trailingSize:y.trailingHeight,extent:T.height}),col:Rr(n,z,{scroll:b,frozenSize:y.width,trailingSize:y.trailingWidth,extent:T.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o($.buildRange(a)))}c.current=requestAnimationFrame(F)},[e,t,n,s,o]),H=i.useCallback($=>{R(),u.current=$,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(F)},[R,F,r]);return i.useEffect(()=>{const $=()=>{document.visibilityState==="hidden"&&R()};return document.addEventListener("visibilitychange",$),()=>{document.removeEventListener("visibilitychange",$),R()}},[R]),i.useMemo(()=>({start:H,stop:R}),[H,R])},Yi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),g=i.useRef(null),R=i.useRef(!1),F=i.useRef(0),H=i.useCallback((T,N)=>{const{axis:O,mainAxis:m,handleRef:p,zoomRef:C}=t.current,v=s.current;if(v===null||m.totalSize()===0)return null;const k=C.current,b=p.current;if(b===null)return null;if(O==="col"){const E=b.getScrollPosition().x;if(E<0)return null;const d=b.getFrozenSize(),L=b.getViewportSize();return Math.min(Math.max(Rr(m,(T-v.left)/k,{scroll:E,frozenSize:d.width,trailingSize:d.trailingWidth,extent:L.width}),0),m.count-1)}const y=b.getScrollPosition().y;if(y<0)return null;const a=b.getFrozenSize(),f=b.getViewportSize();return Math.min(Math.max(vr(m,(N-v.top)/k,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),m.count-1)},[]),$=i.useCallback((T,N)=>{const{axis:O,crossCount:m}=t.current;return O==="col"?{press:{row:0,col:T},extend:{row:m-1,col:N}}:{press:{row:T,col:0},extend:{row:N,col:m-1}}},[]),_=i.useCallback((T,N)=>{const{axis:O,crossCount:m}=t.current;return T.ranges.some(p=>O==="col"?p.startRow===0&&p.endRow===m-1&&N>=p.startCol&&N<=p.endCol:p.startCol===0&&p.endCol===m-1&&N>=p.startRow&&N<=p.endRow)},[]),U=i.useRef(!1),W=i.useRef({clientX:0,clientY:0}),S=i.useCallback(()=>{U.current=!1;const{autoScroller:T,headerRef:N,onDragFrame:O}=t.current;n.current=!1,r.current=null,g.current=null,R.current=!1,F.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const m=N.current;m!==null&&u.current!==null&&m.hasPointerCapture?.(u.current)&&m.releasePointerCapture(u.current),u.current=null,O(null),t.current.repaintOverlay()},[]),x=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.setSelection(T),S()},[S]),{enabled:z,headerRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const N=b=>{const y=t.current;if(b.pointerType!=="mouse")return;if(b.button!==0){b.preventDefault();return}if(R.current=!1,y.pointing?.getPointing()){s.current=T.getBoundingClientRect();const d=H(b.clientX,b.clientY);if(d===null)return;b.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){b.preventDefault(),y.focusSink();return}s.current=T.getBoundingClientRect();const a=H(b.clientX,b.clientY);if(a===null)return;b.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const E=b.ctrlKey||b.metaKey;if(b.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:L}=$(a,a),A={...f,anchor:d};y.setSelection(pn(A,L)),o.current=y.axis==="col"?d.col:d.row}else if(E&&_(f,a))R.current=!0,F.current=a,o.current=a;else{const{press:d,extend:L}=$(a,a),A=gr(f,d,{extend:!1,append:E});y.setSelection(pn(A,L)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:b.clientX,clientY:b.clientY},u.current=b.pointerId,h.current=b.buttons;try{T.setPointerCapture(b.pointerId)}catch{u.current=null}g.current=d=>{const L=t.current.axis==="col"?d.col:d.row,{press:A}=$(o.current,o.current),{extend:D}=$(o.current,L);return ye(A,D)},y.autoScroller.stop(),U.current=!1,W.current={clientX:b.clientX,clientY:b.clientY}},O=b=>u.current!==null?b.pointerId===u.current:b.pointerType==="mouse",m=b=>{if(n.current&&O(b)){if(R.current){const y=b.clientX!==l.current.clientX||b.clientY!==l.current.clientY;if(l.current={clientX:b.clientX,clientY:b.clientY},!y)return;const a=H(b.clientX,b.clientY);if(a===null||a===F.current)return;R.current=!1;const f=t.current,{press:E,extend:d}=$(F.current,F.current),L=gr(f.getSelection(),E,{extend:!1,append:!0});f.setSelection(pn(L,d));const A=g.current,D=Math.abs(b.clientX-W.current.clientX),q=Math.abs(b.clientY-W.current.clientY);A!==null&&Math.max(D,q)>=oo&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:A,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:b.clientX,clientY:b.clientY},!U.current&&g.current!==null){const y=Math.abs(b.clientX-W.current.clientX),a=Math.abs(b.clientY-W.current.clientY);Math.max(y,a)>=oo&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:g.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=g.current;if(!n.current||y===null)return;const a=H(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=b=>{m(b),n.current&&O(b)&&(h.current&1)!==0&&(b.buttons&1)===0&&v(b)},C=b=>{b.button!==0||!(n.current&&O(b))||v(b)},v=b=>{const y=t.current;if(R.current){const{press:f,extend:E}=$(F.current,F.current);y.setSelection(Va(y.getSelection(),ye(f,E),f)),S();return}const a=H(b.clientX,b.clientY);if(a!==null){const{extend:f}=$(o.current,a);y.setSelection(pn(y.getSelection(),f))}S()},k=b=>{!n.current||u.current===null||b.pointerId!==u.current||x()};return T.addEventListener("pointerdown",N),T.addEventListener("pointermove",p),T.addEventListener("pointerup",C),T.addEventListener("lostpointercapture",k),()=>{T.removeEventListener("pointerdown",N),T.removeEventListener("pointermove",p),T.removeEventListener("pointerup",C),T.removeEventListener("lostpointercapture",k),S()}},[z,I,H,$,S,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:x,cancelDrag:S}),[x,S])},ow=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const g=t.offsetOf(r.row),R=g+t.sizeOf(r.row);g<h.height+l?o.scrollBy({y:g-(h.height+l)}):R>l+u-h.trailingVisibleHeight&&o.scrollBy({y:R-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const g=n.offsetOf(r.col),R=g+n.sizeOf(r.col);g<h.width+s?o.scrollBy({x:g-(h.width+s)}):R>s+c-h.trailingVisibleWidth&&o.scrollBy({x:R-(s+c-h.trailingVisibleWidth)})}},sw=50,lw=100,Ya=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<sw:!1,sr={selectAll:Jt("Ctrl+A"),undo:Jt("Ctrl+Z"),redo:Jt("Ctrl+Y"),redoShiftZ:Jt("Ctrl+Shift+Z"),pasteValues:Jt("Ctrl+Shift+V")},iw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),cw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},aw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",uw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const g=c.current,R=u.current;if(!l||g===null||R===null)return;const F=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},H=(a,f,E)=>tn(a,f,E)??f,$=(a,f)=>{const E=s.current;return f==="left"||f==="right"?{row:a.row,col:H(E.colAxis,a.col,f==="right"?1:-1)}:{row:H(E.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),W=(a,f,E,d)=>{if(a.sizeOf(f)>0)return f;const L=tn(a,f,E);if(L!==null)return L;const A=tn(a,f,E===1?-1:1);return A!==null?A:d},S=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},x=a=>$(S(),a),z=(a,f)=>{const E=s.current,d=f==="left"||f==="right",L=f==="right"||f==="down"?1:-1;let A;return E.findDataEdge!==void 0?(A=E.findDataEdge({row:a.row,col:a.col},f),I(A,a,f)):A={row:f==="down"?E.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?E.colAxis.count-1:f==="left"?0:a.col},d?{row:A.row,col:W(E.colAxis,A.col,L,a.col)}:{row:W(E.rowAxis,A.row,L,a.row),col:A.col}},I=(a,f,E)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const L=E==="left"||E==="right";if(L?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${L?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},T=(a,f,E)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${E} component ${a} (count ${f})`)},N=a=>{const f=s.current,E=f.getSelection();if(Wa(E,a)===E){f.moveActive({mode:"reset",cell:$(E.active,a)});return}f.moveActive({mode:"cycle",direction:a})},O=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,E=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
14
- ${a.value.slice(E)}`,a.setSelectionRange(f+1,f+1)},m=(a,f)=>{const E=s.current,d=E.pageExtent();return d<=0?H(E.rowAxis,a,f==="down"?1:-1):E.rowAxis.indexAt(E.rowAxis.offsetOf(a)+(f==="down"?d:-d))},p=a=>{const f=s.current;if(r.current=!1,Ya(a,t.current))return;const E=a.ctrlKey||a.metaKey,d=a.altKey,L=cw[a.key];if(o.current&&!iw.has(a.key)&&!f.isDragging()&&F(),f.isEditing()){const D=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!E&&!a.shiftKey&&!d&&f.abortDrag();return}const q=f.pointing;if(q!==void 0){if(L!==void 0&&!d){const Y=q.getReferenceCursor();if(Y!==null){a.preventDefault();const G=sn(Y.cursor,f.rowAxis.count,f.colAxis.count),J=sn(Y.origin,f.rowAxis.count,f.colAxis.count),te=E?z(G,L):$(G,L);if(f.ensureCellVisible(te),q.insertReference(a.shiftKey?ye(J,te):te,Y.axis),f.onPointFrame!==void 0){const ne=a.shiftKey?ye(J,te):ye(te,te);f.onPointFrame(Y.axis==="columns"?ye({row:0,col:ne.startCol},{row:f.rowAxis.count-1,col:ne.endCol}):Y.axis==="rows"?ye({row:ne.startRow,col:0},{row:ne.endRow,col:f.colAxis.count-1}):ne),o.current=!0}return}}if(a.key==="F2"&&!E&&!a.shiftKey&&!d&&q.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!E&&!a.shiftKey&&!d&&q.cycleAnchorAtCaret()){a.preventDefault();return}}const j=f.commands;if(j!==void 0){const Y=li(j.table,a);if(Y!==null&&Ms.has(Y)&&j.isAvailable(Y)){a.preventDefault(),j.execute(Y);return}}if(L!==void 0&&!d){if(E&&a.shiftKey){a.preventDefault();return}if(E)return;if(D==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:x(L)}):f.moveActive({mode:"reset",cell:$(f.getSelection().active,L)});return}return}if(a.key==="Enter"&&d&&!E&&!a.shiftKey){a.preventDefault(),O();return}if((a.key==="Enter"||a.key==="Tab")&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const Y=!a.shiftKey;N(a.key==="Tab"?Y?"right":"left":Y?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const Y=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(Y.row,a.key==="PageDown"?"down":"up"),col:Y.col}});return}if(a.key==="Escape"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const A=f.commands;if(A!==void 0){const D=li(A.table,a);if(D!==null&&A.isAvailable(D)){a.preventDefault(),A.execute(D);return}}if(L!==void 0&&!d){const D=L==="left"||L==="right",q=L==="right"||L==="down"?1:-1;if(E&&a.shiftKey){a.preventDefault();const j=f.getSelection(),Y=S();let G;if(f.findDataEdge!==void 0){const J=D?{row:j.active.row,col:Y.col}:{row:Y.row,col:j.active.col},te=f.findDataEdge(J,L);G=D?te.col:te.row,T(G,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),G=W(D?f.colAxis:f.rowAxis,G,q,D?Y.col:Y.row)}else{const J=D?f.colAxis:f.rowAxis;G=q===1?U(J):_(J)}f.moveActive({mode:"extend",cell:D?{row:Y.row,col:G}:{row:G,col:Y.col}});return}if(E){a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,L)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:x(L)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:$(f.getSelection().active,L)});return}if(aw(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!E&&!d){a.preventDefault();const D=!a.shiftKey;N(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const q=S();f.moveActive({mode:"extend",cell:{row:E?_(f.rowAxis):q.row,col:_(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?_(f.rowAxis):D.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const q=S();f.moveActive({mode:"extend",cell:{row:E?U(f.rowAxis):q.row,col:U(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?U(f.rowAxis):D.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!E&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const j=S();f.moveActive({mode:"extend",cell:{row:m(j.row,D),col:j.col}});return}const q=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(q.row,D),col:q.col}});return}if(a.key==="F2"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection(),q=At(D.ranges);if(q>f.maxOperationCells){f.onOperationRejected?.("delete",q,"limit");return}if(f.adapter!==void 0&&Pn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:q});return}const j=[],Y=f.adapter!==void 0&&Zr(f.adapter).hyperlink;Zt(D.ranges,G=>{j.push(Y?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),f.commitEdits(j,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(E||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(nr(sr.selectAll,a)){a.preventDefault();const D=f.getSelection(),q=ye({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[q],anchor:D.anchor,active:D.active});return}if(nr(sr.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(nr(sr.redo,a)||nr(sr.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!E&&!d||a.key==="ContextMenu"&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection().active;f.ensureCellVisible(D);const q=h.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),Y=Math.max(0,j.y),G=Math.max(0,j.x),J=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),te=q===null?{width:0,height:0}:q.getViewportSize(),ne=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:gn(f.rowAxis,D.row,{scroll:Y,frozenCount:J.rows,trailingCount:J.trailingRows,extent:te.height})*ne,left:mn(f.colAxis,D.col,{scroll:G,frozenCount:J.cols,trailingCount:J.trailingCols,extent:te.width})*ne,width:f.colAxis.sizeOf(D.col)*ne,height:f.rowAxis.sizeOf(D.row)*ne}});return}if(a.key===" "&&!d&&E!==a.shiftKey){a.preventDefault();const D=f.getSelection(),q=D.ranges.map(j=>E?ye({row:0,col:j.startCol},{row:f.rowAxis.count-1,col:j.endCol}):ye({row:j.startRow,col:0},{row:j.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:q,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&nr(sr.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},v=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},lw)},k=()=>{const a=s.current;if(F(),!a.isEditing()){if(r.current){r.current=!1;const f=g.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){g.value=f,g.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},b=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),F()};return g.addEventListener("keydown",p),g.addEventListener("keyup",b),g.addEventListener("blur",y),g.addEventListener("compositionstart",C),g.addEventListener("compositionend",v),g.addEventListener("input",k),()=>{g.removeEventListener("keydown",p),g.removeEventListener("keyup",b),g.removeEventListener("blur",y),g.removeEventListener("compositionstart",C),g.removeEventListener("compositionend",v),g.removeEventListener("input",k),n.current!==null&&window.clearTimeout(n.current),F()}},[l,c,u,h])},dw=()=>{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)})}},fw=4,pw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),hw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),g=i.useRef(null),R=i.useRef(0),F=i.useRef(null),H=i.useRef(null),$=i.useRef(!1),_=i.useCallback(T=>g.current!==null?T.pointerId===g.current:T.pointerType==="mouse",[]),U=i.useCallback((T,N)=>{const{handleRef:O,rowAxis:m,colAxis:p}=t.current,C=O.current,v=s.current;if(C===null||v===null)return null;const{x:k,y:b}=C.getScrollPosition();if(b<0||k<0||m.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return sn({row:vr(m,(N-v.top)/y,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Rr(p,(T-v.left)/y,{scroll:k,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},m.count,p.count)},[]),W=i.useCallback(T=>{const N=r.current;if(N===null)return ye(T,T);const O=ye({row:Math.min(N.startRow,T.row),col:Math.min(N.startCol,T.col)},{row:Math.max(N.endRow,T.row),col:Math.max(N.endCol,T.col)}),m=O.startRow!==N.startRow||O.endRow!==N.endRow||O.startCol!==N.startCol||O.endCol!==N.endCol;return o.current=m?O:null,m?O:N},[]),S=i.useCallback(()=>{const T=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,F.current!==null&&(cancelAnimationFrame(F.current),F.current=null),T.xAutoScroller.stop(),T.yAutoScroller.stop(),$.current=!1,u.current=!1,h.current={dx:0,dy:0},T.writeFillPreview(null);const N=H.current;N!==null&&(window.removeEventListener("pointermove",N.move),window.removeEventListener("pointerup",N.up),H.current=null);const O=t.current.handleNodeRef.current;O!==null&&g.current!==null&&O.hasPointerCapture?.(g.current)&&O.releasePointerCapture(g.current),g.current=null,T.repaintOverlay()},[]),x=i.useCallback(()=>{const T=t.current,N=r.current,O=o.current;if(S(),N===null||O===null)return;const m=mh(N,O);if(m>T.maxOperationCells){T.onOperationRejected?.("fill",m,"limit");return}if(Pn(T.adapter,gh(N,O))){const v=(O.endRow-O.startRow+1)*(O.endCol-O.startCol+1),k=(N.endRow-N.startRow+1)*(N.endCol-N.startCol+1);T.rejectReadOnly({kind:"operation",op:"fill",cellCount:v-k});return}const p=wh((v,k)=>na(T.adapter,v,k),N,O,ra);if(T.commitEdits(p,{source:"fill"})===null)return;const C=T.getSelection();T.setSelection({ranges:[O],anchor:C.anchor,active:C.active})},[S]),{enabled:z,handleNodeRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const N=v=>{O(v),n.current&&_(v)&&(R.current&1)!==0&&(v.buttons&1)===0&&x()},O=v=>{if(!(n.current&&_(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const k=Math.abs(v.clientX-c.current.clientX),b=Math.abs(v.clientY-c.current.clientY);if(!u.current&&Math.max(k,b)>=fw&&(u.current=!0),!!u.current){if(!$.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:W,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),$.current=!0}F.current===null&&(F.current=requestAnimationFrame(()=>{if(F.current=null,!(n.current&&u.current))return;const y=U(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(W(y))}))}},m=v=>{v.button!==0||!(n.current&&_(v))||x()},p=v=>{const k=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),k.focusSink();const b=k.getSelection(),y=b.ranges[b.ranges.length-1];r.current=y,o.current=null,u.current=!1,k.xAutoScroller.stop(),k.yAutoScroller.stop(),$.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,R.current=v.buttons,n.current=!0,k.repaintOverlay(),s.current=k.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=k.handleRef.current?.getScrollPosition()??{x:-1,y:-1},E=f.y;if(a!==null&&E>=0&&f.x>=0){const A=f.x,D=k.zoomRef.current,q=k.handleRef.current?.getFrozenSize()??pw,j=k.handleRef.current?.getViewportSize()??{width:0,height:0},Y={scroll:A,frozenCount:q.cols,trailingCount:q.trailingCols,extent:j.width},G={scroll:E,frozenCount:q.rows,trailingCount:q.trailingRows,extent:j.height},J=mn(k.colAxis,y.endCol,Y)+k.colAxis.sizeOf(y.endCol),te=gn(k.rowAxis,y.endRow,G)+k.rowAxis.sizeOf(y.endRow),ne=J-1,ve=y.endCol>=q.cols&&q.width>0?Math.max(ne,q.width):ne,Le=!(y.endCol>=k.colAxis.count-q.trailingCols)&&q.trailingWidth>0?Math.min(ve,j.width-q.trailingVisibleWidth-1):ve,De=te-1,et=y.endRow>=q.rows&&q.height>0?Math.max(De,q.height):De,Pe=!(y.endRow>=k.rowAxis.count-q.trailingRows)&&q.trailingHeight>0?Math.min(et,j.height-q.trailingVisibleHeight-1):et;h.current={dx:v.clientX-(a.left+Le*D),dy:v.clientY-(a.top+Pe*D)}}else h.current={dx:0,dy:0};g.current=v.pointerId;try{T.setPointerCapture(v.pointerId)}catch{g.current=null}const d=N,L=m;H.current={move:d,up:L},window.addEventListener("pointermove",d),window.addEventListener("pointerup",L),k.writeFillPreview(r.current)},C=v=>{!n.current||g.current===null||v.pointerId!==g.current||S()};return T.addEventListener("pointerdown",p),T.addEventListener("lostpointercapture",C),()=>{T.removeEventListener("pointerdown",p),T.removeEventListener("lostpointercapture",C),S()}},[z,I,_,U,W,S,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&S()},cancelDrag:S}),[S])},mw=320,Jr=8,gw=64,ww=150,Ka=e=>Math.max(0,Math.min(mw,e.width-xe.SPREADSHEET_SCROLLBAR_SIZE_PX-Jr)),Cw=(e,t,n)=>{const r=n.width-xe.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-xe.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Ka(n),l=Math.max(0,Math.min(t,o-Jr)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+s<=r,g=[e.left,c-s],R=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of R)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const F=o-u,H=e.top,$=Math.min(l,Math.max(F,H));if($>=gw){const _=F>=H?u:e.top-$;for(const U of g)if(h(U))return{left:U,top:_,width:s,height:$}}return{left:Jr,top:Jr,width:s,height:l}},bw=(e,t,n,r)=>t===null||e!==null&&qt(e,t)||n?!1:r(t),yw=(e,t)=>{switch(e.kind){case"note":return K.jsx(Oa,{ctx:e,labels:t});case"note-tip":return K.jsx(xa,{ctx:e,labels:t});case"comment":return K.jsx(ka,{ctx:e,labels:t});case"link":return K.jsx(Sa,{ctx:e,labels:t});case"list":return K.jsx(Ea,{ctx:e,labels:t});default:return K.jsx(Aa,{ctx:e,labels:t})}},Qo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Rw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const g=i.useRef(e);g.current=e;const R=Qo(s),F=Qo(l),H=i.useRef(null),$=(x,z)=>{const I=g.current.getLayerSize();x.style.width=`${Ka(I)}px`,x.style.maxHeight="";const T=Cw(z,x.offsetHeight,I);x.style.left=`${T.left-z.left}px`,x.style.top=`${T.top-z.top}px`,x.style.maxHeight=`${T.height}px`};i.useLayoutEffect(()=>{const x=c.current;if(x===null||s===null){H.current=null;return}if($(x,s.anchorRect),s.kind==="message")return;const z=Qo(s);if(H.current===z)return;H.current=z;const I=x.querySelector("[data-aqsp-popover-autofocus]");I!==null?I.focus({preventScroll:!0}):x.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const x=u.current,z=h.current;x===null||z===null||$(x,z.anchorRect)},[F]);const _=x=>t===void 0?yw(x,n):t(x),U=x=>{e.isCompositionKey(x.nativeEvent)&&x.stopPropagation()},W=x=>{x.key==="Escape"&&!x.defaultPrevented&&(x.preventDefault(),e.close())},S=x=>{e.registerCompositionEnd(x.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:W,onCompositionEnd:S,children:[K.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},R)}),K.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:_(l)})})]})},vw=["note","note-tip","comment","link","list","message"],kw=(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}},lr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&kw(e,n),Sw=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),g=i.useRef(null),R=i.useRef(null),F=i.useRef(null),H=i.useRef(null),$=i.useId(),_=i.useCallback(A=>{const D=t.current,q=D.handleRef.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),Y=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),G=q===null?{width:0,height:0}:q.getViewportSize();return{top:gn(D.rowAxis,A.row,{scroll:Math.max(0,j.y),frozenCount:Y.rows,trailingCount:Y.trailingRows,extent:G.height}),left:mn(D.colAxis,A.col,{scroll:Math.max(0,j.x),frozenCount:Y.cols,trailingCount:Y.trailingCols,extent:G.width}),width:D.colAxis.sizeOf(A.col),height:D.rowAxis.sizeOf(A.row)}},[]),U=i.useCallback(A=>{const D=t.current;D.anchors.current={...D.anchors.current,...A},D.repaintOverlay()},[]),W=i.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),S=i.useCallback(()=>{const A=t.current.sinkRef.current;if(A===null)return;const D=c.current;D!==null&&qt(D,t.current.getActive())?A.setAttribute("aria-describedby",$):A.getAttribute("aria-describedby")===$&&A.removeAttribute("aria-describedby")},[$]),x=i.useCallback(()=>(W(),h.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),S(),!0)),[W,U,S]),z=i.useCallback(()=>{W(),g.current=window.setTimeout(()=>{g.current=null,x()},ww)},[W,x]),I=i.useCallback(A=>{const D=t.current;W();const q=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(A.row,A.col);q===void 0||q===""||(c.current=A,s({kind:"note-tip",cell:A,anchorRect:_(A),current:q,close:x}),U({tip:A}),S())},[_,W,x,U,S]),T=i.useCallback(A=>{const D=t.current;if(A===null&&h.current)return;const q=u.current;u.current=A;const j=c.current;if(j!==null&&A!==null&&qt(j,A)){W();return}const Y=G=>{const J=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(G.row,G.col);return J!==void 0&&J!==""};if(bw(q,A,D.isDraggingAny(),Y)){A!==null&&I(A);return}j!==null&&z()},[I,W,z]),N=i.useCallback((A,D)=>{const q=t.current,j=q.bodyRef.current,Y=q.handleRef.current;if(j===null||Y===null)return null;const G=j.getBoundingClientRect(),J=q.zoomRef.current,te=Y.getScrollPosition(),ne=Y.getFrozenSize(),ve=Y.getViewportSize();return sn({row:vr(q.rowAxis,(D-G.top)/J,{scroll:Math.max(0,te.y),frozenSize:ne.height,trailingSize:ne.trailingHeight,extent:ve.height}),col:Rr(q.colAxis,(A-G.left)/J,{scroll:Math.max(0,te.x),frozenSize:ne.width,trailingSize:ne.trailingWidth,extent:ve.width})},q.rowAxis.count,q.colAxis.count)},[]),O=i.useCallback(A=>{F.current=A,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const D=F.current;T(D===null?null:"cell"in D?D.cell:N(D.clientX,D.clientY))}))},[T,N]),m=i.useCallback(A=>O({cell:A}),[O]),p=i.useCallback(()=>x(),[x]),C=i.useCallback(A=>{if(l.current===null)return;const D=t.current;l.current=null,r(null),U({interactive:null}),(A===void 0||A.restoreFocus)&&D.focusSink({preventScroll:!0}),D.isEditing()||D.rearmSink()},[U]),v=i.useCallback(A=>{l.current=A.kind,r(A),U({interactive:A.cell})},[U]),k=i.useCallback(A=>{const D=t.current;return Qc(D.adapter)?{cellReadOnly:We(D.adapter,A.row,A.col)}:{}},[]),b=i.useCallback((A,D)=>{const q=t.current;if(We(q.adapter,A.cell.row,A.cell.col)){q.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...A,...k(A.cell)});return}if(q.commitEdits(D,{source:"annotate"})===null){v({...A,rejected:!0});return}C()},[v,C,k]),y=i.useCallback((A,D)=>{const q=t.current;if(!lr(q.adapter,q.popovers,A))throw new RangeError(`[spreadsheet] openPopover("${A}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const j=q.getActive();if(A==="list"&&We(q.adapter,j.row,j.col)){q.rejectReadOnly({kind:"edit",cell:j,editSession:"none"});return}if(A==="note-tip"){I(j);return}if(A==="message"){if(l.current!==null&&l.current!=="message")return;const te=D!==void 0&&D.message!==void 0?D.message:void 0,ne=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col),ve=te!==void 0?te:ne===void 0?void 0:ne.inputMessage;if(ve===void 0)return;const Ee=D!==void 0&&D.rejected===!0;v({kind:"message",cell:j,anchorRect:_(j),current:{title:Ne(q.labels,"messageTitle"),message:ve,rejected:Ee},close:C});return}if(q.isEditing()&&!q.requestCommit())return;if(A==="list"){const te=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col);if(te===void 0||te.type!=="list")return;const ne=D!==void 0&&D.typed!==void 0?D.typed:"";x(),q.focusSink({preventScroll:!0}),v({kind:"list",cell:j,anchorRect:_(j),current:te.values,typed:ne,commit:ve=>{if(We(t.current.adapter,j.row,j.col)){t.current.rejectReadOnly({kind:"edit",cell:j,editSession:"none"}),C();return}t.current.commitEdits([{row:j.row,col:j.col,text:ve}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(x(),q.focusSink({preventScroll:!0}),A==="note"){const te=q.adapter.getCellNote===void 0?void 0:q.adapter.getCellNote(j.row,j.col),ne={kind:"note",cell:j,anchorRect:_(j),current:te,commit:ve=>{b(ne,[{row:j.row,col:j.col,note:ve}])},close:C,rejected:!1,...k(j)};v(ne);return}if(A==="comment"){const te=q.adapter.getCellComments===void 0?void 0:q.adapter.getCellComments(j.row,j.col),ne={kind:"comment",cell:j,anchorRect:_(j),current:te===void 0?[]:te,commit:ve=>{b(ne,[{row:j.row,col:j.col,comments:ve}])},close:C,rejected:!1,...k(j)};v(ne);return}const Y=q.adapter.getCellHyperlink===void 0?void 0:Yn(q.adapter.getCellHyperlink(j.row,j.col)),G=q.adapter.getCellText(j.row,j.col),J={kind:"link",cell:j,anchorRect:_(j),current:{text:G,url:Y},commit:te=>{const ne=te.url===null?null:on(te.url);if(ne===null&&te.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(te.url)}`);const ve=te.text===G?{row:j.row,col:j.col,hyperlink:ne}:{row:j.row,col:j.col,text:te.text,hyperlink:ne};b(J,[ve])},close:C,canOpen:q.onHyperlinkOpen!==void 0,open:()=>{const te=t.current.onHyperlinkOpen;te!==void 0&&Y!==void 0&&te(Y,j)},rejected:!1,...k(j)};v(J)},[_,C,b,x,v,I,k]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const A=f.current;if(!a||A===null)return;const D=j=>{const Y=t.current;lr(Y.adapter,Y.popovers,"note-tip")&&O({clientX:j.clientX,clientY:j.clientY})},q=()=>{lr(t.current.adapter,t.current.popovers,"note-tip")&&O({cell:null})};return A.addEventListener("pointermove",D),A.addEventListener("pointerleave",q),()=>{A.removeEventListener("pointermove",D),A.removeEventListener("pointerleave",q)}},[a,f,O]),i.useEffect(()=>()=>{R.current!==null&&cancelAnimationFrame(R.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:E,popovers:d}=e,L=i.useMemo(()=>vw.some(A=>lr(E,d,A)),[E,d]);return i.useMemo(()=>({layerEnabled:L,isKindEnabled:A=>lr(t.current.adapter,t.current.popovers,A),open:y,close:C,isOpen:()=>l.current,onCellHover:m,hideTip:p,onTipPointerEnter:()=>{h.current=!0,W()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&z()},syncTipAriaDescribedBy:S,context:n,tipContext:o,registerCompositionEnd:A=>{H.current=A},isCompositionKey:A=>Ya(A,H.current),getLayerSize:()=>{const A=t.current.handleRef.current;return A===null?{width:0,height:0}:A.getViewportSize()},tipId:$}),[L,y,C,m,p,W,z,S,n,o,$])},Ew=(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},Ua=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),g=e.getViewportSize();return sn({row:vr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:g.height}),col:Rr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:g.width})},n.count,r.count)},Aw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),g=i.useRef(!1),R=i.useRef(null),F=i.useRef(""),H=i.useRef(!1),$=i.useRef(!1),_=i.useCallback((O,m)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:k}=t.current;return Ua(p.current,o.current,C,v,k.current,O,m)},[]),U=i.useRef(!1),W=i.useRef(null),S=i.useRef(null),x=i.useRef({clientX:0,clientY:0}),z=i.useCallback(()=>{const{autoScroller:O,bodyRef:m,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,U.current=!1,W.current=null,S.current=null,g.current=!1,R.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),O.stop();const C=m.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),I=i.useCallback(()=>{if(!n.current)return;const O=r.current;O!==null&&t.current.setSelection(O),z()},[z]),{enabled:T,bodyRef:N}=e;return i.useEffect(()=>{const O=N.current;if(!T||O===null)return;const m=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const L=t.current;if(d.pointerType==="mouse"&&d.button===0&&(g.current=!1,R.current=null,$.current=!1),H.current=m(d.target),!H.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(L.getPointing?.()){L.focusSink();return}if(L.isEditing()&&!L.requestCommit()){d.stopPropagation(),L.focusSink();return}L.focusSink()}return}if(F.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((L.pointDragRef===void 0?null:L.pointDragRef.current)?.onPointerDown(d))return;if(L.isEditing()&&!L.requestCommit()){d.preventDefault(),L.focusSink();return}o.current=O.getBoundingClientRect();const D=_(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),L.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&L.openHyperlinkAt?.(D)===!0){$.current=!0;return}const q=L.getSelection();r.current=q;const j=d.shiftKey,Y=d.ctrlKey||d.metaKey,G=Y&&!j&&q.ranges.some(te=>wn(te,D));g.current=G,R.current=G?D:null,G||L.setSelection(gr(q,D,{extend:j,append:Y})),n.current=!0,L.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{O.setPointerCapture(d.pointerId)}catch{c.current=null}const J=G?D:L.getSelection().anchor;h.current=te=>ye(J,te),W.current=J.col,S.current=J.row,L.autoScroller.stop(),U.current=!1,x.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",v=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!U.current&&h.current!==null){const L=Math.abs(d.clientX-x.current.clientX),A=Math.abs(d.clientY-x.current.clientY);Math.max(L,A)>=oo&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:W.current??void 0,anchorRow:S.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const L=h.current;if(!n.current||L===null)return;const A=t.current,D=_(s.current.clientX,s.current.clientY);D!==null&&A.onDragFrame(L(D))}))}},k=d=>{v(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},b=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const L=t.current,A=_(d.clientX,d.clientY);if(A!==null){const D=R.current;g.current&&D!==null?L.setSelection(Va(L.getSelection(),ye(D,A),D)):L.setSelection(pn(L.getSelection(),A))}z()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||I()},f=d=>{const L=t.current;if(!m(d.target)||F.current!=="mouse"||L.isAnyDragging())return;if(L.isEditing()&&!L.requestCommit()){L.focusSink();return}L.focusSink(),o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);if(A===null)return;const D=L.getSelection();D.ranges.some(j=>wn(j,A))||L.setSelection(gr(D,A,{extend:!1,append:!1})),L.onContextMenuSelect(A,d)},E=d=>{const L=t.current;if(!H.current||F.current!=="mouse"||L.getPointing?.()||$.current)return;o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);A!==null&&qt(L.getSelection().active,A)&&L.onRequestEdit(A,L.caretFromPointEnabled(A)?Ew(d.clientX,d.clientY,A):void 0)};return O.addEventListener("pointerdown",p),O.addEventListener("pointermove",k),O.addEventListener("pointerup",b),O.addEventListener("lostpointercapture",a),O.addEventListener("contextmenu",f),O.addEventListener("dblclick",E),()=>{O.removeEventListener("pointerdown",p),O.removeEventListener("pointermove",k),O.removeEventListener("pointerup",b),O.removeEventListener("lostpointercapture",a),O.removeEventListener("contextmenu",f),O.removeEventListener("dblclick",E),z()}},[T,N,_,z,I]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:I,cancelDrag:z}),[I,z])},Ow=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),g=i.useRef(null),R=i.useRef(null),F=i.useRef(!1),H=i.useCallback((x,z)=>{const{handleRef:I,rowAxis:T,colAxis:N,zoomRef:O}=t.current;return Ua(I.current,o.current,T,N,O.current,x,z)},[]),$=i.useCallback(()=>{const{autoScroller:x,bodyRef:z,onDragFrame:I}=t.current;n.current=!1,r.current=null,g.current=null,R.current=null,F.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),x.stop();const T=z.current;T!==null&&u.current!==null&&T.hasPointerCapture?.(u.current)&&T.releasePointerCapture(u.current),u.current=null,I(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const x=r.current;x!==null&&t.current.restoreSink(x),$()},[$]),U=i.useCallback(x=>{const z=t.current,I=z.bodyRef.current;if(!z.enabled||I===null||!z.getPointing())return!1;o.current=I.getBoundingClientRect();const T=H(x.clientX,x.clientY);if(T===null)return o.current=null,!1;const N=z.captureSink();if(N===null)return o.current=null,!1;x.preventDefault(),z.focusSink(),r.current=N,R.current=T,z.insertReference(T,"cells"),n.current=!0,s.current={clientX:x.clientX,clientY:x.clientY},l.current={clientX:x.clientX,clientY:x.clientY},u.current=x.pointerId,h.current=x.buttons;try{I.setPointerCapture(x.pointerId)}catch{u.current=null}return g.current=O=>{const m=ye(T,O);return t.current.insertReference(m,"cells"),m},z.autoScroller.stop(),F.current=!1,z.onDragFrame(ye(T,T)),!0},[H]),{enabled:W,bodyRef:S}=e;return i.useEffect(()=>{const x=S.current;if(!W||x===null)return;const z=O=>u.current!==null?O.pointerId===u.current:O.pointerType==="mouse",I=O=>{if(!(n.current&&z(O)))return;s.current={clientX:O.clientX,clientY:O.clientY};const m=g.current,p=R.current;if(!F.current&&m!==null&&p!==null){const C=Math.abs(O.clientX-l.current.clientX),v=Math.abs(O.clientY-l.current.clientY);Math.max(C,v)>=oo&&(F.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=g.current;if(!n.current||C===null)return;const v=H(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(h.current&1)!==0&&(O.buttons&1)===0&&$()},T=O=>{O.button!==0||!(n.current&&z(O))||$()},N=O=>{!n.current||u.current===null||O.pointerId!==u.current||$()};return x.addEventListener("pointermove",I),x.addEventListener("pointerup",T),x.addEventListener("lostpointercapture",N),()=>{x.removeEventListener("pointermove",I),x.removeEventListener("pointerup",T),x.removeEventListener("lostpointercapture",N),$()}},[W,S,H,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:$,onPointerDown:U}),[_,$,U])},xw=Object.freeze({width:0,height:0}),Tw=new Set(["hidden","clip","scroll","auto","overlay"]),Lw=(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})`)},$w=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)})`)},Ki=(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},Dw=24,Mw=200,Xa=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Ui=5,zw=/^#[0-9A-Fa-f]{6}$/,Fw=Object.freeze({row:!1,column:!1,intersection:!1}),Xi=Object.freeze({ok:!0}),Gi=(e,t)=>{if(t===void 0)return Xa;if(t.length!==Ui)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Ui} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!zw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Nw=e=>{for(const t of["row","column","intersection"])if(Xe(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},Pw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Ra},_w=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},qw=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Ge.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Mn={ranges:[ye({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Iw=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=Dw,defaultColumnWidth:l=xe.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:g=0,tapScrollCircleOptions:R,overscanRows:F,overscanCols:H,background:$,onRenderTruncated:_,renderCell:U,onSelectionChange:W,onCellContextMenu:S,onUndoRequest:x,onRedoRequest:z,onCopyMultiRange:I,onOperationRejected:T,onEditRejected:N,onReadOnlyRejected:O,formatReadOnlyAnnouncement:m,dataVersion:p,maxOperationCells:C=xe.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:v=!0,enableResizeUI:k=!0,headings:b=!0,onContentSizeChange:y,formatCellAnnouncement:a,formatSelectionAnnouncement:f,formatCommandAnnouncement:E,formatResizeAnnouncement:d,locale:L,labels:A,shortcuts:D,colors:q,formats:j,highlight:Y,defaultHighlight:G,onHighlightChange:J,highlightColors:te,popovers:ne,renderPopover:ve,onClipChange:Ee,onHyperlinkOpen:Le,onValidationRejected:De,onPasteSpecialRequest:et,onClipboardUnavailable:he,onPasteResolved:Pe,now:Ye=Date.now,zoom:tt,defaultZoom:Ot,onZoomChange:xt,testId:je,className:Ct,__onCellRender:Cn,__onVirtualKeyboardRaise:lt,__maxRenderedCells:kr},bn){const se=i.useMemo(()=>r?ah(t):t,[t,r]),ue=Ni(se.rowCount,s),de=Ni(se.colCount,l),jt=i.useRef(null);jt.current===null&&(jt.current=dw());const Ae=jt.current,Ht=Ge.resolveVirtualScrollLocale(L),it=i.useMemo(()=>aa(L,A),[L,A]),yn=qw(Fh(it)),Bt=i.useMemo(()=>$h(D),[D]),Sr=i.useMemo(()=>{if(!k)return;const P=[...Bt].filter(([,Z])=>Wo.includes(Z)).sort(([,Z],[,ee])=>Wo.indexOf(Z)-Wo.indexOf(ee)).map(([Z])=>Eh(Z)).filter(Z=>Z!==null);return P.length===0?void 0:P.join(" ")},[Bt,k]),Kn=i.useMemo(()=>({fill:Gi("fill",q===void 0?void 0:q.fill),font:Gi("font",q===void 0?void 0:q.font)}),[q]),fo=i.useMemo(()=>te===void 0?void 0:Nw(te),[te]);if(se.getConditionalFormats!==void 0&&se.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");Lw(n,u),$w(o);const Er=i.useCallback(()=>Ae.get().editVersion,[Ae]),po=i.useCallback(w=>Ae.subscribeCoalesced(w),[Ae]),ho=i.useSyncExternalStore(po,Er,Er)+(p===void 0?0:p),Vt=se.getConditionalFormats===void 0?null:se.getConditionalFormats(),Rn=i.useMemo(()=>({index:Vt===null?null:Ia(Vt),memo:Fs()}),[se,Vt,ho]),Un=i.useRef(Rn.index);Un.current=Rn.index;const M=i.useRef(Rn.memo);M.current=Rn.memo;const B=i.useCallback((w,P,Z)=>Ns(se,Un.current,M.current,w,P,Z),[se]),X=i.useRef(null),[V,Q]=i.useState(()=>xe.clampSpreadsheetZoom(Ot??1)),le=xe.clampSpreadsheetZoom(tt??V),re=i.useRef(le);re.current=le;const Oe=i.useRef(le);Oe.current=le;const ke=i.useRef(null),He=i.useRef(xt);He.current=xt;const Be=i.useRef(tt!==void 0);Be.current=tt!==void 0;const Ie=i.useCallback(w=>{const P=xe.clampSpreadsheetZoom(w);P!==Oe.current&&(Oe.current=P,Be.current||Q(P),He.current?.(P))},[]),Re=se.rowCount===0||se.colCount===0,ie=!Re;i.useEffect(()=>{const w=X.current;if(!ie||w===null)return;const P=ee=>{ee.defaultPrevented||!ee.altKey||ee.ctrlKey||ee.metaKey||ee.shiftKey||ee.deltaY!==0&&(ee.preventDefault(),ee.stopPropagation(),!ke.current?.()&&Ie(xe.stepSpreadsheetZoom(Oe.current,ee.deltaY<0?1:-1)))},Z=ee=>{if(ee.defaultPrevented||!(ee.ctrlKey&&ee.altKey)||ee.metaKey||ee.getModifierState("AltGraph"))return;const ge=ee.key==="="||ee.key==="+"?xe.stepSpreadsheetZoom(Oe.current,1):ee.key==="-"?xe.stepSpreadsheetZoom(Oe.current,-1):ee.key==="0"?1:null;ge!==null&&(ee.preventDefault(),ee.stopPropagation(),!ke.current?.()&&Ie(ge))};return w.addEventListener("wheel",P,{passive:!1,capture:!0}),w.addEventListener("keydown",Z,!0),()=>{w.removeEventListener("wheel",P,{capture:!0}),w.removeEventListener("keydown",Z,!0)}},[Ie,ie]);const ce=i.useRef(null),me=i.useRef(null),Ce=i.useRef(null),fe=i.useRef(null),oe=i.useRef(null),Se=i.useRef(null),Fe=i.useRef(null),bt=i.useRef(0),ct=i.useRef(null),yt=i.useRef(0),Tt=i.useRef(null),Lt=i.useRef(null),Wt=i.useRef(null),Rt=i.useRef(null),vn=i.useRef(null),kn=i.useRef(null),qs=i.useRef(null),[Sn,mo]=i.useState(Mn),vt=i.useRef(Sn),$t=i.useCallback(()=>vt.current,[]),[Ga,Za]=i.useState(()=>G===void 0?Fw:G),En=Y!==void 0?Y:Ga,go=i.useRef(En);go.current=En;const Ja=Pw(fo,En),Is=i.useRef(Y!==void 0);Is.current=Y!==void 0;const js=i.useRef(J);js.current=J;const Qa=i.useCallback(w=>{Is.current||Za(w),js.current?.(w)},[]),Hs=i.useRef(null),wo=i.useRef(null),Dt=i.useRef(null),Co=i.useRef(()=>!1),Bs=i.useRef(()=>{}),Vs=i.useRef(()=>null),Ws=i.useRef(()=>{}),ln=i.useCallback(()=>Co.current(),[]),bo=i.useMemo(()=>({getPointing:()=>Co.current(),insertReference:(w,P)=>Bs.current(w,P)}),[]),Ys=i.useRef(Nt),Ks=i.useRef(null),yo=i.useRef({interactive:null,tip:null}),Us=i.useRef(null),Xs=i.useRef(null),Ar=i.useRef(()=>{}),Gs=i.useRef(()=>!1),Yt=i.useRef(null),Xn=i.useCallback(()=>{const w=Yt.current;if(w===null||w.isOpen()!=="message")return!1;const P=w.context;return P===null||P.kind!=="message"||!P.current.rejected?!1:(w.close(),!0)},[]),Ro=i.useRef(()=>!1),Zs=i.useRef(()=>!1),Js=i.useRef(null),vo=i.useRef(()=>Promise.resolve("rejected")),$e=i.useCallback(()=>{Hs.current?.()},[]),ze=i.useCallback(w=>{Se.current?.focus(w)},[]),ko=i.useRef(!1),eu=i.useCallback(()=>{const w=X.current;if(w!==null){ko.current=!0;try{w.focus()}finally{ko.current=!1}}},[]),Ze=i.useCallback(()=>{const w=Se.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),An=i.useCallback((w,P)=>{if(w===null)return;const Z=P?"":"none";w.style.display!==Z&&(w.style.display=Z)},[]),at=i.useCallback(()=>{const w=Fe.current;if(w!==null){const Z=Math.max(0,oe.current?.getScrollPosition().y??0),ee=oe.current?.getFrozenSize().height??0;w.style.transform=`translateY(${bt.current-Z-ee}px)`}const P=oe.current;if(P!==null&&(vn.current!==null||kn.current!==null)){const Z=P.getFrozenSize();An(vn.current,Z.height>0),An(kn.current,Z.trailingHeight>0)}},[An]),ut=i.useCallback(()=>{const w=ct.current;if(w!==null){const Z=Math.max(0,oe.current?.getScrollPosition().x??0),ee=oe.current?.getFrozenSize().width??0;w.style.transform=`translateX(${yt.current-Z-ee}px)`}const P=oe.current;if(P!==null&&(Wt.current!==null||Rt.current!==null)){const Z=P.getFrozenSize();An(Wt.current,Z.width>0),An(Rt.current,Z.trailingWidth>0)}},[An]),Gn=i.useRef(null),On=i.useCallback(()=>{Wt.current===null&&Rt.current===null&&vn.current===null&&kn.current===null||Gn.current===null&&(Gn.current=requestAnimationFrame(()=>{Gn.current=null,at(),ut(),$e()}))},[at,ut,$e]);i.useEffect(()=>()=>{Gn.current!==null&&cancelAnimationFrame(Gn.current)},[]);const So=i.useRef(null),Eo=i.useRef(null);(So.current===null||Eo.current?.rowAxis!==ue||Eo.current?.colAxis!==de)&&(Eo.current={rowAxis:ue,colAxis:de},So.current=ow({handleRef:oe,rowAxis:ue,colAxis:de}));const Or=i.useCallback(w=>{const P=oe.current,Z=P===null?{x:0,y:0}:P.getScrollPosition(),ee=P===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:P.getFrozenSize(),ge=P===null?{width:0,height:0}:P.getViewportSize(),pe=re.current;return{top:gn(ue,w.row,{scroll:Math.max(0,Z.y),frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:ge.height})*pe,left:mn(de,w.col,{scroll:Math.max(0,Z.x),frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:ge.width})*pe,width:de.sizeOf(w.col)*pe,height:ue.sizeOf(w.row)*pe}},[ue,de]),Qs=i.useCallback(w=>{const P=fe.current,Z=X.current,ee=me.current;if(P===null||Z===null||ee===null||oe.current===null)return;const ge=re.current,pe=Or(w),qe=ee.offsetTop*ge+pe.top,Qe=ee.offsetLeft*ge+pe.left,Me=Math.max(0,qe),ht=Math.max(0,Qe),Xt=Math.min(Z.clientHeight,qe+pe.height),Tl=Math.min(Z.clientWidth,Qe+pe.width);if(Xt<=Me||Tl<=ht)return;P.style.top=`${Me}px`,P.style.left=`${ht}px`,P.style.width=`${Tl-ht}px`,P.style.height=`${Xt-Me}px`;const Ll=P.getBoundingClientRect();Ll.width===0&&Ll.height===0||P.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Or]),Kt=i.useCallback(w=>{So.current?.(w),Qs(w)},[Qs]),tu=i.useCallback(()=>{const w=oe.current,P=w===null?-1:w.getViewportSize().height,Z=ce.current,ee=X.current;if(P<=0||Z===null||ee===null)return P;const ge=Z.getBoundingClientRect();if(ge.height<=0||Z.offsetHeight<=0)return P;let pe=ge.top,qe=ge.bottom;for(let Me=ee.parentElement;Me!==null;Me=Me.parentElement){if(!Tw.has(getComputedStyle(Me).overflowY))continue;const ht=Me.getBoundingClientRect(),Xt=Me.offsetHeight>0?ht.height/Me.offsetHeight:1;pe=Math.max(pe,ht.top+Me.clientTop*Xt),qe=Math.min(qe,ht.top+(Me.clientTop+Me.clientHeight)*Xt)}pe=Math.max(pe,0),qe=Math.min(qe,ee.ownerDocument.documentElement.clientHeight);const Qe=(qe-pe)*(Z.offsetHeight/ge.height);return Qe>0?Math.min(P,Qe):P},[]),el=i.useRef(y);el.current=y;const Ao=i.useRef(null),Mt=i.useCallback(()=>{const w=el.current;if(w===void 0)return;const P=me.current,Z=Ce.current;let ee;if(P===null||Z===null)ee=xw;else{if(P.getClientRects().length===0)return;{const pe=re.current;ee={width:(Z.clientWidth-P.offsetWidth+de.totalSize()+xe.SPREADSHEET_SCROLLBAR_SIZE_PX)*pe,height:(Z.clientHeight-P.offsetHeight+ue.totalSize()+xe.SPREADSHEET_SCROLLBAR_SIZE_PX)*pe}}}const ge=Ao.current;ge!==null&&ge.width===ee.width&&ge.height===ee.height||(Ao.current=ee,w(ee))},[ue,de]);i.useLayoutEffect(()=>{if(y===void 0){Ao.current=null;return}Mt()});const tl=y!==void 0;i.useEffect(()=>{const w=me.current;if(!tl||w===null)return;const P=new ResizeObserver(()=>Mt());return P.observe(w),()=>P.disconnect()},[tl,Mt,Re]);const xn=i.useRef(null),cn=i.useRef(null),Tn=i.useCallback(w=>{xn.current!==null&&window.clearTimeout(xn.current),cn.current!==null&&(cancelAnimationFrame(cn.current),cn.current=null),xn.current=window.setTimeout(()=>{xn.current=null;const P=qs.current;P!==null&&(P.textContent="",cn.current=requestAnimationFrame(()=>{cn.current=null,P.textContent=w}))},Mw)},[]);i.useEffect(()=>()=>{xn.current!==null&&window.clearTimeout(xn.current),cn.current!==null&&cancelAnimationFrame(cn.current)},[]);const Ln=i.useCallback(w=>{O?.(w),m!==void 0&&Tn(m(w))},[O,m,Tn]),nl=i.useCallback((w,P)=>{if(a===void 0&&f===void 0)return;const Z=P.ranges[P.ranges.length-1],ee=st(Z),ge=P.ranges.length===1&&ee.rows===1&&ee.cols===1,pe=w.ranges[w.ranges.length-1],qe=w.ranges.length!==P.ranges.length||pe.startRow!==Z.startRow||pe.startCol!==Z.startCol||pe.endRow!==Z.endRow||pe.endCol!==Z.endCol,Qe=()=>{if(a!==void 0){const Me=P.active,ht=se.getCellText(Me.row,Me.col),Xt=se.getCellFormat===void 0?void 0:B(Me.row,Me.col,()=>ht);Tn(a({row:Me.row,col:Me.col,text:ht,displayText:Bn(ht,Xt===void 0?void 0:Xt.value),columnName:xe.columnIndexToName(Me.col),...Qc(se)?{readOnly:We(se,Me.row,Me.col)}:{}}))}};if(ge){Qe();return}if(qe){f!==void 0&&Tn(f({range:Z,anchor:P.anchor,active:P.active,rangeRowCount:ee.rows,rangeColCount:ee.cols,rangeCount:P.ranges.length}));return}Qe()},[se,a,f,Tn,B]),Ve=i.useCallback(w=>{const P=vt.current;Object.is(w,P)||Qg(w,P)||(vt.current=w,mo(w),W?.(w),nl(P,w),(Dt.current?.()??!1)||Ze())},[W,nl,Ze]),nu=i.useCallback(w=>{const P=vt.current;if(w.mode==="cycle"){const ee=Wa(P,w.direction);Ve(ee),Kt(ee.active);return}const Z=sn(w.cell,ue.count,de.count);if(w.mode==="extend"){Ve(pn(P,Z)),Kt(Z);return}Ve(gr(P,Z,{extend:!1,append:!1})),Kt(Z)},[Ve,Kt,ue,de]),Ke=i.useCallback(()=>Dt.current?.()??!1,[]),rl=i.useRef(null),dt=i.useCallback(()=>rl.current?.()??!0,[]),ol=i.useRef(null),Zn=i.useCallback((w,P)=>{const Z=Dt.current?.()??!1;ol.current?.(w,P),!Z&&(Dt.current?.()??!1)&&Xn()},[Xn]),[ru,Oo]=i.useState(!1),sl=i.useCallback(()=>{lt?.(),Oo(!0)},[lt]),ou=i.useCallback((w,P)=>{We(se,w.row,w.col)||sl(),Zn("edit",P)},[se,sl,Zn]),ll=i.useRef(null),xr=i.useCallback(()=>ll.current?.()??null,[]),il=i.useRef(null),kt=i.useCallback(()=>{il.current?.()},[]),cl=i.useRef(null),al=i.useCallback(w=>{cl.current?.(w)},[]),ul=i.useRef(()=>{}),Tr=i.useRef(0),an=i.useCallback((w,P,Z)=>{let ee;if(P.source==="paste"){const ge=_w(Z);if(w.length===0&&ge.conditionalFormats.length===0)return null;Tr.current+=1,ee={transaction:Tr.current,source:"paste",sameSheet:ge.sameSheet,conditionalFormats:ge.conditionalFormats}}else{if(w.length===0)return null;Tr.current+=1,ee={transaction:Tr.current,source:P.source}}try{se.applyEdits(w,ee)}catch(ge){return N?.(ge,P),null}return Ae.bumpEdit(),al(P.source),ee.transaction},[se,Ae,N,al]),su=i.useCallback((w,P)=>an(w,{source:"paste"},P),[an]),lu=i.useCallback(w=>{Ae.setVy(w.y),at(),ut(),$e()},[Ae,at,ut,$e]),dl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),iu=i.useCallback(w=>{Ae.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ae.setColRange(w.renderingColStart,w.renderingColEnd);const P=dl.current;(P.rowStart!==w.renderingRowStart||P.rowEnd!==w.renderingRowEnd||P.colStart!==w.renderingColStart||P.colEnd!==w.renderingColEnd)&&(dl.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},$e())},[Ae,$e]),fl=i.useRef(()=>"add"),Ut=i.useCallback(w=>{wo.current?.(w,fl.current())},[]),cu=i.useCallback(w=>{wo.current?.(w,"point")},[]),pl=i.useRef(null),xo=i.useCallback(w=>{pl.current?.(w)},[]),hl=i.useRef(null),au=i.useCallback(w=>{hl.current?.(w)},[]),ml=i.useRef(null),To=i.useCallback((w,P)=>{if(P.length===0)return;const Z=oe.current;if(w==="col"){for(const ee of P){const ge=Math.round(ee.size);de.resize(ee.index,ge),Z?.updateColSize(ee.index,ge)}Ae.bumpColVersion(),ut(),$e(),On(),Mt();return}for(const ee of P){const ge=Math.round(ee.size);ue.resize(ee.index,ge),Z?.updateRowSize(ee.index,ge)}Ae.bumpRowGeometry(),at(),$e(),On(),Mt()},[ue,de,Ae,ut,at,$e,On,Mt]),uu=i.useCallback((w,P)=>{S?.(w,{kind:"pointer",event:P})},[S]),du=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Ut,axis:"both",zoomRef:re}),fu=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Ut,axis:"x",zoomRef:re}),pu=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Ut,axis:"y",zoomRef:re}),hu=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:xo,axis:"x",zoomRef:re}),mu=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:xo,axis:"y",zoomRef:re}),gu=Dn({handleRef:oe,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Ut,axis:"both",zoomRef:re}),gl=i.useRef(null),wl=i.useRef(()=>!1),Lo=i.useCallback(()=>wl.current(),[]),ft=Aw({zoomRef:re,enabled:!Re,rowAxis:ue,colAxis:de,handleRef:oe,bodyRef:ce,isEditing:Ke,requestCommit:dt,getSelection:$t,setSelection:Ve,focusSink:ze,onDragFrame:Ut,onContextMenuSelect:uu,onRequestEdit:ou,caretFromPointEnabled:w=>{if(U!==void 0||se.getCellFormula!==void 0&&se.getCellFormula(w.row,w.col)!==void 0)return!1;if(se.getCellFormat===void 0)return!0;const P=se.getCellText(w.row,w.col);return Bn(P,se.getCellFormat(w.row,w.col)?.value)===P},isAnyDragging:Lo,autoScroller:du,repaintOverlay:$e,pointDragRef:gl,getPointing:ln,openHyperlinkAt:Le===void 0||se.getCellHyperlink===void 0?void 0:w=>{const P=se.getCellHyperlink===void 0?void 0:Yn(se.getCellHyperlink(w.row,w.col));return P===void 0?!1:(Le(P,w),!0)}}),St=Yi({zoomRef:re,enabled:!Re&&b,axis:"col",headerRef:Tt,mainAxis:de,crossCount:se.rowCount,handleRef:oe,isEditing:Ke,requestCommit:dt,getSelection:$t,setSelection:Ve,focusSink:ze,onDragFrame:Ut,autoScroller:fu,repaintOverlay:$e,pointing:bo}),Et=Yi({zoomRef:re,enabled:!Re&&b,axis:"row",headerRef:Lt,mainAxis:ue,crossCount:se.colCount,handleRef:oe,isEditing:Ke,requestCommit:dt,getSelection:$t,setSelection:Ve,focusSink:ze,onDragFrame:Ut,autoScroller:pu,repaintOverlay:$e,pointing:bo}),Je=Jg({zoomRef:re,enabled:!Re&&k&&b,colBandRef:Tt,rowBandRef:Lt,fontSourceRef:ce,colAxis:de,rowAxis:ue,viewStore:Ae,handleRef:oe,isEditing:Ke,requestCommit:dt,focusSink:ze,getSelection:$t,adapter:se,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:T,resizeTracks:To,writeResizeGuide:au,repaintOverlay:$e,isPointing:ln}),pt=hw({zoomRef:re,enabled:!Re&&v,handleNodeRef:ml,bodyRef:ce,rowAxis:ue,colAxis:de,handleRef:oe,getSelection:$t,setSelection:Ve,focusSink:ze,adapter:se,commitEdits:an,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,writeFillPreview:xo,repaintOverlay:$e,xAutoScroller:hu,yAutoScroller:mu}),nt=Ow({zoomRef:re,enabled:!Re,bodyRef:ce,handleRef:oe,rowAxis:ue,colAxis:de,getPointing:ln,insertReference:bo.insertReference,captureSink:()=>Vs.current(),restoreSink:w=>Ws.current(w),focusSink:ze,autoScroller:gu,onDragFrame:Ut});gl.current=nt;const Jn=i.useCallback(()=>ft.isDragging()||St.isDragging()||Et.isDragging()||Je.isDragging()||pt.isDragging()||nt.isDragging(),[ft,St,Et,Je,pt,nt]);ke.current=Jn,wl.current=Jn,fl.current=()=>nt.isDragging()?"point":ft.getDragMode();const wu=i.useCallback(()=>{ft.abortDrag(),St.abortDrag(),Et.abortDrag(),Je.abortDrag(),pt.abortDrag(),nt.abortDrag()},[ft,St,Et,Je,pt,nt]),$o=i.useCallback(()=>vt.current.active,[]),Cl=i.useCallback((w,P)=>{const Z=se.getCellValidation===void 0?void 0:se.getCellValidation(w.row,w.col);if(Z===void 0)return Xi;const ee=se.evaluateFormula,ge=fa(Z,P,Ht,ee===void 0?void 0:pe=>ee(pe,w));return ge.ok||Z.strict!==!0?Xi:(De?.({cell:w,rule:Z,text:P,message:ge.message}),Yt.current?.isKindEnabled("message")&&Ar.current("message",{message:ge.message,rejected:!0}),ge)},[se,De,Ht]),_e=hg({enabled:!Re,sinkRef:Se,rootRef:X,adapter:se,commitEdits:an,getActive:$o,ensureCellVisible:Kt,focusSink:ze,rearmSink:Ze,discardClip:kt,isDragging:Lo,rejectReadOnly:Ln,resolveEditAlign:w=>{if(se.getCellFormat===void 0)return null;const P=Gr(se,w.row,w.col);return Jc(B(w.row,w.col,P),P)},resolveEditPaint:w=>se.getCellFormat===void 0?null:sf(B(w.row,w.col,Gr(se,w.row,w.col))),editPaintRef:Ys,repaintOverlay:$e,validateCommit:Cl});Dt.current=_e.isEditing,rl.current=_e.requestCommit,ol.current=_e.startEdit,Co.current=_e.getPointing,Bs.current=_e.insertReference,Vs.current=_e.captureSink,Ws.current=_e.restoreSink;const bl=i.useCallback(()=>{_e.cancelEdit(),Xn()},[_e.cancelEdit,Xn]),Qn=Xm({enabled:!Re,sinkRef:Se,adapter:se,isEditing:Ke,getSelection:$t,setSelection:Ve,commitPaste:su,maxOperationCells:C,onOperationRejected:T,onCopyMultiRange:I,repaintOverlay:$e,isDragging:Lo,resize:{rowAxis:ue,colAxis:de,resizeTracks:To},pendingPasteOptionsRef:Ks,formats:j,onClipChange:Ee,onClipboardUnavailable:he,onEditRejected:N,rejectReadOnly:Ln,onPasteResolved:Pe});ll.current=Qn.getClip,il.current=Qn.discardClip,cl.current=Qn.discardClipOnCommit,ul.current=Qn.onAdapterSwitch,vo.current=Qn.paste;const er=Sw({enabled:!Re,adapter:se,popovers:ne,sinkRef:Se,bodyRef:ce,handleRef:oe,rowAxis:ue,colAxis:de,zoomRef:re,getActive:$o,isEditing:Ke,requestCommit:dt,focusSink:ze,rearmSink:Ze,isDraggingAny:Jn,commitEdits:an,labels:it,onHyperlinkOpen:Le,anchors:yo,repaintOverlay:$e,rejectReadOnly:Ln});Yt.current=er,Ar.current=er.open,Gs.current=er.hideTip;const Cu=i.useCallback(()=>{const w=vt.current.active;return Kt(w),Or(w)},[Kt,Or]),Do=dg({adapter:se,trackResize:k&&!Re?Je:void 0,getSelection:$t,commitEdits:an,getActive:$o,isEditing:Ke,requestCommit:dt,cancelEdit:bl,getSessionText:_e.getSessionText,validateCommit:Cl,insertAtCaret:_e.insertAtCaret,refreshEditPaint:_e.refreshPaint,maxOperationCells:C,onOperationRejected:T,colors:Kn,formats:j,getHighlight:()=>go.current,setHighlight:Qa,popovers:ne,openPopover:w=>Ar.current(w),onHyperlinkOpen:Le,onPasteSpecialRequest:et,paste:w=>vo.current(w),rowAxis:ue,colAxis:de,resizeTracks:To,defaultRowHeight:s,defaultColumnWidth:l,now:Ye,announce:Tn,formatCommandAnnouncement:E,formatResizeAnnouncement:d,keyboardCellRect:Cu,rejectReadOnly:Ln});Js.current=Do,Ro.current=Do.executeCommand,Zs.current=Do.isCommandAvailable;const bu=i.useMemo(()=>({table:Bt,execute:w=>Ro.current(w),isAvailable:w=>Zs.current(w)}),[Bt]),yu=i.useCallback(()=>{kt(),x?.()},[kt,x]),Ru=i.useCallback(()=>{kt(),z?.()},[kt,z]);uw({zoomRef:re,enabled:!Re,sinkRef:Se,rootRef:X,handOffFocusToRoot:eu,getSelection:$t,setSelection:Ve,moveActive:nu,ensureCellVisible:Kt,pageExtent:tu,isEditing:Ke,requestCommit:dt,startEdit:Zn,commitEdits:an,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,getClip:xr,discardClip:kt,isDragging:Jn,abortDrag:wu,findDataEdge:se.findDataEdge,getEditingMode:_e.getEditingMode,cancelEdit:bl,onUndoRequest:yu,onRedoRequest:Ru,onCellContextMenu:S,rowAxis:ue,colAxis:de,handleRef:oe,rearmSink:Ze,commands:bu,pointing:_e,adapter:se,hideNoteTip:()=>Gs.current(),closeRejectedMessage:Xn,pendingPasteOptionsRef:Ks,onPointFrame:cu});const vu=Sn.active.row,ku=Sn.active.col;i.useLayoutEffect(()=>{const w=Yt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[vu,ku]),i.useLayoutEffect(()=>{$e()},[$e,En.row,En.column,En.intersection]);const Su=i.useCallback(w=>{(Dt.current?.()??!1)||(w.preventDefault(),ze(),Ze())},[ze,Ze]),Eu=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget;if(P!==null&&Z instanceof Node&&P.contains(Z)){w.target===P&&Z===Se.current&&!ko.current&&ze();return}(Dt.current?.()??!1)||(ze(),Ze())},[ze,Ze]),Au=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget;P!==null&&Z instanceof Node&&P.contains(Z)||_e.isFocusoutSuppressed()||Oo(!1)},[_e]),Lr=i.useRef(null),tr=i.useCallback(()=>{const w=Lr.current;w!==null&&(Lr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Mo=i.useCallback(()=>{if(Lr.current!==null)return;const w=Z=>{Z.pointerType==="mouse"&&(tr(),Z.button===1&&Z.preventDefault())},P=Z=>{Z.pointerType==="mouse"&&tr()};Lr.current={up:w,cancel:P},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",P,!0)},[tr]);i.useEffect(()=>tr,[tr]),i.useEffect(()=>{const w=X.current;if(Re||w===null)return;let P=0;const Z=pe=>{if(pe.pointerType!=="mouse"){(Dt.current?.()??!1)||Oo(!1);return}P=pe.buttons,pe.button===1&&(pe.target===Se.current&&(Dt.current?.()??!1)||Mo())},ee=pe=>{pe.pointerType==="mouse"&&(P=pe.buttons)},ge=pe=>{if(pe.pointerType!=="mouse"||pe.buttons===P)return;const qe=pe.buttons&~P;P=pe.buttons,pe.preventDefault(),(qe&4)!==0&&Mo()};return w.addEventListener("pointerdown",Z,!0),w.addEventListener("pointerup",ee,!0),w.addEventListener("pointermove",ge,!0),()=>{w.removeEventListener("pointerdown",Z,!0),w.removeEventListener("pointerup",ee,!0),w.removeEventListener("pointermove",ge,!0)}},[Re,Mo]);const Ou=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(ln()){ze();return}if(Ke()&&!dt()){ze();return}ze()}},[ze,Ke,dt,ln]),zo=i.useRef(!1);i.useLayoutEffect(()=>{if(Re){zo.current=!1;return}if(zo.current)return;zo.current=!0,Ze();const w=(X.current?.clientHeight??0)/re.current;w>0&&ue.totalSize()>0&&Ae.setRowRange(0,ue.indexAt(Math.min(w-1,ue.totalSize()-1)));const P=(X.current?.clientWidth??0)/re.current;P>0&&de.totalSize()>0&&Ae.setColRange(0,de.indexAt(Math.min(P-1,de.totalSize()-1)))},[Re,Ze,Ae,ue,de]);const yl=i.useRef(t);i.useLayoutEffect(()=>{yl.current!==t&&(yl.current=t,ft.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),Je.cancelDrag(),pt.cancelDrag(),nt.cancelDrag(),_e.cancelEdit(),Yt.current?.hideTip(),Yt.current?.close(),Re?(vt.current=Mn,mo(Mn)):Ve(Mn),ul.current())},[t,Re,Ve,ft,St,Et,Je,pt,nt,Ae,_e.cancelEdit]);const Rl=i.useRef({adapter:se,rows:ue.count,cols:de.count}),{getSessionCell:vl,cancelEdit:kl}=_e;i.useLayoutEffect(()=>{const w=Rl.current,P=ue.count,Z=de.count;if(Rl.current={adapter:se,rows:P,cols:Z},w.adapter!==se||P>=w.rows&&Z>=w.cols)return;Re?(vt.current=Mn,mo(Mn)):Ve(ew(vt.current,P,Z)),ft.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),Je.cancelDrag(),pt.cancelDrag(),nt.cancelDrag();const ee=Qe=>Re||Qe.row>=P||Qe.col>=Z,ge=vl();ge!==null&&ee(ge)&&kl();const pe=yo.current;if(pe.tip!==null&&ee(pe.tip)&&Yt.current?.hideTip(),pe.interactive!==null&&ee(pe.interactive)){const Qe=X.current?.contains(document.activeElement)===!0;Yt.current?.close({restoreFocus:Qe})}const qe=xr();qe!==null&&!qe.foreign&&ee({row:qe.range.endRow,col:qe.range.endCol})&&kt()},[se,ue.count,de.count,Re,Ve,ft,St,Et,Je,pt,nt,vl,kl,xr,kt]);const Sl=i.useRef(c),El=i.useRef(u),Al=i.useRef(h),Ol=i.useRef(g);i.useLayoutEffect(()=>{(Sl.current!==c||El.current!==u||Al.current!==h||Ol.current!==g)&&(Sl.current=c,El.current=u,Al.current=h,Ol.current=g,ft.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),Je.cancelDrag(),pt.cancelDrag(),nt.cancelDrag())},[c,u,h,g,ft,St,Et,Je,pt,nt]),i.useLayoutEffect(()=>{at(),ut(),$e()},[c,u,h,g,at,ut,$e]);const xl=i.useRef(p);i.useLayoutEffect(()=>{xl.current!==p&&(xl.current=p,kt())},[p,kt]),i.useLayoutEffect(()=>{$e()},[$e,Sn]);const un=i.useCallback(()=>{const w=Js.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(bn,()=>({resizeRow:(w,P)=>{const Z=Math.round(P);ue.resize(w,Z),oe.current?.updateRowSize(w,Z),Ae.bumpRowGeometry(),at(),$e(),On(),Mt()},resizeColumn:(w,P)=>{const Z=Math.round(P);de.resize(w,Z),oe.current?.updateColSize(w,Z),Ae.bumpColVersion(),ut(),$e(),On(),Mt()},autoFitColumns:w=>{for(const P of w)if(!Number.isInteger(P)||P<0||P>=de.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${de.count-1} (got ${String(P)})`);return Je.autofitColumnsInAllRows(w)},scrollToCell:(w,P)=>{oe.current?.scrollToCell(w.row,w.col,P)},focus:w=>{ze(w),Ke()||Ze()},executeCommand:w=>Ro.current(w),applyFormat:w=>un().applyFormat(w),setBorders:(w,P)=>un().setBorders(w,P),setHyperlink:w=>un().setHyperlink(w),setNote:w=>un().setNote(w),addComment:w=>un().addComment(w),setValidation:w=>un().setValidation(w),paste:w=>vo.current(w),getSelection:()=>vt.current,getBaseFormat:w=>se.getCellFormat===void 0?void 0:se.getCellFormat(w.row,w.col),getPaintedFormat:w=>se.getCellFormat===void 0?void 0:B(w.row,w.col,Gr(se,w.row,w.col)),startEdit:w=>{Zn(w)},openPopover:w=>{Ar.current(w)}}),[ue,de,Ae,ut,at,$e,On,Mt,Je,ze,Ke,Ze,se,B,Zn,un]),Re)return K.jsx("div",{className:Ct?`aqsp-root ${Ct}`:"aqsp-root","data-aqsp-empty":"","data-testid":je});const xu=a!==void 0||f!==void 0||E!==void 0||m!==void 0||d!==void 0,Tu=o===void 0?{"aria-label":it.rootAriaLabel}:{"aria-labelledby":o};return K.jsxs("div",{ref:X,className:Ct?`aqsp-root ${Ct}`:"aqsp-root",role:"group",...Tu,tabIndex:0,onFocus:Eu,onBlur:Au,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-testid":je,children:[K.jsxs("div",{ref:Ce,className:"aqsp-zoom","data-aqsp-zoom":le,onPointerDown:Ou,style:le===1?void 0:{width:`${100/le}%`,height:`${100/le}%`,transform:`scale(${le})`,"--_aqsp-zoom":String(le)},children:[b?K.jsxs(K.Fragment,{children:[K.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(ln()){ze();return}if(Ke()&&!dt()){ze();return}ze(),Ve({ranges:[ye({row:0,col:0},{row:se.rowCount-1,col:se.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(Ug,{viewStore:Ae,colAxis:de,frozenCols:c,frozenTrailingCols:h,handleRef:oe,bandRef:Tt,colTrackRef:ct,windowOriginXRef:yt,repaintColHeaders:ut,selectionRanges:Sn.ranges,enableResizeUI:k,dividerLeadingRef:Wt,dividerTrailingRef:Rt}),K.jsx(Xg,{viewStore:Ae,rowAxis:ue,handleRef:oe,bandRef:Lt,selectionRanges:Sn.ranges,rowTrackRef:Fe,windowOriginYRef:bt,repaintHeaders:at,enableResizeUI:k,frozenRows:u,frozenTrailingRows:g,dividerLeadingRef:vn,dividerTrailingRef:kn})]}):null,K.jsxs("div",{ref:me,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(Kg,{adapter:se,rowAxis:ue,colAxis:de,viewStore:Ae,handleRef:oe,bodyRef:ce,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:n,labelledBy:o,gridLabel:o===void 0?it.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:R,overscanRows:Ki("overscanRows",F),overscanCols:Ki("overscanCols",H),background:$,onRenderTruncated:_,renderCell:U,onScroll:lu,onRangeChange:iu,focusSink:ze,isEditing:Ke,requestCommit:dt,testId:je?`${je}-vs`:void 0,__onCellRender:Cn,__maxRenderedCells:kr,cfIndexRef:Un,cfMemoRef:M,isPointing:ln,locale:Ht,scrollLabels:yn}),K.jsx(km,{rowAxis:ue,colAxis:de,handleRef:oe,sinkRef:Se,getSelection:$t,editing:_e.editing,virtualKeyboard:ru,repaintRef:Hs,dragFrameRef:wo,getClip:xr,getIsDraggingAny:Jn,getIsFillDragging:pt.isDragging,fillFrameRef:pl,resizeGuideFrameRef:hl,fillHandleNodeRef:ml,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:g,sinkAriaLabel:it.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Sr,onSinkMouseDown:Su,editPaintRef:Ys,highlightRef:go,highlightColors:Ja,popoverAnchors:yo,interactiveAnchorRef:Us,tipAnchorRef:Xs}),er.layerEnabled?K.jsx(Rw,{controller:er,labels:it,renderPopover:ve,interactiveAnchorRef:Us,tipAnchorRef:Xs}):null]}),xu?K.jsx("div",{ref:qs,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),K.jsx("div",{ref:fe,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=_t.iterateTsvPrefixRows;exports.iterateTsvRows=_t.iterateTsvRows;exports.measureTsv=_t.measureTsv;exports.parseTsv=_t.parseTsv;exports.serializeClipboardTsv=_t.serializeClipboardTsv;exports.serializeTsv=_t.serializeTsv;exports.columnIndexToName=xe.columnIndexToName;exports.columnNameToIndex=xe.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=bs;exports.CommentPopover=ka;exports.DEFAULT_CUSTOM_COLORS=Xa;exports.DEFAULT_HIGHLIGHT_COLORS=Ra;exports.DEFAULT_SHORTCUTS=ia;exports.LinkPopover=Sa;exports.ListPopover=Ea;exports.MessagePopover=Aa;exports.NotePopover=Oa;exports.NoteTip=xa;exports.SPREADSHEET_LABEL_CATALOGS=ca;exports.SPREADSHEET_RESERVED_SHORTCUTS=Ah;exports.Spreadsheet=Iw;exports.canonicalizeFormat=wt;exports.detectClipSource=lc;exports.enumerateRangeCells=Zt;exports.estimatePasteCellCount=ph;exports.expandPaste=hh;exports.formatCellValue=Bn;exports.formatEquals=Iu;exports.fromR1C1=br;exports.makeRange=ye;exports.mergeFormat=Rs;exports.normalizeHyperlink=on;exports.parseChord=Jt;exports.parseClipPayload=ns;exports.parseHtmlTable=Zc;exports.rangeContains=wn;exports.rangeSize=st;exports.resolveLabel=Ne;exports.resolveLabels=aa;exports.serializeClipPayload=rc;exports.serializeHtmlTable=Kc;exports.shiftFormula=Lc;exports.toR1C1=io;exports.validateCellText=fa;
12
+ `)},nh=(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)}hs(t,Zc(e,r))},rh=(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"?Wc(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<oi.length?oi[l]:null}return null},Jc=(e,t,n)=>t!==void 0&&Yc(t)?dp(e,t,n):e,oh=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&ot(c)!==null)if(n!==void 0&&n.type==="date"){const u=Wc(Number(c));if(u!==null)return u}else return c;return Jc(t,n,r)},sh=(e,t,n,r)=>{const o=Zc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Xp(o)};for(const m of ah(e))Qp(m,l);eh(l,o,s,r.rules);const c=th(l.text,l.mode),u=Zp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),R=m===null?void 0:op(m,r.options);R!==void 0&&(u.value=R);const N=e.getAttribute("data-sheets-value"),H=N===null?null:rh(N,R);h.t=H===null?Jc(c,R,jc):H;const L=e.getAttribute("data-sheets-formula");L?.startsWith("=")&&(h.f=L);const _=e.getAttribute("data-sheets-hyperlink"),U=_!==null?_:l.href,W=U===null?null:sn(U);W!==null&&(h.link=W);const k=e.getAttribute("data-sheets-note");k!==null&&k!==""&&(h.note=k)}else{const m=o.get("mso-number-format"),R=m===void 0?void 0:zs(ps(ro(m)),r.options);R!==void 0&&(u.value=R),h.t=oh(e,c,R,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(h.f=uo(N,{row:t,col:n}));const H=l.href===null?null:sn(l.href);H!==null&&(h.link=H)}return{cell:h,format:u}},ms=(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},lh=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)},ih=(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]))},Qc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:po(n);if(r!==null){const s=r.get("display");if(s!==void 0&&s.toLowerCase()==="none")return 0;const l=r.get(t),c=l===void 0?null:lh(l);if(c!==null)return Math.min(c,on)}const o=ih(e,t);return o===null?null:Math.min(o,on)},ch=(e,t)=>{const n=[],r=o=>{const s=Qc(o,"width");for(let l=ms(o,"span",xs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of wr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of wr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*wr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*ah(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*uh(e){for(const t of["thead","tbody","tfoot"])for(const n of wr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of wr(n))o.localName==="tr"&&(yield o)}}const Yo=()=>({t:""}),dh=(e,t,n)=>{const r=wc(),o=[],s=[],l=[];let c=0;for(const H of uh(e)){const L=o.length,_=(L+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const U=[];for(let k=0;k<l.length;k+=1)l[k]>0&&(U[k]=Yo(),l[k]-=1);let W=0;for(const k of wr(H)){const x=k.localName;if(x!=="td"&&x!=="th")continue;for(;U[W]!==void 0;)W+=1;const z=ms(k,"colspan",xs),I=ms(k,"rowspan",uc),T=(L+1)*Math.max(c,W+z);if(T>n)return{outcome:"limit",cells:T};const F=sh(k,L,W,t),O=r.intern(F.format);O!==void 0&&(F.cell.fmt=O),U[W]=F.cell;for(let g=1;g<z;g+=1)U[W+g]===void 0&&(U[W+g]=Yo());if(I>1)for(let g=0;g<z;g+=1){const p=I-1,C=W+g;l[C]=l[C]===void 0||l[C]<p?p:l[C]}W+=z}U.length>c&&(c=U.length),o.push(U),s.push(Qc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const L=[];for(let _=0;_<c;_+=1){const U=H[_];L.push(U===void 0?Yo():U)}return L}),h=ch(e,c),m=h.length===c&&h.every(H=>H!==null)?h.map(H=>H===null?0:H):void 0,R=s.every(H=>H!==null)?s.map(H=>H===null?0:H):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:As(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...R===void 0?{}:{rowHeights:R},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},ea=(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=Ep(o);return dh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Re=(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)}),Cn=(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}),At=e=>e.reduce((t,n)=>t+st(n).rows*st(n).cols,0),Jt=(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}))}},ln=(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)}},It=(e,t)=>e.row===t.row&&e.col===t.col,ta=(e,t)=>e===void 0?Fl(void 0,void 0,t()):Fl(e.align,e.value,e.align===void 0?t():""),Qr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Yn=(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}},eo=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}),na=e=>e.isCellReadOnly!==void 0,Ye=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,fh=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],ph=()=>!0,hh=e=>{const t=new WeakMap,n={};for(const r of fh)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:ph}),n},mh=/^data-[a-z0-9-]+$/,gh=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},wh=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!gh(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(!mh.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},ur=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},qn=(e,t)=>{for(const n of t)if(ur(e,n))return!0;return!1},Ch=(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},gs=(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,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},R=Math.min(u,r-m.row),N=Math.min(h,o-m.col);return R<=0||N<=0?null:Re(m,{row:m.row+R-1,col:m.col+N-1})},ra=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=gs({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,R=u.endCol-u.startCol+1,N=[];for(let H=0;H<m;H+=l){const L=[];for(let U=0;U<R;U+=c){const W={row:h.row+H,col:h.col+U};L.push(W),N.push(W)}const _=Math.min(l,m-H);for(let U=0;U<_;U+=1){const W=h.row+H+U,k=e[U];for(let x=0;x<L.length;x+=1){const z=x*c,I=Math.min(c,R-z);for(let T=0;T<I;T+=1)s(W,h.col+z+T,k[T],L[x])}}}return N},bh=(e,t,n,r,o)=>{const s=[];return ra(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},ii=(e,t,n,r,o,s)=>{const l=[],c=ra(e,t,n,r,o,(u,h,m,R)=>{const N=s(m,u,h,R);N!==null&&l.push({...N,row:u,col:h})});return{edits:l,tiles:c}},oa=(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)})`)},yh=(e,t)=>{oa(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},Rh=(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(Re({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Re({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Re({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Re({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},vh=(e,t,n,r)=>{oa(t,n);const o=st(t).rows,s=st(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let R=n.startCol;R<=n.endCol;R+=1){if(m&&R>=t.startCol&&R<=t.endCol)continue;const N=t.startCol+((R-t.startCol)%s+s)%s,H=h*2**21+N;let L=c.get(H);L===void 0&&(L={value:e(h,N),origin:{row:h,col:N}},c.set(H,L)),l.push(r(L.value,L.origin,{row:u,col:R}))}}return l},sa=(e,t,n)=>{const r=Yn(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:gt(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=Un(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},la=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Mc(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},ho=["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"],Sh=/^[A-Z]$/,kh=/^[A-Za-z]$/,Eh=/^Key([A-Z])$/,ia=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"]),Ah=e=>Sh.test(e)||ia.has(e),Qt=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||!Ah(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}},Oh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,ca=e=>{if(kh.test(e.key))return e.key.toUpperCase();const t=Eh.exec(e.code);return t!==null?t[1]:ia.has(e.code)?e.code:null},or=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:ca(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ye=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),xh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Th=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},vr=[...xh(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("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"},...Th(),ye("bold","Ctrl+B","both","toggle bold"),ye("italic","Ctrl+I","both","toggle italic"),ye("underline","Ctrl+U","both","toggle underline"),ye("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ye("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ye("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ye("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ye("alignLeft","Ctrl+Shift+L","both","align left"),ye("alignCenter","Ctrl+Shift+E","both","align center"),ye("alignRight","Ctrl+Shift+R","both","align right"),ye("formatNumber","Ctrl+Shift+Digit1","both","number format"),ye("formatTime","Ctrl+Shift+Digit2","both","time format"),ye("formatDate","Ctrl+Shift+Digit3","both","date format"),ye("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ye("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ye("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ye("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ye("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ye("borderTop","Alt+Shift+Digit1","idle","top border"),ye("borderRight","Alt+Shift+Digit2","idle","right border"),ye("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ye("borderLeft","Alt+Shift+Digit4","idle","left border"),ye("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ye("insertNote","Shift+F2","idle","insert / edit note"),ye("insertComment","Ctrl+Alt+M","idle","insert comment"),ye("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ye("openValidationList","Alt+ArrowDown","idle","open the validation list"),ye("fillDown","Ctrl+D","idle","fill down"),ye("fillRight","Ctrl+R","idle","fill right"),ye("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ye("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ye("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ye("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ye("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ye("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),ye("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),ye("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),ye("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),ye("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),ye("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],Uo=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),ci=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),$h=e=>{const t=Qt(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 ci?ci[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},oo=(e,t)=>e.column==="both"||e.column===t,Lh=Array.from(new Set(vr.filter(e=>!e.rebindable&&oo(e,"idle")).map(e=>e.chord))),Ps=new Set(vr.filter(e=>e.command!==void 0&&oo(e,"editing")).map(e=>e.command)),Dh=new Set(vr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),aa=e=>{const t={};for(const n of ho)t[n]=e(n);return t},ua=aa(e=>vr.filter(t=>t.command===e).map(t=>t.chord)),Mh=e=>{const t=new Map;for(const n of ho){const r=e[n];if(r!=null)for(const o of r){const s=t.get(o);s===void 0?t.set(o,[n]):s.includes(n)||s.push(n)}}return t},zh=e=>{const t=new Set(ho);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(Dh.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`)}}}},Nh=(e,t)=>{const n=Qt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Ps.has(e);for(const o of vr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(oo(o,"idle")||r&&oo(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Fh=e=>{e!==void 0&&zh(e);const t=aa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?ua[r]:o===null?[]:o});for(const r of ho)for(const o of t[r])Nh(r,o);const n=new Map;for(const[r,o]of Mh(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},ai=(e,t)=>{const n=ca(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Oh({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},_s=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],ui=[...Je.VIRTUAL_SCROLL_LABEL_KEYS,..._s],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"}),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:"閉じる"})}),da=Object.freeze({en:Object.freeze({...Je.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ws.en}),ja:Object.freeze({...Je.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ws.ja})}),mn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,di=e=>e==="commentCount"||e==="listMore",Ph=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 ${mn(t)}`);for(const n of _s){const r=e[n];if(!(di(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=di(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${mn(r)}`)}}},_h=e=>{const t={};let n=!1;for(const r of Je.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},qh=(e,t,n)=>{e[t]=n},fa=(e,t)=>{const n=Je.resolveVirtualScrollLocale(e);if(t===void 0)return da[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${mn(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(!ui.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${ui.join(", ")}`);const s={...Je.resolveVirtualScrollLabels(n,_h(t)),...ws[n]};for(const l of _s){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&qh(s,l,c)}return Ph(s),Object.freeze(s)},Ih=e=>{const t={};for(const n of Je.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},ze=(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},fi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},jh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Hh=(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}`}},Xo=(e,t)=>{const n=r=>(o,s)=>`${e} ${Hh(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")})},Bh=Object.freeze({list:"Value must be one of the list items.",number:Xo("Value must be a number",fi),textLength:Xo("Text length must be",fi),date:Xo("Value must be a date",jh),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}.`}),Vh=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} を満たす値を入力してください。`}),Go=Object.freeze({en:Bh,ja:Vh}),Wh=Object.freeze({ok:!0}),Kh="TRUE",Yh="FALSE",Uh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Xh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Gh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Zh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Jh=/^[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])?)+$/,pi=e=>{const t=e.trim();if(!(Gh.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,R=m.search(/[^0]/);return R<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(R).replace(/0+$/,""),point:u.length+l-R}},Qh=e=>e===1?-1:e===-1?1:0,em=(e,t)=>{if(e.sign!==t.sign)return e.sign<t.sign?-1:1;if(e.sign===0)return 0;const n=e.point!==t.point?e.point<t.point?-1:1:e.digits===t.digits?0:e.digits<t.digits?-1:1;return e.sign===1?n:Qh(n)},tm=(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}},hi=e=>{const t=Zh.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>tm(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},nm=(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},rm=(e,t)=>e<t?-1:e>t?1:0,om=e=>e==="between"||e==="notBetween",sm=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!om(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},lm=(e,t,n)=>{switch(e){case"gt":return t===1;case"gte":return t!==-1;case"lt":return t===-1;case"lte":return t!==1;case"eq":return t===0;case"neq":return t!==0;case"between":return t!==-1&&n!==1;default:return t===-1||n===1}},Zo=(e,t,n,r,o,s)=>{const l=sm(e,t,n,r);return l===null?!0:o===null?!1:lm(e,s(o,l.a),l.b===null?0:s(o,l.b))},im=e=>Number.isFinite(e)?e:null,cm=e=>{let t=0;for(const n of e)t+=1;return t},am=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),um=(e,t)=>{switch(e.op){case"isEmail":return Jh.test(t);case"isUrl":return am(t)}if(e.value===void 0)return!0;switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);default:return t.endsWith(e.value)}},dm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,pa=e=>({checked:e.checked===void 0?Kh:e.checked,unchecked:e.unchecked===void 0?Yh:e.unchecked}),fm=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Uh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${mn(e.op)} for type "${e.type}"`);return;case"text":if(!Xh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${mn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${mn(e.type)}`)}},pm=(e,t,n)=>{switch(e.type){case"list":return gm(e).has(t);case"number":return Zo(e.op,e.a,e.b,pi,pi(t),em);case"textLength":return Zo(e.op,e.a,e.b,im,cm(t),rm);case"date":return Zo(e.op,e.a,e.b,hi,hi(t),nm);case"text":return um(e,t);case"checkbox":{const r=pa(e);return t===r.checked||t===r.unchecked}default:return n===void 0||dm(n(e.formula))}},ha=(e,t,n)=>(fm(e),t===""||pm(e,t,n)),mi=e=>e===void 0?void 0:e.trim(),hm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),mi(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(),mi(e.b));case"text":return mm(e,t.text);case"checkbox":{const n=pa(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},mm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},gi=new WeakMap,gm=e=>{const t=gi.get(e);if(t!==void 0)return t;const n=new Set(e.values);return gi.set(e,n),n},ma=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Go,n)){const o=Object.keys(Go).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${mn(n)}`)}return ha(e,t,r)?Wh:{ok:!1,message:e.errorMessage===void 0?hm(e,Go[n]):e.errorMessage}},wm=e=>e.type!=="custom",Cm=(e,t)=>wm(e)&&!ha(e,t,void 0),ga=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),wa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Ca=(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,ba=(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),ya=(e,t)=>ga(e,t),Ra=(e,t)=>ga(e,t),va=(e,t)=>wa(e,t),Sa=(e,t)=>wa(e,t),gn=(e,t,n)=>Ca(e,t,n),wn=(e,t,n)=>Ca(e,t,n),Sr=(e,t,n)=>ba(e,t,n),kr=(e,t,n)=>ba(e,t,n),bm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Zt=1,dr=3,Ir=e=>`${-Math.min(dr,Math.max(0,Math.floor(e)))}px`,ka=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),ym=16,Rm=450,vm=e=>e>4?Math.floor(Rm/(5*e)):ym,sr=(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},wi=()=>({rowLeft:sr("row","left"),rowRight:sr("row","right"),colAbove:sr("column","above"),colBelow:sr("column","below"),cross:sr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Ea=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],jr=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},Hr=(e,t)=>Math.min(Math.max(e,0),t),Ci="inset(100%)",Hn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Sm=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Hn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const N=`${t.height}px`;e.rowLeft.style.height=N,e.rowRight.style.height=N}const m=`translate(${Hr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const R=`translate(${Hr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;R!==s.rowRightTransform&&(s.rowRightTransform=R,e.rowRight.style.transform=R)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Hn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const N=`${t.width}px`;e.colAbove.style.width=N,e.colBelow.style.width=N}const m=`translate(${t.left}px, ${Hr(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const R=`translate(${t.left}px, ${Hr(t.top+t.height,n.clampHeight)}px)`;R!==s.colBelowTransform&&(s.colBelowTransform=R,e.colBelow.style.transform=R)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Hn([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--_aqsp-band-${u})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const m=`translate(${t.left}px, ${t.top}px)`;m!==s.crossTransform&&(s.crossTransform=m,e.cross.style.transform=m)}},bi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Hn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Hn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Hn([e.cross],!1))},yi=e=>{for(const t of Ea(e))t.remove()},km=(e,t)=>{const n=e-1-t.lineBoxPx;return t.verticalAlign==="top"?0:t.verticalAlign==="bottom"?Math.max(0,n):Math.max(0,n/2)},Em=Object.freeze([]),Ri=e=>e.dividers[0]??e.active,Am={left:"0px",right:"0px",width:""},Om={top:"0px",bottom:"0px",height:""},vi=()=>({container:null,active:null,dragRect:null,marquee:null,fillPreview:null,resizeGuide:null,fillPool:[],bandPool:[],dragBand:null,bandClampWidth:-1,bandClampHeight:-1,dividerSlots:[null,null,null,null],dividerShown:[!1,!1,!1,!1],dividers:[]}),Si=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],ki=6,xm=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:R,fillFrameRef:N,resizeGuideFrameRef:H,fillHandleNodeRef:L,enableFillHandle:_,frozenCols:U,frozenRows:W,trailingCols:k,trailingRows:x,sinkAriaLabel:z,sinkReadOnly:I,sinkKeyShortcuts:T,onSinkMouseDown:F,editPaintRef:O,highlightRef:g,highlightColors:p,popoverAnchors:C,interactiveAnchorRef:v,tipAnchorRef:S})=>{const b=i.useRef(null),y=i.useRef(null),a=i.useRef(null),f=i.useRef(new Map(Si.map(M=>[M,vi()]))),E=i.useCallback(M=>{const B=f.current.get(M);if(B!==void 0)return B;const X=vi();return f.current.set(M,X),X},[]),d=i.useCallback((M,B,X)=>{if(M===null)return;const V=M.style;V.left!==B.left&&(V.left=B.left),V.right!==B.right&&(V.right=B.right),V.width!==B.width&&(V.width=B.width),V.top!==X.top&&(V.top=X.top),V.bottom!==X.bottom&&(V.bottom=X.bottom),V.height!==X.height&&(V.height=X.height)},[]),$=i.useCallback((M,B,X)=>{if(!(M.bandClampWidth===B&&M.bandClampHeight===X)){M.bandClampWidth=B,M.bandClampHeight=X;for(const V of M.bandPool)jr(V,B,X);M.dragBand!==null&&jr(M.dragBand,B,X)}},[]),A=i.useRef({rowAxis:e,colAxis:t});A.current={rowAxis:e,colAxis:t};const D=i.useCallback((M,B,X)=>{const V=M.dividerSlots[B];V===null||M.dividerShown[B]===X||(M.dividerShown[B]=X,V.style.display=X?"":"none")},[]),q=i.useRef({x:0,y:0}),j=i.useRef(null),K=i.useCallback((M,B)=>{const X=n.current,V=X?.getFrozenSize()??bm,ee=X?.getViewportSize(),se=ee?.width??-1,ne=ee?.height??-1,Oe=q.current;Oe.x=M,Oe.y=B;let Se=j.current;if(Se===null||Se.frozenCols!==V.cols||Se.frozenWidth!==V.width||Se.frozenRows!==V.rows||Se.frozenHeight!==V.height||Se.trailingCols!==V.trailingCols||Se.trailingWidth!==V.trailingWidth||Se.trailingVisibleWidth!==V.trailingVisibleWidth||Se.trailingRows!==V.trailingRows||Se.trailingHeight!==V.trailingHeight||Se.trailingVisibleHeight!==V.trailingVisibleHeight||Se.bodyWidth!==se||Se.bodyHeight!==ne){const ie=V.trailingVisibleWidth,ce=V.trailingVisibleHeight,ge=V.cols<=0&&V.trailingCols<=0?[{kind:"m",map:re=>re-Oe.x,clamp:se,style:Am,seamLead:!1,seamTrail:!1}]:[...V.cols>0?[{kind:"f",map:re=>re,clamp:V.width,style:{left:"0px",width:`${V.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:re=>re-Oe.x-V.width,clamp:Math.max(0,se-V.width-ie),style:{left:`${V.width}px`,right:`${ie}px`,width:""},seamLead:V.cols>0,seamTrail:V.trailingCols>0},...V.trailingCols>0?[{kind:"t",map:re=>re-A.current.colAxis.totalSize()+ie,clamp:ie,style:{left:"",right:"0px",width:`${ie}px`},seamLead:!0,seamTrail:!1}]:[]],Ce=V.rows<=0&&V.trailingRows<=0?[{kind:"m",map:re=>re-Oe.y,clamp:ne,style:Om,seamLead:!1,seamTrail:!1}]:[...V.rows>0?[{kind:"f",map:re=>re,clamp:V.height,style:{top:"0px",height:`${V.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:re=>re-Oe.y-V.height,clamp:Math.max(0,ne-V.height-ce),style:{top:`${V.height}px`,bottom:`${ce}px`,height:""},seamLead:V.rows>0,seamTrail:V.trailingRows>0},...V.trailingRows>0?[{kind:"t",map:re=>re-A.current.rowAxis.totalSize()+ce,clamp:ce,style:{top:"",bottom:"0px",height:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],he=[];for(const re of ge)for(const ke of Ce)he.push({nodes:E(`${re.kind}${ke.kind}`),xKind:re.kind,yKind:ke.kind,mapX:re.map,clampWidth:re.clamp,xStyle:re.style,xSeamLead:re.seamLead,xSeamTrail:re.seamTrail,mapY:ke.map,clampHeight:ke.clamp,yStyle:ke.style,ySeamLead:ke.seamLead,ySeamTrail:ke.seamTrail});Se={frozenCols:V.cols,frozenWidth:V.width,frozenRows:V.rows,frozenHeight:V.height,trailingCols:V.trailingCols,trailingWidth:V.trailingWidth,trailingVisibleWidth:V.trailingVisibleWidth,trailingRows:V.trailingRows,trailingHeight:V.trailingHeight,trailingVisibleHeight:V.trailingVisibleHeight,bodyWidth:se,bodyHeight:ne,ctxs:he},j.current=Se}const Be=V.width>0,Ve=V.trailingWidth>0,_e=V.height>0,ve=V.trailingHeight>0;for(const ie of Se.ctxs)d(ie.nodes.container,ie.xStyle,ie.yStyle),$(ie.nodes,ie.clampWidth,ie.clampHeight),D(ie.nodes,0,Be),D(ie.nodes,1,Ve),D(ie.nodes,2,_e),D(ie.nodes,3,ve);return Se.ctxs},[n,E,d,$,D]),G=i.useCallback((M,B,X)=>{M.dividerSlots[B]=X,M.dividerShown[B]=!1,M.dividers.length=0;for(const V of M.dividerSlots)V!==null&&M.dividers.push(V)},[]),J=i.useCallback(M=>{const B=()=>E(M);return{container:X=>{const V=B();V.container=X,X===null&&(V.fillPool.length=0,V.bandPool.length=0,V.dragBand=null,V.bandClampWidth=-1,V.bandClampHeight=-1)},dividerXLeading:X=>G(B(),0,X),dividerXTrailing:X=>G(B(),1,X),dividerYLeading:X=>G(B(),2,X),dividerYTrailing:X=>G(B(),3,X),active:X=>{B().active=X},dragRect:X=>{B().dragRect=X},marquee:X=>{B().marquee=X},fillPreview:X=>{B().fillPreview=X},resizeGuide:X=>{B().resizeGuide=X}}},[E,G]),te=i.useMemo(()=>Object.fromEntries(Si.map(M=>[M,J(M)])),[J]),le=Math.min(Math.max(0,U),t.count),me=ya(t,le),Ee=Math.min(Math.max(0,W),e.count),xe=Ra(e,Ee),De=k===void 0?0:Math.min(Math.max(0,k),t.count-le),Pe=va(t,De),ue=x===void 0?0:Math.min(Math.max(0,x),e.count-Ee),Ne=Sa(e,ue),Ue=i.useRef(null),je=i.useRef("add"),Ot=i.useRef(s);Ot.current=s;const xt=i.useRef(!1),He=Je.useWheelBridge(n,{enableBridge:!s}),wt=i.useCallback(M=>(r.current=M,He(M)),[r,He]),bn=i.useCallback((M,B)=>({top:B.mapY(e.offsetOf(M.startRow)),bottom:B.mapY(e.offsetOf(M.endRow)+e.sizeOf(M.endRow)),left:B.mapX(t.offsetOf(M.startCol)),right:B.mapX(t.offsetOf(M.endCol)+t.sizeOf(M.endCol))}),[e,t]),lt=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const{top:X,bottom:V,left:ee,right:se}=bn(M,B),ne=-B.clampHeight*Zt,Oe=B.clampHeight*(1+Zt),Se=-B.clampWidth*Zt,Be=B.clampWidth*(1+Zt);if(V<ne||X>Oe||se<Se||ee>Be)return null;const Ve=Math.max(X,ne),_e=Math.max(ee,Se);return{top:Ve,left:_e,width:Math.min(se,Be)-_e,height:Math.min(V,Oe)-Ve}},[bn]),Er=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const X=bn(M,B),V=-B.clampHeight*Zt,ee=B.clampHeight*(1+Zt),se=-B.clampWidth*Zt,ne=B.clampWidth*(1+Zt),Oe=Math.min(Math.max(X.top,V),ee),Se=Math.min(Math.max(X.left,se),ne);return{top:Oe,left:Se,width:Math.min(Math.max(X.right,se),ne)-Se,height:Math.min(Math.max(X.bottom,V),ee)-Oe}},[bn]),yn=i.useCallback(()=>{if(g===void 0)return null;const M=g.current;return M.row||M.column||M.intersection?M:null},[g]),oe=i.useCallback((M,B,X)=>{const V=B.fillPool[0]?.node??Ri(B);for(const ee of Ea(X))M.insertBefore(ee,V)},[]),fe=i.useCallback((M,B,X,V)=>{const ee=Er(B,X);if(ee===null){bi(M);return}Sm(M,ee,X,V,Cc(B,t.count)||bc(B,e.count))},[Er,e,t]),pe=i.useCallback((M,B,X,V)=>{const ee=M.nodes.bandPool;for(;ee.length>X.length;){const se=ee.pop();se!==void 0&&yi(se)}if(V===null){M.nodes.dragBand!==null&&(yi(M.nodes.dragBand),M.nodes.dragBand=null);return}for(let se=0;se<X.length;se+=1){let ne=ee[se];ne===void 0&&(ne=wi(),jr(ne,M.clampWidth,M.clampHeight),oe(B,M.nodes,ne),ee.push(ne)),fe(ne,X[se],M,V)}},[oe,fe]),Ht=i.useCallback((M,B,X)=>{const V=M.nodes.container;if(V===null)return;if(B===null||X===null){M.nodes.dragBand!==null&&bi(M.nodes.dragBand);return}let ee=M.nodes.dragBand;ee===null&&(ee=wi(),jr(ee,M.clampWidth,M.clampHeight),oe(V,M.nodes,ee),M.nodes.dragBand=ee),fe(ee,B,M,X)},[oe,fe]),Ae=i.useCallback((M,B)=>{if(M!==null){if(B===null){M.style.display="none";return}M.style.display="block",M.style.transform=`translate(${B.left}px, ${B.top}px)`,M.style.width=`${B.width}px`,M.style.height=`${B.height}px`}},[]),Bt=i.useCallback((M,B,X,V)=>{const ee=V==="point"?null:yn();for(const se of K(X,B))Ae(se.nodes.dragRect,lt(M,se)),Ht(se,M,ee)},[lt,K,Ae,yn,Ht]),it=i.useCallback((M,B,X)=>{for(const V of K(X,B))Ae(V.nodes.fillPreview,M===null?null:lt(M,V))},[lt,K,Ae]),Rn=i.useCallback((M,B,X)=>{for(const V of K(X,B)){const ee=V.nodes.resizeGuide;if(ee===null)continue;if(M===null){ee.style.display="none";continue}const se=M.anchor==="trailing";if(M.axis==="col"){if(se&&V.xKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ne=V.mapX(M.position);ee.style.transform=`translate(${se?Math.max(0,ne):ne}px, 0px)`,ee.style.width="1px",ee.style.height="100%"}else{if(se&&V.yKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ne=V.mapY(M.position);ee.style.transform=`translate(0px, ${se?Math.max(0,ne):ne}px)`,ee.style.width="100%",ee.style.height="1px"}}},[K]),Vt=i.useCallback((M,B,X,V,ee,se,ne)=>{if(M===null)return;if(B===null||ne<=0||se<=0){M.style.clipPath=Ci;return}const Oe=wn(e,B.row,V),Se=gn(t,B.col,X),Be=t.sizeOf(B.col),Ve=e.sizeOf(B.row),_e=Se>=se||Oe>=ne,ve=B.col>=ee.cols&&Se<ee.width,ie=B.row>=ee.rows&&Oe<ee.height,ce=ee.trailingWidth>0&&B.col<t.count-ee.trailingCols&&Se+Be>se-ee.trailingVisibleWidth,ge=ee.trailingHeight>0&&B.row<e.count-ee.trailingRows&&Oe+Ve>ne-ee.trailingVisibleHeight;if(_e||ve||ie||ce||ge){M.style.clipPath=Ci;return}M.style.clipPath="",M.style.transform=`translate(${Se}px, ${Oe}px)`;const Ce=`${Be} ${Ve}`;M.dataset.aqspAnchorSig!==Ce&&(M.dataset.aqspAnchorSig=Ce,M.style.width=`${Be}px`,M.style.height=`${Ve}px`)},[e,t]),Ar=i.useCallback((M,B,X)=>{if(C===void 0)return;const V=C.current,{width:ee,height:se}=M.getViewportSize(),ne=M.getFrozenSize(),Oe={scroll:X,frozenCount:ne.cols,trailingCount:ne.trailingCols,extent:ee},Se={scroll:B,frozenCount:ne.rows,trailingCount:ne.trailingRows,extent:se};Vt(v===void 0?null:v.current,V.interactive,Oe,Se,ne,ee,se),Vt(S===void 0?null:S.current,V.tip,Oe,Se,ne,ee,se)},[C,v,S,Vt]),Xn=i.useCallback(()=>{const M=b.current,B=n.current;if(M===null||B===null)return;const X=B.getScrollPosition(),V=Math.max(0,X.y),ee=Math.max(0,X.x),se=o(),ne=K(ee,V),Oe=yn(),Se=Oe===null?Em:se.ranges.slice(-vm(ne.length));for(const ie of ne){const ce=ie.nodes.container;if(ce===null)continue;const ge=ie.nodes.fillPool;for(let Ce=0;Ce<Math.max(ge.length,se.ranges.length);Ce+=1){let he=ge[Ce];if(he===void 0){const Me=document.createElement("div");Me.className="aqsp-selection-fill",Me.setAttribute("data-aqsp-fill",""),Me.style.display="none",ce.insertBefore(Me,Ri(ie.nodes)),he={node:Me,last:{shown:!1,width:-1,height:-1,transform:""}},ge.push(he)}const re=se.ranges[Ce],ke=re===void 0?null:lt(re,ie);if(ke===null)he.last.shown&&(he.last.shown=!1,he.node.style.display="none");else{he.last.shown||(he.last.shown=!0,he.node.style.display="block");const Me=`translate(${ke.left}px, ${ke.top}px)`;Me!==he.last.transform&&(he.last.transform=Me,he.node.style.transform=Me),ke.width!==he.last.width&&(he.last.width=ke.width,he.node.style.width=`${ke.width}px`),ke.height!==he.last.height&&(he.last.height=ke.height,he.node.style.height=`${ke.height}px`)}}for(;ge.length>se.ranges.length;)ge.pop()?.node.remove();Ae(ie.nodes.active,lt(Re(se.active,se.active),ie)),pe(ie,ce,Se,Oe)}const Be=h(),Ve=Be===null||Be.foreign?null:Be;for(const ie of ne){const ce=ie.nodes.marquee;if(ce===null)continue;const ge=Ve===null?null:lt(Ve.range,ie),Ce=ge!==null&&(ie.xSeamTrail&&ge.left>=ie.clampWidth&&ge.left<ie.clampWidth+dr||ie.xSeamLead&&ge.left+ge.width<=0&&ge.left+ge.width>-dr||ie.ySeamTrail&&ge.top>=ie.clampHeight&&ge.top<ie.clampHeight+dr||ie.ySeamLead&&ge.top+ge.height<=0&&ge.top+ge.height>-dr)?null:ge;if(Ce===null)ce.style.display="none";else{ce.style.display="block",ce.style.transform=`translate(${Ce.left}px, ${Ce.top}px)`,ce.style.width=`${Ce.width}px`,ce.style.height=`${Ce.height}px`;const ke=Ir(Ce.top),Me=Ir(Ce.left),Ct=Ir(ie.clampHeight-(Ce.top+Ce.height)),ct=Ir(ie.clampWidth-(Ce.left+Ce.width)),bt=`${ke} ${ct} ${Ct} ${Me}`;bt!==ce.dataset.aqspOutsetSig&&(ce.dataset.aqspOutsetSig=bt,ce.style.setProperty("--aqsp-clip-outset-top",ke),ce.style.setProperty("--aqsp-clip-outset-right",ct),ce.style.setProperty("--aqsp-clip-outset-bottom",Ct),ce.style.setProperty("--aqsp-clip-outset-left",Me))}const he=Ce===null?null:Ve?.kind??null,re=ce.dataset.aqspClipKindLast??null;he!==re&&(he===null?(delete ce.dataset.aqspClipKindLast,ce.removeAttribute("data-aqsp-clip-kind")):(ce.dataset.aqspClipKindLast=he,ce.setAttribute("data-aqsp-clip-kind",he)))}Ue.current!==null&&Bt(Ue.current,V,ee,je.current),a.current!==null&&Rn(a.current,V,ee),y.current!==null&&it(y.current,V,ee);const _e=L.current;if(_e!==null&&!R()){const{width:ie,height:ce}=B.getViewportSize(),ge=se.ranges[se.ranges.length-1];if(!(se.ranges.length===1&&!Ot.current&&!m())||ce<=0||ie<=0)_e.style.display="none";else{const he=B.getFrozenSize(),re={scroll:ee,frozenCount:he.cols,trailingCount:he.trailingCols,extent:ie},ke={scroll:V,frozenCount:he.rows,trailingCount:he.trailingRows,extent:ce},Me=ge.endCol<he.cols,Ct=ge.endRow<he.rows,ct=ge.endCol>=t.count-he.trailingCols,bt=ge.endRow>=e.count-he.trailingRows,Tt=gn(t,ge.endCol,re)+t.sizeOf(ge.endCol),$t=wn(e,ge.endRow,ke)+e.sizeOf(ge.endRow),Kt=Me||ct?0:he.width,yt=Ct||bt?0:he.height,Sn=ct?ie:ie-he.trailingVisibleWidth,kn=bt?ce:ce-he.trailingVisibleHeight;$t<=yt||$t>kn||Tt<=Kt||Tt>Sn?_e.style.display="none":(_e.style.display="block",_e.style.transform=`translate(${Tt-ki+1}px, ${$t-ki+1}px)`)}}const ve=r.current;if(ve!==null){const ie=se.active,{width:ce,height:ge}=B.getViewportSize(),Ce=B.getFrozenSize(),he={scroll:ee,frozenCount:Ce.cols,trailingCount:Ce.trailingCols,extent:ce},re={scroll:V,frozenCount:Ce.rows,trailingCount:Ce.trailingRows,extent:ge},ke=wn(e,ie.row,re),Me=gn(t,ie.col,he),Ct=ge>0?Math.min(Math.max(ke,0),Math.max(0,ge-1)):0,ct=ce>0?Math.min(Math.max(Me,0),Math.max(0,ce-1)):0;ve.style.top=`${Ct}px`,ve.style.left=`${ct}px`,Ot.current?(ve.style.width=`${t.sizeOf(ie.col)}px`,ve.style.height=`${e.sizeOf(ie.row)}px`,ve.style.paddingTop=`${km(e.sizeOf(ie.row),O===void 0?Pt:O.current)}px`):(ve.style.width="1px",ve.style.height="1px",ve.style.paddingTop="0px");const bt=ie.col>=Ce.cols&&Me<Ce.width,Tt=ie.row>=Ce.rows&&ke<Ce.height,$t=Ce.trailingWidth>0&&ie.col<t.count-Ce.trailingCols&&Me+t.sizeOf(ie.col)>ce-Ce.trailingVisibleWidth,Kt=Ce.trailingHeight>0&&ie.row<e.count-Ce.trailingRows&&ke+e.sizeOf(ie.row)>ge-Ce.trailingVisibleHeight,yt=Ot.current&&ke===Ct&&Me===ct&&!bt&&!Tt&&!$t&&!Kt;yt!==xt.current&&(xt.current=yt,yt?ve.setAttribute("data-aqsp-editing",""):ve.removeAttribute("data-aqsp-editing"))}Ar(B,V,ee)},[n,lt,K,Ae,Bt,Rn,it,h,o,m,R,L,r,e,t,yn,pe,O,Ar]),mo=i.useCallback((M,B)=>{Ue.current=M,je.current=B;const X=M===null?"add":B;for(const se of K(0,0)){const ne=se.nodes.dragRect;if(ne===null)continue;const Oe=ne.dataset.aqspDragModeLast??"add";X!==Oe&&(ne.dataset.aqspDragModeLast=X,X==="add"?ne.removeAttribute("data-aqsp-drag-mode"):ne.setAttribute("data-aqsp-drag-mode",X))}const V=n.current;if(M===null||V===null){for(const se of K(0,0))se.nodes.dragRect!==null&&(se.nodes.dragRect.style.display="none"),Ht(se,null,null);return}const ee=V.getScrollPosition();Bt(M,Math.max(0,ee.y),Math.max(0,ee.x),B)},[n,Bt,K,Ht]),Or=i.useCallback(M=>{y.current=M;const B=n.current;if(B===null){for(const V of K(0,0))V.nodes.fillPreview!==null&&(V.nodes.fillPreview.style.display="none");return}const X=B.getScrollPosition();it(M,Math.max(0,X.y),Math.max(0,X.x))},[n,it,K]),go=i.useCallback(M=>{a.current=M;const B=n.current;if(B===null){for(const V of K(0,0))V.nodes.resizeGuide!==null&&(V.nodes.resizeGuide.style.display="none");return}const X=B.getScrollPosition();Rn(M,Math.max(0,X.y),Math.max(0,X.x))},[n,Rn,K]);i.useLayoutEffect(()=>{const M=b.current;if(!(M===null||p===void 0))return M.style.setProperty("--aqsp-band-row",p.row),M.style.setProperty("--aqsp-band-column",p.column),M.style.setProperty("--aqsp-band-intersection",p.intersection),M.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{M.style.removeProperty("--aqsp-band-row"),M.style.removeProperty("--aqsp-band-column"),M.style.removeProperty("--aqsp-band-intersection"),M.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Xn,u.current=mo,N.current=Or,H.current=go,()=>{c.current=null,u.current=null,N.current=null,H.current=null})),i.useEffect(()=>{Xn()},[Xn,s,le,Ee,De,ue]),i.useEffect(()=>{const M=r.current;if(M===null)return;const B=X=>F(X);return M.addEventListener("mousedown",B),()=>M.removeEventListener("mousedown",B)},[r,F]);const Hs=le>0||De>0?[...le>0?[{k:"f",style:{left:0,width:me}}]:[],{k:"s",style:{left:me,right:Pe}},...De>0?[{k:"t",style:{right:0,width:Pe}}]:[]]:[{k:"m",style:{left:0,right:0}}],wo=Ee>0||ue>0?[...Ee>0?[{k:"f",style:{top:0,height:xe}}]:[],{k:"s",style:{top:xe,bottom:Ne}},...ue>0?[{k:"t",style:{bottom:0,height:Ne}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Wt=M=>M==="m"?0:M==="s"?1:M==="t"?2:3,vn=Hs.flatMap(M=>wo.map(B=>({xk:M.k,yk:B.k,key:`${M.k}${B.k}`,style:{...M.style,...B.style}}))).sort((M,B)=>Wt(M.key[0])+Wt(M.key[1])-(Wt(B.key[0])+Wt(B.key[1]))),Gn=M=>M==="mm"?{"data-aqsp-overlay-main":""}:M==="fm"?{"data-aqsp-overlay-frozen":""}:M==="sm"?{"data-aqsp-overlay-scroll":""}:{};return Y.jsxs("div",{ref:b,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Te.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[vn.map(({xk:M,yk:B,key:X,style:V})=>{const ee=te[X];return Y.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Gn(X),style:V,ref:ee.container,children:[M==="s"&&le>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:ee.dividerXLeading}):null,M==="s"&&De>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:ee.dividerXTrailing}):null,B==="s"&&Ee>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:ee.dividerYLeading}):null,B==="s"&&ue>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:ee.dividerYTrailing}):null,Y.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:ee.active}),Y.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:ee.dragRect}),Y.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:ee.marquee}),Y.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:ee.fillPreview}),Y.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:ee.resizeGuide})]},X)}),Y.jsx("textarea",{ref:wt,className:"aqsp-sink","aria-label":z,"aria-readonly":I?"true":void 0,"aria-keyshortcuts":T,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?Y.jsx("div",{ref:L,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Aa=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=R=>{l.current=!0;try{R()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=R=>{if(R.key==="Escape"){R.preventDefault(),c(e.close);return}R.key==="Enter"&&(R.ctrlKey||R.metaKey)&&!R.altKey&&!R.shiftKey&&(R.preventDefault(),u())},m=R=>{l.current||R.relatedTarget instanceof Node&&R.currentTarget.contains(R.relatedTarget)||e.rejected||c(e.close)};return Y.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:m,children:[Y.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[ze(t,"commentTitle"),Y.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:ze(t,"commentCount",e.current.length)})]}),Y.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(R=>Y.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":R.id,children:[Y.jsx("span",{className:"aqsp-popover-comment-author",children:R.author}),Y.jsx("time",{className:"aqsp-popover-comment-time",dateTime:R.createdAt,children:R.createdAt}),Y.jsx("p",{className:"aqsp-popover-comment-text",children:R.text})]},R.id))}),Y.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":ze(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:R=>r(R.currentTarget.value),onKeyDown:h}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:ze(t,"commentPost")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Oa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),u=i.useRef(!1),h=o.trim()===""?null:sn(o),m=o.trim()!==""&&h===null,R=_=>{u.current=!0;try{_()}finally{u.current=!1}},N=()=>{l||m||R(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},H=_=>{if(_.key==="Escape"){_.preventDefault(),R(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),N())},L=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||R(e.close)};return Y.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:L,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:ze(t,"linkTitle")}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:ze(t,"linkTextField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:H})]}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:ze(t,"linkUrlField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown:H})]}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:N,children:ze(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:ze(t,"linkOpen")}):null,Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>R(e.close),children:"×"})]})]})},Ei=500,xa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),u=i.useMemo(()=>{const W=n.toLowerCase();return e.current.filter(k=>k.toLowerCase().startsWith(W))},[e.current,n]),h=i.useMemo(()=>u.length>Ei?u.slice(0,Ei):u,[u]),m=u.length-h.length,R=h.length===0?-1:Math.min(o,h.length-1),N=W=>{c.current=!0;try{W()}finally{c.current=!1}},H=()=>{R<0||N(()=>e.commit(h[R]))},L=W=>{if(W.key==="Escape"){W.preventDefault(),N(e.close);return}if(W.key==="Enter"){W.preventDefault(),H();return}if(W.key==="ArrowDown"){W.preventDefault(),s(R+1);return}W.key==="ArrowUp"&&(W.preventDefault(),s(Math.max(R-1,0)))},_=W=>{c.current||W.relatedTarget instanceof Node&&W.currentTarget.contains(W.relatedTarget)||N(e.close)},U=W=>`${l}-${W}`;return Y.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":ze(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":R<0?void 0:U(R),value:n,onChange:W=>{r(W.currentTarget.value),s(0)},onKeyDown:L}),Y.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":ze(t,"listTitle"),children:[h.length===0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:ze(t,"listEmpty")}):h.map((W,k)=>Y.jsx("div",{className:"aqsp-popover-option",id:U(k),role:"option",tabIndex:-1,"aria-selected":k===R,"data-aqsp-list-option":W,onPointerDown:x=>x.preventDefault(),onClick:()=>N(()=>e.commit(W)),children:W},U(k))),m>0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:ze(t,"listMore",m)}):null]})]})},Ta=({ctx:e,labels:t})=>Y.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),Y.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:e.close,children:"×"})]}),$a=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=L=>{u.current=!0;try{L()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},R=()=>{r!==n&&!s?m():h(e.close)},N=L=>{if(L.key==="Escape"){L.preventDefault(),e.rejected?h(e.close):R();return}L.key==="Enter"&&(L.ctrlKey||L.metaKey)&&!L.altKey&&!L.shiftKey&&(L.preventDefault(),m())},H=L=>{u.current||L.relatedTarget instanceof Node&&L.currentTarget.contains(L.relatedTarget)||e.rejected||R()};return Y.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:H,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:ze(t,"noteTitle")}),Y.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:L=>o(L.currentTarget.value),onKeyDown:N}),Y.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:ze(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:ze(t,"noteSave")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},La=({ctx:e})=>Y.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Nt=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")}),Ai=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Da=Object.freeze({all:Nt(Ai),values:Nt(["text"]),formats:Nt(["format","borders","cf"]),formulas:Nt(["text","formula"]),noBorders:Nt(Ai.filter(e=>e!=="borders")),columnWidths:Nt(["sizes"]),validation:Nt(["validation"]),conditionalFormats:Nt(["cf"]),commentsAndNotes:Nt(["note","comments"])}),Oi=Object.freeze({mode:"all"}),Cs=Object.freeze({t:""}),xi=Object.freeze({row:1<<30,col:1<<30}),Tm=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),$m=e=>e.t===""&&e.f===void 0,Lm=e=>e.length>1&&e.startsWith("="),Dm=(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}},Ti=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Mm=(e,t,n,r)=>{const o=Lm(e),s=e===""?"0":ot(e);if(!o&&s===null)return null;const l=Tm[n];if(t.f!==void 0){const h=Rr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Ti(Number(s));const c=ot(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Ti(Dm(Number(s),u,n))},$i=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),zm=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:$i(e.start),end:$i(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}}}},Nm=e=>{const t=Rr(e,xi),n=yr(t);let r="",o=0,s=!1;for(const l of n){const c=zm(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${tn(c)}`,o=l.end,s=!0)}return s?uo(`${r}${t.slice(o)}`,xi):e},Fm=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Cs;const o=r[n];return o===void 0?Cs:o},Pm=e=>{const{rows:t,cols:n}=e,r=Dc(Nm);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const u=[];for(let h=0;h<t;h+=1){const m=Fm(e,h,c);let R=m;if(m.f!==void 0){const N=r(m.f);R=N===m.f?m:{...m,f:N}}(R!==m||m===Cs)&&(o=!1),u.push(R)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},_m=(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,qm=(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},Li=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)_m(m,t)?(h.push(qm(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},Di=new WeakMap,Ma=e=>{const t=Di.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>gt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:gt({...s,borders:void 0})),o={canonical:n,borderless:r};return Di.set(e,o),o},so=(e,t)=>t===void 0?void 0:e[t],Im=(e,t,n,r)=>{const o=Ma(e);if(n){const h=so(o.canonical,t.fmt);return h===void 0?null:h}const s=so(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const u=gt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},jm=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Mm(n.readText(),o,r,n):o.f===void 0?o.t:Rr(o.f,n)},Mi=(e,t,n,r,o)=>{const s=Da[r.mode];if(r.skipBlanks===!0&&$m(e))return null;const l={};let c=!1;if(s.text){const u=jm(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Im(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=so(Ma(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=so(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},zi=(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}}),Hm=["text/html","text/plain"],Bm=(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},Vm=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Wm=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Km=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}}},Ni=e=>{const t=e.clipboardData;return t??null},Ym=(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}},Um=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Ym(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},Xm=(e,t,n,r,o)=>{const s=Yn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=uo(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=Un(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},za=(e,t)=>{const n=wc(),r=Qd(),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(Xm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Um(e.getConditionalFormats(),t)}},Fi=e=>e.kind==="cut"?{...e.payload,...za(e.sourceAdapter,e.range)}:e.payload,Gm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:As(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Zm=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=sn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Jm=(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},Qm=(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 Re({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},eg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(k=>{const x=n.current;if(x===null||k==="format"||k==="annotate")return;const z=r.current;z==="own"||z==="foreign"&&x.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const k=n.current;if(k===null)return;if(k.kind==="copy"){o();return}const x=t.current;x.repaintOverlay(),x.onClipChange?.({kind:"cut",range:k.range,foreign:k.sourceAdapter!==x.adapter})},[o]),c=i.useCallback((k,x,z)=>{const I=t.current;n.current={kind:k,range:x,clipId:z.clipId,sourceAdapter:I.adapter,payload:z},I.repaintOverlay(),I.onClipChange?.({kind:k,range:x,foreign:!1})},[]),u=i.useCallback(k=>{const x=t.current,z=x.adapter,I=st(k),T={v:1,rows:I.rows,cols:I.cols,clipId:As(),...za(z,k),wholeRows:Cc(k,z.colCount),wholeCols:bc(k,z.rowCount)};if(x.resize!==void 0){if(T.wholeCols){const F=[];for(let O=k.startCol;O<=k.endCol;O+=1)F.push(Math.min(x.resize.colAxis.sizeOf(O),on));T.colWidths=F}if(T.wholeRows){const F=[];for(let O=k.startRow;O<=k.endRow;O+=1)F.push(Math.min(x.resize.rowAxis.sizeOf(O),on));T.rowHeights=F}}return T},[]),h=i.useCallback((k,x)=>{const z=t.current,I=z.getSelection(),T=I.ranges[I.ranges.length-1],F=At([T]);if(F>z.maxOperationCells)return k.preventDefault(),z.onOperationRejected?.(x,F,"limit"),null;if(x==="cut"&&ur(z.adapter,T))return k.preventDefault(),z.rejectReadOnly({kind:"operation",op:"cut",cellCount:F}),null;I.ranges.length>1&&z.onCopyMultiRange?.();const O=u(T),g=lc(O),p=Ni(k);return p!==null&&(p.setData("text/plain",qt.serializeClipboardTsv(O.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",Gc(O,g)),p.setData(no,g)),k.preventDefault(),{payload:O,range:T}},[u]),m=i.useCallback((k,x)=>t.current.commitPaste(k,x)!==null,[]),R=i.useCallback((k,x,z)=>{const I=t.current;if(!z.sizes||I.resize===void 0)return;const{rowAxis:T,colAxis:F,resizeTracks:O}=I.resize,g=(p,C,v)=>{const S=vs(C,v,null,{maxOperationCells:I.maxOperationCells,rowHiddenLimit:ys,axisKind:p});if(!S.ok){I.onOperationRejected?.("resize",S.count,S.reason);return}O(p,S.entries)};if(k.colWidths!==void 0){const p=[];for(let C=x.startCol;C<=x.endCol;C+=1)p.push({index:C,size:k.colWidths[(C-x.startCol)%k.cols]});g("col",F,p)}if(k.rowHeights!==void 0){const p=[];for(let C=x.startRow;C<=x.endRow;C+=1)p.push({index:C,size:k.rowHeights[(C-x.startRow)%k.rows]});g("row",T,p)}},[]),N=i.useCallback((k,x)=>{const z=t.current,I=z.adapter,T=k.payload,F={row:x.startRow,col:x.startCol},O=T.rows*T.cols+At([k.range]);if(O>z.maxOperationCells)return z.onOperationRejected?.("paste",O,"limit"),"rejected";if(F.row+T.rows>I.rowCount||F.col+T.cols>I.colCount||k.range.endRow>=k.sourceAdapter.rowCount||k.range.endCol>=k.sourceAdapter.colCount)return z.onOperationRejected?.("paste",O,"bounds"),"rejected";const g=gs({rows:T.rows,cols:T.cols},Re(F,F),F,I.rowCount,I.colCount);if(g!==null&&ur(I,g))return z.rejectReadOnly({kind:"operation",op:"paste",cellCount:T.rows*T.cols}),"rejected";if(ur(k.sourceAdapter,k.range))return z.rejectReadOnly({kind:"operation",op:"cut",cellCount:At([k.range])}),"rejected";const p=Fi(k),C=eo(I),v=Li(p,C),S={row:0,col:0,readText:()=>Yn(I,S.row,S.col).text,readFormat:()=>I.getCellFormat===void 0?void 0:I.getCellFormat(S.row,S.col)},{edits:b,tiles:y}=ii(v.cells,Re(F,F),F,I.rowCount,I.colCount,(E,d,$)=>(S.row=k.range.startRow+(d-F.row),S.col=k.range.startCol+($-F.col),Mi(E,v,S,Oi,C))),a=eo(k.sourceAdapter),f=[];if(Jt([k.range],E=>{f.push(Jm(E.row,E.col,a))}),k.sourceAdapter===I){if(!m([...f,...b],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const E=z.commitPaste(b,{sameSheet:!1,conditionalFormats:zi(v.conditionalFormats,y)});if(E===null)return"rejected";try{k.sourceAdapter.applyEdits(f,{transaction:E,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){z.onEditRejected?.(d,{source:"paste"})}}return z.setSelection({ranges:[Re(F,{row:F.row+p.rows-1,col:F.col+p.cols-1})],anchor:F,active:F}),"applied"},[m]),H=i.useCallback((k,x,z)=>{const I=t.current,T=I.adapter,F=K=>(I.onClipboardUnavailable?.(K),"rejected"),O=ac(k,x);if(O==="none")return x==="menu"?F("empty"):"empty";const g=I.getSelection(),p=g.ranges[g.ranges.length-1],C=z.transpose===!0,v=(K,G)=>{const J=Bm(C?G:K,C?K:G,p);return J>I.maxOperationCells?(I.onOperationRejected?.("paste",J,"limit"),!0):!1};let S,b=null;if(O==="aqsp"){const K=Ad(k,x);if(K===null)return F("unreadable");const G=n.current;if(G!==null&&K.clipId===G.clipId&&(b=G),b!==null&&b.kind==="cut"&&Vm(z))return N(b,p);if(v(K.rows,K.cols))return"rejected";if(b!==null){if(b.kind==="cut"&&(b.range.endRow>=b.sourceAdapter.rowCount||b.range.endCol>=b.sourceAdapter.colCount))return I.onOperationRejected?.("paste",b.payload.rows*b.payload.cols,"bounds"),"rejected";S=Fi(b)}else{const J=Od(k,x);if(J===null)return F("unreadable");if(v(J.rows,J.cols))return"rejected";S=Zm(J)}}else if(O==="tsv"){const K=k.getData("text/plain"),G=qt.measureTsv(K);if(v(G.rows,G.cols))return"rejected";S=Gm(qt.parseTsv(K))}else{const K=k.getData("text/html"),G=Jd(K);if(G.cols===0&&G.rows>I.maxOperationCells)return I.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(v(G.rows,G.cols))return"rejected";const J=ea(K,O,I.formats===void 0?{}:{currency:I.formats.currency,locale:I.formats.locale},I.maxOperationCells);if(J.outcome==="none")return F("unreadable");if(J.outcome==="limit")return I.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(v(J.payload.rows,J.payload.cols))return"rejected";S=J.payload}const y=eo(T),a=Li(C?Pm(S):S,y),f=Da[z.mode];if(Wm(f)){const K=gs({rows:a.rows,cols:a.cols},p,g.active,T.rowCount,T.colCount);if(K!==null&&ur(T,K))return I.rejectReadOnly({kind:"operation",op:"paste",cellCount:At([K])}),"rejected"}const E={row:0,col:0,readText:()=>Yn(T,E.row,E.col).text,readFormat:()=>T.getCellFormat===void 0?void 0:T.getCellFormat(E.row,E.col)},{edits:d,tiles:$}=ii(a.cells,p,g.active,T.rowCount,T.colCount,(K,G,J)=>(E.row=G,E.col=J,Mi(K,a,E,z,y))),A=Qm($,a.rows,a.cols,T.rowCount,T.colCount);if(A===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let K=0;for(const J of a.conditionalFormats)K+=J.ranges.length;const G=$.length*K;if(G>I.maxOperationCells)return I.onOperationRejected?.("paste",G,"limit"),"rejected"}const D=f.cf?zi(a.conditionalFormats,$):[];if(d.length===0&&D.length===0)return R(a,A,f),"empty";r.current=b===null?"foreign":"own";let q=!1;try{q=m(d,{sameSheet:b!==null&&b.sourceAdapter===T,conditionalFormats:D})}finally{r.current="none"}if(!q)return"rejected";R(a,A,f);const j={row:A.startRow,col:A.startCol};return I.setSelection({ranges:[A],anchor:j,active:j}),"applied"},[N,m,R]),L=i.useCallback(async k=>{const x=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),z=navigator;if(z.clipboard===void 0)return x("insecure-origin");let I;try{I=await z.clipboard.read({unsanitized:["text/html"]})}catch{return x("permission-denied")}if(I.length===0)return x("empty");const T=I[0],F=Array.from(T.types),O=new Map;try{for(const C of Hm)F.includes(C)&&O.set(C,await(await T.getType(C)).text())}catch{return x("unreadable")}const g={types:F,getData:C=>{const v=O.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":H(g,"menu",k)},[H]),_=i.useCallback(async k=>{const x=await L(k);return t.current.onPasteResolved?.(x,"menu"),x},[L]),{enabled:U,sinkRef:W}=e;return i.useEffect(()=>{const k=W.current;if(!U||k===null)return;const x=F=>t.current.isDragging()?(F.preventDefault(),!0):!1,z=F=>{const O=t.current;if(x(F)||O.isEditing())return;const g=h(F,"copy");g!==null&&c("copy",g.range,g.payload)},I=F=>{const O=t.current;if(x(F)||O.isEditing())return;const g=h(F,"cut");g!==null&&c("cut",g.range,g.payload)},T=F=>{const O=t.current;if(x(F)||O.isEditing())return;F.preventDefault();let g=Oi;const p=O.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(g=p.current,p.current=null);const C=Ni(F);if(C===null)return;const v=H(Km(C),"event",g);O.onPasteResolved?.(v,"event")};return k.addEventListener("copy",z),k.addEventListener("cut",I),k.addEventListener("paste",T),()=>{k.removeEventListener("copy",z),k.removeEventListener("cut",I),k.removeEventListener("paste",T)}},[U,W,h,c,H]),i.useMemo(()=>({getClip:()=>{const k=n.current;return k===null?null:{kind:k.kind,range:k.range,foreign:k.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},Na=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)}`)},Fa=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}},Pi=(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}`}`},Pa=(e,t)=>{let n;if(e.exponent===null)n=Pi(e.negative,e.digits,e.point+t);else{const r=Pi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return ot(n)===null?null:n},tg=(e,t)=>{Na(t);const n=ot(e);return n===null?null:Pa(Fa(n),t)},ng=e=>{const t=ot(e);if(t!==null){const r=Fa(t);return Pa({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},_a=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)},rg=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},qa=(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 rg(r)?r:null},og=(e,t)=>{Na(t);const n=_a(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=qa(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},sg=e=>{const t=_a(e),n=qa(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},lr=(e,t,n,r)=>{const o=At(t);return o>n?(r?.(e,o,"limit"),!1):!0},Br={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Vr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},_i={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:Br.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Br.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Br.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Br.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:Vr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Vr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Vr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Vr.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},lg={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},mr=e=>e<10?`0${e}`:String(e),ig=e=>{const t=new Date(e);return`${t.getFullYear()}-${mr(t.getMonth()+1)}-${mr(t.getDate())}`},cg=e=>{const t=new Date(e);return`${mr(t.getHours())}:${mr(t.getMinutes())}:${mr(t.getSeconds())}`},ag=(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),ug=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),dg=e=>e===void 0||e.borders===void 0?{}:e.borders,fg={top:1,right:2,bottom:4,left:8},pg={style:"thin",color:Ss},hg=(e,t)=>{if(e===void 0)return!1;const n=Ze(e);return n!==null&&n===Ze(t)},mg=(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}}},gg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const p=g.getActive();return[Re(p,p)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,p=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(g=>{const p=t.current,C=n();if(!lr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:At(C)}),!1;const v=new Map,S=[],b=p.adapter.getCellFormat;for(const y of C)Jt([y],a=>{const f=b===void 0?void 0:b(a.row,a.col),{bucket:E,patch:d}=g(a,y,f);let $=v.get(E);$===void 0&&($=new Map,v.set(E,$));let A;$.has(f)?A=$.get(f):(A=Es(f,d),$.set(f,A)),A!==f&&S.push({row:a.row,col:a.col,format:A===void 0?null:A})});return S.length===0?!0:p.commitEdits(S,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:g,state:p}))},[]),c=i.useCallback((g,p=pg)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=g==="outer"?15:fg[g];return o((v,S,b)=>{const y=ag(v,S)&C;return{bucket:y,patch:{borders:{...dg(b),...ug(y,p)}}}})},[s,o]),u=i.useCallback((g,p,C)=>{const v=sa(t.current.adapter,g.row,g.col);for(const S of p)C.push(la(v,g,S))},[]),h=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!lr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[];if(g==="selection"){const b=C.active,y=[];Jt(C.ranges,a=>{(a.row!==b.row||a.col!==b.col)&&y.push(a)}),v.push({source:b,targets:y})}else for(const b of C.ranges)if(g==="down"){const y=b.startRow===b.endRow;if(y&&b.startRow===0)continue;const a=y?b.startRow-1:b.startRow;for(let f=b.startCol;f<=b.endCol;f+=1){const E=[];for(let d=y?b.startRow:b.startRow+1;d<=b.endRow;d+=1)E.push({row:d,col:f});v.push({source:{row:a,col:f},targets:E})}}else{const y=b.startCol===b.endCol;if(y&&b.startCol===0)continue;const a=y?b.startCol-1:b.startCol;for(let f=b.startRow;f<=b.endRow;f+=1){const E=[];for(let d=y?b.startCol:b.startCol+1;d<=b.endCol;d+=1)E.push({row:f,col:d});v.push({source:{row:f,col:a},targets:E})}}for(const b of v)for(const y of b.targets)if(Ye(p.adapter,y.row,y.col)){let a=0;for(const f of v)a+=f.targets.length;return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:a}),!1}const S=[];for(const b of v)u(b.source,b.targets,S);return S.length===0?!0:p.commitEdits(S,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const g=t.current,p=g.getSessionText();if(p===null)return!1;const C=g.getSelection();if(!lr("fill",C.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(qn(g.adapter,C.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:At(C.ranges)}),!1;const v=[];let S=!1;return Jt(C.ranges,b=>{if(!S){if(!g.validateCommit(b,p).ok){S=!0;return}v.push({row:b.row,col:b.col,text:p})}}),S||g.commitEdits(v,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),R=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!lr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:At(C.ranges)}),!1;const v=[],S=p.adapter;return Jt(C.ranges,b=>{const y=S.getCellFormula===void 0?void 0:S.getCellFormula(b.row,b.col),a=y===void 0?g.text(S.getCellText(b.row,b.col)):g.formula(y);a!==null&&v.push({row:b.row,col:b.col,text:a})}),v.length===0?!0:p.commitEdits(v,{source:"calc"})!==null},[]),N=i.useCallback((g,p)=>{const C=t.current,v=g==="row"?C.rowAxis:C.colAxis,S=C.getSelection(),b=g==="row"?Math.floor(C.maxOperationCells/Rs):C.maxOperationCells;let y=0;for(const $ of S.ranges)y+=g==="row"?$.endRow-$.startRow+1:$.endCol-$.startCol+1;if(y>b)return C.onOperationRejected?.("resize",y,"limit"),!1;const a=new Set,f=[],E=p?0:g==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const $ of S.ranges){const A=g==="row"?$.startRow:$.startCol,D=g==="row"?$.endRow:$.endCol;for(let q=A;q<=D;q+=1){if(a.has(q))continue;a.add(q),v.sizeOf(q)===0!==p&&f.push({index:q,size:E})}}const d=vs(v,f,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:ys,axisKind:g});return d.ok?(d.entries.length>0&&C.resizeTracks(g,d.entries),!0):(C.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),H=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const p=g.getActive();return Un(g.adapter.getCellHyperlink(p.row,p.col))},[]),L=i.useCallback(g=>{const p=t.current,C=p.adapter,v=_i[g],S=C.getCellFormat!==void 0,b=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(v.kind){case"resize":return p.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return S;case"value":return S&&(v.value!=="currency"||p.formats!==void 0);case"popover":switch(v.popover){case"link":return C.getCellHyperlink!==void 0&&b("link");case"note":return C.getCellNote!==void 0&&b("note");case"comment":return C.getCellComments!==void 0&&b("comment");default:return C.getCellValidation!==void 0&&b("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(p.onHyperlinkOpen!==void 0?H()!==void 0:b("link"));case"paste":return v.options.mode==="formats"?S:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[H]),_=i.useCallback(g=>{const p=t.current,C=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=p.getActive();if(!Ye(p.adapter,v.row,v.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let S;if(C==="link")S=H()!==void 0;else if(C==="note"){const b=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(v.row,v.col);S=b!==void 0&&b!==""}else{const b=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(v.row,v.col);S=b!==void 0&&b.length>0}return S?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[H]),U=i.useCallback((g,p,C)=>{const v=t.current,S=v.trackResize;if(S===void 0)return!1;const b=v.getActive(),y=p==="col"?b.col:b.row,a=C==="fit"?S.autofitColumn(y):S.stepTrack(p,y,C),f=(p==="col"?v.colAxis:v.rowAxis).sizeOf(y);return a&&f>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:g,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),W=i.useCallback(g=>{const p=t.current;if(!L(g))return!1;const C=_i[g];if(!_(C))return!1;const v=p.isEditing();if(v&&!Ps.has(g)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const S=r(),b=S!==void 0&&S[C.key]===!0;return s({[C.key]:b?null:!0})?(l(g,!b),!0):!1}case"patch":return s(C.patch)?(l(g,null),!0):!1;case"clear":return s(lg)?(l(g,null),!0):!1;case"value":return s({value:mg(C.value,p.formats)})?(l(g,null),!0):!1;case"borders":return c(C.preset)?(l(g,null),!0):!1;case"color":{const S=C.key==="background"?p.colors.fill:p.colors.font,b=C.preset!==null?C.preset:C.custom!==null&&C.custom<S.length?S[C.custom]:void 0;if(b===void 0)return!1;const y=r(),a=hg(y===void 0?void 0:y[C.key],b);return s({[C.key]:a?null:b})?(l(g,!a),!0):!1}case"calc":return R({text:S=>tg(S,C.exponent),formula:S=>og(S,C.exponent)});case"sign":return R({text:ng,formula:sg});case"fill":return v&&C.direction==="selection"?m():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const S=H();return S===void 0?!1:(p.onHyperlinkOpen(S,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const S=C.unit==="date"?ig(p.now()):cg(p.now());if(v)return p.insertAtCaret(S),!0;const b=p.getActive();return Ye(p.adapter,b.row,b.col)?(p.rejectReadOnly({kind:"edit",cell:b,editSession:"none"}),!1):p.validateCommit(b,S).ok?p.commitEdits([{row:b.row,col:b.col,text:S}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return U(g,C.axis,C.step);default:{const S=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...S,row:!S.row}),!0;case"column":return p.setHighlight({...S,column:!S.column}),!0;case"both":{const b=S.row&&S.column;return p.setHighlight({...S,row:!b,column:!b}),!0}default:return p.setHighlight({...S,intersection:!S.intersection}),!0}}}},[L,_,H,r,s,l,c,R,h,m,N,U]),k=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),x=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=g===null?null:sn(g);if(g!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!k())return!1;const v=p.getActive();return Ye(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[k]),z=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!k())return!1;const C=p.getActive();return Ye(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:g}],{source:"annotate"})!==null},[k]),I=i.useCallback(g=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!k())return!1;const v=p.getActive();if(Ye(p.adapter,v.row,v.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const S=C(v.row,v.col),b=S===void 0?[g]:[...S,g];return p.commitEdits([{row:v.row,col:v.col,comments:b}],{source:"annotate"})!==null},[k]),T=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!k())return!1;const C=p.getSelection().ranges;if(!lr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:At(C)}),!1;const v=[];return Jt(C,S=>{v.push({row:S.row,col:S.col,validation:g})}),p.commitEdits(v,{source:"annotate"})!==null},[k]),F=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),O=i.useCallback((g,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,p)},[c]);return i.useMemo(()=>({executeCommand:W,applyFormat:F,setBorders:O,setHyperlink:x,setNote:z,addComment:I,setValidation:T,isCommandAvailable:L}),[W,F,O,x,z,I,T,L])},Wr="data-aqsp-pointing",wg=(e,t)=>{const n=Pc(e,t);return n!==null&&"insertAt"in n},Cg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},bg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),u=i.useRef(null),h=i.useRef(Pt),m=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=Pc(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),R=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=m()!==null;a!==y.hasAttribute(Wr)&&(a?y.setAttribute(Wr,""):y.removeAttribute(Wr))},[m]),N=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const E=f.resolveEditPaint(a),d=E===null?Pt:E;d!==Pt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),H=i.useCallback(y=>{Cg(y,Object.keys(h.current.style)),h.current=Pt;const a=t.current.editPaintRef;a!==void 0&&(a.current=Pt)},[]),L=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const E=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),H(d),d.removeAttribute(Wr)),o(!1)};if(y.commit){const d=a.sinkRef.current,$=d===null?"":d.value,A=Yn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
13
+ `),D=$===A;let q;if(D)q=!0;else if(Ye(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),q=!1;else{const j={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};q=(a.validateCommit===void 0||a.validateCommit(f.cell,$).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:$}],j)!==null}if(!q)return y.onReject==="discard"&&(E(),a.rearmSink()),!1}return E(),y.rearm&&a.rearmSink(),!0},[H]),_=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const E=f.sinkRef.current;if(E===null)return;const d=f.getActive();if(Ye(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:A,isFormula:D}=Yn(f.adapter,d.row,d.col);E.value=A;const q=a===void 0||D?A.length:Math.min(a,A.length);E.setSelectionRange(q,q)}else E.value="";const $=f.resolveEditAlign(d);$!==null&&(E.style.textAlign=$),N(E,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[N]),U=i.useCallback(()=>{L({rearm:!0,commit:!1})},[L]),W=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return L({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return L({rearm:!0,commit:!0,onReject:"keep"})},[L]),k=i.useCallback(()=>m()!==null,[m]),x=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,R(),!0),[R]),z=i.useCallback(()=>{const y=m(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=Fc(y.sink.value,y.sink.selectionStart);if(f===null)return null;const E=f.token,d=u.current;switch(E.kind){case"cell":{const $={row:E.row,col:E.col};return u.current=$,{origin:$,cursor:$,axis:"cells"}}case"range":{const $=d!==null&&(d.row===E.start.row||d.row===E.end.row)&&(d.col===E.start.col||d.col===E.end.col)?{row:d.row,col:d.col}:{row:E.start.row,col:E.start.col};return u.current=$,{origin:$,cursor:{row:$.row===E.start.row?E.end.row:E.start.row,col:$.col===E.start.col?E.end.col:E.start.col},axis:"cells"}}case"column":{const $=d!==null&&(d.col===E.start.col||d.col===E.end.col)?d.col:E.start.col,A={row:a.cell.row,col:$};return u.current=A,{origin:A,cursor:{row:a.cell.row,col:$===E.start.col?E.end.col:E.start.col},axis:"columns"}}case"row":{const $=d!==null&&(d.row===E.start.row||d.row===E.end.row)?d.row:E.start.row,A={row:$,col:a.cell.col};return u.current=A,{origin:A,cursor:{row:$===E.start.row?E.end.row:E.start.row,col:a.cell.col},axis:"rows"}}}},[m]),I=i.useCallback((y,a)=>{const f=m();if(f===null)return;const E=Mf(y,a),{sink:d}=f,[$,A]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],D=d.value;d.value=`${D.slice(0,$)}${E}${D.slice(A)}`;const q=$+E.length;d.setSelectionRange(q,q),"row"in y&&(u.current={row:y.row,col:y.col}),R()},[m,R]),T=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),F=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,R())},[R]),O=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=Bf(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),R(),!0)},[R]),g=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,E=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(E)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,R()},[R]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(H(f),N(f,a.cell),y.repaintOverlay?.())},[H,N]),{enabled:S,sinkRef:b}=e;return i.useEffect(()=>{const y=b.current;if(!S||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},E=A=>{const D=t.current;if(l.current||n.current===null)return;const q=D.rootRef.current,j=A.relatedTarget;q!==null&&j instanceof Node&&q.contains(j)||L({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const A=t.current;u.current=null,A.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&wg(y.value,y.selectionStart)&&(c.current=!0),R()},$=()=>{n.current!==null&&R()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",E),y.addEventListener("input",d),document.addEventListener("selectionchange",$),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",E),y.removeEventListener("input",d),document.removeEventListener("selectionchange",$)}},[S,b,L,R]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:W,cancelEdit:U,startEdit:_,getPointing:k,togglePointingArm:x,getReferenceCursor:z,insertReference:I,captureSink:T,restoreSink:F,cycleAnchorAtCaret:O,insertAtCaret:g,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[W,U,_,k,x,z,I,T,F,O,g,p,C,v,r])},yg=(e,t,n)=>{const r=new Je.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}},Rg=(e,t,n)=>{const{tree:r,initialHidden:o}=yg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:R}=r.prefixSum(h);return m-R},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),R=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(R+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const R=Math.round(m);r.get(h)===0!=(R===0)&&(s+=R===0?1:-1),r.update(h,R)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},nn=(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)},Bn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:nn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=nn(e,o,1);return r},qi=(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=Rg(e,t,r)),o.current.model},Vn=256,Jo=256,vg=2**32,Sg=4096,Ia=Object.freeze([]),ja=["background","color","bold","italic","underline","strikethrough"],Ha=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},rn=(e,t,n)=>(e.size>=Sg&&e.clear(),e.set(t,n),n),Ba=e=>(Ha(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Va=(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},kg=(e,t,n)=>{const r=Math.floor(t/Vn),o=Math.floor(n/Jo),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Vn,u=o*Jo,h=[];for(const m of e.rules)Va(m.ranges,c,c+Vn-1,u,u+Jo-1)&&h.push(m);return rn(e.buckets,s,h.length===0?Ia:h)},Eg=(e,t,n)=>{const r=Math.floor(t/Vn),o=r*vg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=kg(e,t,n),c=r*Vn,u=[];for(const h of l)Va(h.ranges,c,c+Vn-1,n,n)&&u.push(h);return rn(e.columns,o,u.length===0?Ia:u)},Ag=(e,t)=>{for(const n of e)if(Cn(n,t))return!0;return!1},qs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Kr=(e,t)=>e<t?-1:e>t?1:0,Ii=(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}},ji=new WeakMap,bs=e=>e===null?null:Number(e),Og=e=>{const t=ji.get(e);if(t!==void 0)return t;const n=e.b,r={a:bs(ot(e.a)),b:n===void 0?null:bs(ot(n))};return ji.set(e,r),r},Wa=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:rn(e.numbers,r,bs(ot(n())))},xg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Og(e),l=Wa(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Ii(e.op,Kr(l,s.a),c===null?null:Kr(l,c));const u=n(),h=e.b;return Ii(e.op,Kr(u,e.a),h===void 0?null:Kr(u,h))},Tg=(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}},Qo=e=>{const t=Ze(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]},Yr=e=>e.toString(16).padStart(2,"0"),es=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Yr(r(0))}${Yr(r(1))}${Yr(r(2))}`,s=r(3);return s===255?o:`${o}${Yr(s)}`},ts=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),$g=(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=Qo(t.color),u=Qo(r.color);const h=n===void 0?void 0:Qo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const R=s;s=l,l=R;const N=c;c=u,u=N}if(n!==void 0&&h!==void 0){const R=n.value===void 0?(s+l)/2:n.value;if(s<R&&R<l)return e<=R?es(c,h,ts(e,s,R)):es(h,u,ts(e,R,l))}return es(c,u,ts(e,s,l))},Lg=(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 rn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return rn(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return rn(r.extrema,e.id,{min:c,max:u})},Dg=(e,t,n,r,o,s)=>{const l=Wa(s,n,r);if(l===null)return null;const c=Lg(e,t,o,s);return c===null?null:$g(l,t.min,t.mid,t.max,c)},Mg=(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:rn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},zg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return xg(s,t,n,o)?e.style:null;case"text":return Tg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Dg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Mg(e,s,t,r,o)?e.style:null;default:return null}},Hi=(e,t)=>Es(e,t),Ng=(e,t,n)=>{e[t]=n},Fg=(e,t)=>{let n=e;for(const r of ja)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Ng(n,r,t[r]));return n},Pg=e=>{let t="";for(const n of ja){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Bi=new WeakMap,_g=Object.freeze({}),qg=e=>{const t=e===void 0?_g:e,n=Bi.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Bi.set(t,r),r},Ig=(e,t,n)=>{const r=qg(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=Hi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Pg(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Hi(e,t);return l!==void 0&&rn(r.byKey,o,l),l},Is=(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=Eg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const R of c){if(!Ag(R.ranges,u))continue;const N=zg(R,u,s,e,n);if(N!==null){if(N!==R.style&&(m=!1),h===null)h=N;else{const H=Fg(h,N);H!==h&&(m=!1,h=H)}if(R.stopIfTrue===!0)break}}return h===null?l:Ig(l,h,m)},Vi=new WeakMap,jg=e=>{Ha(e,"widthRelevantRules");const t=Vi.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 Vi.set(e,r),r},Hg=({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},Bg=i.memo(Hg),Vg=Object.freeze({left:Object.freeze({justifyContent:fr("left")}),center:Object.freeze({justifyContent:fr("center")}),right:Object.freeze({justifyContent:fr("right")})}),Wg=Object.freeze({role:"rowgroup"}),Kg=4096,Wi=new WeakMap,Ur=new Map,Yg=(e,t)=>{if(e===null)return Vg[t];let n=Wi.get(e);n===void 0&&(n={},Wi.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:fr(t)},s=JSON.stringify(o);let l=Ur.get(s);return l===void 0&&(Ur.size>=Kg&&Ur.clear(),l=Object.freeze(o),Ur.set(s,l)),n[t]=l,l},Ug=qs(),Xg=(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},Gg=(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=Qr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=Is(e,r===null?null:r.indexRef.current,r===null?Ug:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const R=ta(m,l),N=nn(n,s,1),H=nn(t,o,1),L=uf(m,N===null?void 0:e.getCellFormat(o,N),H===null?void 0:e.getCellFormat(H,s),n.offsetOf(s)===0,t.offsetOf(o)===0);L!==null&&Object.assign(c,L.attrs),c["data-aqsp-align"]=R,u=Yg(L,R)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Un(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&Cm(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Zg=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:R,headerRows:N,labelledBy:H,gridLabel:L,readOnly:_,renderCell:U,onScroll:W,onRangeChange:k,focusSink:x,isEditing:z,requestCommit:I,testId:T,__onCellRender:F,__maxRenderedCells:O,cfIndexRef:g,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:v,overscanRows:S,overscanCols:b,background:y,onRenderTruncated:a,locale:f,scrollLabels:E})=>{const d=i.useRef(null),$=s??d;if(g===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const A=i.useMemo(()=>g===void 0||p===void 0?null:{indexRef:g,memoRef:p},[g,p]),D=i.useCallback(()=>r.get().editVersion,[r]),q=i.useCallback(ue=>r.subscribeCoalesced(ue),[r]),K=i.useSyncExternalStore(q,D,D)+(l??0),G=i.useCallback(ue=>t.sizeOf(ue),[t]),J=i.useCallback(ue=>n.sizeOf(ue),[n]),te=i.useCallback((ue,Ne)=>e.getCellText(ue,Ne),[e]),le=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),me=i.useMemo(()=>({width:Te.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Ee=i.useRef({row:-1,col:-1,value:void 0}),xe=i.useCallback((ue,Ne)=>{const Ue=ue<N,je={role:Ue?"columnheader":"gridcell","aria-rowindex":ue+1,"aria-colindex":Ne+1,"data-aqsp-cell":"","data-row":ue,"data-col":Ne,className:"aqsp-cell",...Ye(e,ue,Ne)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Ue?{"data-aqsp-header-row":""}:{}},Ot=wh(e,ue,Ne),xt=Ot===null?je:{...je,...Ot},He=Gg(e,t,n,A,ue,Ne),wt=Ee.current;return wt.row=ue,wt.col=Ne,wt.value=He===null?void 0:He.value,He===null?xt:He.style===null?{...xt,...He.attrs}:{...xt,...He.attrs,style:He.style}},[e,t,n,A,N]),De=i.useCallback(ue=>({role:"row","aria-rowindex":ue+1,"data-aqsp-row":ue,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Pe=i.useCallback((ue,Ne,Ue)=>{let je=ue;return e.getCellFormat!==void 0&&(je=Wn(ue,Xg(Ee.current,Ne,Ue))),Y.jsx(Bg,{row:Ne,col:Ue,text:ue,display:je,renderCell:U,__onCellRender:F})},[K,U,F,e]);return Y.jsx("div",{ref:$,className:"aqsp-body","data-aqsp-body":"","data-testid":T?`${T}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":L,"aria-labelledby":H,"aria-readonly":_?"true":void 0,onPointerDownCapture:ue=>{if(!(ue.target instanceof Element&&ue.target.closest("[data-aqsp-cells]")!==null)&&ue.pointerType==="mouse"){if(ue.button!==0){ue.preventDefault();return}if(ue.preventDefault(),C?.()===!0){ue.stopPropagation(),x();return}if(z()&&!I()){ue.stopPropagation(),x();return}x()}},children:Y.jsx(Je.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:R,getRowHeight:G,getColWidth:J,getCell:te,getCellProps:xe,getRowProps:De,contentProps:Wg,behaviorOptions:le,scrollBarOptions:me,overscanRows:S,overscanCols:b,background:y,onRenderTruncated:a,__maxRenderedCells:O,locale:f,labels:E,callbackThrottleMs:0,onScroll:W,onRangeChange:k,testId:T,children:Pe})})},Jg=i.memo(Zg),In=6,rt=3,lo=(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:rt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=nn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-In,length:rt}),r.push({kind:"unhide",index:s+1,start:c-rt,length:rt})):l>=2*In?n.push({kind:"resize",index:s,start:c-In,length:In}):n.push({kind:"resize",index:s,start:c-rt,length:rt})}return[...n,...r]},Ka=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:rt}),n.push({kind:"resize",index:c,start:h+rt,length:rt})):u>=2*In?n.push({kind:"resize",index:c,start:h,length:In}):n.push({kind:"resize",index:c,start:h,length:rt})}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-rt,length:rt}),[...n.reverse(),...r]},Qg=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const H=Je.useWheelBridge(o),L=i.useCallback(d=>(s.current=d,H(d)),[s,H]),_=i.useCallback(()=>{const{colStart:d,colEnd:$,colVersion:A}=e.get();return`${d}:${$}:${A}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,_,_);const{colStart:W,colEnd:k}=e.get(),x=t.count===0?0:t.offsetOf(Math.min(W,t.count-1));i.useLayoutEffect(()=>{c.current=x,u()},[x,c,u]);const z=d=>h.some($=>d>=$.startCol&&d<=$.endCol),I=Math.min(Math.max(0,n),t.count),T=ya(t,I),F=I>0?Bn(t,0,I-1):[],O=Math.min(Math.max(0,r),t.count-I),g=va(t,O),p=t.totalSize()-g,C=O>0?Bn(t,t.count-O,t.count-1):[],v=Bn(t,Math.max(W,I),Math.min(k,Math.max(0,t.count-1)-O)),S=[];for(const d of v)S.push(Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-x,width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d));const b=m?lo(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&g>0)),a=m&&I>0?lo(t,F):null,f=m&&O>0?Ka(t,C):null,E=Y.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[S,y?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-x,width:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-x,width:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:L,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:I===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[F.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),Y.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:T,right:O>0?`calc(${Te.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${Te.SPREADSHEET_SCROLLBAR_SIZE_PX+T}px)))`:void 0},children:[E,I>0?Y.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,O>0?Y.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),O>0?Y.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${T}px, calc(100% - ${g+Te.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:Y.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[C.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},ew=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const H=Je.useWheelBridge(n),L=i.useCallback(d=>(r.current=d,H(d)),[r,H]),_=d=>o.some($=>d>=$.startRow&&d<=$.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:$,rowGeomVersion:A}=e.get();return`${d}:${$}:${A}`},[e]),W=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(W,U,U);const{rowStart:k,rowEnd:x}=e.get(),z=t.count===0?0:t.offsetOf(Math.min(k,t.count-1));i.useLayoutEffect(()=>{l.current=z,c()},[z,l,c]);const I=Math.min(Math.max(0,h),t.count),T=Ra(t,I),F=I>0?Bn(t,0,I-1):[],O=Math.min(Math.max(0,m),t.count-I),g=Sa(t,O),p=t.totalSize()-g,C=O>0?Bn(t,t.count-O,t.count-1):[],v=Bn(t,Math.max(k,I),Math.min(x,Math.max(0,t.count-1)-O)),S=[];for(const d of v)S.push(Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-z,height:t.sizeOf(d)},children:d+1},d));const b=u?lo(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&g>0)),a=u&&I>0?lo(t,F):null,f=u&&O>0?Ka(t,C):null,E=Y.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[S,y?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-z,height:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-z,height:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:L,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[F.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),Y.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:T,bottom:O>0?`calc(min(${g}px, max(0px, 100% - ${T}px)))`:void 0},children:[E,I>0?Y.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,O>0?Y.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),O>0?Y.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${T}px, calc(100% - ${g}px))`},children:Y.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[C.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},tw=9,nw=4,Ki=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},Yi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,rw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),R=i.useCallback(g=>s.current!==null?g.pointerId===s.current:g.pointerType==="mouse",[]),N=i.useCallback(()=>{const g=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),g.writeResizeGuide(null);const p=m.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),m.current=null);const C=c.current;C!==null&&s.current!==null&&C.hasPointerCapture?.(s.current)&&C.releasePointerCapture(s.current),c.current=null,s.current=null,g.repaintOverlay()},[]),H=i.useCallback((g,p)=>{const C=t.current;return g==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),L=i.useCallback((g,p)=>{const C=t.current,v=C.getSelection().ranges.filter(f=>H(g,f));if(!v.some(f=>g==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const b=v.reduce((f,E)=>f+(g==="col"?E.endCol-E.startCol+1:E.endRow-E.startRow+1),0),y=g==="row"?Math.floor(C.maxOperationCells/Rs):C.maxOperationCells;if(b>y)return C.onOperationRejected?.("resize",b,"limit"),null;const a=new Set;for(const f of v){const E=g==="col"?f.startCol:f.startRow,d=g==="col"?f.endCol:f.endRow;for(let $=E;$<=d;$+=1)a.add($)}return[...a]},[H]),_=i.useCallback((g,p,C)=>{const v=t.current,S=g==="col"?v.colAxis:v.rowAxis,b=vs(S,p,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:ys,axisKind:g});return b.ok?(v.resizeTracks(g,b.entries),!0):(v.onOperationRejected?.("resize",b.count,b.reason),!1)},[]),U=i.useCallback((g,p)=>{if(p===g.initialSize)return;const C=g.kind==="unhide"?[g.index]:L(g.axis,g.index);C!==null&&_(g.axis,C.map(v=>({index:v,size:p})),g.index)},[L,_]),W=i.useCallback((g,p,C,v)=>{const S=t.current,b=S.fontSourceRef.current;if(b===null)return!1;if(p.length===0)return!0;const y=g.length*p.length;if(y>C)return S.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(b),E=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),$={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},A=`${$.fontStyle} ${$.fontWeight} ${$.fontSize} ${$.fontFamily}`,D=S.adapter.getConditionalFormats===void 0?null:jg(S.adapter.getConditionalFormats()),q=qs(),j=new WeakMap,K=new WeakMap,G=new Map;for(const me of g){const Ee=D===null?null:Ba(D.filter(xe=>xe.ranges.some(De=>me>=De.startCol&&me<=De.endCol)));for(const xe of p){const De=S.adapter.getCellText(xe,me),Pe=S.adapter.getCellFormat===void 0?void 0:Is(S.adapter,Ee,q,xe,me,()=>De),ue=xe<S.headerRows,Ne=Pe===void 0?ue?A:E:ue?Ki(Pe,K,$):Ki(Pe,j,f),Ue=Wn(De,Pe===void 0?void 0:Pe.value),je=G.get(Ne);je===void 0?G.set(Ne,[{col:me,text:Ue}]):je.push({col:me,text:Ue})}}const J=b.ownerDocument.createElement("span");J.setAttribute("aria-hidden","true"),J.style.position="absolute",J.style.visibility="hidden",b.append(J);const te=new Map;for(const[me,Ee]of G){a.font=me,J.style.font=me;const xe=getComputedStyle(J);a.letterSpacing=xe.letterSpacing==="normal"?"0px":xe.letterSpacing,a.wordSpacing=xe.wordSpacing==="normal"?"0px":xe.wordSpacing;for(const De of Ee){const Pe=a.measureText(De.text).width,ue=te.get(De.col);(ue===void 0||Pe>ue)&&te.set(De.col,Pe)}}J.remove();const le=[];for(const me of g){const Ee=te.get(me);Ee!==void 0&&Ee>0&&le.push({index:me,size:Math.ceil(Ee)+tw})}return le.length===0?!0:_("col",le,v)},[_]),k=i.useCallback(g=>{const p=t.current,C=L("col",g);if(C===null)return!1;const v=p.handleRef.current,S=v===null?null:v.getFrozenSize(),b=S===null?0:S.rows,y=S===null?0:S.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),E=Math.min(f,p.rowAxis.count-1),d=[],$=new Set,A=D=>{!$.has(D)&&p.rowAxis.sizeOf(D)>0&&($.add(D),d.push(D))};for(let D=0;D<b;D+=1)A(D);for(let D=a;D<=E;D+=1)A(D);for(let D=p.rowAxis.count-y;D<p.rowAxis.count;D+=1)A(D);return W(C,d,Math.floor(p.maxOperationCells/nw),g)},[L,W]),x=i.useCallback((g,p,C)=>{const v=g==="col"?t.current.colAxis:t.current.rowAxis,S=Nu(v.sizeOf(p),C);if(S===v.sizeOf(p))return!0;const b=L(g,p);return b===null?!1:_(g,b.map(y=>({index:y,size:S})),p)},[L,_]),z=i.useCallback(g=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(g)===0?!0:k(g):!1},[k]),I=i.useCallback(g=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(g)].filter(S=>p.colAxis.sizeOf(S)>0);if(C.length===0)return!0;const v=[];for(let S=0;S<p.rowAxis.count;S+=1)p.rowAxis.sizeOf(S)>0&&v.push(S);return W(C,v,p.maxOperationCells,null)},[W]),{enabled:T,colBandRef:F,rowBandRef:O}=e;return i.useEffect(()=>{const g=F.current,p=O.current;if(!T||g===null||p===null)return;const C=j=>j==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(j,K)=>{if(!(K instanceof Element))return null;const G=K.closest(C(j));if(G===null)return null;const J=G.hasAttribute("data-aqsp-unhide"),te=Number(G.getAttribute(J?"data-aqsp-unhide":j==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),le=G.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:J?"unhide":"resize",index:te,anchor:le}},S=j=>{if(!(n.current&&R(j)))return;const K=r.current;if(K===null)return;const G=(K.axis==="col"?j.clientX-K.startClientX:j.clientY-K.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(K.anchor==="trailing"?K.initialSize-G:K.initialSize+G)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const J=r.current;if(!n.current||J===null)return;const te=t.current,le=J.axis==="col"?te.colAxis:te.rowAxis;te.writeResizeGuide({axis:J.axis,position:Yi(J,le,o.current),anchor:J.anchor})}))},b=()=>{const j=r.current,K=o.current;N(),j!==null&&U(j,K)},y=j=>{S(j),n.current&&R(j)&&(l.current&1)!==0&&(j.buttons&1)===0&&b()},a=j=>{j.button!==0||!(n.current&&R(j))||b()},f=(j,K)=>G=>{const J=t.current;if(h.current=G.pointerType,G.pointerType!=="mouse")return;if(G.button!==0){G.preventDefault();return}const te=v(j,G.target);if(te===null)return;if(G.stopPropagation(),G.preventDefault(),J.isPointing()){J.focusSink();return}if(J.isEditing()&&!J.requestCommit()){J.focusSink();return}J.focusSink();const le=j==="col"?J.colAxis:J.rowAxis,me={axis:j,kind:te.kind,index:te.index,anchor:te.anchor,initialSize:le.sizeOf(te.index),startClientX:G.clientX,startClientY:G.clientY};r.current=me,o.current=me.initialSize,l.current=G.buttons,n.current=!0,J.repaintOverlay(),s.current=G.pointerId,c.current=K;try{K.setPointerCapture(G.pointerId)}catch{s.current=null}const Ee=y,xe=a;m.current={move:Ee,up:xe},window.addEventListener("pointermove",Ee),window.addEventListener("pointerup",xe),J.writeResizeGuide({axis:j,position:Yi(me,le,o.current),anchor:me.anchor})},E=(j,K)=>G=>{const J=t.current;if(h.current!=="mouse")return;const te=K.getRootNode(),le=te instanceof ShadowRoot?te:K.ownerDocument,me=G.target instanceof Element&&G.target.closest(C(j))!==null?G.target:typeof le.elementFromPoint=="function"?le.elementFromPoint(G.clientX,G.clientY):null,Ee=v(j,me);if(Ee!==null){if(G.stopPropagation(),J.isEditing()){J.focusSink();return}if(Ee.kind==="unhide"){_(j,[{index:Ee.index,size:j==="col"?J.defaultColumnWidth:J.defaultRowHeight}],null);return}if(J.autofitEnabled){if(j==="row"){const xe=L("row",Ee.index);xe!==null&&_("row",xe.map(De=>({index:De,size:J.defaultRowHeight})),Ee.index);return}k(Ee.index)}}},d=j=>{!n.current||s.current===null||j.pointerId!==s.current||N()},$=f("col",g),A=f("row",p),D=E("col",g),q=E("row",p);return g.addEventListener("pointerdown",$,{capture:!0}),p.addEventListener("pointerdown",A,{capture:!0}),g.addEventListener("dblclick",D),p.addEventListener("dblclick",q),g.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{g.removeEventListener("pointerdown",$,{capture:!0}),p.removeEventListener("pointerdown",A,{capture:!0}),g.removeEventListener("dblclick",D),p.removeEventListener("dblclick",q),g.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),N()}},[T,F,O,R,N,U,_,L,k]),i.useMemo(()=>({stepTrack:x,autofitColumn:z,autofitColumnsInAllRows:I,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,x,z,I])},js=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,ow=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>js(n,t.ranges[r]))&&It(e.anchor,t.anchor)&&It(e.active,t.active),sw=(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=>ln(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:Re(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)}},lw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return js(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Cr=(e,t,n)=>n.extend?hn(e,t):n.append?{ranges:[...e.ranges,Re(t,t)],anchor:t,active:t}:e.ranges.length===1&&It(e.anchor,t)&&It(e.active,t)&&js(e.ranges[0],Re(t,t))?e:{ranges:[Re(t,t)],anchor:t,active:t},iw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),hn=(e,t)=>{const n=lw(e,Re(e.anchor,t));return n.ranges.some(r=>Cn(r,n.active))?n:{...n,active:iw(n.active,n.ranges[n.ranges.length-1])}},Ya=(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(Re({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Re({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Re({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Re({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Re(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Cn(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}},cw=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Ua=(e,t)=>{const n=e.ranges.findIndex(o=>Cn(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=cw(e.ranges,r.rangeIndex,r.cell,t),!It(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Ft=24,Ui=32,io=4,zn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),R=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),N=i.useCallback(()=>{const L=u.current,_=e.current,U=m.current;if(L===null||_===null||U===null){c.current=null;return}const{clientX:W,clientY:k}=L.getPointerPosition(),x=l.current,z=(W-U.left)/x,I=(k-U.top)/x,T=_.getViewportSize(),F=T.width,O=T.height;if(F<=0||O<=0){c.current=requestAnimationFrame(N);return}const g=y=>Math.min(Ui,Math.ceil(y/Ft*Ui));let p=0,C=0;if(s!=="x"){const y=_.getFrozenSize(),a=y.trailingVisibleHeight;I>O-a-Ft?L.anchorRow!==void 0&&y.trailingRows>0&&L.anchorRow>=t.count-y.trailingRows&&a>0&&I>=O-a||(p=g(I-(O-a-Ft))):I<y.height+Ft&&(L.anchorRow!==void 0&&L.anchorRow<y.rows&&y.height>0&&I<y.height||(p=-g(y.height+Ft-I)))}if(s!=="y"){const y=_.getFrozenSize(),a=y.trailingVisibleWidth;z>F-a-Ft?L.anchorCol!==void 0&&y.trailingCols>0&&L.anchorCol>=n.count-y.trailingCols&&a>0&&z>=F-a||(C=g(z-(F-a-Ft))):z<y.width+Ft&&(L.anchorCol!==void 0&&L.anchorCol<y.cols&&y.width>0&&z<y.width||(C=-g(y.width+Ft-z)))}const v=C!==0||p!==0?_.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):_.getScrollPosition(),S=v.y,b=v.x;if(S>=0&&b>=0&&t.totalSize()>0&&n.totalSize()>0){const y=_.getFrozenSize(),a=ln({row:kr(t,I,{scroll:S,frozenSize:y.height,trailingSize:y.trailingHeight,extent:T.height}),col:Sr(n,z,{scroll:b,frozenSize:y.width,trailingSize:y.trailingWidth,extent:T.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(L.buildRange(a)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),H=i.useCallback(L=>{R(),u.current=L,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[R,N,r]);return i.useEffect(()=>{const L=()=>{document.visibilityState==="hidden"&&R()};return document.addEventListener("visibilitychange",L),()=>{document.removeEventListener("visibilitychange",L),R()}},[R]),i.useMemo(()=>({start:H,stop:R}),[H,R])},Xi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(!1),N=i.useRef(0),H=i.useCallback((T,F)=>{const{axis:O,mainAxis:g,handleRef:p,zoomRef:C}=t.current,v=s.current;if(v===null||g.totalSize()===0)return null;const S=C.current,b=p.current;if(b===null)return null;if(O==="col"){const E=b.getScrollPosition().x;if(E<0)return null;const d=b.getFrozenSize(),$=b.getViewportSize();return Math.min(Math.max(Sr(g,(T-v.left)/S,{scroll:E,frozenSize:d.width,trailingSize:d.trailingWidth,extent:$.width}),0),g.count-1)}const y=b.getScrollPosition().y;if(y<0)return null;const a=b.getFrozenSize(),f=b.getViewportSize();return Math.min(Math.max(kr(g,(F-v.top)/S,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),L=i.useCallback((T,F)=>{const{axis:O,crossCount:g}=t.current;return O==="col"?{press:{row:0,col:T},extend:{row:g-1,col:F}}:{press:{row:T,col:0},extend:{row:F,col:g-1}}},[]),_=i.useCallback((T,F)=>{const{axis:O,crossCount:g}=t.current;return T.ranges.some(p=>O==="col"?p.startRow===0&&p.endRow===g-1&&F>=p.startCol&&F<=p.endCol:p.startCol===0&&p.endCol===g-1&&F>=p.startRow&&F<=p.endRow)},[]),U=i.useRef(!1),W=i.useRef({clientX:0,clientY:0}),k=i.useCallback(()=>{U.current=!1;const{autoScroller:T,headerRef:F,onDragFrame:O}=t.current;n.current=!1,r.current=null,m.current=null,R.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const g=F.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,O(null),t.current.repaintOverlay()},[]),x=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.setSelection(T),k()},[k]),{enabled:z,headerRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const F=b=>{const y=t.current;if(b.pointerType!=="mouse")return;if(b.button!==0){b.preventDefault();return}if(R.current=!1,y.pointing?.getPointing()){s.current=T.getBoundingClientRect();const d=H(b.clientX,b.clientY);if(d===null)return;b.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){b.preventDefault(),y.focusSink();return}s.current=T.getBoundingClientRect();const a=H(b.clientX,b.clientY);if(a===null)return;b.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const E=b.ctrlKey||b.metaKey;if(b.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:$}=L(a,a),A={...f,anchor:d};y.setSelection(hn(A,$)),o.current=y.axis==="col"?d.col:d.row}else if(E&&_(f,a))R.current=!0,N.current=a,o.current=a;else{const{press:d,extend:$}=L(a,a),A=Cr(f,d,{extend:!1,append:E});y.setSelection(hn(A,$)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:b.clientX,clientY:b.clientY},u.current=b.pointerId,h.current=b.buttons;try{T.setPointerCapture(b.pointerId)}catch{u.current=null}m.current=d=>{const $=t.current.axis==="col"?d.col:d.row,{press:A}=L(o.current,o.current),{extend:D}=L(o.current,$);return Re(A,D)},y.autoScroller.stop(),U.current=!1,W.current={clientX:b.clientX,clientY:b.clientY}},O=b=>u.current!==null?b.pointerId===u.current:b.pointerType==="mouse",g=b=>{if(n.current&&O(b)){if(R.current){const y=b.clientX!==l.current.clientX||b.clientY!==l.current.clientY;if(l.current={clientX:b.clientX,clientY:b.clientY},!y)return;const a=H(b.clientX,b.clientY);if(a===null||a===N.current)return;R.current=!1;const f=t.current,{press:E,extend:d}=L(N.current,N.current),$=Cr(f.getSelection(),E,{extend:!1,append:!0});f.setSelection(hn($,d));const A=m.current,D=Math.abs(b.clientX-W.current.clientX),q=Math.abs(b.clientY-W.current.clientY);A!==null&&Math.max(D,q)>=io&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:A,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:b.clientX,clientY:b.clientY},!U.current&&m.current!==null){const y=Math.abs(b.clientX-W.current.clientX),a=Math.abs(b.clientY-W.current.clientY);Math.max(y,a)>=io&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=m.current;if(!n.current||y===null)return;const a=H(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=b=>{g(b),n.current&&O(b)&&(h.current&1)!==0&&(b.buttons&1)===0&&v(b)},C=b=>{b.button!==0||!(n.current&&O(b))||v(b)},v=b=>{const y=t.current;if(R.current){const{press:f,extend:E}=L(N.current,N.current);y.setSelection(Ya(y.getSelection(),Re(f,E),f)),k();return}const a=H(b.clientX,b.clientY);if(a!==null){const{extend:f}=L(o.current,a);y.setSelection(hn(y.getSelection(),f))}k()},S=b=>{!n.current||u.current===null||b.pointerId!==u.current||x()};return T.addEventListener("pointerdown",F),T.addEventListener("pointermove",p),T.addEventListener("pointerup",C),T.addEventListener("lostpointercapture",S),()=>{T.removeEventListener("pointerdown",F),T.removeEventListener("pointermove",p),T.removeEventListener("pointerup",C),T.removeEventListener("lostpointercapture",S),k()}},[z,I,H,L,k,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:x,cancelDrag:k}),[x,k])},aw=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),R=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):R>l+u-h.trailingVisibleHeight&&o.scrollBy({y:R-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),R=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):R>s+c-h.trailingVisibleWidth&&o.scrollBy({x:R-(s+c-h.trailingVisibleWidth)})}},uw=50,dw=100,Xa=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<uw:!1,ir={selectAll:Qt("Ctrl+A"),undo:Qt("Ctrl+Z"),redo:Qt("Ctrl+Y"),redoShiftZ:Qt("Ctrl+Shift+Z"),pasteValues:Qt("Ctrl+Shift+V")},fw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),pw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},hw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",mw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,R=u.current;if(!l||m===null||R===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},H=(a,f,E)=>nn(a,f,E)??f,L=(a,f)=>{const E=s.current;return f==="left"||f==="right"?{row:a.row,col:H(E.colAxis,a.col,f==="right"?1:-1)}:{row:H(E.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),W=(a,f,E,d)=>{if(a.sizeOf(f)>0)return f;const $=nn(a,f,E);if($!==null)return $;const A=nn(a,f,E===1?-1:1);return A!==null?A:d},k=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},x=a=>L(k(),a),z=(a,f)=>{const E=s.current,d=f==="left"||f==="right",$=f==="right"||f==="down"?1:-1;let A;return E.findDataEdge!==void 0?(A=E.findDataEdge({row:a.row,col:a.col},f),I(A,a,f)):A={row:f==="down"?E.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?E.colAxis.count-1:f==="left"?0:a.col},d?{row:A.row,col:W(E.colAxis,A.col,$,a.col)}:{row:W(E.rowAxis,A.row,$,a.row),col:A.col}},I=(a,f,E)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const $=E==="left"||E==="right";if($?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${$?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},T=(a,f,E)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${E} component ${a} (count ${f})`)},F=a=>{const f=s.current,E=f.getSelection();if(Ua(E,a)===E){f.moveActive({mode:"reset",cell:L(E.active,a)});return}f.moveActive({mode:"cycle",direction:a})},O=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,E=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
14
+ ${a.value.slice(E)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const E=s.current,d=E.pageExtent();if(d<=0)return H(E.rowAxis,a,f==="down"?1:-1);const $=E.rowAxis.indexAt(E.rowAxis.offsetOf(a)+(f==="down"?d:-d));return $===a?H(E.rowAxis,a,f==="down"?1:-1):$},p=a=>{const f=s.current;if(r.current=!1,Xa(a,t.current))return;const E=a.ctrlKey||a.metaKey,d=a.altKey,$=pw[a.key];if(o.current&&!fw.has(a.key)&&!f.isDragging()&&N(),f.isEditing()){const D=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!E&&!a.shiftKey&&!d&&f.abortDrag();return}const q=f.pointing;if(q!==void 0){if($!==void 0&&!d){const K=q.getReferenceCursor();if(K!==null){a.preventDefault();const G=ln(K.cursor,f.rowAxis.count,f.colAxis.count),J=ln(K.origin,f.rowAxis.count,f.colAxis.count),te=E?z(G,$):L(G,$);if(f.ensureCellVisible(te),q.insertReference(a.shiftKey?Re(J,te):te,K.axis),f.onPointFrame!==void 0){const le=a.shiftKey?Re(J,te):Re(te,te);f.onPointFrame(K.axis==="columns"?Re({row:0,col:le.startCol},{row:f.rowAxis.count-1,col:le.endCol}):K.axis==="rows"?Re({row:le.startRow,col:0},{row:le.endRow,col:f.colAxis.count-1}):le),o.current=!0}return}}if(a.key==="F2"&&!E&&!a.shiftKey&&!d&&q.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!E&&!a.shiftKey&&!d&&q.cycleAnchorAtCaret()){a.preventDefault();return}}const j=f.commands;if(j!==void 0){const K=ai(j.table,a);if(K!==null&&Ps.has(K)&&j.isAvailable(K)){a.preventDefault(),j.execute(K);return}}if($!==void 0&&!d){if(E&&a.shiftKey){a.preventDefault();return}if(E)return;if(D==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:x($)}):f.moveActive({mode:"reset",cell:L(f.getSelection().active,$)});return}return}if(a.key==="Enter"&&d&&!E&&!a.shiftKey){a.preventDefault(),O();return}if((a.key==="Enter"||a.key==="Tab")&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const K=!a.shiftKey;F(a.key==="Tab"?K?"right":"left":K?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const K=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(K.row,a.key==="PageDown"?"down":"up"),col:K.col}});return}if(a.key==="Escape"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const A=f.commands;if(A!==void 0){const D=ai(A.table,a);if(D!==null&&A.isAvailable(D)){a.preventDefault(),A.execute(D);return}}if($!==void 0&&!d){const D=$==="left"||$==="right",q=$==="right"||$==="down"?1:-1;if(E&&a.shiftKey){a.preventDefault();const j=f.getSelection(),K=k();let G;if(f.findDataEdge!==void 0){const J=D?{row:j.active.row,col:K.col}:{row:K.row,col:j.active.col},te=f.findDataEdge(J,$);G=D?te.col:te.row,T(G,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),G=W(D?f.colAxis:f.rowAxis,G,q,D?K.col:K.row)}else{const J=D?f.colAxis:f.rowAxis;G=q===1?U(J):_(J)}f.moveActive({mode:"extend",cell:D?{row:K.row,col:G}:{row:G,col:K.col}});return}if(E){a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,$)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:x($)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:L(f.getSelection().active,$)});return}if(hw(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!E&&!d){a.preventDefault();const D=!a.shiftKey;F(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const q=k();f.moveActive({mode:"extend",cell:{row:E?_(f.rowAxis):q.row,col:_(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?_(f.rowAxis):D.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const q=k();f.moveActive({mode:"extend",cell:{row:E?U(f.rowAxis):q.row,col:U(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?U(f.rowAxis):D.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!E&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const j=k();f.moveActive({mode:"extend",cell:{row:g(j.row,D),col:j.col}});return}const q=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(q.row,D),col:q.col}});return}if(a.key==="F2"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection(),q=At(D.ranges);if(q>f.maxOperationCells){f.onOperationRejected?.("delete",q,"limit");return}if(f.adapter!==void 0&&qn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:q});return}const j=[],K=f.adapter!==void 0&&eo(f.adapter).hyperlink;Jt(D.ranges,G=>{j.push(K?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),f.commitEdits(j,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(E||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(or(ir.selectAll,a)){a.preventDefault();const D=f.getSelection(),q=Re({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[q],anchor:D.anchor,active:D.active});return}if(or(ir.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(or(ir.redo,a)||or(ir.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!E&&!d||a.key==="ContextMenu"&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection().active;f.ensureCellVisible(D);const q=h.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),K=Math.max(0,j.y),G=Math.max(0,j.x),J=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),te=q===null?{width:0,height:0}:q.getViewportSize(),le=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:wn(f.rowAxis,D.row,{scroll:K,frozenCount:J.rows,trailingCount:J.trailingRows,extent:te.height})*le,left:gn(f.colAxis,D.col,{scroll:G,frozenCount:J.cols,trailingCount:J.trailingCols,extent:te.width})*le,width:f.colAxis.sizeOf(D.col)*le,height:f.rowAxis.sizeOf(D.row)*le}});return}if(a.key===" "&&!d&&E!==a.shiftKey){a.preventDefault();const D=f.getSelection(),q=D.ranges.map(j=>E?Re({row:0,col:j.startCol},{row:f.rowAxis.count-1,col:j.endCol}):Re({row:j.startRow,col:0},{row:j.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:q,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&or(ir.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},v=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},dw)},S=()=>{const a=s.current;if(N(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},b=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),N()};return m.addEventListener("keydown",p),m.addEventListener("keyup",b),m.addEventListener("blur",y),m.addEventListener("compositionstart",C),m.addEventListener("compositionend",v),m.addEventListener("input",S),()=>{m.removeEventListener("keydown",p),m.removeEventListener("keyup",b),m.removeEventListener("blur",y),m.removeEventListener("compositionstart",C),m.removeEventListener("compositionend",v),m.removeEventListener("input",S),n.current!==null&&window.clearTimeout(n.current),N()}},[l,c,u,h])},gw=()=>{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)})}},ww=4,Cw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),bw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),R=i.useRef(0),N=i.useRef(null),H=i.useRef(null),L=i.useRef(!1),_=i.useCallback(T=>m.current!==null?T.pointerId===m.current:T.pointerType==="mouse",[]),U=i.useCallback((T,F)=>{const{handleRef:O,rowAxis:g,colAxis:p}=t.current,C=O.current,v=s.current;if(C===null||v===null)return null;const{x:S,y:b}=C.getScrollPosition();if(b<0||S<0||g.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return ln({row:kr(g,(F-v.top)/y,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Sr(p,(T-v.left)/y,{scroll:S,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,p.count)},[]),W=i.useCallback(T=>{const F=r.current;if(F===null)return Re(T,T);const O=Re({row:Math.min(F.startRow,T.row),col:Math.min(F.startCol,T.col)},{row:Math.max(F.endRow,T.row),col:Math.max(F.endCol,T.col)}),g=O.startRow!==F.startRow||O.endRow!==F.endRow||O.startCol!==F.startCol||O.endCol!==F.endCol;return o.current=g?O:null,g?O:F},[]),k=i.useCallback(()=>{const T=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),T.xAutoScroller.stop(),T.yAutoScroller.stop(),L.current=!1,u.current=!1,h.current={dx:0,dy:0},T.writeFillPreview(null);const F=H.current;F!==null&&(window.removeEventListener("pointermove",F.move),window.removeEventListener("pointerup",F.up),H.current=null);const O=t.current.handleNodeRef.current;O!==null&&m.current!==null&&O.hasPointerCapture?.(m.current)&&O.releasePointerCapture(m.current),m.current=null,T.repaintOverlay()},[]),x=i.useCallback(()=>{const T=t.current,F=r.current,O=o.current;if(k(),F===null||O===null)return;const g=yh(F,O);if(g>T.maxOperationCells){T.onOperationRejected?.("fill",g,"limit");return}if(qn(T.adapter,Rh(F,O))){const v=(O.endRow-O.startRow+1)*(O.endCol-O.startCol+1),S=(F.endRow-F.startRow+1)*(F.endCol-F.startCol+1);T.rejectReadOnly({kind:"operation",op:"fill",cellCount:v-S});return}const p=vh((v,S)=>sa(T.adapter,v,S),F,O,la);if(T.commitEdits(p,{source:"fill"})===null)return;const C=T.getSelection();T.setSelection({ranges:[O],anchor:C.anchor,active:C.active})},[k]),{enabled:z,handleNodeRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const F=v=>{O(v),n.current&&_(v)&&(R.current&1)!==0&&(v.buttons&1)===0&&x()},O=v=>{if(!(n.current&&_(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const S=Math.abs(v.clientX-c.current.clientX),b=Math.abs(v.clientY-c.current.clientY);if(!u.current&&Math.max(S,b)>=ww&&(u.current=!0),!!u.current){if(!L.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:W,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),L.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&u.current))return;const y=U(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(W(y))}))}},g=v=>{v.button!==0||!(n.current&&_(v))||x()},p=v=>{const S=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),S.focusSink();const b=S.getSelection(),y=b.ranges[b.ranges.length-1];r.current=y,o.current=null,u.current=!1,S.xAutoScroller.stop(),S.yAutoScroller.stop(),L.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,R.current=v.buttons,n.current=!0,S.repaintOverlay(),s.current=S.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=S.handleRef.current?.getScrollPosition()??{x:-1,y:-1},E=f.y;if(a!==null&&E>=0&&f.x>=0){const A=f.x,D=S.zoomRef.current,q=S.handleRef.current?.getFrozenSize()??Cw,j=S.handleRef.current?.getViewportSize()??{width:0,height:0},K={scroll:A,frozenCount:q.cols,trailingCount:q.trailingCols,extent:j.width},G={scroll:E,frozenCount:q.rows,trailingCount:q.trailingRows,extent:j.height},J=gn(S.colAxis,y.endCol,K)+S.colAxis.sizeOf(y.endCol),te=wn(S.rowAxis,y.endRow,G)+S.rowAxis.sizeOf(y.endRow),le=J-1,me=y.endCol>=q.cols&&q.width>0?Math.max(le,q.width):le,xe=!(y.endCol>=S.colAxis.count-q.trailingCols)&&q.trailingWidth>0?Math.min(me,j.width-q.trailingVisibleWidth-1):me,De=te-1,Pe=y.endRow>=q.rows&&q.height>0?Math.max(De,q.height):De,Ne=!(y.endRow>=S.rowAxis.count-q.trailingRows)&&q.trailingHeight>0?Math.min(Pe,j.height-q.trailingVisibleHeight-1):Pe;h.current={dx:v.clientX-(a.left+xe*D),dy:v.clientY-(a.top+Ne*D)}}else h.current={dx:0,dy:0};m.current=v.pointerId;try{T.setPointerCapture(v.pointerId)}catch{m.current=null}const d=F,$=g;H.current={move:d,up:$},window.addEventListener("pointermove",d),window.addEventListener("pointerup",$),S.writeFillPreview(r.current)},C=v=>{!n.current||m.current===null||v.pointerId!==m.current||k()};return T.addEventListener("pointerdown",p),T.addEventListener("lostpointercapture",C),()=>{T.removeEventListener("pointerdown",p),T.removeEventListener("lostpointercapture",C),k()}},[z,I,_,U,W,k,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&k()},cancelDrag:k}),[k])},yw=320,to=8,Rw=64,vw=150,Ga=e=>Math.max(0,Math.min(yw,e.width-Te.SPREADSHEET_SCROLLBAR_SIZE_PX-to)),Sw=(e,t,n)=>{const r=n.width-Te.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Te.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Ga(n),l=Math.max(0,Math.min(t,o-to)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+s<=r,m=[e.left,c-s],R=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of R)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const N=o-u,H=e.top,L=Math.min(l,Math.max(N,H));if(L>=Rw){const _=N>=H?u:e.top-L;for(const U of m)if(h(U))return{left:U,top:_,width:s,height:L}}return{left:to,top:to,width:s,height:l}},kw=(e,t,n,r)=>t===null||e!==null&&It(e,t)||n?!1:r(t),Ew=(e,t)=>{switch(e.kind){case"note":return Y.jsx($a,{ctx:e,labels:t});case"note-tip":return Y.jsx(La,{ctx:e,labels:t});case"comment":return Y.jsx(Aa,{ctx:e,labels:t});case"link":return Y.jsx(Oa,{ctx:e,labels:t});case"list":return Y.jsx(xa,{ctx:e,labels:t});default:return Y.jsx(Ta,{ctx:e,labels:t})}},ns=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Aw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const R=ns(s),N=ns(l),H=i.useRef(null),L=(x,z)=>{const I=m.current.getLayerSize();x.style.width=`${Ga(I)}px`,x.style.maxHeight="";const T=Sw(z,x.offsetHeight,I);x.style.left=`${T.left-z.left}px`,x.style.top=`${T.top-z.top}px`,x.style.maxHeight=`${T.height}px`};i.useLayoutEffect(()=>{const x=c.current;if(x===null||s===null){H.current=null;return}if(L(x,s.anchorRect),s.kind==="message")return;const z=ns(s);if(H.current===z)return;H.current=z;const I=x.querySelector("[data-aqsp-popover-autofocus]");I!==null?I.focus({preventScroll:!0}):x.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const x=u.current,z=h.current;x===null||z===null||L(x,z.anchorRect)},[N]);const _=x=>t===void 0?Ew(x,n):t(x),U=x=>{e.isCompositionKey(x.nativeEvent)&&x.stopPropagation()},W=x=>{x.key==="Escape"&&!x.defaultPrevented&&(x.preventDefault(),e.close())},k=x=>{e.registerCompositionEnd(x.timeStamp)};return Y.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:W,onCompositionEnd:k,children:[Y.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:Y.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},R)}),Y.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:Y.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:_(l)})})]})},Ow=["note","note-tip","comment","link","list","message"],xw=(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}},cr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&xw(e,n),Tw=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),R=i.useRef(null),N=i.useRef(null),H=i.useRef(null),L=i.useId(),_=i.useCallback(A=>{const D=t.current,q=D.handleRef.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),K=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),G=q===null?{width:0,height:0}:q.getViewportSize();return{top:wn(D.rowAxis,A.row,{scroll:Math.max(0,j.y),frozenCount:K.rows,trailingCount:K.trailingRows,extent:G.height}),left:gn(D.colAxis,A.col,{scroll:Math.max(0,j.x),frozenCount:K.cols,trailingCount:K.trailingCols,extent:G.width}),width:D.colAxis.sizeOf(A.col),height:D.rowAxis.sizeOf(A.row)}},[]),U=i.useCallback(A=>{const D=t.current;D.anchors.current={...D.anchors.current,...A},D.repaintOverlay()},[]),W=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),k=i.useCallback(()=>{const A=t.current.sinkRef.current;if(A===null)return;const D=c.current;D!==null&&It(D,t.current.getActive())?A.setAttribute("aria-describedby",L):A.getAttribute("aria-describedby")===L&&A.removeAttribute("aria-describedby")},[L]),x=i.useCallback(()=>(W(),h.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),k(),!0)),[W,U,k]),z=i.useCallback(()=>{W(),m.current=window.setTimeout(()=>{m.current=null,x()},vw)},[W,x]),I=i.useCallback(A=>{const D=t.current;W();const q=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(A.row,A.col);q===void 0||q===""||(c.current=A,s({kind:"note-tip",cell:A,anchorRect:_(A),current:q,close:x}),U({tip:A}),k())},[_,W,x,U,k]),T=i.useCallback(A=>{const D=t.current;if(A===null&&h.current)return;const q=u.current;u.current=A;const j=c.current;if(j!==null&&A!==null&&It(j,A)){W();return}const K=G=>{const J=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(G.row,G.col);return J!==void 0&&J!==""};if(kw(q,A,D.isDraggingAny(),K)){A!==null&&I(A);return}j!==null&&z()},[I,W,z]),F=i.useCallback((A,D)=>{const q=t.current,j=q.bodyRef.current,K=q.handleRef.current;if(j===null||K===null)return null;const G=j.getBoundingClientRect(),J=q.zoomRef.current,te=K.getScrollPosition(),le=K.getFrozenSize(),me=K.getViewportSize();return ln({row:kr(q.rowAxis,(D-G.top)/J,{scroll:Math.max(0,te.y),frozenSize:le.height,trailingSize:le.trailingHeight,extent:me.height}),col:Sr(q.colAxis,(A-G.left)/J,{scroll:Math.max(0,te.x),frozenSize:le.width,trailingSize:le.trailingWidth,extent:me.width})},q.rowAxis.count,q.colAxis.count)},[]),O=i.useCallback(A=>{N.current=A,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const D=N.current;T(D===null?null:"cell"in D?D.cell:F(D.clientX,D.clientY))}))},[T,F]),g=i.useCallback(A=>O({cell:A}),[O]),p=i.useCallback(()=>x(),[x]),C=i.useCallback(A=>{if(l.current===null)return;const D=t.current;l.current=null,r(null),U({interactive:null}),(A===void 0||A.restoreFocus)&&D.focusSink({preventScroll:!0}),D.isEditing()||D.rearmSink()},[U]),v=i.useCallback(A=>{l.current=A.kind,r(A),U({interactive:A.cell})},[U]),S=i.useCallback(A=>{const D=t.current;return na(D.adapter)?{cellReadOnly:Ye(D.adapter,A.row,A.col)}:{}},[]),b=i.useCallback((A,D)=>{const q=t.current;if(Ye(q.adapter,A.cell.row,A.cell.col)){q.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...A,...S(A.cell)});return}if(q.commitEdits(D,{source:"annotate"})===null){v({...A,rejected:!0});return}C()},[v,C,S]),y=i.useCallback((A,D)=>{const q=t.current;if(!cr(q.adapter,q.popovers,A))throw new RangeError(`[spreadsheet] openPopover("${A}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const j=q.getActive();if(A==="list"&&Ye(q.adapter,j.row,j.col)){q.rejectReadOnly({kind:"edit",cell:j,editSession:"none"});return}if(A==="note-tip"){I(j);return}if(A==="message"){if(l.current!==null&&l.current!=="message")return;const te=D!==void 0&&D.message!==void 0?D.message:void 0,le=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col),me=te!==void 0?te:le===void 0?void 0:le.inputMessage;if(me===void 0)return;const Ee=D!==void 0&&D.rejected===!0;v({kind:"message",cell:j,anchorRect:_(j),current:{title:ze(q.labels,"messageTitle"),message:me,rejected:Ee},close:C});return}if(q.isEditing()&&!q.requestCommit())return;if(A==="list"){const te=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col);if(te===void 0||te.type!=="list")return;const le=D!==void 0&&D.typed!==void 0?D.typed:"";x(),q.focusSink({preventScroll:!0}),v({kind:"list",cell:j,anchorRect:_(j),current:te.values,typed:le,commit:me=>{if(Ye(t.current.adapter,j.row,j.col)){t.current.rejectReadOnly({kind:"edit",cell:j,editSession:"none"}),C();return}t.current.commitEdits([{row:j.row,col:j.col,text:me}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(x(),q.focusSink({preventScroll:!0}),A==="note"){const te=q.adapter.getCellNote===void 0?void 0:q.adapter.getCellNote(j.row,j.col),le={kind:"note",cell:j,anchorRect:_(j),current:te,commit:me=>{b(le,[{row:j.row,col:j.col,note:me}])},close:C,rejected:!1,...S(j)};v(le);return}if(A==="comment"){const te=q.adapter.getCellComments===void 0?void 0:q.adapter.getCellComments(j.row,j.col),le={kind:"comment",cell:j,anchorRect:_(j),current:te===void 0?[]:te,commit:me=>{b(le,[{row:j.row,col:j.col,comments:me}])},close:C,rejected:!1,...S(j)};v(le);return}const K=q.adapter.getCellHyperlink===void 0?void 0:Un(q.adapter.getCellHyperlink(j.row,j.col)),G=q.adapter.getCellText(j.row,j.col),J={kind:"link",cell:j,anchorRect:_(j),current:{text:G,url:K},commit:te=>{const le=te.url===null?null:sn(te.url);if(le===null&&te.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(te.url)}`);const me=te.text===G?{row:j.row,col:j.col,hyperlink:le}:{row:j.row,col:j.col,text:te.text,hyperlink:le};b(J,[me])},close:C,canOpen:q.onHyperlinkOpen!==void 0,open:()=>{const te=t.current.onHyperlinkOpen;te!==void 0&&K!==void 0&&te(K,j)},rejected:!1,...S(j)};v(J)},[_,C,b,x,v,I,S]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const A=f.current;if(!a||A===null)return;const D=j=>{const K=t.current;cr(K.adapter,K.popovers,"note-tip")&&O({clientX:j.clientX,clientY:j.clientY})},q=()=>{cr(t.current.adapter,t.current.popovers,"note-tip")&&O({cell:null})};return A.addEventListener("pointermove",D),A.addEventListener("pointerleave",q),()=>{A.removeEventListener("pointermove",D),A.removeEventListener("pointerleave",q)}},[a,f,O]),i.useEffect(()=>()=>{R.current!==null&&cancelAnimationFrame(R.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:E,popovers:d}=e,$=i.useMemo(()=>Ow.some(A=>cr(E,d,A)),[E,d]);return i.useMemo(()=>({layerEnabled:$,isKindEnabled:A=>cr(t.current.adapter,t.current.popovers,A),open:y,close:C,isOpen:()=>l.current,onCellHover:g,hideTip:p,onTipPointerEnter:()=>{h.current=!0,W()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&z()},syncTipAriaDescribedBy:k,context:n,tipContext:o,registerCompositionEnd:A=>{H.current=A},isCompositionKey:A=>Xa(A,H.current),getLayerSize:()=>{const A=t.current.handleRef.current;return A===null?{width:0,height:0}:A.getViewportSize()},tipId:L}),[$,y,C,g,p,W,z,k,n,o,L])},$w=(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},Za=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return ln({row:kr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:Sr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},Lw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),R=i.useRef(null),N=i.useRef(""),H=i.useRef(!1),L=i.useRef(!1),_=i.useCallback((O,g)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:S}=t.current;return Za(p.current,o.current,C,v,S.current,O,g)},[]),U=i.useRef(!1),W=i.useRef(null),k=i.useRef(null),x=i.useRef({clientX:0,clientY:0}),z=i.useCallback(()=>{const{autoScroller:O,bodyRef:g,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,U.current=!1,W.current=null,k.current=null,m.current=!1,R.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),O.stop();const C=g.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),I=i.useCallback(()=>{if(!n.current)return;const O=r.current;O!==null&&t.current.setSelection(O),z()},[z]),{enabled:T,bodyRef:F}=e;return i.useEffect(()=>{const O=F.current;if(!T||O===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const $=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,R.current=null,L.current=!1),H.current=g(d.target),!H.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if($.getPointing?.()){$.focusSink();return}if($.isEditing()&&!$.requestCommit()){d.stopPropagation(),$.focusSink();return}$.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if(($.pointDragRef===void 0?null:$.pointDragRef.current)?.onPointerDown(d))return;if($.isEditing()&&!$.requestCommit()){d.preventDefault(),$.focusSink();return}o.current=O.getBoundingClientRect();const D=_(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),$.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&$.openHyperlinkAt?.(D)===!0){L.current=!0;return}const q=$.getSelection();r.current=q;const j=d.shiftKey,K=d.ctrlKey||d.metaKey,G=K&&!j&&q.ranges.some(te=>Cn(te,D));m.current=G,R.current=G?D:null,G||$.setSelection(Cr(q,D,{extend:j,append:K})),n.current=!0,$.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{O.setPointerCapture(d.pointerId)}catch{c.current=null}const J=G?D:$.getSelection().anchor;h.current=te=>Re(J,te),W.current=J.col,k.current=J.row,$.autoScroller.stop(),U.current=!1,x.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",v=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!U.current&&h.current!==null){const $=Math.abs(d.clientX-x.current.clientX),A=Math.abs(d.clientY-x.current.clientY);Math.max($,A)>=io&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:W.current??void 0,anchorRow:k.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const $=h.current;if(!n.current||$===null)return;const A=t.current,D=_(s.current.clientX,s.current.clientY);D!==null&&A.onDragFrame($(D))}))}},S=d=>{v(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},b=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const $=t.current,A=_(d.clientX,d.clientY);if(A!==null){const D=R.current;m.current&&D!==null?$.setSelection(Ya($.getSelection(),Re(D,A),D)):$.setSelection(hn($.getSelection(),A))}z()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||I()},f=d=>{const $=t.current;if(!g(d.target)||N.current!=="mouse"||$.isAnyDragging())return;if($.isEditing()&&!$.requestCommit()){$.focusSink();return}$.focusSink(),o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);if(A===null)return;const D=$.getSelection();D.ranges.some(j=>Cn(j,A))||$.setSelection(Cr(D,A,{extend:!1,append:!1})),$.onContextMenuSelect(A,d)},E=d=>{const $=t.current;if(!H.current||N.current!=="mouse"||$.getPointing?.()||L.current)return;o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);A!==null&&It($.getSelection().active,A)&&$.onRequestEdit(A,$.caretFromPointEnabled(A)?$w(d.clientX,d.clientY,A):void 0)};return O.addEventListener("pointerdown",p),O.addEventListener("pointermove",S),O.addEventListener("pointerup",b),O.addEventListener("lostpointercapture",a),O.addEventListener("contextmenu",f),O.addEventListener("dblclick",E),()=>{O.removeEventListener("pointerdown",p),O.removeEventListener("pointermove",S),O.removeEventListener("pointerup",b),O.removeEventListener("lostpointercapture",a),O.removeEventListener("contextmenu",f),O.removeEventListener("dblclick",E),z()}},[T,F,_,z,I]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:I,cancelDrag:z}),[I,z])},Dw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(null),N=i.useRef(!1),H=i.useCallback((x,z)=>{const{handleRef:I,rowAxis:T,colAxis:F,zoomRef:O}=t.current;return Za(I.current,o.current,T,F,O.current,x,z)},[]),L=i.useCallback(()=>{const{autoScroller:x,bodyRef:z,onDragFrame:I}=t.current;n.current=!1,r.current=null,m.current=null,R.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),x.stop();const T=z.current;T!==null&&u.current!==null&&T.hasPointerCapture?.(u.current)&&T.releasePointerCapture(u.current),u.current=null,I(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const x=r.current;x!==null&&t.current.restoreSink(x),L()},[L]),U=i.useCallback(x=>{const z=t.current,I=z.bodyRef.current;if(!z.enabled||I===null||!z.getPointing())return!1;o.current=I.getBoundingClientRect();const T=H(x.clientX,x.clientY);if(T===null)return o.current=null,!1;const F=z.captureSink();if(F===null)return o.current=null,!1;x.preventDefault(),z.focusSink(),r.current=F,R.current=T,z.insertReference(T,"cells"),n.current=!0,s.current={clientX:x.clientX,clientY:x.clientY},l.current={clientX:x.clientX,clientY:x.clientY},u.current=x.pointerId,h.current=x.buttons;try{I.setPointerCapture(x.pointerId)}catch{u.current=null}return m.current=O=>{const g=Re(T,O);return t.current.insertReference(g,"cells"),g},z.autoScroller.stop(),N.current=!1,z.onDragFrame(Re(T,T)),!0},[H]),{enabled:W,bodyRef:k}=e;return i.useEffect(()=>{const x=k.current;if(!W||x===null)return;const z=O=>u.current!==null?O.pointerId===u.current:O.pointerType==="mouse",I=O=>{if(!(n.current&&z(O)))return;s.current={clientX:O.clientX,clientY:O.clientY};const g=m.current,p=R.current;if(!N.current&&g!==null&&p!==null){const C=Math.abs(O.clientX-l.current.clientX),v=Math.abs(O.clientY-l.current.clientY);Math.max(C,v)>=io&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=m.current;if(!n.current||C===null)return;const v=H(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(h.current&1)!==0&&(O.buttons&1)===0&&L()},T=O=>{O.button!==0||!(n.current&&z(O))||L()},F=O=>{!n.current||u.current===null||O.pointerId!==u.current||L()};return x.addEventListener("pointermove",I),x.addEventListener("pointerup",T),x.addEventListener("lostpointercapture",F),()=>{x.removeEventListener("pointermove",I),x.removeEventListener("pointerup",T),x.removeEventListener("lostpointercapture",F),L()}},[W,k,H,L]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:L,onPointerDown:U}),[_,L,U])},Mw=Object.freeze({width:0,height:0}),rs=33,zw=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,Nw=(e,t,n)=>{const r=(n-t)/(rs-1);let o=-1,s=-1;for(let c=0;c<rs;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,u)=>{let h=c,m=u;for(;Math.abs(m-h)>1;){const R=(h+m)/2;e(R)?m=R:h=R}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===rs-1?n:l(t+r*(s+1),t+r*s)}},Fw=(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})`)},Pw=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)})`)},Gi=(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},_w=24,qw=200,Ja=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Zi=5,Iw=/^#[0-9A-Fa-f]{6}$/,jw=Object.freeze({row:!1,column:!1,intersection:!1}),Ji=Object.freeze({ok:!0}),Qi=(e,t)=>{if(t===void 0)return Ja;if(t.length!==Zi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Zi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Iw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Hw=e=>{for(const t of["row","column","intersection"])if(Ze(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},Bw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ka},Vw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},Ww=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Je.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Nn={ranges:[Re({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Kw=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=_w,defaultColumnWidth:l=Te.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:m=0,tapScrollCircleOptions:R,overscanRows:N,overscanCols:H,background:L,onRenderTruncated:_,renderCell:U,onSelectionChange:W,onCellContextMenu:k,onUndoRequest:x,onRedoRequest:z,onCopyMultiRange:I,onOperationRejected:T,onEditRejected:F,onReadOnlyRejected:O,formatReadOnlyAnnouncement:g,dataVersion:p,maxOperationCells:C=Te.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:v=!0,enableResizeUI:S=!0,headings:b=!0,onContentSizeChange:y,formatCellAnnouncement:a,formatSelectionAnnouncement:f,formatCommandAnnouncement:E,formatResizeAnnouncement:d,locale:$,labels:A,shortcuts:D,colors:q,formats:j,highlight:K,defaultHighlight:G,onHighlightChange:J,highlightColors:te,popovers:le,renderPopover:me,onClipChange:Ee,onHyperlinkOpen:xe,onValidationRejected:De,onPasteSpecialRequest:Pe,onClipboardUnavailable:ue,onPasteResolved:Ne,now:Ue=Date.now,zoom:je,defaultZoom:Ot,onZoomChange:xt,testId:He,className:wt,__onCellRender:bn,__onVirtualKeyboardRaise:lt,__maxRenderedCells:Er},yn){const oe=i.useMemo(()=>r?hh(t):t,[t,r]),fe=qi(oe.rowCount,s),pe=qi(oe.colCount,l),Ht=i.useRef(null);Ht.current===null&&(Ht.current=gw());const Ae=Ht.current,Bt=Je.resolveVirtualScrollLocale($),it=i.useMemo(()=>fa($,A),[$,A]),Rn=Ww(Ih(it)),Vt=i.useMemo(()=>Fh(D),[D]),Ar=i.useMemo(()=>{if(!S)return;const P=[...Vt].filter(([,Z])=>Uo.includes(Z)).sort(([,Z],[,Q])=>Uo.indexOf(Z)-Uo.indexOf(Q)).map(([Z])=>$h(Z)).filter(Z=>Z!==null);return P.length===0?void 0:P.join(" ")},[Vt,S]),Xn=i.useMemo(()=>({fill:Qi("fill",q===void 0?void 0:q.fill),font:Qi("font",q===void 0?void 0:q.font)}),[q]),mo=i.useMemo(()=>te===void 0?void 0:Hw(te),[te]);if(oe.getConditionalFormats!==void 0&&oe.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");Fw(n,u),Pw(o);const Or=i.useCallback(()=>Ae.get().editVersion,[Ae]),go=i.useCallback(w=>Ae.subscribeCoalesced(w),[Ae]),wo=i.useSyncExternalStore(go,Or,Or)+(p===void 0?0:p),Wt=oe.getConditionalFormats===void 0?null:oe.getConditionalFormats(),vn=i.useMemo(()=>({index:Wt===null?null:Ba(Wt),memo:qs()}),[oe,Wt,wo]),Gn=i.useRef(vn.index);Gn.current=vn.index;const M=i.useRef(vn.memo);M.current=vn.memo;const B=i.useCallback((w,P,Z)=>Is(oe,Gn.current,M.current,w,P,Z),[oe]),X=i.useRef(null),[V,ee]=i.useState(()=>Te.clampSpreadsheetZoom(Ot??1)),se=Te.clampSpreadsheetZoom(je??V),ne=i.useRef(se);ne.current=se;const Oe=i.useRef(se);Oe.current=se;const Se=i.useRef(null),Be=i.useRef(xt);Be.current=xt;const Ve=i.useRef(je!==void 0);Ve.current=je!==void 0;const _e=i.useCallback(w=>{const P=Te.clampSpreadsheetZoom(w);P!==Oe.current&&(Oe.current=P,Ve.current||ee(P),Be.current?.(P))},[]),ve=oe.rowCount===0||oe.colCount===0,ie=!ve;i.useEffect(()=>{const w=X.current;if(!ie||w===null)return;const P=Q=>{Q.defaultPrevented||!Q.altKey||Q.ctrlKey||Q.metaKey||Q.shiftKey||Q.deltaY!==0&&(Q.preventDefault(),Q.stopPropagation(),!Se.current?.()&&_e(Te.stepSpreadsheetZoom(Oe.current,Q.deltaY<0?1:-1)))},Z=Q=>{if(Q.defaultPrevented||!(Q.ctrlKey&&Q.altKey)||Q.metaKey||Q.getModifierState("AltGraph"))return;const de=Q.key==="="||Q.key==="+"?Te.stepSpreadsheetZoom(Oe.current,1):Q.key==="-"?Te.stepSpreadsheetZoom(Oe.current,-1):Q.key==="0"?1:null;de!==null&&(Q.preventDefault(),Q.stopPropagation(),!Se.current?.()&&_e(de))};return w.addEventListener("wheel",P,{passive:!1,capture:!0}),w.addEventListener("keydown",Z,!0),()=>{w.removeEventListener("wheel",P,{capture:!0}),w.removeEventListener("keydown",Z,!0)}},[_e,ie]);const ce=i.useRef(null),ge=i.useRef(null),Ce=i.useRef(null),he=i.useRef(null),re=i.useRef(null),ke=i.useRef(null),Me=i.useRef(null),Ct=i.useRef(0),ct=i.useRef(null),bt=i.useRef(0),Tt=i.useRef(null),$t=i.useRef(null),Kt=i.useRef(null),yt=i.useRef(null),Sn=i.useRef(null),kn=i.useRef(null),Bs=i.useRef(null),[En,Co]=i.useState(Nn),Rt=i.useRef(En),Lt=i.useCallback(()=>Rt.current,[]),[Qa,eu]=i.useState(()=>G===void 0?jw:G),An=K!==void 0?K:Qa,bo=i.useRef(An);bo.current=An;const tu=Bw(mo,An),Vs=i.useRef(K!==void 0);Vs.current=K!==void 0;const Ws=i.useRef(J);Ws.current=J;const nu=i.useCallback(w=>{Vs.current||eu(w),Ws.current?.(w)},[]),Ks=i.useRef(null),yo=i.useRef(null),Dt=i.useRef(null),Ro=i.useRef(()=>!1),Ys=i.useRef(()=>{}),Us=i.useRef(()=>null),Xs=i.useRef(()=>{}),cn=i.useCallback(()=>Ro.current(),[]),vo=i.useMemo(()=>({getPointing:()=>Ro.current(),insertReference:(w,P)=>Ys.current(w,P)}),[]),Gs=i.useRef(Pt),Zs=i.useRef(null),So=i.useRef({interactive:null,tip:null}),Js=i.useRef(null),Qs=i.useRef(null),xr=i.useRef(()=>{}),el=i.useRef(()=>!1),Yt=i.useRef(null),Zn=i.useCallback(()=>{const w=Yt.current;if(w===null||w.isOpen()!=="message")return!1;const P=w.context;return P===null||P.kind!=="message"||!P.current.rejected?!1:(w.close(),!0)},[]),ko=i.useRef(()=>!1),tl=i.useRef(()=>!1),nl=i.useRef(null),Eo=i.useRef(()=>Promise.resolve("rejected")),Le=i.useCallback(()=>{Ks.current?.()},[]),Mt=i.useCallback(w=>{ke.current?.focus(w)},[]),qe=i.useCallback(()=>{Mt({preventScroll:!0})},[Mt]),Ao=i.useRef(!1),ru=i.useCallback(()=>{const w=X.current;if(w!==null){Ao.current=!0;try{w.focus()}finally{Ao.current=!1}}},[]),Qe=i.useCallback(()=>{const w=ke.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),On=i.useCallback((w,P)=>{if(w===null)return;const Z=P?"":"none";w.style.display!==Z&&(w.style.display=Z)},[]),at=i.useCallback(()=>{const w=Me.current;if(w!==null){const Z=Math.max(0,re.current?.getScrollPosition().y??0),Q=re.current?.getFrozenSize().height??0;w.style.transform=`translateY(${Ct.current-Z-Q}px)`}const P=re.current;if(P!==null&&(Sn.current!==null||kn.current!==null)){const Z=P.getFrozenSize();On(Sn.current,Z.height>0),On(kn.current,Z.trailingHeight>0)}},[On]),ut=i.useCallback(()=>{const w=ct.current;if(w!==null){const Z=Math.max(0,re.current?.getScrollPosition().x??0),Q=re.current?.getFrozenSize().width??0;w.style.transform=`translateX(${bt.current-Z-Q}px)`}const P=re.current;if(P!==null&&(Kt.current!==null||yt.current!==null)){const Z=P.getFrozenSize();On(Kt.current,Z.width>0),On(yt.current,Z.trailingWidth>0)}},[On]),Jn=i.useRef(null),xn=i.useCallback(()=>{Kt.current===null&&yt.current===null&&Sn.current===null&&kn.current===null||Jn.current===null&&(Jn.current=requestAnimationFrame(()=>{Jn.current=null,at(),ut(),Le()}))},[at,ut,Le]);i.useEffect(()=>()=>{Jn.current!==null&&cancelAnimationFrame(Jn.current)},[]);const Oo=i.useRef(null),xo=i.useRef(null);(Oo.current===null||xo.current?.rowAxis!==fe||xo.current?.colAxis!==pe)&&(xo.current={rowAxis:fe,colAxis:pe},Oo.current=aw({handleRef:re,rowAxis:fe,colAxis:pe}));const Tr=i.useCallback(w=>{const P=re.current,Z=P===null?{x:0,y:0}:P.getScrollPosition(),Q=P===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:P.getFrozenSize(),de=P===null?{width:0,height:0}:P.getViewportSize(),be=ne.current;return{top:wn(fe,w.row,{scroll:Math.max(0,Z.y),frozenCount:Q.rows,trailingCount:Q.trailingRows,extent:de.height})*be,left:gn(pe,w.col,{scroll:Math.max(0,Z.x),frozenCount:Q.cols,trailingCount:Q.trailingCols,extent:de.width})*be,width:pe.sizeOf(w.col)*be,height:fe.sizeOf(w.row)*be}},[fe,pe]),rl=i.useCallback(w=>{const P=he.current,Z=X.current,Q=ge.current;if(P===null||Z===null||Q===null||re.current===null)return;const de=ne.current,be=Tr(w),Ke=Q.offsetTop*de+be.top,tt=Q.offsetLeft*de+be.left,Ie=Math.max(0,Ke),Et=Math.max(0,tt),Gt=Math.min(Z.clientHeight,Ke+be.height),Mr=Math.min(Z.clientWidth,tt+be.width);if(Gt<=Ie||Mr<=Et)return;P.style.top=`${Ie}px`,P.style.left=`${Et}px`,P.style.width=`${Mr-Et}px`,P.style.height=`${Gt-Ie}px`;const Dn=P.getBoundingClientRect();Dn.width===0&&Dn.height===0||P.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Tr]),Ut=i.useCallback(w=>{Oo.current?.(w),rl(w)},[rl]),ou=i.useCallback(()=>{const w=re.current,P=w===null?-1:w.getViewportSize().height,Z=ce.current,Q=X.current;if(P<=0||Z===null||Q===null)return P;const de=Z.getBoundingClientRect(),be=Q.getRootNode();if(de.height<=0||Z.offsetHeight<=0||!zw(be))return P;const Ke=Q.ownerDocument.documentElement,tt=Math.max(de.left,0),Ie=Math.min(de.right,Ke.clientWidth),Et=Math.max(de.top,0)+.5,Gt=Math.min(de.bottom,Ke.clientHeight)-.5,Mr=(tt+Ie)/2,Dn=Ie>tt&&Gt>=Et?Nw(zu=>{const Ml=be.elementFromPoint(Mr,zu);return Ml!==null&&Q.contains(Ml)},Et,Gt):null,Mu=Dn===null?Ke.clientHeight:Dn.bottom-Dn.top+1;return Math.min(P,Mu*(Z.offsetHeight/de.height))},[]),ol=i.useRef(y);ol.current=y;const To=i.useRef(null),zt=i.useCallback(()=>{const w=ol.current;if(w===void 0)return;const P=ge.current;let Z;if(P===null)Z=Mw;else{if(P.getClientRects().length===0)return;{const de=Ce.current,be=ne.current;Z={width:((de===null?0:de.offsetWidth)+pe.totalSize()+Te.SPREADSHEET_SCROLLBAR_SIZE_PX)*be,height:((de===null?0:de.offsetHeight)+fe.totalSize()+Te.SPREADSHEET_SCROLLBAR_SIZE_PX)*be}}}const Q=To.current;Q!==null&&Q.width===Z.width&&Q.height===Z.height||(To.current=Z,w(Z))},[fe,pe]);i.useLayoutEffect(()=>{if(y===void 0){To.current=null;return}zt()});const sl=y!==void 0;i.useEffect(()=>{const w=ge.current;if(!sl||w===null)return;const P=new ResizeObserver(()=>zt());return P.observe(w),()=>P.disconnect()},[sl,zt,ve]);const Tn=i.useRef(null),an=i.useRef(null),$n=i.useCallback(w=>{Tn.current!==null&&window.clearTimeout(Tn.current),an.current!==null&&(cancelAnimationFrame(an.current),an.current=null),Tn.current=window.setTimeout(()=>{Tn.current=null;const P=Bs.current;P!==null&&(P.textContent="",an.current=requestAnimationFrame(()=>{an.current=null,P.textContent=w}))},qw)},[]);i.useEffect(()=>()=>{Tn.current!==null&&window.clearTimeout(Tn.current),an.current!==null&&cancelAnimationFrame(an.current)},[]);const Ln=i.useCallback(w=>{O?.(w),g!==void 0&&$n(g(w))},[O,g,$n]),ll=i.useCallback((w,P)=>{if(a===void 0&&f===void 0)return;const Z=P.ranges[P.ranges.length-1],Q=st(Z),de=P.ranges.length===1&&Q.rows===1&&Q.cols===1,be=w.ranges[w.ranges.length-1],Ke=w.ranges.length!==P.ranges.length||be.startRow!==Z.startRow||be.startCol!==Z.startCol||be.endRow!==Z.endRow||be.endCol!==Z.endCol,tt=()=>{if(a!==void 0){const Ie=P.active,Et=oe.getCellText(Ie.row,Ie.col),Gt=oe.getCellFormat===void 0?void 0:B(Ie.row,Ie.col,()=>Et);$n(a({row:Ie.row,col:Ie.col,text:Et,displayText:Wn(Et,Gt===void 0?void 0:Gt.value),columnName:Te.columnIndexToName(Ie.col),...na(oe)?{readOnly:Ye(oe,Ie.row,Ie.col)}:{}}))}};if(de){tt();return}if(Ke){f!==void 0&&$n(f({range:Z,anchor:P.anchor,active:P.active,rangeRowCount:Q.rows,rangeColCount:Q.cols,rangeCount:P.ranges.length}));return}tt()},[oe,a,f,$n,B]),We=i.useCallback(w=>{const P=Rt.current;Object.is(w,P)||ow(w,P)||(Rt.current=w,Co(w),W?.(w),ll(P,w),(Dt.current?.()??!1)||Qe())},[W,ll,Qe]),su=i.useCallback(w=>{const P=Rt.current;if(w.mode==="cycle"){const Q=Ua(P,w.direction);We(Q),Ut(Q.active);return}const Z=ln(w.cell,fe.count,pe.count);if(w.mode==="extend"){We(hn(P,Z)),Ut(Z);return}We(Cr(P,Z,{extend:!1,append:!1})),Ut(Z)},[We,Ut,fe,pe]),Xe=i.useCallback(()=>Dt.current?.()??!1,[]),il=i.useRef(null),dt=i.useCallback(()=>il.current?.()??!0,[]),cl=i.useRef(null),Qn=i.useCallback((w,P)=>{const Z=Dt.current?.()??!1;cl.current?.(w,P),!Z&&(Dt.current?.()??!1)&&Zn()},[Zn]),[lu,$o]=i.useState(!1),al=i.useCallback(()=>{lt?.(),$o(!0)},[lt]),iu=i.useCallback((w,P)=>{Ye(oe,w.row,w.col)||al(),Qn("edit",P)},[oe,al,Qn]),ul=i.useRef(null),$r=i.useCallback(()=>ul.current?.()??null,[]),dl=i.useRef(null),vt=i.useCallback(()=>{dl.current?.()},[]),fl=i.useRef(null),pl=i.useCallback(w=>{fl.current?.(w)},[]),hl=i.useRef(()=>{}),Lr=i.useRef(0),un=i.useCallback((w,P,Z)=>{let Q;if(P.source==="paste"){const de=Vw(Z);if(w.length===0&&de.conditionalFormats.length===0)return null;Lr.current+=1,Q={transaction:Lr.current,source:"paste",sameSheet:de.sameSheet,conditionalFormats:de.conditionalFormats}}else{if(w.length===0)return null;Lr.current+=1,Q={transaction:Lr.current,source:P.source}}try{oe.applyEdits(w,Q)}catch(de){return F?.(de,P),null}return Ae.bumpEdit(),pl(P.source),Q.transaction},[oe,Ae,F,pl]),cu=i.useCallback((w,P)=>un(w,{source:"paste"},P),[un]),au=i.useCallback(w=>{Ae.setVy(w.y),at(),ut(),Le()},[Ae,at,ut,Le]),ml=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),uu=i.useCallback(w=>{Ae.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ae.setColRange(w.renderingColStart,w.renderingColEnd);const P=ml.current;(P.rowStart!==w.renderingRowStart||P.rowEnd!==w.renderingRowEnd||P.colStart!==w.renderingColStart||P.colEnd!==w.renderingColEnd)&&(ml.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},Le())},[Ae,Le]),gl=i.useRef(()=>"add"),Xt=i.useCallback(w=>{yo.current?.(w,gl.current())},[]),du=i.useCallback(w=>{yo.current?.(w,"point")},[]),wl=i.useRef(null),Lo=i.useCallback(w=>{wl.current?.(w)},[]),Cl=i.useRef(null),fu=i.useCallback(w=>{Cl.current?.(w)},[]),bl=i.useRef(null),Do=i.useCallback((w,P)=>{if(P.length===0)return;const Z=re.current;if(w==="col"){for(const Q of P){const de=Math.round(Q.size);pe.resize(Q.index,de),Z?.updateColSize(Q.index,de)}Ae.bumpColVersion(),ut(),Le(),xn(),zt();return}for(const Q of P){const de=Math.round(Q.size);fe.resize(Q.index,de),Z?.updateRowSize(Q.index,de)}Ae.bumpRowGeometry(),at(),Le(),xn(),zt()},[fe,pe,Ae,ut,at,Le,xn,zt]),pu=i.useCallback((w,P)=>{k?.(w,{kind:"pointer",event:P})},[k]),hu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"both",zoomRef:ne}),mu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"x",zoomRef:ne}),gu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"y",zoomRef:ne}),wu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Lo,axis:"x",zoomRef:ne}),Cu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Lo,axis:"y",zoomRef:ne}),bu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"both",zoomRef:ne}),yl=i.useRef(null),Rl=i.useRef(()=>!1),Mo=i.useCallback(()=>Rl.current(),[]),ft=Lw({zoomRef:ne,enabled:!ve,rowAxis:fe,colAxis:pe,handleRef:re,bodyRef:ce,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,onContextMenuSelect:pu,onRequestEdit:iu,caretFromPointEnabled:w=>{if(U!==void 0||oe.getCellFormula!==void 0&&oe.getCellFormula(w.row,w.col)!==void 0)return!1;if(oe.getCellFormat===void 0)return!0;const P=oe.getCellText(w.row,w.col);return Wn(P,oe.getCellFormat(w.row,w.col)?.value)===P},isAnyDragging:Mo,autoScroller:hu,repaintOverlay:Le,pointDragRef:yl,getPointing:cn,openHyperlinkAt:xe===void 0||oe.getCellHyperlink===void 0?void 0:w=>{const P=oe.getCellHyperlink===void 0?void 0:Un(oe.getCellHyperlink(w.row,w.col));return P===void 0?!1:(xe(P,w),!0)}}),St=Xi({zoomRef:ne,enabled:!ve&&b,axis:"col",headerRef:Tt,mainAxis:pe,crossCount:oe.rowCount,handleRef:re,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,autoScroller:mu,repaintOverlay:Le,pointing:vo}),kt=Xi({zoomRef:ne,enabled:!ve&&b,axis:"row",headerRef:$t,mainAxis:fe,crossCount:oe.colCount,handleRef:re,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,autoScroller:gu,repaintOverlay:Le,pointing:vo}),et=rw({zoomRef:ne,enabled:!ve&&S&&b,colBandRef:Tt,rowBandRef:$t,fontSourceRef:ce,colAxis:pe,rowAxis:fe,viewStore:Ae,handleRef:re,isEditing:Xe,requestCommit:dt,focusSink:qe,getSelection:Lt,adapter:oe,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:T,resizeTracks:Do,writeResizeGuide:fu,repaintOverlay:Le,isPointing:cn}),pt=bw({zoomRef:ne,enabled:!ve&&v,handleNodeRef:bl,bodyRef:ce,rowAxis:fe,colAxis:pe,handleRef:re,getSelection:Lt,setSelection:We,focusSink:qe,adapter:oe,commitEdits:un,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,writeFillPreview:Lo,repaintOverlay:Le,xAutoScroller:wu,yAutoScroller:Cu}),nt=Dw({zoomRef:ne,enabled:!ve,bodyRef:ce,handleRef:re,rowAxis:fe,colAxis:pe,getPointing:cn,insertReference:vo.insertReference,captureSink:()=>Us.current(),restoreSink:w=>Xs.current(w),focusSink:qe,autoScroller:bu,onDragFrame:Xt});yl.current=nt;const er=i.useCallback(()=>ft.isDragging()||St.isDragging()||kt.isDragging()||et.isDragging()||pt.isDragging()||nt.isDragging(),[ft,St,kt,et,pt,nt]);Se.current=er,Rl.current=er,gl.current=()=>nt.isDragging()?"point":ft.getDragMode();const yu=i.useCallback(()=>{ft.abortDrag(),St.abortDrag(),kt.abortDrag(),et.abortDrag(),pt.abortDrag(),nt.abortDrag()},[ft,St,kt,et,pt,nt]),zo=i.useCallback(()=>Rt.current.active,[]),vl=i.useCallback((w,P)=>{const Z=oe.getCellValidation===void 0?void 0:oe.getCellValidation(w.row,w.col);if(Z===void 0)return Ji;const Q=oe.evaluateFormula,de=ma(Z,P,Bt,Q===void 0?void 0:be=>Q(be,w));return de.ok||Z.strict!==!0?Ji:(De?.({cell:w,rule:Z,text:P,message:de.message}),Yt.current?.isKindEnabled("message")&&xr.current("message",{message:de.message,rejected:!0}),de)},[oe,De,Bt]),Fe=bg({enabled:!ve,sinkRef:ke,rootRef:X,adapter:oe,commitEdits:un,getActive:zo,ensureCellVisible:Ut,focusSink:Mt,rearmSink:Qe,discardClip:vt,isDragging:Mo,rejectReadOnly:Ln,resolveEditAlign:w=>{if(oe.getCellFormat===void 0)return null;const P=Qr(oe,w.row,w.col);return ta(B(w.row,w.col,P),P)},resolveEditPaint:w=>oe.getCellFormat===void 0?null:df(B(w.row,w.col,Qr(oe,w.row,w.col))),editPaintRef:Gs,repaintOverlay:Le,validateCommit:vl});Dt.current=Fe.isEditing,il.current=Fe.requestCommit,cl.current=Fe.startEdit,Ro.current=Fe.getPointing,Ys.current=Fe.insertReference,Us.current=Fe.captureSink,Xs.current=Fe.restoreSink;const Sl=i.useCallback(()=>{Fe.cancelEdit(),Zn()},[Fe.cancelEdit,Zn]),tr=eg({enabled:!ve,sinkRef:ke,adapter:oe,isEditing:Xe,getSelection:Lt,setSelection:We,commitPaste:cu,maxOperationCells:C,onOperationRejected:T,onCopyMultiRange:I,repaintOverlay:Le,isDragging:Mo,resize:{rowAxis:fe,colAxis:pe,resizeTracks:Do},pendingPasteOptionsRef:Zs,formats:j,onClipChange:Ee,onClipboardUnavailable:ue,onEditRejected:F,rejectReadOnly:Ln,onPasteResolved:Ne});ul.current=tr.getClip,dl.current=tr.discardClip,fl.current=tr.discardClipOnCommit,hl.current=tr.onAdapterSwitch,Eo.current=tr.paste;const nr=Tw({enabled:!ve,adapter:oe,popovers:le,sinkRef:ke,bodyRef:ce,handleRef:re,rowAxis:fe,colAxis:pe,zoomRef:ne,getActive:zo,isEditing:Xe,requestCommit:dt,focusSink:Mt,rearmSink:Qe,isDraggingAny:er,commitEdits:un,labels:it,onHyperlinkOpen:xe,anchors:So,repaintOverlay:Le,rejectReadOnly:Ln});Yt.current=nr,xr.current=nr.open,el.current=nr.hideTip;const Ru=i.useCallback(()=>{const w=Rt.current.active;return Ut(w),Tr(w)},[Ut,Tr]),No=gg({adapter:oe,trackResize:S&&!ve?et:void 0,getSelection:Lt,commitEdits:un,getActive:zo,isEditing:Xe,requestCommit:dt,cancelEdit:Sl,getSessionText:Fe.getSessionText,validateCommit:vl,insertAtCaret:Fe.insertAtCaret,refreshEditPaint:Fe.refreshPaint,maxOperationCells:C,onOperationRejected:T,colors:Xn,formats:j,getHighlight:()=>bo.current,setHighlight:nu,popovers:le,openPopover:w=>xr.current(w),onHyperlinkOpen:xe,onPasteSpecialRequest:Pe,paste:w=>Eo.current(w),rowAxis:fe,colAxis:pe,resizeTracks:Do,defaultRowHeight:s,defaultColumnWidth:l,now:Ue,announce:$n,formatCommandAnnouncement:E,formatResizeAnnouncement:d,keyboardCellRect:Ru,rejectReadOnly:Ln});nl.current=No,ko.current=No.executeCommand,tl.current=No.isCommandAvailable;const vu=i.useMemo(()=>({table:Vt,execute:w=>ko.current(w),isAvailable:w=>tl.current(w)}),[Vt]),Su=i.useCallback(()=>{vt(),x?.()},[vt,x]),ku=i.useCallback(()=>{vt(),z?.()},[vt,z]);mw({zoomRef:ne,enabled:!ve,sinkRef:ke,rootRef:X,handOffFocusToRoot:ru,getSelection:Lt,setSelection:We,moveActive:su,ensureCellVisible:Ut,pageExtent:ou,isEditing:Xe,requestCommit:dt,startEdit:Qn,commitEdits:un,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,getClip:$r,discardClip:vt,isDragging:er,abortDrag:yu,findDataEdge:oe.findDataEdge,getEditingMode:Fe.getEditingMode,cancelEdit:Sl,onUndoRequest:Su,onRedoRequest:ku,onCellContextMenu:k,rowAxis:fe,colAxis:pe,handleRef:re,rearmSink:Qe,commands:vu,pointing:Fe,adapter:oe,hideNoteTip:()=>el.current(),closeRejectedMessage:Zn,pendingPasteOptionsRef:Zs,onPointFrame:du});const Eu=En.active.row,Au=En.active.col;i.useLayoutEffect(()=>{const w=Yt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[Eu,Au]),i.useLayoutEffect(()=>{Le()},[Le,An.row,An.column,An.intersection]);const Ou=i.useCallback(w=>{(Dt.current?.()??!1)||(w.preventDefault(),qe(),Qe())},[qe,Qe]),xu=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget,Q=P!==null&&!P.matches(":focus-visible");if(P!==null&&Z instanceof Node&&P.contains(Z)){w.target===P&&Z===ke.current&&!Ao.current&&Mt({preventScroll:Q});return}(Dt.current?.()??!1)||(Mt({preventScroll:Q}),Qe())},[Mt,Qe]),Tu=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget;P!==null&&Z instanceof Node&&P.contains(Z)||Fe.isFocusoutSuppressed()||$o(!1)},[Fe]),Dr=i.useRef(null),rr=i.useCallback(()=>{const w=Dr.current;w!==null&&(Dr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Fo=i.useCallback(()=>{if(Dr.current!==null)return;const w=Z=>{Z.pointerType==="mouse"&&(rr(),Z.button===1&&Z.preventDefault())},P=Z=>{Z.pointerType==="mouse"&&rr()};Dr.current={up:w,cancel:P},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",P,!0)},[rr]);i.useEffect(()=>rr,[rr]),i.useEffect(()=>{const w=X.current;if(ve||w===null)return;let P=0;const Z=be=>{if(be.pointerType!=="mouse"){(Dt.current?.()??!1)||$o(!1);return}P=be.buttons,be.button===1&&(be.target===ke.current&&(Dt.current?.()??!1)||Fo())},Q=be=>{be.pointerType==="mouse"&&(P=be.buttons)},de=be=>{if(be.pointerType!=="mouse"||be.buttons===P)return;const Ke=be.buttons&~P;P=be.buttons,be.preventDefault(),(Ke&4)!==0&&Fo()};return w.addEventListener("pointerdown",Z,!0),w.addEventListener("pointerup",Q,!0),w.addEventListener("pointermove",de,!0),()=>{w.removeEventListener("pointerdown",Z,!0),w.removeEventListener("pointerup",Q,!0),w.removeEventListener("pointermove",de,!0)}},[ve,Fo]);const $u=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(cn()){qe();return}if(Xe()&&!dt()){qe();return}qe()}},[qe,Xe,dt,cn]),Po=i.useRef(!1);i.useLayoutEffect(()=>{if(ve){Po.current=!1;return}if(Po.current)return;Po.current=!0,Qe();const w=(X.current?.clientHeight??0)/ne.current;w>0&&fe.totalSize()>0&&Ae.setRowRange(0,fe.indexAt(Math.min(w-1,fe.totalSize()-1)));const P=(X.current?.clientWidth??0)/ne.current;P>0&&pe.totalSize()>0&&Ae.setColRange(0,pe.indexAt(Math.min(P-1,pe.totalSize()-1)))},[ve,Qe,Ae,fe,pe]);const kl=i.useRef(t);i.useLayoutEffect(()=>{kl.current!==t&&(kl.current=t,ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag(),Fe.cancelEdit(),Yt.current?.hideTip(),Yt.current?.close(),ve?(Rt.current=Nn,Co(Nn)):We(Nn),hl.current())},[t,ve,We,ft,St,kt,et,pt,nt,Ae,Fe.cancelEdit]);const El=i.useRef({adapter:oe,rows:fe.count,cols:pe.count}),{getSessionCell:Al,cancelEdit:Ol}=Fe;i.useLayoutEffect(()=>{const w=El.current,P=fe.count,Z=pe.count;if(El.current={adapter:oe,rows:P,cols:Z},w.adapter!==oe||P>=w.rows&&Z>=w.cols)return;ve?(Rt.current=Nn,Co(Nn)):We(sw(Rt.current,P,Z)),ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag();const Q=tt=>ve||tt.row>=P||tt.col>=Z,de=Al();de!==null&&Q(de)&&Ol();const be=So.current;if(be.tip!==null&&Q(be.tip)&&Yt.current?.hideTip(),be.interactive!==null&&Q(be.interactive)){const tt=X.current?.contains(document.activeElement)===!0;Yt.current?.close({restoreFocus:tt})}const Ke=$r();Ke!==null&&!Ke.foreign&&Q({row:Ke.range.endRow,col:Ke.range.endCol})&&vt()},[oe,fe.count,pe.count,ve,We,ft,St,kt,et,pt,nt,Al,Ol,$r,vt]);const xl=i.useRef(c),Tl=i.useRef(u),$l=i.useRef(h),Ll=i.useRef(m);i.useLayoutEffect(()=>{(xl.current!==c||Tl.current!==u||$l.current!==h||Ll.current!==m)&&(xl.current=c,Tl.current=u,$l.current=h,Ll.current=m,ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag())},[c,u,h,m,ft,St,kt,et,pt,nt]),i.useLayoutEffect(()=>{at(),ut(),Le()},[c,u,h,m,at,ut,Le]);const Dl=i.useRef(p);i.useLayoutEffect(()=>{Dl.current!==p&&(Dl.current=p,vt())},[p,vt]),i.useLayoutEffect(()=>{Le()},[Le,En]);const dn=i.useCallback(()=>{const w=nl.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(yn,()=>({resizeRow:(w,P)=>{const Z=Math.round(P);fe.resize(w,Z),re.current?.updateRowSize(w,Z),Ae.bumpRowGeometry(),at(),Le(),xn(),zt()},resizeColumn:(w,P)=>{const Z=Math.round(P);pe.resize(w,Z),re.current?.updateColSize(w,Z),Ae.bumpColVersion(),ut(),Le(),xn(),zt()},autoFitColumns:w=>{for(const P of w)if(!Number.isInteger(P)||P<0||P>=pe.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${pe.count-1} (got ${String(P)})`);return et.autofitColumnsInAllRows(w)},scrollToCell:(w,P)=>{re.current?.scrollToCell(w.row,w.col,P)},focus:w=>{Mt(w),Xe()||Qe()},executeCommand:w=>ko.current(w),applyFormat:w=>dn().applyFormat(w),setBorders:(w,P)=>dn().setBorders(w,P),setHyperlink:w=>dn().setHyperlink(w),setNote:w=>dn().setNote(w),addComment:w=>dn().addComment(w),setValidation:w=>dn().setValidation(w),paste:w=>Eo.current(w),getSelection:()=>Rt.current,getBaseFormat:w=>oe.getCellFormat===void 0?void 0:oe.getCellFormat(w.row,w.col),getPaintedFormat:w=>oe.getCellFormat===void 0?void 0:B(w.row,w.col,Qr(oe,w.row,w.col)),startEdit:w=>{Qn(w)},openPopover:w=>{xr.current(w)}}),[fe,pe,Ae,ut,at,Le,xn,zt,et,Mt,Xe,Qe,oe,B,Qn,dn]),ve)return Y.jsx("div",{className:wt?`aqsp-root ${wt}`:"aqsp-root","data-aqsp-empty":"","data-testid":He});const Lu=a!==void 0||f!==void 0||E!==void 0||g!==void 0||d!==void 0,Du=o===void 0?{"aria-label":it.rootAriaLabel}:{"aria-labelledby":o};return Y.jsxs("div",{ref:X,className:wt?`aqsp-root ${wt}`:"aqsp-root",role:"group",...Du,tabIndex:0,onFocus:xu,onBlur:Tu,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-testid":He,children:[Y.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":se,onPointerDown:$u,style:se===1?void 0:{width:`${100/se}%`,height:`${100/se}%`,transform:`scale(${se})`,"--_aqsp-zoom":String(se)},children:[b?Y.jsxs(Y.Fragment,{children:[Y.jsx("div",{ref:Ce,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(cn()){qe();return}if(Xe()&&!dt()){qe();return}qe(),We({ranges:[Re({row:0,col:0},{row:oe.rowCount-1,col:oe.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),Y.jsx(Qg,{viewStore:Ae,colAxis:pe,frozenCols:c,frozenTrailingCols:h,handleRef:re,bandRef:Tt,colTrackRef:ct,windowOriginXRef:bt,repaintColHeaders:ut,selectionRanges:En.ranges,enableResizeUI:S,dividerLeadingRef:Kt,dividerTrailingRef:yt}),Y.jsx(ew,{viewStore:Ae,rowAxis:fe,handleRef:re,bandRef:$t,selectionRanges:En.ranges,rowTrackRef:Me,windowOriginYRef:Ct,repaintHeaders:at,enableResizeUI:S,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:Sn,dividerTrailingRef:kn})]}):null,Y.jsxs("div",{ref:ge,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[Y.jsx(Jg,{adapter:oe,rowAxis:fe,colAxis:pe,viewStore:Ae,handleRef:re,bodyRef:ce,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:m,headerRows:n,labelledBy:o,gridLabel:o===void 0?it.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:R,overscanRows:Gi("overscanRows",N),overscanCols:Gi("overscanCols",H),background:L,onRenderTruncated:_,renderCell:U,onScroll:au,onRangeChange:uu,focusSink:qe,isEditing:Xe,requestCommit:dt,testId:He?`${He}-vs`:void 0,__onCellRender:bn,__maxRenderedCells:Er,cfIndexRef:Gn,cfMemoRef:M,isPointing:cn,locale:Bt,scrollLabels:Rn}),Y.jsx(xm,{rowAxis:fe,colAxis:pe,handleRef:re,sinkRef:ke,getSelection:Lt,editing:Fe.editing,virtualKeyboard:lu,repaintRef:Ks,dragFrameRef:yo,getClip:$r,getIsDraggingAny:er,getIsFillDragging:pt.isDragging,fillFrameRef:wl,resizeGuideFrameRef:Cl,fillHandleNodeRef:bl,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:m,sinkAriaLabel:it.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Ar,onSinkMouseDown:Ou,editPaintRef:Gs,highlightRef:bo,highlightColors:tu,popoverAnchors:So,interactiveAnchorRef:Js,tipAnchorRef:Qs}),nr.layerEnabled?Y.jsx(Aw,{controller:nr,labels:it,renderPopover:me,interactiveAnchorRef:Js,tipAnchorRef:Qs}):null]}),Lu?Y.jsx("div",{ref:Bs,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),Y.jsx("div",{ref:he,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=qt.iterateTsvPrefixRows;exports.iterateTsvRows=qt.iterateTsvRows;exports.measureTsv=qt.measureTsv;exports.parseTsv=qt.parseTsv;exports.serializeClipboardTsv=qt.serializeClipboardTsv;exports.serializeTsv=qt.serializeTsv;exports.columnIndexToName=Te.columnIndexToName;exports.columnNameToIndex=Te.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Ss;exports.CommentPopover=Aa;exports.DEFAULT_CUSTOM_COLORS=Ja;exports.DEFAULT_HIGHLIGHT_COLORS=ka;exports.DEFAULT_SHORTCUTS=ua;exports.LinkPopover=Oa;exports.ListPopover=xa;exports.MessagePopover=Ta;exports.NotePopover=$a;exports.NoteTip=La;exports.SPREADSHEET_LABEL_CATALOGS=da;exports.SPREADSHEET_RESERVED_SHORTCUTS=Lh;exports.Spreadsheet=Kw;exports.canonicalizeFormat=gt;exports.detectClipSource=ac;exports.enumerateRangeCells=Jt;exports.estimatePasteCellCount=Ch;exports.expandPaste=bh;exports.formatCellValue=Wn;exports.formatEquals=Wu;exports.fromR1C1=Rr;exports.makeRange=Re;exports.mergeFormat=Es;exports.normalizeHyperlink=sn;exports.parseChord=Qt;exports.parseClipPayload=ls;exports.parseHtmlTable=ea;exports.rangeContains=Cn;exports.rangeSize=st;exports.resolveLabel=ze;exports.resolveLabels=fa;exports.serializeClipPayload=lc;exports.serializeHtmlTable=Gc;exports.shiftFormula=Mc;exports.toR1C1=uo;exports.validateCellText=ma;