@aiquants/spreadsheet 0.16.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +43 -6
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +53 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +4249 -4173
- package/dist/styles/spreadsheet.css +1 -1
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/package.json +1 -1
- package/src/Spreadsheet.tsx +280 -92
- package/src/header/useHeaderResize.ts +137 -68
- package/src/index.ts +1 -1
- package/src/styles/spreadsheet.css +20 -0
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Nt=require("./tsv.cjs"),Le=require("./view-BkwCUzTl.cjs"),Ge=require("@aiquants/virtualscroll"),Y=require("react/jsx-runtime"),i=require("react"),cs=1e3,tn=1e4,as=10,Cl=2**(1/4),gu=(e,t)=>e<=0?e:t>0?e>=tn?e:Math.min(tn,Math.max(e+1,Math.round(e*Cl))):Math.max(1,Math.min(e-1,Math.round(e/Cl))),yl=(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),us=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/as):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),tn))}let l=[...s].map(([u,p])=>({index:u,size:p}));if(e.count-e.hiddenCount()-yl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(p=>p.index===u?{index:p.index,size:1}:p)}if(r.axisKind==="row"){const u=e.hiddenCount()+yl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},ds="#000000",Er=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},wu=20,Cu=256,Ar=new Map,Oo=new WeakMap,it=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},yu=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},bu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:wu}:Er(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Er(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Er(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Er(e.decimals)};default:return null}},Ru=e=>{const t=Oo.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=Ar.get(n);if(r!==void 0)return Oo.set(e,r),r;Ar.size>=Cu&&Ar.clear();const o=bu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Ar.set(n,s),Oo.set(e,s),s},vu=(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}},_i=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>vu(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},ku=(e,t)=>{const n=_i(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)}})},qn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return ku(e,t.pattern??"yyyy/MM/dd");const n=it(e);if(n===null)return e;const r=Ru(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?yu(n,-2):n)},bl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?_i(n)!==null?"right":"left":it(n)!==null?"right":"left",ir=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",qi=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Su=["bottom","left","right","top"],ji=(e,t,n)=>{e[t]=n},Ii=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Eu=e=>{if(e===void 0)return;const t={};for(const n of Su){const r=e[n];r!==void 0&&(t[n]=Ii(r))}return Object.keys(t).length===0?void 0:t},yt=e=>{const t={};for(const n of qi){const r=n==="borders"?Eu(e.borders):n==="value"?e.value===void 0?void 0:Ii(e.value):e[n];r!==void 0&&r!==!1&&ji(t,n,r)}return Object.keys(t).length===0?void 0:t},fs=(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]||!fs(o[c],s[c]))return!1}return!0},Au=(e,t)=>e===t?!0:fs(e===void 0?void 0:yt(e),t===void 0?void 0:yt(t)),ps=(e,t)=>{const n={};for(const o of qi){const s=t[o];ji(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=yt(n);return fs(r,e===void 0?void 0:yt(e))?e:r},Hi="data-aqsp-clip",Yr="application/x-aqsp-clip",Ko=512,Rl=16*1024,Yo=`${Hi}=`,Ou=16,hs=()=>{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(Ou));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},hr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",Ue=e=>typeof e=="boolean",Zt=e=>typeof e=="number"&&Number.isFinite(e),Ct=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,vl=e=>Ct(e)&&e>=1,xu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=tn,Ft=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Tu=e=>t=>Array.isArray(t)&&t.every(e),Te=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),_t=(e,t)=>{if(!hr(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},ms=e=>t=>{if(!hr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&_t(t,n)},$u=["left","center","right"],Lu=["top","middle","bottom"],Du=["thin","medium","thick","dashed","dotted","double","hair"],xo=["gt","gte","lt","lte","eq","neq","between","notBetween"],Mu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],zu=["eq","neq","gt","gte","lt","lte","between","notBetween"],Fu=["contains","notContains","startsWith","endsWith"],Nu=new Map([["number",Te({type:le,decimals:Zt,grouping:Ue,locale:le},["type"])],["percent",Te({type:le,decimals:Zt,scale:Ue,locale:le},["type"])],["currency",Te({type:le,currency:le,decimals:Zt,locale:le},["type","currency"])],["scientific",Te({type:le,decimals:Zt,locale:le},["type"])],["date",Te({type:le,pattern:le},["type"])],["text",Te({type:le},["type"])]]),Pu=Te({style:Ft(Du),color:le},["style"]),Or=e=>_t(e,Pu),_u=Te({top:Or,right:Or,bottom:Or,left:Or},[]),qu=Te({value:ms(Nu),align:Ft($u),verticalAlign:Ft(Lu),wrap:Ue,background:le,color:le,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue,fontFamily:le,fontSize:Zt,borders:e=>_t(e,_u)},[]),ju=e=>_t(e,qu),un={strict:Ue,inputMessage:le,errorMessage:le},Iu=new Map([["list",Te({...un,type:le,values:Tu(le),showDropdown:Ue},["type","values"])],["number",Te({...un,type:le,op:Ft(xo),a:le,b:le},["type","op","a"])],["textLength",Te({...un,type:le,op:Ft(xo),a:Zt,b:Zt},["type","op","a"])],["date",Te({...un,type:le,op:Ft(xo),a:le,b:le},["type","op","a"])],["text",Te({...un,type:le,op:Ft(Mu),value:le},["type","op"])],["checkbox",Te({...un,type:le,checked:le,unchecked:le},["type"])],["custom",Te({...un,type:le,formula:le},["type","formula"])]]),Hu=ms(Iu),Bu=Te({startRow:Ct,startCol:Ct,endRow:Ct,endCol:Ct},["startRow","startCol","endRow","endCol"]),Vu=e=>{if(!_t(e,Bu))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return Ct(t)&&Ct(r)&&Ct(n)&&Ct(o)&&t<=r&&n<=o},Wu=Te({color:le,value:Zt},["color"]),To=e=>_t(e,Wu),Ku=new Map([["cellValue",Te({type:le,op:Ft(zu),a:le,b:le},["type","op","a"])],["text",Te({type:le,op:Ft(Fu),value:le},["type","op","value"])],["empty",Te({type:le},["type"])],["notEmpty",Te({type:le},["type"])],["colorScale",Te({type:le,min:To,mid:To,max:To},["type","min","max"])],["customFormula",Te({type:le,formula:le},["type","formula"])]]),Yu=Te({background:le,color:le,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue},[]),Uu=Te({sourceRuleId:le,ranges:Array.isArray,condition:ms(Ku),style:e=>_t(e,Yu),stopIfTrue:Ue},["sourceRuleId","ranges","condition","style"]),Xu=(e,t,n)=>{if(!_t(e,Uu))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Vu(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Gu=Te({text:le,author:le,createdAt:le},["text","author","createdAt"]),Zu=e=>_t(e,Gu),Ju=(e,t,n)=>{if(!hr(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(!Ct(o)||o>=t)return!1;break;case"val":if(!Ct(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(Zu)))return!1;break;default:return!1}}return!0},kl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(xu),Qu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Bi=e=>{if(!hr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Qu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(vl(t)&&vl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(ju)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Hu)))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(!Ju(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!kl(e.colWidths,n)||e.rowHeights!==void 0&&!kl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Xu(c,t,n))},dr=e=>Array.isArray(e)?`[${e.map(dr).join(",")}]`:hr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${dr(e[n])}`).join(",")}}`:JSON.stringify(e),ed=e=>{const t=yt(e);return t===void 0?"{}":JSON.stringify(t)},td=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,nd=e=>{let t=`{"t":${JSON.stringify(e.t)}`;return e.f!==void 0&&(t+=`,"f":${JSON.stringify(e.f)}`),e.fmt!==void 0&&(t+=`,"fmt":${e.fmt}`),e.val!==void 0&&(t+=`,"val":${e.val}`),e.note!==void 0&&(t+=`,"note":${JSON.stringify(e.note)}`),e.comments!==void 0&&(t+=`,"comments":[${e.comments.map(td).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Vi=e=>{if(!Bi(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(ed).join(","),r=e.validations.map(dr).join(","),o=e.cells.map(u=>`[${u.map(nd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(dr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Uo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Bi(t)?t:null},rd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,od=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),Wi=e=>e.includes("&")?e.replace(rd,t=>od[t]):e,sd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Sl=e=>{const t=e.length>Ko?e.slice(0,Ko):e,n=sd.exec(Wi(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},ld=e=>{const t=e.indexOf(Yo);if(t===-1)return null;const n=t+Yo.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Ki=(e,t)=>{if(t==="event"&&e.types.includes(Yr))return{kind:"mime",json:e.getData(Yr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=ld(n);return r===null?null:{kind:"attribute",html:n,at:r}},id=(e,t)=>{const n=Ki(e,t);return n===null?null:n.kind==="mime"?Sl(n.json):Sl(n.html.slice(n.at.start,n.at.start+Ko))},cd=(e,t)=>{const n=Ki(e,t);if(n===null)return null;if(n.kind==="mime")return Uo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Uo(Wi(n.html.slice(n.at.start,r)))},ad=/<google-sheets-html-origin[\s>]/,ud='data-sheets-root="1"',dd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,fd="mso-",pd=/\.xl\d+\s*\{/,hd="<table",md=e=>e.includes(Yo)?"aqsp":ad.test(e)&&e.includes(ud)?"sheets":dd.test(e)||e.includes(fd)||pd.test(e)?"excel":null,Yi=(e,t)=>{if(t==="event"&&e.types.includes(Yr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Rl?n.slice(0,Rl):n,o=md(r);if(o==="aqsp")return"aqsp";if(n.includes(hd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},gs=1e3,Ui=65534,gd=9,wd=10,Cd=12,yd=13,bd=32,Xi=34,Gi=39,Rd=43,ws=47,El=48,vd=57,kd=61,Sd=62,Ed=97,Ad=98,Od=100,xd=102,Zi=104,Ji=114,Qi=116,Td=["able","body","head","foot"],cr=e=>e===bd||e===gd||e===wd||e===yd||e===Cd,Xo=e=>e===Sd||e===ws||cr(e),$d=e=>cr(e)||e===ws||e===Xi||e===Gi,Ld=(e,t,n,r)=>{if(t===0||!$d(e.charCodeAt(t-1)))return null;let o=t+n;for(;cr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==kd)return 1;for(o+=1;cr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Xi||s===Gi)&&(o+=1);cr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Rd&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=El&&u<=vd;u=e.charCodeAt(o))l=l*10+(u-El),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Al=(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=Ld(e,r,t.length,n);if(l!==null)return l}return 1}},Dd=(e,t)=>{if(e.charCodeAt(t+2)!==Qi)return!1;const n=e.charCodeAt(t+3);if(n===Ji)return Xo(e.charCodeAt(t+4));if(n!==Ed&&n!==Ad&&n!==Zi&&n!==xd)return!1;for(const r of Td)if(e.startsWith(r,t+3)&&Xo(e.charCodeAt(t+3+r.length)))return!0;return!1},Md=e=>{const t=e.toLowerCase(),n=Al(t,"colspan",gs),r=Al(t,"rowspan",Ui);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,p=0,h=!1;const b=new Map,P=(_,U)=>{const W=b.get(_);b.set(_,W===void 0?U:W+U)},H=()=>{h&&u+p>c&&(c=u+p),h=!1},D=()=>{H(),l+=1,h=!0,u=0;const _=b.get(l-1);_!==void 0&&(p+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const U=t.charCodeAt(_+1);if(U===ws){Dd(t,_)&&H();continue}if(U!==Qi||!Xo(t.charCodeAt(_+3)))continue;const W=t.charCodeAt(_+2);if(W===Ji)D();else if(W===Od||W===Zi){h||D();const E=_+3,T=s(E),N=n(E,T);u+=N;const j=r(E,T);j>1&&(P(l,N),P(l-1+j,-N))}}return H(),{rows:l,cols:c}},ec=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}},tc=()=>{const e=new WeakMap,t=ec(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=yt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},zd=()=>{const e=new WeakMap,t=ec(dr);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}},Fd=new Set(["http:","https:","mailto:","tel:"]),nn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Fd.has(n.protocol)?n.href:null},Hn=e=>{if(e===void 0)return;const t=nn(e);return t===null?void 0:t},nc=(e,t)=>e.startCol===0&&e.endCol===t-1,rc=(e,t)=>e.startRow===0&&e.endRow===t-1,Go=13,zt=Object.freeze({style:Object.freeze({}),lineBoxPx:Go,verticalAlign:"middle"}),Nd={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"},Pd=new Map(Object.entries(Nd)),_d=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,qd=/^rgba?\((.*)\)$/,oc=/^(\d+(?:\.\d+)?)%$/,xr=e=>e.toString(16).padStart(2,"0"),$o=e=>{const t=oc.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},jd=e=>{const t=oc.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},Id=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=`#${xr(n)}${xr(r)}${xr(o)}`;if(t.length===3)return s;const l=jd(t[3]);return l===null?null:l===255?s:`${s}${xr(l)}`},Xe=e=>{const t=e.trim().toLowerCase(),n=_d.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 Id(r[1]);const o=Pd.get(t);return o===void 0?null:o},Ol={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"}},xl=e=>{if(!Object.hasOwn(Ol,e.style))return null;const t=Ol[e.style],n=e.color===void 0?ds:Xe(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Hd={top:"flex-start",middle:"center",bottom:"flex-end"},Bd=e=>e==="left"||e==="center"||e==="right",sc=e=>e==="top"||e==="middle"||e==="bottom",lc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,ic=(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=lc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Tr=(e,t)=>{const n=e===void 0?null:xl(e);return n!==null?n:t===void 0?null:xl(t)},Lo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Bd(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=ir(e.align)),sc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Hd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),ic(e,s));const c=e?.borders,u=Tr(c?.right,t);u!==null&&(s.borderRight=u);const p=Tr(c?.bottom,n);if(p!==null&&(s.borderBottom=p),r){const h=Tr(c?.left,void 0);h!==null&&(s.borderLeft=h)}if(o){const h=Tr(c?.top,void 0);h!==null&&(s.borderTop=h)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Tl=new WeakMap,Vd=(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:Lo(void 0,s,l,r,o);if(!c)return Lo(e,s,l,r,o);const u=Tl.get(e);if(u!==void 0)return u;const p=Lo(e,void 0,void 0,!1,!1);return Tl.set(e,p),p},Wd=e=>{if(e===void 0)return zt;const t={};ic(e,t);const n=lc(e.fontSize),r=n===null?Go:Math.round(n),o=sc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Go&&o==="middle"?zt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Kd="#REF!",Yd=11,Ud=15,Xd=4096,jr=33,ar=34,Cs=36,Gd=38,Zo=39,cc=40,Zd=42,Jd=43,Qd=44,ac=45,ef=46,tf=47,Fn=58,nf=59,rf=60,uc=61,of=62,sf=67,lf=82,Qr=91,dc=93,cf=94,af=95,fc=e=>e>=65&&e<=90||e>=97&&e<=122,pc=e=>e>=48&&e<=57,ys=e=>fc(e)||pc(e)||e===af||e===ef||e===Cs||e>=128,uf=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,df=e=>e===uc||e===cc||e===Qd||e===nf||e===Jd||e===ac||e===Zd||e===tf||e===cf||e===Gd||e===rf||e===of||e===Fn,hc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(ys(n)||n===cc||n===jr||n===Qr)},$l=(e,t)=>{let n=t;for(;n<e.length&&ys(e.charCodeAt(n));)n+=1;return n},Jo=(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},ff=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Zo){r+=2;continue}if(o===Qr)n+=1;else if(o===dc&&(n-=1,n===0))return r+1;r+=1}return e.length},Ll=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&hc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},mc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===ar){o=Jo(e,o,ar);continue}if(s===Zo){const u=Jo(e,o,Zo);o=e.charCodeAt(u)===jr?Ll(e,o,u,t,n):u;continue}if(s===Qr){o=ff(e,o);continue}if(!ys(s)){o+=1;continue}const l=t(e,o);if(l!==null&&hc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=$l(e,o);if(e.charCodeAt(c)===Fn){const u=$l(e,c+1);u>c+1&&e.charCodeAt(u)===jr&&(c=u)}o=e.charCodeAt(c)===jr?Ll(e,o,c,t,n):c}return n},Do=(e,t)=>{let n=t;const r=e.charCodeAt(n)===Cs;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!fc(l))break;if(s+=1,s>Yd)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Qo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!pc(o))break;if(n-t>=Ud)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},$r=(e,t)=>{const n=e.charCodeAt(t)===Cs,r=Qo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},pf=(e,t)=>{const n=Do(e,t);if(n!==null){const o=$r(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Fn){const s=Do(e,o.end+1);if(s!==null){const l=$r(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)===Fn){const s=Do(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=$r(e,t);if(r!==null&&e.charCodeAt(r.end)===Fn){const o=$r(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},mr=e=>mc(e,pf),gc=(e,t=Xd)=>{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}},es=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},Mo=e=>`${e.absCol?"$":""}${es(e.col)}${e.absRow?"$":""}${e.row+1}`,bs=e=>e.sheet===void 0?"":`${e.sheet}!`,Jt=e=>{const t=bs(e);switch(e.kind){case"cell":return`${t}${Mo(e)}`;case"range":return`${t}${Mo(e.start)}:${Mo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${es(e.start.col)}:${e.end.abs?"$":""}${es(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},$n=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},hf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch($n(n.startRow,"formatRangeReference startRow"),$n(n.startCol,"formatRangeReference startCol"),$n(n.endRow,"formatRangeReference endRow"),$n(n.endCol,"formatRangeReference endCol"),t){case"columns":return Jt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return Jt({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?Jt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):Jt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Rs=(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?`${bs(s.token)}${Kd}`:l),o=s.end}return r+e.slice(o)},eo=e=>e.charCodeAt(0)===uc,zo=(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}},mf=(e,t,n)=>{switch(e.kind){case"cell":{const r=zo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=zo(e.start,t,n),o=zo(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}}}}},wc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return eo(e)?Rs(e,mr(e),r=>{const o=mf(r,t,n);return o===null?null:Jt(o)}):e},Cc=(e,t)=>{$n(e.row,`${t} origin.row`),$n(e.col,`${t} origin.col`)},Ln=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Fo=(e,t)=>`${Ln("R",e.row,e.absRow,t.row)}${Ln("C",e.col,e.absCol,t.col)}`,gf=(e,t)=>{const n=bs(e);switch(e.kind){case"cell":return`${n}${Fo(e,t)}`;case"range":return`${n}${Fo(e.start,t)}:${Fo(e.end,t)}`;case"column":return`${n}${Ln("C",e.start.col,e.start.abs,t.col)}:${Ln("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Ln("R",e.start.row,e.start.abs,t.row)}:${Ln("R",e.end.row,e.end.abs,t.row)}`}},to=(e,t)=>(Cc(t,"toR1C1"),eo(e)?Rs(e,mr(e),n=>gf(n,t)):e),Dl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Qr){const l=e.charCodeAt(o+1)===ac,c=Qo(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==dc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Qo(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}}},Ml=(e,t)=>{const n=Dl(e,t,lf),r=Dl(e,n===null?t:n.end,sf);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}},wf=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}}},Cf=(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,yf=(e,t)=>{const n=Ml(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Fn){const r=Ml(e,n.end+1);if(r!==null){const o=Cf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:wf(n)}},bf=e=>mc(e,yf),Rf=gc(bf),Dn=(e,t)=>e.rel?t+e.n:e.n-1,zl=(e,t)=>{const n=Dn(e.row,t.row),r=Dn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},vf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=zl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=zl(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=Dn(e.start,t.row),s=Dn(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=Dn(e.start,t.col),s=Dn(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}}}},gr=(e,t)=>(Cc(t,"fromR1C1"),eo(e)?Rs(e,Rf(e),n=>{const r=vf(n,t);return r===null?null:Jt(r)}):e),Fl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},kf=e=>{switch(e.kind){case"cell":return{...e,...Fl(e.absCol,e.absRow)};case"range":{const t=Fl(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}}}}},yc=(e,t)=>eo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,bc=(e,t)=>{if(!yc(e,t))return null;for(const n of mr(e))if(n.start<=t&&t<=n.end)return n;return null},Sf=(e,t)=>{const n=bc(e,t);if(n===null)return null;const r=Jt(kf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Nl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===ar){const s=Jo(e,r,ar);if(s>t)return!1;n=ar,r=s;continue}uf(o)||(n=o),r+=1}return df(n)},Rc=(e,t)=>{if(!yc(e,t))return null;for(const n of mr(e))if(n.start<=t&&t<=n.end)return Nl(e,n.start)?{replace:[n.start,n.end]}:null;return Nl(e,t)?{insertAt:t}:null},jn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],no=(e,t)=>`[$${e}-${t}]`,Ef=new Map(jn.map(e=>[no(e.symbol,e.lcid),e])),Af=new Map(jn.filter((e,t)=>jn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(jn.map(e=>[no(e.symbol,e.lcid),e.code]));const Of=new Set([...jn.map(e=>e.symbol),...jn.map(e=>e.code),"¥"]),xf=20,Tf="yyyy/MM/dd",vc=/yyyy|MM|dd|HH|mm|ss/g,kc=" -+/():!^&'~{}<>=",$f="$¥€£₩₹¥",ts=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},Lf=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},Df=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("-"),p=u<0?c:c.slice(0,u),h=u<0?null:c.slice(u+1);if(h!==null&&!/^[0-9a-fA-F]{1,8}$/.test(h)||p===""&&h===null)return null;const b=h===null?null:Number.parseInt(h,16).toString(16);t.push(p===""?{kind:"locale"}:{kind:"currency",symbol:p,lcid:b}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(kc.includes(o)||$f.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},wt=e=>e===void 0?{}:{locale:e},Mf=/^(0|#,##0)(?:\.(0+))?$/,Pl=(e,t,n,r)=>{if(t!==null){const o=Ef.get(no(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Of.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...wt(r.locale)}},zf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const D of e)switch(D.kind){case"locale":break;case"literal":r?u+=D.text:c+=D.text;break;case"digits":if(r)return;n=D.text,r=!0;break;case"currency":if(o!==null)return;o=D;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const p=Mf.exec(n);if(p===null)return;const h=p[1]==="#,##0",b=p[2]===void 0?0:p[2].length,P=c.trim(),H=u.trim();if(s)return l===0&&o===null&&!h&&P===""&&H===""?{type:"scientific",decimals:b,...wt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&P===""&&H===""?{type:"percent",decimals:b,...wt(t.locale)}:void 0;if(H==="%"&&P===""&&o===null)return{type:"percent",decimals:b,scale:!1,...wt(t.locale)};if(o!==null)return P===""&&H===""?Pl(o.symbol,o.lcid,b,t):void 0;if(!(P!==""&&H!==""))return P!==""||H!==""?Pl(P+H,null,b,t):{type:"number",decimals:b,...h?{grouping:!0}:{},...wt(t.locale)}},Ff=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Nf=(e,t)=>{const n=[...e.matchAll(vc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Pf=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":Ff.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Nf(r,n)?{type:"date",pattern:r}:void 0},_f=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...wt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...wt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...wt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...wt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...wt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...wt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),vs=(e,t)=>{const n=Lf(e).trim(),r=_f.get(n);if(r!==void 0)return r(t);const o=Df(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return zf(o,t);if(o.some(s=>s.kind==="date"))return Pf(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:vs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},or=e=>e===0?"":`.${"0".repeat(e)}`,Ir=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=xf,jf=`${kc}.,`,_l=e=>e.includes('"')?null:[...e].every(t=>jf.includes(t))?e:`"${e}"`,If=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(vc)){const u=_l(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=_l(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=vs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Hf=e=>{const t=Af.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Ir(n))return null;const r=`#,##0${or(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${no(t.symbol,t.lcid)}${r}`},Sc=e=>{switch(e.type){case"text":return"@";case"date":return If(e.pattern===void 0?Tf:e.pattern);case"number":return Ir(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${or(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Ir(t)?e.scale===!1?`0${or(t)}"%"`:`0${or(t)}%`:null}case"scientific":return Ir(e.decimals)?`0${or(e.decimals)}E+00`:null;case"currency":return Hf(e);default:return null}},ql="-−",Bf=(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("")},Vf=(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 p=Bf(c[0],t);return p===null?null:{integer:p,fraction:u,exponent:l}},Wf=(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},Kf=(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=N=>N>="0"&&N<="9"||l!==""&&l.includes(N)||n.decimal.includes(N)||c&&(N==="e"||N==="E");let p=0;for(;p<o.length&&!u(o[p]);)p+=1;let h=o.length;for(;h>p&&!u(o[h-1]);)h-=1;let b=0,P=0,H=0,D="";for(const N of o.slice(0,p))ql.includes(N)?b+=1:N==="("?P+=1:D+=N;for(const N of o.slice(h))ql.includes(N)?b+=1:N===")"?H+=1:D+=N;const _=b+P;if(P!==H||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&D.trim()!==""))return e;const U=Vf(o.slice(p,h).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,E=U.exponent+W;if(E>330||E<-330)return e;const T=Wf(U.integer,U.fraction,E,s);return Number.isFinite(Number(T))?T:e},jl="google-sheets-html-origin",Ec=Object.freeze({group:",",decimal:"."}),Il=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"}),Ac=["top","right","bottom","left"],Yf=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Uf=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Xf=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"]),Hl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Gf=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Zf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Jf=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"]),Qf=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),ep=3,tp=1,Oc=-25569,Hr=86400,np=-693959,rp=2958465,op=" ",ro=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 p=c.slice(0,u).trim().toLowerCase(),h=c.slice(u+1).trim();p!==""&&h!==""&&t.set(p,h)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},Ur=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},ks=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},sp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,lp=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 p=l.indexOf("}",u+1);if(p===-1)break;const h=l.slice(c,u),b=l.slice(u+1,p);if(c=p+1,h.trim().startsWith("@"))continue;const P=ro(b);for(const H of h.split(",")){const D=H.trim(),_=sp.exec(D);if(_!==null){const U=t.get(_[1]);if(U===void 0)t.set(_[1],new Map(P));else for(const[W,E]of P)U.set(W,E)}else if(D.toLowerCase()==="table"){const U=P.get("mso-displayed-decimal-separator"),W=P.get("mso-displayed-thousand-separator");U!==void 0&&(n=ts(Ur(U))),W!==void 0&&(r=ts(Ur(W)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Ec}},ip="%_-*? ",cp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||ip.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},ap=(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},xc=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}},On=(e,t)=>String(e).padStart(t,"0"),Tc=e=>{if(e<np||e>rp)return null;let t=Math.floor(e),n=Math.round((e-t)*Hr);n>=Hr&&(t+=1,n-=Hr);const r=xc(t+Oc),o=`${On(r.year,4)}-${On(r.month,2)}-${On(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${On(s,2)}:${On(l,2)}:${On(n%60,2)}`},up=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,dp=e=>{const t=up.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=ap(n,r,o),p=xc(u);return p.year!==n||p.month!==r||p.day!==o?null:u-Oc+(s*3600+l*60+c)/Hr},Ss=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),dn=e=>Ss(e).replaceAll('"',"""),$c=e=>Ss(e).replaceAll("'","'"),fp=e=>Ss(e).replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Nt=require("./tsv.cjs"),xe=require("./view-BkwCUzTl.cjs"),Ue=require("@aiquants/virtualscroll"),Y=require("react/jsx-runtime"),i=require("react"),gs=1e3,en=1e4,ws=10,Tl=2**(1/4),Ou=(e,t)=>e<=0?e:t>0?e>=en?e:Math.min(en,Math.max(e+1,Math.round(e*Tl))):Math.max(1,Math.min(e-1,Math.round(e/Tl))),$l=(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),en))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-$l(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()+$l(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},bs="#000000",Lr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},xu=20,Tu=256,Dr=new Map,Fo=new WeakMap,nt=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}`},Lu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:xu}:Lr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Lr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Lr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Lr(e.decimals)};default:return null}},Du=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>=Tu&&Dr.clear();const o=Lu(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},Mu=(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}},Xi=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>Mu(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},zu=(e,t)=>{const n=Xi(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)}})},jn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return zu(e,t.pattern??"yyyy/MM/dd");const n=nt(e);if(n===null)return e;const r=Du(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?$u(n,-2):n)},Ll=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Xi(n)!==null?"right":"left":nt(n)!==null?"right":"left",ar=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Gi=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Fu=["bottom","left","right","top"],Zi=(e,t,n)=>{e[t]=n},Ji=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Nu=e=>{if(e===void 0)return;const t={};for(const n of Fu){const r=e[n];r!==void 0&&(t[n]=Ji(r))}return Object.keys(t).length===0?void 0:t},gt=e=>{const t={};for(const n of Gi){const r=n==="borders"?Nu(e.borders):n==="value"?e.value===void 0?void 0:Ji(e.value):e[n];r!==void 0&&r!==!1&&Zi(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},Pu=(e,t)=>e===t?!0:ys(e===void 0?void 0:gt(e),t===void 0?void 0:gt(t)),Rs=(e,t)=>{const n={};for(const o of Gi){const s=t[o];Zi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=gt(n);return ys(r,e===void 0?void 0:gt(e))?e:r},Qi="data-aqsp-clip",Qr="application/x-aqsp-clip",es=512,Dl=16*1024,ts=`${Qi}=`,_u=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(_u));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},gr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",Ke=e=>typeof e=="boolean",Gt=e=>typeof e=="number"&&Number.isFinite(e),mt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Ml=e=>mt(e)&&e>=1,qu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=en,Ft=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Iu=e=>t=>Array.isArray(t)&&t.every(e),Te=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),_t=(e,t)=>{if(!gr(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(!gr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&_t(t,n)},ju=["left","center","right"],Hu=["top","middle","bottom"],Bu=["thin","medium","thick","dashed","dotted","double","hair"],No=["gt","gte","lt","lte","eq","neq","between","notBetween"],Vu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Wu=["eq","neq","gt","gte","lt","lte","between","notBetween"],Ku=["contains","notContains","startsWith","endsWith"],Yu=new Map([["number",Te({type:ae,decimals:Gt,grouping:Ke,locale:ae},["type"])],["percent",Te({type:ae,decimals:Gt,scale:Ke,locale:ae},["type"])],["currency",Te({type:ae,currency:ae,decimals:Gt,locale:ae},["type","currency"])],["scientific",Te({type:ae,decimals:Gt,locale:ae},["type"])],["date",Te({type:ae,pattern:ae},["type"])],["text",Te({type:ae},["type"])]]),Uu=Te({style:Ft(Bu),color:ae},["style"]),Mr=e=>_t(e,Uu),Xu=Te({top:Mr,right:Mr,bottom:Mr,left:Mr},[]),Gu=Te({value:ks(Yu),align:Ft(ju),verticalAlign:Ft(Hu),wrap:Ke,background:ae,color:ae,bold:Ke,italic:Ke,underline:Ke,strikethrough:Ke,fontFamily:ae,fontSize:Gt,borders:e=>_t(e,Xu)},[]),Zu=e=>_t(e,Gu),un={strict:Ke,inputMessage:ae,errorMessage:ae},Ju=new Map([["list",Te({...un,type:ae,values:Iu(ae),showDropdown:Ke},["type","values"])],["number",Te({...un,type:ae,op:Ft(No),a:ae,b:ae},["type","op","a"])],["textLength",Te({...un,type:ae,op:Ft(No),a:Gt,b:Gt},["type","op","a"])],["date",Te({...un,type:ae,op:Ft(No),a:ae,b:ae},["type","op","a"])],["text",Te({...un,type:ae,op:Ft(Vu),value:ae},["type","op"])],["checkbox",Te({...un,type:ae,checked:ae,unchecked:ae},["type"])],["custom",Te({...un,type:ae,formula:ae},["type","formula"])]]),Qu=ks(Ju),ed=Te({startRow:mt,startCol:mt,endRow:mt,endCol:mt},["startRow","startCol","endRow","endCol"]),td=e=>{if(!_t(e,ed))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},nd=Te({color:ae,value:Gt},["color"]),Po=e=>_t(e,nd),rd=new Map([["cellValue",Te({type:ae,op:Ft(Wu),a:ae,b:ae},["type","op","a"])],["text",Te({type:ae,op:Ft(Ku),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"])]]),od=Te({background:ae,color:ae,bold:Ke,italic:Ke,underline:Ke,strikethrough:Ke},[]),sd=Te({sourceRuleId:ae,ranges:Array.isArray,condition:ks(rd),style:e=>_t(e,od),stopIfTrue:Ke},["sourceRuleId","ranges","condition","style"]),ld=(e,t,n)=>{if(!_t(e,sd))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!td(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},id=Te({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),cd=e=>_t(e,id),ad=(e,t,n)=>{if(!gr(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(cd)))return!1;break;default:return!1}}return!0},zl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(qu),ud=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),ec=e=>{if(!gr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!ud.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Ml(t)&&Ml(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Zu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Qu)))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(!ad(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!zl(e.colWidths,n)||e.rowHeights!==void 0&&!zl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>ld(c,t,n))},pr=e=>Array.isArray(e)?`[${e.map(pr).join(",")}]`:gr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${pr(e[n])}`).join(",")}}`:JSON.stringify(e),dd=e=>{const t=gt(e);return t===void 0?"{}":JSON.stringify(t)},fd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,pd=e=>{let t=`{"t":${JSON.stringify(e.t)}`;return e.f!==void 0&&(t+=`,"f":${JSON.stringify(e.f)}`),e.fmt!==void 0&&(t+=`,"fmt":${e.fmt}`),e.val!==void 0&&(t+=`,"val":${e.val}`),e.note!==void 0&&(t+=`,"note":${JSON.stringify(e.note)}`),e.comments!==void 0&&(t+=`,"comments":[${e.comments.map(fd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},tc=e=>{if(!ec(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(dd).join(","),r=e.validations.map(pr).join(","),o=e.cells.map(u=>`[${u.map(pd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(pr).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 ec(t)?t:null},hd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,md=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),nc=e=>e.includes("&")?e.replace(hd,t=>md[t]):e,gd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Fl=e=>{const t=e.length>es?e.slice(0,es):e,n=gd.exec(nc(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},wd=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}},rc=(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=wd(n);return r===null?null:{kind:"attribute",html:n,at:r}},Cd=(e,t)=>{const n=rc(e,t);return n===null?null:n.kind==="mime"?Fl(n.json):Fl(n.html.slice(n.at.start,n.at.start+es))},bd=(e,t)=>{const n=rc(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(nc(n.html.slice(n.at.start,r)))},yd=/<google-sheets-html-origin[\s>]/,Rd='data-sheets-root="1"',vd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,kd="mso-",Sd=/\.xl\d+\s*\{/,Ed="<table",Ad=e=>e.includes(ts)?"aqsp":yd.test(e)&&e.includes(Rd)?"sheets":vd.test(e)||e.includes(kd)||Sd.test(e)?"excel":null,oc=(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>Dl?n.slice(0,Dl):n,o=Ad(r);if(o==="aqsp")return"aqsp";if(n.includes(Ed))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Ss=1e3,sc=65534,Od=9,xd=10,Td=12,$d=13,Ld=32,lc=34,ic=39,Dd=43,Es=47,Nl=48,Md=57,zd=61,Fd=62,Nd=97,Pd=98,_d=100,qd=102,cc=104,ac=114,uc=116,Id=["able","body","head","foot"],ur=e=>e===Ld||e===Od||e===xd||e===$d||e===Td,rs=e=>e===Fd||e===Es||ur(e),jd=e=>ur(e)||e===Es||e===lc||e===ic,Hd=(e,t,n,r)=>{if(t===0||!jd(e.charCodeAt(t-1)))return null;let o=t+n;for(;ur(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==zd)return 1;for(o+=1;ur(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===lc||s===ic)&&(o+=1);ur(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Dd&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=Nl&&u<=Md;u=e.charCodeAt(o))l=l*10+(u-Nl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Pl=(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=Hd(e,r,t.length,n);if(l!==null)return l}return 1}},Bd=(e,t)=>{if(e.charCodeAt(t+2)!==uc)return!1;const n=e.charCodeAt(t+3);if(n===ac)return rs(e.charCodeAt(t+4));if(n!==Nd&&n!==Pd&&n!==cc&&n!==qd)return!1;for(const r of Id)if(e.startsWith(r,t+3)&&rs(e.charCodeAt(t+3+r.length)))return!0;return!1},Vd=e=>{const t=e.toLowerCase(),n=Pl(t,"colspan",Ss),r=Pl(t,"rowspan",sc);let o=0;const s=P=>(o!==-1&&o<P&&(o=t.indexOf(">",P)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,g=!1;const R=new Map,F=(P,U)=>{const W=R.get(P);R.set(P,W===void 0?U:W+U)},H=()=>{g&&u+h>c&&(c=u+h),g=!1},L=()=>{H(),l+=1,g=!0,u=0;const P=R.get(l-1);P!==void 0&&(h+=P)};for(let P=t.indexOf("<");P!==-1;P=t.indexOf("<",P+1)){const U=t.charCodeAt(P+1);if(U===Es){Bd(t,P)&&H();continue}if(U!==uc||!rs(t.charCodeAt(P+3)))continue;const W=t.charCodeAt(P+2);if(W===ac)L();else if(W===_d||W===cc){g||L();const S=P+3,x=s(S),z=n(S,x);u+=z;const q=r(S,x);q>1&&(F(l,z),F(l-1+q,-z))}}return H(),{rows:l,cols:c}},dc=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),l=n.get(s);if(l!==void 0)return l;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},fc=()=>{const e=new WeakMap,t=dc(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}},Wd=()=>{const e=new WeakMap,t=dc(pr);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}},Kd=new Set(["http:","https:","mailto:","tel:"]),tn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Kd.has(n.protocol)?n.href:null},Vn=e=>{if(e===void 0)return;const t=tn(e);return t===null?void 0:t},pc=(e,t)=>e.startCol===0&&e.endCol===t-1,hc=(e,t)=>e.startRow===0&&e.endRow===t-1,os=13,zt=Object.freeze({style:Object.freeze({}),lineBoxPx:os,verticalAlign:"middle"}),Yd={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"},Ud=new Map(Object.entries(Yd)),Xd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Gd=/^rgba?\((.*)\)$/,mc=/^(\d+(?:\.\d+)?)%$/,zr=e=>e.toString(16).padStart(2,"0"),_o=e=>{const t=mc.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},Zd=e=>{const t=mc.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},Jd=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=Zd(t[3]);return l===null?null:l===255?s:`${s}${zr(l)}`},Ye=e=>{const t=e.trim().toLowerCase(),n=Xd.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=Gd.exec(t);if(r!==null)return Jd(r[1]);const o=Ud.get(t);return o===void 0?null:o},_l={thin:{width:1,line:"solid"},medium:{width:2,line:"solid"},thick:{width:3,line:"solid"},dashed:{width:1,line:"dashed"},dotted:{width:1,line:"dotted"},double:{width:3,line:"double"},hair:{width:1,line:"dotted"}},ql=e=>{if(!Object.hasOwn(_l,e.style))return null;const t=_l[e.style],n=e.color===void 0?bs:Ye(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Qd={top:"flex-start",middle:"center",bottom:"flex-end"},ef=e=>e==="left"||e==="center"||e==="right",gc=e=>e==="top"||e==="middle"||e==="bottom",wc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Cc=(e,t)=>{if(typeof e.background=="string"){const s=Ye(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ye(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=wc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Fr=(e,t)=>{const n=e===void 0?null:ql(e);return n!==null?n:t===void 0?null:ql(t)},qo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(ef(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=ar(e.align)),gc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Qd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Cc(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)})},Il=new WeakMap,tf=(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=Il.get(e);if(u!==void 0)return u;const h=qo(e,void 0,void 0,!1,!1);return Il.set(e,h),h},nf=e=>{if(e===void 0)return zt;const t={};Cc(e,t);const n=wc(e.fontSize),r=n===null?os:Math.round(n),o=gc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===os&&o==="middle"?zt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},rf="#REF!",of=11,sf=15,lf=4096,Kr=33,dr=34,As=36,cf=38,ss=39,bc=40,af=42,uf=43,df=44,yc=45,ff=46,pf=47,Pn=58,hf=59,mf=60,Rc=61,gf=62,wf=67,Cf=82,so=91,vc=93,bf=94,yf=95,kc=e=>e>=65&&e<=90||e>=97&&e<=122,Sc=e=>e>=48&&e<=57,Os=e=>kc(e)||Sc(e)||e===yf||e===ff||e===As||e>=128,Rf=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,vf=e=>e===Rc||e===bc||e===df||e===hf||e===uf||e===yc||e===af||e===pf||e===bf||e===cf||e===mf||e===gf||e===Pn,Ec=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Os(n)||n===bc||n===Kr||n===so)},jl=(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},kf=(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===vc&&(n-=1,n===0))return r+1;r+=1}return e.length},Hl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Ec(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Ac=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===dr){o=ls(e,o,dr);continue}if(s===ss){const u=ls(e,o,ss);o=e.charCodeAt(u)===Kr?Hl(e,o,u,t,n):u;continue}if(s===so){o=kf(e,o);continue}if(!Os(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Ec(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=jl(e,o);if(e.charCodeAt(c)===Pn){const u=jl(e,c+1);u>c+1&&e.charCodeAt(u)===Kr&&(c=u)}o=e.charCodeAt(c)===Kr?Hl(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(!kc(l))break;if(s+=1,s>of)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(!Sc(o))break;if(n-t>=sf)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}},Sf=(e,t)=>{const n=Io(e,t);if(n!==null){const o=Nr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Pn){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)===Pn){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)===Pn){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},wr=e=>Ac(e,Sf),Oc=(e,t=lf)=>{if(!Number.isInteger(t)||t<=0)throw new RangeError(`[spreadsheet] createFormulaMemo requires a positive integer limit, received ${t}`);const n=new Map;return r=>{const o=n.get(r);if(o!==void 0)return o;n.size>=t&&n.clear();const s=e(r);return n.set(r,s),s}},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}!`,Zt=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}`}},Dn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Ef=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Dn(n.startRow,"formatRangeReference startRow"),Dn(n.startCol,"formatRangeReference startCol"),Dn(n.endRow,"formatRangeReference endRow"),Dn(n.endCol,"formatRangeReference endCol"),t){case"columns":return Zt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return Zt({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?Zt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):Zt({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)}${rf}`:l),o=s.end}return r+e.slice(o)},lo=e=>e.charCodeAt(0)===Rc,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}},Af=(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}}}}},xc=(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,wr(e),r=>{const o=Af(r,t,n);return o===null?null:Zt(o)}):e},Tc=(e,t)=>{Dn(e.row,`${t} origin.row`),Dn(e.col,`${t} origin.col`)},Mn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Bo=(e,t)=>`${Mn("R",e.row,e.absRow,t.row)}${Mn("C",e.col,e.absCol,t.col)}`,Of=(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}${Mn("C",e.start.col,e.start.abs,t.col)}:${Mn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Mn("R",e.start.row,e.start.abs,t.row)}:${Mn("R",e.end.row,e.end.abs,t.row)}`}},io=(e,t)=>(Tc(t,"toR1C1"),lo(e)?Ts(e,wr(e),n=>Of(n,t)):e),Bl=(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)===yc,c=is(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==vc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=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}}},Vl=(e,t)=>{const n=Bl(e,t,Cf),r=Bl(e,n===null?t:n.end,wf);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}},xf=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}}},Tf=(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=Vl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Pn){const r=Vl(e,n.end+1);if(r!==null){const o=Tf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:xf(n)}},Lf=e=>Ac(e,$f),Df=Oc(Lf),zn=(e,t)=>e.rel?t+e.n:e.n-1,Wl=(e,t)=>{const n=zn(e.row,t.row),r=zn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Mf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Wl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Wl(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=zn(e.start,t.row),s=zn(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=zn(e.start,t.col),s=zn(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}}}},Cr=(e,t)=>(Tc(t,"fromR1C1"),lo(e)?Ts(e,Df(e),n=>{const r=Mf(n,t);return r===null?null:Zt(r)}):e),Kl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},zf=e=>{switch(e.kind){case"cell":return{...e,...Kl(e.absCol,e.absRow)};case"range":{const t=Kl(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}}}}},$c=(e,t)=>lo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Lc=(e,t)=>{if(!$c(e,t))return null;for(const n of wr(e))if(n.start<=t&&t<=n.end)return n;return null},Ff=(e,t)=>{const n=Lc(e,t);if(n===null)return null;const r=Zt(zf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Yl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===dr){const s=ls(e,r,dr);if(s>t)return!1;n=dr,r=s;continue}Rf(o)||(n=o),r+=1}return vf(n)},Dc=(e,t)=>{if(!$c(e,t))return null;for(const n of wr(e))if(n.start<=t&&t<=n.end)return Yl(e,n.start)?{replace:[n.start,n.end]}:null;return Yl(e,t)?{insertAt:t}:null},Hn=[{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}]`,Nf=new Map(Hn.map(e=>[co(e.symbol,e.lcid),e])),Pf=new Map(Hn.filter((e,t)=>Hn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Hn.map(e=>[co(e.symbol,e.lcid),e.code]));const _f=new Set([...Hn.map(e=>e.symbol),...Hn.map(e=>e.code),"¥"]),qf=20,If="yyyy/MM/dd",Mc=/yyyy|MM|dd|HH|mm|ss/g,zc=" -+/():!^&'~{}<>=",jf="$¥€£₩₹¥",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},Hf=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},Bf=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(zc.includes(o)||jf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ht=e=>e===void 0?{}:{locale:e},Vf=/^(0|#,##0)(?:\.(0+))?$/,Ul=(e,t,n,r)=>{if(t!==null){const o=Nf.get(co(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!_f.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ht(r.locale)}},Wf=(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=Vf.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,...ht(t.locale)}:void 0;if(l>0)return l===1&&o===null&&F===""&&H===""?{type:"percent",decimals:R,...ht(t.locale)}:void 0;if(H==="%"&&F===""&&o===null)return{type:"percent",decimals:R,scale:!1,...ht(t.locale)};if(o!==null)return F===""&&H===""?Ul(o.symbol,o.lcid,R,t):void 0;if(!(F!==""&&H!==""))return F!==""||H!==""?Ul(F+H,null,R,t):{type:"number",decimals:R,...g?{grouping:!0}:{},...ht(t.locale)}},Kf=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Yf=(e,t)=>{const n=[...e.matchAll(Mc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Uf=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":Kf.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Yf(r,n)?{type:"date",pattern:r}:void 0},Xf=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"})]]),$s=(e,t)=>{const n=Hf(e).trim(),r=Xf.get(n);if(r!==void 0)return r(t);const o=Bf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Wf(o,t);if(o.some(s=>s.kind==="date"))return Uf(o)}},Gf=(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:$s(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},lr=e=>e===0?"":`.${"0".repeat(e)}`,Yr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=qf,Zf=`${zc}.,`,Xl=e=>e.includes('"')?null:[...e].every(t=>Zf.includes(t))?e:`"${e}"`,Jf=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Mc)){const u=Xl(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=Xl(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=$s(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Qf=e=>{const t=Pf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Yr(n))return null;const r=`#,##0${lr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${co(t.symbol,t.lcid)}${r}`},Fc=e=>{switch(e.type){case"text":return"@";case"date":return Jf(e.pattern===void 0?If:e.pattern);case"number":return Yr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${lr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Yr(t)?e.scale===!1?`0${lr(t)}"%"`:`0${lr(t)}%`:null}case"scientific":return Yr(e.decimals)?`0${lr(e.decimals)}E+00`:null;case"currency":return Qf(e);default:return null}},Gl="-−",ep=(e,t)=>{if(t===""||!e.includes(t))return/^\d+$/.test(e)?e:null;const n=e.split(t);return!/^\d{1,3}$/.test(n[0])||n.slice(1).some(r=>!/^\d{3}$/.test(r))?null:n.join("")},tp=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=ep(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},np=(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},rp=(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,L="";for(const z of o.slice(0,h))Gl.includes(z)?R+=1:z==="("?F+=1:L+=z;for(const z of o.slice(g))Gl.includes(z)?R+=1:z===")"?H+=1:L+=z;const P=R+F;if(F!==H||P>1||P===1&&s||(s=s||P===1,r!=="currency"&&L.trim()!==""))return e;const U=tp(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=np(U.integer,U.fraction,S,s);return Number.isFinite(Number(x))?x:e},Zl="google-sheets-html-origin",Nc=Object.freeze({group:",",decimal:"."}),Jl=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"}),Pc=["top","right","bottom","left"],op=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),sp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),lp=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"]),Ql=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],ip=Object.freeze({number:2,percent:3,currency:4,scientific:8}),cp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),ap=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"]),up=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),dp=3,fp=1,_c=-25569,Ur=86400,pp=-693959,hp=2958465,mp=" ",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},Ls=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},gp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,wp=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 L=H.trim(),P=gp.exec(L);if(P!==null){const U=t.get(P[1]);if(U===void 0)t.set(P[1],new Map(F));else for(const[W,S]of F)U.set(W,S)}else if(L.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}:Nc}},Cp="%_-*? ",bp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Cp.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},yp=(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},qc=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}},Tn=(e,t)=>String(e).padStart(t,"0"),Ic=e=>{if(e<pp||e>hp)return null;let t=Math.floor(e),n=Math.round((e-t)*Ur);n>=Ur&&(t+=1,n-=Ur);const r=qc(t+_c),o=`${Tn(r.year,4)}-${Tn(r.month,2)}-${Tn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Tn(s,2)}:${Tn(l,2)}:${Tn(n%60,2)}`},Rp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,vp=e=>{const t=Rp.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=yp(n,r,o),h=qc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-_c+(s*3600+l*60+c)/Ur},Ds=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),dn=e=>Ds(e).replaceAll('"',"""),jc=e=>Ds(e).replaceAll("'","'"),kp=e=>Ds(e).replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).replaceAll("\r",`
|
|
4
4
|
`).replaceAll(`
|
|
5
|
-
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),
|
|
5
|
+
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),Xr=(e,t)=>`${e}="${dn(JSON.stringify(t))}"`,Hc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Sp=e=>{if(nt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Ep=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Ap=e=>{if(e.type==="text")return{1:1};const t=Fc(e);return t===null?null:{1:e.type==="date"?Ep(e.pattern===void 0?"yyyy/MM/dd":e.pattern):ip[e.type],2:t,3:1}},Op=/[;"'{}<>&\\]/,Bc=e=>e==="left"||e==="center"||e==="right",Vc=e=>e==="top"||e==="middle"||e==="bottom",xp=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"?Ye(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Ye(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Bc(e.align)&&t.push(`text-align:${e.align}`),Vc(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Op.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 Pc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(Jl,l.style))continue;const c=l.color===void 0?"windowtext":Ye(l.color);c!==null&&t.push(`border-${s}:${Jl[l.style]} ${c}`)}if(e.value!==void 0){const s=Fc(e.value);s!==null&&t.push(`mso-number-format:"${bp(s)}"`)}return t},Tp={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=jc([n,...xp(e)].join(";"));let o=null;if(t!==void 0){const s=Ap(t);s!==null&&(o=Xr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},Lp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:jn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Hc(o)?Sp(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?vp(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="${dn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${dn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${dn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${dn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const F=Cr(e.f,{row:n,col:r});F.includes("#REF!")||h.push(`x:fmla="${dn(F)}"`)}const g=kp(s),R=e.link===void 0?g:`<a href="${dn(e.link)}">${g}</a>`;return`<td style='${t.style}'${h.map(F=>` ${F}`).join("")}>${R}</td>`},Wc=(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],g=h.fmt===void 0?void 0:r[h.fmt];c+=Lp(h,g===void 0?Tp:g,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Zl}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Qi}='${jc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Zl}>`},us=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Kc=(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},Dp=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"}},Mp=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"},zp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),Fp={pt:1.5,unit:"px"},ei=e=>{let t=null,n=null;const r=[];for(const u of Ls(e)){const h=u.toLowerCase(),g=Dp(u);op.has(h)?n=h:g!==null?t=g:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=zp.get(n),s=o===void 0?Mp(t===null?Fp:t):o,l=r.join(" ");if(l===""||sp.has(l.toLowerCase()))return{style:s};const c=Ye(l);return c===null||c.length===9?null:{style:s,color:c}},Np=e=>e.style==="thin"&&e.color==="#cccccc",Pp=e=>{const t=Ye(e);if(t!==null)return t;for(const n of Ls(e)){const r=Ye(n);if(r!==null)return r}return null},_p=e=>{const t=eo(Ls(e.split(",")[0]).join(" ").trim()).trim();return t===""||lp.has(t.toLowerCase())?null:t},qp=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},Ip=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},jp=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"},Hp=new Set(["normal","pre-wrap","pre-line"]),Bp=(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=Ip(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:Ye(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:Pp(h);g!==null&&g.length!==9&&(r.background=g);const R=e.get("text-align"),F=R===void 0?"":R.toLowerCase();Bc(F)&&(r.align=F);const H=e.get("vertical-align"),L=H===void 0?"":H.toLowerCase();Vc(L)&&(r.verticalAlign=L);const P=e.get("font-family"),U=P===void 0?null:_p(P);U!==null&&(r.fontFamily=U);const W=e.get("font-size"),S=W===void 0?null:qp(W);S!==null&&(r.fontSize=S);const x=e.get("white-space");x!==void 0&&Hp.has(x.toLowerCase())&&(r.wrap=!0);const z={},q=e.get("border"),T=q===void 0?null:ei(q);for(const N of Pc){const O=e.get(`border-${N}`),m=O===void 0?T:ei(O);m!==null&&!(n==="sheets"&&Np(m))&&(z[N]=m)}return Object.keys(z).length>0&&(r.borders=z),r},ti=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
6
|
`)&&(e.text+=`
|
|
7
|
-
`)},
|
|
8
|
-
`);continue}if(o.nodeType!==
|
|
9
|
-
`;continue}const c=t.mode==="collapse"&&
|
|
7
|
+
`)},Vp=e=>{const t=e.getAttribute("style");return t!==null&&ao(t).get("mso-spacerun")==="yes"},Wp=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){up.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&ti(t);continue}const o=r.node;if(o.nodeType===dp){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
|
|
8
|
+
`);continue}if(o.nodeType!==fp)continue;const s=o,l=s.localName;if(cp.has(l)||Vp(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&ap.has(l);if(c&&ti(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})}},Kp=(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&&Up(l.element,t,n,r)},Yp=(e,t)=>{const n=e.replaceAll(mp," ");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
|
-
`)},Pp=(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)}ns(t,Fc(e,r))},_p=(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"?Tc(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<Hl.length?Hl[l]:null}return null},Nc=(e,t,n)=>t!==void 0&&Lc(t)?Kf(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!==""&&it(c)!==null)if(n!==void 0&&n.type==="date"){const u=Tc(Number(c));if(u!==null)return u}else return c;return Nc(t,n,r)},jp=(e,t,n,r)=>{const o=Fc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:$p(o)};for(const h of Vp(e))zp(h,l);Fp(l,o,s,r.rules);const c=Np(l.text,l.mode),u=Dp(o,s,r.kind),p={t:""};if(r.kind==="sheets"){const h=e.getAttribute("data-sheets-numberformat"),b=h===null?void 0:qf(h,r.options);b!==void 0&&(u.value=b);const P=e.getAttribute("data-sheets-value"),H=P===null?null:_p(P,b);p.t=H===null?Nc(c,b,Ec):H;const D=e.getAttribute("data-sheets-formula");D?.startsWith("=")&&(p.f=D);const _=e.getAttribute("data-sheets-hyperlink"),U=_!==null?_:l.href,W=U===null?null:nn(U);W!==null&&(p.link=W);const E=e.getAttribute("data-sheets-note");E!==null&&E!==""&&(p.note=E)}else{const h=o.get("mso-number-format"),b=h===void 0?void 0:vs(ts(Ur(h)),r.options);b!==void 0&&(u.value=b),p.t=qp(e,c,b,r.separators);const P=e.getAttribute("x:fmla");P?.startsWith("=")&&(p.f=to(P,{row:t,col:n}));const H=l.href===null?null:nn(l.href);H!==null&&(p.link=H)}return{cell:p,format:u}},rs=(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},Ip=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)},Hp=(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]))},Pc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:ro(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:Ip(l);if(c!==null)return Math.min(c,tn)}const o=Hp(e,t);return o===null?null:Math.min(o,tn)},Bp=(e,t)=>{const n=[],r=o=>{const s=Pc(o,"width");for(let l=rs(o,"span",gs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of fr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of fr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*fr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Vp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Wp(e){for(const t of["thead","tbody","tfoot"])for(const n of fr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of fr(n))o.localName==="tr"&&(yield o)}}const No=()=>({t:""}),Kp=(e,t,n)=>{const r=tc(),o=[],s=[],l=[];let c=0;for(const H of Wp(e)){const D=o.length,_=(D+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const U=[];for(let E=0;E<l.length;E+=1)l[E]>0&&(U[E]=No(),l[E]-=1);let W=0;for(const E of fr(H)){const T=E.localName;if(T!=="td"&&T!=="th")continue;for(;U[W]!==void 0;)W+=1;const N=rs(E,"colspan",gs),j=rs(E,"rowspan",Ui),$=(D+1)*Math.max(c,W+N);if($>n)return{outcome:"limit",cells:$};const k=jp(E,D,W,t),R=r.intern(k.format);R!==void 0&&(k.cell.fmt=R),U[W]=k.cell;for(let g=1;g<N;g+=1)U[W+g]===void 0&&(U[W+g]=No());if(j>1)for(let g=0;g<N;g+=1){const m=j-1,y=W+g;l[y]=l[y]===void 0||l[y]<m?m:l[y]}W+=N}U.length>c&&(c=U.length),o.push(U),s.push(Pc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const D=[];for(let _=0;_<c;_+=1){const U=H[_];D.push(U===void 0?No():U)}return D}),p=Bp(e,c),h=p.length===c&&p.every(H=>H!==null)?p.map(H=>H===null?0:H):void 0,b=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:hs(),formats:[...r.entries],validations:[],cells:u,...h===void 0?{}:{colWidths:h},...b===void 0?{}:{rowHeights:b},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},_c=(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=lp(o);return Kp(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Ce=(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)}),gn=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,ct=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),At=e=>e.reduce((t,n)=>t+ct(n).rows*ct(n).cols,0),Xt=(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}))}},rn=(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)}},Pt=(e,t)=>e.row===t.row&&e.col===t.col,qc=(e,t)=>e===void 0?bl(void 0,void 0,t()):bl(e.align,e.value,e.align===void 0?t():""),Vr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},In=(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}},Wr=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}),jc=e=>e.isCellReadOnly!==void 0,Ke=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Yp=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],Up=()=>!0,Xp=e=>{const t=new WeakMap,n={};for(const r of Yp)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:Up}),n},Gp=/^data-[a-z0-9-]+$/,Zp=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Jp=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Zp(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(!Gp.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},sr=(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},Mn=(e,t)=>{for(const n of t)if(sr(e,n))return!0;return!1},Qp=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=ct(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},os=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=ct(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,p=c?s.cols:e.cols,h=l?n:{row:t.startRow,col:t.startCol},b=Math.min(u,r-h.row),P=Math.min(p,o-h.col);return b<=0||P<=0?null:Ce(h,{row:h.row+b-1,col:h.col+P-1})},Ic=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=os({rows:l,cols:c},t,n,r,o);if(u===null)return[];const p={row:u.startRow,col:u.startCol},h=u.endRow-u.startRow+1,b=u.endCol-u.startCol+1,P=[];for(let H=0;H<h;H+=l){const D=[];for(let U=0;U<b;U+=c){const W={row:p.row+H,col:p.col+U};D.push(W),P.push(W)}const _=Math.min(l,h-H);for(let U=0;U<_;U+=1){const W=p.row+H+U,E=e[U];for(let T=0;T<D.length;T+=1){const N=T*c,j=Math.min(c,b-N);for(let $=0;$<j;$+=1)s(W,p.col+N+$,E[$],D[T])}}}return P},eh=(e,t,n,r,o)=>{const s=[];return Ic(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},Wl=(e,t,n,r,o,s)=>{const l=[],c=Ic(e,t,n,r,o,(u,p,h,b)=>{const P=s(h,u,p,b);P!==null&&l.push({...P,row:u,col:p})});return{edits:l,tiles:c}},Hc=(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)})`)},th=(e,t)=>{Hc(e,t);const n=ct(t),r=ct(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},nh=(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(Ce({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Ce({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Ce({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Ce({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},rh=(e,t,n,r)=>{Hc(t,n);const o=ct(t).rows,s=ct(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const p=t.startRow+((u-t.startRow)%o+o)%o,h=u>=t.startRow&&u<=t.endRow;for(let b=n.startCol;b<=n.endCol;b+=1){if(h&&b>=t.startCol&&b<=t.endCol)continue;const P=t.startCol+((b-t.startCol)%s+s)%s,H=p*2**21+P;let D=c.get(H);D===void 0&&(D={value:e(p,P),origin:{row:p,col:P}},c.set(H,D)),l.push(r(D.value,D.origin,{row:u,col:b}))}}return l},Bc=(e,t,n)=>{const r=In(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:yt(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=Hn(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},Vc=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?wc(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},oo=["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"],oh=/^[A-Z]$/,sh=/^[A-Za-z]$/,lh=/^Key([A-Z])$/,Wc=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"]),ih=e=>oh.test(e)||Wc.has(e),Gt=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||!ih(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}},ch=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Kc=e=>{if(sh.test(e.key))return e.key.toUpperCase();const t=lh.exec(e.code);return t!==null?t[1]:Wc.has(e.code)?e.code:null},Qn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Kc(t)===e.key,he=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),we=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),ah=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(he(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(he(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(he(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(he(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},uh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(he(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(he(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},wr=[...ah(),he("Home","idle","row start (first visible column)"),he("Ctrl+Home","idle","first visible cell"),he("Shift+Home","idle","extend to row start"),he("Ctrl+Shift+Home","idle","extend to first visible cell"),he("End","idle","row end (last visible column)"),he("Ctrl+End","idle","last visible cell"),he("Shift+End","idle","extend to row end"),he("Ctrl+Shift+End","idle","extend to last visible cell"),he("PageUp","both","page up (idle) / commit + page up (editing)"),he("PageDown","both","page down (idle) / commit + page down (editing)"),he("Shift+PageUp","idle","extend one page up"),he("Shift+PageDown","idle","extend one page down"),he("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),he("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),he("Tab","both","cycle right (idle) / commit + cycle right (editing)"),he("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),he("Enter","both","cycle down (idle) / commit + cycle down (editing)"),he("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),he("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),he("F2","both","start editing (idle) / toggle the pointing arm (editing)"),he("F4","editing","cycle the reference anchor under the caret (formula session)"),he("Delete","idle","clear every selected cell"),he("Backspace","idle","clear every selected cell"),he("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),he("Ctrl+A","idle","select all"),he("Ctrl+Z","idle","undo request"),he("Ctrl+Y","idle","redo request"),he("Ctrl+Shift+Z","idle","redo request"),he("Shift+F10","idle","keyboard context menu"),he("ContextMenu","idle","keyboard context menu"),he("Ctrl+Space","idle","column bands"),he("Shift+Space","idle","row bands"),he("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),he("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),he("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),he("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"},...uh(),we("bold","Ctrl+B","both","toggle bold"),we("italic","Ctrl+I","both","toggle italic"),we("underline","Ctrl+U","both","toggle underline"),we("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),we("clearFormatting","Ctrl+Backslash","idle","clear formatting"),we("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),we("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),we("alignLeft","Ctrl+Shift+L","both","align left"),we("alignCenter","Ctrl+Shift+E","both","align center"),we("alignRight","Ctrl+Shift+R","both","align right"),we("formatNumber","Ctrl+Shift+Digit1","both","number format"),we("formatTime","Ctrl+Shift+Digit2","both","time format"),we("formatDate","Ctrl+Shift+Digit3","both","date format"),we("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),we("formatPercent","Ctrl+Shift+Digit5","both","percent format"),we("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),we("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),we("bordersClear","Alt+Shift+Digit6","idle","clear borders"),we("borderTop","Alt+Shift+Digit1","idle","top border"),we("borderRight","Alt+Shift+Digit2","idle","right border"),we("borderBottom","Alt+Shift+Digit3","idle","bottom border"),we("borderLeft","Alt+Shift+Digit4","idle","left border"),we("insertLink","Ctrl+K","idle","insert / edit hyperlink"),we("insertNote","Shift+F2","idle","insert / edit note"),we("insertComment","Ctrl+Alt+M","idle","insert comment"),we("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),we("openValidationList","Alt+ArrowDown","idle","open the validation list"),we("fillDown","Ctrl+D","idle","fill down"),we("fillRight","Ctrl+R","idle","fill right"),we("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),we("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),we("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),we("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),we("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),we("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),we("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),we("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),we("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),we("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),we("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],Po=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),Kl=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),dh=e=>{const t=Gt(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 Kl?Kl[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},Xr=(e,t)=>e.column==="both"||e.column===t,fh=Array.from(new Set(wr.filter(e=>!e.rebindable&&Xr(e,"idle")).map(e=>e.chord))),Es=new Set(wr.filter(e=>e.command!==void 0&&Xr(e,"editing")).map(e=>e.command)),ph=new Set(wr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Yc=e=>{const t={};for(const n of oo)t[n]=e(n);return t},Uc=Yc(e=>wr.filter(t=>t.command===e).map(t=>t.chord)),hh=e=>{const t=new Map;for(const n of oo){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},mh=e=>{const t=new Set(oo);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(ph.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},gh=(e,t)=>{const n=Gt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Es.has(e);for(const o of wr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Xr(o,"idle")||r&&Xr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},wh=e=>{e!==void 0&&mh(e);const t=Yc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Uc[r]:o===null?[]:o});for(const r of oo)for(const o of t[r])gh(r,o);const n=new Map;for(const[r,o]of hh(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},Yl=(e,t)=>{const n=Kc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(ch({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},As=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],Ul=[...Ge.VIRTUAL_SCROLL_LABEL_KEYS,...As],ss=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:"閉じる"})}),Xc=Object.freeze({en:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ss.en}),ja:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ss.ja})}),pn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Xl=e=>e==="commentCount"||e==="listMore",Ch=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 ${pn(t)}`);for(const n of As){const r=e[n];if(!(Xl(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Xl(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${pn(r)}`)}}},yh=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},bh=(e,t,n)=>{e[t]=n},Gc=(e,t)=>{const n=Ge.resolveVirtualScrollLocale(e);if(t===void 0)return Xc[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${pn(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(!Ul.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Ul.join(", ")}`);const s={...Ge.resolveVirtualScrollLabels(n,yh(t)),...ss[n]};for(const l of As){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&bh(s,l,c)}return Ch(s),Object.freeze(s)},Rh=e=>{const t={};for(const n of Ge.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},Gl={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},vh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},kh=(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}`}},_o=(e,t)=>{const n=r=>(o,s)=>`${e} ${kh(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")})},Sh=Object.freeze({list:"Value must be one of the list items.",number:_o("Value must be a number",Gl),textLength:_o("Text length must be",Gl),date:_o("Value must be a date",vh),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}.`}),Eh=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} を満たす値を入力してください。`}),qo=Object.freeze({en:Sh,ja:Eh}),Ah=Object.freeze({ok:!0}),Oh="TRUE",xh="FALSE",Th=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),$h=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Lh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Dh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Mh=/^[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])?)+$/,Zl=e=>{const t=e.trim();if(!(Lh.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),p=c<0?"":s.slice(c+1),h=u+p,b=h.search(/[^0]/);return b<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:h.slice(b).replace(/0+$/,""),point:u.length+l-b}},zh=e=>e===1?-1:e===-1?1:0,Fh=(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:zh(n)},Nh=(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}},Jl=e=>{const t=Dh.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>Nh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Ph=(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},_h=(e,t)=>e<t?-1:e>t?1:0,qh=e=>e==="between"||e==="notBetween",jh=(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}},Ih=(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}},jo=(e,t,n,r,o,s)=>{const l=jh(e,t,n,r);return l===null?!0:o===null?!1:Ih(e,s(o,l.a),l.b===null?0:s(o,l.b))},Hh=e=>Number.isFinite(e)?e:null,Bh=e=>{let t=0;for(const n of e)t+=1;return t},Vh=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Wh=(e,t)=>{switch(e.op){case"isEmail":return Mh.test(t);case"isUrl":return Vh(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)}},Kh=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Zc=e=>({checked:e.checked===void 0?Oh:e.checked,unchecked:e.unchecked===void 0?xh:e.unchecked}),Yh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Th.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${pn(e.op)} for type "${e.type}"`);return;case"text":if(!$h.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${pn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${pn(e.type)}`)}},Uh=(e,t,n)=>{switch(e.type){case"list":return Zh(e).has(t);case"number":return jo(e.op,e.a,e.b,Zl,Zl(t),Fh);case"textLength":return jo(e.op,e.a,e.b,Hh,Bh(t),_h);case"date":return jo(e.op,e.a,e.b,Jl,Jl(t),Ph);case"text":return Wh(e,t);case"checkbox":{const r=Zc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Kh(n(e.formula))}},Jc=(e,t,n)=>(Yh(e),t===""||Uh(e,t,n)),Ql=e=>e===void 0?void 0:e.trim(),Xh=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Ql(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(),Ql(e.b));case"text":return Gh(e,t.text);case"checkbox":{const n=Zc(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},Gh=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},ei=new WeakMap,Zh=e=>{const t=ei.get(e);if(t!==void 0)return t;const n=new Set(e.values);return ei.set(e,n),n},Qc=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(qo,n)){const o=Object.keys(qo).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${pn(n)}`)}return Jc(e,t,r)?Ah:{ok:!1,message:e.errorMessage===void 0?Xh(e,qo[n]):e.errorMessage}},Jh=e=>e.type!=="custom",Qh=(e,t)=>Jh(e)&&!Jc(e,t,void 0),ea=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),ta=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),na=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,ra=(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),oa=(e,t)=>ea(e,t),sa=(e,t)=>ea(e,t),la=(e,t)=>ta(e,t),ia=(e,t)=>ta(e,t),hn=(e,t,n)=>na(e,t,n),mn=(e,t,n)=>na(e,t,n),Cr=(e,t,n)=>ra(e,t,n),yr=(e,t,n)=>ra(e,t,n),em=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Ut=1,lr=3,Lr=e=>`${-Math.min(lr,Math.max(0,Math.floor(e)))}px`,ca=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),tm=16,nm=450,rm=e=>e>4?Math.floor(nm/(5*e)):tm,er=(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},ti=()=>({rowLeft:er("row","left"),rowRight:er("row","right"),colAbove:er("column","above"),colBelow:er("column","below"),cross:er("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),aa=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Dr=(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},Mr=(e,t)=>Math.min(Math.max(e,0),t),ni="inset(100%)",Nn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},om=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Nn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const P=`${t.height}px`;e.rowLeft.style.height=P,e.rowRight.style.height=P}const h=`translate(${Mr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;h!==s.rowLeftTransform&&(s.rowLeftTransform=h,e.rowLeft.style.transform=h);const b=`translate(${Mr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;b!==s.rowRightTransform&&(s.rowRightTransform=b,e.rowRight.style.transform=b)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Nn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const P=`${t.width}px`;e.colAbove.style.width=P,e.colBelow.style.width=P}const h=`translate(${t.left}px, ${Mr(t.top,n.clampHeight)-n.clampHeight}px)`;h!==s.colAboveTransform&&(s.colAboveTransform=h,e.colAbove.style.transform=h);const b=`translate(${t.left}px, ${Mr(t.top+t.height,n.clampHeight)}px)`;b!==s.colBelowTransform&&(s.colBelowTransform=b,e.colBelow.style.transform=b)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,p=u!==null;if(p!==s.crossShown&&(s.crossShown=p,Nn([e.cross],p)),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 h=`translate(${t.left}px, ${t.top}px)`;h!==s.crossTransform&&(s.crossTransform=h,e.cross.style.transform=h)}},ri=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Nn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Nn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Nn([e.cross],!1))},oi=e=>{for(const t of aa(e))t.remove()},sm=(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)},lm=Object.freeze([]),si=e=>e.dividers[0]??e.active,im={left:"0px",right:"0px",width:""},cm={top:"0px",bottom:"0px",height:""},li=()=>({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:[]}),ii=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],ci=6,am=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:p,getIsDraggingAny:h,getIsFillDragging:b,fillFrameRef:P,resizeGuideFrameRef:H,fillHandleNodeRef:D,enableFillHandle:_,frozenCols:U,frozenRows:W,trailingCols:E,trailingRows:T,sinkAriaLabel:N,sinkReadOnly:j,sinkKeyShortcuts:$,onSinkMouseDown:k,editPaintRef:R,highlightRef:g,highlightColors:m,popoverAnchors:y,interactiveAnchorRef:S,tipAnchorRef:L})=>{const v=i.useRef(null),C=i.useRef(null),a=i.useRef(null),f=i.useRef(new Map(ii.map(M=>[M,li()]))),A=i.useCallback(M=>{const V=f.current.get(M);if(V!==void 0)return V;const X=li();return f.current.set(M,X),X},[]),d=i.useCallback((M,V,X)=>{if(M===null)return;const I=M.style;I.left!==V.left&&(I.left=V.left),I.right!==V.right&&(I.right=V.right),I.width!==V.width&&(I.width=V.width),I.top!==X.top&&(I.top=X.top),I.bottom!==X.bottom&&(I.bottom=X.bottom),I.height!==X.height&&(I.height=X.height)},[]),F=i.useCallback((M,V,X)=>{if(!(M.bandClampWidth===V&&M.bandClampHeight===X)){M.bandClampWidth=V,M.bandClampHeight=X;for(const I of M.bandPool)Dr(I,V,X);M.dragBand!==null&&Dr(M.dragBand,V,X)}},[]),O=i.useRef({rowAxis:e,colAxis:t});O.current={rowAxis:e,colAxis:t};const x=i.useCallback((M,V,X)=>{const I=M.dividerSlots[V];I===null||M.dividerShown[V]===X||(M.dividerShown[V]=X,I.style.display=X?"":"none")},[]),z=i.useRef({x:0,y:0}),q=i.useRef(null),B=i.useCallback((M,V)=>{const X=n.current,I=X?.getFrozenSize()??em,G=X?.getViewportSize(),re=G?.width??-1,ae=G?.height??-1,Oe=z.current;Oe.x=M,Oe.y=V;let ye=q.current;if(ye===null||ye.frozenCols!==I.cols||ye.frozenWidth!==I.width||ye.frozenRows!==I.rows||ye.frozenHeight!==I.height||ye.trailingCols!==I.trailingCols||ye.trailingWidth!==I.trailingWidth||ye.trailingVisibleWidth!==I.trailingVisibleWidth||ye.trailingRows!==I.trailingRows||ye.trailingHeight!==I.trailingHeight||ye.trailingVisibleHeight!==I.trailingVisibleHeight||ye.bodyWidth!==re||ye.bodyHeight!==ae){const J=I.trailingVisibleWidth,ce=I.trailingVisibleHeight,me=I.cols<=0&&I.trailingCols<=0?[{kind:"m",map:Re=>Re-Oe.x,clamp:re,style:im,seamLead:!1,seamTrail:!1}]:[...I.cols>0?[{kind:"f",map:Re=>Re,clamp:I.width,style:{left:"0px",width:`${I.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Re=>Re-Oe.x-I.width,clamp:Math.max(0,re-I.width-J),style:{left:`${I.width}px`,right:`${J}px`,width:""},seamLead:I.cols>0,seamTrail:I.trailingCols>0},...I.trailingCols>0?[{kind:"t",map:Re=>Re-O.current.colAxis.totalSize()+J,clamp:J,style:{left:"",right:"0px",width:`${J}px`},seamLead:!0,seamTrail:!1}]:[]],ge=I.rows<=0&&I.trailingRows<=0?[{kind:"m",map:Re=>Re-Oe.y,clamp:ae,style:cm,seamLead:!1,seamTrail:!1}]:[...I.rows>0?[{kind:"f",map:Re=>Re,clamp:I.height,style:{top:"0px",height:`${I.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Re=>Re-Oe.y-I.height,clamp:Math.max(0,ae-I.height-ce),style:{top:`${I.height}px`,bottom:`${ce}px`,height:""},seamLead:I.rows>0,seamTrail:I.trailingRows>0},...I.trailingRows>0?[{kind:"t",map:Re=>Re-O.current.rowAxis.totalSize()+ce,clamp:ce,style:{top:"",bottom:"0px",height:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],de=[];for(const Re of me)for(const ke of ge)de.push({nodes:A(`${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});ye={frozenCols:I.cols,frozenWidth:I.width,frozenRows:I.rows,frozenHeight:I.height,trailingCols:I.trailingCols,trailingWidth:I.trailingWidth,trailingVisibleWidth:I.trailingVisibleWidth,trailingRows:I.trailingRows,trailingHeight:I.trailingHeight,trailingVisibleHeight:I.trailingVisibleHeight,bodyWidth:re,bodyHeight:ae,ctxs:de},q.current=ye}const He=I.width>0,be=I.trailingWidth>0,Ve=I.height>0,xe=I.trailingHeight>0;for(const J of ye.ctxs)d(J.nodes.container,J.xStyle,J.yStyle),F(J.nodes,J.clampWidth,J.clampHeight),x(J.nodes,0,He),x(J.nodes,1,be),x(J.nodes,2,Ve),x(J.nodes,3,xe);return ye.ctxs},[n,A,d,F,x]),Z=i.useCallback((M,V,X)=>{M.dividerSlots[V]=X,M.dividerShown[V]=!1,M.dividers.length=0;for(const I of M.dividerSlots)I!==null&&M.dividers.push(I)},[]),ee=i.useCallback(M=>{const V=()=>A(M);return{container:X=>{const I=V();I.container=X,X===null&&(I.fillPool.length=0,I.bandPool.length=0,I.dragBand=null,I.bandClampWidth=-1,I.bandClampHeight=-1)},dividerXLeading:X=>Z(V(),0,X),dividerXTrailing:X=>Z(V(),1,X),dividerYLeading:X=>Z(V(),2,X),dividerYTrailing:X=>Z(V(),3,X),active:X=>{V().active=X},dragRect:X=>{V().dragRect=X},marquee:X=>{V().marquee=X},fillPreview:X=>{V().fillPreview=X},resizeGuide:X=>{V().resizeGuide=X}}},[A,Z]),oe=i.useMemo(()=>Object.fromEntries(ii.map(M=>[M,ee(M)])),[ee]),se=Math.min(Math.max(0,U),t.count),ve=oa(t,se),qe=Math.min(Math.max(0,W),e.count),bt=sa(e,qe),Ie=E===void 0?0:Math.min(Math.max(0,E),t.count-se),Ze=la(t,Ie),ue=T===void 0?0:Math.min(Math.max(0,T),e.count-qe),ie=ia(e,ue),je=i.useRef(null),Fe=i.useRef("add"),Ne=i.useRef(s);Ne.current=s;const Pe=i.useRef(!1),Be=Ge.useWheelBridge(n,{enableBridge:!s}),at=i.useCallback(M=>(r.current=M,Be(M)),[r,Be]),Ot=i.useCallback((M,V)=>({top:V.mapY(e.offsetOf(M.startRow)),bottom:V.mapY(e.offsetOf(M.endRow)+e.sizeOf(M.endRow)),left:V.mapX(t.offsetOf(M.startCol)),right:V.mapX(t.offsetOf(M.endCol)+t.sizeOf(M.endCol))}),[e,t]),Je=i.useCallback((M,V)=>{if(V.clampHeight<=0||V.clampWidth<=0)return null;const{top:X,bottom:I,left:G,right:re}=Ot(M,V),ae=-V.clampHeight*Ut,Oe=V.clampHeight*(1+Ut),ye=-V.clampWidth*Ut,He=V.clampWidth*(1+Ut);if(I<ae||X>Oe||re<ye||G>He)return null;const be=Math.max(X,ae),Ve=Math.max(G,ye);return{top:be,left:Ve,width:Math.min(re,He)-Ve,height:Math.min(I,Oe)-be}},[Ot]),ne=i.useCallback((M,V)=>{if(V.clampHeight<=0||V.clampWidth<=0)return null;const X=Ot(M,V),I=-V.clampHeight*Ut,G=V.clampHeight*(1+Ut),re=-V.clampWidth*Ut,ae=V.clampWidth*(1+Ut),Oe=Math.min(Math.max(X.top,I),G),ye=Math.min(Math.max(X.left,re),ae);return{top:Oe,left:ye,width:Math.min(Math.max(X.right,re),ae)-ye,height:Math.min(Math.max(X.bottom,I),G)-Oe}},[Ot]),fe=i.useCallback(()=>{if(g===void 0)return null;const M=g.current;return M.row||M.column||M.intersection?M:null},[g]),pe=i.useCallback((M,V,X)=>{const I=V.fillPool[0]?.node??si(V);for(const G of aa(X))M.insertBefore(G,I)},[]),qt=i.useCallback((M,V,X,I)=>{const G=ne(V,X);if(G===null){ri(M);return}om(M,G,X,I,nc(V,t.count)||rc(V,e.count))},[ne,e,t]),Ae=i.useCallback((M,V,X,I)=>{const G=M.nodes.bandPool;for(;G.length>X.length;){const re=G.pop();re!==void 0&&oi(re)}if(I===null){M.nodes.dragBand!==null&&(oi(M.nodes.dragBand),M.nodes.dragBand=null);return}for(let re=0;re<X.length;re+=1){let ae=G[re];ae===void 0&&(ae=ti(),Dr(ae,M.clampWidth,M.clampHeight),pe(V,M.nodes,ae),G.push(ae)),qt(ae,X[re],M,I)}},[pe,qt]),jt=i.useCallback((M,V,X)=>{const I=M.nodes.container;if(I===null)return;if(V===null||X===null){M.nodes.dragBand!==null&&ri(M.nodes.dragBand);return}let G=M.nodes.dragBand;G===null&&(G=ti(),Dr(G,M.clampWidth,M.clampHeight),pe(I,M.nodes,G),M.nodes.dragBand=G),qt(G,V,M,X)},[pe,qt]),Qe=i.useCallback((M,V)=>{if(M!==null){if(V===null){M.style.display="none";return}M.style.display="block",M.style.transform=`translate(${V.left}px, ${V.top}px)`,M.style.width=`${V.width}px`,M.style.height=`${V.height}px`}},[]),wn=i.useCallback((M,V,X,I)=>{const G=I==="point"?null:fe();for(const re of B(X,V))Qe(re.nodes.dragRect,Je(M,re)),jt(re,M,G)},[Je,B,Qe,fe,jt]),xt=i.useCallback((M,V,X)=>{for(const I of B(X,V))Qe(I.nodes.fillPreview,M===null?null:Je(M,I))},[Je,B,Qe]),Cn=i.useCallback((M,V,X)=>{for(const I of B(X,V)){const G=I.nodes.resizeGuide;if(G===null)continue;if(M===null){G.style.display="none";continue}const re=M.anchor==="trailing";if(M.axis==="col"){if(re&&I.xKind!=="t"){G.style.display="none";continue}G.style.display="block";const ae=I.mapX(M.position);G.style.transform=`translate(${re?Math.max(0,ae):ae}px, 0px)`,G.style.width="1px",G.style.height="100%"}else{if(re&&I.yKind!=="t"){G.style.display="none";continue}G.style.display="block";const ae=I.mapY(M.position);G.style.transform=`translate(0px, ${re?Math.max(0,ae):ae}px)`,G.style.width="100%",G.style.height="1px"}}},[B]),Bn=i.useCallback((M,V,X,I,G,re,ae)=>{if(M===null)return;if(V===null||ae<=0||re<=0){M.style.clipPath=ni;return}const Oe=mn(e,V.row,I),ye=hn(t,V.col,X),He=t.sizeOf(V.col),be=e.sizeOf(V.row),Ve=ye>=re||Oe>=ae,xe=V.col>=G.cols&&ye<G.width,J=V.row>=G.rows&&Oe<G.height,ce=G.trailingWidth>0&&V.col<t.count-G.trailingCols&&ye+He>re-G.trailingVisibleWidth,me=G.trailingHeight>0&&V.row<e.count-G.trailingRows&&Oe+be>ae-G.trailingVisibleHeight;if(Ve||xe||J||ce||me){M.style.clipPath=ni;return}M.style.clipPath="",M.style.transform=`translate(${ye}px, ${Oe}px)`;const ge=`${He} ${be}`;M.dataset.aqspAnchorSig!==ge&&(M.dataset.aqspAnchorSig=ge,M.style.width=`${He}px`,M.style.height=`${be}px`)},[e,t]),br=i.useCallback((M,V,X)=>{if(y===void 0)return;const I=y.current,{width:G,height:re}=M.getViewportSize(),ae=M.getFrozenSize(),Oe={scroll:X,frozenCount:ae.cols,trailingCount:ae.trailingCols,extent:G},ye={scroll:V,frozenCount:ae.rows,trailingCount:ae.trailingRows,extent:re};Bn(S===void 0?null:S.current,I.interactive,Oe,ye,ae,G,re),Bn(L===void 0?null:L.current,I.tip,Oe,ye,ae,G,re)},[y,S,L,Bn]),yn=i.useCallback(()=>{const M=v.current,V=n.current;if(M===null||V===null)return;const X=V.getScrollPosition(),I=Math.max(0,X.y),G=Math.max(0,X.x),re=o(),ae=B(G,I),Oe=fe(),ye=Oe===null?lm:re.ranges.slice(-rm(ae.length));for(const J of ae){const ce=J.nodes.container;if(ce===null)continue;const me=J.nodes.fillPool;for(let ge=0;ge<Math.max(me.length,re.ranges.length);ge+=1){let de=me[ge];if(de===void 0){const De=document.createElement("div");De.className="aqsp-selection-fill",De.setAttribute("data-aqsp-fill",""),De.style.display="none",ce.insertBefore(De,si(J.nodes)),de={node:De,last:{shown:!1,width:-1,height:-1,transform:""}},me.push(de)}const Re=re.ranges[ge],ke=Re===void 0?null:Je(Re,J);if(ke===null)de.last.shown&&(de.last.shown=!1,de.node.style.display="none");else{de.last.shown||(de.last.shown=!0,de.node.style.display="block");const De=`translate(${ke.left}px, ${ke.top}px)`;De!==de.last.transform&&(de.last.transform=De,de.node.style.transform=De),ke.width!==de.last.width&&(de.last.width=ke.width,de.node.style.width=`${ke.width}px`),ke.height!==de.last.height&&(de.last.height=ke.height,de.node.style.height=`${ke.height}px`)}}for(;me.length>re.ranges.length;)me.pop()?.node.remove();Qe(J.nodes.active,Je(Ce(re.active,re.active),J)),Ae(J,ce,ye,Oe)}const He=p(),be=He===null||He.foreign?null:He;for(const J of ae){const ce=J.nodes.marquee;if(ce===null)continue;const me=be===null?null:Je(be.range,J),ge=me!==null&&(J.xSeamTrail&&me.left>=J.clampWidth&&me.left<J.clampWidth+lr||J.xSeamLead&&me.left+me.width<=0&&me.left+me.width>-lr||J.ySeamTrail&&me.top>=J.clampHeight&&me.top<J.clampHeight+lr||J.ySeamLead&&me.top+me.height<=0&&me.top+me.height>-lr)?null:me;if(ge===null)ce.style.display="none";else{ce.style.display="block",ce.style.transform=`translate(${ge.left}px, ${ge.top}px)`,ce.style.width=`${ge.width}px`,ce.style.height=`${ge.height}px`;const ke=Lr(ge.top),De=Lr(ge.left),nt=Lr(J.clampHeight-(ge.top+ge.height)),et=Lr(J.clampWidth-(ge.left+ge.width)),rt=`${ke} ${et} ${nt} ${De}`;rt!==ce.dataset.aqspOutsetSig&&(ce.dataset.aqspOutsetSig=rt,ce.style.setProperty("--aqsp-clip-outset-top",ke),ce.style.setProperty("--aqsp-clip-outset-right",et),ce.style.setProperty("--aqsp-clip-outset-bottom",nt),ce.style.setProperty("--aqsp-clip-outset-left",De))}const de=ge===null?null:be?.kind??null,Re=ce.dataset.aqspClipKindLast??null;de!==Re&&(de===null?(delete ce.dataset.aqspClipKindLast,ce.removeAttribute("data-aqsp-clip-kind")):(ce.dataset.aqspClipKindLast=de,ce.setAttribute("data-aqsp-clip-kind",de)))}je.current!==null&&wn(je.current,I,G,Fe.current),a.current!==null&&Cn(a.current,I,G),C.current!==null&&xt(C.current,I,G);const Ve=D.current;if(Ve!==null&&!b()){const{width:J,height:ce}=V.getViewportSize(),me=re.ranges[re.ranges.length-1];if(!(re.ranges.length===1&&!Ne.current&&!h())||ce<=0||J<=0)Ve.style.display="none";else{const de=V.getFrozenSize(),Re={scroll:G,frozenCount:de.cols,trailingCount:de.trailingCols,extent:J},ke={scroll:I,frozenCount:de.rows,trailingCount:de.trailingRows,extent:ce},De=me.endCol<de.cols,nt=me.endRow<de.rows,et=me.endCol>=t.count-de.trailingCols,rt=me.endRow>=e.count-de.trailingRows,Rt=hn(t,me.endCol,Re)+t.sizeOf(me.endCol),Bt=mn(e,me.endRow,ke)+e.sizeOf(me.endRow),vt=De||et?0:de.width,Tt=nt||rt?0:de.height,ot=et?J:J-de.trailingVisibleWidth,ut=rt?ce:ce-de.trailingVisibleHeight;Bt<=Tt||Bt>ut||Rt<=vt||Rt>ot?Ve.style.display="none":(Ve.style.display="block",Ve.style.transform=`translate(${Rt-ci+1}px, ${Bt-ci+1}px)`)}}const xe=r.current;if(xe!==null){const J=re.active,{width:ce,height:me}=V.getViewportSize(),ge=V.getFrozenSize(),de={scroll:G,frozenCount:ge.cols,trailingCount:ge.trailingCols,extent:ce},Re={scroll:I,frozenCount:ge.rows,trailingCount:ge.trailingRows,extent:me},ke=mn(e,J.row,Re),De=hn(t,J.col,de),nt=me>0?Math.min(Math.max(ke,0),Math.max(0,me-1)):0,et=ce>0?Math.min(Math.max(De,0),Math.max(0,ce-1)):0;xe.style.top=`${nt}px`,xe.style.left=`${et}px`,Ne.current?(xe.style.width=`${t.sizeOf(J.col)}px`,xe.style.height=`${e.sizeOf(J.row)}px`,xe.style.paddingTop=`${sm(e.sizeOf(J.row),R===void 0?zt:R.current)}px`):(xe.style.width="1px",xe.style.height="1px",xe.style.paddingTop="0px");const rt=J.col>=ge.cols&&De<ge.width,Rt=J.row>=ge.rows&&ke<ge.height,Bt=ge.trailingWidth>0&&J.col<t.count-ge.trailingCols&&De+t.sizeOf(J.col)>ce-ge.trailingVisibleWidth,vt=ge.trailingHeight>0&&J.row<e.count-ge.trailingRows&&ke+e.sizeOf(J.row)>me-ge.trailingVisibleHeight,Tt=Ne.current&&ke===nt&&De===et&&!rt&&!Rt&&!Bt&&!vt;Tt!==Pe.current&&(Pe.current=Tt,Tt?xe.setAttribute("data-aqsp-editing",""):xe.removeAttribute("data-aqsp-editing"))}br(V,I,G)},[n,Je,B,Qe,wn,Cn,xt,p,o,h,b,D,r,e,t,fe,Ae,R,br]),so=i.useCallback((M,V)=>{je.current=M,Fe.current=V;const X=M===null?"add":V;for(const re of B(0,0)){const ae=re.nodes.dragRect;if(ae===null)continue;const Oe=ae.dataset.aqspDragModeLast??"add";X!==Oe&&(ae.dataset.aqspDragModeLast=X,X==="add"?ae.removeAttribute("data-aqsp-drag-mode"):ae.setAttribute("data-aqsp-drag-mode",X))}const I=n.current;if(M===null||I===null){for(const re of B(0,0))re.nodes.dragRect!==null&&(re.nodes.dragRect.style.display="none"),jt(re,null,null);return}const G=I.getScrollPosition();wn(M,Math.max(0,G.y),Math.max(0,G.x),V)},[n,wn,B,jt]),$s=i.useCallback(M=>{C.current=M;const V=n.current;if(V===null){for(const I of B(0,0))I.nodes.fillPreview!==null&&(I.nodes.fillPreview.style.display="none");return}const X=V.getScrollPosition();xt(M,Math.max(0,X.y),Math.max(0,X.x))},[n,xt,B]),lo=i.useCallback(M=>{a.current=M;const V=n.current;if(V===null){for(const I of B(0,0))I.nodes.resizeGuide!==null&&(I.nodes.resizeGuide.style.display="none");return}const X=V.getScrollPosition();Cn(M,Math.max(0,X.y),Math.max(0,X.x))},[n,Cn,B]);i.useLayoutEffect(()=>{const M=v.current;if(!(M===null||m===void 0))return M.style.setProperty("--aqsp-band-row",m.row),M.style.setProperty("--aqsp-band-column",m.column),M.style.setProperty("--aqsp-band-intersection",m.intersection),M.style.setProperty("--aqsp-band-opacity",String(m.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")}},[m]),i.useEffect(()=>(c.current=yn,u.current=so,P.current=$s,H.current=lo,()=>{c.current=null,u.current=null,P.current=null,H.current=null})),i.useEffect(()=>{yn()},[yn,s,se,qe,Ie,ue]),i.useEffect(()=>{const M=r.current;if(M===null)return;const V=X=>k(X);return M.addEventListener("mousedown",V),()=>M.removeEventListener("mousedown",V)},[r,k]);const Vn=se>0||Ie>0?[...se>0?[{k:"f",style:{left:0,width:ve}}]:[],{k:"s",style:{left:ve,right:Ze}},...Ie>0?[{k:"t",style:{right:0,width:Ze}}]:[]]:[{k:"m",style:{left:0,right:0}}],bn=qe>0||ue>0?[...qe>0?[{k:"f",style:{top:0,height:bt}}]:[],{k:"s",style:{top:bt,bottom:ie}},...ue>0?[{k:"t",style:{bottom:0,height:ie}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],It=M=>M==="m"?0:M==="s"?1:M==="t"?2:3,Wn=Vn.flatMap(M=>bn.map(V=>({xk:M.k,yk:V.k,key:`${M.k}${V.k}`,style:{...M.style,...V.style}}))).sort((M,V)=>It(M.key[0])+It(M.key[1])-(It(V.key[0])+It(V.key[1]))),Ht=M=>M==="mm"?{"data-aqsp-overlay-main":""}:M==="fm"?{"data-aqsp-overlay-frozen":""}:M==="sm"?{"data-aqsp-overlay-scroll":""}:{};return Y.jsxs("div",{ref:v,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[Wn.map(({xk:M,yk:V,key:X,style:I})=>{const G=oe[X];return Y.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Ht(X),style:I,ref:G.container,children:[M==="s"&&se>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:G.dividerXLeading}):null,M==="s"&&Ie>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:G.dividerXTrailing}):null,V==="s"&&qe>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:G.dividerYLeading}):null,V==="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:G.dividerYTrailing}):null,Y.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:G.active}),Y.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:G.dragRect}),Y.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:G.marquee}),Y.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:G.fillPreview}),Y.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:G.resizeGuide})]},X)}),Y.jsx("textarea",{ref:at,className:"aqsp-sink","aria-label":N,"aria-readonly":j?"true":void 0,"aria-keyshortcuts":$,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?Y.jsx("div",{ref:D,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},ua=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=b=>{l.current=!0;try{b()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},p=b=>{if(b.key==="Escape"){b.preventDefault(),c(e.close);return}b.key==="Enter"&&(b.ctrlKey||b.metaKey)&&!b.altKey&&!b.shiftKey&&(b.preventDefault(),u())},h=b=>{l.current||b.relatedTarget instanceof Node&&b.currentTarget.contains(b.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:h,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(b=>Y.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":b.id,children:[Y.jsx("span",{className:"aqsp-popover-comment-author",children:b.author}),Y.jsx("time",{className:"aqsp-popover-comment-time",dateTime:b.createdAt,children:b.createdAt}),Y.jsx("p",{className:"aqsp-popover-comment-text",children:b.text})]},b.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:b=>r(b.currentTarget.value),onKeyDown:p}),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:"×"})]})]})},da=({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),p=o.trim()===""?null:nn(o),h=o.trim()!==""&&p===null,b=_=>{u.current=!0;try{_()}finally{u.current=!1}},P=()=>{l||h||b(()=>e.commit({text:n===""&&p!==null?p:n,url:p}))},H=_=>{if(_.key==="Escape"){_.preventDefault(),b(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),P())},D=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||b(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":h?"":void 0,role:"dialog","aria-labelledby":c,onBlur:D,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":h||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:h||l,"aria-disabled":l?"true":void 0,onClick:P,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:()=>b(e.close),children:"×"})]})]})},ai=500,fa=({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(E=>E.toLowerCase().startsWith(W))},[e.current,n]),p=i.useMemo(()=>u.length>ai?u.slice(0,ai):u,[u]),h=u.length-p.length,b=p.length===0?-1:Math.min(o,p.length-1),P=W=>{c.current=!0;try{W()}finally{c.current=!1}},H=()=>{b<0||P(()=>e.commit(p[b]))},D=W=>{if(W.key==="Escape"){W.preventDefault(),P(e.close);return}if(W.key==="Enter"){W.preventDefault(),H();return}if(W.key==="ArrowDown"){W.preventDefault(),s(b+1);return}W.key==="ArrowUp"&&(W.preventDefault(),s(Math.max(b-1,0)))},_=W=>{c.current||W.relatedTarget instanceof Node&&W.currentTarget.contains(W.relatedTarget)||P(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":b<0?void 0:U(b),value:n,onChange:W=>{r(W.currentTarget.value),s(0)},onKeyDown:D}),Y.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":ze(t,"listTitle"),children:[p.length===0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:ze(t,"listEmpty")}):p.map((W,E)=>Y.jsx("div",{className:"aqsp-popover-option",id:U(E),role:"option",tabIndex:-1,"aria-selected":E===b,"data-aqsp-list-option":W,onPointerDown:T=>T.preventDefault(),onClick:()=>P(()=>e.commit(W)),children:W},U(E))),h>0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:ze(t,"listMore",h)}):null]})]})},pa=({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:"×"})]}),ha=({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),p=D=>{u.current=!0;try{D()}finally{u.current=!1}},h=()=>{s||p(()=>e.commit(r===""?null:r))},b=()=>{r!==n&&!s?h():p(e.close)},P=D=>{if(D.key==="Escape"){D.preventDefault(),e.rejected?p(e.close):b();return}D.key==="Enter"&&(D.ctrlKey||D.metaKey)&&!D.altKey&&!D.shiftKey&&(D.preventDefault(),h())},H=D=>{u.current||D.relatedTarget instanceof Node&&D.currentTarget.contains(D.relatedTarget)||e.rejected||b()};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:D=>o(D.currentTarget.value),onKeyDown:P}),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:h,children:ze(t,"noteSave")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>p(e.close),children:"×"})]})]})},ma=({ctx:e})=>Y.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Dt=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")}),ui=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],ga=Object.freeze({all:Dt(ui),values:Dt(["text"]),formats:Dt(["format","borders","cf"]),formulas:Dt(["text","formula"]),noBorders:Dt(ui.filter(e=>e!=="borders")),columnWidths:Dt(["sizes"]),validation:Dt(["validation"]),conditionalFormats:Dt(["cf"]),commentsAndNotes:Dt(["note","comments"])}),di=Object.freeze({mode:"all"}),ls=Object.freeze({t:""}),fi=Object.freeze({row:1<<30,col:1<<30}),um=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),dm=e=>e.t===""&&e.f===void 0,fm=e=>e.length>1&&e.startsWith("="),pm=(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}},pi=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,hm=(e,t,n,r)=>{const o=fm(e),s=e===""?"0":it(e);if(!o&&s===null)return null;const l=um[n];if(t.f!==void 0){const p=gr(t.f,r),h=p.startsWith("=")?p.slice(1):p;return`=(${o?e.slice(1):s})${l}(${h})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:pi(Number(s));const c=it(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:pi(pm(Number(s),u,n))},hi=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),mm=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:hi(e.start),end:hi(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}}}},gm=e=>{const t=gr(e,fi),n=mr(t);let r="",o=0,s=!1;for(const l of n){const c=mm(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${Jt(c)}`,o=l.end,s=!0)}return s?to(`${r}${t.slice(o)}`,fi):e},wm=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return ls;const o=r[n];return o===void 0?ls:o},Cm=e=>{const{rows:t,cols:n}=e,r=gc(gm);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 p=0;p<t;p+=1){const h=wm(e,p,c);let b=h;if(h.f!==void 0){const P=r(h.f);b=P===h.f?h:{...h,f:P}}(b!==h||h===ls)&&(o=!1),u.push(b)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},ym=(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,bm=(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},mi=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const p=[];for(const h of c)ym(h,t)?(p.push(bm(h,t)),u=!0):p.push(h);u&&(n=!0),r.push(u?p:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},gi=new WeakMap,wa=e=>{const t=gi.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>yt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:yt({...s,borders:void 0})),o={canonical:n,borderless:r};return gi.set(e,o),o},Gr=(e,t)=>t===void 0?void 0:e[t],Rm=(e,t,n,r)=>{const o=wa(e);if(n){const p=Gr(o.canonical,t.fmt);return p===void 0?null:p}const s=Gr(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=yt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},vm=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?hm(n.readText(),o,r,n):o.f===void 0?o.t:gr(o.f,n)},wi=(e,t,n,r,o)=>{const s=ga[r.mode];if(r.skipBlanks===!0&&dm(e))return null;const l={};let c=!1;if(s.text){const u=vm(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Rm(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Gr(wa(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=Gr(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},Ci=(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}}),km=["text/html","text/plain"],Sm=(e,t,n)=>{if(e===0||t===0)return 0;const r=ct(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Em=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Am=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Om=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}}},yi=e=>{const t=e.clipboardData;return t??null},xm=(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}},Tm=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=xm(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},$m=(e,t,n,r,o)=>{const s=In(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=to(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:p,createdAt:h})=>({text:u,author:p,createdAt:h})))}if(e.getCellHyperlink!==void 0){const c=Hn(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},Ca=(e,t)=>{const n=tc(),r=zd(),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($m(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Tm(e.getConditionalFormats(),t)}},bi=e=>e.kind==="cut"?{...e.payload,...Ca(e.sourceAdapter,e.range)}:e.payload,Lm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:hs(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Dm=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=nn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...p}=l;s.push(p)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Mm=(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},zm=(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 Ce({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Fm=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(E=>{const T=n.current;if(T===null||E==="format"||E==="annotate")return;const N=r.current;N==="own"||N==="foreign"&&T.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const E=n.current;if(E===null)return;if(E.kind==="copy"){o();return}const T=t.current;T.repaintOverlay(),T.onClipChange?.({kind:"cut",range:E.range,foreign:E.sourceAdapter!==T.adapter})},[o]),c=i.useCallback((E,T,N)=>{const j=t.current;n.current={kind:E,range:T,clipId:N.clipId,sourceAdapter:j.adapter,payload:N},j.repaintOverlay(),j.onClipChange?.({kind:E,range:T,foreign:!1})},[]),u=i.useCallback(E=>{const T=t.current,N=T.adapter,j=ct(E),$={v:1,rows:j.rows,cols:j.cols,clipId:hs(),...Ca(N,E),wholeRows:nc(E,N.colCount),wholeCols:rc(E,N.rowCount)};if(T.resize!==void 0){if($.wholeCols){const k=[];for(let R=E.startCol;R<=E.endCol;R+=1)k.push(Math.min(T.resize.colAxis.sizeOf(R),tn));$.colWidths=k}if($.wholeRows){const k=[];for(let R=E.startRow;R<=E.endRow;R+=1)k.push(Math.min(T.resize.rowAxis.sizeOf(R),tn));$.rowHeights=k}}return $},[]),p=i.useCallback((E,T)=>{const N=t.current,j=N.getSelection(),$=j.ranges[j.ranges.length-1],k=At([$]);if(k>N.maxOperationCells)return E.preventDefault(),N.onOperationRejected?.(T,k,"limit"),null;if(T==="cut"&&sr(N.adapter,$))return E.preventDefault(),N.rejectReadOnly({kind:"operation",op:"cut",cellCount:k}),null;j.ranges.length>1&&N.onCopyMultiRange?.();const R=u($),g=Vi(R),m=yi(E);return m!==null&&(m.setData("text/plain",Nt.serializeClipboardTsv(R.cells.map(y=>y.map(S=>S.t)))),m.setData("text/html",zc(R,g)),m.setData(Yr,g)),E.preventDefault(),{payload:R,range:$}},[u]),h=i.useCallback((E,T)=>t.current.commitPaste(E,T)!==null,[]),b=i.useCallback((E,T,N)=>{const j=t.current;if(!N.sizes||j.resize===void 0)return;const{rowAxis:$,colAxis:k,resizeTracks:R}=j.resize,g=(m,y,S)=>{const L=us(y,S,null,{maxOperationCells:j.maxOperationCells,rowHiddenLimit:cs,axisKind:m});if(!L.ok){j.onOperationRejected?.("resize",L.count,L.reason);return}R(m,L.entries)};if(E.colWidths!==void 0){const m=[];for(let y=T.startCol;y<=T.endCol;y+=1)m.push({index:y,size:E.colWidths[(y-T.startCol)%E.cols]});g("col",k,m)}if(E.rowHeights!==void 0){const m=[];for(let y=T.startRow;y<=T.endRow;y+=1)m.push({index:y,size:E.rowHeights[(y-T.startRow)%E.rows]});g("row",$,m)}},[]),P=i.useCallback((E,T)=>{const N=t.current,j=N.adapter,$=E.payload,k={row:T.startRow,col:T.startCol},R=$.rows*$.cols+At([E.range]);if(R>N.maxOperationCells)return N.onOperationRejected?.("paste",R,"limit"),"rejected";if(k.row+$.rows>j.rowCount||k.col+$.cols>j.colCount||E.range.endRow>=E.sourceAdapter.rowCount||E.range.endCol>=E.sourceAdapter.colCount)return N.onOperationRejected?.("paste",R,"bounds"),"rejected";const g=os({rows:$.rows,cols:$.cols},Ce(k,k),k,j.rowCount,j.colCount);if(g!==null&&sr(j,g))return N.rejectReadOnly({kind:"operation",op:"paste",cellCount:$.rows*$.cols}),"rejected";if(sr(E.sourceAdapter,E.range))return N.rejectReadOnly({kind:"operation",op:"cut",cellCount:At([E.range])}),"rejected";const m=bi(E),y=Wr(j),S=mi(m,y),L={row:0,col:0,readText:()=>In(j,L.row,L.col).text,readFormat:()=>j.getCellFormat===void 0?void 0:j.getCellFormat(L.row,L.col)},{edits:v,tiles:C}=Wl(S.cells,Ce(k,k),k,j.rowCount,j.colCount,(A,d,F)=>(L.row=E.range.startRow+(d-k.row),L.col=E.range.startCol+(F-k.col),wi(A,S,L,di,y))),a=Wr(E.sourceAdapter),f=[];if(Xt([E.range],A=>{f.push(Mm(A.row,A.col,a))}),E.sourceAdapter===j){if(!h([...f,...v],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const A=N.commitPaste(v,{sameSheet:!1,conditionalFormats:Ci(S.conditionalFormats,C)});if(A===null)return"rejected";try{E.sourceAdapter.applyEdits(f,{transaction:A,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){N.onEditRejected?.(d,{source:"paste"})}}return N.setSelection({ranges:[Ce(k,{row:k.row+m.rows-1,col:k.col+m.cols-1})],anchor:k,active:k}),"applied"},[h]),H=i.useCallback((E,T,N)=>{const j=t.current,$=j.adapter,k=B=>(j.onClipboardUnavailable?.(B),"rejected"),R=Yi(E,T);if(R==="none")return T==="menu"?k("empty"):"empty";const g=j.getSelection(),m=g.ranges[g.ranges.length-1],y=N.transpose===!0,S=(B,Z)=>{const ee=Sm(y?Z:B,y?B:Z,m);return ee>j.maxOperationCells?(j.onOperationRejected?.("paste",ee,"limit"),!0):!1};let L,v=null;if(R==="aqsp"){const B=id(E,T);if(B===null)return k("unreadable");const Z=n.current;if(Z!==null&&B.clipId===Z.clipId&&(v=Z),v!==null&&v.kind==="cut"&&Em(N))return P(v,m);if(S(B.rows,B.cols))return"rejected";if(v!==null){if(v.kind==="cut"&&(v.range.endRow>=v.sourceAdapter.rowCount||v.range.endCol>=v.sourceAdapter.colCount))return j.onOperationRejected?.("paste",v.payload.rows*v.payload.cols,"bounds"),"rejected";L=bi(v)}else{const ee=cd(E,T);if(ee===null)return k("unreadable");if(S(ee.rows,ee.cols))return"rejected";L=Dm(ee)}}else if(R==="tsv"){const B=E.getData("text/plain"),Z=Nt.measureTsv(B);if(S(Z.rows,Z.cols))return"rejected";L=Lm(Nt.parseTsv(B))}else{const B=E.getData("text/html"),Z=Md(B);if(Z.cols===0&&Z.rows>j.maxOperationCells)return j.onOperationRejected?.("paste",Z.rows,"limit"),"rejected";if(S(Z.rows,Z.cols))return"rejected";const ee=_c(B,R,j.formats===void 0?{}:{currency:j.formats.currency,locale:j.formats.locale},j.maxOperationCells);if(ee.outcome==="none")return k("unreadable");if(ee.outcome==="limit")return j.onOperationRejected?.("paste",ee.cells,"limit"),"rejected";if(S(ee.payload.rows,ee.payload.cols))return"rejected";L=ee.payload}const C=Wr($),a=mi(y?Cm(L):L,C),f=ga[N.mode];if(Am(f)){const B=os({rows:a.rows,cols:a.cols},m,g.active,$.rowCount,$.colCount);if(B!==null&&sr($,B))return j.rejectReadOnly({kind:"operation",op:"paste",cellCount:At([B])}),"rejected"}const A={row:0,col:0,readText:()=>In($,A.row,A.col).text,readFormat:()=>$.getCellFormat===void 0?void 0:$.getCellFormat(A.row,A.col)},{edits:d,tiles:F}=Wl(a.cells,m,g.active,$.rowCount,$.colCount,(B,Z,ee)=>(A.row=Z,A.col=ee,wi(B,a,A,N,C))),O=zm(F,a.rows,a.cols,$.rowCount,$.colCount);if(O===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let B=0;for(const ee of a.conditionalFormats)B+=ee.ranges.length;const Z=F.length*B;if(Z>j.maxOperationCells)return j.onOperationRejected?.("paste",Z,"limit"),"rejected"}const x=f.cf?Ci(a.conditionalFormats,F):[];if(d.length===0&&x.length===0)return b(a,O,f),"empty";r.current=v===null?"foreign":"own";let z=!1;try{z=h(d,{sameSheet:v!==null&&v.sourceAdapter===$,conditionalFormats:x})}finally{r.current="none"}if(!z)return"rejected";b(a,O,f);const q={row:O.startRow,col:O.startCol};return j.setSelection({ranges:[O],anchor:q,active:q}),"applied"},[P,h,b]),D=i.useCallback(async E=>{const T=y=>(t.current.onClipboardUnavailable?.(y),"rejected"),N=navigator;if(N.clipboard===void 0)return T("insecure-origin");let j;try{j=await N.clipboard.read({unsanitized:["text/html"]})}catch{return T("permission-denied")}if(j.length===0)return T("empty");const $=j[0],k=Array.from($.types),R=new Map;try{for(const y of km)k.includes(y)&&R.set(y,await(await $.getType(y)).text())}catch{return T("unreadable")}const g={types:k,getData:y=>{const S=R.get(y);if(S===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${y} was not materialised for the menu path`);return S}},m=t.current;return!m.enabled||m.isDragging()||m.isEditing()?"rejected":H(g,"menu",E)},[H]),_=i.useCallback(async E=>{const T=await D(E);return t.current.onPasteResolved?.(T,"menu"),T},[D]),{enabled:U,sinkRef:W}=e;return i.useEffect(()=>{const E=W.current;if(!U||E===null)return;const T=k=>t.current.isDragging()?(k.preventDefault(),!0):!1,N=k=>{const R=t.current;if(T(k)||R.isEditing())return;const g=p(k,"copy");g!==null&&c("copy",g.range,g.payload)},j=k=>{const R=t.current;if(T(k)||R.isEditing())return;const g=p(k,"cut");g!==null&&c("cut",g.range,g.payload)},$=k=>{const R=t.current;if(T(k)||R.isEditing())return;k.preventDefault();let g=di;const m=R.pendingPasteOptionsRef;m!==void 0&&m.current!==null&&(g=m.current,m.current=null);const y=yi(k);if(y===null)return;const S=H(Om(y),"event",g);R.onPasteResolved?.(S,"event")};return E.addEventListener("copy",N),E.addEventListener("cut",j),E.addEventListener("paste",$),()=>{E.removeEventListener("copy",N),E.removeEventListener("cut",j),E.removeEventListener("paste",$)}},[U,W,p,c,H]),i.useMemo(()=>({getClip:()=>{const E=n.current;return E===null?null:{kind:E.kind,range:E.range,foreign:E.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},ya=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)}`)},ba=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}},Ri=(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}`}`},Ra=(e,t)=>{let n;if(e.exponent===null)n=Ri(e.negative,e.digits,e.point+t);else{const r=Ri(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return it(n)===null?null:n},Nm=(e,t)=>{ya(t);const n=it(e);return n===null?null:Ra(ba(n),t)},Pm=e=>{const t=it(e);if(t!==null){const r=ba(t);return Ra({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},va=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)},_m=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},ka=(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 _m(r)?r:null},qm=(e,t)=>{ya(t);const n=va(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=ka(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},jm=e=>{const t=va(e),n=ka(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},tr=(e,t,n,r)=>{const o=At(t);return o>n?(r?.(e,o,"limit"),!1):!0},zr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Fr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},vi={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:zr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:zr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:zr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:zr.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:Fr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Fr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Fr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Fr.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"}},Im={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},ur=e=>e<10?`0${e}`:String(e),Hm=e=>{const t=new Date(e);return`${t.getFullYear()}-${ur(t.getMonth()+1)}-${ur(t.getDate())}`},Bm=e=>{const t=new Date(e);return`${ur(t.getHours())}:${ur(t.getMinutes())}:${ur(t.getSeconds())}`},Vm=(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),Wm=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Km=e=>e===void 0||e.borders===void 0?{}:e.borders,Ym={top:1,right:2,bottom:4,left:8},Um={style:"thin",color:ds},Xm=(e,t)=>{if(e===void 0)return!1;const n=Xe(e);return n!==null&&n===Xe(t)},Gm=(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}}},Zm=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const m=g.getActive();return[Ce(m,m)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,m=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(m.row,m.col)},[]),o=i.useCallback(g=>{const m=t.current,y=n();if(!tr("format",y,m.maxOperationCells,m.onOperationRejected))return!1;if(Mn(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"format",cellCount:At(y)}),!1;const S=new Map,L=[],v=m.adapter.getCellFormat;for(const C of y)Xt([C],a=>{const f=v===void 0?void 0:v(a.row,a.col),{bucket:A,patch:d}=g(a,C,f);let F=S.get(A);F===void 0&&(F=new Map,S.set(A,F));let O;F.has(f)?O=F.get(f):(O=ps(f,d),F.set(f,O)),O!==f&&L.push({row:a.row,col:a.col,format:O===void 0?null:O})});return L.length===0?!0:m.commitEdits(L,{source:"format"})===null?!1:(m.isEditing()&&m.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,m)=>{const y=t.current;y.formatCommandAnnouncement!==void 0&&y.announce(y.formatCommandAnnouncement({command:g,state:m}))},[]),c=i.useCallback((g,m=Um)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:m,right:m,bottom:m,left:m}});const y=g==="outer"?15:Ym[g];return o((S,L,v)=>{const C=Vm(S,L)&y;return{bucket:C,patch:{borders:{...Km(v),...Wm(C,m)}}}})},[s,o]),u=i.useCallback((g,m,y)=>{const S=Bc(t.current.adapter,g.row,g.col);for(const L of m)y.push(Vc(S,g,L))},[]),p=i.useCallback(g=>{const m=t.current,y=m.getSelection();if(!tr("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;const S=[];if(g==="selection"){const v=y.active,C=[];Xt(y.ranges,a=>{(a.row!==v.row||a.col!==v.col)&&C.push(a)}),S.push({source:v,targets:C})}else for(const v of y.ranges)if(g==="down"){const C=v.startRow===v.endRow;if(C&&v.startRow===0)continue;const a=C?v.startRow-1:v.startRow;for(let f=v.startCol;f<=v.endCol;f+=1){const A=[];for(let d=C?v.startRow:v.startRow+1;d<=v.endRow;d+=1)A.push({row:d,col:f});S.push({source:{row:a,col:f},targets:A})}}else{const C=v.startCol===v.endCol;if(C&&v.startCol===0)continue;const a=C?v.startCol-1:v.startCol;for(let f=v.startRow;f<=v.endRow;f+=1){const A=[];for(let d=C?v.startCol:v.startCol+1;d<=v.endCol;d+=1)A.push({row:f,col:d});S.push({source:{row:f,col:a},targets:A})}}for(const v of S)for(const C of v.targets)if(Ke(m.adapter,C.row,C.col)){let a=0;for(const f of S)a+=f.targets.length;return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:a}),!1}const L=[];for(const v of S)u(v.source,v.targets,L);return L.length===0?!0:m.commitEdits(L,{source:"fill"})!==null},[u]),h=i.useCallback(()=>{const g=t.current,m=g.getSessionText();if(m===null)return!1;const y=g.getSelection();if(!tr("fill",y.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(Mn(g.adapter,y.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:At(y.ranges)}),!1;const S=[];let L=!1;return Xt(y.ranges,v=>{if(!L){if(!g.validateCommit(v,m).ok){L=!0;return}S.push({row:v.row,col:v.col,text:m})}}),L||g.commitEdits(S,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),b=i.useCallback(g=>{const m=t.current,y=m.getSelection();if(!tr("calc",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(Mn(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"calc",cellCount:At(y.ranges)}),!1;const S=[],L=m.adapter;return Xt(y.ranges,v=>{const C=L.getCellFormula===void 0?void 0:L.getCellFormula(v.row,v.col),a=C===void 0?g.text(L.getCellText(v.row,v.col)):g.formula(C);a!==null&&S.push({row:v.row,col:v.col,text:a})}),S.length===0?!0:m.commitEdits(S,{source:"calc"})!==null},[]),P=i.useCallback((g,m)=>{const y=t.current,S=g==="row"?y.rowAxis:y.colAxis,L=y.getSelection(),v=g==="row"?Math.floor(y.maxOperationCells/as):y.maxOperationCells;let C=0;for(const F of L.ranges)C+=g==="row"?F.endRow-F.startRow+1:F.endCol-F.startCol+1;if(C>v)return y.onOperationRejected?.("resize",C,"limit"),!1;const a=new Set,f=[],A=m?0:g==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const F of L.ranges){const O=g==="row"?F.startRow:F.startCol,x=g==="row"?F.endRow:F.endCol;for(let z=O;z<=x;z+=1){if(a.has(z))continue;a.add(z),S.sizeOf(z)===0!==m&&f.push({index:z,size:A})}}const d=us(S,f,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:cs,axisKind:g});return d.ok?(d.entries.length>0&&y.resizeTracks(g,d.entries),!0):(y.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),H=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const m=g.getActive();return Hn(g.adapter.getCellHyperlink(m.row,m.col))},[]),D=i.useCallback(g=>{const m=t.current,y=m.adapter,S=vi[g],L=y.getCellFormat!==void 0,v=C=>m.popovers===void 0?!0:m.popovers[C]!==!1;switch(S.kind){case"resize":return m.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return L;case"value":return L&&(S.value!=="currency"||m.formats!==void 0);case"popover":switch(S.popover){case"link":return y.getCellHyperlink!==void 0&&v("link");case"note":return y.getCellNote!==void 0&&v("note");case"comment":return y.getCellComments!==void 0&&v("comment");default:return y.getCellValidation!==void 0&&v("list")}case"openHyperlink":return y.getCellHyperlink!==void 0&&(m.onHyperlinkOpen!==void 0?H()!==void 0:v("link"));case"paste":return S.options.mode==="formats"?L:S.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[H]),_=i.useCallback(g=>{const m=t.current,y=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&m.onHyperlinkOpen===void 0?"link":void 0;if(y===void 0)return!0;const S=m.getActive();if(!Ke(m.adapter,S.row,S.col))return!0;if(y==="list")return m.rejectReadOnly({kind:"edit",cell:S,editSession:"none"}),!1;let L;if(y==="link")L=H()!==void 0;else if(y==="note"){const v=m.adapter.getCellNote===void 0?void 0:m.adapter.getCellNote(S.row,S.col);L=v!==void 0&&v!==""}else{const v=m.adapter.getCellComments===void 0?void 0:m.adapter.getCellComments(S.row,S.col);L=v!==void 0&&v.length>0}return L?!0:(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[H]),U=i.useCallback((g,m,y)=>{const S=t.current,L=S.trackResize;if(L===void 0)return!1;const v=S.getActive(),C=m==="col"?v.col:v.row,a=y==="fit"?L.autofitColumn(C):L.stepTrack(m,C,y),f=(m==="col"?S.colAxis:S.rowAxis).sizeOf(C);return a&&f>0&&S.formatResizeAnnouncement!==void 0&&S.announce(S.formatResizeAnnouncement({command:g,axis:m==="col"?"column":"row",index:C,size:f})),a},[]),W=i.useCallback(g=>{const m=t.current;if(!D(g))return!1;const y=vi[g];if(!_(y))return!1;const S=m.isEditing();if(S&&!Es.has(g)&&!m.requestCommit())return!1;switch(y.kind){case"toggle":{const L=r(),v=L!==void 0&&L[y.key]===!0;return s({[y.key]:v?null:!0})?(l(g,!v),!0):!1}case"patch":return s(y.patch)?(l(g,null),!0):!1;case"clear":return s(Im)?(l(g,null),!0):!1;case"value":return s({value:Gm(y.value,m.formats)})?(l(g,null),!0):!1;case"borders":return c(y.preset)?(l(g,null),!0):!1;case"color":{const L=y.key==="background"?m.colors.fill:m.colors.font,v=y.preset!==null?y.preset:y.custom!==null&&y.custom<L.length?L[y.custom]:void 0;if(v===void 0)return!1;const C=r(),a=Xm(C===void 0?void 0:C[y.key],v);return s({[y.key]:a?null:v})?(l(g,!a),!0):!1}case"calc":return b({text:L=>Nm(L,y.exponent),formula:L=>qm(L,y.exponent)});case"sign":return b({text:Pm,formula:jm});case"fill":return S&&y.direction==="selection"?h():p(y.direction);case"popover":return m.openPopover(y.popover),!0;case"openHyperlink":{if(m.onHyperlinkOpen!==void 0){const L=H();return L===void 0?!1:(m.onHyperlinkOpen(L,m.getActive()),!0)}return m.openPopover("link"),!0}case"pasteSpecial":return m.onPasteSpecialRequest!==void 0?(m.onPasteSpecialRequest({kind:"keyboard",cellRect:m.keyboardCellRect()}),!0):(m.paste({mode:"formats"}),!0);case"paste":return m.paste(y.options),!0;case"insertNow":{const L=y.unit==="date"?Hm(m.now()):Bm(m.now());if(S)return m.insertAtCaret(L),!0;const v=m.getActive();return Ke(m.adapter,v.row,v.col)?(m.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1):m.validateCommit(v,L).ok?m.commitEdits([{row:v.row,col:v.col,text:L}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return P(y.axis,y.hide);case"resize":return U(g,y.axis,y.step);default:{const L=m.getHighlight();switch(y.target){case"row":return m.setHighlight({...L,row:!L.row}),!0;case"column":return m.setHighlight({...L,column:!L.column}),!0;case"both":{const v=L.row&&L.column;return m.setHighlight({...L,row:!v,column:!v}),!0}default:return m.setHighlight({...L,intersection:!L.intersection}),!0}}}},[D,_,H,r,s,l,c,b,p,h,P,U]),E=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),T=i.useCallback(g=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const y=g===null?null:nn(g);if(g!==null&&y===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!E())return!1;const S=m.getActive();return Ke(m.adapter,S.row,S.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:S.row,col:S.col,hyperlink:y}],{source:"annotate"})!==null},[E]),N=i.useCallback(g=>{const m=t.current;if(m.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!E())return!1;const y=m.getActive();return Ke(m.adapter,y.row,y.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:y.row,col:y.col,note:g}],{source:"annotate"})!==null},[E]),j=i.useCallback(g=>{const m=t.current,y=m.adapter.getCellComments;if(y===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!E())return!1;const S=m.getActive();if(Ke(m.adapter,S.row,S.col))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const L=y(S.row,S.col),v=L===void 0?[g]:[...L,g];return m.commitEdits([{row:S.row,col:S.col,comments:v}],{source:"annotate"})!==null},[E]),$=i.useCallback(g=>{const m=t.current;if(m.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!E())return!1;const y=m.getSelection().ranges;if(!tr("annotate",y,m.maxOperationCells,m.onOperationRejected))return!1;if(Mn(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:At(y)}),!1;const S=[];return Xt(y,L=>{S.push({row:L.row,col:L.col,validation:g})}),m.commitEdits(S,{source:"annotate"})!==null},[E]),k=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),R=i.useCallback((g,m)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,m)},[c]);return i.useMemo(()=>({executeCommand:W,applyFormat:k,setBorders:R,setHyperlink:T,setNote:N,addComment:j,setValidation:$,isCommandAvailable:D}),[W,k,R,T,N,j,$,D])},Nr="data-aqsp-pointing",Jm=(e,t)=>{const n=Rc(e,t);return n!==null&&"insertAt"in n},Qm=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},eg=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),p=i.useRef(zt),h=i.useCallback(()=>{const C=t.current,a=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=Rc(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),b=i.useCallback(()=>{const C=t.current.sinkRef.current;if(C===null)return;const a=h()!==null;a!==C.hasAttribute(Nr)&&(a?C.setAttribute(Nr,""):C.removeAttribute(Nr))},[h]),P=i.useCallback((C,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const A=f.resolveEditPaint(a),d=A===null?zt:A;d!==zt&&Object.assign(C.style,d.style),p.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),H=i.useCallback(C=>{Qm(C,Object.keys(p.current.style)),p.current=zt;const a=t.current.editPaintRef;a!==void 0&&(a.current=zt)},[]),D=i.useCallback(C=>{const a=t.current,f=n.current;if(f===null)return!0;const A=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),H(d),d.removeAttribute(Nr)),o(!1)};if(C.commit){const d=a.sinkRef.current,F=d===null?"":d.value,O=In(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
-
`),x=F===O;let z;if(x)z=!0;else if(Ke(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:C.onReject==="keep"?"kept":"discarded"}),z=!1;else{const q={source:"edit",editSession:C.onReject==="keep"?"kept":"discarded"};z=(a.validateCommit===void 0||a.validateCommit(f.cell,F).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:F}],q)!==null}if(!z)return C.onReject==="discard"&&(A(),a.rearmSink()),!1}return A(),C.rearm&&a.rearmSink(),!0},[H]),_=i.useCallback((C,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const A=f.sinkRef.current;if(A===null)return;const d=f.getActive();if(Ke(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),C==="edit"){const{text:O,isFormula:x}=In(f.adapter,d.row,d.col);A.value=O;const z=a===void 0||x?O.length:Math.min(a,O.length);A.setSelectionRange(z,z)}else A.value="";const F=f.resolveEditAlign(d);F!==null&&(A.style.textAlign=F),P(A,d),c.current=!1,u.current=null,n.current={cell:d,mode:C},o(!0)},[P]),U=i.useCallback(()=>{D({rearm:!0,commit:!1})},[D]),W=i.useCallback(()=>{const C=t.current;if(n.current===null)return!0;const a=C.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return D({rearm:!1,commit:!0,onReject:"keep"})?(C.focusSink(),C.rearmSink(),!0):(C.focusSink(),!1)}return D({rearm:!0,commit:!0,onReject:"keep"})},[D]),E=i.useCallback(()=>h()!==null,[h]),T=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,b(),!0),[b]),N=i.useCallback(()=>{const C=h(),a=n.current;if(C===null||a===null)return null;if("insertAt"in C.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=bc(C.sink.value,C.sink.selectionStart);if(f===null)return null;const A=f.token,d=u.current;switch(A.kind){case"cell":{const F={row:A.row,col:A.col};return u.current=F,{origin:F,cursor:F,axis:"cells"}}case"range":{const F=d!==null&&(d.row===A.start.row||d.row===A.end.row)&&(d.col===A.start.col||d.col===A.end.col)?{row:d.row,col:d.col}:{row:A.start.row,col:A.start.col};return u.current=F,{origin:F,cursor:{row:F.row===A.start.row?A.end.row:A.start.row,col:F.col===A.start.col?A.end.col:A.start.col},axis:"cells"}}case"column":{const F=d!==null&&(d.col===A.start.col||d.col===A.end.col)?d.col:A.start.col,O={row:a.cell.row,col:F};return u.current=O,{origin:O,cursor:{row:a.cell.row,col:F===A.start.col?A.end.col:A.start.col},axis:"columns"}}case"row":{const F=d!==null&&(d.row===A.start.row||d.row===A.end.row)?d.row:A.start.row,O={row:F,col:a.cell.col};return u.current=O,{origin:O,cursor:{row:F===A.start.row?A.end.row:A.start.row,col:a.cell.col},axis:"rows"}}}},[h]),j=i.useCallback((C,a)=>{const f=h();if(f===null)return;const A=hf(C,a),{sink:d}=f,[F,O]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],x=d.value;d.value=`${x.slice(0,F)}${A}${x.slice(O)}`;const z=F+A.length;d.setSelectionRange(z,z),"row"in C&&(u.current={row:C.row,col:C.col}),b()},[h,b]),$=i.useCallback(()=>{const C=t.current.sinkRef.current;return C===null?null:{value:C.value,selectionStart:C.selectionStart,selectionEnd:C.selectionEnd}},[]),k=i.useCallback(C=>{const a=t.current.sinkRef.current;a!==null&&(a.value=C.value,a.setSelectionRange(C.selectionStart,C.selectionEnd),u.current=null,b())},[b]),R=i.useCallback(()=>{const C=t.current,a=C.sinkRef.current;if(C.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=Sf(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),b(),!0)},[b]),g=i.useCallback(C=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,A=a.selectionEnd;a.value=`${a.value.slice(0,f)}${C}${a.value.slice(A)}`;const d=f+C.length;a.setSelectionRange(d,d),u.current=null,b()},[b]),m=i.useCallback(()=>{const C=t.current.sinkRef.current;return n.current===null||C===null?null:C.value},[]),y=i.useCallback(()=>n.current===null?null:n.current.cell,[]),S=i.useCallback(()=>{const C=t.current,a=n.current,f=C.sinkRef.current;a===null||f===null||(H(f),P(f,a.cell),C.repaintOverlay?.())},[H,P]),{enabled:L,sinkRef:v}=e;return i.useEffect(()=>{const C=v.current;if(!L||C===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},A=O=>{const x=t.current;if(l.current||n.current===null)return;const z=x.rootRef.current,q=O.relatedTarget;z!==null&&q instanceof Node&&z.contains(q)||D({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const O=t.current;u.current=null,O.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Jm(C.value,C.selectionStart)&&(c.current=!0),b()},F=()=>{n.current!==null&&b()};return C.addEventListener("compositionstart",a),C.addEventListener("compositionend",f),C.addEventListener("focusout",A),C.addEventListener("input",d),document.addEventListener("selectionchange",F),()=>{C.removeEventListener("compositionstart",a),C.removeEventListener("compositionend",f),C.removeEventListener("focusout",A),C.removeEventListener("input",d),document.removeEventListener("selectionchange",F)}},[L,v,D,b]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:W,cancelEdit:U,startEdit:_,getPointing:E,togglePointingArm:T,getReferenceCursor:N,insertReference:j,captureSink:$,restoreSink:k,cycleAnchorAtCaret:R,insertAtCaret:g,getSessionText:m,getSessionCell:y,refreshPaint:S,editing:r}),[W,U,_,E,T,N,j,$,k,R,g,m,y,S,r])},tg=(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}},ng=(e,t,n)=>{const{tree:r,initialHidden:o}=tg(e,t,n);let s=o;const u={count:e,sizeOf:p=>r.get(p),offsetOf:p=>{const{cumulative:h,currentValue:b}=r.prefixSum(p);return h-b},indexAt:p=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const h=Math.floor(p),b=Math.min(Math.max(h,0),r.getTotal()-1);return r.findIndexAtOrAfter(b+.5).index},totalSize:()=>r.getTotal(),resize:(p,h)=>{if(!(Number.isFinite(h)&&h>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${h}`);const b=Math.round(h);r.get(p)===0!=(b===0)&&(s+=b===0?1:-1),r.update(p,b)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},Qt=(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)},Pn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:Qt(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=Qt(e,o,1);return r},ki=(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=ng(e,t,r)),o.current.model},_n=256,Io=256,rg=2**32,og=4096,Sa=Object.freeze([]),Ea=["background","color","bold","italic","underline","strikethrough"],Aa=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},en=(e,t,n)=>(e.size>=og&&e.clear(),e.set(t,n),n),Oa=e=>(Aa(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),xa=(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},sg=(e,t,n)=>{const r=Math.floor(t/_n),o=Math.floor(n/Io),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*_n,u=o*Io,p=[];for(const h of e.rules)xa(h.ranges,c,c+_n-1,u,u+Io-1)&&p.push(h);return en(e.buckets,s,p.length===0?Sa:p)},lg=(e,t,n)=>{const r=Math.floor(t/_n),o=r*rg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=sg(e,t,n),c=r*_n,u=[];for(const p of l)xa(p.ranges,c,c+_n-1,n,n)&&u.push(p);return en(e.columns,o,u.length===0?Sa:u)},ig=(e,t)=>{for(const n of e)if(gn(n,t))return!0;return!1},Os=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Pr=(e,t)=>e<t?-1:e>t?1:0,Si=(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}},Ei=new WeakMap,is=e=>e===null?null:Number(e),cg=e=>{const t=Ei.get(e);if(t!==void 0)return t;const n=e.b,r={a:is(it(e.a)),b:n===void 0?null:is(it(n))};return Ei.set(e,r),r},Ta=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:en(e.numbers,r,is(it(n())))},ag=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=cg(e),l=Ta(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Si(e.op,Pr(l,s.a),c===null?null:Pr(l,c));const u=n(),p=e.b;return Si(e.op,Pr(u,e.a),p===void 0?null:Pr(u,p))},ug=(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}},Ho=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]},_r=e=>e.toString(16).padStart(2,"0"),Bo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${_r(r(0))}${_r(r(1))}${_r(r(2))}`,s=r(3);return s===255?o:`${o}${_r(s)}`},Vo=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),dg=(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=Ho(t.color),u=Ho(r.color);const p=n===void 0?void 0:Ho(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||p===null)return null;if(s>l){const b=s;s=l,l=b;const P=c;c=u,u=P}if(n!==void 0&&p!==void 0){const b=n.value===void 0?(s+l)/2:n.value;if(s<b&&b<l)return e<=b?Bo(c,p,Vo(e,s,b)):Bo(p,u,Vo(e,b,l))}return Bo(c,u,Vo(e,s,l))},fg=(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 en(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 p of e.ranges){const h=n.getRangeExtrema(p);if(h===null)return en(r.extrema,e.id,null);c=Math.min(c,h.min),u=Math.max(u,h.max)}return en(r.extrema,e.id,{min:c,max:u})},pg=(e,t,n,r,o,s)=>{const l=Ta(s,n,r);if(l===null)return null;const c=fg(e,t,o,s);return c===null?null:dg(l,t.min,t.mid,t.max,c)},hg=(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:en(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},mg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return ag(s,t,n,o)?e.style:null;case"text":return ug(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=pg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return hg(e,s,t,r,o)?e.style:null;default:return null}},Ai=(e,t)=>ps(e,t),gg=(e,t,n)=>{e[t]=n},wg=(e,t)=>{let n=e;for(const r of Ea)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),gg(n,r,t[r]));return n},Cg=e=>{let t="";for(const n of Ea){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Oi=new WeakMap,yg=Object.freeze({}),bg=e=>{const t=e===void 0?yg:e,n=Oi.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Oi.set(t,r),r},Rg=(e,t,n)=>{const r=bg(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=Ai(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Cg(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Ai(e,t);return l!==void 0&&en(r.byKey,o,l),l},xs=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const l=e.getCellFormat(r,o);if(t===null)return l;const c=lg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let p=null,h=!0;for(const b of c){if(!ig(b.ranges,u))continue;const P=mg(b,u,s,e,n);if(P!==null){if(P!==b.style&&(h=!1),p===null)p=P;else{const H=wg(p,P);H!==p&&(h=!1,p=H)}if(b.stopIfTrue===!0)break}}return p===null?l:Rg(l,p,h)},xi=new WeakMap,vg=e=>{Aa(e,"widthRelevantRules");const t=xi.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 xi.set(e,r),r},kg=({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},Sg=i.memo(kg),Eg=Object.freeze({left:Object.freeze({justifyContent:ir("left")}),center:Object.freeze({justifyContent:ir("center")}),right:Object.freeze({justifyContent:ir("right")})}),Ag=Object.freeze({role:"rowgroup"}),Og=4096,Ti=new WeakMap,qr=new Map,xg=(e,t)=>{if(e===null)return Eg[t];let n=Ti.get(e);n===void 0&&(n={},Ti.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:ir(t)},s=JSON.stringify(o);let l=qr.get(s);return l===void 0&&(qr.size>=Og&&qr.clear(),l=Object.freeze(o),qr.set(s,l)),n[t]=l,l},Tg=Os(),$g=(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},Lg=(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=Vr(e,o,s),c={};let u=null,p;if(e.getCellFormat!==void 0){const h=xs(e,r===null?null:r.indexRef.current,r===null?Tg:r.memoRef.current,o,s,l);p=h===void 0?void 0:h.value;const b=qc(h,l),P=Qt(n,s,1),H=Qt(t,o,1),D=Vd(h,P===null?void 0:e.getCellFormat(o,P),H===null?void 0:e.getCellFormat(H,s),n.offsetOf(s)===0,t.offsetOf(o)===0);D!==null&&Object.assign(c,D.attrs),c["data-aqsp-align"]=b,u=xg(D,b)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const h=e.getCellComments(o,s);h!==void 0&&h.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Hn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const h=e.getCellValidation(o,s);h!==void 0&&Qh(h,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:p}},Dg=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:p,frozenTrailingColumns:h,frozenTrailingRows:b,headerRows:P,labelledBy:H,gridLabel:D,readOnly:_,renderCell:U,onScroll:W,onRangeChange:E,focusSink:T,isEditing:N,requestCommit:j,testId:$,__onCellRender:k,__maxRenderedCells:R,cfIndexRef:g,cfMemoRef:m,isPointing:y,tapScrollCircleOptions:S,overscanRows:L,overscanCols:v,background:C,onRenderTruncated:a,locale:f,scrollLabels:A})=>{const d=i.useRef(null),F=s??d;if(g===void 0!=(m===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const O=i.useMemo(()=>g===void 0||m===void 0?null:{indexRef:g,memoRef:m},[g,m]),x=i.useCallback(()=>r.get().editVersion,[r]),z=i.useCallback(ue=>r.subscribeCoalesced(ue),[r]),B=i.useSyncExternalStore(z,x,x)+(l??0),Z=i.useCallback(ue=>t.sizeOf(ue),[t]),ee=i.useCallback(ue=>n.sizeOf(ue),[n]),oe=i.useCallback((ue,ie)=>e.getCellText(ue,ie),[e]),se=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),ve=i.useMemo(()=>({width:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:S,enableArrowButtonTabStops:!1}),[S]),qe=i.useRef({row:-1,col:-1,value:void 0}),bt=i.useCallback((ue,ie)=>{const je=ue<P,Fe={role:je?"columnheader":"gridcell","aria-rowindex":ue+1,"aria-colindex":ie+1,"data-aqsp-cell":"","data-row":ue,"data-col":ie,className:"aqsp-cell",...Ke(e,ue,ie)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...je?{"data-aqsp-header-row":""}:{}},Ne=Jp(e,ue,ie),Pe=Ne===null?Fe:{...Fe,...Ne},Be=Lg(e,t,n,O,ue,ie),at=qe.current;return at.row=ue,at.col=ie,at.value=Be===null?void 0:Be.value,Be===null?Pe:Be.style===null?{...Pe,...Be.attrs}:{...Pe,...Be.attrs,style:Be.style}},[e,t,n,O,P]),Ie=i.useCallback(ue=>({role:"row","aria-rowindex":ue+1,"data-aqsp-row":ue,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Ze=i.useCallback((ue,ie,je)=>{let Fe=ue;return e.getCellFormat!==void 0&&(Fe=qn(ue,$g(qe.current,ie,je))),Y.jsx(Sg,{row:ie,col:je,text:ue,display:Fe,renderCell:U,__onCellRender:k})},[B,U,k,e]);return Y.jsx("div",{ref:F,className:"aqsp-body","data-aqsp-body":"","data-testid":$?`${$}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":D,"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(),y?.()===!0){ue.stopPropagation(),T();return}if(N()&&!j()){ue.stopPropagation(),T();return}T()}},children:Y.jsx(Ge.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:p,frozenTrailingCols:h,frozenTrailingRows:b,getRowHeight:Z,getColWidth:ee,getCell:oe,getCellProps:bt,getRowProps:Ie,contentProps:Ag,behaviorOptions:se,scrollBarOptions:ve,overscanRows:L,overscanCols:v,background:C,onRenderTruncated:a,__maxRenderedCells:R,locale:f,labels:A,callbackThrottleMs:0,onScroll:W,onRangeChange:E,testId:$,children:Ze})})},Mg=i.memo(Dg),zn=6,lt=3,Zr=(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:lt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=Qt(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-zn,length:lt}),r.push({kind:"unhide",index:s+1,start:c-lt,length:lt})):l>=2*zn?n.push({kind:"resize",index:s,start:c-zn,length:zn}):n.push({kind:"resize",index:s,start:c-lt,length:lt})}return[...n,...r]},$a=(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),p=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:p,length:lt}),n.push({kind:"resize",index:c,start:p+lt,length:lt})):u>=2*zn?n.push({kind:"resize",index:c,start:p,length:zn}):n.push({kind:"resize",index:c,start:p,length:lt})}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-lt,length:lt}),[...n.reverse(),...r]},zg=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:p,enableResizeUI:h,dividerLeadingRef:b,dividerTrailingRef:P})=>{const H=Ge.useWheelBridge(o),D=i.useCallback(d=>(s.current=d,H(d)),[s,H]),_=i.useCallback(()=>{const{colStart:d,colEnd:F,colVersion:O}=e.get();return`${d}:${F}:${O}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,_,_);const{colStart:W,colEnd:E}=e.get(),T=t.count===0?0:t.offsetOf(Math.min(W,t.count-1));i.useLayoutEffect(()=>{c.current=T,u()},[T,c,u]);const N=d=>p.some(F=>d>=F.startCol&&d<=F.endCol),j=Math.min(Math.max(0,n),t.count),$=oa(t,j),k=j>0?Pn(t,0,j-1):[],R=Math.min(Math.max(0,r),t.count-j),g=la(t,R),m=t.totalSize()-g,y=R>0?Pn(t,t.count-R,t.count-1):[],S=Pn(t,Math.max(W,j),Math.min(E,Math.max(0,t.count-1)-R)),L=[];for(const d of S)L.push(Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":N(d)?"":void 0,style:{left:t.offsetOf(d)-T,width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d));const v=h?Zr(t,S):null,C=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<j&&$>0||d.kind==="unhide"&&d.index>=t.count-R&&g>0)),a=h&&j>0?Zr(t,k):null,f=h&&R>0?$a(t,y):null,A=Y.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[L,C?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-T,width:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-T,width:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:D,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:j===0&&R===0?A:Y.jsxs(Y.Fragment,{children:[k.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":N(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Le.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:$,right:R>0?`calc(${Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${Le.SPREADSHEET_SCROLLBAR_SIZE_PX+$}px)))`:void 0},children:[A,j>0?Y.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,R>0?Y.jsx("div",{ref:P,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),R>0?Y.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${$}px, calc(100% - ${g+Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:Y.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[y.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":N(d)?"":void 0,style:{left:t.offsetOf(d)-m,width:t.sizeOf(d)},children:Le.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]})})},Fg=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:p,frozenTrailingRows:h,dividerLeadingRef:b,dividerTrailingRef:P})=>{const H=Ge.useWheelBridge(n),D=i.useCallback(d=>(r.current=d,H(d)),[r,H]),_=d=>o.some(F=>d>=F.startRow&&d<=F.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:F,rowGeomVersion:O}=e.get();return`${d}:${F}:${O}`},[e]),W=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(W,U,U);const{rowStart:E,rowEnd:T}=e.get(),N=t.count===0?0:t.offsetOf(Math.min(E,t.count-1));i.useLayoutEffect(()=>{l.current=N,c()},[N,l,c]);const j=Math.min(Math.max(0,p),t.count),$=sa(t,j),k=j>0?Pn(t,0,j-1):[],R=Math.min(Math.max(0,h),t.count-j),g=ia(t,R),m=t.totalSize()-g,y=R>0?Pn(t,t.count-R,t.count-1):[],S=Pn(t,Math.max(E,j),Math.min(T,Math.max(0,t.count-1)-R)),L=[];for(const d of S)L.push(Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-N,height:t.sizeOf(d)},children:d+1},d));const v=u?Zr(t,S):null,C=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<j&&$>0||d.kind==="unhide"&&d.index>=t.count-R&&g>0)),a=u&&j>0?Zr(t,k):null,f=u&&R>0?$a(t,y):null,A=Y.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[L,C?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-N,height:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-N,height:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:D,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:j===0&&R===0?A:Y.jsxs(Y.Fragment,{children:[k.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:$,bottom:R>0?`calc(min(${g}px, max(0px, 100% - ${$}px)))`:void 0},children:[A,j>0?Y.jsx("div",{ref:b,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,R>0?Y.jsx("div",{ref:P,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),R>0?Y.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${$}px, calc(100% - ${g}px))`},children:Y.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[y.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)-m,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]})})},Ng=9,Pg=4,$i=(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},Li=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,_g=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),p=i.useRef(""),h=i.useRef(null),b=i.useCallback(k=>s.current!==null?k.pointerId===s.current:k.pointerType==="mouse",[]),P=i.useCallback(()=>{const k=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),k.writeResizeGuide(null);const R=h.current;R!==null&&(window.removeEventListener("pointermove",R.move),window.removeEventListener("pointerup",R.up),h.current=null);const g=c.current;g!==null&&s.current!==null&&g.hasPointerCapture?.(s.current)&&g.releasePointerCapture(s.current),c.current=null,s.current=null,k.repaintOverlay()},[]),H=i.useCallback((k,R)=>{const g=t.current;return k==="col"?R.startRow===0&&R.endRow===g.rowAxis.count-1:R.startCol===0&&R.endCol===g.colAxis.count-1},[]),D=i.useCallback((k,R)=>{const g=t.current,m=g.getSelection().ranges.filter(C=>H(k,C));if(!m.some(C=>k==="col"?R>=C.startCol&&R<=C.endCol:R>=C.startRow&&R<=C.endRow))return[R];const S=m.reduce((C,a)=>C+(k==="col"?a.endCol-a.startCol+1:a.endRow-a.startRow+1),0),L=k==="row"?Math.floor(g.maxOperationCells/as):g.maxOperationCells;if(S>L)return g.onOperationRejected?.("resize",S,"limit"),null;const v=new Set;for(const C of m){const a=k==="col"?C.startCol:C.startRow,f=k==="col"?C.endCol:C.endRow;for(let A=a;A<=f;A+=1)v.add(A)}return[...v]},[H]),_=i.useCallback((k,R,g)=>{const m=t.current,y=k==="col"?m.colAxis:m.rowAxis,S=us(y,R,g,{maxOperationCells:m.maxOperationCells,rowHiddenLimit:cs,axisKind:k});return S.ok?(m.resizeTracks(k,S.entries),!0):(m.onOperationRejected?.("resize",S.count,S.reason),!1)},[]),U=i.useCallback((k,R)=>{if(R===k.initialSize)return;const g=k.kind==="unhide"?[k.index]:D(k.axis,k.index);g!==null&&_(k.axis,g.map(m=>({index:m,size:R})),k.index)},[D,_]),W=i.useCallback((k,R)=>{const g=t.current,m=D("col",R);if(m===null)return!1;const y=g.handleRef.current,S=y===null?null:y.getFrozenSize(),L=S===null?0:S.rows,v=S===null?0:S.trailingRows,{rowStart:C,rowEnd:a}=g.viewStore.get(),f=Math.min(a,g.rowAxis.count-1),A=[],d=new Set,F=ie=>{!d.has(ie)&&g.rowAxis.sizeOf(ie)>0&&(d.add(ie),A.push(ie))};for(let ie=0;ie<L;ie+=1)F(ie);for(let ie=C;ie<=f;ie+=1)F(ie);for(let ie=g.rowAxis.count-v;ie<g.rowAxis.count;ie+=1)F(ie);if(A.length===0)return!0;const O=m.length*A.length,x=Math.floor(g.maxOperationCells/Pg);if(O>x)return g.onOperationRejected?.("resize",O,"limit"),!1;const z=document.createElement("canvas").getContext("2d");if(z===null)return!0;const q=getComputedStyle(k),B=`${q.fontStyle} ${q.fontWeight} ${q.fontSize} ${q.fontFamily}`,Z=q.getPropertyValue("--_aqsp-header-row-font-weight").trim(),ee={fontStyle:q.fontStyle,fontWeight:Z===""?q.fontWeight:Z,fontSize:q.fontSize,fontFamily:q.fontFamily},oe=`${ee.fontStyle} ${ee.fontWeight} ${ee.fontSize} ${ee.fontFamily}`,se=g.adapter.getConditionalFormats===void 0?null:vg(g.adapter.getConditionalFormats()),ve=Os(),qe=new WeakMap,bt=new WeakMap,Ie=new Map;for(const ie of m){const je=se===null?null:Oa(se.filter(Fe=>Fe.ranges.some(Ne=>ie>=Ne.startCol&&ie<=Ne.endCol)));for(const Fe of A){const Ne=g.adapter.getCellText(Fe,ie),Pe=g.adapter.getCellFormat===void 0?void 0:xs(g.adapter,je,ve,Fe,ie,()=>Ne),Be=Fe<g.headerRows,at=Pe===void 0?Be?oe:B:Be?$i(Pe,bt,ee):$i(Pe,qe,q),Ot=qn(Ne,Pe===void 0?void 0:Pe.value),Je=Ie.get(at);Je===void 0?Ie.set(at,[{col:ie,text:Ot}]):Je.push({col:ie,text:Ot})}}const Ze=new Map;for(const[ie,je]of Ie){z.font=ie;for(const Fe of je){const Ne=z.measureText(Fe.text).width,Pe=Ze.get(Fe.col);(Pe===void 0||Ne>Pe)&&Ze.set(Fe.col,Ne)}}const ue=[];for(const ie of m){const je=Ze.get(ie);je!==void 0&&je>0&&ue.push({index:ie,size:Math.ceil(je)+Ng})}return ue.length===0?!0:_("col",ue,R)},[D,_]),E=i.useCallback((k,R,g)=>{const m=k==="col"?t.current.colAxis:t.current.rowAxis,y=gu(m.sizeOf(R),g);if(y===m.sizeOf(R))return!0;const S=D(k,R);return S===null?!1:_(k,S.map(L=>({index:L,size:y})),R)},[D,_]),T=i.useCallback(k=>{const R=t.current,g=R.colBandRef.current;return!R.autofitEnabled||g===null?!1:R.colAxis.sizeOf(k)===0?!0:W(g,k)},[W]),{enabled:N,colBandRef:j,rowBandRef:$}=e;return i.useEffect(()=>{const k=j.current,R=$.current;if(!N||k===null||R===null)return;const g=x=>x==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",m=(x,z)=>{if(!(z instanceof Element))return null;const q=z.closest(g(x));if(q===null)return null;const B=q.hasAttribute("data-aqsp-unhide"),Z=Number(q.getAttribute(B?"data-aqsp-unhide":x==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ee=q.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:B?"unhide":"resize",index:Z,anchor:ee}},y=x=>{if(!(n.current&&b(x)))return;const z=r.current;if(z===null)return;const q=(z.axis==="col"?x.clientX-z.startClientX:x.clientY-z.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(z.anchor==="trailing"?z.initialSize-q:z.initialSize+q)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const B=r.current;if(!n.current||B===null)return;const Z=t.current,ee=B.axis==="col"?Z.colAxis:Z.rowAxis;Z.writeResizeGuide({axis:B.axis,position:Li(B,ee,o.current),anchor:B.anchor})}))},S=()=>{const x=r.current,z=o.current;P(),x!==null&&U(x,z)},L=x=>{y(x),n.current&&b(x)&&(l.current&1)!==0&&(x.buttons&1)===0&&S()},v=x=>{x.button!==0||!(n.current&&b(x))||S()},C=(x,z)=>q=>{const B=t.current;if(p.current=q.pointerType,q.pointerType!=="mouse")return;if(q.button!==0){q.preventDefault();return}const Z=m(x,q.target);if(Z===null)return;if(q.stopPropagation(),q.preventDefault(),B.isPointing()){B.focusSink();return}if(B.isEditing()&&!B.requestCommit()){B.focusSink();return}B.focusSink();const ee=x==="col"?B.colAxis:B.rowAxis,oe={axis:x,kind:Z.kind,index:Z.index,anchor:Z.anchor,initialSize:ee.sizeOf(Z.index),startClientX:q.clientX,startClientY:q.clientY};r.current=oe,o.current=oe.initialSize,l.current=q.buttons,n.current=!0,B.repaintOverlay(),s.current=q.pointerId,c.current=z;try{z.setPointerCapture(q.pointerId)}catch{s.current=null}const se=L,ve=v;h.current={move:se,up:ve},window.addEventListener("pointermove",se),window.addEventListener("pointerup",ve),B.writeResizeGuide({axis:x,position:Li(oe,ee,o.current),anchor:oe.anchor})},a=(x,z)=>q=>{const B=t.current;if(p.current!=="mouse")return;const Z=z.getRootNode(),ee=Z instanceof ShadowRoot?Z:z.ownerDocument,oe=q.target instanceof Element&&q.target.closest(g(x))!==null?q.target:typeof ee.elementFromPoint=="function"?ee.elementFromPoint(q.clientX,q.clientY):null,se=m(x,oe);if(se!==null){if(q.stopPropagation(),B.isEditing()){B.focusSink();return}if(se.kind==="unhide"){_(x,[{index:se.index,size:x==="col"?B.defaultColumnWidth:B.defaultRowHeight}],null);return}if(B.autofitEnabled){if(x==="row"){const ve=D("row",se.index);ve!==null&&_("row",ve.map(qe=>({index:qe,size:B.defaultRowHeight})),se.index);return}W(z,se.index)}}},f=x=>{!n.current||s.current===null||x.pointerId!==s.current||P()},A=C("col",k),d=C("row",R),F=a("col",k),O=a("row",R);return k.addEventListener("pointerdown",A,{capture:!0}),R.addEventListener("pointerdown",d,{capture:!0}),k.addEventListener("dblclick",F),R.addEventListener("dblclick",O),k.addEventListener("lostpointercapture",f),R.addEventListener("lostpointercapture",f),()=>{k.removeEventListener("pointerdown",A,{capture:!0}),R.removeEventListener("pointerdown",d,{capture:!0}),k.removeEventListener("dblclick",F),R.removeEventListener("dblclick",O),k.removeEventListener("lostpointercapture",f),R.removeEventListener("lostpointercapture",f),P()}},[N,j,$,b,P,U,_,D,W]),i.useMemo(()=>({stepTrack:E,autofitColumn:T,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&P()},cancelDrag:P}),[P,E,T])},Ts=(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)=>Ts(n,t.ranges[r]))&&Pt(e.anchor,t.anchor)&&Pt(e.active,t.active),jg=(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=>rn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:Ce(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)}},Ig=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Ts(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},pr=(e,t,n)=>n.extend?fn(e,t):n.append?{ranges:[...e.ranges,Ce(t,t)],anchor:t,active:t}:e.ranges.length===1&&Pt(e.anchor,t)&&Pt(e.active,t)&&Ts(e.ranges[0],Ce(t,t))?e:{ranges:[Ce(t,t)],anchor:t,active:t},Hg=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),fn=(e,t)=>{const n=Ig(e,Ce(e.anchor,t));return n.ranges.some(r=>gn(r,n.active))?n:{...n,active:Hg(n.active,n.ranges[n.ranges.length-1])}},La=(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(Ce({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Ce({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),p=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Ce({row:u,col:c.startCol},{row:p,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Ce({row:u,col:t.endCol+1},{row:p,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Ce(n,n)],anchor:n,active:n};const s=o.findIndex(c=>gn(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}},Bg=(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}}},Da=(e,t)=>{const n=e.ranges.findIndex(o=>gn(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=Bg(e.ranges,r.rangeIndex,r.cell,t),!Pt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Mt=24,Di=32,Jr=4,xn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),p=i.useRef(null),h=i.useRef(null),b=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,h.current=null,p.current=null},[]),P=i.useCallback(()=>{const D=u.current,_=e.current,U=h.current;if(D===null||_===null||U===null){c.current=null;return}const{clientX:W,clientY:E}=D.getPointerPosition(),T=l.current,N=(W-U.left)/T,j=(E-U.top)/T,$=_.getViewportSize(),k=$.width,R=$.height;if(k<=0||R<=0){c.current=requestAnimationFrame(P);return}const g=C=>Math.min(Di,Math.ceil(C/Mt*Di));let m=0,y=0;if(s!=="x"){const C=_.getFrozenSize(),a=C.trailingVisibleHeight;j>R-a-Mt?D.anchorRow!==void 0&&C.trailingRows>0&&D.anchorRow>=t.count-C.trailingRows&&a>0&&j>=R-a||(m=g(j-(R-a-Mt))):j<C.height+Mt&&(D.anchorRow!==void 0&&D.anchorRow<C.rows&&C.height>0&&j<C.height||(m=-g(C.height+Mt-j)))}if(s!=="y"){const C=_.getFrozenSize(),a=C.trailingVisibleWidth;N>k-a-Mt?D.anchorCol!==void 0&&C.trailingCols>0&&D.anchorCol>=n.count-C.trailingCols&&a>0&&N>=k-a||(y=g(N-(k-a-Mt))):N<C.width+Mt&&(D.anchorCol!==void 0&&D.anchorCol<C.cols&&C.width>0&&N<C.width||(y=-g(C.width+Mt-N)))}const S=y!==0||m!==0?_.scrollBy({x:y!==0?y:void 0,y:m!==0?m:void 0}):_.getScrollPosition(),L=S.y,v=S.x;if(L>=0&&v>=0&&t.totalSize()>0&&n.totalSize()>0){const C=_.getFrozenSize(),a=rn({row:yr(t,j,{scroll:L,frozenSize:C.height,trailingSize:C.trailingHeight,extent:$.height}),col:Cr(n,N,{scroll:v,frozenSize:C.width,trailingSize:C.trailingWidth,extent:$.width})},t.count,n.count),f=p.current;(m!==0||y!==0||f===null||f.row!==a.row||f.col!==a.col)&&(p.current=a,o(D.buildRange(a)))}c.current=requestAnimationFrame(P)},[e,t,n,s,o]),H=i.useCallback(D=>{b(),u.current=D,h.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(P)},[b,P,r]);return i.useEffect(()=>{const D=()=>{document.visibilityState==="hidden"&&b()};return document.addEventListener("visibilitychange",D),()=>{document.removeEventListener("visibilitychange",D),b()}},[b]),i.useMemo(()=>({start:H,stop:b}),[H,b])},Mi=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),p=i.useRef(0),h=i.useRef(null),b=i.useRef(!1),P=i.useRef(0),H=i.useCallback(($,k)=>{const{axis:R,mainAxis:g,handleRef:m,zoomRef:y}=t.current,S=s.current;if(S===null||g.totalSize()===0)return null;const L=y.current,v=m.current;if(v===null)return null;if(R==="col"){const A=v.getScrollPosition().x;if(A<0)return null;const d=v.getFrozenSize(),F=v.getViewportSize();return Math.min(Math.max(Cr(g,($-S.left)/L,{scroll:A,frozenSize:d.width,trailingSize:d.trailingWidth,extent:F.width}),0),g.count-1)}const C=v.getScrollPosition().y;if(C<0)return null;const a=v.getFrozenSize(),f=v.getViewportSize();return Math.min(Math.max(yr(g,(k-S.top)/L,{scroll:C,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),D=i.useCallback(($,k)=>{const{axis:R,crossCount:g}=t.current;return R==="col"?{press:{row:0,col:$},extend:{row:g-1,col:k}}:{press:{row:$,col:0},extend:{row:k,col:g-1}}},[]),_=i.useCallback(($,k)=>{const{axis:R,crossCount:g}=t.current;return $.ranges.some(m=>R==="col"?m.startRow===0&&m.endRow===g-1&&k>=m.startCol&&k<=m.endCol:m.startCol===0&&m.endCol===g-1&&k>=m.startRow&&k<=m.endRow)},[]),U=i.useRef(!1),W=i.useRef({clientX:0,clientY:0}),E=i.useCallback(()=>{U.current=!1;const{autoScroller:$,headerRef:k,onDragFrame:R}=t.current;n.current=!1,r.current=null,h.current=null,b.current=!1,P.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),$.stop();const g=k.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,R(null),t.current.repaintOverlay()},[]),T=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.setSelection($),E()},[E]),{enabled:N,headerRef:j}=e;return i.useEffect(()=>{const $=j.current;if(!N||$===null)return;const k=v=>{const C=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}if(b.current=!1,C.pointing?.getPointing()){s.current=$.getBoundingClientRect();const d=H(v.clientX,v.clientY);if(d===null)return;v.preventDefault(),C.focusSink(),C.pointing.insertReference(C.axis==="col"?{row:0,col:d}:{row:d,col:0},C.axis==="col"?"columns":"rows");return}if(C.isEditing()&&!C.requestCommit()){v.preventDefault(),C.focusSink();return}s.current=$.getBoundingClientRect();const a=H(v.clientX,v.clientY);if(a===null)return;v.preventDefault(),C.focusSink();const f=C.getSelection();r.current=f;const A=v.ctrlKey||v.metaKey;if(v.shiftKey){const d=C.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:F}=D(a,a),O={...f,anchor:d};C.setSelection(fn(O,F)),o.current=C.axis==="col"?d.col:d.row}else if(A&&_(f,a))b.current=!0,P.current=a,o.current=a;else{const{press:d,extend:F}=D(a,a),O=pr(f,d,{extend:!1,append:A});C.setSelection(fn(O,F)),o.current=a}n.current=!0,C.repaintOverlay(),l.current={clientX:v.clientX,clientY:v.clientY},u.current=v.pointerId,p.current=v.buttons;try{$.setPointerCapture(v.pointerId)}catch{u.current=null}h.current=d=>{const F=t.current.axis==="col"?d.col:d.row,{press:O}=D(o.current,o.current),{extend:x}=D(o.current,F);return Ce(O,x)},C.autoScroller.stop(),U.current=!1,W.current={clientX:v.clientX,clientY:v.clientY}},R=v=>u.current!==null?v.pointerId===u.current:v.pointerType==="mouse",g=v=>{if(n.current&&R(v)){if(b.current){const C=v.clientX!==l.current.clientX||v.clientY!==l.current.clientY;if(l.current={clientX:v.clientX,clientY:v.clientY},!C)return;const a=H(v.clientX,v.clientY);if(a===null||a===P.current)return;b.current=!1;const f=t.current,{press:A,extend:d}=D(P.current,P.current),F=pr(f.getSelection(),A,{extend:!1,append:!0});f.setSelection(fn(F,d));const O=h.current,x=Math.abs(v.clientX-W.current.clientX),z=Math.abs(v.clientY-W.current.clientY);O!==null&&Math.max(x,z)>=Jr&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:O,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:v.clientX,clientY:v.clientY},!U.current&&h.current!==null){const C=Math.abs(v.clientX-W.current.clientX),a=Math.abs(v.clientY-W.current.clientY);Math.max(C,a)>=Jr&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:h.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=h.current;if(!n.current||C===null)return;const a=H(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(C(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},m=v=>{g(v),n.current&&R(v)&&(p.current&1)!==0&&(v.buttons&1)===0&&S(v)},y=v=>{v.button!==0||!(n.current&&R(v))||S(v)},S=v=>{const C=t.current;if(b.current){const{press:f,extend:A}=D(P.current,P.current);C.setSelection(La(C.getSelection(),Ce(f,A),f)),E();return}const a=H(v.clientX,v.clientY);if(a!==null){const{extend:f}=D(o.current,a);C.setSelection(fn(C.getSelection(),f))}E()},L=v=>{!n.current||u.current===null||v.pointerId!==u.current||T()};return $.addEventListener("pointerdown",k),$.addEventListener("pointermove",m),$.addEventListener("pointerup",y),$.addEventListener("lostpointercapture",L),()=>{$.removeEventListener("pointerdown",k),$.removeEventListener("pointermove",m),$.removeEventListener("pointerup",y),$.removeEventListener("lostpointercapture",L),E()}},[N,j,H,D,E,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:T,cancelDrag:E}),[T,E])},Vg=({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 p=o.getFrozenSize();if(u>0&&r.row>=p.rows&&r.row<t.count-p.trailingRows){const h=t.offsetOf(r.row),b=h+t.sizeOf(r.row);h<p.height+l?o.scrollBy({y:h-(p.height+l)}):b>l+u-p.trailingVisibleHeight&&o.scrollBy({y:b-(l+u-p.trailingVisibleHeight)})}if(c>0){if(r.col<p.cols||r.col>=n.count-p.trailingCols)return;const h=n.offsetOf(r.col),b=h+n.sizeOf(r.col);h<p.width+s?o.scrollBy({x:h-(p.width+s)}):b>s+c-p.trailingVisibleWidth&&o.scrollBy({x:b-(s+c-p.trailingVisibleWidth)})}},Wg=50,Kg=100,Ma=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Wg:!1,nr={selectAll:Gt("Ctrl+A"),undo:Gt("Ctrl+Z"),redo:Gt("Ctrl+Y"),redoShiftZ:Gt("Ctrl+Shift+Z"),pasteValues:Gt("Ctrl+Shift+V")},Yg=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Ug={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Xg=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Gg=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:p}=e;i.useEffect(()=>{const h=c.current,b=u.current;if(!l||h===null||b===null)return;const P=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},H=(a,f,A)=>Qt(a,f,A)??f,D=(a,f)=>{const A=s.current;return f==="left"||f==="right"?{row:a.row,col:H(A.colAxis,a.col,f==="right"?1:-1)}:{row:H(A.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),W=(a,f,A,d)=>{if(a.sizeOf(f)>0)return f;const F=Qt(a,f,A);if(F!==null)return F;const O=Qt(a,f,A===1?-1:1);return O!==null?O:d},E=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},T=a=>D(E(),a),N=(a,f)=>{const A=s.current,d=f==="left"||f==="right",F=f==="right"||f==="down"?1:-1;let O;return A.findDataEdge!==void 0?(O=A.findDataEdge({row:a.row,col:a.col},f),j(O,a,f)):O={row:f==="down"?A.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?A.colAxis.count-1:f==="left"?0:a.col},d?{row:O.row,col:W(A.colAxis,O.col,F,a.col)}:{row:W(A.rowAxis,O.row,F,a.row),col:O.col}},j=(a,f,A)=>{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 F=A==="left"||A==="right";if(F?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${F?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},$=(a,f,A)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${A} component ${a} (count ${f})`)},k=a=>{const f=s.current,A=f.getSelection();if(Da(A,a)===A){f.moveActive({mode:"reset",cell:D(A.active,a)});return}f.moveActive({mode:"cycle",direction:a})},R=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,A=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
|
|
14
|
-
${a.value.slice(A)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const A=s.current,d=p.current?.getViewportSize().height??-1;return d<=0?H(A.rowAxis,a,f==="down"?1:-1):A.rowAxis.indexAt(A.rowAxis.offsetOf(a)+(f==="down"?d:-d))},m=a=>{const f=s.current;if(r.current=!1,Ma(a,t.current))return;const A=a.ctrlKey||a.metaKey,d=a.altKey,F=Ug[a.key];if(o.current&&!Yg.has(a.key)&&!f.isDragging()&&P(),f.isEditing()){const x=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!A&&!a.shiftKey&&!d&&f.abortDrag();return}const z=f.pointing;if(z!==void 0){if(F!==void 0&&!d){const B=z.getReferenceCursor();if(B!==null){a.preventDefault();const Z=rn(B.cursor,f.rowAxis.count,f.colAxis.count),ee=rn(B.origin,f.rowAxis.count,f.colAxis.count),oe=A?N(Z,F):D(Z,F);if(f.ensureCellVisible(oe),z.insertReference(a.shiftKey?Ce(ee,oe):oe,B.axis),f.onPointFrame!==void 0){const se=a.shiftKey?Ce(ee,oe):Ce(oe,oe);f.onPointFrame(B.axis==="columns"?Ce({row:0,col:se.startCol},{row:f.rowAxis.count-1,col:se.endCol}):B.axis==="rows"?Ce({row:se.startRow,col:0},{row:se.endRow,col:f.colAxis.count-1}):se),o.current=!0}return}}if(a.key==="F2"&&!A&&!a.shiftKey&&!d&&z.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!A&&!a.shiftKey&&!d&&z.cycleAnchorAtCaret()){a.preventDefault();return}}const q=f.commands;if(q!==void 0){const B=Yl(q.table,a);if(B!==null&&Es.has(B)&&q.isAvailable(B)){a.preventDefault(),q.execute(B);return}}if(F!==void 0&&!d){if(A&&a.shiftKey){a.preventDefault();return}if(A)return;if(x==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:T(F)}):f.moveActive({mode:"reset",cell:D(f.getSelection().active,F)});return}return}if(a.key==="Enter"&&d&&!A&&!a.shiftKey){a.preventDefault(),R();return}if((a.key==="Enter"||a.key==="Tab")&&!A&&!d){if(a.preventDefault(),!f.requestCommit())return;const B=!a.shiftKey;k(a.key==="Tab"?B?"right":"left":B?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!A&&!d){if(a.preventDefault(),!f.requestCommit())return;const B=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(B.row,a.key==="PageDown"?"down":"up"),col:B.col}});return}if(a.key==="Escape"&&!A&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const O=f.commands;if(O!==void 0){const x=Yl(O.table,a);if(x!==null&&O.isAvailable(x)){a.preventDefault(),O.execute(x);return}}if(F!==void 0&&!d){const x=F==="left"||F==="right",z=F==="right"||F==="down"?1:-1;if(A&&a.shiftKey){a.preventDefault();const q=f.getSelection(),B=E();let Z;if(f.findDataEdge!==void 0){const ee=x?{row:q.active.row,col:B.col}:{row:B.row,col:q.active.col},oe=f.findDataEdge(ee,F);Z=x?oe.col:oe.row,$(Z,x?f.colAxis.count:f.rowAxis.count,x?"col":"row"),Z=W(x?f.colAxis:f.rowAxis,Z,z,x?B.col:B.row)}else{const ee=x?f.colAxis:f.rowAxis;Z=z===1?U(ee):_(ee)}f.moveActive({mode:"extend",cell:x?{row:B.row,col:Z}:{row:Z,col:B.col}});return}if(A){a.preventDefault(),f.moveActive({mode:"reset",cell:N(f.getSelection().active,F)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:T(F)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:D(f.getSelection().active,F)});return}if(Xg(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!A&&!d){a.preventDefault();const x=!a.shiftKey;k(a.key==="Tab"?x?"right":"left":x?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const z=E();f.moveActive({mode:"extend",cell:{row:A?_(f.rowAxis):z.row,col:_(f.colAxis)}});return}const x=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:A?_(f.rowAxis):x.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const z=E();f.moveActive({mode:"extend",cell:{row:A?U(f.rowAxis):z.row,col:U(f.colAxis)}});return}const x=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:A?U(f.rowAxis):x.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!A&&!d){a.preventDefault();const x=a.key==="PageDown"?"down":"up";if(a.shiftKey){const q=E();f.moveActive({mode:"extend",cell:{row:g(q.row,x),col:q.col}});return}const z=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(z.row,x),col:z.col}});return}if(a.key==="F2"&&!A&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!A&&!a.shiftKey&&!d){a.preventDefault();const x=f.getSelection(),z=At(x.ranges);if(z>f.maxOperationCells){f.onOperationRejected?.("delete",z,"limit");return}if(f.adapter!==void 0&&Mn(f.adapter,x.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:z});return}const q=[],B=f.adapter!==void 0&&Wr(f.adapter).hyperlink;Xt(x.ranges,Z=>{q.push(B?{row:Z.row,col:Z.col,text:"",hyperlink:null}:{row:Z.row,col:Z.col,text:""})}),f.commitEdits(q,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(A||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(Qn(nr.selectAll,a)){a.preventDefault();const x=f.getSelection(),z=Ce({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[z],anchor:x.anchor,active:x.active});return}if(Qn(nr.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(Qn(nr.redo,a)||Qn(nr.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!A&&!d||a.key==="ContextMenu"&&!A&&!a.shiftKey&&!d){a.preventDefault();const x=f.getSelection().active;f.ensureCellVisible(x);const z=p.current,q=z===null?{x:0,y:0}:z.getScrollPosition(),B=Math.max(0,q.y),Z=Math.max(0,q.x),ee=z===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:z.getFrozenSize(),oe=z===null?{width:0,height:0}:z.getViewportSize(),se=f.zoomRef.current;f.onCellContextMenu?.(x,{kind:"keyboard",cellRect:{top:mn(f.rowAxis,x.row,{scroll:B,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:oe.height})*se,left:hn(f.colAxis,x.col,{scroll:Z,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:oe.width})*se,width:f.colAxis.sizeOf(x.col)*se,height:f.rowAxis.sizeOf(x.row)*se}});return}if(a.key===" "&&!d&&A!==a.shiftKey){a.preventDefault();const x=f.getSelection(),z=x.ranges.map(q=>A?Ce({row:0,col:q.startCol},{row:f.rowAxis.count-1,col:q.endCol}):Ce({row:q.startRow,col:0},{row:q.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:z,anchor:x.anchor,active:x.active});return}if(f.pendingPasteOptionsRef!==void 0&&Qn(nr.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}},y=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},S=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Kg)},L=()=>{const a=s.current;if(P(),!a.isEditing()){if(r.current){r.current=!1;const f=h.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){h.value=f,h.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},v=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},C=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),P()};return h.addEventListener("keydown",m),h.addEventListener("keyup",v),h.addEventListener("blur",C),h.addEventListener("compositionstart",y),h.addEventListener("compositionend",S),h.addEventListener("input",L),()=>{h.removeEventListener("keydown",m),h.removeEventListener("keyup",v),h.removeEventListener("blur",C),h.removeEventListener("compositionstart",y),h.removeEventListener("compositionend",S),h.removeEventListener("input",L),n.current!==null&&window.clearTimeout(n.current),P()}},[l,c,u,p])},Zg=()=>{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)})}},Jg=4,Qg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),ew=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),p=i.useRef({dx:0,dy:0}),h=i.useRef(null),b=i.useRef(0),P=i.useRef(null),H=i.useRef(null),D=i.useRef(!1),_=i.useCallback($=>h.current!==null?$.pointerId===h.current:$.pointerType==="mouse",[]),U=i.useCallback(($,k)=>{const{handleRef:R,rowAxis:g,colAxis:m}=t.current,y=R.current,S=s.current;if(y===null||S===null)return null;const{x:L,y:v}=y.getScrollPosition();if(v<0||L<0||g.totalSize()===0||m.totalSize()===0)return null;const C=t.current.zoomRef.current,a=y.getFrozenSize(),f=y.getViewportSize();return rn({row:yr(g,(k-S.top)/C,{scroll:v,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Cr(m,($-S.left)/C,{scroll:L,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,m.count)},[]),W=i.useCallback($=>{const k=r.current;if(k===null)return Ce($,$);const R=Ce({row:Math.min(k.startRow,$.row),col:Math.min(k.startCol,$.col)},{row:Math.max(k.endRow,$.row),col:Math.max(k.endCol,$.col)}),g=R.startRow!==k.startRow||R.endRow!==k.endRow||R.startCol!==k.startCol||R.endCol!==k.endCol;return o.current=g?R:null,g?R:k},[]),E=i.useCallback(()=>{const $=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,P.current!==null&&(cancelAnimationFrame(P.current),P.current=null),$.xAutoScroller.stop(),$.yAutoScroller.stop(),D.current=!1,u.current=!1,p.current={dx:0,dy:0},$.writeFillPreview(null);const k=H.current;k!==null&&(window.removeEventListener("pointermove",k.move),window.removeEventListener("pointerup",k.up),H.current=null);const R=t.current.handleNodeRef.current;R!==null&&h.current!==null&&R.hasPointerCapture?.(h.current)&&R.releasePointerCapture(h.current),h.current=null,$.repaintOverlay()},[]),T=i.useCallback(()=>{const $=t.current,k=r.current,R=o.current;if(E(),k===null||R===null)return;const g=th(k,R);if(g>$.maxOperationCells){$.onOperationRejected?.("fill",g,"limit");return}if(Mn($.adapter,nh(k,R))){const S=(R.endRow-R.startRow+1)*(R.endCol-R.startCol+1),L=(k.endRow-k.startRow+1)*(k.endCol-k.startCol+1);$.rejectReadOnly({kind:"operation",op:"fill",cellCount:S-L});return}const m=rh((S,L)=>Bc($.adapter,S,L),k,R,Vc);if($.commitEdits(m,{source:"fill"})===null)return;const y=$.getSelection();$.setSelection({ranges:[R],anchor:y.anchor,active:y.active})},[E]),{enabled:N,handleNodeRef:j}=e;return i.useEffect(()=>{const $=j.current;if(!N||$===null)return;const k=S=>{R(S),n.current&&_(S)&&(b.current&1)!==0&&(S.buttons&1)===0&&T()},R=S=>{if(!(n.current&&_(S)))return;l.current={clientX:S.clientX,clientY:S.clientY};const L=Math.abs(S.clientX-c.current.clientX),v=Math.abs(S.clientY-c.current.clientY);if(!u.current&&Math.max(L,v)>=Jg&&(u.current=!0),!!u.current){if(!D.current){const C=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-p.current.dx,clientY:l.current.clientY-p.current.dy}),buildRange:W,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};C.xAutoScroller.start(a),C.yAutoScroller.start(a),D.current=!0}P.current===null&&(P.current=requestAnimationFrame(()=>{if(P.current=null,!(n.current&&u.current))return;const C=U(l.current.clientX-p.current.dx,l.current.clientY-p.current.dy);C!==null&&t.current.writeFillPreview(W(C))}))}},g=S=>{S.button!==0||!(n.current&&_(S))||T()},m=S=>{const L=t.current;if(S.pointerType!=="mouse")return;if(S.button!==0){S.preventDefault();return}S.preventDefault(),S.stopPropagation(),L.focusSink();const v=L.getSelection(),C=v.ranges[v.ranges.length-1];r.current=C,o.current=null,u.current=!1,L.xAutoScroller.stop(),L.yAutoScroller.stop(),D.current=!1,c.current={clientX:S.clientX,clientY:S.clientY},l.current=c.current,b.current=S.buttons,n.current=!0,L.repaintOverlay(),s.current=L.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=L.handleRef.current?.getScrollPosition()??{x:-1,y:-1},A=f.y;if(a!==null&&A>=0&&f.x>=0){const O=f.x,x=L.zoomRef.current,z=L.handleRef.current?.getFrozenSize()??Qg,q=L.handleRef.current?.getViewportSize()??{width:0,height:0},B={scroll:O,frozenCount:z.cols,trailingCount:z.trailingCols,extent:q.width},Z={scroll:A,frozenCount:z.rows,trailingCount:z.trailingRows,extent:q.height},ee=hn(L.colAxis,C.endCol,B)+L.colAxis.sizeOf(C.endCol),oe=mn(L.rowAxis,C.endRow,Z)+L.rowAxis.sizeOf(C.endRow),se=ee-1,ve=C.endCol>=z.cols&&z.width>0?Math.max(se,z.width):se,bt=!(C.endCol>=L.colAxis.count-z.trailingCols)&&z.trailingWidth>0?Math.min(ve,q.width-z.trailingVisibleWidth-1):ve,Ie=oe-1,Ze=C.endRow>=z.rows&&z.height>0?Math.max(Ie,z.height):Ie,ie=!(C.endRow>=L.rowAxis.count-z.trailingRows)&&z.trailingHeight>0?Math.min(Ze,q.height-z.trailingVisibleHeight-1):Ze;p.current={dx:S.clientX-(a.left+bt*x),dy:S.clientY-(a.top+ie*x)}}else p.current={dx:0,dy:0};h.current=S.pointerId;try{$.setPointerCapture(S.pointerId)}catch{h.current=null}const d=k,F=g;H.current={move:d,up:F},window.addEventListener("pointermove",d),window.addEventListener("pointerup",F),L.writeFillPreview(r.current)},y=S=>{!n.current||h.current===null||S.pointerId!==h.current||E()};return $.addEventListener("pointerdown",m),$.addEventListener("lostpointercapture",y),()=>{$.removeEventListener("pointerdown",m),$.removeEventListener("lostpointercapture",y),E()}},[N,j,_,U,W,E,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&E()},cancelDrag:E}),[E])},tw=320,Kr=8,nw=64,rw=150,za=e=>Math.max(0,Math.min(tw,e.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX-Kr)),ow=(e,t,n)=>{const r=n.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,s=za(n),l=Math.max(0,Math.min(t,o-Kr)),c=e.left+e.width,u=e.top+e.height,p=_=>_>=0&&_+s<=r,h=[e.left,c-s],b=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of b)if(p(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const P=o-u,H=e.top,D=Math.min(l,Math.max(P,H));if(D>=nw){const _=P>=H?u:e.top-D;for(const U of h)if(p(U))return{left:U,top:_,width:s,height:D}}return{left:Kr,top:Kr,width:s,height:l}},sw=(e,t,n,r)=>t===null||e!==null&&Pt(e,t)||n?!1:r(t),lw=(e,t)=>{switch(e.kind){case"note":return Y.jsx(ha,{ctx:e,labels:t});case"note-tip":return Y.jsx(ma,{ctx:e,labels:t});case"comment":return Y.jsx(ua,{ctx:e,labels:t});case"link":return Y.jsx(da,{ctx:e,labels:t});case"list":return Y.jsx(fa,{ctx:e,labels:t});default:return Y.jsx(pa,{ctx:e,labels:t})}},Wo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,iw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),p=i.useRef(l);p.current=l;const h=i.useRef(e);h.current=e;const b=Wo(s),P=Wo(l),H=i.useRef(null),D=(T,N)=>{const j=h.current.getLayerSize();T.style.width=`${za(j)}px`,T.style.maxHeight="";const $=ow(N,T.offsetHeight,j);T.style.left=`${$.left-N.left}px`,T.style.top=`${$.top-N.top}px`,T.style.maxHeight=`${$.height}px`};i.useLayoutEffect(()=>{const T=c.current;if(T===null||s===null){H.current=null;return}if(D(T,s.anchorRect),s.kind==="message")return;const N=Wo(s);if(H.current===N)return;H.current=N;const j=T.querySelector("[data-aqsp-popover-autofocus]");j!==null?j.focus({preventScroll:!0}):T.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const T=u.current,N=p.current;T===null||N===null||D(T,N.anchorRect)},[P]);const _=T=>t===void 0?lw(T,n):t(T),U=T=>{e.isCompositionKey(T.nativeEvent)&&T.stopPropagation()},W=T=>{T.key==="Escape"&&!T.defaultPrevented&&(T.preventDefault(),e.close())},E=T=>{e.registerCompositionEnd(T.timeStamp)};return Y.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:W,onCompositionEnd:E,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)},b)}),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)})})]})},cw=["note","note-tip","comment","link","list","message"],aw=(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}},rr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&aw(e,n),uw=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),p=i.useRef(!1),h=i.useRef(null),b=i.useRef(null),P=i.useRef(null),H=i.useRef(null),D=i.useId(),_=i.useCallback(O=>{const x=t.current,z=x.handleRef.current,q=z===null?{x:0,y:0}:z.getScrollPosition(),B=z===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:z.getFrozenSize(),Z=z===null?{width:0,height:0}:z.getViewportSize();return{top:mn(x.rowAxis,O.row,{scroll:Math.max(0,q.y),frozenCount:B.rows,trailingCount:B.trailingRows,extent:Z.height}),left:hn(x.colAxis,O.col,{scroll:Math.max(0,q.x),frozenCount:B.cols,trailingCount:B.trailingCols,extent:Z.width}),width:x.colAxis.sizeOf(O.col),height:x.rowAxis.sizeOf(O.row)}},[]),U=i.useCallback(O=>{const x=t.current;x.anchors.current={...x.anchors.current,...O},x.repaintOverlay()},[]),W=i.useCallback(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),E=i.useCallback(()=>{const O=t.current.sinkRef.current;if(O===null)return;const x=c.current;x!==null&&Pt(x,t.current.getActive())?O.setAttribute("aria-describedby",D):O.getAttribute("aria-describedby")===D&&O.removeAttribute("aria-describedby")},[D]),T=i.useCallback(()=>(W(),p.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),E(),!0)),[W,U,E]),N=i.useCallback(()=>{W(),h.current=window.setTimeout(()=>{h.current=null,T()},rw)},[W,T]),j=i.useCallback(O=>{const x=t.current;W();const z=x.adapter.getCellNote===void 0?void 0:x.adapter.getCellNote(O.row,O.col);z===void 0||z===""||(c.current=O,s({kind:"note-tip",cell:O,anchorRect:_(O),current:z,close:T}),U({tip:O}),E())},[_,W,T,U,E]),$=i.useCallback(O=>{const x=t.current;if(O===null&&p.current)return;const z=u.current;u.current=O;const q=c.current;if(q!==null&&O!==null&&Pt(q,O)){W();return}const B=Z=>{const ee=x.adapter.getCellNote===void 0?void 0:x.adapter.getCellNote(Z.row,Z.col);return ee!==void 0&&ee!==""};if(sw(z,O,x.isDraggingAny(),B)){O!==null&&j(O);return}q!==null&&N()},[j,W,N]),k=i.useCallback((O,x)=>{const z=t.current,q=z.bodyRef.current,B=z.handleRef.current;if(q===null||B===null)return null;const Z=q.getBoundingClientRect(),ee=z.zoomRef.current,oe=B.getScrollPosition(),se=B.getFrozenSize(),ve=B.getViewportSize();return rn({row:yr(z.rowAxis,(x-Z.top)/ee,{scroll:Math.max(0,oe.y),frozenSize:se.height,trailingSize:se.trailingHeight,extent:ve.height}),col:Cr(z.colAxis,(O-Z.left)/ee,{scroll:Math.max(0,oe.x),frozenSize:se.width,trailingSize:se.trailingWidth,extent:ve.width})},z.rowAxis.count,z.colAxis.count)},[]),R=i.useCallback(O=>{P.current=O,b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const x=P.current;$(x===null?null:"cell"in x?x.cell:k(x.clientX,x.clientY))}))},[$,k]),g=i.useCallback(O=>R({cell:O}),[R]),m=i.useCallback(()=>T(),[T]),y=i.useCallback(O=>{if(l.current===null)return;const x=t.current;l.current=null,r(null),U({interactive:null}),(O===void 0||O.restoreFocus)&&x.focusSink({preventScroll:!0}),x.isEditing()||x.rearmSink()},[U]),S=i.useCallback(O=>{l.current=O.kind,r(O),U({interactive:O.cell})},[U]),L=i.useCallback(O=>{const x=t.current;return jc(x.adapter)?{cellReadOnly:Ke(x.adapter,O.row,O.col)}:{}},[]),v=i.useCallback((O,x)=>{const z=t.current;if(Ke(z.adapter,O.cell.row,O.cell.col)){z.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),S({...O,...L(O.cell)});return}if(z.commitEdits(x,{source:"annotate"})===null){S({...O,rejected:!0});return}y()},[S,y,L]),C=i.useCallback((O,x)=>{const z=t.current;if(!rr(z.adapter,z.popovers,O))throw new RangeError(`[spreadsheet] openPopover("${O}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const q=z.getActive();if(O==="list"&&Ke(z.adapter,q.row,q.col)){z.rejectReadOnly({kind:"edit",cell:q,editSession:"none"});return}if(O==="note-tip"){j(q);return}if(O==="message"){if(l.current!==null&&l.current!=="message")return;const oe=x!==void 0&&x.message!==void 0?x.message:void 0,se=z.adapter.getCellValidation===void 0?void 0:z.adapter.getCellValidation(q.row,q.col),ve=oe!==void 0?oe:se===void 0?void 0:se.inputMessage;if(ve===void 0)return;const qe=x!==void 0&&x.rejected===!0;S({kind:"message",cell:q,anchorRect:_(q),current:{title:ze(z.labels,"messageTitle"),message:ve,rejected:qe},close:y});return}if(z.isEditing()&&!z.requestCommit())return;if(O==="list"){const oe=z.adapter.getCellValidation===void 0?void 0:z.adapter.getCellValidation(q.row,q.col);if(oe===void 0||oe.type!=="list")return;const se=x!==void 0&&x.typed!==void 0?x.typed:"";T(),z.focusSink({preventScroll:!0}),S({kind:"list",cell:q,anchorRect:_(q),current:oe.values,typed:se,commit:ve=>{if(Ke(t.current.adapter,q.row,q.col)){t.current.rejectReadOnly({kind:"edit",cell:q,editSession:"none"}),y();return}t.current.commitEdits([{row:q.row,col:q.col,text:ve}],{source:"edit",editSession:"discarded"}),y()},close:y});return}if(T(),z.focusSink({preventScroll:!0}),O==="note"){const oe=z.adapter.getCellNote===void 0?void 0:z.adapter.getCellNote(q.row,q.col),se={kind:"note",cell:q,anchorRect:_(q),current:oe,commit:ve=>{v(se,[{row:q.row,col:q.col,note:ve}])},close:y,rejected:!1,...L(q)};S(se);return}if(O==="comment"){const oe=z.adapter.getCellComments===void 0?void 0:z.adapter.getCellComments(q.row,q.col),se={kind:"comment",cell:q,anchorRect:_(q),current:oe===void 0?[]:oe,commit:ve=>{v(se,[{row:q.row,col:q.col,comments:ve}])},close:y,rejected:!1,...L(q)};S(se);return}const B=z.adapter.getCellHyperlink===void 0?void 0:Hn(z.adapter.getCellHyperlink(q.row,q.col)),Z=z.adapter.getCellText(q.row,q.col),ee={kind:"link",cell:q,anchorRect:_(q),current:{text:Z,url:B},commit:oe=>{const se=oe.url===null?null:nn(oe.url);if(se===null&&oe.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(oe.url)}`);const ve=oe.text===Z?{row:q.row,col:q.col,hyperlink:se}:{row:q.row,col:q.col,text:oe.text,hyperlink:se};v(ee,[ve])},close:y,canOpen:z.onHyperlinkOpen!==void 0,open:()=>{const oe=t.current.onHyperlinkOpen;oe!==void 0&&B!==void 0&&oe(B,q)},rejected:!1,...L(q)};S(ee)},[_,y,v,T,S,j,L]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const O=f.current;if(!a||O===null)return;const x=q=>{const B=t.current;rr(B.adapter,B.popovers,"note-tip")&&R({clientX:q.clientX,clientY:q.clientY})},z=()=>{rr(t.current.adapter,t.current.popovers,"note-tip")&&R({cell:null})};return O.addEventListener("pointermove",x),O.addEventListener("pointerleave",z),()=>{O.removeEventListener("pointermove",x),O.removeEventListener("pointerleave",z)}},[a,f,R]),i.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),h.current!==null&&window.clearTimeout(h.current)},[]);const{adapter:A,popovers:d}=e,F=i.useMemo(()=>cw.some(O=>rr(A,d,O)),[A,d]);return i.useMemo(()=>({layerEnabled:F,isKindEnabled:O=>rr(t.current.adapter,t.current.popovers,O),open:C,close:y,isOpen:()=>l.current,onCellHover:g,hideTip:m,onTipPointerEnter:()=>{p.current=!0,W()},onTipPointerLeave:()=>{p.current=!1,c.current!==null&&N()},syncTipAriaDescribedBy:E,context:n,tipContext:o,registerCompositionEnd:O=>{H.current=O},isCompositionKey:O=>Ma(O,H.current),getLayerSize:()=>{const O=t.current.handleRef.current;return O===null?{width:0,height:0}:O.getViewportSize()},tipId:D}),[F,C,y,g,m,W,N,E,n,o,D])},dw=(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},Fa=(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 p=e.getFrozenSize(),h=e.getViewportSize();return rn({row:yr(n,(l-t.top)/o,{scroll:u,frozenSize:p.height,trailingSize:p.trailingHeight,extent:h.height}),col:Cr(r,(s-t.left)/o,{scroll:c,frozenSize:p.width,trailingSize:p.trailingWidth,extent:h.width})},n.count,r.count)},fw=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),p=i.useRef(null),h=i.useRef(!1),b=i.useRef(null),P=i.useRef(""),H=i.useRef(!1),D=i.useRef(!1),_=i.useCallback((R,g)=>{const{handleRef:m,rowAxis:y,colAxis:S,zoomRef:L}=t.current;return Fa(m.current,o.current,y,S,L.current,R,g)},[]),U=i.useRef(!1),W=i.useRef(null),E=i.useRef(null),T=i.useRef({clientX:0,clientY:0}),N=i.useCallback(()=>{const{autoScroller:R,bodyRef:g,onDragFrame:m}=t.current;n.current=!1,r.current=null,p.current=null,U.current=!1,W.current=null,E.current=null,h.current=!1,b.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),R.stop();const y=g.current;y!==null&&c.current!==null&&y.hasPointerCapture?.(c.current)&&y.releasePointerCapture(c.current),c.current=null,m(null),t.current.repaintOverlay()},[]),j=i.useCallback(()=>{if(!n.current)return;const R=r.current;R!==null&&t.current.setSelection(R),N()},[N]),{enabled:$,bodyRef:k}=e;return i.useEffect(()=>{const R=k.current;if(!$||R===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,m=d=>{const F=t.current;if(d.pointerType==="mouse"&&d.button===0&&(h.current=!1,b.current=null,D.current=!1),H.current=g(d.target),!H.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(F.getPointing?.()){F.focusSink();return}if(F.isEditing()&&!F.requestCommit()){d.stopPropagation(),F.focusSink();return}F.focusSink()}return}if(P.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((F.pointDragRef===void 0?null:F.pointDragRef.current)?.onPointerDown(d))return;if(F.isEditing()&&!F.requestCommit()){d.preventDefault(),F.focusSink();return}o.current=R.getBoundingClientRect();const x=_(d.clientX,d.clientY);if(x===null)return;if(d.preventDefault(),F.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&F.openHyperlinkAt?.(x)===!0){D.current=!0;return}const z=F.getSelection();r.current=z;const q=d.shiftKey,B=d.ctrlKey||d.metaKey,Z=B&&!q&&z.ranges.some(oe=>gn(oe,x));h.current=Z,b.current=Z?x:null,Z||F.setSelection(pr(z,x,{extend:q,append:B})),n.current=!0,F.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{R.setPointerCapture(d.pointerId)}catch{c.current=null}const ee=Z?x:F.getSelection().anchor;p.current=oe=>Ce(ee,oe),W.current=ee.col,E.current=ee.row,F.autoScroller.stop(),U.current=!1,T.current={clientX:d.clientX,clientY:d.clientY}},y=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",S=d=>{if(n.current&&y(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!U.current&&p.current!==null){const F=Math.abs(d.clientX-T.current.clientX),O=Math.abs(d.clientY-T.current.clientY);Math.max(F,O)>=Jr&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:p.current,anchorCol:W.current??void 0,anchorRow:E.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const F=p.current;if(!n.current||F===null)return;const O=t.current,x=_(s.current.clientX,s.current.clientY);x!==null&&O.onDragFrame(F(x))}))}},L=d=>{S(d),n.current&&y(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&C(d)},v=d=>{d.button!==0||!(n.current&&y(d))||C(d)},C=d=>{const F=t.current,O=_(d.clientX,d.clientY);if(O!==null){const x=b.current;h.current&&x!==null?F.setSelection(La(F.getSelection(),Ce(x,O),x)):F.setSelection(fn(F.getSelection(),O))}N()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||j()},f=d=>{const F=t.current;if(!g(d.target)||P.current!=="mouse"||F.isAnyDragging())return;if(F.isEditing()&&!F.requestCommit()){F.focusSink();return}F.focusSink(),o.current=R.getBoundingClientRect();const O=_(d.clientX,d.clientY);if(O===null)return;const x=F.getSelection();x.ranges.some(q=>gn(q,O))||F.setSelection(pr(x,O,{extend:!1,append:!1})),F.onContextMenuSelect(O,d)},A=d=>{const F=t.current;if(!H.current||P.current!=="mouse"||F.getPointing?.()||D.current)return;o.current=R.getBoundingClientRect();const O=_(d.clientX,d.clientY);O!==null&&Pt(F.getSelection().active,O)&&F.onRequestEdit(O,F.caretFromPointEnabled(O)?dw(d.clientX,d.clientY,O):void 0)};return R.addEventListener("pointerdown",m),R.addEventListener("pointermove",L),R.addEventListener("pointerup",v),R.addEventListener("lostpointercapture",a),R.addEventListener("contextmenu",f),R.addEventListener("dblclick",A),()=>{R.removeEventListener("pointerdown",m),R.removeEventListener("pointermove",L),R.removeEventListener("pointerup",v),R.removeEventListener("lostpointercapture",a),R.removeEventListener("contextmenu",f),R.removeEventListener("dblclick",A),N()}},[$,k,_,N,j]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>h.current?"subtract":"add",abortDrag:j,cancelDrag:N}),[j,N])},pw=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),p=i.useRef(0),h=i.useRef(null),b=i.useRef(null),P=i.useRef(!1),H=i.useCallback((T,N)=>{const{handleRef:j,rowAxis:$,colAxis:k,zoomRef:R}=t.current;return Fa(j.current,o.current,$,k,R.current,T,N)},[]),D=i.useCallback(()=>{const{autoScroller:T,bodyRef:N,onDragFrame:j}=t.current;n.current=!1,r.current=null,h.current=null,b.current=null,P.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const $=N.current;$!==null&&u.current!==null&&$.hasPointerCapture?.(u.current)&&$.releasePointerCapture(u.current),u.current=null,j(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.restoreSink(T),D()},[D]),U=i.useCallback(T=>{const N=t.current,j=N.bodyRef.current;if(!N.enabled||j===null||!N.getPointing())return!1;o.current=j.getBoundingClientRect();const $=H(T.clientX,T.clientY);if($===null)return o.current=null,!1;const k=N.captureSink();if(k===null)return o.current=null,!1;T.preventDefault(),N.focusSink(),r.current=k,b.current=$,N.insertReference($,"cells"),n.current=!0,s.current={clientX:T.clientX,clientY:T.clientY},l.current={clientX:T.clientX,clientY:T.clientY},u.current=T.pointerId,p.current=T.buttons;try{j.setPointerCapture(T.pointerId)}catch{u.current=null}return h.current=R=>{const g=Ce($,R);return t.current.insertReference(g,"cells"),g},N.autoScroller.stop(),P.current=!1,N.onDragFrame(Ce($,$)),!0},[H]),{enabled:W,bodyRef:E}=e;return i.useEffect(()=>{const T=E.current;if(!W||T===null)return;const N=R=>u.current!==null?R.pointerId===u.current:R.pointerType==="mouse",j=R=>{if(!(n.current&&N(R)))return;s.current={clientX:R.clientX,clientY:R.clientY};const g=h.current,m=b.current;if(!P.current&&g!==null&&m!==null){const y=Math.abs(R.clientX-l.current.clientX),S=Math.abs(R.clientY-l.current.clientY);Math.max(y,S)>=Jr&&(P.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:m.col,anchorRow:m.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=h.current;if(!n.current||y===null)return;const S=H(s.current.clientX,s.current.clientY);S!==null&&t.current.onDragFrame(y(S))})),(p.current&1)!==0&&(R.buttons&1)===0&&D()},$=R=>{R.button!==0||!(n.current&&N(R))||D()},k=R=>{!n.current||u.current===null||R.pointerId!==u.current||D()};return T.addEventListener("pointermove",j),T.addEventListener("pointerup",$),T.addEventListener("lostpointercapture",k),()=>{T.removeEventListener("pointermove",j),T.removeEventListener("pointerup",$),T.removeEventListener("lostpointercapture",k),D()}},[W,E,H,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:D,onPointerDown:U}),[_,D,U])},hw=(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})`)},mw=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)})`)},zi=(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},gw=24,ww=200,Na=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Fi=5,Cw=/^#[0-9A-Fa-f]{6}$/,yw=Object.freeze({row:!1,column:!1,intersection:!1}),Ni=Object.freeze({ok:!0}),Pi=(e,t)=>{if(t===void 0)return Na;if(t.length!==Fi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Fi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Cw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},bw=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},Rw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ca},vw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},kw=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)},Tn={ranges:[Ce({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Sw=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=gw,defaultColumnWidth:l=Le.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:p=0,frozenTrailingRows:h=0,tapScrollCircleOptions:b,overscanRows:P,overscanCols:H,background:D,onRenderTruncated:_,renderCell:U,onSelectionChange:W,onCellContextMenu:E,onUndoRequest:T,onRedoRequest:N,onCopyMultiRange:j,onOperationRejected:$,onEditRejected:k,onReadOnlyRejected:R,formatReadOnlyAnnouncement:g,dataVersion:m,maxOperationCells:y=Le.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:S=!0,enableResizeUI:L=!0,formatCellAnnouncement:v,formatSelectionAnnouncement:C,formatCommandAnnouncement:a,formatResizeAnnouncement:f,locale:A,labels:d,shortcuts:F,colors:O,formats:x,highlight:z,defaultHighlight:q,onHighlightChange:B,highlightColors:Z,popovers:ee,renderPopover:oe,onClipChange:se,onHyperlinkOpen:ve,onValidationRejected:qe,onPasteSpecialRequest:bt,onClipboardUnavailable:Ie,onPasteResolved:Ze,now:ue=Date.now,zoom:ie,defaultZoom:je,onZoomChange:Fe,testId:Ne,className:Pe,__onCellRender:Be,__onVirtualKeyboardRaise:at,__maxRenderedCells:Ot},Je){const ne=i.useMemo(()=>r?Xp(t):t,[t,r]),fe=ki(ne.rowCount,s),pe=ki(ne.colCount,l),qt=i.useRef(null);qt.current===null&&(qt.current=Zg());const Ae=qt.current,jt=Ge.resolveVirtualScrollLocale(A),Qe=i.useMemo(()=>Gc(A,d),[A,d]),wn=kw(Rh(Qe)),xt=i.useMemo(()=>wh(F),[F]),Cn=i.useMemo(()=>{if(!L)return;const K=[...xt].filter(([,Q])=>Po.includes(Q)).sort(([,Q],[,te])=>Po.indexOf(Q)-Po.indexOf(te)).map(([Q])=>dh(Q)).filter(Q=>Q!==null);return K.length===0?void 0:K.join(" ")},[xt,L]),Bn=i.useMemo(()=>({fill:Pi("fill",O===void 0?void 0:O.fill),font:Pi("font",O===void 0?void 0:O.font)}),[O]),br=i.useMemo(()=>Z===void 0?void 0:bw(Z),[Z]);if(ne.getConditionalFormats!==void 0&&ne.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");hw(n,u),mw(o);const yn=i.useCallback(()=>Ae.get().editVersion,[Ae]),so=i.useCallback(w=>Ae.subscribeCoalesced(w),[Ae]),lo=i.useSyncExternalStore(so,yn,yn)+(m===void 0?0:m),Vn=ne.getConditionalFormats===void 0?null:ne.getConditionalFormats(),bn=i.useMemo(()=>({index:Vn===null?null:Oa(Vn),memo:Os()}),[ne,Vn,lo]),It=i.useRef(bn.index);It.current=bn.index;const Wn=i.useRef(bn.memo);Wn.current=bn.memo;const Ht=i.useCallback((w,K,Q)=>xs(ne,It.current,Wn.current,w,K,Q),[ne]),M=i.useRef(null),[V,X]=i.useState(()=>Le.clampSpreadsheetZoom(je??1)),I=Le.clampSpreadsheetZoom(ie??V),G=i.useRef(I);G.current=I;const re=i.useRef(I);re.current=I;const ae=i.useRef(null),Oe=i.useRef(Fe);Oe.current=Fe;const ye=i.useRef(ie!==void 0);ye.current=ie!==void 0;const He=i.useCallback(w=>{const K=Le.clampSpreadsheetZoom(w);K!==re.current&&(re.current=K,ye.current||X(K),Oe.current?.(K))},[]),be=ne.rowCount===0||ne.colCount===0,Ve=!be;i.useEffect(()=>{const w=M.current;if(!Ve||w===null)return;const K=te=>{te.defaultPrevented||!te.altKey||te.ctrlKey||te.metaKey||te.shiftKey||te.deltaY!==0&&(te.preventDefault(),te.stopPropagation(),!ae.current?.()&&He(Le.stepSpreadsheetZoom(re.current,te.deltaY<0?1:-1)))},Q=te=>{if(te.defaultPrevented||!(te.ctrlKey&&te.altKey)||te.metaKey||te.getModifierState("AltGraph"))return;const Se=te.key==="="||te.key==="+"?Le.stepSpreadsheetZoom(re.current,1):te.key==="-"?Le.stepSpreadsheetZoom(re.current,-1):te.key==="0"?1:null;Se!==null&&(te.preventDefault(),te.stopPropagation(),!ae.current?.()&&He(Se))};return w.addEventListener("wheel",K,{passive:!1,capture:!0}),w.addEventListener("keydown",Q,!0),()=>{w.removeEventListener("wheel",K,{capture:!0}),w.removeEventListener("keydown",Q,!0)}},[He,Ve]);const xe=i.useRef(null),J=i.useRef(null),ce=i.useRef(null),me=i.useRef(null),ge=i.useRef(0),de=i.useRef(null),Re=i.useRef(0),ke=i.useRef(null),De=i.useRef(null),nt=i.useRef(null),et=i.useRef(null),rt=i.useRef(null),Rt=i.useRef(null),Bt=i.useRef(null),[vt,Tt]=i.useState(Tn),ot=i.useRef(vt),ut=i.useCallback(()=>ot.current,[]),[Pa,_a]=i.useState(()=>q===void 0?yw:q),Rn=z!==void 0?z:Pa,io=i.useRef(Rn);io.current=Rn;const qa=Rw(br,Rn),Ls=i.useRef(z!==void 0);Ls.current=z!==void 0;const Ds=i.useRef(B);Ds.current=B;const ja=i.useCallback(w=>{Ls.current||_a(w),Ds.current?.(w)},[]),Ms=i.useRef(null),co=i.useRef(null),$t=i.useRef(null),ao=i.useRef(()=>!1),zs=i.useRef(()=>{}),Fs=i.useRef(()=>null),Ns=i.useRef(()=>{}),on=i.useCallback(()=>ao.current(),[]),uo=i.useMemo(()=>({getPointing:()=>ao.current(),insertReference:(w,K)=>zs.current(w,K)}),[]),Ps=i.useRef(zt),_s=i.useRef(null),fo=i.useRef({interactive:null,tip:null}),qs=i.useRef(null),js=i.useRef(null),Rr=i.useRef(()=>{}),Is=i.useRef(()=>!1),Vt=i.useRef(null),Kn=i.useCallback(()=>{const w=Vt.current;if(w===null||w.isOpen()!=="message")return!1;const K=w.context;return K===null||K.kind!=="message"||!K.current.rejected?!1:(w.close(),!0)},[]),po=i.useRef(()=>!1),Hs=i.useRef(()=>!1),Bs=i.useRef(null),ho=i.useRef(()=>Promise.resolve("rejected")),$e=i.useCallback(()=>{Ms.current?.()},[]),Me=i.useCallback(w=>{ce.current?.focus(w)},[]),mo=i.useRef(!1),Ia=i.useCallback(()=>{const w=M.current;if(w!==null){mo.current=!0;try{w.focus()}finally{mo.current=!1}}},[]),tt=i.useCallback(()=>{const w=ce.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),vn=i.useCallback((w,K)=>{if(w===null)return;const Q=K?"":"none";w.style.display!==Q&&(w.style.display=Q)},[]),dt=i.useCallback(()=>{const w=me.current;if(w!==null){const Q=Math.max(0,J.current?.getScrollPosition().y??0),te=J.current?.getFrozenSize().height??0;w.style.transform=`translateY(${ge.current-Q-te}px)`}const K=J.current;if(K!==null&&(rt.current!==null||Rt.current!==null)){const Q=K.getFrozenSize();vn(rt.current,Q.height>0),vn(Rt.current,Q.trailingHeight>0)}},[vn]),ft=i.useCallback(()=>{const w=de.current;if(w!==null){const Q=Math.max(0,J.current?.getScrollPosition().x??0),te=J.current?.getFrozenSize().width??0;w.style.transform=`translateX(${Re.current-Q-te}px)`}const K=J.current;if(K!==null&&(nt.current!==null||et.current!==null)){const Q=K.getFrozenSize();vn(nt.current,Q.width>0),vn(et.current,Q.trailingWidth>0)}},[vn]),Yn=i.useRef(null),kn=i.useCallback(()=>{nt.current===null&&et.current===null&&rt.current===null&&Rt.current===null||Yn.current===null&&(Yn.current=requestAnimationFrame(()=>{Yn.current=null,dt(),ft(),$e()}))},[dt,ft,$e]);i.useEffect(()=>()=>{Yn.current!==null&&cancelAnimationFrame(Yn.current)},[]);const go=i.useRef(null),wo=i.useRef(null);(go.current===null||wo.current?.rowAxis!==fe||wo.current?.colAxis!==pe)&&(wo.current={rowAxis:fe,colAxis:pe},go.current=Vg({handleRef:J,rowAxis:fe,colAxis:pe}));const Wt=i.useCallback(w=>{go.current?.(w)},[]),Sn=i.useRef(null),sn=i.useRef(null),En=i.useCallback(w=>{Sn.current!==null&&window.clearTimeout(Sn.current),sn.current!==null&&(cancelAnimationFrame(sn.current),sn.current=null),Sn.current=window.setTimeout(()=>{Sn.current=null;const K=Bt.current;K!==null&&(K.textContent="",sn.current=requestAnimationFrame(()=>{sn.current=null,K.textContent=w}))},ww)},[]);i.useEffect(()=>()=>{Sn.current!==null&&window.clearTimeout(Sn.current),sn.current!==null&&cancelAnimationFrame(sn.current)},[]);const An=i.useCallback(w=>{R?.(w),g!==void 0&&En(g(w))},[R,g,En]),Vs=i.useCallback((w,K)=>{if(v===void 0&&C===void 0)return;const Q=K.ranges[K.ranges.length-1],te=ct(Q),Se=K.ranges.length===1&&te.rows===1&&te.cols===1,Ee=w.ranges[w.ranges.length-1],Yt=w.ranges.length!==K.ranges.length||Ee.startRow!==Q.startRow||Ee.startCol!==Q.startCol||Ee.endRow!==Q.endRow||Ee.endCol!==Q.endCol,an=()=>{if(v!==void 0){const Lt=K.active,Ao=ne.getCellText(Lt.row,Lt.col),wl=ne.getCellFormat===void 0?void 0:Ht(Lt.row,Lt.col,()=>Ao);En(v({row:Lt.row,col:Lt.col,text:Ao,displayText:qn(Ao,wl===void 0?void 0:wl.value),columnName:Le.columnIndexToName(Lt.col),...jc(ne)?{readOnly:Ke(ne,Lt.row,Lt.col)}:{}}))}};if(Se){an();return}if(Yt){C!==void 0&&En(C({range:Q,anchor:K.anchor,active:K.active,rangeRowCount:te.rows,rangeColCount:te.cols,rangeCount:K.ranges.length}));return}an()},[ne,v,C,En,Ht]),We=i.useCallback(w=>{const K=ot.current;Object.is(w,K)||qg(w,K)||(ot.current=w,Tt(w),W?.(w),Vs(K,w),($t.current?.()??!1)||tt())},[W,Vs,tt]),Ha=i.useCallback(w=>{const K=ot.current;if(w.mode==="cycle"){const te=Da(K,w.direction);We(te),Wt(te.active);return}const Q=rn(w.cell,fe.count,pe.count);if(w.mode==="extend"){We(fn(K,Q)),Wt(Q);return}We(pr(K,Q,{extend:!1,append:!1})),Wt(Q)},[We,Wt,fe,pe]),Ye=i.useCallback(()=>$t.current?.()??!1,[]),Ws=i.useRef(null),pt=i.useCallback(()=>Ws.current?.()??!0,[]),Ks=i.useRef(null),Un=i.useCallback((w,K)=>{const Q=$t.current?.()??!1;Ks.current?.(w,K),!Q&&($t.current?.()??!1)&&Kn()},[Kn]),[Ba,Co]=i.useState(!1),Ys=i.useCallback(()=>{at?.(),Co(!0)},[at]),Va=i.useCallback((w,K)=>{Ke(ne,w.row,w.col)||Ys(),Un("edit",K)},[ne,Ys,Un]),Us=i.useRef(null),vr=i.useCallback(()=>Us.current?.()??null,[]),Xs=i.useRef(null),kt=i.useCallback(()=>{Xs.current?.()},[]),Gs=i.useRef(null),Zs=i.useCallback(w=>{Gs.current?.(w)},[]),Js=i.useRef(()=>{}),kr=i.useRef(0),ln=i.useCallback((w,K,Q)=>{let te;if(K.source==="paste"){const Se=vw(Q);if(w.length===0&&Se.conditionalFormats.length===0)return null;kr.current+=1,te={transaction:kr.current,source:"paste",sameSheet:Se.sameSheet,conditionalFormats:Se.conditionalFormats}}else{if(w.length===0)return null;kr.current+=1,te={transaction:kr.current,source:K.source}}try{ne.applyEdits(w,te)}catch(Se){return k?.(Se,K),null}return Ae.bumpEdit(),Zs(K.source),te.transaction},[ne,Ae,k,Zs]),Wa=i.useCallback((w,K)=>ln(w,{source:"paste"},K),[ln]),Ka=i.useCallback(w=>{Ae.setVy(w.y),dt(),ft(),$e()},[Ae,dt,ft,$e]),Qs=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Ya=i.useCallback(w=>{Ae.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ae.setColRange(w.renderingColStart,w.renderingColEnd);const K=Qs.current;(K.rowStart!==w.renderingRowStart||K.rowEnd!==w.renderingRowEnd||K.colStart!==w.renderingColStart||K.colEnd!==w.renderingColEnd)&&(Qs.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},$e())},[Ae,$e]),el=i.useRef(()=>"add"),Kt=i.useCallback(w=>{co.current?.(w,el.current())},[]),Ua=i.useCallback(w=>{co.current?.(w,"point")},[]),tl=i.useRef(null),yo=i.useCallback(w=>{tl.current?.(w)},[]),nl=i.useRef(null),Xa=i.useCallback(w=>{nl.current?.(w)},[]),rl=i.useRef(null),bo=i.useCallback((w,K)=>{if(K.length===0)return;const Q=J.current;if(w==="col"){for(const te of K){const Se=Math.round(te.size);pe.resize(te.index,Se),Q?.updateColSize(te.index,Se)}Ae.bumpColVersion(),ft(),$e(),kn();return}for(const te of K){const Se=Math.round(te.size);fe.resize(te.index,Se),Q?.updateRowSize(te.index,Se)}Ae.bumpRowGeometry(),dt(),$e(),kn()},[fe,pe,Ae,ft,dt,$e,kn]),Ga=i.useCallback((w,K)=>{E?.(w,{kind:"pointer",event:K})},[E]),Za=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:Kt,axis:"both",zoomRef:G}),Ja=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:Kt,axis:"x",zoomRef:G}),Qa=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:Kt,axis:"y",zoomRef:G}),eu=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:yo,axis:"x",zoomRef:G}),tu=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:yo,axis:"y",zoomRef:G}),nu=xn({handleRef:J,rowAxis:fe,colAxis:pe,bodyRef:xe,onDragFrame:Kt,axis:"both",zoomRef:G}),ol=i.useRef(null),sl=i.useRef(()=>!1),Ro=i.useCallback(()=>sl.current(),[]),ht=fw({zoomRef:G,enabled:!be,rowAxis:fe,colAxis:pe,handleRef:J,bodyRef:xe,isEditing:Ye,requestCommit:pt,getSelection:ut,setSelection:We,focusSink:Me,onDragFrame:Kt,onContextMenuSelect:Ga,onRequestEdit:Va,caretFromPointEnabled:w=>{if(U!==void 0||ne.getCellFormula!==void 0&&ne.getCellFormula(w.row,w.col)!==void 0)return!1;if(ne.getCellFormat===void 0)return!0;const K=ne.getCellText(w.row,w.col);return qn(K,ne.getCellFormat(w.row,w.col)?.value)===K},isAnyDragging:Ro,autoScroller:Za,repaintOverlay:$e,pointDragRef:ol,getPointing:on,openHyperlinkAt:ve===void 0||ne.getCellHyperlink===void 0?void 0:w=>{const K=ne.getCellHyperlink===void 0?void 0:Hn(ne.getCellHyperlink(w.row,w.col));return K===void 0?!1:(ve(K,w),!0)}}),St=Mi({zoomRef:G,enabled:!be,axis:"col",headerRef:ke,mainAxis:pe,crossCount:ne.rowCount,handleRef:J,isEditing:Ye,requestCommit:pt,getSelection:ut,setSelection:We,focusSink:Me,onDragFrame:Kt,autoScroller:Ja,repaintOverlay:$e,pointing:uo}),Et=Mi({zoomRef:G,enabled:!be,axis:"row",headerRef:De,mainAxis:fe,crossCount:ne.colCount,handleRef:J,isEditing:Ye,requestCommit:pt,getSelection:ut,setSelection:We,focusSink:Me,onDragFrame:Kt,autoScroller:Qa,repaintOverlay:$e,pointing:uo}),mt=_g({zoomRef:G,enabled:!be&&L,colBandRef:ke,rowBandRef:De,colAxis:pe,rowAxis:fe,viewStore:Ae,handleRef:J,isEditing:Ye,requestCommit:pt,focusSink:Me,getSelection:ut,adapter:ne,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:y,onOperationRejected:$,resizeTracks:bo,writeResizeGuide:Xa,repaintOverlay:$e,isPointing:on}),gt=ew({zoomRef:G,enabled:!be&&S,handleNodeRef:rl,bodyRef:xe,rowAxis:fe,colAxis:pe,handleRef:J,getSelection:ut,setSelection:We,focusSink:Me,adapter:ne,commitEdits:ln,maxOperationCells:y,onOperationRejected:$,rejectReadOnly:An,writeFillPreview:yo,repaintOverlay:$e,xAutoScroller:eu,yAutoScroller:tu}),st=pw({zoomRef:G,enabled:!be,bodyRef:xe,handleRef:J,rowAxis:fe,colAxis:pe,getPointing:on,insertReference:uo.insertReference,captureSink:()=>Fs.current(),restoreSink:w=>Ns.current(w),focusSink:Me,autoScroller:nu,onDragFrame:Kt});ol.current=st;const Xn=i.useCallback(()=>ht.isDragging()||St.isDragging()||Et.isDragging()||mt.isDragging()||gt.isDragging()||st.isDragging(),[ht,St,Et,mt,gt,st]);ae.current=Xn,sl.current=Xn,el.current=()=>st.isDragging()?"point":ht.getDragMode();const ru=i.useCallback(()=>{ht.abortDrag(),St.abortDrag(),Et.abortDrag(),mt.abortDrag(),gt.abortDrag(),st.abortDrag()},[ht,St,Et,mt,gt,st]),vo=i.useCallback(()=>ot.current.active,[]),ll=i.useCallback((w,K)=>{const Q=ne.getCellValidation===void 0?void 0:ne.getCellValidation(w.row,w.col);if(Q===void 0)return Ni;const te=ne.evaluateFormula,Se=Qc(Q,K,jt,te===void 0?void 0:Ee=>te(Ee,w));return Se.ok||Q.strict!==!0?Ni:(qe?.({cell:w,rule:Q,text:K,message:Se.message}),Vt.current?.isKindEnabled("message")&&Rr.current("message",{message:Se.message,rejected:!0}),Se)},[ne,qe,jt]),_e=eg({enabled:!be,sinkRef:ce,rootRef:M,adapter:ne,commitEdits:ln,getActive:vo,ensureCellVisible:Wt,focusSink:Me,rearmSink:tt,discardClip:kt,isDragging:Ro,rejectReadOnly:An,resolveEditAlign:w=>{if(ne.getCellFormat===void 0)return null;const K=Vr(ne,w.row,w.col);return qc(Ht(w.row,w.col,K),K)},resolveEditPaint:w=>ne.getCellFormat===void 0?null:Wd(Ht(w.row,w.col,Vr(ne,w.row,w.col))),editPaintRef:Ps,repaintOverlay:$e,validateCommit:ll});$t.current=_e.isEditing,Ws.current=_e.requestCommit,Ks.current=_e.startEdit,ao.current=_e.getPointing,zs.current=_e.insertReference,Fs.current=_e.captureSink,Ns.current=_e.restoreSink;const il=i.useCallback(()=>{_e.cancelEdit(),Kn()},[_e.cancelEdit,Kn]),Gn=Fm({enabled:!be,sinkRef:ce,adapter:ne,isEditing:Ye,getSelection:ut,setSelection:We,commitPaste:Wa,maxOperationCells:y,onOperationRejected:$,onCopyMultiRange:j,repaintOverlay:$e,isDragging:Ro,resize:{rowAxis:fe,colAxis:pe,resizeTracks:bo},pendingPasteOptionsRef:_s,formats:x,onClipChange:se,onClipboardUnavailable:Ie,onEditRejected:k,rejectReadOnly:An,onPasteResolved:Ze});Us.current=Gn.getClip,Xs.current=Gn.discardClip,Gs.current=Gn.discardClipOnCommit,Js.current=Gn.onAdapterSwitch,ho.current=Gn.paste;const Zn=uw({enabled:!be,adapter:ne,popovers:ee,sinkRef:ce,bodyRef:xe,handleRef:J,rowAxis:fe,colAxis:pe,zoomRef:G,getActive:vo,isEditing:Ye,requestCommit:pt,focusSink:Me,rearmSink:tt,isDraggingAny:Xn,commitEdits:ln,labels:Qe,onHyperlinkOpen:ve,anchors:fo,repaintOverlay:$e,rejectReadOnly:An});Vt.current=Zn,Rr.current=Zn.open,Is.current=Zn.hideTip;const ou=i.useCallback(()=>{const w=ot.current.active;Wt(w);const K=J.current,Q=K===null?{x:0,y:0}:K.getScrollPosition(),te=K===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:K.getFrozenSize(),Se=K===null?{width:0,height:0}:K.getViewportSize(),Ee=G.current;return{top:mn(fe,w.row,{scroll:Math.max(0,Q.y),frozenCount:te.rows,trailingCount:te.trailingRows,extent:Se.height})*Ee,left:hn(pe,w.col,{scroll:Math.max(0,Q.x),frozenCount:te.cols,trailingCount:te.trailingCols,extent:Se.width})*Ee,width:pe.sizeOf(w.col)*Ee,height:fe.sizeOf(w.row)*Ee}},[fe,pe,Wt]),ko=Zm({adapter:ne,trackResize:L&&!be?mt:void 0,getSelection:ut,commitEdits:ln,getActive:vo,isEditing:Ye,requestCommit:pt,cancelEdit:il,getSessionText:_e.getSessionText,validateCommit:ll,insertAtCaret:_e.insertAtCaret,refreshEditPaint:_e.refreshPaint,maxOperationCells:y,onOperationRejected:$,colors:Bn,formats:x,getHighlight:()=>io.current,setHighlight:ja,popovers:ee,openPopover:w=>Rr.current(w),onHyperlinkOpen:ve,onPasteSpecialRequest:bt,paste:w=>ho.current(w),rowAxis:fe,colAxis:pe,resizeTracks:bo,defaultRowHeight:s,defaultColumnWidth:l,now:ue,announce:En,formatCommandAnnouncement:a,formatResizeAnnouncement:f,keyboardCellRect:ou,rejectReadOnly:An});Bs.current=ko,po.current=ko.executeCommand,Hs.current=ko.isCommandAvailable;const su=i.useMemo(()=>({table:xt,execute:w=>po.current(w),isAvailable:w=>Hs.current(w)}),[xt]),lu=i.useCallback(()=>{kt(),T?.()},[kt,T]),iu=i.useCallback(()=>{kt(),N?.()},[kt,N]);Gg({zoomRef:G,enabled:!be,sinkRef:ce,rootRef:M,handOffFocusToRoot:Ia,getSelection:ut,setSelection:We,moveActive:Ha,ensureCellVisible:Wt,isEditing:Ye,requestCommit:pt,startEdit:Un,commitEdits:ln,maxOperationCells:y,onOperationRejected:$,rejectReadOnly:An,getClip:vr,discardClip:kt,isDragging:Xn,abortDrag:ru,findDataEdge:ne.findDataEdge,getEditingMode:_e.getEditingMode,cancelEdit:il,onUndoRequest:lu,onRedoRequest:iu,onCellContextMenu:E,rowAxis:fe,colAxis:pe,handleRef:J,rearmSink:tt,commands:su,pointing:_e,adapter:ne,hideNoteTip:()=>Is.current(),closeRejectedMessage:Kn,pendingPasteOptionsRef:_s,onPointFrame:Ua});const cu=vt.active.row,au=vt.active.col;i.useLayoutEffect(()=>{const w=Vt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[cu,au]),i.useLayoutEffect(()=>{$e()},[$e,Rn.row,Rn.column,Rn.intersection]);const uu=i.useCallback(w=>{($t.current?.()??!1)||(w.preventDefault(),Me(),tt())},[Me,tt]),du=i.useCallback(w=>{const K=M.current,Q=w.relatedTarget;if(K!==null&&Q instanceof Node&&K.contains(Q)){w.target===K&&Q===ce.current&&!mo.current&&Me();return}($t.current?.()??!1)||(Me(),tt())},[Me,tt]),fu=i.useCallback(w=>{const K=M.current,Q=w.relatedTarget;K!==null&&Q instanceof Node&&K.contains(Q)||_e.isFocusoutSuppressed()||Co(!1)},[_e]),Sr=i.useRef(null),Jn=i.useCallback(()=>{const w=Sr.current;w!==null&&(Sr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),So=i.useCallback(()=>{if(Sr.current!==null)return;const w=Q=>{Q.pointerType==="mouse"&&(Jn(),Q.button===1&&Q.preventDefault())},K=Q=>{Q.pointerType==="mouse"&&Jn()};Sr.current={up:w,cancel:K},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",K,!0)},[Jn]);i.useEffect(()=>Jn,[Jn]),i.useEffect(()=>{const w=M.current;if(be||w===null)return;let K=0;const Q=Ee=>{if(Ee.pointerType!=="mouse"){($t.current?.()??!1)||Co(!1);return}K=Ee.buttons,Ee.button===1&&(Ee.target===ce.current&&($t.current?.()??!1)||So())},te=Ee=>{Ee.pointerType==="mouse"&&(K=Ee.buttons)},Se=Ee=>{if(Ee.pointerType!=="mouse"||Ee.buttons===K)return;const Yt=Ee.buttons&~K;K=Ee.buttons,Ee.preventDefault(),(Yt&4)!==0&&So()};return w.addEventListener("pointerdown",Q,!0),w.addEventListener("pointerup",te,!0),w.addEventListener("pointermove",Se,!0),()=>{w.removeEventListener("pointerdown",Q,!0),w.removeEventListener("pointerup",te,!0),w.removeEventListener("pointermove",Se,!0)}},[be,So]);const pu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(on()){Me();return}if(Ye()&&!pt()){Me();return}Me()}},[Me,Ye,pt,on]),Eo=i.useRef(!1);i.useLayoutEffect(()=>{if(be){Eo.current=!1;return}if(Eo.current)return;Eo.current=!0,tt();const w=(M.current?.clientHeight??0)/G.current;w>0&&fe.totalSize()>0&&Ae.setRowRange(0,fe.indexAt(Math.min(w-1,fe.totalSize()-1)));const K=(M.current?.clientWidth??0)/G.current;K>0&&pe.totalSize()>0&&Ae.setColRange(0,pe.indexAt(Math.min(K-1,pe.totalSize()-1)))},[be,tt,Ae,fe,pe]);const cl=i.useRef(t);i.useLayoutEffect(()=>{cl.current!==t&&(cl.current=t,ht.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),mt.cancelDrag(),gt.cancelDrag(),st.cancelDrag(),_e.cancelEdit(),Vt.current?.hideTip(),Vt.current?.close(),be?(ot.current=Tn,Tt(Tn)):We(Tn),Js.current())},[t,be,We,ht,St,Et,mt,gt,st,Ae,_e.cancelEdit]);const al=i.useRef({adapter:ne,rows:fe.count,cols:pe.count}),{getSessionCell:ul,cancelEdit:dl}=_e;i.useLayoutEffect(()=>{const w=al.current,K=fe.count,Q=pe.count;if(al.current={adapter:ne,rows:K,cols:Q},w.adapter!==ne||K>=w.rows&&Q>=w.cols)return;be?(ot.current=Tn,Tt(Tn)):We(jg(ot.current,K,Q)),ht.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),mt.cancelDrag(),gt.cancelDrag(),st.cancelDrag();const te=an=>be||an.row>=K||an.col>=Q,Se=ul();Se!==null&&te(Se)&&dl();const Ee=fo.current;if(Ee.tip!==null&&te(Ee.tip)&&Vt.current?.hideTip(),Ee.interactive!==null&&te(Ee.interactive)){const an=M.current?.contains(document.activeElement)===!0;Vt.current?.close({restoreFocus:an})}const Yt=vr();Yt!==null&&!Yt.foreign&&te({row:Yt.range.endRow,col:Yt.range.endCol})&&kt()},[ne,fe.count,pe.count,be,We,ht,St,Et,mt,gt,st,ul,dl,vr,kt]);const fl=i.useRef(c),pl=i.useRef(u),hl=i.useRef(p),ml=i.useRef(h);i.useLayoutEffect(()=>{(fl.current!==c||pl.current!==u||hl.current!==p||ml.current!==h)&&(fl.current=c,pl.current=u,hl.current=p,ml.current=h,ht.cancelDrag(),St.cancelDrag(),Et.cancelDrag(),mt.cancelDrag(),gt.cancelDrag(),st.cancelDrag())},[c,u,p,h,ht,St,Et,mt,gt,st]),i.useLayoutEffect(()=>{dt(),ft(),$e()},[c,u,p,h,dt,ft,$e]);const gl=i.useRef(m);i.useLayoutEffect(()=>{gl.current!==m&&(gl.current=m,kt())},[m,kt]),i.useLayoutEffect(()=>{$e()},[$e,vt]);const cn=i.useCallback(()=>{const w=Bs.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(Je,()=>({resizeRow:(w,K)=>{const Q=Math.round(K);fe.resize(w,Q),J.current?.updateRowSize(w,Q),Ae.bumpRowGeometry(),dt(),$e(),kn()},resizeColumn:(w,K)=>{const Q=Math.round(K);pe.resize(w,Q),J.current?.updateColSize(w,Q),Ae.bumpColVersion(),ft(),$e(),kn()},scrollToCell:(w,K)=>{J.current?.scrollToCell(w.row,w.col,K)},focus:w=>{Me(w),Ye()||tt()},executeCommand:w=>po.current(w),applyFormat:w=>cn().applyFormat(w),setBorders:(w,K)=>cn().setBorders(w,K),setHyperlink:w=>cn().setHyperlink(w),setNote:w=>cn().setNote(w),addComment:w=>cn().addComment(w),setValidation:w=>cn().setValidation(w),paste:w=>ho.current(w),getSelection:()=>ot.current,getBaseFormat:w=>ne.getCellFormat===void 0?void 0:ne.getCellFormat(w.row,w.col),getPaintedFormat:w=>ne.getCellFormat===void 0?void 0:Ht(w.row,w.col,Vr(ne,w.row,w.col)),startEdit:w=>{Un(w)},openPopover:w=>{Rr.current(w)}}),[fe,pe,Ae,ft,dt,$e,kn,Me,Ye,tt,ne,Ht,Un,cn]),be)return Y.jsx("div",{className:Pe?`aqsp-root ${Pe}`:"aqsp-root","data-aqsp-empty":"","data-testid":Ne});const hu=v!==void 0||C!==void 0||a!==void 0||g!==void 0||f!==void 0,mu=o===void 0?{"aria-label":Qe.rootAriaLabel}:{"aria-labelledby":o};return Y.jsx("div",{ref:M,className:Pe?`aqsp-root ${Pe}`:"aqsp-root",role:"group",...mu,tabIndex:0,onFocus:du,onBlur:fu,"data-aqsp-root":"","data-testid":Ne,children:Y.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":I,onPointerDown:pu,style:I===1?void 0:{width:`${100/I}%`,height:`${100/I}%`,transform:`scale(${I})`},children:[Y.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(on()){Me();return}if(Ye()&&!pt()){Me();return}Me(),We({ranges:[Ce({row:0,col:0},{row:ne.rowCount-1,col:ne.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),Y.jsx(zg,{viewStore:Ae,colAxis:pe,frozenCols:c,frozenTrailingCols:p,handleRef:J,bandRef:ke,colTrackRef:de,windowOriginXRef:Re,repaintColHeaders:ft,selectionRanges:vt.ranges,enableResizeUI:L,dividerLeadingRef:nt,dividerTrailingRef:et}),Y.jsx(Fg,{viewStore:Ae,rowAxis:fe,handleRef:J,bandRef:De,selectionRanges:vt.ranges,rowTrackRef:me,windowOriginYRef:ge,repaintHeaders:dt,enableResizeUI:L,frozenRows:u,frozenTrailingRows:h,dividerLeadingRef:rt,dividerTrailingRef:Rt}),Y.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[Y.jsx(Mg,{adapter:ne,rowAxis:fe,colAxis:pe,viewStore:Ae,handleRef:J,bodyRef:xe,dataVersion:m,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:p,frozenTrailingRows:h,headerRows:n,labelledBy:o,gridLabel:o===void 0?Qe.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:b,overscanRows:zi("overscanRows",P),overscanCols:zi("overscanCols",H),background:D,onRenderTruncated:_,renderCell:U,onScroll:Ka,onRangeChange:Ya,focusSink:Me,isEditing:Ye,requestCommit:pt,testId:Ne?`${Ne}-vs`:void 0,__onCellRender:Be,__maxRenderedCells:Ot,cfIndexRef:It,cfMemoRef:Wn,isPointing:on,locale:jt,scrollLabels:wn}),Y.jsx(am,{rowAxis:fe,colAxis:pe,handleRef:J,sinkRef:ce,getSelection:ut,editing:_e.editing,virtualKeyboard:Ba,repaintRef:Ms,dragFrameRef:co,getClip:vr,getIsDraggingAny:Xn,getIsFillDragging:gt.isDragging,fillFrameRef:tl,resizeGuideFrameRef:nl,fillHandleNodeRef:rl,enableFillHandle:S,frozenCols:c,frozenRows:u,trailingCols:p,trailingRows:h,sinkAriaLabel:Qe.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Cn,onSinkMouseDown:uu,editPaintRef:Ps,highlightRef:io,highlightColors:qa,popoverAnchors:fo,interactiveAnchorRef:qs,tipAnchorRef:js}),Zn.layerEnabled?Y.jsx(iw,{controller:Zn,labels:Qe,renderPopover:oe,interactiveAnchorRef:qs,tipAnchorRef:js}):null]}),hu?Y.jsx("div",{ref:Bt,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.iterateTsvPrefixRows=Nt.iterateTsvPrefixRows;exports.iterateTsvRows=Nt.iterateTsvRows;exports.measureTsv=Nt.measureTsv;exports.parseTsv=Nt.parseTsv;exports.serializeClipboardTsv=Nt.serializeClipboardTsv;exports.serializeTsv=Nt.serializeTsv;exports.columnIndexToName=Le.columnIndexToName;exports.columnNameToIndex=Le.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=ds;exports.CommentPopover=ua;exports.DEFAULT_CUSTOM_COLORS=Na;exports.DEFAULT_HIGHLIGHT_COLORS=ca;exports.DEFAULT_SHORTCUTS=Uc;exports.LinkPopover=da;exports.ListPopover=fa;exports.MessagePopover=pa;exports.NotePopover=ha;exports.NoteTip=ma;exports.SPREADSHEET_LABEL_CATALOGS=Xc;exports.SPREADSHEET_RESERVED_SHORTCUTS=fh;exports.Spreadsheet=Sw;exports.canonicalizeFormat=yt;exports.detectClipSource=Yi;exports.enumerateRangeCells=Xt;exports.estimatePasteCellCount=Qp;exports.expandPaste=eh;exports.formatCellValue=qn;exports.formatEquals=Au;exports.fromR1C1=gr;exports.makeRange=Ce;exports.mergeFormat=ps;exports.normalizeHyperlink=nn;exports.parseChord=Gt;exports.parseClipPayload=Uo;exports.parseHtmlTable=_c;exports.rangeContains=gn;exports.rangeSize=ct;exports.resolveLabel=ze;exports.resolveLabels=Gc;exports.serializeClipPayload=Vi;exports.serializeHtmlTable=zc;exports.shiftFormula=wc;exports.toR1C1=to;exports.validateCellText=Qc;
|
|
12
|
+
`)},Up=(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,Kc(e,r))},Xp=(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"?Ic(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<Ql.length?Ql[l]:null}return null},Yc=(e,t,n)=>t!==void 0&&Hc(t)?rp(e,t,n):e,Gp=(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!==""&&nt(c)!==null)if(n!==void 0&&n.type==="date"){const u=Ic(Number(c));if(u!==null)return u}else return c;return Yc(t,n,r)},Zp=(e,t,n,r)=>{const o=Kc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:jp(o)};for(const g of th(e))Wp(g,l);Kp(l,o,s,r.rules);const c=Yp(l.text,l.mode),u=Bp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),R=g===null?void 0:Gf(g,r.options);R!==void 0&&(u.value=R);const F=e.getAttribute("data-sheets-value"),H=F===null?null:Xp(F,R);h.t=H===null?Yc(c,R,Nc):H;const L=e.getAttribute("data-sheets-formula");L?.startsWith("=")&&(h.f=L);const P=e.getAttribute("data-sheets-hyperlink"),U=P!==null?P:l.href,W=U===null?null:tn(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:$s(as(eo(g)),r.options);R!==void 0&&(u.value=R),h.t=Gp(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:tn(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},Jp=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)},Qp=(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]))},Uc=(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:Jp(l);if(c!==null)return Math.min(c,en)}const o=Qp(e,t);return o===null?null:Math.min(o,en)},eh=(e,t)=>{const n=[],r=o=>{const s=Uc(o,"width");for(let l=ds(o,"span",Ss);l>0&&n.length<t;l-=1)n.push(s)};for(const o of hr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of hr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*hr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*th(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*nh(e){for(const t of["thead","tbody","tfoot"])for(const n of hr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of hr(n))o.localName==="tr"&&(yield o)}}const Vo=()=>({t:""}),rh=(e,t,n)=>{const r=fc(),o=[],s=[],l=[];let c=0;for(const H of nh(e)){const L=o.length,P=(L+1)*Math.max(c,1);if(P>n)return{outcome:"limit",cells:P};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 hr(H)){const x=S.localName;if(x!=="td"&&x!=="th")continue;for(;U[W]!==void 0;)W+=1;const z=ds(S,"colspan",Ss),q=ds(S,"rowspan",sc),T=(L+1)*Math.max(c,W+z);if(T>n)return{outcome:"limit",cells:T};const N=Zp(S,L,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(q>1)for(let m=0;m<z;m+=1){const p=q-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(Uc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const L=[];for(let P=0;P<c;P+=1){const U=H[P];L.push(U===void 0?Vo():U)}return L}),h=eh(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:[]}}},Xc=(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=wp(o);return rh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Ce=(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)}),gn=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,rt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),At=e=>e.reduce((t,n)=>t+rt(n).rows*rt(n).cols,0),Ut=(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}))}},nn=(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)}},Pt=(e,t)=>e.row===t.row&&e.col===t.col,Gc=(e,t)=>e===void 0?Ll(void 0,void 0,t()):Ll(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)},Bn=(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}),Zc=e=>e.isCellReadOnly!==void 0,Be=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,oh=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],sh=()=>!0,lh=e=>{const t=new WeakMap,n={};for(const r of oh)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:sh}),n},ih=/^data-[a-z0-9-]+$/,ch=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},ah=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!ch(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(!ih.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},ir=(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},Fn=(e,t)=>{for(const n of t)if(ir(e,n))return!0;return!1},uh=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=rt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},fs=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=rt(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,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:Ce(g,{row:g.row+R-1,col:g.col+F-1})},Jc=(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 L=[];for(let U=0;U<R;U+=c){const W={row:h.row+H,col:h.col+U};L.push(W),F.push(W)}const P=Math.min(l,g-H);for(let U=0;U<P;U+=1){const W=h.row+H+U,S=e[U];for(let x=0;x<L.length;x+=1){const z=x*c,q=Math.min(c,R-z);for(let T=0;T<q;T+=1)s(W,h.col+z+T,S[T],L[x])}}}return F},dh=(e,t,n,r,o)=>{const s=[];return Jc(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},ni=(e,t,n,r,o,s)=>{const l=[],c=Jc(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}},Qc=(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)})`)},fh=(e,t)=>{Qc(e,t);const n=rt(t),r=rt(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},ph=(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(Ce({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Ce({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Ce({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Ce({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},hh=(e,t,n,r)=>{Qc(t,n);const o=rt(t).rows,s=rt(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 L=c.get(H);L===void 0&&(L={value:e(h,F),origin:{row:h,col:F}},c.set(H,L)),l.push(r(L.value,L.origin,{row:u,col:R}))}}return l},ea=(e,t,n)=>{const r=Bn(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=Vn(e.getCellHyperlink(t,n));o.hyperlink=s===void 0?null:s}if(e.getCellNote!==void 0){const s=e.getCellNote(t,n);o.note=s===void 0?null:s}return o},ta=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?xc(e.text,n.row-t.row,n.col-t.col):e.text};return e.format!==void 0&&(r.format=e.format),e.validation!==void 0&&(r.validation=e.validation),e.hyperlink!==void 0&&(r.hyperlink=e.hyperlink),e.note!==void 0&&(r.note=e.note),r},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"],mh=/^[A-Z]$/,gh=/^[A-Za-z]$/,wh=/^Key([A-Z])$/,na=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"]),Ch=e=>mh.test(e)||na.has(e),Xt=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||!Ch(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}},bh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,ra=e=>{if(gh.test(e.key))return e.key.toUpperCase();const t=wh.exec(e.code);return t!==null?t[1]:na.has(e.code)?e.code:null},tr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:ra(t)===e.key,me=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),we=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),yh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(me(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(me(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(me(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(me(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Rh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(me(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(me(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},br=[...yh(),me("Home","idle","row start (first visible column)"),me("Ctrl+Home","idle","first visible cell"),me("Shift+Home","idle","extend to row start"),me("Ctrl+Shift+Home","idle","extend to first visible cell"),me("End","idle","row end (last visible column)"),me("Ctrl+End","idle","last visible cell"),me("Shift+End","idle","extend to row end"),me("Ctrl+Shift+End","idle","extend to last visible cell"),me("PageUp","both","page up (idle) / commit + page up (editing)"),me("PageDown","both","page down (idle) / commit + page down (editing)"),me("Shift+PageUp","idle","extend one page up"),me("Shift+PageDown","idle","extend one page down"),me("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),me("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),me("Tab","both","cycle right (idle) / commit + cycle right (editing)"),me("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),me("Enter","both","cycle down (idle) / commit + cycle down (editing)"),me("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),me("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),me("F2","both","start editing (idle) / toggle the pointing arm (editing)"),me("F4","editing","cycle the reference anchor under the caret (formula session)"),me("Delete","idle","clear every selected cell"),me("Backspace","idle","clear every selected cell"),me("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),me("Ctrl+A","idle","select all"),me("Ctrl+Z","idle","undo request"),me("Ctrl+Y","idle","redo request"),me("Ctrl+Shift+Z","idle","redo request"),me("Shift+F10","idle","keyboard context menu"),me("ContextMenu","idle","keyboard context menu"),me("Ctrl+Space","idle","column bands"),me("Shift+Space","idle","row bands"),me("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),me("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),me("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),me("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"},...Rh(),we("bold","Ctrl+B","both","toggle bold"),we("italic","Ctrl+I","both","toggle italic"),we("underline","Ctrl+U","both","toggle underline"),we("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),we("clearFormatting","Ctrl+Backslash","idle","clear formatting"),we("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),we("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),we("alignLeft","Ctrl+Shift+L","both","align left"),we("alignCenter","Ctrl+Shift+E","both","align center"),we("alignRight","Ctrl+Shift+R","both","align right"),we("formatNumber","Ctrl+Shift+Digit1","both","number format"),we("formatTime","Ctrl+Shift+Digit2","both","time format"),we("formatDate","Ctrl+Shift+Digit3","both","date format"),we("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),we("formatPercent","Ctrl+Shift+Digit5","both","percent format"),we("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),we("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),we("bordersClear","Alt+Shift+Digit6","idle","clear borders"),we("borderTop","Alt+Shift+Digit1","idle","top border"),we("borderRight","Alt+Shift+Digit2","idle","right border"),we("borderBottom","Alt+Shift+Digit3","idle","bottom border"),we("borderLeft","Alt+Shift+Digit4","idle","left border"),we("insertLink","Ctrl+K","idle","insert / edit hyperlink"),we("insertNote","Shift+F2","idle","insert / edit note"),we("insertComment","Ctrl+Alt+M","idle","insert comment"),we("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),we("openValidationList","Alt+ArrowDown","idle","open the validation list"),we("fillDown","Ctrl+D","idle","fill down"),we("fillRight","Ctrl+R","idle","fill right"),we("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),we("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),we("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),we("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),we("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),we("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),we("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),we("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),we("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),we("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),we("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],Wo=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),ri=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),vh=e=>{const t=Xt(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 ri?ri[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},to=(e,t)=>e.column==="both"||e.column===t,kh=Array.from(new Set(br.filter(e=>!e.rebindable&&to(e,"idle")).map(e=>e.chord))),Ms=new Set(br.filter(e=>e.command!==void 0&&to(e,"editing")).map(e=>e.command)),Sh=new Set(br.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),oa=e=>{const t={};for(const n of uo)t[n]=e(n);return t},sa=oa(e=>br.filter(t=>t.command===e).map(t=>t.chord)),Eh=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},Ah=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(Sh.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`)}}}},Oh=(e,t)=>{const n=Xt(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 br)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})`)},xh=e=>{e!==void 0&&Ah(e);const t=oa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?sa[r]:o===null?[]:o});for(const r of uo)for(const o of t[r])Oh(r,o);const n=new Map;for(const[r,o]of Eh(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},oi=(e,t)=>{const n=ra(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(bh({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"],si=[...Ue.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:"閉じる"})}),la=Object.freeze({en:Object.freeze({...Ue.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ps.en}),ja:Object.freeze({...Ue.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ps.ja})}),pn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,li=e=>e==="commentCount"||e==="listMore",Th=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 ${pn(t)}`);for(const n of zs){const r=e[n];if(!(li(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=li(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${pn(r)}`)}}},$h=e=>{const t={};let n=!1;for(const r of Ue.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},Lh=(e,t,n)=>{e[t]=n},ia=(e,t)=>{const n=Ue.resolveVirtualScrollLocale(e);if(t===void 0)return la[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${pn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!si.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${si.join(", ")}`);const s={...Ue.resolveVirtualScrollLabels(n,$h(t)),...ps[n]};for(const l of zs){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&Lh(s,l,c)}return Th(s),Object.freeze(s)},Dh=e=>{const t={};for(const n of Ue.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Fe=(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},ii={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Mh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},zh=(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}`}},Ko=(e,t)=>{const n=r=>(o,s)=>`${e} ${zh(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")})},Fh=Object.freeze({list:"Value must be one of the list items.",number:Ko("Value must be a number",ii),textLength:Ko("Text length must be",ii),date:Ko("Value must be a date",Mh),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}.`}),Nh=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} を満たす値を入力してください。`}),Yo=Object.freeze({en:Fh,ja:Nh}),Ph=Object.freeze({ok:!0}),_h="TRUE",qh="FALSE",Ih=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),jh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Hh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Bh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Vh=/^[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])?)+$/,ci=e=>{const t=e.trim();if(!(Hh.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}},Wh=e=>e===1?-1:e===-1?1:0,Kh=(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:Wh(n)},Yh=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},ai=e=>{const t=Bh.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>Yh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Uh=(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},Xh=(e,t)=>e<t?-1:e>t?1:0,Gh=e=>e==="between"||e==="notBetween",Zh=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Gh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Jh=(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=Zh(e,t,n,r);return l===null?!0:o===null?!1:Jh(e,s(o,l.a),l.b===null?0:s(o,l.b))},Qh=e=>Number.isFinite(e)?e:null,em=e=>{let t=0;for(const n of e)t+=1;return t},tm=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),nm=(e,t)=>{switch(e.op){case"isEmail":return Vh.test(t);case"isUrl":return tm(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)}},rm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,ca=e=>({checked:e.checked===void 0?_h:e.checked,unchecked:e.unchecked===void 0?qh:e.unchecked}),om=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Ih.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${pn(e.op)} for type "${e.type}"`);return;case"text":if(!jh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${pn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${pn(e.type)}`)}},sm=(e,t,n)=>{switch(e.type){case"list":return cm(e).has(t);case"number":return Uo(e.op,e.a,e.b,ci,ci(t),Kh);case"textLength":return Uo(e.op,e.a,e.b,Qh,em(t),Xh);case"date":return Uo(e.op,e.a,e.b,ai,ai(t),Uh);case"text":return nm(e,t);case"checkbox":{const r=ca(e);return t===r.checked||t===r.unchecked}default:return n===void 0||rm(n(e.formula))}},aa=(e,t,n)=>(om(e),t===""||sm(e,t,n)),ui=e=>e===void 0?void 0:e.trim(),lm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),ui(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(),ui(e.b));case"text":return im(e,t.text);case"checkbox":{const n=ca(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},im=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},di=new WeakMap,cm=e=>{const t=di.get(e);if(t!==void 0)return t;const n=new Set(e.values);return di.set(e,n),n},ua=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Yo,n)){const o=Object.keys(Yo).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${pn(n)}`)}return aa(e,t,r)?Ph:{ok:!1,message:e.errorMessage===void 0?lm(e,Yo[n]):e.errorMessage}},am=e=>e.type!=="custom",um=(e,t)=>am(e)&&!aa(e,t,void 0),da=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),fa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),pa=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,ha=(e,t,{scroll:n,frozenSize:r,trailingSize:o,extent:s})=>r>0&&t<r?e.indexAt(t):o>0&&s>0&&t>=s-o?e.indexAt(e.totalSize()-(s-t)):e.indexAt(t+n),ma=(e,t)=>da(e,t),ga=(e,t)=>da(e,t),wa=(e,t)=>fa(e,t),Ca=(e,t)=>fa(e,t),hn=(e,t,n)=>pa(e,t,n),mn=(e,t,n)=>pa(e,t,n),yr=(e,t,n)=>ha(e,t,n),Rr=(e,t,n)=>ha(e,t,n),dm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Yt=1,cr=3,Pr=e=>`${-Math.min(cr,Math.max(0,Math.floor(e)))}px`,ba=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),fm=16,pm=450,hm=e=>e>4?Math.floor(pm/(5*e)):fm,nr=(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},fi=()=>({rowLeft:nr("row","left"),rowRight:nr("row","right"),colAbove:nr("column","above"),colBelow:nr("column","below"),cross:nr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),ya=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),pi="inset(100%)",_n=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},mm=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,_n([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,_n([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,_n([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)}},hi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,_n([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,_n([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,_n([e.cross],!1))},mi=e=>{for(const t of ya(e))t.remove()},gm=(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)},wm=Object.freeze([]),gi=e=>e.dividers[0]??e.active,Cm={left:"0px",right:"0px",width:""},bm={top:"0px",bottom:"0px",height:""},wi=()=>({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:[]}),Ci=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],bi=6,ym=({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:L,enableFillHandle:P,frozenCols:U,frozenRows:W,trailingCols:S,trailingRows:x,sinkAriaLabel:z,sinkReadOnly:q,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(Ci.map(M=>[M,wi()]))),E=i.useCallback(M=>{const B=f.current.get(M);if(B!==void 0)return B;const X=wi();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)_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")},[]),_=i.useRef({x:0,y:0}),I=i.useRef(null),K=i.useCallback((M,B)=>{const X=n.current,V=X?.getFrozenSize()??dm,Q=X?.getViewportSize(),le=Q?.width??-1,oe=Q?.height??-1,Ae=_.current;Ae.x=M,Ae.y=B;let Re=I.current;if(Re===null||Re.frozenCols!==V.cols||Re.frozenWidth!==V.width||Re.frozenRows!==V.rows||Re.frozenHeight!==V.height||Re.trailingCols!==V.trailingCols||Re.trailingWidth!==V.trailingWidth||Re.trailingVisibleWidth!==V.trailingVisibleWidth||Re.trailingRows!==V.trailingRows||Re.trailingHeight!==V.trailingHeight||Re.trailingVisibleHeight!==V.trailingVisibleHeight||Re.bodyWidth!==le||Re.bodyHeight!==oe){const ie=V.trailingVisibleWidth,ce=V.trailingVisibleHeight,pe=V.cols<=0&&V.trailingCols<=0?[{kind:"m",map:he=>he-Ae.x,clamp:le,style:Cm,seamLead:!1,seamTrail:!1}]:[...V.cols>0?[{kind:"f",map:he=>he,clamp:V.width,style:{left:"0px",width:`${V.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:he=>he-Ae.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:he=>he-A.current.colAxis.totalSize()+ie,clamp:ie,style:{left:"",right:"0px",width:`${ie}px`},seamLead:!0,seamTrail:!1}]:[]],ge=V.rows<=0&&V.trailingRows<=0?[{kind:"m",map:he=>he-Ae.y,clamp:oe,style:bm,seamLead:!1,seamTrail:!1}]:[...V.rows>0?[{kind:"f",map:he=>he,clamp:V.height,style:{top:"0px",height:`${V.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:he=>he-Ae.y-V.height,clamp:Math.max(0,oe-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:he=>he-A.current.rowAxis.totalSize()+ce,clamp:ce,style:{top:"",bottom:"0px",height:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],ee=[];for(const he of pe)for(const Oe of ge)ee.push({nodes:E(`${he.kind}${Oe.kind}`),xKind:he.kind,yKind:Oe.kind,mapX:he.map,clampWidth:he.clamp,xStyle:he.style,xSeamLead:he.seamLead,xSeamTrail:he.seamTrail,mapY:Oe.map,clampHeight:Oe.clamp,yStyle:Oe.style,ySeamLead:Oe.seamLead,ySeamTrail:Oe.seamTrail});Re={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:oe,ctxs:ee},I.current=Re}const Ie=V.width>0,je=V.trailingWidth>0,_e=V.height>0,ye=V.trailingHeight>0;for(const ie of Re.ctxs)d(ie.nodes.container,ie.xStyle,ie.yStyle),$(ie.nodes,ie.clampWidth,ie.clampHeight),D(ie.nodes,0,Ie),D(ie.nodes,1,je),D(ie.nodes,2,_e),D(ie.nodes,3,ye);return Re.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]),ne=i.useMemo(()=>Object.fromEntries(Ci.map(M=>[M,J(M)])),[J]),re=Math.min(Math.max(0,U),t.count),be=ma(t,re),Se=Math.min(Math.max(0,W),e.count),$e=ga(e,Se),De=S===void 0?0:Math.min(Math.max(0,S),t.count-re),Je=wa(t,De),fe=x===void 0?0:Math.min(Math.max(0,x),e.count-Se),Ne=Ca(e,fe),Ve=i.useRef(null),Qe=i.useRef("add"),Ot=i.useRef(s);Ot.current=s;const xt=i.useRef(!1),qe=Ue.useWheelBridge(n,{enableBridge:!s}),wt=i.useCallback(M=>(r.current=M,qe(M)),[r,qe]),wn=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]),ot=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const{top:X,bottom:V,left:Q,right:le}=wn(M,B),oe=-B.clampHeight*Yt,Ae=B.clampHeight*(1+Yt),Re=-B.clampWidth*Yt,Ie=B.clampWidth*(1+Yt);if(V<oe||X>Ae||le<Re||Q>Ie)return null;const je=Math.max(X,oe),_e=Math.max(Q,Re);return{top:je,left:_e,width:Math.min(le,Ie)-_e,height:Math.min(V,Ae)-je}},[wn]),vr=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const X=wn(M,B),V=-B.clampHeight*Yt,Q=B.clampHeight*(1+Yt),le=-B.clampWidth*Yt,oe=B.clampWidth*(1+Yt),Ae=Math.min(Math.max(X.top,V),Q),Re=Math.min(Math.max(X.left,le),oe);return{top:Ae,left:Re,width:Math.min(Math.max(X.right,le),oe)-Re,height:Math.min(Math.max(X.bottom,V),Q)-Ae}},[wn]),Cn=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??gi(B);for(const Q of ya(X))M.insertBefore(Q,V)},[]),ue=i.useCallback((M,B,X,V)=>{const Q=vr(B,X);if(Q===null){hi(M);return}mm(M,Q,X,V,pc(B,t.count)||hc(B,e.count))},[vr,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&&mi(le)}if(V===null){M.nodes.dragBand!==null&&(mi(M.nodes.dragBand),M.nodes.dragBand=null);return}for(let le=0;le<X.length;le+=1){let oe=Q[le];oe===void 0&&(oe=fi(),_r(oe,M.clampWidth,M.clampHeight),se(B,M.nodes,oe),Q.push(oe)),ue(oe,X[le],M,V)}},[se,ue]),qt=i.useCallback((M,B,X)=>{const V=M.nodes.container;if(V===null)return;if(B===null||X===null){M.nodes.dragBand!==null&&hi(M.nodes.dragBand);return}let Q=M.nodes.dragBand;Q===null&&(Q=fi(),_r(Q,M.clampWidth,M.clampHeight),se(V,M.nodes,Q),M.nodes.dragBand=Q),ue(Q,B,M,X)},[se,ue]),Ee=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`}},[]),It=i.useCallback((M,B,X,V)=>{const Q=V==="point"?null:Cn();for(const le of K(X,B))Ee(le.nodes.dragRect,ot(M,le)),qt(le,M,Q)},[ot,K,Ee,Cn,qt]),st=i.useCallback((M,B,X)=>{for(const V of K(X,B))Ee(V.nodes.fillPreview,M===null?null:ot(M,V))},[ot,K,Ee]),bn=i.useCallback((M,B,X)=>{for(const V of K(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 oe=V.mapX(M.position);Q.style.transform=`translate(${le?Math.max(0,oe):oe}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 oe=V.mapY(M.position);Q.style.transform=`translate(0px, ${le?Math.max(0,oe):oe}px)`,Q.style.width="100%",Q.style.height="1px"}}},[K]),jt=i.useCallback((M,B,X,V,Q,le,oe)=>{if(M===null)return;if(B===null||oe<=0||le<=0){M.style.clipPath=pi;return}const Ae=mn(e,B.row,V),Re=hn(t,B.col,X),Ie=t.sizeOf(B.col),je=e.sizeOf(B.row),_e=Re>=le||Ae>=oe,ye=B.col>=Q.cols&&Re<Q.width,ie=B.row>=Q.rows&&Ae<Q.height,ce=Q.trailingWidth>0&&B.col<t.count-Q.trailingCols&&Re+Ie>le-Q.trailingVisibleWidth,pe=Q.trailingHeight>0&&B.row<e.count-Q.trailingRows&&Ae+je>oe-Q.trailingVisibleHeight;if(_e||ye||ie||ce||pe){M.style.clipPath=pi;return}M.style.clipPath="",M.style.transform=`translate(${Re}px, ${Ae}px)`;const ge=`${Ie} ${je}`;M.dataset.aqspAnchorSig!==ge&&(M.dataset.aqspAnchorSig=ge,M.style.width=`${Ie}px`,M.style.height=`${je}px`)},[e,t]),kr=i.useCallback((M,B,X)=>{if(C===void 0)return;const V=C.current,{width:Q,height:le}=M.getViewportSize(),oe=M.getFrozenSize(),Ae={scroll:X,frozenCount:oe.cols,trailingCount:oe.trailingCols,extent:Q},Re={scroll:B,frozenCount:oe.rows,trailingCount:oe.trailingRows,extent:le};jt(v===void 0?null:v.current,V.interactive,Ae,Re,oe,Q,le),jt(k===void 0?null:k.current,V.tip,Ae,Re,oe,Q,le)},[C,v,k,jt]),Wn=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(),oe=K(Q,V),Ae=Cn(),Re=Ae===null?wm:le.ranges.slice(-hm(oe.length));for(const ie of oe){const ce=ie.nodes.container;if(ce===null)continue;const pe=ie.nodes.fillPool;for(let ge=0;ge<Math.max(pe.length,le.ranges.length);ge+=1){let ee=pe[ge];if(ee===void 0){const ze=document.createElement("div");ze.className="aqsp-selection-fill",ze.setAttribute("data-aqsp-fill",""),ze.style.display="none",ce.insertBefore(ze,gi(ie.nodes)),ee={node:ze,last:{shown:!1,width:-1,height:-1,transform:""}},pe.push(ee)}const he=le.ranges[ge],Oe=he===void 0?null:ot(he,ie);if(Oe===null)ee.last.shown&&(ee.last.shown=!1,ee.node.style.display="none");else{ee.last.shown||(ee.last.shown=!0,ee.node.style.display="block");const ze=`translate(${Oe.left}px, ${Oe.top}px)`;ze!==ee.last.transform&&(ee.last.transform=ze,ee.node.style.transform=ze),Oe.width!==ee.last.width&&(ee.last.width=Oe.width,ee.node.style.width=`${Oe.width}px`),Oe.height!==ee.last.height&&(ee.last.height=Oe.height,ee.node.style.height=`${Oe.height}px`)}}for(;pe.length>le.ranges.length;)pe.pop()?.node.remove();Ee(ie.nodes.active,ot(Ce(le.active,le.active),ie)),de(ie,ce,Re,Ae)}const Ie=h(),je=Ie===null||Ie.foreign?null:Ie;for(const ie of oe){const ce=ie.nodes.marquee;if(ce===null)continue;const pe=je===null?null:ot(je.range,ie),ge=pe!==null&&(ie.xSeamTrail&&pe.left>=ie.clampWidth&&pe.left<ie.clampWidth+cr||ie.xSeamLead&&pe.left+pe.width<=0&&pe.left+pe.width>-cr||ie.ySeamTrail&&pe.top>=ie.clampHeight&&pe.top<ie.clampHeight+cr||ie.ySeamLead&&pe.top+pe.height<=0&&pe.top+pe.height>-cr)?null:pe;if(ge===null)ce.style.display="none";else{ce.style.display="block",ce.style.transform=`translate(${ge.left}px, ${ge.top}px)`,ce.style.width=`${ge.width}px`,ce.style.height=`${ge.height}px`;const Oe=Pr(ge.top),ze=Pr(ge.left),Ct=Pr(ie.clampHeight-(ge.top+ge.height)),lt=Pr(ie.clampWidth-(ge.left+ge.width)),it=`${Oe} ${lt} ${Ct} ${ze}`;it!==ce.dataset.aqspOutsetSig&&(ce.dataset.aqspOutsetSig=it,ce.style.setProperty("--aqsp-clip-outset-top",Oe),ce.style.setProperty("--aqsp-clip-outset-right",lt),ce.style.setProperty("--aqsp-clip-outset-bottom",Ct),ce.style.setProperty("--aqsp-clip-outset-left",ze))}const ee=ge===null?null:je?.kind??null,he=ce.dataset.aqspClipKindLast??null;ee!==he&&(ee===null?(delete ce.dataset.aqspClipKindLast,ce.removeAttribute("data-aqsp-clip-kind")):(ce.dataset.aqspClipKindLast=ee,ce.setAttribute("data-aqsp-clip-kind",ee)))}Ve.current!==null&&It(Ve.current,V,Q,Qe.current),a.current!==null&&bn(a.current,V,Q),y.current!==null&&st(y.current,V,Q);const _e=L.current;if(_e!==null&&!R()){const{width:ie,height:ce}=B.getViewportSize(),pe=le.ranges[le.ranges.length-1];if(!(le.ranges.length===1&&!Ot.current&&!g())||ce<=0||ie<=0)_e.style.display="none";else{const ee=B.getFrozenSize(),he={scroll:Q,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:ie},Oe={scroll:V,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:ce},ze=pe.endCol<ee.cols,Ct=pe.endRow<ee.rows,lt=pe.endCol>=t.count-ee.trailingCols,it=pe.endRow>=e.count-ee.trailingRows,Tt=hn(t,pe.endCol,he)+t.sizeOf(pe.endCol),bt=mn(e,pe.endRow,Oe)+e.sizeOf(pe.endRow),Bt=ze||lt?0:ee.width,yt=Ct||it?0:ee.height,Rn=lt?ie:ie-ee.trailingVisibleWidth,Er=it?ce:ce-ee.trailingVisibleHeight;bt<=yt||bt>Er||Tt<=Bt||Tt>Rn?_e.style.display="none":(_e.style.display="block",_e.style.transform=`translate(${Tt-bi+1}px, ${bt-bi+1}px)`)}}const ye=r.current;if(ye!==null){const ie=le.active,{width:ce,height:pe}=B.getViewportSize(),ge=B.getFrozenSize(),ee={scroll:Q,frozenCount:ge.cols,trailingCount:ge.trailingCols,extent:ce},he={scroll:V,frozenCount:ge.rows,trailingCount:ge.trailingRows,extent:pe},Oe=mn(e,ie.row,he),ze=hn(t,ie.col,ee),Ct=pe>0?Math.min(Math.max(Oe,0),Math.max(0,pe-1)):0,lt=ce>0?Math.min(Math.max(ze,0),Math.max(0,ce-1)):0;ye.style.top=`${Ct}px`,ye.style.left=`${lt}px`,Ot.current?(ye.style.width=`${t.sizeOf(ie.col)}px`,ye.style.height=`${e.sizeOf(ie.row)}px`,ye.style.paddingTop=`${gm(e.sizeOf(ie.row),O===void 0?zt:O.current)}px`):(ye.style.width="1px",ye.style.height="1px",ye.style.paddingTop="0px");const it=ie.col>=ge.cols&&ze<ge.width,Tt=ie.row>=ge.rows&&Oe<ge.height,bt=ge.trailingWidth>0&&ie.col<t.count-ge.trailingCols&&ze+t.sizeOf(ie.col)>ce-ge.trailingVisibleWidth,Bt=ge.trailingHeight>0&&ie.row<e.count-ge.trailingRows&&Oe+e.sizeOf(ie.row)>pe-ge.trailingVisibleHeight,yt=Ot.current&&Oe===Ct&&ze===lt&&!it&&!Tt&&!bt&&!Bt;yt!==xt.current&&(xt.current=yt,yt?ye.setAttribute("data-aqsp-editing",""):ye.removeAttribute("data-aqsp-editing"))}kr(B,V,Q)},[n,ot,K,Ee,It,bn,st,h,o,g,R,L,r,e,t,Cn,de,O,kr]),fo=i.useCallback((M,B)=>{Ve.current=M,Qe.current=B;const X=M===null?"add":B;for(const le of K(0,0)){const oe=le.nodes.dragRect;if(oe===null)continue;const Ae=oe.dataset.aqspDragModeLast??"add";X!==Ae&&(oe.dataset.aqspDragModeLast=X,X==="add"?oe.removeAttribute("data-aqsp-drag-mode"):oe.setAttribute("data-aqsp-drag-mode",X))}const V=n.current;if(M===null||V===null){for(const le of K(0,0))le.nodes.dragRect!==null&&(le.nodes.dragRect.style.display="none"),qt(le,null,null);return}const Q=V.getScrollPosition();It(M,Math.max(0,Q.y),Math.max(0,Q.x),B)},[n,It,K,qt]),Sr=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();st(M,Math.max(0,X.y),Math.max(0,X.x))},[n,st,K]),po=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();bn(M,Math.max(0,X.y),Math.max(0,X.x))},[n,bn,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=Wn,u.current=fo,F.current=Sr,H.current=po,()=>{c.current=null,u.current=null,F.current=null,H.current=null})),i.useEffect(()=>{Wn()},[Wn,s,re,Se,De,fe]),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=re>0||De>0?[...re>0?[{k:"f",style:{left:0,width:be}}]:[],{k:"s",style:{left:be,right:Je}},...De>0?[{k:"t",style:{right:0,width:Je}}]:[]]:[{k:"m",style:{left:0,right:0}}],ho=Se>0||fe>0?[...Se>0?[{k:"f",style:{top:0,height:$e}}]:[],{k:"s",style:{top:$e,bottom:Ne}},...fe>0?[{k:"t",style:{bottom:0,height:Ne}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Ht=M=>M==="m"?0:M==="s"?1:M==="t"?2:3,yn=_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)=>Ht(M.key[0])+Ht(M.key[1])-(Ht(B.key[0])+Ht(B.key[1]))),Kn=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:xe.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:xe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[yn.map(({xk:M,yk:B,key:X,style:V})=>{const Q=ne[X];return Y.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Kn(X),style:V,ref:Q.container,children:[M==="s"&&re>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:Q.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:Q.dividerXTrailing}):null,B==="s"&&Se>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:Q.dividerYLeading}):null,B==="s"&&fe>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:Q.dividerYTrailing}):null,Y.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:Q.active}),Y.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:Q.dragRect}),Y.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:Q.marquee}),Y.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:Q.fillPreview}),Y.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:Q.resizeGuide})]},X)}),Y.jsx("textarea",{ref:wt,className:"aqsp-sink","aria-label":z,"aria-readonly":q?"true":void 0,"aria-keyshortcuts":T,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),P?Y.jsx("div",{ref:L,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ra=({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 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:g,children:[Y.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[Fe(t,"commentTitle"),Y.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Fe(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":Fe(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:Fe(t,"commentPost")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Fe(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},va=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),u=i.useRef(!1),h=o.trim()===""?null:tn(o),g=o.trim()!==""&&h===null,R=P=>{u.current=!0;try{P()}finally{u.current=!1}},F=()=>{l||g||R(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},H=P=>{if(P.key==="Escape"){P.preventDefault(),R(e.close);return}P.key==="Enter"&&!P.altKey&&!P.shiftKey&&(P.preventDefault(),F())},L=P=>{u.current||P.relatedTarget instanceof Node&&P.currentTarget.contains(P.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":g?"":void 0,role:"dialog","aria-labelledby":c,onBlur:L,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Fe(t,"linkTitle")}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:Fe(t,"linkTextField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:P=>r(P.currentTarget.value),onKeyDown:H})]}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:Fe(t,"linkUrlField")}),Y.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:P=>s(P.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:g||l,"aria-disabled":l?"true":void 0,onClick:F,children:Fe(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:Fe(t,"linkOpen")}):null,Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Fe(t,"popoverClose"),onClick:()=>R(e.close),children:"×"})]})]})},yi=500,ka=({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>yi?u.slice(0,yi):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]))},L=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)))},P=W=>{c.current||W.relatedTarget instanceof Node&&W.currentTarget.contains(W.relatedTarget)||F(e.close)},U=W=>`${l}-${W}`;return Y.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:P,children:[Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Fe(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":Fe(t,"listTitle"),children:[h.length===0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Fe(t,"listEmpty")}):h.map((W,S)=>Y.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?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Fe(t,"listMore",g)}):null]})]})},Sa=({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":Fe(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ea=({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}},g=()=>{s||h(()=>e.commit(r===""?null:r))},R=()=>{r!==n&&!s?g():h(e.close)},F=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(),g())},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:Fe(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:F}),Y.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Fe(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:g,children:Fe(t,"noteSave")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Fe(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},Aa=({ctx:e})=>Y.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Dt=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")}),Ri=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Oa=Object.freeze({all:Dt(Ri),values:Dt(["text"]),formats:Dt(["format","borders","cf"]),formulas:Dt(["text","formula"]),noBorders:Dt(Ri.filter(e=>e!=="borders")),columnWidths:Dt(["sizes"]),validation:Dt(["validation"]),conditionalFormats:Dt(["cf"]),commentsAndNotes:Dt(["note","comments"])}),vi=Object.freeze({mode:"all"}),hs=Object.freeze({t:""}),ki=Object.freeze({row:1<<30,col:1<<30}),Rm=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),vm=e=>e.t===""&&e.f===void 0,km=e=>e.length>1&&e.startsWith("="),Sm=(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}},Si=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Em=(e,t,n,r)=>{const o=km(e),s=e===""?"0":nt(e);if(!o&&s===null)return null;const l=Rm[n];if(t.f!==void 0){const h=Cr(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:Si(Number(s));const c=nt(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Si(Sm(Number(s),u,n))},Ei=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Am=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:Ei(e.start),end:Ei(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}}}},Om=e=>{const t=Cr(e,ki),n=wr(t);let r="",o=0,s=!1;for(const l of n){const c=Am(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${Zt(c)}`,o=l.end,s=!0)}return s?io(`${r}${t.slice(o)}`,ki):e},xm=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return hs;const o=r[n];return o===void 0?hs:o},Tm=e=>{const{rows:t,cols:n}=e,r=Oc(Om);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=xm(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}},$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,Lm=(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},Ai=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const g of c)$m(g,t)?(h.push(Lm(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},Oi=new WeakMap,xa=e=>{const t=Oi.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 Oi.set(e,o),o},no=(e,t)=>t===void 0?void 0:e[t],Dm=(e,t,n,r)=>{const o=xa(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=gt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},Mm=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Em(n.readText(),o,r,n):o.f===void 0?o.t:Cr(o.f,n)},xi=(e,t,n,r,o)=>{const s=Oa[r.mode];if(r.skipBlanks===!0&&vm(e))return null;const l={};let c=!1;if(s.text){const u=Mm(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Dm(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=no(xa(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=no(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},Ti=(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}}),zm=["text/html","text/plain"],Fm=(e,t,n)=>{if(e===0||t===0)return 0;const r=rt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Nm=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Pm=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,_m=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}}},$i=e=>{const t=e.clipboardData;return t??null},qm=(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}},Im=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=qm(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},jm=(e,t,n,r,o)=>{const s=Bn(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=Vn(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},Ta=(e,t)=>{const n=fc(),r=Wd(),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(jm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Im(e.getConditionalFormats(),t)}},Li=e=>e.kind==="cut"?{...e.payload,...Ta(e.sourceAdapter,e.range)}:e.payload,Hm=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:[]}),Bm=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=tn(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},Vm=(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},Wm=(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 Ce({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Km=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 q=t.current;n.current={kind:S,range:x,clipId:z.clipId,sourceAdapter:q.adapter,payload:z},q.repaintOverlay(),q.onClipChange?.({kind:S,range:x,foreign:!1})},[]),u=i.useCallback(S=>{const x=t.current,z=x.adapter,q=rt(S),T={v:1,rows:q.rows,cols:q.cols,clipId:vs(),...Ta(z,S),wholeRows:pc(S,z.colCount),wholeCols:hc(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),en));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),en));T.rowHeights=N}}return T},[]),h=i.useCallback((S,x)=>{const z=t.current,q=z.getSelection(),T=q.ranges[q.ranges.length-1],N=At([T]);if(N>z.maxOperationCells)return S.preventDefault(),z.onOperationRejected?.(x,N,"limit"),null;if(x==="cut"&&ir(z.adapter,T))return S.preventDefault(),z.rejectReadOnly({kind:"operation",op:"cut",cellCount:N}),null;q.ranges.length>1&&z.onCopyMultiRange?.();const O=u(T),m=tc(O),p=$i(S);return p!==null&&(p.setData("text/plain",Nt.serializeClipboardTsv(O.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",Wc(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 q=t.current;if(!z.sizes||q.resize===void 0)return;const{rowAxis:T,colAxis:N,resizeTracks:O}=q.resize,m=(p,C,v)=>{const k=Cs(C,v,null,{maxOperationCells:q.maxOperationCells,rowHiddenLimit:gs,axisKind:p});if(!k.ok){q.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,q=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>q.rowCount||N.col+T.cols>q.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},Ce(N,N),N,q.rowCount,q.colCount);if(m!==null&&ir(q,m))return z.rejectReadOnly({kind:"operation",op:"paste",cellCount:T.rows*T.cols}),"rejected";if(ir(S.sourceAdapter,S.range))return z.rejectReadOnly({kind:"operation",op:"cut",cellCount:At([S.range])}),"rejected";const p=Li(S),C=Zr(q),v=Ai(p,C),k={row:0,col:0,readText:()=>Bn(q,k.row,k.col).text,readFormat:()=>q.getCellFormat===void 0?void 0:q.getCellFormat(k.row,k.col)},{edits:b,tiles:y}=ni(v.cells,Ce(N,N),N,q.rowCount,q.colCount,(E,d,$)=>(k.row=S.range.startRow+(d-N.row),k.col=S.range.startCol+($-N.col),xi(E,v,k,vi,C))),a=Zr(S.sourceAdapter),f=[];if(Ut([S.range],E=>{f.push(Vm(E.row,E.col,a))}),S.sourceAdapter===q){if(!g([...f,...b],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const E=z.commitPaste(b,{sameSheet:!1,conditionalFormats:Ti(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:[Ce(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 q=t.current,T=q.adapter,N=K=>(q.onClipboardUnavailable?.(K),"rejected"),O=oc(S,x);if(O==="none")return x==="menu"?N("empty"):"empty";const m=q.getSelection(),p=m.ranges[m.ranges.length-1],C=z.transpose===!0,v=(K,G)=>{const J=Fm(C?G:K,C?K:G,p);return J>q.maxOperationCells?(q.onOperationRejected?.("paste",J,"limit"),!0):!1};let k,b=null;if(O==="aqsp"){const K=Cd(S,x);if(K===null)return N("unreadable");const G=n.current;if(G!==null&&K.clipId===G.clipId&&(b=G),b!==null&&b.kind==="cut"&&Nm(z))return F(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 q.onOperationRejected?.("paste",b.payload.rows*b.payload.cols,"bounds"),"rejected";k=Li(b)}else{const J=bd(S,x);if(J===null)return N("unreadable");if(v(J.rows,J.cols))return"rejected";k=Bm(J)}}else if(O==="tsv"){const K=S.getData("text/plain"),G=Nt.measureTsv(K);if(v(G.rows,G.cols))return"rejected";k=Hm(Nt.parseTsv(K))}else{const K=S.getData("text/html"),G=Vd(K);if(G.cols===0&&G.rows>q.maxOperationCells)return q.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(v(G.rows,G.cols))return"rejected";const J=Xc(K,O,q.formats===void 0?{}:{currency:q.formats.currency,locale:q.formats.locale},q.maxOperationCells);if(J.outcome==="none")return N("unreadable");if(J.outcome==="limit")return q.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(v(J.payload.rows,J.payload.cols))return"rejected";k=J.payload}const y=Zr(T),a=Ai(C?Tm(k):k,y),f=Oa[z.mode];if(Pm(f)){const K=fs({rows:a.rows,cols:a.cols},p,m.active,T.rowCount,T.colCount);if(K!==null&&ir(T,K))return q.rejectReadOnly({kind:"operation",op:"paste",cellCount:At([K])}),"rejected"}const E={row:0,col:0,readText:()=>Bn(T,E.row,E.col).text,readFormat:()=>T.getCellFormat===void 0?void 0:T.getCellFormat(E.row,E.col)},{edits:d,tiles:$}=ni(a.cells,p,m.active,T.rowCount,T.colCount,(K,G,J)=>(E.row=G,E.col=J,xi(K,a,E,z,y))),A=Wm($,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>q.maxOperationCells)return q.onOperationRejected?.("paste",G,"limit"),"rejected"}const D=f.cf?Ti(a.conditionalFormats,$):[];if(d.length===0&&D.length===0)return R(a,A,f),"empty";r.current=b===null?"foreign":"own";let _=!1;try{_=g(d,{sameSheet:b!==null&&b.sourceAdapter===T,conditionalFormats:D})}finally{r.current="none"}if(!_)return"rejected";R(a,A,f);const I={row:A.startRow,col:A.startCol};return q.setSelection({ranges:[A],anchor:I,active:I}),"applied"},[F,g,R]),L=i.useCallback(async S=>{const x=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),z=navigator;if(z.clipboard===void 0)return x("insecure-origin");let q;try{q=await z.clipboard.read({unsanitized:["text/html"]})}catch{return x("permission-denied")}if(q.length===0)return x("empty");const T=q[0],N=Array.from(T.types),O=new Map;try{for(const C of zm)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]),P=i.useCallback(async S=>{const x=await L(S);return t.current.onPasteResolved?.(x,"menu"),x},[L]),{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)},q=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=vi;const p=O.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(m=p.current,p.current=null);const C=$i(N);if(C===null)return;const v=H(_m(C),"event",m);O.onPasteResolved?.(v,"event")};return S.addEventListener("copy",z),S.addEventListener("cut",q),S.addEventListener("paste",T),()=>{S.removeEventListener("copy",z),S.removeEventListener("cut",q),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:P}),[o,s,l,P])},$a=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)}`)},La=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}},Di=(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}`}`},Da=(e,t)=>{let n;if(e.exponent===null)n=Di(e.negative,e.digits,e.point+t);else{const r=Di(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return nt(n)===null?null:n},Ym=(e,t)=>{$a(t);const n=nt(e);return n===null?null:Da(La(n),t)},Um=e=>{const t=nt(e);if(t!==null){const r=La(t);return Da({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},Ma=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)},Xm=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},za=(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 Xm(r)?r:null},Gm=(e,t)=>{$a(t);const n=Ma(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=za(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},Zm=e=>{const t=Ma(e),n=za(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},rr=(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"},Mi={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"}},Jm={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},fr=e=>e<10?`0${e}`:String(e),Qm=e=>{const t=new Date(e);return`${t.getFullYear()}-${fr(t.getMonth()+1)}-${fr(t.getDate())}`},eg=e=>{const t=new Date(e);return`${fr(t.getHours())}:${fr(t.getMinutes())}:${fr(t.getSeconds())}`},tg=(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),ng=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),rg=e=>e===void 0||e.borders===void 0?{}:e.borders,og={top:1,right:2,bottom:4,left:8},sg={style:"thin",color:bs},lg=(e,t)=>{if(e===void 0)return!1;const n=Ye(e);return n!==null&&n===Ye(t)},ig=(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}}},cg=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[Ce(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(!rr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Fn(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)Ut([y],a=>{const f=b===void 0?void 0:b(a.row,a.col),{bucket:E,patch:d}=m(a,y,f);let $=v.get(E);$===void 0&&($=new Map,v.set(E,$));let A;$.has(f)?A=$.get(f):(A=Rs(f,d),$.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=sg)=>{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:og[m];return o((v,k,b)=>{const y=tg(v,k)&C;return{bucket:y,patch:{borders:{...rg(b),...ng(y,p)}}}})},[s,o]),u=i.useCallback((m,p,C)=>{const v=ea(t.current.adapter,m.row,m.col);for(const k of p)C.push(ta(v,m,k))},[]),h=i.useCallback(m=>{const p=t.current,C=p.getSelection();if(!rr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[];if(m==="selection"){const b=C.active,y=[];Ut(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(Be(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(!rr("fill",C.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(Fn(m.adapter,C.ranges))return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:At(C.ranges)}),!1;const v=[];let k=!1;return Ut(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(!rr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Fn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:At(C.ranges)}),!1;const v=[],k=p.adapter;return Ut(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 $ of k.ranges)y+=m==="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:m==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const $ of k.ranges){const A=m==="row"?$.startRow:$.startCol,D=m==="row"?$.endRow:$.endCol;for(let _=A;_<=D;_+=1){if(a.has(_))continue;a.add(_),v.sizeOf(_)===0!==p&&f.push({index:_,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 Vn(m.adapter.getCellHyperlink(p.row,p.col))},[]),L=i.useCallback(m=>{const p=t.current,C=p.adapter,v=Mi[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]),P=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(!Be(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(!L(m))return!1;const C=Mi[m];if(!P(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(Jm)?(l(m,null),!0):!1;case"value":return s({value:ig(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=lg(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=>Ym(k,C.exponent),formula:k=>Gm(k,C.exponent)});case"sign":return R({text:Um,formula:Zm});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"?Qm(p.now()):eg(p.now());if(v)return p.insertAtCaret(k),!0;const b=p.getActive();return Be(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}}}},[L,P,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:tn(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 Be(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 Be(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]),q=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(Be(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(!rr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Fn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:At(C)}),!1;const v=[];return Ut(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:q,setValidation:T,isCommandAvailable:L}),[W,N,O,x,z,q,T,L])},Hr="data-aqsp-pointing",ag=(e,t)=>{const n=Dc(e,t);return n!==null&&"insertAt"in n},ug=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},dg=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(zt),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=Dc(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?zt:E;d!==zt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),H=i.useCallback(y=>{ug(y,Object.keys(h.current.style)),h.current=zt;const a=t.current.editPaintRef;a!==void 0&&(a.current=zt)},[]),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(Hr)),o(!1)};if(y.commit){const d=a.sinkRef.current,$=d===null?"":d.value,A=Bn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
+
`),D=$===A;let _;if(D)_=!0;else if(Be(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),_=!1;else{const I={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};_=(a.validateCommit===void 0||a.validateCommit(f.cell,$).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:$}],I)!==null}if(!_)return y.onReject==="discard"&&(E(),a.rearmSink()),!1}return E(),y.rearm&&a.rearmSink(),!0},[H]),P=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(Be(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}=Bn(f.adapter,d.row,d.col);E.value=A;const _=a===void 0||D?A.length:Math.min(a,A.length);E.setSelectionRange(_,_)}else E.value="";const $=f.resolveEditAlign(d);$!==null&&(E.style.textAlign=$),F(E,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[F]),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]),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=Lc(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"}}}},[g]),q=i.useCallback((y,a)=>{const f=g();if(f===null)return;const E=Ef(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 _=$+E.length;d.setSelectionRange(_,_),"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=Ff(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 _=D.rootRef.current,I=A.relatedTarget;_!==null&&I instanceof Node&&_.contains(I)||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&&ag(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",$)}},[k,b,L,R]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:W,cancelEdit:U,startEdit:P,getPointing:S,togglePointingArm:x,getReferenceCursor:z,insertReference:q,captureSink:T,restoreSink:N,cycleAnchorAtCaret:O,insertAtCaret:m,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[W,U,P,S,x,z,q,T,N,O,m,p,C,v,r])},fg=(e,t,n)=>{const r=new Ue.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}},pg=(e,t,n)=>{const{tree:r,initialHidden:o}=fg(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}},Jt=(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)},qn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:Jt(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=Jt(e,o,1);return r},zi=(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=pg(e,t,r)),o.current.model},In=256,Xo=256,hg=2**32,mg=4096,Fa=Object.freeze([]),Na=["background","color","bold","italic","underline","strikethrough"],Pa=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Qt=(e,t,n)=>(e.size>=mg&&e.clear(),e.set(t,n),n),_a=e=>(Pa(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),qa=(e,t,n,r,o)=>{for(const s of e)if(s.startRow<=n&&s.endRow>=t&&s.startCol<=o&&s.endCol>=r)return!0;return!1},gg=(e,t,n)=>{const r=Math.floor(t/In),o=Math.floor(n/Xo),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*In,u=o*Xo,h=[];for(const g of e.rules)qa(g.ranges,c,c+In-1,u,u+Xo-1)&&h.push(g);return Qt(e.buckets,s,h.length===0?Fa:h)},wg=(e,t,n)=>{const r=Math.floor(t/In),o=r*hg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=gg(e,t,n),c=r*In,u=[];for(const h of l)qa(h.ranges,c,c+In-1,n,n)&&u.push(h);return Qt(e.columns,o,u.length===0?Fa:u)},Cg=(e,t)=>{for(const n of e)if(gn(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,Fi=(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}},Ni=new WeakMap,ms=e=>e===null?null:Number(e),bg=e=>{const t=Ni.get(e);if(t!==void 0)return t;const n=e.b,r={a:ms(nt(e.a)),b:n===void 0?null:ms(nt(n))};return Ni.set(e,r),r},Ia=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Qt(e.numbers,r,ms(nt(n())))},yg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=bg(e),l=Ia(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Fi(e.op,Br(l,s.a),c===null?null:Br(l,c));const u=n(),h=e.b;return Fi(e.op,Br(u,e.a),h===void 0?null:Br(u,h))},Rg=(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=Ye(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))),vg=(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))},kg=(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 Qt(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 Qt(r.extrema,e.id,null);c=Math.min(c,g.min),u=Math.max(u,g.max)}return Qt(r.extrema,e.id,{min:c,max:u})},Sg=(e,t,n,r,o,s)=>{const l=Ia(s,n,r);if(l===null)return null;const c=kg(e,t,o,s);return c===null?null:vg(l,t.min,t.mid,t.max,c)},Eg=(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:Qt(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Ag=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return yg(s,t,n,o)?e.style:null;case"text":return Rg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Sg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Eg(e,s,t,r,o)?e.style:null;default:return null}},Pi=(e,t)=>Rs(e,t),Og=(e,t,n)=>{e[t]=n},xg=(e,t)=>{let n=e;for(const r of Na)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Og(n,r,t[r]));return n},Tg=e=>{let t="";for(const n of Na){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},_i=new WeakMap,$g=Object.freeze({}),Lg=e=>{const t=e===void 0?$g:e,n=_i.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return _i.set(t,r),r},Dg=(e,t,n)=>{const r=Lg(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=Pi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Tg(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Pi(e,t);return l!==void 0&&Qt(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=wg(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(!Cg(R.ranges,u))continue;const F=Ag(R,u,s,e,n);if(F!==null){if(F!==R.style&&(g=!1),h===null)h=F;else{const H=xg(h,F);H!==h&&(g=!1,h=H)}if(R.stopIfTrue===!0)break}}return h===null?l:Dg(l,h,g)},qi=new WeakMap,Mg=e=>{Pa(e,"widthRelevantRules");const t=qi.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 qi.set(e,r),r},zg=({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},Fg=i.memo(zg),Ng=Object.freeze({left:Object.freeze({justifyContent:ar("left")}),center:Object.freeze({justifyContent:ar("center")}),right:Object.freeze({justifyContent:ar("right")})}),Pg=Object.freeze({role:"rowgroup"}),_g=4096,Ii=new WeakMap,Wr=new Map,qg=(e,t)=>{if(e===null)return Ng[t];let n=Ii.get(e);n===void 0&&(n={},Ii.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:ar(t)},s=JSON.stringify(o);let l=Wr.get(s);return l===void 0&&(Wr.size>=_g&&Wr.clear(),l=Object.freeze(o),Wr.set(s,l)),n[t]=l,l},Ig=Fs(),jg=(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},Hg=(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?Ig:r.memoRef.current,o,s,l);h=g===void 0?void 0:g.value;const R=Gc(g,l),F=Jt(n,s,1),H=Jt(t,o,1),L=tf(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);L!==null&&Object.assign(c,L.attrs),c["data-aqsp-align"]=R,u=qg(L,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&&Vn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&um(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Bg=({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:L,readOnly:P,renderCell:U,onScroll:W,onRangeChange:S,focusSink:x,isEditing:z,requestCommit:q,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),$=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]),_=i.useCallback(fe=>r.subscribeCoalesced(fe),[r]),K=i.useSyncExternalStore(_,D,D)+(l??0),G=i.useCallback(fe=>t.sizeOf(fe),[t]),J=i.useCallback(fe=>n.sizeOf(fe),[n]),ne=i.useCallback((fe,Ne)=>e.getCellText(fe,Ne),[e]),re=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),be=i.useMemo(()=>({width:xe.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Se=i.useRef({row:-1,col:-1,value:void 0}),$e=i.useCallback((fe,Ne)=>{const Ve=fe<F,Qe={role:Ve?"columnheader":"gridcell","aria-rowindex":fe+1,"aria-colindex":Ne+1,"data-aqsp-cell":"","data-row":fe,"data-col":Ne,className:"aqsp-cell",...Be(e,fe,Ne)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Ve?{"data-aqsp-header-row":""}:{}},Ot=ah(e,fe,Ne),xt=Ot===null?Qe:{...Qe,...Ot},qe=Hg(e,t,n,A,fe,Ne),wt=Se.current;return wt.row=fe,wt.col=Ne,wt.value=qe===null?void 0:qe.value,qe===null?xt:qe.style===null?{...xt,...qe.attrs}:{...xt,...qe.attrs,style:qe.style}},[e,t,n,A,F]),De=i.useCallback(fe=>({role:"row","aria-rowindex":fe+1,"data-aqsp-row":fe,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Je=i.useCallback((fe,Ne,Ve)=>{let Qe=fe;return e.getCellFormat!==void 0&&(Qe=jn(fe,jg(Se.current,Ne,Ve))),Y.jsx(Fg,{row:Ne,col:Ve,text:fe,display:Qe,renderCell:U,__onCellRender:N})},[K,U,N,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":P?"true":void 0,onPointerDownCapture:fe=>{if(!(fe.target instanceof Element&&fe.target.closest("[data-aqsp-cells]")!==null)&&fe.pointerType==="mouse"){if(fe.button!==0){fe.preventDefault();return}if(fe.preventDefault(),C?.()===!0){fe.stopPropagation(),x();return}if(z()&&!q()){fe.stopPropagation(),x();return}x()}},children:Y.jsx(Ue.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:g,frozenTrailingRows:R,getRowHeight:G,getColWidth:J,getCell:ne,getCellProps:$e,getRowProps:De,contentProps:Pg,behaviorOptions:re,scrollBarOptions:be,overscanRows:k,overscanCols:b,background:y,onRenderTruncated:a,__maxRenderedCells:O,locale:f,labels:E,callbackThrottleMs:0,onScroll:W,onRangeChange:S,testId:T,children:Je})})},Vg=i.memo(Bg),Nn=6,tt=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:tt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=Jt(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-Nn,length:tt}),r.push({kind:"unhide",index:s+1,start:c-tt,length:tt})):l>=2*Nn?n.push({kind:"resize",index:s,start:c-Nn,length:Nn}):n.push({kind:"resize",index:s,start:c-tt,length:tt})}return[...n,...r]},ja=(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:tt}),n.push({kind:"resize",index:c,start:h+tt,length:tt})):u>=2*Nn?n.push({kind:"resize",index:c,start:h,length:Nn}):n.push({kind:"resize",index:c,start:h,length:tt})}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-tt,length:tt}),[...n.reverse(),...r]},Wg=({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=Ue.useWheelBridge(o),L=i.useCallback(d=>(s.current=d,H(d)),[s,H]),P=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,P,P);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($=>d>=$.startCol&&d<=$.endCol),q=Math.min(Math.max(0,n),t.count),T=ma(t,q),N=q>0?qn(t,0,q-1):[],O=Math.min(Math.max(0,r),t.count-q),m=wa(t,O),p=t.totalSize()-m,C=O>0?qn(t,t.count-O,t.count-1):[],v=qn(t,Math.max(W,q),Math.min(S,Math.max(0,t.count-1)-O)),k=[];for(const d of v)k.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:xe.columnIndexToName(d)},d));const b=g?ro(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<q&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&m>0)),a=g&&q>0?ro(t,N):null,f=g&&O>0?ja(t,C):null,E=Y.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,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:q===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[N.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:xe.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(${xe.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${xe.SPREADSHEET_SCROLLBAR_SIZE_PX+T}px)))`:void 0},children:[E,q>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: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?Y.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:Y.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},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:xe.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]})})},Kg=({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=Ue.useWheelBridge(n),L=i.useCallback(d=>(r.current=d,H(d)),[r,H]),P=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: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 q=Math.min(Math.max(0,h),t.count),T=ga(t,q),N=q>0?qn(t,0,q-1):[],O=Math.min(Math.max(0,g),t.count-q),m=Ca(t,O),p=t.totalSize()-m,C=O>0?qn(t,t.count-O,t.count-1):[],v=qn(t,Math.max(S,q),Math.min(x,Math.max(0,t.count-1)-O)),k=[];for(const d of v)k.push(Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":P(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<q&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&m>0)),a=u&&q>0?ro(t,N):null,f=u&&O>0?ja(t,C):null,E=Y.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,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:xe.SPREADSHEET_SCROLLBAR_SIZE_PX},children:q===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[N.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":P(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(${m}px, max(0px, 100% - ${T}px)))`:void 0},children:[E,q>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: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?Y.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${T}px, calc(100% - ${m}px))`},children:Y.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[C.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":P(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]})})},Yg=9,Ug=4,ji=(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},Hi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Xg=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},[]),L=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 $=E;$<=d;$+=1)a.add($)}return[...a]},[H]),P=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]:L(m.axis,m.index);C!==null&&P(m.axis,C.map(v=>({index:v,size:p})),m.index)},[L,P]),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),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=k.adapter.getConditionalFormats===void 0?null:Mg(k.adapter.getConditionalFormats()),_=Fs(),I=new WeakMap,K=new WeakMap,G=new Map;for(const re of m){const be=D===null?null:_a(D.filter(Se=>Se.ranges.some($e=>re>=$e.startCol&&re<=$e.endCol)));for(const Se of p){const $e=k.adapter.getCellText(Se,re),De=k.adapter.getCellFormat===void 0?void 0:Ns(k.adapter,be,_,Se,re,()=>$e),Je=Se<k.headerRows,fe=De===void 0?Je?A:E:Je?ji(De,K,$):ji(De,I,f),Ne=jn($e,De===void 0?void 0:De.value),Ve=G.get(fe);Ve===void 0?G.set(fe,[{col:re,text:Ne}]):Ve.push({col:re,text:Ne})}}const J=new Map;for(const[re,be]of G){a.font=re;for(const Se of be){const $e=a.measureText(Se.text).width,De=J.get(Se.col);(De===void 0||$e>De)&&J.set(Se.col,$e)}}const ne=[];for(const re of m){const be=J.get(re);be!==void 0&&be>0&&ne.push({index:re,size:Math.ceil(be)+Yg})}return ne.length===0?!0:P("col",ne,v)},[P]),S=i.useCallback(m=>{const p=t.current,C=L("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=[],$=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/Ug),m)},[L,W]),x=i.useCallback((m,p,C)=>{const v=m==="col"?t.current.colAxis:t.current.rowAxis,k=Ou(v.sizeOf(p),C);if(k===v.sizeOf(p))return!0;const b=L(m,p);return b===null?!1:P(m,b.map(y=>({index:y,size:k})),p)},[L,P]),z=i.useCallback(m=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(m)===0?!0:S(m):!1},[S]),q=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=I=>I==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(I,K)=>{if(!(K instanceof Element))return null;const G=K.closest(C(I));if(G===null)return null;const J=G.hasAttribute("data-aqsp-unhide"),ne=Number(G.getAttribute(J?"data-aqsp-unhide":I==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),re=G.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:J?"unhide":"resize",index:ne,anchor:re}},k=I=>{if(!(n.current&&R(I)))return;const K=r.current;if(K===null)return;const G=(K.axis==="col"?I.clientX-K.startClientX:I.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 ne=t.current,re=J.axis==="col"?ne.colAxis:ne.rowAxis;ne.writeResizeGuide({axis:J.axis,position:Hi(J,re,o.current),anchor:J.anchor})}))},b=()=>{const I=r.current,K=o.current;F(),I!==null&&U(I,K)},y=I=>{k(I),n.current&&R(I)&&(l.current&1)!==0&&(I.buttons&1)===0&&b()},a=I=>{I.button!==0||!(n.current&&R(I))||b()},f=(I,K)=>G=>{const J=t.current;if(h.current=G.pointerType,G.pointerType!=="mouse")return;if(G.button!==0){G.preventDefault();return}const ne=v(I,G.target);if(ne===null)return;if(G.stopPropagation(),G.preventDefault(),J.isPointing()){J.focusSink();return}if(J.isEditing()&&!J.requestCommit()){J.focusSink();return}J.focusSink();const re=I==="col"?J.colAxis:J.rowAxis,be={axis:I,kind:ne.kind,index:ne.index,anchor:ne.anchor,initialSize:re.sizeOf(ne.index),startClientX:G.clientX,startClientY:G.clientY};r.current=be,o.current=be.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 Se=y,$e=a;g.current={move:Se,up:$e},window.addEventListener("pointermove",Se),window.addEventListener("pointerup",$e),J.writeResizeGuide({axis:I,position:Hi(be,re,o.current),anchor:be.anchor})},E=(I,K)=>G=>{const J=t.current;if(h.current!=="mouse")return;const ne=K.getRootNode(),re=ne instanceof ShadowRoot?ne:K.ownerDocument,be=G.target instanceof Element&&G.target.closest(C(I))!==null?G.target:typeof re.elementFromPoint=="function"?re.elementFromPoint(G.clientX,G.clientY):null,Se=v(I,be);if(Se!==null){if(G.stopPropagation(),J.isEditing()){J.focusSink();return}if(Se.kind==="unhide"){P(I,[{index:Se.index,size:I==="col"?J.defaultColumnWidth:J.defaultRowHeight}],null);return}if(J.autofitEnabled){if(I==="row"){const $e=L("row",Se.index);$e!==null&&P("row",$e.map(De=>({index:De,size:J.defaultRowHeight})),Se.index);return}S(Se.index)}}},d=I=>{!n.current||s.current===null||I.pointerId!==s.current||F()},$=f("col",m),A=f("row",p),D=E("col",m),_=E("row",p);return m.addEventListener("pointerdown",$,{capture:!0}),p.addEventListener("pointerdown",A,{capture:!0}),m.addEventListener("dblclick",D),p.addEventListener("dblclick",_),m.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{m.removeEventListener("pointerdown",$,{capture:!0}),p.removeEventListener("pointerdown",A,{capture:!0}),m.removeEventListener("dblclick",D),p.removeEventListener("dblclick",_),m.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),F()}},[T,N,O,R,F,U,P,L,S]),i.useMemo(()=>({stepTrack:x,autofitColumn:z,autofitColumnsInAllRows:q,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&F()},cancelDrag:F}),[F,x,z,q])},Ps=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Gg=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Ps(n,t.ranges[r]))&&Pt(e.anchor,t.anchor)&&Pt(e.active,t.active),Zg=(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=>nn(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:Ce(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)}},Jg=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Ps(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},mr=(e,t,n)=>n.extend?fn(e,t):n.append?{ranges:[...e.ranges,Ce(t,t)],anchor:t,active:t}:e.ranges.length===1&&Pt(e.anchor,t)&&Pt(e.active,t)&&Ps(e.ranges[0],Ce(t,t))?e:{ranges:[Ce(t,t)],anchor:t,active:t},Qg=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),fn=(e,t)=>{const n=Jg(e,Ce(e.anchor,t));return n.ranges.some(r=>gn(r,n.active))?n:{...n,active:Qg(n.active,n.ranges[n.ranges.length-1])}},Ha=(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(Ce({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Ce({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(Ce({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Ce({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Ce(n,n)],anchor:n,active:n};const s=o.findIndex(c=>gn(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}},ew=(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}}},Ba=(e,t)=>{const n=e.ranges.findIndex(o=>gn(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=ew(e.ranges,r.rangeIndex,r.cell,t),!Pt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Mt=24,Bi=32,oo=4,$n=({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 L=u.current,P=e.current,U=g.current;if(L===null||P===null||U===null){c.current=null;return}const{clientX:W,clientY:S}=L.getPointerPosition(),x=l.current,z=(W-U.left)/x,q=(S-U.top)/x,T=P.getViewportSize(),N=T.width,O=T.height;if(N<=0||O<=0){c.current=requestAnimationFrame(F);return}const m=y=>Math.min(Bi,Math.ceil(y/Mt*Bi));let p=0,C=0;if(s!=="x"){const y=P.getFrozenSize(),a=y.trailingVisibleHeight;q>O-a-Mt?L.anchorRow!==void 0&&y.trailingRows>0&&L.anchorRow>=t.count-y.trailingRows&&a>0&&q>=O-a||(p=m(q-(O-a-Mt))):q<y.height+Mt&&(L.anchorRow!==void 0&&L.anchorRow<y.rows&&y.height>0&&q<y.height||(p=-m(y.height+Mt-q)))}if(s!=="y"){const y=P.getFrozenSize(),a=y.trailingVisibleWidth;z>N-a-Mt?L.anchorCol!==void 0&&y.trailingCols>0&&L.anchorCol>=n.count-y.trailingCols&&a>0&&z>=N-a||(C=m(z-(N-a-Mt))):z<y.width+Mt&&(L.anchorCol!==void 0&&L.anchorCol<y.cols&&y.width>0&&z<y.width||(C=-m(y.width+Mt-z)))}const v=C!==0||p!==0?P.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):P.getScrollPosition(),k=v.y,b=v.x;if(k>=0&&b>=0&&t.totalSize()>0&&n.totalSize()>0){const y=P.getFrozenSize(),a=nn({row:Rr(t,q,{scroll:k,frozenSize:y.height,trailingSize:y.trailingHeight,extent:T.height}),col:yr(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(F)},[e,t,n,s,o]),H=i.useCallback(L=>{R(),u.current=L,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(F)},[R,F,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])},Vi=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(),$=b.getViewportSize();return Math.min(Math.max(yr(m,(T-v.left)/k,{scroll:E,frozenSize:d.width,trailingSize:d.trailingWidth,extent:$.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(Rr(m,(N-v.top)/k,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),m.count-1)},[]),L=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}}},[]),P=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:q}=e;return i.useEffect(()=>{const T=q.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(fn(A,$)),o.current=y.axis==="col"?d.col:d.row}else if(E&&P(f,a))R.current=!0,F.current=a,o.current=a;else{const{press:d,extend:$}=L(a,a),A=mr(f,d,{extend:!1,append:E});y.setSelection(fn(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}g.current=d=>{const $=t.current.axis==="col"?d.col:d.row,{press:A}=L(o.current,o.current),{extend:D}=L(o.current,$);return Ce(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}=L(F.current,F.current),$=mr(f.getSelection(),E,{extend:!1,append:!0});f.setSelection(fn($,d));const A=g.current,D=Math.abs(b.clientX-W.current.clientX),_=Math.abs(b.clientY-W.current.clientY);A!==null&&Math.max(D,_)>=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}=L(F.current,F.current);y.setSelection(Ha(y.getSelection(),Ce(f,E),f)),S();return}const a=H(b.clientX,b.clientY);if(a!==null){const{extend:f}=L(o.current,a);y.setSelection(fn(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,q,H,L,S,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:x,cancelDrag:S}),[x,S])},tw=({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)})}},nw=50,rw=100,Va=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<nw:!1,or={selectAll:Xt("Ctrl+A"),undo:Xt("Ctrl+Z"),redo:Xt("Ctrl+Y"),redoShiftZ:Xt("Ctrl+Shift+Z"),pasteValues:Xt("Ctrl+Shift+V")},ow=new Set(["Shift","Control","Alt","Meta","AltGraph"]),sw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},lw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",iw=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)=>Jt(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}},P=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),W=(a,f,E,d)=>{if(a.sizeOf(f)>0)return f;const $=Jt(a,f,E);if($!==null)return $;const A=Jt(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=>L(S(),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),q(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}},q=(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})`)},N=a=>{const f=s.current,E=f.getSelection();if(Ba(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)},m=(a,f)=>{const E=s.current,d=h.current?.getViewportSize().height??-1;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,Va(a,t.current))return;const E=a.ctrlKey||a.metaKey,d=a.altKey,$=sw[a.key];if(o.current&&!ow.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 _=f.pointing;if(_!==void 0){if($!==void 0&&!d){const K=_.getReferenceCursor();if(K!==null){a.preventDefault();const G=nn(K.cursor,f.rowAxis.count,f.colAxis.count),J=nn(K.origin,f.rowAxis.count,f.colAxis.count),ne=E?z(G,$):L(G,$);if(f.ensureCellVisible(ne),_.insertReference(a.shiftKey?Ce(J,ne):ne,K.axis),f.onPointFrame!==void 0){const re=a.shiftKey?Ce(J,ne):Ce(ne,ne);f.onPointFrame(K.axis==="columns"?Ce({row:0,col:re.startCol},{row:f.rowAxis.count-1,col:re.endCol}):K.axis==="rows"?Ce({row:re.startRow,col:0},{row:re.endRow,col:f.colAxis.count-1}):re),o.current=!0}return}}if(a.key==="F2"&&!E&&!a.shiftKey&&!d&&_.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!E&&!a.shiftKey&&!d&&_.cycleAnchorAtCaret()){a.preventDefault();return}}const I=f.commands;if(I!==void 0){const K=oi(I.table,a);if(K!==null&&Ms.has(K)&&I.isAvailable(K)){a.preventDefault(),I.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;N(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:m(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=oi(A.table,a);if(D!==null&&A.isAvailable(D)){a.preventDefault(),A.execute(D);return}}if($!==void 0&&!d){const D=$==="left"||$==="right",_=$==="right"||$==="down"?1:-1;if(E&&a.shiftKey){a.preventDefault();const I=f.getSelection(),K=S();let G;if(f.findDataEdge!==void 0){const J=D?{row:I.active.row,col:K.col}:{row:K.row,col:I.active.col},ne=f.findDataEdge(J,$);G=D?ne.col:ne.row,T(G,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),G=W(D?f.colAxis:f.rowAxis,G,_,D?K.col:K.row)}else{const J=D?f.colAxis:f.rowAxis;G=_===1?U(J):P(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(lw(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 _=S();f.moveActive({mode:"extend",cell:{row:E?P(f.rowAxis):_.row,col:P(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?P(f.rowAxis):D.row,col:P(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const _=S();f.moveActive({mode:"extend",cell:{row:E?U(f.rowAxis):_.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 I=S();f.moveActive({mode:"extend",cell:{row:m(I.row,D),col:I.col}});return}const _=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(_.row,D),col:_.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(),_=At(D.ranges);if(_>f.maxOperationCells){f.onOperationRejected?.("delete",_,"limit");return}if(f.adapter!==void 0&&Fn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:_});return}const I=[],K=f.adapter!==void 0&&Zr(f.adapter).hyperlink;Ut(D.ranges,G=>{I.push(K?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),f.commitEdits(I,{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(tr(or.selectAll,a)){a.preventDefault();const D=f.getSelection(),_=Ce({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[_],anchor:D.anchor,active:D.active});return}if(tr(or.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(tr(or.redo,a)||tr(or.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 _=h.current,I=_===null?{x:0,y:0}:_.getScrollPosition(),K=Math.max(0,I.y),G=Math.max(0,I.x),J=_===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:_.getFrozenSize(),ne=_===null?{width:0,height:0}:_.getViewportSize(),re=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:mn(f.rowAxis,D.row,{scroll:K,frozenCount:J.rows,trailingCount:J.trailingRows,extent:ne.height})*re,left:hn(f.colAxis,D.col,{scroll:G,frozenCount:J.cols,trailingCount:J.trailingCols,extent:ne.width})*re,width:f.colAxis.sizeOf(D.col)*re,height:f.rowAxis.sizeOf(D.row)*re}});return}if(a.key===" "&&!d&&E!==a.shiftKey){a.preventDefault();const D=f.getSelection(),_=D.ranges.map(I=>E?Ce({row:0,col:I.startCol},{row:f.rowAxis.count-1,col:I.endCol}):Ce({row:I.startRow,col:0},{row:I.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:_,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&tr(or.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},rw)},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])},cw=()=>{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)})}},aw=4,uw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),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(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),L=i.useRef(!1),P=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 nn({row:Rr(m,(N-v.top)/y,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:yr(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 Ce(T,T);const O=Ce({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(),L.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=fh(N,O);if(m>T.maxOperationCells){T.onOperationRejected?.("fill",m,"limit");return}if(Fn(T.adapter,ph(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=hh((v,k)=>ea(T.adapter,v,k),N,O,ta);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:q}=e;return i.useEffect(()=>{const T=q.current;if(!z||T===null)return;const N=v=>{O(v),n.current&&P(v)&&(R.current&1)!==0&&(v.buttons&1)===0&&x()},O=v=>{if(!(n.current&&P(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)>=aw&&(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}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&&P(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(),L.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,_=k.handleRef.current?.getFrozenSize()??uw,I=k.handleRef.current?.getViewportSize()??{width:0,height:0},K={scroll:A,frozenCount:_.cols,trailingCount:_.trailingCols,extent:I.width},G={scroll:E,frozenCount:_.rows,trailingCount:_.trailingRows,extent:I.height},J=hn(k.colAxis,y.endCol,K)+k.colAxis.sizeOf(y.endCol),ne=mn(k.rowAxis,y.endRow,G)+k.rowAxis.sizeOf(y.endRow),re=J-1,be=y.endCol>=_.cols&&_.width>0?Math.max(re,_.width):re,$e=!(y.endCol>=k.colAxis.count-_.trailingCols)&&_.trailingWidth>0?Math.min(be,I.width-_.trailingVisibleWidth-1):be,De=ne-1,Je=y.endRow>=_.rows&&_.height>0?Math.max(De,_.height):De,Ne=!(y.endRow>=k.rowAxis.count-_.trailingRows)&&_.trailingHeight>0?Math.min(Je,I.height-_.trailingVisibleHeight-1):Je;h.current={dx:v.clientX-(a.left+$e*D),dy:v.clientY-(a.top+Ne*D)}}else h.current={dx:0,dy:0};g.current=v.pointerId;try{T.setPointerCapture(v.pointerId)}catch{g.current=null}const d=N,$=m;H.current={move:d,up:$},window.addEventListener("pointermove",d),window.addEventListener("pointerup",$),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,q,P,U,W,S,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&S()},cancelDrag:S}),[S])},fw=320,Jr=8,pw=64,hw=150,Wa=e=>Math.max(0,Math.min(fw,e.width-xe.SPREADSHEET_SCROLLBAR_SIZE_PX-Jr)),mw=(e,t,n)=>{const r=n.width-xe.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-xe.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Wa(n),l=Math.max(0,Math.min(t,o-Jr)),c=e.left+e.width,u=e.top+e.height,h=P=>P>=0&&P+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 P of R)if(h(P.left)&&P.top>=0&&P.top+l<=o)return{left:P.left,top:P.top,width:s,height:l};const F=o-u,H=e.top,L=Math.min(l,Math.max(F,H));if(L>=pw){const P=F>=H?u:e.top-L;for(const U of g)if(h(U))return{left:U,top:P,width:s,height:L}}return{left:Jr,top:Jr,width:s,height:l}},gw=(e,t,n,r)=>t===null||e!==null&&Pt(e,t)||n?!1:r(t),ww=(e,t)=>{switch(e.kind){case"note":return Y.jsx(Ea,{ctx:e,labels:t});case"note-tip":return Y.jsx(Aa,{ctx:e,labels:t});case"comment":return Y.jsx(Ra,{ctx:e,labels:t});case"link":return Y.jsx(va,{ctx:e,labels:t});case"list":return Y.jsx(ka,{ctx:e,labels:t});default:return Y.jsx(Sa,{ctx:e,labels:t})}},Qo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Cw=({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),L=(x,z)=>{const q=g.current.getLayerSize();x.style.width=`${Wa(q)}px`,x.style.maxHeight="";const T=mw(z,x.offsetHeight,q);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=Qo(s);if(H.current===z)return;H.current=z;const q=x.querySelector("[data-aqsp-popover-autofocus]");q!==null?q.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)},[F]);const P=x=>t===void 0?ww(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 Y.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:W,onCompositionEnd:S,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:P(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:P(l)})})]})},bw=["note","note-tip","comment","link","list","message"],yw=(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}},sr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&yw(e,n),Rw=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),L=i.useId(),P=i.useCallback(A=>{const D=t.current,_=D.handleRef.current,I=_===null?{x:0,y:0}:_.getScrollPosition(),K=_===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:_.getFrozenSize(),G=_===null?{width:0,height:0}:_.getViewportSize();return{top:mn(D.rowAxis,A.row,{scroll:Math.max(0,I.y),frozenCount:K.rows,trailingCount:K.trailingRows,extent:G.height}),left:hn(D.colAxis,A.col,{scroll:Math.max(0,I.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(()=>{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&&Pt(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}),S(),!0)),[W,U,S]),z=i.useCallback(()=>{W(),g.current=window.setTimeout(()=>{g.current=null,x()},hw)},[W,x]),q=i.useCallback(A=>{const D=t.current;W();const _=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(A.row,A.col);_===void 0||_===""||(c.current=A,s({kind:"note-tip",cell:A,anchorRect:P(A),current:_,close:x}),U({tip:A}),S())},[P,W,x,U,S]),T=i.useCallback(A=>{const D=t.current;if(A===null&&h.current)return;const _=u.current;u.current=A;const I=c.current;if(I!==null&&A!==null&&Pt(I,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(gw(_,A,D.isDraggingAny(),K)){A!==null&&q(A);return}I!==null&&z()},[q,W,z]),N=i.useCallback((A,D)=>{const _=t.current,I=_.bodyRef.current,K=_.handleRef.current;if(I===null||K===null)return null;const G=I.getBoundingClientRect(),J=_.zoomRef.current,ne=K.getScrollPosition(),re=K.getFrozenSize(),be=K.getViewportSize();return nn({row:Rr(_.rowAxis,(D-G.top)/J,{scroll:Math.max(0,ne.y),frozenSize:re.height,trailingSize:re.trailingHeight,extent:be.height}),col:yr(_.colAxis,(A-G.left)/J,{scroll:Math.max(0,ne.x),frozenSize:re.width,trailingSize:re.trailingWidth,extent:be.width})},_.rowAxis.count,_.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 Zc(D.adapter)?{cellReadOnly:Be(D.adapter,A.row,A.col)}:{}},[]),b=i.useCallback((A,D)=>{const _=t.current;if(Be(_.adapter,A.cell.row,A.cell.col)){_.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...A,...k(A.cell)});return}if(_.commitEdits(D,{source:"annotate"})===null){v({...A,rejected:!0});return}C()},[v,C,k]),y=i.useCallback((A,D)=>{const _=t.current;if(!sr(_.adapter,_.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 I=_.getActive();if(A==="list"&&Be(_.adapter,I.row,I.col)){_.rejectReadOnly({kind:"edit",cell:I,editSession:"none"});return}if(A==="note-tip"){q(I);return}if(A==="message"){if(l.current!==null&&l.current!=="message")return;const ne=D!==void 0&&D.message!==void 0?D.message:void 0,re=_.adapter.getCellValidation===void 0?void 0:_.adapter.getCellValidation(I.row,I.col),be=ne!==void 0?ne:re===void 0?void 0:re.inputMessage;if(be===void 0)return;const Se=D!==void 0&&D.rejected===!0;v({kind:"message",cell:I,anchorRect:P(I),current:{title:Fe(_.labels,"messageTitle"),message:be,rejected:Se},close:C});return}if(_.isEditing()&&!_.requestCommit())return;if(A==="list"){const ne=_.adapter.getCellValidation===void 0?void 0:_.adapter.getCellValidation(I.row,I.col);if(ne===void 0||ne.type!=="list")return;const re=D!==void 0&&D.typed!==void 0?D.typed:"";x(),_.focusSink({preventScroll:!0}),v({kind:"list",cell:I,anchorRect:P(I),current:ne.values,typed:re,commit:be=>{if(Be(t.current.adapter,I.row,I.col)){t.current.rejectReadOnly({kind:"edit",cell:I,editSession:"none"}),C();return}t.current.commitEdits([{row:I.row,col:I.col,text:be}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(x(),_.focusSink({preventScroll:!0}),A==="note"){const ne=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(I.row,I.col),re={kind:"note",cell:I,anchorRect:P(I),current:ne,commit:be=>{b(re,[{row:I.row,col:I.col,note:be}])},close:C,rejected:!1,...k(I)};v(re);return}if(A==="comment"){const ne=_.adapter.getCellComments===void 0?void 0:_.adapter.getCellComments(I.row,I.col),re={kind:"comment",cell:I,anchorRect:P(I),current:ne===void 0?[]:ne,commit:be=>{b(re,[{row:I.row,col:I.col,comments:be}])},close:C,rejected:!1,...k(I)};v(re);return}const K=_.adapter.getCellHyperlink===void 0?void 0:Vn(_.adapter.getCellHyperlink(I.row,I.col)),G=_.adapter.getCellText(I.row,I.col),J={kind:"link",cell:I,anchorRect:P(I),current:{text:G,url:K},commit:ne=>{const re=ne.url===null?null:tn(ne.url);if(re===null&&ne.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ne.url)}`);const be=ne.text===G?{row:I.row,col:I.col,hyperlink:re}:{row:I.row,col:I.col,text:ne.text,hyperlink:re};b(J,[be])},close:C,canOpen:_.onHyperlinkOpen!==void 0,open:()=>{const ne=t.current.onHyperlinkOpen;ne!==void 0&&K!==void 0&&ne(K,I)},rejected:!1,...k(I)};v(J)},[P,C,b,x,v,q,k]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const A=f.current;if(!a||A===null)return;const D=I=>{const K=t.current;sr(K.adapter,K.popovers,"note-tip")&&O({clientX:I.clientX,clientY:I.clientY})},_=()=>{sr(t.current.adapter,t.current.popovers,"note-tip")&&O({cell:null})};return A.addEventListener("pointermove",D),A.addEventListener("pointerleave",_),()=>{A.removeEventListener("pointermove",D),A.removeEventListener("pointerleave",_)}},[a,f,O]),i.useEffect(()=>()=>{R.current!==null&&cancelAnimationFrame(R.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:E,popovers:d}=e,$=i.useMemo(()=>bw.some(A=>sr(E,d,A)),[E,d]);return i.useMemo(()=>({layerEnabled:$,isKindEnabled:A=>sr(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=>Va(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,L])},vw=(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},Ka=(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 nn({row:Rr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:g.height}),col:yr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:g.width})},n.count,r.count)},kw=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),L=i.useRef(!1),P=i.useCallback((O,m)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:k}=t.current;return Ka(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()},[]),q=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 $=t.current;if(d.pointerType==="mouse"&&d.button===0&&(g.current=!1,R.current=null,L.current=!1),H.current=m(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(F.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=P(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 _=$.getSelection();r.current=_;const I=d.shiftKey,K=d.ctrlKey||d.metaKey,G=K&&!I&&_.ranges.some(ne=>gn(ne,D));g.current=G,R.current=G?D:null,G||$.setSelection(mr(_,D,{extend:I,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=ne=>Ce(J,ne),W.current=J.col,S.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)>=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 $=h.current;if(!n.current||$===null)return;const A=t.current,D=P(s.current.clientX,s.current.clientY);D!==null&&A.onDragFrame($(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 $=t.current,A=P(d.clientX,d.clientY);if(A!==null){const D=R.current;g.current&&D!==null?$.setSelection(Ha($.getSelection(),Ce(D,A),D)):$.setSelection(fn($.getSelection(),A))}z()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||q()},f=d=>{const $=t.current;if(!m(d.target)||F.current!=="mouse"||$.isAnyDragging())return;if($.isEditing()&&!$.requestCommit()){$.focusSink();return}$.focusSink(),o.current=O.getBoundingClientRect();const A=P(d.clientX,d.clientY);if(A===null)return;const D=$.getSelection();D.ranges.some(I=>gn(I,A))||$.setSelection(mr(D,A,{extend:!1,append:!1})),$.onContextMenuSelect(A,d)},E=d=>{const $=t.current;if(!H.current||F.current!=="mouse"||$.getPointing?.()||L.current)return;o.current=O.getBoundingClientRect();const A=P(d.clientX,d.clientY);A!==null&&Pt($.getSelection().active,A)&&$.onRequestEdit(A,$.caretFromPointEnabled(A)?vw(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,P,z,q]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:q,cancelDrag:z}),[q,z])},Sw=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:q,rowAxis:T,colAxis:N,zoomRef:O}=t.current;return Ka(q.current,o.current,T,N,O.current,x,z)},[]),L=i.useCallback(()=>{const{autoScroller:x,bodyRef:z,onDragFrame:q}=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,q(null)},[]),P=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,q=z.bodyRef.current;if(!z.enabled||q===null||!z.getPointing())return!1;o.current=q.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{q.setPointerCapture(x.pointerId)}catch{u.current=null}return g.current=O=>{const m=Ce(T,O);return t.current.insertReference(m,"cells"),m},z.autoScroller.stop(),F.current=!1,z.onDragFrame(Ce(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",q=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&&L()},T=O=>{O.button!==0||!(n.current&&z(O))||L()},N=O=>{!n.current||u.current===null||O.pointerId!==u.current||L()};return x.addEventListener("pointermove",q),x.addEventListener("pointerup",T),x.addEventListener("lostpointercapture",N),()=>{x.removeEventListener("pointermove",q),x.removeEventListener("pointerup",T),x.removeEventListener("lostpointercapture",N),L()}},[W,S,H,L]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:P,cancelDrag:L,onPointerDown:U}),[P,L,U])},Ew=(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})`)},Aw=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)})`)},Wi=(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},Ow=24,xw=200,Ya=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Ki=5,Tw=/^#[0-9A-Fa-f]{6}$/,$w=Object.freeze({row:!1,column:!1,intersection:!1}),Yi=Object.freeze({ok:!0}),Ui=(e,t)=>{if(t===void 0)return Ya;if(t.length!==Ki)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Ki} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Tw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Lw=e=>{for(const t of["row","column","intersection"])if(Ye(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},Dw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ba},Mw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},zw=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Ue.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Ln={ranges:[Ce({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Fw=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=Ow,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:L,onRenderTruncated:P,renderCell:U,onSelectionChange:W,onCellContextMenu:S,onUndoRequest:x,onRedoRequest:z,onCopyMultiRange:q,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:$,labels:A,shortcuts:D,colors:_,formats:I,highlight:K,defaultHighlight:G,onHighlightChange:J,highlightColors:ne,popovers:re,renderPopover:be,onClipChange:Se,onHyperlinkOpen:$e,onValidationRejected:De,onPasteSpecialRequest:Je,onClipboardUnavailable:fe,onPasteResolved:Ne,now:Ve=Date.now,zoom:Qe,defaultZoom:Ot,onZoomChange:xt,testId:qe,className:wt,__onCellRender:wn,__onVirtualKeyboardRaise:ot,__maxRenderedCells:vr},Cn){const se=i.useMemo(()=>r?lh(t):t,[t,r]),ue=zi(se.rowCount,s),de=zi(se.colCount,l),qt=i.useRef(null);qt.current===null&&(qt.current=cw());const Ee=qt.current,It=Ue.resolveVirtualScrollLocale($),st=i.useMemo(()=>ia($,A),[$,A]),bn=zw(Dh(st)),jt=i.useMemo(()=>xh(D),[D]),kr=i.useMemo(()=>{if(!k)return;const j=[...jt].filter(([,Z])=>Wo.includes(Z)).sort(([,Z],[,te])=>Wo.indexOf(Z)-Wo.indexOf(te)).map(([Z])=>vh(Z)).filter(Z=>Z!==null);return j.length===0?void 0:j.join(" ")},[jt,k]),Wn=i.useMemo(()=>({fill:Ui("fill",_===void 0?void 0:_.fill),font:Ui("font",_===void 0?void 0:_.font)}),[_]),fo=i.useMemo(()=>ne===void 0?void 0:Lw(ne),[ne]);if(se.getConditionalFormats!==void 0&&se.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");Ew(n,u),Aw(o);const Sr=i.useCallback(()=>Ee.get().editVersion,[Ee]),po=i.useCallback(w=>Ee.subscribeCoalesced(w),[Ee]),ho=i.useSyncExternalStore(po,Sr,Sr)+(p===void 0?0:p),Ht=se.getConditionalFormats===void 0?null:se.getConditionalFormats(),yn=i.useMemo(()=>({index:Ht===null?null:_a(Ht),memo:Fs()}),[se,Ht,ho]),Kn=i.useRef(yn.index);Kn.current=yn.index;const M=i.useRef(yn.memo);M.current=yn.memo;const B=i.useCallback((w,j,Z)=>Ns(se,Kn.current,M.current,w,j,Z),[se]),X=i.useRef(null),[V,Q]=i.useState(()=>xe.clampSpreadsheetZoom(Ot??1)),le=xe.clampSpreadsheetZoom(Qe??V),oe=i.useRef(le);oe.current=le;const Ae=i.useRef(le);Ae.current=le;const Re=i.useRef(null),Ie=i.useRef(xt);Ie.current=xt;const je=i.useRef(Qe!==void 0);je.current=Qe!==void 0;const _e=i.useCallback(w=>{const j=xe.clampSpreadsheetZoom(w);j!==Ae.current&&(Ae.current=j,je.current||Q(j),Ie.current?.(j))},[]),ye=se.rowCount===0||se.colCount===0,ie=!ye;i.useEffect(()=>{const w=X.current;if(!ie||w===null)return;const j=te=>{te.defaultPrevented||!te.altKey||te.ctrlKey||te.metaKey||te.shiftKey||te.deltaY!==0&&(te.preventDefault(),te.stopPropagation(),!Re.current?.()&&_e(xe.stepSpreadsheetZoom(Ae.current,te.deltaY<0?1:-1)))},Z=te=>{if(te.defaultPrevented||!(te.ctrlKey&&te.altKey)||te.metaKey||te.getModifierState("AltGraph"))return;const ve=te.key==="="||te.key==="+"?xe.stepSpreadsheetZoom(Ae.current,1):te.key==="-"?xe.stepSpreadsheetZoom(Ae.current,-1):te.key==="0"?1:null;ve!==null&&(te.preventDefault(),te.stopPropagation(),!Re.current?.()&&_e(ve))};return w.addEventListener("wheel",j,{passive:!1,capture:!0}),w.addEventListener("keydown",Z,!0),()=>{w.removeEventListener("wheel",j,{capture:!0}),w.removeEventListener("keydown",Z,!0)}},[_e,ie]);const ce=i.useRef(null),pe=i.useRef(null),ge=i.useRef(null),ee=i.useRef(null),he=i.useRef(null),Oe=i.useRef(null),ze=i.useRef(0),Ct=i.useRef(null),lt=i.useRef(0),it=i.useRef(null),Tt=i.useRef(null),bt=i.useRef(null),Bt=i.useRef(null),yt=i.useRef(null),Rn=i.useRef(null),Er=i.useRef(null),[vn,mo]=i.useState(Ln),Rt=i.useRef(vn),$t=i.useCallback(()=>Rt.current,[]),[Ua,Xa]=i.useState(()=>G===void 0?$w:G),kn=K!==void 0?K:Ua,go=i.useRef(kn);go.current=kn;const Ga=Dw(fo,kn),qs=i.useRef(K!==void 0);qs.current=K!==void 0;const Is=i.useRef(J);Is.current=J;const Za=i.useCallback(w=>{qs.current||Xa(w),Is.current?.(w)},[]),js=i.useRef(null),wo=i.useRef(null),Lt=i.useRef(null),Co=i.useRef(()=>!1),Hs=i.useRef(()=>{}),Bs=i.useRef(()=>null),Vs=i.useRef(()=>{}),rn=i.useCallback(()=>Co.current(),[]),bo=i.useMemo(()=>({getPointing:()=>Co.current(),insertReference:(w,j)=>Hs.current(w,j)}),[]),Ws=i.useRef(zt),Ks=i.useRef(null),yo=i.useRef({interactive:null,tip:null}),Ys=i.useRef(null),Us=i.useRef(null),Ar=i.useRef(()=>{}),Xs=i.useRef(()=>!1),Vt=i.useRef(null),Yn=i.useCallback(()=>{const w=Vt.current;if(w===null||w.isOpen()!=="message")return!1;const j=w.context;return j===null||j.kind!=="message"||!j.current.rejected?!1:(w.close(),!0)},[]),Ro=i.useRef(()=>!1),Gs=i.useRef(()=>!1),Zs=i.useRef(null),vo=i.useRef(()=>Promise.resolve("rejected")),Le=i.useCallback(()=>{js.current?.()},[]),Me=i.useCallback(w=>{he.current?.focus(w)},[]),ko=i.useRef(!1),Ja=i.useCallback(()=>{const w=X.current;if(w!==null){ko.current=!0;try{w.focus()}finally{ko.current=!1}}},[]),Xe=i.useCallback(()=>{const w=he.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),Sn=i.useCallback((w,j)=>{if(w===null)return;const Z=j?"":"none";w.style.display!==Z&&(w.style.display=Z)},[]),ct=i.useCallback(()=>{const w=Oe.current;if(w!==null){const Z=Math.max(0,ee.current?.getScrollPosition().y??0),te=ee.current?.getFrozenSize().height??0;w.style.transform=`translateY(${ze.current-Z-te}px)`}const j=ee.current;if(j!==null&&(yt.current!==null||Rn.current!==null)){const Z=j.getFrozenSize();Sn(yt.current,Z.height>0),Sn(Rn.current,Z.trailingHeight>0)}},[Sn]),at=i.useCallback(()=>{const w=Ct.current;if(w!==null){const Z=Math.max(0,ee.current?.getScrollPosition().x??0),te=ee.current?.getFrozenSize().width??0;w.style.transform=`translateX(${lt.current-Z-te}px)`}const j=ee.current;if(j!==null&&(bt.current!==null||Bt.current!==null)){const Z=j.getFrozenSize();Sn(bt.current,Z.width>0),Sn(Bt.current,Z.trailingWidth>0)}},[Sn]),Un=i.useRef(null),En=i.useCallback(()=>{bt.current===null&&Bt.current===null&&yt.current===null&&Rn.current===null||Un.current===null&&(Un.current=requestAnimationFrame(()=>{Un.current=null,ct(),at(),Le()}))},[ct,at,Le]);i.useEffect(()=>()=>{Un.current!==null&&cancelAnimationFrame(Un.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=tw({handleRef:ee,rowAxis:ue,colAxis:de}));const Or=i.useCallback(w=>{const j=ee.current,Z=j===null?{x:0,y:0}:j.getScrollPosition(),te=j===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:j.getFrozenSize(),ve=j===null?{width:0,height:0}:j.getViewportSize(),ke=oe.current;return{top:mn(ue,w.row,{scroll:Math.max(0,Z.y),frozenCount:te.rows,trailingCount:te.trailingRows,extent:ve.height})*ke,left:hn(de,w.col,{scroll:Math.max(0,Z.x),frozenCount:te.cols,trailingCount:te.trailingCols,extent:ve.width})*ke,width:de.sizeOf(w.col)*ke,height:ue.sizeOf(w.row)*ke}},[ue,de]),Js=i.useCallback(w=>{const j=ge.current,Z=X.current,te=pe.current;if(j===null||Z===null||te===null||ee.current===null)return;const ve=oe.current,ke=Or(w),pt=te.offsetTop*ve+ke.top,Et=te.offsetLeft*ve+ke.left,Ze=Math.max(0,pt),an=Math.max(0,Et),er=Math.min(Z.clientHeight,pt+ke.height),Ol=Math.min(Z.clientWidth,Et+ke.width);if(er<=Ze||Ol<=an)return;j.style.top=`${Ze}px`,j.style.left=`${an}px`,j.style.width=`${Ol-an}px`,j.style.height=`${er-Ze}px`;const xl=j.getBoundingClientRect();xl.width===0&&xl.height===0||j.scrollIntoView({block:"nearest",inline:"nearest"})},[Or]),Wt=i.useCallback(w=>{So.current?.(w),Js(w)},[Js]),Qs=i.useRef(y);Qs.current=y;const Ao=i.useRef(null),on=i.useCallback(()=>{const w=Qs.current,j=pe.current;if(w===void 0||j===null)return;const Z=oe.current,te={width:(j.offsetLeft+de.totalSize()+xe.SPREADSHEET_SCROLLBAR_SIZE_PX)*Z,height:(j.offsetTop+ue.totalSize()+xe.SPREADSHEET_SCROLLBAR_SIZE_PX)*Z},ve=Ao.current;ve!==null&&ve.width===te.width&&ve.height===te.height||(Ao.current=te,w(te))},[ue,de]);i.useLayoutEffect(()=>{if(y===void 0){Ao.current=null;return}on()});const An=i.useRef(null),sn=i.useRef(null),On=i.useCallback(w=>{An.current!==null&&window.clearTimeout(An.current),sn.current!==null&&(cancelAnimationFrame(sn.current),sn.current=null),An.current=window.setTimeout(()=>{An.current=null;const j=Er.current;j!==null&&(j.textContent="",sn.current=requestAnimationFrame(()=>{sn.current=null,j.textContent=w}))},xw)},[]);i.useEffect(()=>()=>{An.current!==null&&window.clearTimeout(An.current),sn.current!==null&&cancelAnimationFrame(sn.current)},[]);const xn=i.useCallback(w=>{O?.(w),m!==void 0&&On(m(w))},[O,m,On]),el=i.useCallback((w,j)=>{if(a===void 0&&f===void 0)return;const Z=j.ranges[j.ranges.length-1],te=rt(Z),ve=j.ranges.length===1&&te.rows===1&&te.cols===1,ke=w.ranges[w.ranges.length-1],pt=w.ranges.length!==j.ranges.length||ke.startRow!==Z.startRow||ke.startCol!==Z.startCol||ke.endRow!==Z.endRow||ke.endCol!==Z.endCol,Et=()=>{if(a!==void 0){const Ze=j.active,an=se.getCellText(Ze.row,Ze.col),er=se.getCellFormat===void 0?void 0:B(Ze.row,Ze.col,()=>an);On(a({row:Ze.row,col:Ze.col,text:an,displayText:jn(an,er===void 0?void 0:er.value),columnName:xe.columnIndexToName(Ze.col),...Zc(se)?{readOnly:Be(se,Ze.row,Ze.col)}:{}}))}};if(ve){Et();return}if(pt){f!==void 0&&On(f({range:Z,anchor:j.anchor,active:j.active,rangeRowCount:te.rows,rangeColCount:te.cols,rangeCount:j.ranges.length}));return}Et()},[se,a,f,On,B]),He=i.useCallback(w=>{const j=Rt.current;Object.is(w,j)||Gg(w,j)||(Rt.current=w,mo(w),W?.(w),el(j,w),(Lt.current?.()??!1)||Xe())},[W,el,Xe]),Qa=i.useCallback(w=>{const j=Rt.current;if(w.mode==="cycle"){const te=Ba(j,w.direction);He(te),Wt(te.active);return}const Z=nn(w.cell,ue.count,de.count);if(w.mode==="extend"){He(fn(j,Z)),Wt(Z);return}He(mr(j,Z,{extend:!1,append:!1})),Wt(Z)},[He,Wt,ue,de]),We=i.useCallback(()=>Lt.current?.()??!1,[]),tl=i.useRef(null),ut=i.useCallback(()=>tl.current?.()??!0,[]),nl=i.useRef(null),Xn=i.useCallback((w,j)=>{const Z=Lt.current?.()??!1;nl.current?.(w,j),!Z&&(Lt.current?.()??!1)&&Yn()},[Yn]),[eu,Oo]=i.useState(!1),rl=i.useCallback(()=>{ot?.(),Oo(!0)},[ot]),tu=i.useCallback((w,j)=>{Be(se,w.row,w.col)||rl(),Xn("edit",j)},[se,rl,Xn]),ol=i.useRef(null),xr=i.useCallback(()=>ol.current?.()??null,[]),sl=i.useRef(null),vt=i.useCallback(()=>{sl.current?.()},[]),ll=i.useRef(null),il=i.useCallback(w=>{ll.current?.(w)},[]),cl=i.useRef(()=>{}),Tr=i.useRef(0),ln=i.useCallback((w,j,Z)=>{let te;if(j.source==="paste"){const ve=Mw(Z);if(w.length===0&&ve.conditionalFormats.length===0)return null;Tr.current+=1,te={transaction:Tr.current,source:"paste",sameSheet:ve.sameSheet,conditionalFormats:ve.conditionalFormats}}else{if(w.length===0)return null;Tr.current+=1,te={transaction:Tr.current,source:j.source}}try{se.applyEdits(w,te)}catch(ve){return N?.(ve,j),null}return Ee.bumpEdit(),il(j.source),te.transaction},[se,Ee,N,il]),nu=i.useCallback((w,j)=>ln(w,{source:"paste"},j),[ln]),ru=i.useCallback(w=>{Ee.setVy(w.y),ct(),at(),Le()},[Ee,ct,at,Le]),al=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),ou=i.useCallback(w=>{Ee.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ee.setColRange(w.renderingColStart,w.renderingColEnd);const j=al.current;(j.rowStart!==w.renderingRowStart||j.rowEnd!==w.renderingRowEnd||j.colStart!==w.renderingColStart||j.colEnd!==w.renderingColEnd)&&(al.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},Le())},[Ee,Le]),ul=i.useRef(()=>"add"),Kt=i.useCallback(w=>{wo.current?.(w,ul.current())},[]),su=i.useCallback(w=>{wo.current?.(w,"point")},[]),dl=i.useRef(null),xo=i.useCallback(w=>{dl.current?.(w)},[]),fl=i.useRef(null),lu=i.useCallback(w=>{fl.current?.(w)},[]),pl=i.useRef(null),To=i.useCallback((w,j)=>{if(j.length===0)return;const Z=ee.current;if(w==="col"){for(const te of j){const ve=Math.round(te.size);de.resize(te.index,ve),Z?.updateColSize(te.index,ve)}Ee.bumpColVersion(),at(),Le(),En(),on();return}for(const te of j){const ve=Math.round(te.size);ue.resize(te.index,ve),Z?.updateRowSize(te.index,ve)}Ee.bumpRowGeometry(),ct(),Le(),En(),on()},[ue,de,Ee,at,ct,Le,En,on]),iu=i.useCallback((w,j)=>{S?.(w,{kind:"pointer",event:j})},[S]),cu=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Kt,axis:"both",zoomRef:oe}),au=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Kt,axis:"x",zoomRef:oe}),uu=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Kt,axis:"y",zoomRef:oe}),du=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:xo,axis:"x",zoomRef:oe}),fu=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:xo,axis:"y",zoomRef:oe}),pu=$n({handleRef:ee,rowAxis:ue,colAxis:de,bodyRef:ce,onDragFrame:Kt,axis:"both",zoomRef:oe}),hl=i.useRef(null),ml=i.useRef(()=>!1),$o=i.useCallback(()=>ml.current(),[]),dt=kw({zoomRef:oe,enabled:!ye,rowAxis:ue,colAxis:de,handleRef:ee,bodyRef:ce,isEditing:We,requestCommit:ut,getSelection:$t,setSelection:He,focusSink:Me,onDragFrame:Kt,onContextMenuSelect:iu,onRequestEdit:tu,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 j=se.getCellText(w.row,w.col);return jn(j,se.getCellFormat(w.row,w.col)?.value)===j},isAnyDragging:$o,autoScroller:cu,repaintOverlay:Le,pointDragRef:hl,getPointing:rn,openHyperlinkAt:$e===void 0||se.getCellHyperlink===void 0?void 0:w=>{const j=se.getCellHyperlink===void 0?void 0:Vn(se.getCellHyperlink(w.row,w.col));return j===void 0?!1:($e(j,w),!0)}}),kt=Vi({zoomRef:oe,enabled:!ye&&b,axis:"col",headerRef:it,mainAxis:de,crossCount:se.rowCount,handleRef:ee,isEditing:We,requestCommit:ut,getSelection:$t,setSelection:He,focusSink:Me,onDragFrame:Kt,autoScroller:au,repaintOverlay:Le,pointing:bo}),St=Vi({zoomRef:oe,enabled:!ye&&b,axis:"row",headerRef:Tt,mainAxis:ue,crossCount:se.colCount,handleRef:ee,isEditing:We,requestCommit:ut,getSelection:$t,setSelection:He,focusSink:Me,onDragFrame:Kt,autoScroller:uu,repaintOverlay:Le,pointing:bo}),Ge=Xg({zoomRef:oe,enabled:!ye&&k&&b,colBandRef:it,rowBandRef:Tt,fontSourceRef:ce,colAxis:de,rowAxis:ue,viewStore:Ee,handleRef:ee,isEditing:We,requestCommit:ut,focusSink:Me,getSelection:$t,adapter:se,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:T,resizeTracks:To,writeResizeGuide:lu,repaintOverlay:Le,isPointing:rn}),ft=dw({zoomRef:oe,enabled:!ye&&v,handleNodeRef:pl,bodyRef:ce,rowAxis:ue,colAxis:de,handleRef:ee,getSelection:$t,setSelection:He,focusSink:Me,adapter:se,commitEdits:ln,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:xn,writeFillPreview:xo,repaintOverlay:Le,xAutoScroller:du,yAutoScroller:fu}),et=Sw({zoomRef:oe,enabled:!ye,bodyRef:ce,handleRef:ee,rowAxis:ue,colAxis:de,getPointing:rn,insertReference:bo.insertReference,captureSink:()=>Bs.current(),restoreSink:w=>Vs.current(w),focusSink:Me,autoScroller:pu,onDragFrame:Kt});hl.current=et;const Gn=i.useCallback(()=>dt.isDragging()||kt.isDragging()||St.isDragging()||Ge.isDragging()||ft.isDragging()||et.isDragging(),[dt,kt,St,Ge,ft,et]);Re.current=Gn,ml.current=Gn,ul.current=()=>et.isDragging()?"point":dt.getDragMode();const hu=i.useCallback(()=>{dt.abortDrag(),kt.abortDrag(),St.abortDrag(),Ge.abortDrag(),ft.abortDrag(),et.abortDrag()},[dt,kt,St,Ge,ft,et]),Lo=i.useCallback(()=>Rt.current.active,[]),gl=i.useCallback((w,j)=>{const Z=se.getCellValidation===void 0?void 0:se.getCellValidation(w.row,w.col);if(Z===void 0)return Yi;const te=se.evaluateFormula,ve=ua(Z,j,It,te===void 0?void 0:ke=>te(ke,w));return ve.ok||Z.strict!==!0?Yi:(De?.({cell:w,rule:Z,text:j,message:ve.message}),Vt.current?.isKindEnabled("message")&&Ar.current("message",{message:ve.message,rejected:!0}),ve)},[se,De,It]),Pe=dg({enabled:!ye,sinkRef:he,rootRef:X,adapter:se,commitEdits:ln,getActive:Lo,ensureCellVisible:Wt,focusSink:Me,rearmSink:Xe,discardClip:vt,isDragging:$o,rejectReadOnly:xn,resolveEditAlign:w=>{if(se.getCellFormat===void 0)return null;const j=Gr(se,w.row,w.col);return Gc(B(w.row,w.col,j),j)},resolveEditPaint:w=>se.getCellFormat===void 0?null:nf(B(w.row,w.col,Gr(se,w.row,w.col))),editPaintRef:Ws,repaintOverlay:Le,validateCommit:gl});Lt.current=Pe.isEditing,tl.current=Pe.requestCommit,nl.current=Pe.startEdit,Co.current=Pe.getPointing,Hs.current=Pe.insertReference,Bs.current=Pe.captureSink,Vs.current=Pe.restoreSink;const wl=i.useCallback(()=>{Pe.cancelEdit(),Yn()},[Pe.cancelEdit,Yn]),Zn=Km({enabled:!ye,sinkRef:he,adapter:se,isEditing:We,getSelection:$t,setSelection:He,commitPaste:nu,maxOperationCells:C,onOperationRejected:T,onCopyMultiRange:q,repaintOverlay:Le,isDragging:$o,resize:{rowAxis:ue,colAxis:de,resizeTracks:To},pendingPasteOptionsRef:Ks,formats:I,onClipChange:Se,onClipboardUnavailable:fe,onEditRejected:N,rejectReadOnly:xn,onPasteResolved:Ne});ol.current=Zn.getClip,sl.current=Zn.discardClip,ll.current=Zn.discardClipOnCommit,cl.current=Zn.onAdapterSwitch,vo.current=Zn.paste;const Jn=Rw({enabled:!ye,adapter:se,popovers:re,sinkRef:he,bodyRef:ce,handleRef:ee,rowAxis:ue,colAxis:de,zoomRef:oe,getActive:Lo,isEditing:We,requestCommit:ut,focusSink:Me,rearmSink:Xe,isDraggingAny:Gn,commitEdits:ln,labels:st,onHyperlinkOpen:$e,anchors:yo,repaintOverlay:Le,rejectReadOnly:xn});Vt.current=Jn,Ar.current=Jn.open,Xs.current=Jn.hideTip;const mu=i.useCallback(()=>{const w=Rt.current.active;return Wt(w),Or(w)},[Wt,Or]),Do=cg({adapter:se,trackResize:k&&!ye?Ge:void 0,getSelection:$t,commitEdits:ln,getActive:Lo,isEditing:We,requestCommit:ut,cancelEdit:wl,getSessionText:Pe.getSessionText,validateCommit:gl,insertAtCaret:Pe.insertAtCaret,refreshEditPaint:Pe.refreshPaint,maxOperationCells:C,onOperationRejected:T,colors:Wn,formats:I,getHighlight:()=>go.current,setHighlight:Za,popovers:re,openPopover:w=>Ar.current(w),onHyperlinkOpen:$e,onPasteSpecialRequest:Je,paste:w=>vo.current(w),rowAxis:ue,colAxis:de,resizeTracks:To,defaultRowHeight:s,defaultColumnWidth:l,now:Ve,announce:On,formatCommandAnnouncement:E,formatResizeAnnouncement:d,keyboardCellRect:mu,rejectReadOnly:xn});Zs.current=Do,Ro.current=Do.executeCommand,Gs.current=Do.isCommandAvailable;const gu=i.useMemo(()=>({table:jt,execute:w=>Ro.current(w),isAvailable:w=>Gs.current(w)}),[jt]),wu=i.useCallback(()=>{vt(),x?.()},[vt,x]),Cu=i.useCallback(()=>{vt(),z?.()},[vt,z]);iw({zoomRef:oe,enabled:!ye,sinkRef:he,rootRef:X,handOffFocusToRoot:Ja,getSelection:$t,setSelection:He,moveActive:Qa,ensureCellVisible:Wt,isEditing:We,requestCommit:ut,startEdit:Xn,commitEdits:ln,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:xn,getClip:xr,discardClip:vt,isDragging:Gn,abortDrag:hu,findDataEdge:se.findDataEdge,getEditingMode:Pe.getEditingMode,cancelEdit:wl,onUndoRequest:wu,onRedoRequest:Cu,onCellContextMenu:S,rowAxis:ue,colAxis:de,handleRef:ee,rearmSink:Xe,commands:gu,pointing:Pe,adapter:se,hideNoteTip:()=>Xs.current(),closeRejectedMessage:Yn,pendingPasteOptionsRef:Ks,onPointFrame:su});const bu=vn.active.row,yu=vn.active.col;i.useLayoutEffect(()=>{const w=Vt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[bu,yu]),i.useLayoutEffect(()=>{Le()},[Le,kn.row,kn.column,kn.intersection]);const Ru=i.useCallback(w=>{(Lt.current?.()??!1)||(w.preventDefault(),Me(),Xe())},[Me,Xe]),vu=i.useCallback(w=>{const j=X.current,Z=w.relatedTarget;if(j!==null&&Z instanceof Node&&j.contains(Z)){w.target===j&&Z===he.current&&!ko.current&&Me();return}(Lt.current?.()??!1)||(Me(),Xe())},[Me,Xe]),ku=i.useCallback(w=>{const j=X.current,Z=w.relatedTarget;j!==null&&Z instanceof Node&&j.contains(Z)||Pe.isFocusoutSuppressed()||Oo(!1)},[Pe]),$r=i.useRef(null),Qn=i.useCallback(()=>{const w=$r.current;w!==null&&($r.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Mo=i.useCallback(()=>{if($r.current!==null)return;const w=Z=>{Z.pointerType==="mouse"&&(Qn(),Z.button===1&&Z.preventDefault())},j=Z=>{Z.pointerType==="mouse"&&Qn()};$r.current={up:w,cancel:j},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",j,!0)},[Qn]);i.useEffect(()=>Qn,[Qn]),i.useEffect(()=>{const w=X.current;if(ye||w===null)return;let j=0;const Z=ke=>{if(ke.pointerType!=="mouse"){(Lt.current?.()??!1)||Oo(!1);return}j=ke.buttons,ke.button===1&&(ke.target===he.current&&(Lt.current?.()??!1)||Mo())},te=ke=>{ke.pointerType==="mouse"&&(j=ke.buttons)},ve=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===j)return;const pt=ke.buttons&~j;j=ke.buttons,ke.preventDefault(),(pt&4)!==0&&Mo()};return w.addEventListener("pointerdown",Z,!0),w.addEventListener("pointerup",te,!0),w.addEventListener("pointermove",ve,!0),()=>{w.removeEventListener("pointerdown",Z,!0),w.removeEventListener("pointerup",te,!0),w.removeEventListener("pointermove",ve,!0)}},[ye,Mo]);const Su=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(rn()){Me();return}if(We()&&!ut()){Me();return}Me()}},[Me,We,ut,rn]),zo=i.useRef(!1);i.useLayoutEffect(()=>{if(ye){zo.current=!1;return}if(zo.current)return;zo.current=!0,Xe();const w=(X.current?.clientHeight??0)/oe.current;w>0&&ue.totalSize()>0&&Ee.setRowRange(0,ue.indexAt(Math.min(w-1,ue.totalSize()-1)));const j=(X.current?.clientWidth??0)/oe.current;j>0&&de.totalSize()>0&&Ee.setColRange(0,de.indexAt(Math.min(j-1,de.totalSize()-1)))},[ye,Xe,Ee,ue,de]);const Cl=i.useRef(t);i.useLayoutEffect(()=>{Cl.current!==t&&(Cl.current=t,dt.cancelDrag(),kt.cancelDrag(),St.cancelDrag(),Ge.cancelDrag(),ft.cancelDrag(),et.cancelDrag(),Pe.cancelEdit(),Vt.current?.hideTip(),Vt.current?.close(),ye?(Rt.current=Ln,mo(Ln)):He(Ln),cl.current())},[t,ye,He,dt,kt,St,Ge,ft,et,Ee,Pe.cancelEdit]);const bl=i.useRef({adapter:se,rows:ue.count,cols:de.count}),{getSessionCell:yl,cancelEdit:Rl}=Pe;i.useLayoutEffect(()=>{const w=bl.current,j=ue.count,Z=de.count;if(bl.current={adapter:se,rows:j,cols:Z},w.adapter!==se||j>=w.rows&&Z>=w.cols)return;ye?(Rt.current=Ln,mo(Ln)):He(Zg(Rt.current,j,Z)),dt.cancelDrag(),kt.cancelDrag(),St.cancelDrag(),Ge.cancelDrag(),ft.cancelDrag(),et.cancelDrag();const te=Et=>ye||Et.row>=j||Et.col>=Z,ve=yl();ve!==null&&te(ve)&&Rl();const ke=yo.current;if(ke.tip!==null&&te(ke.tip)&&Vt.current?.hideTip(),ke.interactive!==null&&te(ke.interactive)){const Et=X.current?.contains(document.activeElement)===!0;Vt.current?.close({restoreFocus:Et})}const pt=xr();pt!==null&&!pt.foreign&&te({row:pt.range.endRow,col:pt.range.endCol})&&vt()},[se,ue.count,de.count,ye,He,dt,kt,St,Ge,ft,et,yl,Rl,xr,vt]);const vl=i.useRef(c),kl=i.useRef(u),Sl=i.useRef(h),El=i.useRef(g);i.useLayoutEffect(()=>{(vl.current!==c||kl.current!==u||Sl.current!==h||El.current!==g)&&(vl.current=c,kl.current=u,Sl.current=h,El.current=g,dt.cancelDrag(),kt.cancelDrag(),St.cancelDrag(),Ge.cancelDrag(),ft.cancelDrag(),et.cancelDrag())},[c,u,h,g,dt,kt,St,Ge,ft,et]),i.useLayoutEffect(()=>{ct(),at(),Le()},[c,u,h,g,ct,at,Le]);const Al=i.useRef(p);i.useLayoutEffect(()=>{Al.current!==p&&(Al.current=p,vt())},[p,vt]),i.useLayoutEffect(()=>{Le()},[Le,vn]);const cn=i.useCallback(()=>{const w=Zs.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(Cn,()=>({resizeRow:(w,j)=>{const Z=Math.round(j);ue.resize(w,Z),ee.current?.updateRowSize(w,Z),Ee.bumpRowGeometry(),ct(),Le(),En(),on()},resizeColumn:(w,j)=>{const Z=Math.round(j);de.resize(w,Z),ee.current?.updateColSize(w,Z),Ee.bumpColVersion(),at(),Le(),En(),on()},autoFitColumns:w=>{for(const j of w)if(!Number.isInteger(j)||j<0||j>=de.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${de.count-1} (got ${String(j)})`);return Ge.autofitColumnsInAllRows(w)},scrollToCell:(w,j)=>{ee.current?.scrollToCell(w.row,w.col,j)},focus:w=>{Me(w),We()||Xe()},executeCommand:w=>Ro.current(w),applyFormat:w=>cn().applyFormat(w),setBorders:(w,j)=>cn().setBorders(w,j),setHyperlink:w=>cn().setHyperlink(w),setNote:w=>cn().setNote(w),addComment:w=>cn().addComment(w),setValidation:w=>cn().setValidation(w),paste:w=>vo.current(w),getSelection:()=>Rt.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=>{Xn(w)},openPopover:w=>{Ar.current(w)}}),[ue,de,Ee,at,ct,Le,En,on,Ge,Me,We,Xe,se,B,Xn,cn]),ye)return Y.jsx("div",{className:wt?`aqsp-root ${wt}`:"aqsp-root","data-aqsp-empty":"","data-testid":qe});const Eu=a!==void 0||f!==void 0||E!==void 0||m!==void 0||d!==void 0,Au=o===void 0?{"aria-label":st.rootAriaLabel}:{"aria-labelledby":o};return Y.jsxs("div",{ref:X,className:wt?`aqsp-root ${wt}`:"aqsp-root",role:"group",...Au,tabIndex:0,onFocus:vu,onBlur:ku,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-testid":qe,children:[Y.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":le,onPointerDown:Su,style:le===1?void 0:{width:`${100/le}%`,height:`${100/le}%`,transform:`scale(${le})`},children:[b?Y.jsxs(Y.Fragment,{children:[Y.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(rn()){Me();return}if(We()&&!ut()){Me();return}Me(),He({ranges:[Ce({row:0,col:0},{row:se.rowCount-1,col:se.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),Y.jsx(Wg,{viewStore:Ee,colAxis:de,frozenCols:c,frozenTrailingCols:h,handleRef:ee,bandRef:it,colTrackRef:Ct,windowOriginXRef:lt,repaintColHeaders:at,selectionRanges:vn.ranges,enableResizeUI:k,dividerLeadingRef:bt,dividerTrailingRef:Bt}),Y.jsx(Kg,{viewStore:Ee,rowAxis:ue,handleRef:ee,bandRef:Tt,selectionRanges:vn.ranges,rowTrackRef:Oe,windowOriginYRef:ze,repaintHeaders:ct,enableResizeUI:k,frozenRows:u,frozenTrailingRows:g,dividerLeadingRef:yt,dividerTrailingRef:Rn})]}):null,Y.jsxs("div",{ref:pe,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[Y.jsx(Vg,{adapter:se,rowAxis:ue,colAxis:de,viewStore:Ee,handleRef:ee,bodyRef:ce,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:g,headerRows:n,labelledBy:o,gridLabel:o===void 0?st.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:R,overscanRows:Wi("overscanRows",F),overscanCols:Wi("overscanCols",H),background:L,onRenderTruncated:P,renderCell:U,onScroll:ru,onRangeChange:ou,focusSink:Me,isEditing:We,requestCommit:ut,testId:qe?`${qe}-vs`:void 0,__onCellRender:wn,__maxRenderedCells:vr,cfIndexRef:Kn,cfMemoRef:M,isPointing:rn,locale:It,scrollLabels:bn}),Y.jsx(ym,{rowAxis:ue,colAxis:de,handleRef:ee,sinkRef:he,getSelection:$t,editing:Pe.editing,virtualKeyboard:eu,repaintRef:js,dragFrameRef:wo,getClip:xr,getIsDraggingAny:Gn,getIsFillDragging:ft.isDragging,fillFrameRef:dl,resizeGuideFrameRef:fl,fillHandleNodeRef:pl,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:g,sinkAriaLabel:st.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:kr,onSinkMouseDown:Ru,editPaintRef:Ws,highlightRef:go,highlightColors:Ga,popoverAnchors:yo,interactiveAnchorRef:Ys,tipAnchorRef:Us}),Jn.layerEnabled?Y.jsx(Cw,{controller:Jn,labels:st,renderPopover:be,interactiveAnchorRef:Ys,tipAnchorRef:Us}):null]}),Eu?Y.jsx("div",{ref:Er,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),Y.jsx("div",{ref:ge,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=Nt.iterateTsvPrefixRows;exports.iterateTsvRows=Nt.iterateTsvRows;exports.measureTsv=Nt.measureTsv;exports.parseTsv=Nt.parseTsv;exports.serializeClipboardTsv=Nt.serializeClipboardTsv;exports.serializeTsv=Nt.serializeTsv;exports.columnIndexToName=xe.columnIndexToName;exports.columnNameToIndex=xe.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=bs;exports.CommentPopover=Ra;exports.DEFAULT_CUSTOM_COLORS=Ya;exports.DEFAULT_HIGHLIGHT_COLORS=ba;exports.DEFAULT_SHORTCUTS=sa;exports.LinkPopover=va;exports.ListPopover=ka;exports.MessagePopover=Sa;exports.NotePopover=Ea;exports.NoteTip=Aa;exports.SPREADSHEET_LABEL_CATALOGS=la;exports.SPREADSHEET_RESERVED_SHORTCUTS=kh;exports.Spreadsheet=Fw;exports.canonicalizeFormat=gt;exports.detectClipSource=oc;exports.enumerateRangeCells=Ut;exports.estimatePasteCellCount=uh;exports.expandPaste=dh;exports.formatCellValue=jn;exports.formatEquals=Pu;exports.fromR1C1=Cr;exports.makeRange=Ce;exports.mergeFormat=Rs;exports.normalizeHyperlink=tn;exports.parseChord=Xt;exports.parseClipPayload=ns;exports.parseHtmlTable=Xc;exports.rangeContains=gn;exports.rangeSize=rt;exports.resolveLabel=Fe;exports.resolveLabels=ia;exports.serializeClipPayload=tc;exports.serializeHtmlTable=Wc;exports.shiftFormula=xc;exports.toR1C1=io;exports.validateCellText=ua;
|